Salome HOME
Merge V8_4_BR branch.
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
index 851b83ab11e1422e0ab7b11945d8c174d1fc8cfa..3104e50078b22a9428e88dbc4b56b64af9b8505b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
 #include "GEOM_WireframeFace.h" 
 #include "GEOM_ShadingFace.h"
 #include "GEOM_PainterPolyDataMapper.h"
+#include "GEOMUtils.hxx" 
 #include "SVTK_Actor.h"
 
 #include <OCC2VTK_Tools.h>
+#include <GEOMUtils.hxx>
 
 #include <vtkObjectFactory.h> 
 #include <vtkRenderer.h> 
+#include <vtkTextActor.h>
+#include <vtkTextProperty.h>
 #include <vtkProperty.h> 
 #include <vtkPointPicker.h>
 #include <vtkCellPicker.h>
@@ -83,10 +87,14 @@ GEOM_Actor::GEOM_Actor():
   myIsSelected(false), 
   myVectorMode(false),
   myVerticesMode(false),
+  myNameMode(false),
 
   myVertexActor(GEOM_DeviceActor::New(),true), 
   myVertexSource(GEOM_VertexSource::New(),true), 
  
+  myStandaloneVertexActor(GEOM_DeviceActor::New(),true), 
+  myStandaloneVertexSource(GEOM_VertexSource::New(),true), 
+
   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
  
@@ -111,6 +119,8 @@ GEOM_Actor::GEOM_Actor():
   // defined in this class !!!
   myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
 
+  myTextActor( vtkTextActor::New() ),
+
   myHighlightProp(vtkProperty::New()),
   myPreHighlightProp(vtkProperty::New()),
   myShadingFaceProp(vtkProperty::New()),
@@ -130,13 +140,13 @@ GEOM_Actor::GEOM_Actor():
   myHighlightProp->SetAmbientColor(1, 1, 1);
   myHighlightProp->SetDiffuseColor(1, 1, 1);
   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
-  myHighlightProp->SetPointSize(0);
+  myHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
 
   this->myHighlightActor->SetInput(myAppendFilter->GetOutputPort(),false);
 
   myPreHighlightProp->SetColor(0,1,1);
-  myPreHighlightProp->SetPointSize(0);
+  myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE);
   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
   myPreHighlightProp->SetRepresentationToWireframe();
 
@@ -147,6 +157,13 @@ GEOM_Actor::GEOM_Actor():
   aProperty->SetPointSize(3); 
   aProperty->SetColor(1, 1, 0);
  
+  myAppendFilter->AddInputConnection(myStandaloneVertexSource->GetOutputPort()); 
+  myStandaloneVertexActor->SetInput(myStandaloneVertexSource->GetOutputPort(),false); 
+  aProperty = myStandaloneVertexActor->GetProperty(); 
+  aProperty->SetRepresentation(VTK_POINTS); 
+  aProperty->SetPointSize(3); 
+  aProperty->SetColor(1, 1, 0);
   myAppendFilter->AddInputConnection(myIsolatedEdgeSource->GetOutputPort());
   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutputPort(),false); 
   aProperty = myIsolatedEdgeActor->GetProperty(); 
@@ -191,6 +208,7 @@ GEOM_Actor::GEOM_Actor():
   setDisplayMode(0); // WIRE FRAME
   SetVectorMode(0);  //
   SetVerticesMode(0);  //
+  SetNameMode(0); 
 } 
  
  
@@ -199,6 +217,7 @@ GEOM_Actor::~GEOM_Actor()
 #ifdef MYDEBUG
   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
 #endif
+  myTextActor->Delete();
   myHighlightProp->Delete();
   myPreHighlightProp->Delete();
   myShadingFaceProp->Delete();
@@ -229,11 +248,13 @@ GEOM_Actor::
 SetModified() 
 { 
   this->myVertexSource->Modified(); 
+  this->myStandaloneVertexSource->Modified(); 
   this->myIsolatedEdgeSource->Modified(); 
   this->myOneFaceEdgeSource->Modified(); 
   this->mySharedEdgeSource->Modified(); 
   this->myWireframeFaceSource->Modified(); 
   this->myShadingFaceSource->Modified(); 
+  this->myTextActor->Modified();
 } 
 
 void  
@@ -262,6 +283,9 @@ AddToRender(vtkRenderer* theRenderer)
   myIsolatedEdgeActor->AddToRender(theRenderer); 
  
   myVertexActor->AddToRender(theRenderer); 
+  myStandaloneVertexActor->AddToRender(theRenderer); 
+
+  theRenderer->AddActor( myTextActor );
 }
  
 void 
@@ -282,7 +306,9 @@ RemoveFromRender(vtkRenderer* theRenderer)
   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
  
   myVertexActor->RemoveFromRender(theRenderer);
+  myStandaloneVertexActor->RemoveFromRender(theRenderer);
 
+  theRenderer->RemoveActor( myTextActor );
   
   SetSelected(false);
   SetVisibility(false);
