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>
79 //================================================================================
82 * \param theToCreate - if this parameter is true then operation is used for creation,
83 * for editing otherwise
85 * Initialize operation
87 //================================================================================
88 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
89 : SMESHGUI_SelectionOp(),
90 myToCreate( theToCreate ),
91 myIsMesh( theIsMesh ),
95 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
96 GeometryGUI::InitGeomGen();
97 myIsOnGeometry = true;
100 //================================================================================
104 //================================================================================
105 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
111 //================================================================================
113 * \brief Gets dialog of this operation
114 * \retval LightApp_Dialog* - pointer to dialog of this operation
116 //================================================================================
117 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
122 //================================================================================
124 * \brief Creates or edits mesh
125 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
127 * Virtual slot redefined from the base class called when "Apply" button is clicked
128 * creates or edits mesh
130 //================================================================================
131 bool SMESHGUI_MeshOp::onApply()
137 if ( !isValid( aMess ) )
141 SUIT_MessageBox::warn1( myDlg,
142 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
146 bool aResult = false;
150 if ( myToCreate && myIsMesh )
151 aResult = createMesh( aMess );
152 if ( myToCreate && !myIsMesh )
153 aResult = createSubMesh( aMess );
154 else if ( !myToCreate )
155 aResult = editMeshOrSubMesh( aMess );
157 update( UF_ObjBrowser | UF_Model );
159 catch ( const SALOME::SALOME_Exception& S_ex )
161 SalomeApp_Tools::QtCatchCorbaException( S_ex );
177 aMess = tr( "SMESH_OPERATION_FAILED" );
178 SUIT_MessageBox::warn1( myDlg,
179 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
185 //================================================================================
187 * \brief Creates dialog if necessary and shows it
189 * Virtual method redefined from base class called when operation is started creates
190 * dialog if necessary and shows it, activates selection
192 //================================================================================
193 void SMESHGUI_MeshOp::startOperation()
197 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
198 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
200 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
201 this, SLOT( onCreateHyp( const int, const int ) ) );
202 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
203 this, SLOT( onEditHyp( const int, const int ) ) );
204 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
205 this, SLOT( onAlgoSelected( const int ) ) );
207 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
208 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
211 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
212 else myHelpFileName = "constructing_submeshes_page.html";
213 else myHelpFileName = "editing_meshes_page.html";
215 SMESHGUI_SelectionOp::startOperation();
217 // iterate through dimensions and get available algoritms, set them to the dialog
218 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
219 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
221 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
223 // clear available hypotheses
224 aTab->setAvailableHyps( MainHyp, hypList );
225 aTab->setAvailableHyps( AddHyp, hypList );
226 aTab->setExistingHyps( MainHyp, hypList );
227 aTab->setExistingHyps( AddHyp, hypList );
228 myExistingHyps[ i ][ MainHyp ].clear();
229 myExistingHyps[ i ][ AddHyp ].clear();
231 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
232 aTab->setAvailableHyps( Algo, hypList );
237 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
240 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
242 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
244 myDlg->setCurrentTab( SMESH::DIM_3D );
249 myIgnoreAlgoSelection = false;
252 //================================================================================
254 * \brief Creates selection filter
255 * \param theId - identifier of current selection widget
256 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
258 * Creates selection filter in accordance with identifier of current selection widget
260 //================================================================================
261 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
263 if ( theId == SMESHGUI_MeshDlg::Geom )
265 // TColStd_MapOfInteger allTypesMap;
266 // for ( int i = 0; i < 10; i++ )
267 // allTypesMap.Add( i );
268 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
269 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
271 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
272 return new SMESH_TypeFilter( MESHorSUBMESH );
273 else if ( theId == SMESHGUI_MeshDlg::Mesh )
274 return new SMESH_TypeFilter( MESH );
279 //================================================================================
281 * \brief check if selected shape is a subshape of the shape to mesh
282 * \retval bool - check result
284 //================================================================================
286 bool SMESHGUI_MeshOp::isSubshapeOk() const
288 if ( !myToCreate || myIsMesh ) // not submesh creation
292 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
293 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
294 if (!pMesh) return false;
296 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
297 if (mesh->_is_nil()) return false;
299 // main shape of the mesh
300 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
301 if (mainGeom->_is_nil()) return false;
305 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
307 if (aGEOMs.count() > 0) {
308 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
309 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
310 if (geomGen->_is_nil() || !aStudy) return false;
312 GEOM::GEOM_IGroupOperations_var op =
313 geomGen->GetIGroupOperations(aStudy->StudyId());
314 if (op->_is_nil()) return false;
316 // check all selected shapes
317 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
318 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
319 QString aSubGeomEntry = (*aSubShapesIter);
320 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
321 if (!pSubGeom) return false;
323 GEOM::GEOM_Object_var aSubGeomVar =
324 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
325 if (aSubGeomVar->_is_nil()) return false;
327 // skl for NPAL14695 - implementation of searching of mainObj
328 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
329 //if (mainObj->_is_nil() ||
330 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
332 if (mainObj->_is_nil())
334 if (string(mainObj->GetEntry()) == string(mainGeom->GetEntry()))
336 mainObj = op->GetMainShape(mainObj);
345 //================================================================================
347 * \brief Return name of the algorithm that does not support submeshes and makes
348 * submesh creation useless
349 * \retval char* - string is to be deleted!!!
351 //================================================================================
353 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
355 if ( myToCreate && !myIsMesh ) {
357 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
358 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
359 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
362 QStringList algoNames;
364 existingHyps(3, Algo, pMesh, algoNames, algoList);
365 if (!algoList.empty()) {
366 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
368 algo->InputTypes.empty() && // builds all dimensions it-self
369 !algo->IsSupportSubmeshes )
370 return CORBA::string_dup( algoNames[0].latin1() );
373 // GEOM::GEOM_Object_var geom;
374 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ))
375 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
377 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
378 existingHyps(2, Algo, pMesh, algoNames, algoList);
379 if (!algoList.empty()) {
380 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
382 algo->InputTypes.empty() && // builds all dimensions it-self
383 !algo->IsSupportSubmeshes )
384 return CORBA::string_dup( algoNames[0].latin1() );
392 //================================================================================
394 * \brief find an existing submesh by the selected shape
395 * \retval _PTR(SObject) - the found submesh SObject
397 //================================================================================
399 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
401 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
402 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
403 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
404 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
405 if ( pMesh && pGeom ) {
406 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
407 if ( !geom->_is_nil() ) {
409 switch ( geom->GetShapeType() ) {
410 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex ; break;
411 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge ; break;
412 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire ; break;
413 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace ; break;
414 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell ; break;
415 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid ; break;
416 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
419 _PTR(GenericAttribute) anAttr;
420 _PTR(SObject) aSubmeshRoot;
421 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
422 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
424 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
425 for (; smIter->More(); smIter->Next() )
427 _PTR(SObject) aSmObj = smIter->Value();
428 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
430 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
431 for (; anIter1->More(); anIter1->Next()) {
432 _PTR(SObject) pGeom2 = anIter1->Value();
433 if ( pGeom2->ReferencedObject( pGeom2 ) &&
434 pGeom2->GetID() == pGeom->GetID() )
441 return _PTR(SObject)();
444 //================================================================================
446 * \brief Updates dialog's look and feel
448 * Virtual method redefined from the base class updates dialog's look and feel
450 //================================================================================
451 void SMESHGUI_MeshOp::selectionDone()
453 if (!dlg()->isShown() || !myDlg->isEnabled())
456 SMESHGUI_SelectionOp::selectionDone();
460 myIsOnGeometry = true;
462 //Check geometry for mesh
463 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
464 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.latin1());
467 SMESH::SMESH_Mesh_var aMeshVar =
468 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
469 if (!aMeshVar->_is_nil()) {
470 if (!myToCreate && !aMeshVar->HasShapeToMesh())
471 myIsOnGeometry = false;
477 // Enable tabs according to shape dimension
482 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
483 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
485 if (aGEOMs.count() > 0) {
486 // one or more GEOM shape selected
487 aSeq->length(aGEOMs.count());
488 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
490 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
491 QString aSubGeomEntry = (*aSubShapesIter);
492 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
493 GEOM::GEOM_Object_var aSubGeomVar =
494 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
495 aSeq[iSubSh] = aSubGeomVar;
498 // get geometry by selected sub-mesh
499 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
500 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
501 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
502 if (!aGeomVar->_is_nil()) {
508 if (aSeq->length() > 0) {
510 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
511 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
512 switch ( aGeomVar->GetShapeType() ) {
514 case GEOM::SHELL: shapeDim = 3; break;
515 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
517 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
518 case GEOM::VERTEX: break;
521 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
522 TopExp_Explorer exp( aShape, TopAbs_SHELL );
525 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
526 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
527 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
528 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
535 myDlg->setMaxHypoDim( shapeDim );
538 if (!myToCreate) // edition: read hypotheses
542 SMESH::SMESH_subMesh_var aVar =
543 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
544 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
545 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
546 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
547 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
548 myDlg->updateGeometry();
555 else if ( !myIsMesh ) // submesh creation
557 // if a submesh on the selected shape already exist, pass to submesh edition mode
558 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
559 SMESH::SMESH_subMesh_var sm =
560 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
561 bool editSubmesh = ( !sm->_is_nil() &&
562 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
563 tr( "EDIT_SUBMESH_QUESTION"),
564 tr( "SMESH_BUT_YES" ),
565 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
568 selectionMgr()->clearFilters();
569 selectObject( pSubmesh );
570 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
575 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
576 selectObject( _PTR(SObject)() );
581 // discard selected mesh if submesh creation not allowed because of
582 // a global algorithm that does not support submeshes
583 if ( char* algoName = isSubmeshIgnored() ) {
584 SUIT_MessageBox::warn1( myDlg, tr( "SMESH_ERROR" ),
585 tr("SUBMESH_NOT_ALLOWED").arg(algoName), tr( "SMESH_BUT_OK" ));
586 CORBA::string_free( algoName );
587 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
588 selectObject( _PTR(SObject)() );
593 // enable/disable popup for choice of geom selection way
595 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
596 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
597 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
598 if ( !mesh->_is_nil() )
599 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
601 myDlg->setGeomPopupEnabled( enable );
605 myDlg->enableTab( SMESH::DIM_3D );
607 availableHyps( SMESH::DIM_3D, Algo, hypList,
608 myAvailableHypData[SMESH::DIM_3D][Algo]);
610 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
611 aTab->setAvailableHyps( Algo, hypList );
612 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
613 myDlg->disableTab(i);
615 //Hide labels and fields (Mesh ang Geometry)
616 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
617 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
622 catch ( const SALOME::SALOME_Exception& S_ex )
624 SalomeApp_Tools::QtCatchCorbaException( S_ex );
631 //================================================================================
633 * \brief Verifies validity of input data
634 * \param theMess - Output parameter intended for returning error message
635 * \retval bool - TRUE if input data is valid, false otherwise
637 * Verifies validity of input data. This method is called when "Apply" or "OK" button
638 * is pressed before mesh creation or editing.
640 //================================================================================
641 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
643 // Selected object to be edited
644 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
646 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
651 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
652 aMeshName = aMeshName.stripWhiteSpace();
653 if ( aMeshName == "" )
655 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
659 /* // Imported mesh, if create sub-mesh or edit mesh
660 if ( !myToCreate || ( myToCreate && !myIsMesh ))
662 QString aMeshEntry = myDlg->selectedObject
663 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
664 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
665 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
666 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
667 theMess = tr( "IMPORTED_MESH" );
676 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
677 if ( aGeomEntry == "" )
679 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
682 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
683 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
685 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
690 if ( !myIsMesh ) // i.e sub-mesh creation,
692 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
693 if ( aMeshEntry == "" )
695 theMess = tr( "MESH_IS_NOT_DEFINED" );
698 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
699 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
701 theMess = tr( "MESH_IS_NULL" );
704 if ( !isSubshapeOk() )
706 theMess = tr( "INVALID_SUBSHAPE" );
715 //================================================================================
717 * \brief check compatibility of the algorithm and another algorithm or hypothesis
718 * \param theAlgoData - algorithm data
719 * \param theHypData - hypothesis data
720 * \param theHypType - hypothesis type
721 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
722 * \retval bool - check result
724 //================================================================================
726 static bool isCompatible(const HypothesisData* theAlgoData,
727 const HypothesisData* theHypData,
728 const int theHypType)
733 if ( theHypType == SMESHGUI_MeshOp::Algo )
734 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
737 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
740 //================================================================================
742 * \brief Gets available hypotheses or algorithms
743 * \param theDim - specifies dimension of returned hypotheses/algorifms
744 * \param theHypType - specifies whether algorims or hypotheses or additional ones
745 * are retrieved (possible values are in HypType enumeration)
746 * \param theHyps - Output list of hypotheses' names
747 * \param theAlgoData - to select hypos able to be used by this algo (optional)
749 * Gets available hypotheses or algorithm in accordance with input parameters
751 //================================================================================
752 void SMESHGUI_MeshOp::availableHyps( const int theDim,
753 const int theHypType,
754 QStringList& theHyps,
755 THypDataList& theDataList,
756 HypothesisData* theAlgoData ) const
760 bool isAlgo = ( theHypType == Algo );
761 bool isAux = ( theHypType == AddHyp );
762 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
764 QStringList::const_iterator anIter;
765 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
767 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
768 if ( isCompatible ( theAlgoData, aData, theHypType )) {
769 theDataList.append( aData );
770 theHyps.append( aData->Label );
775 //================================================================================
777 * \brief Gets existing hypotheses or algorithms
778 * \param theDim - specifies dimension of returned hypotheses/algorifms
779 * \param theHypType - specifies whether algorims or hypotheses or additional ones
780 * are retrieved (possible values are in HypType enumeration)
781 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
782 * \param theHyps - output list of names.
783 * \param theHypVars - output list of variables.
784 * \param theAlgoData - to select hypos able to be used by this algo (optional)
786 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
789 //================================================================================
790 void SMESHGUI_MeshOp::existingHyps( const int theDim,
791 const int theHypType,
792 _PTR(SObject) theFather,
793 QStringList& theHyps,
794 THypList& theHypList,
795 HypothesisData* theAlgoData)
797 // Clear hypoheses list
804 const bool isAux = ( theHypType == AddHyp );
806 _PTR(SObject) aHypRoot;
807 _PTR(GenericAttribute) anAttr;
808 _PTR(AttributeName) aName;
809 _PTR(AttributeIOR) anIOR;
811 bool isMesh = !_CAST( SComponent, theFather );
814 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
816 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
818 if ( theFather->FindSubObject( aPart, aHypRoot ) )
820 _PTR(ChildIterator) anIter =
821 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
822 for (; anIter->More(); anIter->Next() )
824 _PTR(SObject) anObj = anIter->Value();
825 if ( isMesh ) // i.e. mesh or submesh
827 _PTR(SObject) aRefObj;
828 if ( anObj->ReferencedObject( aRefObj ) )
833 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
836 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
837 if ( !CORBA::is_nil( aVar ) )
839 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
840 if ( !aHypVar->_is_nil() )
842 CORBA::String_var aHypType( aHypVar->GetName() );
843 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
844 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
845 ( isCompatible ( theAlgoData, aData, theHypType )) &&
846 ( isAux == aData->IsAux ))
848 std::string aHypName = aName->Value();
849 theHyps.append( aHypName.c_str() );
850 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
859 //================================================================================
861 * \brief If create or edit a submesh, return a hypothesis holding parameters used
863 * \param aHypType - The hypothesis type name
864 * \param aServerLib - Server library name
865 * \param hypData - The structure holding the hypothesis type etc.
866 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
868 //================================================================================
870 SMESH::SMESH_Hypothesis_var
871 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
872 const QString& aServerLib ) const
874 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
875 return SMESH::SMESH_Hypothesis::_nil();
877 const int nbColonsInMeshEntry = 3;
878 bool isSubMesh = myToCreate ?
880 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
884 // get mesh and geom object
885 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
886 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
888 QString anEntry = myDlg->selectedObject
889 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
890 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
892 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
893 if ( myToCreate ) // mesh and geom may be selected
895 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
896 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
897 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
898 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
900 else // edition: sub-mesh may be selected
902 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
903 if ( !sm->_is_nil() ) {
904 aMeshVar = sm->GetFather();
905 aGeomVar = sm->GetSubShape();
910 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
911 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
916 return SMESH::SMESH_Hypothesis::_nil();
919 //================================================================================
921 * \Brief Returns tab dimention
922 * \param tab - the tab in the dlg
923 * \param dlg - my dialogue
924 * \retval int - dimention
926 //================================================================================
928 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
931 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
932 if (tab == dlg->tab(i))
937 //================================================================================
939 * \brief Create hypothesis
940 * \param theHypType - hypothesis category (main or additional)
941 * \param theIndex - index of type of hypothesis to be cerated
943 * Specifies dimension of hypothesis to be created (using sender() method),
944 * specifies its type and calls method for hypothesis creation
946 //================================================================================
947 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
949 // Specifies dimension of hypothesis to be created
950 int aDim = getTabDim( sender(), myDlg );
954 // Specifies type of hypothesis to be created
955 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
956 if (theIndex < 0 || theIndex >= dataList.count())
958 QString aHypTypeName = dataList[ theIndex ]->TypeName;
961 createHypothesis(aDim, theHypType, aHypTypeName);
964 //================================================================================
966 * Create hypothesis and update dialog.
967 * \param theDim - dimension of hypothesis to be created
968 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
969 * \param theTypeName - specifies hypothesis to be created
971 //================================================================================
974 QString GetUniqueName (const QStringList& theHypNames,
975 const QString& theName,
976 size_t theIteration = 1)
978 QString aName = theName + "_" + QString::number( theIteration );
979 if ( theHypNames.contains( aName ) )
980 return GetUniqueName( theHypNames, theName, ++theIteration );
985 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
987 const QString& theTypeName)
989 // During a hypothesis creation we might need to select some objects.
990 // Main dialog must not update it's own selected objects in this case.
991 dlg()->deactivateAll();
993 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
997 QStringList aHypNames;
998 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
999 for (; aDimIter != myExistingHyps.end(); aDimIter++) {
1000 const TType2HypList& aType2HypList = aDimIter.data();
1001 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1002 for (; aTypeIter != aType2HypList.end(); aTypeIter++) {
1003 const THypList& aHypList = aTypeIter.data();
1004 THypList::const_iterator anIter = aHypList.begin();
1005 for (; anIter != aHypList.end(); anIter++) {
1006 const THypItem& aHypItem = *anIter;
1007 const QString& aHypName = aHypItem.second;
1008 aHypNames.append(aHypName);
1012 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1015 int nbHyp = myExistingHyps[theDim][theType].count();
1017 QString aClientLibName = aData->ClientLibName;
1018 if (aClientLibName == "") {
1019 // Call hypothesis creation server method (without GUI)
1020 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1022 // Get hypotheses creator client (GUI)
1023 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1025 // Create hypothesis
1027 // When create or edit a submesh, try to initialize a new hypothesis
1028 // with values used to mesh a subshape
1029 SMESH::SMESH_Hypothesis_var initParamHyp =
1030 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1031 myDlg->setEnabled( false );
1032 aCreator->create(initParamHyp, aHypName, myDlg);
1033 myDlg->setEnabled( true );
1035 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1039 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1041 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
1042 QStringList aNewHyps;
1043 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
1044 if (aNewHyps.count() > nbHyp) {
1045 for (int i = nbHyp; i < aNewHyps.count(); i++)
1046 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
1050 //================================================================================
1052 * \brief Calls plugin methods for hypothesis editing
1053 * \param theHypType - specifies whether main hypothesis or additional one
1055 * \param theIndex - index of existing hypothesis
1057 * Calls plugin methods for hypothesis editing
1059 //================================================================================
1060 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1062 // Speicfies dimension of hypothesis to be created
1063 int aDim = getTabDim( sender(), myDlg );
1067 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1068 if ( theIndex < 0 || theIndex >= aList.count() )
1070 const THypItem& aHypItem = aList[ theIndex ];
1071 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1072 if ( aHyp->_is_nil() )
1075 CORBA::String_var aTypeName = aHyp->GetName();
1076 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
1078 myDlg->setEnabled( false );
1079 aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
1080 myDlg->setEnabled( true );
1084 //================================================================================
1086 * \brief access to hypothesis data
1087 * \param theDim - hyp dimension
1088 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1089 * \param theIndex - index in the list
1090 * \retval HypothesisData* - result data, may be 0
1092 //================================================================================
1094 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1095 const int theHypType,
1098 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1099 theHypType > -1 && theHypType < NbHypTypes &&
1100 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1101 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1105 //================================================================================
1107 * \brief Set available algos and hypos according to the selected algorithm
1108 * \param theIndex - algorithm index
1110 //================================================================================
1112 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1115 if ( myIgnoreAlgoSelection )
1118 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1122 // find highest available dimension, all algos of this dimension are available for choice
1124 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1125 if (isAccessibleDim( i ))
1130 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1132 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1133 HypothesisData* algoByDim[4];
1134 algoByDim[ aDim ] = algoData;
1136 QStringList anAvailable;
1137 if ( !algoData ) { // all algos becomes available
1138 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1139 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1142 // check that algorithms of other dimentions are compatible with
1145 // 2 loops: backward and forward from algo dimension
1146 for ( int forward = false; forward <= true; ++forward )
1148 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1150 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1152 HypothesisData* prevAlgo = algoData;
1153 bool noCompatible = false;
1154 for (; dim * dir <= lastDim * dir; dim += dir)
1156 if ( !isAccessibleDim( dim ))
1158 if ( noCompatible ) { // the selected algo has no compatible ones
1159 anAvailable.clear();
1160 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1161 myAvailableHypData[dim][Algo].clear();
1162 algoByDim[ dim ] = 0;
1165 // get currently selected algo
1166 int algoIndex = currentHyp( dim, Algo );
1167 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1168 if ( curAlgo ) { // some algo selected
1169 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1172 // set new available algoritms
1173 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1174 HypothesisData* soleCompatible = 0;
1175 if ( anAvailable.count() == 1 )
1176 soleCompatible = myAvailableHypData[dim][Algo][0];
1177 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1178 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1179 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1180 noCompatible = anAvailable.isEmpty();
1182 // restore previously selected algo
1183 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1184 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1185 // select the sole compatible algo
1186 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1187 setCurrentHyp( dim, Algo, algoIndex );
1189 // remember current algo
1190 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1194 // set hypotheses corresponding to the found algoritms
1196 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1198 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1200 if ( !isAccessibleDim( dim ))
1202 for ( int type = MainHyp; type < NbHypTypes; type++ )
1204 myAvailableHypData[ dim ][ type ].clear();
1205 QStringList anAvailable, anExisting;
1207 HypothesisData* curAlgo = algoByDim[ dim ];
1208 int hypIndex = currentHyp( dim, type );
1210 SMESH::SMESH_Hypothesis_var curHyp;
1211 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1212 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1214 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1215 // try to find algo by selected hypothesis in order to keep it selected
1216 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1217 CORBA::String_var curHypType = curHyp->GetName();
1218 if ( !algoDeselectedByUser &&
1219 myObjHyps[ dim ][ type ].count() > 0 &&
1220 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1222 CORBA::String_var aName = curHyp->GetName();
1223 HypothesisData* hypData = SMESH::GetHypothesisData( aName );
1224 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1225 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1226 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1233 // get hyps compatible with curAlgo
1236 // check if a selected hyp is compatible with the curAlgo
1237 if ( !curHyp->_is_nil() ) {
1238 CORBA::String_var aName = curHyp->GetName();
1239 HypothesisData* hypData = SMESH::GetHypothesisData( aName );
1240 if ( !isCompatible( curAlgo, hypData, type ))
1241 curHyp = SMESH::SMESH_Hypothesis::_nil();
1243 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1244 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1246 // set list of hypotheses
1247 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1248 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1250 // set current existing hypothesis
1251 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1252 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1255 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1256 // none is yet selected => select the sole existing if it is not optional
1257 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1258 bool isOptional = true;
1259 if ( algoByDim[ dim ] &&
1260 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1264 setCurrentHyp( dim, type, hypIndex );
1269 //================================================================================
1271 * \brief Creates and selects hypothesis of hypotheses set
1272 * \param theSetName - The name of hypotheses set
1274 //================================================================================
1275 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1277 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1278 if (!aHypoSet) return;
1281 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1282 setCurrentHyp(dim, Algo, -1);
1283 setCurrentHyp(dim, AddHyp, -1);
1284 setCurrentHyp(dim, MainHyp, -1);
1287 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1288 bool isAlgo = (aHypType == Algo);
1290 // set hyps from the set
1291 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1292 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1293 const QString& aHypoTypeName = (*aHypoList)[ i ];
1294 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1298 int aDim = aHypData->Dim[0];
1299 // create or/and set
1301 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1303 QStringList anAvailable;
1304 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1305 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1306 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1308 setCurrentHyp( aDim, Algo, index );
1309 onAlgoSelected( index, aDim );
1312 bool mainHyp = true;
1313 QStringList anAvailable;
1314 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1315 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1316 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1319 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1322 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1324 } // loop on hypos in the set
1325 } // loop on algo/hypo
1328 //================================================================================
1330 * \brief Creates mesh
1331 * \param theMess - Output parameter intended for returning error message
1332 * \retval bool - TRUE if mesh is created, FALSE otherwise
1336 //================================================================================
1337 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1341 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1342 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1345 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1346 QStringList::Iterator it = aList.begin();
1347 for (; it!=aList.end(); it++)
1349 QString aGeomEntry = *it;
1350 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1351 GEOM::GEOM_Object_var aGeomVar =
1352 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1354 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1355 if ( aSMESHGen->_is_nil() )
1358 SUIT_OverrideCursor aWaitCursor;
1361 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1362 if ( aMeshVar->_is_nil() )
1364 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1366 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1368 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1369 if ( !isAccessibleDim( aDim )) continue;
1371 // assign hypotheses
1372 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1373 int aHypIndex = currentHyp( aDim, aHypType );
1374 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1375 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1376 if ( !aHypVar->_is_nil() )
1377 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1380 // find or create algorithm
1381 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1382 if ( !anAlgoVar->_is_nil() )
1383 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1390 //================================================================================
1392 * \brief Creates sub-mesh
1393 * \param theMess - Output parameter intended for returning error message
1394 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1398 //================================================================================
1399 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1403 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1404 if ( aSMESHGen->_is_nil() )
1408 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1409 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1410 SMESH::SMESH_Mesh_var aMeshVar =
1411 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1412 if (aMeshVar->_is_nil())
1415 // GEOM shape of the main mesh
1416 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1418 // Name for the new sub-mesh
1419 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1422 GEOM::GEOM_Object_var aGeomVar;
1424 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1425 if (aGEOMs.count() == 1)
1427 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1428 QString aGeomEntry = aGEOMs.first();
1429 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1430 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1432 else if (aGEOMs.count() > 1)
1434 // create a GEOM group
1435 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1436 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1437 if (!geomGen->_is_nil() && aStudy) {
1438 GEOM::GEOM_IGroupOperations_var op =
1439 geomGen->GetIGroupOperations(aStudy->StudyId());
1440 if (!op->_is_nil()) {
1441 // check and add all selected GEOM objects: they must be
1442 // a sub-shapes of the main GEOM and must be of one type
1444 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1445 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1446 aSeq->length(aGEOMs.count());
1447 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1448 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1449 QString aSubGeomEntry = (*aSubShapesIter);
1450 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
1451 GEOM::GEOM_Object_var aSubGeomVar =
1452 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1453 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1455 aGroupType = aSubShapeType;
1457 if (aSubShapeType != aGroupType)
1458 aGroupType = TopAbs_SHAPE;
1460 aSeq[iSubSh] = aSubGeomVar;
1463 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1464 op->UnionList(aGroupVar, aSeq);
1467 aGeomVar = aGroupVar;
1469 // publish the GEOM group in study
1470 QString aNewGeomGroupName ("Auto_group_for_");
1471 aNewGeomGroupName += aName;
1472 SALOMEDS::SObject_var aNewGroupSO =
1473 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
1480 if (aGeomVar->_is_nil())
1483 SUIT_OverrideCursor aWaitCursor;
1486 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1488 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1490 if ( !isAccessibleDim( aDim )) continue;
1492 // find or create algorithm
1493 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1494 if ( !anAlgoVar->_is_nil() )
1495 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1496 // assign hypotheses
1497 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1499 int aHypIndex = currentHyp( aDim, aHypType );
1500 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1502 SMESH::SMESH_Hypothesis_var aHypVar =
1503 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1504 if ( !aHypVar->_is_nil() )
1505 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1510 // deselect geometry: next submesh should be created on other subshape
1511 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1512 selectObject( _PTR(SObject)() );
1518 //================================================================================
1520 * \brief Gets current hypothesis or algorithms
1521 * \param theDim - dimension of hypothesis or algorithm
1522 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1523 * \retval int - current hypothesis or algorithms
1525 * Gets current hypothesis or algorithms
1527 //================================================================================
1528 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1530 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1533 //================================================================================
1535 * \brief Returns true if hypotheses of given dim can be assigned
1536 * \param theDim - hypotheses dimension
1537 * \retval bool - result
1539 //================================================================================
1540 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1542 return myDlg->tab( theDim )->isEnabled();
1545 //================================================================================
1547 * \brief Sets current hypothesis or algorithms
1548 * \param theDim - dimension of hypothesis or algorithm
1549 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1550 * \param theIndex - Index of hypothesis
1552 * Gets current hypothesis or algorithms
1554 //================================================================================
1555 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1556 const int theHypType,
1557 const int theIndex )
1559 myIgnoreAlgoSelection = true;
1560 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1561 myIgnoreAlgoSelection = false;
1564 //================================================================================
1566 * \brief Generates default and sets mesh/submesh name
1568 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1570 //================================================================================
1571 void SMESHGUI_MeshOp::setDefaultName() const
1575 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1577 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1578 _PTR(SObject) anObj;
1581 aResName = aPrefix + QString::number( i++ );
1582 anObj = aStudy->FindObject( aResName.latin1() );
1586 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1587 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1588 aControl->setText( aResName );
1591 //================================================================================
1593 * \brief Gets algorithm or creates it if necessary
1594 * \param theDim - specifies dimension of returned hypotheses/algorifms
1595 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1597 * Gets algorithm or creates it if necessary
1599 //================================================================================
1600 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1602 SMESH::SMESH_Hypothesis_var anAlgoVar;
1604 // get type of the selected algo
1605 int aHypIndex = currentHyp( theDim, Algo );
1606 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1607 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1609 QString aHypName = dataList[ aHypIndex ]->TypeName;
1611 // get existing algoritms
1612 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1614 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1616 // look for anexisting algo of such a type
1617 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1618 THypList::iterator anIter = aHypVarList.begin();
1619 for (; anIter != aHypVarList.end(); anIter++)
1621 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1622 CORBA::String_var aName = aHypVar->GetName();
1623 if ( !aHypVar->_is_nil() && aHypName == aName )
1625 anAlgoVar = aHypVar;
1630 if (anAlgoVar->_is_nil()) {
1631 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1633 QString aClientLibName = aHypData->ClientLibName;
1634 if (aClientLibName == "") {
1635 // Call hypothesis creation server method (without GUI)
1636 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1638 // Get hypotheses creator client (GUI)
1639 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1643 aCreator->create(true, aHypName, myDlg);
1645 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1647 QStringList tmpList;
1648 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1649 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1652 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1653 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1655 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1656 CORBA::String_var aName = aHypVar->GetName();
1657 if ( !aHypVar->_is_nil() && aHypName == aName )
1659 anAlgoVar = aHypVar;
1665 return anAlgoVar._retn();
1668 //================================================================================
1670 * \brief Reads parameters of edited mesh and assigns them to the dialog
1672 * Reads parameters of edited mesh and assigns them to the dialog (called when
1673 * mesh is edited only)
1675 //================================================================================
1676 void SMESHGUI_MeshOp::readMesh()
1678 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1679 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1683 if (myIsOnGeometry) {
1684 // Get name of mesh if current object is sub-mesh
1685 SMESH::SMESH_subMesh_var aSubMeshVar =
1686 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1687 if ( !aSubMeshVar->_is_nil() )
1689 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1690 if ( !aMeshVar->_is_nil() )
1692 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1693 QString aMeshName = name( aMeshSO );
1694 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1698 // Get name of geometry object
1699 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1700 if ( !aGeomVar->_is_nil() )
1702 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1703 QString aShapeName = name( aGeomSO );
1704 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1708 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1709 QStringList anExisting;
1710 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1711 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1714 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1715 // find algo index among available ones
1717 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1719 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1720 CORBA::String_var aHypTypeName = aVar->GetName();
1721 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1722 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1723 // if ( aHypIndex < 0 && algoData ) {
1724 // // assigned algo is incompatible with other algorithms
1725 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1726 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1729 setCurrentHyp( dim, Algo, aHypIndex );
1730 // set existing and available hypothesis according to the selected algo
1731 onAlgoSelected( aHypIndex, dim );
1735 bool hypWithoutAlgo = false;
1736 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1738 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1741 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1742 // find index of requered hypothesis among existing ones for this dimension and type
1744 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1745 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1746 myExistingHyps[ dim ][ hypType ] );
1747 if ( aHypIndex < 0 ) {
1748 // assigned hypothesis is incompatible with the algorithm
1749 if ( currentHyp( dim, Algo ) < 0 )
1750 { // none algo selected; it is edition for sure, of submesh maybe
1751 hypWithoutAlgo = true;
1752 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1753 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1754 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1758 setCurrentHyp( dim, hypType, aHypIndex );
1761 // make available other hyps of same type as one without algo
1762 if ( hypWithoutAlgo )
1763 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1766 //================================================================================
1768 * \brief Gets name of object
1769 * \param theSO - SObject
1770 * \retval QString - name of object
1772 * Gets name of object
1774 //================================================================================
1775 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1780 _PTR(GenericAttribute) anAttr;
1781 _PTR(AttributeName) aNameAttr;
1782 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1785 aResName = aNameAttr->Value().c_str();
1791 //================================================================================
1793 * \brief Finds hypothesis in input list
1794 * \param theHyp - hypothesis to be found
1795 * \param theHypList - input list of hypotheses
1796 * \retval int - index of hypothesis or -1 if it is not found
1798 * Finds position of hypothesis in input list
1800 //================================================================================
1801 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1802 const THypList& theHypList ) const
1805 if ( !theHyp->_is_nil() )
1808 THypList::const_iterator anIter = theHypList.begin();
1809 for (; anIter != theHypList.end(); ++ anIter)
1811 if ( theHyp->_is_equivalent( (*anIter).first ) )
1822 //================================================================================
1824 * \brief Edits mesh or sub-mesh
1825 * \param theMess - Output parameter intended for returning error message
1826 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1828 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1830 //================================================================================
1831 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1835 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1836 if ( aSMESHGen->_is_nil() )
1839 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1840 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1844 SUIT_OverrideCursor aWaitCursor;
1847 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1848 SMESH::SetName( pObj, aName.latin1() );
1849 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1851 // First, remove old algos in order to avoid messages on algorithm hiding
1852 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1854 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
1856 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
1857 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1858 if ( anAlgoVar->_is_nil() || // no new algo selected or
1859 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
1861 // remove old algorithm
1862 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
1863 myObjHyps[ dim ][ Algo ].clear();
1868 // Assign new algorithms and hypotheses
1869 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1871 if ( !isAccessibleDim( dim )) continue;
1873 // find or create algorithm
1874 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1876 // assign new algorithm
1877 if ( !anAlgoVar->_is_nil() && // some algo selected and
1878 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
1880 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
1881 CORBA::Object_var anObject = aSObject->GetObject();
1882 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
1883 bool isMesh = !aMeshVar->_is_nil();
1885 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1887 SMESH::SMESH_subMesh_var aVar =
1888 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1889 if ( !aVar->_is_nil() )
1890 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1892 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
1895 // assign hypotheses
1896 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1898 int aNewHypIndex = currentHyp( dim, hypType );
1899 int anOldHypIndex = -1;
1901 // remove old hypotheses
1902 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1904 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first ,
1905 myExistingHyps[ dim ][ hypType ] );
1906 if ( aNewHypIndex != anOldHypIndex || // different hyps
1907 anOldHypIndex == -1 ) // hyps of different algos
1909 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1910 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
1911 myObjHyps[ dim ][ hypType ].clear();
1915 // assign new hypotheses
1916 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1918 SMESH::SMESH_Mesh_var aMeshVar =
1919 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1920 bool isMesh = !aMeshVar->_is_nil();
1923 SMESH::AddHypothesisOnMesh
1924 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1928 SMESH::SMESH_subMesh_var aVar =
1929 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1930 if ( !aVar->_is_nil() )
1931 SMESH::AddHypothesisOnSubMesh
1932 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1935 // reread all hypotheses of mesh if necessary
1936 QStringList anExisting;
1937 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1944 //================================================================================
1946 * \brief Verifies whether given operator is valid for this one
1947 * \param theOtherOp - other operation
1948 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1950 * method redefined from base class verifies whether given operator is valid for
1951 * this one (i.e. can be started "above" this operator). In current implementation method
1952 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1955 //================================================================================
1956 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1958 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1961 //================================================================================
1963 * \brief SLOT. Is called when the user selects a way of geometry selection
1964 * \param theByMesh - true if the user wants to find geometry by mesh element
1966 //================================================================================
1968 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1971 if ( !myShapeByMeshOp ) {
1972 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1973 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1974 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1975 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1976 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1978 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1979 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1980 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1981 SMESH::SMESH_Mesh_var aMeshVar =
1982 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1983 if ( !aMeshVar->_is_nil() ) {
1984 myDlg->hide(); // stop processing selection
1985 myShapeByMeshOp->setModule( getSMESHGUI() );
1986 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1987 myShapeByMeshOp->SetMesh( aMeshVar );
1988 myShapeByMeshOp->start();
1994 //================================================================================
1996 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1998 //================================================================================
2000 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2002 if ( myShapeByMeshOp == op ) {
2003 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2005 // Select a found geometry object
2006 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2007 if ( !aGeomVar->_is_nil() )
2009 QString ID = aGeomVar->GetStudyEntry();
2010 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
2011 selectObject( aGeomSO );
2018 //================================================================================
2020 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2022 //================================================================================
2024 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2026 if ( myShapeByMeshOp == op && myDlg ) {
2031 //================================================================================
2033 * \brief Selects a SObject
2034 * \param theSObj - the SObject to select
2036 //================================================================================
2038 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2040 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2041 SALOME_ListIO anIOList;
2043 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2044 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2045 anIOList.Append( anIO );
2047 sm->setSelectedObjects( anIOList, false );