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 QStringList TypeMeshList;
692 createMeshTypeList( TypeMeshList );
693 setAvailableMeshType( TypeMeshList );
694 setFilteredAlgoData( myMaxShapeDim, myDlg->currentMeshType( ));
696 catch ( const SALOME::SALOME_Exception& S_ex )
698 SalomeApp_Tools::QtCatchCorbaException( S_ex );
705 //================================================================================
707 * \brief Verifies validity of input data
708 * \param theMess - Output parameter intended for returning error message
709 * \retval bool - TRUE if input data is valid, false otherwise
711 * Verifies validity of input data. This method is called when "Apply" or "OK" button
712 * is pressed before mesh creation or editing.
714 //================================================================================
715 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
717 // Selected object to be edited
718 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
720 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
725 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
726 if ( aMeshName.isEmpty() )
728 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
732 /* // Imported mesh, if create sub-mesh or edit mesh
733 if ( !myToCreate || ( myToCreate && !myIsMesh ))
735 QString aMeshEntry = myDlg->selectedObject
736 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
737 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
738 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
739 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
740 theMess = tr( "IMPORTED_MESH" );
749 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
750 if ( aGeomEntry.isEmpty() )
752 theMess = tr( myIsMesh ?
753 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
754 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
758 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
759 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
766 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
767 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
769 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
774 if ( !myIsMesh ) // i.e sub-mesh creation,
776 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
777 if ( aMeshEntry == "" )
779 theMess = tr( "MESH_IS_NOT_DEFINED" );
782 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
783 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
785 theMess = tr( "MESH_IS_NULL" );
788 if ( !isSubshapeOk() )
790 theMess = tr( "INVALID_SUBSHAPE" );
799 //================================================================================
801 * \brief check compatibility of the algorithm and another algorithm or hypothesis
802 * \param theAlgoData - algorithm data
803 * \param theHypData - hypothesis data
804 * \param theHypType - hypothesis type
805 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
806 * \retval bool - check result
808 //================================================================================
809 static bool isCompatible(const HypothesisData* theAlgoData,
810 const HypothesisData* theHypData,
811 const int theHypType)
816 if ( theHypType == SMESHGUI_MeshOp::Algo )
817 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
820 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
823 //================================================================================
825 * \brief Gets available hypotheses or algorithms
826 * \param theDim - specifies dimension of returned hypotheses/algorifms
827 * \param theHypType - specifies whether algorims or hypotheses or additional ones
828 * are retrieved (possible values are in HypType enumeration)
829 * \param theHyps - Output list of hypotheses' names
830 * \param theAlgoData - to select hypos able to be used by this algo (optional)
832 * Gets available hypotheses or algorithm in accordance with input parameters
834 //================================================================================
835 void SMESHGUI_MeshOp::availableHyps( const int theDim,
836 const int theHypType,
837 QStringList& theHyps,
838 THypDataList& theDataList,
839 HypothesisData* theAlgoData ) const
843 bool isAlgo = ( theHypType == Algo );
844 bool isAux = ( theHypType == AddHyp );
845 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
847 QStringList::const_iterator anIter;
848 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
850 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
851 if ( isCompatible ( theAlgoData, aData, theHypType )) {
852 theDataList.append( aData );
853 theHyps.append( aData->Label );
858 //================================================================================
860 * \brief Gets existing hypotheses or algorithms
861 * \param theDim - specifies dimension of returned hypotheses/algorifms
862 * \param theHypType - specifies whether algorims or hypotheses or additional ones
863 * are retrieved (possible values are in HypType enumeration)
864 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
865 * \param theHyps - output list of names.
866 * \param theHypVars - output list of variables.
867 * \param theAlgoData - to select hypos able to be used by this algo (optional)
869 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
872 //================================================================================
873 void SMESHGUI_MeshOp::existingHyps( const int theDim,
874 const int theHypType,
875 _PTR(SObject) theFather,
876 QStringList& theHyps,
877 THypList& theHypList,
878 HypothesisData* theAlgoData)
880 // Clear hypoheses list
887 const bool isAux = ( theHypType == AddHyp );
889 _PTR(SObject) aHypRoot;
890 _PTR(GenericAttribute) anAttr;
891 _PTR(AttributeName) aName;
892 _PTR(AttributeIOR) anIOR;
894 bool isMesh = !_CAST( SComponent, theFather );
897 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
899 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
901 if ( theFather->FindSubObject( aPart, aHypRoot ) )
903 _PTR(ChildIterator) anIter =
904 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
905 for ( ; anIter->More(); anIter->Next() )
907 _PTR(SObject) anObj = anIter->Value();
908 if ( isMesh ) // i.e. mesh or submesh
910 _PTR(SObject) aRefObj;
911 if ( anObj->ReferencedObject( aRefObj ) )
916 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
919 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
920 if ( !CORBA::is_nil( aVar ) )
922 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
923 if ( !aHypVar->_is_nil() )
925 CORBA::String_var hypType = aHypVar->GetName();
926 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
927 if ( !aData) continue;
928 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
929 ( isCompatible ( theAlgoData, aData, theHypType )) &&
930 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ))
932 std::string aHypName = aName->Value();
933 theHyps.append( aHypName.c_str() );
934 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
943 //================================================================================
945 * \brief If create or edit a submesh, return a hypothesis holding parameters used
946 * to mesh a sub-shape
947 * \param aHypType - The hypothesis type name
948 * \param aServerLib - Server library name
949 * \param hypData - The structure holding the hypothesis type etc.
950 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
952 //================================================================================
953 SMESH::SMESH_Hypothesis_var
954 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
955 const QString& aServerLib ) const
957 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
958 return SMESH::SMESH_Hypothesis::_nil();
960 const int nbColonsInMeshEntry = 3;
961 bool isSubMesh = myToCreate ?
963 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
965 // get mesh and geom object
966 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
967 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
972 anEntry = myDlg->selectedObject
973 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
974 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
976 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
977 if ( myToCreate ) // mesh and geom may be selected
979 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
980 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
981 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
982 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
984 else // edition: sub-mesh may be selected
986 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
987 if ( !sm->_is_nil() ) {
988 aMeshVar = sm->GetFather();
989 aGeomVar = sm->GetSubShape();
996 if ( !myToCreate ) // mesh to edit can be selected
998 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
999 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1001 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1002 if ( !aMeshVar->_is_nil() )
1003 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1006 if ( aGeomVar->_is_nil() ) {
1007 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1008 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1010 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1015 SMESH::SMESH_Hypothesis_var hyp =
1016 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1017 aServerLib.toLatin1().data(),
1020 /*byMesh = */isSubMesh);
1021 if ( hyp->_is_nil() && isSubMesh )
1022 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1023 aServerLib.toLatin1().data(),
1026 /*byMesh = */false);
1030 //================================================================================
1032 * \Brief Returns tab dimention
1033 * \param tab - the tab in the dlg
1034 * \param dlg - my dialogue
1035 * \retval int - dimention
1037 //================================================================================
1038 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1041 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1042 if (tab == dlg->tab(i))
1047 //================================================================================
1049 * \brief Create hypothesis
1050 * \param theHypType - hypothesis category (main or additional)
1051 * \param theIndex - index of type of hypothesis to be cerated
1053 * Specifies dimension of hypothesis to be created (using sender() method),
1054 * specifies its type and calls method for hypothesis creation
1056 //================================================================================
1057 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1059 // Specifies dimension of hypothesis to be created
1060 int aDim = getTabDim( sender(), myDlg );
1064 // Specifies type of hypothesis to be created
1065 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1066 if (theIndex < 0 || theIndex >= dataList.count())
1068 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1070 // Create hypothesis
1071 createHypothesis(aDim, theHypType, aHypTypeName);
1076 QString GetUniqueName (const QStringList& theHypNames,
1077 const QString& theName,
1078 size_t theIteration = 1)
1080 QString aName = theName + "_" + QString::number( theIteration );
1081 if ( theHypNames.contains( aName ) )
1082 return GetUniqueName( theHypNames, theName, ++theIteration );
1087 //================================================================================
1089 * Create hypothesis and update dialog.
1090 * \param theDim - dimension of hypothesis to be created
1091 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1092 * \param theTypeName - specifies hypothesis to be created
1094 //================================================================================
1095 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1097 const QString& theTypeName)
1099 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1105 QStringList aHypNames;
1106 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1107 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1108 const TType2HypList& aType2HypList = aDimIter.value();
1109 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1110 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1111 const THypList& aHypList = aTypeIter.value();
1112 THypList::const_iterator anIter = aHypList.begin();
1113 for ( ; anIter != aHypList.end(); anIter++) {
1114 const THypItem& aHypItem = *anIter;
1115 const QString& aHypName = aHypItem.second;
1116 aHypNames.append(aHypName);
1120 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1123 bool dialog = false;
1125 QString aClientLibName = aData->ClientLibName;
1126 if (aClientLibName == "") {
1127 // Call hypothesis creation server method (without GUI)
1128 SMESH::SMESH_Hypothesis_var aHyp =
1129 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1133 // Get hypotheses creator client (GUI)
1134 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1136 // Create hypothesis
1138 // Get parameters appropriate to initialize a new hypothesis
1139 SMESH::SMESH_Hypothesis_var initParamHyp =
1140 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1142 removeCustomFilters(); // Issue 0020170
1144 // Get Entry of the Geom object
1145 QString aGeomEntry = "";
1146 QString aMeshEntry = "";
1147 QString anObjEntry = "";
1148 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1149 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1150 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1152 if ( myToCreate && myIsMesh )
1153 aMeshEntry = aGeomEntry;
1155 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1156 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1157 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1158 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1161 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1162 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1164 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1165 if ( !aGeomVar->_is_nil() )
1167 aGeomEntry = aGeomVar->GetStudyEntry();
1169 aMeshEntry = aGeomEntry;
1173 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1174 // take geometry from submesh being created
1175 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1177 // if current object is sub-mesh
1178 SMESH::SMESH_subMesh_var aSubMeshVar =
1179 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1180 if ( !aSubMeshVar->_is_nil() ) {
1181 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1182 if ( !aMeshVar->_is_nil() ) {
1183 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1184 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1185 if ( !aGeomVar->_is_nil() )
1186 aMeshEntry = aGeomVar->GetStudyEntry();
1192 aCreator->setShapeEntry( aGeomEntry );
1193 if ( aMeshEntry != "" )
1194 aCreator->setMainShapeEntry( aMeshEntry );
1195 myDlg->setEnabled( false );
1196 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1200 SMESH::SMESH_Hypothesis_var aHyp =
1201 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1210 //================================================================================
1212 * Necessary steps after hypothesis creation
1213 * \param result - creation result:
1216 * 2 = additional value meaning that slot is called not from dialog box
1218 //================================================================================
1219 void SMESHGUI_MeshOp::onHypoCreated( int result )
1223 int obj = myDlg->getActiveObject();
1224 onActivateObject( obj ); // Issue 0020170. Restore filters
1225 myDlg->setEnabled( true );
1228 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1230 int nbHyp = myExistingHyps[myDim][myType].count();
1231 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1232 QStringList aNewHyps;
1233 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1234 if (aNewHyps.count() > nbHyp)
1236 for (int i = nbHyp; i < aNewHyps.count(); i++)
1237 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1240 if( result!=2 && myHypoSet )
1244 //================================================================================
1246 * \brief Calls plugin methods for hypothesis editing
1247 * \param theHypType - specifies whether main hypothesis or additional one
1249 * \param theIndex - index of existing hypothesis
1251 * Calls plugin methods for hypothesis editing
1253 //================================================================================
1254 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1256 // Speicfies dimension of hypothesis to be created
1257 int aDim = getTabDim( sender(), myDlg );
1261 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1262 if ( theIndex < 0 || theIndex >= aList.count() )
1264 const THypItem& aHypItem = aList[ theIndex ];
1265 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1266 if ( aHyp->_is_nil() )
1269 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1272 // Get initial parameters
1273 SMESH::SMESH_Hypothesis_var initParamHyp =
1274 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1275 aCreator->setInitParamsHypothesis( initParamHyp );
1277 // Get Entry of the Geom object
1278 QString aGeomEntry = "";
1279 QString aMeshEntry = "";
1280 QString anObjEntry = "";
1281 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1282 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1283 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1285 if ( myToCreate && myIsMesh )
1286 aMeshEntry = aGeomEntry;
1288 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1289 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1290 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1291 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1294 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1295 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1297 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1298 if ( !aGeomVar->_is_nil() )
1300 aGeomEntry = aGeomVar->GetStudyEntry();
1302 aMeshEntry = aGeomEntry;
1306 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1307 // take geometry from submesh being created
1308 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1310 // if current object is sub-mesh
1311 SMESH::SMESH_subMesh_var aSubMeshVar =
1312 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1313 if ( !aSubMeshVar->_is_nil() ) {
1314 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1315 if ( !aMeshVar->_is_nil() ) {
1316 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1317 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1318 if ( !aGeomVar->_is_nil() )
1319 aMeshEntry = aGeomVar->GetStudyEntry();
1325 aCreator->setShapeEntry( aGeomEntry );
1326 if ( aMeshEntry != "" )
1327 aCreator->setMainShapeEntry( aMeshEntry );
1328 removeCustomFilters(); // Issue 0020170
1329 myDlg->setEnabled( false );
1330 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1334 //================================================================================
1336 * Necessary steps after hypothesis edition
1337 * \param result - creation result:
1341 //================================================================================
1342 void SMESHGUI_MeshOp::onHypoEdited( int result )
1344 int obj = myDlg->getActiveObject();
1345 onActivateObject( obj ); // Issue 0020170. Restore filters
1346 myDlg->setEnabled( true );
1349 //================================================================================
1351 * \brief access to hypothesis data
1352 * \param theDim - hyp dimension
1353 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1354 * \param theIndex - index in the list
1355 * \retval HypothesisData* - result data, may be 0
1357 //================================================================================
1358 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1359 const int theHypType,
1362 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1363 theHypType > -1 && theHypType < NbHypTypes &&
1364 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1365 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1369 //================================================================================
1371 * \brief Set available algos and hypos according to the selected algorithm
1372 * \param theIndex - algorithm index
1374 //================================================================================
1375 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1378 if ( myIgnoreAlgoSelection )
1381 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1385 // find highest available dimension, all algos of this dimension are available for choice
1387 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1388 if (isAccessibleDim( i ))
1393 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1395 // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
1396 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1397 HypothesisData* algoByDim[4];
1398 algoByDim[ aDim ] = algoData;
1400 QStringList anAvailable;
1402 // check that tab enabled of one less dimension
1403 if ( aDim > SMESH::DIM_0D )
1405 if ( isAccessibleDim( aDim - 1 ) )
1407 if (( myDlg->currentMeshType() != MT_ANY ) &&
1408 ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1409 for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1410 if ( isAccessibleDim( i ) ) {
1411 myDlg->disableTab( i );
1412 setCurrentHyp(i, Algo, -1);
1415 else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1417 myDlg->enableTab( aDim - 1 );
1421 // check that algorithms of other dimentions are compatible with
1423 if ( !algoData ) { // all algos becomes available
1424 if (myDlg->currentMeshType() == MT_ANY)
1425 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1427 anAvailable.clear();
1428 for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1429 HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1430 anAvailable.append( aCurAlgo->Label );
1433 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1435 // 2 loops: backward and forward from algo dimension
1436 for ( int forward = false; forward <= true; ++forward )
1438 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1440 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1442 HypothesisData* prevAlgo = algoData;
1443 bool noCompatible = false;
1444 for ( ; dim * dir <= lastDim * dir; dim += dir)
1446 if ( !isAccessibleDim( dim ))
1448 if ( noCompatible ) { // the selected algo has no compatible ones
1449 anAvailable.clear();
1450 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1451 myAvailableHypData[dim][Algo].clear();
1452 algoByDim[ dim ] = 0;
1455 // get currently selected algo
1456 int algoIndex = currentHyp( dim, Algo );
1457 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1458 if ( curAlgo ) { // some algo selected
1459 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1462 // set new available algoritms
1463 if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1464 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1466 anAvailable.clear();
1467 myAvailableHypData[dim][Algo].clear();
1468 for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1469 HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1470 if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1471 anAvailable.append( aCurAlgo->Label );
1472 myAvailableHypData[dim][Algo].append( aCurAlgo );
1476 HypothesisData* soleCompatible = 0;
1477 if ( anAvailable.count() == 1 )
1478 soleCompatible = myAvailableHypData[dim][Algo][0];
1479 if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1480 if (myDlg->currentMeshType() == MT_ANY)
1481 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1483 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1484 noCompatible = anAvailable.isEmpty();
1486 // restore previously selected algo
1487 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1488 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1489 // select the sole compatible algo
1490 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1491 setCurrentHyp( dim, Algo, algoIndex);
1493 // remember current algo
1494 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1498 // set hypotheses corresponding to the found algoritms
1500 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1502 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1504 if ( !isAccessibleDim( dim ))
1506 for ( int type = MainHyp; type < NbHypTypes; type++ )
1508 myAvailableHypData[ dim ][ type ].clear();
1509 QStringList anAvailable, anExisting;
1511 HypothesisData* curAlgo = algoByDim[ dim ];
1512 int hypIndex = currentHyp( dim, type );
1514 SMESH::SMESH_Hypothesis_var curHyp;
1515 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1516 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1518 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1519 // try to find algo by selected hypothesis in order to keep it selected
1520 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1521 CORBA::String_var curHypType = curHyp->GetName();
1522 if ( !algoDeselectedByUser &&
1523 myObjHyps[ dim ][ type ].count() > 0 &&
1524 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1526 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1527 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1528 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1529 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1536 // get hyps compatible with curAlgo
1537 bool defaulHypAvlbl = false;
1540 // check if a selected hyp is compatible with the curAlgo
1541 if ( !curHyp->_is_nil() ) {
1542 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1543 if ( !isCompatible( curAlgo, hypData, type ))
1544 curHyp = SMESH::SMESH_Hypothesis::_nil();
1546 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1547 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1548 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1550 // set list of hypotheses
1551 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1552 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1554 // set current existing hypothesis
1555 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1556 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1559 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1560 // none is yet selected => select the sole existing if it is not optional
1561 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1562 bool isOptional = true;
1563 if ( algoByDim[ dim ] &&
1564 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1568 setCurrentHyp( dim, type, hypIndex );
1573 //================================================================================
1575 * \brief Creates and selects hypothesis of hypotheses set
1576 * \param theSetName - The name of hypotheses set
1578 //================================================================================
1579 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1581 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1586 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1587 setCurrentHyp(dim, Algo, -1);
1588 setCurrentHyp(dim, AddHyp, -1);
1589 setCurrentHyp(dim, MainHyp, -1);
1592 myHypoSet->init(true); //algorithms
1594 myHypoSet->init(false); //hypotheses
1599 //================================================================================
1601 * \brief One step of hypothesis/algorithm list creation
1603 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1605 //================================================================================
1606 void SMESHGUI_MeshOp::processSet()
1609 if( !myHypoSet->more() )
1612 bool isAlgo = myHypoSet->isAlgo();
1613 QString aHypoTypeName = myHypoSet->current();
1614 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1621 int aDim = aHypData->Dim[0];
1622 // create or/and set
1625 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1628 QStringList anAvailable;
1629 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1630 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1631 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1633 setCurrentHyp( aDim, Algo, index );
1634 onAlgoSelected( index, aDim );
1639 bool mainHyp = true;
1640 QStringList anAvailable;
1641 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1642 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1643 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1647 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1650 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1656 //================================================================================
1658 * \brief Creates mesh
1659 * \param theMess - Output parameter intended for returning error message
1660 * \param theEntryList - List of entries of published objects
1661 * \retval bool - TRUE if mesh is created, FALSE otherwise
1665 //================================================================================
1666 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1671 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1672 if ( aList.isEmpty() )
1674 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1675 if ( aSMESHGen->_is_nil() )
1678 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1679 if ( aMeshVar->_is_nil() )
1682 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1684 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1685 theEntryList.append( aMeshSO->GetID().c_str() );
1690 if ( aList.count() > 1 )
1692 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1693 int i = namePrefix.length() - 1;
1694 while ( i > 0 && namePrefix[i].isDigit() )
1696 if ( i < namePrefix.length() - 1 )
1697 namePrefix.chop( namePrefix.length() - 1 - i );
1701 QStringList::Iterator it = aList.begin();
1702 for ( int i = 0; it!=aList.end(); it++, ++i )
1704 QString aGeomEntry = *it;
1705 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1706 GEOM::GEOM_Object_var aGeomVar =
1707 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1709 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1710 if ( aSMESHGen->_is_nil() )
1713 SUIT_OverrideCursor aWaitCursor;
1716 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1717 if ( aMeshVar->_is_nil() )
1719 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1721 theEntryList.append( aMeshSO->GetID().c_str() );
1722 if ( i > 0 ) setDefaultName( namePrefix );
1723 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1726 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1727 if ( !isAccessibleDim( aDim )) continue;
1729 // assign hypotheses
1730 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1731 int aHypIndex = currentHyp( aDim, aHypType );
1732 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1733 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1734 if ( !aHypVar->_is_nil() )
1735 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1738 // find or create algorithm
1739 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1740 if ( !anAlgoVar->_is_nil() )
1741 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1747 //================================================================================
1749 * \brief Creates sub-mesh
1750 * \param theMess - Output parameter intended for returning error message
1751 * \param theEntryList - List of entries of published objects
1752 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1756 //================================================================================
1757 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1761 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1762 if ( aSMESHGen->_is_nil() )
1766 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1767 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1768 SMESH::SMESH_Mesh_var aMeshVar =
1769 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1770 if (aMeshVar->_is_nil())
1773 // GEOM shape of the main mesh
1774 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1776 // Name for the new sub-mesh
1777 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1780 GEOM::GEOM_Object_var aGeomVar;
1782 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1783 if (aGEOMs.count() == 1)
1785 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1786 QString aGeomEntry = aGEOMs.first();
1787 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1788 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1790 else if (aGEOMs.count() > 1)
1792 // create a GEOM group
1793 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1794 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1795 if (!geomGen->_is_nil() && aStudy) {
1796 GEOM::GEOM_IGroupOperations_wrap op =
1797 geomGen->GetIGroupOperations(aStudy->StudyId());
1798 if (!op->_is_nil()) {
1799 // check and add all selected GEOM objects: they must be
1800 // a sub-shapes of the main GEOM and must be of one type
1802 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1803 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1804 aSeq->length(aGEOMs.count());
1805 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1806 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1807 QString aSubGeomEntry = (*aSubShapesIter);
1808 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1809 GEOM::GEOM_Object_var aSubGeomVar =
1810 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1811 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1813 aGroupType = aSubShapeType;
1815 if (aSubShapeType != aGroupType)
1816 aGroupType = TopAbs_SHAPE;
1818 aSeq[iSubSh] = aSubGeomVar;
1821 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1822 op->UnionList(aGroupVar, aSeq);
1826 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1828 // publish the GEOM group in study
1829 QString aNewGeomGroupName ("Auto_group_for_");
1830 aNewGeomGroupName += aName;
1831 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1832 SALOMEDS::SObject_wrap aNewGroupSO =
1833 geomGen->AddInStudy( aStudyVar, aGeomVar,
1834 aNewGeomGroupName.toLatin1().data(), mainGeom);
1841 if (aGeomVar->_is_nil())
1844 SUIT_OverrideCursor aWaitCursor;
1847 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1848 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1850 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1851 theEntryList.append( aSubMeshSO->GetID().c_str() );
1854 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1856 if ( !isAccessibleDim( aDim )) continue;
1858 // find or create algorithm
1859 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1860 if ( !anAlgoVar->_is_nil() )
1861 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1862 // assign hypotheses
1863 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1865 int aHypIndex = currentHyp( aDim, aHypType );
1866 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1868 SMESH::SMESH_Hypothesis_var aHypVar =
1869 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1870 if ( !aHypVar->_is_nil() )
1871 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1876 // deselect geometry: next submesh should be created on other sub-shape
1877 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1878 selectObject( _PTR(SObject)() );
1881 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1886 //================================================================================
1888 * \brief Gets current hypothesis or algorithms
1889 * \param theDim - dimension of hypothesis or algorithm
1890 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1891 * \retval int - current hypothesis or algorithms
1893 * Gets current hypothesis or algorithms
1895 //================================================================================
1896 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1898 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1901 //================================================================================
1903 * \brief Returns true if hypotheses of given dim can be assigned
1904 * \param theDim - hypotheses dimension
1905 * \retval bool - result
1907 //================================================================================
1908 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1910 return myDlg->isTabEnabled( theDim );
1913 //================================================================================
1915 * \brief Sets current hypothesis or algorithms
1916 * \param theDim - dimension of hypothesis or algorithm
1917 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1918 * \param theIndex - Index of hypothesis
1920 * Gets current hypothesis or algorithms
1922 //================================================================================
1923 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1924 const int theHypType,
1925 const int theIndex )
1927 myIgnoreAlgoSelection = true;
1928 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1929 myIgnoreAlgoSelection = false;
1932 //================================================================================
1934 * \brief Generates default and sets mesh/submesh name
1936 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1938 //================================================================================
1939 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1943 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1946 QString aPrefix = thePrefix;
1947 if ( aPrefix.isEmpty() )
1948 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1950 _PTR(SObject) anObj;
1953 aResName = aPrefix + QString::number( i++ );
1954 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1958 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1959 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1960 aControl->setText( aResName );
1963 //================================================================================
1965 * \brief Gets algorithm or creates it if necessary
1966 * \param theDim - specifies dimension of returned hypotheses/algorifms
1967 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1969 * Gets algorithm or creates it if necessary
1971 //================================================================================
1972 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1974 SMESH::SMESH_Hypothesis_var anAlgoVar;
1976 // get type of the selected algo
1977 int aHypIndex = currentHyp( theDim, Algo );
1978 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1979 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1981 QString aHypName = dataList[ aHypIndex ]->TypeName;
1983 // get existing algoritms
1984 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1986 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1988 // look for an existing algo of such a type
1989 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1990 THypList::iterator anIter = aHypVarList.begin();
1991 for ( ; anIter != aHypVarList.end(); anIter++)
1993 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1994 CORBA::String_var aName = aHypVar->GetName();
1995 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1997 anAlgoVar = aHypVar;
2002 if (anAlgoVar->_is_nil())
2004 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2007 QString aClientLibName = aHypData->ClientLibName;
2008 if ( aClientLibName.isEmpty() )
2010 // Call hypothesis creation server method (without GUI)
2011 SMESH::SMESH_Hypothesis_var aHyp =
2012 SMESH::CreateHypothesis(aHypName, aHypName, true);
2017 // Get hypotheses creator client (GUI)
2018 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2022 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2024 SMESH::SMESH_Hypothesis_var aHyp =
2025 SMESH::CreateHypothesis(aHypName, aHypName, true);
2029 QStringList tmpList;
2030 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2031 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2034 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2035 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2037 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2038 CORBA::String_var aName = aHypVar->GetName();
2039 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2041 anAlgoVar = aHypVar;
2047 return anAlgoVar._retn();
2050 //================================================================================
2052 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2054 * Called when mesh is edited only.
2056 //================================================================================
2057 void SMESHGUI_MeshOp::readMesh()
2059 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2060 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2064 if (myIsOnGeometry) {
2065 // Get name of mesh if current object is sub-mesh
2066 SMESH::SMESH_subMesh_var aSubMeshVar =
2067 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2068 if ( !aSubMeshVar->_is_nil() )
2070 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2071 if ( !aMeshVar->_is_nil() )
2073 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2074 QString aMeshName = name( aMeshSO );
2075 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2077 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2080 // Get name of geometry object
2081 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2082 if ( !aGeomVar->_is_nil() )
2084 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2085 QString aShapeName = name( aGeomSO );
2086 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2090 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2091 QStringList anExisting;
2092 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2093 bool algoFound = false;
2094 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2097 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2098 // find algo index among available ones
2100 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2102 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2103 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2104 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2105 // if ( aHypIndex < 0 && algoData ) {
2106 // // assigned algo is incompatible with other algorithms
2107 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2108 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2110 algoFound = ( aHypIndex > -1 );
2112 setCurrentHyp( dim, Algo, aHypIndex );
2113 // set existing and available hypothesis according to the selected algo
2114 if ( aHypIndex > -1 || !algoFound )
2115 onAlgoSelected( aHypIndex, dim );
2119 bool hypWithoutAlgo = false;
2120 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2122 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2125 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2126 // find index of requered hypothesis among existing ones for this dimension and type
2128 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2129 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2130 myExistingHyps[ dim ][ hypType ] );
2131 if ( aHypIndex < 0 ) {
2132 // assigned hypothesis is incompatible with the algorithm
2133 if ( currentHyp( dim, Algo ) < 0 )
2134 { // none algo selected; it is edition for sure, of submesh maybe
2135 hypWithoutAlgo = true;
2136 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2137 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2138 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2142 setCurrentHyp( dim, hypType, aHypIndex );
2145 // make available other hyps of same type as one without algo
2146 if ( hypWithoutAlgo )
2147 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2150 //================================================================================
2152 * \brief Gets name of object
2153 * \param theSO - SObject
2154 * \retval QString - name of object
2156 * Gets name of object
2158 //================================================================================
2159 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2164 _PTR(GenericAttribute) anAttr;
2165 _PTR(AttributeName) aNameAttr;
2166 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2169 aResName = aNameAttr->Value().c_str();
2175 //================================================================================
2177 * \brief Finds hypothesis in input list
2178 * \param theHyp - hypothesis to be found
2179 * \param theHypList - input list of hypotheses
2180 * \retval int - index of hypothesis or -1 if it is not found
2182 * Finds position of hypothesis in input list
2184 //================================================================================
2185 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2186 const THypList& theHypList ) const
2189 if ( !theHyp->_is_nil() )
2192 THypList::const_iterator anIter = theHypList.begin();
2193 for ( ; anIter != theHypList.end(); ++ anIter)
2195 if ( theHyp->_is_equivalent( (*anIter).first ) )
2206 //================================================================================
2208 * \brief Edits mesh or sub-mesh
2209 * \param theMess - Output parameter intended for returning error message
2210 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2212 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2214 //================================================================================
2215 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2219 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2220 if ( aSMESHGen->_is_nil() )
2223 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2224 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2228 SUIT_OverrideCursor aWaitCursor;
2231 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2232 SMESH::SetName( pObj, aName );
2233 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2235 // First, remove old algos in order to avoid messages on algorithm hiding
2236 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2238 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2240 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2241 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2242 if ( anAlgoVar->_is_nil() || // no new algo selected or
2243 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2245 // remove old algorithm
2246 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2247 myObjHyps[ dim ][ Algo ].clear();
2252 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2253 CORBA::Object_var anObject = aSObject->GetObject();
2254 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2255 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2256 bool isMesh = !aMeshVar->_is_nil();
2257 if ( !isMesh && !aSubMeshVar->_is_nil() )
2258 aMeshVar = aSubMeshVar->GetFather();
2260 // Assign new algorithms and hypotheses
2261 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2263 if ( !isAccessibleDim( dim )) continue;
2265 // find or create algorithm
2266 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2268 // assign new algorithm
2269 if ( !anAlgoVar->_is_nil() && // some algo selected and
2270 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2273 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2274 else if ( !aSubMeshVar->_is_nil() )
2275 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2277 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2280 // assign hypotheses
2281 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2283 int aNewHypIndex = currentHyp( dim, hypType );
2284 int anOldHypIndex = -1;
2286 // remove old hypotheses
2287 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2289 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2290 myExistingHyps[ dim ][ hypType ] );
2291 if ( aNewHypIndex != anOldHypIndex || // different hyps
2292 anOldHypIndex == -1 ) // hyps of different algos
2294 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2295 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2296 myObjHyps[ dim ][ hypType ].clear();
2300 // assign new hypotheses
2301 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex > -1 )
2304 SMESH::AddHypothesisOnMesh
2305 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2306 else if ( !aSubMeshVar->_is_nil() )
2307 SMESH::AddHypothesisOnSubMesh
2308 ( aSubMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2310 // reread all hypotheses of mesh if necessary
2311 QStringList anExisting;
2312 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2316 myHasConcurrentSubBefore =
2317 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2322 //================================================================================
2324 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2325 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2326 * order of sub-mesh computation.
2327 * Returns \c true if a sub-mesh concurrency detected.
2329 //================================================================================
2331 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2332 SMESH::SMESH_subMesh_ptr submesh,
2335 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2338 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2339 if ( isNewConcurrent && askUser )
2341 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2342 tr("CONCURRENT_SUBMESH_APPEARS"),
2343 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2346 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2347 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2348 if ( meshSO && aSelectionMgr )
2350 myDlg->setEnabled( false ); // disactivate selection
2351 selectionMgr()->clearFilters();
2352 selectObject( meshSO );
2353 SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2354 qApp->processEvents();
2356 myDlg->setEnabled( true );
2357 int obj = myDlg->getActiveObject();
2358 onActivateObject( obj ); // restore filter
2361 selectObject( SMESH::FindSObject( submesh ));
2368 return isNewConcurrent;
2371 //================================================================================
2373 * \brief Verifies whether given operator is valid for this one
2374 * \param theOtherOp - other operation
2375 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2377 * method redefined from base class verifies whether given operator is valid for
2378 * this one (i.e. can be started "above" this operator). In current implementation method
2379 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2382 //================================================================================
2383 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2385 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2388 //================================================================================
2390 * \brief SLOT. Is called when the user selects a way of geometry selection
2391 * \param theByMesh - true if the user wants to find geometry by mesh element
2393 //================================================================================
2394 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2397 if ( !myShapeByMeshOp ) {
2398 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2399 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2400 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2401 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2402 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2404 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2405 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2406 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2407 SMESH::SMESH_Mesh_var aMeshVar =
2408 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2409 if ( !aMeshVar->_is_nil() ) {
2410 myDlg->hide(); // stop processing selection
2411 myShapeByMeshOp->setModule( getSMESHGUI() );
2412 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2413 myShapeByMeshOp->SetMesh( aMeshVar );
2414 myShapeByMeshOp->start();
2420 //================================================================================
2422 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2424 //================================================================================
2425 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2427 if ( myShapeByMeshOp == op ) {
2428 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2430 // Select a found geometry object
2431 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2432 if ( !aGeomVar->_is_nil() )
2434 QString ID = aGeomVar->GetStudyEntry();
2435 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2436 selectObject( aGeomSO );
2443 //================================================================================
2445 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2447 //================================================================================
2448 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2450 if ( myShapeByMeshOp == op && myDlg ) {
2455 //================================================================================
2457 * \brief Selects a SObject
2458 * \param theSObj - the SObject to select
2460 //================================================================================
2461 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2463 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2464 SALOME_ListIO anIOList;
2466 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2467 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2468 anIOList.Append( anIO );
2470 sm->setSelectedObjects( anIOList, false );
2473 //================================================================================
2475 * \brief Create available list types of mesh
2476 * \param theTypeMesh - Output list of available types of mesh
2478 //================================================================================
2479 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2481 theTypeMesh.clear();
2482 theTypeMesh.append( tr( "MT_ANY" ) );
2483 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2485 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2486 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2488 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2490 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2491 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2495 //================================================================================
2497 * \brief Set available types of mesh
2498 * \param theTypeMesh - List of available types of mesh
2500 //================================================================================
2501 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2503 myDlg->setAvailableMeshType( theTypeMesh );
2506 //================================================================================
2508 * \brief SLOT. Is called when the user select type of mesh
2509 * \param theTabIndex - Index of current active tab
2510 * \param theIndex - Index of current type of mesh
2512 //================================================================================
2513 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2515 setFilteredAlgoData( theTabIndex, theIndex);
2518 //================================================================================
2520 * \brief Set a filtered list of available algorithms by mesh type
2521 * \param theTabIndex - Index of current active tab
2522 * \param theIndex - Index of current type of mesh
2524 //================================================================================
2525 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2528 THypDataList anAvailableAlgsData;
2529 QStringList anAvailableAlgs;
2530 QString anCompareType = "";
2531 bool isAvailableChoiceAlgo = false;
2532 int anCurrentAvailableAlgo = 0;
2534 switch ( theIndex ) {
2536 anCompareType = "ANY";
2537 aDim = SMESH::DIM_3D;
2540 case MT_TRIANGULAR:{
2541 aDim = SMESH::DIM_2D;
2542 anCompareType = "TRIA";
2545 case MT_QUADRILATERAL:{
2546 aDim = SMESH::DIM_2D;
2547 anCompareType = "QUAD";
2550 case MT_TETRAHEDRAL:{
2551 aDim = SMESH::DIM_3D;
2552 anCompareType = "TETRA";
2555 case MT_HEXAHEDRAL:{
2556 aDim = SMESH::DIM_3D;
2557 anCompareType = "HEXA";
2562 if ( anCompareType == "ANY" )
2564 for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
2566 isNone = currentHyp( dim, Algo ) < 0;
2567 isAvailableChoiceAlgo = false;
2568 // retrieves a list of available algorithms from resources
2569 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2570 //return current algo in current tab and set new algorithm list
2571 HypothesisData* algoCur;
2572 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ){
2573 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2575 myAvailableHypData[dim][Algo].clear();
2576 anAvailableAlgs.clear();
2577 for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2579 HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2580 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2581 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
2582 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2584 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2586 if ( aGeomVar->_is_nil() ||
2587 ( !aGeomVar->_is_nil() && SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, !myIsMesh ))){
2588 anAvailableAlgs.append( curAlgo->Label );
2589 myAvailableHypData[dim][Algo].append( curAlgo );
2592 if ( !isNone && algoCur ){
2593 for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2595 HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2596 if ( algoAny->Label == algoCur->Label ){
2597 isAvailableChoiceAlgo = true;
2598 anCurrentAvailableAlgo = i;
2603 else if ( !isNone ){
2604 isAvailableChoiceAlgo = true;
2605 anCurrentAvailableAlgo = currentHyp( dim, Algo );
2607 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2608 if ( isAvailableChoiceAlgo )
2609 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2611 if ( !myIsOnGeometry )
2612 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2613 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2614 else myDlg->enableTab( i );
2617 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2618 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2619 else myDlg->enableTab( i );
2621 myDlg->setCurrentTab( theTabIndex );
2625 QString anCurrentAlgo;
2626 bool isReqDisBound = true;
2627 QString anCurrentCompareType = anCompareType;
2628 isNone = currentHyp( aDim, Algo ) < 0;
2629 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2630 myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2631 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2633 isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2634 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2636 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2637 isAvailableChoiceAlgo = false;
2638 // retrieves a list of available algorithms from resources
2639 availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2640 // finding algorithm which is selected
2641 if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2642 myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2643 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2644 else if ( !isNoneAlg )
2645 anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2646 anAvailableAlgs.clear();
2647 myAvailableHypData[dim][Algo].clear();
2648 myFilteredAlgoData[dim].clear();
2649 // finding and adding algorithm depending on the type mesh
2650 for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2652 HypothesisData* algoIn = anAvailableAlgsData.at( i );
2653 bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2654 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2655 for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2657 if ( *inElemType == anCurrentCompareType ){
2658 isAvailableAlgo = true;
2662 if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ){
2663 QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2664 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
2665 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2667 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2669 if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2670 ( !aGeomVar->_is_nil() && SMESH::IsApplicable( algoIn->TypeName, aGeomVar, !myIsMesh ))){
2671 anAvailableAlgs.append( algoIn->Label );
2672 myAvailableHypData[dim][Algo].append( algoIn );
2673 myFilteredAlgoData[dim].append( algoIn );
2676 //algorithm will be active, if the chosen algorithm available in the current mesh type
2677 if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ){
2678 isAvailableChoiceAlgo = true;
2679 anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2682 //set new algorithm list and select the current algorithm
2683 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2684 anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2685 if ( isAvailableChoiceAlgo )
2686 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2688 setCurrentHyp( dim, Algo, -1 );
2691 int aMaxShapeDim = ( myMaxShapeDim != aDim) ? aDim : myMaxShapeDim;
2692 if ( isNone || isReqDisBound ) {
2693 for ( int i = SMESH::DIM_0D; i <= aMaxShapeDim; i++ ) {
2695 myDlg->disableTab( i );
2696 setCurrentHyp(i, Algo, -1);
2700 else if ( !isNone ){
2701 if ( aDim == SMESH::DIM_2D){
2702 myDlg->disableTab( SMESH::DIM_3D );
2703 setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2705 for ( int i = aMaxShapeDim; i > SMESH::DIM_0D; i-- )
2707 isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2708 myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2709 if ( isReqDisBound ) {
2710 for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2711 myDlg->disableTab( j );
2712 setCurrentHyp( j , Algo, -1 );
2718 myDlg->enableTab( aDim );
2719 myDlg->setCurrentTab( aDim );
2721 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2722 QStringList aFilteredHypothesesSetsList;
2723 aFilteredHypothesesSetsList.clear();
2724 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2725 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2727 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2728 bool isAvailable = false;
2729 currentHypoSet->init( true );
2730 while ( currentHypoSet->next(), currentHypoSet->more() )
2732 isAvailable = false;
2733 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2735 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
2737 for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2738 HypothesisData* aCurAlgo = hypData( i, Algo, j );
2739 if ( aCurAlgo->Label == algoDataIn->Label ){
2744 if ( isAvailable ) break;
2746 if ( !isAvailable ) break;
2750 aFilteredHypothesesSetsList.append( *inHypoSetName );
2752 myDlg->setHypoSets( aFilteredHypothesesSetsList );