CustusX  22.04-rc2
An IGT application
cxClippers.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxClippers.h"
13 #include "cxVisServices.h"
14 #include "cxLogger.h"
15 #include "cxInteractiveClipper.h"
16 #include "cxEnumConversion.h"
18 #include "cxXmlOptionItem.h"
19 #include "cxProfile.h"
20 #include "cxStringProperty.h"
21 #include "cxXmlOptionItem.h"
22 #include "cxXMLNodeWrapper.h"
23 
24 
25 namespace cx
26 {
27 
29  mServices(services)
30 // mStorage(services->session(), "Clippers")
31 {
32  this->createDefaultClippers();
33 // mStorage.storeVariable("clipperList", boost::bind(&Clippers::exportList, this), boost::bind(&Clippers::importList, this, _1));
34 
35 // XmlOptionFile mOptions = profile()->getXmlSettings().descend("clippers");
36 
37 
38  //TODO: Store clippers in profile file instead of patient file
39 // QString defaultValue = this->getInitialClipperNames().join(';');
40 // mClipperList = StringProperty::initialize("clipperList", "Clipper List",
41 // "List of clippers",
42 // defaultValue, mOptions.getElement());
43 
44 
45 
46 // XmlOptionItem xmlStore = XmlOptionItem("clipperList", mOptions.toElement());
47 // this->importList(xmlStore.readValue(this->getInitialClipperNames().join(';')));
48 }
49 
50 void Clippers::addXml(QDomNode& parentNode)
51 {
52  XMLNodeAdder parent(parentNode);
53  XMLNodeAdder clippersNode(parent.addElement("clippers"));
54 
55  std::map<QString, InteractiveClipperPtr>::iterator iter = mClippers.begin();
56  for (; iter != mClippers.end(); ++iter)
57  {
58  QDomElement clipperNode = clippersNode.addElement("clipper");
59  clipperNode.setAttribute("name", iter->first);
60  iter->second->addXml(clipperNode);
61  }
62 }
63 
64 void Clippers::parseXml(QDomNode parentNode)
65 {
66  XMLNodeParser base(parentNode);
67 
68  QDomElement clippersNode = base.parseElement("clippers");
69  QDomNode clipperNode = clippersNode.firstChild();
70  while (!clipperNode.isNull())
71  {
72  if (clipperNode.toElement().tagName() != "clipper")
73  {
74  clipperNode = clipperNode.nextSibling();
75  continue;
76  }
77  QString clipperName = clipperNode.toElement().attribute("name");
78  InteractiveClipperPtr clipper = this->getClipper(clipperName);
79  clipper->parseXml(clipperNode);
80 
81  clipperNode = clipperNode.nextSibling();
82  }
83 }
84 
85 void Clippers::importList(QString clippers)
86 {
87  mClipperList.clear();
88  if(!clippers.isEmpty())
89  mClipperList = clippers.split(';');
90 
91  emit changed();
92 }
93 
95 {
96  return mClipperList.join(';');
97 }
98 
100 {
101  QStringList initialList = this->getInitialClipperNames();
102 
103  foreach(QString name, initialList)
104  {
106 
107  PLANE_TYPE plane = string2enum<PLANE_TYPE> (name);
108  interactiveClipper->setSlicePlane(plane);
109  this->add(name, interactiveClipper);
110  }
111 }
112 
114 {
116  StringPropertyBasePtr planeAdapter = StringPropertyClipPlane::New(interactiveClipper);
117  QStringList clipperNames = planeAdapter->getValueRange();
118  return clipperNames;
119 }
120 
122 {
123  if(this->exists(clipperName))
124  return mClippers.at(clipperName);
125  else
126  {
128  this->add(clipperName, clipper);
129  return clipper;
130  }
131 }
132 
133 void Clippers::add(QString clipperName, InteractiveClipperPtr clipper)
134 {
135  if(!clipper)
136  return;
137  if(!this->exists(clipperName))
138  {
139  mClippers[clipperName] = clipper;
140  mClipperList << clipperName;
141  connect(clipper.get(), &InteractiveClipper::changed, this, &Clippers::changed);
142  }
143  else
144  CX_LOG_WARNING() << "Cannot add clipper: " << clipperName << " already exists";
145 }
146 
147 void Clippers::remove(QString clipperName)
148 {
149  if(this->exists(clipperName))
150  {
151  InteractiveClipperPtr clipper = mClippers[clipperName];
152  disconnect(clipper.get(), &InteractiveClipper::changed, this, &Clippers::changed);
153  }
154 
155  mClippers.erase(clipperName);
156  int index = mClipperList.indexOf(clipperName);
157  if(index >= 0)
158  mClipperList.removeAt(index);
159  emit changed();
160 }
161 
162 bool Clippers::exists(QString clipperName)
163 {
164  return mClippers.find(clipperName) != mClippers.end();
165 }
166 
168 {
169  return mClipperList;
170 }
171 
172 
173 
174 }//cx
void remove(QString clipperName)
Definition: cxClippers.cpp:147
InteractiveClipperPtr getClipper(QString clipperName)
Definition: cxClippers.cpp:121
void changed()
void createDefaultClippers()
Definition: cxClippers.cpp:99
void parseXml(QDomNode parentNode)
Definition: cxClippers.cpp:64
void addXml(QDomNode &parentNode)
Definition: cxClippers.cpp:50
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
void importList(QString clippers)
Definition: cxClippers.cpp:85
QDomElement addElement(QString name)
VisServicesPtr mServices
Definition: cxClippers.h:48
std::map< QString, InteractiveClipperPtr > mClippers
Definition: cxClippers.h:50
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
void add(QString clipperName, InteractiveClipperPtr clipper)
Definition: cxClippers.cpp:133
QString exportList()
Definition: cxClippers.cpp:94
QStringList getClipperNames()
Definition: cxClippers.cpp:167
#define CX_LOG_WARNING
Definition: cxLogger.h:98
QStringList getInitialClipperNames()
Definition: cxClippers.cpp:113
QStringList mClipperList
Definition: cxClippers.h:51
Clippers(VisServicesPtr services)
Definition: cxClippers.cpp:28
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
bool exists(QString clipperName)
Definition: cxClippers.cpp:162
static StringPropertyClipPlanePtr New(InteractiveClipperPtr clipper)
QDomElement parseElement(QString name)
Namespace for all CustusX production code.