1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshOp.h"
30 #include "SMESHGUI_MeshDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Hypotheses.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_NumberFilter.hxx>
40 // SALOME GEOM includes
41 #include <GEOM_SelectionFilter.h>
43 #include <GeometryGUI.h>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SALOME_InteractiveObject.hxx>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDS_SComponent.hxx>
57 #include <SALOMEDS_SObject.hxx>
60 #include <QStringList>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Shell.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <BRep_Tool.hxx>
71 #include <SALOMEconfig.h>
72 #include CORBA_CLIENT_HEADER(SMESH_Gen)
74 //================================================================================
77 * \param theToCreate - if this parameter is true then operation is used for creation,
78 * for editing otherwise
80 * Initialize operation
82 //================================================================================
83 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
84 : SMESHGUI_SelectionOp(),
85 myToCreate( theToCreate ),
86 myIsMesh( theIsMesh ),
90 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
91 GeometryGUI::InitGeomGen();
92 myIsOnGeometry = true;
95 //================================================================================
99 //================================================================================
100 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
106 //================================================================================
108 * \brief Gets dialog of this operation
109 * \retval LightApp_Dialog* - pointer to dialog of this operation
111 //================================================================================
112 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
117 //================================================================================
119 * \brief Creates or edits mesh
120 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
122 * Virtual slot redefined from the base class called when "Apply" button is clicked
123 * creates or edits mesh
125 //================================================================================
126 bool SMESHGUI_MeshOp::onApply()
132 if ( !isValid( aMess ) )
136 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
140 bool aResult = false;
144 if ( myToCreate && myIsMesh )
145 aResult = createMesh( aMess );
146 if ( myToCreate && !myIsMesh )
147 aResult = createSubMesh( aMess );
148 else if ( !myToCreate )
149 aResult = editMeshOrSubMesh( aMess );
151 update( UF_ObjBrowser | UF_Model );
153 catch ( const SALOME::SALOME_Exception& S_ex )
155 SalomeApp_Tools::QtCatchCorbaException( S_ex );
171 aMess = tr( "SMESH_OPERATION_FAILED" );
172 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
178 //================================================================================
180 * \brief Creates dialog if necessary and shows it
182 * Virtual method redefined from base class called when operation is started creates
183 * dialog if necessary and shows it, activates selection
185 //================================================================================
186 void SMESHGUI_MeshOp::startOperation()
190 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
191 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
193 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
194 this, SLOT( onCreateHyp( const int, const int ) ) );
195 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
196 this, SLOT( onEditHyp( const int, const int ) ) );
197 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
198 this, SLOT( onAlgoSelected( const int ) ) );
200 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
201 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
204 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
205 else myHelpFileName = "constructing_submeshes_page.html";
206 else myHelpFileName = "editing_meshes_page.html";
208 SMESHGUI_SelectionOp::startOperation();
210 // iterate through dimensions and get available algoritms, set them to the dialog
211 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
212 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
214 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
216 // clear available hypotheses
217 aTab->setAvailableHyps( MainHyp, hypList );
218 aTab->setAvailableHyps( AddHyp, hypList );
219 aTab->setExistingHyps( MainHyp, hypList );
220 aTab->setExistingHyps( AddHyp, hypList );
221 myExistingHyps[ i ][ MainHyp ].clear();
222 myExistingHyps[ i ][ AddHyp ].clear();
224 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
225 aTab->setAvailableHyps( Algo, hypList );
230 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
233 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
235 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
237 myDlg->setCurrentTab( SMESH::DIM_3D );
242 myIgnoreAlgoSelection = false;
245 //================================================================================
247 * \brief Creates selection filter
248 * \param theId - identifier of current selection widget
249 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
251 * Creates selection filter in accordance with identifier of current selection widget
253 //================================================================================
254 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
256 if ( theId == SMESHGUI_MeshDlg::Geom )
258 // TColStd_MapOfInteger allTypesMap;
259 // for ( int i = 0; i < 10; i++ )
260 // allTypesMap.Add( i );
261 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
262 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
264 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
265 return new SMESH_TypeFilter( MESHorSUBMESH );
266 else if ( theId == SMESHGUI_MeshDlg::Mesh )
267 return new SMESH_TypeFilter( MESH );
272 //================================================================================
274 * \brief check if selected shape is a subshape of the shape to mesh
275 * \retval bool - check result
277 //================================================================================
279 bool SMESHGUI_MeshOp::isSubshapeOk() const
281 if ( !myToCreate || myIsMesh ) // not submesh creation
285 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
286 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
287 if (!pMesh) return false;
289 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
290 if (mesh->_is_nil()) return false;
292 // main shape of the mesh
293 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
294 if (mainGeom->_is_nil()) return false;
298 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
300 if (aGEOMs.count() > 0) {
301 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
302 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
303 if (geomGen->_is_nil() || !aStudy) return false;
305 GEOM::GEOM_IGroupOperations_var op =
306 geomGen->GetIGroupOperations(aStudy->StudyId());
307 if (op->_is_nil()) return false;
309 // check all selected shapes
310 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
311 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
312 QString aSubGeomEntry = (*aSubShapesIter);
313 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
314 if (!pSubGeom) return false;
316 GEOM::GEOM_Object_var aSubGeomVar =
317 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
318 if (aSubGeomVar->_is_nil()) return false;
320 // skl for NPAL14695 - implementation of searching of mainObj
321 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
322 //if (mainObj->_is_nil() ||
323 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
325 if (mainObj->_is_nil())
327 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
329 mainObj = op->GetMainShape(mainObj);
338 //================================================================================
340 * \brief Return name of the algorithm that does not support submeshes and makes
341 * submesh creation useless
342 * \retval char* - string is to be deleted!!!
344 //================================================================================
346 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
348 if ( myToCreate && !myIsMesh ) {
350 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
351 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
352 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
355 QStringList algoNames;
357 existingHyps(3, Algo, pMesh, algoNames, algoList);
358 if (!algoList.empty()) {
359 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
361 algo->InputTypes.empty() && // builds all dimensions it-self
362 !algo->IsSupportSubmeshes )
363 return CORBA::string_dup( algoNames[0].toLatin1().data() );
366 // GEOM::GEOM_Object_var geom;
367 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
368 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
370 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
371 existingHyps(2, Algo, pMesh, algoNames, algoList);
372 if (!algoList.empty()) {
373 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
375 algo->InputTypes.empty() && // builds all dimensions it-self
376 !algo->IsSupportSubmeshes )
377 return CORBA::string_dup( algoNames[0].toLatin1().data() );
385 //================================================================================
387 * \brief find an existing submesh by the selected shape
388 * \retval _PTR(SObject) - the found submesh SObject
390 //================================================================================
392 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
394 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
395 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
396 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
397 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
398 if ( pMesh && pGeom ) {
399 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
400 if ( !geom->_is_nil() ) {
402 switch ( geom->GetShapeType() ) {
403 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
404 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
405 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
406 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
407 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
408 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
409 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
412 _PTR(GenericAttribute) anAttr;
413 _PTR(SObject) aSubmeshRoot;
414 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
415 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
417 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
418 for ( ; smIter->More(); smIter->Next() )
420 _PTR(SObject) aSmObj = smIter->Value();
421 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
423 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
424 for ( ; anIter1->More(); anIter1->Next()) {
425 _PTR(SObject) pGeom2 = anIter1->Value();
426 if ( pGeom2->ReferencedObject( pGeom2 ) &&
427 pGeom2->GetID() == pGeom->GetID() )
434 return _PTR(SObject)();
437 //================================================================================
439 * \brief Updates dialog's look and feel
441 * Virtual method redefined from the base class updates dialog's look and feel
443 //================================================================================
444 void SMESHGUI_MeshOp::selectionDone()
446 if (!dlg()->isVisible() || !myDlg->isEnabled())
449 SMESHGUI_SelectionOp::selectionDone();
453 myIsOnGeometry = true;
455 //Check geometry for mesh
456 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
457 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
460 SMESH::SMESH_Mesh_var aMeshVar =
461 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
462 if (!aMeshVar->_is_nil()) {
463 if (!myToCreate && !aMeshVar->HasShapeToMesh())
464 myIsOnGeometry = false;
470 // Enable tabs according to shape dimension
475 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
476 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
478 if (aGEOMs.count() > 0) {
479 // one or more GEOM shape selected
480 aSeq->length(aGEOMs.count());
481 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
483 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
484 QString aSubGeomEntry = (*aSubShapesIter);
485 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
486 GEOM::GEOM_Object_var aSubGeomVar =
487 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
488 aSeq[iSubSh] = aSubGeomVar;
491 // get geometry by selected sub-mesh
492 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
493 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
494 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
495 if (!aGeomVar->_is_nil()) {
501 if (aSeq->length() > 0) {
503 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
504 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
505 switch ( aGeomVar->GetShapeType() ) {
506 case GEOM::SOLID: shapeDim = 3; break;
509 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
510 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
512 if (GEOMBase::GetShape(aGeomVar, aShape)) {
513 if (/*aShape.Closed()*/BRep_Tool::IsClosed(aShape))
518 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
520 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
521 case GEOM::VERTEX: break;
525 if (GEOMBase::GetShape(aGeomVar, aShape)) {
526 TopExp_Explorer exp (aShape, TopAbs_SHELL);
528 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
529 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
530 for (; exp.More() && shapeDim == 2; exp.Next()) {
531 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
535 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
536 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
537 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
538 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
546 myDlg->setMaxHypoDim( shapeDim );
549 if (!myToCreate) // edition: read hypotheses
553 SMESH::SMESH_subMesh_var aVar =
554 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
555 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
556 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
557 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
558 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
559 myDlg->updateGeometry();
566 else if ( !myIsMesh ) // submesh creation
568 // if a submesh on the selected shape already exist, pass to submesh edition mode
569 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
570 SMESH::SMESH_subMesh_var sm =
571 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
572 bool editSubmesh = ( !sm->_is_nil() &&
573 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
574 tr( "EDIT_SUBMESH_QUESTION"),
575 SUIT_MessageBox::Yes |
577 SUIT_MessageBox::No )
578 == SUIT_MessageBox::Yes );
581 selectionMgr()->clearFilters();
582 selectObject( pSubmesh );
583 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
588 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
589 selectObject( _PTR(SObject)() );
594 // discard selected mesh if submesh creation not allowed because of
595 // a global algorithm that does not support submeshes
596 if ( char* algoName = isSubmeshIgnored() ) {
597 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
598 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
599 CORBA::string_free( algoName );
600 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
601 selectObject( _PTR(SObject)() );
606 // enable/disable popup for choice of geom selection way
608 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
609 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
610 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
611 if ( !mesh->_is_nil() )
612 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
614 myDlg->setGeomPopupEnabled( enable );
618 myDlg->enableTab( SMESH::DIM_3D );
620 availableHyps( SMESH::DIM_3D, Algo, hypList,
621 myAvailableHypData[SMESH::DIM_3D][Algo]);
623 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
624 aTab->setAvailableHyps( Algo, hypList );
625 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
626 myDlg->disableTab(i);
628 //Hide labels and fields (Mesh ang Geometry)
629 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
630 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
635 catch ( const SALOME::SALOME_Exception& S_ex )
637 SalomeApp_Tools::QtCatchCorbaException( S_ex );
644 //================================================================================
646 * \brief Verifies validity of input data
647 * \param theMess - Output parameter intended for returning error message
648 * \retval bool - TRUE if input data is valid, false otherwise
650 * Verifies validity of input data. This method is called when "Apply" or "OK" button
651 * is pressed before mesh creation or editing.
653 //================================================================================
654 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
656 // Selected object to be edited
657 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
659 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
664 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
665 if ( aMeshName.isEmpty() )
667 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
671 /* // Imported mesh, if create sub-mesh or edit mesh
672 if ( !myToCreate || ( myToCreate && !myIsMesh ))
674 QString aMeshEntry = myDlg->selectedObject
675 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
676 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
677 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
678 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
679 theMess = tr( "IMPORTED_MESH" );
688 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
689 if ( aGeomEntry == "" )
691 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
694 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
695 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
697 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
702 if ( !myIsMesh ) // i.e sub-mesh creation,
704 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
705 if ( aMeshEntry == "" )
707 theMess = tr( "MESH_IS_NOT_DEFINED" );
710 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
711 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
713 theMess = tr( "MESH_IS_NULL" );
716 if ( !isSubshapeOk() )
718 theMess = tr( "INVALID_SUBSHAPE" );
727 //================================================================================
729 * \brief check compatibility of the algorithm and another algorithm or hypothesis
730 * \param theAlgoData - algorithm data
731 * \param theHypData - hypothesis data
732 * \param theHypType - hypothesis type
733 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
734 * \retval bool - check result
736 //================================================================================
738 static bool isCompatible(const HypothesisData* theAlgoData,
739 const HypothesisData* theHypData,
740 const int theHypType)
745 if ( theHypType == SMESHGUI_MeshOp::Algo )
746 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
749 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
752 //================================================================================
754 * \brief Gets available hypotheses or algorithms
755 * \param theDim - specifies dimension of returned hypotheses/algorifms
756 * \param theHypType - specifies whether algorims or hypotheses or additional ones
757 * are retrieved (possible values are in HypType enumeration)
758 * \param theHyps - Output list of hypotheses' names
759 * \param theAlgoData - to select hypos able to be used by this algo (optional)
761 * Gets available hypotheses or algorithm in accordance with input parameters
763 //================================================================================
764 void SMESHGUI_MeshOp::availableHyps( const int theDim,
765 const int theHypType,
766 QStringList& theHyps,
767 THypDataList& theDataList,
768 HypothesisData* theAlgoData ) const
772 bool isAlgo = ( theHypType == Algo );
773 bool isAux = ( theHypType == AddHyp );
774 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
776 QStringList::const_iterator anIter;
777 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
779 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
780 if ( isCompatible ( theAlgoData, aData, theHypType )) {
781 theDataList.append( aData );
782 theHyps.append( aData->Label );
787 //================================================================================
789 * \brief Gets existing hypotheses or algorithms
790 * \param theDim - specifies dimension of returned hypotheses/algorifms
791 * \param theHypType - specifies whether algorims or hypotheses or additional ones
792 * are retrieved (possible values are in HypType enumeration)
793 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
794 * \param theHyps - output list of names.
795 * \param theHypVars - output list of variables.
796 * \param theAlgoData - to select hypos able to be used by this algo (optional)
798 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
801 //================================================================================
802 void SMESHGUI_MeshOp::existingHyps( const int theDim,
803 const int theHypType,
804 _PTR(SObject) theFather,
805 QStringList& theHyps,
806 THypList& theHypList,
807 HypothesisData* theAlgoData)
809 // Clear hypoheses list
816 const bool isAux = ( theHypType == AddHyp );
818 _PTR(SObject) aHypRoot;
819 _PTR(GenericAttribute) anAttr;
820 _PTR(AttributeName) aName;
821 _PTR(AttributeIOR) anIOR;
823 bool isMesh = !_CAST( SComponent, theFather );
826 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
828 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
830 if ( theFather->FindSubObject( aPart, aHypRoot ) )
832 _PTR(ChildIterator) anIter =
833 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
834 for ( ; anIter->More(); anIter->Next() )
836 _PTR(SObject) anObj = anIter->Value();
837 if ( isMesh ) // i.e. mesh or submesh
839 _PTR(SObject) aRefObj;
840 if ( anObj->ReferencedObject( aRefObj ) )
845 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
848 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
849 if ( !CORBA::is_nil( aVar ) )
851 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
852 if ( !aHypVar->_is_nil() )
854 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
855 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
856 ( isCompatible ( theAlgoData, aData, theHypType )) &&
857 ( isAux == aData->IsAux ))
859 std::string aHypName = aName->Value();
860 theHyps.append( aHypName.c_str() );
861 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
870 //================================================================================
872 * \brief If create or edit a submesh, return a hypothesis holding parameters used
874 * \param aHypType - The hypothesis type name
875 * \param aServerLib - Server library name
876 * \param hypData - The structure holding the hypothesis type etc.
877 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
879 //================================================================================
881 SMESH::SMESH_Hypothesis_var
882 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
883 const QString& aServerLib ) const
885 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
886 return SMESH::SMESH_Hypothesis::_nil();
888 const int nbColonsInMeshEntry = 3;
889 bool isSubMesh = myToCreate ?
891 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
895 // get mesh and geom object
896 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
897 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
899 QString anEntry = myDlg->selectedObject
900 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
901 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
903 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
904 if ( myToCreate ) // mesh and geom may be selected
906 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
907 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
908 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
909 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
911 else // edition: sub-mesh may be selected
913 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
914 if ( !sm->_is_nil() ) {
915 aMeshVar = sm->GetFather();
916 aGeomVar = sm->GetSubShape();
921 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
922 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
923 aServerLib.toLatin1().data(),
927 return SMESH::SMESH_Hypothesis::_nil();
930 //================================================================================
932 * \Brief Returns tab dimention
933 * \param tab - the tab in the dlg
934 * \param dlg - my dialogue
935 * \retval int - dimention
937 //================================================================================
939 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
942 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
943 if (tab == dlg->tab(i))
948 //================================================================================
950 * \brief Create hypothesis
951 * \param theHypType - hypothesis category (main or additional)
952 * \param theIndex - index of type of hypothesis to be cerated
954 * Specifies dimension of hypothesis to be created (using sender() method),
955 * specifies its type and calls method for hypothesis creation
957 //================================================================================
958 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
960 // Specifies dimension of hypothesis to be created
961 int aDim = getTabDim( sender(), myDlg );
965 // Specifies type of hypothesis to be created
966 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
967 if (theIndex < 0 || theIndex >= dataList.count())
969 QString aHypTypeName = dataList[ theIndex ]->TypeName;
972 createHypothesis(aDim, theHypType, aHypTypeName);
975 //================================================================================
977 * Create hypothesis and update dialog.
978 * \param theDim - dimension of hypothesis to be created
979 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
980 * \param theTypeName - specifies hypothesis to be created
982 //================================================================================
985 QString GetUniqueName (const QStringList& theHypNames,
986 const QString& theName,
987 size_t theIteration = 1)
989 QString aName = theName + "_" + QString::number( theIteration );
990 if ( theHypNames.contains( aName ) )
991 return GetUniqueName( theHypNames, theName, ++theIteration );
996 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
998 const QString& theTypeName)
1000 // During a hypothesis creation we might need to select some objects.
1001 // Main dialog must not update it's own selected objects in this case.
1002 dlg()->deactivateAll();
1004 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1008 QStringList aHypNames;
1009 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1010 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1011 const TType2HypList& aType2HypList = aDimIter.value();
1012 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1013 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1014 const THypList& aHypList = aTypeIter.value();
1015 THypList::const_iterator anIter = aHypList.begin();
1016 for ( ; anIter != aHypList.end(); anIter++) {
1017 const THypItem& aHypItem = *anIter;
1018 const QString& aHypName = aHypItem.second;
1019 aHypNames.append(aHypName);
1023 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1026 int nbHyp = myExistingHyps[theDim][theType].count();
1028 QString aClientLibName = aData->ClientLibName;
1029 if (aClientLibName == "") {
1030 // Call hypothesis creation server method (without GUI)
1031 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1033 // Get hypotheses creator client (GUI)
1034 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1036 // Create hypothesis
1038 // When create or edit a submesh, try to initialize a new hypothesis
1039 // with values used to mesh a subshape
1040 SMESH::SMESH_Hypothesis_var initParamHyp =
1041 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1042 myDlg->setEnabled( false );
1043 aCreator->create(initParamHyp, aHypName, myDlg);
1044 myDlg->setEnabled( true );
1046 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1050 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1052 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
1053 QStringList aNewHyps;
1054 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
1055 if (aNewHyps.count() > nbHyp) {
1056 for (int i = nbHyp; i < aNewHyps.count(); i++)
1057 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
1061 //================================================================================
1063 * \brief Calls plugin methods for hypothesis editing
1064 * \param theHypType - specifies whether main hypothesis or additional one
1066 * \param theIndex - index of existing hypothesis
1068 * Calls plugin methods for hypothesis editing
1070 //================================================================================
1071 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1073 // Speicfies dimension of hypothesis to be created
1074 int aDim = getTabDim( sender(), myDlg );
1078 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1079 if ( theIndex < 0 || theIndex >= aList.count() )
1081 const THypItem& aHypItem = aList[ theIndex ];
1082 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1083 if ( aHyp->_is_nil() )
1086 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHyp->GetName() );
1088 myDlg->setEnabled( false );
1089 aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
1090 myDlg->setEnabled( true );
1094 //================================================================================
1096 * \brief access to hypothesis data
1097 * \param theDim - hyp dimension
1098 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1099 * \param theIndex - index in the list
1100 * \retval HypothesisData* - result data, may be 0
1102 //================================================================================
1104 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1105 const int theHypType,
1108 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1109 theHypType > -1 && theHypType < NbHypTypes &&
1110 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1111 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1115 //================================================================================
1117 * \brief Set available algos and hypos according to the selected algorithm
1118 * \param theIndex - algorithm index
1120 //================================================================================
1122 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1125 if ( myIgnoreAlgoSelection )
1128 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1132 // find highest available dimension, all algos of this dimension are available for choice
1134 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1135 if (isAccessibleDim( i ))
1140 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1142 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1143 HypothesisData* algoByDim[4];
1144 algoByDim[ aDim ] = algoData;
1146 QStringList anAvailable;
1147 if ( !algoData ) { // all algos becomes available
1148 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1149 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1152 // check that algorithms of other dimentions are compatible with
1155 // 2 loops: backward and forward from algo dimension
1156 for ( int forward = false; forward <= true; ++forward )
1158 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1160 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1162 HypothesisData* prevAlgo = algoData;
1163 bool noCompatible = false;
1164 for ( ; dim * dir <= lastDim * dir; dim += dir)
1166 if ( !isAccessibleDim( dim ))
1168 if ( noCompatible ) { // the selected algo has no compatible ones
1169 anAvailable.clear();
1170 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1171 myAvailableHypData[dim][Algo].clear();
1172 algoByDim[ dim ] = 0;
1175 // get currently selected algo
1176 int algoIndex = currentHyp( dim, Algo );
1177 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1178 if ( curAlgo ) { // some algo selected
1179 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1182 // set new available algoritms
1183 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1184 HypothesisData* soleCompatible = 0;
1185 if ( anAvailable.count() == 1 )
1186 soleCompatible = myAvailableHypData[dim][Algo][0];
1187 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1188 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1189 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1190 noCompatible = anAvailable.isEmpty();
1192 // restore previously selected algo
1193 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1194 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1195 // select the sole compatible algo
1196 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1197 setCurrentHyp( dim, Algo, algoIndex );
1199 // remember current algo
1200 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1204 // set hypotheses corresponding to the found algoritms
1206 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1208 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1210 if ( !isAccessibleDim( dim ))
1212 for ( int type = MainHyp; type < NbHypTypes; type++ )
1214 myAvailableHypData[ dim ][ type ].clear();
1215 QStringList anAvailable, anExisting;
1217 HypothesisData* curAlgo = algoByDim[ dim ];
1218 int hypIndex = currentHyp( dim, type );
1220 SMESH::SMESH_Hypothesis_var curHyp;
1221 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1222 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1224 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1225 // try to find algo by selected hypothesis in order to keep it selected
1226 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1227 CORBA::String_var curHypType = curHyp->GetName();
1228 if ( !algoDeselectedByUser &&
1229 myObjHyps[ dim ][ type ].count() > 0 &&
1230 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1232 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1233 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1234 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1235 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1242 // get hyps compatible with curAlgo
1245 // check if a selected hyp is compatible with the curAlgo
1246 if ( !curHyp->_is_nil() ) {
1247 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1248 if ( !isCompatible( curAlgo, hypData, type ))
1249 curHyp = SMESH::SMESH_Hypothesis::_nil();
1251 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1252 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1254 // set list of hypotheses
1255 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1256 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1258 // set current existing hypothesis
1259 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1260 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1263 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1264 // none is yet selected => select the sole existing if it is not optional
1265 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1266 bool isOptional = true;
1267 if ( algoByDim[ dim ] &&
1268 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1272 setCurrentHyp( dim, type, hypIndex );
1277 //================================================================================
1279 * \brief Creates and selects hypothesis of hypotheses set
1280 * \param theSetName - The name of hypotheses set
1282 //================================================================================
1283 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1285 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1286 if (!aHypoSet) return;
1289 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1290 setCurrentHyp(dim, Algo, -1);
1291 setCurrentHyp(dim, AddHyp, -1);
1292 setCurrentHyp(dim, MainHyp, -1);
1295 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1296 bool isAlgo = (aHypType == Algo);
1298 // set hyps from the set
1299 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1300 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1301 const QString& aHypoTypeName = (*aHypoList)[ i ];
1302 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1306 int aDim = aHypData->Dim[0];
1307 // create or/and set
1309 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1311 QStringList anAvailable;
1312 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1313 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1314 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1316 setCurrentHyp( aDim, Algo, index );
1317 onAlgoSelected( index, aDim );
1320 bool mainHyp = true;
1321 QStringList anAvailable;
1322 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1323 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1324 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1327 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1330 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1332 } // loop on hypos in the set
1333 } // loop on algo/hypo
1336 //================================================================================
1338 * \brief Creates mesh
1339 * \param theMess - Output parameter intended for returning error message
1340 * \retval bool - TRUE if mesh is created, FALSE otherwise
1344 //================================================================================
1345 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1349 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1350 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1353 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1354 QStringList::Iterator it = aList.begin();
1355 for ( ; it!=aList.end(); it++)
1357 QString aGeomEntry = *it;
1358 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1359 GEOM::GEOM_Object_var aGeomVar =
1360 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1362 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1363 if ( aSMESHGen->_is_nil() )
1366 SUIT_OverrideCursor aWaitCursor;
1369 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1370 if ( aMeshVar->_is_nil() )
1372 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1374 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1376 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1377 if ( !isAccessibleDim( aDim )) continue;
1379 // assign hypotheses
1380 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1381 int aHypIndex = currentHyp( aDim, aHypType );
1382 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1383 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1384 if ( !aHypVar->_is_nil() )
1385 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1388 // find or create algorithm
1389 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1390 if ( !anAlgoVar->_is_nil() )
1391 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1398 //================================================================================
1400 * \brief Creates sub-mesh
1401 * \param theMess - Output parameter intended for returning error message
1402 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1406 //================================================================================
1407 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1411 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1412 if ( aSMESHGen->_is_nil() )
1416 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1417 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1418 SMESH::SMESH_Mesh_var aMeshVar =
1419 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1420 if (aMeshVar->_is_nil())
1423 // GEOM shape of the main mesh
1424 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1426 // Name for the new sub-mesh
1427 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1430 GEOM::GEOM_Object_var aGeomVar;
1432 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1433 if (aGEOMs.count() == 1)
1435 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1436 QString aGeomEntry = aGEOMs.first();
1437 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1438 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1440 else if (aGEOMs.count() > 1)
1442 // create a GEOM group
1443 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1444 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1445 if (!geomGen->_is_nil() && aStudy) {
1446 GEOM::GEOM_IGroupOperations_var op =
1447 geomGen->GetIGroupOperations(aStudy->StudyId());
1448 if (!op->_is_nil()) {
1449 // check and add all selected GEOM objects: they must be
1450 // a sub-shapes of the main GEOM and must be of one type
1452 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1453 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1454 aSeq->length(aGEOMs.count());
1455 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1456 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1457 QString aSubGeomEntry = (*aSubShapesIter);
1458 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1459 GEOM::GEOM_Object_var aSubGeomVar =
1460 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1461 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1463 aGroupType = aSubShapeType;
1465 if (aSubShapeType != aGroupType)
1466 aGroupType = TopAbs_SHAPE;
1468 aSeq[iSubSh] = aSubGeomVar;
1471 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1472 op->UnionList(aGroupVar, aSeq);
1475 aGeomVar = aGroupVar;
1477 // publish the GEOM group in study
1478 QString aNewGeomGroupName ("Auto_group_for_");
1479 aNewGeomGroupName += aName;
1480 SALOMEDS::SObject_var aNewGroupSO =
1481 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1482 aNewGeomGroupName.toLatin1().data(), mainGeom);
1489 if (aGeomVar->_is_nil())
1492 SUIT_OverrideCursor aWaitCursor;
1495 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1497 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1499 if ( !isAccessibleDim( aDim )) continue;
1501 // find or create algorithm
1502 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1503 if ( !anAlgoVar->_is_nil() )
1504 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1505 // assign hypotheses
1506 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1508 int aHypIndex = currentHyp( aDim, aHypType );
1509 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1511 SMESH::SMESH_Hypothesis_var aHypVar =
1512 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1513 if ( !aHypVar->_is_nil() )
1514 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1519 // deselect geometry: next submesh should be created on other subshape
1520 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1521 selectObject( _PTR(SObject)() );
1527 //================================================================================
1529 * \brief Gets current hypothesis or algorithms
1530 * \param theDim - dimension of hypothesis or algorithm
1531 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1532 * \retval int - current hypothesis or algorithms
1534 * Gets current hypothesis or algorithms
1536 //================================================================================
1537 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1539 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1542 //================================================================================
1544 * \brief Returns true if hypotheses of given dim can be assigned
1545 * \param theDim - hypotheses dimension
1546 * \retval bool - result
1548 //================================================================================
1549 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1551 return myDlg->tab( theDim )->isEnabled();
1554 //================================================================================
1556 * \brief Sets current hypothesis or algorithms
1557 * \param theDim - dimension of hypothesis or algorithm
1558 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1559 * \param theIndex - Index of hypothesis
1561 * Gets current hypothesis or algorithms
1563 //================================================================================
1564 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1565 const int theHypType,
1566 const int theIndex )
1568 myIgnoreAlgoSelection = true;
1569 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1570 myIgnoreAlgoSelection = false;
1573 //================================================================================
1575 * \brief Generates default and sets mesh/submesh name
1577 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1579 //================================================================================
1580 void SMESHGUI_MeshOp::setDefaultName() const
1584 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1586 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1587 _PTR(SObject) anObj;
1590 aResName = aPrefix + QString::number( i++ );
1591 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1595 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1596 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1597 aControl->setText( aResName );
1600 //================================================================================
1602 * \brief Gets algorithm or creates it if necessary
1603 * \param theDim - specifies dimension of returned hypotheses/algorifms
1604 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1606 * Gets algorithm or creates it if necessary
1608 //================================================================================
1609 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1611 SMESH::SMESH_Hypothesis_var anAlgoVar;
1613 // get type of the selected algo
1614 int aHypIndex = currentHyp( theDim, Algo );
1615 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1616 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1618 QString aHypName = dataList[ aHypIndex ]->TypeName;
1620 // get existing algoritms
1621 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1623 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1625 // look for anexisting algo of such a type
1626 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1627 THypList::iterator anIter = aHypVarList.begin();
1628 for ( ; anIter != aHypVarList.end(); anIter++)
1630 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1631 CORBA::String_var aName = aHypVar->GetName();
1632 if ( !aHypVar->_is_nil() && aHypName == aName )
1634 anAlgoVar = aHypVar;
1639 if (anAlgoVar->_is_nil()) {
1640 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1642 QString aClientLibName = aHypData->ClientLibName;
1643 if (aClientLibName == "") {
1644 // Call hypothesis creation server method (without GUI)
1645 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1647 // Get hypotheses creator client (GUI)
1648 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1652 aCreator->create(true, aHypName, myDlg);
1654 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1656 QStringList tmpList;
1657 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1658 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1661 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1662 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1664 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1665 CORBA::String_var aName = aHypVar->GetName();
1666 if ( !aHypVar->_is_nil() && aHypName == aName )
1668 anAlgoVar = aHypVar;
1674 return anAlgoVar._retn();
1677 //================================================================================
1679 * \brief Reads parameters of edited mesh and assigns them to the dialog
1681 * Reads parameters of edited mesh and assigns them to the dialog (called when
1682 * mesh is edited only)
1684 //================================================================================
1685 void SMESHGUI_MeshOp::readMesh()
1687 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1688 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1692 if (myIsOnGeometry) {
1693 // Get name of mesh if current object is sub-mesh
1694 SMESH::SMESH_subMesh_var aSubMeshVar =
1695 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1696 if ( !aSubMeshVar->_is_nil() )
1698 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1699 if ( !aMeshVar->_is_nil() )
1701 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1702 QString aMeshName = name( aMeshSO );
1703 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1707 // Get name of geometry object
1708 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1709 if ( !aGeomVar->_is_nil() )
1711 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1712 QString aShapeName = name( aGeomSO );
1713 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1717 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1718 QStringList anExisting;
1719 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1720 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1723 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1724 // find algo index among available ones
1726 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1728 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1729 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1730 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1731 // if ( aHypIndex < 0 && algoData ) {
1732 // // assigned algo is incompatible with other algorithms
1733 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1734 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1737 setCurrentHyp( dim, Algo, aHypIndex );
1738 // set existing and available hypothesis according to the selected algo
1739 onAlgoSelected( aHypIndex, dim );
1743 bool hypWithoutAlgo = false;
1744 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1746 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1749 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1750 // find index of requered hypothesis among existing ones for this dimension and type
1752 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1753 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1754 myExistingHyps[ dim ][ hypType ] );
1755 if ( aHypIndex < 0 ) {
1756 // assigned hypothesis is incompatible with the algorithm
1757 if ( currentHyp( dim, Algo ) < 0 )
1758 { // none algo selected; it is edition for sure, of submesh maybe
1759 hypWithoutAlgo = true;
1760 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1761 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1762 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1766 setCurrentHyp( dim, hypType, aHypIndex );
1769 // make available other hyps of same type as one without algo
1770 if ( hypWithoutAlgo )
1771 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1774 //================================================================================
1776 * \brief Gets name of object
1777 * \param theSO - SObject
1778 * \retval QString - name of object
1780 * Gets name of object
1782 //================================================================================
1783 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1788 _PTR(GenericAttribute) anAttr;
1789 _PTR(AttributeName) aNameAttr;
1790 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1793 aResName = aNameAttr->Value().c_str();
1799 //================================================================================
1801 * \brief Finds hypothesis in input list
1802 * \param theHyp - hypothesis to be found
1803 * \param theHypList - input list of hypotheses
1804 * \retval int - index of hypothesis or -1 if it is not found
1806 * Finds position of hypothesis in input list
1808 //================================================================================
1809 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1810 const THypList& theHypList ) const
1813 if ( !theHyp->_is_nil() )
1816 THypList::const_iterator anIter = theHypList.begin();
1817 for ( ; anIter != theHypList.end(); ++ anIter)
1819 if ( theHyp->_is_equivalent( (*anIter).first ) )
1830 //================================================================================
1832 * \brief Edits mesh or sub-mesh
1833 * \param theMess - Output parameter intended for returning error message
1834 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1836 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1838 //================================================================================
1839 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1843 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1844 if ( aSMESHGen->_is_nil() )
1847 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1848 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1852 SUIT_OverrideCursor aWaitCursor;
1855 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1856 SMESH::SetName( pObj, aName );
1857 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1859 // First, remove old algos in order to avoid messages on algorithm hiding
1860 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1862 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
1864 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
1865 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1866 if ( anAlgoVar->_is_nil() || // no new algo selected or
1867 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
1869 // remove old algorithm
1870 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
1871 myObjHyps[ dim ][ Algo ].clear();
1876 // Assign new algorithms and hypotheses
1877 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1879 if ( !isAccessibleDim( dim )) continue;
1881 // find or create algorithm
1882 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1884 // assign new algorithm
1885 if ( !anAlgoVar->_is_nil() && // some algo selected and
1886 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
1888 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
1889 CORBA::Object_var anObject = aSObject->GetObject();
1890 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
1891 bool isMesh = !aMeshVar->_is_nil();
1893 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1895 SMESH::SMESH_subMesh_var aVar =
1896 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1897 if ( !aVar->_is_nil() )
1898 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1900 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
1903 // assign hypotheses
1904 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1906 int aNewHypIndex = currentHyp( dim, hypType );
1907 int anOldHypIndex = -1;
1909 // remove old hypotheses
1910 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1912 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1913 myExistingHyps[ dim ][ hypType ] );
1914 if ( aNewHypIndex != anOldHypIndex || // different hyps
1915 anOldHypIndex == -1 ) // hyps of different algos
1917 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1918 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
1919 myObjHyps[ dim ][ hypType ].clear();
1923 // assign new hypotheses
1924 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1926 SMESH::SMESH_Mesh_var aMeshVar =
1927 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1928 bool isMesh = !aMeshVar->_is_nil();
1931 SMESH::AddHypothesisOnMesh
1932 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1936 SMESH::SMESH_subMesh_var aVar =
1937 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1938 if ( !aVar->_is_nil() )
1939 SMESH::AddHypothesisOnSubMesh
1940 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
1943 // reread all hypotheses of mesh if necessary
1944 QStringList anExisting;
1945 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1952 //================================================================================
1954 * \brief Verifies whether given operator is valid for this one
1955 * \param theOtherOp - other operation
1956 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1958 * method redefined from base class verifies whether given operator is valid for
1959 * this one (i.e. can be started "above" this operator). In current implementation method
1960 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1963 //================================================================================
1964 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1966 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1969 //================================================================================
1971 * \brief SLOT. Is called when the user selects a way of geometry selection
1972 * \param theByMesh - true if the user wants to find geometry by mesh element
1974 //================================================================================
1976 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1979 if ( !myShapeByMeshOp ) {
1980 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1981 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1982 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1983 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1984 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1986 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1987 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1988 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
1989 SMESH::SMESH_Mesh_var aMeshVar =
1990 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1991 if ( !aMeshVar->_is_nil() ) {
1992 myDlg->hide(); // stop processing selection
1993 myShapeByMeshOp->setModule( getSMESHGUI() );
1994 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1995 myShapeByMeshOp->SetMesh( aMeshVar );
1996 myShapeByMeshOp->start();
2002 //================================================================================
2004 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2006 //================================================================================
2008 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2010 if ( myShapeByMeshOp == op ) {
2011 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2013 // Select a found geometry object
2014 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2015 if ( !aGeomVar->_is_nil() )
2017 QString ID = aGeomVar->GetStudyEntry();
2018 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2019 selectObject( aGeomSO );
2026 //================================================================================
2028 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2030 //================================================================================
2032 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2034 if ( myShapeByMeshOp == op && myDlg ) {
2039 //================================================================================
2041 * \brief Selects a SObject
2042 * \param theSObj - the SObject to select
2044 //================================================================================
2046 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2048 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2049 SALOME_ListIO anIOList;
2051 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2052 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2053 anIOList.Append( anIO );
2055 sm->setSelectedObjects( anIOList, false );