1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_Hypotheses.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_MeshDlg.h"
33 #include "SMESHGUI_Operations.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESH_NumberFilter.hxx"
37 #include "SMESH_TypeFilter.hxx"
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
44 #include <GEOMImpl_Types.hxx>
46 // SALOME GUI includes
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <LightApp_UpdateFlags.h>
52 #include <SUIT_MessageBox.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_Session.h>
55 #include <SALOME_InteractiveObject.hxx>
56 #include <SALOME_ListIO.hxx>
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SComponent.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDS_Study.hxx>
62 #include <SALOMEDS_wrap.hxx>
65 #include <QStringList>
67 #include <QApplication>
71 #include <TopoDS_Shape.hxx>
72 #include <TopoDS_Shell.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <BRep_Tool.hxx>
77 #include <SALOMEconfig.h>
78 #include CORBA_CLIENT_HEADER(SMESH_Gen)
80 //================================================================================
83 * \param theToCreate - if this parameter is true then operation is used for creation,
84 * for editing otherwise
86 * Initialize operation
88 //================================================================================
89 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
90 : SMESHGUI_SelectionOp(),
93 myToCreate( theToCreate ),
94 myIsMesh( theIsMesh ),
97 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
98 GeometryGUI::InitGeomGen();
99 myIsOnGeometry = true;
103 //================================================================================
107 //================================================================================
108 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
114 //================================================================================
116 * \brief Gets dialog of this operation
117 * \retval LightApp_Dialog* - pointer to dialog of this operation
119 //================================================================================
120 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
125 //================================================================================
127 * \brief Creates or edits mesh
128 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
130 * Virtual slot redefined from the base class called when "Apply" button is clicked
131 * creates or edits mesh
133 //================================================================================
134 bool SMESHGUI_MeshOp::onApply()
140 if ( !isValid( aMess ) )
144 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
148 bool aResult = false;
152 QStringList anEntryList;
153 if ( myToCreate && myIsMesh )
154 aResult = createMesh( aMess, anEntryList );
155 if ( myToCreate && !myIsMesh )
156 aResult = createSubMesh( aMess, anEntryList );
157 else if ( !myToCreate )
158 aResult = editMeshOrSubMesh( aMess );
161 SMESHGUI::Modified();
162 update( UF_ObjBrowser | UF_Model );
163 if( LightApp_Application* anApp =
164 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
165 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
168 catch ( const SALOME::SALOME_Exception& S_ex )
170 SalomeApp_Tools::QtCatchCorbaException( S_ex );
186 aMess = tr( "SMESH_OPERATION_FAILED" );
187 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
193 //================================================================================
195 * \brief Creates dialog if necessary and shows it
197 * Virtual method redefined from base class called when operation is started creates
198 * dialog if necessary and shows it, activates selection
200 //================================================================================
201 void SMESHGUI_MeshOp::startOperation()
205 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
206 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
208 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
209 this, SLOT( onCreateHyp( const int, const int ) ) );
210 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
211 this, SLOT( onEditHyp( const int, const int ) ) );
212 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
213 this, SLOT( onAlgoSelected( const int ) ) );
215 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
216 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
219 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
220 else myHelpFileName = "constructing_submeshes_page.html";
223 myHelpFileName = "editing_meshes_page.html";
226 SMESHGUI_SelectionOp::startOperation();
227 // iterate through dimensions and get available algorithms, set them to the dialog
228 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
229 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
231 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
233 // clear available hypotheses
234 aTab->setAvailableHyps( MainHyp, hypList );
235 aTab->setAvailableHyps( AddHyp, hypList );
236 aTab->setExistingHyps( MainHyp, hypList );
237 aTab->setExistingHyps( AddHyp, hypList );
238 myExistingHyps[ i ][ MainHyp ].clear();
239 myExistingHyps[ i ][ AddHyp ].clear();
241 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
242 aTab->setAvailableHyps( Algo, hypList );
247 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
251 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
253 myDlg->setCurrentTab( SMESH::DIM_3D );
255 QStringList TypeMeshList;
256 createMeshTypeList( TypeMeshList );
257 setAvailableMeshType( TypeMeshList );
260 myDlg->setGeomPopupEnabled(false);
263 myIgnoreAlgoSelection = false;
264 myHasConcurrentSubBefore = false;
266 myObjectToSelect.clear();
269 //=================================================================================
271 * \brief Selects a recently created mesh or sub-mesh if necessary
273 * Virtual method redefined from base class called when operation is commited
274 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
275 * selection when the custom selection filters are removed.
277 //=================================================================================
278 void SMESHGUI_MeshOp::commitOperation()
280 SMESHGUI_SelectionOp::commitOperation();
282 if ( !myObjectToSelect.isEmpty() ) {
283 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
284 SUIT_DataOwnerPtrList aList;
285 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
286 aSelectionMgr->setSelected( aList );
291 //================================================================================
293 * \brief Creates selection filter
294 * \param theId - identifier of current selection widget
295 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
297 * Creates selection filter in accordance with identifier of current selection widget
299 //================================================================================
300 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
302 if ( theId == SMESHGUI_MeshDlg::Geom )
304 // TColStd_MapOfInteger allTypesMap;
305 // for ( int i = 0; i < 10; i++ )
306 // allTypesMap.Add( i );
307 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
308 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
310 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
311 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
312 else if ( theId == SMESHGUI_MeshDlg::Mesh )
313 return new SMESH_TypeFilter( SMESH::MESH );
318 //================================================================================
320 * \brief check if selected shape is a sub-shape of the shape to mesh
321 * \retval bool - check result
323 //================================================================================
324 bool SMESHGUI_MeshOp::isSubshapeOk() const
326 if ( !myToCreate || myIsMesh ) // not submesh creation
330 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
331 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
332 if (!pMesh) return false;
334 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
335 if (mesh->_is_nil()) return false;
337 // main shape of the mesh
338 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
339 if (mainGeom->_is_nil()) return false;
343 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
345 if (aGEOMs.count() > 0) {
346 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
347 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
348 if (geomGen->_is_nil() || !aStudy) return false;
350 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
351 if (op->_is_nil()) return false;
353 // check all selected shapes
354 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
355 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
356 QString aSubGeomEntry = (*aSubShapesIter);
357 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
358 if (!pSubGeom) return false;
360 GEOM::GEOM_Object_var aSubGeomVar =
361 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
362 if (aSubGeomVar->_is_nil()) return false;
364 // skl for NPAL14695 - implementation of searching of mainObj
365 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
366 mainObj already exists! */
367 while( !mainObj->_is_nil()) {
368 CORBA::String_var entry1 = mainObj->GetEntry();
369 CORBA::String_var entry2 = mainGeom->GetEntry();
370 if (std::string( entry1.in() ) == entry2.in() )
372 mainObj = op->GetMainShape(mainObj);
374 if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
376 // is aSubGeomVar a compound of sub-shapes?
377 GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations(aStudy->StudyId());
378 if (sop->_is_nil()) return false;
379 GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
380 GEOM::SHAPE,/*sorted=*/false);
381 if ( ids->length() > 0 )
384 GEOM::GEOM_Object_var compSub = geomGen->AddSubShape( aSubGeomVar, ids );
385 if ( !compSub->_is_nil() )
387 GEOM::ListOfGO_var shared = sop->GetSharedShapes( mainGeom,
389 compSub->GetShapeType() );
390 geomGen->RemoveObject( compSub );
391 compSub->UnRegister();
392 if ( shared->length() > 0 ) {
393 geomGen->RemoveObject( shared[0] );
394 shared[0]->UnRegister();
396 return ( shared->length() > 0 );
406 //================================================================================
408 * \brief Return name of the algorithm that does not support sub-meshes and makes
409 * sub-mesh creation useless
410 * \retval char* - string is to be deleted!!!
412 //================================================================================
413 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
415 if ( myToCreate && !myIsMesh ) {
417 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
418 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
419 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
422 QStringList algoNames;
424 existingHyps(3, Algo, pMesh, algoNames, algoList);
425 if (!algoList.empty()) {
426 HypothesisData* algo =
427 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
429 algo->InputTypes.empty() && // builds all dimensions it-self
430 !algo->IsSupportSubmeshes )
431 return CORBA::string_dup( algoNames[0].toLatin1().data() );
434 // GEOM::GEOM_Object_var geom;
435 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
436 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
438 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
439 existingHyps(2, Algo, pMesh, algoNames, algoList);
440 if (!algoList.empty()) {
441 HypothesisData* algo =
442 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
444 algo->InputTypes.empty() && // builds all dimensions it-self
445 !algo->IsSupportSubmeshes )
446 return CORBA::string_dup( algoNames[0].toLatin1().data() );
454 //================================================================================
456 * \brief find an existing submesh by the selected shape
457 * \retval _PTR(SObject) - the found submesh SObject
459 //================================================================================
460 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
462 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
463 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
464 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
465 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
466 if ( pMesh && pGeom ) {
467 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
468 if ( !geom->_is_nil() ) {
470 switch ( geom->GetShapeType() ) {
471 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
472 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
473 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
474 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
475 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
476 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
477 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
480 _PTR(GenericAttribute) anAttr;
481 _PTR(SObject) aSubmeshRoot;
482 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
483 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
485 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
486 for ( ; smIter->More(); smIter->Next() )
488 _PTR(SObject) aSmObj = smIter->Value();
489 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
491 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
492 for ( ; anIter1->More(); anIter1->Next()) {
493 _PTR(SObject) pGeom2 = anIter1->Value();
494 if ( pGeom2->ReferencedObject( pGeom2 ) &&
495 pGeom2->GetID() == pGeom->GetID() )
502 return _PTR(SObject)();
505 //================================================================================
507 * \brief Updates dialog's look and feel
509 * Virtual method redefined from the base class updates dialog's look and feel
511 //================================================================================
512 void SMESHGUI_MeshOp::selectionDone()
514 if (!dlg()->isVisible() || !myDlg->isEnabled())
517 SMESHGUI_SelectionOp::selectionDone();
521 myIsOnGeometry = true;
523 //Check geometry for mesh
524 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
525 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
528 SMESH::SMESH_Mesh_var aMeshVar =
529 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
530 if (!aMeshVar->_is_nil()) {
531 if (!myToCreate && !aMeshVar->HasShapeToMesh())
532 myIsOnGeometry = false;
538 // Enable tabs according to shape dimension
543 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
544 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
546 if (aGEOMs.count() > 0) {
547 // one or more GEOM shape selected
548 aSeq->length(aGEOMs.count());
549 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
551 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
552 QString aSubGeomEntry = (*aSubShapesIter);
553 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
556 SALOMEDS_SObject* sobj = _CAST(SObject,pSubGeom);
558 GEOM::GEOM_Object_var aSubGeomVar =
559 GEOM::GEOM_Object::_narrow(sobj->GetObject());
560 if( !aSubGeomVar->_is_nil() ){
561 aSeq[iSubSh] = aSubGeomVar;
567 // get geometry by selected sub-mesh
568 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
569 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
570 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
571 if (!aGeomVar->_is_nil()) {
577 if (aSeq->length() > 0) {
579 for ( CORBA::ULong iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
580 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
581 switch ( aGeomVar->GetShapeType() ) {
582 case GEOM::SOLID: shapeDim = 3; break;
584 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
586 // TopoDS_Shape aShape;
587 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
588 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
591 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
593 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
594 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
598 if (GEOMBase::GetShape(aGeomVar, aShape))
600 TopExp_Explorer exp (aShape, TopAbs_SOLID);
604 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
605 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
608 // for (; exp.More() && shapeDim == 2; exp.Next()) {
609 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
613 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
614 shapeDim = qMax(2, shapeDim);
615 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
616 shapeDim = qMax(1, shapeDim);
617 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
618 shapeDim = qMax(0, shapeDim);
626 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
627 // reset algos before disabling tabs (0020138)
628 onAlgoSelected(-1, i);
630 myDlg->setMaxHypoDim( shapeDim );
631 myMaxShapeDim = shapeDim;
632 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
634 if (!myToCreate) // edition: read hypotheses
638 SMESH::SMESH_subMesh_var submeshVar =
639 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
640 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
641 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
642 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
643 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
644 myDlg->updateGeometry();
646 myIsMesh = submeshVar->_is_nil();
652 else if ( !myIsMesh ) // submesh creation
654 // if a submesh on the selected shape already exist, pass to submesh edition mode
655 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
656 SMESH::SMESH_subMesh_var sm =
657 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
658 bool editSubmesh = ( !sm->_is_nil() &&
659 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
660 tr( "EDIT_SUBMESH_QUESTION"),
661 SUIT_MessageBox::Yes |
663 SUIT_MessageBox::No )
664 == SUIT_MessageBox::Yes );
667 selectionMgr()->clearFilters();
668 selectObject( pSubmesh );
669 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
674 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
675 selectObject( _PTR(SObject)() );
680 // discard selected mesh if submesh creation not allowed because of
681 // a global algorithm that does not support submeshes
682 if ( char* algoName = isSubmeshIgnored() ) {
683 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
684 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
685 CORBA::string_free( algoName );
686 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
687 selectObject( _PTR(SObject)() );
692 // enable/disable popup for choice of geom selection way
694 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
695 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
696 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
697 if ( !mesh->_is_nil() ) {
698 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
699 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
700 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
701 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
702 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
703 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
706 myDlg->setGeomPopupEnabled( enable );
709 else { // no geometry defined
710 myDlg->enableTab( SMESH::DIM_3D );
712 availableHyps( SMESH::DIM_3D, Algo, hypList,
713 myAvailableHypData[SMESH::DIM_3D][Algo]);
715 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
716 aTab->setAvailableHyps( Algo, hypList );
717 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
718 myDlg->disableTab(i);
721 //Hide labels and fields (Mesh and Geometry)
722 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
723 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
727 int curIndex = myDlg->currentMeshType( );
728 QStringList TypeMeshList;
729 createMeshTypeList( TypeMeshList );
730 setAvailableMeshType( TypeMeshList );
731 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
732 myDlg->setCurrentMeshType( curIndex );
733 setFilteredAlgoData( myMaxShapeDim, curIndex);
735 catch ( const SALOME::SALOME_Exception& S_ex )
737 SalomeApp_Tools::QtCatchCorbaException( S_ex );
744 //================================================================================
746 * \brief Verifies validity of input data
747 * \param theMess - Output parameter intended for returning error message
748 * \retval bool - TRUE if input data is valid, false otherwise
750 * Verifies validity of input data. This method is called when "Apply" or "OK" button
751 * is pressed before mesh creation or editing.
753 //================================================================================
754 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
756 // Selected object to be edited
757 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
759 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
764 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
765 if ( aMeshName.isEmpty() )
767 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
771 /* // Imported mesh, if create sub-mesh or edit mesh
772 if ( !myToCreate || ( myToCreate && !myIsMesh ))
774 QString aMeshEntry = myDlg->selectedObject
775 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
776 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
777 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
778 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
779 theMess = tr( "IMPORTED_MESH" );
788 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
789 if ( aGeomEntry.isEmpty() )
791 theMess = tr( myIsMesh ?
792 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
793 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
797 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
798 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
805 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
806 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
808 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
813 if ( !myIsMesh ) // i.e sub-mesh creation,
815 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
816 if ( aMeshEntry == "" )
818 theMess = tr( "MESH_IS_NOT_DEFINED" );
821 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
822 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
824 theMess = tr( "MESH_IS_NULL" );
827 if ( !isSubshapeOk() )
829 theMess = tr( "INVALID_SUBSHAPE" );
838 //================================================================================
840 * \brief check compatibility of the algorithm and another algorithm or hypothesis
841 * \param theAlgoData - algorithm data
842 * \param theHypData - hypothesis data
843 * \param theHypType - hypothesis type
844 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
845 * \retval bool - check result
847 //================================================================================
848 static bool isCompatible(const HypothesisData* theAlgoData,
849 const HypothesisData* theHypData,
850 const int theHypType)
855 if ( theHypType == SMESHGUI_MeshOp::Algo )
856 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
859 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
862 //================================================================================
864 * \brief check compatibility of the geometry
865 * \param theAlgoData - to select hypos able to be used by this algo
866 * \param theCurrentGeomToSelect - the current name of the selected geometry
867 * \param theGeomVar - currently selected geometry
868 * \retval bool - check result
870 //================================================================================
871 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
872 QString theCurrentGeomToSelect,
873 GEOM::GEOM_Object_var theGeomVar)
875 if ( theGeomVar->_is_nil() )
878 bool isApplicable = false;
879 if ( theCurrentGeomToSelect == myLastGeomToSelect && !theCurrentGeomToSelect.isEmpty() ) {
880 THypLabelIsAppMap::const_iterator iter = myHypMapIsApplicable.find( theAlgoData->Label );
881 if ( iter != myHypMapIsApplicable.end() && iter.key() == theAlgoData->Label ) {
882 isApplicable = iter.value();
886 bool toCheckIsApplicableToAll = !myIsMesh;
887 if ( toCheckIsApplicableToAll )
888 toCheckIsApplicableToAll = ( theGeomVar->GetType() == GEOM_GROUP );
889 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, theGeomVar, toCheckIsApplicableToAll );
890 myHypMapIsApplicable.insert( theAlgoData->Label, isApplicable );
894 //================================================================================
896 * \brief check compatibility of the mesh type
897 * \param theAlgoData - to select hypos able to be used by this algo
898 * \param theMeshType - type of mesh for filtering algorithms
899 * \retval bool - check result
901 //================================================================================
902 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
905 bool isAvailableAlgo = ( theAlgoData->OutputTypes.count() == 0 );
906 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
907 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ ) {
908 if ( *inElemType == theMeshType ) {
909 isAvailableAlgo = true;
913 return isAvailableAlgo;
916 //================================================================================
918 * \brief Gets available hypotheses or algorithms
919 * \param theDim - specifies dimension of returned hypotheses/algorifms
920 * \param theHypType - specifies whether algorims or hypotheses or additional ones
921 * are retrieved (possible values are in HypType enumeration)
922 * \param theHyps - Output list of hypotheses' names
923 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
924 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
925 * \param theMeshType - type of mesh for filtering algorithms (optional)
927 * Gets available hypotheses or algorithm in accordance with input parameters
929 //================================================================================
930 void SMESHGUI_MeshOp::availableHyps( const int theDim,
931 const int theHypType,
932 QStringList& theHyps,
933 THypDataList& theDataList,
934 HypothesisData* thePrevAlgoData,
935 HypothesisData* theNextAlgoData,
936 const QString& theMeshType)
940 bool isAlgo = ( theHypType == Algo );
941 bool isAux = ( theHypType >= AddHyp );
942 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
944 QStringList::const_iterator anIter;
945 GEOM::GEOM_Object_var aGeomVar;
946 QString aCurrentGeomToSelect;
947 if ( !theMeshType.isEmpty() ) {
948 aCurrentGeomToSelect = myDlg->selectedObject( myToCreate ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Obj );
949 if ( _PTR(SObject) so = studyDS()->FindObjectID( aCurrentGeomToSelect.toLatin1().data() )) {
950 aGeomVar = SMESH::GetGeom( so );
952 if ( aCurrentGeomToSelect != myLastGeomToSelect )
953 myHypMapIsApplicable.clear();
956 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
958 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
959 if ( ( isCompatible ( thePrevAlgoData, aData, theHypType ) &&
960 isCompatible ( theNextAlgoData, aData, theHypType ) ) ||
961 ( theMeshType == "ANY" && aData->InputTypes.isEmpty())) {
962 if ( !theMeshType.isEmpty() && theDim >= SMESH::DIM_2D &&
963 ( ( theMeshType != "ANY" && !isCompatibleToMeshType( aData, theMeshType )) ||
964 !isCompatibleToGeometry( aData, aCurrentGeomToSelect, aGeomVar )))
966 theDataList.append( aData );
967 theHyps.append( aData->Label );
971 if ( !theMeshType.isEmpty() && !aCurrentGeomToSelect.isEmpty() &&
972 myLastGeomToSelect != aCurrentGeomToSelect )
973 myLastGeomToSelect = aCurrentGeomToSelect;
976 //================================================================================
978 * \brief Gets existing hypotheses or algorithms
979 * \param theDim - specifies dimension of returned hypotheses/algorifms
980 * \param theHypType - specifies whether algorims or hypotheses or additional ones
981 * are retrieved (possible values are in HypType enumeration)
982 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
983 * \param theHyps - output list of names.
984 * \param theHypVars - output list of variables.
985 * \param theAlgoData - to select hypos able to be used by this algo (optional)
987 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
990 * WARNING: when using this method to get hyps existing in Mesh component,
991 * call availableHyps() before in order to get only hyps of available types
992 * that was filtered by availableHyps()
994 //================================================================================
995 void SMESHGUI_MeshOp::existingHyps( const int theDim,
996 const int theHypType,
997 _PTR(SObject) theFather,
998 QStringList& theHyps,
999 THypList& theHypList,
1000 HypothesisData* theAlgoData) const
1002 // Clear hypoheses list
1009 _PTR(SObject) aHypRoot;
1010 _PTR(GenericAttribute) anAttr;
1011 _PTR(AttributeName) aName;
1012 _PTR(AttributeIOR) anIOR;
1014 const bool isMesh = !_CAST( SComponent, theFather );
1017 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
1019 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
1021 const bool isAux = ( theHypType >= AddHyp );
1022 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
1024 if ( theFather->FindSubObject( aPart, aHypRoot ) )
1026 _PTR(ChildIterator) anIter =
1027 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1028 for ( ; anIter->More(); anIter->Next() )
1030 _PTR(SObject) anObj = anIter->Value();
1031 if ( isMesh ) // i.e. mesh or submesh
1033 _PTR(SObject) aRefObj;
1034 if ( anObj->ReferencedObject( aRefObj ) )
1039 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1042 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1043 if ( !CORBA::is_nil( aVar ) )
1045 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
1046 if ( !aHypVar->_is_nil() )
1048 CORBA::String_var hypType = aHypVar->GetName();
1049 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
1050 if ( !aData) continue;
1051 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
1052 ( isCompatible ( theAlgoData, aData, theHypType )) &&
1053 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
1054 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
1056 std::string aHypName = aName->Value();
1057 theHyps.append( aHypName.c_str() );
1058 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
1067 //================================================================================
1069 * \brief If create or edit a submesh, return a hypothesis holding parameters used
1070 * to mesh a sub-shape
1071 * \param aHypType - The hypothesis type name
1072 * \param aServerLib - Server library name
1073 * \param hypData - The structure holding the hypothesis type etc.
1074 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
1076 //================================================================================
1077 SMESH::SMESH_Hypothesis_var
1078 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1079 const QString& aServerLib ) const
1081 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1082 return SMESH::SMESH_Hypothesis::_nil();
1084 const int nbColonsInMeshEntry = 3;
1085 bool isSubMesh = myToCreate ?
1087 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1089 // get mesh and geom object
1090 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
1091 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1096 anEntry = myDlg->selectedObject
1097 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1098 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1100 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1101 if ( myToCreate ) // mesh and geom may be selected
1103 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
1104 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1105 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1106 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1108 else // edition: sub-mesh may be selected
1110 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1111 if ( !sm->_is_nil() ) {
1112 aMeshVar = sm->GetFather();
1113 aGeomVar = sm->GetSubShape();
1120 if ( !myToCreate ) // mesh to edit can be selected
1122 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1123 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1125 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1126 if ( !aMeshVar->_is_nil() )
1127 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1130 if ( aGeomVar->_is_nil() ) {
1131 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1132 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1134 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1139 SMESH::SMESH_Hypothesis_var hyp =
1140 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1141 aServerLib.toLatin1().data(),
1144 /*byMesh = */isSubMesh);
1145 if ( hyp->_is_nil() && isSubMesh )
1146 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1147 aServerLib.toLatin1().data(),
1150 /*byMesh = */false);
1154 //================================================================================
1156 * \brief initialize a hypothesis creator
1158 //================================================================================
1160 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1162 if ( !theCreator ) return;
1164 // Set shapes, of mesh and sub-mesh if any
1166 // get Entry of the Geom object
1167 QString aGeomEntry = "";
1168 QString aMeshEntry = "";
1169 QString anObjEntry = "";
1170 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1171 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1172 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1174 if ( myToCreate && myIsMesh )
1175 aMeshEntry = aGeomEntry;
1177 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1178 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1179 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1180 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1183 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1184 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1186 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1187 if ( !aGeomVar->_is_nil() )
1189 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1191 aMeshEntry = aGeomEntry;
1195 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1196 // take geometry from submesh being created
1197 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1199 // if current object is sub-mesh
1200 SMESH::SMESH_subMesh_var aSubMeshVar =
1201 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1202 if ( !aSubMeshVar->_is_nil() ) {
1203 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1204 if ( !aMeshVar->_is_nil() ) {
1205 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1206 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1207 if ( !aGeomVar->_is_nil() )
1208 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1214 theCreator->setShapeEntry( aGeomEntry );
1215 if ( aMeshEntry != "" )
1216 theCreator->setMainShapeEntry( aMeshEntry );
1219 //================================================================================
1221 * \Brief Returns tab dimention
1222 * \param tab - the tab in the dlg
1223 * \param dlg - my dialogue
1224 * \retval int - dimention
1226 //================================================================================
1227 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1230 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1231 if (tab == dlg->tab(i))
1236 //================================================================================
1238 * \brief Create hypothesis
1239 * \param theHypType - hypothesis category (main or additional)
1240 * \param theIndex - index of type of hypothesis to be cerated
1242 * Specifies dimension of hypothesis to be created (using sender() method),
1243 * specifies its type and calls method for hypothesis creation
1245 //================================================================================
1246 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1248 // Specifies dimension of hypothesis to be created
1249 int aDim = getTabDim( sender(), myDlg );
1253 // Specifies type of hypothesis to be created
1254 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1255 if (theIndex < 0 || theIndex >= dataList.count())
1257 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1259 // Create hypothesis
1260 createHypothesis(aDim, theHypType, aHypTypeName);
1265 QString GetUniqueName (const QStringList& theHypNames,
1266 const QString& theName,
1267 size_t theIteration = 1)
1269 QString aName = theName + "_" + QString::number( theIteration );
1270 if ( theHypNames.contains( aName ) )
1271 return GetUniqueName( theHypNames, theName, ++theIteration );
1276 //================================================================================
1278 * Create hypothesis and update dialog.
1279 * \param theDim - dimension of hypothesis to be created
1280 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1281 * \param theTypeName - specifies hypothesis to be created
1283 //================================================================================
1284 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1286 const QString& theTypeName)
1288 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1295 // get a unique hyp name
1296 QStringList aHypNames;
1297 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1298 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1299 const TType2HypList& aType2HypList = aDimIter.value();
1300 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1301 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1302 const THypList& aHypList = aTypeIter.value();
1303 THypList::const_iterator anIter = aHypList.begin();
1304 for ( ; anIter != aHypList.end(); anIter++) {
1305 const THypItem& aHypItem = *anIter;
1306 const QString& aHypName = aHypItem.second;
1307 aHypNames.append(aHypName);
1311 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1314 bool dialog = false;
1316 QString aClientLibName = aData->ClientLibName;
1317 if (aClientLibName == "") {
1318 // Call hypothesis creation server method (without GUI)
1319 SMESH::SMESH_Hypothesis_var aHyp =
1320 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1324 // Get hypotheses creator client (GUI)
1325 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1327 // Create hypothesis
1330 // Get parameters appropriate to initialize a new hypothesis
1331 SMESH::SMESH_Hypothesis_var initParamHyp =
1332 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1334 removeCustomFilters(); // Issue 0020170
1336 // set shapes, of mesh and sub-mesh if any
1337 initHypCreator( aCreator );
1339 myDlg->setEnabled( false );
1340 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1344 SMESH::SMESH_Hypothesis_var aHyp =
1345 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1354 //================================================================================
1356 * Necessary steps after hypothesis creation
1357 * \param result - creation result:
1360 * 2 = additional value meaning that slot is called not from dialog box
1362 //================================================================================
1363 void SMESHGUI_MeshOp::onHypoCreated( int result )
1367 int obj = myDlg->getActiveObject();
1368 onActivateObject( obj ); // Issue 0020170. Restore filters
1369 myDlg->setEnabled( true );
1372 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1374 int nbHyp = myExistingHyps[myDim][myType].count();
1375 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1376 QStringList aNewHyps;
1377 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1378 if (aNewHyps.count() > nbHyp)
1380 for (int i = nbHyp; i < aNewHyps.count(); i++)
1381 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1384 if( result!=2 && myHypoSet )
1388 //================================================================================
1390 * \brief Calls plugin methods for hypothesis editing
1391 * \param theHypType - specifies whether main hypothesis or additional one
1393 * \param theIndex - index of existing hypothesis
1395 * Calls plugin methods for hypothesis editing
1397 //================================================================================
1398 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1400 // Speicfies dimension of hypothesis to be created
1401 int aDim = getTabDim( sender(), myDlg );
1405 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1406 if ( theIndex < 0 || theIndex >= aList.count() )
1408 const THypItem& aHypItem = aList[ theIndex ];
1409 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1410 if ( aHyp->_is_nil() )
1413 SMESHGUI_GenericHypothesisCreator* aCreator =
1414 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1417 // set initial parameters
1418 SMESH::SMESH_Hypothesis_var initParamHyp =
1419 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1420 SMESH::toQStr( aHyp->GetLibName() ));
1421 aCreator->setInitParamsHypothesis( initParamHyp );
1423 // set shapes, of mesh and sub-mesh if any
1424 initHypCreator( aCreator );
1426 removeCustomFilters(); // Issue 0020170
1427 myDlg->setEnabled( false );
1429 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1433 //================================================================================
1435 * Necessary steps after hypothesis edition
1436 * \param result - creation result:
1440 //================================================================================
1441 void SMESHGUI_MeshOp::onHypoEdited( int result )
1443 int obj = myDlg->getActiveObject();
1444 onActivateObject( obj ); // Issue 0020170. Restore filters
1445 myDlg->setEnabled( true );
1448 //================================================================================
1450 * \brief access to hypothesis data
1451 * \param theDim - hyp dimension
1452 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1453 * \param theIndex - index in the list
1454 * \retval HypothesisData* - result data, may be 0
1456 //================================================================================
1457 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1458 const int theHypType,
1461 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1462 theHypType > -1 && theHypType < NbHypTypes &&
1463 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1464 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1468 //================================================================================
1470 * \brief Set available algos and hypos according to the selected algorithm
1471 * \param theIndex - algorithm index
1473 //================================================================================
1474 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1477 if ( myIgnoreAlgoSelection )
1480 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1484 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1486 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1487 HypothesisData* algoByDim[4];
1488 algoByDim[ aDim ] = algoData;
1490 QStringList anAvailable;
1492 // enable / disable tabs
1493 if ( myIsOnGeometry ) {
1494 for (int i = SMESH::DIM_3D; i >= SMESH::DIM_0D; i--) {
1496 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
1497 else myDlg->enableTab( i );
1499 else if ( i == aDim ) {
1502 else {//( i < aDim )
1503 if ( algoData && algoData->InputTypes.isEmpty() ) {
1504 myDlg->disableTab( i );
1505 for ( int type = Algo, nbTypes = nbDlgHypTypes(i); type < nbTypes; type++ )
1506 setCurrentHyp(i, type, -1);
1509 myDlg->enableTab( i );
1516 HypothesisData* a3DAlgo = 0;
1517 // 2 loops: backward and forward from algo dimension
1518 for ( int forward = 0; forward <= 1; ++forward )
1520 int dim = algoDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1522 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1524 HypothesisData* prevAlgo = algoData;
1525 bool noCompatible = false;
1526 for ( ; dim * dir <= lastDim * dir; dim += dir)
1528 if ( !isAccessibleDim( dim ))
1530 if ( noCompatible ) { // the selected algo has no compatible ones
1531 anAvailable.clear();
1532 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1533 myAvailableHypData[dim][Algo].clear();
1534 algoByDim[ dim ] = 0;
1537 HypothesisData* nextAlgo = 0;
1538 if ( myMaxShapeDim == SMESH::DIM_3D && a3DAlgo && dim == SMESH::DIM_2D ) {
1541 // get currently selected algo
1542 int algoIndex = currentHyp( dim, Algo );
1543 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1545 QString anCompareType = currentMeshTypeName(myDlg->currentMeshType());
1546 QString anCurrentCompareType = "";
1547 if ( dim == SMESH::DIM_3D || anCompareType == "ANY" )
1548 anCurrentCompareType = anCompareType;
1549 else if ( dim == SMESH::DIM_2D ) {
1550 anCurrentCompareType = (anCompareType == "HEXA" || anCompareType == "QUAD") ? "QUAD" : "TRIA";
1554 // set new available algorithms
1555 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType);
1556 HypothesisData* soleCompatible = 0;
1557 if ( anAvailable.count() == 1 )
1558 soleCompatible = myAvailableHypData[dim][Algo][0];
1559 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1560 noCompatible = anAvailable.isEmpty();
1561 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1562 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D) {
1563 // select the sole compatible algo
1566 setCurrentHyp( dim, Algo, algoIndex );
1568 // remember current algo
1569 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1573 if ( myMaxShapeDim == SMESH::DIM_3D && forward && algoDim == SMESH::DIM_1D )
1575 algoDim = SMESH::DIM_3D;
1580 } // loops backward and forward
1583 // set hypotheses corresponding to the found algorithms
1585 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1587 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1589 if ( !isAccessibleDim( dim ))
1592 // get indices of selected hyps
1593 const int nbTypes = nbDlgHypTypes(dim);
1594 std::vector<int> hypIndexByType( nbTypes, -1 );
1595 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1597 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1601 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1603 const int type = Min( dlgType, AddHyp );
1604 myAvailableHypData[ dim ][ type ].clear();
1605 QStringList anAvailable, anExisting;
1607 HypothesisData* curAlgo = algoByDim[ dim ];
1608 int hypIndex = hypIndexByType[ dlgType ];
1610 SMESH::SMESH_Hypothesis_var curHyp;
1611 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1612 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1614 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1615 // try to find algo by selected hypothesis in order to keep it selected
1616 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1617 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1618 if ( !algoDeselectedByUser &&
1619 myObjHyps[ dim ][ type ].count() > 0 &&
1620 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1622 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1623 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1624 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1625 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1632 // get hyps compatible with curAlgo
1633 bool defaulHypAvlbl = false;
1636 // check if a selected hyp is compatible with the curAlgo
1637 if ( !curHyp->_is_nil() ) {
1638 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1639 if ( !isCompatible( curAlgo, hypData, type ))
1640 curHyp = SMESH::SMESH_Hypothesis::_nil();
1642 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1643 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1644 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1646 // set list of hypotheses
1647 if ( dlgType <= AddHyp )
1649 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1650 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1652 // set current existing hypothesis
1653 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1654 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1657 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 ) {
1658 // none is yet selected => select the sole existing if it is not optional
1659 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1660 bool isOptional = true;
1661 if ( algoByDim[ dim ] &&
1662 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1666 setCurrentHyp( dim, dlgType, hypIndex );
1671 //================================================================================
1673 * \brief Creates and selects hypothesis of hypotheses set
1674 * \param theSetName - The name of hypotheses set
1676 //================================================================================
1677 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1679 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1684 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1685 setCurrentHyp(dim, Algo, -1);
1686 setCurrentHyp(dim, AddHyp, -1);
1687 setCurrentHyp(dim, MainHyp, -1);
1690 myHypoSet->init(true); //algorithms
1692 myHypoSet->init(false); //hypotheses
1697 //================================================================================
1699 * \brief One step of hypothesis/algorithm list creation
1701 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1703 //================================================================================
1704 void SMESHGUI_MeshOp::processSet()
1707 if( !myHypoSet->more() )
1710 bool isAlgo = myHypoSet->isAlgo();
1711 QString aHypoTypeName = myHypoSet->current();
1712 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1719 int aDim = aHypData->Dim[0];
1720 // create or/and set
1723 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1726 QStringList anAvailable;
1727 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1728 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1729 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1731 setCurrentHyp( aDim, Algo, index );
1732 onAlgoSelected( index, aDim );
1737 bool mainHyp = true;
1738 QStringList anAvailable;
1739 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1740 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1741 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1745 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1748 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1754 //================================================================================
1756 * \brief Creates mesh
1757 * \param theMess - Output parameter intended for returning error message
1758 * \param theEntryList - List of entries of published objects
1759 * \retval bool - TRUE if mesh is created, FALSE otherwise
1763 //================================================================================
1764 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1769 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1770 if ( aList.isEmpty() )
1772 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1773 if ( aSMESHGen->_is_nil() )
1776 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1777 if ( aMeshVar->_is_nil() )
1780 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1782 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1783 theEntryList.append( aMeshSO->GetID().c_str() );
1788 if ( aList.count() > 1 )
1790 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1791 int i = namePrefix.length() - 1;
1792 while ( i > 0 && namePrefix[i].isDigit() )
1794 if ( i < namePrefix.length() - 1 )
1795 namePrefix.chop( namePrefix.length() - 1 - i );
1799 QStringList::Iterator it = aList.begin();
1800 for ( int i = 0; it!=aList.end(); it++, ++i )
1802 QString aGeomEntry = *it;
1803 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1804 GEOM::GEOM_Object_var aGeomVar =
1805 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1807 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1808 if ( aSMESHGen->_is_nil() )
1811 SUIT_OverrideCursor aWaitCursor;
1814 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1815 if ( aMeshVar->_is_nil() )
1817 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1819 theEntryList.append( aMeshSO->GetID().c_str() );
1820 if ( i > 0 ) setDefaultName( namePrefix );
1821 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1824 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1826 if ( !isAccessibleDim( aDim )) continue;
1828 // assign hypotheses
1829 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1831 const int aHypIndex = currentHyp( aDim, dlgType );
1832 const int aHypType = Min( dlgType, AddHyp );
1833 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1835 SMESH::SMESH_Hypothesis_var aHypVar =
1836 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1837 if ( !aHypVar->_is_nil() )
1838 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1841 // find or create algorithm
1842 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1843 if ( !anAlgoVar->_is_nil() )
1844 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1850 //================================================================================
1852 * \brief Creates sub-mesh
1853 * \param theMess - Output parameter intended for returning error message
1854 * \param theEntryList - List of entries of published objects
1855 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1859 //================================================================================
1860 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1864 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1865 if ( aSMESHGen->_is_nil() )
1869 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1870 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1871 SMESH::SMESH_Mesh_var aMeshVar =
1872 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1873 if (aMeshVar->_is_nil())
1876 // GEOM shape of the main mesh
1877 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1879 // Name for the new sub-mesh
1880 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1883 GEOM::GEOM_Object_var aGeomVar;
1885 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1886 if (aGEOMs.count() == 1)
1888 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1889 QString aGeomEntry = aGEOMs.first();
1890 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1891 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1893 else if (aGEOMs.count() > 1)
1895 // create a GEOM group
1896 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1897 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1898 if (!geomGen->_is_nil() && aStudy) {
1899 GEOM::GEOM_IGroupOperations_wrap op =
1900 geomGen->GetIGroupOperations(aStudy->StudyId());
1901 if (!op->_is_nil()) {
1902 // check and add all selected GEOM objects: they must be
1903 // a sub-shapes of the main GEOM and must be of one type
1905 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1906 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1907 aSeq->length(aGEOMs.count());
1908 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1909 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1910 QString aSubGeomEntry = (*aSubShapesIter);
1911 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1912 GEOM::GEOM_Object_var aSubGeomVar =
1913 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1914 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1916 aGroupType = aSubShapeType;
1918 if (aSubShapeType != aGroupType)
1919 aGroupType = TopAbs_SHAPE;
1921 aSeq[iSubSh] = aSubGeomVar;
1924 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1925 op->UnionList(aGroupVar, aSeq);
1929 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1931 // publish the GEOM group in study
1932 QString aNewGeomGroupName ("Auto_group_for_");
1933 aNewGeomGroupName += aName;
1934 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1935 SALOMEDS::SObject_wrap aNewGroupSO =
1936 geomGen->AddInStudy( aStudyVar, aGeomVar,
1937 aNewGeomGroupName.toLatin1().data(), mainGeom);
1944 if (aGeomVar->_is_nil())
1947 SUIT_OverrideCursor aWaitCursor;
1950 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1951 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1953 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1954 theEntryList.append( aSubMeshSO->GetID().c_str() );
1957 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1959 if ( !isAccessibleDim( aDim )) continue;
1961 // find or create algorithm
1962 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1963 if ( !anAlgoVar->_is_nil() )
1964 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1965 // assign hypotheses
1966 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1968 const int aHypIndex = currentHyp( aDim, dlgType );
1969 const int aHypType = Min( dlgType, AddHyp );
1970 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1972 SMESH::SMESH_Hypothesis_var aHypVar =
1973 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1974 if ( !aHypVar->_is_nil() )
1975 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1980 // deselect geometry: next submesh should be created on other sub-shape
1981 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1982 selectObject( _PTR(SObject)() );
1985 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1990 //================================================================================
1992 * \brief Gets current hypothesis or algorithms
1993 * \param theDim - dimension of hypothesis or algorithm
1994 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1995 * \retval int - current hypothesis or algorithms
1997 * Gets current hypothesis or algorithms
1999 //================================================================================
2000 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2002 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2005 //================================================================================
2007 * \brief Checks if a hypothesis is selected
2009 //================================================================================
2011 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2016 if ( theHypType < AddHyp ) // only one hyp can be selected
2017 return currentHyp( theDim, theHypType ) == theIndex;
2019 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2020 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2026 //================================================================================
2028 * \brief Returns nb of HypType's taking into account possible several
2029 * selected additional hypotheses which are coded as additional HypType's.
2031 //================================================================================
2033 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2035 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2038 //================================================================================
2040 * \brief Returns true if hypotheses of given dim can be assigned
2041 * \param theDim - hypotheses dimension
2042 * \retval bool - result
2044 //================================================================================
2045 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2047 return myDlg->isTabEnabled( theDim );
2050 //================================================================================
2052 * \brief Sets current hypothesis or algorithms
2053 * \param theDim - dimension of hypothesis or algorithm
2054 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2055 * \param theIndex - Index of hypothesis
2056 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2058 * Gets current hypothesis or algorithms
2060 //================================================================================
2061 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2062 const int theHypType,
2064 const bool updateHypsOnAlgoDeselection)
2066 myIgnoreAlgoSelection = true;
2067 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2068 myIgnoreAlgoSelection = false;
2070 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2072 const QStringList noHyps;
2073 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2074 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2075 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2076 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2080 //================================================================================
2082 * \brief Generates default and sets mesh/submesh name
2084 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2086 //================================================================================
2087 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2091 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2094 QString aPrefix = thePrefix;
2095 if ( aPrefix.isEmpty() )
2096 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2098 _PTR(SObject) anObj;
2101 aResName = aPrefix + QString::number( i++ );
2102 anObj = aStudy->FindObject( aResName.toLatin1().data() );
2106 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2107 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2108 aControl->setText( aResName );
2111 //================================================================================
2113 * \brief Gets algorithm or creates it if necessary
2114 * \param theDim - specifies dimension of returned hypotheses/algorifms
2115 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2117 * Gets algorithm or creates it if necessary
2119 //================================================================================
2120 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2122 SMESH::SMESH_Hypothesis_var anAlgoVar;
2124 // get type of the selected algo
2125 int aHypIndex = currentHyp( theDim, Algo );
2126 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2127 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2129 QString aHypName = dataList[ aHypIndex ]->TypeName;
2131 // get existing algorithms
2132 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
2134 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2136 // look for an existing algo of such a type
2137 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2138 THypList::iterator anIter = aHypVarList.begin();
2139 for ( ; anIter != aHypVarList.end(); anIter++)
2141 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2142 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2144 anAlgoVar = aHypVar;
2149 if (anAlgoVar->_is_nil())
2151 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2154 QString aClientLibName = aHypData->ClientLibName;
2155 if ( aClientLibName.isEmpty() )
2157 // Call hypothesis creation server method (without GUI)
2158 SMESH::SMESH_Hypothesis_var aHyp =
2159 SMESH::CreateHypothesis(aHypName, aHypName, true);
2164 // Get hypotheses creator client (GUI)
2165 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2169 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2171 SMESH::SMESH_Hypothesis_var aHyp =
2172 SMESH::CreateHypothesis(aHypName, aHypName, true);
2176 QStringList tmpList;
2177 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2178 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2181 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2182 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2184 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2185 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2187 anAlgoVar = aHypVar;
2193 return anAlgoVar._retn();
2196 //================================================================================
2198 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2200 * Called when mesh is edited only.
2202 //================================================================================
2203 void SMESHGUI_MeshOp::readMesh()
2205 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2206 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2210 if (myIsOnGeometry) {
2211 // Get name of mesh if current object is sub-mesh
2212 SMESH::SMESH_subMesh_var aSubMeshVar =
2213 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2214 if ( !aSubMeshVar->_is_nil() )
2216 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2217 if ( !aMeshVar->_is_nil() )
2219 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2220 QString aMeshName = name( aMeshSO );
2221 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2223 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2226 // Get name of geometry object
2227 CORBA::String_var name = SMESH::GetGeomName( pObj );
2229 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2232 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2233 QStringList anExisting;
2234 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2235 bool algoFound = false;
2236 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2239 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2240 // find algo index among available ones
2242 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2244 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2245 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( aVar->GetName() ));
2246 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2247 // if ( aHypIndex < 0 && algoData ) {
2248 // // assigned algo is incompatible with other algorithms
2249 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2250 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2252 algoFound = ( aHypIndex > -1 );
2254 setCurrentHyp( dim, Algo, aHypIndex );
2255 // set existing and available hypothesis according to the selected algo
2256 if ( aHypIndex > -1 || !algoFound )
2257 onAlgoSelected( aHypIndex, dim );
2261 bool hypWithoutAlgo = false;
2262 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2264 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2267 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2268 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2269 setCurrentHyp( dim, hypType, -1 );
2271 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2273 // find index of required hypothesis among existing ones for this dimension and type
2274 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2275 myExistingHyps[ dim ][ hypType ] );
2276 if ( aHypIndex < 0 ) {
2277 // assigned hypothesis is incompatible with the algorithm
2278 if ( currentHyp( dim, Algo ) < 0 )
2279 { // none algo selected; it is edition for sure, of submesh maybe
2280 hypWithoutAlgo = true;
2281 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2282 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2283 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2284 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2287 setCurrentHyp( dim, hypType + i, aHypIndex );
2289 if ( hypType == MainHyp ) break; // only one main hyp allowed
2293 // make available other hyps of same type as one without algo
2294 if ( hypWithoutAlgo )
2295 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2298 //================================================================================
2300 * \brief Gets name of object
2301 * \param theSO - SObject
2302 * \retval QString - name of object
2304 * Gets name of object
2306 //================================================================================
2307 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2312 _PTR(GenericAttribute) anAttr;
2313 _PTR(AttributeName) aNameAttr;
2314 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2317 aResName = aNameAttr->Value().c_str();
2323 //================================================================================
2325 * \brief Finds hypothesis in input list
2326 * \param theHyp - hypothesis to be found
2327 * \param theHypList - input list of hypotheses
2328 * \retval int - index of hypothesis or -1 if it is not found
2330 * Finds position of hypothesis in input list
2332 //================================================================================
2333 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2334 const THypList& theHypList ) const
2337 if ( !theHyp->_is_nil() )
2340 THypList::const_iterator anIter = theHypList.begin();
2341 for ( ; anIter != theHypList.end(); ++ anIter)
2343 if ( theHyp->_is_equivalent( (*anIter).first ) )
2354 //================================================================================
2356 * \brief Edits mesh or sub-mesh
2357 * \param theMess - Output parameter intended for returning error message
2358 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2360 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2362 //================================================================================
2363 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2367 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2368 if ( aSMESHGen->_is_nil() )
2371 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2372 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2376 SUIT_OverrideCursor aWaitCursor;
2379 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2380 SMESH::SetName( pObj, aName );
2381 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2383 // First, remove old algos in order to avoid messages on algorithm hiding
2384 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2386 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2388 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2389 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2390 if ( anAlgoVar->_is_nil() || // no new algo selected or
2391 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2393 // remove old algorithm
2394 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2395 myObjHyps[ dim ][ Algo ].clear();
2400 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2401 CORBA::Object_var anObject = aSObject->GetObject();
2402 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2403 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2404 bool isMesh = !aMeshVar->_is_nil();
2405 if ( !isMesh && !aSubMeshVar->_is_nil() )
2406 aMeshVar = aSubMeshVar->GetFather();
2408 // Assign new algorithms and hypotheses
2409 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2411 //if ( !isAccessibleDim( dim )) continue;
2413 // find or create algorithm
2414 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2416 // assign new algorithm
2417 if ( !anAlgoVar->_is_nil() && // some algo selected and
2418 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2421 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2422 else if ( !aSubMeshVar->_is_nil() )
2423 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2425 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2428 // remove deselected hypotheses
2429 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2431 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2433 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2434 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2435 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2437 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2441 // assign newly selected hypotheses
2442 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2444 const int curIndex = currentHyp( dim, dlgType );
2445 const int hypType = Min( dlgType, AddHyp );
2446 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2448 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2450 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2454 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2455 else if ( !aSubMeshVar->_is_nil() )
2456 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2459 // reread all hypotheses of mesh
2460 QStringList anExisting;
2461 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2465 myHasConcurrentSubBefore =
2466 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2471 //================================================================================
2473 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2474 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2475 * order of sub-mesh computation.
2476 * Returns \c true if a sub-mesh concurrency detected.
2478 //================================================================================
2480 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2481 SMESH::SMESH_subMesh_ptr submesh,
2484 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2487 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2488 if ( isNewConcurrent && askUser )
2490 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2491 tr("CONCURRENT_SUBMESH_APPEARS"),
2492 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2495 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2496 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2497 if ( meshSO && aSelectionMgr )
2499 myDlg->setEnabled( false ); // disactivate selection
2500 selectionMgr()->clearFilters();
2501 selectObject( meshSO );
2502 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2503 qApp->processEvents();
2505 myDlg->setEnabled( true );
2506 int obj = myDlg->getActiveObject();
2507 onActivateObject( obj ); // restore filter
2510 selectObject( SMESH::FindSObject( submesh ));
2517 return isNewConcurrent;
2520 //================================================================================
2522 * \brief Verifies whether given operator is valid for this one
2523 * \param theOtherOp - other operation
2524 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2526 * method redefined from base class verifies whether given operator is valid for
2527 * this one (i.e. can be started "above" this operator). In current implementation method
2528 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2531 //================================================================================
2532 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2534 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2537 //================================================================================
2539 * \brief SLOT. Is called when the user selects a way of geometry selection
2540 * \param theByMesh - true if the user wants to find geometry by mesh element
2542 //================================================================================
2543 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2546 if ( !myShapeByMeshOp ) {
2547 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2548 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2549 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2550 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2551 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2553 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2554 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2555 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2556 SMESH::SMESH_Mesh_var aMeshVar =
2557 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2558 if ( !aMeshVar->_is_nil() ) {
2559 myDlg->hide(); // stop processing selection
2560 myShapeByMeshOp->setModule( getSMESHGUI() );
2561 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2562 myShapeByMeshOp->SetMesh( aMeshVar );
2563 myShapeByMeshOp->start();
2569 //================================================================================
2571 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2573 //================================================================================
2574 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2576 if ( myShapeByMeshOp == op ) {
2577 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2579 // Select a found geometry object
2580 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2581 if ( !aGeomVar->_is_nil() )
2583 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2584 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2585 selectObject( aGeomSO );
2592 //================================================================================
2594 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2596 //================================================================================
2597 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2599 if ( myShapeByMeshOp == op && myDlg ) {
2604 //================================================================================
2606 * \brief Selects a SObject
2607 * \param theSObj - the SObject to select
2609 //================================================================================
2610 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2612 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2613 SALOME_ListIO anIOList;
2615 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2616 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2617 anIOList.Append( anIO );
2619 sm->setSelectedObjects( anIOList, false );
2622 //================================================================================
2624 * \brief Create available list types of mesh
2625 * \param theTypeMesh - Output list of available types of mesh
2627 //================================================================================
2628 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2630 theTypeMesh.clear();
2631 theTypeMesh.append( tr( "MT_ANY" ) );
2632 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2634 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2635 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2637 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2639 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2640 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2644 //================================================================================
2646 * \brief Set available types of mesh
2647 * \param theTypeMesh - List of available types of mesh
2649 //================================================================================
2650 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2652 myDlg->setAvailableMeshType( theTypeMesh );
2655 //================================================================================
2657 * \brief SLOT. Is called when the user select type of mesh
2658 * \param theTabIndex - Index of current active tab
2659 * \param theIndex - Index of current type of mesh
2661 //================================================================================
2662 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex )
2664 setFilteredAlgoData( theTabIndex, theIndex);
2667 //================================================================================
2669 * \brief Set a filtered list of available algorithms by mesh type
2670 * \param theTabIndex - Index of current active tab
2671 * \param theIndex - Index of current type of mesh
2673 //================================================================================
2674 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex )
2676 QStringList anAvailableAlgs;
2677 QString anCompareType = currentMeshTypeName( theIndex );
2678 int anCurrentAvailableAlgo = -1;
2680 int aDim = SMESH::DIM_3D;
2681 if ( theIndex == MT_TRIANGULAR || theIndex == MT_QUADRILATERAL)
2682 aDim = SMESH::DIM_2D;
2683 if ( anCompareType == "ANY" )
2685 bool isReqDisBound = false;
2686 int aReqDim = SMESH::DIM_3D;
2687 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2689 anCurrentAvailableAlgo = -1;
2690 isNone = currentHyp( dim, Algo ) < 0;
2691 //return current algo in current tab and set new algorithm list
2692 HypothesisData* algoCur = 0;
2693 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2694 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2696 HypothesisData* prevAlgo = 0;
2697 HypothesisData* nextAlgo = 0;
2698 if ( dim == SMESH::DIM_2D ) {
2699 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2700 if ( aDim == SMESH::DIM_3D )
2701 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2703 // retrieves a list of available algorithms from resources
2704 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCompareType);
2705 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoCur );
2706 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2707 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2708 if ( anCurrentAvailableAlgo > -1 )
2709 isReqDisBound = algoCur->InputTypes.isEmpty();
2710 if ( isReqDisBound ) {
2715 if ( !myIsOnGeometry )
2716 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2717 if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2718 else myDlg->enableTab( i );
2721 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2722 if ( i > myMaxShapeDim || ( isReqDisBound && i < aReqDim ) ) myDlg->disableTab( i );
2723 else myDlg->enableTab( i );
2725 myDlg->setCurrentTab( theTabIndex );
2729 HypothesisData* anCurrentAlgo = 0;
2730 bool isReqDisBound = true;
2731 QString anCurrentCompareType = anCompareType;
2732 isNone = currentHyp( aDim, Algo ) < 0;
2733 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() )
2734 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2735 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2737 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2738 anCurrentAvailableAlgo = -1;
2739 HypothesisData* prevAlgo = 0;
2740 HypothesisData* nextAlgo = 0;
2741 if ( dim == SMESH::DIM_2D ) {
2742 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2743 if ( aDim == SMESH::DIM_3D )
2744 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2746 // finding algorithm which is selected
2748 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2750 // retrieves a list of available algorithms from resources
2751 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType );
2752 // finding and adding algorithm depending on the type mesh
2753 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( anCurrentAlgo );
2754 //set new algorithm list and select the current algorithm
2755 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2756 anCurrentCompareType = ( anCompareType == "HEXA" || anCompareType == "QUAD" ) ? "QUAD" : "TRIA";
2757 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo, /*updateHyps=*/true );
2760 for ( int i = myMaxShapeDim; i >= SMESH::DIM_0D; i-- ) {
2761 bool isNoneAlg = currentHyp( i, Algo ) < 0;
2763 isReqDisBound = myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2765 isReqDisBound = true;
2766 if ( isReqDisBound && !isNoneAlg && i <= aDim) {
2767 for (int j = myMaxShapeDim; j >= SMESH::DIM_0D; j--) {
2768 if ( currentHyp( j, Algo ) < 0 ) {
2769 myDlg->disableTab( j );
2770 setCurrentHyp( j , Algo, -1, /*updateHyps=*/true );
2776 myDlg->enableTab( i );
2779 if ( aDim == SMESH::DIM_2D) {
2780 setCurrentHyp( SMESH::DIM_3D, Algo, -1, /*updateHyps=*/true );
2781 myDlg->disableTab( SMESH::DIM_3D );
2784 int currentTab = ( theTabIndex <= aDim ) ? theTabIndex : aDim;
2785 myDlg->setCurrentTab( currentTab );
2787 THypDataList anAvailableAlgsData;
2788 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2789 QStringList aFilteredHypothesesSetsList;
2790 aFilteredHypothesesSetsList.clear();
2791 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2792 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName ) {
2793 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2794 bool isAvailable = false;
2795 currentHypoSet->init( true );
2796 while ( currentHypoSet->next(), currentHypoSet->more() ) {
2797 isAvailable = false;
2798 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2799 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++) {
2800 int anCurrentAvailableAlgo = myAvailableHypData[i][Algo].indexOf( algoDataIn );
2801 if ( anCurrentAvailableAlgo > -1 ) {
2811 aFilteredHypothesesSetsList.append( *inHypoSetName );
2813 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2816 //================================================================================
2818 * \brief Get current name types of mesh
2819 * \param theIndex - current index types of mesh
2820 * \retval QString - result
2822 //================================================================================
2823 QString SMESHGUI_MeshOp::currentMeshTypeName( const int theIndex ) const
2825 QString aMeshType = "";
2826 switch ( theIndex ) {
2833 case MT_QUADRILATERAL:
2836 case MT_TETRAHEDRAL:
2837 aMeshType = "TETRA";