Fraxinus  16.5.0-fx-rc6
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxClippers.h"
34 #include "cxVisServices.h"
35 #include "cxLogger.h"
36 #include "cxInteractiveClipper.h"
37 #include "cxEnumConverter.h"
39 #include "cxXmlOptionItem.h"
40 #include "cxProfile.h"
41 #include "cxStringProperty.h"
42 #include "cxXmlOptionItem.h"
43 #include "cxXMLNodeWrapper.h"
44 
45 
46 namespace cx
47 {
48 
50  mServices(services)
51 // mStorage(services->session(), "Clippers")
52 {
53  this->createDefaultClippers();
54 // mStorage.storeVariable("clipperList", boost::bind(&Clippers::exportList, this), boost::bind(&Clippers::importList, this, _1));
55 
56 // XmlOptionFile mOptions = profile()->getXmlSettings().descend("clippers");
57 
58 
59  //TODO: Store clippers in profile file instead of patient file
60 // QString defaultValue = this->getInitialClipperNames().join(';');
61 // mClipperList = StringProperty::initialize("clipperList", "Clipper List",
62 // "List of clippers",
63 // defaultValue, mOptions.getElement());
64 
65 
66 
67 // XmlOptionItem xmlStore = XmlOptionItem("clipperList", mOptions.toElement());
68 // this->importList(xmlStore.readValue(this->getInitialClipperNames().join(';')));
69 }
70 
71 void Clippers::addXml(QDomNode& parentNode)
72 {
73  XMLNodeAdder parent(parentNode);
74  XMLNodeAdder clippersNode(parent.addElement("clippers"));
75 
76  std::map<QString, InteractiveClipperPtr>::iterator iter = mClippers.begin();
77  for (; iter != mClippers.end(); ++iter)
78  {
79  QDomElement clipperNode = clippersNode.addElement("clipper");
80  clipperNode.setAttribute("name", iter->first);
81  iter->second->addXml(clipperNode);
82  }
83 }
84 
85 void Clippers::parseXml(QDomNode parentNode)
86 {
87  XMLNodeParser base(parentNode);
88 
89  QDomElement clippersNode = base.parseElement("clippers");
90  QDomNode clipperNode = clippersNode.firstChild();
91  while (!clipperNode.isNull())
92  {
93  if (clipperNode.toElement().tagName() != "clipper")
94  {
95  clipperNode = clipperNode.nextSibling();
96  continue;
97  }
98  QString clipperName = clipperNode.toElement().attribute("name");
99  InteractiveClipperPtr clipper = this->getClipper(clipperName);
100  clipper->parseXml(clipperNode);
101 
102  clipperNode = clipperNode.nextSibling();
103  }
104 }
105 
106 void Clippers::importList(QString clippers)
107 {
108  mClipperList.clear();
109  if(!clippers.isEmpty())
110  mClipperList = clippers.split(';');
111 
112  emit changed();
113 }
114 
116 {
117  return mClipperList.join(';');
118 }
119 
121 {
122  QStringList initialList = this->getInitialClipperNames();
123 
124  foreach(QString name, initialList)
125  {
127 
128  PLANE_TYPE plane = string2enum<PLANE_TYPE> (name);
129  interactiveClipper->setSlicePlane(plane);
130  this->add(name, interactiveClipper);
131  }
132 }
133 
135 {
137  StringPropertyBasePtr planeAdapter = StringPropertyClipPlane::New(interactiveClipper);
138  QStringList clipperNames = planeAdapter->getValueRange();
139  return clipperNames;
140 }
141 
143 {
144  if(this->exists(clipperName))
145  return mClippers.at(clipperName);
146  else
147  {
149  this->add(clipperName, clipper);
150  return clipper;
151  }
152 }
153 
154 void Clippers::add(QString clipperName, InteractiveClipperPtr clipper)
155 {
156  if(!clipper)
157  return;
158  if(!this->exists(clipperName))
159  {
160  mClippers[clipperName] = clipper;
161  mClipperList << clipperName;
162  connect(clipper.get(), &InteractiveClipper::changed, this, &Clippers::changed);
163  }
164  else
165  CX_LOG_WARNING() << "Cannot add clipper: " << clipperName << " already exists";
166 }
167 
168 void Clippers::remove(QString clipperName)
169 {
170  if(this->exists(clipperName))
171  {
172  InteractiveClipperPtr clipper = mClippers[clipperName];
173  disconnect(clipper.get(), &InteractiveClipper::changed, this, &Clippers::changed);
174  }
175 
176  mClippers.erase(clipperName);
177  int index = mClipperList.indexOf(clipperName);
178  if(index >= 0)
179  mClipperList.removeAt(index);
180  emit changed();
181 }
182 
183 bool Clippers::exists(QString clipperName)
184 {
185  return mClippers.find(clipperName) != mClippers.end();
186 }
187 
189 {
190  return mClipperList;
191 }
192 
193 
194 
195 }//cx
void remove(QString clipperName)
Definition: cxClippers.cpp:168
InteractiveClipperPtr getClipper(QString clipperName)
Definition: cxClippers.cpp:142
void changed()
void createDefaultClippers()
Definition: cxClippers.cpp:120
void parseXml(QDomNode parentNode)
Definition: cxClippers.cpp:85
void addXml(QDomNode &parentNode)
Definition: cxClippers.cpp:71
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
void importList(QString clippers)
Definition: cxClippers.cpp:106
QDomElement addElement(QString name)
VisServicesPtr mServices
Definition: cxClippers.h:70
std::map< QString, InteractiveClipperPtr > mClippers
Definition: cxClippers.h:72
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
void add(QString clipperName, InteractiveClipperPtr clipper)
Definition: cxClippers.cpp:154
QString exportList()
Definition: cxClippers.cpp:115
QStringList getClipperNames()
Definition: cxClippers.cpp:188
#define CX_LOG_WARNING
Definition: cxLogger.h:113
QStringList getInitialClipperNames()
Definition: cxClippers.cpp:134
QStringList mClipperList
Definition: cxClippers.h:73
Clippers(VisServicesPtr services)
Definition: cxClippers.cpp:49
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
bool exists(QString clipperName)
Definition: cxClippers.cpp:183
static StringPropertyClipPlanePtr New(InteractiveClipperPtr clipper)
QDomElement parseElement(QString name)