From: apo Date: Mon, 12 Sep 2005 04:28:14 +0000 (+0000) Subject: To introduce segmentation functionality X-Git-Tag: BR-D5-38-2003_D2005-12-09~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9f39e7f7da7e12bd8a535c5dd6d4bffd6e7b3d8f;p=modules%2Fgui.git To introduce segmentation functionality --- diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index d81a1e22a..9e81cb01d 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -25,6 +25,7 @@ EXPORT_HEADERS= SVTK.h \ SVTK_Renderer.h \ SVTK_InteractorStyle.h \ SVTK_RenderWindowInteractor.h \ + SVTK_GenericRenderWindowInteractor.h \ SVTK_Selector.h \ SVTK_Selection.h \ SVTK_SelectionEvent.h \ @@ -47,25 +48,29 @@ LIB_SRC= SVTK_Prs.cxx \ SVTK_ViewWindow.cxx \ SVTK_InteractorStyle.cxx \ SVTK_RenderWindowInteractor.cxx \ + SVTK_GenericRenderWindowInteractor.cxx \ SVTK_SpaceMouse.cxx \ SVTK_Selector.cxx -LIB_MOC = SVTK_RenderWindowInteractor.h \ - SVTK_InteractorStyle.h \ - SVTK_View.h \ +LIB_MOC = SVTK_GenericRenderWindowInteractor.h \ + SVTK_RenderWindowInteractor.h \ + SVTK_ViewModelBase.h \ + SVTK_ViewManager.h \ SVTK_ViewWindow.h \ SVTK_ViewModel.h \ - SVTK_ViewManager.h \ - SVTK_ViewModelBase.h + SVTK_View.h LIB_CLIENT_IDL = SALOMEDS.idl \ + SALOMEDS_Attributes.idl \ SALOME_Exception.idl \ SALOME_ModuleCatalog.idl \ SALOME_GenericObj.idl +BIN = SVTK + CPPFLAGS+=$(QT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(BOOST_CPPFLAGS) -I$(KERNEL_ROOT_DIR)/include/salome LDFLAGS+=$(QT_MT_LIBS) $(OCC_LIBS) $(VTK_LIBS) -L$(KERNEL_ROOT_DIR)/lib/salome -LIBS+= -lsuit -lCAM -lSalomeObject -lSalomePrs -lVTKViewer -lOpUtil +LIBS+= -lsuit -lCAM -lSalomeObject -lSalomePrs -lVTKViewer -lOpUtil -lToolsGUI -lSalomeDS @CONCLUDE@ diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index c8ae5aba6..2e0257d44 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -208,6 +208,16 @@ SALOME_Actor theRenderer->RemoveActor( myOutlineActor ); } +void +SALOME_Actor +::AddToInteractor(vtkRenderWindowInteractor* theInteractor) +{} + +void +SALOME_Actor +::RemoveFromInteractor(vtkRenderWindowInteractor* theInteractor) +{} + //---------------------------------------------------------------------------- void diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index 06896be1b..ed7d6d1d2 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -52,6 +52,8 @@ class vtkPolyDataMapper; class vtkOutlineSource; class vtkRenderer; class vtkInteractorStyle; +class vtkRenderWindowInteractor; + class VTKViewer_Transform; class VTKViewer_GeometryFilter; class VTKViewer_TransformFilter; @@ -320,6 +322,7 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor void SetVisibility( int ); + //---------------------------------------------------------------------------- virtual void AddToRender( vtkRenderer* ); @@ -328,7 +331,15 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor void RemoveFromRender( vtkRenderer* ); - + virtual + void + AddToInteractor(vtkRenderWindowInteractor* theInteractor); + + virtual + void + RemoveFromInteractor(vtkRenderWindowInteractor* theInteractor); + + //---------------------------------------------------------------------------- virtual bool PreHighlight( SVTK_Selector*, diff --git a/src/SVTK/SVTK.cxx b/src/SVTK/SVTK.cxx new file mode 100644 index 000000000..df2b3e9cf --- /dev/null +++ b/src/SVTK/SVTK.cxx @@ -0,0 +1,33 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +int +main(int argc, char** argv) +{ + return 0; +} diff --git a/src/SVTK/SVTK_Actor.cxx b/src/SVTK/SVTK_Actor.cxx index 1ec5fa4b1..16faf1791 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -31,7 +31,7 @@ #include #include -//#include "utilities.h" +#include "utilities.h" using namespace std; @@ -59,6 +59,8 @@ vtkStandardNewMacro(SVTK_Actor); SVTK_Actor::SVTK_Actor() { + if(MYDEBUG) INFOS("SVTK_Actor - "<RemoveAllInputs(); myMapper->Delete(); diff --git a/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx b/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx new file mode 100644 index 000000000..0114c0c6b --- /dev/null +++ b/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx @@ -0,0 +1,150 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SVTK_GenericRenderWindowInteractor.h" +#include "SVTK_Selector.h" + +#include "utilities.h" + +#include +#include + +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(QVTK_GenericRenderWindowInteractor); + +QVTK_GenericRenderWindowInteractor +::QVTK_GenericRenderWindowInteractor() +{ + if(MYDEBUG) INFOS("QVTK_GenericRenderWindowInteractor() - "<InvokeEvent(vtkCommand::TimerEvent,NULL); + } +} + +int +QVTK_GenericRenderWindowInteractor +::CreateTimer(int vtkNotUsed(timertype)) +{ + // + // Start a one-shot timer for ms. + // + static int DELAY = 1; + myTimer->start(DELAY,TRUE); + return 1; +} + +int +QVTK_GenericRenderWindowInteractor +::DestroyTimer(void) +{ + // + // :TRICKY: Tue May 2 00:17:32 2000 Pagey + // + // QTimer will automatically expire after 10ms. So + // we do not need to do anything here. In fact, we + // should not even Stop() the QTimer here because doing + // this will skip some of the processing that the TimerFunc() + // does and will result in undesirable effects. For + // example, this will result in vtkLODActor to leave + // the models in low-res mode after the mouse stops + // moving. + // + return 1; +} + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_GenericRenderWindowInteractor); + +SVTK_GenericRenderWindowInteractor +::SVTK_GenericRenderWindowInteractor(): + myRenderWidget(NULL) +{ + if(MYDEBUG) INFOS("SVTK_GenericRenderWindowInteractor() - "< +#include +#include + +class QTimer; +class QWidget; + +class SVTK_Selector; +class SVTK_Renderer; + +// ------------------------------------------------------------ +// :TRICKY: Fri Apr 21 22:19:27 2000 Pagey +// The Signal/Slot mechanism used by Qt requires that QObject +// appear as the first class when using multiple inheritance. +// Hence the order of the two classes QObject and vtkRenderWindowInteractor +// matters here. Be careful not to change it by accident. +// ------------------------------------------------------------ +class SVTK_EXPORT QVTK_GenericRenderWindowInteractor: + public QObject, + public vtkGenericRenderWindowInteractor +{ + Q_OBJECT; + + public: + static QVTK_GenericRenderWindowInteractor* New(); + vtkTypeMacro(QVTK_GenericRenderWindowInteractor,vtkGenericRenderWindowInteractor); + + virtual + int + CreateTimer( int ) ; + + virtual + int + DestroyTimer() ; + + protected slots: + void + OnTimeOut(); + + protected: + QVTK_GenericRenderWindowInteractor(); + ~QVTK_GenericRenderWindowInteractor(); + + QTimer* myTimer ; +}; + + +// ------------------------------------------------------------ +class SVTK_EXPORT SVTK_GenericRenderWindowInteractor: public QVTK_GenericRenderWindowInteractor +{ + public: + static SVTK_GenericRenderWindowInteractor* New(); + vtkTypeMacro(SVTK_GenericRenderWindowInteractor,QVTK_GenericRenderWindowInteractor); + + SVTK_Selector* + GetSelector(); + + void + SetSelector(SVTK_Selector* theSelector); + + QWidget* + GetRenderWidget(); + + void + SetRenderWidget(QWidget* theRenderWidget); + + protected: + SVTK_GenericRenderWindowInteractor(); + ~SVTK_GenericRenderWindowInteractor(); + + vtkSmartPointer mySelector; + QWidget* myRenderWidget; +}; + +#endif diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 4fe4eb51e..c9b2a9a7e 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -21,8 +21,8 @@ // // // -// File : SVTK_InteractorStyle.cxx -// Author : Christophe ATTANASIO +// File : +// Author : // Module : SALOME // $Header$ @@ -31,6 +31,7 @@ #include "VTKViewer_Utilities.h" #include "VTKViewer_RectPicker.h" +#include "SVTK_GenericRenderWindowInteractor.h" #include "SVTK_Selection.h" #include "SVTK_Event.h" @@ -74,25 +75,21 @@ using namespace std; #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; #else static int MYDEBUG = 0; #endif namespace { - bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){ - switch(theMode){ - case CellSelection: - return true; - case EdgeSelection: - return ( theActor->GetObjDimension( theObjId ) == 1 ); - case FaceSelection: - return ( theActor->GetObjDimension( theObjId ) == 2 ); - case VolumeSelection: - return ( theActor->GetObjDimension( theObjId ) == 3 ); - }; - return false; + inline + void + GetEventPosition(vtkRenderWindowInteractor* theInteractor, + int& theX, + int& theY) + { + theInteractor->GetEventPosition(theX,theY); + theY = theInteractor->GetSize()[1] - theY - 1; } } @@ -103,6 +100,8 @@ vtkStandardNewMacro(SVTK_InteractorStyle); SVTK_InteractorStyle ::SVTK_InteractorStyle() { + if(MYDEBUG) INFOS("SVTK_InteractorStyle() - "<MotionFactor = 10.0; this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE; this->RadianToDegree = 180.0 / vtkMath::Pi(); @@ -131,15 +130,22 @@ SVTK_InteractorStyle SVTK_InteractorStyle ::~SVTK_InteractorStyle() { - if(MYDEBUG) INFOS("SVTK_InteractorStyle::~SVTK_InteractorStyle()"); + if(MYDEBUG) INFOS("~SVTK_InteractorStyle() - "<GetRenderWidget(); +} + SVTK_Selector* SVTK_InteractorStyle ::GetSelector() { - return mySelector.GetPointer(); + return myInteractor->GetSelector(); } //---------------------------------------------------------------------------- @@ -157,12 +163,11 @@ SVTK_InteractorStyle { SVTK_SelectionEvent aSelectionEvent; - int x, y, w, h; - Interactor->GetEventPosition( x, y ); - Interactor->GetSize( w, h ); + int x, y; + GetEventPosition( this->Interactor, x, y ); aSelectionEvent.myX = x; - aSelectionEvent.myY = h - y - 1; + aSelectionEvent.myY = y; aSelectionEvent.myIsCtrl = Interactor->GetControlKey(); aSelectionEvent.myIsShift = Interactor->GetShiftKey(); aSelectionEvent.mySelectionMode = GetSelector()->SelectionMode(); @@ -170,22 +175,6 @@ SVTK_InteractorStyle return aSelectionEvent; } -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::SetSelector( SVTK_Selector* theSelector ) -{ - mySelector = theSelector; -} - -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::SetRenderWidget(QWidget* theWidget) -{ - myRenderWidget = theWidget; -} - //---------------------------------------------------------------------------- void SVTK_InteractorStyle @@ -287,7 +276,7 @@ SVTK_InteractorStyle ::OnMouseMove() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnMouseMove( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -300,7 +289,7 @@ SVTK_InteractorStyle ::OnLeftButtonDown() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnLeftButtonDown( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -313,7 +302,7 @@ SVTK_InteractorStyle ::OnLeftButtonUp() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnLeftButtonUp( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -326,7 +315,7 @@ SVTK_InteractorStyle ::OnMiddleButtonDown() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnMiddleButtonDown( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -339,7 +328,7 @@ SVTK_InteractorStyle ::OnMiddleButtonUp() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnMiddleButtonUp( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -352,7 +341,7 @@ SVTK_InteractorStyle ::OnRightButtonDown() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnRightButtonDown( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -364,7 +353,7 @@ SVTK_InteractorStyle ::OnRightButtonUp() { int x, y; - this->Interactor->GetEventPosition( x, y ); + GetEventPosition( this->Interactor, x, y ); this->OnRightButtonUp( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); @@ -622,35 +611,17 @@ void SVTK_InteractorStyle ::loadCursors() { - myDefCursor = QCursor(ArrowCursor); - myHandCursor = QCursor(PointingHandCursor); - myPanCursor = QCursor(SizeAllCursor); + myDefCursor = QCursor(Qt::ArrowCursor); + myHandCursor = QCursor(Qt::PointingHandCursor); + myPanCursor = QCursor(Qt::SizeAllCursor); myZoomCursor = QCursor(QPixmap(imageZoomCursor)); myRotateCursor = QCursor(QPixmap(imageRotateCursor)); mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!! - myGlobalPanCursor = QCursor(CrossCursor); + myGlobalPanCursor = QCursor(Qt::CrossCursor); myCursorState = false; } -//---------------------------------------------------------------------------- -// event filter - controls mouse and keyboard events during viewer operations -bool -SVTK_InteractorStyle -::eventFilter(QObject* object, QEvent* event) -{ - if (!myRenderWidget) return false; - if ( (event->type() == QEvent::MouseButtonPress || - event->type() == QEvent::KeyPress) && - object != myRenderWidget) - { - qApp->removeEventFilter(this); - startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); - } - return QObject::eventFilter(object, event); -} - - //---------------------------------------------------------------------------- // starts Zoom operation (e.g. through menu command) void @@ -664,7 +635,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM; - qApp->installEventFilter(this); } @@ -681,7 +651,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN; - qApp->installEventFilter(this); } //---------------------------------------------------------------------------- @@ -697,7 +666,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE; - qApp->installEventFilter(this); } @@ -714,7 +682,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN; - qApp->installEventFilter(this); } @@ -732,7 +699,6 @@ SVTK_InteractorStyle } setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT); ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT; - qApp->installEventFilter(this); } @@ -751,14 +717,11 @@ SVTK_InteractorStyle ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN; // store current zoom scale - vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera(); - myScale = cam->GetParallelScale(); + myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale(); GetCurrentRenderer()->ResetCamera(); this->Render(); - - qApp->installEventFilter(this); } @@ -836,37 +799,37 @@ void SVTK_InteractorStyle ::setCursor(const int operation) { - if (!myRenderWidget) return; + if (!GetRenderWidget()) return; switch (operation) { case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: - myRenderWidget->setCursor(myZoomCursor); + GetRenderWidget()->setCursor(myZoomCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_PAN: - myRenderWidget->setCursor(myPanCursor); + GetRenderWidget()->setCursor(myPanCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: - myRenderWidget->setCursor(myRotateCursor); + GetRenderWidget()->setCursor(myRotateCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_SPIN: - myRenderWidget->setCursor(mySpinCursor); + GetRenderWidget()->setCursor(mySpinCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: - myRenderWidget->setCursor(myGlobalPanCursor); + GetRenderWidget()->setCursor(myGlobalPanCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_FIT: case VTK_INTERACTOR_STYLE_CAMERA_SELECT: - myRenderWidget->setCursor(myHandCursor); + GetRenderWidget()->setCursor(myHandCursor); myCursorState = true; break; case VTK_INTERACTOR_STYLE_CAMERA_NONE: default: - myRenderWidget->setCursor(myDefCursor); + GetRenderWidget()->setCursor(myDefCursor); myCursorState = false; break; } @@ -879,14 +842,14 @@ void SVTK_InteractorStyle ::onStartOperation() { - if (!myRenderWidget) return; + if (!GetRenderWidget()) return; // VSV: LOD actor activisation // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate()); switch (State) { case VTK_INTERACTOR_STYLE_CAMERA_SELECT: case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myRenderWidget); + QPainter p(GetRenderWidget()); p.setPen(Qt::lightGray); p.setRasterOp(Qt::XorROP); p.drawRect(QRect(myPoint, myOtherPoint)); @@ -908,7 +871,7 @@ void SVTK_InteractorStyle ::onFinishOperation() { - if (!myRenderWidget) + if (!GetRenderWidget()) return; // VSV: LOD actor activisation @@ -920,7 +883,7 @@ SVTK_InteractorStyle case VTK_INTERACTOR_STYLE_CAMERA_SELECT: case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myRenderWidget); + QPainter p(GetRenderWidget()); p.setPen(Qt::lightGray); p.setRasterOp(Qt::XorROP); QRect rect(myPoint, myOtherPoint); @@ -1032,7 +995,7 @@ void SVTK_InteractorStyle ::onOperation(QPoint mousePos) { - if (!myRenderWidget) + if (!GetRenderWidget()) return; switch (State) { @@ -1071,7 +1034,7 @@ SVTK_InteractorStyle } case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myRenderWidget); + QPainter p(GetRenderWidget()); p.setPen(Qt::lightGray); p.setRasterOp(Qt::XorROP); p.drawRect(QRect(myPoint, myOtherPoint)); @@ -1203,40 +1166,42 @@ SVTK_InteractorStyle //---------------------------------------------------------------------------- void SVTK_InteractorStyle -::SetInteractor( vtkRenderWindowInteractor* interactor ) +::SetInteractor( vtkRenderWindowInteractor* theInteractor ) { // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc) - vtkInteractorStyle::SetInteractor( interactor ); + vtkInteractorStyle::SetInteractor( theInteractor ); - if ( interactor ) { + myInteractor = dynamic_cast(theInteractor); + + if ( myInteractor.GetPointer() ) { // register EventCallbackCommand as observer of custorm event (3d space mouse event) - interactor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority ); - - interactor->AddObserver( SVTK::SetSpaceMouseF1Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::SetSpaceMouseF2Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::SetSpaceMouseF3Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::SetSpaceMouseF4Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::SetSpaceMouseF5Event, EventCallbackCommand, Priority ); - - interactor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority ); - interactor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority ); + + theInteractor->AddObserver( SVTK::SetSpaceMouseF1Event, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSpaceMouseF2Event, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSpaceMouseF3Event, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSpaceMouseF4Event, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::SetSpaceMouseF5Event, EventCallbackCommand, Priority ); + + theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority ); + theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority ); } } @@ -1268,7 +1233,7 @@ SVTK_InteractorStyle // general things, do SetCurrentRenderer() within FindPokedRenderer() int x, y; - Interactor->GetEventPosition( x, y ); // current mouse position (from last mouse move event or any other event) + GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event) FindPokedRenderer( x, y ); // calls SetCurrentRenderer IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 26a54d47c..a1e5158f9 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -31,27 +31,22 @@ #include "SVTK.h" +#include "SVTK_SelectionEvent.h" + #include #include -class vtkCell; -class vtkRenderWindowInteractor; - -#include #include #include #include -#include "SVTK_SelectionEvent.h" - +class vtkCell; class vtkPicker; class VTKViewer_RectPicker; -class SALOME_Actor; -class SVTK_Viewer; class SVTK_Selector; -class SVTK_ViewWindow; +class SVTK_GenericRenderWindowInteractor; #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1 @@ -62,12 +57,8 @@ class SVTK_ViewWindow; #define VTK_INTERACTOR_STYLE_CAMERA_SELECT 6 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7 -class SVTK_EXPORT SVTK_InteractorStyle : - public QObject, - public vtkInteractorStyle +class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle { - Q_OBJECT; - public: // Description: // This class must be supplied with a vtkRenderWindowInteractor wrapper or @@ -76,11 +67,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : static SVTK_InteractorStyle *New(); vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle); - void SetSelector( SVTK_Selector* theSelector ); - SVTK_Selector* GetSelector(); - - void SetRenderWidget(QWidget* theRenderWidget); - virtual int GetState(); SVTK_SelectionEvent GetSelectionEvent(); @@ -103,20 +89,15 @@ class SVTK_EXPORT SVTK_InteractorStyle : virtual void OnRightButtonDown(); virtual void OnRightButtonUp(); - void - IncrementalPan( const int incrX, const int incrY ); - - void - IncrementalZoom( const int incr ); - - void - IncrementalRotate( const int incrX, const int incrY ); - protected: SVTK_InteractorStyle(); ~SVTK_InteractorStyle(); - SVTK_InteractorStyle(const SVTK_InteractorStyle&) {}; - void operator=(const SVTK_InteractorStyle&) {}; + + QWidget* + GetRenderWidget(); + + SVTK_Selector* + GetSelector(); // Generic event bindings must be overridden in subclasses virtual void OnMouseMove (int ctrl, int shift, int x, int y); @@ -135,6 +116,15 @@ class SVTK_EXPORT SVTK_InteractorStyle : void Place(const int theX, const int theY); void TranslateView(int toX, int toY, int fromX, int fromY); + void + IncrementalPan( const int incrX, const int incrY ); + + void + IncrementalZoom( const int incr ); + + void + IncrementalRotate( const int incrX, const int incrY ); + // custom event handling function (to handle 3d space mouse events) static void ProcessEvents( vtkObject* object, unsigned long event, void* clientData, void* callData ); @@ -144,7 +134,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : double myScale; public: - bool eventFilter(QObject* object, QEvent* event); void startZoom(); void startPan(); void startGlobalPan(); @@ -192,6 +181,7 @@ class SVTK_EXPORT SVTK_InteractorStyle : QWidget* myRenderWidget; vtkSmartPointer mySelector; + vtkSmartPointer myInteractor; vtkSmartPointer myPicker; vtkSmartPointer myRectPicker; diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 1c6df4d46..709505d89 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -27,6 +27,7 @@ // $Header$ #include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" #include "SVTK_Renderer.h" @@ -63,80 +64,21 @@ using namespace std; #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; #else static int MYDEBUG = 0; #endif //#define GENERATE_SUIT_EVENTS -//---------------------------------------------------------------------------- -vtkStandardNewMacro(QtRenderWindowInteractor); - -QtRenderWindowInteractor -::QtRenderWindowInteractor() -{ - myTimer = new QTimer( ) ; - connect(myTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())) ; -} - -QtRenderWindowInteractor -::~QtRenderWindowInteractor() -{ - delete myTimer; -} - - -//---------------------------------------------------------------------------- -void -QtRenderWindowInteractor -::OnTimeOut() -{ - if( GetEnabled() ) { - this->InvokeEvent(vtkCommand::TimerEvent,NULL); - } -} - -int -QtRenderWindowInteractor -::CreateTimer(int vtkNotUsed(timertype)) -{ - // - // Start a one-shot timer for 10ms. - // - myTimer->start(1,TRUE); - return 1; -} - -int -QtRenderWindowInteractor -::DestroyTimer(void) -{ - // - // :TRICKY: Tue May 2 00:17:32 2000 Pagey - // - // QTimer will automatically expire after 10ms. So - // we do not need to do anything here. In fact, we - // should not even Stop() the QTimer here because doing - // this will skip some of the processing that the TimerFunc() - // does and will result in undesirable effects. For - // example, this will result in vtkLODActor to leave - // the models in low-res mode after the mouse stops - // moving. - // - return 1; -} - //---------------------------------------------------------------------------- QVTK_RenderWindowInteractor ::QVTK_RenderWindowInteractor(QWidget* theParent, const char* theName): - QWidget(theParent,theName), - myInteractor(QtRenderWindowInteractor::New()) + QWidget(theParent,theName) { - myInteractor->Delete(); - + if(MYDEBUG) INFOS("QVTK_RenderWindowInteractor() - "<isSpaceMouseOn()) aSpaceMouse->close(x11Display()); } //---------------------------------------------------------------------------- -vtkRenderWindowInteractor* +vtkGenericRenderWindowInteractor* QVTK_RenderWindowInteractor ::GetDevice() { - return myInteractor.GetPointer(); + return myDevice.GetPointer(); +} + +void +QVTK_RenderWindowInteractor +::SetDevice(vtkGenericRenderWindowInteractor* theDevice) +{ + myDevice = theDevice; } //---------------------------------------------------------------------------- @@ -162,7 +113,7 @@ void QVTK_RenderWindowInteractor ::SetRenderWindow(vtkRenderWindow *theRenderWindow) { - myInteractor->SetRenderWindow(theRenderWindow); + GetDevice()->SetRenderWindow(theRenderWindow); theRenderWindow->DoubleBufferOn(); } @@ -170,7 +121,7 @@ vtkRenderWindow* QVTK_RenderWindowInteractor ::GetRenderWindow() { - return myInteractor->GetRenderWindow(); + return GetDevice()->GetRenderWindow(); } //---------------------------------------------------------------------------- @@ -178,7 +129,7 @@ void QVTK_RenderWindowInteractor ::InvokeEvent(unsigned long theEvent, void* theCallData) { - myInteractor->InvokeEvent(theEvent,theCallData); + GetDevice()->InvokeEvent(theEvent,theCallData); } //---------------------------------------------------------------------------- @@ -195,13 +146,13 @@ void QVTK_RenderWindowInteractor ::polish() { - // Final initialization just before the widget is displayed. - myInteractor->SetSize(width(),height()); + // Final initialization just before the widget is displayed + GetDevice()->SetSize(width(),height()); #ifndef WNT GetRenderWindow()->SetDisplayId((void*)x11Display()); #endif GetRenderWindow()->SetWindowId((void*)winId()); - myInteractor->Enable(); + GetDevice()->Enable(); } //---------------------------------------------------------------------------- @@ -209,7 +160,7 @@ void QVTK_RenderWindowInteractor ::resize(int w, int h) { - myInteractor->UpdateSize(w,h); + GetDevice()->UpdateSize(w,h); } //---------------------------------------------------------------------------- @@ -217,12 +168,12 @@ void QVTK_RenderWindowInteractor ::paintEvent( QPaintEvent* theEvent ) { - if(myInteractor->GetEnabled()){ - if(!myInteractor->GetInitialized()){ - myInteractor->Initialize(); - myInteractor->ConfigureEvent(); + if(GetDevice()->GetEnabled()){ + if(!GetDevice()->GetInitialized()){ + GetDevice()->Initialize(); + GetDevice()->ConfigureEvent(); } - myInteractor->Render(); + GetDevice()->Render(); } } @@ -236,9 +187,9 @@ QVTK_RenderWindowInteractor int aWidth = aSize[0]; int aHeight = aSize[1]; - myInteractor->UpdateSize(width(),height()); + GetDevice()->UpdateSize(width(),height()); - if(aWidth && aHeight){ + if(isVisible() && aWidth && aHeight){ if( aWidth != width() || aHeight != height() ) { vtkRendererCollection * aRenderers = GetRenderWindow()->GetRenderers(); aRenderers->InitTraversal(); @@ -271,10 +222,11 @@ void QVTK_RenderWindowInteractor ::mouseMoveEvent( QMouseEvent* event ) { - myInteractor->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - myInteractor->MouseMoveEvent(); + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); + GetDevice()->MouseMoveEvent(); } @@ -283,15 +235,16 @@ void QVTK_RenderWindowInteractor ::mousePressEvent( QMouseEvent* event ) { - myInteractor->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); if( event->button() & LeftButton ) - myInteractor->LeftButtonPressEvent(); + GetDevice()->LeftButtonPressEvent(); else if( event->button() & MidButton ) - myInteractor->MiddleButtonPressEvent(); + GetDevice()->MiddleButtonPressEvent(); else if( event->button() & RightButton ) - myInteractor->RightButtonPressEvent(); + GetDevice()->RightButtonPressEvent(); } @@ -300,16 +253,17 @@ void QVTK_RenderWindowInteractor ::mouseReleaseEvent( QMouseEvent *event ) { - myInteractor->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); + GetDevice()->SetEventInformationFlipY(event->x(), + event->y(), + event->state() & ControlButton, + event->state() & ShiftButton); if( event->button() & LeftButton ) - myInteractor->LeftButtonReleaseEvent(); + GetDevice()->LeftButtonReleaseEvent(); else if( event->button() & MidButton ) - myInteractor->MiddleButtonReleaseEvent(); + GetDevice()->MiddleButtonReleaseEvent(); else if( event->button() & RightButton ) - myInteractor->RightButtonReleaseEvent(); + GetDevice()->RightButtonReleaseEvent(); } @@ -332,10 +286,11 @@ void QVTK_RenderWindowInteractor ::keyPressEvent( QKeyEvent* event ) { - myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ), - ( event->state() & ShiftButton ), - event->key() ); - myInteractor->KeyPressEvent(); + GetDevice()->SetKeyEventInformation(event->state() & ControlButton, + event->state() & ShiftButton, + event->key()); + GetDevice()->KeyPressEvent(); + GetDevice()->CharEvent(); } //---------------------------------------------------------------------------- @@ -343,10 +298,10 @@ void QVTK_RenderWindowInteractor ::keyReleaseEvent( QKeyEvent * event ) { - myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ), - ( event->state() & ShiftButton ), - event->key() ); - myInteractor->KeyReleaseEvent(); + GetDevice()->SetKeyEventInformation(event->state() & ControlButton, + event->state() & ShiftButton, + event->key()); + GetDevice()->KeyReleaseEvent(); } @@ -366,7 +321,7 @@ QVTK_RenderWindowInteractor } } - myInteractor->EnterEvent(); + GetDevice()->EnterEvent(); } //---------------------------------------------------------------------------- @@ -382,7 +337,7 @@ QVTK_RenderWindowInteractor aSpaceMouse->setWindow(x11Display(),0); } - myInteractor->LeaveEvent(); + GetDevice()->LeaveEvent(); } @@ -398,10 +353,10 @@ QVTK_RenderWindowInteractor int type = aSpaceMouse->translateEvent( x11Display(), xEvent, &anEvent, 1.0, 1.0 ); switch( type ){ case SVTK_SpaceMouse::SpaceMouseMove : - myInteractor->InvokeEvent(SVTK::SpaceMouseMoveEvent, anEvent.data ); + GetDevice()->InvokeEvent(SVTK::SpaceMouseMoveEvent, anEvent.data ); break; case SVTK_SpaceMouse::SpaceButtonPress : - myInteractor->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button ); + GetDevice()->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button ); break; case SVTK_SpaceMouse::SpaceButtonRelease : break; @@ -422,6 +377,8 @@ SVTK_RenderWindowInteractor myEventCallbackCommand(vtkCallbackCommand::New()), myRenderWindow(vtkRenderWindow::New()) { + if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor() - "<Delete(); myEventCallbackCommand->SetClientData(this); @@ -429,16 +386,26 @@ SVTK_RenderWindowInteractor myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); - myRenderWindow->Delete(); - GetDevice()->SetRenderWindow(getRenderWindow()); + SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New(); + SetDevice(aDevice); + aDevice->Delete(); + + aDevice->SetRenderWidget(this); SetSelector(SVTK_Selector::New()); mySelector->Delete(); + + aDevice->SetSelector(GetSelector()); + + GetDevice()->SetRenderWindow(getRenderWindow()); + myRenderWindow->Delete(); } SVTK_RenderWindowInteractor ::~SVTK_RenderWindowInteractor() -{} +{ + if(MYDEBUG) INFOS("~SVTK_RenderWindowInteractor() - "<GetDevice(); } void SVTK_RenderWindowInteractor ::SetRenderer(SVTK_Renderer* theRenderer) { - myRenderWindow->RemoveRenderer(GetRenderer()); + if(theRenderer == myRenderer.GetPointer()) + return; + + if(GetRenderer()){ + myRenderWindow->RemoveRenderer(getRenderer()); + theRenderer->SetInteractor(NULL); + } + myRenderer = theRenderer; - myRenderWindow->AddRenderer(GetRenderer()); + + if(GetRenderer()){ + myRenderWindow->AddRenderer(getRenderer()); + theRenderer->SetInteractor(GetDevice()); + } } //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::InitInteractorStyle(SVTK_InteractorStyle* theStyle) +::InitInteractorStyle(vtkInteractorStyle* theStyle) { GetDevice()->SetInteractorStyle(theStyle); - - theStyle->SetSelector(GetSelector()); - theStyle->SetRenderWidget(this); } //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::PushInteractorStyle(SVTK_InteractorStyle* theStyle) +::PushInteractorStyle(vtkInteractorStyle* theStyle) { myInteractorStyles.push(PInteractorStyle(theStyle)); InitInteractorStyle(theStyle); @@ -509,7 +484,7 @@ SVTK_RenderWindowInteractor //---------------------------------------------------------------------------- -SVTK_InteractorStyle* +vtkInteractorStyle* SVTK_RenderWindowInteractor ::GetInteractorStyle() { diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 6ac251674..146be1081 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -21,8 +21,8 @@ // // // -// File : SVTK_RenderWindowInteractor.h -// Author : Nicolas REJNERI +// File : +// Author : // Module : SALOME // $Header$ @@ -32,62 +32,20 @@ #include "SVTK.h" #include "SVTK_Selection.h" -#include "SALOME_InteractiveObject.hxx" - -#include -#include - -#include #include +#include -class QTimer; +#include -class vtkCallbackCommand; -class vtkActorCollection; class vtkGenericRenderWindowInteractor; +class vtkInteractorStyle; +class vtkCallbackCommand; +class vtkRenderWindow; +class vtkRenderer; +class vtkObject; -class SALOME_Actor; class SVTK_Selector; class SVTK_Renderer; -class SVTK_InteractorStyle; - -// ------------------------------------------------------------ -// :TRICKY: Fri Apr 21 22:19:27 2000 Pagey -// The Signal/Slot mechanism used by Qt requires that QObject -// appear as the first class when using multiple inheritance. -// Hence the order of the two classes QObject and vtkRenderWindowInteractor -// matters here. Be careful not to change it by accident. -// ------------------------------------------------------------ -class SVTK_EXPORT QtRenderWindowInteractor: - public QObject, - public vtkGenericRenderWindowInteractor -{ - Q_OBJECT; - - public: - static QtRenderWindowInteractor* New(); - vtkTypeMacro(QtRenderWindowInteractor,vtkGenericRenderWindowInteractor); - - virtual - int - CreateTimer( int ) ; - - virtual - int - DestroyTimer() ; - - protected slots: - virtual - void - OnTimeOut(); - - protected: - QtRenderWindowInteractor(); - ~QtRenderWindowInteractor(); - - QTimer* myTimer ; -}; - // ------------------------------------------------------------ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget @@ -100,9 +58,12 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget ~QVTK_RenderWindowInteractor(); - vtkRenderWindowInteractor* + vtkGenericRenderWindowInteractor* GetDevice(); + void + SetDevice(vtkGenericRenderWindowInteractor* theDevice); + void SetRenderWindow(vtkRenderWindow *theRenderWindow); @@ -138,7 +99,7 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget virtual bool x11Event( XEvent *e ); - vtkSmartPointer myInteractor; + vtkSmartPointer myDevice; }; @@ -167,11 +128,11 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto getRenderer(); //---------------------------------------------------------------------------- - SVTK_InteractorStyle* + vtkInteractorStyle* GetInteractorStyle(); void - PushInteractorStyle(SVTK_InteractorStyle* theStyle); + PushInteractorStyle(vtkInteractorStyle* theStyle); void PopInteractorStyle(); @@ -219,7 +180,7 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto virtual void contextMenuEvent( QContextMenuEvent * e ); void - InitInteractorStyle(SVTK_InteractorStyle* theStyle); + InitInteractorStyle(vtkInteractorStyle* theStyle); // Main process VTK event method static @@ -240,7 +201,7 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto vtkSmartPointer myRenderer; vtkSmartPointer myRenderWindow; - typedef vtkSmartPointer PInteractorStyle; + typedef vtkSmartPointer PInteractorStyle; QValueStack myInteractorStyles; }; diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index d04ad8936..bf499d375 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -31,20 +31,25 @@ #include "SVTK_Trihedron.h" #include "SVTK_CubeAxesActor2D.h" -#include "VTKViewer_Actor.h" #include "SALOME_Actor.h" - +#include "VTKViewer_Actor.h" #include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" -#include "SUIT_Session.h" -#include "SUIT_ResourceMgr.h" - #include +#include #include #include #include +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + //---------------------------------------------------------------------------- vtkStandardNewMacro(SVTK_Renderer); @@ -52,6 +57,8 @@ vtkStandardNewMacro(SVTK_Renderer); //---------------------------------------------------------------------------- SVTK_Renderer ::SVTK_Renderer(): + myDevice(vtkRenderer::New()), + myInteractor(NULL), myTransform(VTKViewer_Transform::New()), myCubeAxes(SVTK_CubeAxesActor2D::New()), myTrihedron(SVTK_Trihedron::New()), @@ -59,62 +66,60 @@ SVTK_Renderer myPriority(0.0), myEventCallbackCommand(vtkCallbackCommand::New()) { + if(MYDEBUG) INFOS("SVTK_Renderer() - "<Delete(); myTrihedron->Delete(); myCubeAxes->Delete(); myEventCallbackCommand->Delete(); - myTrihedron->AddToRender(this); - this->AddProp(GetCubeAxes()); + myTrihedron->AddToRender(GetDevice()); + GetDevice()->AddProp(GetCubeAxes()); - vtkTextProperty* aTextProp = vtkTextProperty::New(); - aTextProp->SetColor(1, 1, 1); - aTextProp->ShadowOn(); - - float aBndBox[6]; - aBndBox[0] = aBndBox[2] = aBndBox[4] = 0; - aBndBox[1] = aBndBox[3] = aBndBox[5] = myTrihedron->GetSize(); - myCubeAxes->SetBounds(aBndBox); - myCubeAxes->SetCamera(this->GetActiveCamera()); + myBndBox[0] = myBndBox[2] = myBndBox[4] = 0; + myBndBox[1] = myBndBox[3] = myBndBox[5] = myTrihedron->GetSize(); + + myCubeAxes->SetBounds(myBndBox); + myCubeAxes->SetCamera(GetDevice()->GetActiveCamera()); myCubeAxes->SetLabelFormat("%6.4g"); myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee myCubeAxes->SetFontFactor(0.8); - myCubeAxes->SetAxisTitleTextProperty(aTextProp); - myCubeAxes->SetAxisLabelTextProperty(aTextProp); myCubeAxes->SetCornerOffset(0); myCubeAxes->SetScaling(0); myCubeAxes->SetNumberOfLabels(5); myCubeAxes->VisibilityOff(); myCubeAxes->SetTransform(GetTransform()); - aTextProp->Delete(); - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QColor aColor = aResMgr->colorValue("VTKViewer","background",QColor()); - this->SetBackground(aColor.red()/255.0, - aColor.green()/255.0, - aColor.blue()/255.0); + vtkTextProperty* aTextProp = vtkTextProperty::New(); + aTextProp->SetColor(1, 1, 1); + aTextProp->ShadowOn(); + myCubeAxes->SetAxisTitleTextProperty(aTextProp); + myCubeAxes->SetAxisLabelTextProperty(aTextProp); + aTextProp->Delete(); - this->GetActiveCamera()->ParallelProjectionOn(); - this->LightFollowCameraOn(); - this->TwoSidedLightingOn(); + GetDevice()->GetActiveCamera()->ParallelProjectionOn(); + GetDevice()->LightFollowCameraOn(); + GetDevice()->TwoSidedLightingOn(); myEventCallbackCommand->SetClientData(this); myEventCallbackCommand->SetCallback(SVTK_Renderer::ProcessEvents); - this->AddObserver(vtkCommand::ConfigureEvent, - myEventCallbackCommand.GetPointer(), - myPriority); - this->AddObserver(vtkCommand::ResetCameraEvent, - myEventCallbackCommand.GetPointer(), - myPriority); - this->AddObserver(vtkCommand::ResetCameraClippingRangeEvent, - myEventCallbackCommand.GetPointer(), - myPriority); + GetDevice()->AddObserver(vtkCommand::ConfigureEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + GetDevice()->AddObserver(vtkCommand::ResetCameraEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + GetDevice()->AddObserver(vtkCommand::ResetCameraClippingRangeEvent, + myEventCallbackCommand.GetPointer(), + myPriority); } SVTK_Renderer ::~SVTK_Renderer() -{} +{ + if(MYDEBUG) INFOS("~SVTK_Renderer() - "<onResetView(); + self->OnResetView(); break; case vtkCommand::ResetCameraEvent: - self->onFitAll(); + self->OnFitAll(); break; case vtkCommand::ResetCameraClippingRangeEvent: - self->onResetClippingRange(); + self->OnResetClippingRange(); break; } } + //---------------------------------------------------------------------------- -SVTK_CubeAxesActor2D* +vtkRenderer* SVTK_Renderer -::GetCubeAxes() +::GetDevice() { - return myCubeAxes.GetPointer(); + return myDevice.GetPointer(); } -bool +void SVTK_Renderer -::isCubeAxesDisplayed() +::SetInteractor(vtkRenderWindowInteractor* theInteractor) { - return myCubeAxes->GetVisibility() == 1; + myInteractor = theInteractor; } -VTKViewer_Trihedron* +//---------------------------------------------------------------------------- +void SVTK_Renderer -::GetTrihedron() +::AddActor(VTKViewer_Actor* theActor) { - return myTrihedron.GetPointer(); + if(SALOME_Actor* anActor = dynamic_cast(theActor)) + anActor->AddToInteractor(myInteractor); + theActor->SetTransform(GetTransform()); + theActor->AddToRender(GetDevice()); + AdjustActors(); } -bool +void SVTK_Renderer -::isTrihedronDisplayed() +::RemoveActor(VTKViewer_Actor* theActor) { - return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; + if(SALOME_Actor* anActor = dynamic_cast(theActor)) + anActor->RemoveFromInteractor(myInteractor); + theActor->SetTransform(NULL); + theActor->RemoveFromRender(GetDevice()); + AdjustActors(); } -int +VTKViewer_Transform* SVTK_Renderer -::GetTrihedronSize() const +::GetTransform() { - return myTrihedronSize; + return myTransform.GetPointer(); } void SVTK_Renderer -::SetTrihedronSize(int theSize) +::GetScale( double theScale[3] ) { - if(myTrihedronSize != theSize){ - myTrihedronSize = theSize; - AdjustTrihedrons(true); - } + myTransform->GetMatrixScale( theScale ); +} + +void +SVTK_Renderer +::SetScale( double theScale[3] ) +{ + myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); + AdjustActors(); } @@ -201,51 +221,39 @@ CheckBndBox(const float theBounds[6]) return false; } -void +bool SVTK_Renderer -::AdjustTrihedrons(const bool theIsForced) +::OnAdjustActors() { - bool aTDisplayed = isTrihedronDisplayed(); - bool aCDisplayed = isCubeAxesDisplayed(); - - if(!aCDisplayed && !aTDisplayed && !theIsForced) - return; - - float aBndBox[ 6 ]; - myCubeAxes->GetBounds(aBndBox); + bool aTDisplayed = IsTrihedronDisplayed(); + bool aCDisplayed = IsCubeAxesDisplayed(); float aNewBndBox[6]; aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT; aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; - int aVisibleNum = myTrihedron->GetVisibleActorCount(this); + int aVisibleNum = myTrihedron->GetVisibleActorCount(GetDevice()); if(aVisibleNum){ - // if the new trihedron size have sufficient difference, then apply the value - double aNewSize = 100; - double anOldSize = myTrihedron->GetSize(); - if(aTDisplayed) myTrihedron->VisibilityOff(); if(aCDisplayed) myCubeAxes->VisibilityOff(); - static SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - float aSizeInPercents = aResMgr->doubleValue("VTKViewer","trihedron_size", 105); - - ComputeTrihedronSize(this,aNewSize,anOldSize,aSizeInPercents); - - myTrihedron->SetSize(aNewSize); + // if the new trihedron size have sufficient difference, then apply the value + double aSize = myTrihedron->GetSize(); + ComputeTrihedronSize(GetDevice(),aSize,aSize,myTrihedronSize); + myTrihedron->SetSize(aSize); // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = this->GetActors(); + vtkActorCollection* anActors = GetDevice()->GetActors(); anActors->InitTraversal(); - while(vtkActor* anActor = anActors->GetNextActor()){ - if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor )){ - if(aSActor->IsResizable()) - aSActor->SetSize(0.5 * aNewSize); - if(aSActor->GetVisibility() && !aSActor->IsInfinitive()){ - float *aBounds = aSActor->GetBounds(); + while(vtkActor* anAct = anActors->GetNextActor()){ + if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + if(anActor->IsResizable()) + anActor->SetSize(0.5*aSize); + if(anActor->GetVisibility() && !anActor->IsInfinitive()){ + float *aBounds = anActor->GetBounds(); if(CheckBndBox(aBounds)) for(int i = 0; i < 5; i = i + 2){ if(aBounds[i] < aNewBndBox[i]) @@ -269,107 +277,124 @@ SVTK_Renderer aNewBndBox[1] = aNewBndBox[3] = aNewBndBox[5] = aSize; } - if(CheckBndBox(aNewBndBox)) - myCubeAxes->SetBounds(aNewBndBox); + if(CheckBndBox(aNewBndBox)){ + for(int i = 0; i < 6; i++) + myBndBox[i] = aNewBndBox[i]; + myCubeAxes->SetBounds(myBndBox); + return true; + } - ::ResetCameraClippingRange(this); + return false; } - -//---------------------------------------------------------------------------- -void +void SVTK_Renderer -::onViewTrihedron() +::AdjustActors() { - if(isTrihedronDisplayed()) - myTrihedron->VisibilityOff(); - else - myTrihedron->VisibilityOn(); + if(OnAdjustActors()) + ::ResetCameraClippingRange(GetDevice()); } void SVTK_Renderer -::onViewCubeAxes() +::SetTrihedronSize(int theSize) { - if(isCubeAxesDisplayed()) - myCubeAxes->VisibilityOff(); - else - myCubeAxes->VisibilityOn(); + if(myTrihedronSize != theSize){ + myTrihedronSize = theSize; + AdjustActors(); + } +} + +int +SVTK_Renderer +::GetTrihedronSize() const +{ + return myTrihedronSize; } //---------------------------------------------------------------------------- -void +VTKViewer_Trihedron* SVTK_Renderer -::onAdjustTrihedron() -{ - AdjustTrihedrons(false); +::GetTrihedron() +{ + return myTrihedron.GetPointer(); } -void +bool SVTK_Renderer -::onAdjustCubeAxes() -{ - AdjustTrihedrons(false); +::IsTrihedronDisplayed() +{ + return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; } - -//---------------------------------------------------------------------------- -VTKViewer_Transform* +void SVTK_Renderer -::GetTransform() +::OnViewTrihedron() { - return myTransform.GetPointer(); + if(IsTrihedronDisplayed()) + myTrihedron->VisibilityOff(); + else + myTrihedron->VisibilityOn(); } void SVTK_Renderer -::GetScale( double theScale[3] ) -{ - myTransform->GetMatrixScale( theScale ); +::OnAdjustTrihedron() +{ + AdjustActors(); } -void + +//---------------------------------------------------------------------------- +SVTK_CubeAxesActor2D* SVTK_Renderer -::SetScale( double theScale[3] ) +::GetCubeAxes() { - myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); + return myCubeAxes.GetPointer(); } +bool +SVTK_Renderer +::IsCubeAxesDisplayed() +{ + return myCubeAxes->GetVisibility() == 1; +} -//---------------------------------------------------------------------------- void SVTK_Renderer -::AddActor(VTKViewer_Actor* theActor) +::OnViewCubeAxes() { - theActor->SetTransform(GetTransform()); - theActor->AddToRender(this); + if(IsCubeAxesDisplayed()) + myCubeAxes->VisibilityOff(); + else + myCubeAxes->VisibilityOn(); } void SVTK_Renderer -::RemoveActor(VTKViewer_Actor* theActor) -{ - theActor->RemoveFromRender(this); +::OnAdjustCubeAxes() +{ + AdjustActors(); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onResetView() +::OnResetView() { - int aTrihedronIsVisible = isTrihedronDisplayed(); - int aCubeAxesIsVisible = isCubeAxesDisplayed(); + int aTrihedronIsVisible = IsTrihedronDisplayed(); + int aCubeAxesIsVisible = IsCubeAxesDisplayed(); myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn ); myCubeAxes->SetVisibility(0); - ::ResetCamera(this,true); - vtkCamera* aCamera = this->GetActiveCamera(); + ::ResetCamera(GetDevice(),true); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(1,-1,1); aCamera->SetViewUp(0,0,1); - ::ResetCamera(this,true); + ::ResetCamera(GetDevice(),true); if(aTrihedronIsVisible) myTrihedron->VisibilityOn(); @@ -389,27 +414,27 @@ SVTK_Renderer //---------------------------------------------------------------------------- void SVTK_Renderer -::onFitAll() +::OnFitAll() { int aTrihedronWasVisible = false; int aCubeAxesWasVisible = false; - aTrihedronWasVisible = isTrihedronDisplayed(); + aTrihedronWasVisible = IsTrihedronDisplayed(); if(aTrihedronWasVisible) myTrihedron->VisibilityOff(); - aCubeAxesWasVisible = isCubeAxesDisplayed(); + aCubeAxesWasVisible = IsCubeAxesDisplayed(); if(aCubeAxesWasVisible) myCubeAxes->VisibilityOff(); - if(myTrihedron->GetVisibleActorCount(this)){ + if(myTrihedron->GetVisibleActorCount(GetDevice())){ myTrihedron->VisibilityOff(); myCubeAxes->VisibilityOff(); - ::ResetCamera(this); + ::ResetCamera(GetDevice()); }else{ myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); myCubeAxes->SetVisibility(2); - ::ResetCamera(this,true); + ::ResetCamera(GetDevice(),true); } if(aTrihedronWasVisible) @@ -422,88 +447,88 @@ SVTK_Renderer else myCubeAxes->VisibilityOff(); - ::ResetCameraClippingRange(this); + ::ResetCameraClippingRange(GetDevice()); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onResetClippingRange() +::OnResetClippingRange() { return; - ::ResetCameraClippingRange(this); + ::ResetCameraClippingRange(GetDevice()); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onFrontView() +::OnFrontView() { - vtkCamera* aCamera = this->GetActiveCamera(); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(1,0,0); aCamera->SetViewUp(0,0,1); aCamera->SetFocalPoint(0,0,0); - this->onFitAll(); + this->OnFitAll(); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onBackView() +::OnBackView() { - vtkCamera* aCamera = this->GetActiveCamera(); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(-1,0,0); aCamera->SetViewUp(0,0,1); aCamera->SetFocalPoint(0,0,0); - this->onFitAll(); + this->OnFitAll(); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onTopView() +::OnTopView() { - vtkCamera* aCamera = this->GetActiveCamera(); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(0,0,1); aCamera->SetViewUp(0,1,0); aCamera->SetFocalPoint(0,0,0); - this->onFitAll(); + this->OnFitAll(); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onBottomView() +::OnBottomView() { - vtkCamera* aCamera = this->GetActiveCamera(); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(0,0,-1); aCamera->SetViewUp(0,1,0); aCamera->SetFocalPoint(0,0,0); - this->onFitAll(); + this->OnFitAll(); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onLeftView() +::OnLeftView() { - vtkCamera* aCamera = this->GetActiveCamera(); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(0,-1,0); aCamera->SetViewUp(0,0,1); aCamera->SetFocalPoint(0,0,0); - this->onFitAll(); + this->OnFitAll(); } //---------------------------------------------------------------------------- void SVTK_Renderer -::onRightView() +::OnRightView() { - vtkCamera* aCamera = this->GetActiveCamera(); + vtkCamera* aCamera = GetDevice()->GetActiveCamera(); aCamera->SetPosition(0,1,0); aCamera->SetViewUp(0,0,1); aCamera->SetFocalPoint(0,0,0); - this->onFitAll(); + this->OnFitAll(); } diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h index feb48827f..18186da7c 100644 --- a/src/SVTK/SVTK_Renderer.h +++ b/src/SVTK/SVTK_Renderer.h @@ -21,8 +21,8 @@ // // // -// File : VTKViewer_RenderWindow.h -// Author : Nicolas REJNERI +// File : +// Author : // Module : SALOME // $Header$ @@ -31,33 +31,106 @@ #include "SVTK.h" +#include #include -#ifndef VTK_IMPLEMENT_MESA_CXX -#include -#define SVTK_RENDERER_SUPERCLASS vtkOpenGLRenderer -#else -#include -#define SVTK_RENDERER_SUPERCLASS vtkMesaRenderer -#endif - +class vtkRenderer; class vtkCallbackCommand; +class vtkRenderWindowInteractor; class VTKViewer_Trihedron; class VTKViewer_Transform; class SVTK_CubeAxesActor2D; class VTKViewer_Actor; -class SVTK_EXPORT SVTK_Renderer : public SVTK_RENDERER_SUPERCLASS +class SVTK_EXPORT SVTK_Renderer : public vtkObject { + public: + vtkTypeMacro(SVTK_Renderer,vtkObject); + static SVTK_Renderer* New(); + + //---------------------------------------------------------------------------- + vtkRenderer* + GetDevice(); + + virtual + void + SetInteractor(vtkRenderWindowInteractor* theInteractor); + + //---------------------------------------------------------------------------- + virtual + void + AddActor(VTKViewer_Actor* theActor); + + virtual + void + RemoveActor(VTKViewer_Actor* theActor); + + VTKViewer_Transform* + GetTransform(); + + virtual + void + SetScale( double theScale[3] ); + + void + GetScale( double theScale[3] ); + + //---------------------------------------------------------------------------- + void + AdjustActors(); + + void + SetTrihedronSize(int theSize); + + int + GetTrihedronSize() const; + + //---------------------------------------------------------------------------- + VTKViewer_Trihedron* + GetTrihedron(); + + bool + IsTrihedronDisplayed(); + + void + OnViewTrihedron(); + + void + OnAdjustTrihedron(); + + //---------------------------------------------------------------------------- + SVTK_CubeAxesActor2D* + GetCubeAxes(); + + bool + IsCubeAxesDisplayed(); + + void + OnViewCubeAxes(); + + void + OnAdjustCubeAxes(); + + //---------------------------------------------------------------------------- + void OnFitAll(); + void OnResetView(); + void OnResetClippingRange(); + + void OnFrontView(); + void OnBackView(); + void OnTopView(); + void OnBottomView(); + void OnRightView(); + void OnLeftView(); + protected: SVTK_Renderer(); ~SVTK_Renderer(); - vtkSmartPointer myTransform; - vtkSmartPointer myCubeAxes; - vtkSmartPointer myTrihedron; - int myTrihedronSize; + virtual + bool + OnAdjustActors(); // Priority at which events are processed float myPriority; @@ -72,43 +145,14 @@ class SVTK_EXPORT SVTK_Renderer : public SVTK_RENDERER_SUPERCLASS void* clientdata, void* calldata); - public: - vtkTypeMacro(SVTK_Renderer,SVTK_RENDERER_SUPERCLASS); - static SVTK_Renderer* New(); - - VTKViewer_Trihedron* GetTrihedron(); - SVTK_CubeAxesActor2D* GetCubeAxes(); - - bool isTrihedronDisplayed(); - bool isCubeAxesDisplayed(); + vtkSmartPointer myDevice; + vtkRenderWindowInteractor* myInteractor; - int GetTrihedronSize() const; - void SetTrihedronSize(int theSize); - void AdjustTrihedrons(bool theIsForced); - - void onViewTrihedron(); - void onViewCubeAxes(); - - void onAdjustTrihedron(); - void onAdjustCubeAxes(); - - VTKViewer_Transform* GetTransform(); - void SetScale( double theScale[3] ); - void GetScale( double theScale[3] ); - - void AddActor(VTKViewer_Actor* theActor); - void RemoveActor(VTKViewer_Actor* theActor); - - void onFitAll(); - void onResetView(); - void onResetClippingRange(); - - void onFrontView(); - void onBackView(); - void onTopView(); - void onBottomView(); - void onRightView(); - void onLeftView(); + vtkSmartPointer myTransform; + vtkSmartPointer myCubeAxes; + vtkSmartPointer myTrihedron; + int myTrihedronSize; + float myBndBox[6]; }; #endif diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 1cf6e52b8..bc2dc2c75 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -1,8 +1,37 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + #include "SALOME_Actor.h" #include #include +#include #include #include #include @@ -38,6 +67,14 @@ #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + //---------------------------------------------------------------------------- SVTK_MainWindow @@ -46,6 +83,8 @@ SVTK_MainWindow SUIT_ResourceMgr* theResourceMgr) : QMainWindow(theParent,theName,0) { + if(MYDEBUG) INFOS("SVTK_MainWindow() - "<setCloseMode(QDockWindow::Undocked); myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); @@ -56,24 +95,33 @@ SVTK_MainWindow void SVTK_MainWindow -::Initialize() +::Initialize(SVTK_Renderer *theRenderer) { SetInteractor(new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor")); - SVTK_Renderer* aRenderer = SVTK_Renderer::New(); - GetInteractor()->SetRenderer(aRenderer); - aRenderer->Delete(); - SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); GetInteractor()->PushInteractorStyle(aStyle); aStyle->Delete(); + + GetInteractor()->SetRenderer(theRenderer); +} + +void +SVTK_MainWindow +::Initialize() +{ + SVTK_Renderer* aRenderer = SVTK_Renderer::New(); + Initialize(aRenderer); + aRenderer->Delete(); } //---------------------------------------------------------------------------- SVTK_MainWindow ::~SVTK_MainWindow() -{} +{ + if(MYDEBUG) INFOS("~SVTK_MainWindow() - "<onAdjustTrihedron(); + GetRenderer()->OnAdjustTrihedron(); GetInteractor()->update(); } @@ -140,7 +188,7 @@ SVTK_MainWindow } //---------------------------------------------------------------------------- -SVTK_InteractorStyle* +vtkInteractorStyle* SVTK_MainWindow ::GetInteractorStyle() { @@ -149,7 +197,7 @@ SVTK_MainWindow void SVTK_MainWindow -::PushInteractorStyle(SVTK_InteractorStyle* theStyle) +::PushInteractorStyle(vtkInteractorStyle* theStyle) { GetInteractor()->PushInteractorStyle(theStyle); } @@ -218,7 +266,7 @@ void SVTK_MainWindow ::SetBackgroundColor(const QColor& theColor) { - GetRenderer()->SetBackground(theColor.red()/255.0, + getRenderer()->SetBackground(theColor.red()/255.0, theColor.green()/255.0, theColor.blue()/255.0); } @@ -228,7 +276,7 @@ SVTK_MainWindow ::BackgroundColor() { float aBackgroundColor[3]; - GetRenderer()->GetBackground(aBackgroundColor); + getRenderer()->GetBackground(aBackgroundColor); return QColor(int(aBackgroundColor[0]*255), int(aBackgroundColor[1]*255), int(aBackgroundColor[2]*255)); @@ -298,9 +346,9 @@ SVTK_MainWindow */ void SVTK_MainWindow -::AdjustTrihedrons(const bool theIsForced) +::AdjustActors() { - GetRenderer()->AdjustTrihedrons(theIsForced); + GetRenderer()->AdjustActors(); Repaint(); } @@ -309,7 +357,7 @@ bool SVTK_MainWindow ::IsTrihedronDisplayed() { - return GetRenderer()->isTrihedronDisplayed(); + return GetRenderer()->IsTrihedronDisplayed(); } //---------------------------------------------------------------------------- @@ -317,7 +365,7 @@ bool SVTK_MainWindow ::IsCubeAxesDisplayed() { - return GetRenderer()->isCubeAxesDisplayed(); + return GetRenderer()->IsCubeAxesDisplayed(); } //---------------------------------------------------------------------------- @@ -554,7 +602,7 @@ void SVTK_MainWindow ::onFrontView() { - GetRenderer()->onFrontView(); + GetRenderer()->OnFrontView(); } //---------------------------------------------------------------------------- @@ -562,7 +610,7 @@ void SVTK_MainWindow ::onBackView() { - GetRenderer()->onBackView(); + GetRenderer()->OnBackView(); } //---------------------------------------------------------------------------- @@ -570,7 +618,7 @@ void SVTK_MainWindow ::onTopView() { - GetRenderer()->onTopView(); + GetRenderer()->OnTopView(); } //---------------------------------------------------------------------------- @@ -578,7 +626,7 @@ void SVTK_MainWindow ::onBottomView() { - GetRenderer()->onBottomView(); + GetRenderer()->OnBottomView(); } //---------------------------------------------------------------------------- @@ -586,7 +634,7 @@ void SVTK_MainWindow ::onLeftView() { - GetRenderer()->onLeftView(); + GetRenderer()->OnLeftView(); } //---------------------------------------------------------------------------- @@ -594,7 +642,7 @@ void SVTK_MainWindow ::onRightView() { - GetRenderer()->onRightView(); + GetRenderer()->OnRightView(); } //---------------------------------------------------------------------------- @@ -602,7 +650,7 @@ void SVTK_MainWindow ::onResetView() { - GetRenderer()->onResetView(); + GetRenderer()->OnResetView(); Repaint(); } @@ -611,7 +659,7 @@ void SVTK_MainWindow ::onFitAll() { - GetRenderer()->onFitAll(); + GetRenderer()->OnFitAll(); Repaint(); } @@ -620,7 +668,7 @@ void SVTK_MainWindow ::onViewTrihedron() { - GetRenderer()->onViewTrihedron(); + GetRenderer()->OnViewTrihedron(); Repaint(); } @@ -629,7 +677,7 @@ void SVTK_MainWindow ::onViewCubeAxes() { - GetRenderer()->onViewCubeAxes(); + GetRenderer()->OnViewCubeAxes(); Repaint(); } @@ -638,7 +686,7 @@ void SVTK_MainWindow ::onAdjustTrihedron() { - GetRenderer()->onAdjustTrihedron(); + GetRenderer()->OnAdjustTrihedron(); } //---------------------------------------------------------------------------- @@ -646,7 +694,7 @@ void SVTK_MainWindow ::onAdjustCubeAxes() { - GetRenderer()->onAdjustCubeAxes(); + GetRenderer()->OnAdjustCubeAxes(); } //---------------------------------------------------------------------------- @@ -671,6 +719,8 @@ SVTK_SignalHandler QObject(theMainWindow), myMainWindow(theMainWindow) { + if(MYDEBUG) INFOS("SVTK_SignalHandler() - "<GetInteractor(); connect(anInteractor,SIGNAL(KeyPressed(QKeyEvent*)), @@ -693,7 +743,9 @@ SVTK_SignalHandler SVTK_SignalHandler ::~SVTK_SignalHandler() -{} +{ + if(MYDEBUG) INFOS("~SVTK_SignalHandler() - "<GetRenderer(); + return myMainWindow->getRenderer(); } //---------------------------------------------------------------- @@ -757,7 +809,7 @@ void SVTK_SignalHandler ::onSelectionChanged() { - vtkActorCollection* anActors = myMainWindow->GetRenderer()->GetActors(); + vtkActorCollection* anActors = myMainWindow->getRenderer()->GetActors(); using namespace VTK; ForEach(anActors, @@ -780,12 +832,16 @@ SVTK_SignalHandler SVTK_View ::SVTK_View(SVTK_MainWindow* theMainWindow) : SVTK_SignalHandler(theMainWindow) -{} +{ + if(MYDEBUG) INFOS("SVTK_View() - "<(GetRenderer()->GetActors(), + ForEach(getRenderer()->GetActors(), THighlightAction( false )); Repaint(); @@ -808,7 +864,7 @@ SVTK_View { using namespace VTK; SVTK_Selector* aSelector = myMainWindow->GetSelector(); - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject( theIO ), THighlightAction( theIsHighlight, aSelector->SelectionMode() )); @@ -823,7 +879,7 @@ SVTK_View const double& theBlue, const int& theWidth) { - vtkActorCollection* anActors = GetRenderer()->GetActors(); + vtkActorCollection* anActors = getRenderer()->GetActors(); anActors->InitTraversal(); while( vtkActor* anActor = anActors->GetNextActor() ) { @@ -847,7 +903,7 @@ SVTK_View ::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems) { - vtkActorCollection* anActors = GetRenderer()->GetActors(); + vtkActorCollection* anActors = getRenderer()->GetActors(); anActors->InitTraversal(); while( vtkActor* anActor = anActors->GetNextActor() ) { @@ -867,7 +923,7 @@ SVTK_View { using namespace VTK; SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), + Find(getRenderer()->GetActors(), TIsSameIObject(theIObject)); return anActor != NULL; } @@ -879,7 +935,7 @@ SVTK_View { using namespace VTK; SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), + Find(getRenderer()->GetActors(), TIsSameIObject(theIObject)); return anActor != NULL && anActor->GetVisibility(); } @@ -891,7 +947,7 @@ SVTK_View const QString& theName) { using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::setName,theName.latin1())); @@ -922,7 +978,7 @@ SVTK_View int theMode) { using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::setDisplayMode,theMode)); @@ -933,14 +989,14 @@ void SVTK_View ::ChangeRepresentationToWireframe() { - ChangeRepresentationToWireframe(GetRenderer()->GetActors()); + ChangeRepresentationToWireframe(getRenderer()->GetActors()); } void SVTK_View ::ChangeRepresentationToSurface() { - ChangeRepresentationToSurface(GetRenderer()->GetActors()); + ChangeRepresentationToSurface(getRenderer()->GetActors()); } @@ -988,7 +1044,7 @@ SVTK_View ::EraseAll() { using namespace VTK; - ForEach(GetRenderer()->GetActors(), + ForEach(getRenderer()->GetActors(), TErase()); Repaint(); } @@ -998,7 +1054,7 @@ SVTK_View ::DisplayAll() { using namespace VTK; - ForEach(GetRenderer()->GetActors(), + ForEach(getRenderer()->GetActors(), TSetVisibility(true)); Repaint(); } @@ -1022,7 +1078,7 @@ SVTK_View bool theIsUpdate) { using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TErase()); if(theIsUpdate) @@ -1049,7 +1105,7 @@ SVTK_View bool theIsUpdate) { using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TSetVisibility(true)); @@ -1060,10 +1116,14 @@ SVTK_View //---------------------------------------------------------------------------- struct TRemoveAction { - vtkRenderer* myRen; - TRemoveAction(vtkRenderer* theRen): myRen(theRen){} - void operator()(SALOME_Actor* theActor){ - myRen->RemoveActor(theActor); + SVTK_Renderer* myRenderer; + TRemoveAction(SVTK_Renderer* theRenderer): + myRenderer(theRenderer) + {} + void + operator()(SALOME_Actor* theActor) + { + myRenderer->RemoveActor(theActor); } }; @@ -1073,7 +1133,7 @@ SVTK_View bool theIsUpdate) { using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TRemoveAction(GetRenderer())); if(theIsUpdate) @@ -1085,7 +1145,7 @@ SVTK_View ::Remove(SALOME_Actor* theActor, bool theIsUpdate) { - GetRenderer()->RemoveProp(theActor); + GetRenderer()->RemoveActor(theActor); if(theIsUpdate) Repaint(); } @@ -1094,7 +1154,7 @@ void SVTK_View ::RemoveAll(bool theIsUpdate) { - vtkRenderer* aRenderer = GetRenderer(); + vtkRenderer* aRenderer = getRenderer(); if(vtkActorCollection* anActors = aRenderer->GetActors()){ anActors->InitTraversal(); while(vtkActor *anAct = anActors->GetNextActor()){ @@ -1116,7 +1176,7 @@ SVTK_View { using namespace VTK; SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), + Find(getRenderer()->GetActors(), TIsSameIObject(theIObject)); if(anActor) return 1.0 - anActor->GetOpacity(); @@ -1131,7 +1191,7 @@ SVTK_View { float anOpacity = 1.0 - theTrans; using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::SetOpacity,anOpacity)); @@ -1146,7 +1206,7 @@ SVTK_View float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), + ForEachIf(getRenderer()->GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::SetColor,aColor)); @@ -1159,7 +1219,7 @@ SVTK_View { using namespace VTK; SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), + Find(getRenderer()->GetActors(), TIsSameIObject(theIObject)); if(anActor){ float r,g,b; diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 1514b8d38..e99283017 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -17,6 +17,7 @@ class QtxAction; class vtkRenderer; class vtkRenderWindow; +class vtkInteractorStyle; class vtkRenderWindowInteractor; class vtkObject; @@ -36,7 +37,6 @@ class VTKViewer_Actor; class SVTK_Renderer; class SVTK_RenderWindow; -class SVTK_InteractorStyle; class SVTK_RenderWindowInteractor; class SALOME_Actor; @@ -51,6 +51,10 @@ public: const char* theName, SUIT_ResourceMgr* theResourceMgr); + virtual + void + Initialize(SVTK_Renderer *theRenderer); + virtual void Initialize(); @@ -81,11 +85,11 @@ public: InvokeEvent(unsigned long theEvent, void* theCallData); //---------------------------------------------------------------------------- - SVTK_InteractorStyle* + vtkInteractorStyle* GetInteractorStyle(); void - PushInteractorStyle(SVTK_InteractorStyle* theStyle); + PushInteractorStyle(vtkInteractorStyle* theStyle); void PopInteractorStyle(); @@ -128,6 +132,7 @@ public: void AddActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); + void RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); @@ -139,7 +144,7 @@ public: SetTrihedronSize(const int theSize); void - AdjustTrihedrons(const bool theIsForced); + AdjustActors(); bool IsTrihedronDisplayed(); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 96da68fea..6e97aef20 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -41,7 +41,9 @@ //---------------------------------------------------------------------------- SVTK_ViewWindow ::SVTK_ViewWindow(SUIT_Desktop* theDesktop): - SUIT_ViewWindow(theDesktop) + SUIT_ViewWindow(theDesktop), + myMainWindow(NULL), + myView(NULL) {} void @@ -359,7 +361,7 @@ void SVTK_ViewWindow ::AdjustTrihedrons(const bool theIsForcedUpdate) { - myMainWindow->AdjustTrihedrons( theIsForcedUpdate ); + myMainWindow->AdjustActors(); } //---------------------------------------------------------------------------- diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index b5efe0519..02a563f9f 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -96,18 +96,37 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow void Repaint() { Repaint(true); } //apply existing transformation on adding SALOME_Actor - void SetScale( double theScale[3] ); - void GetScale( double theScale[3] ); - void AddActor( VTKViewer_Actor*, bool update = false ); - void RemoveActor(VTKViewer_Actor*, bool update = false); + virtual + void + SetScale( double theScale[3] ); + + virtual + void + GetScale( double theScale[3] ); + + virtual + void + AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + virtual + void + RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); void AdjustTrihedrons( const bool forced ); - VTKViewer_Trihedron* GetTrihedron(); - SVTK_CubeAxesActor2D* GetCubeAxes(); + VTKViewer_Trihedron* + GetTrihedron(); + + SVTK_CubeAxesActor2D* + GetCubeAxes(); - int GetTrihedronSize() const; - void SetTrihedronSize( const int ); + int + GetTrihedronSize() const; + + void + SetTrihedronSize( const int ); void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, @@ -129,8 +148,14 @@ public slots: void onBottomView(); void onRightView(); void onLeftView(); - void onResetView(); - void onFitAll(); + + virtual + void + onResetView(); + + virtual + void + onFitAll(); void onViewTrihedron(); void onViewCubeAxes();