]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To improve selection management.
authorapo <apo@opencascade.com>
Mon, 17 Oct 2005 06:14:06 +0000 (06:14 +0000)
committerapo <apo@opencascade.com>
Mon, 17 Oct 2005 06:14:06 +0000 (06:14 +0000)
1. Now internal highlight/prehighlight actors use the same position as its container - SALOME_Actor
2. All SALOME_Actor share the same instances of pickers and highlight/prehighlight properties that is stored into SVTK_Renderer

src/SVTK/SALOME_Actor.cxx
src/SVTK/SALOME_Actor.h

index f94dd6f4f00e4f40cd294d914548eab5d5efd7dd..43d8236af1f78b601266efffbfc3d5b5741af42f 100644 (file)
 
 using namespace std;
 
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
 #if defined __GNUC__
   #if __GNUC__ == 2
     #define __GNUC_2__
@@ -144,59 +150,39 @@ SALOME_Actor
   myIsResolveCoincidentTopology(true),
   myStoreMapping(false),
   myGeomFilter(VTKViewer_GeometryFilter::New()),
-  myTransformFilter(VTKViewer_TransformFilter::New())
+  myTransformFilter(VTKViewer_TransformFilter::New()),
+  myPreHighlightActor(SVTK_Actor::New()),
+  myHighlightActor(SVTK_Actor::New()),
+  myOutline(vtkOutlineSource::New()),
+  myOutlineActor(VTKViewer_Actor::New())
 {
+  if(MYDEBUG) MESSAGE("SALOME_Actor::SALOME_Actor - this = "<<this);
+
   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
                                                                 myPolygonOffsetUnits);
 
   for(int i = 0; i < 6; i++)
     myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
 
-  myPointPicker = vtkPointPicker::New();
-  myPointPicker->Delete();
-
-  myCellPicker = vtkCellPicker::New();
-  myCellPicker->Delete();
-
-  myCellRectPicker = VTKViewer_CellRectPicker::New();
-  myCellRectPicker->Delete();
-
-  myPreHighlightProperty = vtkProperty::New();
-  myPreHighlightProperty->Delete();
-  myPreHighlightProperty->SetColor(0,1,1);
-  myPreHighlightProperty->SetPointSize(SALOME_POINT_SIZE);
-  myPreHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH);
-  myPreHighlightProperty->SetRepresentationToPoints();
-
-  myPreHighlightActor = SVTK_Actor::New(); 
   myPreHighlightActor->Delete();
-  myPreHighlightActor->SetProperty(myPreHighlightProperty.GetPointer());
+  myPreHighlightActor->PickableOff();
   myPreHighlightActor->SetVisibility( false );
 
-  myHighlightProperty = vtkProperty::New();
-  myHighlightProperty->Delete();
-  myHighlightProperty->SetColor(1,1,0);
-  myHighlightProperty->SetPointSize(SALOME_POINT_SIZE);
-  myHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH);
-  myHighlightProperty->SetRepresentationToPoints();
-
-  myHighlightActor = SVTK_Actor::New(); 
+  myHighlightActor->Delete();
   myHighlightActor->PickableOff();
-  myHighlightActor->SetProperty(myHighlightProperty.GetPointer());
   myHighlightActor->SetVisibility( false );
 
-  myOutline = vtkOutlineSource::New();
   myOutline->Delete();
 
-  vtkSmartPointer<vtkPolyDataMapper> anOutlineMapper = vtkPolyDataMapper::New();
-  anOutlineMapper->Delete();
+  vtkPolyDataMapper* anOutlineMapper = vtkPolyDataMapper::New();
   anOutlineMapper->SetInput(myOutline->GetOutput());
 
-  myOutlineActor = VTKViewer_Actor::New();
   myOutlineActor->Delete();
+  myOutlineActor->SetMapper( anOutlineMapper );
+  anOutlineMapper->Delete();
+
   myOutlineActor->PickableOff();
   myOutlineActor->DragableOff();
-  myOutlineActor->SetMapper( anOutlineMapper.GetPointer() );
   myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0);
   myOutlineActor->GetProperty()->SetAmbient(1.0);
   myOutlineActor->GetProperty()->SetDiffuse(0.0);
@@ -208,6 +194,8 @@ SALOME_Actor
 SALOME_Actor
 ::~SALOME_Actor()
 {
+  if(MYDEBUG) MESSAGE("SALOME_Actor::~SALOME_Actor - this = "<<this);
+
   SetPreviewProperty(NULL);
 
   myGeomFilter->UnRegisterAllOutputs(); 
@@ -308,8 +296,6 @@ SALOME_Actor
   theRenderer->AddActor( myPreHighlightActor.GetPointer() );
   theRenderer->AddActor( myHighlightActor.GetPointer() );
   theRenderer->AddActor( myOutlineActor.GetPointer() );
-
-  this->SetSelectionTolerance( 0.005 );
 }
 
 void 
