+#include "utilities.h"
+
+using namespace std;
+
+
+namespace SMESH{
+
+ void AddNode(SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z){
+ QAD_WaitCursor wc;
+ try{
+ SALOMEDS::SObject_var aSobj = SMESH::FindSObject(theMesh);
+ CORBA::String_var anEntry = aSobj->GetID();
+ SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
+ aMeshEditor->AddNode(x,y,z);
+ SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
+ CORBA::Long anId = aStudy->StudyId();
+ if(TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,anEntry.in())){
+ aVisualObj->Update(true);
+ }
+ }catch(SALOME::SALOME_Exception& exc) {
+ INFOS("Follow exception was cought:\n\t"<<exc.details.text);
+ }catch(const std::exception& exc){
+ INFOS("Follow exception was cought:\n\t"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was cought !!!");
+ }
+ }
+
+
+ class TNodeSimulation{
+ QAD_Study* myStudy;
+ QAD_StudyFrame* myStudyFrame;
+ VTKViewer_ViewFrame* myViewFrame;
+
+ SALOME_Actor *myPreviewActor;
+ vtkDataSetMapper* myMapper;
+ vtkPoints* myPoints;
+
+ public:
+
+ TNodeSimulation(QAD_Study* theStudy):
+ myStudy(theStudy),
+ myStudyFrame(theStudy->getActiveStudyFrame()),
+ myViewFrame(GetVtkViewFrame(theStudy->getActiveStudyFrame()))
+ {
+ vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
+
+ // Create points
+ myPoints = vtkPoints::New();
+ myPoints->SetNumberOfPoints( 1 );
+ myPoints->SetPoint(0,0.0,0.0,0.0);
+
+ // Create cells
+ vtkIdList *anIdList = vtkIdList::New();
+ anIdList->SetNumberOfIds( 1 );
+
+ vtkCellArray *aCells = vtkCellArray::New();
+ aCells->Allocate( 2, 0 );
+
+ vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+ aCellTypesArray->SetNumberOfComponents( 1 );
+ aCellTypesArray->Allocate( 1 );
+
+ anIdList->SetId( 0, 0 );
+ aCells->InsertNextCell( anIdList );
+ aCellTypesArray->InsertNextValue( VTK_VERTEX );
+
+ vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+ aCellLocationsArray->SetNumberOfComponents( 1 );
+ aCellLocationsArray->SetNumberOfTuples( 1 );
+
+ aCells->InitTraversal();
+ vtkIdType npts;
+ aCellLocationsArray->SetValue( 0, aCells->GetTraversalLocation( npts ) );
+
+ aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
+
+ aGrid->SetPoints( myPoints );
+ aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aCells );
+ aCellLocationsArray->Delete();
+ aCellTypesArray->Delete();
+ aCells->Delete();
+ anIdList->Delete();
+
+ // Create and display actor
+ myMapper = vtkDataSetMapper::New();
+ myMapper->SetInput( aGrid );
+ aGrid->Delete();
+
+ myPreviewActor = SALOME_Actor::New();
+ myPreviewActor->SetInfinitive(true);
+ myPreviewActor->VisibilityOff();
+ myPreviewActor->PickableOff();
+ myPreviewActor->SetMapper( myMapper );
+
+ vtkProperty* aProp = vtkProperty::New();
+ aProp->SetRepresentationToPoints();
+
+ float anRGB[3];
+ anRGB[0] = GetFloat("SMESH:SettingsNodeColorRed",0)/255.;
+ anRGB[1] = GetFloat("SMESH:SettingsNodeColorGreen",255)/255.;
+ anRGB[2] = GetFloat("SMESH:SettingsNodeColorBlue",0)/255.;
+ aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
+
+ float aPointSize = GetFloat("SMESH:SettingsNodesSize",3);
+ aProp->SetPointSize(aPointSize);
+
+ myPreviewActor->SetProperty( aProp );
+ aProp->Delete();
+
+ myViewFrame->AddActor( myPreviewActor );
+
+ }
+
+
+ void SetPosition(float x, float y, float z){
+ myPoints->SetPoint(0,x,y,z);
+ myPoints->Modified();
+ SetVisibility(true);
+ }
+
+
+ void SetVisibility(bool theVisibility){
+ myPreviewActor->SetVisibility(theVisibility);
+ RepaintCurrentView();
+ }
+
+
+ ~TNodeSimulation(){
+ if(FindVtkViewFrame(myStudy,myStudyFrame)){
+ myViewFrame->RemoveActor(myPreviewActor);
+ }
+ myPreviewActor->Delete();
+
+ myMapper->RemoveAllInputs();
+ myMapper->Delete();
+
+ myPoints->Delete();
+ }
+
+ };
+
+}
+