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_Operation(),
60 myHypothesisFilter( 0 ),
61 myAlgorithmFilter( 0 )
65 //=================================================================================
66 // function : Destructor
68 //=================================================================================
69 SMESHGUI_InitMeshOp::~SMESHGUI_InitMeshOp()
77 if( myAlgorithmFilter )
78 delete myAlgorithmFilter;
80 if( myHypothesisFilter )
81 delete myHypothesisFilter;
84 //=================================================================================
85 // function : startOperation
87 //=================================================================================
88 void SMESHGUI_InitMeshOp::startOperation()
92 myDlg = new SMESHGUI_InitMeshDlg( getSMESHGUI() );
93 connect( myDlg, SIGNAL( objectActivated( int ) ), this, SLOT( onActivateObject( int ) ) );
96 SMESHGUI_Operation::startOperation();
100 TColStd_MapOfInteger allTypesMap;
101 for (int i = 0; i < 10; i++)
103 myGeomFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 0, allTypesMap);
106 if( !myAlgorithmFilter )
107 myAlgorithmFilter = new SMESH_TypeFilter (ALGORITHM);
109 if( !myHypothesisFilter )
110 myHypothesisFilter = new SMESH_TypeFilter (HYPOTHESIS);
116 //=================================================================================
119 //=================================================================================
120 SalomeApp_Dialog* SMESHGUI_InitMeshOp::dlg() const
125 //=================================================================================
126 // function : selectionDone
128 //=================================================================================
129 void SMESHGUI_InitMeshOp::selectionDone()
131 QStringList names, ids;
132 SMESHGUI_Dialog::TypesList types;
133 selected( names, types, ids );
136 myDlg->selectObject( names, types, ids );
137 myDlg->updateControlState();
141 //=================================================================================
142 // function : onActivateObject
144 //=================================================================================
145 void SMESHGUI_InitMeshOp::onActivateObject( int obj )
147 SalomeApp_SelectionMgr* mgr = selectionMgr();
153 if( obj==SMESHGUI_InitMeshDlg::GeomObj )
154 mgr->installFilter( myGeomFilter );
156 else if( obj==SMESHGUI_InitMeshDlg::Hypo )
157 mgr->installFilter( myHypothesisFilter );
159 else if( obj==SMESHGUI_InitMeshDlg::Algo )
160 mgr->installFilter( myAlgorithmFilter );
163 //=================================================================================
164 // function : commitOperation
166 //=================================================================================
167 bool SMESHGUI_InitMeshOp::onApply()
169 if( getSMESHGUI()->isActiveStudyLocked() )
172 QString myNameMesh = myDlg->meshName();
173 if (myNameMesh.isEmpty())
175 SUIT_MessageBox::warn1( dlg(), tr("SMESH_WRN_WARNING"),
176 tr("SMESH_WRN_EMPTY_NAME"), tr("SMESH_BUT_OK") );
180 SUIT_OverrideCursor wc;
182 QStringList selGeom, selHypo, selAlgo;
183 myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom );
184 myDlg->selectedObject( SMESHGUI_InitMeshDlg::Hypo, selHypo );
185 myDlg->selectedObject( SMESHGUI_InitMeshDlg::Algo, selAlgo );
187 _PTR(Study) study = studyDS();
188 _PTR(SObject) aGeomSO = study->FindObjectID( selGeom.first() );
189 GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() );
192 SMESH::SMESH_Mesh_var aMesh = initMesh(myGeomShape, myNameMesh);
194 if (!aMesh->_is_nil())
197 for (int i = 0; i < selHypo.count(); i++)
199 _PTR(SObject) aHypSOClient =
200 study->FindObjectID(selHypo[i].latin1());
203 CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->GetObject();
204 if (!CORBA::is_nil(anObject))
206 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
207 if (!aHyp->_is_nil())
209 if (!SMESH::AddHypothesisOnMesh(aMesh, aHyp))
216 for (int i = 0; i < selAlgo.count(); i++)
218 _PTR(SObject) aHypSOClient =
219 study->FindObjectID(selAlgo[i].latin1());
222 CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->GetObject();
223 if (!CORBA::is_nil(anObject))
225 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
226 if (!aHyp->_is_nil())
228 if (!SMESH::AddHypothesisOnMesh(aMesh, aHyp))
236 update( UF_Model | UF_ObjBrowser );
242 //=================================================================================
243 // function : defaultMeshName()
245 //=================================================================================
246 QString SMESHGUI_InitMeshOp::defaultMeshName() const
248 _PTR(Study) aStudy = studyDS();
254 aMeshName = QString(tr("SMESH_OBJECT_MESH")) + "_" + QString::number(++aNumber);
255 obj = aStudy->FindObject(aMeshName.latin1());
261 //=================================================================================
264 //=================================================================================
265 void SMESHGUI_InitMeshOp::init()
269 myDlg->setMeshName( defaultMeshName() );
270 myDlg->clearSelection();
271 myDlg->updateControlState();
275 //=================================================================================
276 // function : defaultMeshName()
278 //=================================================================================
279 SMESH::SMESH_Mesh_var SMESHGUI_InitMeshOp::initMesh ( GEOM::GEOM_Object_ptr theShapeObject,
280 const QString& theMeshName )
282 SMESH::SMESH_Mesh_var aMesh;
285 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
286 if (!aSMESHGen->_is_nil() && !theShapeObject->_is_nil())
288 aMesh = aSMESHGen->CreateMesh(theShapeObject);
289 if (!aMesh->_is_nil())
291 _PTR(SObject) aMeshSObject = SMESH::FindSObject(aMesh.in());
292 SMESH::SetName(aMeshSObject, theMeshName);
296 catch( const SALOME::SALOME_Exception& S_ex )
298 SalomeApp_Tools::QtCatchCorbaException(S_ex);
301 return aMesh._retn();
304 //=================================================================================
305 // function : defaultMeshName()
307 //=================================================================================
308 void SMESHGUI_InitMeshOp::onSelectionChanged( int id )
310 if( !myDlg->hasSelection( id ) )
313 if( id==SMESHGUI_InitMeshDlg::GeomObj )
316 myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom );
318 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( selGeom.first() );
319 GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() );
320 if( myGeomShape->_is_nil() || !GEOMBase::IsShape( myGeomShape ) )
321 myDlg->clearSelection( id );