@@ -365,6 +351,26 @@ SALOME_Actor
 }
 
 
+void
+SALOME_Actor
+::SetPosition(float _arg1, float _arg2, float _arg3)
+{
+  Superclass::SetPosition(_arg1,_arg2,_arg3);
+
+  myPreHighlightActor->SetPosition(_arg1,_arg2,_arg3);
+  myHighlightActor->SetPosition(_arg1,_arg2,_arg3);
+  myOutlineActor->SetPosition(_arg1,_arg2,_arg3);
+}
+
+
+void
+SALOME_Actor
+::SetPosition(float _arg[3])
+{
+  SetPosition(_arg[0],_arg[1],_arg[2]);
+}
+
+
 void
 SALOME_Actor
 ::SetMapper(vtkMapper* theMapper)
@@ -715,6 +721,19 @@ SALOME_Actor::setDisplayMode(int theMode)
 }
 
 
+//----------------------------------------------------------------
+void
+SALOME_Actor
+::SetVisibility( int theVisibility )
+{
+  Superclass::SetVisibility( theVisibility );
+
+  myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() );
+  myHighlightActor->SetVisibility( theVisibility && isHighlighted() );
+  myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
+}
+
+
 //----------------------------------------------------------------
 void
 SALOME_Actor
@@ -740,16 +759,41 @@ SALOME_Actor
   }
 }
 
-//----------------------------------------------------------------
 void
 SALOME_Actor
-::SetVisibility( int theVisibility )
+::highlight(bool theIsHighlight, 
+           SVTK_Selector* theSelector)
 {
-  Superclass::SetVisibility( theVisibility );
+  TColStd_IndexedMapOfInteger aMapIndex;
+  theSelector->GetIndex( getIO(), aMapIndex );
+  mySelectionMode = theSelector->SelectionMode();
 
-  myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() );
-  myHighlightActor->SetVisibility( theVisibility && isHighlighted() );
-  myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
+  if(MYDEBUG) MESSAGE("SALOME_Actor::highlight - this = "<<this<<
+                     "; theIsHighlight = "<<theIsHighlight<<
+                     "; mySelectionMode = "<<mySelectionMode);
+
+  switch( mySelectionMode )
+  {
+    case NodeSelection:
+      myHighlightActor->GetProperty()->SetRepresentationToPoints();
+      myHighlightActor->MapPoints( this, aMapIndex );
+      break;
+    case EdgeOfCellSelection:
+      myHighlightActor->GetProperty()->SetRepresentationToWireframe();
+      myHighlightActor->MapEdge( this, aMapIndex );
+      break;
+    case CellSelection:
+    case EdgeSelection:
+    case FaceSelection:
+    case VolumeSelection:
+      myHighlightActor->GetProperty()->SetRepresentationToSurface();
+      myHighlightActor->MapCells( this, aMapIndex );
+      break;
+    case ActorSelection:
+      break;
+  }
+
+  highlight( theIsHighlight, mySelectionMode );
 }
 
 
@@ -765,9 +809,9 @@ SALOME_Actor
   //
   myPreHighlightActor->SetVisibility( false );
     
-  bool anIsChanged = (mySelectionMode != theSelectionEvent->mySelectionMode);
-
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
+  bool anIsChanged = (mySelectionMode != aSelectionMode);
+
   float x = theSelectionEvent->myX;
   float y = theSelectionEvent->myY;
   float z = 0.0;
