MCPcopy Create free account
hub / github.com/MITK/MITK / ActivateTool

Method ActivateTool

Modules/Segmentation/src/Controllers/mitkToolManager.cpp:166–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166bool mitk::ToolManager::ActivateTool(int id)
167{
168 const auto workingDataNode = this->GetWorkingData(0);
169 const mitk::BaseData* workingData = nullptr;
170 if (nullptr != workingDataNode)
171 {
172 workingData = workingDataNode->GetData();
173 }
174
175 const auto referenceDataNode = this->GetReferenceData(0);
176 const mitk::BaseData* referenceData = nullptr;
177 if (nullptr != referenceDataNode)
178 {
179 referenceData = referenceDataNode->GetData();
180 }
181
182 if (id != -1 && !this->GetToolById(id)->CanHandle(referenceData, workingData))
183 return false;
184
185 if (this->GetDataStorage())
186 {
187 this->GetDataStorage()->RemoveNodeEvent.AddListener(
188 mitk::MessageDelegate1<ToolManager, const mitk::DataNode *>(this, &ToolManager::OnNodeRemoved));
189 }
190
191 if (GetToolById(id) == m_ActiveTool)
192 return true; // no change needed
193
194 static int nextTool = -1;
195 nextTool = id;
196
197 static bool inActivateTool = false;
198 if (inActivateTool)
199 {
200 return true;
201 }
202 inActivateTool = true;
203
204 while (nextTool != m_ActiveToolID)
205 {
206 // Deactivate all other active tools to ensure a globally single active tool
207 for (const auto& toolManager : ToolManagerProvider::GetInstance()->GetToolManagers())
208 {
209 if (nullptr != toolManager.second->m_ActiveTool)
210 {
211 toolManager.second->m_ActiveTool->Deactivated();
212
213 try
214 {
215 toolManager.second->m_ActiveToolRegistration.Unregister();
216 }
217 catch (const std::logic_error&)
218 {
219 // In rare conditions it may happen that this code is called twice for the same tool leading to an attempt to
220 // unregister an already unregistered tool. We just want to make sure that the tool is unregistered, hence we
221 // can safely ignore the attempt/exception as the outcome is the same.
222
223 MITK_DEBUG << "Detected an attempt to unregister an already unregistered segmentation tool.";

Callers 15

SetWorkingDataMethod · 0.95
OnCreateCroppedMaskMethod · 0.80
OnCreateMaskMethod · 0.80
OnAcceptButtonClickedMethod · 0.80
toolButtonClickedMethod · 0.80
setEnabledMethod · 0.80
OnStampMethod · 0.80
ActivatedMethod · 0.80
ConfirmSegmentationMethod · 0.80

Calls 14

GetWorkingDataMethod · 0.95
GetReferenceDataMethod · 0.95
GetToolByIdMethod · 0.95
GetDataStorageMethod · 0.95
EnsureTimeObservationMethod · 0.95
GetModuleContextFunction · 0.85
GetToolManagersMethod · 0.80
GetDataMethod · 0.45
CanHandleMethod · 0.45
AddListenerMethod · 0.45
DeactivatedMethod · 0.45
UnregisterMethod · 0.45

Tested by 3

RunTestWithParametersMethod · 0.64
tearDownMethod · 0.64