1 // Copyright (C) 2007-2021 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 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_CreateDualMeshOp.cxx
25 // Author : Yoann AUDOUIN (EDF)
28 #include "SMESHGUI_CreateDualMeshOp.h"
31 #include "SMESHGUI_CreateDualMeshDlg.h"
32 #include "SMESHGUI_MeshEditPreview.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESH_ActorUtils.h"
35 #include "SMESH_TypeFilter.hxx"
36 #include "SMDSAbs_ElementType.hxx"
38 // SALOME GUI includes
39 #include <LightApp_UpdateFlags.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SalomeApp_Tools.h>
43 #include <SalomeApp_Application.h>
44 #include <SALOME_Actor.h>
50 #include <SALOMEconfig.h>
51 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
54 #include <vtkProperty.h>
56 //================================================================================
60 * Initialize operation
62 //================================================================================
63 SMESHGUI_CreateDualMeshOp::SMESHGUI_CreateDualMeshOp()
64 : SMESHGUI_SelectionOp(),
69 //================================================================================
73 //================================================================================
74 SMESHGUI_CreateDualMeshOp::~SMESHGUI_CreateDualMeshOp()
76 if ( myDlg ) delete myDlg;
79 //================================================================================
81 * \brief Gets dialog of this operation
82 * \retval LightApp_Dialog* - pointer to dialog of this operation
84 //================================================================================
85 LightApp_Dialog* SMESHGUI_CreateDualMeshOp::dlg() const
90 //================================================================================
92 * \brief Creates dialog if necessary and shows it
94 * Virtual method redefined from base class called when operation is started creates
95 * dialog if necessary and shows it, activates selection
97 //================================================================================
98 void SMESHGUI_CreateDualMeshOp::startOperation()
102 myDlg = new SMESHGUI_CreateDualMeshDlg( );
104 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
106 myHelpFileName = "create_dual_mesh.html";
108 SMESHGUI_SelectionOp::startOperation();
110 myDlg->activateObject( 0 );
111 myDlg->ShowWarning( false );
117 //================================================================================
119 * \brief Updates dialog's look and feel
121 * Virtual method redefined from the base class updates dialog's look and feel
123 //================================================================================
124 void SMESHGUI_CreateDualMeshOp::selectionDone()
126 if ( !dlg()->isVisible() )
129 SMESHGUI_SelectionOp::selectionDone();
132 QString anObjEntry = myDlg->selectedObject( 0 );
133 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
136 SMESH::SMESH_IDSource_var idSource =
137 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
139 myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply );
140 if( idSource->_is_nil() )
142 myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply );
145 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
147 // show warning on non-conformal result mesh
148 if ( ! idSource->_is_nil() )
150 SMESH::SMESH_subMesh_var subMesh =
151 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pObj );
152 // TODO: Check that mesh is only tetra
153 if (!checkMesh(idSource)){
154 myDlg->ShowWarning( true );
157 std::string mesh_name = "dual_" + pObj->GetName();
158 myDlg->myMeshName->setText(QString(mesh_name.c_str()));
161 catch ( const SALOME::SALOME_Exception& S_ex )
163 SalomeApp_Tools::QtCatchCorbaException( S_ex );
171 //================================================================================
173 * \brief Creates selection filter
174 * \param theId - identifier of current selection widget
175 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
177 * Creates selection filter in accordance with identifier of current selection widget
179 //================================================================================
180 SUIT_SelectionFilter* SMESHGUI_CreateDualMeshOp::createFilter( const int theId ) const
183 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
188 //================================================================================
192 * Virtual slot redefined from the base class called when "Apply" button is clicked
194 //================================================================================
195 bool SMESHGUI_CreateDualMeshOp::onApply()
197 SUIT_OverrideCursor aWaitCursor;
200 QStringList anEntryList;
202 QString anObjEntry = myDlg->selectedObject( 0 );
203 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
207 SUIT_MessageBox::warning( myDlg,
208 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
212 SMESH::SMESH_Mesh_var mesh;
213 SMESH::SMESH_IDSource_var idSource =
214 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
215 if( !CORBA::is_nil(idSource) )
216 mesh = idSource->GetMesh();
218 if( CORBA::is_nil(mesh) )
220 SUIT_MessageBox::warning( myDlg,
221 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
225 bool aResult = false;
226 SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGen();
227 SMESH::SMESH_Mesh_var newMesh;
228 QByteArray newMeshName=myDlg->myMeshName->text().toUtf8();
231 // TODO: change name as previous name + "_dual"
232 newMesh = gen->CreateDualMesh(mesh, newMeshName.constData());
234 if ( !newMesh->_is_nil() )
235 if ( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
237 anEntryList.append( aSObject->GetID().c_str() );
239 SMESH::SetName( aSObject, newMeshName );
243 catch ( const SALOME::SALOME_Exception& S_ex )
245 SalomeApp_Tools::QtCatchCorbaException( S_ex );
254 SMESHGUI::Modified();
256 update( UF_ObjBrowser | UF_Model | UF_Viewer );
259 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
261 // updateObjBrowser(true);
262 // SMESHGUI::Modified();
264 // if( LightApp_Application* anApp =
265 // dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
266 // anApp->browseObjects( anEntryList, true );
272 //================================================================================
274 * Verify that mesh as only tetraheadrons as 3D elements
276 //================================================================================
279 SMESHGUI_CreateDualMeshOp::checkMesh( const SMESH::SMESH_IDSource_var& idSource)
281 SMESH::smIdType_array_var nbElemOfType = idSource->GetMeshInfo();
282 // Checking that the mesh only has Tetrahedron
283 bool hasOnlyTetra = (
284 nbElemOfType[SMDSEntity_Tetra ] &&
285 !nbElemOfType[SMDSEntity_Hexa ] &&
286 !nbElemOfType[SMDSEntity_Pyramid ] &&
287 !nbElemOfType[SMDSEntity_Polygon ] &&
288 !nbElemOfType[SMDSEntity_Penta ] );