@@ -783,7 +827,7 @@ SALOME_Actor
 
     anIsChanged = true;
   }else{
-    switch(mySelectionMode){
+    switch(aSelectionMode){
     case NodeSelection: 
     {
       myPointPicker->Pick( x, y, z, aRenderer );
@@ -1104,71 +1148,39 @@ SALOME_Actor
   return true;
 }
 
+//----------------------------------------------------------------------------
 void
 SALOME_Actor
-::highlight(bool theIsHighlight, 
-           SVTK_Selector* theSelector)
+::SetPointPicker(vtkPointPicker* thePointPicker) 
 {
-  TColStd_IndexedMapOfInteger aMapIndex;
-  theSelector->GetIndex( getIO(), aMapIndex );
-
-  switch( mySelectionMode )
-  {
-    case NodeSelection:
-      myHighlightProperty->SetRepresentationToPoints();
-      myHighlightActor->MapPoints( this, aMapIndex );
-      break;
-    case EdgeOfCellSelection:
-      myHighlightProperty->SetRepresentationToWireframe();
-      myHighlightActor->MapEdge( this, aMapIndex );
-      break;
-    case CellSelection:
-    case EdgeSelection:
-    case FaceSelection:
-    case VolumeSelection:
-      myHighlightProperty->SetRepresentationToSurface();
-      myHighlightActor->MapCells( this, aMapIndex );
-      break;
-    case ActorSelection:
-      break;
-  }
-
-  highlight( theIsHighlight, mySelectionMode );
+  myPointPicker = thePointPicker;
 }
 
-
-//----------------------------------------------------------------------------
 void
 SALOME_Actor
-::SetSelectionProp(const double& theRed, 
-                  const double& theGreen, 
-                  const double& theBlue, 
-                  const int& theWidth) 
+::SetCellPicker(vtkCellPicker* theCellPicker) 
 {
-  myHighlightProperty->SetColor( theRed, theGreen, theBlue );
-  myHighlightProperty->SetLineWidth( theWidth );
+  myCellPicker = theCellPicker;
 }
 
-//----------------------------------------------------------------------------
 void
 SALOME_Actor
-::SetPreselectionProp(const double& theRed, 
-                     const double& theGreen, 
-                     const double& theBlue, 
-                     const int& theWidth) 
+::SetCellRectPicker(VTKViewer_CellRectPicker* theCellRectPicker) 
 {
-  myPreHighlightProperty->SetColor( theRed, theGreen, theBlue );
-  myPreHighlightProperty->SetLineWidth( theWidth );
+  myCellRectPicker = theCellRectPicker;
 }
 
 //----------------------------------------------------------------------------
 void
 SALOME_Actor
-::SetSelectionTolerance(const double& theTolNodes, 
-                       const double& theTolCell)
+::SetPreHighlightProperty(vtkProperty* theProperty) 
 {
-  myPointPicker->SetTolerance( theTolNodes );
-  myCellPicker->SetTolerance( theTolCell );
-  myCellRectPicker->SetTolerance( theTolCell );
+  myPreHighlightActor->SetProperty(theProperty);
 }
 
+void
+SALOME_Actor
+::SetHighlightProperty(vtkProperty* theProperty) 
+{
+  myHighlightActor->SetProperty(theProperty);
+}
index 819a4c2d9310d7a303b7ce13fe3b7d758899f778..9c1e5d2b554d3700ef720f01978eb8bcbb88e5a7 100644 (file)
@@ -186,6 +186,14 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
   void
   SetTransform(VTKViewer_Transform* theTransform); 
 
+  virtual
+  void
+  SetPosition(float _arg1, float _arg2, float _arg3);
+
+  virtual
+  void
+  SetPosition(float _arg[3]);
+
   virtual
   unsigned long int
   GetMTime();
@@ -297,7 +305,7 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
   virtual
   void
   GetChildActors(vtkActorCollection*);
-  
+
   //----------------------------------------------------------------------------
   virtual
   void
@@ -322,24 +330,22 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
            SVTK_SelectionEvent* theSelectionEvent,
            bool theIsHighlight);
 
-  virtual
+  //----------------------------------------------------------------------------
   void
-  SetSelectionProp(const double& theRed = 1, 
-                  const double& theGreen = 1,
-                  const double& theBlue = 0, 
-                  const int& theWidth = 5);
+  SetPointPicker(vtkPointPicker* thePointPicker); 
 
-  virtual
   void
-  SetPreselectionProp(const double& theRed = 0, 
-                     const double& theGreen = 1,
-                     const double& theBlue = 1, 
-                     const int& theWidth = 5);
+  SetCellPicker(vtkCellPicker* theCellPicker); 
 
-  virtual
   void
-  SetSelectionTolerance(const double& theTolNodes = 0.025, 
-                       const double& theTolCell = 0.001);
+  SetCellRectPicker(VTKViewer_CellRectPicker* theCellRectPicker);
+
+  //----------------------------------------------------------------------------
+  void
+  SetPreHighlightProperty(vtkProperty* theProperty);
+
+  void
+  SetHighlightProperty(vtkProperty* theProperty);
 
   vtkSetObjectMacro(PreviewProperty,vtkProperty);
 
@@ -385,10 +391,7 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
   vtkSmartPointer<vtkCellPicker> myCellPicker;
   vtkSmartPointer<VTKViewer_CellRectPicker> myCellRectPicker;
 
-  vtkSmartPointer<vtkProperty> myPreHighlightProperty;
   vtkSmartPointer<SVTK_Actor> myPreHighlightActor;
-
-  vtkSmartPointer<vtkProperty> myHighlightProperty;
   vtkSmartPointer<SVTK_Actor> myHighlightActor;
 
   vtkSmartPointer<VTKViewer_Actor> myOutlineActor;