@@ -313,9 +339,9 @@ setDisplayMode(int theMode)
     myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
                                                  myIsolatedEdgeColor[1],
                                                  myIsolatedEdgeColor[2]);
-    mySharedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
-                                               myIsolatedEdgeColor[1],
-                                               myIsolatedEdgeColor[2]);
+    mySharedEdgeActor->GetProperty()->SetColor(mySharedEdgeColor[0],
+                                               mySharedEdgeColor[1],
+                                               mySharedEdgeColor[2]);
     myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
                                                myOneFaceEdgeColor[1],
                                                myOneFaceEdgeColor[2]);
@@ -357,7 +383,11 @@ SetVisibility(int theVisibility)
   myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
 
-  myVertexActor->SetVisibility(theVisibility && myVerticesMode && (!myIsSelected && !myIsPreselected));// must be added new mode points
+  myVertexActor->SetVisibility(theVisibility && (isOnlyVertex || (myVerticesMode && (!myIsSelected && !myIsPreselected))));// must be added new mode points
+
+  myStandaloneVertexActor->SetVisibility(theVisibility);
+
+  myTextActor->SetVisibility( theVisibility && myNameMode );
 }
  
 
@@ -398,8 +428,11 @@ GEOM_Actor
 ::SetVerticesMode(bool theMode)
 {
   myVerticesMode = theMode;
-  theMode ? myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2) : myPreHighlightProp->SetPointSize(0);
-  theMode ? myHighlightProp->SetPointSize(SALOME_POINT_SIZE) : myHighlightProp->SetPointSize(0);
+  if ( theMode || isOnlyVertex ) {
+    myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort()); 
+  } else {
+    myAppendFilter->RemoveInputConnection(0, myVertexSource->GetOutputPort()); 
+  }
   SetModified();
 }
 
@@ -410,27 +443,62 @@ GEOM_Actor
   return myVerticesMode;
 }
 
+void
+GEOM_Actor
+::SetShapeName()
+{
+  if( !getIO() || myShape.IsNull() )
+    return;
+
+  gp_Ax3 anAx3 = GEOMUtils::GetPosition(myShape);
+  double center[3] = { anAx3.Location().X(),
+                       anAx3.Location().Y(),
+                       anAx3.Location().Z() };
+  double* pos = center;
+  myTextActor->GetTextProperty()->SetFontSize( 16 );
+  myTextActor->GetTextProperty()->ShadowOn();
+  myTextActor->GetPositionCoordinate()->SetCoordinateSystemToWorld();
+  myTextActor->GetPositionCoordinate()->SetValue(pos);
+  myTextActor->SetInput( getIO()->getName() );
+}
+
+void
+GEOM_Actor
+::SetNameMode(bool theMode)
+{
+  myNameMode = theMode;
+  myTextActor->SetVisibility(theMode);
+  SetModified();
+}
+
+bool
+GEOM_Actor
+::GetNameMode()
+{
+  return myNameMode;
+}
+
 void  
 GEOM_Actor:: 
-SetDeflection(float theDeflection) 
+SetDeflection(double theDeflection) 
 { 
-  if( myDeflection == theDeflection ) 
-    return;
-    
-  myDeflection = theDeflection; 
-  GEOM::MeshShape(myShape,myDeflection);
-  
-  SetModified(); 
+  double aDeflection = ( theDeflection <= 0 ) ? GEOMUtils::DefaultDeflection() : theDeflection;
+
+  if ( myDeflection != aDeflection ) {
+    myDeflection = aDeflection; 
+    GEOMUtils::MeshShape( myShape, myDeflection );
+    SetModified(); 
+  }
 }
 
 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
-                           float theDeflection,
+                           double theDeflection,
                            bool theIsVector)
 {
   myShape = theShape;
 
   myVertexSource->Clear();
+  myStandaloneVertexSource->Clear();
   myIsolatedEdgeSource->Clear();
   myOneFaceEdgeSource->Clear();
   mySharedEdgeSource->Clear();
@@ -450,12 +518,13 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
   
-  GEOM::SetShape(theShape,anEdgeMap,theIsVector,
-                 myIsolatedEdgeSource.Get(),
-                 myOneFaceEdgeSource.Get(),
-                 mySharedEdgeSource.Get(),
-                 myWireframeFaceSource.Get(),
-                 myShadingFaceSource.Get());
+  GEOM::ShapeToVTK(theShape,anEdgeMap,theIsVector,
+                   myStandaloneVertexSource.Get(),
+                   myIsolatedEdgeSource.Get(),
+                   myOneFaceEdgeSource.Get(),
+                   mySharedEdgeSource.Get(),
+                   myWireframeFaceSource.Get(),
+                   myShadingFaceSource.Get());
   isOnlyVertex =  
     myIsolatedEdgeSource->IsEmpty() &&
     myOneFaceEdgeSource->IsEmpty() &&
@@ -466,22 +535,16 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
   
   if((bool)myShape.Infinite() || isOnlyVertex ){
     myVertexActor->GetDeviceActor()->SetInfinitive(true);
+    myStandaloneVertexActor->GetDeviceActor()->SetInfinitive(true);
     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
   }
 
+  SetShapeName();
+
   // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
   myAppendFilter->Update();
 }
 
