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 =
402 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
404 algo->InputTypes.empty() && // builds all dimensions it-self
405 !algo->IsSupportSubmeshes )
406 return CORBA::string_dup( algoNames[0].toLatin1().data() );
409 // GEOM::GEOM_Object_var geom;
410 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
411 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
413 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
414 existingHyps(2, Algo, pMesh, algoNames, algoList);
415 if (!algoList.empty()) {
416 HypothesisData* algo =
417 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
419 algo->InputTypes.empty() && // builds all dimensions it-self
420 !algo->IsSupportSubmeshes )
421 return CORBA::string_dup( algoNames[0].toLatin1().data() );
429 //================================================================================
431 * \brief find an existing submesh by the selected shape
432 * \retval _PTR(SObject) - the found submesh SObject
434 //================================================================================
435 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
437 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
438 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
439 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
440 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
441 if ( pMesh && pGeom ) {
442 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
443 if ( !geom->_is_nil() ) {
445 switch ( geom->GetShapeType() ) {
446 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
447 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
448 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
449 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
450 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
451 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
452 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
455 _PTR(GenericAttribute) anAttr;
456 _PTR(SObject) aSubmeshRoot;
457 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
458 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
460 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
461 for ( ; smIter->More(); smIter->Next() )
463 _PTR(SObject) aSmObj = smIter->Value();
464 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
466 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
467 for ( ; anIter1->More(); anIter1->Next()) {
468 _PTR(SObject) pGeom2 = anIter1->Value();
469 if ( pGeom2->ReferencedObject( pGeom2 ) &&
470 pGeom2->GetID() == pGeom->GetID() )
477 return _PTR(SObject)();
480 //================================================================================
482 * \brief Updates dialog's look and feel
484 * Virtual method redefined from the base class updates dialog's look and feel
486 //================================================================================
487 void SMESHGUI_MeshOp::selectionDone()
489 if (!dlg()->isVisible() || !myDlg->isEnabled())
492 SMESHGUI_SelectionOp::selectionDone();
496 myIsOnGeometry = true;
498 //Check geometry for mesh
499 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
500 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
503 SMESH::SMESH_Mesh_var aMeshVar =
504 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
505 if (!aMeshVar->_is_nil()) {
506 if (!myToCreate && !aMeshVar->HasShapeToMesh())
507 myIsOnGeometry = false;
513 // Enable tabs according to shape dimension
518 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
519 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
521 if (aGEOMs.count() > 0) {
522 // one or more GEOM shape selected
523 aSeq->length(aGEOMs.count());
524 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
526 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
527 QString aSubGeomEntry = (*aSubShapesIter);
528 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
529 GEOM::GEOM_Object_var aSubGeomVar =
530 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
531 aSeq[iSubSh] = aSubGeomVar;
534 // get geometry by selected sub-mesh
535 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
536 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
537 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
538 if (!aGeomVar->_is_nil()) {
544 if (aSeq->length() > 0) {
546 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
547 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
548 switch ( aGeomVar->GetShapeType() ) {
549 case GEOM::SOLID: shapeDim = 3; break;
551 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
553 // TopoDS_Shape aShape;
554 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
555 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
558 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
560 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
561 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
565 if (GEOMBase::GetShape(aGeomVar, aShape))
567 TopExp_Explorer exp (aShape, TopAbs_SOLID);
571 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
572 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
575 // for (; exp.More() && shapeDim == 2; exp.Next()) {
576 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
580 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
581 shapeDim = qMax(2, shapeDim);
582 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
583 shapeDim = qMax(1, shapeDim);
584 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
585 shapeDim = qMax(0, shapeDim);
593 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
594 // reset algos before disabling tabs (0020138)
595 onAlgoSelected(-1, i);
597 myDlg->setMaxHypoDim( shapeDim );
598 myMaxShapeDim = shapeDim;
599 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
601 if (!myToCreate) // edition: read hypotheses
605 SMESH::SMESH_subMesh_var submeshVar =
606 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
607 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
608 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
609 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
610 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
611 myDlg->updateGeometry();
613 myIsMesh = submeshVar->_is_nil();
619 else if ( !myIsMesh ) // submesh creation
621 // if a submesh on the selected shape already exist, pass to submesh edition mode
622 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
623 SMESH::SMESH_subMesh_var sm =
624 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
625 bool editSubmesh = ( !sm->_is_nil() &&
626 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
627 tr( "EDIT_SUBMESH_QUESTION"),
628 SUIT_MessageBox::Yes |
630 SUIT_MessageBox::No )
631 == SUIT_MessageBox::Yes );
634 selectionMgr()->clearFilters();
635 selectObject( pSubmesh );
636 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
641 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
642 selectObject( _PTR(SObject)() );
647 // discard selected mesh if submesh creation not allowed because of
648 // a global algorithm that does not support submeshes
649 if ( char* algoName = isSubmeshIgnored() ) {
650 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
651 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
652 CORBA::string_free( algoName );
653 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
654 selectObject( _PTR(SObject)() );
659 // enable/disable popup for choice of geom selection way
661 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
662 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
663 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
664 if ( !mesh->_is_nil() ) {
665 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
666 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
667 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
668 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
669 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
670 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
673 myDlg->setGeomPopupEnabled( enable );
676 else { // no geometry defined
677 myDlg->enableTab( SMESH::DIM_3D );
679 availableHyps( SMESH::DIM_3D, Algo, hypList,
680 myAvailableHypData[SMESH::DIM_3D][Algo]);
682 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
683 aTab->setAvailableHyps( Algo, hypList );
684 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
685 myDlg->disableTab(i);
688 //Hide labels and fields (Mesh and Geometry)
689 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
690 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
694 int curIndex = myDlg->currentMeshType( );
695 QStringList TypeMeshList;
696 createMeshTypeList( TypeMeshList );
697 setAvailableMeshType( TypeMeshList );
698 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
699 myDlg->setCurrentMeshType( curIndex );
700 setFilteredAlgoData( myMaxShapeDim, curIndex);
702 catch ( const SALOME::SALOME_Exception& S_ex )
704 SalomeApp_Tools::QtCatchCorbaException( S_ex );
711 //================================================================================
713 * \brief Verifies validity of input data
714 * \param theMess - Output parameter intended for returning error message
715 * \retval bool - TRUE if input data is valid, false otherwise
717 * Verifies validity of input data. This method is called when "Apply" or "OK" button
718 * is pressed before mesh creation or editing.
720 //================================================================================
721 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
723 // Selected object to be edited
724 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
726 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
731 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
732 if ( aMeshName.isEmpty() )
734 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
738 /* // Imported mesh, if create sub-mesh or edit mesh
739 if ( !myToCreate || ( myToCreate && !myIsMesh ))
741 QString aMeshEntry = myDlg->selectedObject
742 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
743 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
744 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
745 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
746 theMess = tr( "IMPORTED_MESH" );
755 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
756 if ( aGeomEntry.isEmpty() )
758 theMess = tr( myIsMesh ?
759 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
760 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
764 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
765 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
772 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
773 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
775 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
780 if ( !myIsMesh ) // i.e sub-mesh creation,
782 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
783 if ( aMeshEntry == "" )
785 theMess = tr( "MESH_IS_NOT_DEFINED" );
788 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
789 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
791 theMess = tr( "MESH_IS_NULL" );
794 if ( !isSubshapeOk() )
796 theMess = tr( "INVALID_SUBSHAPE" );
805 //================================================================================
807 * \brief check compatibility of the algorithm and another algorithm or hypothesis
808 * \param theAlgoData - algorithm data
809 * \param theHypData - hypothesis data
810 * \param theHypType - hypothesis type
811 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
812 * \retval bool - check result
814 //================================================================================
815 static bool isCompatible(const HypothesisData* theAlgoData,
816 const HypothesisData* theHypData,
817 const int theHypType)
822 if ( theHypType == SMESHGUI_MeshOp::Algo )
823 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
826 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
829 //================================================================================
831 * \brief Gets available hypotheses or algorithms
832 * \param theDim - specifies dimension of returned hypotheses/algorifms
833 * \param theHypType - specifies whether algorims or hypotheses or additional ones
834 * are retrieved (possible values are in HypType enumeration)
835 * \param theHyps - Output list of hypotheses' names
836 * \param theAlgoData - to select hypos able to be used by this algo (optional)
838 * Gets available hypotheses or algorithm in accordance with input parameters
840 //================================================================================
841 void SMESHGUI_MeshOp::availableHyps( const int theDim,
842 const int theHypType,
843 QStringList& theHyps,
844 THypDataList& theDataList,
845 HypothesisData* theAlgoData ) const
849 bool isAlgo = ( theHypType == Algo );
850 bool isAux = ( theHypType >= AddHyp );
851 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
853 QStringList::const_iterator anIter;
854 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
856 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
857 if ( isCompatible ( theAlgoData, aData, theHypType )) {
858 theDataList.append( aData );
859 theHyps.append( aData->Label );
864 //================================================================================
866 * \brief Gets existing hypotheses or algorithms
867 * \param theDim - specifies dimension of returned hypotheses/algorifms
868 * \param theHypType - specifies whether algorims or hypotheses or additional ones
869 * are retrieved (possible values are in HypType enumeration)
870 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
871 * \param theHyps - output list of names.
872 * \param theHypVars - output list of variables.
873 * \param theAlgoData - to select hypos able to be used by this algo (optional)
875 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
878 * WARNING: when using this method to get hyps existing in Mesh component,
879 * call availableHyps() before in order to get only hyps of available types
880 * that was filtered by availableHyps()
882 //================================================================================
883 void SMESHGUI_MeshOp::existingHyps( const int theDim,
884 const int theHypType,
885 _PTR(SObject) theFather,
886 QStringList& theHyps,
887 THypList& theHypList,
888 HypothesisData* theAlgoData) const
890 // Clear hypoheses list
897 _PTR(SObject) aHypRoot;
898 _PTR(GenericAttribute) anAttr;
899 _PTR(AttributeName) aName;
900 _PTR(AttributeIOR) anIOR;
902 const bool isMesh = !_CAST( SComponent, theFather );
905 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
907 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
909 const bool isAux = ( theHypType >= AddHyp );
910 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
912 if ( theFather->FindSubObject( aPart, aHypRoot ) )
914 _PTR(ChildIterator) anIter =
915 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
916 for ( ; anIter->More(); anIter->Next() )
918 _PTR(SObject) anObj = anIter->Value();
919 if ( isMesh ) // i.e. mesh or submesh
921 _PTR(SObject) aRefObj;
922 if ( anObj->ReferencedObject( aRefObj ) )
927 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
930 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
931 if ( !CORBA::is_nil( aVar ) )
933 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
934 if ( !aHypVar->_is_nil() )
936 CORBA::String_var hypType = aHypVar->GetName();
937 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
938 if ( !aData) continue;
939 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
940 ( isCompatible ( theAlgoData, aData, theHypType )) &&
941 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
942 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
944 std::string aHypName = aName->Value();
945 theHyps.append( aHypName.c_str() );
946 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
955 //================================================================================
957 * \brief If create or edit a submesh, return a hypothesis holding parameters used
958 * to mesh a sub-shape
959 * \param aHypType - The hypothesis type name
960 * \param aServerLib - Server library name
961 * \param hypData - The structure holding the hypothesis type etc.
962 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
964 //================================================================================
965 SMESH::SMESH_Hypothesis_var
966 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
967 const QString& aServerLib ) const
969 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
970 return SMESH::SMESH_Hypothesis::_nil();
972 const int nbColonsInMeshEntry = 3;
973 bool isSubMesh = myToCreate ?
975 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
977 // get mesh and geom object
978 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
979 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
984 anEntry = myDlg->selectedObject
985 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
986 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
988 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
989 if ( myToCreate ) // mesh and geom may be selected
991 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
992 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
993 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
994 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
996 else // edition: sub-mesh may be selected
998 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
999 if ( !sm->_is_nil() ) {
1000 aMeshVar = sm->GetFather();
1001 aGeomVar = sm->GetSubShape();
1008 if ( !myToCreate ) // mesh to edit can be selected
1010 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1011 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1013 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1014 if ( !aMeshVar->_is_nil() )
1015 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1018 if ( aGeomVar->_is_nil() ) {
1019 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1020 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1022 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1027 SMESH::SMESH_Hypothesis_var hyp =
1028 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1029 aServerLib.toLatin1().data(),
1032 /*byMesh = */isSubMesh);
1033 if ( hyp->_is_nil() && isSubMesh )
1034 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1035 aServerLib.toLatin1().data(),
1038 /*byMesh = */false);
1042 //================================================================================
1044 * \brief initialize a hypothesis creator
1046 //================================================================================
1048 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1050 if ( !theCreator ) return;
1052 // Set shapes, of mesh and sub-mesh if any
1054 // get Entry of the Geom object
1055 QString aGeomEntry = "";
1056 QString aMeshEntry = "";
1057 QString anObjEntry = "";
1058 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1059 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1060 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1062 if ( myToCreate && myIsMesh )
1063 aMeshEntry = aGeomEntry;
1065 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1066 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1067 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1068 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1071 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1072 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1074 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1075 if ( !aGeomVar->_is_nil() )
1077 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1079 aMeshEntry = aGeomEntry;
1083 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1084 // take geometry from submesh being created
1085 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1087 // if current object is sub-mesh
1088 SMESH::SMESH_subMesh_var aSubMeshVar =
1089 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1090 if ( !aSubMeshVar->_is_nil() ) {
1091 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1092 if ( !aMeshVar->_is_nil() ) {
1093 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1094 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1095 if ( !aGeomVar->_is_nil() )
1096 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1102 theCreator->setShapeEntry( aGeomEntry );
1103 if ( aMeshEntry != "" )
1104 theCreator->setMainShapeEntry( aMeshEntry );
1107 //================================================================================
1109 * \Brief Returns tab dimention
1110 * \param tab - the tab in the dlg
1111 * \param dlg - my dialogue
1112 * \retval int - dimention
1114 //================================================================================
1115 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1118 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1119 if (tab == dlg->tab(i))
1124 //================================================================================
1126 * \brief Create hypothesis
1127 * \param theHypType - hypothesis category (main or additional)
1128 * \param theIndex - index of type of hypothesis to be cerated
1130 * Specifies dimension of hypothesis to be created (using sender() method),
1131 * specifies its type and calls method for hypothesis creation
1133 //================================================================================
1134 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1136 // Specifies dimension of hypothesis to be created
1137 int aDim = getTabDim( sender(), myDlg );
1141 // Specifies type of hypothesis to be created
1142 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1143 if (theIndex < 0 || theIndex >= dataList.count())
1145 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1147 // Create hypothesis
1148 createHypothesis(aDim, theHypType, aHypTypeName);
1153 QString GetUniqueName (const QStringList& theHypNames,
1154 const QString& theName,
1155 size_t theIteration = 1)
1157 QString aName = theName + "_" + QString::number( theIteration );
1158 if ( theHypNames.contains( aName ) )
1159 return GetUniqueName( theHypNames, theName, ++theIteration );
1164 //================================================================================
1166 * Create hypothesis and update dialog.
1167 * \param theDim - dimension of hypothesis to be created
1168 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1169 * \param theTypeName - specifies hypothesis to be created
1171 //================================================================================
1172 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1174 const QString& theTypeName)
1176 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1183 // get a unique hyp name
1184 QStringList aHypNames;
1185 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1186 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1187 const TType2HypList& aType2HypList = aDimIter.value();
1188 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1189 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1190 const THypList& aHypList = aTypeIter.value();
1191 THypList::const_iterator anIter = aHypList.begin();
1192 for ( ; anIter != aHypList.end(); anIter++) {
1193 const THypItem& aHypItem = *anIter;
1194 const QString& aHypName = aHypItem.second;
1195 aHypNames.append(aHypName);
1199 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1202 bool dialog = false;
1204 QString aClientLibName = aData->ClientLibName;
1205 if (aClientLibName == "") {
1206 // Call hypothesis creation server method (without GUI)
1207 SMESH::SMESH_Hypothesis_var aHyp =
1208 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1212 // Get hypotheses creator client (GUI)
1213 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1215 // Create hypothesis
1218 // Get parameters appropriate to initialize a new hypothesis
1219 SMESH::SMESH_Hypothesis_var initParamHyp =
1220 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1222 removeCustomFilters(); // Issue 0020170
1224 // set shapes, of mesh and sub-mesh if any
1225 initHypCreator( aCreator );
1227 myDlg->setEnabled( false );
1228 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1232 SMESH::SMESH_Hypothesis_var aHyp =
1233 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1242 //================================================================================
1244 * Necessary steps after hypothesis creation
1245 * \param result - creation result:
1248 * 2 = additional value meaning that slot is called not from dialog box
1250 //================================================================================
1251 void SMESHGUI_MeshOp::onHypoCreated( int result )
1255 int obj = myDlg->getActiveObject();
1256 onActivateObject( obj ); // Issue 0020170. Restore filters
1257 myDlg->setEnabled( true );
1260 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1262 int nbHyp = myExistingHyps[myDim][myType].count();
1263 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1264 QStringList aNewHyps;
1265 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1266 if (aNewHyps.count() > nbHyp)
1268 for (int i = nbHyp; i < aNewHyps.count(); i++)
1269 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1272 if( result!=2 && myHypoSet )
1276 //================================================================================
1278 * \brief Calls plugin methods for hypothesis editing
1279 * \param theHypType - specifies whether main hypothesis or additional one
1281 * \param theIndex - index of existing hypothesis
1283 * Calls plugin methods for hypothesis editing
1285 //================================================================================
1286 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1288 // Speicfies dimension of hypothesis to be created
1289 int aDim = getTabDim( sender(), myDlg );
1293 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1294 if ( theIndex < 0 || theIndex >= aList.count() )
1296 const THypItem& aHypItem = aList[ theIndex ];
1297 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1298 if ( aHyp->_is_nil() )
1301 SMESHGUI_GenericHypothesisCreator* aCreator =
1302 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1305 // set initial parameters
1306 SMESH::SMESH_Hypothesis_var initParamHyp =
1307 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1308 SMESH::toQStr( aHyp->GetLibName() ));
1309 aCreator->setInitParamsHypothesis( initParamHyp );
1311 // set shapes, of mesh and sub-mesh if any
1312 initHypCreator( aCreator );
1314 removeCustomFilters(); // Issue 0020170
1315 myDlg->setEnabled( false );
1317 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1321 //================================================================================
1323 * Necessary steps after hypothesis edition
1324 * \param result - creation result:
1328 //================================================================================
1329 void SMESHGUI_MeshOp::onHypoEdited( int result )
1331 int obj = myDlg->getActiveObject();
1332 onActivateObject( obj ); // Issue 0020170. Restore filters
1333 myDlg->setEnabled( true );
1336 //================================================================================
1338 * \brief access to hypothesis data
1339 * \param theDim - hyp dimension
1340 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1341 * \param theIndex - index in the list
1342 * \retval HypothesisData* - result data, may be 0
1344 //================================================================================
1345 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1346 const int theHypType,
1349 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1350 theHypType > -1 && theHypType < NbHypTypes &&
1351 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1352 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1356 //================================================================================
1358 * \brief Set available algos and hypos according to the selected algorithm
1359 * \param theIndex - algorithm index
1361 //================================================================================
1362 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1365 if ( myIgnoreAlgoSelection )
1368 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1372 // find highest available dimension, all algos of this dimension are available for choice
1374 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1375 if (isAccessibleDim( i ))
1380 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1382 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1383 HypothesisData* algoByDim[4];
1384 algoByDim[ aDim ] = algoData;
1386 QStringList anAvailable;
1388 // check that tab enabled of one less dimension
1389 if ( aDim > SMESH::DIM_0D )
1391 if ( isAccessibleDim( aDim - 1 ) )
1393 if (( myDlg->currentMeshType() != MT_ANY ) &&
1394 ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1395 for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1396 if ( isAccessibleDim( i ) ) {
1397 myDlg->disableTab( i );
1398 setCurrentHyp(i, Algo, -1);
1401 else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1403 myDlg->enableTab( aDim - 1 );
1407 // check that algorithms of other dimentions are compatible with
1409 if ( !algoData ) { // all algos becomes available
1410 if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
1411 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1413 anAvailable.clear();
1414 for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1415 HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1416 anAvailable.append( aCurAlgo->Label );
1419 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1421 // 2 loops: backward and forward from algo dimension
1422 for ( int forward = false; forward <= true; ++forward )
1424 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1426 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1428 HypothesisData* prevAlgo = algoData;
1429 bool noCompatible = false;
1430 for ( ; dim * dir <= lastDim * dir; dim += dir)
1432 if ( !isAccessibleDim( dim ))
1434 if ( noCompatible ) { // the selected algo has no compatible ones
1435 anAvailable.clear();
1436 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1437 myAvailableHypData[dim][Algo].clear();
1438 algoByDim[ dim ] = 0;
1441 // get currently selected algo
1442 int algoIndex = currentHyp( dim, Algo );
1443 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1444 if ( curAlgo ) { // some algo selected
1445 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1448 // set new available algoritms
1449 if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1450 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1452 anAvailable.clear();
1453 myAvailableHypData[dim][Algo].clear();
1454 for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1455 HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1456 if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1457 anAvailable.append( aCurAlgo->Label );
1458 myAvailableHypData[dim][Algo].append( aCurAlgo );
1462 HypothesisData* soleCompatible = 0;
1463 if ( anAvailable.count() == 1 )
1464 soleCompatible = myAvailableHypData[dim][Algo][0];
1465 if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1466 if (myDlg->currentMeshType() == MT_ANY)
1467 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1469 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1470 noCompatible = anAvailable.isEmpty();
1472 // restore previously selected algo
1473 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1474 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1475 // select the sole compatible algo
1476 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1477 setCurrentHyp( dim, Algo, algoIndex);
1479 // remember current algo
1480 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1484 // set hypotheses corresponding to the found algoritms
1486 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1488 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1490 if ( !isAccessibleDim( dim ))
1493 // get indices of selected hyps
1494 const int nbTypes = nbDlgHypTypes(dim);
1495 std::vector<int> hypIndexByType( nbTypes, -1 );
1496 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1498 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1502 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1504 const int type = Min( dlgType, AddHyp );
1505 myAvailableHypData[ dim ][ type ].clear();
1506 QStringList anAvailable, anExisting;
1508 HypothesisData* curAlgo = algoByDim[ dim ];
1509 int hypIndex = hypIndexByType[ dlgType ];
1511 SMESH::SMESH_Hypothesis_var curHyp;
1512 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1513 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1515 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1516 // try to find algo by selected hypothesis in order to keep it selected
1517 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1518 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1519 if ( !algoDeselectedByUser &&
1520 myObjHyps[ dim ][ type ].count() > 0 &&
1521 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1523 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1524 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1525 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1526 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1533 // get hyps compatible with curAlgo
1534 bool defaulHypAvlbl = false;
1537 // check if a selected hyp is compatible with the curAlgo
1538 if ( !curHyp->_is_nil() ) {
1539 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1540 if ( !isCompatible( curAlgo, hypData, type ))
1541 curHyp = SMESH::SMESH_Hypothesis::_nil();
1543 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1544 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1545 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1547 // set list of hypotheses
1548 if ( dlgType <= AddHyp )
1550 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1551 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1553 // set current existing hypothesis
1554 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1555 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1558 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1559 // none is yet selected => select the sole existing if it is not optional
1560 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1561 bool isOptional = true;
1562 if ( algoByDim[ dim ] &&
1563 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1567 setCurrentHyp( dim, dlgType, hypIndex );
1572 //================================================================================
1574 * \brief Creates and selects hypothesis of hypotheses set
1575 * \param theSetName - The name of hypotheses set
1577 //================================================================================
1578 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1580 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1585 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1586 setCurrentHyp(dim, Algo, -1);
1587 setCurrentHyp(dim, AddHyp, -1);
1588 setCurrentHyp(dim, MainHyp, -1);
1591 myHypoSet->init(true); //algorithms
1593 myHypoSet->init(false); //hypotheses
1598 //================================================================================
1600 * \brief One step of hypothesis/algorithm list creation
1602 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1604 //================================================================================
1605 void SMESHGUI_MeshOp::processSet()
1608 if( !myHypoSet->more() )
1611 bool isAlgo = myHypoSet->isAlgo();
1612 QString aHypoTypeName = myHypoSet->current();
1613 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1620 int aDim = aHypData->Dim[0];
1621 // create or/and set
1624 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1627 QStringList anAvailable;
1628 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1629 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1630 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1632 setCurrentHyp( aDim, Algo, index );
1633 onAlgoSelected( index, aDim );
1638 bool mainHyp = true;
1639 QStringList anAvailable;
1640 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1641 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1642 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1646 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1649 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1655 //================================================================================
1657 * \brief Creates mesh
1658 * \param theMess - Output parameter intended for returning error message
1659 * \param theEntryList - List of entries of published objects
1660 * \retval bool - TRUE if mesh is created, FALSE otherwise
1664 //================================================================================
1665 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1670 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1671 if ( aList.isEmpty() )
1673 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1674 if ( aSMESHGen->_is_nil() )
1677 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1678 if ( aMeshVar->_is_nil() )
1681 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1683 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1684 theEntryList.append( aMeshSO->GetID().c_str() );
1689 if ( aList.count() > 1 )
1691 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1692 int i = namePrefix.length() - 1;
1693 while ( i > 0 && namePrefix[i].isDigit() )
1695 if ( i < namePrefix.length() - 1 )
1696 namePrefix.chop( namePrefix.length() - 1 - i );
1700 QStringList::Iterator it = aList.begin();
1701 for ( int i = 0; it!=aList.end(); it++, ++i )
1703 QString aGeomEntry = *it;
1704 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1705 GEOM::GEOM_Object_var aGeomVar =
1706 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1708 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1709 if ( aSMESHGen->_is_nil() )
1712 SUIT_OverrideCursor aWaitCursor;
1715 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1716 if ( aMeshVar->_is_nil() )
1718 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1720 theEntryList.append( aMeshSO->GetID().c_str() );
1721 if ( i > 0 ) setDefaultName( namePrefix );
1722 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1725 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1727 if ( !isAccessibleDim( aDim )) continue;
1729 // assign hypotheses
1730 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1732 const int aHypIndex = currentHyp( aDim, dlgType );
1733 const int aHypType = Min( dlgType, AddHyp );
1734 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1736 SMESH::SMESH_Hypothesis_var aHypVar =
1737 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 dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1869 const int aHypIndex = currentHyp( aDim, dlgType );
1870 const int aHypType = Min( dlgType, AddHyp );
1871 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1873 SMESH::SMESH_Hypothesis_var aHypVar =
1874 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1875 if ( !aHypVar->_is_nil() )
1876 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1881 // deselect geometry: next submesh should be created on other sub-shape
1882 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1883 selectObject( _PTR(SObject)() );
1886 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1891 //================================================================================
1893 * \brief Gets current hypothesis or algorithms
1894 * \param theDim - dimension of hypothesis or algorithm
1895 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1896 * \retval int - current hypothesis or algorithms
1898 * Gets current hypothesis or algorithms
1900 //================================================================================
1901 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1903 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1906 //================================================================================
1908 * \brief Checks if a hypothesis is selected
1910 //================================================================================
1912 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
1914 if ( theHypType < AddHyp ) // only one hyp can be selected
1915 return currentHyp( theDim, theHypType ) == theIndex;
1917 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
1918 if ( currentHyp( theDim, dlgHypType ) == theIndex )
1924 //================================================================================
1926 * \brief Returns nb of HypType's taking into account possible several
1927 * selected additional hypotheses which are coded as additional HypType's.
1929 //================================================================================
1931 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
1933 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
1936 //================================================================================
1938 * \brief Returns true if hypotheses of given dim can be assigned
1939 * \param theDim - hypotheses dimension
1940 * \retval bool - result
1942 //================================================================================
1943 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1945 return myDlg->isTabEnabled( theDim );
1948 //================================================================================
1950 * \brief Sets current hypothesis or algorithms
1951 * \param theDim - dimension of hypothesis or algorithm
1952 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1953 * \param theIndex - Index of hypothesis
1955 * Gets current hypothesis or algorithms
1957 //================================================================================
1958 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1959 const int theHypType,
1960 const int theIndex )
1962 myIgnoreAlgoSelection = true;
1963 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1964 myIgnoreAlgoSelection = false;
1967 //================================================================================
1969 * \brief Generates default and sets mesh/submesh name
1971 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1973 //================================================================================
1974 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1978 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1981 QString aPrefix = thePrefix;
1982 if ( aPrefix.isEmpty() )
1983 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1985 _PTR(SObject) anObj;
1988 aResName = aPrefix + QString::number( i++ );
1989 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1993 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1994 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1995 aControl->setText( aResName );
1998 //================================================================================
2000 * \brief Gets algorithm or creates it if necessary
2001 * \param theDim - specifies dimension of returned hypotheses/algorifms
2002 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2004 * Gets algorithm or creates it if necessary
2006 //================================================================================
2007 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2009 SMESH::SMESH_Hypothesis_var anAlgoVar;
2011 // get type of the selected algo
2012 int aHypIndex = currentHyp( theDim, Algo );
2013 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2014 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2016 QString aHypName = dataList[ aHypIndex ]->TypeName;
2018 // get existing algoritms
2019 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
2021 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2023 // look for an existing algo of such a type
2024 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2025 THypList::iterator anIter = aHypVarList.begin();
2026 for ( ; anIter != aHypVarList.end(); anIter++)
2028 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2029 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2031 anAlgoVar = aHypVar;
2036 if (anAlgoVar->_is_nil())
2038 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2041 QString aClientLibName = aHypData->ClientLibName;
2042 if ( aClientLibName.isEmpty() )
2044 // Call hypothesis creation server method (without GUI)
2045 SMESH::SMESH_Hypothesis_var aHyp =
2046 SMESH::CreateHypothesis(aHypName, aHypName, true);
2051 // Get hypotheses creator client (GUI)
2052 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2056 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2058 SMESH::SMESH_Hypothesis_var aHyp =
2059 SMESH::CreateHypothesis(aHypName, aHypName, true);
2063 QStringList tmpList;
2064 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2065 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2068 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2069 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2071 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2072 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2074 anAlgoVar = aHypVar;
2080 return anAlgoVar._retn();
2083 //================================================================================
2085 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2087 * Called when mesh is edited only.
2089 //================================================================================
2090 void SMESHGUI_MeshOp::readMesh()
2092 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2093 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2097 if (myIsOnGeometry) {
2098 // Get name of mesh if current object is sub-mesh
2099 SMESH::SMESH_subMesh_var aSubMeshVar =
2100 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2101 if ( !aSubMeshVar->_is_nil() )
2103 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2104 if ( !aMeshVar->_is_nil() )
2106 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2107 QString aMeshName = name( aMeshSO );
2108 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2110 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2113 // Get name of geometry object
2114 CORBA::String_var name = SMESH::GetGeomName( pObj );
2116 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2119 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2120 QStringList anExisting;
2121 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2122 bool algoFound = false;
2123 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2126 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2127 // find algo index among available ones
2129 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2131 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2132 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2133 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2134 // if ( aHypIndex < 0 && algoData ) {
2135 // // assigned algo is incompatible with other algorithms
2136 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2137 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2139 algoFound = ( aHypIndex > -1 );
2141 setCurrentHyp( dim, Algo, aHypIndex );
2142 // set existing and available hypothesis according to the selected algo
2143 if ( aHypIndex > -1 || !algoFound )
2144 onAlgoSelected( aHypIndex, dim );
2148 bool hypWithoutAlgo = false;
2149 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2151 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2154 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2155 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2157 // find index of required hypothesis among existing ones for this dimension and type
2158 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2159 myExistingHyps[ dim ][ hypType ] );
2160 if ( aHypIndex < 0 ) {
2161 // assigned hypothesis is incompatible with the algorithm
2162 if ( currentHyp( dim, Algo ) < 0 )
2163 { // none algo selected; it is edition for sure, of submesh maybe
2164 hypWithoutAlgo = true;
2165 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2166 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2167 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2168 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2171 setCurrentHyp( dim, hypType + i, aHypIndex );
2173 if ( hypType == MainHyp ) break; // only one main hyp allowed
2177 // make available other hyps of same type as one without algo
2178 if ( hypWithoutAlgo )
2179 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2182 //================================================================================
2184 * \brief Gets name of object
2185 * \param theSO - SObject
2186 * \retval QString - name of object
2188 * Gets name of object
2190 //================================================================================
2191 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2196 _PTR(GenericAttribute) anAttr;
2197 _PTR(AttributeName) aNameAttr;
2198 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2201 aResName = aNameAttr->Value().c_str();
2207 //================================================================================
2209 * \brief Finds hypothesis in input list
2210 * \param theHyp - hypothesis to be found
2211 * \param theHypList - input list of hypotheses
2212 * \retval int - index of hypothesis or -1 if it is not found
2214 * Finds position of hypothesis in input list
2216 //================================================================================
2217 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2218 const THypList& theHypList ) const
2221 if ( !theHyp->_is_nil() )
2224 THypList::const_iterator anIter = theHypList.begin();
2225 for ( ; anIter != theHypList.end(); ++ anIter)
2227 if ( theHyp->_is_equivalent( (*anIter).first ) )
2238 //================================================================================
2240 * \brief Edits mesh or sub-mesh
2241 * \param theMess - Output parameter intended for returning error message
2242 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2244 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2246 //================================================================================
2247 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2251 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2252 if ( aSMESHGen->_is_nil() )
2255 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2256 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2260 SUIT_OverrideCursor aWaitCursor;
2263 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2264 SMESH::SetName( pObj, aName );
2265 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2267 // First, remove old algos in order to avoid messages on algorithm hiding
2268 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2270 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2272 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2273 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2274 if ( anAlgoVar->_is_nil() || // no new algo selected or
2275 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2277 // remove old algorithm
2278 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2279 myObjHyps[ dim ][ Algo ].clear();
2284 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2285 CORBA::Object_var anObject = aSObject->GetObject();
2286 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2287 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2288 bool isMesh = !aMeshVar->_is_nil();
2289 if ( !isMesh && !aSubMeshVar->_is_nil() )
2290 aMeshVar = aSubMeshVar->GetFather();
2292 // Assign new algorithms and hypotheses
2293 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2295 if ( !isAccessibleDim( dim )) continue;
2297 // find or create algorithm
2298 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2300 // assign new algorithm
2301 if ( !anAlgoVar->_is_nil() && // some algo selected and
2302 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2305 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2306 else if ( !aSubMeshVar->_is_nil() )
2307 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2309 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2312 // remove deselected hypotheses
2313 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2315 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2317 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2318 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2319 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2321 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2325 // assign newly selected hypotheses
2326 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2328 const int curIndex = currentHyp( dim, dlgType );
2329 const int hypType = Min( dlgType, AddHyp );
2330 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2332 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2334 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2338 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2339 else if ( !aSubMeshVar->_is_nil() )
2340 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2343 // reread all hypotheses of mesh
2344 QStringList anExisting;
2345 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2349 myHasConcurrentSubBefore =
2350 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2355 //================================================================================
2357 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2358 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2359 * order of sub-mesh computation.
2360 * Returns \c true if a sub-mesh concurrency detected.
2362 //================================================================================
2364 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2365 SMESH::SMESH_subMesh_ptr submesh,
2368 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2371 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2372 if ( isNewConcurrent && askUser )
2374 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2375 tr("CONCURRENT_SUBMESH_APPEARS"),
2376 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2379 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2380 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2381 if ( meshSO && aSelectionMgr )
2383 myDlg->setEnabled( false ); // disactivate selection
2384 selectionMgr()->clearFilters();
2385 selectObject( meshSO );
2386 SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2387 qApp->processEvents();
2389 myDlg->setEnabled( true );
2390 int obj = myDlg->getActiveObject();
2391 onActivateObject( obj ); // restore filter
2394 selectObject( SMESH::FindSObject( submesh ));
2401 return isNewConcurrent;
2404 //================================================================================
2406 * \brief Verifies whether given operator is valid for this one
2407 * \param theOtherOp - other operation
2408 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2410 * method redefined from base class verifies whether given operator is valid for
2411 * this one (i.e. can be started "above" this operator). In current implementation method
2412 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2415 //================================================================================
2416 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2418 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2421 //================================================================================
2423 * \brief SLOT. Is called when the user selects a way of geometry selection
2424 * \param theByMesh - true if the user wants to find geometry by mesh element
2426 //================================================================================
2427 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2430 if ( !myShapeByMeshOp ) {
2431 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2432 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2433 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2434 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2435 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2437 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2438 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2439 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2440 SMESH::SMESH_Mesh_var aMeshVar =
2441 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2442 if ( !aMeshVar->_is_nil() ) {
2443 myDlg->hide(); // stop processing selection
2444 myShapeByMeshOp->setModule( getSMESHGUI() );
2445 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2446 myShapeByMeshOp->SetMesh( aMeshVar );
2447 myShapeByMeshOp->start();
2453 //================================================================================
2455 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2457 //================================================================================
2458 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2460 if ( myShapeByMeshOp == op ) {
2461 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2463 // Select a found geometry object
2464 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2465 if ( !aGeomVar->_is_nil() )
2467 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2468 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2469 selectObject( aGeomSO );
2476 //================================================================================
2478 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2480 //================================================================================
2481 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2483 if ( myShapeByMeshOp == op && myDlg ) {
2488 //================================================================================
2490 * \brief Selects a SObject
2491 * \param theSObj - the SObject to select
2493 //================================================================================
2494 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2496 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2497 SALOME_ListIO anIOList;
2499 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2500 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2501 anIOList.Append( anIO );
2503 sm->setSelectedObjects( anIOList, false );
2506 //================================================================================
2508 * \brief Create available list types of mesh
2509 * \param theTypeMesh - Output list of available types of mesh
2511 //================================================================================
2512 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2514 theTypeMesh.clear();
2515 theTypeMesh.append( tr( "MT_ANY" ) );
2516 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2518 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2519 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2521 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2523 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2524 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2528 //================================================================================
2530 * \brief Set available types of mesh
2531 * \param theTypeMesh - List of available types of mesh
2533 //================================================================================
2534 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2536 myDlg->setAvailableMeshType( theTypeMesh );
2539 //================================================================================
2541 * \brief SLOT. Is called when the user select type of mesh
2542 * \param theTabIndex - Index of current active tab
2543 * \param theIndex - Index of current type of mesh
2545 //================================================================================
2546 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2548 setFilteredAlgoData( theTabIndex, theIndex);
2551 //================================================================================
2553 * \brief Set a filtered list of available algorithms by mesh type
2554 * \param theTabIndex - Index of current active tab
2555 * \param theIndex - Index of current type of mesh
2557 //================================================================================
2558 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2561 THypDataList anAvailableAlgsData;
2562 QStringList anAvailableAlgs;
2563 QString anCompareType = "";
2564 bool isAvailableChoiceAlgo = false;
2565 int anCurrentAvailableAlgo = 0;
2567 switch ( theIndex ) {
2569 anCompareType = "ANY";
2570 aDim = SMESH::DIM_3D;
2573 aDim = SMESH::DIM_2D;
2574 anCompareType = "TRIA";
2576 case MT_QUADRILATERAL:
2577 aDim = SMESH::DIM_2D;
2578 anCompareType = "QUAD";
2580 case MT_TETRAHEDRAL:
2581 aDim = SMESH::DIM_3D;
2582 anCompareType = "TETRA";
2585 aDim = SMESH::DIM_3D;
2586 anCompareType = "HEXA";
2591 bool toCheckIsApplicableToAll = !myIsMesh;
2592 GEOM::GEOM_Object_var aGeomVar;
2593 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2594 if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2596 CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
2597 aGeomVar = GEOM::GEOM_Object::_narrow( obj );
2598 if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
2599 toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
2602 if ( anCompareType == "ANY" )
2604 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2606 isNone = currentHyp( dim, Algo ) < 0;
2607 isAvailableChoiceAlgo = false;
2608 // retrieves a list of available algorithms from resources
2609 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2610 //return current algo in current tab and set new algorithm list
2611 HypothesisData* algoCur;
2612 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2613 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2615 myAvailableHypData[dim][Algo].clear();
2616 anAvailableAlgs.clear();
2617 if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
2618 myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
2619 !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
2621 for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2623 HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2624 if ( aGeomVar->_is_nil() ||
2625 SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2627 anAvailableAlgs.append( curAlgo->Label );
2628 myAvailableHypData[dim][Algo].append( curAlgo );
2631 if ( !isNone && algoCur ) {
2632 for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2634 HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2635 if ( algoAny->Label == algoCur->Label ){
2636 isAvailableChoiceAlgo = true;
2637 anCurrentAvailableAlgo = i;
2642 else if ( !isNone ) {
2643 isAvailableChoiceAlgo = true;
2644 anCurrentAvailableAlgo = currentHyp( dim, Algo );
2647 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2648 if ( isAvailableChoiceAlgo )
2649 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2651 if ( !myIsOnGeometry )
2652 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2653 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2654 else myDlg->enableTab( i );
2657 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2658 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2659 else myDlg->enableTab( i );
2661 myDlg->setCurrentTab( theTabIndex );
2665 QString anCurrentAlgo;
2666 bool isReqDisBound = true;
2667 QString anCurrentCompareType = anCompareType;
2668 isNone = currentHyp( aDim, Algo ) < 0;
2669 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2670 myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2671 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2673 isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2674 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2676 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2677 isAvailableChoiceAlgo = false;
2678 // retrieves a list of available algorithms from resources
2679 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2680 // finding algorithm which is selected
2681 if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2682 myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2683 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2684 else if ( !isNoneAlg )
2685 anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2686 anAvailableAlgs.clear();
2687 myAvailableHypData[dim][Algo].clear();
2688 myFilteredAlgoData[dim].clear();
2689 // finding and adding algorithm depending on the type mesh
2690 for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2692 HypothesisData* algoIn = anAvailableAlgsData.at( i );
2693 bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2694 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2695 for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2697 if ( *inElemType == anCurrentCompareType ) {
2698 isAvailableAlgo = true;
2702 if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
2703 if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2704 SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2706 anAvailableAlgs.append( algoIn->Label );
2707 myAvailableHypData[dim][Algo].append( algoIn );
2708 myFilteredAlgoData[dim].append( algoIn );
2711 //algorithm will be active, if the chosen algorithm available in the current mesh type
2712 if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
2713 isAvailableChoiceAlgo = true;
2714 anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2717 //set new algorithm list and select the current algorithm
2718 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2719 anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2720 if ( isAvailableChoiceAlgo )
2721 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2723 setCurrentHyp( dim, Algo, -1 );
2726 if ( isNone || isReqDisBound ) {
2727 for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
2729 myDlg->disableTab( i );
2730 setCurrentHyp(i, Algo, -1);
2734 else if ( !isNone ) {
2735 if ( aDim == SMESH::DIM_2D){
2736 myDlg->disableTab( SMESH::DIM_3D );
2737 setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2739 for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
2741 isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2742 myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2743 if ( isReqDisBound ) {
2744 for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2745 myDlg->disableTab( j );
2746 setCurrentHyp( j , Algo, -1 );
2752 myDlg->enableTab( aDim );
2753 myDlg->setCurrentTab( aDim );
2755 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2756 QStringList aFilteredHypothesesSetsList;
2757 aFilteredHypothesesSetsList.clear();
2758 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2759 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2761 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2762 bool isAvailable = false;
2763 currentHypoSet->init( true );
2764 while ( currentHypoSet->next(), currentHypoSet->more() )
2766 isAvailable = false;
2767 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2769 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
2771 if ( myAvailableHypData[i][Algo].count() == 0 ) {
2772 availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
2773 for ( int j = 0 ; j < anAvailableAlgsData.count(); j++ )
2775 HypothesisData* aCurAlgo = anAvailableAlgsData.at( j );
2776 if ( aCurAlgo->Label == algoDataIn->Label ){
2783 for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2784 HypothesisData* aCurAlgo = hypData( i, Algo, j );
2785 if ( aCurAlgo->Label == algoDataIn->Label ){
2791 if ( isAvailable ) break;
2793 if ( !isAvailable ) break;
2797 aFilteredHypothesesSetsList.append( *inHypoSetName );
2799 myDlg->setHypoSets( aFilteredHypothesesSetsList );