1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_MeshDlg.h"
30 #include "SMESHGUI_ShapeByMeshDlg.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_NumberFilter.hxx>
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
44 #include <GEOMImpl_Types.hxx>
46 // SALOME GUI includes
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <LightApp_UpdateFlags.h>
52 #include <SUIT_MessageBox.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_Session.h>
55 #include <SALOME_InteractiveObject.hxx>
56 #include <SALOME_ListIO.hxx>
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SComponent.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDS_Study.hxx>
62 #include <SALOMEDS_wrap.hxx>
65 #include <QStringList>
67 #include <QApplication>
71 #include <TopoDS_Shape.hxx>
72 #include <TopoDS_Shell.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <BRep_Tool.hxx>
77 #include <SALOMEconfig.h>
78 #include CORBA_CLIENT_HEADER(SMESH_Gen)
80 //================================================================================
83 * \param theToCreate - if this parameter is true then operation is used for creation,
84 * for editing otherwise
86 * Initialize operation
88 //================================================================================
89 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
90 : SMESHGUI_SelectionOp(),
91 myToCreate( theToCreate ),
92 myIsMesh( theIsMesh ),
97 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
98 GeometryGUI::InitGeomGen();
99 myIsOnGeometry = true;
103 //================================================================================
107 //================================================================================
108 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
114 //================================================================================
116 * \brief Gets dialog of this operation
117 * \retval LightApp_Dialog* - pointer to dialog of this operation
119 //================================================================================
120 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
125 //================================================================================
127 * \brief Creates or edits mesh
128 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
130 * Virtual slot redefined from the base class called when "Apply" button is clicked
131 * creates or edits mesh
133 //================================================================================
134 bool SMESHGUI_MeshOp::onApply()
140 if ( !isValid( aMess ) )
144 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
148 bool aResult = false;
152 QStringList anEntryList;
153 if ( myToCreate && myIsMesh )
154 aResult = createMesh( aMess, anEntryList );
155 if ( myToCreate && !myIsMesh )
156 aResult = createSubMesh( aMess, anEntryList );
157 else if ( !myToCreate )
158 aResult = editMeshOrSubMesh( aMess );
161 SMESHGUI::Modified();
162 update( UF_ObjBrowser | UF_Model );
163 if( LightApp_Application* anApp =
164 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
165 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
168 catch ( const SALOME::SALOME_Exception& S_ex )
170 SalomeApp_Tools::QtCatchCorbaException( S_ex );
186 aMess = tr( "SMESH_OPERATION_FAILED" );
187 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
193 //================================================================================
195 * \brief Creates dialog if necessary and shows it
197 * Virtual method redefined from base class called when operation is started creates
198 * dialog if necessary and shows it, activates selection
200 //================================================================================
201 void SMESHGUI_MeshOp::startOperation()
205 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
206 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
208 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
209 this, SLOT( onCreateHyp( const int, const int ) ) );
210 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
211 this, SLOT( onEditHyp( const int, const int ) ) );
212 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
213 this, SLOT( onAlgoSelected( const int ) ) );
215 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
216 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
219 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
220 else myHelpFileName = "constructing_submeshes_page.html";
223 myHelpFileName = "editing_meshes_page.html";
226 SMESHGUI_SelectionOp::startOperation();
227 // iterate through dimensions and get available algoritms, set them to the dialog
228 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
229 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
231 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
233 // clear available hypotheses
234 aTab->setAvailableHyps( MainHyp, hypList );
235 aTab->setAvailableHyps( AddHyp, hypList );
236 aTab->setExistingHyps( MainHyp, hypList );
237 aTab->setExistingHyps( AddHyp, hypList );
238 myExistingHyps[ i ][ MainHyp ].clear();
239 myExistingHyps[ i ][ AddHyp ].clear();
241 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
242 aTab->setAvailableHyps( Algo, hypList );
247 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
250 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
252 myDlg->setCurrentTab( SMESH::DIM_3D );
254 QStringList TypeMeshList;
255 createMeshTypeList( TypeMeshList );
256 setAvailableMeshType( TypeMeshList );
259 myDlg->setGeomPopupEnabled(false);
262 myIgnoreAlgoSelection = false;
263 myHasConcurrentSubBefore = false;
265 myObjectToSelect.clear();
268 //=================================================================================
270 * \brief Selects a recently created mesh or sub-mesh if necessary
272 * Virtual method redefined from base class called when operation is commited
273 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
274 * selection when the custom selection filters are removed.
276 //=================================================================================
277 void SMESHGUI_MeshOp::commitOperation()
279 SMESHGUI_SelectionOp::commitOperation();
281 if ( !myObjectToSelect.isEmpty() ) {
282 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
283 SUIT_DataOwnerPtrList aList;
284 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
285 aSelectionMgr->setSelected( aList );
290 //================================================================================
292 * \brief Creates selection filter
293 * \param theId - identifier of current selection widget
294 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
296 * Creates selection filter in accordance with identifier of current selection widget
298 //================================================================================
299 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
301 if ( theId == SMESHGUI_MeshDlg::Geom )
303 // TColStd_MapOfInteger allTypesMap;
304 // for ( int i = 0; i < 10; i++ )
305 // allTypesMap.Add( i );
306 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
307 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
309 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
310 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
311 else if ( theId == SMESHGUI_MeshDlg::Mesh )
312 return new SMESH_TypeFilter( SMESH::MESH );
317 //================================================================================
319 * \brief check if selected shape is a sub-shape of the shape to mesh
320 * \retval bool - check result
322 //================================================================================
323 bool SMESHGUI_MeshOp::isSubshapeOk() const
325 if ( !myToCreate || myIsMesh ) // not submesh creation
329 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
330 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
331 if (!pMesh) return false;
333 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
334 if (mesh->_is_nil()) return false;
336 // main shape of the mesh
337 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
338 if (mainGeom->_is_nil()) return false;
342 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
344 if (aGEOMs.count() > 0) {
345 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
346 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
347 if (geomGen->_is_nil() || !aStudy) return false;
349 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
350 if (op->_is_nil()) return false;
352 // check all selected shapes
353 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
354 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
355 QString aSubGeomEntry = (*aSubShapesIter);
356 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
357 if (!pSubGeom) return false;
359 GEOM::GEOM_Object_var aSubGeomVar =
360 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
361 if (aSubGeomVar->_is_nil()) return false;
363 // skl for NPAL14695 - implementation of searching of mainObj
364 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
365 mainObj already exists! */
367 if (mainObj->_is_nil())
369 CORBA::String_var entry1 = mainObj->GetEntry();
370 CORBA::String_var entry2 = mainGeom->GetEntry();
371 if (std::string( entry1.in() ) == entry2.in() )
373 mainObj = op->GetMainShape(mainObj);
381 //================================================================================
383 * \brief Return name of the algorithm that does not support submeshes and makes
384 * submesh creation useless
385 * \retval char* - string is to be deleted!!!
387 //================================================================================
388 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
390 if ( myToCreate && !myIsMesh ) {
392 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
393 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
394 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
397 QStringList algoNames;
399 existingHyps(3, Algo, pMesh, algoNames, algoList);
400 if (!algoList.empty()) {
401 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
403 algo->InputTypes.empty() && // builds all dimensions it-self
404 !algo->IsSupportSubmeshes )
405 return CORBA::string_dup( algoNames[0].toLatin1().data() );
408 // GEOM::GEOM_Object_var geom;
409 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
410 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
412 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
413 existingHyps(2, Algo, pMesh, algoNames, algoList);
414 if (!algoList.empty()) {
415 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
417 algo->InputTypes.empty() && // builds all dimensions it-self
418 !algo->IsSupportSubmeshes )
419 return CORBA::string_dup( algoNames[0].toLatin1().data() );
427 //================================================================================
429 * \brief find an existing submesh by the selected shape
430 * \retval _PTR(SObject) - the found submesh SObject
432 //================================================================================
433 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
435 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
436 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
437 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
438 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
439 if ( pMesh && pGeom ) {
440 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
441 if ( !geom->_is_nil() ) {
443 switch ( geom->GetShapeType() ) {
444 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
445 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
446 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
447 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
448 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
449 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
450 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
453 _PTR(GenericAttribute) anAttr;
454 _PTR(SObject) aSubmeshRoot;
455 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
456 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
458 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
459 for ( ; smIter->More(); smIter->Next() )
461 _PTR(SObject) aSmObj = smIter->Value();
462 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
464 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
465 for ( ; anIter1->More(); anIter1->Next()) {
466 _PTR(SObject) pGeom2 = anIter1->Value();
467 if ( pGeom2->ReferencedObject( pGeom2 ) &&
468 pGeom2->GetID() == pGeom->GetID() )
475 return _PTR(SObject)();
478 //================================================================================
480 * \brief Updates dialog's look and feel
482 * Virtual method redefined from the base class updates dialog's look and feel
484 //================================================================================
485 void SMESHGUI_MeshOp::selectionDone()
487 if (!dlg()->isVisible() || !myDlg->isEnabled())
490 SMESHGUI_SelectionOp::selectionDone();
494 myIsOnGeometry = true;
496 //Check geometry for mesh
497 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
498 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
501 SMESH::SMESH_Mesh_var aMeshVar =
502 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
503 if (!aMeshVar->_is_nil()) {
504 if (!myToCreate && !aMeshVar->HasShapeToMesh())
505 myIsOnGeometry = false;
511 // Enable tabs according to shape dimension
516 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
517 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
519 if (aGEOMs.count() > 0) {
520 // one or more GEOM shape selected
521 aSeq->length(aGEOMs.count());
522 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
524 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
525 QString aSubGeomEntry = (*aSubShapesIter);
526 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
527 GEOM::GEOM_Object_var aSubGeomVar =
528 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
529 aSeq[iSubSh] = aSubGeomVar;
532 // get geometry by selected sub-mesh
533 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
534 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
535 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
536 if (!aGeomVar->_is_nil()) {
542 if (aSeq->length() > 0) {
544 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
545 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
546 switch ( aGeomVar->GetShapeType() ) {
547 case GEOM::SOLID: shapeDim = 3; break;
549 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
551 // TopoDS_Shape aShape;
552 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
553 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
556 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
558 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
559 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
563 if (GEOMBase::GetShape(aGeomVar, aShape))
565 TopExp_Explorer exp (aShape, TopAbs_SOLID);
569 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
570 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
573 // for (; exp.More() && shapeDim == 2; exp.Next()) {
574 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
578 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
579 shapeDim = qMax(2, shapeDim);
580 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
581 shapeDim = qMax(1, shapeDim);
582 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
583 shapeDim = qMax(0, shapeDim);
591 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
592 // reset algos before disabling tabs (0020138)
593 onAlgoSelected(-1, i);
595 myDlg->setMaxHypoDim( shapeDim );
596 myMaxShapeDim = shapeDim;
597 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
599 if (!myToCreate) // edition: read hypotheses
603 SMESH::SMESH_subMesh_var submeshVar =
604 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
605 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
606 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
607 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
608 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
609 myDlg->updateGeometry();
612 myIsMesh = submeshVar->_is_nil();
617 else if ( !myIsMesh ) // submesh creation
619 // if a submesh on the selected shape already exist, pass to submesh edition mode
620 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
621 SMESH::SMESH_subMesh_var sm =
622 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
623 bool editSubmesh = ( !sm->_is_nil() &&
624 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
625 tr( "EDIT_SUBMESH_QUESTION"),
626 SUIT_MessageBox::Yes |
628 SUIT_MessageBox::No )
629 == SUIT_MessageBox::Yes );
632 selectionMgr()->clearFilters();
633 selectObject( pSubmesh );
634 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
639 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
640 selectObject( _PTR(SObject)() );
645 // discard selected mesh if submesh creation not allowed because of
646 // a global algorithm that does not support submeshes
647 if ( char* algoName = isSubmeshIgnored() ) {
648 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
649 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
650 CORBA::string_free( algoName );
651 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
652 selectObject( _PTR(SObject)() );
657 // enable/disable popup for choice of geom selection way
659 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
660 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
661 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
662 if ( !mesh->_is_nil() ) {
663 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
664 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
665 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
666 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
667 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
668 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
671 myDlg->setGeomPopupEnabled( enable );
674 else { // no geometry defined
675 myDlg->enableTab( SMESH::DIM_3D );
677 availableHyps( SMESH::DIM_3D, Algo, hypList,
678 myAvailableHypData[SMESH::DIM_3D][Algo]);
680 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
681 aTab->setAvailableHyps( Algo, hypList );
682 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
683 myDlg->disableTab(i);
686 //Hide labels and fields (Mesh and Geometry)
687 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
688 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
692 int curIndex = myDlg->currentMeshType( );
693 QStringList TypeMeshList;
694 createMeshTypeList( TypeMeshList );
695 setAvailableMeshType( TypeMeshList );
696 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
697 myDlg->setCurrentMeshType( curIndex );
698 setFilteredAlgoData( myMaxShapeDim, curIndex);
700 catch ( const SALOME::SALOME_Exception& S_ex )
702 SalomeApp_Tools::QtCatchCorbaException( S_ex );
709 //================================================================================
711 * \brief Verifies validity of input data
712 * \param theMess - Output parameter intended for returning error message
713 * \retval bool - TRUE if input data is valid, false otherwise
715 * Verifies validity of input data. This method is called when "Apply" or "OK" button
716 * is pressed before mesh creation or editing.
718 //================================================================================
719 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
721 // Selected object to be edited
722 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
724 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
729 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
730 if ( aMeshName.isEmpty() )
732 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
736 /* // Imported mesh, if create sub-mesh or edit mesh
737 if ( !myToCreate || ( myToCreate && !myIsMesh ))
739 QString aMeshEntry = myDlg->selectedObject
740 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
741 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
742 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
743 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
744 theMess = tr( "IMPORTED_MESH" );
753 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
754 if ( aGeomEntry.isEmpty() )
756 theMess = tr( myIsMesh ?
757 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
758 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
762 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
763 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
770 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
771 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
773 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
778 if ( !myIsMesh ) // i.e sub-mesh creation,
780 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
781 if ( aMeshEntry == "" )
783 theMess = tr( "MESH_IS_NOT_DEFINED" );
786 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
787 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
789 theMess = tr( "MESH_IS_NULL" );
792 if ( !isSubshapeOk() )
794 theMess = tr( "INVALID_SUBSHAPE" );
803 //================================================================================
805 * \brief check compatibility of the algorithm and another algorithm or hypothesis
806 * \param theAlgoData - algorithm data
807 * \param theHypData - hypothesis data
808 * \param theHypType - hypothesis type
809 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
810 * \retval bool - check result
812 //================================================================================
813 static bool isCompatible(const HypothesisData* theAlgoData,
814 const HypothesisData* theHypData,
815 const int theHypType)
820 if ( theHypType == SMESHGUI_MeshOp::Algo )
821 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
824 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
827 //================================================================================
829 * \brief Gets available hypotheses or algorithms
830 * \param theDim - specifies dimension of returned hypotheses/algorifms
831 * \param theHypType - specifies whether algorims or hypotheses or additional ones
832 * are retrieved (possible values are in HypType enumeration)
833 * \param theHyps - Output list of hypotheses' names
834 * \param theAlgoData - to select hypos able to be used by this algo (optional)
836 * Gets available hypotheses or algorithm in accordance with input parameters
838 //================================================================================
839 void SMESHGUI_MeshOp::availableHyps( const int theDim,
840 const int theHypType,
841 QStringList& theHyps,
842 THypDataList& theDataList,
843 HypothesisData* theAlgoData ) const
847 bool isAlgo = ( theHypType == Algo );
848 bool isAux = ( theHypType == AddHyp );
849 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
851 QStringList::const_iterator anIter;
852 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
854 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
855 if ( isCompatible ( theAlgoData, aData, theHypType )) {
856 theDataList.append( aData );
857 theHyps.append( aData->Label );
862 //================================================================================
864 * \brief Gets existing hypotheses or algorithms
865 * \param theDim - specifies dimension of returned hypotheses/algorifms
866 * \param theHypType - specifies whether algorims or hypotheses or additional ones
867 * are retrieved (possible values are in HypType enumeration)
868 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
869 * \param theHyps - output list of names.
870 * \param theHypVars - output list of variables.
871 * \param theAlgoData - to select hypos able to be used by this algo (optional)
873 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
876 //================================================================================
877 void SMESHGUI_MeshOp::existingHyps( const int theDim,
878 const int theHypType,
879 _PTR(SObject) theFather,
880 QStringList& theHyps,
881 THypList& theHypList,
882 HypothesisData* theAlgoData)
884 // Clear hypoheses list
891 const bool isAux = ( theHypType == AddHyp );
893 _PTR(SObject) aHypRoot;
894 _PTR(GenericAttribute) anAttr;
895 _PTR(AttributeName) aName;
896 _PTR(AttributeIOR) anIOR;
898 bool isMesh = !_CAST( SComponent, theFather );
901 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
903 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
905 if ( theFather->FindSubObject( aPart, aHypRoot ) )
907 _PTR(ChildIterator) anIter =
908 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
909 for ( ; anIter->More(); anIter->Next() )
911 _PTR(SObject) anObj = anIter->Value();
912 if ( isMesh ) // i.e. mesh or submesh
914 _PTR(SObject) aRefObj;
915 if ( anObj->ReferencedObject( aRefObj ) )
920 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
923 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
924 if ( !CORBA::is_nil( aVar ) )
926 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
927 if ( !aHypVar->_is_nil() )
929 CORBA::String_var hypType = aHypVar->GetName();
930 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
931 if ( !aData) continue;
932 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
933 ( isCompatible ( theAlgoData, aData, theHypType )) &&
934 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ))
936 std::string aHypName = aName->Value();
937 theHyps.append( aHypName.c_str() );
938 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
947 //================================================================================
949 * \brief If create or edit a submesh, return a hypothesis holding parameters used
950 * to mesh a sub-shape
951 * \param aHypType - The hypothesis type name
952 * \param aServerLib - Server library name
953 * \param hypData - The structure holding the hypothesis type etc.
954 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
956 //================================================================================
957 SMESH::SMESH_Hypothesis_var
958 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
959 const QString& aServerLib ) const
961 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
962 return SMESH::SMESH_Hypothesis::_nil();
964 const int nbColonsInMeshEntry = 3;
965 bool isSubMesh = myToCreate ?
967 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
969 // get mesh and geom object
970 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
971 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
976 anEntry = myDlg->selectedObject
977 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
978 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
980 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
981 if ( myToCreate ) // mesh and geom may be selected
983 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
984 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
985 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
986 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
988 else // edition: sub-mesh may be selected
990 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
991 if ( !sm->_is_nil() ) {
992 aMeshVar = sm->GetFather();
993 aGeomVar = sm->GetSubShape();
1000 if ( !myToCreate ) // mesh to edit can be selected
1002 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1003 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1005 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1006 if ( !aMeshVar->_is_nil() )
1007 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1010 if ( aGeomVar->_is_nil() ) {
1011 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1012 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1014 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1019 SMESH::SMESH_Hypothesis_var hyp =
1020 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1021 aServerLib.toLatin1().data(),
1024 /*byMesh = */isSubMesh);
1025 if ( hyp->_is_nil() && isSubMesh )
1026 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1027 aServerLib.toLatin1().data(),
1030 /*byMesh = */false);
1034 //================================================================================
1036 * \Brief Returns tab dimention
1037 * \param tab - the tab in the dlg
1038 * \param dlg - my dialogue
1039 * \retval int - dimention
1041 //================================================================================
1042 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1045 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1046 if (tab == dlg->tab(i))
1051 //================================================================================
1053 * \brief Create hypothesis
1054 * \param theHypType - hypothesis category (main or additional)
1055 * \param theIndex - index of type of hypothesis to be cerated
1057 * Specifies dimension of hypothesis to be created (using sender() method),
1058 * specifies its type and calls method for hypothesis creation
1060 //================================================================================
1061 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1063 // Specifies dimension of hypothesis to be created
1064 int aDim = getTabDim( sender(), myDlg );
1068 // Specifies type of hypothesis to be created
1069 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1070 if (theIndex < 0 || theIndex >= dataList.count())
1072 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1074 // Create hypothesis
1075 createHypothesis(aDim, theHypType, aHypTypeName);
1080 QString GetUniqueName (const QStringList& theHypNames,
1081 const QString& theName,
1082 size_t theIteration = 1)
1084 QString aName = theName + "_" + QString::number( theIteration );
1085 if ( theHypNames.contains( aName ) )
1086 return GetUniqueName( theHypNames, theName, ++theIteration );
1091 //================================================================================
1093 * Create hypothesis and update dialog.
1094 * \param theDim - dimension of hypothesis to be created
1095 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1096 * \param theTypeName - specifies hypothesis to be created
1098 //================================================================================
1099 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1101 const QString& theTypeName)
1103 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1109 QStringList aHypNames;
1110 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1111 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1112 const TType2HypList& aType2HypList = aDimIter.value();
1113 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1114 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1115 const THypList& aHypList = aTypeIter.value();
1116 THypList::const_iterator anIter = aHypList.begin();
1117 for ( ; anIter != aHypList.end(); anIter++) {
1118 const THypItem& aHypItem = *anIter;
1119 const QString& aHypName = aHypItem.second;
1120 aHypNames.append(aHypName);
1124 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1127 bool dialog = false;
1129 QString aClientLibName = aData->ClientLibName;
1130 if (aClientLibName == "") {
1131 // Call hypothesis creation server method (without GUI)
1132 SMESH::SMESH_Hypothesis_var aHyp =
1133 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1137 // Get hypotheses creator client (GUI)
1138 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1140 // Create hypothesis
1142 // Get parameters appropriate to initialize a new hypothesis
1143 SMESH::SMESH_Hypothesis_var initParamHyp =
1144 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1146 removeCustomFilters(); // Issue 0020170
1148 // Get Entry of the Geom object
1149 QString aGeomEntry = "";
1150 QString aMeshEntry = "";
1151 QString anObjEntry = "";
1152 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1153 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1154 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1156 if ( myToCreate && myIsMesh )
1157 aMeshEntry = aGeomEntry;
1159 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1160 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1161 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1162 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1165 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1166 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1168 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1169 if ( !aGeomVar->_is_nil() )
1171 aGeomEntry = aGeomVar->GetStudyEntry();
1173 aMeshEntry = aGeomEntry;
1177 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1178 // take geometry from submesh being created
1179 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1181 // if current object is sub-mesh
1182 SMESH::SMESH_subMesh_var aSubMeshVar =
1183 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1184 if ( !aSubMeshVar->_is_nil() ) {
1185 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1186 if ( !aMeshVar->_is_nil() ) {
1187 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1188 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1189 if ( !aGeomVar->_is_nil() )
1190 aMeshEntry = aGeomVar->GetStudyEntry();
1196 aCreator->setShapeEntry( aGeomEntry );
1197 if ( aMeshEntry != "" )
1198 aCreator->setMainShapeEntry( aMeshEntry );
1199 myDlg->setEnabled( false );
1200 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1204 SMESH::SMESH_Hypothesis_var aHyp =
1205 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1214 //================================================================================
1216 * Necessary steps after hypothesis creation
1217 * \param result - creation result:
1220 * 2 = additional value meaning that slot is called not from dialog box
1222 //================================================================================
1223 void SMESHGUI_MeshOp::onHypoCreated( int result )
1227 int obj = myDlg->getActiveObject();
1228 onActivateObject( obj ); // Issue 0020170. Restore filters
1229 myDlg->setEnabled( true );
1232 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1234 int nbHyp = myExistingHyps[myDim][myType].count();
1235 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1236 QStringList aNewHyps;
1237 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1238 if (aNewHyps.count() > nbHyp)
1240 for (int i = nbHyp; i < aNewHyps.count(); i++)
1241 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1244 if( result!=2 && myHypoSet )
1248 //================================================================================
1250 * \brief Calls plugin methods for hypothesis editing
1251 * \param theHypType - specifies whether main hypothesis or additional one
1253 * \param theIndex - index of existing hypothesis
1255 * Calls plugin methods for hypothesis editing
1257 //================================================================================
1258 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1260 // Speicfies dimension of hypothesis to be created
1261 int aDim = getTabDim( sender(), myDlg );
1265 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1266 if ( theIndex < 0 || theIndex >= aList.count() )
1268 const THypItem& aHypItem = aList[ theIndex ];
1269 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1270 if ( aHyp->_is_nil() )
1273 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1276 // Get initial parameters
1277 SMESH::SMESH_Hypothesis_var initParamHyp =
1278 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1279 aCreator->setInitParamsHypothesis( initParamHyp );
1281 // Get Entry of the Geom object
1282 QString aGeomEntry = "";
1283 QString aMeshEntry = "";
1284 QString anObjEntry = "";
1285 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1286 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1287 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1289 if ( myToCreate && myIsMesh )
1290 aMeshEntry = aGeomEntry;
1292 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1293 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1294 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1295 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1298 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1299 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1301 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1302 if ( !aGeomVar->_is_nil() )
1304 aGeomEntry = aGeomVar->GetStudyEntry();
1306 aMeshEntry = aGeomEntry;
1310 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1311 // take geometry from submesh being created
1312 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1314 // if current object is sub-mesh
1315 SMESH::SMESH_subMesh_var aSubMeshVar =
1316 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1317 if ( !aSubMeshVar->_is_nil() ) {
1318 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1319 if ( !aMeshVar->_is_nil() ) {
1320 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1321 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1322 if ( !aGeomVar->_is_nil() )
1323 aMeshEntry = aGeomVar->GetStudyEntry();
1329 aCreator->setShapeEntry( aGeomEntry );
1330 if ( aMeshEntry != "" )
1331 aCreator->setMainShapeEntry( aMeshEntry );
1332 removeCustomFilters(); // Issue 0020170
1333 myDlg->setEnabled( false );
1334 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1338 //================================================================================
1340 * Necessary steps after hypothesis edition
1341 * \param result - creation result:
1345 //================================================================================
1346 void SMESHGUI_MeshOp::onHypoEdited( int result )
1348 int obj = myDlg->getActiveObject();
1349 onActivateObject( obj ); // Issue 0020170. Restore filters
1350 myDlg->setEnabled( true );
1353 //================================================================================
1355 * \brief access to hypothesis data
1356 * \param theDim - hyp dimension
1357 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1358 * \param theIndex - index in the list
1359 * \retval HypothesisData* - result data, may be 0
1361 //================================================================================
1362 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1363 const int theHypType,
1366 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1367 theHypType > -1 && theHypType < NbHypTypes &&
1368 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1369 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1373 //================================================================================
1375 * \brief Set available algos and hypos according to the selected algorithm
1376 * \param theIndex - algorithm index
1378 //================================================================================
1379 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1382 if ( myIgnoreAlgoSelection )
1385 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1389 // find highest available dimension, all algos of this dimension are available for choice
1391 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1392 if (isAccessibleDim( i ))
1397 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1399 // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
1400 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1401 HypothesisData* algoByDim[4];
1402 algoByDim[ aDim ] = algoData;
1404 QStringList anAvailable;
1406 // check that tab enabled of one less dimension
1407 if ( aDim > SMESH::DIM_0D )
1409 if ( isAccessibleDim( aDim - 1 ) )
1411 if (( myDlg->currentMeshType() != MT_ANY ) &&
1412 ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1413 for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1414 if ( isAccessibleDim( i ) ) {
1415 myDlg->disableTab( i );
1416 setCurrentHyp(i, Algo, -1);
1419 else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1421 myDlg->enableTab( aDim - 1 );
1425 // check that algorithms of other dimentions are compatible with
1427 if ( !algoData ) { // all algos becomes available
1428 if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
1429 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1431 anAvailable.clear();
1432 for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1433 HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1434 anAvailable.append( aCurAlgo->Label );
1437 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1439 // 2 loops: backward and forward from algo dimension
1440 for ( int forward = false; forward <= true; ++forward )
1442 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1444 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1446 HypothesisData* prevAlgo = algoData;
1447 bool noCompatible = false;
1448 for ( ; dim * dir <= lastDim * dir; dim += dir)
1450 if ( !isAccessibleDim( dim ))
1452 if ( noCompatible ) { // the selected algo has no compatible ones
1453 anAvailable.clear();
1454 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1455 myAvailableHypData[dim][Algo].clear();
1456 algoByDim[ dim ] = 0;
1459 // get currently selected algo
1460 int algoIndex = currentHyp( dim, Algo );
1461 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1462 if ( curAlgo ) { // some algo selected
1463 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1466 // set new available algoritms
1467 if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1468 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1470 anAvailable.clear();
1471 myAvailableHypData[dim][Algo].clear();
1472 for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1473 HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1474 if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1475 anAvailable.append( aCurAlgo->Label );
1476 myAvailableHypData[dim][Algo].append( aCurAlgo );
1480 HypothesisData* soleCompatible = 0;
1481 if ( anAvailable.count() == 1 )
1482 soleCompatible = myAvailableHypData[dim][Algo][0];
1483 if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1484 if (myDlg->currentMeshType() == MT_ANY)
1485 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1487 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1488 noCompatible = anAvailable.isEmpty();
1490 // restore previously selected algo
1491 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1492 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1493 // select the sole compatible algo
1494 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1495 setCurrentHyp( dim, Algo, algoIndex);
1497 // remember current algo
1498 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1502 // set hypotheses corresponding to the found algoritms
1504 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1506 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1508 if ( !isAccessibleDim( dim ))
1510 for ( int type = MainHyp; type < NbHypTypes; type++ )
1512 myAvailableHypData[ dim ][ type ].clear();
1513 QStringList anAvailable, anExisting;
1515 HypothesisData* curAlgo = algoByDim[ dim ];
1516 int hypIndex = currentHyp( dim, type );
1518 SMESH::SMESH_Hypothesis_var curHyp;
1519 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1520 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1522 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1523 // try to find algo by selected hypothesis in order to keep it selected
1524 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1525 CORBA::String_var curHypType = curHyp->GetName();
1526 if ( !algoDeselectedByUser &&
1527 myObjHyps[ dim ][ type ].count() > 0 &&
1528 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1530 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1531 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1532 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1533 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1540 // get hyps compatible with curAlgo
1541 bool defaulHypAvlbl = false;
1544 // check if a selected hyp is compatible with the curAlgo
1545 if ( !curHyp->_is_nil() ) {
1546 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1547 if ( !isCompatible( curAlgo, hypData, type ))
1548 curHyp = SMESH::SMESH_Hypothesis::_nil();
1550 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1551 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1552 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1554 // set list of hypotheses
1555 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1556 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1558 // set current existing hypothesis
1559 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1560 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1563 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1564 // none is yet selected => select the sole existing if it is not optional
1565 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1566 bool isOptional = true;
1567 if ( algoByDim[ dim ] &&
1568 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1572 setCurrentHyp( dim, type, hypIndex );
1577 //================================================================================
1579 * \brief Creates and selects hypothesis of hypotheses set
1580 * \param theSetName - The name of hypotheses set
1582 //================================================================================
1583 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1585 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1590 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1591 setCurrentHyp(dim, Algo, -1);
1592 setCurrentHyp(dim, AddHyp, -1);
1593 setCurrentHyp(dim, MainHyp, -1);
1596 myHypoSet->init(true); //algorithms
1598 myHypoSet->init(false); //hypotheses
1603 //================================================================================
1605 * \brief One step of hypothesis/algorithm list creation
1607 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1609 //================================================================================
1610 void SMESHGUI_MeshOp::processSet()
1613 if( !myHypoSet->more() )
1616 bool isAlgo = myHypoSet->isAlgo();
1617 QString aHypoTypeName = myHypoSet->current();
1618 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1625 int aDim = aHypData->Dim[0];
1626 // create or/and set
1629 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1632 QStringList anAvailable;
1633 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1634 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1635 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1637 setCurrentHyp( aDim, Algo, index );
1638 onAlgoSelected( index, aDim );
1643 bool mainHyp = true;
1644 QStringList anAvailable;
1645 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1646 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1647 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1651 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1654 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1660 //================================================================================
1662 * \brief Creates mesh
1663 * \param theMess - Output parameter intended for returning error message
1664 * \param theEntryList - List of entries of published objects
1665 * \retval bool - TRUE if mesh is created, FALSE otherwise
1669 //================================================================================
1670 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1675 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1676 if ( aList.isEmpty() )
1678 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1679 if ( aSMESHGen->_is_nil() )
1682 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1683 if ( aMeshVar->_is_nil() )
1686 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1688 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1689 theEntryList.append( aMeshSO->GetID().c_str() );
1694 if ( aList.count() > 1 )
1696 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1697 int i = namePrefix.length() - 1;
1698 while ( i > 0 && namePrefix[i].isDigit() )
1700 if ( i < namePrefix.length() - 1 )
1701 namePrefix.chop( namePrefix.length() - 1 - i );
1705 QStringList::Iterator it = aList.begin();
1706 for ( int i = 0; it!=aList.end(); it++, ++i )
1708 QString aGeomEntry = *it;
1709 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1710 GEOM::GEOM_Object_var aGeomVar =
1711 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1713 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1714 if ( aSMESHGen->_is_nil() )
1717 SUIT_OverrideCursor aWaitCursor;
1720 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1721 if ( aMeshVar->_is_nil() )
1723 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1725 theEntryList.append( aMeshSO->GetID().c_str() );
1726 if ( i > 0 ) setDefaultName( namePrefix );
1727 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1730 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1731 if ( !isAccessibleDim( aDim )) continue;
1733 // assign hypotheses
1734 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1735 int aHypIndex = currentHyp( aDim, aHypType );
1736 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1737 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1738 if ( !aHypVar->_is_nil() )
1739 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1742 // find or create algorithm
1743 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1744 if ( !anAlgoVar->_is_nil() )
1745 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1751 //================================================================================
1753 * \brief Creates sub-mesh
1754 * \param theMess - Output parameter intended for returning error message
1755 * \param theEntryList - List of entries of published objects
1756 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1760 //================================================================================
1761 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1765 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1766 if ( aSMESHGen->_is_nil() )
1770 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1771 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1772 SMESH::SMESH_Mesh_var aMeshVar =
1773 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1774 if (aMeshVar->_is_nil())
1777 // GEOM shape of the main mesh
1778 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1780 // Name for the new sub-mesh
1781 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1784 GEOM::GEOM_Object_var aGeomVar;
1786 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1787 if (aGEOMs.count() == 1)
1789 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1790 QString aGeomEntry = aGEOMs.first();
1791 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1792 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1794 else if (aGEOMs.count() > 1)
1796 // create a GEOM group
1797 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1798 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1799 if (!geomGen->_is_nil() && aStudy) {
1800 GEOM::GEOM_IGroupOperations_wrap op =
1801 geomGen->GetIGroupOperations(aStudy->StudyId());
1802 if (!op->_is_nil()) {
1803 // check and add all selected GEOM objects: they must be
1804 // a sub-shapes of the main GEOM and must be of one type
1806 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1807 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1808 aSeq->length(aGEOMs.count());
1809 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1810 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1811 QString aSubGeomEntry = (*aSubShapesIter);
1812 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1813 GEOM::GEOM_Object_var aSubGeomVar =
1814 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1815 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1817 aGroupType = aSubShapeType;
1819 if (aSubShapeType != aGroupType)
1820 aGroupType = TopAbs_SHAPE;
1822 aSeq[iSubSh] = aSubGeomVar;
1825 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1826 op->UnionList(aGroupVar, aSeq);
1830 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1832 // publish the GEOM group in study
1833 QString aNewGeomGroupName ("Auto_group_for_");
1834 aNewGeomGroupName += aName;
1835 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1836 SALOMEDS::SObject_wrap aNewGroupSO =
1837 geomGen->AddInStudy( aStudyVar, aGeomVar,
1838 aNewGeomGroupName.toLatin1().data(), mainGeom);
1845 if (aGeomVar->_is_nil())
1848 SUIT_OverrideCursor aWaitCursor;
1851 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1852 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1854 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1855 theEntryList.append( aSubMeshSO->GetID().c_str() );
1858 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1860 if ( !isAccessibleDim( aDim )) continue;
1862 // find or create algorithm
1863 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1864 if ( !anAlgoVar->_is_nil() )
1865 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1866 // assign hypotheses
1867 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1869 int aHypIndex = currentHyp( aDim, aHypType );
1870 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1872 SMESH::SMESH_Hypothesis_var aHypVar =
1873 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1874 if ( !aHypVar->_is_nil() )
1875 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1880 // deselect geometry: next submesh should be created on other sub-shape
1881 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1882 selectObject( _PTR(SObject)() );
1885 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1890 //================================================================================
1892 * \brief Gets current hypothesis or algorithms
1893 * \param theDim - dimension of hypothesis or algorithm
1894 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1895 * \retval int - current hypothesis or algorithms
1897 * Gets current hypothesis or algorithms
1899 //================================================================================
1900 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1902 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1905 //================================================================================
1907 * \brief Returns true if hypotheses of given dim can be assigned
1908 * \param theDim - hypotheses dimension
1909 * \retval bool - result
1911 //================================================================================
1912 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1914 return myDlg->isTabEnabled( theDim );
1917 //================================================================================
1919 * \brief Sets current hypothesis or algorithms
1920 * \param theDim - dimension of hypothesis or algorithm
1921 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1922 * \param theIndex - Index of hypothesis
1924 * Gets current hypothesis or algorithms
1926 //================================================================================
1927 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1928 const int theHypType,
1929 const int theIndex )
1931 myIgnoreAlgoSelection = true;
1932 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1933 myIgnoreAlgoSelection = false;
1936 //================================================================================
1938 * \brief Generates default and sets mesh/submesh name
1940 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1942 //================================================================================
1943 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1947 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1950 QString aPrefix = thePrefix;
1951 if ( aPrefix.isEmpty() )
1952 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1954 _PTR(SObject) anObj;
1957 aResName = aPrefix + QString::number( i++ );
1958 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1962 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1963 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1964 aControl->setText( aResName );
1967 //================================================================================
1969 * \brief Gets algorithm or creates it if necessary
1970 * \param theDim - specifies dimension of returned hypotheses/algorifms
1971 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1973 * Gets algorithm or creates it if necessary
1975 //================================================================================
1976 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1978 SMESH::SMESH_Hypothesis_var anAlgoVar;
1980 // get type of the selected algo
1981 int aHypIndex = currentHyp( theDim, Algo );
1982 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1983 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1985 QString aHypName = dataList[ aHypIndex ]->TypeName;
1987 // get existing algoritms
1988 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1990 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1992 // look for an existing algo of such a type
1993 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1994 THypList::iterator anIter = aHypVarList.begin();
1995 for ( ; anIter != aHypVarList.end(); anIter++)
1997 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1998 CORBA::String_var aName = aHypVar->GetName();
1999 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2001 anAlgoVar = aHypVar;
2006 if (anAlgoVar->_is_nil())
2008 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2011 QString aClientLibName = aHypData->ClientLibName;
2012 if ( aClientLibName.isEmpty() )
2014 // Call hypothesis creation server method (without GUI)
2015 SMESH::SMESH_Hypothesis_var aHyp =
2016 SMESH::CreateHypothesis(aHypName, aHypName, true);
2021 // Get hypotheses creator client (GUI)
2022 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2026 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2028 SMESH::SMESH_Hypothesis_var aHyp =
2029 SMESH::CreateHypothesis(aHypName, aHypName, true);
2033 QStringList tmpList;
2034 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2035 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2038 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2039 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2041 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2042 CORBA::String_var aName = aHypVar->GetName();
2043 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2045 anAlgoVar = aHypVar;
2051 return anAlgoVar._retn();
2054 //================================================================================
2056 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2058 * Called when mesh is edited only.
2060 //================================================================================
2061 void SMESHGUI_MeshOp::readMesh()
2063 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2064 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2068 if (myIsOnGeometry) {
2069 // Get name of mesh if current object is sub-mesh
2070 SMESH::SMESH_subMesh_var aSubMeshVar =
2071 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2072 if ( !aSubMeshVar->_is_nil() )
2074 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2075 if ( !aMeshVar->_is_nil() )
2077 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2078 QString aMeshName = name( aMeshSO );
2079 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2081 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2084 // Get name of geometry object
2085 CORBA::String_var name = SMESH::GetGeomName( pObj );
2087 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2090 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2091 QStringList anExisting;
2092 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2093 bool algoFound = false;
2094 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2097 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2098 // find algo index among available ones
2100 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2102 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2103 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2104 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2105 // if ( aHypIndex < 0 && algoData ) {
2106 // // assigned algo is incompatible with other algorithms
2107 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2108 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2110 algoFound = ( aHypIndex > -1 );
2112 setCurrentHyp( dim, Algo, aHypIndex );
2113 // set existing and available hypothesis according to the selected algo
2114 if ( aHypIndex > -1 || !algoFound )
2115 onAlgoSelected( aHypIndex, dim );
2119 bool hypWithoutAlgo = false;
2120 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2122 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2125 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2126 // find index of requered hypothesis among existing ones for this dimension and type
2128 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2129 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2130 myExistingHyps[ dim ][ hypType ] );
2131 if ( aHypIndex < 0 ) {
2132 // assigned hypothesis is incompatible with the algorithm
2133 if ( currentHyp( dim, Algo ) < 0 )
2134 { // none algo selected; it is edition for sure, of submesh maybe
2135 hypWithoutAlgo = true;
2136 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2137 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2138 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2142 setCurrentHyp( dim, hypType, aHypIndex );
2145 // make available other hyps of same type as one without algo
2146 if ( hypWithoutAlgo )
2147 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2150 //================================================================================
2152 * \brief Gets name of object
2153 * \param theSO - SObject
2154 * \retval QString - name of object
2156 * Gets name of object
2158 //================================================================================
2159 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2164 _PTR(GenericAttribute) anAttr;
2165 _PTR(AttributeName) aNameAttr;
2166 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2169 aResName = aNameAttr->Value().c_str();
2175 //================================================================================
2177 * \brief Finds hypothesis in input list
2178 * \param theHyp - hypothesis to be found
2179 * \param theHypList - input list of hypotheses
2180 * \retval int - index of hypothesis or -1 if it is not found
2182 * Finds position of hypothesis in input list
2184 //================================================================================
2185 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2186 const THypList& theHypList ) const
2189 if ( !theHyp->_is_nil() )
2192 THypList::const_iterator anIter = theHypList.begin();
2193 for ( ; anIter != theHypList.end(); ++ anIter)
2195 if ( theHyp->_is_equivalent( (*anIter).first ) )
2206 //================================================================================
2208 * \brief Edits mesh or sub-mesh
2209 * \param theMess - Output parameter intended for returning error message
2210 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2212 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2214 //================================================================================
2215 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2219 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2220 if ( aSMESHGen->_is_nil() )
2223 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2224 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2228 SUIT_OverrideCursor aWaitCursor;
2231 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2232 SMESH::SetName( pObj, aName );
2233 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2235 // First, remove old algos in order to avoid messages on algorithm hiding
2236 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2238 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2240 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2241 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2242 if ( anAlgoVar->_is_nil() || // no new algo selected or
2243 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2245 // remove old algorithm
2246 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2247 myObjHyps[ dim ][ Algo ].clear();
2252 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2253 CORBA::Object_var anObject = aSObject->GetObject();
2254 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2255 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2256 bool isMesh = !aMeshVar->_is_nil();
2257 if ( !isMesh && !aSubMeshVar->_is_nil() )
2258 aMeshVar = aSubMeshVar->GetFather();
2260 // Assign new algorithms and hypotheses
2261 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2263 if ( !isAccessibleDim( dim )) continue;
2265 // find or create algorithm
2266 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2268 // assign new algorithm
2269 if ( !anAlgoVar->_is_nil() && // some algo selected and
2270 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2273 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2274 else if ( !aSubMeshVar->_is_nil() )
2275 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2277 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2280 // assign hypotheses
2281 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2283 int aNewHypIndex = currentHyp( dim, hypType );
2284 int anOldHypIndex = -1;
2286 // remove old hypotheses
2287 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2289 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2290 myExistingHyps[ dim ][ hypType ] );
2291 if ( aNewHypIndex != anOldHypIndex || // different hyps
2292 anOldHypIndex == -1 ) // hyps of different algos
2294 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2295 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2296 myObjHyps[ dim ][ hypType ].clear();
2300 // assign new hypotheses
2301 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex > -1 )
2304 SMESH::AddHypothesisOnMesh
2305 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2306 else if ( !aSubMeshVar->_is_nil() )
2307 SMESH::AddHypothesisOnSubMesh
2308 ( aSubMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2310 // reread all hypotheses of mesh if necessary
2311 QStringList anExisting;
2312 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2316 myHasConcurrentSubBefore =
2317 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2322 //================================================================================
2324 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2325 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2326 * order of sub-mesh computation.
2327 * Returns \c true if a sub-mesh concurrency detected.
2329 //================================================================================
2331 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2332 SMESH::SMESH_subMesh_ptr submesh,
2335 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2338 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2339 if ( isNewConcurrent && askUser )
2341 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2342 tr("CONCURRENT_SUBMESH_APPEARS"),
2343 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2346 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2347 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2348 if ( meshSO && aSelectionMgr )
2350 myDlg->setEnabled( false ); // disactivate selection
2351 selectionMgr()->clearFilters();
2352 selectObject( meshSO );
2353 SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2354 qApp->processEvents();
2356 myDlg->setEnabled( true );
2357 int obj = myDlg->getActiveObject();
2358 onActivateObject( obj ); // restore filter
2361 selectObject( SMESH::FindSObject( submesh ));
2368 return isNewConcurrent;
2371 //================================================================================
2373 * \brief Verifies whether given operator is valid for this one
2374 * \param theOtherOp - other operation
2375 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2377 * method redefined from base class verifies whether given operator is valid for
2378 * this one (i.e. can be started "above" this operator). In current implementation method
2379 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2382 //================================================================================
2383 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2385 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2388 //================================================================================
2390 * \brief SLOT. Is called when the user selects a way of geometry selection
2391 * \param theByMesh - true if the user wants to find geometry by mesh element
2393 //================================================================================
2394 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2397 if ( !myShapeByMeshOp ) {
2398 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2399 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2400 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2401 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2402 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2404 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2405 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2406 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2407 SMESH::SMESH_Mesh_var aMeshVar =
2408 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2409 if ( !aMeshVar->_is_nil() ) {
2410 myDlg->hide(); // stop processing selection
2411 myShapeByMeshOp->setModule( getSMESHGUI() );
2412 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2413 myShapeByMeshOp->SetMesh( aMeshVar );
2414 myShapeByMeshOp->start();
2420 //================================================================================
2422 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2424 //================================================================================
2425 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2427 if ( myShapeByMeshOp == op ) {
2428 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2430 // Select a found geometry object
2431 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2432 if ( !aGeomVar->_is_nil() )
2434 QString ID = aGeomVar->GetStudyEntry();
2435 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2436 selectObject( aGeomSO );
2443 //================================================================================
2445 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2447 //================================================================================
2448 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2450 if ( myShapeByMeshOp == op && myDlg ) {
2455 //================================================================================
2457 * \brief Selects a SObject
2458 * \param theSObj - the SObject to select
2460 //================================================================================
2461 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2463 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2464 SALOME_ListIO anIOList;
2466 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2467 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2468 anIOList.Append( anIO );
2470 sm->setSelectedObjects( anIOList, false );
2473 //================================================================================
2475 * \brief Create available list types of mesh
2476 * \param theTypeMesh - Output list of available types of mesh
2478 //================================================================================
2479 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2481 theTypeMesh.clear();
2482 theTypeMesh.append( tr( "MT_ANY" ) );
2483 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2485 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2486 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2488 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2490 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2491 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2495 //================================================================================
2497 * \brief Set available types of mesh
2498 * \param theTypeMesh - List of available types of mesh
2500 //================================================================================
2501 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2503 myDlg->setAvailableMeshType( theTypeMesh );
2506 //================================================================================
2508 * \brief SLOT. Is called when the user select type of mesh
2509 * \param theTabIndex - Index of current active tab
2510 * \param theIndex - Index of current type of mesh
2512 //================================================================================
2513 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2515 setFilteredAlgoData( theTabIndex, theIndex);
2518 //================================================================================
2520 * \brief Set a filtered list of available algorithms by mesh type
2521 * \param theTabIndex - Index of current active tab
2522 * \param theIndex - Index of current type of mesh
2524 //================================================================================
2525 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2528 THypDataList anAvailableAlgsData;
2529 QStringList anAvailableAlgs;
2530 QString anCompareType = "";
2531 bool isAvailableChoiceAlgo = false;
2532 int anCurrentAvailableAlgo = 0;
2534 switch ( theIndex ) {
2536 anCompareType = "ANY";
2537 aDim = SMESH::DIM_3D;
2540 aDim = SMESH::DIM_2D;
2541 anCompareType = "TRIA";
2543 case MT_QUADRILATERAL:
2544 aDim = SMESH::DIM_2D;
2545 anCompareType = "QUAD";
2547 case MT_TETRAHEDRAL:
2548 aDim = SMESH::DIM_3D;
2549 anCompareType = "TETRA";
2552 aDim = SMESH::DIM_3D;
2553 anCompareType = "HEXA";
2558 bool toCheckIsApplicableToAll = !myIsMesh;
2559 GEOM::GEOM_Object_var aGeomVar;
2560 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2561 if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2563 CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
2564 aGeomVar = GEOM::GEOM_Object::_narrow( obj );
2565 if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
2566 toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
2569 if ( anCompareType == "ANY" )
2571 for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
2573 isNone = currentHyp( dim, Algo ) < 0;
2574 isAvailableChoiceAlgo = false;
2575 // retrieves a list of available algorithms from resources
2576 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2577 //return current algo in current tab and set new algorithm list
2578 HypothesisData* algoCur;
2579 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2580 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2582 myAvailableHypData[dim][Algo].clear();
2583 anAvailableAlgs.clear();
2584 for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2586 HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2587 if ( aGeomVar->_is_nil() ||
2588 SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2590 anAvailableAlgs.append( curAlgo->Label );
2591 myAvailableHypData[dim][Algo].append( curAlgo );
2594 if ( !isNone && algoCur ) {
2595 for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2597 HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2598 if ( algoAny->Label == algoCur->Label ){
2599 isAvailableChoiceAlgo = true;
2600 anCurrentAvailableAlgo = i;
2605 else if ( !isNone ) {
2606 isAvailableChoiceAlgo = true;
2607 anCurrentAvailableAlgo = currentHyp( dim, Algo );
2609 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2610 if ( isAvailableChoiceAlgo )
2611 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2613 if ( !myIsOnGeometry )
2614 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2615 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2616 else myDlg->enableTab( i );
2619 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2620 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2621 else myDlg->enableTab( i );
2623 myDlg->setCurrentTab( theTabIndex );
2627 QString anCurrentAlgo;
2628 bool isReqDisBound = true;
2629 QString anCurrentCompareType = anCompareType;
2630 isNone = currentHyp( aDim, Algo ) < 0;
2631 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2632 myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2633 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2635 isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2636 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2638 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2639 isAvailableChoiceAlgo = false;
2640 // retrieves a list of available algorithms from resources
2641 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2642 // finding algorithm which is selected
2643 if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2644 myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2645 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2646 else if ( !isNoneAlg )
2647 anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2648 anAvailableAlgs.clear();
2649 myAvailableHypData[dim][Algo].clear();
2650 myFilteredAlgoData[dim].clear();
2651 // finding and adding algorithm depending on the type mesh
2652 for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2654 HypothesisData* algoIn = anAvailableAlgsData.at( i );
2655 bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2656 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2657 for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2659 if ( *inElemType == anCurrentCompareType ) {
2660 isAvailableAlgo = true;
2664 if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
2665 if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2666 SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2668 anAvailableAlgs.append( algoIn->Label );
2669 myAvailableHypData[dim][Algo].append( algoIn );
2670 myFilteredAlgoData[dim].append( algoIn );
2673 //algorithm will be active, if the chosen algorithm available in the current mesh type
2674 if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
2675 isAvailableChoiceAlgo = true;
2676 anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2679 //set new algorithm list and select the current algorithm
2680 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2681 anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2682 if ( isAvailableChoiceAlgo )
2683 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2685 setCurrentHyp( dim, Algo, -1 );
2688 if ( isNone || isReqDisBound ) {
2689 for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
2691 myDlg->disableTab( i );
2692 setCurrentHyp(i, Algo, -1);
2696 else if ( !isNone ) {
2697 if ( aDim == SMESH::DIM_2D){
2698 myDlg->disableTab( SMESH::DIM_3D );
2699 setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2701 for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
2703 isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2704 myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2705 if ( isReqDisBound ) {
2706 for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2707 myDlg->disableTab( j );
2708 setCurrentHyp( j , Algo, -1 );
2714 myDlg->enableTab( aDim );
2715 myDlg->setCurrentTab( aDim );
2717 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2718 QStringList aFilteredHypothesesSetsList;
2719 aFilteredHypothesesSetsList.clear();
2720 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2721 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2723 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2724 bool isAvailable = false;
2725 currentHypoSet->init( true );
2726 while ( currentHypoSet->next(), currentHypoSet->more() )
2728 isAvailable = false;
2729 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2731 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
2733 for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2734 HypothesisData* aCurAlgo = hypData( i, Algo, j );
2735 if ( aCurAlgo->Label == algoDataIn->Label ){
2740 if ( isAvailable ) break;
2742 if ( !isAvailable ) break;
2746 aFilteredHypothesesSetsList.append( *inHypoSetName );
2748 myDlg->setHypoSets( aFilteredHypothesesSetsList );