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 ) ) );
233 connect( myDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
236 SMESHGUI_SelectionOp::startOperation();
238 mySimulation = new SMESH::TNodeSimulation( viewWindow() );
242 //=================================================================================
245 //=================================================================================
246 void SMESHGUI_NodesOp::commitOperation()
251 SMESHGUI_SelectionOp::commitOperation();
254 //=================================================================================
257 //=================================================================================
258 void SMESHGUI_NodesOp::abortOperation()
263 SMESHGUI_SelectionOp::abortOperation();
266 //=================================================================================
269 //=================================================================================
270 void SMESHGUI_NodesOp::selectionDone()
275 mySimulation->SetVisibility(false);
276 SMESH::SetPointRepresentation(true);
278 const SALOME_ListIO& aList = selector()->StoredIObjects();
279 if (aList.Extent() == 1) {
280 Handle(SALOME_InteractiveObject) anIO = aList.First();
281 if (anIO->hasEntry()) {
282 myMesh = SMESH::GetMeshByIO(anIO);
283 if (myMesh->_is_nil()) return;
285 if (SMESH::GetNameOfSelectedNodes(selector(),anIO,aText) == 1) {
286 if (SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh.in())) {
287 if (SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh()) {
288 if (const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
289 myDlg->setCoords( aNode->X(), aNode->Y(), aNode->Z() );
295 myDlg->coords( x, y, z );
296 mySimulation->SetPosition( x, y, z );
301 //=================================================================================
304 //=================================================================================
305 void SMESHGUI_NodesOp::initDialog()
307 myDlg->setCoords( 0, 0, 0 );
310 //=================================================================================
313 //=================================================================================
314 bool SMESHGUI_NodesOp::onApply()
316 if( getSMESHGUI()->isActiveStudyLocked() || !mySimulation )
319 if (myMesh->_is_nil()) {
320 SUIT_MessageBox::warn1( myDlg, tr("SMESH_WRN_WARNING"),
321 tr("MESH_IS_NOT_SELECTED"), tr("SMESH_BUT_OK"));
325 double x, y, z; myDlg->coords( x, y, z );
326 mySimulation->SetVisibility(false);
327 SMESH::AddNode(myMesh,x,y,z);
328 SMESH::SetPointRepresentation(true);
332 selectionMgr()->selectedObjects(aList);
333 if (aList.Extent() != 1) {
334 if (SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView()) {
335 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
336 aCollection->InitTraversal();
337 while (vtkActor *anAct = aCollection->GetNextActor()) {
338 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
339 if (anActor->hasIO()) {
340 if (SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>(anActor->GetObject().get())) {
341 if (myMesh->_is_equivalent(aMeshObj->GetMeshServer())) {
343 aList.Append(anActor->getIO());
344 selectionMgr()->setSelectedObjects(aList, false);
356 //=================================================================================
359 //=================================================================================
360 void SMESHGUI_NodesOp::onValueChanged( double )
362 double vx, vy, vz; myDlg->coords( vx, vy, vz );
364 mySimulation->SetPosition( vx, vy, vz );