|
| 1 | +/*============================================================================== |
| 2 | +
|
| 3 | + Program: 3D Slicer |
| 4 | +
|
| 5 | + Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved. |
| 6 | +
|
| 7 | + See COPYRIGHT.txt |
| 8 | + or http://www.slicer.org/copyright/copyright.txt for details. |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +
|
| 16 | +==============================================================================*/ |
| 17 | + |
| 18 | +// GUIWidgets Logic includes |
| 19 | +#include "vtkSlicerGUIWidgetsLogic.h" |
| 20 | + |
| 21 | +// GUIWidgets MRML includes |
| 22 | +#include "vtkMRMLGUIWidgetNode.h" |
| 23 | +#include "vtkMRMLGUIWidgetDisplayNode.h" |
| 24 | + |
| 25 | +// MRML includes |
| 26 | +#include <vtkMRMLScene.h> |
| 27 | +#include <vtkMRMLSelectionNode.h> |
| 28 | + |
| 29 | +// Markups logic includes |
| 30 | +#include <vtkSlicerMarkupsLogic.h> |
| 31 | + |
| 32 | +// VTK includes |
| 33 | +#include <vtkIntArray.h> |
| 34 | +#include <vtkNew.h> |
| 35 | +#include <vtkObjectFactory.h> |
| 36 | + |
| 37 | +// STD includes |
| 38 | +#include <cassert> |
| 39 | + |
| 40 | +//---------------------------------------------------------------------------- |
| 41 | +vtkStandardNewMacro(vtkSlicerGUIWidgetsLogic); |
| 42 | + |
| 43 | +//---------------------------------------------------------------------------- |
| 44 | +vtkSlicerGUIWidgetsLogic::vtkSlicerGUIWidgetsLogic() |
| 45 | +{ |
| 46 | +} |
| 47 | + |
| 48 | +//---------------------------------------------------------------------------- |
| 49 | +vtkSlicerGUIWidgetsLogic::~vtkSlicerGUIWidgetsLogic() |
| 50 | +{ |
| 51 | +} |
| 52 | + |
| 53 | +//---------------------------------------------------------------------------- |
| 54 | +void vtkSlicerGUIWidgetsLogic::PrintSelf(ostream& os, vtkIndent indent) |
| 55 | +{ |
| 56 | + this->Superclass::PrintSelf(os, indent); |
| 57 | +} |
| 58 | + |
| 59 | +//--------------------------------------------------------------------------- |
| 60 | +void vtkSlicerGUIWidgetsLogic::SetMRMLSceneInternal(vtkMRMLScene * newScene) |
| 61 | +{ |
| 62 | + vtkNew<vtkIntArray> events; |
| 63 | + events->InsertNextValue(vtkMRMLScene::NodeAddedEvent); |
| 64 | + events->InsertNextValue(vtkMRMLScene::NodeRemovedEvent); |
| 65 | + events->InsertNextValue(vtkMRMLScene::EndBatchProcessEvent); |
| 66 | + this->SetAndObserveMRMLSceneEventsInternal(newScene, events.GetPointer()); |
| 67 | +} |
| 68 | + |
| 69 | +//--------------------------------------------------------------------------- |
| 70 | +void vtkSlicerGUIWidgetsLogic::ObserveMRMLScene() |
| 71 | +{ |
| 72 | + if (!this->GetMRMLScene()) |
| 73 | + { |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + vtkMRMLApplicationLogic* mrmlAppLogic = this->GetMRMLApplicationLogic(); |
| 78 | + if (!mrmlAppLogic) |
| 79 | + { |
| 80 | + vtkErrorMacro("ObserveMRMLScene: invalid MRML Application Logic"); |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + vtkMRMLNode* node = this->GetMRMLScene()->GetNodeByID(this->GetSelectionNodeID().c_str()); |
| 85 | + if (!node) |
| 86 | + { |
| 87 | + vtkErrorMacro("Observe MRMLScene: invalid Selection Node"); |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + // add known markup types to the selection node |
| 92 | + vtkMRMLSelectionNode* selectionNode = vtkMRMLSelectionNode::SafeDownCast(node); |
| 93 | + if (selectionNode) |
| 94 | + { |
| 95 | + // got into batch process mode so that an update on the mouse mode tool |
| 96 | + // bar is triggered when leave it |
| 97 | + this->GetMRMLScene()->StartState(vtkMRMLScene::BatchProcessState); |
| 98 | + |
| 99 | + auto guiWidgetNode = vtkSmartPointer<vtkMRMLGUIWidgetNode>::New(); |
| 100 | + selectionNode->AddNewPlaceNodeClassNameToList( |
| 101 | + guiWidgetNode->GetClassName(), guiWidgetNode->GetAddIcon(), guiWidgetNode->GetMarkupType()); |
| 102 | + |
| 103 | + // trigger an update on the mouse mode toolbar |
| 104 | + this->GetMRMLScene()->EndState(vtkMRMLScene::BatchProcessState); |
| 105 | + } |
| 106 | + |
| 107 | + this->Superclass::ObserveMRMLScene(); |
| 108 | +} |
| 109 | + |
| 110 | +//----------------------------------------------------------------------------- |
| 111 | +void vtkSlicerGUIWidgetsLogic::RegisterNodes() |
| 112 | +{ |
| 113 | + vtkMRMLScene* scene = this->GetMRMLScene(); |
| 114 | + if (!scene) |
| 115 | + { |
| 116 | + vtkErrorMacro("RegisterNodes: Invalid MRML scene"); |
| 117 | + return; |
| 118 | + } |
| 119 | + if (!scene->IsNodeClassRegistered("vtkMRMLGUIWidgetNode")) |
| 120 | + { |
| 121 | + scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLGUIWidgetNode>::New()); |
| 122 | + } |
| 123 | + if (!scene->IsNodeClassRegistered("vtkMRMLGUIWidgetDisplayNode")) |
| 124 | + { |
| 125 | + scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLGUIWidgetDisplayNode>::New()); |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +//--------------------------------------------------------------------------- |
| 130 | +void vtkSlicerGUIWidgetsLogic::UpdateFromMRMLScene() |
| 131 | +{ |
| 132 | + assert(this->GetMRMLScene() != 0); |
| 133 | +} |
| 134 | + |
| 135 | +//--------------------------------------------------------------------------- |
| 136 | +void vtkSlicerGUIWidgetsLogic::OnMRMLSceneNodeAdded(vtkMRMLNode* vtkNotUsed(node)) |
| 137 | +{ |
| 138 | +} |
| 139 | + |
| 140 | +//--------------------------------------------------------------------------- |
| 141 | +void vtkSlicerGUIWidgetsLogic::OnMRMLSceneNodeRemoved(vtkMRMLNode* vtkNotUsed(node)) |
| 142 | +{ |
| 143 | +} |
0 commit comments