Salome HOME
22359: Body Fitting algorithm: grid orientation
authoreap <eap@opencascade.com>
Tue, 4 Feb 2014 13:06:14 +0000 (13:06 +0000)
committereap <eap@opencascade.com>
Tue, 4 Feb 2014 13:06:14 +0000 (13:06 +0000)
Add labels to arrows

src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx
src/SMESHGUI/SMESHGUI_MeshEditPreview.h

index f80c0dc524c920be61a65379f7afbb6ecc6fd000..ea861e8ed811d2e1fb8222c6c54f52e3d2fec86e 100644 (file)
 #include "SMESHGUI_MeshEditPreview.h"
 
 #include "SMESHGUI_VTKUtils.h"
-
-#include <SMESH_Actor.h>
-#include <SMESH_ActorUtils.h>
+#include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
 
 // SALOME GUI includes
-#include <VTKViewer_CellLocationsArray.h>
+#include <SVTK_Renderer.h>
 #include <SVTK_ViewWindow.h>
+#include <VTKViewer_CellLocationsArray.h>
 
 // VTK includes
-#include <vtkPoints.h>
-#include <vtkIdList.h>
 #include <vtkCellArray.h>
-#include <vtkUnsignedCharArray.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkUnstructuredGridWriter.h>
+#include <vtkCoordinate.h>
 #include <vtkDataSetMapper.h>
+#include <vtkIdList.h>
+#include <vtkPoints.h>
 #include <vtkProperty.h>
+#include <vtkRenderer.h>
+#include <vtkTextActor.h>
+#include <vtkTextMapper.h>
+#include <vtkUnsignedCharArray.h>
+#include <vtkUnstructuredGrid.h>
 
 // Qt includes
 #include <QColor>
@@ -88,7 +91,6 @@ SMESHGUI_MeshEditPreview::SMESHGUI_MeshEditPreview(SVTK_ViewWindow* theViewWindo
   aMapper->Delete();
 
   myViewWindow->AddActor(myPreviewActor);
-
 }
 
 //================================================================================
@@ -104,6 +106,12 @@ SMESHGUI_MeshEditPreview::~SMESHGUI_MeshEditPreview()
   myViewWindow->RemoveActor(myPreviewActor);
   myPreviewActor->Delete();
 
+  for ( size_t iA = 0; iA < myLabelActors.size(); ++iA )
+    if ( myLabelActors[iA] )
+    {
+      myPreviewActor->GetRenderer()->RemoveActor( myLabelActors[iA] );
+      myLabelActors[iA]->Delete();
+    }
 }
 
 //================================================================================
@@ -232,10 +240,11 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD
  */
 //================================================================================
 
-void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int    nbArrows,
-                                                   double headLength,
-                                                   double headRadius,
-                                                   double start)
+void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int         nbArrows,
+                                                   double      headLength,
+                                                   double      headRadius,
+                                                   double      start,
+                                                   const char* labels)
 {
   const int theNbPoints = 10; // in one arrow
   myUnitArrowPnts.reserve( theNbPoints );
@@ -286,7 +295,28 @@ void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int    nbArrows,
     myGrid->InsertNextCell( VTK_LINE, 2, conn );
   }
 
-  myNbArrows = nbArrows;
+  myLabelActors.resize( nbArrows, ( vtkTextActor*) NULL );
+  char label[] = "X";
+  if ( labels )
+    for ( int iP = 0, iA = 0; iA < nbArrows; ++iA )
+    {
+      label[0] = labels[iA];
+      vtkTextMapper* text = vtkTextMapper::New();
+      text->SetInput( label );
+      vtkCoordinate* coord = vtkCoordinate::New();
+
+      myLabelActors[iA] = vtkTextActor::New();
+      //myLabelActors[iA]->SetMapper( text );
+      myLabelActors[iA]->SetInput( label );
+      myLabelActors[iA]->SetTextScaleModeToNone();
+      myLabelActors[iA]->PickableOff();
+      myLabelActors[iA]->GetPositionCoordinate()->SetReferenceCoordinate( coord );
+
+      text->Delete();
+      coord->Delete();
+
+      myPreviewActor->GetRenderer()->AddActor(myLabelActors[iA]);
+    }
 }
 
 //================================================================================
@@ -302,7 +332,7 @@ void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
 {
   vtkPoints* aPoints = myGrid->GetPoints();
 
-  for ( int iP = 0, iA = 0; iA < myNbArrows; ++iA )
+  for ( int iP = 0, iA = 0; iA < myLabelActors.size(); ++iA )
   {
     gp_Trsf trsf;
     trsf.SetTransformation( gp_Ax3( axes[iA].Location(), axes[iA].Direction() ), gp::XOY() );
@@ -313,6 +343,14 @@ void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
       p.Transform( trsf );
       aPoints->SetPoint( iP, p.X(), p.Y(), p.Z() );
     }
+    if ( myLabelActors[iA] )
+      if ( vtkCoordinate* aCoord =
+           myLabelActors[iA]->GetPositionCoordinate()->GetReferenceCoordinate() )
+      {
+        double p[3];
+        aPoints->GetPoint( iP-1, p );
+        aCoord->SetValue( p );
+      }
   }
 
   myGrid->Modified();
@@ -327,6 +365,9 @@ void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
 void SMESHGUI_MeshEditPreview::SetVisibility (bool theVisibility)
 {
   myPreviewActor->SetVisibility(theVisibility);
+  for ( size_t iA = 0; iA < myLabelActors.size(); ++iA )
+    if ( myLabelActors[iA] )
+      myLabelActors[iA]->SetVisibility(theVisibility);
   SMESH::RepaintCurrentView();
 }
 
index 7091999f35c9bde3d99af294e430e9fd78438341..7d68f921b053732ed84cfd795a1f0ea6a3b9fb0b 100644 (file)
 #include <gp_Ax1.hxx>
 #include <gp_Pnt.hxx>
 
+class SALOME_Actor;
 class SVTK_ViewWindow;
+class vtkTextActor;
 class vtkUnstructuredGrid;
-class SALOME_Actor;
 
 namespace SMESH
 {
@@ -51,8 +52,8 @@ class SMESHGUI_EXPORT SMESHGUI_MeshEditPreview
   vtkUnstructuredGrid* myGrid;
   SALOME_Actor*        myPreviewActor;
 
-  std::vector<gp_Pnt>  myUnitArrowPnts;
-  int                  myNbArrows;
+  std::vector<gp_Pnt>        myUnitArrowPnts;
+  std::vector<vtkTextActor*> myLabelActors;
 
 public:
   SMESHGUI_MeshEditPreview( SVTK_ViewWindow* );
@@ -63,10 +64,11 @@ public:
   void                 SetVisibility( bool );
   void                 SetColor( double, double, double );
 
-  void                 SetArrowShapeAndNb( int    nbArrows,
-                                           double headLength,
-                                           double headRadius,
-                                           double start=0.);
+  void                 SetArrowShapeAndNb( int         nbArrows,
+                                           double      headLength,
+                                           double      headRadius,
+                                           double      start=0.,
+                                           const char* labels=0);
   void                 SetArrows( const gp_Ax1* axes,
                                   double        length);