]> 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 47bc66b176d03b06d2c5c4c9ef2ea03f7a16e4fb..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>
@@ -82,10 +86,15 @@ GEOM_Actor::GEOM_Actor():
   //  myDisplayMode(eWireframe), 
   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), 
  
@@ -102,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");
@@ -129,13 +141,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(SALOME_POINT_SIZE);
+  myHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
 
   this->myHighlightActor->SetInput(myAppendFilter->GetOutputPort(),false);
 
   myPreHighlightProp->SetColor(0,1,1);
-  myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
+  myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE);
   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
   myPreHighlightProp->SetRepresentationToWireframe();
 
@@ -146,6 +158,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(); 
@@ -189,6 +208,8 @@ GEOM_Actor::GEOM_Actor():
   // Toggle display mode 
   setDisplayMode(0); // WIRE FRAME
   SetVectorMode(0);  //
+  SetVerticesMode(0);  //
+  SetNameMode(0); 
 } 
  
  
@@ -197,6 +218,7 @@ GEOM_Actor::~GEOM_Actor()
 #ifdef MYDEBUG
   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
 #endif
+  myTextActor->Delete();
   myHighlightProp->Delete();
   myPreHighlightProp->Delete();
   myShadingFaceProp->Delete();
@@ -227,11 +249,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  
@@ -260,6 +284,9 @@ AddToRender(vtkRenderer* theRenderer)
   myIsolatedEdgeActor->AddToRender(theRenderer); 
  
   myVertexActor->AddToRender(theRenderer); 
+  myStandaloneVertexActor->AddToRender(theRenderer); 
+
+  theRenderer->AddActor( myTextActor );
 }
  
 void 
@@ -280,7 +307,9 @@ RemoveFromRender(vtkRenderer* theRenderer)
   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
  
   myVertexActor->RemoveFromRender(theRenderer);
+  myStandaloneVertexActor->RemoveFromRender(theRenderer);
 
+  theRenderer->RemoveActor( myTextActor );
   
   SetSelected(false);
   SetVisibility(false);
@@ -311,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]);
@@ -355,7 +384,11 @@ SetVisibility(int theVisibility)
   myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
 
-  myVertexActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);// 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 );
 }
  
 
@@ -391,27 +424,82 @@ GEOM_Actor
   return myVectorMode;
 }
 
+void
+GEOM_Actor
+::SetVerticesMode(bool theMode)
+{
+  myVerticesMode = theMode;
+  if ( theMode || isOnlyVertex ) {
+    myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort()); 
+  } else {
+    myAppendFilter->RemoveInputConnection(0, myVertexSource->GetOutputPort()); 
+  }
+  SetModified();
+}
+
+bool
+GEOM_Actor
+::GetVerticesMode()
+{
+  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();
@@ -431,12 +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,
-                 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() &&
@@ -447,22 +536,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
@@ -502,6 +585,11 @@ vtkProperty* GEOM_Actor::GetVertexProperty()
   return myVertexActor->GetProperty();
 }
 
+vtkProperty* GEOM_Actor::GetStandaloneVertexProperty()
+{
+  return myStandaloneVertexActor->GetProperty();
+}
+
 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
 {
   return mySharedEdgeActor->GetProperty();
@@ -644,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
@@ -691,6 +770,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()
@@ -731,6 +811,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);
 }
 
 /*!
@@ -777,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
@@ -794,6 +884,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);
@@ -802,6 +893,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);
@@ -810,6 +902,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);
@@ -821,6 +914,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]);
@@ -829,6 +923,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]);
@@ -837,6 +932,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]);
@@ -845,6 +941,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);