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>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LightApp_UpdateFlags.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_Session.h>
54 #include <SALOME_InteractiveObject.hxx>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SComponent.hxx>
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDS_Study.hxx>
61 #include <SALOMEDS_wrap.hxx>
64 #include <QStringList>
66 #include <QApplication>
70 #include <TopoDS_Shape.hxx>
71 #include <TopoDS_Shell.hxx>
72 #include <TopExp_Explorer.hxx>
73 #include <BRep_Tool.hxx>
76 #include <SALOMEconfig.h>
77 #include CORBA_CLIENT_HEADER(SMESH_Gen)
79 //================================================================================
82 * \param theToCreate - if this parameter is true then operation is used for creation,
83 * for editing otherwise
85 * Initialize operation
87 //================================================================================
88 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
89 : SMESHGUI_SelectionOp(),
90 myToCreate( theToCreate ),
91 myIsMesh( theIsMesh ),
96 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
97 GeometryGUI::InitGeomGen();
98 myIsOnGeometry = true;
102 //================================================================================
106 //================================================================================
107 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
113 //================================================================================
115 * \brief Gets dialog of this operation
116 * \retval LightApp_Dialog* - pointer to dialog of this operation
118 //================================================================================
119 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
124 //================================================================================
126 * \brief Creates or edits mesh
127 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
129 * Virtual slot redefined from the base class called when "Apply" button is clicked
130 * creates or edits mesh
132 //================================================================================
133 bool SMESHGUI_MeshOp::onApply()
139 if ( !isValid( aMess ) )
143 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
147 bool aResult = false;
151 QStringList anEntryList;
152 if ( myToCreate && myIsMesh )
153 aResult = createMesh( aMess, anEntryList );
154 if ( myToCreate && !myIsMesh )
155 aResult = createSubMesh( aMess, anEntryList );
156 else if ( !myToCreate )
157 aResult = editMeshOrSubMesh( aMess );
160 SMESHGUI::Modified();
161 update( UF_ObjBrowser | UF_Model );
162 if( LightApp_Application* anApp =
163 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
164 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
167 catch ( const SALOME::SALOME_Exception& S_ex )
169 SalomeApp_Tools::QtCatchCorbaException( S_ex );
185 aMess = tr( "SMESH_OPERATION_FAILED" );
186 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
192 //================================================================================
194 * \brief Creates dialog if necessary and shows it
196 * Virtual method redefined from base class called when operation is started creates
197 * dialog if necessary and shows it, activates selection
199 //================================================================================
200 void SMESHGUI_MeshOp::startOperation()
204 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
205 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
207 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
208 this, SLOT( onCreateHyp( const int, const int ) ) );
209 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
210 this, SLOT( onEditHyp( const int, const int ) ) );
211 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
212 this, SLOT( onAlgoSelected( const int ) ) );
214 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
215 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
216 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
218 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
219 else myHelpFileName = "constructing_submeshes_page.html";
222 myHelpFileName = "editing_meshes_page.html";
225 SMESHGUI_SelectionOp::startOperation();
226 // iterate through dimensions and get available algoritms, set them to the dialog
227 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
228 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
230 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
232 // clear available hypotheses
233 aTab->setAvailableHyps( MainHyp, hypList );
234 aTab->setAvailableHyps( AddHyp, hypList );
235 aTab->setExistingHyps( MainHyp, hypList );
236 aTab->setExistingHyps( AddHyp, hypList );
237 myExistingHyps[ i ][ MainHyp ].clear();
238 myExistingHyps[ i ][ AddHyp ].clear();
240 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
241 aTab->setAvailableHyps( Algo, hypList );
246 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
249 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
251 myDlg->setCurrentTab( SMESH::DIM_3D );
253 QStringList TypeMeshList;
254 createMeshTypeList( TypeMeshList );
255 setAvailableMeshType( TypeMeshList );
258 myDlg->setGeomPopupEnabled(false);
261 myIgnoreAlgoSelection = false;
262 myHasConcurrentSubBefore = false;
264 myObjectToSelect.clear();
267 //=================================================================================
269 * \brief Selects a recently created mesh or sub-mesh if necessary
271 * Virtual method redefined from base class called when operation is commited
272 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
273 * selection when the custom selection filters are removed.
275 //=================================================================================
276 void SMESHGUI_MeshOp::commitOperation()
278 SMESHGUI_SelectionOp::commitOperation();
280 if ( !myObjectToSelect.isEmpty() ) {
281 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
282 SUIT_DataOwnerPtrList aList;
283 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
284 aSelectionMgr->setSelected( aList );
289 //================================================================================
291 * \brief Creates selection filter
292 * \param theId - identifier of current selection widget
293 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
295 * Creates selection filter in accordance with identifier of current selection widget
297 //================================================================================
298 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
300 if ( theId == SMESHGUI_MeshDlg::Geom )
302 // TColStd_MapOfInteger allTypesMap;
303 // for ( int i = 0; i < 10; i++ )
304 // allTypesMap.Add( i );
305 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
306 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
308 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
309 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
310 else if ( theId == SMESHGUI_MeshDlg::Mesh )
311 return new SMESH_TypeFilter( SMESH::MESH );
316 //================================================================================
318 * \brief check if selected shape is a sub-shape of the shape to mesh
319 * \retval bool - check result
321 //================================================================================
322 bool SMESHGUI_MeshOp::isSubshapeOk() const
324 if ( !myToCreate || myIsMesh ) // not submesh creation
328 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
329 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
330 if (!pMesh) return false;
332 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
333 if (mesh->_is_nil()) return false;
335 // main shape of the mesh
336 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
337 if (mainGeom->_is_nil()) return false;
341 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
343 if (aGEOMs.count() > 0) {
344 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
345 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
346 if (geomGen->_is_nil() || !aStudy) return false;
348 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
349 if (op->_is_nil()) return false;
351 // check all selected shapes
352 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
353 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
354 QString aSubGeomEntry = (*aSubShapesIter);
355 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
356 if (!pSubGeom) return false;
358 GEOM::GEOM_Object_var aSubGeomVar =
359 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
360 if (aSubGeomVar->_is_nil()) return false;
362 // skl for NPAL14695 - implementation of searching of mainObj
363 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
364 mainObj already exists! */
366 if (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);
380 //================================================================================
382 * \brief Return name of the algorithm that does not support submeshes and makes
383 * submesh creation useless
384 * \retval char* - string is to be deleted!!!
386 //================================================================================
387 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
389 if ( myToCreate && !myIsMesh ) {
391 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
392 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
393 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
396 QStringList algoNames;
398 existingHyps(3, Algo, pMesh, algoNames, algoList);
399 if (!algoList.empty()) {
400 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
402 algo->InputTypes.empty() && // builds all dimensions it-self
403 !algo->IsSupportSubmeshes )
404 return CORBA::string_dup( algoNames[0].toLatin1().data() );
407 // GEOM::GEOM_Object_var geom;
408 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
409 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
411 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
412 existingHyps(2, Algo, pMesh, algoNames, algoList);
413 if (!algoList.empty()) {
414 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
416 algo->InputTypes.empty() && // builds all dimensions it-self
417 !algo->IsSupportSubmeshes )
418 return CORBA::string_dup( algoNames[0].toLatin1().data() );
426 //================================================================================
428 * \brief find an existing submesh by the selected shape
429 * \retval _PTR(SObject) - the found submesh SObject
431 //================================================================================
432 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
434 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
435 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
436 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
437 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
438 if ( pMesh && pGeom ) {
439 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
440 if ( !geom->_is_nil() ) {
442 switch ( geom->GetShapeType() ) {
443 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
444 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
445 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
446 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
447 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
448 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
449 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
452 _PTR(GenericAttribute) anAttr;
453 _PTR(SObject) aSubmeshRoot;
454 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
455 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
457 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
458 for ( ; smIter->More(); smIter->Next() )
460 _PTR(SObject) aSmObj = smIter->Value();
461 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
463 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
464 for ( ; anIter1->More(); anIter1->Next()) {
465 _PTR(SObject) pGeom2 = anIter1->Value();
466 if ( pGeom2->ReferencedObject( pGeom2 ) &&
467 pGeom2->GetID() == pGeom->GetID() )
474 return _PTR(SObject)();
477 //================================================================================
479 * \brief Updates dialog's look and feel
481 * Virtual method redefined from the base class updates dialog's look and feel
483 //================================================================================
484 void SMESHGUI_MeshOp::selectionDone()
486 if (!dlg()->isVisible() || !myDlg->isEnabled())
489 SMESHGUI_SelectionOp::selectionDone();
493 myIsOnGeometry = true;
495 //Check geometry for mesh
496 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
497 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
500 SMESH::SMESH_Mesh_var aMeshVar =
501 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
502 if (!aMeshVar->_is_nil()) {
503 if (!myToCreate && !aMeshVar->HasShapeToMesh())
504 myIsOnGeometry = false;
510 // Enable tabs according to shape dimension
515 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
516 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
518 if (aGEOMs.count() > 0) {
519 // one or more GEOM shape selected
520 aSeq->length(aGEOMs.count());
521 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
523 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
524 QString aSubGeomEntry = (*aSubShapesIter);
525 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
526 GEOM::GEOM_Object_var aSubGeomVar =
527 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
528 aSeq[iSubSh] = aSubGeomVar;
531 // get geometry by selected sub-mesh
532 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
533 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
534 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
535 if (!aGeomVar->_is_nil()) {
541 if (aSeq->length() > 0) {
543 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
544 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
545 switch ( aGeomVar->GetShapeType() ) {
546 case GEOM::SOLID: shapeDim = 3; break;
548 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
550 // TopoDS_Shape aShape;
551 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
552 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
555 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
557 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
558 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
562 if (GEOMBase::GetShape(aGeomVar, aShape))
564 TopExp_Explorer exp (aShape, TopAbs_SOLID);
568 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
569 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
572 // for (; exp.More() && shapeDim == 2; exp.Next()) {
573 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
577 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
578 shapeDim = qMax(2, shapeDim);
579 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
580 shapeDim = qMax(1, shapeDim);
581 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
582 shapeDim = qMax(0, shapeDim);
590 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
591 // reset algos before disabling tabs (0020138)
592 onAlgoSelected(-1, i);
594 myDlg->setMaxHypoDim( shapeDim );
595 myMaxShapeDim = shapeDim;
596 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
598 if (!myToCreate) // edition: read hypotheses
602 SMESH::SMESH_subMesh_var submeshVar =
603 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
604 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
605 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
606 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
607 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
608 myDlg->updateGeometry();
611 myIsMesh = submeshVar->_is_nil();
616 else if ( !myIsMesh ) // submesh creation
618 // if a submesh on the selected shape already exist, pass to submesh edition mode
619 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
620 SMESH::SMESH_subMesh_var sm =
621 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
622 bool editSubmesh = ( !sm->_is_nil() &&
623 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
624 tr( "EDIT_SUBMESH_QUESTION"),
625 SUIT_MessageBox::Yes |
627 SUIT_MessageBox::No )
628 == SUIT_MessageBox::Yes );
631 selectionMgr()->clearFilters();
632 selectObject( pSubmesh );
633 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
638 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
639 selectObject( _PTR(SObject)() );
644 // discard selected mesh if submesh creation not allowed because of
645 // a global algorithm that does not support submeshes
646 if ( char* algoName = isSubmeshIgnored() ) {
647 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
648 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
649 CORBA::string_free( algoName );
650 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
651 selectObject( _PTR(SObject)() );
656 // enable/disable popup for choice of geom selection way
658 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
659 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
660 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
661 if ( !mesh->_is_nil() ) {
662 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
663 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
664 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
665 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
666 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
667 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
670 myDlg->setGeomPopupEnabled( enable );
673 else { // no geometry defined
674 myDlg->enableTab( SMESH::DIM_3D );
676 availableHyps( SMESH::DIM_3D, Algo, hypList,
677 myAvailableHypData[SMESH::DIM_3D][Algo]);
679 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
680 aTab->setAvailableHyps( Algo, hypList );
681 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
682 myDlg->disableTab(i);
685 //Hide labels and fields (Mesh and Geometry)
686 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
687 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
691 int curIndex = myDlg->currentMeshType( );
692 QStringList TypeMeshList;
693 createMeshTypeList( TypeMeshList );
694 setAvailableMeshType( TypeMeshList );
695 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
696 myDlg->setCurrentMeshType( curIndex );
697 setFilteredAlgoData( myMaxShapeDim, curIndex);
699 catch ( const SALOME::SALOME_Exception& S_ex )
701 SalomeApp_Tools::QtCatchCorbaException( S_ex );
708 //================================================================================
710 * \brief Verifies validity of input data
711 * \param theMess - Output parameter intended for returning error message
712 * \retval bool - TRUE if input data is valid, false otherwise
714 * Verifies validity of input data. This method is called when "Apply" or "OK" button
715 * is pressed before mesh creation or editing.
717 //================================================================================
718 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
720 // Selected object to be edited
721 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
723 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
728 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
729 if ( aMeshName.isEmpty() )
731 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
735 /* // Imported mesh, if create sub-mesh or edit mesh
736 if ( !myToCreate || ( myToCreate && !myIsMesh ))
738 QString aMeshEntry = myDlg->selectedObject
739 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
740 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
741 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
742 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
743 theMess = tr( "IMPORTED_MESH" );
752 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
753 if ( aGeomEntry.isEmpty() )
755 theMess = tr( myIsMesh ?
756 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
757 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
761 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
762 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
769 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
770 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
772 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
777 if ( !myIsMesh ) // i.e sub-mesh creation,
779 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
780 if ( aMeshEntry == "" )
782 theMess = tr( "MESH_IS_NOT_DEFINED" );
785 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
786 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
788 theMess = tr( "MESH_IS_NULL" );
791 if ( !isSubshapeOk() )
793 theMess = tr( "INVALID_SUBSHAPE" );
802 //================================================================================
804 * \brief check compatibility of the algorithm and another algorithm or hypothesis
805 * \param theAlgoData - algorithm data
806 * \param theHypData - hypothesis data
807 * \param theHypType - hypothesis type
808 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
809 * \retval bool - check result
811 //================================================================================
812 static bool isCompatible(const HypothesisData* theAlgoData,
813 const HypothesisData* theHypData,
814 const int theHypType)
819 if ( theHypType == SMESHGUI_MeshOp::Algo )
820 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
823 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
826 //================================================================================
828 * \brief Gets available hypotheses or algorithms
829 * \param theDim - specifies dimension of returned hypotheses/algorifms
830 * \param theHypType - specifies whether algorims or hypotheses or additional ones
831 * are retrieved (possible values are in HypType enumeration)
832 * \param theHyps - Output list of hypotheses' names
833 * \param theAlgoData - to select hypos able to be used by this algo (optional)
835 * Gets available hypotheses or algorithm in accordance with input parameters
837 //================================================================================
838 void SMESHGUI_MeshOp::availableHyps( const int theDim,
839 const int theHypType,
840 QStringList& theHyps,
841 THypDataList& theDataList,
842 HypothesisData* theAlgoData ) const
846 bool isAlgo = ( theHypType == Algo );
847 bool isAux = ( theHypType == AddHyp );
848 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
850 QStringList::const_iterator anIter;
851 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
853 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
854 if ( isCompatible ( theAlgoData, aData, theHypType )) {
855 theDataList.append( aData );
856 theHyps.append( aData->Label );
861 //================================================================================
863 * \brief Gets existing hypotheses or algorithms
864 * \param theDim - specifies dimension of returned hypotheses/algorifms
865 * \param theHypType - specifies whether algorims or hypotheses or additional ones
866 * are retrieved (possible values are in HypType enumeration)
867 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
868 * \param theHyps - output list of names.
869 * \param theHypVars - output list of variables.
870 * \param theAlgoData - to select hypos able to be used by this algo (optional)
872 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
875 //================================================================================
876 void SMESHGUI_MeshOp::existingHyps( const int theDim,
877 const int theHypType,
878 _PTR(SObject) theFather,
879 QStringList& theHyps,
880 THypList& theHypList,
881 HypothesisData* theAlgoData)
883 // Clear hypoheses list
890 const bool isAux = ( theHypType == AddHyp );
892 _PTR(SObject) aHypRoot;
893 _PTR(GenericAttribute) anAttr;
894 _PTR(AttributeName) aName;
895 _PTR(AttributeIOR) anIOR;
897 bool isMesh = !_CAST( SComponent, theFather );
900 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
902 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
904 if ( theFather->FindSubObject( aPart, aHypRoot ) )
906 _PTR(ChildIterator) anIter =
907 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
908 for ( ; anIter->More(); anIter->Next() )
910 _PTR(SObject) anObj = anIter->Value();
911 if ( isMesh ) // i.e. mesh or submesh
913 _PTR(SObject) aRefObj;
914 if ( anObj->ReferencedObject( aRefObj ) )
919 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
922 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
923 if ( !CORBA::is_nil( aVar ) )
925 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
926 if ( !aHypVar->_is_nil() )
928 CORBA::String_var hypType = aHypVar->GetName();
929 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
930 if ( !aData) continue;
931 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
932 ( isCompatible ( theAlgoData, aData, theHypType )) &&
933 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ))
935 std::string aHypName = aName->Value();
936 theHyps.append( aHypName.c_str() );
937 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
946 //================================================================================
948 * \brief If create or edit a submesh, return a hypothesis holding parameters used
949 * to mesh a sub-shape
950 * \param aHypType - The hypothesis type name
951 * \param aServerLib - Server library name
952 * \param hypData - The structure holding the hypothesis type etc.
953 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
955 //================================================================================
956 SMESH::SMESH_Hypothesis_var
957 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
958 const QString& aServerLib ) const
960 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
961 return SMESH::SMESH_Hypothesis::_nil();
963 const int nbColonsInMeshEntry = 3;
964 bool isSubMesh = myToCreate ?
966 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
968 // get mesh and geom object
969 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
970 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
975 anEntry = myDlg->selectedObject
976 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
977 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
979 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
980 if ( myToCreate ) // mesh and geom may be selected
982 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
983 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
984 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
985 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
987 else // edition: sub-mesh may be selected
989 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
990 if ( !sm->_is_nil() ) {
991 aMeshVar = sm->GetFather();
992 aGeomVar = sm->GetSubShape();
999 if ( !myToCreate ) // mesh to edit can be selected
1001 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1002 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1004 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1005 if ( !aMeshVar->_is_nil() )
1006 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1009 if ( aGeomVar->_is_nil() ) {
1010 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1011 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1013 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1018 SMESH::SMESH_Hypothesis_var hyp =
1019 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1020 aServerLib.toLatin1().data(),
1023 /*byMesh = */isSubMesh);
1024 if ( hyp->_is_nil() && isSubMesh )
1025 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1026 aServerLib.toLatin1().data(),
1029 /*byMesh = */false);
1033 //================================================================================
1035 * \Brief Returns tab dimention
1036 * \param tab - the tab in the dlg
1037 * \param dlg - my dialogue
1038 * \retval int - dimention
1040 //================================================================================
1041 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1044 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1045 if (tab == dlg->tab(i))
1050 //================================================================================
1052 * \brief Create hypothesis
1053 * \param theHypType - hypothesis category (main or additional)
1054 * \param theIndex - index of type of hypothesis to be cerated
1056 * Specifies dimension of hypothesis to be created (using sender() method),
1057 * specifies its type and calls method for hypothesis creation
1059 //================================================================================
1060 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1062 // Specifies dimension of hypothesis to be created
1063 int aDim = getTabDim( sender(), myDlg );
1067 // Specifies type of hypothesis to be created
1068 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1069 if (theIndex < 0 || theIndex >= dataList.count())
1071 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1073 // Create hypothesis
1074 createHypothesis(aDim, theHypType, aHypTypeName);
1079 QString GetUniqueName (const QStringList& theHypNames,
1080 const QString& theName,
1081 size_t theIteration = 1)
1083 QString aName = theName + "_" + QString::number( theIteration );
1084 if ( theHypNames.contains( aName ) )
1085 return GetUniqueName( theHypNames, theName, ++theIteration );
1090 //================================================================================
1092 * Create hypothesis and update dialog.
1093 * \param theDim - dimension of hypothesis to be created
1094 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1095 * \param theTypeName - specifies hypothesis to be created
1097 //================================================================================
1098 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1100 const QString& theTypeName)
1102 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1108 QStringList aHypNames;
1109 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1110 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1111 const TType2HypList& aType2HypList = aDimIter.value();
1112 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1113 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1114 const THypList& aHypList = aTypeIter.value();
1115 THypList::const_iterator anIter = aHypList.begin();
1116 for ( ; anIter != aHypList.end(); anIter++) {
1117 const THypItem& aHypItem = *anIter;
1118 const QString& aHypName = aHypItem.second;
1119 aHypNames.append(aHypName);
1123 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1126 bool dialog = false;
1128 QString aClientLibName = aData->ClientLibName;
1129 if (aClientLibName == "") {
1130 // Call hypothesis creation server method (without GUI)
1131 SMESH::SMESH_Hypothesis_var aHyp =
1132 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1136 // Get hypotheses creator client (GUI)
1137 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1139 // Create hypothesis
1141 // Get parameters appropriate to initialize a new hypothesis
1142 SMESH::SMESH_Hypothesis_var initParamHyp =
1143 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1145 removeCustomFilters(); // Issue 0020170
1147 // Get Entry of the Geom object
1148 QString aGeomEntry = "";
1149 QString aMeshEntry = "";
1150 QString anObjEntry = "";
1151 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1152 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1153 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1155 if ( myToCreate && myIsMesh )
1156 aMeshEntry = aGeomEntry;
1158 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1159 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1160 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1161 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1164 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1165 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1167 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1168 if ( !aGeomVar->_is_nil() )
1170 aGeomEntry = aGeomVar->GetStudyEntry();
1172 aMeshEntry = aGeomEntry;
1176 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1177 // take geometry from submesh being created
1178 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1180 // if current object is sub-mesh
1181 SMESH::SMESH_subMesh_var aSubMeshVar =
1182 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1183 if ( !aSubMeshVar->_is_nil() ) {
1184 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1185 if ( !aMeshVar->_is_nil() ) {
1186 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1187 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1188 if ( !aGeomVar->_is_nil() )
1189 aMeshEntry = aGeomVar->GetStudyEntry();
1195 aCreator->setShapeEntry( aGeomEntry );
1196 if ( aMeshEntry != "" )
1197 aCreator->setMainShapeEntry( aMeshEntry );
1198 myDlg->setEnabled( false );
1199 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1203 SMESH::SMESH_Hypothesis_var aHyp =
1204 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1213 //================================================================================
1215 * Necessary steps after hypothesis creation
1216 * \param result - creation result:
1219 * 2 = additional value meaning that slot is called not from dialog box
1221 //================================================================================
1222 void SMESHGUI_MeshOp::onHypoCreated( int result )
1226 int obj = myDlg->getActiveObject();
1227 onActivateObject( obj ); // Issue 0020170. Restore filters
1228 myDlg->setEnabled( true );
1231 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1233 int nbHyp = myExistingHyps[myDim][myType].count();
1234 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1235 QStringList aNewHyps;
1236 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1237 if (aNewHyps.count() > nbHyp)
1239 for (int i = nbHyp; i < aNewHyps.count(); i++)
1240 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1243 if( result!=2 && myHypoSet )
1247 //================================================================================
1249 * \brief Calls plugin methods for hypothesis editing
1250 * \param theHypType - specifies whether main hypothesis or additional one
1252 * \param theIndex - index of existing hypothesis
1254 * Calls plugin methods for hypothesis editing
1256 //================================================================================
1257 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1259 // Speicfies dimension of hypothesis to be created
1260 int aDim = getTabDim( sender(), myDlg );
1264 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1265 if ( theIndex < 0 || theIndex >= aList.count() )
1267 const THypItem& aHypItem = aList[ theIndex ];
1268 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1269 if ( aHyp->_is_nil() )
1272 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1275 // Get initial parameters
1276 SMESH::SMESH_Hypothesis_var initParamHyp =
1277 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1278 aCreator->setInitParamsHypothesis( initParamHyp );
1280 // Get Entry of the Geom object
1281 QString aGeomEntry = "";
1282 QString aMeshEntry = "";
1283 QString anObjEntry = "";
1284 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1285 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1286 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1288 if ( myToCreate && myIsMesh )
1289 aMeshEntry = aGeomEntry;
1291 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1292 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1293 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1294 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1297 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1298 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1300 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1301 if ( !aGeomVar->_is_nil() )
1303 aGeomEntry = aGeomVar->GetStudyEntry();
1305 aMeshEntry = aGeomEntry;
1309 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1310 // take geometry from submesh being created
1311 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1313 // if current object is sub-mesh
1314 SMESH::SMESH_subMesh_var aSubMeshVar =
1315 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1316 if ( !aSubMeshVar->_is_nil() ) {
1317 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1318 if ( !aMeshVar->_is_nil() ) {
1319 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1320 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1321 if ( !aGeomVar->_is_nil() )
1322 aMeshEntry = aGeomVar->GetStudyEntry();
1328 aCreator->setShapeEntry( aGeomEntry );
1329 if ( aMeshEntry != "" )
1330 aCreator->setMainShapeEntry( aMeshEntry );
1331 removeCustomFilters(); // Issue 0020170
1332 myDlg->setEnabled( false );
1333 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1337 //================================================================================
1339 * Necessary steps after hypothesis edition
1340 * \param result - creation result:
1344 //================================================================================
1345 void SMESHGUI_MeshOp::onHypoEdited( int result )
1347 int obj = myDlg->getActiveObject();
1348 onActivateObject( obj ); // Issue 0020170. Restore filters
1349 myDlg->setEnabled( true );
1352 //================================================================================
1354 * \brief access to hypothesis data
1355 * \param theDim - hyp dimension
1356 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1357 * \param theIndex - index in the list
1358 * \retval HypothesisData* - result data, may be 0
1360 //================================================================================
1361 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1362 const int theHypType,
1365 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1366 theHypType > -1 && theHypType < NbHypTypes &&
1367 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1368 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1372 //================================================================================
1374 * \brief Set available algos and hypos according to the selected algorithm
1375 * \param theIndex - algorithm index
1377 //================================================================================
1378 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1381 if ( myIgnoreAlgoSelection )
1384 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1388 // find highest available dimension, all algos of this dimension are available for choice
1390 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1391 if (isAccessibleDim( i ))
1396 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1398 // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
1399 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1400 HypothesisData* algoByDim[4];
1401 algoByDim[ aDim ] = algoData;
1403 QStringList anAvailable;
1405 // check that tab enabled of one less dimension
1406 if ( aDim > SMESH::DIM_0D )
1408 if ( isAccessibleDim( aDim - 1 ) )
1410 if (( myDlg->currentMeshType() != MT_ANY ) &&
1411 ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1412 for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1413 if ( isAccessibleDim( i ) ) {
1414 myDlg->disableTab( i );
1415 setCurrentHyp(i, Algo, -1);
1418 else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1420 myDlg->enableTab( aDim - 1 );
1424 // check that algorithms of other dimentions are compatible with
1426 if ( !algoData ) { // all algos becomes available
1427 if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
1428 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1430 anAvailable.clear();
1431 for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1432 HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1433 anAvailable.append( aCurAlgo->Label );
1436 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1438 // 2 loops: backward and forward from algo dimension
1439 for ( int forward = false; forward <= true; ++forward )
1441 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1443 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1445 HypothesisData* prevAlgo = algoData;
1446 bool noCompatible = false;
1447 for ( ; dim * dir <= lastDim * dir; dim += dir)
1449 if ( !isAccessibleDim( dim ))
1451 if ( noCompatible ) { // the selected algo has no compatible ones
1452 anAvailable.clear();
1453 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1454 myAvailableHypData[dim][Algo].clear();
1455 algoByDim[ dim ] = 0;
1458 // get currently selected algo
1459 int algoIndex = currentHyp( dim, Algo );
1460 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1461 if ( curAlgo ) { // some algo selected
1462 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1465 // set new available algoritms
1466 if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1467 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1469 anAvailable.clear();
1470 myAvailableHypData[dim][Algo].clear();
1471 for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1472 HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1473 if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1474 anAvailable.append( aCurAlgo->Label );
1475 myAvailableHypData[dim][Algo].append( aCurAlgo );
1479 HypothesisData* soleCompatible = 0;
1480 if ( anAvailable.count() == 1 )
1481 soleCompatible = myAvailableHypData[dim][Algo][0];
1482 if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1483 if (myDlg->currentMeshType() == MT_ANY)
1484 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1486 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1487 noCompatible = anAvailable.isEmpty();
1489 // restore previously selected algo
1490 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1491 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1492 // select the sole compatible algo
1493 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1494 setCurrentHyp( dim, Algo, algoIndex);
1496 // remember current algo
1497 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1501 // set hypotheses corresponding to the found algoritms
1503 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1505 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1507 if ( !isAccessibleDim( dim ))
1509 for ( int type = MainHyp; type < NbHypTypes; type++ )
1511 myAvailableHypData[ dim ][ type ].clear();
1512 QStringList anAvailable, anExisting;
1514 HypothesisData* curAlgo = algoByDim[ dim ];
1515 int hypIndex = currentHyp( dim, type );
1517 SMESH::SMESH_Hypothesis_var curHyp;
1518 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1519 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1521 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1522 // try to find algo by selected hypothesis in order to keep it selected
1523 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1524 CORBA::String_var curHypType = curHyp->GetName();
1525 if ( !algoDeselectedByUser &&
1526 myObjHyps[ dim ][ type ].count() > 0 &&
1527 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1529 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1530 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1531 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1532 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1539 // get hyps compatible with curAlgo
1540 bool defaulHypAvlbl = false;
1543 // check if a selected hyp is compatible with the curAlgo
1544 if ( !curHyp->_is_nil() ) {
1545 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1546 if ( !isCompatible( curAlgo, hypData, type ))
1547 curHyp = SMESH::SMESH_Hypothesis::_nil();
1549 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1550 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1551 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1553 // set list of hypotheses
1554 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1555 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1557 // set current existing hypothesis
1558 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1559 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1562 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1563 // none is yet selected => select the sole existing if it is not optional
1564 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1565 bool isOptional = true;
1566 if ( algoByDim[ dim ] &&
1567 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1571 setCurrentHyp( dim, type, hypIndex );
1576 //================================================================================
1578 * \brief Creates and selects hypothesis of hypotheses set
1579 * \param theSetName - The name of hypotheses set
1581 //================================================================================
1582 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1584 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1589 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1590 setCurrentHyp(dim, Algo, -1);
1591 setCurrentHyp(dim, AddHyp, -1);
1592 setCurrentHyp(dim, MainHyp, -1);
1595 myHypoSet->init(true); //algorithms
1597 myHypoSet->init(false); //hypotheses
1602 //================================================================================
1604 * \brief One step of hypothesis/algorithm list creation
1606 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1608 //================================================================================
1609 void SMESHGUI_MeshOp::processSet()
1612 if( !myHypoSet->more() )
1615 bool isAlgo = myHypoSet->isAlgo();
1616 QString aHypoTypeName = myHypoSet->current();
1617 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1624 int aDim = aHypData->Dim[0];
1625 // create or/and set
1628 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1631 QStringList anAvailable;
1632 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1633 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1634 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1636 setCurrentHyp( aDim, Algo, index );
1637 onAlgoSelected( index, aDim );
1642 bool mainHyp = true;
1643 QStringList anAvailable;
1644 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1645 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1646 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1650 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1653 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1659 //================================================================================
1661 * \brief Creates mesh
1662 * \param theMess - Output parameter intended for returning error message
1663 * \param theEntryList - List of entries of published objects
1664 * \retval bool - TRUE if mesh is created, FALSE otherwise
1668 //================================================================================
1669 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1674 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1675 if ( aList.isEmpty() )
1677 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1678 if ( aSMESHGen->_is_nil() )
1681 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1682 if ( aMeshVar->_is_nil() )
1685 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1687 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1688 theEntryList.append( aMeshSO->GetID().c_str() );
1693 if ( aList.count() > 1 )
1695 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1696 int i = namePrefix.length() - 1;
1697 while ( i > 0 && namePrefix[i].isDigit() )
1699 if ( i < namePrefix.length() - 1 )
1700 namePrefix.chop( namePrefix.length() - 1 - i );
1704 QStringList::Iterator it = aList.begin();
1705 for ( int i = 0; it!=aList.end(); it++, ++i )
1707 QString aGeomEntry = *it;
1708 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1709 GEOM::GEOM_Object_var aGeomVar =
1710 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1712 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1713 if ( aSMESHGen->_is_nil() )
1716 SUIT_OverrideCursor aWaitCursor;
1719 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1720 if ( aMeshVar->_is_nil() )
1722 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1724 theEntryList.append( aMeshSO->GetID().c_str() );
1725 if ( i > 0 ) setDefaultName( namePrefix );
1726 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1729 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1730 if ( !isAccessibleDim( aDim )) continue;
1732 // assign hypotheses
1733 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1734 int aHypIndex = currentHyp( aDim, aHypType );
1735 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1736 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1737 if ( !aHypVar->_is_nil() )
1738 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1741 // find or create algorithm
1742 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1743 if ( !anAlgoVar->_is_nil() )
1744 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1750 //================================================================================
1752 * \brief Creates sub-mesh
1753 * \param theMess - Output parameter intended for returning error message
1754 * \param theEntryList - List of entries of published objects
1755 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1759 //================================================================================
1760 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1764 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1765 if ( aSMESHGen->_is_nil() )
1769 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1770 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1771 SMESH::SMESH_Mesh_var aMeshVar =
1772 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1773 if (aMeshVar->_is_nil())
1776 // GEOM shape of the main mesh
1777 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1779 // Name for the new sub-mesh
1780 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1783 GEOM::GEOM_Object_var aGeomVar;
1785 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1786 if (aGEOMs.count() == 1)
1788 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1789 QString aGeomEntry = aGEOMs.first();
1790 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1791 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1793 else if (aGEOMs.count() > 1)
1795 // create a GEOM group
1796 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1797 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1798 if (!geomGen->_is_nil() && aStudy) {
1799 GEOM::GEOM_IGroupOperations_wrap op =
1800 geomGen->GetIGroupOperations(aStudy->StudyId());
1801 if (!op->_is_nil()) {
1802 // check and add all selected GEOM objects: they must be
1803 // a sub-shapes of the main GEOM and must be of one type
1805 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1806 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1807 aSeq->length(aGEOMs.count());
1808 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1809 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1810 QString aSubGeomEntry = (*aSubShapesIter);
1811 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1812 GEOM::GEOM_Object_var aSubGeomVar =
1813 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1814 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1816 aGroupType = aSubShapeType;
1818 if (aSubShapeType != aGroupType)
1819 aGroupType = TopAbs_SHAPE;
1821 aSeq[iSubSh] = aSubGeomVar;
1824 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1825 op->UnionList(aGroupVar, aSeq);
1829 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1831 // publish the GEOM group in study
1832 QString aNewGeomGroupName ("Auto_group_for_");
1833 aNewGeomGroupName += aName;
1834 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1835 SALOMEDS::SObject_wrap aNewGroupSO =
1836 geomGen->AddInStudy( aStudyVar, aGeomVar,
1837 aNewGeomGroupName.toLatin1().data(), mainGeom);
1844 if (aGeomVar->_is_nil())
1847 SUIT_OverrideCursor aWaitCursor;
1850 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1851 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1853 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1854 theEntryList.append( aSubMeshSO->GetID().c_str() );
1857 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1859 if ( !isAccessibleDim( aDim )) continue;
1861 // find or create algorithm
1862 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1863 if ( !anAlgoVar->_is_nil() )
1864 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1865 // assign hypotheses
1866 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1868 int aHypIndex = currentHyp( aDim, aHypType );
1869 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1871 SMESH::SMESH_Hypothesis_var aHypVar =
1872 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1873 if ( !aHypVar->_is_nil() )
1874 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1879 // deselect geometry: next submesh should be created on other sub-shape
1880 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1881 selectObject( _PTR(SObject)() );
1884 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1889 //================================================================================
1891 * \brief Gets current hypothesis or algorithms
1892 * \param theDim - dimension of hypothesis or algorithm
1893 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1894 * \retval int - current hypothesis or algorithms
1896 * Gets current hypothesis or algorithms
1898 //================================================================================
1899 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1901 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1904 //================================================================================
1906 * \brief Returns true if hypotheses of given dim can be assigned
1907 * \param theDim - hypotheses dimension
1908 * \retval bool - result
1910 //================================================================================
1911 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1913 return myDlg->isTabEnabled( theDim );
1916 //================================================================================
1918 * \brief Sets current hypothesis or algorithms
1919 * \param theDim - dimension of hypothesis or algorithm
1920 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1921 * \param theIndex - Index of hypothesis
1923 * Gets current hypothesis or algorithms
1925 //================================================================================
1926 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1927 const int theHypType,
1928 const int theIndex )
1930 myIgnoreAlgoSelection = true;
1931 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1932 myIgnoreAlgoSelection = false;
1935 //================================================================================
1937 * \brief Generates default and sets mesh/submesh name
1939 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1941 //================================================================================
1942 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1946 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1949 QString aPrefix = thePrefix;
1950 if ( aPrefix.isEmpty() )
1951 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1953 _PTR(SObject) anObj;
1956 aResName = aPrefix + QString::number( i++ );
1957 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1961 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1962 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1963 aControl->setText( aResName );
1966 //================================================================================
1968 * \brief Gets algorithm or creates it if necessary
1969 * \param theDim - specifies dimension of returned hypotheses/algorifms
1970 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1972 * Gets algorithm or creates it if necessary
1974 //================================================================================
1975 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1977 SMESH::SMESH_Hypothesis_var anAlgoVar;
1979 // get type of the selected algo
1980 int aHypIndex = currentHyp( theDim, Algo );
1981 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1982 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1984 QString aHypName = dataList[ aHypIndex ]->TypeName;
1986 // get existing algoritms
1987 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1989 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1991 // look for an existing algo of such a type
1992 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1993 THypList::iterator anIter = aHypVarList.begin();
1994 for ( ; anIter != aHypVarList.end(); anIter++)
1996 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1997 CORBA::String_var aName = aHypVar->GetName();
1998 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2000 anAlgoVar = aHypVar;
2005 if (anAlgoVar->_is_nil())
2007 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2010 QString aClientLibName = aHypData->ClientLibName;
2011 if ( aClientLibName.isEmpty() )
2013 // Call hypothesis creation server method (without GUI)
2014 SMESH::SMESH_Hypothesis_var aHyp =
2015 SMESH::CreateHypothesis(aHypName, aHypName, true);
2020 // Get hypotheses creator client (GUI)
2021 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2025 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2027 SMESH::SMESH_Hypothesis_var aHyp =
2028 SMESH::CreateHypothesis(aHypName, aHypName, true);
2032 QStringList tmpList;
2033 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2034 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2037 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2038 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2040 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2041 CORBA::String_var aName = aHypVar->GetName();
2042 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2044 anAlgoVar = aHypVar;
2050 return anAlgoVar._retn();
2053 //================================================================================
2055 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2057 * Called when mesh is edited only.
2059 //================================================================================
2060 void SMESHGUI_MeshOp::readMesh()
2062 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2063 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2067 if (myIsOnGeometry) {
2068 // Get name of mesh if current object is sub-mesh
2069 SMESH::SMESH_subMesh_var aSubMeshVar =
2070 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2071 if ( !aSubMeshVar->_is_nil() )
2073 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2074 if ( !aMeshVar->_is_nil() )
2076 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2077 QString aMeshName = name( aMeshSO );
2078 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2080 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2083 // Get name of geometry object
2084 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2085 if ( !aGeomVar->_is_nil() )
2087 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2088 QString aShapeName = name( aGeomSO );
2089 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2093 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2094 QStringList anExisting;
2095 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2096 bool algoFound = false;
2097 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2100 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2101 // find algo index among available ones
2103 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2105 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2106 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2107 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2108 // if ( aHypIndex < 0 && algoData ) {
2109 // // assigned algo is incompatible with other algorithms
2110 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2111 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2113 algoFound = ( aHypIndex > -1 );
2115 setCurrentHyp( dim, Algo, aHypIndex );
2116 // set existing and available hypothesis according to the selected algo
2117 if ( aHypIndex > -1 || !algoFound )
2118 onAlgoSelected( aHypIndex, dim );
2122 bool hypWithoutAlgo = false;
2123 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2125 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2128 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2129 // find index of requered hypothesis among existing ones for this dimension and type
2131 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2132 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2133 myExistingHyps[ dim ][ hypType ] );
2134 if ( aHypIndex < 0 ) {
2135 // assigned hypothesis is incompatible with the algorithm
2136 if ( currentHyp( dim, Algo ) < 0 )
2137 { // none algo selected; it is edition for sure, of submesh maybe
2138 hypWithoutAlgo = true;
2139 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2140 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2141 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2145 setCurrentHyp( dim, hypType, aHypIndex );
2148 // make available other hyps of same type as one without algo
2149 if ( hypWithoutAlgo )
2150 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2153 //================================================================================
2155 * \brief Gets name of object
2156 * \param theSO - SObject
2157 * \retval QString - name of object
2159 * Gets name of object
2161 //================================================================================
2162 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2167 _PTR(GenericAttribute) anAttr;
2168 _PTR(AttributeName) aNameAttr;
2169 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2172 aResName = aNameAttr->Value().c_str();
2178 //================================================================================
2180 * \brief Finds hypothesis in input list
2181 * \param theHyp - hypothesis to be found
2182 * \param theHypList - input list of hypotheses
2183 * \retval int - index of hypothesis or -1 if it is not found
2185 * Finds position of hypothesis in input list
2187 //================================================================================
2188 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2189 const THypList& theHypList ) const
2192 if ( !theHyp->_is_nil() )
2195 THypList::const_iterator anIter = theHypList.begin();
2196 for ( ; anIter != theHypList.end(); ++ anIter)
2198 if ( theHyp->_is_equivalent( (*anIter).first ) )
2209 //================================================================================
2211 * \brief Edits mesh or sub-mesh
2212 * \param theMess - Output parameter intended for returning error message
2213 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2215 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2217 //================================================================================
2218 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2222 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2223 if ( aSMESHGen->_is_nil() )
2226 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2227 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2231 SUIT_OverrideCursor aWaitCursor;
2234 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2235 SMESH::SetName( pObj, aName );
2236 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2238 // First, remove old algos in order to avoid messages on algorithm hiding
2239 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2241 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2243 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2244 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2245 if ( anAlgoVar->_is_nil() || // no new algo selected or
2246 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2248 // remove old algorithm
2249 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2250 myObjHyps[ dim ][ Algo ].clear();
2255 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2256 CORBA::Object_var anObject = aSObject->GetObject();
2257 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2258 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2259 bool isMesh = !aMeshVar->_is_nil();
2260 if ( !isMesh && !aSubMeshVar->_is_nil() )
2261 aMeshVar = aSubMeshVar->GetFather();
2263 // Assign new algorithms and hypotheses
2264 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2266 if ( !isAccessibleDim( dim )) continue;
2268 // find or create algorithm
2269 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2271 // assign new algorithm
2272 if ( !anAlgoVar->_is_nil() && // some algo selected and
2273 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2276 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2277 else if ( !aSubMeshVar->_is_nil() )
2278 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2280 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2283 // assign hypotheses
2284 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2286 int aNewHypIndex = currentHyp( dim, hypType );
2287 int anOldHypIndex = -1;
2289 // remove old hypotheses
2290 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2292 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2293 myExistingHyps[ dim ][ hypType ] );
2294 if ( aNewHypIndex != anOldHypIndex || // different hyps
2295 anOldHypIndex == -1 ) // hyps of different algos
2297 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2298 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2299 myObjHyps[ dim ][ hypType ].clear();
2303 // assign new hypotheses
2304 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex > -1 )
2307 SMESH::AddHypothesisOnMesh
2308 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2309 else if ( !aSubMeshVar->_is_nil() )
2310 SMESH::AddHypothesisOnSubMesh
2311 ( aSubMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2313 // reread all hypotheses of mesh if necessary
2314 QStringList anExisting;
2315 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2319 myHasConcurrentSubBefore =
2320 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2325 //================================================================================
2327 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2328 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2329 * order of sub-mesh computation.
2330 * Returns \c true if a sub-mesh concurrency detected.
2332 //================================================================================
2334 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2335 SMESH::SMESH_subMesh_ptr submesh,
2338 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2341 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2342 if ( isNewConcurrent && askUser )
2344 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2345 tr("CONCURRENT_SUBMESH_APPEARS"),
2346 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2349 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2350 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2351 if ( meshSO && aSelectionMgr )
2353 myDlg->setEnabled( false ); // disactivate selection
2354 selectionMgr()->clearFilters();
2355 selectObject( meshSO );
2356 SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2357 qApp->processEvents();
2359 myDlg->setEnabled( true );
2360 int obj = myDlg->getActiveObject();
2361 onActivateObject( obj ); // restore filter
2364 selectObject( SMESH::FindSObject( submesh ));
2371 return isNewConcurrent;
2374 //================================================================================
2376 * \brief Verifies whether given operator is valid for this one
2377 * \param theOtherOp - other operation
2378 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2380 * method redefined from base class verifies whether given operator is valid for
2381 * this one (i.e. can be started "above" this operator). In current implementation method
2382 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2385 //================================================================================
2386 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2388 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2391 //================================================================================
2393 * \brief SLOT. Is called when the user selects a way of geometry selection
2394 * \param theByMesh - true if the user wants to find geometry by mesh element
2396 //================================================================================
2397 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2400 if ( !myShapeByMeshOp ) {
2401 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2402 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2403 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2404 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2405 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2407 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2408 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2409 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2410 SMESH::SMESH_Mesh_var aMeshVar =
2411 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2412 if ( !aMeshVar->_is_nil() ) {
2413 myDlg->hide(); // stop processing selection
2414 myShapeByMeshOp->setModule( getSMESHGUI() );
2415 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2416 myShapeByMeshOp->SetMesh( aMeshVar );
2417 myShapeByMeshOp->start();
2423 //================================================================================
2425 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2427 //================================================================================
2428 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2430 if ( myShapeByMeshOp == op ) {
2431 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2433 // Select a found geometry object
2434 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2435 if ( !aGeomVar->_is_nil() )
2437 QString ID = aGeomVar->GetStudyEntry();
2438 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2439 selectObject( aGeomSO );
2446 //================================================================================
2448 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2450 //================================================================================
2451 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2453 if ( myShapeByMeshOp == op && myDlg ) {
2458 //================================================================================
2460 * \brief Selects a SObject
2461 * \param theSObj - the SObject to select
2463 //================================================================================
2464 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2466 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2467 SALOME_ListIO anIOList;
2469 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2470 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2471 anIOList.Append( anIO );
2473 sm->setSelectedObjects( anIOList, false );
2476 //================================================================================
2478 * \brief Create available list types of mesh
2479 * \param theTypeMesh - Output list of available types of mesh
2481 //================================================================================
2482 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2484 theTypeMesh.clear();
2485 theTypeMesh.append( tr( "MT_ANY" ) );
2486 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2488 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2489 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2491 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2493 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2494 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2498 //================================================================================
2500 * \brief Set available types of mesh
2501 * \param theTypeMesh - List of available types of mesh
2503 //================================================================================
2504 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2506 myDlg->setAvailableMeshType( theTypeMesh );
2509 //================================================================================
2511 * \brief SLOT. Is called when the user select type of mesh
2512 * \param theTabIndex - Index of current active tab
2513 * \param theIndex - Index of current type of mesh
2515 //================================================================================
2516 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2518 setFilteredAlgoData( theTabIndex, theIndex);
2521 //================================================================================
2523 * \brief Set a filtered list of available algorithms by mesh type
2524 * \param theTabIndex - Index of current active tab
2525 * \param theIndex - Index of current type of mesh
2527 //================================================================================
2528 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2531 THypDataList anAvailableAlgsData;
2532 QStringList anAvailableAlgs;
2533 QString anCompareType = "";
2534 bool isAvailableChoiceAlgo = false;
2535 int anCurrentAvailableAlgo = 0;
2537 switch ( theIndex ) {
2539 anCompareType = "ANY";
2540 aDim = SMESH::DIM_3D;
2543 case MT_TRIANGULAR:{
2544 aDim = SMESH::DIM_2D;
2545 anCompareType = "TRIA";
2548 case MT_QUADRILATERAL:{
2549 aDim = SMESH::DIM_2D;
2550 anCompareType = "QUAD";
2553 case MT_TETRAHEDRAL:{
2554 aDim = SMESH::DIM_3D;
2555 anCompareType = "TETRA";
2558 case MT_HEXAHEDRAL:{
2559 aDim = SMESH::DIM_3D;
2560 anCompareType = "HEXA";
2565 if ( anCompareType == "ANY" )
2567 for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
2569 isNone = currentHyp( dim, Algo ) < 0;
2570 isAvailableChoiceAlgo = false;
2571 // retrieves a list of available algorithms from resources
2572 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2573 //return current algo in current tab and set new algorithm list
2574 HypothesisData* algoCur;
2575 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ){
2576 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2578 myAvailableHypData[dim][Algo].clear();
2579 anAvailableAlgs.clear();
2580 for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2582 HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2583 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2584 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
2585 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2587 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2589 if ( aGeomVar->_is_nil() ||
2590 ( !aGeomVar->_is_nil() && SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, !myIsMesh ))){
2591 anAvailableAlgs.append( curAlgo->Label );
2592 myAvailableHypData[dim][Algo].append( curAlgo );
2595 if ( !isNone && algoCur ){
2596 for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2598 HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2599 if ( algoAny->Label == algoCur->Label ){
2600 isAvailableChoiceAlgo = true;
2601 anCurrentAvailableAlgo = i;
2606 else if ( !isNone ){
2607 isAvailableChoiceAlgo = true;
2608 anCurrentAvailableAlgo = currentHyp( dim, Algo );
2610 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2611 if ( isAvailableChoiceAlgo )
2612 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2614 if ( !myIsOnGeometry )
2615 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2616 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2617 else myDlg->enableTab( i );
2620 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2621 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2622 else myDlg->enableTab( i );
2624 myDlg->setCurrentTab( theTabIndex );
2628 QString anCurrentAlgo;
2629 bool isReqDisBound = true;
2630 QString anCurrentCompareType = anCompareType;
2631 isNone = currentHyp( aDim, Algo ) < 0;
2632 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2633 myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2634 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2636 isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2637 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2639 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2640 isAvailableChoiceAlgo = false;
2641 // retrieves a list of available algorithms from resources
2642 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2643 // finding algorithm which is selected
2644 if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2645 myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2646 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2647 else if ( !isNoneAlg )
2648 anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2649 anAvailableAlgs.clear();
2650 myAvailableHypData[dim][Algo].clear();
2651 myFilteredAlgoData[dim].clear();
2652 // finding and adding algorithm depending on the type mesh
2653 for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2655 HypothesisData* algoIn = anAvailableAlgsData.at( i );
2656 bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2657 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2658 for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2660 if ( *inElemType == anCurrentCompareType ){
2661 isAvailableAlgo = true;
2665 if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ){
2666 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2667 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
2668 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2670 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2672 if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2673 ( !aGeomVar->_is_nil() && SMESH::IsApplicable( algoIn->TypeName, aGeomVar, !myIsMesh ))){
2674 anAvailableAlgs.append( algoIn->Label );
2675 myAvailableHypData[dim][Algo].append( algoIn );
2676 myFilteredAlgoData[dim].append( algoIn );
2679 //algorithm will be active, if the chosen algorithm available in the current mesh type
2680 if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ){
2681 isAvailableChoiceAlgo = true;
2682 anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2685 //set new algorithm list and select the current algorithm
2686 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2687 anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2688 if ( isAvailableChoiceAlgo )
2689 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2691 setCurrentHyp( dim, Algo, -1 );
2694 int aMaxShapeDim = ( myMaxShapeDim != aDim) ? aDim : myMaxShapeDim;
2695 if ( isNone || isReqDisBound ) {
2696 for ( int i = SMESH::DIM_0D; i <= aMaxShapeDim; i++ ) {
2698 myDlg->disableTab( i );
2699 setCurrentHyp(i, Algo, -1);
2703 else if ( !isNone ){
2704 if ( aDim == SMESH::DIM_2D){
2705 myDlg->disableTab( SMESH::DIM_3D );
2706 setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2708 for ( int i = aMaxShapeDim; i > SMESH::DIM_0D; i-- )
2710 isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2711 myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2712 if ( isReqDisBound ) {
2713 for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2714 myDlg->disableTab( j );
2715 setCurrentHyp( j , Algo, -1 );
2721 myDlg->enableTab( aDim );
2722 myDlg->setCurrentTab( aDim );
2724 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2725 QStringList aFilteredHypothesesSetsList;
2726 aFilteredHypothesesSetsList.clear();
2727 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2728 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2730 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2731 bool isAvailable = false;
2732 currentHypoSet->init( true );
2733 while ( currentHypoSet->next(), currentHypoSet->more() )
2735 isAvailable = false;
2736 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2738 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
2740 for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2741 HypothesisData* aCurAlgo = hypData( i, Algo, j );
2742 if ( aCurAlgo->Label == algoDataIn->Label ){
2747 if ( isAvailable ) break;
2749 if ( !isAvailable ) break;
2753 aFilteredHypothesesSetsList.append( *inHypoSetName );
2755 myDlg->setHypoSets( aFilteredHypothesesSetsList );