-// OLD METHODS
-void GEOM_Actor::setDeflection(double adef) {
-#ifdef MYDEBUG
-  MESSAGE ( "GEOM_Actor::setDeflection" );
-#endif
-  SetDeflection((float)adef);
-}
-
-
 // warning! must be checked!
 // SetHighlightProperty
 // SetWireframeProperty
@@ -521,6 +584,11 @@ vtkProperty* GEOM_Actor::GetVertexProperty()
   return myVertexActor->GetProperty();
 }
 
+vtkProperty* GEOM_Actor::GetStandaloneVertexProperty()
+{
+  return myStandaloneVertexActor->GetProperty();
+}
+
 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
 {
   return mySharedEdgeActor->GetProperty();
@@ -663,15 +731,6 @@ void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
 #endif
 }
 
-double GEOM_Actor::getDeflection()
-{
-#ifdef MYDEBUG
-  MESSAGE ( "GEOM_Actor::getDeflection" );
-#endif
-  return (double) GetDeflection();
-}
-
-
 double GEOM_Actor::isVector()
 {
 #ifdef MYDEBUG
@@ -710,6 +769,7 @@ void GEOM_Actor::SetOpacity(double opa)
   myHighlightProp->SetOpacity(opa);
   myPreHighlightProp->SetOpacity(opa);
   myVertexActor->GetProperty()->SetOpacity(opa);
+  myStandaloneVertexActor->GetProperty()->SetOpacity(opa);
 }
 
 double GEOM_Actor::GetOpacity()
@@ -750,6 +810,7 @@ void GEOM_Actor::GetColor(double& r,double& g,double& b)
 void GEOM_Actor::SetPointColor(double r,  double g,  double b)
 {
   myVertexActor->GetProperty()->SetColor(r, g, b);
+  myStandaloneVertexActor->GetProperty()->SetColor(r, g, b);
 }
 
 /*!
@@ -796,6 +857,15 @@ void GEOM_Actor::SetIsosColor(double r, double g, double b)
   myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
 }
 
+/*!
+  \brief Set color of labels
+  This actor is shown only if 'Show name' is switched-on, see SetVisibility()
+*/
+void GEOM_Actor::SetLabelColor(double r, double g, double b)
+{
+  myTextActor->GetTextProperty()->SetColor(r, g, b);
+}
+
 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
 {
   // we set material properties as back and front material
@@ -813,6 +883,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aCoefnt = theProps[0]->GetAmbient();
   myShadingFaceProp->SetAmbient(aCoefnt);
   myVertexActor->GetProperty()->SetAmbient(aCoefnt);
+  myStandaloneVertexActor->GetProperty()->SetAmbient(aCoefnt);
   if ( aSize == 2 )
     aCoefnt = theProps[1]->GetAmbient();
   myShadingBackFaceProp->SetAmbient(aCoefnt);
@@ -821,6 +892,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aCoefnt = theProps[0]->GetDiffuse();
   myShadingFaceProp->SetDiffuse(aCoefnt);
   myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
+  myStandaloneVertexActor->GetProperty()->SetDiffuse(aCoefnt);
   if ( aSize == 2 )
     aCoefnt = theProps[1]->GetDiffuse();
   myShadingBackFaceProp->SetDiffuse(aCoefnt);
@@ -829,6 +901,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aCoefnt = theProps[0]->GetSpecular();
   myShadingFaceProp->SetSpecular(aCoefnt);
   myVertexActor->GetProperty()->SetSpecular(aCoefnt);
+  myStandaloneVertexActor->GetProperty()->SetSpecular(aCoefnt);
   if ( aSize == 2 )
     aCoefnt = theProps[1]->GetSpecular();
   myShadingBackFaceProp->SetSpecular(aCoefnt);
@@ -840,6 +913,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aColor = theProps[0]->GetAmbientColor();
   myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
   myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
+  myStandaloneVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
   if ( aSize == 2 )
     aColor = theProps[1]->GetAmbientColor();
   myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
@@ -848,6 +922,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aColor = theProps[0]->GetDiffuseColor();
   myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
   myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
+  myStandaloneVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
   if ( aSize == 2 )
     aColor = theProps[1]->GetDiffuseColor();
   myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
@@ -856,6 +931,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aColor = theProps[0]->GetSpecularColor();
   myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
   myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
+  myStandaloneVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
   if ( aSize == 2 )
     aColor = theProps[1]->GetSpecularColor();
   myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
@@ -864,6 +940,7 @@ void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
   aCoefnt = theProps[0]->GetSpecularPower();
   myShadingFaceProp->SetSpecularPower(aCoefnt);
   myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
+  myStandaloneVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
   if ( aSize == 2 )
     aCoefnt = theProps[1]->GetSpecularPower();
   myShadingBackFaceProp->SetSpecularPower(aCoefnt);