+#include <qheader.h>
+
+using namespace std;
+
+namespace SMESH {
+ class TIdPreview { // to display in the viewer IDs of the selected elements
+ SVTK_ViewWindow* myViewWindow;
+
+ vtkUnstructuredGrid* myIdGrid;
+ SALOME_Actor* myIdActor;
+
+ vtkUnstructuredGrid* myPointsNumDataSet;
+ vtkMaskPoints* myPtsMaskPoints;
+ vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
+ vtkLabeledDataMapper* myPtsLabeledDataMapper;
+ vtkTextProperty* aPtsTextProp;
+ bool myIsPointsLabeled;
+ vtkActor2D* myPointLabels;
+
+ vector<int> myIDs;
+
+ public:
+ TIdPreview(SVTK_ViewWindow* theViewWindow):
+ myViewWindow(theViewWindow)
+ {
+ myIdGrid = vtkUnstructuredGrid::New();
+
+ // Create and display actor
+ vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
+ aMapper->SetInput( myIdGrid );
+
+ myIdActor = SALOME_Actor::New();
+ myIdActor->SetInfinitive(true);
+ myIdActor->VisibilityOff();
+ myIdActor->PickableOff();
+
+ myIdActor->SetMapper( aMapper );
+ aMapper->Delete();
+
+ myViewWindow->AddActor(myIdActor);
+
+ //Definition of points numbering pipeline
+ myPointsNumDataSet = vtkUnstructuredGrid::New();
+
+ myPtsMaskPoints = vtkMaskPoints::New();
+ myPtsMaskPoints->SetInput(myPointsNumDataSet);
+ myPtsMaskPoints->SetOnRatio(1);
+
+ myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
+ myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
+ myPtsSelectVisiblePoints->SelectInvisibleOff();
+ myPtsSelectVisiblePoints->SetTolerance(0.1);
+
+ myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
+ myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
+ myPtsLabeledDataMapper->SetLabelFormat("%g");
+ myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
+
+ vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
+ aPtsTextProp->SetFontFamilyToTimes();
+ static int aPointsFontSize = 12;
+ aPtsTextProp->SetFontSize(aPointsFontSize);
+ aPtsTextProp->SetBold(1);
+ aPtsTextProp->SetItalic(0);
+ aPtsTextProp->SetShadow(0);
+ myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
+ aPtsTextProp->Delete();
+
+ myIsPointsLabeled = false;
+
+ myPointLabels = vtkActor2D::New();
+ myPointLabels->SetMapper(myPtsLabeledDataMapper);
+ myPointLabels->GetProperty()->SetColor(1,1,1);
+ myPointLabels->SetVisibility(myIsPointsLabeled);
+
+ AddToRender(myViewWindow->getRenderer());
+ }
+
+ void SetPointsData ( SMDS_Mesh* theMesh,
+ TColStd_MapOfInteger & theNodesIdMap )
+ {
+ vtkPoints* aPoints = vtkPoints::New();
+ aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
+ myIDs.clear();
+
+ TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
+ for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
+ const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
+ aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
+ myIDs.push_back(idIter.Key());
+ }
+
+ myIdGrid->SetPoints(aPoints);
+
+ aPoints->Delete();
+
+ myIdActor->GetMapper()->Update();
+ }
+
+ void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
+ list<gp_XYZ> & aGrCentersXYZ )
+ {
+ vtkPoints* aPoints = vtkPoints::New();
+ aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
+ myIDs.clear();
+
+ TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
+ for( ; idIter.More(); idIter.Next() ) {
+ myIDs.push_back(idIter.Key());
+ }
+
+ gp_XYZ aXYZ;
+ list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
+ for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
+ aXYZ = *coordIt;
+ aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
+ }
+ myIdGrid->SetPoints(aPoints);
+ aPoints->Delete();
+
+ myIdActor->GetMapper()->Update();
+ }
+
+ void AddToRender(vtkRenderer* theRenderer)
+ {
+ myIdActor->AddToRender(theRenderer);
+
+ myPtsSelectVisiblePoints->SetRenderer(theRenderer);
+ theRenderer->AddActor2D(myPointLabels);
+ }
+
+ void RemoveFromRender(vtkRenderer* theRenderer)
+ {
+ myIdActor->RemoveFromRender(theRenderer);
+
+ myPtsSelectVisiblePoints->SetRenderer(theRenderer);
+ theRenderer->RemoveActor(myPointLabels);
+ }
+
+ void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
+ {
+ myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
+
+ if ( myIsPointsLabeled ) {
+ myPointsNumDataSet->ShallowCopy(myIdGrid);
+ vtkDataSet *aDataSet = myPointsNumDataSet;
+ int aNbElem = myIDs.size();
+ vtkIntArray *anArray = vtkIntArray::New();
+ anArray->SetNumberOfValues( aNbElem );
+ for ( int i = 0; i < aNbElem; i++ )
+ anArray->SetValue( i, myIDs[i] );
+ aDataSet->GetPointData()->SetScalars( anArray );
+ anArray->Delete();
+ myPtsMaskPoints->SetInput( aDataSet );
+ myPointLabels->SetVisibility( theIsActorVisible );
+ }
+ else {
+ myPointLabels->SetVisibility( false );
+ }
+ }
+
+ ~TIdPreview()
+ {
+ RemoveFromRender(myViewWindow->getRenderer());
+
+ myIdGrid->Delete();
+
+ myViewWindow->RemoveActor(myIdActor);
+ myIdActor->Delete();
+
+ //Deleting of points numbering pipeline
+ //---------------------------------------
+ myPointsNumDataSet->Delete();
+
+ myPtsLabeledDataMapper->RemoveAllInputs();
+ myPtsLabeledDataMapper->Delete();
+
+ myPtsSelectVisiblePoints->UnRegisterAllOutputs();
+ myPtsSelectVisiblePoints->Delete();
+
+ myPtsMaskPoints->UnRegisterAllOutputs();
+ myPtsMaskPoints->Delete();
+
+ myPointLabels->Delete();
+
+// myTimeStamp->Delete();
+ }
+ };
+}
+
+static const char * IconFirst[] = {
+"18 10 2 1",
+" g None",
+". g #000000",
+" . . ",
+" .. .. .. ",
+" .. ... ... ",
+" .. .... .... ",
+" .. ..... ..... ",
+" .. ..... ..... ",
+" .. .... .... ",
+" .. ... ... ",
+" .. .. .. ",
+" . . "};