]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/OBJECT/GEOM_Actor.cxx
Salome HOME
Fix compilation error and some warnings
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
index 1b15c5640c22aff2c3c818de23fec8276ea4c033..422f2b740d837be3cd970ab6e63952537b7fe63b 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,6 +87,7 @@ GEOM_Actor::GEOM_Actor():
   myIsSelected(false), 
   myVectorMode(false),
   myVerticesMode(false),
+  myNameMode(false),
 
   myVertexActor(GEOM_DeviceActor::New(),true), 
   myVertexSource(GEOM_VertexSource::New(),true), 
@@ -106,18 +111,21 @@ GEOM_Actor::GEOM_Actor():
   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
  
   myHighlightActor(GEOM_DeviceActor::New(),true), 
+
+  myTextActor( vtkTextActor::New() ),
+
+  myHighlightProp(vtkProperty::New()),
+  myPreHighlightProp(vtkProperty::New()),
+  myShadingFaceProp(vtkProperty::New()),
+  myShadingBackFaceProp(vtkProperty::New()),
+
   myAppendFilter(vtkAppendPolyData::New(),true), 
   // Use mapper as an instance of GEOM_PainterPolyDataMapper class
   // to prevent drawing of mappers' content (due to an empty definition
   // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
   // !!! Presentation of GEOM_Actor is drawing only with help of actors
   // defined in this class !!!
-  myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
-
-  myHighlightProp(vtkProperty::New()),
-  myPreHighlightProp(vtkProperty::New()),
-  myShadingFaceProp(vtkProperty::New()),
-  myShadingBackFaceProp(vtkProperty::New())
+  myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true)
 { 
 #ifdef MYDEBUG
   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
@@ -201,6 +209,7 @@ GEOM_Actor::GEOM_Actor():
   setDisplayMode(0); // WIRE FRAME
   SetVectorMode(0);  //
   SetVerticesMode(0);  //
+  SetNameMode(0); 
 } 
  
  
@@ -209,6 +218,7 @@ GEOM_Actor::~GEOM_Actor()
 #ifdef MYDEBUG
   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
 #endif
+  myTextActor->Delete();
   myHighlightProp->Delete();
   myPreHighlightProp->Delete();
   myShadingFaceProp->Delete();
@@ -245,6 +255,7 @@ SetModified()
   this->mySharedEdgeSource->Modified(); 
   this->myWireframeFaceSource->Modified(); 
   this->myShadingFaceSource->Modified(); 
+  this->myTextActor->Modified();
 } 
 
 void  
@@ -274,6 +285,8 @@ AddToRender(vtkRenderer* theRenderer)
  
   myVertexActor->AddToRender(theRenderer); 
   myStandaloneVertexActor->AddToRender(theRenderer); 
+
+  theRenderer->AddActor( myTextActor );
 }
  
 void 
@@ -296,6 +309,7 @@ RemoveFromRender(vtkRenderer* theRenderer)
   myVertexActor->RemoveFromRender(theRenderer);
   myStandaloneVertexActor->RemoveFromRender(theRenderer);
 
+  theRenderer->RemoveActor( myTextActor );
   
   SetSelected(false);
   SetVisibility(false);
@@ -326,9 +340,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]);
@@ -373,6 +387,8 @@ SetVisibility(int theVisibility)
   myVertexActor->SetVisibility(theVisibility && (isOnlyVertex || (myVerticesMode && (!myIsSelected && !myIsPreselected))));// must be added new mode points
 
   myStandaloneVertexActor->SetVisibility(theVisibility);
+
+  myTextActor->SetVisibility( theVisibility && myNameMode );
 }
  
 
@@ -428,22 +444,56 @@ 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;
@@ -469,13 +519,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,
-                 myStandaloneVertexSource.Get(),
-                 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() &&
@@ -490,19 +540,12 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
     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
@@ -689,15 +732,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
@@ -824,6 +858,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