From: apo Date: Mon, 19 Sep 2005 05:49:43 +0000 (+0000) Subject: To implement callback mechanism for Model & VTK Actor interaction X-Git-Tag: BR-D5-38-2003_D2005-12-10~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a674ea3519e2ea37610bfbda72a05669bee4d456;p=modules%2Fgui.git To implement callback mechanism for Model & VTK Actor interaction --- diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 2e0257d44..2c427b5c8 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -55,7 +55,9 @@ #include #include #include + #include +#include #include #include @@ -79,27 +81,24 @@ vtkStandardNewMacro(SALOME_Actor); //---------------------------------------------------------------------------- SALOME_Actor -::SALOME_Actor() +::SALOME_Actor(): + myRenderer(NULL), + myInteractor(NULL), + mySelectionMode(ActorSelection), + myIsHighlighted(false), + myIsPreselected(false), + myRepresentation(VTK_WIREFRAME), + myDisplayMode(0), + myProperty(vtkProperty::New()), + PreviewProperty(NULL), + myIsInfinite(false), + myIsResolveCoincidentTopology(true), + myStoreMapping(false), + myGeomFilter(VTKViewer_GeometryFilter::New()), + myTransformFilter(VTKViewer_TransformFilter::New()) { - mySelectionMode = ActorSelection; - myIsHighlighted = myIsPreselected = false; - - myRepresentation = 1; - myDisplayMode = myRepresentation - 1; - - myProperty = vtkProperty::New(); - PreviewProperty = NULL; - - myIsInfinite = false; - - myIsResolveCoincidentTopology = true; - vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); - myStoreMapping = false; - myGeomFilter = VTKViewer_GeometryFilter::New(); - - myTransformFilter = VTKViewer_TransformFilter::New(); for(int i = 0; i < 6; i++) myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); @@ -188,9 +187,10 @@ void SALOME_Actor ::AddToRender(vtkRenderer* theRenderer) { + myRenderer = theRenderer; + theRenderer->AddActor(this); - // from VISU theRenderer->AddActor( myPreHighlightActor ); theRenderer->AddActor( myHighlightActor ); theRenderer->AddActor( myOutlineActor ); @@ -202,21 +202,33 @@ SALOME_Actor { theRenderer->RemoveActor(this); - // from VISU theRenderer->RemoveActor( myPreHighlightActor ); theRenderer->RemoveActor( myHighlightActor ); theRenderer->RemoveActor( myOutlineActor ); } +vtkRenderer* +SALOME_Actor +::GetRenderer() +{ + return myRenderer; +} + + +//---------------------------------------------------------------------------- void SALOME_Actor -::AddToInteractor(vtkRenderWindowInteractor* theInteractor) -{} +::SetInteractor(vtkRenderWindowInteractor* theInteractor) +{ + myInteractor = theInteractor; +} void SALOME_Actor -::RemoveFromInteractor(vtkRenderWindowInteractor* theInteractor) -{} +::Update() +{ + myInteractor->CreateTimer(VTKI_TIMER_UPDATE); +} //---------------------------------------------------------------------------- diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index ed7d6d1d2..082c542c3 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -325,19 +325,23 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor //---------------------------------------------------------------------------- virtual void - AddToRender( vtkRenderer* ); + AddToRender(vtkRenderer* theRendere); virtual void - RemoveFromRender( vtkRenderer* ); + RemoveFromRender(vtkRenderer* theRendere); + vtkRenderer* + GetRenderer(); + + //---------------------------------------------------------------------------- virtual void - AddToInteractor(vtkRenderWindowInteractor* theInteractor); + SetInteractor(vtkRenderWindowInteractor* theInteractor); virtual void - RemoveFromInteractor(vtkRenderWindowInteractor* theInteractor); + Update(); //---------------------------------------------------------------------------- virtual @@ -391,6 +395,9 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor } protected: + vtkRenderWindowInteractor* myInteractor; + vtkRenderer* myRenderer; + bool myIsResolveCoincidentTopology; float myPolygonOffsetFactor; float myPolygonOffsetUnits; @@ -401,7 +408,7 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor vtkProperty *PreviewProperty; bool myIsPreselected; bool myIsHighlighted; - int mySelectionMode; + Selection_Mode mySelectionMode; float myOpacity; int myDisplayMode; diff --git a/src/SVTK/SVTK.cxx b/src/SVTK/SVTK.cxx index df2b3e9cf..d1b3ec184 100644 --- a/src/SVTK/SVTK.cxx +++ b/src/SVTK/SVTK.cxx @@ -26,6 +26,27 @@ // Module : // $Header$ +#include "SVTK.h" +#include "SVTK_Prs.h" +#include "SVTK_Actor.h" +#include "SALOME_Actor.h" +#include "SVTK_CubeAxesActor2D.h" +#include "SVTK_Functor.h" +#include "SVTK_View.h" +#include "SVTK_ViewManager.h" +#include "SVTK_ViewModel.h" +#include "SVTK_ViewWindow.h" +#include "SVTK_Renderer.h" +#include "SVTK_InteractorStyle.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" +#include "SVTK_Selector.h" +#include "SVTK_Selection.h" +#include "SVTK_SelectionEvent.h" +#include "SVTK_SpaceMouse.h" +#include "SVTK_Event.h" +#include "SVTK_ViewModelBase.h" + int main(int argc, char** argv) { diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index 0f09f1935..eba1a7390 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -166,7 +166,7 @@ SVTK_Renderer ::AddActor(VTKViewer_Actor* theActor) { if(SALOME_Actor* anActor = dynamic_cast(theActor)) - anActor->AddToInteractor(myInteractor); + anActor->SetInteractor(myInteractor); theActor->SetTransform(GetTransform()); theActor->AddToRender(GetDevice()); AdjustActors(); @@ -176,8 +176,6 @@ void SVTK_Renderer ::RemoveActor(VTKViewer_Actor* theActor) { - if(SALOME_Actor* anActor = dynamic_cast(theActor)) - anActor->RemoveFromInteractor(myInteractor); theActor->SetTransform(NULL); theActor->RemoveFromRender(GetDevice()); AdjustActors(); diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index bc2dc2c75..014ff3834 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -1091,14 +1091,15 @@ SVTK_View ::Display(SALOME_Actor* theActor, bool theIsUpdate) { - GetRenderer()->AddActor(theActor); + if(!isInViewer(theActor->getIO())) + GetRenderer()->AddActor(theActor); + theActor->SetVisibility(true); if(theIsUpdate) Repaint(); } - void SVTK_View ::Display(const Handle(SALOME_InteractiveObject)& theIObject, @@ -1113,6 +1114,15 @@ SVTK_View Repaint(); } +void +SVTK_View +::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject) +{ + EraseAll(); + Display(theIObject); +} + + //---------------------------------------------------------------------------- struct TRemoveAction { diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 6e97aef20..180a53a66 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -232,9 +232,9 @@ SVTK_ViewWindow //---------------------------------------------------------------- void SVTK_ViewWindow -::highlight( const Handle(SALOME_InteractiveObject)& theIO, - bool theIsHighlight, - bool theIsUpdate ) +::highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight, + bool theIsUpdate ) { myView->highlight( theIO, theIsHighlight, theIsUpdate ); } @@ -248,11 +248,41 @@ SVTK_ViewWindow } //---------------------------------------------------------------- -bool +void +SVTK_ViewWindow +::Display(const Handle(SALOME_InteractiveObject)& theIO, + bool theImmediatly) +{ + myView->Display(theIO,theImmediatly); +} + +void +SVTK_ViewWindow +::Erase(const Handle(SALOME_InteractiveObject)& theIO, + bool theImmediatly) +{ + myView->Erase(theIO,theImmediatly); +} + +void +SVTK_ViewWindow +::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) +{ + myView->DisplayOnly(theIO); +} + +void +SVTK_ViewWindow +::DisplayAll() +{ + myView->DisplayAll(); +} + +void SVTK_ViewWindow -::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) +::EraseAll() { - return myView->isVisible( theIO ); + myView->EraseAll(); } //---------------------------------------------------------------------------- diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 02a563f9f..0cc14a104 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -65,37 +65,73 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow Selection_Mode SelectionMode() const; + virtual void SetSelectionMode(Selection_Mode theMode); - void setBackgroundColor( const QColor& ); - QColor backgroundColor() const; + virtual + void + setBackgroundColor( const QColor& ); + + QColor + backgroundColor() const; + + bool + isTrihedronDisplayed(); - bool isTrihedronDisplayed(); - bool isCubeAxesDisplayed(); + bool + isCubeAxesDisplayed(); /* interactive object management */ - void highlight( const Handle(SALOME_InteractiveObject)& IObject, - bool highlight, bool immediatly = true ); - void unHighlightAll(); - bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject ); - bool isVisible( const Handle(SALOME_InteractiveObject)& IObject ); + virtual + void + highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight = true, + bool theIsUpdate = true); + virtual + void + unHighlightAll(); + + bool + isInViewer(const Handle(SALOME_InteractiveObject)& theIObject); + + bool + isVisible(const Handle(SALOME_InteractiveObject)& theIObject); /* selection */ - Handle(SALOME_InteractiveObject) FindIObject(const char* Entry); + //---------------------------------------------------------------------------- + Handle(SALOME_InteractiveObject) + FindIObject(const char* theEntry); /* display */ - void Display( const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true ); - void DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject ); - void Erase( const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true ); - void DisplayAll(); - void EraseAll(); - void Repaint( bool theUpdateTrihedron ); - void Repaint() { Repaint(true); } - - //apply existing transformation on adding SALOME_Actor + //---------------------------------------------------------------------------- + virtual + void + Display(const Handle(SALOME_InteractiveObject)& theIObject, + bool theImmediatly = true); + + virtual + void + DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject); + + virtual + void + Erase(const Handle(SALOME_InteractiveObject)& theIObject, + bool theImmediatly = true); + + virtual + void + DisplayAll(); + + virtual + void + EraseAll(); + + virtual + void + Repaint(bool theUpdateTrihedron = true); + + //---------------------------------------------------------------------------- virtual void SetScale( double theScale[3] ); @@ -114,7 +150,10 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); - void AdjustTrihedrons( const bool forced ); + //---------------------------------------------------------------------------- + virtual + void + AdjustTrihedrons(const bool theIsForced); VTKViewer_Trihedron* GetTrihedron(); @@ -125,29 +164,54 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow int GetTrihedronSize() const; + virtual void SetTrihedronSize( const int ); - void SetSelectionProp(const double& theRed = 1, - const double& theGreen = 1, - const double& theBlue = 0, - const int& theWidth = 5); - void SetSelectionTolerance(const double& theTolNodes = 0.025, - const double& theTolCell = 0.001); + virtual + void + SetSelectionProp(const double& theRed = 1, + const double& theGreen = 1, + const double& theBlue = 0, + const int& theWidth = 5); + virtual + void + SetSelectionTolerance(const double& theTolNodes = 0.025, + const double& theTolCell = 0.001); + public slots: - void onSelectionChanged(); + virtual + void + onSelectionChanged(); signals: void selectionChanged(); public slots: - void onFrontView(); - void onBackView(); - void onTopView(); - void onBottomView(); - void onRightView(); - void onLeftView(); + virtual + void + onFrontView(); + + virtual + void + onBackView(); + + virtual + void + onTopView(); + + virtual + void + onBottomView(); + + virtual + void + onRightView(); + + virtual + void + onLeftView(); virtual void @@ -157,11 +221,21 @@ public slots: void onFitAll(); - void onViewTrihedron(); - void onViewCubeAxes(); + virtual + void + onViewTrihedron(); + + virtual + void + onViewCubeAxes(); + + virtual + void + onAdjustTrihedron(); - void onAdjustTrihedron(); - void onAdjustCubeAxes(); + virtual + void + onAdjustCubeAxes(); protected slots: void onKeyPressed(QKeyEvent* event);