20 #include <itkCommand.h>
21 #include <itkObjectFactoryBase.h>
32 : m_ActiveTool(nullptr), m_ActiveToolID(-1), m_RegisteredClients(0),
m_DataStorage(storage)
41 for (DataVectorType::iterator dataIter = m_WorkingData.begin(); dataIter != m_WorkingData.end(); ++dataIter)
42 (*dataIter)->RemoveObserver(m_WorkingDataObserverTags[(*dataIter)]);
50 m_ActiveTool->Deactivated();
51 m_ActiveToolRegistration.Unregister();
53 m_ActiveTool =
nullptr;
56 ActiveToolChanged.Send();
58 for (NodeTagMapType::iterator observerTagMapIter = m_ReferenceDataObserverTags.begin();
59 observerTagMapIter != m_ReferenceDataObserverTags.end();
62 observerTagMapIter->first->RemoveObserver(observerTagMapIter->second);
70 std::list<itk::LightObject::Pointer> thingsThatClaimToBeATool = itk::ObjectFactoryBase::CreateAllInstance(
"mitkTool");
73 for (std::list<itk::LightObject::Pointer>::iterator iter = thingsThatClaimToBeATool.begin();
74 iter != thingsThatClaimToBeATool.end();
77 if (
Tool *tool = dynamic_cast<Tool *>(iter->GetPointer()))
79 tool->InitializeStateMachine();
80 tool->SetToolManager(
this);
82 tool->GeneralMessage +=
84 m_Tools.push_back(tool);
91 this->ToolErrorMessage(s);
96 this->GeneralToolMessage(s);
103 for (ToolVectorType::iterator iter = m_Tools.begin(); iter != m_Tools.end(); ++iter)
105 resultList.push_back(iter->GetPointer());
115 return m_Tools.at(
id);
117 catch (
const std::exception &)
125 if (
id != -1 && !this->GetToolById(
id)->CanHandle(this->GetReferenceData(0)->
GetData()))
134 if (GetToolById(
id) == m_ActiveTool)
137 static int nextTool = -1;
140 static bool inActivateTool =
false;
145 inActivateTool =
true;
147 while (nextTool != m_ActiveToolID)
151 m_ActiveTool->Deactivated();
152 m_ActiveToolRegistration.Unregister();
155 m_ActiveTool = GetToolById(nextTool);
156 m_ActiveToolID = m_ActiveTool ? nextTool : -1;
158 ActiveToolChanged.Send();
162 if (m_RegisteredClients > 0)
164 m_ActiveTool->Activated();
165 m_ActiveToolRegistration =
171 inActivateTool =
false;
172 return (m_ActiveTool !=
nullptr);
177 if (data != m_ReferenceData)
180 for (DataVectorType::iterator dataIter = m_ReferenceData.begin(); dataIter != m_ReferenceData.end(); ++dataIter)
182 NodeTagMapType::iterator searchIter = m_ReferenceDataObserverTags.find(*dataIter);
183 if (searchIter != m_ReferenceDataObserverTags.end())
185 (*dataIter)->RemoveObserver(searchIter->second);
189 m_ReferenceData = data;
193 m_ReferenceDataObserverTags.clear();
194 for (DataVectorType::iterator dataIter = m_ReferenceData.begin(); dataIter != m_ReferenceData.end(); ++dataIter)
199 m_ReferenceDataObserverTags.insert(
200 std::pair<DataNode *, unsigned long>((*dataIter), (*dataIter)->AddObserver(itk::DeleteEvent(), command)));
203 ReferenceDataChanged.Send();
209 OnOneOfTheReferenceDataDeleted(const_cast<itk::Object *>(caller), e);
216 for (DataVectorType::iterator dataIter = m_ReferenceData.begin(); dataIter != m_ReferenceData.end(); ++dataIter)
218 if ((
void *)(*dataIter) != (
void *)caller)
220 v.push_back(*dataIter);
224 m_ReferenceDataObserverTags.erase(*dataIter);
227 this->SetReferenceData(v);
242 if (data != m_WorkingData)
245 for (DataVectorType::iterator dataIter = m_WorkingData.begin(); dataIter != m_WorkingData.end(); ++dataIter)
247 NodeTagMapType::iterator searchIter = m_WorkingDataObserverTags.find(*dataIter);
248 if (searchIter != m_WorkingDataObserverTags.end())
250 (*dataIter)->RemoveObserver(searchIter->second);
254 m_WorkingData = data;
258 if (m_WorkingData.empty())
259 this->ActivateTool(-1);
263 m_WorkingDataObserverTags.clear();
264 for (DataVectorType::iterator dataIter = m_WorkingData.begin(); dataIter != m_WorkingData.end(); ++dataIter)
269 m_WorkingDataObserverTags.insert(
270 std::pair<DataNode *, unsigned long>((*dataIter), (*dataIter)->AddObserver(itk::DeleteEvent(), command)));
273 WorkingDataChanged.Send();
279 OnOneOfTheWorkingDataDeleted(const_cast<itk::Object *>(caller), e);
286 for (DataVectorType::iterator dataIter = m_WorkingData.begin(); dataIter != m_WorkingData.end(); ++dataIter)
288 if ((
void *)(*dataIter) != (
void *)caller)
290 v.push_back(*dataIter);
294 m_WorkingDataObserverTags.erase(*dataIter);
297 this->SetWorkingData(v);
314 if (data != m_RoiData)
317 for (DataVectorType::iterator dataIter = m_RoiData.begin(); dataIter != m_RoiData.end(); ++dataIter)
319 NodeTagMapType::iterator searchIter = m_RoiDataObserverTags.find(*dataIter);
320 if (searchIter != m_RoiDataObserverTags.end())
322 (*dataIter)->RemoveObserver(searchIter->second);
330 m_RoiDataObserverTags.clear();
331 for (DataVectorType::iterator dataIter = m_RoiData.begin(); dataIter != m_RoiData.end(); ++dataIter)
336 m_RoiDataObserverTags.insert(
337 std::pair<DataNode *, unsigned long>((*dataIter), (*dataIter)->AddObserver(itk::DeleteEvent(), command)));
339 RoiDataChanged.Send();
356 OnOneOfTheRoiDataDeleted(const_cast<itk::Object *>(caller), e);
363 for (DataVectorType::iterator dataIter = m_RoiData.begin(); dataIter != m_RoiData.end(); ++dataIter)
365 if ((
void *)(*dataIter) != (
void *)caller)
367 v.push_back(*dataIter);
371 m_RoiDataObserverTags.erase(*dataIter);
379 return m_ReferenceData;
386 return m_ReferenceData.at(idx);
388 catch (
const std::exception &)
396 return m_WorkingData;
408 return m_RoiData.at(idx);
410 catch (
const std::exception &)
437 return m_WorkingData.at(idx);
439 catch (
const std::exception &)
447 return m_ActiveToolID;
457 if (m_RegisteredClients < 1)
461 m_ActiveTool->Activated();
462 m_ActiveToolRegistration =
466 ++m_RegisteredClients;
471 if (m_RegisteredClients < 1)
474 --m_RegisteredClients;
475 if (m_RegisteredClients < 1)
479 m_ActiveTool->Deactivated();
480 m_ActiveToolRegistration.Unregister();
488 for (ToolVectorType::iterator iter = m_Tools.begin(); iter != m_Tools.end(); ++iter, ++id)
490 if (tool == iter->GetPointer())
501 OnOneOfTheReferenceDataDeleted(const_cast<mitk::DataNode *>(node), itk::DeleteEvent());
502 OnOneOfTheRoiDataDeleted(const_cast<mitk::DataNode *>(node), itk::DeleteEvent());
503 OnOneOfTheWorkingDataDeleted(const_cast<mitk::DataNode *>(node), itk::DeleteEvent());
Data management class that handles 'was created by' relations.
Base class to implement InteractionEventObservers.
itk::SmartPointer< Self > Pointer
ServiceRegistrationU RegisterService(const InterfaceMap &service, const ServiceProperties &properties=ServiceProperties())
static Pointer GetInstance()
static mitk::DataStorage::Pointer GetDataStorage()
T::Pointer GetData(const std::string &name)
mitk::DataStorage::Pointer m_DataStorage
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.