Salome HOME
untabify
[modules/smesh.git] / src / OBJECT / SMESH_NodeLabelActor.cxx
index 51c913585c4f634ce9504e93505e5091d4f38bd6..b3a8d3d0f8d4a72012ae854136a5b3d260b3d45a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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
@@ -37,7 +37,7 @@
 #include <vtkPointData.h>
 #include <vtkProperty2D.h>
 #include <vtkRenderer.h>
-#include <vtkPolyData.h>
+#include <vtkUnstructuredGrid.h>
 
 vtkStandardNewMacro(SMESH_NodeLabelActor);
 
@@ -47,7 +47,7 @@ vtkStandardNewMacro(SMESH_NodeLabelActor);
 SMESH_NodeLabelActor::SMESH_NodeLabelActor() {
   //Definition of points numbering pipeline
   //---------------------------------------
-  myPointsNumDataSet = vtkPolyData::New();
+  myPointsNumDataSet = vtkUnstructuredGrid::New();
 
   myPtsMaskPoints = vtkMaskPoints::New();
   myPtsMaskPoints->SetInput(myPointsNumDataSet);
@@ -63,21 +63,19 @@ SMESH_NodeLabelActor::SMESH_NodeLabelActor() {
   myPtsLabeledDataMapper->SetLabelFormat("%d");
   myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
     
-  vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
-  aPtsTextProp->SetFontFamilyToTimes();
-  static int aPointsFontSize = 10;
-  aPtsTextProp->SetFontSize(aPointsFontSize);
-  aPtsTextProp->SetBold(1);
-  aPtsTextProp->SetItalic(0);
-  aPtsTextProp->SetShadow(0);
-  myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
-  aPtsTextProp->Delete();
+  myPtsTextProp = vtkTextProperty::New();
+  myPtsTextProp->SetFontFamilyToTimes();
+  myPtsTextProp->SetFontSize(10);
+  myPtsTextProp->SetBold(1);
+  myPtsTextProp->SetItalic(0);
+  myPtsTextProp->SetShadow(0);
+  myPtsTextProp->SetColor( 1, 1, 1 );
+  myPtsLabeledDataMapper->SetLabelTextProperty(myPtsTextProp);
 
   myIsPointsLabeled = false;
 
   myPointLabels = vtkActor2D::New();
   myPointLabels->SetMapper(myPtsLabeledDataMapper);
-  myPointLabels->GetProperty()->SetColor(1,1,1);
   myPointLabels->SetVisibility(myIsPointsLabeled);
 
   vtkCallbackCommand* callBackCommand = vtkCallbackCommand::New();
@@ -85,7 +83,7 @@ SMESH_NodeLabelActor::SMESH_NodeLabelActor() {
   callBackCommand->SetCallback(SMESH_NodeLabelActor::ProcessEvents);
 
   myTransformFilter->AddObserver("VTKViewer_TransformFilter::TransformationFinished",
-                                callBackCommand);
+                                 callBackCommand);
   callBackCommand->Delete();
 }
 
@@ -109,12 +107,32 @@ SMESH_NodeLabelActor::~SMESH_NodeLabelActor() {
   //  myPtsMaskPoints->UnRegisterAllOutputs();
   myPtsMaskPoints->Delete();
   myPointLabels->Delete();
+  myPtsTextProp->Delete();
+}
 
+void SMESH_NodeLabelActor::SetFontProperties( SMESH::LabelFont family, int size, 
+                                              bool bold, bool italic, bool shadow,
+                                              vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b )
+{
+  switch ( family ) {
+  case SMESH::FntArial:
+    myPtsTextProp->SetFontFamilyToArial(); break;
+  case SMESH::FntCourier:
+    myPtsTextProp->SetFontFamilyToCourier(); break;
+  case SMESH::FntTimes:
+  default:
+    myPtsTextProp->SetFontFamilyToTimes(); break;
+  }
+  myPtsTextProp->SetFontSize( size );
+  myPtsTextProp->SetBold( bold );
+  myPtsTextProp->SetItalic( italic );
+  myPtsTextProp->SetShadow( shadow ); 
+  myPtsTextProp->SetColor( r, g, b ); 
 }
 
 void SMESH_NodeLabelActor::SetPointsLabeled(bool theIsPointsLabeled) {
   myTransformFilter->Update();
-  vtkDataSet* aGrid = vtkPolyData::SafeDownCast(myTransformFilter->GetOutput());
+  vtkDataSet* aGrid = vtkUnstructuredGrid::SafeDownCast(myTransformFilter->GetOutput());
 
   if(!aGrid)
     return;
@@ -124,7 +142,7 @@ void SMESH_NodeLabelActor::SetPointsLabeled(bool theIsPointsLabeled) {
   if ( myIsPointsLabeled )
   {
     myPointsNumDataSet->ShallowCopy(aGrid);
-    vtkDataSet *aDataSet = myPointsNumDataSet;
+    vtkUnstructuredGrid *aDataSet = myPointsNumDataSet;
     
     int aNbElem = aDataSet->GetNumberOfPoints();
     
@@ -133,7 +151,7 @@ void SMESH_NodeLabelActor::SetPointsLabeled(bool theIsPointsLabeled) {
     
     for ( vtkIdType anId = 0; anId < aNbElem; anId++ )
     {
-      int aSMDSId = GetNodeObjId( anId );
+      int aSMDSId = myVisualObj->GetNodeObjId( anId );
       anArray->SetValue( anId, aSMDSId );
     }
     
@@ -178,9 +196,9 @@ void SMESH_NodeLabelActor::UpdateLabels() {
 
 
 void SMESH_NodeLabelActor::ProcessEvents(vtkObject* vtkNotUsed(theObject),
-                                        unsigned long theEvent,
-                                        void* theClientData,
-                                        void* vtkNotUsed(theCallData)) {
+                                         unsigned long theEvent,
+                                         void* theClientData,
+                                         void* vtkNotUsed(theCallData)) {
   SMESH_NodeLabelActor* self = reinterpret_cast<SMESH_NodeLabelActor*>(theClientData);    
   if(self)
     self->UpdateLabels();