1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Copyright (C) 2005 CEA/DEN, EDF R&D
27 * File : SMESHGUI_MeshOp.h
28 * Author : Sergey LITONIN
32 #include "SMESHGUI_MeshOp.h"
33 #include "SMESHGUI_MeshDlg.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESH_TypeFilter.hxx"
38 #include "SMESHGUI_HypothesesUtils.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
41 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESHGUI_VTKUtils.h"
44 #include "SMESH_TypeFilter.hxx"
45 #include "SMESH_NumberFilter.hxx"
47 #include CORBA_CLIENT_HEADER(SMESH_Gen)
49 #include "GEOM_SelectionFilter.h"
51 #include "GeometryGUI.h"
53 #include "SalomeApp_Tools.h"
54 #include "SalomeApp_Application.h"
55 #include "SALOMEDSClient_Study.hxx"
56 #include "SALOMEDSClient_AttributeIOR.hxx"
57 #include "SALOMEDSClient_AttributeName.hxx"
58 #include "SALOMEDS_SComponent.hxx"
59 #include "SALOMEDS_SObject.hxx"
61 #include "LightApp_SelectionMgr.h"
62 #include "LightApp_UpdateFlags.h"
63 #include "SUIT_MessageBox.h"
64 #include "SUIT_Desktop.h"
65 #include "SUIT_OverrideCursor.h"
66 #include "SALOME_InteractiveObject.hxx"
67 #include "SALOME_ListIO.hxx"
69 #include "utilities.h"
71 #include <qstringlist.h>
72 #include <qlineedit.h>
74 #include <TopoDS_Shape.hxx>
75 #include <TopExp_Explorer.hxx>
77 //================================================================================
80 * \param theToCreate - if this parameter is true then operation is used for creation,
81 * for editing otherwise
83 * Initialize operation
85 //================================================================================
86 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
87 : SMESHGUI_SelectionOp(),
88 myToCreate( theToCreate ),
89 myIsMesh( theIsMesh ),
93 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
94 GeometryGUI::InitGeomGen();
95 myIsOnGeometry = true;
98 //================================================================================
102 //================================================================================
103 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
109 //================================================================================
111 * \brief Gets dialog of this operation
112 * \retval LightApp_Dialog* - pointer to dialog of this operation
114 //================================================================================
115 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
120 //================================================================================
122 * \brief Creates or edits mesh
123 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
125 * Virtual slot redefined from the base class called when "Apply" button is clicked
126 * creates or edits mesh
128 //================================================================================
129 bool SMESHGUI_MeshOp::onApply()
135 if ( !isValid( aMess ) )
139 SUIT_MessageBox::warn1( myDlg,
140 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
144 bool aResult = false;
148 if ( myToCreate && myIsMesh )
149 aResult = createMesh( aMess );
150 if ( myToCreate && !myIsMesh )
151 aResult = createSubMesh( aMess );
152 else if ( !myToCreate )
153 aResult = editMeshOrSubMesh( aMess );
155 update( UF_ObjBrowser | UF_Model );
157 catch ( const SALOME::SALOME_Exception& S_ex )
159 SalomeApp_Tools::QtCatchCorbaException( S_ex );
175 aMess = tr( "SMESH_OPERATION_FAILED" );
176 SUIT_MessageBox::warn1( myDlg,
177 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
183 //================================================================================
185 * \brief Creates dialog if necessary and shows it
187 * Virtual method redefined from base class called when operation is started creates
188 * dialog if necessary and shows it, activates selection
190 //================================================================================
191 void SMESHGUI_MeshOp::startOperation()
195 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
196 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
198 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
199 this, SLOT( onCreateHyp( const int, const int ) ) );
200 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
201 this, SLOT( onEditHyp( const int, const int ) ) );
202 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
203 this, SLOT( onAlgoSelected( const int ) ) );
205 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
206 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
209 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
210 else myHelpFileName = "constructing_submeshes_page.html";
211 else myHelpFileName = "editing_meshes_page.html";
213 SMESHGUI_SelectionOp::startOperation();
215 // iterate through dimensions and get available algoritms, set them to the dialog
216 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
217 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
219 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
221 // clear available hypotheses
222 aTab->setAvailableHyps( MainHyp, hypList );
223 aTab->setAvailableHyps( AddHyp, hypList );
224 aTab->setExistingHyps( MainHyp, hypList );
225 aTab->setExistingHyps( AddHyp, hypList );
226 myExistingHyps[ i ][ MainHyp ].clear();
227 myExistingHyps[ i ][ AddHyp ].clear();
229 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
230 aTab->setAvailableHyps( Algo, hypList );
235 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
238 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
240 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
242 myDlg->setCurrentTab( SMESH::DIM_3D );
247 myIgnoreAlgoSelection = false;
250 //================================================================================
252 * \brief Creates selection filter
253 * \param theId - identifier of current selection widget
254 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
256 * Creates selection filter in accordance with identifier of current selection widget
258 //================================================================================
259 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
261 if ( theId == SMESHGUI_MeshDlg::Geom )
263 // TColStd_MapOfInteger allTypesMap;
264 // for ( int i = 0; i < 10; i++ )
265 // allTypesMap.Add( i );
266 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
267 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
269 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
270 return new SMESH_TypeFilter( MESHorSUBMESH );
271 else if ( theId == SMESHGUI_MeshDlg::Mesh )
272 return new SMESH_TypeFilter( MESH );
277 //================================================================================
279 * \brief check if selected shape is a subshape of the shape to mesh
280 * \retval bool - check result
282 //================================================================================
284 bool SMESHGUI_MeshOp::isSubshapeOk() const
286 if ( !myToCreate || myIsMesh ) // not submesh creation
290 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
291 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
292 if (!pMesh) return false;
294 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
295 if (mesh->_is_nil()) return false;
297 // main shape of the mesh
298 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
299 if (mainGeom->_is_nil()) return false;
303 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
305 if (aGEOMs.count() > 0) {
306 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
307 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
308 if (geomGen->_is_nil() || !aStudy) return false;
310 GEOM::GEOM_IGroupOperations_var op =
311 geomGen->GetIGroupOperations(aStudy->StudyId());
312 if (op->_is_nil()) return false;
314 // check all selected shapes
315 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
316 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
317 QString aSubGeomEntry = (*aSubShapesIter);
318 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
319 if (!pSubGeom) return false;
321 GEOM::GEOM_Object_var aSubGeomVar =
322 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
323 if (aSubGeomVar->_is_nil()) return false;
325 // skl for NPAL14695 - implementation of searching of mainObj
326 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
327 //if (mainObj->_is_nil() ||
328 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
330 if (mainObj->_is_nil())
332 if (string(mainObj->GetEntry()) == string(mainGeom->GetEntry()))
334 mainObj = op->GetMainShape(mainObj);
343 //================================================================================
345 * \brief Return name of the algorithm that does not support submeshes and makes
346 * submesh creation useless
347 * \retval char* - string is to be deleted!!!
349 //================================================================================
351 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
353 if ( myToCreate && !myIsMesh ) {
355 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
356 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
357 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
360 QStringList algoNames;
362 existingHyps(3, Algo, pMesh, algoNames, algoList);
363 if (!algoList.empty()) {
364 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
366 algo->InputTypes.empty() && // builds all dimensions it-self
367 !algo->IsSupportSubmeshes )
368 return CORBA::string_dup( algoNames[0].latin1() );
371 // GEOM::GEOM_Object_var geom;
372 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ))
373 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
375 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
376 existingHyps(2, Algo, pMesh, algoNames, algoList);
377 if (!algoList.empty()) {
378 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
380 algo->InputTypes.empty() && // builds all dimensions it-self
381 !algo->IsSupportSubmeshes )
382 return CORBA::string_dup( algoNames[0].latin1() );
390 //================================================================================
392 * \brief find an existing submesh by the selected shape
393 * \retval _PTR(SObject) - the found submesh SObject
395 //================================================================================
397 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
399 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
400 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
401 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
402 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
403 if ( pMesh && pGeom ) {
404 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
405 if ( !geom->_is_nil() ) {
407 switch ( geom->GetShapeType() ) {
408 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex ; break;
409 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge ; break;
410 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire ; break;
411 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace ; break;
412 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell ; break;
413 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid ; break;
414 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
417 _PTR(GenericAttribute) anAttr;
418 _PTR(SObject) aSubmeshRoot;
419 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
420 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
422 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
423 for (; smIter->More(); smIter->Next() )
425 _PTR(SObject) aSmObj = smIter->Value();
426 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
428 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
429 for (; anIter1->More(); anIter1->Next()) {
430 _PTR(SObject) pGeom2 = anIter1->Value();
431 if ( pGeom2->ReferencedObject( pGeom2 ) &&
432 pGeom2->GetID() == pGeom->GetID() )
439 return _PTR(SObject)();
442 //================================================================================
444 * \brief Updates dialog's look and feel
446 * Virtual method redefined from the base class updates dialog's look and feel
448 //================================================================================
449 void SMESHGUI_MeshOp::selectionDone()
451 if (!dlg()->isShown() || !myDlg->isEnabled())
454 SMESHGUI_SelectionOp::selectionDone();
458 myIsOnGeometry = true;
460 //Check geometry for mesh
461 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
462 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.latin1());
465 SMESH::SMESH_Mesh_var aMeshVar =
466 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
467 if (!aMeshVar->_is_nil()) {
468 if (!myToCreate && !aMeshVar->HasShapeToMesh())
469 myIsOnGeometry = false;
475 // Enable tabs according to shape dimension
480 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
481 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
483 if (aGEOMs.count() > 0) {
484 // one or more GEOM shape selected
485 aSeq->length(aGEOMs.count());
486 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
488 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
489 QString aSubGeomEntry = (*aSubShapesIter);
490 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
491 GEOM::GEOM_Object_var aSubGeomVar =
492 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
493 aSeq[iSubSh] = aSubGeomVar;
496 // get geometry by selected sub-mesh
497 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
498 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
499 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
500 if (!aGeomVar->_is_nil()) {
506 if (aSeq->length() > 0) {
508 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
509 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
510 switch ( aGeomVar->GetShapeType() ) {
512 case GEOM::SHELL: shapeDim = 3; break;
513 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
515 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
516 case GEOM::VERTEX: break;
519 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
520 TopExp_Explorer exp( aShape, TopAbs_SHELL );
523 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
524 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
525 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
526 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
533 myDlg->setMaxHypoDim( shapeDim );
536 if (!myToCreate) // edition: read hypotheses
540 SMESH::SMESH_subMesh_var aVar =
541 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
542 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
543 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
544 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
545 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
546 myDlg->updateGeometry();
553 else if ( !myIsMesh ) // submesh creation
555 // if a submesh on the selected shape already exist, pass to submesh edition mode
556 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
557 SMESH::SMESH_subMesh_var sm =
558 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
559 bool editSubmesh = ( !sm->_is_nil() &&
560 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
561 tr( "EDIT_SUBMESH_QUESTION"),
562 tr( "SMESH_BUT_YES" ),
563 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
566 selectionMgr()->clearFilters();
567 selectObject( pSubmesh );
568 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
573 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
574 selectObject( _PTR(SObject)() );
579 // discard selected mesh if submesh creation not allowed because of
580 // a global algorithm that does not support submeshes
581 if ( char* algoName = isSubmeshIgnored() ) {
582 SUIT_MessageBox::warn1( myDlg, tr( "SMESH_ERROR" ),
583 tr("SUBMESH_NOT_ALLOWED").arg(algoName), tr( "SMESH_BUT_OK" ));
584 CORBA::string_free( algoName );
585 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
586 selectObject( _PTR(SObject)() );
591 // enable/disable popup for choice of geom selection way
593 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
594 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
595 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
596 if ( !mesh->_is_nil() )
597 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
599 myDlg->setGeomPopupEnabled( enable );
603 myDlg->enableTab( SMESH::DIM_3D );
605 availableHyps( SMESH::DIM_3D, Algo, hypList,
606 myAvailableHypData[SMESH::DIM_3D][Algo]);
608 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
609 aTab->setAvailableHyps( Algo, hypList );
610 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
611 myDlg->disableTab(i);
613 //Hide labels and fields (Mesh ang Geometry)
614 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
615 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
620 catch ( const SALOME::SALOME_Exception& S_ex )
622 SalomeApp_Tools::QtCatchCorbaException( S_ex );
629 //================================================================================
631 * \brief Verifies validity of input data
632 * \param theMess - Output parameter intended for returning error message
633 * \retval bool - TRUE if input data is valid, false otherwise
635 * Verifies validity of input data. This method is called when "Apply" or "OK" button
636 * is pressed before mesh creation or editing.
638 //================================================================================
639 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
641 // Selected object to be edited
642 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
644 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
649 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
650 aMeshName = aMeshName.stripWhiteSpace();
651 if ( aMeshName == "" )
653 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
657 /* // Imported mesh, if create sub-mesh or edit mesh
658 if ( !myToCreate || ( myToCreate && !myIsMesh ))
660 QString aMeshEntry = myDlg->selectedObject
661 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
662 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
663 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
664 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
665 theMess = tr( "IMPORTED_MESH" );
674 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
675 if ( aGeomEntry == "" )
677 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
680 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
681 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
683 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
688 if ( !myIsMesh ) // i.e sub-mesh creation,
690 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
691 if ( aMeshEntry == "" )
693 theMess = tr( "MESH_IS_NOT_DEFINED" );
696 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
697 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
699 theMess = tr( "MESH_IS_NULL" );
702 if ( !isSubshapeOk() )
704 theMess = tr( "INVALID_SUBSHAPE" );
713 //================================================================================
715 * \brief check compatibility of the algorithm and another algorithm or hypothesis
716 * \param theAlgoData - algorithm data
717 * \param theHypData - hypothesis data
718 * \param theHypType - hypothesis type
719 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
720 * \retval bool - check result
722 //================================================================================
724 static bool isCompatible(const HypothesisData* theAlgoData,
725 const HypothesisData* theHypData,
726 const int theHypType)
731 if ( theHypType == SMESHGUI_MeshOp::Algo )
732 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
735 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
738 //================================================================================
740 * \brief Gets available hypotheses or algorithms
741 * \param theDim - specifies dimension of returned hypotheses/algorifms
742 * \param theHypType - specifies whether algorims or hypotheses or additional ones
743 * are retrieved (possible values are in HypType enumeration)
744 * \param theHyps - Output list of hypotheses' names
745 * \param theAlgoData - to select hypos able to be used by this algo (optional)
747 * Gets available hypotheses or algorithm in accordance with input parameters
749 //================================================================================
750 void SMESHGUI_MeshOp::availableHyps( const int theDim,
751 const int theHypType,
752 QStringList& theHyps,
753 THypDataList& theDataList,
754 HypothesisData* theAlgoData ) const
758 bool isAlgo = ( theHypType == Algo );
759 bool isAux = ( theHypType == AddHyp );
760 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
762 QStringList::const_iterator anIter;
763 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
765 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
766 if ( isCompatible ( theAlgoData, aData, theHypType )) {
767 theDataList.append( aData );
768 theHyps.append( aData->Label );
773 //================================================================================
775 * \brief Gets existing hypotheses or algorithms
776 * \param theDim - specifies dimension of returned hypotheses/algorifms
777 * \param theHypType - specifies whether algorims or hypotheses or additional ones
778 * are retrieved (possible values are in HypType enumeration)
779 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
780 * \param theHyps - output list of names.
781 * \param theHypVars - output list of variables.
782 * \param theAlgoData - to select hypos able to be used by this algo (optional)
784 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
787 //================================================================================
788 void SMESHGUI_MeshOp::existingHyps( const int theDim,
789 const int theHypType,
790 _PTR(SObject) theFather,
791 QStringList& theHyps,
792 THypList& theHypList,
793 HypothesisData* theAlgoData)
795 // Clear hypoheses list
802 const bool isAux = ( theHypType == AddHyp );
804 _PTR(SObject) aHypRoot;
805 _PTR(GenericAttribute) anAttr;
806 _PTR(AttributeName) aName;
807 _PTR(AttributeIOR) anIOR;
809 bool isMesh = !_CAST( SComponent, theFather );
812 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
814 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
816 if ( theFather->FindSubObject( aPart, aHypRoot ) )
818 _PTR(ChildIterator) anIter =
819 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
820 for (; anIter->More(); anIter->Next() )
822 _PTR(SObject) anObj = anIter->Value();
823 if ( isMesh ) // i.e. mesh or submesh
825 _PTR(SObject) aRefObj;
826 if ( anObj->ReferencedObject( aRefObj ) )
831 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
834 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
835 if ( !CORBA::is_nil( aVar ) )
837 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
838 if ( !aHypVar->_is_nil() )
840 CORBA::String_var aHypType( aHypVar->GetName() );
841 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
842 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
843 ( isCompatible ( theAlgoData, aData, theHypType )) &&
844 ( isAux == aData->IsAux ))
846 std::string aHypName = aName->Value();
847 theHyps.append( aHypName.c_str() );
848 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
857 //================================================================================
859 * \brief If create or edit a submesh, return a hypothesis holding parameters used
861 * \param aHypType - The hypothesis type name
862 * \param aServerLib - Server library name
863 * \param hypData - The structure holding the hypothesis type etc.
864 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
866 //================================================================================
868 SMESH::SMESH_Hypothesis_var
869 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
870 const QString& aServerLib ) const
872 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
873 return SMESH::SMESH_Hypothesis::_nil();
875 const int nbColonsInMeshEntry = 3;
876 bool isSubMesh = myToCreate ?
878 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
882 // get mesh and geom object
883 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
884 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
886 QString anEntry = myDlg->selectedObject
887 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
888 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
890 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
891 if ( myToCreate ) // mesh and geom may be selected
893 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
894 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
895 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
896 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
898 else // edition: sub-mesh may be selected
900 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
901 if ( !sm->_is_nil() ) {
902 aMeshVar = sm->GetFather();
903 aGeomVar = sm->GetSubShape();
908 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
909 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
914 return SMESH::SMESH_Hypothesis::_nil();
917 //================================================================================
919 * \Brief Returns tab dimention
920 * \param tab - the tab in the dlg
921 * \param dlg - my dialogue
922 * \retval int - dimention
924 //================================================================================
926 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
929 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
930 if (tab == dlg->tab(i))
935 //================================================================================
937 * \brief Create hypothesis
938 * \param theHypType - hypothesis category (main or additional)
939 * \param theIndex - index of type of hypothesis to be cerated
941 * Specifies dimension of hypothesis to be created (using sender() method),
942 * specifies its type and calls method for hypothesis creation
944 //================================================================================
945 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
947 // Specifies dimension of hypothesis to be created
948 int aDim = getTabDim( sender(), myDlg );
952 // Specifies type of hypothesis to be created
953 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
954 if (theIndex < 0 || theIndex >= dataList.count())
956 QString aHypTypeName = dataList[ theIndex ]->TypeName;
959 createHypothesis(aDim, theHypType, aHypTypeName);
962 //================================================================================
964 * Create hypothesis and update dialog.
965 * \param theDim - dimension of hypothesis to be created
966 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
967 * \param theTypeName - specifies hypothesis to be created
969 //================================================================================
972 QString GetUniqueName (const QStringList& theHypNames,
973 const QString& theName,
974 size_t theIteration = 1)
976 QString aName = theName + "_" + QString::number( theIteration );
977 if ( theHypNames.contains( aName ) )
978 return GetUniqueName( theHypNames, theName, ++theIteration );
983 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
985 const QString& theTypeName)
987 // During a hypothesis creation we might need to select some objects.
988 // Main dialog must not update it's own selected objects in this case.
989 dlg()->deactivateAll();
991 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
995 QStringList aHypNames;
996 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
997 for (; aDimIter != myExistingHyps.end(); aDimIter++) {
998 const TType2HypList& aType2HypList = aDimIter.data();
999 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1000 for (; aTypeIter != aType2HypList.end(); aTypeIter++) {
1001 const THypList& aHypList = aTypeIter.data();
1002 THypList::const_iterator anIter = aHypList.begin();
1003 for (; anIter != aHypList.end(); anIter++) {
1004 const THypItem& aHypItem = *anIter;
1005 const QString& aHypName = aHypItem.second;
1006 aHypNames.append(aHypName);
1010 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1013 int nbHyp = myExistingHyps[theDim][theType].count();
1015 QString aClientLibName = aData->ClientLibName;
1016 if (aClientLibName == "") {
1017 // Call hypothesis creation server method (without GUI)
1018 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1020 // Get hypotheses creator client (GUI)
1021 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1023 // Create hypothesis
1025 // When create or edit a submesh, try to initialize a new hypothesis
1026 // with values used to mesh a subshape
1027 SMESH::SMESH_Hypothesis_var initParamHyp =
1028 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1029 myDlg->setEnabled( false );
1030 aCreator->create(initParamHyp, aHypName, myDlg);
1031 myDlg->setEnabled( true );
1033 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1037 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1039 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
1040 QStringList aNewHyps;
1041 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
1042 if (aNewHyps.count() > nbHyp) {
1043 for (int i = nbHyp; i < aNewHyps.count(); i++)
1044 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
1048 //================================================================================
1050 * \brief Calls plugin methods for hypothesis editing
1051 * \param theHypType - specifies whether main hypothesis or additional one
1053 * \param theIndex - index of existing hypothesis
1055 * Calls plugin methods for hypothesis editing
1057 //================================================================================
1058 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1060 // Speicfies dimension of hypothesis to be created
1061 int aDim = getTabDim( sender(), myDlg );
1065 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1066 if ( theIndex < 0 || theIndex >= aList.count() )
1068 const THypItem& aHypItem = aList[ theIndex ];
1069 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1070 if ( aHyp->_is_nil() )
1073 CORBA::String_var aTypeName = aHyp->GetName();
1074 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
1076 myDlg->setEnabled( false );
1077 aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
1078 myDlg->setEnabled( true );
1082 //================================================================================
1084 * \brief access to hypothesis data
1085 * \param theDim - hyp dimension
1086 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1087 * \param theIndex - index in the list
1088 * \retval HypothesisData* - result data, may be 0
1090 //================================================================================
1092 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1093 const int theHypType,
1096 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1097 theHypType > -1 && theHypType < NbHypTypes &&
1098 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1099 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1103 //================================================================================
1105 * \brief Set available algos and hypos according to the selected algorithm
1106 * \param theIndex - algorithm index
1108 //================================================================================
1110 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1113 if ( myIgnoreAlgoSelection )
1116 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1120 // find highest available dimension, all algos of this dimension are available for choice
1122 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1123 if (isAccessibleDim( i ))
1128 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1130 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1131 HypothesisData* algoByDim[4];
1132 algoByDim[ aDim ] = algoData;
1134 QStringList anAvailable;
1135 if ( !algoData ) { // all algos becomes available
1136 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1137 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1140 // check that algorithms of other dimentions are compatible with
1143 // 2 loops: backward and forward from algo dimension
1144 for ( int forward = false; forward <= true; ++forward )
1146 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1148 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1150 HypothesisData* prevAlgo = algoData;
1151 bool noCompatible = false;
1152 for (; dim * dir <= lastDim * dir; dim += dir)
1154 if ( !isAccessibleDim( dim ))
1156 if ( noCompatible ) { // the selected algo has no compatible ones
1157 anAvailable.clear();
1158 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1159 myAvailableHypData[dim][Algo].clear();
1160 algoByDim[ dim ] = 0;
1163 // get currently selected algo
1164 int algoIndex = currentHyp( dim, Algo );
1165 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1166 if ( curAlgo ) { // some algo selected
1167 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1170 // set new available algoritms
1171 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1172 HypothesisData* soleCompatible = 0;
1173 if ( anAvailable.count() == 1 )
1174 soleCompatible = myAvailableHypData[dim][Algo][0];
1175 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1176 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1177 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1178 noCompatible = anAvailable.isEmpty();
1180 // restore previously selected algo
1181 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1182 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1183 // select the sole compatible algo
1184 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1185 setCurrentHyp( dim, Algo, algoIndex );
1187 // remember current algo
1188 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1192 // set hypotheses corresponding to the found algoritms
1194 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1196 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1198 if ( !isAccessibleDim( dim ))
1200 for ( int type = MainHyp; type < NbHypTypes; type++ )
1202 myAvailableHypData[ dim ][ type ].clear();
1203 QStringList anAvailable, anExisting;
1205 HypothesisData* curAlgo = algoByDim[ dim ];
1206 int hypIndex = currentHyp( dim, type );
1208 SMESH::SMESH_Hypothesis_var curHyp;
1209 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1210 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1212 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1213 // try to find algo by selected hypothesis in order to keep it selected
1214 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1215 CORBA::String_var curHypType = curHyp->GetName();
1216 if ( !algoDeselectedByUser &&
1217 myObjHyps[ dim ][ type ].count() > 0 &&
1218 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1220 CORBA::String_var aName = curHyp->GetName();
1221 HypothesisData* hypData = SMESH::GetHypothesisData( aName );
1222 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1223 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1224 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1231 // get hyps compatible with curAlgo
1234 // check if a selected hyp is compatible with the curAlgo
1235 if ( !curHyp->_is_nil() ) {
1236 CORBA::String_var aName = curHyp->GetName();
1237 HypothesisData* hypData = SMESH::GetHypothesisData( aName );
1238 if ( !isCompatible( curAlgo, hypData, type ))
1239 curHyp = SMESH::SMESH_Hypothesis::_nil();
1241 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1242 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1244 // set list of hypotheses
1245 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1246 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1248 // set current existing hypothesis
1249 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1250 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1253 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1254 // none is yet selected => select the sole existing if it is not optional
1255 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1256 bool isOptional = true;
1257 if ( algoByDim[ dim ] &&
1258 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1262 setCurrentHyp( dim, type, hypIndex );
1267 //================================================================================
1269 * \brief Creates and selects hypothesis of hypotheses set
1270 * \param theSetName - The name of hypotheses set
1272 //================================================================================
1273 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1275 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1276 if (!aHypoSet) return;
1279 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1280 setCurrentHyp(dim, Algo, -1);
1281 setCurrentHyp(dim, AddHyp, -1);
1282 setCurrentHyp(dim, MainHyp, -1);
1285 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1286 bool isAlgo = (aHypType == Algo);
1288 // set hyps from the set
1289 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1290 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1291 const QString& aHypoTypeName = (*aHypoList)[ i ];
1292 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1296 int aDim = aHypData->Dim[0];
1297 // create or/and set
1299 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1301 QStringList anAvailable;
1302 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1303 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1304 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1306 setCurrentHyp( aDim, Algo, index );
1307 onAlgoSelected( index, aDim );
1310 bool mainHyp = true;
1311 QStringList anAvailable;
1312 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1313 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1314 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1317 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1320 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1322 } // loop on hypos in the set
1323 } // loop on algo/hypo
1326 //================================================================================
1328 * \brief Creates mesh
1329 * \param theMess - Output parameter intended for returning error message
1330 * \retval bool - TRUE if mesh is created, FALSE otherwise
1334 //================================================================================
1335 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1339 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1340 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1343 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1344 QStringList::Iterator it = aList.begin();
1345 for (; it!=aList.end(); it++)
1347 QString aGeomEntry = *it;
1348 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1349 GEOM::GEOM_Object_var aGeomVar =
1350 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1352 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1353 if ( aSMESHGen->_is_nil() )
1356 SUIT_OverrideCursor aWaitCursor;
1359 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1360 if ( aMeshVar->_is_nil() )
1362 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1364 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1366 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1367 if ( !isAccessibleDim( aDim )) continue;
1369 // assign hypotheses
1370 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1371 int aHypIndex = currentHyp( aDim, aHypType );
1372 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1373 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1374 if ( !aHypVar->_is_nil() )
1375 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1378 // find or create algorithm
1379 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1380 if ( !anAlgoVar->_is_nil() )
1381 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1388 //================================================================================
1390 * \brief Creates sub-mesh
1391 * \param theMess - Output parameter intended for returning error message
1392 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1396 //================================================================================
1397 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1401 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1402 if ( aSMESHGen->_is_nil() )
1406 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1407 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1408 SMESH::SMESH_Mesh_var aMeshVar =
1409 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1410 if (aMeshVar->_is_nil())
1413 // GEOM shape of the main mesh
1414 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1416 // Name for the new sub-mesh
1417 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1420 GEOM::GEOM_Object_var aGeomVar;
1422 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1423 if (aGEOMs.count() == 1)
1425 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1426 QString aGeomEntry = aGEOMs.first();
1427 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1428 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1430 else if (aGEOMs.count() > 1)
1432 // create a GEOM group
1433 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1434 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1435 if (!geomGen->_is_nil() && aStudy) {
1436 GEOM::GEOM_IGroupOperations_var op =
1437 geomGen->GetIGroupOperations(aStudy->StudyId());
1438 if (!op->_is_nil()) {
1439 // check and add all selected GEOM objects: they must be
1440 // a sub-shapes of the main GEOM and must be of one type
1442 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1443 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1444 aSeq->length(aGEOMs.count());
1445 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1446 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1447 QString aSubGeomEntry = (*aSubShapesIter);
1448 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
1449 GEOM::GEOM_Object_var aSubGeomVar =
1450 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1451 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1453 aGroupType = aSubShapeType;
1455 if (aSubShapeType != aGroupType)
1456 aGroupType = TopAbs_SHAPE;
1458 aSeq[iSubSh] = aSubGeomVar;
1461 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1462 op->UnionList(aGroupVar, aSeq);
1465 aGeomVar = aGroupVar;
1467 // publish the GEOM group in study
1468 QString aNewGeomGroupName ("Auto_group_for_");
1469 aNewGeomGroupName += aName;
1470 SALOMEDS::SObject_var aNewGroupSO =
1471 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
1478 if (aGeomVar->_is_nil())
1481 SUIT_OverrideCursor aWaitCursor;
1484 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1486 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1488 if ( !isAccessibleDim( aDim )) continue;
1490 // find or create algorithm
1491 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1492 if ( !anAlgoVar->_is_nil() )
1493 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1494 // assign hypotheses
1495 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1497 int aHypIndex = currentHyp( aDim, aHypType );
1498 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1500 SMESH::SMESH_Hypothesis_var aHypVar =
1501 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1502 if ( !aHypVar->_is_nil() )
1503 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1508 // deselect geometry: next submesh should be created on other subshape
1509 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1510 selectObject( _PTR(SObject)() );
1516 //================================================================================
1518 * \brief Gets current hypothesis or algorithms
1519 * \param theDim - dimension of hypothesis or algorithm
1520 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1521 * \retval int - current hypothesis or algorithms
1523 * Gets current hypothesis or algorithms
1525 //================================================================================
1526 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1528 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1531 //================================================================================
1533 * \brief Returns true if hypotheses of given dim can be assigned
1534 * \param theDim - hypotheses dimension
1535 * \retval bool - result
1537 //================================================================================
1538 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1540 return myDlg->tab( theDim )->isEnabled();
1543 //================================================================================
1545 * \brief Sets current hypothesis or algorithms
1546 * \param theDim - dimension of hypothesis or algorithm
1547 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1548 * \param theIndex - Index of hypothesis
1550 * Gets current hypothesis or algorithms
1552 //================================================================================
1553 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1554 const int theHypType,
1555 const int theIndex )
1557 myIgnoreAlgoSelection = true;
1558 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1559 myIgnoreAlgoSelection = false;
1562 //================================================================================
1564 * \brief Generates default and sets mesh/submesh name
1566 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1568 //================================================================================
1569 void SMESHGUI_MeshOp::setDefaultName() const
1573 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1575 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1576 _PTR(SObject) anObj;
1579 aResName = aPrefix + QString::number( i++ );
1580 anObj = aStudy->FindObject( aResName.latin1() );
1584 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1585 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1586 aControl->setText( aResName );
1589 //================================================================================
1591 * \brief Gets algorithm or creates it if necessary
1592 * \param theDim - specifies dimension of returned hypotheses/algorifms
1593 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1595 * Gets algorithm or creates it if necessary
1597 //================================================================================
1598 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1600 SMESH::SMESH_Hypothesis_var anAlgoVar;
1602 // get type of the selected algo
1603 int aHypIndex = currentHyp( theDim, Algo );
1604 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1605 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1607 QString aHypName = dataList[ aHypIndex ]->TypeName;
1609 // get existing algoritms
1610 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1612 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1614 // look for anexisting algo of such a type
1615 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1616 THypList::iterator anIter = aHypVarList.begin();
1617 for (; anIter != aHypVarList.end(); anIter++)
1619 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1620 CORBA::String_var aName = aHypVar->GetName();
1621 if ( !aHypVar->_is_nil() && aHypName == aName )
1623 anAlgoVar = aHypVar;
1628 if (anAlgoVar->_is_nil()) {
1629 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1631 QString aClientLibName = aHypData->ClientLibName;
1632 if (aClientLibName == "") {
1633 // Call hypothesis creation server method (without GUI)
1634 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1636 // Get hypotheses creator client (GUI)
1637 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1641 aCreator->create(true, aHypName, myDlg);
1643 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1645 QStringList tmpList;
1646 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1647 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1650 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1651 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1653 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1654 CORBA::String_var aName = aHypVar->GetName();
1655 if ( !aHypVar->_is_nil() && aHypName == aName )
1657 anAlgoVar = aHypVar;
1663 return anAlgoVar._retn();
1666 //================================================================================
1668 * \brief Reads parameters of edited mesh and assigns them to the dialog
1670 * Reads parameters of edited mesh and assigns them to the dialog (called when
1671 * mesh is edited only)
1673 //================================================================================
1674 void SMESHGUI_MeshOp::readMesh()
1676 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1677 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1681 if (myIsOnGeometry) {
1682 // Get name of mesh if current object is sub-mesh
1683 SMESH::SMESH_subMesh_var aSubMeshVar =
1684 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1685 if ( !aSubMeshVar->_is_nil() )
1687 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1688 if ( !aMeshVar->_is_nil() )
1690 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1691 QString aMeshName = name( aMeshSO );
1692 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1696 // Get name of geometry object
1697 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1698 if ( !aGeomVar->_is_nil() )
1700 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1701 QString aShapeName = name( aGeomSO );
1702 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1706 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1707 QStringList anExisting;
1708 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1709 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1712 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1713 // find algo index among available ones
1715 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1717 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1718 CORBA::String_var aHypTypeName = aVar->GetName();
1719 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1720 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1721 // if ( aHypIndex < 0 && algoData ) {
1722 // // assigned algo is incompatible with other algorithms
1723 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1724 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1727 setCurrentHyp( dim, Algo, aHypIndex );
1728 // set existing and available hypothesis according to the selected algo
1729 onAlgoSelected( aHypIndex, dim );
1733 bool hypWithoutAlgo = false;
1734 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1736 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1739 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1740 // find index of requered hypothesis among existing ones for this dimension and type
1742 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1743 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1744 myExistingHyps[ dim ][ hypType ] );
1745 if ( aHypIndex < 0 ) {
1746 // assigned hypothesis is incompatible with the algorithm
1747 if ( currentHyp( dim, Algo ) < 0 )
1748 { // none algo selected; it is edition for sure, of submesh maybe
1749 hypWithoutAlgo = true;
1750 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1751 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1752 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1756 setCurrentHyp( dim, hypType, aHypIndex );
1759 // make available other hyps of same type as one without algo
1760 if ( hypWithoutAlgo )
1761 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1764 //================================================================================
1766 * \brief Gets name of object
1767 * \param theSO - SObject
1768 * \retval QString - name of object
1770 * Gets name of object
1772 //================================================================================
1773 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1778 _PTR(GenericAttribute) anAttr;
1779 _PTR(AttributeName) aNameAttr;
1780 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1783 aResName = aNameAttr->Value().c_str();
1789 //================================================================================
1791 * \brief Finds hypothesis in input list
1792 * \param theHyp - hypothesis to be found
1793 * \param theHypList - input list of hypotheses
1794 * \retval int - index of hypothesis or -1 if it is not found
1796 * Finds position of hypothesis in input list
1798 //================================================================================
1799 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1800 const THypList& theHypList ) const
1803 if ( !theHyp->_is_nil() )
1806 THypList::const_iterator anIter = theHypList.begin();
1807 for (; anIter != theHypList.end(); ++ anIter)
1809 if ( theHyp->_is_equivalent( (*anIter).first ) )
1820 //================================================================================
1822 * \brief Edits mesh or sub-mesh
1823 * \param theMess - Output parameter intended for returning error message
1824 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1826 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1828 //================================================================================
1829 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1833 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1834 if ( aSMESHGen->_is_nil() )
1837 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1838 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1842 SUIT_OverrideCursor aWaitCursor;
1845 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1846 SMESH::SetName( pObj, aName.latin1() );
1847 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1849 // First, remove old algos in order to avoid messages on algorithm hiding
1850 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1852 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
1854 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
1855 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1856 if ( anAlgoVar->_is_nil() || // no new algo selected or
1857 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
1859 // remove old algorithm
1860 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
1861 myObjHyps[ dim ][ Algo ].clear();
1866 // Assign new algorithms and hypotheses
1867 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1869 if ( !isAccessibleDim( dim )) continue;
1871 // find or create algorithm
1872 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1874 // assign new algorithm
1875 if ( !anAlgoVar->_is_nil() && // some algo selected and
1876 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
1878 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
1879 CORBA::Object_var anObject = aSObject->GetObject();
1880 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
1881 bool isMesh = !aMeshVar->_is_nil();
1883 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1885 SMESH::SMESH_subMesh_var aVar =
1886 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1887 if ( !aVar->_is_nil() )
1888 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1890 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
1893 // assign hypotheses
1894 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1896 int aNewHypIndex = currentHyp( dim, hypType );
1897 int anOldHypIndex = -1;
1899 // remove old hypotheses
1900 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1902 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first ,
1903 myExistingHyps[ dim ][ hypType ] );
1904 if ( aNewHypIndex != anOldHypIndex || // different hyps
1905 anOldHypIndex == -1 ) // hyps of different algos
1907 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1908 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
1909 myObjHyps[ dim ][ hypType ].clear();
1913 // assign new hypotheses
1914 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1916 SMESH::SMESH_Mesh_var aMeshVar =
1917 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1918 bool isMesh = !aMeshVar->_is_nil();
1921 SMESH::AddHypothesisOnMesh
1922 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1926 SMESH::SMESH_subMesh_var aVar =
1927 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1928 if ( !aVar->_is_nil() )
1929 SMESH::AddHypothesisOnSubMesh
1930 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1933 // reread all hypotheses of mesh if necessary
1934 QStringList anExisting;
1935 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1942 //================================================================================
1944 * \brief Verifies whether given operator is valid for this one
1945 * \param theOtherOp - other operation
1946 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1948 * method redefined from base class verifies whether given operator is valid for
1949 * this one (i.e. can be started "above" this operator). In current implementation method
1950 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1953 //================================================================================
1954 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1956 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1959 //================================================================================
1961 * \brief SLOT. Is called when the user selects a way of geometry selection
1962 * \param theByMesh - true if the user wants to find geometry by mesh element
1964 //================================================================================
1966 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1969 if ( !myShapeByMeshOp ) {
1970 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1971 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1972 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1973 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1974 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1976 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1977 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1978 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1979 SMESH::SMESH_Mesh_var aMeshVar =
1980 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1981 if ( !aMeshVar->_is_nil() ) {
1982 myDlg->hide(); // stop processing selection
1983 myShapeByMeshOp->setModule( getSMESHGUI() );
1984 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1985 myShapeByMeshOp->SetMesh( aMeshVar );
1986 myShapeByMeshOp->start();
1992 //================================================================================
1994 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1996 //================================================================================
1998 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2000 if ( myShapeByMeshOp == op ) {
2001 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2003 // Select a found geometry object
2004 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2005 if ( !aGeomVar->_is_nil() )
2007 QString ID = aGeomVar->GetStudyEntry();
2008 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
2009 selectObject( aGeomSO );
2016 //================================================================================
2018 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2020 //================================================================================
2022 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2024 if ( myShapeByMeshOp == op && myDlg ) {
2029 //================================================================================
2031 * \brief Selects a SObject
2032 * \param theSObj - the SObject to select
2034 //================================================================================
2036 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2038 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2039 SALOME_ListIO anIOList;
2041 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2042 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2043 anIOList.Append( anIO );
2045 sm->setSelectedObjects( anIOList, false );