1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_NodesOp.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_NodesOp.h"
30 #include <SMESHGUI_NodesDlg.h>
31 #include <SMESHGUI_Utils.h>
32 #include <SMESHGUI_VTKUtils.h>
33 #include <SMESHGUI_MeshUtils.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMESH_Actor.h>
38 #include <SMESH_ObjectDef.h>
40 #include <SalomeApp_SelectionMgr.h>
42 #include <SALOME_ListIO.hxx>
44 #include <SUIT_OverrideCursor.h>
45 #include <SUIT_MessageBox.h>
47 #include <SVTK_ViewWindow.h>
48 #include <SVTK_Selector.h>
50 #include <SMDS_Mesh.hxx>
51 #include <SMDS_MeshNode.hxx>
53 #include "utilities.h"
55 #include <vtkDataSetMapper.h>
56 #include <vtkPoints.h>
57 #include <vtkUnstructuredGrid.h>
58 #include <vtkUnsignedCharArray.h>
59 #include <vtkIntArray.h>
60 #include <vtkIdList.h>
61 #include <vtkCellArray.h>
62 #include <vtkActorCollection.h>
63 #include <vtkRenderer.h>
67 void AddNode (SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z)
69 SUIT_OverrideCursor wc;
71 _PTR(SObject) aSobj = SMESH::FindSObject(theMesh);
72 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
73 aMeshEditor->AddNode(x,y,z);
74 _PTR(Study) aStudy = GetActiveStudyDocument();
75 CORBA::Long anId = aStudy->StudyId();
76 if (TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, aSobj->GetID().c_str())) {
77 aVisualObj->Update(true);
79 } catch (SALOME::SALOME_Exception& exc) {
80 INFOS("Follow exception was cought:\n\t" << exc.details.text);
81 } catch (const std::exception& exc) {
82 INFOS("Follow exception was cought:\n\t" << exc.what());
84 INFOS("Unknown exception was cought !!!");
88 class TNodeSimulation {
89 SVTK_ViewWindow* myViewWindow;
91 SALOME_Actor *myPreviewActor;
92 vtkDataSetMapper* myMapper;
96 TNodeSimulation(SVTK_ViewWindow* theViewWindow):
97 myViewWindow(theViewWindow)
99 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
102 myPoints = vtkPoints::New();
103 myPoints->SetNumberOfPoints(1);
104 myPoints->SetPoint(0,0.0,0.0,0.0);
107 vtkIdList *anIdList = vtkIdList::New();
108 anIdList->SetNumberOfIds(1);
110 vtkCellArray *aCells = vtkCellArray::New();
111 aCells->Allocate(2, 0);
113 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
114 aCellTypesArray->SetNumberOfComponents(1);
115 aCellTypesArray->Allocate(1);
117 anIdList->SetId(0, 0);
118 aCells->InsertNextCell(anIdList);
119 aCellTypesArray->InsertNextValue(VTK_VERTEX);
121 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
122 aCellLocationsArray->SetNumberOfComponents(1);
123 aCellLocationsArray->SetNumberOfTuples(1);
125 aCells->InitTraversal();
127 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
129 aGrid->SetCells(aCellTypesArray, aCellLocationsArray, aCells);
131 aGrid->SetPoints(myPoints);
132 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aCells);
133 aCellLocationsArray->Delete();
134 aCellTypesArray->Delete();
138 // Create and display actor
139 myMapper = vtkDataSetMapper::New();
140 myMapper->SetInput(aGrid);
143 myPreviewActor = SALOME_Actor::New();
144 myPreviewActor->SetInfinitive(true);
145 myPreviewActor->VisibilityOff();
146 myPreviewActor->PickableOff();
147 myPreviewActor->SetMapper(myMapper);
149 vtkProperty* aProp = vtkProperty::New();
150 aProp->SetRepresentationToPoints();
153 GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
154 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
156 float aPointSize = GetFloat( "SMESH:node_size", 3 );
157 aProp->SetPointSize( aPointSize );
159 myPreviewActor->SetProperty( aProp );
162 myViewWindow->AddActor(myPreviewActor);
165 void SetPosition (float x, float y, float z)
167 myPoints->SetPoint(0,x,y,z);
168 myPoints->Modified();
172 void SetVisibility (bool theVisibility)
174 myPreviewActor->SetVisibility(theVisibility);
175 RepaintCurrentView();
180 SetVisibility( false );
181 myViewWindow->RemoveActor(myPreviewActor);
182 myPreviewActor->Delete();
184 myMapper->RemoveAllInputs();
193 //=================================================================================
196 //=================================================================================
197 SMESHGUI_NodesOp::SMESHGUI_NodesOp()
198 : SMESHGUI_SelectionOp( NodeSelection ),
204 //=================================================================================
207 //=================================================================================
208 SMESHGUI_NodesOp::~SMESHGUI_NodesOp()
214 //=================================================================================
217 //=================================================================================
218 SalomeApp_Dialog* SMESHGUI_NodesOp::dlg() const
223 //=================================================================================
226 //=================================================================================
227 void SMESHGUI_NodesOp::startOperation()
231 myDlg = new SMESHGUI_NodesDlg();
232 connect( myDlg, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
235 SMESHGUI_SelectionOp::startOperation();
237 mySimulation = new SMESH::TNodeSimulation( viewWindow() );
241 //=================================================================================
244 //=================================================================================
245 void SMESHGUI_NodesOp::commitOperation()
250 SMESHGUI_SelectionOp::commitOperation();
253 //=================================================================================
256 //=================================================================================
257 void SMESHGUI_NodesOp::abortOperation()
262 SMESHGUI_SelectionOp::abortOperation();
265 //=================================================================================
268 //=================================================================================
269 void SMESHGUI_NodesOp::selectionDone()
274 mySimulation->SetVisibility(false);
275 SMESH::SetPointRepresentation(true);
277 const SALOME_ListIO& aList = selector()->StoredIObjects();
278 if (aList.Extent() == 1)
280 Handle(SALOME_InteractiveObject) anIO = aList.First();
281 if (anIO->hasEntry())
284 if( SMESH::GetNameOfSelectedNodes( selector(), anIO, aText ) == 1 )
285 if( SMESH_Actor* anActor = actor() )
286 if( SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh() )
287 if( const SMDS_MeshNode* aNode = aMesh->FindNode( aText.toInt() ) )
288 myDlg->setCoords( aNode->X(), aNode->Y(), aNode->Z() );
293 myDlg->coords( x, y, z );
294 mySimulation->SetPosition( x, y, z );
297 //=================================================================================
300 //=================================================================================
301 void SMESHGUI_NodesOp::initDialog()
303 myDlg->setCoords( 0, 0, 0 );
306 //=================================================================================
309 //=================================================================================
310 bool SMESHGUI_NodesOp::onApply()
312 if( isStudyLocked() || !mySimulation )
315 if( mesh()->_is_nil()) {
316 SUIT_MessageBox::warn1( myDlg, tr("SMESH_WRN_WARNING"),
317 tr("MESH_IS_NOT_SELECTED"), tr("SMESH_BUT_OK"));
321 double x, y, z; myDlg->coords( x, y, z );
322 mySimulation->SetVisibility(false);
323 SMESH::AddNode( mesh(), x, y, z );
324 SMESH::SetPointRepresentation(true);
328 selectionMgr()->selectedObjects(aList);
329 if (aList.Extent() != 1) {
330 if (SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView()) {
331 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
332 aCollection->InitTraversal();
333 while (vtkActor *anAct = aCollection->GetNextActor()) {
334 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
335 if (anActor->hasIO()) {
336 if (SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>(anActor->GetObject().get())) {
337 if ( mesh()->_is_equivalent(aMeshObj->GetMeshServer())) {
339 aList.Append(anActor->getIO());
340 selectionMgr()->setSelectedObjects(aList, false);
352 //=================================================================================
355 //=================================================================================
356 void SMESHGUI_NodesOp::onValueChanged( double )
358 double vx, vy, vz; myDlg->coords( vx, vy, vz );
360 mySimulation->SetPosition( vx, vy, vz );