1 // Copyright (C) 2007-2015 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_GEOMGenUtils.h"
30 #include "SMESHGUI_Hypotheses.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_MeshDlg.h"
33 #include "SMESHGUI_Operations.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESH_NumberFilter.hxx"
37 #include "SMESH_TypeFilter.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 );
251 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
253 myDlg->setCurrentTab( SMESH::DIM_3D );
255 QStringList TypeMeshList;
256 createMeshTypeList( TypeMeshList );
257 setAvailableMeshType( TypeMeshList );
260 myDlg->setGeomPopupEnabled(false);
263 myIgnoreAlgoSelection = false;
264 myHasConcurrentSubBefore = false;
266 myObjectToSelect.clear();
269 //=================================================================================
271 * \brief Selects a recently created mesh or sub-mesh if necessary
273 * Virtual method redefined from base class called when operation is commited
274 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
275 * selection when the custom selection filters are removed.
277 //=================================================================================
278 void SMESHGUI_MeshOp::commitOperation()
280 SMESHGUI_SelectionOp::commitOperation();
282 if ( !myObjectToSelect.isEmpty() ) {
283 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
284 SUIT_DataOwnerPtrList aList;
285 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
286 aSelectionMgr->setSelected( aList );
291 //================================================================================
293 * \brief Creates selection filter
294 * \param theId - identifier of current selection widget
295 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
297 * Creates selection filter in accordance with identifier of current selection widget
299 //================================================================================
300 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
302 if ( theId == SMESHGUI_MeshDlg::Geom )
304 // TColStd_MapOfInteger allTypesMap;
305 // for ( int i = 0; i < 10; i++ )
306 // allTypesMap.Add( i );
307 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
308 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
310 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
311 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
312 else if ( theId == SMESHGUI_MeshDlg::Mesh )
313 return new SMESH_TypeFilter( SMESH::MESH );
318 //================================================================================
320 * \brief check if selected shape is a sub-shape of the shape to mesh
321 * \retval bool - check result
323 //================================================================================
324 bool SMESHGUI_MeshOp::isSubshapeOk() const
326 if ( !myToCreate || myIsMesh ) // not submesh creation
330 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
331 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
332 if (!pMesh) return false;
334 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
335 if (mesh->_is_nil()) return false;
337 // main shape of the mesh
338 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
339 if (mainGeom->_is_nil()) return false;
343 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
345 if (aGEOMs.count() > 0) {
346 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
347 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
348 if (geomGen->_is_nil() || !aStudy) return false;
350 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
351 if (op->_is_nil()) return false;
353 // check all selected shapes
354 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
355 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
356 QString aSubGeomEntry = (*aSubShapesIter);
357 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
358 if (!pSubGeom) return false;
360 GEOM::GEOM_Object_var aSubGeomVar =
361 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
362 if (aSubGeomVar->_is_nil()) return false;
364 // skl for NPAL14695 - implementation of searching of mainObj
365 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
366 mainObj already exists! */
367 while( !mainObj->_is_nil()) {
368 CORBA::String_var entry1 = mainObj->GetEntry();
369 CORBA::String_var entry2 = mainGeom->GetEntry();
370 if (std::string( entry1.in() ) == entry2.in() )
372 mainObj = op->GetMainShape(mainObj);
374 if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
376 // is aSubGeomVar a compound of sub-shapes?
377 GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations(aStudy->StudyId());
378 if (sop->_is_nil()) return false;
379 GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
380 GEOM::SHAPE,/*sorted=*/false);
381 if ( ids->length() > 0 )
384 GEOM::GEOM_Object_var compSub = geomGen->AddSubShape( aSubGeomVar, ids );
385 if ( !compSub->_is_nil() )
387 GEOM::ListOfGO_var shared = sop->GetSharedShapes( mainGeom,
389 compSub->GetShapeType() );
390 geomGen->RemoveObject( compSub );
391 compSub->UnRegister();
392 if ( shared->length() > 0 ) {
393 geomGen->RemoveObject( shared[0] );
394 shared[0]->UnRegister();
396 return ( shared->length() > 0 );
406 //================================================================================
408 * \brief Return name of the algorithm that does not support sub-meshes and makes
409 * sub-mesh creation useless
410 * \retval char* - string is to be deleted!!!
412 //================================================================================
413 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
415 if ( myToCreate && !myIsMesh ) {
417 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
418 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
419 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
422 QStringList algoNames;
424 existingHyps(3, Algo, pMesh, algoNames, algoList);
425 if (!algoList.empty()) {
426 HypothesisData* algo =
427 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
429 algo->InputTypes.empty() && // builds all dimensions it-self
430 !algo->IsSupportSubmeshes )
431 return CORBA::string_dup( algoNames[0].toLatin1().data() );
434 // GEOM::GEOM_Object_var geom;
435 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
436 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
438 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
439 existingHyps(2, Algo, pMesh, algoNames, algoList);
440 if (!algoList.empty()) {
441 HypothesisData* algo =
442 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
444 algo->InputTypes.empty() && // builds all dimensions it-self
445 !algo->IsSupportSubmeshes )
446 return CORBA::string_dup( algoNames[0].toLatin1().data() );
454 //================================================================================
456 * \brief find an existing submesh by the selected shape
457 * \retval _PTR(SObject) - the found submesh SObject
459 //================================================================================
460 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
462 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
463 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
464 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
465 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
466 if ( pMesh && pGeom ) {
467 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
468 if ( !geom->_is_nil() ) {
470 switch ( geom->GetShapeType() ) {
471 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
472 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
473 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
474 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
475 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
476 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
477 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
480 _PTR(GenericAttribute) anAttr;
481 _PTR(SObject) aSubmeshRoot;
482 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
483 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
485 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
486 for ( ; smIter->More(); smIter->Next() )
488 _PTR(SObject) aSmObj = smIter->Value();
489 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
491 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
492 for ( ; anIter1->More(); anIter1->Next()) {
493 _PTR(SObject) pGeom2 = anIter1->Value();
494 if ( pGeom2->ReferencedObject( pGeom2 ) &&
495 pGeom2->GetID() == pGeom->GetID() )
502 return _PTR(SObject)();
505 //================================================================================
507 * \brief Updates dialog's look and feel
509 * Virtual method redefined from the base class updates dialog's look and feel
511 //================================================================================
512 void SMESHGUI_MeshOp::selectionDone()
514 if (!dlg()->isVisible() || !myDlg->isEnabled())
517 SMESHGUI_SelectionOp::selectionDone();
521 myIsOnGeometry = true;
523 //Check geometry for mesh
524 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
525 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
528 SMESH::SMESH_Mesh_var aMeshVar =
529 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
530 if (!aMeshVar->_is_nil()) {
531 if (!myToCreate && !aMeshVar->HasShapeToMesh())
532 myIsOnGeometry = false;
538 // Enable tabs according to shape dimension
543 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
544 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
546 if (aGEOMs.count() > 0) {
547 // one or more GEOM shape selected
548 aSeq->length(aGEOMs.count());
549 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
551 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
552 QString aSubGeomEntry = (*aSubShapesIter);
553 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
556 SALOMEDS_SObject* sobj = _CAST(SObject,pSubGeom);
558 GEOM::GEOM_Object_var aSubGeomVar =
559 GEOM::GEOM_Object::_narrow(sobj->GetObject());
560 if( !aSubGeomVar->_is_nil() ){
561 aSeq[iSubSh] = aSubGeomVar;
567 // get geometry by selected sub-mesh
568 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
569 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
570 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
571 if (!aGeomVar->_is_nil()) {
577 if (aSeq->length() > 0) {
579 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
580 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
581 switch ( aGeomVar->GetShapeType() ) {
582 case GEOM::SOLID: shapeDim = 3; break;
584 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
586 // TopoDS_Shape aShape;
587 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
588 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
591 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
593 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
594 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
598 if (GEOMBase::GetShape(aGeomVar, aShape))
600 TopExp_Explorer exp (aShape, TopAbs_SOLID);
604 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
605 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
608 // for (; exp.More() && shapeDim == 2; exp.Next()) {
609 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
613 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
614 shapeDim = qMax(2, shapeDim);
615 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
616 shapeDim = qMax(1, shapeDim);
617 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
618 shapeDim = qMax(0, shapeDim);
626 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
627 // reset algos before disabling tabs (0020138)
628 onAlgoSelected(-1, i);
630 myDlg->setMaxHypoDim( shapeDim );
631 myMaxShapeDim = shapeDim;
632 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
634 if (!myToCreate) // edition: read hypotheses
638 SMESH::SMESH_subMesh_var submeshVar =
639 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
640 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
641 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
642 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
643 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
644 myDlg->updateGeometry();
646 myIsMesh = submeshVar->_is_nil();
652 else if ( !myIsMesh ) // submesh creation
654 // if a submesh on the selected shape already exist, pass to submesh edition mode
655 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
656 SMESH::SMESH_subMesh_var sm =
657 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
658 bool editSubmesh = ( !sm->_is_nil() &&
659 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
660 tr( "EDIT_SUBMESH_QUESTION"),
661 SUIT_MessageBox::Yes |
663 SUIT_MessageBox::No )
664 == SUIT_MessageBox::Yes );
667 selectionMgr()->clearFilters();
668 selectObject( pSubmesh );
669 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
674 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
675 selectObject( _PTR(SObject)() );
680 // discard selected mesh if submesh creation not allowed because of
681 // a global algorithm that does not support submeshes
682 if ( char* algoName = isSubmeshIgnored() ) {
683 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
684 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
685 CORBA::string_free( algoName );
686 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
687 selectObject( _PTR(SObject)() );
692 // enable/disable popup for choice of geom selection way
694 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
695 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
696 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
697 if ( !mesh->_is_nil() ) {
698 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
699 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
700 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
701 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
702 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
703 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
706 myDlg->setGeomPopupEnabled( enable );
709 else { // no geometry defined
710 myDlg->enableTab( SMESH::DIM_3D );
712 availableHyps( SMESH::DIM_3D, Algo, hypList,
713 myAvailableHypData[SMESH::DIM_3D][Algo]);
715 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
716 aTab->setAvailableHyps( Algo, hypList );
717 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
718 myDlg->disableTab(i);
721 //Hide labels and fields (Mesh and Geometry)
722 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
723 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
727 int curIndex = myDlg->currentMeshType( );
728 QStringList TypeMeshList;
729 createMeshTypeList( TypeMeshList );
730 setAvailableMeshType( TypeMeshList );
731 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
732 myDlg->setCurrentMeshType( curIndex );
733 setFilteredAlgoData( myMaxShapeDim, curIndex);
735 catch ( const SALOME::SALOME_Exception& S_ex )
737 SalomeApp_Tools::QtCatchCorbaException( S_ex );
744 //================================================================================
746 * \brief Verifies validity of input data
747 * \param theMess - Output parameter intended for returning error message
748 * \retval bool - TRUE if input data is valid, false otherwise
750 * Verifies validity of input data. This method is called when "Apply" or "OK" button
751 * is pressed before mesh creation or editing.
753 //================================================================================
754 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
756 // Selected object to be edited
757 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
759 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
764 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
765 if ( aMeshName.isEmpty() )
767 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
771 /* // Imported mesh, if create sub-mesh or edit mesh
772 if ( !myToCreate || ( myToCreate && !myIsMesh ))
774 QString aMeshEntry = myDlg->selectedObject
775 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
776 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
777 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
778 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
779 theMess = tr( "IMPORTED_MESH" );
788 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
789 if ( aGeomEntry.isEmpty() )
791 theMess = tr( myIsMesh ?
792 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
793 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
797 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
798 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
805 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
806 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
808 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
813 if ( !myIsMesh ) // i.e sub-mesh creation,
815 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
816 if ( aMeshEntry == "" )
818 theMess = tr( "MESH_IS_NOT_DEFINED" );
821 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
822 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
824 theMess = tr( "MESH_IS_NULL" );
827 if ( !isSubshapeOk() )
829 theMess = tr( "INVALID_SUBSHAPE" );
838 //================================================================================
840 * \brief check compatibility of the algorithm and another algorithm or hypothesis
841 * \param theAlgoData - algorithm data
842 * \param theHypData - hypothesis data
843 * \param theHypType - hypothesis type
844 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
845 * \retval bool - check result
847 //================================================================================
848 static bool isCompatible(const HypothesisData* theAlgoData,
849 const HypothesisData* theHypData,
850 const int theHypType)
855 if ( theHypType == SMESHGUI_MeshOp::Algo )
856 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
859 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
862 //================================================================================
864 * \brief Gets available hypotheses or algorithms
865 * \param theDim - specifies dimension of returned hypotheses/algorifms
866 * \param theHypType - specifies whether algorims or hypotheses or additional ones
867 * are retrieved (possible values are in HypType enumeration)
868 * \param theHyps - Output list of hypotheses' names
869 * \param theAlgoData - to select hypos able to be used by this algo (optional)
871 * Gets available hypotheses or algorithm in accordance with input parameters
873 //================================================================================
874 void SMESHGUI_MeshOp::availableHyps( const int theDim,
875 const int theHypType,
876 QStringList& theHyps,
877 THypDataList& theDataList,
878 HypothesisData* theAlgoData ) const
882 bool isAlgo = ( theHypType == Algo );
883 bool isAux = ( theHypType >= AddHyp );
884 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
886 QStringList::const_iterator anIter;
887 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
889 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
890 if ( isCompatible ( theAlgoData, aData, theHypType )) {
891 theDataList.append( aData );
892 theHyps.append( aData->Label );
897 //================================================================================
899 * \brief Gets existing hypotheses or algorithms
900 * \param theDim - specifies dimension of returned hypotheses/algorifms
901 * \param theHypType - specifies whether algorims or hypotheses or additional ones
902 * are retrieved (possible values are in HypType enumeration)
903 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
904 * \param theHyps - output list of names.
905 * \param theHypVars - output list of variables.
906 * \param theAlgoData - to select hypos able to be used by this algo (optional)
908 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
911 * WARNING: when using this method to get hyps existing in Mesh component,
912 * call availableHyps() before in order to get only hyps of available types
913 * that was filtered by availableHyps()
915 //================================================================================
916 void SMESHGUI_MeshOp::existingHyps( const int theDim,
917 const int theHypType,
918 _PTR(SObject) theFather,
919 QStringList& theHyps,
920 THypList& theHypList,
921 HypothesisData* theAlgoData) const
923 // Clear hypoheses list
930 _PTR(SObject) aHypRoot;
931 _PTR(GenericAttribute) anAttr;
932 _PTR(AttributeName) aName;
933 _PTR(AttributeIOR) anIOR;
935 const bool isMesh = !_CAST( SComponent, theFather );
938 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
940 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
942 const bool isAux = ( theHypType >= AddHyp );
943 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
945 if ( theFather->FindSubObject( aPart, aHypRoot ) )
947 _PTR(ChildIterator) anIter =
948 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
949 for ( ; anIter->More(); anIter->Next() )
951 _PTR(SObject) anObj = anIter->Value();
952 if ( isMesh ) // i.e. mesh or submesh
954 _PTR(SObject) aRefObj;
955 if ( anObj->ReferencedObject( aRefObj ) )
960 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
963 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
964 if ( !CORBA::is_nil( aVar ) )
966 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
967 if ( !aHypVar->_is_nil() )
969 CORBA::String_var hypType = aHypVar->GetName();
970 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
971 if ( !aData) continue;
972 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
973 ( isCompatible ( theAlgoData, aData, theHypType )) &&
974 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
975 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
977 std::string aHypName = aName->Value();
978 theHyps.append( aHypName.c_str() );
979 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
988 //================================================================================
990 * \brief If create or edit a submesh, return a hypothesis holding parameters used
991 * to mesh a sub-shape
992 * \param aHypType - The hypothesis type name
993 * \param aServerLib - Server library name
994 * \param hypData - The structure holding the hypothesis type etc.
995 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
997 //================================================================================
998 SMESH::SMESH_Hypothesis_var
999 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1000 const QString& aServerLib ) const
1002 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1003 return SMESH::SMESH_Hypothesis::_nil();
1005 const int nbColonsInMeshEntry = 3;
1006 bool isSubMesh = myToCreate ?
1008 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1010 // get mesh and geom object
1011 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
1012 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1017 anEntry = myDlg->selectedObject
1018 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1019 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1021 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1022 if ( myToCreate ) // mesh and geom may be selected
1024 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
1025 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1026 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1027 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1029 else // edition: sub-mesh may be selected
1031 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1032 if ( !sm->_is_nil() ) {
1033 aMeshVar = sm->GetFather();
1034 aGeomVar = sm->GetSubShape();
1041 if ( !myToCreate ) // mesh to edit can be selected
1043 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1044 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1046 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1047 if ( !aMeshVar->_is_nil() )
1048 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1051 if ( aGeomVar->_is_nil() ) {
1052 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1053 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1055 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1060 SMESH::SMESH_Hypothesis_var hyp =
1061 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1062 aServerLib.toLatin1().data(),
1065 /*byMesh = */isSubMesh);
1066 if ( hyp->_is_nil() && isSubMesh )
1067 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1068 aServerLib.toLatin1().data(),
1071 /*byMesh = */false);
1075 //================================================================================
1077 * \brief initialize a hypothesis creator
1079 //================================================================================
1081 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1083 if ( !theCreator ) return;
1085 // Set shapes, of mesh and sub-mesh if any
1087 // get Entry of the Geom object
1088 QString aGeomEntry = "";
1089 QString aMeshEntry = "";
1090 QString anObjEntry = "";
1091 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1092 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1093 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1095 if ( myToCreate && myIsMesh )
1096 aMeshEntry = aGeomEntry;
1098 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1099 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1100 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1101 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1104 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1105 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1107 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1108 if ( !aGeomVar->_is_nil() )
1110 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1112 aMeshEntry = aGeomEntry;
1116 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1117 // take geometry from submesh being created
1118 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1120 // if current object is sub-mesh
1121 SMESH::SMESH_subMesh_var aSubMeshVar =
1122 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1123 if ( !aSubMeshVar->_is_nil() ) {
1124 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1125 if ( !aMeshVar->_is_nil() ) {
1126 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1127 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1128 if ( !aGeomVar->_is_nil() )
1129 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1135 theCreator->setShapeEntry( aGeomEntry );
1136 if ( aMeshEntry != "" )
1137 theCreator->setMainShapeEntry( aMeshEntry );
1140 //================================================================================
1142 * \Brief Returns tab dimention
1143 * \param tab - the tab in the dlg
1144 * \param dlg - my dialogue
1145 * \retval int - dimention
1147 //================================================================================
1148 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1151 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1152 if (tab == dlg->tab(i))
1157 //================================================================================
1159 * \brief Create hypothesis
1160 * \param theHypType - hypothesis category (main or additional)
1161 * \param theIndex - index of type of hypothesis to be cerated
1163 * Specifies dimension of hypothesis to be created (using sender() method),
1164 * specifies its type and calls method for hypothesis creation
1166 //================================================================================
1167 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1169 // Specifies dimension of hypothesis to be created
1170 int aDim = getTabDim( sender(), myDlg );
1174 // Specifies type of hypothesis to be created
1175 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1176 if (theIndex < 0 || theIndex >= dataList.count())
1178 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1180 // Create hypothesis
1181 createHypothesis(aDim, theHypType, aHypTypeName);
1186 QString GetUniqueName (const QStringList& theHypNames,
1187 const QString& theName,
1188 size_t theIteration = 1)
1190 QString aName = theName + "_" + QString::number( theIteration );
1191 if ( theHypNames.contains( aName ) )
1192 return GetUniqueName( theHypNames, theName, ++theIteration );
1197 //================================================================================
1199 * Create hypothesis and update dialog.
1200 * \param theDim - dimension of hypothesis to be created
1201 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1202 * \param theTypeName - specifies hypothesis to be created
1204 //================================================================================
1205 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1207 const QString& theTypeName)
1209 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1216 // get a unique hyp name
1217 QStringList aHypNames;
1218 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1219 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1220 const TType2HypList& aType2HypList = aDimIter.value();
1221 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1222 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1223 const THypList& aHypList = aTypeIter.value();
1224 THypList::const_iterator anIter = aHypList.begin();
1225 for ( ; anIter != aHypList.end(); anIter++) {
1226 const THypItem& aHypItem = *anIter;
1227 const QString& aHypName = aHypItem.second;
1228 aHypNames.append(aHypName);
1232 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1235 bool dialog = false;
1237 QString aClientLibName = aData->ClientLibName;
1238 if (aClientLibName == "") {
1239 // Call hypothesis creation server method (without GUI)
1240 SMESH::SMESH_Hypothesis_var aHyp =
1241 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1245 // Get hypotheses creator client (GUI)
1246 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1248 // Create hypothesis
1251 // Get parameters appropriate to initialize a new hypothesis
1252 SMESH::SMESH_Hypothesis_var initParamHyp =
1253 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1255 removeCustomFilters(); // Issue 0020170
1257 // set shapes, of mesh and sub-mesh if any
1258 initHypCreator( aCreator );
1260 myDlg->setEnabled( false );
1261 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1265 SMESH::SMESH_Hypothesis_var aHyp =
1266 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1275 //================================================================================
1277 * Necessary steps after hypothesis creation
1278 * \param result - creation result:
1281 * 2 = additional value meaning that slot is called not from dialog box
1283 //================================================================================
1284 void SMESHGUI_MeshOp::onHypoCreated( int result )
1288 int obj = myDlg->getActiveObject();
1289 onActivateObject( obj ); // Issue 0020170. Restore filters
1290 myDlg->setEnabled( true );
1293 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1295 int nbHyp = myExistingHyps[myDim][myType].count();
1296 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1297 QStringList aNewHyps;
1298 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1299 if (aNewHyps.count() > nbHyp)
1301 for (int i = nbHyp; i < aNewHyps.count(); i++)
1302 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1305 if( result!=2 && myHypoSet )
1309 //================================================================================
1311 * \brief Calls plugin methods for hypothesis editing
1312 * \param theHypType - specifies whether main hypothesis or additional one
1314 * \param theIndex - index of existing hypothesis
1316 * Calls plugin methods for hypothesis editing
1318 //================================================================================
1319 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1321 // Speicfies dimension of hypothesis to be created
1322 int aDim = getTabDim( sender(), myDlg );
1326 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1327 if ( theIndex < 0 || theIndex >= aList.count() )
1329 const THypItem& aHypItem = aList[ theIndex ];
1330 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1331 if ( aHyp->_is_nil() )
1334 SMESHGUI_GenericHypothesisCreator* aCreator =
1335 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1338 // set initial parameters
1339 SMESH::SMESH_Hypothesis_var initParamHyp =
1340 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1341 SMESH::toQStr( aHyp->GetLibName() ));
1342 aCreator->setInitParamsHypothesis( initParamHyp );
1344 // set shapes, of mesh and sub-mesh if any
1345 initHypCreator( aCreator );
1347 removeCustomFilters(); // Issue 0020170
1348 myDlg->setEnabled( false );
1350 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1354 //================================================================================
1356 * Necessary steps after hypothesis edition
1357 * \param result - creation result:
1361 //================================================================================
1362 void SMESHGUI_MeshOp::onHypoEdited( int result )
1364 int obj = myDlg->getActiveObject();
1365 onActivateObject( obj ); // Issue 0020170. Restore filters
1366 myDlg->setEnabled( true );
1369 //================================================================================
1371 * \brief access to hypothesis data
1372 * \param theDim - hyp dimension
1373 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1374 * \param theIndex - index in the list
1375 * \retval HypothesisData* - result data, may be 0
1377 //================================================================================
1378 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1379 const int theHypType,
1382 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1383 theHypType > -1 && theHypType < NbHypTypes &&
1384 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1385 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1389 //================================================================================
1391 * \brief Set available algos and hypos according to the selected algorithm
1392 * \param theIndex - algorithm index
1394 //================================================================================
1395 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1398 if ( myIgnoreAlgoSelection )
1401 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1405 // find highest available dimension, all algos of this dimension are available for choice
1407 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1408 if (isAccessibleDim( i ))
1413 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1415 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1416 HypothesisData* algoByDim[4];
1417 algoByDim[ aDim ] = algoData;
1419 QStringList anAvailable;
1421 // check that tab enabled of one less dimension
1422 if ( aDim > SMESH::DIM_0D )
1424 if ( isAccessibleDim( aDim - 1 ) )
1426 if (( myDlg->currentMeshType() != MT_ANY ) &&
1427 ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1428 for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1429 if ( isAccessibleDim( i ) ) {
1430 myDlg->disableTab( i );
1431 setCurrentHyp(i, Algo, -1);
1434 else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1436 myDlg->enableTab( aDim - 1 );
1440 // check that algorithms of other dimentions are compatible with
1442 if ( !algoData ) { // all algos becomes available
1443 if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
1444 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1446 anAvailable.clear();
1447 for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1448 HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1449 anAvailable.append( aCurAlgo->Label );
1452 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1454 // 2 loops: backward and forward from algo dimension
1455 for ( int forward = false; forward <= true; ++forward )
1457 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1459 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1461 HypothesisData* prevAlgo = algoData;
1462 bool noCompatible = false;
1463 for ( ; dim * dir <= lastDim * dir; dim += dir)
1465 if ( !isAccessibleDim( dim ))
1467 if ( noCompatible ) { // the selected algo has no compatible ones
1468 anAvailable.clear();
1469 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1470 myAvailableHypData[dim][Algo].clear();
1471 algoByDim[ dim ] = 0;
1474 // get currently selected algo
1475 int algoIndex = currentHyp( dim, Algo );
1476 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1477 if ( curAlgo ) { // some algo selected
1478 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1481 // set new available algoritms
1482 if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1483 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1485 anAvailable.clear();
1486 myAvailableHypData[dim][Algo].clear();
1487 for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1488 HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1489 if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1490 anAvailable.append( aCurAlgo->Label );
1491 myAvailableHypData[dim][Algo].append( aCurAlgo );
1495 HypothesisData* soleCompatible = 0;
1496 if ( anAvailable.count() == 1 )
1497 soleCompatible = myAvailableHypData[dim][Algo][0];
1498 if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1499 if (myDlg->currentMeshType() == MT_ANY)
1500 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1502 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1503 noCompatible = anAvailable.isEmpty();
1505 // restore previously selected algo
1506 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1507 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1508 // select the sole compatible algo
1509 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1510 setCurrentHyp( dim, Algo, algoIndex);
1512 // remember current algo
1513 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1517 // set hypotheses corresponding to the found algoritms
1519 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1521 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1523 if ( !isAccessibleDim( dim ))
1526 // get indices of selected hyps
1527 const int nbTypes = nbDlgHypTypes(dim);
1528 std::vector<int> hypIndexByType( nbTypes, -1 );
1529 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1531 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1535 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1537 const int type = Min( dlgType, AddHyp );
1538 myAvailableHypData[ dim ][ type ].clear();
1539 QStringList anAvailable, anExisting;
1541 HypothesisData* curAlgo = algoByDim[ dim ];
1542 int hypIndex = hypIndexByType[ dlgType ];
1544 SMESH::SMESH_Hypothesis_var curHyp;
1545 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1546 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1548 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1549 // try to find algo by selected hypothesis in order to keep it selected
1550 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1551 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1552 if ( !algoDeselectedByUser &&
1553 myObjHyps[ dim ][ type ].count() > 0 &&
1554 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1556 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1557 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1558 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1559 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1566 // get hyps compatible with curAlgo
1567 bool defaulHypAvlbl = false;
1570 // check if a selected hyp is compatible with the curAlgo
1571 if ( !curHyp->_is_nil() ) {
1572 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1573 if ( !isCompatible( curAlgo, hypData, type ))
1574 curHyp = SMESH::SMESH_Hypothesis::_nil();
1576 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1577 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1578 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1580 // set list of hypotheses
1581 if ( dlgType <= AddHyp )
1583 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1584 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1586 // set current existing hypothesis
1587 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1588 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1591 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 ) {
1592 // none is yet selected => select the sole existing if it is not optional
1593 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1594 bool isOptional = true;
1595 if ( algoByDim[ dim ] &&
1596 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1600 setCurrentHyp( dim, dlgType, hypIndex );
1605 //================================================================================
1607 * \brief Creates and selects hypothesis of hypotheses set
1608 * \param theSetName - The name of hypotheses set
1610 //================================================================================
1611 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1613 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1618 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1619 setCurrentHyp(dim, Algo, -1);
1620 setCurrentHyp(dim, AddHyp, -1);
1621 setCurrentHyp(dim, MainHyp, -1);
1624 myHypoSet->init(true); //algorithms
1626 myHypoSet->init(false); //hypotheses
1631 //================================================================================
1633 * \brief One step of hypothesis/algorithm list creation
1635 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1637 //================================================================================
1638 void SMESHGUI_MeshOp::processSet()
1641 if( !myHypoSet->more() )
1644 bool isAlgo = myHypoSet->isAlgo();
1645 QString aHypoTypeName = myHypoSet->current();
1646 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1653 int aDim = aHypData->Dim[0];
1654 // create or/and set
1657 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1660 QStringList anAvailable;
1661 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1662 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1663 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1665 setCurrentHyp( aDim, Algo, index );
1666 onAlgoSelected( index, aDim );
1671 bool mainHyp = true;
1672 QStringList anAvailable;
1673 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1674 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1675 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1679 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1682 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1688 //================================================================================
1690 * \brief Creates mesh
1691 * \param theMess - Output parameter intended for returning error message
1692 * \param theEntryList - List of entries of published objects
1693 * \retval bool - TRUE if mesh is created, FALSE otherwise
1697 //================================================================================
1698 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1703 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1704 if ( aList.isEmpty() )
1706 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1707 if ( aSMESHGen->_is_nil() )
1710 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1711 if ( aMeshVar->_is_nil() )
1714 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1716 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1717 theEntryList.append( aMeshSO->GetID().c_str() );
1722 if ( aList.count() > 1 )
1724 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1725 int i = namePrefix.length() - 1;
1726 while ( i > 0 && namePrefix[i].isDigit() )
1728 if ( i < namePrefix.length() - 1 )
1729 namePrefix.chop( namePrefix.length() - 1 - i );
1733 QStringList::Iterator it = aList.begin();
1734 for ( int i = 0; it!=aList.end(); it++, ++i )
1736 QString aGeomEntry = *it;
1737 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1738 GEOM::GEOM_Object_var aGeomVar =
1739 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1741 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1742 if ( aSMESHGen->_is_nil() )
1745 SUIT_OverrideCursor aWaitCursor;
1748 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1749 if ( aMeshVar->_is_nil() )
1751 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1753 theEntryList.append( aMeshSO->GetID().c_str() );
1754 if ( i > 0 ) setDefaultName( namePrefix );
1755 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1758 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1760 if ( !isAccessibleDim( aDim )) continue;
1762 // assign hypotheses
1763 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1765 const int aHypIndex = currentHyp( aDim, dlgType );
1766 const int aHypType = Min( dlgType, AddHyp );
1767 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1769 SMESH::SMESH_Hypothesis_var aHypVar =
1770 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1771 if ( !aHypVar->_is_nil() )
1772 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1775 // find or create algorithm
1776 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1777 if ( !anAlgoVar->_is_nil() )
1778 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1784 //================================================================================
1786 * \brief Creates sub-mesh
1787 * \param theMess - Output parameter intended for returning error message
1788 * \param theEntryList - List of entries of published objects
1789 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1793 //================================================================================
1794 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1798 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1799 if ( aSMESHGen->_is_nil() )
1803 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1804 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1805 SMESH::SMESH_Mesh_var aMeshVar =
1806 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1807 if (aMeshVar->_is_nil())
1810 // GEOM shape of the main mesh
1811 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1813 // Name for the new sub-mesh
1814 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1817 GEOM::GEOM_Object_var aGeomVar;
1819 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1820 if (aGEOMs.count() == 1)
1822 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1823 QString aGeomEntry = aGEOMs.first();
1824 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1825 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1827 else if (aGEOMs.count() > 1)
1829 // create a GEOM group
1830 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1831 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1832 if (!geomGen->_is_nil() && aStudy) {
1833 GEOM::GEOM_IGroupOperations_wrap op =
1834 geomGen->GetIGroupOperations(aStudy->StudyId());
1835 if (!op->_is_nil()) {
1836 // check and add all selected GEOM objects: they must be
1837 // a sub-shapes of the main GEOM and must be of one type
1839 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1840 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1841 aSeq->length(aGEOMs.count());
1842 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1843 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1844 QString aSubGeomEntry = (*aSubShapesIter);
1845 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1846 GEOM::GEOM_Object_var aSubGeomVar =
1847 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1848 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1850 aGroupType = aSubShapeType;
1852 if (aSubShapeType != aGroupType)
1853 aGroupType = TopAbs_SHAPE;
1855 aSeq[iSubSh] = aSubGeomVar;
1858 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1859 op->UnionList(aGroupVar, aSeq);
1863 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1865 // publish the GEOM group in study
1866 QString aNewGeomGroupName ("Auto_group_for_");
1867 aNewGeomGroupName += aName;
1868 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1869 SALOMEDS::SObject_wrap aNewGroupSO =
1870 geomGen->AddInStudy( aStudyVar, aGeomVar,
1871 aNewGeomGroupName.toLatin1().data(), mainGeom);
1878 if (aGeomVar->_is_nil())
1881 SUIT_OverrideCursor aWaitCursor;
1884 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1885 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1887 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1888 theEntryList.append( aSubMeshSO->GetID().c_str() );
1891 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1893 if ( !isAccessibleDim( aDim )) continue;
1895 // find or create algorithm
1896 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1897 if ( !anAlgoVar->_is_nil() )
1898 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1899 // assign hypotheses
1900 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1902 const int aHypIndex = currentHyp( aDim, dlgType );
1903 const int aHypType = Min( dlgType, AddHyp );
1904 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1906 SMESH::SMESH_Hypothesis_var aHypVar =
1907 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1908 if ( !aHypVar->_is_nil() )
1909 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1914 // deselect geometry: next submesh should be created on other sub-shape
1915 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1916 selectObject( _PTR(SObject)() );
1919 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1924 //================================================================================
1926 * \brief Gets current hypothesis or algorithms
1927 * \param theDim - dimension of hypothesis or algorithm
1928 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1929 * \retval int - current hypothesis or algorithms
1931 * Gets current hypothesis or algorithms
1933 //================================================================================
1934 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1936 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1939 //================================================================================
1941 * \brief Checks if a hypothesis is selected
1943 //================================================================================
1945 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
1947 if ( theHypType < AddHyp ) // only one hyp can be selected
1948 return currentHyp( theDim, theHypType ) == theIndex;
1950 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
1951 if ( currentHyp( theDim, dlgHypType ) == theIndex )
1957 //================================================================================
1959 * \brief Returns nb of HypType's taking into account possible several
1960 * selected additional hypotheses which are coded as additional HypType's.
1962 //================================================================================
1964 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
1966 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
1969 //================================================================================
1971 * \brief Returns true if hypotheses of given dim can be assigned
1972 * \param theDim - hypotheses dimension
1973 * \retval bool - result
1975 //================================================================================
1976 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1978 return myDlg->isTabEnabled( theDim );
1981 //================================================================================
1983 * \brief Sets current hypothesis or algorithms
1984 * \param theDim - dimension of hypothesis or algorithm
1985 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1986 * \param theIndex - Index of hypothesis
1988 * Gets current hypothesis or algorithms
1990 //================================================================================
1991 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1992 const int theHypType,
1993 const int theIndex )
1995 myIgnoreAlgoSelection = true;
1996 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1997 myIgnoreAlgoSelection = false;
2000 //================================================================================
2002 * \brief Generates default and sets mesh/submesh name
2004 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2006 //================================================================================
2007 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2011 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2014 QString aPrefix = thePrefix;
2015 if ( aPrefix.isEmpty() )
2016 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2018 _PTR(SObject) anObj;
2021 aResName = aPrefix + QString::number( i++ );
2022 anObj = aStudy->FindObject( aResName.toLatin1().data() );
2026 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2027 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2028 aControl->setText( aResName );
2031 //================================================================================
2033 * \brief Gets algorithm or creates it if necessary
2034 * \param theDim - specifies dimension of returned hypotheses/algorifms
2035 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2037 * Gets algorithm or creates it if necessary
2039 //================================================================================
2040 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2042 SMESH::SMESH_Hypothesis_var anAlgoVar;
2044 // get type of the selected algo
2045 int aHypIndex = currentHyp( theDim, Algo );
2046 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2047 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2049 QString aHypName = dataList[ aHypIndex ]->TypeName;
2051 // get existing algoritms
2052 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
2054 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2056 // look for an existing algo of such a type
2057 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2058 THypList::iterator anIter = aHypVarList.begin();
2059 for ( ; anIter != aHypVarList.end(); anIter++)
2061 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2062 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2064 anAlgoVar = aHypVar;
2069 if (anAlgoVar->_is_nil())
2071 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2074 QString aClientLibName = aHypData->ClientLibName;
2075 if ( aClientLibName.isEmpty() )
2077 // Call hypothesis creation server method (without GUI)
2078 SMESH::SMESH_Hypothesis_var aHyp =
2079 SMESH::CreateHypothesis(aHypName, aHypName, true);
2084 // Get hypotheses creator client (GUI)
2085 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2089 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2091 SMESH::SMESH_Hypothesis_var aHyp =
2092 SMESH::CreateHypothesis(aHypName, aHypName, true);
2096 QStringList tmpList;
2097 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2098 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2101 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2102 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2104 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2105 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2107 anAlgoVar = aHypVar;
2113 return anAlgoVar._retn();
2116 //================================================================================
2118 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2120 * Called when mesh is edited only.
2122 //================================================================================
2123 void SMESHGUI_MeshOp::readMesh()
2125 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2126 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2130 if (myIsOnGeometry) {
2131 // Get name of mesh if current object is sub-mesh
2132 SMESH::SMESH_subMesh_var aSubMeshVar =
2133 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2134 if ( !aSubMeshVar->_is_nil() )
2136 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2137 if ( !aMeshVar->_is_nil() )
2139 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2140 QString aMeshName = name( aMeshSO );
2141 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2143 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2146 // Get name of geometry object
2147 CORBA::String_var name = SMESH::GetGeomName( pObj );
2149 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2152 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2153 QStringList anExisting;
2154 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2155 bool algoFound = false;
2156 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2159 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2160 // find algo index among available ones
2162 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2164 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2165 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2166 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2167 // if ( aHypIndex < 0 && algoData ) {
2168 // // assigned algo is incompatible with other algorithms
2169 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2170 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2172 algoFound = ( aHypIndex > -1 );
2174 setCurrentHyp( dim, Algo, aHypIndex );
2175 // set existing and available hypothesis according to the selected algo
2176 if ( aHypIndex > -1 || !algoFound )
2177 onAlgoSelected( aHypIndex, dim );
2181 bool hypWithoutAlgo = false;
2182 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2184 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2187 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2188 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2190 // find index of required hypothesis among existing ones for this dimension and type
2191 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2192 myExistingHyps[ dim ][ hypType ] );
2193 if ( aHypIndex < 0 ) {
2194 // assigned hypothesis is incompatible with the algorithm
2195 if ( currentHyp( dim, Algo ) < 0 )
2196 { // none algo selected; it is edition for sure, of submesh maybe
2197 hypWithoutAlgo = true;
2198 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2199 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2200 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2201 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2204 setCurrentHyp( dim, hypType + i, aHypIndex );
2206 if ( hypType == MainHyp ) break; // only one main hyp allowed
2210 // make available other hyps of same type as one without algo
2211 if ( hypWithoutAlgo )
2212 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2215 //================================================================================
2217 * \brief Gets name of object
2218 * \param theSO - SObject
2219 * \retval QString - name of object
2221 * Gets name of object
2223 //================================================================================
2224 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2229 _PTR(GenericAttribute) anAttr;
2230 _PTR(AttributeName) aNameAttr;
2231 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2234 aResName = aNameAttr->Value().c_str();
2240 //================================================================================
2242 * \brief Finds hypothesis in input list
2243 * \param theHyp - hypothesis to be found
2244 * \param theHypList - input list of hypotheses
2245 * \retval int - index of hypothesis or -1 if it is not found
2247 * Finds position of hypothesis in input list
2249 //================================================================================
2250 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2251 const THypList& theHypList ) const
2254 if ( !theHyp->_is_nil() )
2257 THypList::const_iterator anIter = theHypList.begin();
2258 for ( ; anIter != theHypList.end(); ++ anIter)
2260 if ( theHyp->_is_equivalent( (*anIter).first ) )
2271 //================================================================================
2273 * \brief Edits mesh or sub-mesh
2274 * \param theMess - Output parameter intended for returning error message
2275 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2277 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2279 //================================================================================
2280 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2284 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2285 if ( aSMESHGen->_is_nil() )
2288 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2289 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2293 SUIT_OverrideCursor aWaitCursor;
2296 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2297 SMESH::SetName( pObj, aName );
2298 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2300 // First, remove old algos in order to avoid messages on algorithm hiding
2301 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2303 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2305 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2306 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2307 if ( anAlgoVar->_is_nil() || // no new algo selected or
2308 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2310 // remove old algorithm
2311 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2312 myObjHyps[ dim ][ Algo ].clear();
2317 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2318 CORBA::Object_var anObject = aSObject->GetObject();
2319 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2320 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2321 bool isMesh = !aMeshVar->_is_nil();
2322 if ( !isMesh && !aSubMeshVar->_is_nil() )
2323 aMeshVar = aSubMeshVar->GetFather();
2325 // Assign new algorithms and hypotheses
2326 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2328 if ( !isAccessibleDim( dim )) continue;
2330 // find or create algorithm
2331 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2333 // assign new algorithm
2334 if ( !anAlgoVar->_is_nil() && // some algo selected and
2335 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2338 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2339 else if ( !aSubMeshVar->_is_nil() )
2340 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2342 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2345 // remove deselected hypotheses
2346 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2348 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2350 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2351 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2352 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2354 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2358 // assign newly selected hypotheses
2359 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2361 const int curIndex = currentHyp( dim, dlgType );
2362 const int hypType = Min( dlgType, AddHyp );
2363 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2365 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2367 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2371 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2372 else if ( !aSubMeshVar->_is_nil() )
2373 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2376 // reread all hypotheses of mesh
2377 QStringList anExisting;
2378 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2382 myHasConcurrentSubBefore =
2383 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2388 //================================================================================
2390 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2391 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2392 * order of sub-mesh computation.
2393 * Returns \c true if a sub-mesh concurrency detected.
2395 //================================================================================
2397 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2398 SMESH::SMESH_subMesh_ptr submesh,
2401 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2404 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2405 if ( isNewConcurrent && askUser )
2407 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2408 tr("CONCURRENT_SUBMESH_APPEARS"),
2409 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2412 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2413 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2414 if ( meshSO && aSelectionMgr )
2416 myDlg->setEnabled( false ); // disactivate selection
2417 selectionMgr()->clearFilters();
2418 selectObject( meshSO );
2419 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2420 qApp->processEvents();
2422 myDlg->setEnabled( true );
2423 int obj = myDlg->getActiveObject();
2424 onActivateObject( obj ); // restore filter
2427 selectObject( SMESH::FindSObject( submesh ));
2434 return isNewConcurrent;
2437 //================================================================================
2439 * \brief Verifies whether given operator is valid for this one
2440 * \param theOtherOp - other operation
2441 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2443 * method redefined from base class verifies whether given operator is valid for
2444 * this one (i.e. can be started "above" this operator). In current implementation method
2445 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2448 //================================================================================
2449 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2451 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2454 //================================================================================
2456 * \brief SLOT. Is called when the user selects a way of geometry selection
2457 * \param theByMesh - true if the user wants to find geometry by mesh element
2459 //================================================================================
2460 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2463 if ( !myShapeByMeshOp ) {
2464 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2465 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2466 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2467 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2468 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2470 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2471 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2472 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2473 SMESH::SMESH_Mesh_var aMeshVar =
2474 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2475 if ( !aMeshVar->_is_nil() ) {
2476 myDlg->hide(); // stop processing selection
2477 myShapeByMeshOp->setModule( getSMESHGUI() );
2478 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2479 myShapeByMeshOp->SetMesh( aMeshVar );
2480 myShapeByMeshOp->start();
2486 //================================================================================
2488 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2490 //================================================================================
2491 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2493 if ( myShapeByMeshOp == op ) {
2494 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2496 // Select a found geometry object
2497 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2498 if ( !aGeomVar->_is_nil() )
2500 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2501 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2502 selectObject( aGeomSO );
2509 //================================================================================
2511 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2513 //================================================================================
2514 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2516 if ( myShapeByMeshOp == op && myDlg ) {
2521 //================================================================================
2523 * \brief Selects a SObject
2524 * \param theSObj - the SObject to select
2526 //================================================================================
2527 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2529 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2530 SALOME_ListIO anIOList;
2532 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2533 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2534 anIOList.Append( anIO );
2536 sm->setSelectedObjects( anIOList, false );
2539 //================================================================================
2541 * \brief Create available list types of mesh
2542 * \param theTypeMesh - Output list of available types of mesh
2544 //================================================================================
2545 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2547 theTypeMesh.clear();
2548 theTypeMesh.append( tr( "MT_ANY" ) );
2549 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2551 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2552 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2554 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2556 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2557 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2561 //================================================================================
2563 * \brief Set available types of mesh
2564 * \param theTypeMesh - List of available types of mesh
2566 //================================================================================
2567 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2569 myDlg->setAvailableMeshType( theTypeMesh );
2572 //================================================================================
2574 * \brief SLOT. Is called when the user select type of mesh
2575 * \param theTabIndex - Index of current active tab
2576 * \param theIndex - Index of current type of mesh
2578 //================================================================================
2579 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2581 setFilteredAlgoData( theTabIndex, theIndex);
2584 //================================================================================
2586 * \brief Set a filtered list of available algorithms by mesh type
2587 * \param theTabIndex - Index of current active tab
2588 * \param theIndex - Index of current type of mesh
2590 //================================================================================
2591 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2594 THypDataList anAvailableAlgsData;
2595 QStringList anAvailableAlgs;
2596 QString anCompareType = "";
2597 bool isAvailableChoiceAlgo = false;
2598 int anCurrentAvailableAlgo = 0;
2600 switch ( theIndex ) {
2602 anCompareType = "ANY";
2603 aDim = SMESH::DIM_3D;
2606 aDim = SMESH::DIM_2D;
2607 anCompareType = "TRIA";
2609 case MT_QUADRILATERAL:
2610 aDim = SMESH::DIM_2D;
2611 anCompareType = "QUAD";
2613 case MT_TETRAHEDRAL:
2614 aDim = SMESH::DIM_3D;
2615 anCompareType = "TETRA";
2618 aDim = SMESH::DIM_3D;
2619 anCompareType = "HEXA";
2624 bool toCheckIsApplicableToAll = !myIsMesh;
2625 GEOM::GEOM_Object_var aGeomVar;
2627 myDlg->selectedObject( myToCreate ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Obj );
2628 if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2630 aGeomVar = SMESH::GetGeom( so );
2631 if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
2632 toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
2635 if ( anCompareType == "ANY" )
2637 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2639 isNone = currentHyp( dim, Algo ) < 0;
2640 isAvailableChoiceAlgo = false;
2641 // retrieves a list of available algorithms from resources
2642 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2643 //return current algo in current tab and set new algorithm list
2644 HypothesisData* algoCur;
2645 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2646 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2648 myAvailableHypData[dim][Algo].clear();
2649 anAvailableAlgs.clear();
2650 if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
2651 myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
2652 !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
2654 for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2656 HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2657 if ( aGeomVar->_is_nil() ||
2658 SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2660 anAvailableAlgs.append( curAlgo->Label );
2661 myAvailableHypData[dim][Algo].append( curAlgo );
2664 if ( !isNone && algoCur ) {
2665 for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2667 HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2668 if ( algoAny->Label == algoCur->Label ){
2669 isAvailableChoiceAlgo = true;
2670 anCurrentAvailableAlgo = i;
2675 else if ( !isNone ) {
2676 isAvailableChoiceAlgo = true;
2677 anCurrentAvailableAlgo = currentHyp( dim, Algo );
2680 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2681 if ( isAvailableChoiceAlgo )
2682 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2684 if ( !myIsOnGeometry )
2685 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2686 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2687 else myDlg->enableTab( i );
2690 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2691 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2692 else myDlg->enableTab( i );
2694 myDlg->setCurrentTab( theTabIndex );
2698 QString anCurrentAlgo;
2699 bool isReqDisBound = true;
2700 QString anCurrentCompareType = anCompareType;
2701 isNone = currentHyp( aDim, Algo ) < 0;
2702 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2703 myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2704 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2706 isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2707 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2709 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2710 isAvailableChoiceAlgo = false;
2711 // retrieves a list of available algorithms from resources
2712 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2713 // finding algorithm which is selected
2714 if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2715 myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2716 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2717 else if ( !isNoneAlg )
2718 anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2719 anAvailableAlgs.clear();
2720 myAvailableHypData[dim][Algo].clear();
2721 myFilteredAlgoData[dim].clear();
2722 // finding and adding algorithm depending on the type mesh
2723 for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2725 HypothesisData* algoIn = anAvailableAlgsData.at( i );
2726 bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2727 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2728 for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2730 if ( *inElemType == anCurrentCompareType ) {
2731 isAvailableAlgo = true;
2735 if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
2736 if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2737 SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2739 anAvailableAlgs.append( algoIn->Label );
2740 myAvailableHypData[dim][Algo].append( algoIn );
2741 myFilteredAlgoData[dim].append( algoIn );
2744 //algorithm will be active, if the chosen algorithm available in the current mesh type
2745 if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
2746 isAvailableChoiceAlgo = true;
2747 anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2750 //set new algorithm list and select the current algorithm
2751 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2752 anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2753 if ( isAvailableChoiceAlgo )
2754 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2756 setCurrentHyp( dim, Algo, -1 );
2759 if ( isNone || isReqDisBound ) {
2760 for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
2762 myDlg->disableTab( i );
2763 setCurrentHyp(i, Algo, -1);
2767 else if ( !isNone ) {
2768 if ( aDim == SMESH::DIM_2D){
2769 myDlg->disableTab( SMESH::DIM_3D );
2770 setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2772 for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
2774 isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2775 myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2776 if ( isReqDisBound ) {
2777 for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2778 myDlg->disableTab( j );
2779 setCurrentHyp( j , Algo, -1 );
2785 myDlg->enableTab( aDim );
2786 myDlg->setCurrentTab( aDim );
2788 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2789 QStringList aFilteredHypothesesSetsList;
2790 aFilteredHypothesesSetsList.clear();
2791 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2792 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2794 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2795 bool isAvailable = false;
2796 currentHypoSet->init( true );
2797 while ( currentHypoSet->next(), currentHypoSet->more() )
2799 isAvailable = false;
2800 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2802 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
2804 if ( myAvailableHypData[i][Algo].count() == 0 ) {
2805 availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
2806 for ( int j = 0 ; j < anAvailableAlgsData.count(); j++ )
2808 HypothesisData* aCurAlgo = anAvailableAlgsData.at( j );
2809 if ( aCurAlgo->Label == algoDataIn->Label ){
2816 for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2817 HypothesisData* aCurAlgo = hypData( i, Algo, j );
2818 if ( aCurAlgo->Label == algoDataIn->Label ){
2824 if ( isAvailable ) break;
2826 if ( !isAvailable ) break;
2830 aFilteredHypothesesSetsList.append( *inHypoSetName );
2832 myDlg->setHypoSets( aFilteredHypothesesSetsList );