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 )
63 setAutoResumed( true );
66 //=================================================================================
67 // function : Destructor
69 //=================================================================================
70 SMESHGUI_InitMeshOp::~SMESHGUI_InitMeshOp()
78 if( myAlgorithmFilter )
79 delete myAlgorithmFilter;
81 if( myHypothesisFilter )
82 delete myHypothesisFilter;
85 //=================================================================================
86 // function : startOperation
88 //=================================================================================
89 void SMESHGUI_InitMeshOp::startOperation()
93 myDlg = new SMESHGUI_InitMeshDlg( getSMESHGUI() );
94 connect( myDlg, SIGNAL( objectActivated( int ) ), this, SLOT( onActivateObject( int ) ) );
97 SMESHGUI_Operation::startOperation();
101 TColStd_MapOfInteger allTypesMap;
102 for (int i = 0; i < 10; i++)
104 myGeomFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 0, allTypesMap);
107 if( !myAlgorithmFilter )
108 myAlgorithmFilter = new SMESH_TypeFilter (ALGORITHM);
110 if( !myHypothesisFilter )
111 myHypothesisFilter = new SMESH_TypeFilter (HYPOTHESIS);
117 //=================================================================================
120 //=================================================================================
121 SalomeApp_Dialog* SMESHGUI_InitMeshOp::dlg() const
126 //=================================================================================
127 // function : selectionDone
129 //=================================================================================
130 void SMESHGUI_InitMeshOp::selectionDone()
132 QStringList names, ids;
133 SMESHGUI_Dialog::TypesList types;
134 selected( names, types, ids );
137 myDlg->selectObject( names, types, ids );
138 myDlg->updateControlState();
142 //=================================================================================
143 // function : onActivateObject
145 //=================================================================================
146 void SMESHGUI_InitMeshOp::onActivateObject( int obj )
148 SalomeApp_SelectionMgr* mgr = selectionMgr();
154 if( obj==SMESHGUI_InitMeshDlg::GeomObj )
155 mgr->installFilter( myGeomFilter );
157 else if( obj==SMESHGUI_InitMeshDlg::Hypo )
158 mgr->installFilter( myHypothesisFilter );
160 else if( obj==SMESHGUI_InitMeshDlg::Algo )
161 mgr->installFilter( myAlgorithmFilter );
164 //=================================================================================
165 // function : commitOperation
167 //=================================================================================
168 bool SMESHGUI_InitMeshOp::onApply()
170 if( getSMESHGUI()->isActiveStudyLocked() )
173 QString myNameMesh = myDlg->meshName();
174 if (myNameMesh.isEmpty())
176 SUIT_MessageBox::warn1( dlg(), tr("SMESH_WRN_WARNING"),
177 tr("SMESH_WRN_EMPTY_NAME"), tr("SMESH_BUT_OK") );
181 SUIT_OverrideCursor wc;
183 QStringList selGeom, selHypo, selAlgo;
184 myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom );
185 myDlg->selectedObject( SMESHGUI_InitMeshDlg::Hypo, selHypo );
186 myDlg->selectedObject( SMESHGUI_InitMeshDlg::Algo, selAlgo );
188 _PTR(Study) study = studyDS();
189 _PTR(SObject) aGeomSO = study->FindObjectID( selGeom.first() );
190 GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() );
193 SMESH::SMESH_Mesh_var aMesh = initMesh(myGeomShape, myNameMesh);
195 if (!aMesh->_is_nil())
198 for (int i = 0; i < selHypo.count(); i++)
200 _PTR(SObject) aHypSOClient =
201 study->FindObjectID(selHypo[i].latin1());
204 CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->GetObject();
205 if (!CORBA::is_nil(anObject))
207 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
208 if (!aHyp->_is_nil())
210 if (!SMESH::AddHypothesisOnMesh(aMesh, aHyp))
217 for (int i = 0; i < selAlgo.count(); i++)
219 _PTR(SObject) aHypSOClient =
220 study->FindObjectID(selAlgo[i].latin1());
223 CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->GetObject();
224 if (!CORBA::is_nil(anObject))
226 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
227 if (!aHyp->_is_nil())
229 if (!SMESH::AddHypothesisOnMesh(aMesh, aHyp))
237 update( UF_Model | UF_ObjBrowser );
243 //=================================================================================
244 // function : defaultMeshName()
246 //=================================================================================
247 QString SMESHGUI_InitMeshOp::defaultMeshName() const
249 _PTR(Study) aStudy = studyDS();
255 aMeshName = QString(tr("SMESH_OBJECT_MESH")) + "_" + QString::number(++aNumber);
256 obj = aStudy->FindObject(aMeshName.latin1());
262 //=================================================================================
265 //=================================================================================
266 void SMESHGUI_InitMeshOp::init()
270 myDlg->setMeshName( defaultMeshName() );
271 myDlg->clearSelection();
272 myDlg->updateControlState();
276 //=================================================================================
277 // function : defaultMeshName()
279 //=================================================================================
280 SMESH::SMESH_Mesh_var SMESHGUI_InitMeshOp::initMesh ( GEOM::GEOM_Object_ptr theShapeObject,
281 const QString& theMeshName )
283 SMESH::SMESH_Mesh_var aMesh;
286 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
287 if (!aSMESHGen->_is_nil() && !theShapeObject->_is_nil())
289 aMesh = aSMESHGen->CreateMesh(theShapeObject);
290 if (!aMesh->_is_nil())
292 _PTR(SObject) aMeshSObject = SMESH::FindSObject(aMesh.in());
293 SMESH::SetName(aMeshSObject, theMeshName);
297 catch( const SALOME::SALOME_Exception& S_ex )
299 SalomeApp_Tools::QtCatchCorbaException(S_ex);
302 return aMesh._retn();
305 //=================================================================================
306 // function : defaultMeshName()
308 //=================================================================================
309 void SMESHGUI_InitMeshOp::onSelectionChanged( int id )
311 if( !myDlg->hasSelection( id ) )
314 if( id==SMESHGUI_InitMeshDlg::GeomObj )
317 myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom );
319 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( selGeom.first() );
320 GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() );
321 if( myGeomShape->_is_nil() || !GEOMBase::IsShape( myGeomShape ) )
322 myDlg->clearSelection( id );
326 //=================================================================================
327 // function : isValid
329 //=================================================================================
330 bool SMESHGUI_InitMeshOp::isValid( SUIT_Operation* theOtherOp ) const
332 if ( theOtherOp && theOtherOp->inherits( "SMESHGUI_AddSubMeshOp" ) )