1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MeshOp.cxx
24 // 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 ),
91 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
92 GeometryGUI::InitGeomGen();
93 myIsOnGeometry = true;
96 //================================================================================
100 //================================================================================
101 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
107 //================================================================================
109 * \brief Gets dialog of this operation
110 * \retval LightApp_Dialog* - pointer to dialog of this operation
112 //================================================================================
113 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
118 //================================================================================
120 * \brief Creates or edits mesh
121 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
123 * Virtual slot redefined from the base class called when "Apply" button is clicked
124 * creates or edits mesh
126 //================================================================================
127 bool SMESHGUI_MeshOp::onApply()
133 if ( !isValid( aMess ) )
137 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
141 bool aResult = false;
145 if ( myToCreate && myIsMesh )
146 aResult = createMesh( aMess );
147 if ( myToCreate && !myIsMesh )
148 aResult = createSubMesh( aMess );
149 else if ( !myToCreate )
150 aResult = editMeshOrSubMesh( aMess );
152 update( UF_ObjBrowser | UF_Model );
154 catch ( const SALOME::SALOME_Exception& S_ex )
156 SalomeApp_Tools::QtCatchCorbaException( S_ex );
172 aMess = tr( "SMESH_OPERATION_FAILED" );
173 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
179 //================================================================================
181 * \brief Creates dialog if necessary and shows it
183 * Virtual method redefined from base class called when operation is started creates
184 * dialog if necessary and shows it, activates selection
186 //================================================================================
187 void SMESHGUI_MeshOp::startOperation()
191 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
192 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
194 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
195 this, SLOT( onCreateHyp( const int, const int ) ) );
196 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
197 this, SLOT( onEditHyp( const int, const int ) ) );
198 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
199 this, SLOT( onAlgoSelected( const int ) ) );
201 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
202 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
205 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
206 else myHelpFileName = "constructing_submeshes_page.html";
207 else myHelpFileName = "editing_meshes_page.html";
209 SMESHGUI_SelectionOp::startOperation();
211 // iterate through dimensions and get available algoritms, set them to the dialog
212 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
213 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
215 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
217 // clear available hypotheses
218 aTab->setAvailableHyps( MainHyp, hypList );
219 aTab->setAvailableHyps( AddHyp, hypList );
220 aTab->setExistingHyps( MainHyp, hypList );
221 aTab->setExistingHyps( AddHyp, hypList );
222 myExistingHyps[ i ][ MainHyp ].clear();
223 myExistingHyps[ i ][ AddHyp ].clear();
225 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
226 aTab->setAvailableHyps( Algo, hypList );
231 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
234 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
236 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
238 myDlg->setCurrentTab( SMESH::DIM_3D );
243 myIgnoreAlgoSelection = false;
246 //================================================================================
248 * \brief Creates selection filter
249 * \param theId - identifier of current selection widget
250 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
252 * Creates selection filter in accordance with identifier of current selection widget
254 //================================================================================
255 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
257 if ( theId == SMESHGUI_MeshDlg::Geom )
259 // TColStd_MapOfInteger allTypesMap;
260 // for ( int i = 0; i < 10; i++ )
261 // allTypesMap.Add( i );
262 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
263 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
265 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
266 return new SMESH_TypeFilter( MESHorSUBMESH );
267 else if ( theId == SMESHGUI_MeshDlg::Mesh )
268 return new SMESH_TypeFilter( MESH );
273 //================================================================================
275 * \brief check if selected shape is a subshape of the shape to mesh
276 * \retval bool - check result
278 //================================================================================
280 bool SMESHGUI_MeshOp::isSubshapeOk() const
282 if ( !myToCreate || myIsMesh ) // not submesh creation
286 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
287 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
288 if (!pMesh) return false;
290 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
291 if (mesh->_is_nil()) return false;
293 // main shape of the mesh
294 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
295 if (mainGeom->_is_nil()) return false;
299 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
301 if (aGEOMs.count() > 0) {
302 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
303 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
304 if (geomGen->_is_nil() || !aStudy) return false;
306 GEOM::GEOM_IGroupOperations_var op =
307 geomGen->GetIGroupOperations(aStudy->StudyId());
308 if (op->_is_nil()) return false;
310 // check all selected shapes
311 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
312 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
313 QString aSubGeomEntry = (*aSubShapesIter);
314 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
315 if (!pSubGeom) return false;
317 GEOM::GEOM_Object_var aSubGeomVar =
318 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
319 if (aSubGeomVar->_is_nil()) return false;
321 // skl for NPAL14695 - implementation of searching of mainObj
322 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
323 //if (mainObj->_is_nil() ||
324 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
326 if (mainObj->_is_nil())
328 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
330 mainObj = op->GetMainShape(mainObj);
339 //================================================================================
341 * \brief Return name of the algorithm that does not support submeshes and makes
342 * submesh creation useless
343 * \retval char* - string is to be deleted!!!
345 //================================================================================
347 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
349 if ( myToCreate && !myIsMesh ) {
351 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
352 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
353 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
356 QStringList algoNames;
358 existingHyps(3, Algo, pMesh, algoNames, algoList);
359 if (!algoList.empty()) {
360 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
362 algo->InputTypes.empty() && // builds all dimensions it-self
363 !algo->IsSupportSubmeshes )
364 return CORBA::string_dup( algoNames[0].toLatin1().data() );
367 // GEOM::GEOM_Object_var geom;
368 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
369 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
371 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
372 existingHyps(2, Algo, pMesh, algoNames, algoList);
373 if (!algoList.empty()) {
374 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
376 algo->InputTypes.empty() && // builds all dimensions it-self
377 !algo->IsSupportSubmeshes )
378 return CORBA::string_dup( algoNames[0].toLatin1().data() );
386 //================================================================================
388 * \brief find an existing submesh by the selected shape
389 * \retval _PTR(SObject) - the found submesh SObject
391 //================================================================================
393 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
395 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
396 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
397 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
398 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
399 if ( pMesh && pGeom ) {
400 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
401 if ( !geom->_is_nil() ) {
403 switch ( geom->GetShapeType() ) {
404 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
405 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
406 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
407 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
408 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
409 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
410 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
413 _PTR(GenericAttribute) anAttr;
414 _PTR(SObject) aSubmeshRoot;
415 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
416 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
418 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
419 for ( ; smIter->More(); smIter->Next() )
421 _PTR(SObject) aSmObj = smIter->Value();
422 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
424 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
425 for ( ; anIter1->More(); anIter1->Next()) {
426 _PTR(SObject) pGeom2 = anIter1->Value();
427 if ( pGeom2->ReferencedObject( pGeom2 ) &&
428 pGeom2->GetID() == pGeom->GetID() )
435 return _PTR(SObject)();
438 //================================================================================
440 * \brief Updates dialog's look and feel
442 * Virtual method redefined from the base class updates dialog's look and feel
444 //================================================================================
445 void SMESHGUI_MeshOp::selectionDone()
447 if (!dlg()->isVisible() || !myDlg->isEnabled())
450 SMESHGUI_SelectionOp::selectionDone();
454 myIsOnGeometry = true;
456 //Check geometry for mesh
457 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
458 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
461 SMESH::SMESH_Mesh_var aMeshVar =
462 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
463 if (!aMeshVar->_is_nil()) {
464 if (!myToCreate && !aMeshVar->HasShapeToMesh())
465 myIsOnGeometry = false;
471 // Enable tabs according to shape dimension
476 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
477 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
479 if (aGEOMs.count() > 0) {
480 // one or more GEOM shape selected
481 aSeq->length(aGEOMs.count());
482 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
484 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
485 QString aSubGeomEntry = (*aSubShapesIter);
486 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
487 GEOM::GEOM_Object_var aSubGeomVar =
488 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
489 aSeq[iSubSh] = aSubGeomVar;
492 // get geometry by selected sub-mesh
493 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
494 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
495 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
496 if (!aGeomVar->_is_nil()) {
502 if (aSeq->length() > 0) {
504 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
505 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
506 switch ( aGeomVar->GetShapeType() ) {
507 case GEOM::SOLID: shapeDim = 3; break;
510 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
511 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
513 if (GEOMBase::GetShape(aGeomVar, aShape)) {
514 if (/*aShape.Closed()*/BRep_Tool::IsClosed(aShape))
519 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
521 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
522 case GEOM::VERTEX: break;
526 if (GEOMBase::GetShape(aGeomVar, aShape)) {
527 TopExp_Explorer exp (aShape, TopAbs_SHELL);
529 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
530 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
531 for (; exp.More() && shapeDim == 2; exp.Next()) {
532 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
536 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
537 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
538 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
539 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
547 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
548 // reset algos before disabling tabs (0020138)
549 onAlgoSelected(-1, i);
551 myDlg->setMaxHypoDim( shapeDim );
554 if (!myToCreate) // edition: read hypotheses
558 SMESH::SMESH_subMesh_var aVar =
559 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
560 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
561 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
562 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
563 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
564 myDlg->updateGeometry();
571 else if ( !myIsMesh ) // submesh creation
573 // if a submesh on the selected shape already exist, pass to submesh edition mode
574 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
575 SMESH::SMESH_subMesh_var sm =
576 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
577 bool editSubmesh = ( !sm->_is_nil() &&
578 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
579 tr( "EDIT_SUBMESH_QUESTION"),
580 SUIT_MessageBox::Yes |
582 SUIT_MessageBox::No )
583 == SUIT_MessageBox::Yes );
586 selectionMgr()->clearFilters();
587 selectObject( pSubmesh );
588 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
593 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
594 selectObject( _PTR(SObject)() );
599 // discard selected mesh if submesh creation not allowed because of
600 // a global algorithm that does not support submeshes
601 if ( char* algoName = isSubmeshIgnored() ) {
602 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
603 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
604 CORBA::string_free( algoName );
605 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
606 selectObject( _PTR(SObject)() );
611 // enable/disable popup for choice of geom selection way
613 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
614 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
615 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
616 if ( !mesh->_is_nil() )
617 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
619 myDlg->setGeomPopupEnabled( enable );
623 myDlg->enableTab( SMESH::DIM_3D );
625 availableHyps( SMESH::DIM_3D, Algo, hypList,
626 myAvailableHypData[SMESH::DIM_3D][Algo]);
628 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
629 aTab->setAvailableHyps( Algo, hypList );
630 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
631 myDlg->disableTab(i);
633 //Hide labels and fields (Mesh ang Geometry)
634 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
635 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
640 catch ( const SALOME::SALOME_Exception& S_ex )
642 SalomeApp_Tools::QtCatchCorbaException( S_ex );
649 //================================================================================
651 * \brief Verifies validity of input data
652 * \param theMess - Output parameter intended for returning error message
653 * \retval bool - TRUE if input data is valid, false otherwise
655 * Verifies validity of input data. This method is called when "Apply" or "OK" button
656 * is pressed before mesh creation or editing.
658 //================================================================================
659 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
661 // Selected object to be edited
662 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
664 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
669 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
670 if ( aMeshName.isEmpty() )
672 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
676 /* // Imported mesh, if create sub-mesh or edit mesh
677 if ( !myToCreate || ( myToCreate && !myIsMesh ))
679 QString aMeshEntry = myDlg->selectedObject
680 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
681 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
682 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
683 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
684 theMess = tr( "IMPORTED_MESH" );
693 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
694 if ( aGeomEntry == "" )
696 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
699 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
700 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
702 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
707 if ( !myIsMesh ) // i.e sub-mesh creation,
709 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
710 if ( aMeshEntry == "" )
712 theMess = tr( "MESH_IS_NOT_DEFINED" );
715 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
716 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
718 theMess = tr( "MESH_IS_NULL" );
721 if ( !isSubshapeOk() )
723 theMess = tr( "INVALID_SUBSHAPE" );
732 //================================================================================
734 * \brief check compatibility of the algorithm and another algorithm or hypothesis
735 * \param theAlgoData - algorithm data
736 * \param theHypData - hypothesis data
737 * \param theHypType - hypothesis type
738 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
739 * \retval bool - check result
741 //================================================================================
743 static bool isCompatible(const HypothesisData* theAlgoData,
744 const HypothesisData* theHypData,
745 const int theHypType)
750 if ( theHypType == SMESHGUI_MeshOp::Algo )
751 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
754 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
757 //================================================================================
759 * \brief Gets available hypotheses or algorithms
760 * \param theDim - specifies dimension of returned hypotheses/algorifms
761 * \param theHypType - specifies whether algorims or hypotheses or additional ones
762 * are retrieved (possible values are in HypType enumeration)
763 * \param theHyps - Output list of hypotheses' names
764 * \param theAlgoData - to select hypos able to be used by this algo (optional)
766 * Gets available hypotheses or algorithm in accordance with input parameters
768 //================================================================================
769 void SMESHGUI_MeshOp::availableHyps( const int theDim,
770 const int theHypType,
771 QStringList& theHyps,
772 THypDataList& theDataList,
773 HypothesisData* theAlgoData ) const
777 bool isAlgo = ( theHypType == Algo );
778 bool isAux = ( theHypType == AddHyp );
779 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
781 QStringList::const_iterator anIter;
782 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
784 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
785 if ( isCompatible ( theAlgoData, aData, theHypType )) {
786 theDataList.append( aData );
787 theHyps.append( aData->Label );
792 //================================================================================
794 * \brief Gets existing hypotheses or algorithms
795 * \param theDim - specifies dimension of returned hypotheses/algorifms
796 * \param theHypType - specifies whether algorims or hypotheses or additional ones
797 * are retrieved (possible values are in HypType enumeration)
798 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
799 * \param theHyps - output list of names.
800 * \param theHypVars - output list of variables.
801 * \param theAlgoData - to select hypos able to be used by this algo (optional)
803 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
806 //================================================================================
807 void SMESHGUI_MeshOp::existingHyps( const int theDim,
808 const int theHypType,
809 _PTR(SObject) theFather,
810 QStringList& theHyps,
811 THypList& theHypList,
812 HypothesisData* theAlgoData)
814 // Clear hypoheses list
821 const bool isAux = ( theHypType == AddHyp );
823 _PTR(SObject) aHypRoot;
824 _PTR(GenericAttribute) anAttr;
825 _PTR(AttributeName) aName;
826 _PTR(AttributeIOR) anIOR;
828 bool isMesh = !_CAST( SComponent, theFather );
831 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
833 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
835 if ( theFather->FindSubObject( aPart, aHypRoot ) )
837 _PTR(ChildIterator) anIter =
838 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
839 for ( ; anIter->More(); anIter->Next() )
841 _PTR(SObject) anObj = anIter->Value();
842 if ( isMesh ) // i.e. mesh or submesh
844 _PTR(SObject) aRefObj;
845 if ( anObj->ReferencedObject( aRefObj ) )
850 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
853 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
854 if ( !CORBA::is_nil( aVar ) )
856 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
857 if ( !aHypVar->_is_nil() )
859 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
860 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
861 ( isCompatible ( theAlgoData, aData, theHypType )) &&
862 ( isAux == aData->IsAux ))
864 std::string aHypName = aName->Value();
865 theHyps.append( aHypName.c_str() );
866 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
875 //================================================================================
877 * \brief If create or edit a submesh, return a hypothesis holding parameters used
879 * \param aHypType - The hypothesis type name
880 * \param aServerLib - Server library name
881 * \param hypData - The structure holding the hypothesis type etc.
882 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
884 //================================================================================
886 SMESH::SMESH_Hypothesis_var
887 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
888 const QString& aServerLib ) const
890 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
891 return SMESH::SMESH_Hypothesis::_nil();
893 const int nbColonsInMeshEntry = 3;
894 bool isSubMesh = myToCreate ?
896 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
898 // get mesh and geom object
899 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
900 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
905 anEntry = myDlg->selectedObject
906 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
907 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
909 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
910 if ( myToCreate ) // mesh and geom may be selected
912 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
913 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
914 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
915 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
917 else // edition: sub-mesh may be selected
919 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
920 if ( !sm->_is_nil() ) {
921 aMeshVar = sm->GetFather();
922 aGeomVar = sm->GetSubShape();
929 if ( !myToCreate ) // mesh to edit can be selected
931 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
932 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
934 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
935 if ( !aMeshVar->_is_nil() )
936 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
939 if ( aGeomVar->_is_nil() ) {
940 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
941 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
943 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
948 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
949 aServerLib.toLatin1().data(),
952 /*byMesh = */isSubMesh);
956 //================================================================================
958 * \Brief Returns tab dimention
959 * \param tab - the tab in the dlg
960 * \param dlg - my dialogue
961 * \retval int - dimention
963 //================================================================================
965 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
968 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
969 if (tab == dlg->tab(i))
974 //================================================================================
976 * \brief Create hypothesis
977 * \param theHypType - hypothesis category (main or additional)
978 * \param theIndex - index of type of hypothesis to be cerated
980 * Specifies dimension of hypothesis to be created (using sender() method),
981 * specifies its type and calls method for hypothesis creation
983 //================================================================================
984 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
986 // Specifies dimension of hypothesis to be created
987 int aDim = getTabDim( sender(), myDlg );
991 // Specifies type of hypothesis to be created
992 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
993 if (theIndex < 0 || theIndex >= dataList.count())
995 QString aHypTypeName = dataList[ theIndex ]->TypeName;
998 createHypothesis(aDim, theHypType, aHypTypeName);
1003 QString GetUniqueName (const QStringList& theHypNames,
1004 const QString& theName,
1005 size_t theIteration = 1)
1007 QString aName = theName + "_" + QString::number( theIteration );
1008 if ( theHypNames.contains( aName ) )
1009 return GetUniqueName( theHypNames, theName, ++theIteration );
1014 //================================================================================
1016 * Create hypothesis and update dialog.
1017 * \param theDim - dimension of hypothesis to be created
1018 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1019 * \param theTypeName - specifies hypothesis to be created
1021 //================================================================================
1023 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1025 const QString& theTypeName)
1027 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1033 QStringList aHypNames;
1034 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1035 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1036 const TType2HypList& aType2HypList = aDimIter.value();
1037 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1038 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1039 const THypList& aHypList = aTypeIter.value();
1040 THypList::const_iterator anIter = aHypList.begin();
1041 for ( ; anIter != aHypList.end(); anIter++) {
1042 const THypItem& aHypItem = *anIter;
1043 const QString& aHypName = aHypItem.second;
1044 aHypNames.append(aHypName);
1048 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1051 bool dialog = false;
1053 QString aClientLibName = aData->ClientLibName;
1054 if (aClientLibName == "") {
1055 // Call hypothesis creation server method (without GUI)
1056 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1058 // Get hypotheses creator client (GUI)
1060 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1061 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1063 // Create hypothesis
1065 // Get parameters appropriate to initialize a new hypothesis
1066 SMESH::SMESH_Hypothesis_var initParamHyp =
1067 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1069 removeCustomFilters(); // Issue 0020170
1071 // Get Entry of the Geom object
1072 QString anObjEntry = "";
1073 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1074 if ( anObjEntry == "" ) {
1075 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1076 if ( anObjEntry != "" ) {
1077 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1078 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1079 anObjEntry = ( aGeomVar->_is_nil() ) ? "" : anObjEntry = aGeomVar->GetStudyEntry();
1083 aCreator->setShapeEntry( anObjEntry );
1084 myDlg->setEnabled( false );
1085 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1089 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1096 //================================================================================
1098 * Necessary steps after hypothesis creation
1099 * \param result - creation result:
1102 * 2 = additional value meaning that slot is called not from dialog box
1104 //================================================================================
1105 void SMESHGUI_MeshOp::onHypoCreated( int result )
1109 int obj = myDlg->getActiveObject();
1110 onActivateObject( obj ); // Issue 0020170. Restore filters
1111 myDlg->setEnabled( true );
1114 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1116 int nbHyp = myExistingHyps[myDim][myType].count();
1117 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1118 QStringList aNewHyps;
1119 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1120 if (aNewHyps.count() > nbHyp)
1122 for (int i = nbHyp; i < aNewHyps.count(); i++)
1123 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1126 if( result!=2 && myHypoSet )
1130 //================================================================================
1132 * \brief Calls plugin methods for hypothesis editing
1133 * \param theHypType - specifies whether main hypothesis or additional one
1135 * \param theIndex - index of existing hypothesis
1137 * Calls plugin methods for hypothesis editing
1139 //================================================================================
1140 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1142 // Speicfies dimension of hypothesis to be created
1143 int aDim = getTabDim( sender(), myDlg );
1147 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1148 if ( theIndex < 0 || theIndex >= aList.count() )
1150 const THypItem& aHypItem = aList[ theIndex ];
1151 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1152 if ( aHyp->_is_nil() )
1156 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1157 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1160 // Get initial parameters
1161 SMESH::SMESH_Hypothesis_var initParamHyp =
1162 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1163 aCreator->setInitParamsHypothesis( initParamHyp );
1165 // Get Entry of the Geom object
1166 QString anObjEntry = "";
1167 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1168 if ( anObjEntry == "" ) {
1169 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1170 if ( anObjEntry != "" ) {
1171 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1172 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1173 anObjEntry = aGeomVar->GetStudyEntry();
1177 aCreator->setShapeEntry( anObjEntry );
1178 removeCustomFilters(); // Issue 0020170
1179 myDlg->setEnabled( false );
1180 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1184 //================================================================================
1186 * Necessary steps after hypothesis edition
1187 * \param result - creation result:
1191 //================================================================================
1192 void SMESHGUI_MeshOp::onHypoEdited( int result )
1194 int obj = myDlg->getActiveObject();
1195 onActivateObject( obj ); // Issue 0020170. Restore filters
1196 myDlg->setEnabled( true );
1199 //================================================================================
1201 * \brief access to hypothesis data
1202 * \param theDim - hyp dimension
1203 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1204 * \param theIndex - index in the list
1205 * \retval HypothesisData* - result data, may be 0
1207 //================================================================================
1209 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1210 const int theHypType,
1213 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1214 theHypType > -1 && theHypType < NbHypTypes &&
1215 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1216 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1220 //================================================================================
1222 * \brief Set available algos and hypos according to the selected algorithm
1223 * \param theIndex - algorithm index
1225 //================================================================================
1227 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1230 if ( myIgnoreAlgoSelection )
1233 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1237 // find highest available dimension, all algos of this dimension are available for choice
1239 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1240 if (isAccessibleDim( i ))
1245 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1247 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1248 HypothesisData* algoByDim[4];
1249 algoByDim[ aDim ] = algoData;
1251 QStringList anAvailable;
1252 if ( !algoData ) { // all algos becomes available
1253 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1254 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1257 // check that algorithms of other dimentions are compatible with
1260 // 2 loops: backward and forward from algo dimension
1261 for ( int forward = false; forward <= true; ++forward )
1263 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1265 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1267 HypothesisData* prevAlgo = algoData;
1268 bool noCompatible = false;
1269 for ( ; dim * dir <= lastDim * dir; dim += dir)
1271 if ( !isAccessibleDim( dim ))
1273 if ( noCompatible ) { // the selected algo has no compatible ones
1274 anAvailable.clear();
1275 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1276 myAvailableHypData[dim][Algo].clear();
1277 algoByDim[ dim ] = 0;
1280 // get currently selected algo
1281 int algoIndex = currentHyp( dim, Algo );
1282 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1283 if ( curAlgo ) { // some algo selected
1284 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1287 // set new available algoritms
1288 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1289 HypothesisData* soleCompatible = 0;
1290 if ( anAvailable.count() == 1 )
1291 soleCompatible = myAvailableHypData[dim][Algo][0];
1292 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1293 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1294 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1295 noCompatible = anAvailable.isEmpty();
1297 // restore previously selected algo
1298 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1299 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1300 // select the sole compatible algo
1301 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1302 setCurrentHyp( dim, Algo, algoIndex );
1304 // remember current algo
1305 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1309 // set hypotheses corresponding to the found algoritms
1311 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1313 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1315 if ( !isAccessibleDim( dim ))
1317 for ( int type = MainHyp; type < NbHypTypes; type++ )
1319 myAvailableHypData[ dim ][ type ].clear();
1320 QStringList anAvailable, anExisting;
1322 HypothesisData* curAlgo = algoByDim[ dim ];
1323 int hypIndex = currentHyp( dim, type );
1325 SMESH::SMESH_Hypothesis_var curHyp;
1326 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1327 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1329 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1330 // try to find algo by selected hypothesis in order to keep it selected
1331 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1332 CORBA::String_var curHypType = curHyp->GetName();
1333 if ( !algoDeselectedByUser &&
1334 myObjHyps[ dim ][ type ].count() > 0 &&
1335 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1337 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1338 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1339 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1340 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1347 // get hyps compatible with curAlgo
1350 // check if a selected hyp is compatible with the curAlgo
1351 if ( !curHyp->_is_nil() ) {
1352 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1353 if ( !isCompatible( curAlgo, hypData, type ))
1354 curHyp = SMESH::SMESH_Hypothesis::_nil();
1356 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1357 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1359 // set list of hypotheses
1360 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1361 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1363 // set current existing hypothesis
1364 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1365 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1368 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1369 // none is yet selected => select the sole existing if it is not optional
1370 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1371 bool isOptional = true;
1372 if ( algoByDim[ dim ] &&
1373 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1377 setCurrentHyp( dim, type, hypIndex );
1382 //================================================================================
1384 * \brief Creates and selects hypothesis of hypotheses set
1385 * \param theSetName - The name of hypotheses set
1387 //================================================================================
1388 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1390 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1395 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1396 setCurrentHyp(dim, Algo, -1);
1397 setCurrentHyp(dim, AddHyp, -1);
1398 setCurrentHyp(dim, MainHyp, -1);
1401 myHypoSet->init(true); //algorithms
1403 myHypoSet->init(false); //hypotheses
1408 //================================================================================
1410 * \brief One step of hypothesis/algorithm list creation
1412 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1414 //================================================================================
1415 void SMESHGUI_MeshOp::processSet()
1418 if( !myHypoSet->more() )
1421 bool isAlgo = myHypoSet->isAlgo();
1422 QString aHypoTypeName = myHypoSet->current();
1423 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1430 int aDim = aHypData->Dim[0];
1431 // create or/and set
1434 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1437 QStringList anAvailable;
1438 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1439 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1440 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1442 setCurrentHyp( aDim, Algo, index );
1443 onAlgoSelected( index, aDim );
1448 bool mainHyp = true;
1449 QStringList anAvailable;
1450 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1451 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1452 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1456 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1459 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1465 //================================================================================
1467 * \brief Creates mesh
1468 * \param theMess - Output parameter intended for returning error message
1469 * \retval bool - TRUE if mesh is created, FALSE otherwise
1473 //================================================================================
1474 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1478 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1479 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1482 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1483 QStringList::Iterator it = aList.begin();
1484 for ( ; it!=aList.end(); it++)
1486 QString aGeomEntry = *it;
1487 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1488 GEOM::GEOM_Object_var aGeomVar =
1489 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1491 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1492 if ( aSMESHGen->_is_nil() )
1495 SUIT_OverrideCursor aWaitCursor;
1498 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1499 if ( aMeshVar->_is_nil() )
1501 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1503 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1505 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1506 if ( !isAccessibleDim( aDim )) continue;
1508 // assign hypotheses
1509 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1510 int aHypIndex = currentHyp( aDim, aHypType );
1511 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1512 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1513 if ( !aHypVar->_is_nil() )
1514 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1517 // find or create algorithm
1518 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1519 if ( !anAlgoVar->_is_nil() )
1520 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1527 //================================================================================
1529 * \brief Creates sub-mesh
1530 * \param theMess - Output parameter intended for returning error message
1531 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1535 //================================================================================
1536 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1540 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1541 if ( aSMESHGen->_is_nil() )
1545 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1546 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1547 SMESH::SMESH_Mesh_var aMeshVar =
1548 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1549 if (aMeshVar->_is_nil())
1552 // GEOM shape of the main mesh
1553 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1555 // Name for the new sub-mesh
1556 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1559 GEOM::GEOM_Object_var aGeomVar;
1561 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1562 if (aGEOMs.count() == 1)
1564 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1565 QString aGeomEntry = aGEOMs.first();
1566 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1567 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1569 else if (aGEOMs.count() > 1)
1571 // create a GEOM group
1572 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1573 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1574 if (!geomGen->_is_nil() && aStudy) {
1575 GEOM::GEOM_IGroupOperations_var op =
1576 geomGen->GetIGroupOperations(aStudy->StudyId());
1577 if (!op->_is_nil()) {
1578 // check and add all selected GEOM objects: they must be
1579 // a sub-shapes of the main GEOM and must be of one type
1581 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1582 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1583 aSeq->length(aGEOMs.count());
1584 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1585 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1586 QString aSubGeomEntry = (*aSubShapesIter);
1587 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1588 GEOM::GEOM_Object_var aSubGeomVar =
1589 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1590 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1592 aGroupType = aSubShapeType;
1594 if (aSubShapeType != aGroupType)
1595 aGroupType = TopAbs_SHAPE;
1597 aSeq[iSubSh] = aSubGeomVar;
1600 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1601 op->UnionList(aGroupVar, aSeq);
1604 aGeomVar = aGroupVar;
1606 // publish the GEOM group in study
1607 QString aNewGeomGroupName ("Auto_group_for_");
1608 aNewGeomGroupName += aName;
1609 SALOMEDS::SObject_var aNewGroupSO =
1610 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1611 aNewGeomGroupName.toLatin1().data(), mainGeom);
1618 if (aGeomVar->_is_nil())
1621 SUIT_OverrideCursor aWaitCursor;
1624 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1625 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1627 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1629 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1631 if ( !isAccessibleDim( aDim )) continue;
1633 // find or create algorithm
1634 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1635 if ( !anAlgoVar->_is_nil() )
1636 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1637 // assign hypotheses
1638 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1640 int aHypIndex = currentHyp( aDim, aHypType );
1641 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1643 SMESH::SMESH_Hypothesis_var aHypVar =
1644 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1645 if ( !aHypVar->_is_nil() )
1646 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1651 // deselect geometry: next submesh should be created on other subshape
1652 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1653 selectObject( _PTR(SObject)() );
1659 //================================================================================
1661 * \brief Gets current hypothesis or algorithms
1662 * \param theDim - dimension of hypothesis or algorithm
1663 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1664 * \retval int - current hypothesis or algorithms
1666 * Gets current hypothesis or algorithms
1668 //================================================================================
1669 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1671 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1674 //================================================================================
1676 * \brief Returns true if hypotheses of given dim can be assigned
1677 * \param theDim - hypotheses dimension
1678 * \retval bool - result
1680 //================================================================================
1681 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1683 return myDlg->isTabEnabled( theDim );
1686 //================================================================================
1688 * \brief Sets current hypothesis or algorithms
1689 * \param theDim - dimension of hypothesis or algorithm
1690 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1691 * \param theIndex - Index of hypothesis
1693 * Gets current hypothesis or algorithms
1695 //================================================================================
1696 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1697 const int theHypType,
1698 const int theIndex )
1700 myIgnoreAlgoSelection = true;
1701 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1702 myIgnoreAlgoSelection = false;
1705 //================================================================================
1707 * \brief Generates default and sets mesh/submesh name
1709 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1711 //================================================================================
1712 void SMESHGUI_MeshOp::setDefaultName() const
1716 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1718 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1719 _PTR(SObject) anObj;
1722 aResName = aPrefix + QString::number( i++ );
1723 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1727 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1728 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1729 aControl->setText( aResName );
1732 //================================================================================
1734 * \brief Gets algorithm or creates it if necessary
1735 * \param theDim - specifies dimension of returned hypotheses/algorifms
1736 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1738 * Gets algorithm or creates it if necessary
1740 //================================================================================
1741 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1743 SMESH::SMESH_Hypothesis_var anAlgoVar;
1745 // get type of the selected algo
1746 int aHypIndex = currentHyp( theDim, Algo );
1747 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1748 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1750 QString aHypName = dataList[ aHypIndex ]->TypeName;
1752 // get existing algoritms
1753 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1755 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1757 // look for an existing algo of such a type
1758 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1759 THypList::iterator anIter = aHypVarList.begin();
1760 for ( ; anIter != aHypVarList.end(); anIter++)
1762 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1763 CORBA::String_var aName = aHypVar->GetName();
1764 if ( !aHypVar->_is_nil() && aHypName == aName )
1766 anAlgoVar = aHypVar;
1771 if (anAlgoVar->_is_nil())
1773 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1776 QString aClientLibName = aHypData->ClientLibName;
1777 if (aClientLibName == "")
1779 // Call hypothesis creation server method (without GUI)
1780 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1784 // Get hypotheses creator client (GUI)
1786 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1787 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1791 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1793 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1795 QStringList tmpList;
1796 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1797 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1800 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1801 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1803 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1804 CORBA::String_var aName = aHypVar->GetName();
1805 if ( !aHypVar->_is_nil() && aHypName == aName )
1807 anAlgoVar = aHypVar;
1813 return anAlgoVar._retn();
1816 //================================================================================
1818 * \brief Reads parameters of edited mesh and assigns them to the dialog
1820 * Reads parameters of edited mesh and assigns them to the dialog (called when
1821 * mesh is edited only)
1823 //================================================================================
1824 void SMESHGUI_MeshOp::readMesh()
1826 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1827 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1831 if (myIsOnGeometry) {
1832 // Get name of mesh if current object is sub-mesh
1833 SMESH::SMESH_subMesh_var aSubMeshVar =
1834 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1835 if ( !aSubMeshVar->_is_nil() )
1837 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1838 if ( !aMeshVar->_is_nil() )
1840 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1841 QString aMeshName = name( aMeshSO );
1842 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1846 // Get name of geometry object
1847 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1848 if ( !aGeomVar->_is_nil() )
1850 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1851 QString aShapeName = name( aGeomSO );
1852 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1856 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1857 QStringList anExisting;
1858 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1859 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1862 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1863 // find algo index among available ones
1865 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1867 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1868 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1869 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1870 // if ( aHypIndex < 0 && algoData ) {
1871 // // assigned algo is incompatible with other algorithms
1872 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1873 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1876 setCurrentHyp( dim, Algo, aHypIndex );
1877 // set existing and available hypothesis according to the selected algo
1878 onAlgoSelected( aHypIndex, dim );
1882 bool hypWithoutAlgo = false;
1883 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1885 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1888 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1889 // find index of requered hypothesis among existing ones for this dimension and type
1891 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1892 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1893 myExistingHyps[ dim ][ hypType ] );
1894 if ( aHypIndex < 0 ) {
1895 // assigned hypothesis is incompatible with the algorithm
1896 if ( currentHyp( dim, Algo ) < 0 )
1897 { // none algo selected; it is edition for sure, of submesh maybe
1898 hypWithoutAlgo = true;
1899 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1900 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1901 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1905 setCurrentHyp( dim, hypType, aHypIndex );
1908 // make available other hyps of same type as one without algo
1909 if ( hypWithoutAlgo )
1910 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1913 //================================================================================
1915 * \brief Gets name of object
1916 * \param theSO - SObject
1917 * \retval QString - name of object
1919 * Gets name of object
1921 //================================================================================
1922 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1927 _PTR(GenericAttribute) anAttr;
1928 _PTR(AttributeName) aNameAttr;
1929 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1932 aResName = aNameAttr->Value().c_str();
1938 //================================================================================
1940 * \brief Finds hypothesis in input list
1941 * \param theHyp - hypothesis to be found
1942 * \param theHypList - input list of hypotheses
1943 * \retval int - index of hypothesis or -1 if it is not found
1945 * Finds position of hypothesis in input list
1947 //================================================================================
1948 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1949 const THypList& theHypList ) const
1952 if ( !theHyp->_is_nil() )
1955 THypList::const_iterator anIter = theHypList.begin();
1956 for ( ; anIter != theHypList.end(); ++ anIter)
1958 if ( theHyp->_is_equivalent( (*anIter).first ) )
1969 //================================================================================
1971 * \brief Edits mesh or sub-mesh
1972 * \param theMess - Output parameter intended for returning error message
1973 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1975 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1977 //================================================================================
1978 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1982 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1983 if ( aSMESHGen->_is_nil() )
1986 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1987 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1991 SUIT_OverrideCursor aWaitCursor;
1994 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1995 SMESH::SetName( pObj, aName );
1996 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1998 // First, remove old algos in order to avoid messages on algorithm hiding
1999 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2001 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2003 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2004 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2005 if ( anAlgoVar->_is_nil() || // no new algo selected or
2006 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2008 // remove old algorithm
2009 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2010 myObjHyps[ dim ][ Algo ].clear();
2015 // Assign new algorithms and hypotheses
2016 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2018 if ( !isAccessibleDim( dim )) continue;
2020 // find or create algorithm
2021 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2023 // assign new algorithm
2024 if ( !anAlgoVar->_is_nil() && // some algo selected and
2025 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2027 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2028 CORBA::Object_var anObject = aSObject->GetObject();
2029 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2030 bool isMesh = !aMeshVar->_is_nil();
2032 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2034 SMESH::SMESH_subMesh_var aVar =
2035 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2036 if ( !aVar->_is_nil() )
2037 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2039 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2042 // assign hypotheses
2043 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2045 int aNewHypIndex = currentHyp( dim, hypType );
2046 int anOldHypIndex = -1;
2048 // remove old hypotheses
2049 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2051 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2052 myExistingHyps[ dim ][ hypType ] );
2053 if ( aNewHypIndex != anOldHypIndex || // different hyps
2054 anOldHypIndex == -1 ) // hyps of different algos
2056 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2057 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2058 myObjHyps[ dim ][ hypType ].clear();
2062 // assign new hypotheses
2063 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2065 SMESH::SMESH_Mesh_var aMeshVar =
2066 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2067 bool isMesh = !aMeshVar->_is_nil();
2070 SMESH::AddHypothesisOnMesh
2071 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2075 SMESH::SMESH_subMesh_var aVar =
2076 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2077 if ( !aVar->_is_nil() )
2078 SMESH::AddHypothesisOnSubMesh
2079 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2082 // reread all hypotheses of mesh if necessary
2083 QStringList anExisting;
2084 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2091 //================================================================================
2093 * \brief Verifies whether given operator is valid for this one
2094 * \param theOtherOp - other operation
2095 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2097 * method redefined from base class verifies whether given operator is valid for
2098 * this one (i.e. can be started "above" this operator). In current implementation method
2099 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2102 //================================================================================
2103 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2105 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2108 //================================================================================
2110 * \brief SLOT. Is called when the user selects a way of geometry selection
2111 * \param theByMesh - true if the user wants to find geometry by mesh element
2113 //================================================================================
2115 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2118 if ( !myShapeByMeshOp ) {
2119 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2120 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2121 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2122 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2123 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2125 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2126 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2127 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2128 SMESH::SMESH_Mesh_var aMeshVar =
2129 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2130 if ( !aMeshVar->_is_nil() ) {
2131 myDlg->hide(); // stop processing selection
2132 myShapeByMeshOp->setModule( getSMESHGUI() );
2133 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2134 myShapeByMeshOp->SetMesh( aMeshVar );
2135 myShapeByMeshOp->start();
2141 //================================================================================
2143 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2145 //================================================================================
2147 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2149 if ( myShapeByMeshOp == op ) {
2150 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2152 // Select a found geometry object
2153 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2154 if ( !aGeomVar->_is_nil() )
2156 QString ID = aGeomVar->GetStudyEntry();
2157 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2158 selectObject( aGeomSO );
2165 //================================================================================
2167 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2169 //================================================================================
2171 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2173 if ( myShapeByMeshOp == op && myDlg ) {
2178 //================================================================================
2180 * \brief Selects a SObject
2181 * \param theSObj - the SObject to select
2183 //================================================================================
2185 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2187 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2188 SALOME_ListIO anIOList;
2190 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2191 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2192 anIOList.Append( anIO );
2194 sm->setSelectedObjects( anIOList, false );