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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshOp.h"
30 #include "SMESHGUI_MeshDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Hypotheses.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_NumberFilter.hxx>
40 // SALOME GEOM includes
41 #include <GEOM_SelectionFilter.h>
43 #include <GeometryGUI.h>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SALOME_InteractiveObject.hxx>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDS_SComponent.hxx>
57 #include <SALOMEDS_SObject.hxx>
60 #include <QStringList>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Shell.hxx>
67 #include <TopExp_Explorer.hxx>
70 #include <SALOMEconfig.h>
71 #include CORBA_CLIENT_HEADER(SMESH_Gen)
73 //================================================================================
76 * \param theToCreate - if this parameter is true then operation is used for creation,
77 * for editing otherwise
79 * Initialize operation
81 //================================================================================
82 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
83 : SMESHGUI_SelectionOp(),
84 myToCreate( theToCreate ),
85 myIsMesh( theIsMesh ),
89 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
90 GeometryGUI::InitGeomGen();
91 myIsOnGeometry = true;
94 //================================================================================
98 //================================================================================
99 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
105 //================================================================================
107 * \brief Gets dialog of this operation
108 * \retval LightApp_Dialog* - pointer to dialog of this operation
110 //================================================================================
111 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
116 //================================================================================
118 * \brief Creates or edits mesh
119 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
121 * Virtual slot redefined from the base class called when "Apply" button is clicked
122 * creates or edits mesh
124 //================================================================================
125 bool SMESHGUI_MeshOp::onApply()
131 if ( !isValid( aMess ) )
135 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
139 bool aResult = false;
143 if ( myToCreate && myIsMesh )
144 aResult = createMesh( aMess );
145 if ( myToCreate && !myIsMesh )
146 aResult = createSubMesh( aMess );
147 else if ( !myToCreate )
148 aResult = editMeshOrSubMesh( aMess );
150 update( UF_ObjBrowser | UF_Model );
152 catch ( const SALOME::SALOME_Exception& S_ex )
154 SalomeApp_Tools::QtCatchCorbaException( S_ex );
170 aMess = tr( "SMESH_OPERATION_FAILED" );
171 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
177 //================================================================================
179 * \brief Creates dialog if necessary and shows it
181 * Virtual method redefined from base class called when operation is started creates
182 * dialog if necessary and shows it, activates selection
184 //================================================================================
185 void SMESHGUI_MeshOp::startOperation()
189 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
190 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
192 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
193 this, SLOT( onCreateHyp( const int, const int ) ) );
194 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
195 this, SLOT( onEditHyp( const int, const int ) ) );
196 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
197 this, SLOT( onAlgoSelected( const int ) ) );
199 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
200 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
203 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
204 else myHelpFileName = "constructing_submeshes_page.html";
205 else myHelpFileName = "editing_meshes_page.html";
207 SMESHGUI_SelectionOp::startOperation();
209 // iterate through dimensions and get available algoritms, set them to the dialog
210 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
211 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
213 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
215 // clear available hypotheses
216 aTab->setAvailableHyps( MainHyp, hypList );
217 aTab->setAvailableHyps( AddHyp, hypList );
218 aTab->setExistingHyps( MainHyp, hypList );
219 aTab->setExistingHyps( AddHyp, hypList );
220 myExistingHyps[ i ][ MainHyp ].clear();
221 myExistingHyps[ i ][ AddHyp ].clear();
223 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
224 aTab->setAvailableHyps( Algo, hypList );
229 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
232 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
234 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
236 myDlg->setCurrentTab( SMESH::DIM_3D );
241 myIgnoreAlgoSelection = false;
244 //================================================================================
246 * \brief Creates selection filter
247 * \param theId - identifier of current selection widget
248 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
250 * Creates selection filter in accordance with identifier of current selection widget
252 //================================================================================
253 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
255 if ( theId == SMESHGUI_MeshDlg::Geom )
257 // TColStd_MapOfInteger allTypesMap;
258 // for ( int i = 0; i < 10; i++ )
259 // allTypesMap.Add( i );
260 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
261 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
263 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
264 return new SMESH_TypeFilter( MESHorSUBMESH );
265 else if ( theId == SMESHGUI_MeshDlg::Mesh )
266 return new SMESH_TypeFilter( MESH );
271 //================================================================================
273 * \brief check if selected shape is a subshape of the shape to mesh
274 * \retval bool - check result
276 //================================================================================
278 bool SMESHGUI_MeshOp::isSubshapeOk() const
280 if ( !myToCreate || myIsMesh ) // not submesh creation
284 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
285 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
286 if (!pMesh) return false;
288 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
289 if (mesh->_is_nil()) return false;
291 // main shape of the mesh
292 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
293 if (mainGeom->_is_nil()) return false;
297 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
299 if (aGEOMs.count() > 0) {
300 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
301 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
302 if (geomGen->_is_nil() || !aStudy) return false;
304 GEOM::GEOM_IGroupOperations_var op =
305 geomGen->GetIGroupOperations(aStudy->StudyId());
306 if (op->_is_nil()) return false;
308 // check all selected shapes
309 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
310 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
311 QString aSubGeomEntry = (*aSubShapesIter);
312 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
313 if (!pSubGeom) return false;
315 GEOM::GEOM_Object_var aSubGeomVar =
316 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
317 if (aSubGeomVar->_is_nil()) return false;
319 // skl for NPAL14695 - implementation of searching of mainObj
320 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
321 //if (mainObj->_is_nil() ||
322 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
324 if (mainObj->_is_nil())
326 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
328 mainObj = op->GetMainShape(mainObj);
337 //================================================================================
339 * \brief Return name of the algorithm that does not support submeshes and makes
340 * submesh creation useless
341 * \retval char* - string is to be deleted!!!
343 //================================================================================
345 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
347 if ( myToCreate && !myIsMesh ) {
349 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
350 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
351 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
354 QStringList algoNames;
356 existingHyps(3, Algo, pMesh, algoNames, algoList);
357 if (!algoList.empty()) {
358 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
360 algo->InputTypes.empty() && // builds all dimensions it-self
361 !algo->IsSupportSubmeshes )
362 return CORBA::string_dup( algoNames[0].toLatin1().data() );
365 // GEOM::GEOM_Object_var geom;
366 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
367 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
369 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
370 existingHyps(2, Algo, pMesh, algoNames, algoList);
371 if (!algoList.empty()) {
372 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
374 algo->InputTypes.empty() && // builds all dimensions it-self
375 !algo->IsSupportSubmeshes )
376 return CORBA::string_dup( algoNames[0].toLatin1().data() );
384 //================================================================================
386 * \brief find an existing submesh by the selected shape
387 * \retval _PTR(SObject) - the found submesh SObject
389 //================================================================================
391 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
393 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
394 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
395 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
396 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
397 if ( pMesh && pGeom ) {
398 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
399 if ( !geom->_is_nil() ) {
401 switch ( geom->GetShapeType() ) {
402 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
403 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
404 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
405 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
406 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
407 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
408 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
411 _PTR(GenericAttribute) anAttr;
412 _PTR(SObject) aSubmeshRoot;
413 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
414 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
416 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
417 for ( ; smIter->More(); smIter->Next() )
419 _PTR(SObject) aSmObj = smIter->Value();
420 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
422 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
423 for ( ; anIter1->More(); anIter1->Next()) {
424 _PTR(SObject) pGeom2 = anIter1->Value();
425 if ( pGeom2->ReferencedObject( pGeom2 ) &&
426 pGeom2->GetID() == pGeom->GetID() )
433 return _PTR(SObject)();
436 //================================================================================
438 * \brief Updates dialog's look and feel
440 * Virtual method redefined from the base class updates dialog's look and feel
442 //================================================================================
443 void SMESHGUI_MeshOp::selectionDone()
445 if (!dlg()->isVisible() || !myDlg->isEnabled())
448 SMESHGUI_SelectionOp::selectionDone();
452 myIsOnGeometry = true;
454 //Check geometry for mesh
455 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
456 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
459 SMESH::SMESH_Mesh_var aMeshVar =
460 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
461 if (!aMeshVar->_is_nil()) {
462 if (!myToCreate && !aMeshVar->HasShapeToMesh())
463 myIsOnGeometry = false;
469 // Enable tabs according to shape dimension
474 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
475 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
477 if (aGEOMs.count() > 0) {
478 // one or more GEOM shape selected
479 aSeq->length(aGEOMs.count());
480 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
482 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
483 QString aSubGeomEntry = (*aSubShapesIter);
484 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
485 GEOM::GEOM_Object_var aSubGeomVar =
486 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
487 aSeq[iSubSh] = aSubGeomVar;
490 // get geometry by selected sub-mesh
491 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
492 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
493 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
494 if (!aGeomVar->_is_nil()) {
500 if (aSeq->length() > 0) {
502 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
503 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
504 switch ( aGeomVar->GetShapeType() ) {
505 case GEOM::SOLID: shapeDim = 3; break;
508 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
509 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
511 if (GEOMBase::GetShape(aGeomVar, aShape)) {
517 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
519 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
520 case GEOM::VERTEX: break;
524 if (GEOMBase::GetShape(aGeomVar, aShape)) {
525 TopExp_Explorer exp (aShape, TopAbs_SHELL);
527 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
528 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
529 for (; exp.More() && shapeDim == 2; exp.Next()) {
530 if (exp.Current().Closed())
534 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
535 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
536 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
537 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
545 myDlg->setMaxHypoDim( shapeDim );
548 if (!myToCreate) // edition: read hypotheses
552 SMESH::SMESH_subMesh_var aVar =
553 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
554 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
555 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
556 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
557 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
558 myDlg->updateGeometry();
565 else if ( !myIsMesh ) // submesh creation
567 // if a submesh on the selected shape already exist, pass to submesh edition mode
568 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
569 SMESH::SMESH_subMesh_var sm =
570 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
571 bool editSubmesh = ( !sm->_is_nil() &&
572 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
573 tr( "EDIT_SUBMESH_QUESTION"),
574 SUIT_MessageBox::Yes |
576 SUIT_MessageBox::No )
577 == SUIT_MessageBox::Yes );
580 selectionMgr()->clearFilters();
581 selectObject( pSubmesh );
582 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
587 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
588 selectObject( _PTR(SObject)() );
593 // discard selected mesh if submesh creation not allowed because of
594 // a global algorithm that does not support submeshes
595 if ( char* algoName = isSubmeshIgnored() ) {
596 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
597 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
598 CORBA::string_free( algoName );
599 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
600 selectObject( _PTR(SObject)() );
605 // enable/disable popup for choice of geom selection way
607 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
608 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
609 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
610 if ( !mesh->_is_nil() )
611 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
613 myDlg->setGeomPopupEnabled( enable );
617 myDlg->enableTab( SMESH::DIM_3D );
619 availableHyps( SMESH::DIM_3D, Algo, hypList,
620 myAvailableHypData[SMESH::DIM_3D][Algo]);
622 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
623 aTab->setAvailableHyps( Algo, hypList );
624 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
625 myDlg->disableTab(i);
627 //Hide labels and fields (Mesh ang Geometry)
628 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
629 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
634 catch ( const SALOME::SALOME_Exception& S_ex )
636 SalomeApp_Tools::QtCatchCorbaException( S_ex );
643 //================================================================================
645 * \brief Verifies validity of input data
646 * \param theMess - Output parameter intended for returning error message
647 * \retval bool - TRUE if input data is valid, false otherwise
649 * Verifies validity of input data. This method is called when "Apply" or "OK" button
650 * is pressed before mesh creation or editing.
652 //================================================================================
653 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
655 // Selected object to be edited
656 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
658 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
663 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
664 if ( aMeshName.isEmpty() )
666 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
670 /* // Imported mesh, if create sub-mesh or edit mesh
671 if ( !myToCreate || ( myToCreate && !myIsMesh ))
673 QString aMeshEntry = myDlg->selectedObject
674 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
675 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
676 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
677 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
678 theMess = tr( "IMPORTED_MESH" );
687 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
688 if ( aGeomEntry == "" )
690 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
693 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
694 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
696 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
701 if ( !myIsMesh ) // i.e sub-mesh creation,
703 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
704 if ( aMeshEntry == "" )
706 theMess = tr( "MESH_IS_NOT_DEFINED" );
709 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
710 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
712 theMess = tr( "MESH_IS_NULL" );
715 if ( !isSubshapeOk() )
717 theMess = tr( "INVALID_SUBSHAPE" );
726 //================================================================================
728 * \brief check compatibility of the algorithm and another algorithm or hypothesis
729 * \param theAlgoData - algorithm data
730 * \param theHypData - hypothesis data
731 * \param theHypType - hypothesis type
732 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
733 * \retval bool - check result
735 //================================================================================
737 static bool isCompatible(const HypothesisData* theAlgoData,
738 const HypothesisData* theHypData,
739 const int theHypType)
744 if ( theHypType == SMESHGUI_MeshOp::Algo )
745 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
748 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
751 //================================================================================
753 * \brief Gets available hypotheses or algorithms
754 * \param theDim - specifies dimension of returned hypotheses/algorifms
755 * \param theHypType - specifies whether algorims or hypotheses or additional ones
756 * are retrieved (possible values are in HypType enumeration)
757 * \param theHyps - Output list of hypotheses' names
758 * \param theAlgoData - to select hypos able to be used by this algo (optional)
760 * Gets available hypotheses or algorithm in accordance with input parameters
762 //================================================================================
763 void SMESHGUI_MeshOp::availableHyps( const int theDim,
764 const int theHypType,
765 QStringList& theHyps,
766 THypDataList& theDataList,
767 HypothesisData* theAlgoData ) const
771 bool isAlgo = ( theHypType == Algo );
772 bool isAux = ( theHypType == AddHyp );
773 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
775 QStringList::const_iterator anIter;
776 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
778 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
779 if ( isCompatible ( theAlgoData, aData, theHypType )) {
780 theDataList.append( aData );
781 theHyps.append( aData->Label );
786 //================================================================================
788 * \brief Gets existing hypotheses or algorithms
789 * \param theDim - specifies dimension of returned hypotheses/algorifms
790 * \param theHypType - specifies whether algorims or hypotheses or additional ones
791 * are retrieved (possible values are in HypType enumeration)
792 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
793 * \param theHyps - output list of names.
794 * \param theHypVars - output list of variables.
795 * \param theAlgoData - to select hypos able to be used by this algo (optional)
797 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
800 //================================================================================
801 void SMESHGUI_MeshOp::existingHyps( const int theDim,
802 const int theHypType,
803 _PTR(SObject) theFather,
804 QStringList& theHyps,
805 THypList& theHypList,
806 HypothesisData* theAlgoData)
808 // Clear hypoheses list
815 const bool isAux = ( theHypType == AddHyp );
817 _PTR(SObject) aHypRoot;
818 _PTR(GenericAttribute) anAttr;
819 _PTR(AttributeName) aName;
820 _PTR(AttributeIOR) anIOR;
822 bool isMesh = !_CAST( SComponent, theFather );
825 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
827 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
829 if ( theFather->FindSubObject( aPart, aHypRoot ) )
831 _PTR(ChildIterator) anIter =
832 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
833 for ( ; anIter->More(); anIter->Next() )
835 _PTR(SObject) anObj = anIter->Value();
836 if ( isMesh ) // i.e. mesh or submesh
838 _PTR(SObject) aRefObj;
839 if ( anObj->ReferencedObject( aRefObj ) )
844 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
847 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
848 if ( !CORBA::is_nil( aVar ) )
850 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
851 if ( !aHypVar->_is_nil() )
853 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
854 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
855 ( isCompatible ( theAlgoData, aData, theHypType )) &&
856 ( isAux == aData->IsAux ))
858 std::string aHypName = aName->Value();
859 theHyps.append( aHypName.c_str() );
860 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
869 //================================================================================
871 * \brief If create or edit a submesh, return a hypothesis holding parameters used
873 * \param aHypType - The hypothesis type name
874 * \param aServerLib - Server library name
875 * \param hypData - The structure holding the hypothesis type etc.
876 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
878 //================================================================================
880 SMESH::SMESH_Hypothesis_var
881 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
882 const QString& aServerLib ) const
884 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
885 return SMESH::SMESH_Hypothesis::_nil();
887 const int nbColonsInMeshEntry = 3;
888 bool isSubMesh = myToCreate ?
890 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
894 // get mesh and geom object
895 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
896 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
898 QString anEntry = myDlg->selectedObject
899 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
900 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
902 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
903 if ( myToCreate ) // mesh and geom may be selected
905 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
906 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
907 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
908 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
910 else // edition: sub-mesh may be selected
912 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
913 if ( !sm->_is_nil() ) {
914 aMeshVar = sm->GetFather();
915 aGeomVar = sm->GetSubShape();
920 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
921 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
922 aServerLib.toLatin1().data(),
926 return SMESH::SMESH_Hypothesis::_nil();
929 //================================================================================
931 * \Brief Returns tab dimention
932 * \param tab - the tab in the dlg
933 * \param dlg - my dialogue
934 * \retval int - dimention
936 //================================================================================
938 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
941 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
942 if (tab == dlg->tab(i))
947 //================================================================================
949 * \brief Create hypothesis
950 * \param theHypType - hypothesis category (main or additional)
951 * \param theIndex - index of type of hypothesis to be cerated
953 * Specifies dimension of hypothesis to be created (using sender() method),
954 * specifies its type and calls method for hypothesis creation
956 //================================================================================
957 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
959 // Specifies dimension of hypothesis to be created
960 int aDim = getTabDim( sender(), myDlg );
964 // Specifies type of hypothesis to be created
965 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
966 if (theIndex < 0 || theIndex >= dataList.count())
968 QString aHypTypeName = dataList[ theIndex ]->TypeName;
971 createHypothesis(aDim, theHypType, aHypTypeName);
974 //================================================================================
976 * Create hypothesis and update dialog.
977 * \param theDim - dimension of hypothesis to be created
978 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
979 * \param theTypeName - specifies hypothesis to be created
981 //================================================================================
984 QString GetUniqueName (const QStringList& theHypNames,
985 const QString& theName,
986 size_t theIteration = 1)
988 QString aName = theName + "_" + QString::number( theIteration );
989 if ( theHypNames.contains( aName ) )
990 return GetUniqueName( theHypNames, theName, ++theIteration );
995 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
997 const QString& theTypeName)
999 // During a hypothesis creation we might need to select some objects.
1000 // Main dialog must not update it's own selected objects in this case.
1001 dlg()->deactivateAll();
1003 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1007 QStringList aHypNames;
1008 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1009 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1010 const TType2HypList& aType2HypList = aDimIter.value();
1011 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1012 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1013 const THypList& aHypList = aTypeIter.value();
1014 THypList::const_iterator anIter = aHypList.begin();
1015 for ( ; anIter != aHypList.end(); anIter++) {
1016 const THypItem& aHypItem = *anIter;
1017 const QString& aHypName = aHypItem.second;
1018 aHypNames.append(aHypName);
1022 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1025 int nbHyp = myExistingHyps[theDim][theType].count();
1027 QString aClientLibName = aData->ClientLibName;
1028 if (aClientLibName == "") {
1029 // Call hypothesis creation server method (without GUI)
1030 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1032 // Get hypotheses creator client (GUI)
1033 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1035 // Create hypothesis
1037 // When create or edit a submesh, try to initialize a new hypothesis
1038 // with values used to mesh a subshape
1039 SMESH::SMESH_Hypothesis_var initParamHyp =
1040 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1041 myDlg->setEnabled( false );
1042 aCreator->create(initParamHyp, aHypName, myDlg);
1043 myDlg->setEnabled( true );
1045 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1049 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1051 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
1052 QStringList aNewHyps;
1053 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
1054 if (aNewHyps.count() > nbHyp) {
1055 for (int i = nbHyp; i < aNewHyps.count(); i++)
1056 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
1060 //================================================================================
1062 * \brief Calls plugin methods for hypothesis editing
1063 * \param theHypType - specifies whether main hypothesis or additional one
1065 * \param theIndex - index of existing hypothesis
1067 * Calls plugin methods for hypothesis editing
1069 //================================================================================
1070 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1072 // Speicfies dimension of hypothesis to be created
1073 int aDim = getTabDim( sender(), myDlg );
1077 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1078 if ( theIndex < 0 || theIndex >= aList.count() )
1080 const THypItem& aHypItem = aList[ theIndex ];
1081 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1082 if ( aHyp->_is_nil() )
1085 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHyp->GetName() );
1087 myDlg->setEnabled( false );
1088 aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
1089 myDlg->setEnabled( true );
1093 //================================================================================
1095 * \brief access to hypothesis data
1096 * \param theDim - hyp dimension
1097 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1098 * \param theIndex - index in the list
1099 * \retval HypothesisData* - result data, may be 0
1101 //================================================================================
1103 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1104 const int theHypType,
1107 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1108 theHypType > -1 && theHypType < NbHypTypes &&
1109 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1110 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1114 //================================================================================
1116 * \brief Set available algos and hypos according to the selected algorithm
1117 * \param theIndex - algorithm index
1119 //================================================================================
1121 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1124 if ( myIgnoreAlgoSelection )
1127 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1131 // find highest available dimension, all algos of this dimension are available for choice
1133 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1134 if (isAccessibleDim( i ))
1139 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1141 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1142 HypothesisData* algoByDim[4];
1143 algoByDim[ aDim ] = algoData;
1145 QStringList anAvailable;
1146 if ( !algoData ) { // all algos becomes available
1147 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1148 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1151 // check that algorithms of other dimentions are compatible with
1154 // 2 loops: backward and forward from algo dimension
1155 for ( int forward = false; forward <= true; ++forward )
1157 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1159 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1161 HypothesisData* prevAlgo = algoData;
1162 bool noCompatible = false;
1163 for ( ; dim * dir <= lastDim * dir; dim += dir)
1165 if ( !isAccessibleDim( dim ))
1167 if ( noCompatible ) { // the selected algo has no compatible ones
1168 anAvailable.clear();
1169 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1170 myAvailableHypData[dim][Algo].clear();
1171 algoByDim[ dim ] = 0;
1174 // get currently selected algo
1175 int algoIndex = currentHyp( dim, Algo );
1176 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1177 if ( curAlgo ) { // some algo selected
1178 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1181 // set new available algoritms
1182 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1183 HypothesisData* soleCompatible = 0;
1184 if ( anAvailable.count() == 1 )
1185 soleCompatible = myAvailableHypData[dim][Algo][0];
1186 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1187 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1188 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1189 noCompatible = anAvailable.isEmpty();
1191 // restore previously selected algo
1192 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1193 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1194 // select the sole compatible algo
1195 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1196 setCurrentHyp( dim, Algo, algoIndex );
1198 // remember current algo
1199 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1203 // set hypotheses corresponding to the found algoritms
1205 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1207 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1209 if ( !isAccessibleDim( dim ))
1211 for ( int type = MainHyp; type < NbHypTypes; type++ )
1213 myAvailableHypData[ dim ][ type ].clear();
1214 QStringList anAvailable, anExisting;
1216 HypothesisData* curAlgo = algoByDim[ dim ];
1217 int hypIndex = currentHyp( dim, type );
1219 SMESH::SMESH_Hypothesis_var curHyp;
1220 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1221 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1223 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1224 // try to find algo by selected hypothesis in order to keep it selected
1225 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1226 CORBA::String_var curHypType = curHyp->GetName();
1227 if ( !algoDeselectedByUser &&
1228 myObjHyps[ dim ][ type ].count() > 0 &&
1229 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1231 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1232 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1233 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1234 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1241 // get hyps compatible with curAlgo
1244 // check if a selected hyp is compatible with the curAlgo
1245 if ( !curHyp->_is_nil() ) {
1246 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1247 if ( !isCompatible( curAlgo, hypData, type ))
1248 curHyp = SMESH::SMESH_Hypothesis::_nil();
1250 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1251 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1253 // set list of hypotheses
1254 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1255 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1257 // set current existing hypothesis
1258 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1259 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1262 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1263 // none is yet selected => select the sole existing if it is not optional
1264 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1265 bool isOptional = true;
1266 if ( algoByDim[ dim ] &&
1267 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1271 setCurrentHyp( dim, type, hypIndex );
1276 //================================================================================
1278 * \brief Creates and selects hypothesis of hypotheses set
1279 * \param theSetName - The name of hypotheses set
1281 //================================================================================
1282 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1284 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1285 if (!aHypoSet) return;
1288 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1289 setCurrentHyp(dim, Algo, -1);
1290 setCurrentHyp(dim, AddHyp, -1);
1291 setCurrentHyp(dim, MainHyp, -1);
1294 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1295 bool isAlgo = (aHypType == Algo);
1297 // set hyps from the set
1298 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1299 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1300 const QString& aHypoTypeName = (*aHypoList)[ i ];
1301 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1305 int aDim = aHypData->Dim[0];
1306 // create or/and set
1308 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1310 QStringList anAvailable;
1311 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1312 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1313 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1315 setCurrentHyp( aDim, Algo, index );
1316 onAlgoSelected( index, aDim );
1319 bool mainHyp = true;
1320 QStringList anAvailable;
1321 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1322 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1323 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1326 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1329 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1331 } // loop on hypos in the set
1332 } // loop on algo/hypo
1335 //================================================================================
1337 * \brief Creates mesh
1338 * \param theMess - Output parameter intended for returning error message
1339 * \retval bool - TRUE if mesh is created, FALSE otherwise
1343 //================================================================================
1344 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1348 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1349 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1352 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1353 QStringList::Iterator it = aList.begin();
1354 for ( ; it!=aList.end(); it++)
1356 QString aGeomEntry = *it;
1357 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1358 GEOM::GEOM_Object_var aGeomVar =
1359 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1361 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1362 if ( aSMESHGen->_is_nil() )
1365 SUIT_OverrideCursor aWaitCursor;
1368 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1369 if ( aMeshVar->_is_nil() )
1371 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1373 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1375 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1376 if ( !isAccessibleDim( aDim )) continue;
1378 // assign hypotheses
1379 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1380 int aHypIndex = currentHyp( aDim, aHypType );
1381 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1382 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1383 if ( !aHypVar->_is_nil() )
1384 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1387 // find or create algorithm
1388 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1389 if ( !anAlgoVar->_is_nil() )
1390 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1397 //================================================================================
1399 * \brief Creates sub-mesh
1400 * \param theMess - Output parameter intended for returning error message
1401 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1405 //================================================================================
1406 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1410 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1411 if ( aSMESHGen->_is_nil() )
1415 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1416 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1417 SMESH::SMESH_Mesh_var aMeshVar =
1418 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1419 if (aMeshVar->_is_nil())
1422 // GEOM shape of the main mesh
1423 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1425 // Name for the new sub-mesh
1426 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1429 GEOM::GEOM_Object_var aGeomVar;
1431 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1432 if (aGEOMs.count() == 1)
1434 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1435 QString aGeomEntry = aGEOMs.first();
1436 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1437 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1439 else if (aGEOMs.count() > 1)
1441 // create a GEOM group
1442 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1443 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1444 if (!geomGen->_is_nil() && aStudy) {
1445 GEOM::GEOM_IGroupOperations_var op =
1446 geomGen->GetIGroupOperations(aStudy->StudyId());
1447 if (!op->_is_nil()) {
1448 // check and add all selected GEOM objects: they must be
1449 // a sub-shapes of the main GEOM and must be of one type
1451 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1452 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1453 aSeq->length(aGEOMs.count());
1454 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1455 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1456 QString aSubGeomEntry = (*aSubShapesIter);
1457 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1458 GEOM::GEOM_Object_var aSubGeomVar =
1459 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1460 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1462 aGroupType = aSubShapeType;
1464 if (aSubShapeType != aGroupType)
1465 aGroupType = TopAbs_SHAPE;
1467 aSeq[iSubSh] = aSubGeomVar;
1470 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1471 op->UnionList(aGroupVar, aSeq);
1474 aGeomVar = aGroupVar;
1476 // publish the GEOM group in study
1477 QString aNewGeomGroupName ("Auto_group_for_");
1478 aNewGeomGroupName += aName;
1479 SALOMEDS::SObject_var aNewGroupSO =
1480 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1481 aNewGeomGroupName.toLatin1().data(), mainGeom);
1488 if (aGeomVar->_is_nil())
1491 SUIT_OverrideCursor aWaitCursor;
1494 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1496 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1498 if ( !isAccessibleDim( aDim )) continue;
1500 // find or create algorithm
1501 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1502 if ( !anAlgoVar->_is_nil() )
1503 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1504 // assign hypotheses
1505 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1507 int aHypIndex = currentHyp( aDim, aHypType );
1508 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1510 SMESH::SMESH_Hypothesis_var aHypVar =
1511 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1512 if ( !aHypVar->_is_nil() )
1513 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1518 // deselect geometry: next submesh should be created on other subshape
1519 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1520 selectObject( _PTR(SObject)() );
1526 //================================================================================
1528 * \brief Gets current hypothesis or algorithms
1529 * \param theDim - dimension of hypothesis or algorithm
1530 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1531 * \retval int - current hypothesis or algorithms
1533 * Gets current hypothesis or algorithms
1535 //================================================================================
1536 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1538 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1541 //================================================================================
1543 * \brief Returns true if hypotheses of given dim can be assigned
1544 * \param theDim - hypotheses dimension
1545 * \retval bool - result
1547 //================================================================================
1548 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1550 return myDlg->tab( theDim )->isEnabled();
1553 //================================================================================
1555 * \brief Sets current hypothesis or algorithms
1556 * \param theDim - dimension of hypothesis or algorithm
1557 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1558 * \param theIndex - Index of hypothesis
1560 * Gets current hypothesis or algorithms
1562 //================================================================================
1563 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1564 const int theHypType,
1565 const int theIndex )
1567 myIgnoreAlgoSelection = true;
1568 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1569 myIgnoreAlgoSelection = false;
1572 //================================================================================
1574 * \brief Generates default and sets mesh/submesh name
1576 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1578 //================================================================================
1579 void SMESHGUI_MeshOp::setDefaultName() const
1583 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1585 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1586 _PTR(SObject) anObj;
1589 aResName = aPrefix + QString::number( i++ );
1590 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1594 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1595 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1596 aControl->setText( aResName );
1599 //================================================================================
1601 * \brief Gets algorithm or creates it if necessary
1602 * \param theDim - specifies dimension of returned hypotheses/algorifms
1603 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1605 * Gets algorithm or creates it if necessary
1607 //================================================================================
1608 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1610 SMESH::SMESH_Hypothesis_var anAlgoVar;
1612 // get type of the selected algo
1613 int aHypIndex = currentHyp( theDim, Algo );
1614 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1615 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1617 QString aHypName = dataList[ aHypIndex ]->TypeName;
1619 // get existing algoritms
1620 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1622 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1624 // look for anexisting algo of such a type
1625 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1626 THypList::iterator anIter = aHypVarList.begin();
1627 for ( ; anIter != aHypVarList.end(); anIter++)
1629 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1630 CORBA::String_var aName = aHypVar->GetName();
1631 if ( !aHypVar->_is_nil() && aHypName == aName )
1633 anAlgoVar = aHypVar;
1638 if (anAlgoVar->_is_nil()) {
1639 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1641 QString aClientLibName = aHypData->ClientLibName;
1642 if (aClientLibName == "") {
1643 // Call hypothesis creation server method (without GUI)
1644 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1646 // Get hypotheses creator client (GUI)
1647 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1651 aCreator->create(true, aHypName, myDlg);
1653 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1655 QStringList tmpList;
1656 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1657 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1660 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1661 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1663 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1664 CORBA::String_var aName = aHypVar->GetName();
1665 if ( !aHypVar->_is_nil() && aHypName == aName )
1667 anAlgoVar = aHypVar;
1673 return anAlgoVar._retn();
1676 //================================================================================
1678 * \brief Reads parameters of edited mesh and assigns them to the dialog
1680 * Reads parameters of edited mesh and assigns them to the dialog (called when
1681 * mesh is edited only)
1683 //================================================================================
1684 void SMESHGUI_MeshOp::readMesh()
1686 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1687 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1691 if (myIsOnGeometry) {
1692 // Get name of mesh if current object is sub-mesh
1693 SMESH::SMESH_subMesh_var aSubMeshVar =
1694 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1695 if ( !aSubMeshVar->_is_nil() )
1697 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1698 if ( !aMeshVar->_is_nil() )
1700 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1701 QString aMeshName = name( aMeshSO );
1702 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1706 // Get name of geometry object
1707 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1708 if ( !aGeomVar->_is_nil() )
1710 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1711 QString aShapeName = name( aGeomSO );
1712 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1716 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1717 QStringList anExisting;
1718 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1719 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1722 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1723 // find algo index among available ones
1725 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1727 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1728 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1729 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1730 // if ( aHypIndex < 0 && algoData ) {
1731 // // assigned algo is incompatible with other algorithms
1732 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1733 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1736 setCurrentHyp( dim, Algo, aHypIndex );
1737 // set existing and available hypothesis according to the selected algo
1738 onAlgoSelected( aHypIndex, dim );
1742 bool hypWithoutAlgo = false;
1743 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1745 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1748 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1749 // find index of requered hypothesis among existing ones for this dimension and type
1751 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1752 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1753 myExistingHyps[ dim ][ hypType ] );
1754 if ( aHypIndex < 0 ) {
1755 // assigned hypothesis is incompatible with the algorithm
1756 if ( currentHyp( dim, Algo ) < 0 )
1757 { // none algo selected; it is edition for sure, of submesh maybe
1758 hypWithoutAlgo = true;
1759 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1760 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1761 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1765 setCurrentHyp( dim, hypType, aHypIndex );
1768 // make available other hyps of same type as one without algo
1769 if ( hypWithoutAlgo )
1770 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1773 //================================================================================
1775 * \brief Gets name of object
1776 * \param theSO - SObject
1777 * \retval QString - name of object
1779 * Gets name of object
1781 //================================================================================
1782 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1787 _PTR(GenericAttribute) anAttr;
1788 _PTR(AttributeName) aNameAttr;
1789 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1792 aResName = aNameAttr->Value().c_str();
1798 //================================================================================
1800 * \brief Finds hypothesis in input list
1801 * \param theHyp - hypothesis to be found
1802 * \param theHypList - input list of hypotheses
1803 * \retval int - index of hypothesis or -1 if it is not found
1805 * Finds position of hypothesis in input list
1807 //================================================================================
1808 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1809 const THypList& theHypList ) const
1812 if ( !theHyp->_is_nil() )
1815 THypList::const_iterator anIter = theHypList.begin();
1816 for ( ; anIter != theHypList.end(); ++ anIter)
1818 if ( theHyp->_is_equivalent( (*anIter).first ) )
1829 //================================================================================
1831 * \brief Edits mesh or sub-mesh
1832 * \param theMess - Output parameter intended for returning error message
1833 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1835 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1837 //================================================================================
1838 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1842 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1843 if ( aSMESHGen->_is_nil() )
1846 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1847 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1851 SUIT_OverrideCursor aWaitCursor;
1854 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1855 SMESH::SetName( pObj, aName );
1856 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1858 // First, remove old algos in order to avoid messages on algorithm hiding
1859 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1861 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
1863 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
1864 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1865 if ( anAlgoVar->_is_nil() || // no new algo selected or
1866 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
1868 // remove old algorithm
1869 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
1870 myObjHyps[ dim ][ Algo ].clear();
1875 // Assign new algorithms and hypotheses
1876 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1878 if ( !isAccessibleDim( dim )) continue;
1880 // find or create algorithm
1881 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1883 // assign new algorithm
1884 if ( !anAlgoVar->_is_nil() && // some algo selected and
1885 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
1887 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
1888 CORBA::Object_var anObject = aSObject->GetObject();
1889 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
1890 bool isMesh = !aMeshVar->_is_nil();
1892 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1894 SMESH::SMESH_subMesh_var aVar =
1895 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1896 if ( !aVar->_is_nil() )
1897 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1899 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
1902 // assign hypotheses
1903 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1905 int aNewHypIndex = currentHyp( dim, hypType );
1906 int anOldHypIndex = -1;
1908 // remove old hypotheses
1909 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1911 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1912 myExistingHyps[ dim ][ hypType ] );
1913 if ( aNewHypIndex != anOldHypIndex || // different hyps
1914 anOldHypIndex == -1 ) // hyps of different algos
1916 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1917 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
1918 myObjHyps[ dim ][ hypType ].clear();
1922 // assign new hypotheses
1923 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1925 SMESH::SMESH_Mesh_var aMeshVar =
1926 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1927 bool isMesh = !aMeshVar->_is_nil();
1930 SMESH::AddHypothesisOnMesh
1931 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1935 SMESH::SMESH_subMesh_var aVar =
1936 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1937 if ( !aVar->_is_nil() )
1938 SMESH::AddHypothesisOnSubMesh
1939 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1942 // reread all hypotheses of mesh if necessary
1943 QStringList anExisting;
1944 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1951 //================================================================================
1953 * \brief Verifies whether given operator is valid for this one
1954 * \param theOtherOp - other operation
1955 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1957 * method redefined from base class verifies whether given operator is valid for
1958 * this one (i.e. can be started "above" this operator). In current implementation method
1959 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1962 //================================================================================
1963 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1965 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1968 //================================================================================
1970 * \brief SLOT. Is called when the user selects a way of geometry selection
1971 * \param theByMesh - true if the user wants to find geometry by mesh element
1973 //================================================================================
1975 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1978 if ( !myShapeByMeshOp ) {
1979 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1980 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1981 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1982 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1983 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1985 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1986 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1987 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
1988 SMESH::SMESH_Mesh_var aMeshVar =
1989 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1990 if ( !aMeshVar->_is_nil() ) {
1991 myDlg->hide(); // stop processing selection
1992 myShapeByMeshOp->setModule( getSMESHGUI() );
1993 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1994 myShapeByMeshOp->SetMesh( aMeshVar );
1995 myShapeByMeshOp->start();
2001 //================================================================================
2003 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2005 //================================================================================
2007 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2009 if ( myShapeByMeshOp == op ) {
2010 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2012 // Select a found geometry object
2013 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2014 if ( !aGeomVar->_is_nil() )
2016 QString ID = aGeomVar->GetStudyEntry();
2017 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2018 selectObject( aGeomSO );
2025 //================================================================================
2027 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2029 //================================================================================
2031 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2033 if ( myShapeByMeshOp == op && myDlg ) {
2038 //================================================================================
2040 * \brief Selects a SObject
2041 * \param theSObj - the SObject to select
2043 //================================================================================
2045 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2047 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2048 SALOME_ListIO anIOList;
2050 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2051 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2052 anIOList.Append( anIO );
2054 sm->setSelectedObjects( anIOList, false );