Salome HOME
PR: merged from V5_1_4rc1
[modules/smesh.git] / src / OBJECT / SMESH_Actor.cxx
index 7a37d65410b17301f6db14ab0fb145891d3ea17f..cd9e0691967992a98cc2b113fd863498a0c67211 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  SMESH OBJECT : interactive object for SMESH visualization
 //  File   : SMESH_Actor.cxx
 //  Author : Nicolas REJNERI
 //  Module : SMESH
-
-
+//
 #include "SMESH_ActorDef.h"
 #include "SMESH_ActorUtils.h"
 #include "SMESH_DeviceActor.h"
@@ -86,7 +86,6 @@ static int MYDEBUG = 0;
 #endif
 
 static int aLineWidthInc = 2;
-static int aPointSizeInc = 2;
 
 
 SMESH_ActorDef* SMESH_ActorDef::New(){
@@ -129,7 +128,6 @@ SMESH_ActorDef::SMESH_ActorDef()
   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
     myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
 
-  vtkFloatingPointType aPointSize  = SMESH::GetFloat("SMESH:node_size",3);
   vtkFloatingPointType aElem0DSize = SMESH::GetFloat("SMESH:elem0d_size",5);
   vtkFloatingPointType aLineWidth  = SMESH::GetFloat("SMESH:element_width",1);
 
@@ -224,7 +222,7 @@ SMESH_ActorDef::SMESH_ActorDef()
   my1DProp = vtkProperty::New();
   my1DProp->DeepCopy(myEdgeProp);
   my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
-  my1DProp->SetPointSize(aPointSize);
+  my1DProp->SetPointSize(aElem0DSize);
   
   my1DExtProp = vtkProperty::New();
   my1DExtProp->DeepCopy(myEdgeProp);
@@ -233,7 +231,7 @@ SMESH_ActorDef::SMESH_ActorDef()
   anRGB[2] = 1 - anRGB[2];
   my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
   my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
-  my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
+  my1DExtProp->SetPointSize(aElem0DSize);
 
   my1DExtActor = SMESH_DeviceActor::New();
   my1DExtActor->SetUserMatrix(aMatrix);
@@ -294,7 +292,6 @@ SMESH_ActorDef::SMESH_ActorDef()
   myNodeProp = vtkProperty::New();
   SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
   myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
-  myNodeProp->SetPointSize(aPointSize);
 
   myNodeActor = SMESH_DeviceActor::New();
   myNodeActor->SetUserMatrix(aMatrix);
@@ -312,7 +309,6 @@ SMESH_ActorDef::SMESH_ActorDef()
   anRGB[1] = 1 - anRGB[1];
   anRGB[2] = 1 - anRGB[2];
   myNodeExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
-  myNodeExtProp->SetPointSize(aPointSize);
 
   myNodeExtActor = SMESH_DeviceActor::New();
   myNodeExtActor->SetUserMatrix(aMatrix);
@@ -342,8 +338,7 @@ SMESH_ActorDef::SMESH_ActorDef()
   myHighlightProp->SetSpecular(0.0);
   SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
   myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
-  //myHighlightProp->SetPointSize(aPointSize);
-  myHighlightProp->SetPointSize(std::max(aElem0DSize,aPointSize)); // ??
+  myHighlightProp->SetPointSize(aElem0DSize); // ??
   myHighlightProp->SetRepresentation(1);
 
   myPreselectProp = vtkProperty::New();
@@ -352,8 +347,7 @@ SMESH_ActorDef::SMESH_ActorDef()
   myPreselectProp->SetSpecular(0.0);
   SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
   myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
-  //myPreselectProp->SetPointSize(aPointSize);
-  myPreselectProp->SetPointSize(std::max(aElem0DSize,aPointSize)); // ??
+  myPreselectProp->SetPointSize(aElem0DSize); // ??
   myPreselectProp->SetRepresentation(1);
 
   myHighlitableActor = SMESH_DeviceActor::New();
@@ -404,9 +398,7 @@ SMESH_ActorDef::SMESH_ActorDef()
     
   myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
   myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
-#if (VTK_XVERSION >= 0x050200)
-  myPtsLabeledDataMapper->SetLabelFormat("%d");
-#else
+#if (VTK_XVERSION < 0x050200)
   myPtsLabeledDataMapper->SetLabelFormat("%g");
 #endif
   myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
@@ -449,9 +441,7 @@ SMESH_ActorDef::SMESH_ActorDef()
     
   myClsLabeledDataMapper = vtkLabeledDataMapper::New();
   myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
-#if (VTK_XVERSION >= 0x050200)
-  myClsLabeledDataMapper->SetLabelFormat("%d");
-#else
+#if (VTK_XVERSION < 0x050200)
   myClsLabeledDataMapper->SetLabelFormat("%g");
 #endif
   myClsLabeledDataMapper->SetLabelModeToLabelScalars();
@@ -665,6 +655,39 @@ bool SMESH_ActorDef::GetFacesOriented()
   return myIsFacesOriented;
 }
 
