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_InitMeshDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_InitMeshOp.h"
30 #include <SMESHGUI_InitMeshDlg.h>
32 #include <SMESHGUI_Utils.h>
33 #include <SMESHGUI_HypothesesUtils.h>
35 #include <SMESH_NumberFilter.hxx>
36 #include <SMESH_TypeFilter.hxx>
38 #include <SALOMEDS_SObject.hxx>
40 #include <SUIT_SelectionFilter.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
44 #include <SalomeApp_SelectionMgr.h>
45 #include <SalomeApp_Tools.h>
46 #include <SalomeApp_UpdateFlags.h>
48 #include <TColStd_MapOfInteger.hxx>
52 //=================================================================================
53 // function : Constructor
55 //=================================================================================
56 SMESHGUI_InitMeshOp::SMESHGUI_InitMeshOp()
57 : SMESHGUI_SelectionOp(),
60 setAutoResumed( true );
63 //=================================================================================
64 // function : Destructor
66 //=================================================================================
67 SMESHGUI_InitMeshOp::~SMESHGUI_InitMeshOp()
73 //=================================================================================
74 // function : startOperation
76 //=================================================================================
77 void SMESHGUI_InitMeshOp::startOperation()
81 myDlg = new SMESHGUI_InitMeshDlg();
82 connect( myDlg, SIGNAL( nameChanged( const QString& ) ), this, SLOT( onNameChanged( const QString& ) ) );
85 SMESHGUI_SelectionOp::startOperation();
90 //=================================================================================
93 //=================================================================================
94 SalomeApp_Dialog* SMESHGUI_InitMeshOp::dlg() const
99 //=================================================================================
100 // function : selectionDone
102 //=================================================================================
103 void SMESHGUI_InitMeshOp::selectionDone()
105 SMESHGUI_SelectionOp::selectionDone();
110 //=================================================================================
111 // function : createFilter
113 //=================================================================================
114 SUIT_SelectionFilter* SMESHGUI_InitMeshOp::createFilter( const int id ) const
116 if( id==SMESHGUI_InitMeshDlg::GeomObj )
118 TColStd_MapOfInteger allTypesMap;
119 for (int i = 0; i < 10; i++)
121 return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
124 else if( id==SMESHGUI_InitMeshDlg::Hypo )
125 return new SMESH_TypeFilter (HYPOTHESIS);
127 else if( id==SMESHGUI_InitMeshDlg::Algo )
128 return new SMESH_TypeFilter (ALGORITHM);
134 //=================================================================================
135 // function : commitOperation
137 //=================================================================================
138 bool SMESHGUI_InitMeshOp::onApply()
140 if( getSMESHGUI()->isActiveStudyLocked() )
143 QString myNameMesh = myDlg->meshName();
144 if (myNameMesh.isEmpty())
146 SUIT_MessageBox::warn1( dlg(), tr("SMESH_WRN_WARNING"),
147 tr("SMESH_WRN_EMPTY_NAME"), tr("SMESH_BUT_OK") );
151 SUIT_OverrideCursor wc;
153 QStringList selGeom, selHypo, selAlgo;
154 myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom );
155 myDlg->selectedObject( SMESHGUI_InitMeshDlg::Hypo, selHypo );
156 myDlg->selectedObject( SMESHGUI_InitMeshDlg::Algo, selAlgo );
158 _PTR(Study) study = studyDS();
159 _PTR(SObject) aGeomSO = study->FindObjectID( selGeom.first() );
160 GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() );
163 SMESH::SMESH_Mesh_var aMesh = initMesh(myGeomShape, myNameMesh);
165 if (!aMesh->_is_nil())
168 for (int i = 0; i < selHypo.count(); i++)
170 _PTR(SObject) aHypSOClient =
171 study->FindObjectID(selHypo[i].latin1());
174 CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->GetObject();
175 if (!CORBA::is_nil(anObject))
177 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
178 if (!aHyp->_is_nil())
180 if (!SMESH::AddHypothesisOnMesh(aMesh, aHyp))
187 for (int i = 0; i < selAlgo.count(); i++)
189 _PTR(SObject) aHypSOClient =
190 study->FindObjectID(selAlgo[i].latin1());
193 CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->GetObject();
194 if (!CORBA::is_nil(anObject))
196 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
197 if (!aHyp->_is_nil())
199 if (!SMESH::AddHypothesisOnMesh(aMesh, aHyp))
207 update( UF_Model | UF_ObjBrowser );
213 //=================================================================================
214 // function : defaultMeshName()
216 //=================================================================================
217 QString SMESHGUI_InitMeshOp::defaultMeshName() const
219 _PTR(Study) aStudy = studyDS();
225 aMeshName = QString(tr("SMESH_OBJECT_MESH")) + "_" + QString::number(++aNumber);
226 obj = aStudy->FindObject(aMeshName.latin1());
232 //=================================================================================
235 //=================================================================================
236 void SMESHGUI_InitMeshOp::initDialog()
238 SMESHGUI_SelectionOp::initDialog();
241 myDlg->setMeshName( defaultMeshName() );
246 //=================================================================================
247 // function : defaultMeshName()
249 //=================================================================================
250 SMESH::SMESH_Mesh_var SMESHGUI_InitMeshOp::initMesh ( GEOM::GEOM_Object_ptr theShapeObject,
251 const QString& theMeshName )
253 SMESH::SMESH_Mesh_var aMesh;
256 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
257 if (!aSMESHGen->_is_nil() && !theShapeObject->_is_nil())
259 aMesh = aSMESHGen->CreateMesh(theShapeObject);
260 if (!aMesh->_is_nil())
262 _PTR(SObject) aMeshSObject = SMESH::FindSObject(aMesh.in());
263 SMESH::SetName(aMeshSObject, theMeshName);
267 catch( const SALOME::SALOME_Exception& S_ex )
269 SalomeApp_Tools::QtCatchCorbaException(S_ex);
272 return aMesh._retn();
275 //=================================================================================
276 // function : defaultMeshName()
278 //=================================================================================
279 void SMESHGUI_InitMeshOp::onSelectionChanged( int id )
281 if( !myDlg->hasSelection( id ) )
284 if( id==SMESHGUI_InitMeshDlg::GeomObj )
287 myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom );
289 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( selGeom.first() );
290 GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() );
291 if( myGeomShape->_is_nil() || !GEOMBase::IsShape( myGeomShape ) )
292 myDlg->clearSelection( id );
296 //=================================================================================
297 // function : onNameChanged()
299 //=================================================================================
300 void SMESHGUI_InitMeshOp::onNameChanged( const QString& )
305 //=================================================================================
306 // function : updateDialog()
308 //=================================================================================
309 void SMESHGUI_InitMeshOp::updateDialog()
314 bool isEnabled = !myDlg->meshName().isEmpty() &&
315 myDlg->hasSelection( SMESHGUI_InitMeshDlg::GeomObj ) &&
316 myDlg->hasSelection( SMESHGUI_InitMeshDlg::Hypo ) &&
317 myDlg->hasSelection( SMESHGUI_InitMeshDlg::Algo );
318 myDlg->setButtonEnabled( isEnabled, QtxDialog::OK | QtxDialog::Apply );
321 //=================================================================================
322 // function : isValid
324 //=================================================================================
325 bool SMESHGUI_InitMeshOp::isValid( SUIT_Operation* theOtherOp ) const
327 //if ( theOtherOp && theOtherOp->inherits( "SMESHGUI_AddSubMeshOp" ) )