16#include <usGetModuleContext.h>
18#include <usModuleContext.h>
26 m_DataStorage(nullptr),
27 m_storageLocked(false)
29 this->
SetName(
"ToolStorage (no name given)");
33 : m_storageLocked(false)
37 this->
SetName(
"Tool Storage (no name given)");
43 m_props[US_PROPKEY_STORAGE_NAME] = m_Name;
53 if (m_ServiceRegistration) { m_ServiceRegistration.SetProperties(m_props); }
58 if (m_DataStorage.IsNotNull())
60 for (std::vector<mitk::NavigationTool::Pointer>::iterator it = m_ToolCollection.begin(); it != m_ToolCollection.end(); it++)
61 m_DataStorage->Remove((*it)->GetDataNode());
67 us::ModuleContext* context = us::GetModuleContext();
70 m_ServiceRegistration = context->RegisterService(
this, m_props);
76 if (!m_ServiceRegistration)
78 MITK_WARN(
"NavigationToolStorage")
79 <<
"Cannot unregister microservice as it wasn't registered before.";
83 m_ServiceRegistration.Unregister();
84 m_ServiceRegistration = 0;
91 MITK_WARN <<
"Storage is locked, cannot modify it!";
95 else if ((
unsigned int)number > m_ToolCollection.size())
97 MITK_WARN <<
"Tool no " << number <<
"doesn't exist, can't delete it!";
100 std::vector<mitk::NavigationTool::Pointer>::iterator it = m_ToolCollection.begin() + number;
101 if (m_DataStorage.IsNotNull())
102 m_DataStorage->Remove((*it)->GetDataNode());
103 m_ToolCollection.erase(it);
106 this->UpdateMicroservice();
114 MITK_WARN <<
"Storage is locked, cannot modify it!";
118 while (m_ToolCollection.size() > 0)
if (!DeleteTool(0))
return false;
126 MITK_WARN <<
"Storage is locked, cannot modify it!";
129 else if (GetTool(tool->GetIdentifier()).IsNotNull())
131 MITK_WARN <<
"Tool ID already exists in storage, can't add!";
136 m_ToolCollection.push_back(tool);
137 if (m_DataStorage.IsNotNull())
139 if (!m_DataStorage->Exists(tool->GetDataNode()))
140 m_DataStorage->Add(tool->GetDataNode());
143 this->UpdateMicroservice();
150 return m_ToolCollection.at(number);
155 for (
unsigned int i = 0; i < GetToolCount(); i++)
if ((GetTool(i)->GetIdentifier()) == identifier)
return GetTool(i);
161 for (
unsigned int i = 0; i < GetToolCount(); i++)
if ((GetTool(i)->GetToolName()) == name)
return GetTool(i);
167 return m_ToolCollection.size();
172 return m_ToolCollection.empty();
177 m_storageLocked =
true;
182 m_storageLocked =
false;
187 return m_storageLocked;
192 if (this->GetTool(identifier1).IsNull())
194 MITK_WARN <<
"Identifier does not exist, cannot assign new number";
198 if ((number2 >=
static_cast<int>(m_ToolCollection.size())) || (number2 < 0))
200 MITK_WARN <<
"Invalid number, cannot assign new number";
204 mitk::NavigationTool::Pointer tool2 = m_ToolCollection.at(number2);
208 for(
int i = 0; i<static_cast<int>(m_ToolCollection.size()); i++)
210 if (m_ToolCollection.at(i)->GetIdentifier() == identifier1) { number1 = i; }
213 m_ToolCollection[number2] = m_ToolCollection.at(number1);
215 m_ToolCollection[number1] = tool2;
217 MITK_DEBUG <<
"Swapped tool " << number2 <<
" with tool " << number1;
220 this->UpdateMicroservice();
228 m_props[US_PROPKEY_SOURCE_ID] = m_SourceID;