+void SMESH_ActorDef::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
+{
+  my2DActor->SetFacesOrientationColor( theColor );
+  my3DActor->SetFacesOrientationColor( theColor );
+}
+
+void SMESH_ActorDef::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
+{
+  my3DActor->GetFacesOrientationColor( theColor );
+}
+
+void SMESH_ActorDef::SetFacesOrientationScale(vtkFloatingPointType theScale)
+{
+  my2DActor->SetFacesOrientationScale( theScale );
+  my3DActor->SetFacesOrientationScale( theScale );
+}
+
+vtkFloatingPointType SMESH_ActorDef::GetFacesOrientationScale()
+{
+  return my3DActor->GetFacesOrientationScale();
+}
+
+void SMESH_ActorDef::SetFacesOrientation3DVectors(bool theState)
+{
+  my2DActor->SetFacesOrientation3DVectors( theState );
+  my3DActor->SetFacesOrientation3DVectors( theState );
+}
+
+bool SMESH_ActorDef::GetFacesOrientation3DVectors()
+{
+  return my3DActor->GetFacesOrientation3DVectors();
+}
+
 
 void 
 SMESH_ActorDef::
@@ -858,8 +881,6 @@ SetControlMode(eControl theMode,
 
 
 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
-  SALOME_Actor::AddToRender(theRenderer);
-
   theRenderer->AddActor(myNodeActor);
   theRenderer->AddActor(myBaseActor);
   
@@ -884,6 +905,10 @@ void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
 
   theRenderer->AddActor2D(myPointLabels);
   theRenderer->AddActor2D(myCellsLabels);
+
+  // the superclass' method should be called at the end
+  // (in particular, for correct work of selection)
+  SALOME_Actor::AddToRender(theRenderer);
 }
 
 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
@@ -983,6 +1008,10 @@ bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
     SetIsDisplayNameActor( true );
 
+  int aMarkerType = mgr->integerValue( "SMESH", "type_of_marker", 1 ); // dot
+  int aMarkerScale = mgr->integerValue( "SMESH", "marker_scale", 9 );  // 5 pixels
+  SetMarkerStd( (VTK::MarkerType)aMarkerType, (VTK::MarkerScale)aMarkerScale );
+
   myTimeStamp->Modified();
   Modified();
   return true;
@@ -1190,15 +1219,15 @@ void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
       my0DActor->VisibilityOn();
     }
 
-    if(myEntityMode & eEdges){
+    if(myEntityMode & eEdges && GetRepresentation() != ePoint){
       my1DActor->VisibilityOn();
     }
     
-    if(myEntityMode & eFaces){
+    if(myEntityMode & eFaces && GetRepresentation() != ePoint){
       my2DActor->VisibilityOn();
     }
     
-    if(myEntityMode & eVolumes){
+    if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
       my3DActor->VisibilityOn();
     }
     
@@ -1263,11 +1292,7 @@ void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
 
   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
   aHightFilter->ClearRegisteredCellsWithType();
-
-  // The following row has been commented (initially added in 1.28.2.3.1 revision)
-  // Reason: seems to be unnecessary, this filter should always have default (ePassAll) mode of changing
-  // In addition, it leads to exception (see bug IPAL21372)
-  //aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
+  aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
 
   if (myEntityMode & e0DElements) {
     if (MYDEBUG) MESSAGE("0D ELEMENTS");
@@ -1483,6 +1508,12 @@ void SMESH_ActorDef::UpdateHighlight(){
         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
       myHighlitableActor->SetVisibility(anIsVisible);
       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
+
+      VTK::MarkerType aMarkerType = GetMarkerType();
+      if(aMarkerType != VTK::MT_USER)
+        myHighlitableActor->SetMarkerStd(aMarkerType, GetMarkerScale());
+      else
+        myHighlitableActor->SetMarkerTexture(GetMarkerTexture(), myMarkerTexture);
     }
   }
 }
@@ -1644,6 +1675,18 @@ void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType&
   ::GetColor(myNodeProp,r,g,b);
 }
 
+void SMESH_ActorDef::Set0DColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
+  my0DProp->SetColor(r,g,b);
+  if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
+    if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
+      myNameActor->SetBackgroundColor(r,g,b);
+  Modified();
+}
+
+void SMESH_ActorDef::Get0DColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
+  ::GetColor(my0DProp,r,g,b);
+}
+
 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
   myHighlightProp->SetColor(r,g,b);
   Modified();
@@ -1678,24 +1721,13 @@ void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
 }
 
 
-void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
-  myNodeProp->SetPointSize(theVal);
-  myNodeExtProp->SetPointSize(theVal);
-
-  vtkFloatingPointType aPointSize = my0DProp->GetPointSize() > theVal ? my0DProp->GetPointSize() : theVal;
-  //myHighlightProp->SetPointSize(theVal);
-  myHighlightProp->SetPointSize(aPointSize); // ??
-  //myPreselectProp->SetPointSize(theVal);
-  myPreselectProp->SetPointSize(aPointSize); // ??
-
-  my1DProp->SetPointSize(theVal + aPointSizeInc);
-  my1DExtProp->SetPointSize(theVal + aPointSizeInc);
-
+void SMESH_ActorDef::Set0DSize(vtkFloatingPointType theVal){
+  my0DProp->SetPointSize(theVal);
   Modified();
 }
 
-vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
-  return myNodeProp->GetPointSize();
+vtkFloatingPointType SMESH_ActorDef::Get0DSize(){
+  return my0DProp->GetPointSize();
 }
 
 int SMESH_ActorDef::GetObjDimension( const int theObjId )
@@ -1999,3 +2031,18 @@ SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresenta
   else
     return SMESH_Actor::eLines;
 }
+
+void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
+{
+  SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
+  myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
+  myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
+}
+
+void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
+{
+  SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
+  myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
+  myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
+  myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
+}