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()
136 if (SMESHGUI::isStudyLocked())
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()
203 myIgnoreAlgoSelection = false;
207 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
208 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
210 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
211 this, SLOT( onCreateHyp( const int, const int ) ) );
212 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
213 this, SLOT( onEditHyp( const int, const int ) ) );
214 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
215 this, SLOT( onAlgoSelected( const int ) ) );
217 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
218 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
219 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
221 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
222 else myHelpFileName = "constructing_submeshes.html";
225 myHelpFileName = "editing_meshes.html";
228 SMESHGUI_SelectionOp::startOperation();
229 // iterate through dimensions and get available algorithms, set them to the dialog
230 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
231 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
233 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
235 // clear available hypotheses
236 aTab->setAvailableHyps( MainHyp, hypList );
237 aTab->setAvailableHyps( AddHyp, hypList );
238 aTab->setExistingHyps( MainHyp, hypList );
239 aTab->setExistingHyps( AddHyp, hypList );
240 myExistingHyps[ i ][ MainHyp ].clear();
241 myExistingHyps[ i ][ AddHyp ].clear();
243 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
244 aTab->setAvailableHyps( Algo, hypList );
249 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
253 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
255 myDlg->setCurrentTab( SMESH::DIM_3D );
257 QStringList TypeMeshList;
258 createMeshTypeList( TypeMeshList );
259 setAvailableMeshType( TypeMeshList );
262 myDlg->setGeomPopupEnabled(false);
265 myHasConcurrentSubBefore = false;
267 myObjectToSelect.clear();
270 //=================================================================================
272 * \brief Selects a recently created mesh or sub-mesh if necessary
274 * Virtual method redefined from base class called when operation is committed
275 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
276 * selection when the custom selection filters are removed.
278 //=================================================================================
279 void SMESHGUI_MeshOp::commitOperation()
281 SMESHGUI_SelectionOp::commitOperation();
283 if ( !myObjectToSelect.isEmpty() ) {
284 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
285 SUIT_DataOwnerPtrList aList;
286 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
287 aSelectionMgr->setSelected( aList );
292 //================================================================================
294 * \brief Creates selection filter
295 * \param theId - identifier of current selection widget
296 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
298 * Creates selection filter in accordance with identifier of current selection widget
300 //================================================================================
301 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
303 if ( theId == SMESHGUI_MeshDlg::Geom )
305 // TColStd_MapOfInteger allTypesMap;
306 // for ( int i = 0; i < 10; i++ )
307 // allTypesMap.Add( i );
308 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
309 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
311 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
312 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
313 else if ( theId == SMESHGUI_MeshDlg::Mesh )
314 return new SMESH_TypeFilter( SMESH::MESH );
319 //================================================================================
321 * \brief check if selected shape is a sub-shape of the shape to mesh
322 * \retval bool - check result
324 //================================================================================
325 bool SMESHGUI_MeshOp::isSubshapeOk() const
327 if ( !myToCreate || myIsMesh ) // not submesh creation
331 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
332 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
333 if (!pMesh) return false;
335 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
336 if (mesh->_is_nil()) return false;
338 // main shape of the mesh
339 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
340 if (mainGeom->_is_nil()) return false;
344 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
346 if (aGEOMs.count() > 0) {
347 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
348 if (geomGen->_is_nil()) return false;
350 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
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 = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().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();
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 = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().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].toUtf8().data() );
434 // GEOM::GEOM_Object_var geom;
435 // if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().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].toUtf8().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 = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
465 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().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::getStudy();
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 = SMESH::getStudy()->FindObjectID(anObjEntry.toUtf8().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 = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().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 = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().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 myIsMesh = submeshVar->_is_nil();
641 myDlg->setTitile( myToCreate, myIsMesh );
642 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
643 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
644 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
645 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
646 myDlg->updateGeometry();
653 else if ( !myIsMesh ) // submesh creation
655 // if a submesh on the selected shape already exist, pass to submesh edition mode
656 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
657 SMESH::SMESH_subMesh_var sm =
658 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
659 bool editSubmesh = ( !sm->_is_nil() &&
660 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
661 tr( "EDIT_SUBMESH_QUESTION"),
662 SUIT_MessageBox::Yes |
664 SUIT_MessageBox::No )
665 == SUIT_MessageBox::Yes );
668 selectionMgr()->clearFilters();
669 selectObject( pSubmesh );
670 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
675 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
676 selectObject( _PTR(SObject)() );
681 // discard selected mesh if submesh creation not allowed because of
682 // a global algorithm that does not support submeshes
683 if ( char* algoName = isSubmeshIgnored() ) {
684 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
685 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
686 CORBA::string_free( algoName );
687 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
688 selectObject( _PTR(SObject)() );
693 // enable/disable popup for choice of geom selection way
695 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
696 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
697 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
698 if ( !mesh->_is_nil() ) {
699 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
700 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
701 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
702 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
703 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
704 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
707 myDlg->setGeomPopupEnabled( enable );
710 else { // no geometry defined
713 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
715 availableHyps( dim, Algo, hypList, myAvailableHypData[dim][Algo]);
716 myDlg->tab( dim )->setAvailableHyps( Algo, hypList );
717 if ( hypList.empty() ) myDlg->disableTab( dim );
718 else myDlg->enableTab( dim );
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 = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().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 = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().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 = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().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 GEOM::GEOM_Object_var aGeomVar;
945 QString aCurrentGeomToSelect;
946 if ( !theMeshType.isEmpty() ) {
947 aCurrentGeomToSelect = myDlg->selectedObject( myToCreate ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Obj );
948 if ( _PTR(SObject) so = SMESH::getStudy()->FindObjectID( aCurrentGeomToSelect.toUtf8().data() )) {
949 aGeomVar = SMESH::GetGeom( so );
951 if ( aCurrentGeomToSelect != myLastGeomToSelect )
952 myHypMapIsApplicable.clear();
955 std::multimap< double, HypothesisData* > sortedHyps;
956 QStringList::const_iterator anIter;
957 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
959 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
960 if ( ( isCompatible ( thePrevAlgoData, aData, theHypType ) &&
961 isCompatible ( theNextAlgoData, aData, theHypType ) ) ||
962 ( theMeshType == "ANY" && aData->InputTypes.isEmpty()))
964 if ( ( !theMeshType.isEmpty() ) &&
965 ( theDim >= SMESH::DIM_2D ) &&
966 ( ( theMeshType != "ANY" && !isCompatibleToMeshType( aData, theMeshType )) ||
967 !isCompatibleToGeometry( aData, aCurrentGeomToSelect, aGeomVar )))
970 int groupID = aData->GroupID;
971 int priority = aData->Priority;
972 if ( groupID < 0 || groupID > 9 ) groupID = 9;
973 if ( priority < 0 || priority > 999 ) priority = 999;
975 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
979 if ( !sortedHyps.empty() )
981 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
982 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
983 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
985 HypothesisData* aData = key_hyp->second;
986 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
987 if ( aPrevGroup != aGroup )
989 theDataList.append( aGroup );
990 theHyps.append( aGroup->Label );
993 theDataList.append( aData );
994 theHyps.append( aData->Label );
998 if ( !theMeshType.isEmpty() && !aCurrentGeomToSelect.isEmpty() )
999 myLastGeomToSelect = aCurrentGeomToSelect;
1002 //================================================================================
1004 * \brief Gets existing hypotheses or algorithms
1005 * \param theDim - specifies dimension of returned hypotheses/algorifms
1006 * \param theHypType - specifies whether algorims or hypotheses or additional ones
1007 * are retrieved (possible values are in HypType enumeration)
1008 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
1009 * \param theHyps - output list of names.
1010 * \param theHypVars - output list of variables.
1011 * \param theAlgoData - to select hypos able to be used by this algo (optional)
1013 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
1016 * WARNING: when using this method to get hyps existing in Mesh component,
1017 * call availableHyps() before in order to get only hyps of available types
1018 * that was filtered by availableHyps()
1020 //================================================================================
1021 void SMESHGUI_MeshOp::existingHyps( const int theDim,
1022 const int theHypType,
1023 _PTR(SObject) theFather,
1024 QStringList& theHyps,
1025 THypList& theHypList,
1026 HypothesisData* theAlgoData) const
1028 // Clear hypoheses list
1035 _PTR(SObject) aHypRoot;
1036 _PTR(GenericAttribute) anAttr;
1037 _PTR(AttributeName) aName;
1038 _PTR(AttributeIOR) anIOR;
1040 const bool isMesh = !_CAST( SComponent, theFather );
1043 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
1045 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
1047 const bool isAux = ( theHypType >= AddHyp );
1048 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
1050 if ( theFather->FindSubObject( aPart, aHypRoot ) )
1052 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypRoot );
1053 for ( ; anIter->More(); anIter->Next() )
1055 _PTR(SObject) anObj = anIter->Value();
1056 if ( isMesh ) // i.e. mesh or submesh
1058 _PTR(SObject) aRefObj;
1059 if ( anObj->ReferencedObject( aRefObj ) )
1064 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1067 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1068 if ( !CORBA::is_nil( aVar ) )
1070 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
1071 if ( !aHypVar->_is_nil() )
1073 CORBA::String_var hypType = aHypVar->GetName();
1074 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
1075 if ( !aData) continue;
1076 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
1077 ( isCompatible ( theAlgoData, aData, theHypType )) &&
1078 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
1079 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
1081 std::string aHypName = aName->Value();
1082 theHyps.append( aHypName.c_str() );
1083 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
1092 //================================================================================
1094 * \brief If create or edit a submesh, return a hypothesis holding parameters used
1095 * to mesh a sub-shape
1096 * \param aHypType - The hypothesis type name
1097 * \param aServerLib - Server library name
1098 * \param hypData - The structure holding the hypothesis type etc.
1099 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
1101 //================================================================================
1102 SMESH::SMESH_Hypothesis_var
1103 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1104 const QString& aServerLib ) const
1106 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1107 return SMESH::SMESH_Hypothesis::_nil();
1109 const int nbColonsInMeshEntry = 3;
1110 bool isSubMesh = myToCreate ?
1112 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1114 // get mesh and geom object
1115 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
1116 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1121 anEntry = myDlg->selectedObject
1122 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1123 if ( _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1125 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1126 if ( myToCreate ) // mesh and geom may be selected
1128 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
1129 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1130 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1131 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1133 else // edition: sub-mesh may be selected
1135 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1136 if ( !sm->_is_nil() ) {
1137 aMeshVar = sm->GetFather();
1138 aGeomVar = sm->GetSubShape();
1145 if ( !myToCreate ) // mesh to edit can be selected
1147 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1148 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1150 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1151 if ( !aMeshVar->_is_nil() )
1152 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1155 if ( aGeomVar->_is_nil() ) {
1156 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1157 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1159 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1164 SMESH::SMESH_Hypothesis_var hyp =
1165 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1166 aServerLib.toUtf8().data(),
1169 /*byMesh = */isSubMesh);
1170 if ( hyp->_is_nil() && isSubMesh )
1171 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1172 aServerLib.toUtf8().data(),
1175 /*byMesh = */false);
1179 //================================================================================
1181 * \brief initialize a hypothesis creator
1183 //================================================================================
1185 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1187 if ( !theCreator ) return;
1189 // Set shapes, of mesh and sub-mesh if any
1191 // get Entry of the Geom object
1192 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1193 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1194 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1196 if ( myToCreate && myIsMesh )
1197 aMeshEntry = aGeomEntry;
1199 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1200 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1201 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1202 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1205 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1206 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1208 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1209 if ( !aGeomVar->_is_nil() )
1211 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1213 aMeshEntry = aGeomEntry;
1217 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1218 // take geometry from submesh being created
1219 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1221 // if current object is sub-mesh
1222 SMESH::SMESH_subMesh_var aSubMeshVar =
1223 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1224 if ( !aSubMeshVar->_is_nil() ) {
1225 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1226 if ( !aMeshVar->_is_nil() ) {
1227 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1228 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1229 if ( !aGeomVar->_is_nil() )
1230 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1236 theCreator->setShapeEntry( aGeomEntry );
1237 if ( aMeshEntry != "" )
1238 theCreator->setMainShapeEntry( aMeshEntry );
1240 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1243 //================================================================================
1245 * \Brief Returns tab dimension
1246 * \param tab - the tab in the dlg
1247 * \param dlg - my dialogue
1248 * \retval int - dimension
1250 //================================================================================
1251 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1254 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1255 if (tab == dlg->tab(i))
1260 //================================================================================
1262 * \brief Create hypothesis
1263 * \param theHypType - hypothesis category (main or additional)
1264 * \param theIndex - index of type of hypothesis to be created
1266 * Specifies dimension of hypothesis to be created (using sender() method),
1267 * specifies its type and calls method for hypothesis creation
1269 //================================================================================
1270 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1272 // Specifies dimension of hypothesis to be created
1273 int aDim = getTabDim( sender(), myDlg );
1277 // Specifies type of hypothesis to be created
1278 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1279 if (theIndex < 0 || theIndex >= dataList.count())
1281 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1283 // Create hypothesis
1284 createHypothesis(aDim, theHypType, aHypTypeName);
1289 QString GetUniqueName (const QStringList& theHypNames,
1290 const QString& theName,
1291 size_t theIteration = 1)
1293 QString aName = theName + "_" + QString::number( theIteration );
1294 if ( theHypNames.contains( aName ) )
1295 return GetUniqueName( theHypNames, theName, ++theIteration );
1300 //================================================================================
1302 * Create hypothesis and update dialog.
1303 * \param theDim - dimension of hypothesis to be created
1304 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1305 * \param theTypeName - specifies hypothesis to be created
1307 //================================================================================
1308 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1310 const QString& theTypeName)
1312 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1319 // get a unique hyp name
1320 QStringList aHypNames;
1321 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1322 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1323 const TType2HypList& aType2HypList = aDimIter.value();
1324 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1325 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1326 const THypList& aHypList = aTypeIter.value();
1327 THypList::const_iterator anIter = aHypList.begin();
1328 for ( ; anIter != aHypList.end(); anIter++) {
1329 const THypItem& aHypItem = *anIter;
1330 const QString& aHypName = aHypItem.second;
1331 aHypNames.append(aHypName);
1335 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1338 bool dialog = false;
1340 QString aClientLibName = aData->ClientLibName;
1341 if (aClientLibName == "") {
1342 // Call hypothesis creation server method (without GUI)
1343 SMESH::SMESH_Hypothesis_var aHyp =
1344 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1348 // Get hypotheses creator client (GUI)
1349 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1351 // Create hypothesis
1354 // Get parameters appropriate to initialize a new hypothesis
1355 SMESH::SMESH_Hypothesis_var initParamHyp =
1356 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1358 removeCustomFilters(); // Issue 0020170
1360 // set shapes, of mesh and sub-mesh if any
1361 initHypCreator( aCreator );
1363 myDlg->setEnabled( false );
1364 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1369 SMESH::SMESH_Hypothesis_var aHyp =
1370 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1379 //================================================================================
1381 * Necessary steps after hypothesis creation
1382 * \param result - creation result:
1385 * 2 = additional value meaning that slot is called not from dialog box
1387 //================================================================================
1388 void SMESHGUI_MeshOp::onHypoCreated( int result )
1392 int obj = myDlg->getActiveObject();
1393 onActivateObject( obj ); // Issue 0020170. Restore filters
1394 myDlg->setEnabled( true );
1397 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1399 int nbHyp = myExistingHyps[myDim][myType].count();
1400 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1401 QStringList aNewHyps;
1402 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1403 if (aNewHyps.count() > nbHyp)
1405 for (int i = nbHyp; i < aNewHyps.count(); i++)
1406 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1409 if( result!=2 && myHypoSet )
1413 //================================================================================
1415 * \brief Calls plugin methods for hypothesis editing
1416 * \param theHypType - specifies whether main hypothesis or additional one
1418 * \param theIndex - index of existing hypothesis
1420 * Calls plugin methods for hypothesis editing
1422 //================================================================================
1423 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1425 // Speicfies dimension of hypothesis to be created
1426 int aDim = getTabDim( sender(), myDlg );
1430 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1431 if ( theIndex < 0 || theIndex >= aList.count() )
1433 const THypItem& aHypItem = aList[ theIndex ];
1434 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1435 if ( aHyp->_is_nil() )
1438 SMESHGUI_GenericHypothesisCreator* aCreator =
1439 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1442 // set initial parameters
1443 SMESH::SMESH_Hypothesis_var initParamHyp =
1444 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1445 SMESH::toQStr( aHyp->GetLibName() ));
1446 aCreator->setInitParamsHypothesis( initParamHyp );
1448 // set shapes, of mesh and sub-mesh if any
1449 initHypCreator( aCreator );
1451 removeCustomFilters(); // Issue 0020170
1452 myDlg->setEnabled( false );
1454 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1458 //================================================================================
1460 * Necessary steps after hypothesis edition
1461 * \param result - creation result:
1465 //================================================================================
1466 void SMESHGUI_MeshOp::onHypoEdited( int result )
1468 int obj = myDlg->getActiveObject();
1469 onActivateObject( obj ); // Issue 0020170. Restore filters
1470 myDlg->setEnabled( true );
1473 //================================================================================
1475 * \brief access to hypothesis data
1476 * \param theDim - hyp dimension
1477 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1478 * \param theIndex - index in the list
1479 * \retval HypothesisData* - result data, may be 0
1481 //================================================================================
1482 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1483 const int theHypType,
1486 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1487 theHypType > -1 && theHypType < NbHypTypes &&
1488 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1489 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1493 //================================================================================
1495 * \brief Set available algos and hypos according to the selected algorithm
1496 * \param theIndex - algorithm index
1498 //================================================================================
1499 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1502 if ( myIgnoreAlgoSelection )
1505 int curDim = getTabDim( sender(), myDlg );
1506 int aDim = theDim < 0 ? curDim : theDim;
1510 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1512 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1513 HypothesisData* algoByDim[4];
1514 algoByDim[ aDim ] = algoData;
1516 QStringList anAvailable;
1518 // enable / disable tabs
1519 if ( myIsOnGeometry ) {
1520 for (int i = SMESH::DIM_3D; i >= SMESH::DIM_0D; i--) {
1522 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
1523 else myDlg->enableTab( i );
1525 else if ( i == aDim ) {
1528 else {//( i < aDim )
1529 if ( algoData && algoData->InputTypes.isEmpty() ) {
1530 myDlg->disableTab( i );
1531 for ( int type = Algo, nbTypes = nbDlgHypTypes(i); type < nbTypes; type++ )
1532 setCurrentHyp(i, type, -1);
1535 myDlg->enableTab( i );
1542 HypothesisData* a3DAlgo = 0;
1543 // 2 loops: backward and forward from algo dimension
1544 for ( int forward = 0; forward <= 1; ++forward )
1546 int dim = algoDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1548 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1550 HypothesisData* prevAlgo = algoData;
1551 bool noCompatible = false;
1552 for ( ; dim * dir <= lastDim * dir; dim += dir)
1554 if ( !isAccessibleDim( dim ))
1556 if ( noCompatible ) { // the selected algo has no compatible ones
1557 anAvailable.clear();
1558 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1559 myAvailableHypData[dim][Algo].clear();
1560 algoByDim[ dim ] = 0;
1563 HypothesisData* nextAlgo = 0;
1564 if ( myMaxShapeDim == SMESH::DIM_3D && a3DAlgo && dim == SMESH::DIM_2D ) {
1567 // get currently selected algo
1568 int algoIndex = currentHyp( dim, Algo );
1569 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1571 QString anCompareType = currentMeshTypeName(myDlg->currentMeshType());
1572 QString anCurrentCompareType = "";
1573 if ( dim == SMESH::DIM_3D || anCompareType == "ANY" )
1574 anCurrentCompareType = anCompareType;
1575 else if ( dim == SMESH::DIM_2D ) {
1576 anCurrentCompareType = (anCompareType == "HEXA" || anCompareType == "QUAD") ? "QUAD" : "TRIA";
1580 // set new available algorithms
1581 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType);
1582 HypothesisData* soleCompatible = 0;
1583 if ( anAvailable.count() == 1 )
1584 soleCompatible = myAvailableHypData[dim][Algo][0];
1585 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1586 noCompatible = anAvailable.isEmpty();
1587 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1588 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim == curDim ) {
1589 // select the sole compatible algo
1592 setCurrentHyp( dim, Algo, algoIndex );
1594 // remember current algo
1595 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1599 if ( myMaxShapeDim == SMESH::DIM_3D && forward && algoDim == SMESH::DIM_1D )
1601 algoDim = SMESH::DIM_3D;
1606 } // loops backward and forward
1609 // set hypotheses corresponding to the found algorithms
1611 _PTR(SObject) pObj = SMESH::getStudy()->FindComponent("SMESH");
1613 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1615 if ( !isAccessibleDim( dim ))
1618 // get indices of selected hyps
1619 const int nbTypes = nbDlgHypTypes(dim);
1620 std::vector<int> hypIndexByType( nbTypes, -1 );
1621 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1623 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1627 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1629 const int type = Min( dlgType, AddHyp );
1630 myAvailableHypData[ dim ][ type ].clear();
1631 QStringList anAvailable, anExisting;
1633 HypothesisData* curAlgo = algoByDim[ dim ];
1634 int hypIndex = hypIndexByType[ dlgType ];
1636 SMESH::SMESH_Hypothesis_var curHyp;
1637 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1638 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1640 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1641 // try to find algo by selected hypothesis in order to keep it selected
1642 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1643 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1644 if ( !algoDeselectedByUser &&
1645 myObjHyps[ dim ][ type ].count() > 0 &&
1646 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1648 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1649 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1650 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1651 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1658 // get hyps compatible with curAlgo
1659 bool defaulHypAvlbl = false;
1662 // check if a selected hyp is compatible with the curAlgo
1663 if ( !curHyp->_is_nil() ) {
1664 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1665 if ( !isCompatible( curAlgo, hypData, type ))
1666 curHyp = SMESH::SMESH_Hypothesis::_nil();
1668 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1669 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1670 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1672 // set list of hypotheses
1673 if ( dlgType <= AddHyp )
1675 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1676 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1678 // set current existing hypothesis
1679 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1680 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1683 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1685 // none is yet selected => select the sole existing if it is not optional
1686 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1687 bool isOptional = true;
1688 if ( algoByDim[ dim ] &&
1689 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1693 setCurrentHyp( dim, dlgType, hypIndex );
1698 //================================================================================
1700 * \brief Creates and selects hypothesis of hypotheses set
1701 * \param theSetName - The name of hypotheses set
1703 //================================================================================
1704 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1706 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1711 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1712 setCurrentHyp(dim, Algo, -1);
1713 setCurrentHyp(dim, AddHyp, -1);
1714 setCurrentHyp(dim, MainHyp, -1);
1717 myHypoSet->init(true); //algorithms
1719 myHypoSet->init(false); //hypotheses
1724 //================================================================================
1726 * \brief One step of hypothesis/algorithm list creation
1728 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1730 //================================================================================
1731 void SMESHGUI_MeshOp::processSet()
1734 if( !myHypoSet->more() )
1737 bool isAlgo = myHypoSet->isAlgo();
1738 QString aHypoTypeName = myHypoSet->current();
1739 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1746 int aDim = aHypData->Dim[0];
1747 // create or/and set
1750 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1753 QStringList anAvailable;
1754 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1755 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1756 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1758 setCurrentHyp( aDim, Algo, index );
1759 onAlgoSelected( index, aDim );
1764 bool mainHyp = true;
1765 QStringList anAvailable;
1766 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1767 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1768 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1772 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1775 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1781 //================================================================================
1783 * \brief Creates mesh
1784 * \param theMess - Output parameter intended for returning error message
1785 * \param theEntryList - List of entries of published objects
1786 * \retval bool - TRUE if mesh is created, FALSE otherwise
1790 //================================================================================
1791 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1796 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1797 if ( aList.isEmpty() )
1799 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1800 if ( aSMESHGen->_is_nil() )
1803 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1804 if ( aMeshVar->_is_nil() )
1807 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1809 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1810 theEntryList.append( aMeshSO->GetID().c_str() );
1815 if ( aList.count() > 1 )
1817 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1818 int i = namePrefix.length() - 1;
1819 while ( i > 0 && namePrefix[i].isDigit() )
1821 if ( i < namePrefix.length() - 1 )
1822 namePrefix.chop( namePrefix.length() - 1 - i );
1826 QStringList::Iterator it = aList.begin();
1827 for ( int i = 0; it!=aList.end(); it++, ++i )
1829 QString aGeomEntry = *it;
1830 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
1831 GEOM::GEOM_Object_var aGeomVar =
1832 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1834 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1835 if ( aSMESHGen->_is_nil() )
1838 SUIT_OverrideCursor aWaitCursor;
1841 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1842 if ( aMeshVar->_is_nil() )
1844 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1846 theEntryList.append( aMeshSO->GetID().c_str() );
1847 if ( i > 0 ) setDefaultName( namePrefix );
1848 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1851 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1853 if ( !isAccessibleDim( aDim )) continue;
1855 // assign hypotheses
1856 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1858 const int aHypIndex = currentHyp( aDim, dlgType );
1859 const int aHypType = Min( dlgType, AddHyp );
1860 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1862 SMESH::SMESH_Hypothesis_var aHypVar =
1863 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1864 if ( !aHypVar->_is_nil() )
1865 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1868 // find or create algorithm
1869 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1870 if ( !anAlgoVar->_is_nil() )
1871 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1877 //================================================================================
1879 * \brief Creates sub-mesh
1880 * \param theMess - Output parameter intended for returning error message
1881 * \param theEntryList - List of entries of published objects
1882 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1886 //================================================================================
1887 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1891 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1892 if ( aSMESHGen->_is_nil() )
1896 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1897 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1898 SMESH::SMESH_Mesh_var aMeshVar =
1899 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1900 if (aMeshVar->_is_nil())
1903 // GEOM shape of the main mesh
1904 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1906 // Name for the new sub-mesh
1907 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1910 GEOM::GEOM_Object_var aGeomVar;
1912 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1913 if (aGEOMs.count() == 1)
1915 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1916 QString aGeomEntry = aGEOMs.first();
1917 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
1918 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1920 else if (aGEOMs.count() > 1)
1922 // create a GEOM group
1923 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1924 if (!geomGen->_is_nil()) {
1925 GEOM::GEOM_IGroupOperations_wrap op =
1926 geomGen->GetIGroupOperations();
1927 if (!op->_is_nil()) {
1928 // check and add all selected GEOM objects: they must be
1929 // a sub-shapes of the main GEOM and must be of one type
1931 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1932 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1933 aSeq->length(aGEOMs.count());
1934 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1935 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1936 QString aSubGeomEntry = (*aSubShapesIter);
1937 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
1938 GEOM::GEOM_Object_var aSubGeomVar =
1939 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1940 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1942 aGroupType = aSubShapeType;
1944 if (aSubShapeType != aGroupType)
1945 aGroupType = TopAbs_SHAPE;
1947 aSeq[iSubSh] = aSubGeomVar;
1950 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1951 op->UnionList(aGroupVar, aSeq);
1955 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1957 // publish the GEOM group in study
1958 QString aNewGeomGroupName ("Auto_group_for_");
1959 aNewGeomGroupName += aName;
1960 SALOMEDS::SObject_wrap aNewGroupSO =
1961 geomGen->AddInStudy( aGeomVar,
1962 aNewGeomGroupName.toUtf8().data(), mainGeom);
1969 if (aGeomVar->_is_nil())
1972 SUIT_OverrideCursor aWaitCursor;
1975 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toUtf8().data() );
1976 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1978 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
1979 theEntryList.append( aSubMeshSO->GetID().c_str() );
1982 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1984 if ( !isAccessibleDim( aDim )) continue;
1986 // find or create algorithm
1987 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1988 if ( !anAlgoVar->_is_nil() )
1989 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1990 // assign hypotheses
1991 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1993 const int aHypIndex = currentHyp( aDim, dlgType );
1994 const int aHypType = Min( dlgType, AddHyp );
1995 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1997 SMESH::SMESH_Hypothesis_var aHypVar =
1998 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1999 if ( !aHypVar->_is_nil() )
2000 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2005 // deselect geometry: next submesh should be created on other sub-shape
2006 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2007 selectObject( _PTR(SObject)() );
2010 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
2015 //================================================================================
2017 * \brief Gets current hypothesis or algorithms
2018 * \param theDim - dimension of hypothesis or algorithm
2019 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2020 * \retval int - current hypothesis or algorithms
2022 * Gets current hypothesis or algorithms
2024 //================================================================================
2025 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2027 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2030 //================================================================================
2032 * \brief Checks if a hypothesis is selected
2034 //================================================================================
2036 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2041 if ( theHypType < AddHyp ) // only one hyp can be selected
2042 return currentHyp( theDim, theHypType ) == theIndex;
2044 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2045 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2051 //================================================================================
2053 * \brief Returns nb of HypType's taking into account possible several
2054 * selected additional hypotheses which are coded as additional HypType's.
2056 //================================================================================
2058 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2060 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2063 //================================================================================
2065 * \brief Returns true if hypotheses of given dim can be assigned
2066 * \param theDim - hypotheses dimension
2067 * \retval bool - result
2069 //================================================================================
2070 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2072 return myDlg->isTabEnabled( theDim );
2075 //================================================================================
2077 * \brief Sets current hypothesis or algorithms
2078 * \param theDim - dimension of hypothesis or algorithm
2079 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2080 * \param theIndex - Index of hypothesis
2081 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2083 * Gets current hypothesis or algorithms
2085 //================================================================================
2086 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2087 const int theHypType,
2089 const bool updateHypsOnAlgoDeselection)
2091 myIgnoreAlgoSelection = true;
2092 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2093 myIgnoreAlgoSelection = false;
2095 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2097 const QStringList noHyps;
2098 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2099 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2100 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2101 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2105 //================================================================================
2107 * \brief Generates default and sets mesh/submesh name
2109 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2111 //================================================================================
2112 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2116 _PTR(Study) aStudy = SMESH::getStudy();
2119 QString aPrefix = thePrefix;
2120 if ( aPrefix.isEmpty() )
2121 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2123 _PTR(SObject) anObj;
2126 aResName = aPrefix + QString::number( i++ );
2127 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2131 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2132 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2133 aControl->setText( aResName );
2136 //================================================================================
2138 * \brief Gets algorithm or creates it if necessary
2139 * \param theDim - specifies dimension of returned hypotheses/algorifms
2140 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2142 * Gets algorithm or creates it if necessary
2144 //================================================================================
2145 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2147 SMESH::SMESH_Hypothesis_var anAlgoVar;
2149 // get type of the selected algo
2150 int aHypIndex = currentHyp( theDim, Algo );
2151 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2152 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2154 QString aHypName = dataList[ aHypIndex ]->TypeName;
2156 // get existing algorithms
2157 _PTR(SObject) pObj = SMESH::getStudy()->FindComponent("SMESH");
2159 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2161 // look for an existing algo of such a type
2162 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2163 THypList::iterator anIter = aHypVarList.begin();
2164 for ( ; anIter != aHypVarList.end(); anIter++)
2166 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2167 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2169 anAlgoVar = aHypVar;
2174 if (anAlgoVar->_is_nil())
2176 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2179 QString aClientLibName = aHypData->ClientLibName;
2180 if ( aClientLibName.isEmpty() )
2182 // Call hypothesis creation server method (without GUI)
2183 SMESH::SMESH_Hypothesis_var aHyp =
2184 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2189 // Get hypotheses creator client (GUI)
2190 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2194 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2196 SMESH::SMESH_Hypothesis_var aHyp =
2197 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2202 QStringList tmpList;
2203 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2204 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2207 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2208 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2210 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2211 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2213 anAlgoVar = aHypVar;
2219 return anAlgoVar._retn();
2222 //================================================================================
2224 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2226 * Called when mesh is edited only.
2228 //================================================================================
2229 void SMESHGUI_MeshOp::readMesh()
2231 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2232 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2236 if (myIsOnGeometry) {
2237 // Get name of mesh if current object is sub-mesh
2238 SMESH::SMESH_subMesh_var aSubMeshVar =
2239 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2240 if ( !aSubMeshVar->_is_nil() )
2242 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2243 if ( !aMeshVar->_is_nil() )
2245 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2246 QString aMeshName = name( aMeshSO );
2247 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2249 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2252 // Get name of geometry object
2253 CORBA::String_var name = SMESH::GetGeomName( pObj );
2255 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2258 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2259 QStringList anExisting;
2260 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2261 bool algoFound = false;
2262 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2265 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2266 // find algo index among available ones
2268 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2270 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2271 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( aVar->GetName() ));
2272 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2273 // if ( aHypIndex < 0 && algoData ) {
2274 // // assigned algo is incompatible with other algorithms
2275 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2276 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2278 algoFound = ( aHypIndex > -1 );
2280 setCurrentHyp( dim, Algo, aHypIndex );
2281 // set existing and available hypothesis according to the selected algo
2282 if ( aHypIndex > -1 || !algoFound )
2283 onAlgoSelected( aHypIndex, dim );
2287 bool hypWithoutAlgo = false;
2288 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2290 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2293 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2294 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2295 setCurrentHyp( dim, hypType, -1 );
2297 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2299 // find index of required hypothesis among existing ones for this dimension and type
2300 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2301 myExistingHyps[ dim ][ hypType ] );
2302 if ( aHypIndex < 0 ) {
2303 // assigned hypothesis is incompatible with the algorithm
2304 if ( currentHyp( dim, Algo ) < 0 )
2305 { // none algo selected; it is edition for sure, of submesh maybe
2306 hypWithoutAlgo = true;
2307 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2308 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2309 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2310 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2313 setCurrentHyp( dim, hypType + i, aHypIndex );
2315 if ( hypType == MainHyp ) break; // only one main hyp allowed
2319 // make available other hyps of same type as one without algo
2320 if ( hypWithoutAlgo )
2321 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2324 //================================================================================
2326 * \brief Gets name of object
2327 * \param theSO - SObject
2328 * \retval QString - name of object
2330 * Gets name of object
2332 //================================================================================
2333 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2338 _PTR(GenericAttribute) anAttr;
2339 _PTR(AttributeName) aNameAttr;
2340 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2343 aResName = aNameAttr->Value().c_str();
2349 //================================================================================
2351 * \brief Finds hypothesis in input list
2352 * \param theHyp - hypothesis to be found
2353 * \param theHypList - input list of hypotheses
2354 * \retval int - index of hypothesis or -1 if it is not found
2356 * Finds position of hypothesis in input list
2358 //================================================================================
2359 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2360 const THypList& theHypList ) const
2363 if ( !theHyp->_is_nil() )
2366 THypList::const_iterator anIter = theHypList.begin();
2367 for ( ; anIter != theHypList.end(); ++ anIter)
2369 if ( theHyp->_is_equivalent( (*anIter).first ) )
2380 //================================================================================
2382 * \brief Edits mesh or sub-mesh
2383 * \param theMess - Output parameter intended for returning error message
2384 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2386 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2388 //================================================================================
2389 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2393 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2394 if ( aSMESHGen->_is_nil() )
2397 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2398 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2402 SUIT_OverrideCursor aWaitCursor;
2405 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2406 SMESH::SetName( pObj, aName );
2407 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2409 // First, remove old algos in order to avoid messages on algorithm hiding
2410 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2412 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2414 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2415 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2416 if ( anAlgoVar->_is_nil() || // no new algo selected or
2417 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2419 // remove old algorithm
2420 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2421 myObjHyps[ dim ][ Algo ].clear();
2426 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2427 CORBA::Object_var anObject = aSObject->GetObject();
2428 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2429 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2430 bool isMesh = !aMeshVar->_is_nil();
2431 if ( !isMesh && !aSubMeshVar->_is_nil() )
2432 aMeshVar = aSubMeshVar->GetFather();
2434 // Assign new algorithms and hypotheses
2435 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2437 //if ( !isAccessibleDim( dim )) continue;
2439 // find or create algorithm
2440 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2442 // assign new algorithm
2443 if ( !anAlgoVar->_is_nil() && // some algo selected and
2444 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2447 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2448 else if ( !aSubMeshVar->_is_nil() )
2449 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2451 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2454 // remove deselected hypotheses
2455 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2457 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2459 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2460 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2461 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2463 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2467 // assign newly selected hypotheses
2468 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2470 const int curIndex = currentHyp( dim, dlgType );
2471 const int hypType = Min( dlgType, AddHyp );
2472 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2474 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2476 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2480 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2481 else if ( !aSubMeshVar->_is_nil() )
2482 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2485 // reread all hypotheses of mesh
2486 QStringList anExisting;
2487 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2491 myHasConcurrentSubBefore =
2492 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2497 //================================================================================
2499 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2500 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2501 * order of sub-mesh computation.
2502 * Returns \c true if a sub-mesh concurrency detected.
2504 //================================================================================
2506 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2507 SMESH::SMESH_subMesh_ptr submesh,
2510 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2513 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2514 if ( isNewConcurrent && askUser )
2516 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2517 tr("CONCURRENT_SUBMESH_APPEARS"),
2518 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2521 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2522 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2523 if ( meshSO && aSelectionMgr )
2525 myDlg->setEnabled( false ); // disactivate selection
2526 selectionMgr()->clearFilters();
2527 selectObject( meshSO );
2528 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2529 qApp->processEvents();
2531 myDlg->setEnabled( true );
2532 int obj = myDlg->getActiveObject();
2533 onActivateObject( obj ); // restore filter
2536 selectObject( SMESH::FindSObject( submesh ));
2543 return isNewConcurrent;
2546 //================================================================================
2548 * \brief Verifies whether given operator is valid for this one
2549 * \param theOtherOp - other operation
2550 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2552 * method redefined from base class verifies whether given operator is valid for
2553 * this one (i.e. can be started "above" this operator). In current implementation method
2554 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2557 //================================================================================
2558 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2560 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2563 //================================================================================
2565 * \brief SLOT. Is called when the user selects a way of geometry selection
2566 * \param theByMesh - true if the user wants to find geometry by mesh element
2568 //================================================================================
2569 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2572 if ( !myShapeByMeshOp ) {
2573 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2574 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2575 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2576 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2577 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2579 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2580 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2581 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2582 SMESH::SMESH_Mesh_var aMeshVar =
2583 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2584 if ( !aMeshVar->_is_nil() ) {
2585 myDlg->hide(); // stop processing selection
2586 myShapeByMeshOp->setModule( getSMESHGUI() );
2587 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2588 myShapeByMeshOp->SetMesh( aMeshVar );
2589 myShapeByMeshOp->start();
2595 //================================================================================
2597 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2599 //================================================================================
2600 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2602 if ( myShapeByMeshOp == op ) {
2603 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2605 // Select a found geometry object
2606 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2607 if ( !aGeomVar->_is_nil() )
2609 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2610 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2611 selectObject( aGeomSO );
2618 //================================================================================
2620 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2622 //================================================================================
2623 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2625 if ( myShapeByMeshOp == op && myDlg ) {
2630 //================================================================================
2632 * \brief Selects a SObject
2633 * \param theSObj - the SObject to select
2635 //================================================================================
2636 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2638 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2639 SALOME_ListIO anIOList;
2641 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2642 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2643 anIOList.Append( anIO );
2645 sm->setSelectedObjects( anIOList, false );
2648 //================================================================================
2650 * \brief Create available list types of mesh
2651 * \param theTypeMesh - Output list of available types of mesh
2653 //================================================================================
2654 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2656 theTypeMesh.clear();
2657 theTypeMesh.append( tr( "MT_ANY" ) );
2658 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2660 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2661 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2663 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2665 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2666 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2670 //================================================================================
2672 * \brief Set available types of mesh
2673 * \param theTypeMesh - List of available types of mesh
2675 //================================================================================
2676 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2678 myDlg->setAvailableMeshType( theTypeMesh );
2681 //================================================================================
2683 * \brief SLOT. Is called when the user select type of mesh
2684 * \param theTabIndex - Index of current active tab
2685 * \param theIndex - Index of current type of mesh
2687 //================================================================================
2688 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex )
2690 setFilteredAlgoData( theTabIndex, theIndex);
2693 //================================================================================
2695 * \brief Set a filtered list of available algorithms by mesh type
2696 * \param theTabIndex - Index of current active tab
2697 * \param theIndex - Index of current type of mesh
2699 //================================================================================
2700 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex )
2702 QStringList anAvailableAlgs;
2703 QString anCompareType = currentMeshTypeName( theIndex );
2704 int anCurrentAvailableAlgo = -1;
2706 int aDim = SMESH::DIM_3D;
2707 if ( theIndex == MT_TRIANGULAR || theIndex == MT_QUADRILATERAL)
2708 aDim = SMESH::DIM_2D;
2709 if ( anCompareType == "ANY" )
2711 bool isReqDisBound = false;
2712 int aReqDim = SMESH::DIM_3D;
2713 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2715 anCurrentAvailableAlgo = -1;
2716 isNone = currentHyp( dim, Algo ) < 0;
2717 //return current algo in current tab and set new algorithm list
2718 HypothesisData* algoCur = 0;
2719 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2720 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2722 HypothesisData* prevAlgo = 0;
2723 HypothesisData* nextAlgo = 0;
2724 if ( dim == SMESH::DIM_2D ) {
2725 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2726 if ( aDim == SMESH::DIM_3D )
2727 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2729 // retrieves a list of available algorithms from resources
2730 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCompareType);
2731 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoCur );
2732 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2733 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2734 if ( anCurrentAvailableAlgo > -1 )
2735 isReqDisBound = algoCur->InputTypes.isEmpty();
2736 if ( isReqDisBound ) {
2741 if ( !myIsOnGeometry )
2742 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2743 bool disable = myAvailableHypData[i][Algo].isEmpty();
2744 if ( disable ) myDlg->disableTab( i );
2745 else myDlg->enableTab( i );
2748 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2749 if ( i > myMaxShapeDim || ( isReqDisBound && i < aReqDim ) ) myDlg->disableTab( i );
2750 else myDlg->enableTab( i );
2752 myDlg->setCurrentTab( theTabIndex );
2756 HypothesisData* anCurrentAlgo = 0;
2757 bool isReqDisBound = true;
2758 QString anCurrentCompareType = anCompareType;
2759 isNone = currentHyp( aDim, Algo ) < 0;
2760 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() )
2761 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2762 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2764 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2765 anCurrentAvailableAlgo = -1;
2766 HypothesisData* prevAlgo = 0;
2767 HypothesisData* nextAlgo = 0;
2768 if ( dim == SMESH::DIM_2D ) {
2769 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2770 if ( aDim == SMESH::DIM_3D )
2771 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2773 // finding algorithm which is selected
2775 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2777 // retrieves a list of available algorithms from resources
2778 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType );
2779 // finding and adding algorithm depending on the type mesh
2780 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( anCurrentAlgo );
2781 //set new algorithm list and select the current algorithm
2782 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2783 anCurrentCompareType = ( anCompareType == "HEXA" || anCompareType == "QUAD" ) ? "QUAD" : "TRIA";
2784 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo, /*updateHyps=*/true );
2787 for ( int i = myMaxShapeDim; i >= SMESH::DIM_0D; i-- ) {
2788 bool isNoneAlg = currentHyp( i, Algo ) < 0;
2790 isReqDisBound = myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2792 isReqDisBound = true;
2793 if ( isReqDisBound && !isNoneAlg && i <= aDim) {
2794 for (int j = myMaxShapeDim; j >= SMESH::DIM_0D; j--) {
2795 if ( currentHyp( j, Algo ) < 0 ) {
2796 myDlg->disableTab( j );
2797 setCurrentHyp( j , Algo, -1, /*updateHyps=*/true );
2803 myDlg->enableTab( i );
2806 if ( aDim == SMESH::DIM_2D) {
2807 setCurrentHyp( SMESH::DIM_3D, Algo, -1, /*updateHyps=*/true );
2808 myDlg->disableTab( SMESH::DIM_3D );
2811 int currentTab = ( theTabIndex <= aDim ) ? theTabIndex : aDim;
2812 myDlg->setCurrentTab( currentTab );
2814 THypDataList anAvailableAlgsData;
2815 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2816 QStringList aFilteredHypothesesSetsList;
2817 aFilteredHypothesesSetsList.clear();
2818 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2819 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName ) {
2820 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2821 bool isAvailable = false;
2822 currentHypoSet->init( true );
2823 while ( currentHypoSet->next(), currentHypoSet->more() ) {
2824 isAvailable = false;
2825 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2826 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++) {
2827 int anCurrentAvailableAlgo = myAvailableHypData[i][Algo].indexOf( algoDataIn );
2828 if ( anCurrentAvailableAlgo > -1 ) {
2838 aFilteredHypothesesSetsList.append( *inHypoSetName );
2840 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2843 //================================================================================
2845 * \brief Get current name types of mesh
2846 * \param theIndex - current index types of mesh
2847 * \retval QString - result
2849 //================================================================================
2850 QString SMESHGUI_MeshOp::currentMeshTypeName( const int theIndex ) const
2852 QString aMeshType = "";
2853 switch ( theIndex ) {
2860 case MT_QUADRILATERAL:
2863 case MT_TETRAHEDRAL:
2864 aMeshType = "TETRA";