1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHGUI_MakeNodeAtPointDlg.cxx
24 // Author : Edward AGAPOV, Open CASCADE S.A.S.
27 #include "SMESHGUI_RemoveNodeReconnectionDlg.h"
30 #include "SMESHGUI_IdValidator.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshEditPreview.h"
35 #include <SMDS_Mesh.hxx>
36 #include <SMESH_Actor.h>
37 #include <SMESH_ActorUtils.h>
38 #include <SMESH_LogicalFilter.hxx>
40 // SALOME GUI includes
41 #include <LightApp_SelectionMgr.h>
42 #include <SALOME_ListIO.hxx>
43 #include <SUIT_Desktop.h>
44 #include <SVTK_ViewModel.h>
45 #include <SVTK_ViewWindow.h>
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_TypeFilter.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_OverrideCursor.h>
50 #include <SUIT_MessageBox.h>
53 #include <QApplication>
55 #include <QGridLayout>
56 #include <QHBoxLayout>
57 #include <QVBoxLayout>
59 #include <QPushButton>
61 #include <QRadioButton>
63 #include <QButtonGroup>
66 #include <vtkProperty.h>
69 #include <SALOMEconfig.h>
70 #include CORBA_SERVER_HEADER(SMESH_Mesh)
71 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
76 //=======================================================================
78 * \brief Dialog to Remove a node with elements re-connection
80 //=======================================================================
82 SMESHGUI_RemoveNodeReconnectionDlg::SMESHGUI_RemoveNodeReconnectionDlg()
83 : SMESHGUI_Dialog( 0, false, true )
85 setWindowTitle(tr("CAPTION"));
87 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
88 aDlgLay->setMargin(0);
89 aDlgLay->setSpacing(SPACING);
90 myMainFrame = createMainFrame(mainFrame());
92 aDlgLay->addWidget(myMainFrame);
94 aDlgLay->setStretchFactor(myMainFrame, 1);
97 //=======================================================================
98 // function : createMainFrame()
99 // purpose : Create frame containing dialog's input fields
100 //=======================================================================
102 QWidget* SMESHGUI_RemoveNodeReconnectionDlg::createMainFrame (QWidget* theParent)
104 QWidget* aFrame = new QWidget(theParent);
108 myNodeToMoveGrp = new QGroupBox(tr("NODE_2REMOVE"), aFrame);
109 myNodeToMoveGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
110 QLabel* idLabel = new QLabel(tr("NODE_2REMOVE_ID"), myNodeToMoveGrp);
111 myId = new QLineEdit(myNodeToMoveGrp);
112 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
114 QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp);
115 myNodeToMoveGrpLayout->setSpacing(SPACING);
116 myNodeToMoveGrpLayout->setMargin(MARGIN);
118 myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 );
119 myNodeToMoveGrpLayout->addWidget( myId, 0, 2 );
123 myPreviewChkBox = new QCheckBox( tr("PREVIEW"), aFrame);
125 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
126 aLay->addWidget(myNodeToMoveGrp);
127 aLay->addWidget(myPreviewChkBox);
132 //================================================================================
136 //================================================================================
138 SMESHGUI_RemoveNodeReconnectionOp::SMESHGUI_RemoveNodeReconnectionOp()
142 myDlg = new SMESHGUI_RemoveNodeReconnectionDlg;
144 myHelpFileName = "removing_nodes_and_elements.html#removing-nodes-reconnect-anchor";
148 // connect signals and slots
149 connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
150 connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)), SLOT(redisplayPreview()));
151 connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
154 //=======================================================================
155 // function : startOperation()
156 // purpose : Init dialog fields, connect signals and slots, show dialog
157 //=======================================================================
159 void SMESHGUI_RemoveNodeReconnectionOp::startOperation()
164 // init simulation with a current View
165 if ( mySimulation ) delete mySimulation;
166 mySMESHGUI = getSMESHGUI();
167 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ) );
168 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
169 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
170 vtkProperty* aProp = vtkProperty::New();
171 aProp->SetRepresentationToWireframe();
172 aProp->SetColor(250, 0, 250);
173 aProp->SetPointSize(5);
174 aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
175 mySimulation->GetActor()->SetProperty(aProp);
178 // SalomeApp_TypeFilter depends on a current study
179 if ( myFilter ) delete myFilter;
180 // QList<SUIT_SelectionFilter*> filters;
181 // filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
182 // myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
185 SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
186 myDlg->myId->setText("");
190 onSelectionDone(); // init myMeshActor
193 //================================================================================
195 * \brief Stops operation
197 //================================================================================
199 void SMESHGUI_RemoveNodeReconnectionOp::stopOperation()
204 mySimulation->SetVisibility(false);
211 SMESH::SetPointRepresentation( false );
212 SMESH::RepaintCurrentView();
214 disconnect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
215 disconnect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
216 //selectionMgr()->removeFilter( myFilter );
217 SMESHGUI_SelectionOp::stopOperation();
220 //================================================================================
222 * \brief perform it's intention action: move or create a node
224 //================================================================================
226 bool SMESHGUI_RemoveNodeReconnectionOp::onApply()
228 if( SMESHGUI::isStudyLocked() )
231 if ( !myMeshActor ) {
232 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), tr("INVALID_MESH") );
238 if ( !isValid( msg ) ) { // node id is invalid
239 if ( !msg.isEmpty() )
240 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), tr("INVALID_ID") );
246 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( myMeshActor->getIO() );
247 if ( aMesh->_is_nil() )
249 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), tr("SMESHG_NO_MESH") );
252 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
253 if ( aMeshEditor->_is_nil() )
257 int anId = myDlg->myId->text().toInt( &ok );
258 myDlg->myId->setText( "" );
260 aMeshEditor->RemoveNodeWithReconnection( anId );
263 selectionMgr()->setSelectedObjects(aList,false);
264 aList.Append( myMeshActor->getIO() );
265 selectionMgr()->setSelectedObjects(aList,false);
267 SMESHGUI::Modified();
270 catch (const SALOME::SALOME_Exception& S_ex) {
271 SalomeApp_Tools::QtCatchCorbaException(S_ex);
279 //================================================================================
281 * \brief Check selected node id validity
283 //================================================================================
285 bool SMESHGUI_RemoveNodeReconnectionOp::isValid( QString& msg )
291 int id = myDlg->myId->text().toInt();
293 if ( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
294 ok = aMesh->FindNode( id );
296 msg += tr("INVALID_ID") + "\n";
302 //================================================================================
304 * \brief SLOT called when selection changed
306 //================================================================================
308 void SMESHGUI_RemoveNodeReconnectionOp::onSelectionDone()
310 if ( !myDlg->isVisible() || !myDlg->isEnabled() )
313 myDlg->myId->setText("");
318 selectionMgr()->selectedObjects( aList, SVTK_Viewer::Type() );
319 if ( aList.Extent() != 1)
321 Handle(SALOME_InteractiveObject) anIO = aList.First();
322 myMeshActor = SMESH::FindActorByEntry( anIO->getEntry() );
325 int nbElems = SMESH::GetNameOfSelectedElements( selector(), anIO, aString );
327 myDlg->myId->setText( aString );
336 //================================================================================
338 * \brief update preview
340 //================================================================================
342 void SMESHGUI_RemoveNodeReconnectionOp::redisplayPreview()
351 SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
354 if ( myMeshActor && isValid( msg ) && myDlg->myPreviewChkBox->isChecked() )
356 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( myMeshActor->getIO() );
357 if ( !aMesh->_is_nil() )
359 SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
360 if (!aPreviewer->_is_nil())
362 int anId = myDlg->myId->text().toInt();
363 aPreviewer->RemoveNodeWithReconnection( anId );
364 aMeshPreviewStruct = aPreviewer->GetPreviewData();
372 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
375 if ( & aMeshPreviewStruct.in() )
377 mySimulation->SetData( aMeshPreviewStruct.in() );
381 mySimulation->SetVisibility( false );
387 //=================================================================================
389 * \brief SLOT called when the viewer opened
391 //=================================================================================
393 void SMESHGUI_RemoveNodeReconnectionOp::onOpenView()
397 mySimulation->SetVisibility( false );
398 SMESH::SetPointRepresentation( false );
402 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
406 //=================================================================================
408 * \brief SLOT called when the viewer closed
410 //=================================================================================
412 void SMESHGUI_RemoveNodeReconnectionOp::onCloseView()
418 //================================================================================
420 * \brief SLOT called when the node id is manually changed
422 //================================================================================
424 void SMESHGUI_RemoveNodeReconnectionOp::onTextChange( const QString& theText )
428 if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
430 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
432 aList.Append( anIO );
433 selectionMgr()->setSelectedObjects( aList, false );
435 if ( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ))
437 SVTK_TVtkIDsMap aListInd;
438 aListInd.Add( FromSmIdType<int>( aNode->GetID()) );
439 selector()->AddOrRemoveIndex( anIO, aListInd, false );
440 if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
441 aViewWindow->highlight( anIO, true, true );
447 //================================================================================
449 * \brief Activate Node selection
451 //================================================================================
453 void SMESHGUI_RemoveNodeReconnectionOp::activateSelection()
455 selectionMgr()->clearFilters();
456 SMESH::SetPointRepresentation( true );
457 //selectionMgr()->installFilter( myFilter );
458 setSelectionMode( NodeSelection );
461 //================================================================================
465 //================================================================================
467 SMESHGUI_RemoveNodeReconnectionOp::~SMESHGUI_RemoveNodeReconnectionOp()
469 if ( myDlg ) delete myDlg;
470 if ( mySimulation ) delete mySimulation;
471 if ( myFilter ) delete myFilter;
474 //================================================================================
476 * \brief Gets dialog of this operation
477 * \retval LightApp_Dialog* - pointer to dialog of this operation
479 //================================================================================
481 LightApp_Dialog* SMESHGUI_RemoveNodeReconnectionOp::dlg() const