From 494cae92368d8ad49b1cd4a15200d4921d65af1e Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 4 Feb 2014 13:06:14 +0000 Subject: [PATCH] 22359: Body Fitting algorithm: grid orientation Add labels to arrows --- src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx | 73 ++++++++++++++++++----- src/SMESHGUI/SMESHGUI_MeshEditPreview.h | 16 ++--- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx index f80c0dc52..ea861e8ed 100644 --- a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx @@ -28,23 +28,26 @@ #include "SMESHGUI_MeshEditPreview.h" #include "SMESHGUI_VTKUtils.h" - -#include -#include +#include "SMESH_Actor.h" +#include "SMESH_ActorUtils.h" // SALOME GUI includes -#include +#include #include +#include // VTK includes -#include -#include #include -#include -#include -#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include // Qt includes #include @@ -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(); } diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.h b/src/SMESHGUI/SMESHGUI_MeshEditPreview.h index 7091999f3..7d68f921b 100644 --- a/src/SMESHGUI/SMESHGUI_MeshEditPreview.h +++ b/src/SMESHGUI/SMESHGUI_MeshEditPreview.h @@ -32,9 +32,10 @@ #include #include +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 myUnitArrowPnts; - int myNbArrows; + std::vector myUnitArrowPnts; + std::vector 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); -- 2.39.2