1 // Copyright (C) 2007-2008 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.
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
25 * Copyright (C) 2005 CEA/DEN, EDF R&D
29 * File : SMESHGUI_MeshOp.h
30 * Author : Sergey LITONIN
34 #include "SMESHGUI_MeshOp.h"
35 #include "SMESHGUI_MeshDlg.h"
36 #include "SMESHGUI_ShapeByMeshDlg.h"
37 #include "SMESH_TypeFilter.hxx"
40 #include "SMESHGUI_HypothesesUtils.h"
41 #include "SMESHGUI_Hypotheses.h"
42 #include "SMESHGUI_Utils.h"
43 #include "SMESHGUI_GEOMGenUtils.h"
44 #include "SMESHGUI_VTKUtils.h"
46 #include "SMESH_TypeFilter.hxx"
47 #include "SMESH_NumberFilter.hxx"
49 #include CORBA_CLIENT_HEADER(SMESH_Gen)
51 #include "GEOM_SelectionFilter.h"
53 #include "GeometryGUI.h"
55 #include "SalomeApp_Tools.h"
56 #include "SalomeApp_Application.h"
57 #include "SALOMEDSClient_Study.hxx"
58 #include "SALOMEDSClient_AttributeIOR.hxx"
59 #include "SALOMEDSClient_AttributeName.hxx"
60 #include "SALOMEDS_SComponent.hxx"
61 #include "SALOMEDS_SObject.hxx"
63 #include "LightApp_SelectionMgr.h"
64 #include "LightApp_UpdateFlags.h"
65 #include "SUIT_MessageBox.h"
66 #include "SUIT_Desktop.h"
67 #include "SUIT_OverrideCursor.h"
68 #include "SALOME_InteractiveObject.hxx"
69 #include "SALOME_ListIO.hxx"
71 #include "utilities.h"
73 #include <qstringlist.h>
74 #include <qlineedit.h>
76 #include <TopoDS_Shape.hxx>
77 #include <TopExp_Explorer.hxx>
81 //================================================================================
84 * \param theToCreate - if this parameter is true then operation is used for creation,
85 * for editing otherwise
87 * Initialize operation
89 //================================================================================
90 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
91 : SMESHGUI_SelectionOp(),
92 myToCreate( theToCreate ),
93 myIsMesh( theIsMesh ),
97 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
98 GeometryGUI::InitGeomGen();
99 myIsOnGeometry = true;
102 //================================================================================
106 //================================================================================
107 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
113 //================================================================================
115 * \brief Gets dialog of this operation
116 * \retval LightApp_Dialog* - pointer to dialog of this operation
118 //================================================================================
119 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
124 //================================================================================
126 * \brief Creates or edits mesh
127 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
129 * Virtual slot redefined from the base class called when "Apply" button is clicked
130 * creates or edits mesh
132 //================================================================================
133 bool SMESHGUI_MeshOp::onApply()
139 if ( !isValid( aMess ) )
143 SUIT_MessageBox::warn1( myDlg,
144 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
148 bool aResult = false;
152 if ( myToCreate && myIsMesh )
153 aResult = createMesh( aMess );
154 if ( myToCreate && !myIsMesh )
155 aResult = createSubMesh( aMess );
156 else if ( !myToCreate )
157 aResult = editMeshOrSubMesh( aMess );
159 update( UF_ObjBrowser | UF_Model );
161 catch ( const SALOME::SALOME_Exception& S_ex )
163 SalomeApp_Tools::QtCatchCorbaException( S_ex );
179 aMess = tr( "SMESH_OPERATION_FAILED" );
180 SUIT_MessageBox::warn1( myDlg,
181 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
187 //================================================================================
189 * \brief Creates dialog if necessary and shows it
191 * Virtual method redefined from base class called when operation is started creates
192 * dialog if necessary and shows it, activates selection
194 //================================================================================
195 void SMESHGUI_MeshOp::startOperation()
199 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
200 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
202 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
203 this, SLOT( onCreateHyp( const int, const int ) ) );
204 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
205 this, SLOT( onEditHyp( const int, const int ) ) );
206 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
207 this, SLOT( onAlgoSelected( const int ) ) );
209 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
210 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
213 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
214 else myHelpFileName = "constructing_submeshes_page.html";
215 else myHelpFileName = "editing_meshes_page.html";
217 SMESHGUI_SelectionOp::startOperation();
219 // iterate through dimensions and get available algoritms, set them to the dialog
220 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
221 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
223 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
225 // clear available hypotheses
226 aTab->setAvailableHyps( MainHyp, hypList );
227 aTab->setAvailableHyps( AddHyp, hypList );
228 aTab->setExistingHyps( MainHyp, hypList );
229 aTab->setExistingHyps( AddHyp, hypList );
230 myExistingHyps[ i ][ MainHyp ].clear();
231 myExistingHyps[ i ][ AddHyp ].clear();
233 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
234 aTab->setAvailableHyps( Algo, hypList );
239 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
242 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
244 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
246 myDlg->setCurrentTab( SMESH::DIM_3D );
251 myIgnoreAlgoSelection = false;
254 //================================================================================
256 * \brief Creates selection filter
257 * \param theId - identifier of current selection widget
258 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
260 * Creates selection filter in accordance with identifier of current selection widget
262 //================================================================================
263 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
265 if ( theId == SMESHGUI_MeshDlg::Geom )
267 // TColStd_MapOfInteger allTypesMap;
268 // for ( int i = 0; i < 10; i++ )
269 // allTypesMap.Add( i );
270 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
271 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
273 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
274 return new SMESH_TypeFilter( MESHorSUBMESH );
275 else if ( theId == SMESHGUI_MeshDlg::Mesh )
276 return new SMESH_TypeFilter( MESH );
281 //================================================================================
283 * \brief check if selected shape is a subshape of the shape to mesh
284 * \retval bool - check result
286 //================================================================================
288 bool SMESHGUI_MeshOp::isSubshapeOk() const
290 if ( !myToCreate || myIsMesh ) // not submesh creation
294 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
295 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
296 if (!pMesh) return false;
298 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
299 if (mesh->_is_nil()) return false;
301 // main shape of the mesh
302 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
303 if (mainGeom->_is_nil()) return false;
307 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
309 if (aGEOMs.count() > 0) {
310 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
311 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
312 if (geomGen->_is_nil() || !aStudy) return false;
314 GEOM::GEOM_IGroupOperations_var op =
315 geomGen->GetIGroupOperations(aStudy->StudyId());
316 if (op->_is_nil()) return false;
318 // check all selected shapes
319 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
320 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
321 QString aSubGeomEntry = (*aSubShapesIter);
322 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
323 if (!pSubGeom) return false;
325 GEOM::GEOM_Object_var aSubGeomVar =
326 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
327 if (aSubGeomVar->_is_nil()) return false;
329 // skl for NPAL14695 - implementation of searching of mainObj
330 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
331 //if (mainObj->_is_nil() ||
332 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
334 if (mainObj->_is_nil())
336 if (string(mainObj->GetEntry()) == string(mainGeom->GetEntry()))
338 mainObj = op->GetMainShape(mainObj);
347 //================================================================================
349 * \brief Return name of the algorithm that does not support submeshes and makes
350 * submesh creation useless
351 * \retval char* - string is to be deleted!!!
353 //================================================================================
355 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
357 if ( myToCreate && !myIsMesh ) {
359 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
360 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
361 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
364 QStringList algoNames;
366 existingHyps(3, Algo, pMesh, algoNames, algoList);
367 if (!algoList.empty()) {
368 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
370 algo->InputTypes.empty() && // builds all dimensions it-self
371 !algo->IsSupportSubmeshes )
372 return CORBA::string_dup( algoNames[0].latin1() );
375 // GEOM::GEOM_Object_var geom;
376 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ))
377 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
379 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
380 existingHyps(2, Algo, pMesh, algoNames, algoList);
381 if (!algoList.empty()) {
382 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
384 algo->InputTypes.empty() && // builds all dimensions it-self
385 !algo->IsSupportSubmeshes )
386 return CORBA::string_dup( algoNames[0].latin1() );
394 //================================================================================
396 * \brief find an existing submesh by the selected shape
397 * \retval _PTR(SObject) - the found submesh SObject
399 //================================================================================
401 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
403 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
404 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
405 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
406 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
407 if ( pMesh && pGeom ) {
408 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
409 if ( !geom->_is_nil() ) {
411 switch ( geom->GetShapeType() ) {
412 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex ; break;
413 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge ; break;
414 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire ; break;
415 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace ; break;
416 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell ; break;
417 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid ; break;
418 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
421 _PTR(GenericAttribute) anAttr;
422 _PTR(SObject) aSubmeshRoot;
423 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
424 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
426 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
427 for (; smIter->More(); smIter->Next() )
429 _PTR(SObject) aSmObj = smIter->Value();
430 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
432 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
433 for (; anIter1->More(); anIter1->Next()) {
434 _PTR(SObject) pGeom2 = anIter1->Value();
435 if ( pGeom2->ReferencedObject( pGeom2 ) &&
436 pGeom2->GetID() == pGeom->GetID() )
443 return _PTR(SObject)();
446 //================================================================================
448 * \brief Updates dialog's look and feel
450 * Virtual method redefined from the base class updates dialog's look and feel
452 //================================================================================
453 void SMESHGUI_MeshOp::selectionDone()
455 if (!dlg()->isShown() || !myDlg->isEnabled())
458 SMESHGUI_SelectionOp::selectionDone();
462 myIsOnGeometry = true;
464 //Check geometry for mesh
465 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
466 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.latin1());
469 SMESH::SMESH_Mesh_var aMeshVar =
470 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
471 if (!aMeshVar->_is_nil()) {
472 if (!myToCreate && !aMeshVar->HasShapeToMesh())
473 myIsOnGeometry = false;
479 // Enable tabs according to shape dimension
484 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
485 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
487 if (aGEOMs.count() > 0) {
488 // one or more GEOM shape selected
489 aSeq->length(aGEOMs.count());
490 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
492 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
493 QString aSubGeomEntry = (*aSubShapesIter);
494 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
495 GEOM::GEOM_Object_var aSubGeomVar =
496 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
497 aSeq[iSubSh] = aSubGeomVar;
500 // get geometry by selected sub-mesh
501 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
502 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
503 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
504 if (!aGeomVar->_is_nil()) {
510 if (aSeq->length() > 0) {
512 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
513 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
514 switch ( aGeomVar->GetShapeType() ) {
516 case GEOM::SHELL: shapeDim = 3; break;
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;
523 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
524 TopExp_Explorer exp( aShape, TopAbs_SHELL );
527 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
528 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
529 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
530 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
537 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
538 // reset algos before disabling tabs (0020138)
539 onAlgoSelected(-1, i);
541 myDlg->setMaxHypoDim( shapeDim );
544 if (!myToCreate) // edition: read hypotheses
548 SMESH::SMESH_subMesh_var aVar =
549 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
550 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
551 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
552 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
553 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
554 myDlg->updateGeometry();
561 else if ( !myIsMesh ) // submesh creation
563 // if a submesh on the selected shape already exist, pass to submesh edition mode
564 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
565 SMESH::SMESH_subMesh_var sm =
566 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
567 bool editSubmesh = ( !sm->_is_nil() &&
568 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
569 tr( "EDIT_SUBMESH_QUESTION"),
570 tr( "SMESH_BUT_YES" ),
571 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
574 selectionMgr()->clearFilters();
575 selectObject( pSubmesh );
576 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
581 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
582 selectObject( _PTR(SObject)() );
587 // discard selected mesh if submesh creation not allowed because of
588 // a global algorithm that does not support submeshes
589 if ( char* algoName = isSubmeshIgnored() ) {
590 SUIT_MessageBox::warn1( myDlg, tr( "SMESH_ERROR" ),
591 tr("SUBMESH_NOT_ALLOWED").arg(algoName), tr( "SMESH_BUT_OK" ));
592 CORBA::string_free( algoName );
593 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
594 selectObject( _PTR(SObject)() );
599 // enable/disable popup for choice of geom selection way
601 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
602 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
603 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
604 if ( !mesh->_is_nil() )
605 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
607 myDlg->setGeomPopupEnabled( enable );
611 myDlg->enableTab( SMESH::DIM_3D );
613 availableHyps( SMESH::DIM_3D, Algo, hypList,
614 myAvailableHypData[SMESH::DIM_3D][Algo]);
616 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
617 aTab->setAvailableHyps( Algo, hypList );
618 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
619 myDlg->disableTab(i);
621 //Hide labels and fields (Mesh ang Geometry)
622 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
623 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
628 catch ( const SALOME::SALOME_Exception& S_ex )
630 SalomeApp_Tools::QtCatchCorbaException( S_ex );
637 //================================================================================
639 * \brief Verifies validity of input data
640 * \param theMess - Output parameter intended for returning error message
641 * \retval bool - TRUE if input data is valid, false otherwise
643 * Verifies validity of input data. This method is called when "Apply" or "OK" button
644 * is pressed before mesh creation or editing.
646 //================================================================================
647 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
649 // Selected object to be edited
650 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
652 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
657 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
658 aMeshName = aMeshName.stripWhiteSpace();
659 if ( aMeshName == "" )
661 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
665 /* // Imported mesh, if create sub-mesh or edit mesh
666 if ( !myToCreate || ( myToCreate && !myIsMesh ))
668 QString aMeshEntry = myDlg->selectedObject
669 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
670 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
671 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
672 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
673 theMess = tr( "IMPORTED_MESH" );
682 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
683 if ( aGeomEntry == "" )
685 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
688 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
689 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
691 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
696 if ( !myIsMesh ) // i.e sub-mesh creation,
698 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
699 if ( aMeshEntry == "" )
701 theMess = tr( "MESH_IS_NOT_DEFINED" );
704 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
705 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
707 theMess = tr( "MESH_IS_NULL" );
710 if ( !isSubshapeOk() )
712 theMess = tr( "INVALID_SUBSHAPE" );
721 //================================================================================
723 * \brief check compatibility of the algorithm and another algorithm or hypothesis
724 * \param theAlgoData - algorithm data
725 * \param theHypData - hypothesis data
726 * \param theHypType - hypothesis type
727 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
728 * \retval bool - check result
730 //================================================================================
732 static bool isCompatible(const HypothesisData* theAlgoData,
733 const HypothesisData* theHypData,
734 const int theHypType)
739 if ( theHypType == SMESHGUI_MeshOp::Algo )
740 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
743 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
746 //================================================================================
748 * \brief Gets available hypotheses or algorithms
749 * \param theDim - specifies dimension of returned hypotheses/algorifms
750 * \param theHypType - specifies whether algorims or hypotheses or additional ones
751 * are retrieved (possible values are in HypType enumeration)
752 * \param theHyps - Output list of hypotheses' names
753 * \param theAlgoData - to select hypos able to be used by this algo (optional)
755 * Gets available hypotheses or algorithm in accordance with input parameters
757 //================================================================================
758 void SMESHGUI_MeshOp::availableHyps( const int theDim,
759 const int theHypType,
760 QStringList& theHyps,
761 THypDataList& theDataList,
762 HypothesisData* theAlgoData ) const
766 bool isAlgo = ( theHypType == Algo );
767 bool isAux = ( theHypType == AddHyp );
768 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
770 QStringList::const_iterator anIter;
771 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
773 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
774 if ( isCompatible ( theAlgoData, aData, theHypType )) {
775 theDataList.append( aData );
776 theHyps.append( aData->Label );
781 //================================================================================
783 * \brief Gets existing hypotheses or algorithms
784 * \param theDim - specifies dimension of returned hypotheses/algorifms
785 * \param theHypType - specifies whether algorims or hypotheses or additional ones
786 * are retrieved (possible values are in HypType enumeration)
787 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
788 * \param theHyps - output list of names.
789 * \param theHypVars - output list of variables.
790 * \param theAlgoData - to select hypos able to be used by this algo (optional)
792 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
795 //================================================================================
796 void SMESHGUI_MeshOp::existingHyps( const int theDim,
797 const int theHypType,
798 _PTR(SObject) theFather,
799 QStringList& theHyps,
800 THypList& theHypList,
801 HypothesisData* theAlgoData)
803 // Clear hypoheses list
810 const bool isAux = ( theHypType == AddHyp );
812 _PTR(SObject) aHypRoot;
813 _PTR(GenericAttribute) anAttr;
814 _PTR(AttributeName) aName;
815 _PTR(AttributeIOR) anIOR;
817 bool isMesh = !_CAST( SComponent, theFather );
820 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
822 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
824 if ( theFather->FindSubObject( aPart, aHypRoot ) )
826 _PTR(ChildIterator) anIter =
827 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
828 for (; anIter->More(); anIter->Next() )
830 _PTR(SObject) anObj = anIter->Value();
831 if ( isMesh ) // i.e. mesh or submesh
833 _PTR(SObject) aRefObj;
834 if ( anObj->ReferencedObject( aRefObj ) )
839 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
842 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
843 if ( !CORBA::is_nil( aVar ) )
845 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
846 if ( !aHypVar->_is_nil() )
848 CORBA::String_var aHypType( aHypVar->GetName() );
849 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
850 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
851 ( isCompatible ( theAlgoData, aData, theHypType )) &&
852 ( isAux == aData->IsAux ))
854 std::string aHypName = aName->Value();
855 theHyps.append( aHypName.c_str() );
856 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
865 //================================================================================
867 * \brief If create or edit a submesh, return a hypothesis holding parameters used
869 * \param aHypType - The hypothesis type name
870 * \param aServerLib - Server library name
871 * \param hypData - The structure holding the hypothesis type etc.
872 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
874 //================================================================================
876 SMESH::SMESH_Hypothesis_var
877 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
878 const QString& aServerLib ) const
880 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
881 return SMESH::SMESH_Hypothesis::_nil();
883 const int nbColonsInMeshEntry = 3;
884 bool isSubMesh = myToCreate ?
886 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
890 // get mesh and geom object
891 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
892 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
894 QString anEntry = myDlg->selectedObject
895 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
896 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
898 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
899 if ( myToCreate ) // mesh and geom may be selected
901 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
902 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
903 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
904 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
906 else // edition: sub-mesh may be selected
908 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
909 if ( !sm->_is_nil() ) {
910 aMeshVar = sm->GetFather();
911 aGeomVar = sm->GetSubShape();
916 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
917 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
922 return SMESH::SMESH_Hypothesis::_nil();
925 //================================================================================
927 * \Brief Returns tab dimention
928 * \param tab - the tab in the dlg
929 * \param dlg - my dialogue
930 * \retval int - dimention
932 //================================================================================
934 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
937 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
938 if (tab == dlg->tab(i))
943 //================================================================================
945 * \brief Create hypothesis
946 * \param theHypType - hypothesis category (main or additional)
947 * \param theIndex - index of type of hypothesis to be cerated
949 * Specifies dimension of hypothesis to be created (using sender() method),
950 * specifies its type and calls method for hypothesis creation
952 //================================================================================
953 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
955 // Specifies dimension of hypothesis to be created
956 int aDim = getTabDim( sender(), myDlg );
960 // Specifies type of hypothesis to be created
961 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
962 if (theIndex < 0 || theIndex >= dataList.count())
964 QString aHypTypeName = dataList[ theIndex ]->TypeName;
967 createHypothesis(aDim, theHypType, aHypTypeName);
970 //================================================================================
972 * Create hypothesis and update dialog.
973 * \param theDim - dimension of hypothesis to be created
974 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
975 * \param theTypeName - specifies hypothesis to be created
977 //================================================================================
980 QString GetUniqueName (const QStringList& theHypNames,
981 const QString& theName,
982 size_t theIteration = 1)
984 QString aName = theName + "_" + QString::number( theIteration );
985 if ( theHypNames.contains( aName ) )
986 return GetUniqueName( theHypNames, theName, ++theIteration );
991 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
993 const QString& theTypeName)
995 // During a hypothesis creation we might need to select some objects.
996 // Main dialog must not update it's own selected objects in this case.
997 dlg()->deactivateAll();
999 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
1003 QStringList aHypNames;
1004 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1005 for (; aDimIter != myExistingHyps.end(); aDimIter++) {
1006 const TType2HypList& aType2HypList = aDimIter.data();
1007 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1008 for (; aTypeIter != aType2HypList.end(); aTypeIter++) {
1009 const THypList& aHypList = aTypeIter.data();
1010 THypList::const_iterator anIter = aHypList.begin();
1011 for (; anIter != aHypList.end(); anIter++) {
1012 const THypItem& aHypItem = *anIter;
1013 const QString& aHypName = aHypItem.second;
1014 aHypNames.append(aHypName);
1018 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1021 int nbHyp = myExistingHyps[theDim][theType].count();
1023 QString aClientLibName = aData->ClientLibName;
1024 if (aClientLibName == "") {
1025 // Call hypothesis creation server method (without GUI)
1026 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1028 // Get hypotheses creator client (GUI)
1029 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1031 // Create hypothesis
1033 // When create or edit a submesh, try to initialize a new hypothesis
1034 // with values used to mesh a subshape
1035 SMESH::SMESH_Hypothesis_var initParamHyp =
1036 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1037 myDlg->setEnabled( false );
1038 aCreator->create(initParamHyp, aHypName, myDlg);
1039 myDlg->setEnabled( true );
1041 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1045 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1047 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
1048 QStringList aNewHyps;
1049 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
1050 if (aNewHyps.count() > nbHyp) {
1051 for (int i = nbHyp; i < aNewHyps.count(); i++)
1052 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
1056 //================================================================================
1058 * \brief Calls plugin methods for hypothesis editing
1059 * \param theHypType - specifies whether main hypothesis or additional one
1061 * \param theIndex - index of existing hypothesis
1063 * Calls plugin methods for hypothesis editing
1065 //================================================================================
1066 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1068 // Speicfies dimension of hypothesis to be created
1069 int aDim = getTabDim( sender(), myDlg );
1073 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1074 if ( theIndex < 0 || theIndex >= aList.count() )
1076 const THypItem& aHypItem = aList[ theIndex ];
1077 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1078 if ( aHyp->_is_nil() )
1081 CORBA::String_var aTypeName = aHyp->GetName();
1082 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
1084 myDlg->setEnabled( false );
1085 aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
1086 myDlg->setEnabled( true );
1090 //================================================================================
1092 * \brief access to hypothesis data
1093 * \param theDim - hyp dimension
1094 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1095 * \param theIndex - index in the list
1096 * \retval HypothesisData* - result data, may be 0
1098 //================================================================================
1100 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1101 const int theHypType,
1104 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1105 theHypType > -1 && theHypType < NbHypTypes &&
1106 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1107 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1111 //================================================================================
1113 * \brief Set available algos and hypos according to the selected algorithm
1114 * \param theIndex - algorithm index
1116 //================================================================================
1118 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1121 if ( myIgnoreAlgoSelection )
1124 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1128 // find highest available dimension, all algos of this dimension are available for choice
1130 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1131 if (isAccessibleDim( i ))
1136 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1138 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1139 HypothesisData* algoByDim[4];
1140 algoByDim[ aDim ] = algoData;
1142 QStringList anAvailable;
1143 if ( !algoData ) { // all algos becomes available
1144 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1145 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1148 // check that algorithms of other dimentions are compatible with
1151 // 2 loops: backward and forward from algo dimension
1152 for ( int forward = false; forward <= true; ++forward )
1154 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1156 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1158 HypothesisData* prevAlgo = algoData;
1159 bool noCompatible = false;
1160 for (; dim * dir <= lastDim * dir; dim += dir)
1162 if ( !isAccessibleDim( dim ))
1164 if ( noCompatible ) { // the selected algo has no compatible ones
1165 anAvailable.clear();
1166 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1167 myAvailableHypData[dim][Algo].clear();
1168 algoByDim[ dim ] = 0;
1171 // get currently selected algo
1172 int algoIndex = currentHyp( dim, Algo );
1173 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1174 if ( curAlgo ) { // some algo selected
1175 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1178 // set new available algoritms
1179 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1180 HypothesisData* soleCompatible = 0;
1181 if ( anAvailable.count() == 1 )
1182 soleCompatible = myAvailableHypData[dim][Algo][0];
1183 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1184 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1185 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1186 noCompatible = anAvailable.isEmpty();
1188 // restore previously selected algo
1189 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1190 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1191 // select the sole compatible algo
1192 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1193 setCurrentHyp( dim, Algo, algoIndex );
1195 // remember current algo
1196 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1200 // set hypotheses corresponding to the found algoritms
1202 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1204 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1206 if ( !isAccessibleDim( dim ))
1208 for ( int type = MainHyp; type < NbHypTypes; type++ )
1210 myAvailableHypData[ dim ][ type ].clear();
1211 QStringList anAvailable, anExisting;
1213 HypothesisData* curAlgo = algoByDim[ dim ];
1214 int hypIndex = currentHyp( dim, type );
1216 SMESH::SMESH_Hypothesis_var curHyp;
1217 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1218 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1220 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1221 // try to find algo by selected hypothesis in order to keep it selected
1222 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1223 CORBA::String_var curHypType = curHyp->GetName();
1224 if ( !algoDeselectedByUser &&
1225 myObjHyps[ dim ][ type ].count() > 0 &&
1226 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1228 CORBA::String_var aName = curHyp->GetName();
1229 HypothesisData* hypData = SMESH::GetHypothesisData( aName );
1230 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1231 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1232 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1239 // get hyps compatible with curAlgo
1242 // check if a selected hyp is compatible with the curAlgo
1243 if ( !curHyp->_is_nil() ) {
1244 CORBA::String_var aName = curHyp->GetName();
1245 HypothesisData* hypData = SMESH::GetHypothesisData( aName );
1246 if ( !isCompatible( curAlgo, hypData, type ))
1247 curHyp = SMESH::SMESH_Hypothesis::_nil();
1249 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1250 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1252 // set list of hypotheses
1253 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1254 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1256 // set current existing hypothesis
1257 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1258 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1261 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1262 // none is yet selected => select the sole existing if it is not optional
1263 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1264 bool isOptional = true;
1265 if ( algoByDim[ dim ] &&
1266 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1270 setCurrentHyp( dim, type, hypIndex );
1275 //================================================================================
1277 * \brief Creates and selects hypothesis of hypotheses set
1278 * \param theSetName - The name of hypotheses set
1280 //================================================================================
1281 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1283 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1284 if (!aHypoSet) return;
1287 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1288 setCurrentHyp(dim, Algo, -1);
1289 setCurrentHyp(dim, AddHyp, -1);
1290 setCurrentHyp(dim, MainHyp, -1);
1293 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1294 bool isAlgo = (aHypType == Algo);
1296 // set hyps from the set
1297 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1298 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1299 const QString& aHypoTypeName = (*aHypoList)[ i ];
1300 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1304 int aDim = aHypData->Dim[0];
1305 // create or/and set
1307 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1309 QStringList anAvailable;
1310 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1311 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1312 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1314 setCurrentHyp( aDim, Algo, index );
1315 onAlgoSelected( index, aDim );
1318 bool mainHyp = true;
1319 QStringList anAvailable;
1320 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1321 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1322 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1325 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1328 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1330 } // loop on hypos in the set
1331 } // loop on algo/hypo
1334 //================================================================================
1336 * \brief Creates mesh
1337 * \param theMess - Output parameter intended for returning error message
1338 * \retval bool - TRUE if mesh is created, FALSE otherwise
1342 //================================================================================
1343 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1347 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1348 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1351 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1352 QStringList::Iterator it = aList.begin();
1353 for (; it!=aList.end(); it++)
1355 QString aGeomEntry = *it;
1356 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1357 GEOM::GEOM_Object_var aGeomVar =
1358 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1360 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1361 if ( aSMESHGen->_is_nil() )
1364 SUIT_OverrideCursor aWaitCursor;
1367 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1368 if ( aMeshVar->_is_nil() )
1370 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1372 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1374 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1375 if ( !isAccessibleDim( aDim )) continue;
1377 // assign hypotheses
1378 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1379 int aHypIndex = currentHyp( aDim, aHypType );
1380 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1381 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1382 if ( !aHypVar->_is_nil() )
1383 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1386 // find or create algorithm
1387 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1388 if ( !anAlgoVar->_is_nil() )
1389 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1396 //================================================================================
1398 * \brief Creates sub-mesh
1399 * \param theMess - Output parameter intended for returning error message
1400 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1404 //================================================================================
1405 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1409 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1410 if ( aSMESHGen->_is_nil() )
1414 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1415 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1416 SMESH::SMESH_Mesh_var aMeshVar =
1417 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1418 if (aMeshVar->_is_nil())
1421 // GEOM shape of the main mesh
1422 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1424 // Name for the new sub-mesh
1425 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1428 GEOM::GEOM_Object_var aGeomVar;
1430 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1431 if (aGEOMs.count() == 1)
1433 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1434 QString aGeomEntry = aGEOMs.first();
1435 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1436 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1438 else if (aGEOMs.count() > 1)
1440 // create a GEOM group
1441 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1442 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1443 if (!geomGen->_is_nil() && aStudy) {
1444 GEOM::GEOM_IGroupOperations_var op =
1445 geomGen->GetIGroupOperations(aStudy->StudyId());
1446 if (!op->_is_nil()) {
1447 // check and add all selected GEOM objects: they must be
1448 // a sub-shapes of the main GEOM and must be of one type
1450 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1451 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1452 aSeq->length(aGEOMs.count());
1453 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1454 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1455 QString aSubGeomEntry = (*aSubShapesIter);
1456 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
1457 GEOM::GEOM_Object_var aSubGeomVar =
1458 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1459 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1461 aGroupType = aSubShapeType;
1463 if (aSubShapeType != aGroupType)
1464 aGroupType = TopAbs_SHAPE;
1466 aSeq[iSubSh] = aSubGeomVar;
1469 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1470 op->UnionList(aGroupVar, aSeq);
1473 aGeomVar = aGroupVar;
1475 // publish the GEOM group in study
1476 QString aNewGeomGroupName ("Auto_group_for_");
1477 aNewGeomGroupName += aName;
1478 SALOMEDS::SObject_var aNewGroupSO =
1479 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
1486 if (aGeomVar->_is_nil())
1489 SUIT_OverrideCursor aWaitCursor;
1492 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1494 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1496 if ( !isAccessibleDim( aDim )) continue;
1498 // find or create algorithm
1499 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1500 if ( !anAlgoVar->_is_nil() )
1501 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1502 // assign hypotheses
1503 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1505 int aHypIndex = currentHyp( aDim, aHypType );
1506 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1508 SMESH::SMESH_Hypothesis_var aHypVar =
1509 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1510 if ( !aHypVar->_is_nil() )
1511 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1516 // deselect geometry: next submesh should be created on other subshape
1517 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1518 selectObject( _PTR(SObject)() );
1524 //================================================================================
1526 * \brief Gets current hypothesis or algorithms
1527 * \param theDim - dimension of hypothesis or algorithm
1528 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1529 * \retval int - current hypothesis or algorithms
1531 * Gets current hypothesis or algorithms
1533 //================================================================================
1534 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1536 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1539 //================================================================================
1541 * \brief Returns true if hypotheses of given dim can be assigned
1542 * \param theDim - hypotheses dimension
1543 * \retval bool - result
1545 //================================================================================
1546 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1548 return myDlg->tab( theDim )->isEnabled();
1551 //================================================================================
1553 * \brief Sets current hypothesis or algorithms
1554 * \param theDim - dimension of hypothesis or algorithm
1555 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1556 * \param theIndex - Index of hypothesis
1558 * Gets current hypothesis or algorithms
1560 //================================================================================
1561 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1562 const int theHypType,
1563 const int theIndex )
1565 myIgnoreAlgoSelection = true;
1566 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1567 myIgnoreAlgoSelection = false;
1570 //================================================================================
1572 * \brief Generates default and sets mesh/submesh name
1574 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1576 //================================================================================
1577 void SMESHGUI_MeshOp::setDefaultName() const
1581 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1583 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1584 _PTR(SObject) anObj;
1587 aResName = aPrefix + QString::number( i++ );
1588 anObj = aStudy->FindObject( aResName.latin1() );
1592 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1593 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1594 aControl->setText( aResName );
1597 //================================================================================
1599 * \brief Gets algorithm or creates it if necessary
1600 * \param theDim - specifies dimension of returned hypotheses/algorifms
1601 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1603 * Gets algorithm or creates it if necessary
1605 //================================================================================
1606 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1608 SMESH::SMESH_Hypothesis_var anAlgoVar;
1610 // get type of the selected algo
1611 int aHypIndex = currentHyp( theDim, Algo );
1612 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1613 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1615 QString aHypName = dataList[ aHypIndex ]->TypeName;
1617 // get existing algoritms
1618 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1620 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1622 // look for anexisting algo of such a type
1623 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1624 THypList::iterator anIter = aHypVarList.begin();
1625 for (; anIter != aHypVarList.end(); anIter++)
1627 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1628 CORBA::String_var aName = aHypVar->GetName();
1629 if ( !aHypVar->_is_nil() && aHypName == aName )
1631 anAlgoVar = aHypVar;
1636 if (anAlgoVar->_is_nil()) {
1637 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1639 QString aClientLibName = aHypData->ClientLibName;
1640 if (aClientLibName == "") {
1641 // Call hypothesis creation server method (without GUI)
1642 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1644 // Get hypotheses creator client (GUI)
1645 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1649 aCreator->create(true, aHypName, myDlg);
1651 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1653 QStringList tmpList;
1654 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1655 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1658 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1659 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1661 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1662 CORBA::String_var aName = aHypVar->GetName();
1663 if ( !aHypVar->_is_nil() && aHypName == aName )
1665 anAlgoVar = aHypVar;
1671 return anAlgoVar._retn();
1674 //================================================================================
1676 * \brief Reads parameters of edited mesh and assigns them to the dialog
1678 * Reads parameters of edited mesh and assigns them to the dialog (called when
1679 * mesh is edited only)
1681 //================================================================================
1682 void SMESHGUI_MeshOp::readMesh()
1684 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1685 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1689 if (myIsOnGeometry) {
1690 // Get name of mesh if current object is sub-mesh
1691 SMESH::SMESH_subMesh_var aSubMeshVar =
1692 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1693 if ( !aSubMeshVar->_is_nil() )
1695 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1696 if ( !aMeshVar->_is_nil() )
1698 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1699 QString aMeshName = name( aMeshSO );
1700 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1704 // Get name of geometry object
1705 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1706 if ( !aGeomVar->_is_nil() )
1708 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1709 QString aShapeName = name( aGeomSO );
1710 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1714 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1715 QStringList anExisting;
1716 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1717 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1720 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1721 // find algo index among available ones
1723 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1725 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1726 CORBA::String_var aHypTypeName = aVar->GetName();
1727 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1728 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1729 // if ( aHypIndex < 0 && algoData ) {
1730 // // assigned algo is incompatible with other algorithms
1731 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1732 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1735 setCurrentHyp( dim, Algo, aHypIndex );
1736 // set existing and available hypothesis according to the selected algo
1737 onAlgoSelected( aHypIndex, dim );
1741 bool hypWithoutAlgo = false;
1742 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1744 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1747 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1748 // find index of requered hypothesis among existing ones for this dimension and type
1750 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1751 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1752 myExistingHyps[ dim ][ hypType ] );
1753 if ( aHypIndex < 0 ) {
1754 // assigned hypothesis is incompatible with the algorithm
1755 if ( currentHyp( dim, Algo ) < 0 )
1756 { // none algo selected; it is edition for sure, of submesh maybe
1757 hypWithoutAlgo = true;
1758 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1759 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1760 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1764 setCurrentHyp( dim, hypType, aHypIndex );
1767 // make available other hyps of same type as one without algo
1768 if ( hypWithoutAlgo )
1769 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1772 //================================================================================
1774 * \brief Gets name of object
1775 * \param theSO - SObject
1776 * \retval QString - name of object
1778 * Gets name of object
1780 //================================================================================
1781 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1786 _PTR(GenericAttribute) anAttr;
1787 _PTR(AttributeName) aNameAttr;
1788 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1791 aResName = aNameAttr->Value().c_str();
1797 //================================================================================
1799 * \brief Finds hypothesis in input list
1800 * \param theHyp - hypothesis to be found
1801 * \param theHypList - input list of hypotheses
1802 * \retval int - index of hypothesis or -1 if it is not found
1804 * Finds position of hypothesis in input list
1806 //================================================================================
1807 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1808 const THypList& theHypList ) const
1811 if ( !theHyp->_is_nil() )
1814 THypList::const_iterator anIter = theHypList.begin();
1815 for (; anIter != theHypList.end(); ++ anIter)
1817 if ( theHyp->_is_equivalent( (*anIter).first ) )
1828 //================================================================================
1830 * \brief Edits mesh or sub-mesh
1831 * \param theMess - Output parameter intended for returning error message
1832 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1834 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1836 //================================================================================
1837 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1841 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1842 if ( aSMESHGen->_is_nil() )
1845 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1846 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1850 SUIT_OverrideCursor aWaitCursor;
1853 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1854 SMESH::SetName( pObj, aName.latin1() );
1855 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1857 // First, remove old algos in order to avoid messages on algorithm hiding
1858 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1860 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
1862 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
1863 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1864 if ( anAlgoVar->_is_nil() || // no new algo selected or
1865 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
1867 // remove old algorithm
1868 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
1869 myObjHyps[ dim ][ Algo ].clear();
1874 // Assign new algorithms and hypotheses
1875 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1877 if ( !isAccessibleDim( dim )) continue;
1879 // find or create algorithm
1880 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1882 // assign new algorithm
1883 if ( !anAlgoVar->_is_nil() && // some algo selected and
1884 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
1886 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
1887 CORBA::Object_var anObject = aSObject->GetObject();
1888 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
1889 bool isMesh = !aMeshVar->_is_nil();
1891 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1893 SMESH::SMESH_subMesh_var aVar =
1894 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1895 if ( !aVar->_is_nil() )
1896 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1898 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
1901 // assign hypotheses
1902 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1904 int aNewHypIndex = currentHyp( dim, hypType );
1905 int anOldHypIndex = -1;
1907 // remove old hypotheses
1908 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1910 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first ,
1911 myExistingHyps[ dim ][ hypType ] );
1912 if ( aNewHypIndex != anOldHypIndex || // different hyps
1913 anOldHypIndex == -1 ) // hyps of different algos
1915 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1916 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
1917 myObjHyps[ dim ][ hypType ].clear();
1921 // assign new hypotheses
1922 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1924 SMESH::SMESH_Mesh_var aMeshVar =
1925 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1926 bool isMesh = !aMeshVar->_is_nil();
1929 SMESH::AddHypothesisOnMesh
1930 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1934 SMESH::SMESH_subMesh_var aVar =
1935 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1936 if ( !aVar->_is_nil() )
1937 SMESH::AddHypothesisOnSubMesh
1938 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1941 // reread all hypotheses of mesh if necessary
1942 QStringList anExisting;
1943 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1950 //================================================================================
1952 * \brief Verifies whether given operator is valid for this one
1953 * \param theOtherOp - other operation
1954 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1956 * method redefined from base class verifies whether given operator is valid for
1957 * this one (i.e. can be started "above" this operator). In current implementation method
1958 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1961 //================================================================================
1962 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1964 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1967 //================================================================================
1969 * \brief SLOT. Is called when the user selects a way of geometry selection
1970 * \param theByMesh - true if the user wants to find geometry by mesh element
1972 //================================================================================
1974 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1977 if ( !myShapeByMeshOp ) {
1978 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1979 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1980 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1981 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1982 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1984 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1985 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1986 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1987 SMESH::SMESH_Mesh_var aMeshVar =
1988 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1989 if ( !aMeshVar->_is_nil() ) {
1990 myDlg->hide(); // stop processing selection
1991 myShapeByMeshOp->setModule( getSMESHGUI() );
1992 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1993 myShapeByMeshOp->SetMesh( aMeshVar );
1994 myShapeByMeshOp->start();
2000 //================================================================================
2002 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2004 //================================================================================
2006 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2008 if ( myShapeByMeshOp == op ) {
2009 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2011 // Select a found geometry object
2012 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2013 if ( !aGeomVar->_is_nil() )
2015 QString ID = aGeomVar->GetStudyEntry();
2016 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
2017 selectObject( aGeomSO );
2024 //================================================================================
2026 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2028 //================================================================================
2030 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2032 if ( myShapeByMeshOp == op && myDlg ) {
2037 //================================================================================
2039 * \brief Selects a SObject
2040 * \param theSObj - the SObject to select
2042 //================================================================================
2044 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2046 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2047 SALOME_ListIO anIOList;
2049 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2050 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2051 anIOList.Append( anIO );
2053 sm->setSelectedObjects( anIOList, false );