diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp index 6f30e06bfe..dc1ae66d0b 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp @@ -1,78 +1,100 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkNavigationToolStorage.h" mitk::NavigationToolStorage::NavigationToolStorage() { m_ToolCollection = std::vector(); + this->m_DataStorage = NULL; } -mitk::NavigationToolStorage::~NavigationToolStorage() +mitk::NavigationToolStorage::NavigationToolStorage(mitk::DataStorage::Pointer ds) { + m_ToolCollection = std::vector(); + this->m_DataStorage = ds; + } + + +mitk::NavigationToolStorage::~NavigationToolStorage() + { + if (m_DataStorage.IsNotNull()) //remove all nodes from the data storage + { + for(std::vector::iterator it = m_ToolCollection.begin(); it != m_ToolCollection.end(); it++) + m_DataStorage->Remove((*it)->GetDataNode()); + } } bool mitk::NavigationToolStorage::DeleteTool(int number) { if ((unsigned int)number > m_ToolCollection.size()) return false; std::vector::iterator it = m_ToolCollection.begin() + number; + if(m_DataStorage.IsNotNull()) + m_DataStorage->Remove((*it)->GetDataNode()); m_ToolCollection.erase(it); + return true; } + bool mitk::NavigationToolStorage::DeleteAllTools() { while(m_ToolCollection.size() > 0) if (!DeleteTool(0)) return false; return true; } bool mitk::NavigationToolStorage::AddTool(mitk::NavigationTool::Pointer tool) { if (GetTool(tool->GetIdentifier()).IsNotNull()) return false; else { m_ToolCollection.push_back(tool); + if(m_DataStorage.IsNotNull()) + { + if (!m_DataStorage->Exists(tool->GetDataNode())) + m_DataStorage->Add(tool->GetDataNode()); + } return true; } } mitk::NavigationTool::Pointer mitk::NavigationToolStorage::GetTool(int number) { return m_ToolCollection.at(number); } mitk::NavigationTool::Pointer mitk::NavigationToolStorage::GetTool(std::string identifier) { for (int i=0; iGetIdentifier())==identifier) return GetTool(i); return NULL; } mitk::NavigationTool::Pointer mitk::NavigationToolStorage::GetToolByName(std::string name) { for (int i=0; iGetToolName())==name) return GetTool(i); return NULL; } int mitk::NavigationToolStorage::GetToolCount() { return m_ToolCollection.size(); } bool mitk::NavigationToolStorage::isEmpty() { return m_ToolCollection.empty(); } diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h index 4a03bcdfc0..a2ea9c7957 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h @@ -1,103 +1,111 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-08-11 15:15:02 +0200 (Di, 11 Aug 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef NAVIGATIONTOOLSTORAGE_H_INCLUDED #define NAVIGATIONTOOLSTORAGE_H_INCLUDED //itk headers #include //mitk headers #include #include #include "mitkNavigationTool.h" +#include namespace mitk { /**Documentation * \brief An object of this class represents a collection of navigation tools. * You may add/delete navigation tools or store/load the whole collection * to/from the harddisc by using the class NavigationToolStorageSerializer * and NavigationToolStorageDeserializer. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationToolStorage : public itk::Object { public: mitkClassMacro(NavigationToolStorage,itk::Object); + /** @brief Constructs a NavigationToolStorage without reference to a DataStorage. The Data Nodes of tools have to be added and removed to a data storage outside this class. + * Normaly the other constructor should be used. + */ itkNewMacro(Self); + /** @brief Constructs a NavigationToolStorage with reference to a DataStorage. The Data Nodes of tools are added and removed automatically to this data storage. */ + mitkNewMacro1Param(Self,mitk::DataStorage::Pointer); /** * @brief Adds a tool to the storage. Be sure that the tool has a unique * identifier which is not already part of this storage. * @return Returns true if the tool was added to the storage, false if not * (false can be returned if the identifier already exists in this storage * for example). */ bool AddTool(mitk::NavigationTool::Pointer tool); /** * @return Returns the tracking tool at the position "number" * in the storage. Returns NULL if there is no * tracking tool at this position. */ mitk::NavigationTool::Pointer GetTool(int number); /** * @return Returns the tracking tool with the given identifier. * Returns NULL if there is no * tracking tool with this identifier in the storage. */ mitk::NavigationTool::Pointer GetTool(std::string identifier); /** * @return Returns the tracking tool with the given name. * Returns NULL if there is no * tracking tool with this name in the storage. */ mitk::NavigationTool::Pointer GetToolByName(std::string name); /** * @brief Deletes a tool from the collection. */ bool DeleteTool(int number); /** * @brief Deletes all tools from the collection. */ bool DeleteAllTools(); /** * @return Returns the number of tools stored in the storage. */ int GetToolCount(); /** * @return Returns true if the storage is empty, false if not. */ bool isEmpty(); protected: NavigationToolStorage(); + NavigationToolStorage(mitk::DataStorage::Pointer); ~NavigationToolStorage(); std::vector m_ToolCollection; + mitk::DataStorage::Pointer m_DataStorage; }; } // namespace mitk -#endif //NAVIGATIONTOOLSTORAGE \ No newline at end of file +#endif //NAVIGATIONTOOLSTORAGE