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! */
366 while( !mainObj->_is_nil()) {
367 CORBA::String_var entry1 = mainObj->GetEntry();
368 CORBA::String_var entry2 = mainGeom->GetEntry();
369 if (std::string( entry1.in() ) == entry2.in() )
371 mainObj = op->GetMainShape(mainObj);
373 if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
375 // is aSubGeomVar a compound of sub-shapes?
376 GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations(aStudy->StudyId());
377 if (sop->_is_nil()) return false;
378 GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
379 GEOM::SHAPE,/*sorted=*/false);
380 if ( ids->length() > 0 )
383 GEOM::GEOM_Object_var compSub = geomGen->AddSubShape( aSubGeomVar, ids );
384 if ( !compSub->_is_nil() )
386 GEOM::ListOfGO_var shared = sop->GetSharedShapes( mainGeom,
388 compSub->GetShapeType() );
389 geomGen->RemoveObject( compSub );
390 if ( shared->length() > 0 )
391 geomGen->RemoveObject( shared[0] );
392 return ( shared->length() > 0 );
402 //================================================================================
404 * \brief Return name of the algorithm that does not support submeshes and makes
405 * submesh creation useless
406 * \retval char* - string is to be deleted!!!
408 //================================================================================
409 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
411 if ( myToCreate && !myIsMesh ) {
413 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
414 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
415 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
418 QStringList algoNames;
420 existingHyps(3, Algo, pMesh, algoNames, algoList);
421 if (!algoList.empty()) {
422 HypothesisData* algo =
423 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
425 algo->InputTypes.empty() && // builds all dimensions it-self
426 !algo->IsSupportSubmeshes )
427 return CORBA::string_dup( algoNames[0].toLatin1().data() );
430 // GEOM::GEOM_Object_var geom;
431 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
432 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
434 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
435 existingHyps(2, Algo, pMesh, algoNames, algoList);
436 if (!algoList.empty()) {
437 HypothesisData* algo =
438 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
440 algo->InputTypes.empty() && // builds all dimensions it-self
441 !algo->IsSupportSubmeshes )
442 return CORBA::string_dup( algoNames[0].toLatin1().data() );
450 //================================================================================
452 * \brief find an existing submesh by the selected shape
453 * \retval _PTR(SObject) - the found submesh SObject
455 //================================================================================
456 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
458 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
459 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
460 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
461 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
462 if ( pMesh && pGeom ) {
463 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
464 if ( !geom->_is_nil() ) {
466 switch ( geom->GetShapeType() ) {
467 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
468 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
469 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
470 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
471 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
472 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
473 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
476 _PTR(GenericAttribute) anAttr;
477 _PTR(SObject) aSubmeshRoot;
478 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
479 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
481 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
482 for ( ; smIter->More(); smIter->Next() )
484 _PTR(SObject) aSmObj = smIter->Value();
485 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
487 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
488 for ( ; anIter1->More(); anIter1->Next()) {
489 _PTR(SObject) pGeom2 = anIter1->Value();
490 if ( pGeom2->ReferencedObject( pGeom2 ) &&
491 pGeom2->GetID() == pGeom->GetID() )
498 return _PTR(SObject)();
501 //================================================================================
503 * \brief Updates dialog's look and feel
505 * Virtual method redefined from the base class updates dialog's look and feel
507 //================================================================================
508 void SMESHGUI_MeshOp::selectionDone()
510 if (!dlg()->isVisible() || !myDlg->isEnabled())
513 SMESHGUI_SelectionOp::selectionDone();
517 myIsOnGeometry = true;
519 //Check geometry for mesh
520 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
521 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
524 SMESH::SMESH_Mesh_var aMeshVar =
525 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
526 if (!aMeshVar->_is_nil()) {
527 if (!myToCreate && !aMeshVar->HasShapeToMesh())
528 myIsOnGeometry = false;
534 // Enable tabs according to shape dimension
539 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
540 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
542 if (aGEOMs.count() > 0) {
543 // one or more GEOM shape selected
544 aSeq->length(aGEOMs.count());
545 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
547 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
548 QString aSubGeomEntry = (*aSubShapesIter);
549 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
550 GEOM::GEOM_Object_var aSubGeomVar =
551 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
552 aSeq[iSubSh] = aSubGeomVar;
555 // get geometry by selected sub-mesh
556 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
557 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
558 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
559 if (!aGeomVar->_is_nil()) {
565 if (aSeq->length() > 0) {
567 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
568 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
569 switch ( aGeomVar->GetShapeType() ) {
570 case GEOM::SOLID: shapeDim = 3; break;
572 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
574 // TopoDS_Shape aShape;
575 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
576 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
579 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
581 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
582 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
586 if (GEOMBase::GetShape(aGeomVar, aShape))
588 TopExp_Explorer exp (aShape, TopAbs_SOLID);
592 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
593 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
596 // for (; exp.More() && shapeDim == 2; exp.Next()) {
597 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
601 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
602 shapeDim = qMax(2, shapeDim);
603 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
604 shapeDim = qMax(1, shapeDim);
605 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
606 shapeDim = qMax(0, shapeDim);
614 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
615 // reset algos before disabling tabs (0020138)
616 onAlgoSelected(-1, i);
618 myDlg->setMaxHypoDim( shapeDim );
619 myMaxShapeDim = shapeDim;
620 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
622 if (!myToCreate) // edition: read hypotheses
626 SMESH::SMESH_subMesh_var submeshVar =
627 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
628 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
629 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
630 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
631 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
632 myDlg->updateGeometry();
634 myIsMesh = submeshVar->_is_nil();
640 else if ( !myIsMesh ) // submesh creation
642 // if a submesh on the selected shape already exist, pass to submesh edition mode
643 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
644 SMESH::SMESH_subMesh_var sm =
645 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
646 bool editSubmesh = ( !sm->_is_nil() &&
647 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
648 tr( "EDIT_SUBMESH_QUESTION"),
649 SUIT_MessageBox::Yes |
651 SUIT_MessageBox::No )
652 == SUIT_MessageBox::Yes );
655 selectionMgr()->clearFilters();
656 selectObject( pSubmesh );
657 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
662 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
663 selectObject( _PTR(SObject)() );
668 // discard selected mesh if submesh creation not allowed because of
669 // a global algorithm that does not support submeshes
670 if ( char* algoName = isSubmeshIgnored() ) {
671 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
672 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
673 CORBA::string_free( algoName );
674 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
675 selectObject( _PTR(SObject)() );
680 // enable/disable popup for choice of geom selection way
682 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
683 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
684 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
685 if ( !mesh->_is_nil() ) {
686 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
687 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
688 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
689 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
690 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
691 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
694 myDlg->setGeomPopupEnabled( enable );
697 else { // no geometry defined
698 myDlg->enableTab( SMESH::DIM_3D );
700 availableHyps( SMESH::DIM_3D, Algo, hypList,
701 myAvailableHypData[SMESH::DIM_3D][Algo]);
703 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
704 aTab->setAvailableHyps( Algo, hypList );
705 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
706 myDlg->disableTab(i);
709 //Hide labels and fields (Mesh and Geometry)
710 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
711 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
715 int curIndex = myDlg->currentMeshType( );
716 QStringList TypeMeshList;
717 createMeshTypeList( TypeMeshList );
718 setAvailableMeshType( TypeMeshList );
719 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
720 myDlg->setCurrentMeshType( curIndex );
721 setFilteredAlgoData( myMaxShapeDim, curIndex);
723 catch ( const SALOME::SALOME_Exception& S_ex )
725 SalomeApp_Tools::QtCatchCorbaException( S_ex );
732 //================================================================================
734 * \brief Verifies validity of input data
735 * \param theMess - Output parameter intended for returning error message
736 * \retval bool - TRUE if input data is valid, false otherwise
738 * Verifies validity of input data. This method is called when "Apply" or "OK" button
739 * is pressed before mesh creation or editing.
741 //================================================================================
742 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
744 // Selected object to be edited
745 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
747 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
752 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
753 if ( aMeshName.isEmpty() )
755 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
759 /* // Imported mesh, if create sub-mesh or edit mesh
760 if ( !myToCreate || ( myToCreate && !myIsMesh ))
762 QString aMeshEntry = myDlg->selectedObject
763 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
764 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
765 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
766 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
767 theMess = tr( "IMPORTED_MESH" );
776 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
777 if ( aGeomEntry.isEmpty() )
779 theMess = tr( myIsMesh ?
780 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
781 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
785 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
786 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
793 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
794 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
796 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
801 if ( !myIsMesh ) // i.e sub-mesh creation,
803 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
804 if ( aMeshEntry == "" )
806 theMess = tr( "MESH_IS_NOT_DEFINED" );
809 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
810 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
812 theMess = tr( "MESH_IS_NULL" );
815 if ( !isSubshapeOk() )
817 theMess = tr( "INVALID_SUBSHAPE" );
826 //================================================================================
828 * \brief check compatibility of the algorithm and another algorithm or hypothesis
829 * \param theAlgoData - algorithm data
830 * \param theHypData - hypothesis data
831 * \param theHypType - hypothesis type
832 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
833 * \retval bool - check result
835 //================================================================================
836 static bool isCompatible(const HypothesisData* theAlgoData,
837 const HypothesisData* theHypData,
838 const int theHypType)
843 if ( theHypType == SMESHGUI_MeshOp::Algo )
844 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
847 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
850 //================================================================================
852 * \brief Gets available hypotheses or algorithms
853 * \param theDim - specifies dimension of returned hypotheses/algorifms
854 * \param theHypType - specifies whether algorims or hypotheses or additional ones
855 * are retrieved (possible values are in HypType enumeration)
856 * \param theHyps - Output list of hypotheses' names
857 * \param theAlgoData - to select hypos able to be used by this algo (optional)
859 * Gets available hypotheses or algorithm in accordance with input parameters
861 //================================================================================
862 void SMESHGUI_MeshOp::availableHyps( const int theDim,
863 const int theHypType,
864 QStringList& theHyps,
865 THypDataList& theDataList,
866 HypothesisData* theAlgoData ) const
870 bool isAlgo = ( theHypType == Algo );
871 bool isAux = ( theHypType >= AddHyp );
872 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
874 QStringList::const_iterator anIter;
875 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
877 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
878 if ( isCompatible ( theAlgoData, aData, theHypType )) {
879 theDataList.append( aData );
880 theHyps.append( aData->Label );
885 //================================================================================
887 * \brief Gets existing hypotheses or algorithms
888 * \param theDim - specifies dimension of returned hypotheses/algorifms
889 * \param theHypType - specifies whether algorims or hypotheses or additional ones
890 * are retrieved (possible values are in HypType enumeration)
891 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
892 * \param theHyps - output list of names.
893 * \param theHypVars - output list of variables.
894 * \param theAlgoData - to select hypos able to be used by this algo (optional)
896 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
899 * WARNING: when using this method to get hyps existing in Mesh component,
900 * call availableHyps() before in order to get only hyps of available types
901 * that was filtered by availableHyps()
903 //================================================================================
904 void SMESHGUI_MeshOp::existingHyps( const int theDim,
905 const int theHypType,
906 _PTR(SObject) theFather,
907 QStringList& theHyps,
908 THypList& theHypList,
909 HypothesisData* theAlgoData) const
911 // Clear hypoheses list
918 _PTR(SObject) aHypRoot;
919 _PTR(GenericAttribute) anAttr;
920 _PTR(AttributeName) aName;
921 _PTR(AttributeIOR) anIOR;
923 const bool isMesh = !_CAST( SComponent, theFather );
926 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
928 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
930 const bool isAux = ( theHypType >= AddHyp );
931 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
933 if ( theFather->FindSubObject( aPart, aHypRoot ) )
935 _PTR(ChildIterator) anIter =
936 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
937 for ( ; anIter->More(); anIter->Next() )
939 _PTR(SObject) anObj = anIter->Value();
940 if ( isMesh ) // i.e. mesh or submesh
942 _PTR(SObject) aRefObj;
943 if ( anObj->ReferencedObject( aRefObj ) )
948 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
951 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
952 if ( !CORBA::is_nil( aVar ) )
954 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
955 if ( !aHypVar->_is_nil() )
957 CORBA::String_var hypType = aHypVar->GetName();
958 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
959 if ( !aData) continue;
960 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
961 ( isCompatible ( theAlgoData, aData, theHypType )) &&
962 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
963 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
965 std::string aHypName = aName->Value();
966 theHyps.append( aHypName.c_str() );
967 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
976 //================================================================================
978 * \brief If create or edit a submesh, return a hypothesis holding parameters used
979 * to mesh a sub-shape
980 * \param aHypType - The hypothesis type name
981 * \param aServerLib - Server library name
982 * \param hypData - The structure holding the hypothesis type etc.
983 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
985 //================================================================================
986 SMESH::SMESH_Hypothesis_var
987 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
988 const QString& aServerLib ) const
990 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
991 return SMESH::SMESH_Hypothesis::_nil();
993 const int nbColonsInMeshEntry = 3;
994 bool isSubMesh = myToCreate ?
996 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
998 // get mesh and geom object
999 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
1000 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1005 anEntry = myDlg->selectedObject
1006 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1007 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1009 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1010 if ( myToCreate ) // mesh and geom may be selected
1012 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
1013 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1014 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1015 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1017 else // edition: sub-mesh may be selected
1019 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1020 if ( !sm->_is_nil() ) {
1021 aMeshVar = sm->GetFather();
1022 aGeomVar = sm->GetSubShape();
1029 if ( !myToCreate ) // mesh to edit can be selected
1031 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1032 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1034 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1035 if ( !aMeshVar->_is_nil() )
1036 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1039 if ( aGeomVar->_is_nil() ) {
1040 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1041 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1043 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1048 SMESH::SMESH_Hypothesis_var hyp =
1049 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1050 aServerLib.toLatin1().data(),
1053 /*byMesh = */isSubMesh);
1054 if ( hyp->_is_nil() && isSubMesh )
1055 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1056 aServerLib.toLatin1().data(),
1059 /*byMesh = */false);
1063 //================================================================================
1065 * \brief initialize a hypothesis creator
1067 //================================================================================
1069 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1071 if ( !theCreator ) return;
1073 // Set shapes, of mesh and sub-mesh if any
1075 // get Entry of the Geom object
1076 QString aGeomEntry = "";
1077 QString aMeshEntry = "";
1078 QString anObjEntry = "";
1079 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1080 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1081 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1083 if ( myToCreate && myIsMesh )
1084 aMeshEntry = aGeomEntry;
1086 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1087 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1088 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1089 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1092 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1093 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1095 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1096 if ( !aGeomVar->_is_nil() )
1098 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1100 aMeshEntry = aGeomEntry;
1104 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1105 // take geometry from submesh being created
1106 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1108 // if current object is sub-mesh
1109 SMESH::SMESH_subMesh_var aSubMeshVar =
1110 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1111 if ( !aSubMeshVar->_is_nil() ) {
1112 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1113 if ( !aMeshVar->_is_nil() ) {
1114 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1115 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1116 if ( !aGeomVar->_is_nil() )
1117 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1123 theCreator->setShapeEntry( aGeomEntry );
1124 if ( aMeshEntry != "" )
1125 theCreator->setMainShapeEntry( aMeshEntry );
1128 //================================================================================
1130 * \Brief Returns tab dimention
1131 * \param tab - the tab in the dlg
1132 * \param dlg - my dialogue
1133 * \retval int - dimention
1135 //================================================================================
1136 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1139 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1140 if (tab == dlg->tab(i))
1145 //================================================================================
1147 * \brief Create hypothesis
1148 * \param theHypType - hypothesis category (main or additional)
1149 * \param theIndex - index of type of hypothesis to be cerated
1151 * Specifies dimension of hypothesis to be created (using sender() method),
1152 * specifies its type and calls method for hypothesis creation
1154 //================================================================================
1155 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1157 // Specifies dimension of hypothesis to be created
1158 int aDim = getTabDim( sender(), myDlg );
1162 // Specifies type of hypothesis to be created
1163 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1164 if (theIndex < 0 || theIndex >= dataList.count())
1166 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1168 // Create hypothesis
1169 createHypothesis(aDim, theHypType, aHypTypeName);
1174 QString GetUniqueName (const QStringList& theHypNames,
1175 const QString& theName,
1176 size_t theIteration = 1)
1178 QString aName = theName + "_" + QString::number( theIteration );
1179 if ( theHypNames.contains( aName ) )
1180 return GetUniqueName( theHypNames, theName, ++theIteration );
1185 //================================================================================
1187 * Create hypothesis and update dialog.
1188 * \param theDim - dimension of hypothesis to be created
1189 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1190 * \param theTypeName - specifies hypothesis to be created
1192 //================================================================================
1193 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1195 const QString& theTypeName)
1197 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1204 // get a unique hyp name
1205 QStringList aHypNames;
1206 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1207 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1208 const TType2HypList& aType2HypList = aDimIter.value();
1209 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1210 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1211 const THypList& aHypList = aTypeIter.value();
1212 THypList::const_iterator anIter = aHypList.begin();
1213 for ( ; anIter != aHypList.end(); anIter++) {
1214 const THypItem& aHypItem = *anIter;
1215 const QString& aHypName = aHypItem.second;
1216 aHypNames.append(aHypName);
1220 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1223 bool dialog = false;
1225 QString aClientLibName = aData->ClientLibName;
1226 if (aClientLibName == "") {
1227 // Call hypothesis creation server method (without GUI)
1228 SMESH::SMESH_Hypothesis_var aHyp =
1229 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1233 // Get hypotheses creator client (GUI)
1234 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1236 // Create hypothesis
1239 // Get parameters appropriate to initialize a new hypothesis
1240 SMESH::SMESH_Hypothesis_var initParamHyp =
1241 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1243 removeCustomFilters(); // Issue 0020170
1245 // set shapes, of mesh and sub-mesh if any
1246 initHypCreator( aCreator );
1248 myDlg->setEnabled( false );
1249 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1253 SMESH::SMESH_Hypothesis_var aHyp =
1254 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1263 //================================================================================
1265 * Necessary steps after hypothesis creation
1266 * \param result - creation result:
1269 * 2 = additional value meaning that slot is called not from dialog box
1271 //================================================================================
1272 void SMESHGUI_MeshOp::onHypoCreated( int result )
1276 int obj = myDlg->getActiveObject();
1277 onActivateObject( obj ); // Issue 0020170. Restore filters
1278 myDlg->setEnabled( true );
1281 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1283 int nbHyp = myExistingHyps[myDim][myType].count();
1284 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1285 QStringList aNewHyps;
1286 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1287 if (aNewHyps.count() > nbHyp)
1289 for (int i = nbHyp; i < aNewHyps.count(); i++)
1290 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1293 if( result!=2 && myHypoSet )
1297 //================================================================================
1299 * \brief Calls plugin methods for hypothesis editing
1300 * \param theHypType - specifies whether main hypothesis or additional one
1302 * \param theIndex - index of existing hypothesis
1304 * Calls plugin methods for hypothesis editing
1306 //================================================================================
1307 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1309 // Speicfies dimension of hypothesis to be created
1310 int aDim = getTabDim( sender(), myDlg );
1314 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1315 if ( theIndex < 0 || theIndex >= aList.count() )
1317 const THypItem& aHypItem = aList[ theIndex ];
1318 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1319 if ( aHyp->_is_nil() )
1322 SMESHGUI_GenericHypothesisCreator* aCreator =
1323 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1326 // set initial parameters
1327 SMESH::SMESH_Hypothesis_var initParamHyp =
1328 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1329 SMESH::toQStr( aHyp->GetLibName() ));
1330 aCreator->setInitParamsHypothesis( initParamHyp );
1332 // set shapes, of mesh and sub-mesh if any
1333 initHypCreator( aCreator );
1335 removeCustomFilters(); // Issue 0020170
1336 myDlg->setEnabled( false );
1338 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1342 //================================================================================
1344 * Necessary steps after hypothesis edition
1345 * \param result - creation result:
1349 //================================================================================
1350 void SMESHGUI_MeshOp::onHypoEdited( int result )
1352 int obj = myDlg->getActiveObject();
1353 onActivateObject( obj ); // Issue 0020170. Restore filters
1354 myDlg->setEnabled( true );
1357 //================================================================================
1359 * \brief access to hypothesis data
1360 * \param theDim - hyp dimension
1361 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1362 * \param theIndex - index in the list
1363 * \retval HypothesisData* - result data, may be 0
1365 //================================================================================
1366 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1367 const int theHypType,
1370 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1371 theHypType > -1 && theHypType < NbHypTypes &&
1372 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1373 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1377 //================================================================================
1379 * \brief Set available algos and hypos according to the selected algorithm
1380 * \param theIndex - algorithm index
1382 //================================================================================
1383 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1386 if ( myIgnoreAlgoSelection )
1389 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1393 // find highest available dimension, all algos of this dimension are available for choice
1395 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1396 if (isAccessibleDim( i ))
1401 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1403 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1404 HypothesisData* algoByDim[4];
1405 algoByDim[ aDim ] = algoData;
1407 QStringList anAvailable;
1409 // check that tab enabled of one less dimension
1410 if ( aDim > SMESH::DIM_0D )
1412 if ( isAccessibleDim( aDim - 1 ) )
1414 if (( myDlg->currentMeshType() != MT_ANY ) &&
1415 ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1416 for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1417 if ( isAccessibleDim( i ) ) {
1418 myDlg->disableTab( i );
1419 setCurrentHyp(i, Algo, -1);
1422 else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1424 myDlg->enableTab( aDim - 1 );
1428 // check that algorithms of other dimentions are compatible with
1430 if ( !algoData ) { // all algos becomes available
1431 if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
1432 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1434 anAvailable.clear();
1435 for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1436 HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1437 anAvailable.append( aCurAlgo->Label );
1440 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1442 // 2 loops: backward and forward from algo dimension
1443 for ( int forward = false; forward <= true; ++forward )
1445 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1447 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1449 HypothesisData* prevAlgo = algoData;
1450 bool noCompatible = false;
1451 for ( ; dim * dir <= lastDim * dir; dim += dir)
1453 if ( !isAccessibleDim( dim ))
1455 if ( noCompatible ) { // the selected algo has no compatible ones
1456 anAvailable.clear();
1457 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1458 myAvailableHypData[dim][Algo].clear();
1459 algoByDim[ dim ] = 0;
1462 // get currently selected algo
1463 int algoIndex = currentHyp( dim, Algo );
1464 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1465 if ( curAlgo ) { // some algo selected
1466 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1469 // set new available algoritms
1470 if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1471 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1473 anAvailable.clear();
1474 myAvailableHypData[dim][Algo].clear();
1475 for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1476 HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1477 if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1478 anAvailable.append( aCurAlgo->Label );
1479 myAvailableHypData[dim][Algo].append( aCurAlgo );
1483 HypothesisData* soleCompatible = 0;
1484 if ( anAvailable.count() == 1 )
1485 soleCompatible = myAvailableHypData[dim][Algo][0];
1486 if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1487 if (myDlg->currentMeshType() == MT_ANY)
1488 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1490 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1491 noCompatible = anAvailable.isEmpty();
1493 // restore previously selected algo
1494 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1495 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1496 // select the sole compatible algo
1497 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1498 setCurrentHyp( dim, Algo, algoIndex);
1500 // remember current algo
1501 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1505 // set hypotheses corresponding to the found algoritms
1507 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1509 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1511 if ( !isAccessibleDim( dim ))
1514 // get indices of selected hyps
1515 const int nbTypes = nbDlgHypTypes(dim);
1516 std::vector<int> hypIndexByType( nbTypes, -1 );
1517 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1519 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1523 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1525 const int type = Min( dlgType, AddHyp );
1526 myAvailableHypData[ dim ][ type ].clear();
1527 QStringList anAvailable, anExisting;
1529 HypothesisData* curAlgo = algoByDim[ dim ];
1530 int hypIndex = hypIndexByType[ dlgType ];
1532 SMESH::SMESH_Hypothesis_var curHyp;
1533 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1534 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1536 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1537 // try to find algo by selected hypothesis in order to keep it selected
1538 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1539 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1540 if ( !algoDeselectedByUser &&
1541 myObjHyps[ dim ][ type ].count() > 0 &&
1542 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1544 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1545 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1546 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1547 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1554 // get hyps compatible with curAlgo
1555 bool defaulHypAvlbl = false;
1558 // check if a selected hyp is compatible with the curAlgo
1559 if ( !curHyp->_is_nil() ) {
1560 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1561 if ( !isCompatible( curAlgo, hypData, type ))
1562 curHyp = SMESH::SMESH_Hypothesis::_nil();
1564 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1565 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1566 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1568 // set list of hypotheses
1569 if ( dlgType <= AddHyp )
1571 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1572 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1574 // set current existing hypothesis
1575 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1576 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1579 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 ) {
1580 // none is yet selected => select the sole existing if it is not optional
1581 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1582 bool isOptional = true;
1583 if ( algoByDim[ dim ] &&
1584 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1588 setCurrentHyp( dim, dlgType, hypIndex );
1593 //================================================================================
1595 * \brief Creates and selects hypothesis of hypotheses set
1596 * \param theSetName - The name of hypotheses set
1598 //================================================================================
1599 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1601 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1606 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1607 setCurrentHyp(dim, Algo, -1);
1608 setCurrentHyp(dim, AddHyp, -1);
1609 setCurrentHyp(dim, MainHyp, -1);
1612 myHypoSet->init(true); //algorithms
1614 myHypoSet->init(false); //hypotheses
1619 //================================================================================
1621 * \brief One step of hypothesis/algorithm list creation
1623 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1625 //================================================================================
1626 void SMESHGUI_MeshOp::processSet()
1629 if( !myHypoSet->more() )
1632 bool isAlgo = myHypoSet->isAlgo();
1633 QString aHypoTypeName = myHypoSet->current();
1634 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1641 int aDim = aHypData->Dim[0];
1642 // create or/and set
1645 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1648 QStringList anAvailable;
1649 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1650 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1651 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1653 setCurrentHyp( aDim, Algo, index );
1654 onAlgoSelected( index, aDim );
1659 bool mainHyp = true;
1660 QStringList anAvailable;
1661 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1662 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1663 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1667 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1670 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1676 //================================================================================
1678 * \brief Creates mesh
1679 * \param theMess - Output parameter intended for returning error message
1680 * \param theEntryList - List of entries of published objects
1681 * \retval bool - TRUE if mesh is created, FALSE otherwise
1685 //================================================================================
1686 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1691 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1692 if ( aList.isEmpty() )
1694 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1695 if ( aSMESHGen->_is_nil() )
1698 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1699 if ( aMeshVar->_is_nil() )
1702 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1704 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1705 theEntryList.append( aMeshSO->GetID().c_str() );
1710 if ( aList.count() > 1 )
1712 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1713 int i = namePrefix.length() - 1;
1714 while ( i > 0 && namePrefix[i].isDigit() )
1716 if ( i < namePrefix.length() - 1 )
1717 namePrefix.chop( namePrefix.length() - 1 - i );
1721 QStringList::Iterator it = aList.begin();
1722 for ( int i = 0; it!=aList.end(); it++, ++i )
1724 QString aGeomEntry = *it;
1725 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1726 GEOM::GEOM_Object_var aGeomVar =
1727 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1729 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1730 if ( aSMESHGen->_is_nil() )
1733 SUIT_OverrideCursor aWaitCursor;
1736 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1737 if ( aMeshVar->_is_nil() )
1739 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1741 theEntryList.append( aMeshSO->GetID().c_str() );
1742 if ( i > 0 ) setDefaultName( namePrefix );
1743 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1746 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1748 if ( !isAccessibleDim( aDim )) continue;
1750 // assign hypotheses
1751 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1753 const int aHypIndex = currentHyp( aDim, dlgType );
1754 const int aHypType = Min( dlgType, AddHyp );
1755 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1757 SMESH::SMESH_Hypothesis_var aHypVar =
1758 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1759 if ( !aHypVar->_is_nil() )
1760 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1763 // find or create algorithm
1764 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1765 if ( !anAlgoVar->_is_nil() )
1766 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1772 //================================================================================
1774 * \brief Creates sub-mesh
1775 * \param theMess - Output parameter intended for returning error message
1776 * \param theEntryList - List of entries of published objects
1777 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1781 //================================================================================
1782 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1786 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1787 if ( aSMESHGen->_is_nil() )
1791 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1792 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1793 SMESH::SMESH_Mesh_var aMeshVar =
1794 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1795 if (aMeshVar->_is_nil())
1798 // GEOM shape of the main mesh
1799 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1801 // Name for the new sub-mesh
1802 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1805 GEOM::GEOM_Object_var aGeomVar;
1807 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1808 if (aGEOMs.count() == 1)
1810 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1811 QString aGeomEntry = aGEOMs.first();
1812 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1813 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1815 else if (aGEOMs.count() > 1)
1817 // create a GEOM group
1818 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1819 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1820 if (!geomGen->_is_nil() && aStudy) {
1821 GEOM::GEOM_IGroupOperations_wrap op =
1822 geomGen->GetIGroupOperations(aStudy->StudyId());
1823 if (!op->_is_nil()) {
1824 // check and add all selected GEOM objects: they must be
1825 // a sub-shapes of the main GEOM and must be of one type
1827 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1828 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1829 aSeq->length(aGEOMs.count());
1830 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1831 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1832 QString aSubGeomEntry = (*aSubShapesIter);
1833 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1834 GEOM::GEOM_Object_var aSubGeomVar =
1835 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1836 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1838 aGroupType = aSubShapeType;
1840 if (aSubShapeType != aGroupType)
1841 aGroupType = TopAbs_SHAPE;
1843 aSeq[iSubSh] = aSubGeomVar;
1846 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1847 op->UnionList(aGroupVar, aSeq);
1851 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1853 // publish the GEOM group in study
1854 QString aNewGeomGroupName ("Auto_group_for_");
1855 aNewGeomGroupName += aName;
1856 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1857 SALOMEDS::SObject_wrap aNewGroupSO =
1858 geomGen->AddInStudy( aStudyVar, aGeomVar,
1859 aNewGeomGroupName.toLatin1().data(), mainGeom);
1866 if (aGeomVar->_is_nil())
1869 SUIT_OverrideCursor aWaitCursor;
1872 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1873 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1875 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1876 theEntryList.append( aSubMeshSO->GetID().c_str() );
1879 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1881 if ( !isAccessibleDim( aDim )) continue;
1883 // find or create algorithm
1884 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1885 if ( !anAlgoVar->_is_nil() )
1886 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1887 // assign hypotheses
1888 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1890 const int aHypIndex = currentHyp( aDim, dlgType );
1891 const int aHypType = Min( dlgType, AddHyp );
1892 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1894 SMESH::SMESH_Hypothesis_var aHypVar =
1895 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1896 if ( !aHypVar->_is_nil() )
1897 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1902 // deselect geometry: next submesh should be created on other sub-shape
1903 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1904 selectObject( _PTR(SObject)() );
1907 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1912 //================================================================================
1914 * \brief Gets current hypothesis or algorithms
1915 * \param theDim - dimension of hypothesis or algorithm
1916 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1917 * \retval int - current hypothesis or algorithms
1919 * Gets current hypothesis or algorithms
1921 //================================================================================
1922 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1924 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1927 //================================================================================
1929 * \brief Checks if a hypothesis is selected
1931 //================================================================================
1933 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
1935 if ( theHypType < AddHyp ) // only one hyp can be selected
1936 return currentHyp( theDim, theHypType ) == theIndex;
1938 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
1939 if ( currentHyp( theDim, dlgHypType ) == theIndex )
1945 //================================================================================
1947 * \brief Returns nb of HypType's taking into account possible several
1948 * selected additional hypotheses which are coded as additional HypType's.
1950 //================================================================================
1952 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
1954 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
1957 //================================================================================
1959 * \brief Returns true if hypotheses of given dim can be assigned
1960 * \param theDim - hypotheses dimension
1961 * \retval bool - result
1963 //================================================================================
1964 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1966 return myDlg->isTabEnabled( theDim );
1969 //================================================================================
1971 * \brief Sets current hypothesis or algorithms
1972 * \param theDim - dimension of hypothesis or algorithm
1973 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1974 * \param theIndex - Index of hypothesis
1976 * Gets current hypothesis or algorithms
1978 //================================================================================
1979 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1980 const int theHypType,
1981 const int theIndex )
1983 myIgnoreAlgoSelection = true;
1984 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1985 myIgnoreAlgoSelection = false;
1988 //================================================================================
1990 * \brief Generates default and sets mesh/submesh name
1992 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1994 //================================================================================
1995 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1999 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2002 QString aPrefix = thePrefix;
2003 if ( aPrefix.isEmpty() )
2004 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2006 _PTR(SObject) anObj;
2009 aResName = aPrefix + QString::number( i++ );
2010 anObj = aStudy->FindObject( aResName.toLatin1().data() );
2014 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2015 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2016 aControl->setText( aResName );
2019 //================================================================================
2021 * \brief Gets algorithm or creates it if necessary
2022 * \param theDim - specifies dimension of returned hypotheses/algorifms
2023 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2025 * Gets algorithm or creates it if necessary
2027 //================================================================================
2028 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2030 SMESH::SMESH_Hypothesis_var anAlgoVar;
2032 // get type of the selected algo
2033 int aHypIndex = currentHyp( theDim, Algo );
2034 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2035 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2037 QString aHypName = dataList[ aHypIndex ]->TypeName;
2039 // get existing algoritms
2040 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
2042 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2044 // look for an existing algo of such a type
2045 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2046 THypList::iterator anIter = aHypVarList.begin();
2047 for ( ; anIter != aHypVarList.end(); anIter++)
2049 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2050 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2052 anAlgoVar = aHypVar;
2057 if (anAlgoVar->_is_nil())
2059 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2062 QString aClientLibName = aHypData->ClientLibName;
2063 if ( aClientLibName.isEmpty() )
2065 // Call hypothesis creation server method (without GUI)
2066 SMESH::SMESH_Hypothesis_var aHyp =
2067 SMESH::CreateHypothesis(aHypName, aHypName, true);
2072 // Get hypotheses creator client (GUI)
2073 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2077 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2079 SMESH::SMESH_Hypothesis_var aHyp =
2080 SMESH::CreateHypothesis(aHypName, aHypName, true);
2084 QStringList tmpList;
2085 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2086 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2089 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2090 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2092 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2093 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2095 anAlgoVar = aHypVar;
2101 return anAlgoVar._retn();
2104 //================================================================================
2106 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2108 * Called when mesh is edited only.
2110 //================================================================================
2111 void SMESHGUI_MeshOp::readMesh()
2113 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2114 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2118 if (myIsOnGeometry) {
2119 // Get name of mesh if current object is sub-mesh
2120 SMESH::SMESH_subMesh_var aSubMeshVar =
2121 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2122 if ( !aSubMeshVar->_is_nil() )
2124 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2125 if ( !aMeshVar->_is_nil() )
2127 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2128 QString aMeshName = name( aMeshSO );
2129 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2131 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2134 // Get name of geometry object
2135 CORBA::String_var name = SMESH::GetGeomName( pObj );
2137 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2140 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2141 QStringList anExisting;
2142 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2143 bool algoFound = false;
2144 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2147 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2148 // find algo index among available ones
2150 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2152 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2153 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2154 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2155 // if ( aHypIndex < 0 && algoData ) {
2156 // // assigned algo is incompatible with other algorithms
2157 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2158 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2160 algoFound = ( aHypIndex > -1 );
2162 setCurrentHyp( dim, Algo, aHypIndex );
2163 // set existing and available hypothesis according to the selected algo
2164 if ( aHypIndex > -1 || !algoFound )
2165 onAlgoSelected( aHypIndex, dim );
2169 bool hypWithoutAlgo = false;
2170 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2172 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2175 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2176 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2178 // find index of required hypothesis among existing ones for this dimension and type
2179 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2180 myExistingHyps[ dim ][ hypType ] );
2181 if ( aHypIndex < 0 ) {
2182 // assigned hypothesis is incompatible with the algorithm
2183 if ( currentHyp( dim, Algo ) < 0 )
2184 { // none algo selected; it is edition for sure, of submesh maybe
2185 hypWithoutAlgo = true;
2186 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2187 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2188 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2189 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2192 setCurrentHyp( dim, hypType + i, aHypIndex );
2194 if ( hypType == MainHyp ) break; // only one main hyp allowed
2198 // make available other hyps of same type as one without algo
2199 if ( hypWithoutAlgo )
2200 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2203 //================================================================================
2205 * \brief Gets name of object
2206 * \param theSO - SObject
2207 * \retval QString - name of object
2209 * Gets name of object
2211 //================================================================================
2212 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2217 _PTR(GenericAttribute) anAttr;
2218 _PTR(AttributeName) aNameAttr;
2219 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2222 aResName = aNameAttr->Value().c_str();
2228 //================================================================================
2230 * \brief Finds hypothesis in input list
2231 * \param theHyp - hypothesis to be found
2232 * \param theHypList - input list of hypotheses
2233 * \retval int - index of hypothesis or -1 if it is not found
2235 * Finds position of hypothesis in input list
2237 //================================================================================
2238 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2239 const THypList& theHypList ) const
2242 if ( !theHyp->_is_nil() )
2245 THypList::const_iterator anIter = theHypList.begin();
2246 for ( ; anIter != theHypList.end(); ++ anIter)
2248 if ( theHyp->_is_equivalent( (*anIter).first ) )
2259 //================================================================================
2261 * \brief Edits mesh or sub-mesh
2262 * \param theMess - Output parameter intended for returning error message
2263 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2265 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2267 //================================================================================
2268 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2272 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2273 if ( aSMESHGen->_is_nil() )
2276 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2277 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2281 SUIT_OverrideCursor aWaitCursor;
2284 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2285 SMESH::SetName( pObj, aName );
2286 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2288 // First, remove old algos in order to avoid messages on algorithm hiding
2289 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2291 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2293 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2294 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2295 if ( anAlgoVar->_is_nil() || // no new algo selected or
2296 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2298 // remove old algorithm
2299 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2300 myObjHyps[ dim ][ Algo ].clear();
2305 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2306 CORBA::Object_var anObject = aSObject->GetObject();
2307 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2308 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2309 bool isMesh = !aMeshVar->_is_nil();
2310 if ( !isMesh && !aSubMeshVar->_is_nil() )
2311 aMeshVar = aSubMeshVar->GetFather();
2313 // Assign new algorithms and hypotheses
2314 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2316 if ( !isAccessibleDim( dim )) continue;
2318 // find or create algorithm
2319 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2321 // assign new algorithm
2322 if ( !anAlgoVar->_is_nil() && // some algo selected and
2323 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2326 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2327 else if ( !aSubMeshVar->_is_nil() )
2328 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2330 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2333 // remove deselected hypotheses
2334 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2336 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2338 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2339 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2340 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2342 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2346 // assign newly selected hypotheses
2347 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2349 const int curIndex = currentHyp( dim, dlgType );
2350 const int hypType = Min( dlgType, AddHyp );
2351 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2353 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2355 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2359 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2360 else if ( !aSubMeshVar->_is_nil() )
2361 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2364 // reread all hypotheses of mesh
2365 QStringList anExisting;
2366 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2370 myHasConcurrentSubBefore =
2371 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2376 //================================================================================
2378 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2379 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2380 * order of sub-mesh computation.
2381 * Returns \c true if a sub-mesh concurrency detected.
2383 //================================================================================
2385 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2386 SMESH::SMESH_subMesh_ptr submesh,
2389 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2392 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2393 if ( isNewConcurrent && askUser )
2395 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2396 tr("CONCURRENT_SUBMESH_APPEARS"),
2397 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2400 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2401 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2402 if ( meshSO && aSelectionMgr )
2404 myDlg->setEnabled( false ); // disactivate selection
2405 selectionMgr()->clearFilters();
2406 selectObject( meshSO );
2407 SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2408 qApp->processEvents();
2410 myDlg->setEnabled( true );
2411 int obj = myDlg->getActiveObject();
2412 onActivateObject( obj ); // restore filter
2415 selectObject( SMESH::FindSObject( submesh ));
2422 return isNewConcurrent;
2425 //================================================================================
2427 * \brief Verifies whether given operator is valid for this one
2428 * \param theOtherOp - other operation
2429 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2431 * method redefined from base class verifies whether given operator is valid for
2432 * this one (i.e. can be started "above" this operator). In current implementation method
2433 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2436 //================================================================================
2437 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2439 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2442 //================================================================================
2444 * \brief SLOT. Is called when the user selects a way of geometry selection
2445 * \param theByMesh - true if the user wants to find geometry by mesh element
2447 //================================================================================
2448 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2451 if ( !myShapeByMeshOp ) {
2452 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2453 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2454 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2455 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2456 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2458 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2459 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2460 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2461 SMESH::SMESH_Mesh_var aMeshVar =
2462 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2463 if ( !aMeshVar->_is_nil() ) {
2464 myDlg->hide(); // stop processing selection
2465 myShapeByMeshOp->setModule( getSMESHGUI() );
2466 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2467 myShapeByMeshOp->SetMesh( aMeshVar );
2468 myShapeByMeshOp->start();
2474 //================================================================================
2476 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2478 //================================================================================
2479 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2481 if ( myShapeByMeshOp == op ) {
2482 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2484 // Select a found geometry object
2485 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2486 if ( !aGeomVar->_is_nil() )
2488 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2489 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2490 selectObject( aGeomSO );
2497 //================================================================================
2499 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2501 //================================================================================
2502 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2504 if ( myShapeByMeshOp == op && myDlg ) {
2509 //================================================================================
2511 * \brief Selects a SObject
2512 * \param theSObj - the SObject to select
2514 //================================================================================
2515 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2517 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2518 SALOME_ListIO anIOList;
2520 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2521 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2522 anIOList.Append( anIO );
2524 sm->setSelectedObjects( anIOList, false );
2527 //================================================================================
2529 * \brief Create available list types of mesh
2530 * \param theTypeMesh - Output list of available types of mesh
2532 //================================================================================
2533 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2535 theTypeMesh.clear();
2536 theTypeMesh.append( tr( "MT_ANY" ) );
2537 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2539 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2540 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2542 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2544 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2545 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2549 //================================================================================
2551 * \brief Set available types of mesh
2552 * \param theTypeMesh - List of available types of mesh
2554 //================================================================================
2555 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2557 myDlg->setAvailableMeshType( theTypeMesh );
2560 //================================================================================
2562 * \brief SLOT. Is called when the user select type of mesh
2563 * \param theTabIndex - Index of current active tab
2564 * \param theIndex - Index of current type of mesh
2566 //================================================================================
2567 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2569 setFilteredAlgoData( theTabIndex, theIndex);
2572 //================================================================================
2574 * \brief Set a filtered list of available algorithms by mesh type
2575 * \param theTabIndex - Index of current active tab
2576 * \param theIndex - Index of current type of mesh
2578 //================================================================================
2579 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2582 THypDataList anAvailableAlgsData;
2583 QStringList anAvailableAlgs;
2584 QString anCompareType = "";
2585 bool isAvailableChoiceAlgo = false;
2586 int anCurrentAvailableAlgo = 0;
2588 switch ( theIndex ) {
2590 anCompareType = "ANY";
2591 aDim = SMESH::DIM_3D;
2594 aDim = SMESH::DIM_2D;
2595 anCompareType = "TRIA";
2597 case MT_QUADRILATERAL:
2598 aDim = SMESH::DIM_2D;
2599 anCompareType = "QUAD";
2601 case MT_TETRAHEDRAL:
2602 aDim = SMESH::DIM_3D;
2603 anCompareType = "TETRA";
2606 aDim = SMESH::DIM_3D;
2607 anCompareType = "HEXA";
2612 bool toCheckIsApplicableToAll = !myIsMesh;
2613 GEOM::GEOM_Object_var aGeomVar;
2614 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2615 if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2617 CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
2618 aGeomVar = GEOM::GEOM_Object::_narrow( obj );
2619 if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
2620 toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
2623 if ( anCompareType == "ANY" )
2625 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2627 isNone = currentHyp( dim, Algo ) < 0;
2628 isAvailableChoiceAlgo = false;
2629 // retrieves a list of available algorithms from resources
2630 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2631 //return current algo in current tab and set new algorithm list
2632 HypothesisData* algoCur;
2633 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2634 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2636 myAvailableHypData[dim][Algo].clear();
2637 anAvailableAlgs.clear();
2638 if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
2639 myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
2640 !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
2642 for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2644 HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2645 if ( aGeomVar->_is_nil() ||
2646 SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2648 anAvailableAlgs.append( curAlgo->Label );
2649 myAvailableHypData[dim][Algo].append( curAlgo );
2652 if ( !isNone && algoCur ) {
2653 for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2655 HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2656 if ( algoAny->Label == algoCur->Label ){
2657 isAvailableChoiceAlgo = true;
2658 anCurrentAvailableAlgo = i;
2663 else if ( !isNone ) {
2664 isAvailableChoiceAlgo = true;
2665 anCurrentAvailableAlgo = currentHyp( dim, Algo );
2668 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2669 if ( isAvailableChoiceAlgo )
2670 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2672 if ( !myIsOnGeometry )
2673 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2674 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2675 else myDlg->enableTab( i );
2678 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2679 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2680 else myDlg->enableTab( i );
2682 myDlg->setCurrentTab( theTabIndex );
2686 QString anCurrentAlgo;
2687 bool isReqDisBound = true;
2688 QString anCurrentCompareType = anCompareType;
2689 isNone = currentHyp( aDim, Algo ) < 0;
2690 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2691 myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2692 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2694 isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2695 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2697 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2698 isAvailableChoiceAlgo = false;
2699 // retrieves a list of available algorithms from resources
2700 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2701 // finding algorithm which is selected
2702 if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2703 myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2704 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2705 else if ( !isNoneAlg )
2706 anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2707 anAvailableAlgs.clear();
2708 myAvailableHypData[dim][Algo].clear();
2709 myFilteredAlgoData[dim].clear();
2710 // finding and adding algorithm depending on the type mesh
2711 for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2713 HypothesisData* algoIn = anAvailableAlgsData.at( i );
2714 bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2715 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2716 for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2718 if ( *inElemType == anCurrentCompareType ) {
2719 isAvailableAlgo = true;
2723 if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
2724 if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2725 SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2727 anAvailableAlgs.append( algoIn->Label );
2728 myAvailableHypData[dim][Algo].append( algoIn );
2729 myFilteredAlgoData[dim].append( algoIn );
2732 //algorithm will be active, if the chosen algorithm available in the current mesh type
2733 if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
2734 isAvailableChoiceAlgo = true;
2735 anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2738 //set new algorithm list and select the current algorithm
2739 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2740 anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2741 if ( isAvailableChoiceAlgo )
2742 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2744 setCurrentHyp( dim, Algo, -1 );
2747 if ( isNone || isReqDisBound ) {
2748 for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
2750 myDlg->disableTab( i );
2751 setCurrentHyp(i, Algo, -1);
2755 else if ( !isNone ) {
2756 if ( aDim == SMESH::DIM_2D){
2757 myDlg->disableTab( SMESH::DIM_3D );
2758 setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2760 for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
2762 isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2763 myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2764 if ( isReqDisBound ) {
2765 for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2766 myDlg->disableTab( j );
2767 setCurrentHyp( j , Algo, -1 );
2773 myDlg->enableTab( aDim );
2774 myDlg->setCurrentTab( aDim );
2776 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2777 QStringList aFilteredHypothesesSetsList;
2778 aFilteredHypothesesSetsList.clear();
2779 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2780 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2782 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2783 bool isAvailable = false;
2784 currentHypoSet->init( true );
2785 while ( currentHypoSet->next(), currentHypoSet->more() )
2787 isAvailable = false;
2788 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2790 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
2792 if ( myAvailableHypData[i][Algo].count() == 0 ) {
2793 availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
2794 for ( int j = 0 ; j < anAvailableAlgsData.count(); j++ )
2796 HypothesisData* aCurAlgo = anAvailableAlgsData.at( j );
2797 if ( aCurAlgo->Label == algoDataIn->Label ){
2804 for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2805 HypothesisData* aCurAlgo = hypData( i, Algo, j );
2806 if ( aCurAlgo->Label == algoDataIn->Label ){
2812 if ( isAvailable ) break;
2814 if ( !isAvailable ) break;
2818 aFilteredHypothesesSetsList.append( *inHypoSetName );
2820 myDlg->setHypoSets( aFilteredHypothesesSetsList );