1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHGUI_InteractiveOp.cxx
24 // Author : Roman NIKOLAEV, Open CASCADE S.A.S.
29 #include "SMESHGUI_InteractiveOp.h"
30 #include "SMESHGUI_VTKUtils.h"
33 #include <SVTK_ViewWindow.h>
34 #include <SVTK_RenderWindowInteractor.h>
35 #include <SVTK_Event.h>
38 #include <vtkInteractorStyle.h>
39 #include <vtkCallbackCommand.h>
40 #include <vtkGenericRenderWindowInteractor.h>
41 #include <vtkInteractorObserver.h>
44 //================================================================================
48 //================================================================================
50 SMESHGUI_InteractiveOp::SMESHGUI_InteractiveOp() :
51 SMESHGUI_SelectionOp(),
54 myStyleEventCallbackCommand(vtkCallbackCommand::New()),
55 myInteractorStypePriority(0.0),
56 myInteractorEventCallbackCommand(vtkCallbackCommand::New()),
57 myInteractorPriority(1.0)
59 myStyleEventCallbackCommand->Delete();
60 myStyleEventCallbackCommand->SetClientData(this);
61 myStyleEventCallbackCommand->SetCallback(SMESHGUI_InteractiveOp::ProcessStyleEvents);
63 myInteractorEventCallbackCommand->Delete();
64 myInteractorEventCallbackCommand->SetClientData(this);
65 myInteractorEventCallbackCommand->SetCallback(SMESHGUI_InteractiveOp::ProcessInteractorEvents);
68 //================================================================================
72 //================================================================================
73 SMESHGUI_InteractiveOp::~SMESHGUI_InteractiveOp()
77 //=======================================================================
78 // function : addObserver()
79 // purpose : Add VTK observers to process SVTK_InteractorStyle and vtkGenericRenderWindowInteractor events
80 //======================================================================
81 void SMESHGUI_InteractiveOp::addObserver()
83 if (myInteractorStyle && !myInteractorStyle->HasObserver(SVTK::InteractiveSelectionChanged, myStyleEventCallbackCommand.GetPointer())) {
84 myInteractorStyle->AddObserver(SVTK::InteractiveSelectionChanged, myStyleEventCallbackCommand.GetPointer(),
85 myInteractorStypePriority);
87 if (myRWInteractor && myRWInteractor->GetDevice() &&
88 !myRWInteractor->GetDevice()->HasObserver(vtkCommand::LeftButtonPressEvent, myInteractorEventCallbackCommand.GetPointer())) {
89 myRWInteractor->GetDevice()->AddObserver(vtkCommand::LeftButtonPressEvent, myInteractorEventCallbackCommand.GetPointer(),
90 myInteractorPriority);
94 //=======================================================================
95 // function : removeObserver()
96 // purpose : Remove VTK observers
97 //======================================================================
98 void SMESHGUI_InteractiveOp::removeObserver() {
99 if (myInteractorStyle && myInteractorStyle->HasObserver(SVTK::InteractiveSelectionChanged, myStyleEventCallbackCommand.GetPointer())) {
100 myInteractorStyle->RemoveObserver(myStyleEventCallbackCommand.GetPointer());
102 if (myRWInteractor && myRWInteractor->GetDevice() &&
103 myRWInteractor->GetDevice()->HasObserver(vtkCommand::LeftButtonPressEvent, myInteractorEventCallbackCommand.GetPointer())) {
104 myRWInteractor->GetDevice()->RemoveObserver(myInteractorEventCallbackCommand.GetPointer());
108 //=======================================================================
109 // function : startOperation()
110 // purpose : Init dialog fields, connect signals and slots, show dialog
111 //=======================================================================
113 void SMESHGUI_InteractiveOp::startOperation()
115 SVTK_ViewWindow* svtkViewWindow = SMESH::GetViewWindow(getSMESHGUI());
116 if (svtkViewWindow) {
117 myInteractorStyle = svtkViewWindow->GetInteractorStyle();
118 myRWInteractor = svtkViewWindow->GetInteractor();
122 //================================================================================
124 * \brief Process interactor style events
125 Static method. Used by vtkCallbackCommand->SetCallback method.
127 //===============================================================================
128 void SMESHGUI_InteractiveOp::ProcessStyleEvents(vtkObject* vtkNotUsed(theObject),
129 unsigned long theEvent,
132 SMESHGUI_InteractiveOp* self = reinterpret_cast<SMESHGUI_InteractiveOp*>(theClientData);
134 self->processStyleEvents(theEvent, theCallData);
137 //================================================================================
139 * \brief Process Generic Render Window Interactor events.
140 Static method. Used by vtkCallbackCommand->SetCallback method.
142 //===============================================================================
143 void SMESHGUI_InteractiveOp::ProcessInteractorEvents(vtkObject* vtkNotUsed(theObject),
144 unsigned long theEvent,
147 SMESHGUI_InteractiveOp* self = reinterpret_cast<SMESHGUI_InteractiveOp*>(theClientData);
149 self->processInteractorEvents(theEvent, theCallData);
152 //================================================================================
154 * \brief Process interactor style events ()
155 Virtual method. Should be overridden in inherited classes.
157 //===============================================================================
159 void SMESHGUI_InteractiveOp::processStyleEvents(unsigned long theEvent, void* theCallData) {
162 //================================================================================
164 * \brief Process Generic Render Window Interactor events.
165 Virtual method. Should be overridden in inherited classes.
167 //===============================================================================
168 void SMESHGUI_InteractiveOp::processInteractorEvents(unsigned long theEvent, void* theCallData)
172 //================================================================================
174 * \brief Deactivate current operation in active VTK viewer
176 //===============================================================================
177 void SMESHGUI_InteractiveOp::deactivateCurrentViewOperation() {
178 if (SVTK_ViewWindow* svtkViewWindow = SMESH::GetViewWindow(getSMESHGUI())) {
179 svtkViewWindow->deactivateCurrectOperation();