1 // Copyright (C) 2007-2019 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 ),
95 myIsInvalidSubMesh( false ),
98 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
99 GeometryGUI::InitGeomGen();
100 myIsOnGeometry = true;
104 //================================================================================
108 //================================================================================
109 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
115 //================================================================================
117 * \brief Gets dialog of this operation
118 * \retval LightApp_Dialog* - pointer to dialog of this operation
120 //================================================================================
121 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
126 //================================================================================
128 * \brief Creates or edits mesh
129 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
131 * Virtual slot redefined from the base class called when "Apply" button is clicked
132 * creates or edits mesh
134 //================================================================================
135 bool SMESHGUI_MeshOp::onApply()
137 if (SMESHGUI::isStudyLocked())
141 if ( !isValid( aMess ) )
145 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
149 bool aResult = false;
153 QStringList anEntryList;
154 if ( myToCreate && myIsMesh )
155 aResult = createMesh( aMess, anEntryList );
156 if (( myToCreate && !myIsMesh ) || myIsInvalidSubMesh )
157 aResult = createSubMesh( aMess, anEntryList );
158 else if ( !myToCreate )
159 aResult = editMeshOrSubMesh( aMess );
162 SMESHGUI::Modified();
163 update( UF_ObjBrowser | UF_Model );
164 if( LightApp_Application* anApp =
165 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
166 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
169 catch ( const SALOME::SALOME_Exception& S_ex )
171 SalomeApp_Tools::QtCatchCorbaException( S_ex );
187 aMess = tr( "SMESH_OPERATION_FAILED" );
188 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
194 //================================================================================
196 * \brief Creates dialog if necessary and shows it
198 * Virtual method redefined from base class called when operation is started creates
199 * dialog if necessary and shows it, activates selection
201 //================================================================================
202 void SMESHGUI_MeshOp::startOperation()
204 myIgnoreAlgoSelection = false;
208 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
209 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
211 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
212 this, SLOT( onCreateHyp( const int, const int ) ) );
213 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
214 this, SLOT( onEditHyp( const int, const int ) ) );
215 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
216 this, SLOT( onAlgoSelected( const int ) ) );
218 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
219 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
220 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
222 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
223 else myHelpFileName = "constructing_submeshes.html";
226 myHelpFileName = "editing_meshes.html";
229 SMESHGUI_SelectionOp::startOperation();
230 // iterate through dimensions and get available algorithms, set them to the dialog
231 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
232 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
234 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
236 // clear available hypotheses
237 aTab->setAvailableHyps( MainHyp, hypList );
238 aTab->setAvailableHyps( AddHyp, hypList );
239 aTab->setExistingHyps( MainHyp, hypList );
240 aTab->setExistingHyps( AddHyp, hypList );
241 myExistingHyps[ i ][ MainHyp ].clear();
242 myExistingHyps[ i ][ AddHyp ].clear();
244 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
245 aTab->setAvailableHyps( Algo, hypList );
250 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
254 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
256 myDlg->setCurrentTab( SMESH::DIM_3D );
258 QStringList TypeMeshList;
259 createMeshTypeList( TypeMeshList );
260 setAvailableMeshType( TypeMeshList );
263 myDlg->setGeomPopupEnabled(false);
266 myHasConcurrentSubBefore = false;
268 myObjectToSelect.clear();
271 //=================================================================================
273 * \brief Selects a recently created mesh or sub-mesh if necessary
275 * Virtual method redefined from base class called when operation is committed
276 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
277 * selection when the custom selection filters are removed.
279 //=================================================================================
280 void SMESHGUI_MeshOp::commitOperation()
282 SMESHGUI_SelectionOp::commitOperation();
284 if ( !myObjectToSelect.isEmpty() ) {
285 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
286 SUIT_DataOwnerPtrList aList;
287 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
288 aSelectionMgr->setSelected( aList );
293 //================================================================================
295 * \brief Creates selection filter
296 * \param theId - identifier of current selection widget
297 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
299 * Creates selection filter in accordance with identifier of current selection widget
301 //================================================================================
302 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
304 if ( theId == SMESHGUI_MeshDlg::Geom )
306 // TColStd_MapOfInteger allTypesMap;
307 // for ( int i = 0; i < 10; i++ )
308 // allTypesMap.Add( i );
309 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
310 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
312 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
313 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
314 else if ( theId == SMESHGUI_MeshDlg::Mesh )
315 return new SMESH_TypeFilter( SMESH::MESH );
320 //================================================================================
322 * \brief check if selected shape is a sub-shape of the shape to mesh
323 * \retval bool - check result
325 //================================================================================
326 bool SMESHGUI_MeshOp::isSubshapeOk() const
328 if ( !myToCreate || myIsMesh ) // not submesh creation
332 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
333 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
334 if (!pMesh) return false;
336 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
337 if (mesh->_is_nil()) return false;
339 // main shape of the mesh
340 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
341 if (mainGeom->_is_nil()) return false;
345 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
347 if (aGEOMs.count() > 0) {
348 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
349 if (geomGen->_is_nil()) return false;
351 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
352 if (op->_is_nil()) return false;
354 // check all selected shapes
355 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
356 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
357 QString aSubGeomEntry = (*aSubShapesIter);
358 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
359 if (!pSubGeom) return false;
361 GEOM::GEOM_Object_var aSubGeomVar =
362 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
363 if (aSubGeomVar->_is_nil()) return false;
365 // skl for NPAL14695 - implementation of searching of mainObj
366 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
367 mainObj already exists! */
368 while( !mainObj->_is_nil()) {
369 CORBA::String_var entry1 = mainObj->GetEntry();
370 CORBA::String_var entry2 = mainGeom->GetEntry();
371 if (std::string( entry1.in() ) == entry2.in() )
373 mainObj = op->GetMainShape(mainObj);
375 if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
377 // is aSubGeomVar a compound of sub-shapes?
378 GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
379 if (sop->_is_nil()) return false;
380 GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
381 GEOM::SHAPE,/*sorted=*/false);
382 if ( ids->length() > 0 )
385 GEOM::GEOM_Object_var compSub = geomGen->AddSubShape( aSubGeomVar, ids );
386 if ( !compSub->_is_nil() )
388 GEOM::ListOfGO_var shared = sop->GetSharedShapes( mainGeom,
390 compSub->GetShapeType() );
391 geomGen->RemoveObject( compSub );
392 compSub->UnRegister();
393 if ( shared->length() > 0 ) {
394 geomGen->RemoveObject( shared[0] );
395 shared[0]->UnRegister();
397 return ( shared->length() > 0 );
407 //================================================================================
409 * \brief Return name of the algorithm that does not support sub-meshes and makes
410 * sub-mesh creation useless
411 * \retval char* - string is to be deleted!!!
413 //================================================================================
414 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
416 if ( myToCreate && !myIsMesh ) {
418 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
419 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
420 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
423 QStringList algoNames;
425 existingHyps(3, Algo, pMesh, algoNames, algoList);
426 if (!algoList.empty()) {
427 HypothesisData* algo =
428 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
430 algo->InputTypes.empty() && // builds all dimensions it-self
431 !algo->IsSupportSubmeshes )
432 return CORBA::string_dup( algoNames[0].toUtf8().data() );
435 // GEOM::GEOM_Object_var geom;
436 // if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() ))
437 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
439 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
440 existingHyps(2, Algo, pMesh, algoNames, algoList);
441 if (!algoList.empty()) {
442 HypothesisData* algo =
443 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
445 algo->InputTypes.empty() && // builds all dimensions it-self
446 !algo->IsSupportSubmeshes )
447 return CORBA::string_dup( algoNames[0].toUtf8().data() );
455 //================================================================================
457 * \brief find an existing submesh by the selected shape
458 * \retval _PTR(SObject) - the found submesh SObject
460 //================================================================================
461 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
463 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
464 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
465 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
466 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
467 if ( pMesh && pGeom ) {
468 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
469 if ( !geom->_is_nil() ) {
471 switch ( geom->GetShapeType() ) {
472 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
473 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
474 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
475 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
476 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
477 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
478 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
481 _PTR(GenericAttribute) anAttr;
482 _PTR(SObject) aSubmeshRoot;
483 _PTR(Study) aStudy = SMESH::getStudy();
484 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
486 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
487 for ( ; smIter->More(); smIter->Next() )
489 _PTR(SObject) aSmObj = smIter->Value();
490 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
492 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
493 for ( ; anIter1->More(); anIter1->Next()) {
494 _PTR(SObject) pGeom2 = anIter1->Value();
495 if ( pGeom2->ReferencedObject( pGeom2 ) &&
496 pGeom2->GetID() == pGeom->GetID() )
503 return _PTR(SObject)();
506 //================================================================================
508 * \brief Updates dialog's look and feel
510 * Virtual method redefined from the base class updates dialog's look and feel
512 //================================================================================
513 void SMESHGUI_MeshOp::selectionDone()
515 if (!dlg()->isVisible() || !myDlg->isEnabled())
518 SMESHGUI_SelectionOp::selectionDone();
522 myIsOnGeometry = true;
523 myIsInvalidSubMesh = false;
525 //Check geometry for mesh
526 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
527 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID(anObjEntry.toUtf8().data());
530 SMESH::SMESH_Mesh_var aMeshVar =
531 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
532 if (!aMeshVar->_is_nil()) {
533 if (!myToCreate && !aMeshVar->HasShapeToMesh())
534 myIsOnGeometry = false;
540 // Enable tabs according to shape dimension
545 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
546 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
548 if (aGEOMs.count() > 0) {
549 // one or more GEOM shape selected
550 aSeq->length(aGEOMs.count());
551 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
553 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
554 QString aSubGeomEntry = (*aSubShapesIter);
555 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
558 SALOMEDS_SObject* sobj = _CAST(SObject,pSubGeom);
560 GEOM::GEOM_Object_var aSubGeomVar =
561 GEOM::GEOM_Object::_narrow(sobj->GetObject());
562 if( !aSubGeomVar->_is_nil() ){
563 aSeq[iSubSh] = aSubGeomVar;
569 // get geometry by selected sub-mesh
570 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
571 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
572 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
573 if (!aGeomVar->_is_nil()) {
579 if (aSeq->length() > 0) {
581 for ( CORBA::ULong iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
582 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
583 switch ( aGeomVar->GetShapeType() ) {
584 case GEOM::SOLID: shapeDim = 3; break;
586 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
588 // TopoDS_Shape aShape;
589 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
590 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
593 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
595 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
596 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
600 if (GEOMBase::GetShape(aGeomVar, aShape))
602 TopExp_Explorer exp (aShape, TopAbs_SOLID);
606 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
607 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
610 // for (; exp.More() && shapeDim == 2; exp.Next()) {
611 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
615 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
616 shapeDim = qMax(2, shapeDim);
617 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
618 shapeDim = qMax(1, shapeDim);
619 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
620 shapeDim = qMax(0, shapeDim);
628 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
629 // reset algos before disabling tabs (0020138)
630 onAlgoSelected(-1, i);
632 myDlg->setMaxHypoDim( shapeDim );
633 myMaxShapeDim = shapeDim;
634 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
636 if (!myToCreate) // edition: read hypotheses
640 SMESH::SMESH_subMesh_var submeshVar =
641 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
642 myIsMesh = submeshVar->_is_nil();
643 myIsInvalidSubMesh = ( !myIsMesh && submeshVar->GetId() < 1 );
644 myDlg->setTitile( myToCreate, myIsMesh );
645 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
646 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
647 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
648 if ( myIsInvalidSubMesh )
650 // it is necessary to select a new geometry
651 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->show();
652 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
656 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
658 myDlg->updateGeometry();
665 else if ( !myIsMesh ) // submesh creation
667 // if a submesh on the selected shape already exist, pass to submesh edition mode
668 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
669 SMESH::SMESH_subMesh_var sm =
670 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
671 bool editSubmesh = ( !sm->_is_nil() &&
672 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
673 tr( "EDIT_SUBMESH_QUESTION"),
674 SUIT_MessageBox::Yes |
676 SUIT_MessageBox::No )
677 == SUIT_MessageBox::Yes );
680 selectionMgr()->clearFilters();
681 selectObject( pSubmesh );
682 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
687 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
688 selectObject( _PTR(SObject)() );
693 // discard selected mesh if submesh creation not allowed because of
694 // a global algorithm that does not support submeshes
695 if ( char* algoName = isSubmeshIgnored() ) {
696 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
697 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
698 CORBA::string_free( algoName );
699 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
700 selectObject( _PTR(SObject)() );
705 // enable/disable popup for choice of geom selection way
707 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
708 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
709 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
710 if ( !mesh->_is_nil() ) {
711 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
712 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
713 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
714 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
715 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
716 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
719 myDlg->setGeomPopupEnabled( enable );
722 else { // no geometry defined
725 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
727 availableHyps( dim, Algo, hypList, myAvailableHypData[dim][Algo]);
728 myDlg->tab( dim )->setAvailableHyps( Algo, hypList );
729 if ( hypList.empty() ) myDlg->disableTab( dim );
730 else myDlg->enableTab( dim );
733 //Hide labels and fields (Mesh and Geometry)
734 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
735 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
739 int curIndex = myDlg->currentMeshType( );
740 QStringList TypeMeshList;
741 createMeshTypeList( TypeMeshList );
742 setAvailableMeshType( TypeMeshList );
743 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
744 myDlg->setCurrentMeshType( curIndex );
745 setFilteredAlgoData( myMaxShapeDim, curIndex);
747 catch ( const SALOME::SALOME_Exception& S_ex )
749 SalomeApp_Tools::QtCatchCorbaException( S_ex );
756 //================================================================================
758 * \brief Verifies validity of input data
759 * \param theMess - Output parameter intended for returning error message
760 * \retval bool - TRUE if input data is valid, false otherwise
762 * Verifies validity of input data. This method is called when "Apply" or "OK" button
763 * is pressed before mesh creation or editing.
765 //================================================================================
766 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
768 // Selected object to be edited
769 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
771 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
776 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
777 if ( aMeshName.isEmpty() )
779 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
783 /* // Imported mesh, if create sub-mesh or edit mesh
784 if ( !myToCreate || ( myToCreate && !myIsMesh ))
786 QString aMeshEntry = myDlg->selectedObject
787 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
788 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
789 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
790 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
791 theMess = tr( "IMPORTED_MESH" );
800 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
801 if ( aGeomEntry.isEmpty() )
803 theMess = tr( myIsMesh ?
804 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
805 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
809 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
810 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
817 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
818 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
820 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
825 if ( !myIsMesh ) // i.e sub-mesh creation,
827 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
828 if ( aMeshEntry == "" )
830 theMess = tr( "MESH_IS_NOT_DEFINED" );
833 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
834 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
836 theMess = tr( "MESH_IS_NULL" );
839 if ( !isSubshapeOk() )
841 theMess = tr( "INVALID_SUBSHAPE" );
850 //================================================================================
852 * \brief check compatibility of the algorithm and another algorithm or hypothesis
853 * \param theAlgoData - algorithm data
854 * \param theHypData - hypothesis data
855 * \param theHypType - hypothesis type
856 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
857 * \retval bool - check result
859 //================================================================================
860 static bool isCompatible(const HypothesisData* theAlgoData,
861 const HypothesisData* theHypData,
862 const int theHypType)
867 if ( theHypType == SMESHGUI_MeshOp::Algo )
868 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
871 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
874 //================================================================================
876 * \brief check compatibility of the geometry
877 * \param theAlgoData - to select hypos able to be used by this algo
878 * \param theCurrentGeomToSelect - the current name of the selected geometry
879 * \param theGeomVar - currently selected geometry
880 * \retval bool - check result
882 //================================================================================
883 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
884 QString theCurrentGeomToSelect,
885 GEOM::GEOM_Object_var theGeomVar)
887 if ( theGeomVar->_is_nil() )
890 bool isApplicable = false;
891 if ( theCurrentGeomToSelect == myLastGeomToSelect && !theCurrentGeomToSelect.isEmpty() ) {
892 THypLabelIsAppMap::const_iterator iter = myHypMapIsApplicable.find( theAlgoData->Label );
893 if ( iter != myHypMapIsApplicable.end() && iter.key() == theAlgoData->Label ) {
894 isApplicable = iter.value();
898 bool toCheckIsApplicableToAll = !myIsMesh;
899 if ( toCheckIsApplicableToAll )
900 toCheckIsApplicableToAll = ( theGeomVar->GetType() == GEOM_GROUP );
901 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, theGeomVar, toCheckIsApplicableToAll );
902 myHypMapIsApplicable.insert( theAlgoData->Label, isApplicable );
906 //================================================================================
908 * \brief check compatibility of the mesh type
909 * \param theAlgoData - to select hypos able to be used by this algo
910 * \param theMeshType - type of mesh for filtering algorithms
911 * \retval bool - check result
913 //================================================================================
914 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
917 bool isAvailableAlgo = ( theAlgoData->OutputTypes.count() == 0 );
918 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
919 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ ) {
920 if ( *inElemType == theMeshType ) {
921 isAvailableAlgo = true;
925 return isAvailableAlgo;
928 //================================================================================
930 * \brief Gets available hypotheses or algorithms
931 * \param theDim - specifies dimension of returned hypotheses/algorifms
932 * \param theHypType - specifies whether algorims or hypotheses or additional ones
933 * are retrieved (possible values are in HypType enumeration)
934 * \param theHyps - Output list of hypotheses' names
935 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
936 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
937 * \param theMeshType - type of mesh for filtering algorithms (optional)
939 * Gets available hypotheses or algorithm in accordance with input parameters
941 //================================================================================
942 void SMESHGUI_MeshOp::availableHyps( const int theDim,
943 const int theHypType,
944 QStringList& theHyps,
945 THypDataList& theDataList,
946 HypothesisData* thePrevAlgoData,
947 HypothesisData* theNextAlgoData,
948 const QString& theMeshType)
952 bool isAlgo = ( theHypType == Algo );
953 bool isAux = ( theHypType >= AddHyp );
954 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
956 GEOM::GEOM_Object_var aGeomVar;
957 QString aCurrentGeomToSelect;
958 if ( !theMeshType.isEmpty() ) {
959 aCurrentGeomToSelect = myDlg->selectedObject( myToCreate ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Obj );
960 if ( _PTR(SObject) so = SMESH::getStudy()->FindObjectID( aCurrentGeomToSelect.toUtf8().data() )) {
961 aGeomVar = SMESH::GetGeom( so );
963 if ( aCurrentGeomToSelect != myLastGeomToSelect )
964 myHypMapIsApplicable.clear();
967 std::multimap< double, HypothesisData* > sortedHyps;
968 QStringList::const_iterator anIter;
969 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
971 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
972 if ( ( isCompatible ( thePrevAlgoData, aData, theHypType ) &&
973 isCompatible ( theNextAlgoData, aData, theHypType ) ) ||
974 ( theMeshType == "ANY" && aData->InputTypes.isEmpty()))
976 if ( ( !theMeshType.isEmpty() ) &&
977 ( theDim >= SMESH::DIM_2D ) &&
978 ( ( theMeshType != "ANY" && !isCompatibleToMeshType( aData, theMeshType )) ||
979 !isCompatibleToGeometry( aData, aCurrentGeomToSelect, aGeomVar )))
982 int groupID = aData->GroupID;
983 int priority = aData->Priority;
984 if ( groupID < 0 || groupID > 9 ) groupID = 9;
985 if ( priority < 0 || priority > 999 ) priority = 999;
987 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
991 if ( !sortedHyps.empty() )
993 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
994 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
995 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
997 HypothesisData* aData = key_hyp->second;
998 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
999 if ( aPrevGroup != aGroup )
1001 theDataList.append( aGroup );
1002 theHyps.append( aGroup->Label );
1003 aPrevGroup = aGroup;
1005 theDataList.append( aData );
1006 theHyps.append( aData->Label );
1010 if ( !theMeshType.isEmpty() && !aCurrentGeomToSelect.isEmpty() )
1011 myLastGeomToSelect = aCurrentGeomToSelect;
1014 //================================================================================
1016 * \brief Gets existing hypotheses or algorithms
1017 * \param theDim - specifies dimension of returned hypotheses/algorifms
1018 * \param theHypType - specifies whether algorims or hypotheses or additional ones
1019 * are retrieved (possible values are in HypType enumeration)
1020 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
1021 * \param theHyps - output list of names.
1022 * \param theHypVars - output list of variables.
1023 * \param theAlgoData - to select hypos able to be used by this algo (optional)
1025 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
1028 * WARNING: when using this method to get hyps existing in Mesh component,
1029 * call availableHyps() before in order to get only hyps of available types
1030 * that was filtered by availableHyps()
1032 //================================================================================
1033 void SMESHGUI_MeshOp::existingHyps( const int theDim,
1034 const int theHypType,
1035 _PTR(SObject) theFather,
1036 QStringList& theHyps,
1037 THypList& theHypList,
1038 HypothesisData* theAlgoData) const
1040 // Clear hypoheses list
1047 _PTR(SObject) aHypRoot;
1048 _PTR(GenericAttribute) anAttr;
1049 _PTR(AttributeName) aName;
1050 _PTR(AttributeIOR) anIOR;
1052 const bool isMesh = !_CAST( SComponent, theFather );
1055 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
1057 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
1059 const bool isAux = ( theHypType >= AddHyp );
1060 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
1062 if ( theFather->FindSubObject( aPart, aHypRoot ) )
1064 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypRoot );
1065 for ( ; anIter->More(); anIter->Next() )
1067 _PTR(SObject) anObj = anIter->Value();
1068 if ( isMesh ) // i.e. mesh or submesh
1070 _PTR(SObject) aRefObj;
1071 if ( anObj->ReferencedObject( aRefObj ) )
1076 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1079 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1080 if ( !CORBA::is_nil( aVar ) )
1082 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
1083 if ( !aHypVar->_is_nil() )
1085 CORBA::String_var hypType = aHypVar->GetName();
1086 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
1087 if ( !aData) continue;
1088 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
1089 ( isCompatible ( theAlgoData, aData, theHypType )) &&
1090 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
1091 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
1093 std::string aHypName = aName->Value();
1094 theHyps.append( aHypName.c_str() );
1095 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
1104 //================================================================================
1106 * \brief If create or edit a submesh, return a hypothesis holding parameters used
1107 * to mesh a sub-shape
1108 * \param aHypType - The hypothesis type name
1109 * \param aServerLib - Server library name
1110 * \param hypData - The structure holding the hypothesis type etc.
1111 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
1113 //================================================================================
1114 SMESH::SMESH_Hypothesis_var
1115 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1116 const QString& aServerLib ) const
1118 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1119 return SMESH::SMESH_Hypothesis::_nil();
1121 const int nbColonsInMeshEntry = 3;
1122 bool isSubMesh = myToCreate ?
1124 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1126 // get mesh and geom object
1127 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
1128 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1133 anEntry = myDlg->selectedObject
1134 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1135 if ( _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1137 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1138 if ( myToCreate ) // mesh and geom may be selected
1140 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
1141 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1142 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1143 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1145 else // edition: sub-mesh may be selected
1147 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1148 if ( !sm->_is_nil() ) {
1149 aMeshVar = sm->GetFather();
1150 aGeomVar = sm->GetSubShape();
1157 if ( !myToCreate ) // mesh to edit can be selected
1159 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1160 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1162 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1163 if ( !aMeshVar->_is_nil() )
1164 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1167 if ( aGeomVar->_is_nil() ) {
1168 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1169 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1171 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1176 SMESH::SMESH_Hypothesis_var hyp =
1177 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1178 aServerLib.toUtf8().data(),
1181 /*byMesh = */isSubMesh);
1182 if ( hyp->_is_nil() && isSubMesh )
1183 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1184 aServerLib.toUtf8().data(),
1187 /*byMesh = */false);
1191 //================================================================================
1193 * \brief initialize a hypothesis creator
1195 //================================================================================
1197 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1199 if ( !theCreator ) return;
1201 // Set shapes, of mesh and sub-mesh if any
1203 // get Entry of the Geom object
1204 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1205 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1206 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1208 if ( myToCreate && myIsMesh )
1209 aMeshEntry = aGeomEntry;
1211 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1212 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1213 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1214 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1217 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1218 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1220 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1221 if ( !aGeomVar->_is_nil() )
1223 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1225 aMeshEntry = aGeomEntry;
1229 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1230 // take geometry from submesh being created
1231 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1233 // if current object is sub-mesh
1234 SMESH::SMESH_subMesh_var aSubMeshVar =
1235 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1236 if ( !aSubMeshVar->_is_nil() ) {
1237 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1238 if ( !aMeshVar->_is_nil() ) {
1239 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1240 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1241 if ( !aGeomVar->_is_nil() )
1242 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1248 theCreator->setShapeEntry( aGeomEntry );
1249 if ( aMeshEntry != "" )
1250 theCreator->setMainShapeEntry( aMeshEntry );
1252 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1255 //================================================================================
1257 * \Brief Returns tab dimension
1258 * \param tab - the tab in the dlg
1259 * \param dlg - my dialogue
1260 * \retval int - dimension
1262 //================================================================================
1263 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1266 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1267 if (tab == dlg->tab(i))
1272 //================================================================================
1274 * \brief Create hypothesis
1275 * \param theHypType - hypothesis category (main or additional)
1276 * \param theIndex - index of type of hypothesis to be created
1278 * Specifies dimension of hypothesis to be created (using sender() method),
1279 * specifies its type and calls method for hypothesis creation
1281 //================================================================================
1282 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1284 // Specifies dimension of hypothesis to be created
1285 int aDim = getTabDim( sender(), myDlg );
1289 // Specifies type of hypothesis to be created
1290 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1291 if (theIndex < 0 || theIndex >= dataList.count())
1293 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1295 // Create hypothesis
1296 createHypothesis(aDim, theHypType, aHypTypeName);
1301 QString GetUniqueName (const QStringList& theHypNames,
1302 const QString& theName,
1303 size_t theIteration = 1)
1305 QString aName = theName + "_" + QString::number( theIteration );
1306 if ( theHypNames.contains( aName ) )
1307 return GetUniqueName( theHypNames, theName, ++theIteration );
1312 //================================================================================
1314 * Create hypothesis and update dialog.
1315 * \param theDim - dimension of hypothesis to be created
1316 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1317 * \param theTypeName - specifies hypothesis to be created
1319 //================================================================================
1320 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1322 const QString& theTypeName)
1324 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1331 // get a unique hyp name
1332 QStringList aHypNames;
1333 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1334 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1335 const TType2HypList& aType2HypList = aDimIter.value();
1336 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1337 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1338 const THypList& aHypList = aTypeIter.value();
1339 THypList::const_iterator anIter = aHypList.begin();
1340 for ( ; anIter != aHypList.end(); anIter++) {
1341 const THypItem& aHypItem = *anIter;
1342 const QString& aHypName = aHypItem.second;
1343 aHypNames.append(aHypName);
1347 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1350 bool dialog = false;
1352 QString aClientLibName = aData->ClientLibName;
1353 if (aClientLibName == "") {
1354 // Call hypothesis creation server method (without GUI)
1355 SMESH::SMESH_Hypothesis_var aHyp =
1356 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1360 // Get hypotheses creator client (GUI)
1361 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1363 // Create hypothesis
1366 // Get parameters appropriate to initialize a new hypothesis
1367 SMESH::SMESH_Hypothesis_var initParamHyp =
1368 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1370 removeCustomFilters(); // Issue 0020170
1372 // set shapes, of mesh and sub-mesh if any
1373 initHypCreator( aCreator );
1375 myDlg->setEnabled( false );
1376 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1381 SMESH::SMESH_Hypothesis_var aHyp =
1382 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1391 //================================================================================
1393 * Necessary steps after hypothesis creation
1394 * \param result - creation result:
1397 * 2 = additional value meaning that slot is called not from dialog box
1399 //================================================================================
1400 void SMESHGUI_MeshOp::onHypoCreated( int result )
1404 int obj = myDlg->getActiveObject();
1405 onActivateObject( obj ); // Issue 0020170. Restore filters
1406 myDlg->setEnabled( true );
1409 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1411 int nbHyp = myExistingHyps[myDim][myType].count();
1412 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1413 QStringList aNewHyps;
1414 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1415 if (aNewHyps.count() > nbHyp)
1417 for (int i = nbHyp; i < aNewHyps.count(); i++)
1418 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1421 if( result!=2 && myHypoSet )
1425 //================================================================================
1427 * \brief Calls plugin methods for hypothesis editing
1428 * \param theHypType - specifies whether main hypothesis or additional one
1430 * \param theIndex - index of existing hypothesis
1432 * Calls plugin methods for hypothesis editing
1434 //================================================================================
1435 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1437 // Speicfies dimension of hypothesis to be created
1438 int aDim = getTabDim( sender(), myDlg );
1442 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1443 if ( theIndex < 0 || theIndex >= aList.count() )
1445 const THypItem& aHypItem = aList[ theIndex ];
1446 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1447 if ( aHyp->_is_nil() )
1450 SMESHGUI_GenericHypothesisCreator* aCreator =
1451 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1454 // set initial parameters
1455 SMESH::SMESH_Hypothesis_var initParamHyp =
1456 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1457 SMESH::toQStr( aHyp->GetLibName() ));
1458 aCreator->setInitParamsHypothesis( initParamHyp );
1460 // set shapes, of mesh and sub-mesh if any
1461 initHypCreator( aCreator );
1463 removeCustomFilters(); // Issue 0020170
1464 myDlg->setEnabled( false );
1466 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1470 //================================================================================
1472 * Necessary steps after hypothesis edition
1473 * \param result - creation result:
1477 //================================================================================
1478 void SMESHGUI_MeshOp::onHypoEdited( int result )
1480 int obj = myDlg->getActiveObject();
1481 onActivateObject( obj ); // Issue 0020170. Restore filters
1482 myDlg->setEnabled( true );
1485 //================================================================================
1487 * \brief access to hypothesis data
1488 * \param theDim - hyp dimension
1489 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1490 * \param theIndex - index in the list
1491 * \retval HypothesisData* - result data, may be 0
1493 //================================================================================
1494 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1495 const int theHypType,
1498 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1499 theHypType > -1 && theHypType < NbHypTypes &&
1500 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1501 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1505 //================================================================================
1507 * \brief Set available algos and hypos according to the selected algorithm
1508 * \param theIndex - algorithm index
1510 //================================================================================
1511 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1514 if ( myIgnoreAlgoSelection )
1517 int curDim = getTabDim( sender(), myDlg );
1518 int aDim = theDim < 0 ? curDim : theDim;
1522 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1524 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1525 HypothesisData* algoByDim[4];
1526 algoByDim[ aDim ] = algoData;
1528 QStringList anAvailable;
1530 // enable / disable tabs
1531 if ( myIsOnGeometry ) {
1532 for (int i = SMESH::DIM_3D; i >= SMESH::DIM_0D; i--) {
1534 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
1535 else myDlg->enableTab( i );
1537 else if ( i == aDim ) {
1540 else {//( i < aDim )
1541 if ( algoData && algoData->InputTypes.isEmpty() ) {
1542 myDlg->disableTab( i );
1543 for ( int type = Algo, nbTypes = nbDlgHypTypes(i); type < nbTypes; type++ )
1544 setCurrentHyp(i, type, -1);
1547 myDlg->enableTab( i );
1554 HypothesisData* a3DAlgo = 0;
1555 // 2 loops: backward and forward from algo dimension
1556 for ( int forward = 0; forward <= 1; ++forward )
1558 int dim = algoDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1560 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1562 HypothesisData* prevAlgo = algoData;
1563 bool noCompatible = false;
1564 for ( ; dim * dir <= lastDim * dir; dim += dir)
1566 if ( !isAccessibleDim( dim ))
1568 if ( noCompatible ) { // the selected algo has no compatible ones
1569 anAvailable.clear();
1570 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1571 myAvailableHypData[dim][Algo].clear();
1572 algoByDim[ dim ] = 0;
1575 HypothesisData* nextAlgo = 0;
1576 if ( myMaxShapeDim == SMESH::DIM_3D && a3DAlgo && dim == SMESH::DIM_2D ) {
1579 // get currently selected algo
1580 int algoIndex = currentHyp( dim, Algo );
1581 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1583 QString anCompareType = currentMeshTypeName(myDlg->currentMeshType());
1584 QString anCurrentCompareType = "";
1585 if ( dim == SMESH::DIM_3D || anCompareType == "ANY" )
1586 anCurrentCompareType = anCompareType;
1587 else if ( dim == SMESH::DIM_2D ) {
1588 anCurrentCompareType = (anCompareType == "HEXA" || anCompareType == "QUAD") ? "QUAD" : "TRIA";
1592 // set new available algorithms
1593 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType);
1594 HypothesisData* soleCompatible = 0;
1595 if ( anAvailable.count() == 1 )
1596 soleCompatible = myAvailableHypData[dim][Algo][0];
1597 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1598 noCompatible = anAvailable.isEmpty();
1599 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1600 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim == curDim ) {
1601 // select the sole compatible algo
1604 setCurrentHyp( dim, Algo, algoIndex );
1606 // remember current algo
1607 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1611 if ( myMaxShapeDim == SMESH::DIM_3D && forward && algoDim == SMESH::DIM_1D )
1613 algoDim = SMESH::DIM_3D;
1618 } // loops backward and forward
1621 // set hypotheses corresponding to the found algorithms
1623 _PTR(SObject) pObj = SMESH::getStudy()->FindComponent("SMESH");
1625 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1627 if ( !isAccessibleDim( dim ))
1630 // get indices of selected hyps
1631 const int nbTypes = nbDlgHypTypes(dim);
1632 std::vector<int> hypIndexByType( nbTypes, -1 );
1633 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1635 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1639 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1641 const int type = Min( dlgType, AddHyp );
1642 myAvailableHypData[ dim ][ type ].clear();
1643 QStringList anAvailable, anExisting;
1645 HypothesisData* curAlgo = algoByDim[ dim ];
1646 int hypIndex = hypIndexByType[ dlgType ];
1648 SMESH::SMESH_Hypothesis_var curHyp;
1649 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1650 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1652 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1653 // try to find algo by selected hypothesis in order to keep it selected
1654 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1655 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1656 if ( !algoDeselectedByUser &&
1657 myObjHyps[ dim ][ type ].count() > 0 &&
1658 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1660 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1661 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1662 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1663 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1670 // get hyps compatible with curAlgo
1671 bool defaulHypAvlbl = false;
1674 // check if a selected hyp is compatible with the curAlgo
1675 if ( !curHyp->_is_nil() ) {
1676 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1677 if ( !isCompatible( curAlgo, hypData, type ))
1678 curHyp = SMESH::SMESH_Hypothesis::_nil();
1680 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1681 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1682 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1684 // set list of hypotheses
1685 if ( dlgType <= AddHyp )
1687 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1688 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1690 // set current existing hypothesis
1691 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1692 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1695 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1697 // none is yet selected => select the sole existing if it is not optional
1698 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1699 bool isOptional = true;
1700 if ( algoByDim[ dim ] &&
1701 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1705 setCurrentHyp( dim, dlgType, hypIndex );
1710 //================================================================================
1712 * \brief Creates and selects hypothesis of hypotheses set
1713 * \param theSetName - The name of hypotheses set
1715 //================================================================================
1716 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1718 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1723 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1724 setCurrentHyp(dim, Algo, -1);
1725 setCurrentHyp(dim, AddHyp, -1);
1726 setCurrentHyp(dim, MainHyp, -1);
1729 myHypoSet->init(true); //algorithms
1731 myHypoSet->init(false); //hypotheses
1736 //================================================================================
1738 * \brief One step of hypothesis/algorithm list creation
1740 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1742 //================================================================================
1743 void SMESHGUI_MeshOp::processSet()
1746 if( !myHypoSet->more() )
1749 bool isAlgo = myHypoSet->isAlgo();
1750 QString aHypoTypeName = myHypoSet->current();
1751 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1758 int aDim = aHypData->Dim[0];
1759 // create or/and set
1762 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1765 QStringList anAvailable;
1766 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1767 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1768 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1770 setCurrentHyp( aDim, Algo, index );
1771 onAlgoSelected( index, aDim );
1776 bool mainHyp = true;
1777 QStringList anAvailable;
1778 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1779 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1780 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1784 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1787 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1793 //================================================================================
1795 * \brief Creates mesh
1796 * \param theMess - Output parameter intended for returning error message
1797 * \param theEntryList - List of entries of published objects
1798 * \retval bool - TRUE if mesh is created, FALSE otherwise
1802 //================================================================================
1803 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1808 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1809 if ( aList.isEmpty() )
1811 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1812 if ( aSMESHGen->_is_nil() )
1815 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1816 if ( aMeshVar->_is_nil() )
1819 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1821 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1822 theEntryList.append( aMeshSO->GetID().c_str() );
1827 if ( aList.count() > 1 )
1829 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1830 int i = namePrefix.length() - 1;
1831 while ( i > 0 && namePrefix[i].isDigit() )
1833 if ( i < namePrefix.length() - 1 )
1834 namePrefix.chop( namePrefix.length() - 1 - i );
1838 QStringList::Iterator it = aList.begin();
1839 for ( int i = 0; it!=aList.end(); it++, ++i )
1841 QString aGeomEntry = *it;
1842 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
1843 GEOM::GEOM_Object_var aGeomVar =
1844 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1846 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1847 if ( aSMESHGen->_is_nil() )
1850 SUIT_OverrideCursor aWaitCursor;
1853 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1854 if ( aMeshVar->_is_nil() )
1856 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1858 theEntryList.append( aMeshSO->GetID().c_str() );
1859 if ( i > 0 ) setDefaultName( namePrefix );
1860 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1863 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1865 if ( !isAccessibleDim( aDim )) continue;
1867 // assign hypotheses
1868 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1870 const int aHypIndex = currentHyp( aDim, dlgType );
1871 const int aHypType = Min( dlgType, AddHyp );
1872 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1874 SMESH::SMESH_Hypothesis_var aHypVar =
1875 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1876 if ( !aHypVar->_is_nil() )
1877 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1880 // find or create algorithm
1881 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1882 if ( !anAlgoVar->_is_nil() )
1883 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1889 //================================================================================
1891 * \brief Creates sub-mesh
1892 * \param theMess - Output parameter intended for returning error message
1893 * \param theEntryList - List of entries of published objects
1894 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1898 //================================================================================
1899 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1903 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1904 if ( aSMESHGen->_is_nil() )
1908 SMESH::SMESH_Mesh_var aMeshVar =
1909 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
1910 if ( aMeshVar->_is_nil() && myIsInvalidSubMesh )
1912 SMESH::SMESH_subMesh_var aSMVar =
1913 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
1914 if ( !aSMVar->_is_nil() )
1915 aMeshVar = aSMVar->GetMesh();
1917 if ( aMeshVar->_is_nil() )
1920 // GEOM shape of the main mesh
1921 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1923 // Name for the new sub-mesh
1924 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1927 GEOM::GEOM_Object_var aGeomVar;
1929 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1930 if (aGEOMs.count() == 1)
1932 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1933 QString aGeomEntry = aGEOMs.first();
1934 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
1935 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1937 else if (aGEOMs.count() > 1)
1939 // create a GEOM group
1940 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1941 if (!geomGen->_is_nil()) {
1942 GEOM::GEOM_IGroupOperations_wrap op =
1943 geomGen->GetIGroupOperations();
1944 if (!op->_is_nil()) {
1945 // check and add all selected GEOM objects: they must be
1946 // a sub-shapes of the main GEOM and must be of one type
1948 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1949 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1950 aSeq->length(aGEOMs.count());
1951 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1952 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1953 QString aSubGeomEntry = (*aSubShapesIter);
1954 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
1955 GEOM::GEOM_Object_var aSubGeomVar =
1956 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1957 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1959 aGroupType = aSubShapeType;
1961 if (aSubShapeType != aGroupType)
1962 aGroupType = TopAbs_SHAPE;
1964 aSeq[iSubSh] = aSubGeomVar;
1967 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1968 op->UnionList(aGroupVar, aSeq);
1972 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1974 // publish the GEOM group in study
1975 QString aNewGeomGroupName ("Auto_group_for_");
1976 aNewGeomGroupName += aName;
1977 SALOMEDS::SObject_wrap aNewGroupSO =
1978 geomGen->AddInStudy( aGeomVar,
1979 aNewGeomGroupName.toUtf8().data(), mainGeom);
1986 if (aGeomVar->_is_nil())
1989 SUIT_OverrideCursor aWaitCursor;
1991 QString aNameOrID = aName;
1992 if ( myIsInvalidSubMesh )
1993 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
1994 // by a valid one in an existing SO
1995 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
1998 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aNameOrID.toUtf8().data() );
1999 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2001 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
2002 theEntryList.append( aSubMeshSO->GetID().c_str() );
2005 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2007 if ( !isAccessibleDim( aDim )) continue;
2009 // find or create algorithm
2010 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2011 if ( !anAlgoVar->_is_nil() )
2012 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2013 // assign hypotheses
2014 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2016 const int aHypIndex = currentHyp( aDim, dlgType );
2017 const int aHypType = Min( dlgType, AddHyp );
2018 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2020 SMESH::SMESH_Hypothesis_var aHypVar =
2021 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2022 if ( !aHypVar->_is_nil() )
2023 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2028 // deselect geometry: next submesh should be created on other sub-shape
2029 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2030 selectObject( _PTR(SObject)() );
2033 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
2038 //================================================================================
2040 * \brief Gets current hypothesis or algorithms
2041 * \param theDim - dimension of hypothesis or algorithm
2042 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2043 * \retval int - current hypothesis or algorithms
2045 * Gets current hypothesis or algorithms
2047 //================================================================================
2048 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2050 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2053 //================================================================================
2055 * \brief Checks if a hypothesis is selected
2057 //================================================================================
2059 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2064 if ( theHypType < AddHyp ) // only one hyp can be selected
2065 return currentHyp( theDim, theHypType ) == theIndex;
2067 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2068 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2074 //================================================================================
2076 * \brief Returns nb of HypType's taking into account possible several
2077 * selected additional hypotheses which are coded as additional HypType's.
2079 //================================================================================
2081 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2083 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2086 //================================================================================
2088 * \brief Returns true if hypotheses of given dim can be assigned
2089 * \param theDim - hypotheses dimension
2090 * \retval bool - result
2092 //================================================================================
2093 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2095 return myDlg->isTabEnabled( theDim );
2098 //================================================================================
2100 * \brief Sets current hypothesis or algorithms
2101 * \param theDim - dimension of hypothesis or algorithm
2102 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2103 * \param theIndex - Index of hypothesis
2104 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2106 * Gets current hypothesis or algorithms
2108 //================================================================================
2109 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2110 const int theHypType,
2112 const bool updateHypsOnAlgoDeselection)
2114 myIgnoreAlgoSelection = true;
2115 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2116 myIgnoreAlgoSelection = false;
2118 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2120 const QStringList noHyps;
2121 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2122 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2123 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2124 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2128 //================================================================================
2130 * \brief Generates default and sets mesh/submesh name
2132 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2134 //================================================================================
2135 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2139 _PTR(Study) aStudy = SMESH::getStudy();
2142 QString aPrefix = thePrefix;
2143 if ( aPrefix.isEmpty() )
2144 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2146 _PTR(SObject) anObj;
2149 aResName = aPrefix + QString::number( i++ );
2150 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2154 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2155 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2156 aControl->setText( aResName );
2159 //================================================================================
2161 * \brief Gets algorithm or creates it if necessary
2162 * \param theDim - specifies dimension of returned hypotheses/algorifms
2163 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2165 * Gets algorithm or creates it if necessary
2167 //================================================================================
2168 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2170 SMESH::SMESH_Hypothesis_var anAlgoVar;
2172 // get type of the selected algo
2173 int aHypIndex = currentHyp( theDim, Algo );
2174 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2175 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2177 QString aHypName = dataList[ aHypIndex ]->TypeName;
2179 // get existing algorithms
2180 _PTR(SObject) pObj = SMESH::getStudy()->FindComponent("SMESH");
2182 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2184 // look for an existing algo of such a type
2185 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2186 THypList::iterator anIter = aHypVarList.begin();
2187 for ( ; anIter != aHypVarList.end(); anIter++)
2189 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2190 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2192 anAlgoVar = aHypVar;
2197 if (anAlgoVar->_is_nil())
2199 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2202 QString aClientLibName = aHypData->ClientLibName;
2203 if ( aClientLibName.isEmpty() )
2205 // Call hypothesis creation server method (without GUI)
2206 SMESH::SMESH_Hypothesis_var aHyp =
2207 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2212 // Get hypotheses creator client (GUI)
2213 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2217 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2219 SMESH::SMESH_Hypothesis_var aHyp =
2220 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2225 QStringList tmpList;
2226 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2227 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2230 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2231 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2233 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2234 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2236 anAlgoVar = aHypVar;
2242 return anAlgoVar._retn();
2245 //================================================================================
2247 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2249 * Called when mesh is edited only.
2251 //================================================================================
2252 void SMESHGUI_MeshOp::readMesh()
2254 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2255 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2259 if (myIsOnGeometry) {
2260 // Get name of mesh if current object is sub-mesh
2261 SMESH::SMESH_subMesh_var aSubMeshVar =
2262 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2263 if ( !aSubMeshVar->_is_nil() )
2265 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2266 if ( !aMeshVar->_is_nil() )
2268 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2269 QString aMeshName = name( aMeshSO );
2270 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2272 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2275 if ( !myIsInvalidSubMesh )
2277 // Get name of geometry object
2278 CORBA::String_var name = SMESH::GetGeomName( pObj );
2280 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2284 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2285 QStringList anExisting;
2286 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2287 bool algoFound = false;
2288 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2291 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2292 // find algo index among available ones
2294 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2296 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2297 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( aVar->GetName() ));
2298 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2299 // if ( aHypIndex < 0 && algoData ) {
2300 // // assigned algo is incompatible with other algorithms
2301 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2302 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2304 algoFound = ( aHypIndex > -1 );
2306 setCurrentHyp( dim, Algo, aHypIndex );
2307 // set existing and available hypothesis according to the selected algo
2308 if ( aHypIndex > -1 || !algoFound )
2309 onAlgoSelected( aHypIndex, dim );
2313 bool hypWithoutAlgo = false;
2314 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2316 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2319 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2320 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2321 setCurrentHyp( dim, hypType, -1 );
2323 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2325 // find index of required hypothesis among existing ones for this dimension and type
2326 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2327 myExistingHyps[ dim ][ hypType ] );
2328 if ( aHypIndex < 0 ) {
2329 // assigned hypothesis is incompatible with the algorithm
2330 if ( currentHyp( dim, Algo ) < 0 )
2331 { // none algo selected; it is edition for sure, of submesh maybe
2332 hypWithoutAlgo = true;
2333 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2334 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2335 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2336 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2339 setCurrentHyp( dim, hypType + i, aHypIndex );
2341 if ( hypType == MainHyp ) break; // only one main hyp allowed
2345 // make available other hyps of same type as one without algo
2346 if ( hypWithoutAlgo )
2347 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2350 //================================================================================
2352 * \brief Gets name of object
2353 * \param theSO - SObject
2354 * \retval QString - name of object
2356 * Gets name of object
2358 //================================================================================
2359 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2364 _PTR(GenericAttribute) anAttr;
2365 _PTR(AttributeName) aNameAttr;
2366 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2369 aResName = aNameAttr->Value().c_str();
2375 //================================================================================
2377 * \brief Finds hypothesis in input list
2378 * \param theHyp - hypothesis to be found
2379 * \param theHypList - input list of hypotheses
2380 * \retval int - index of hypothesis or -1 if it is not found
2382 * Finds position of hypothesis in input list
2384 //================================================================================
2385 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2386 const THypList& theHypList ) const
2389 if ( !theHyp->_is_nil() )
2392 THypList::const_iterator anIter = theHypList.begin();
2393 for ( ; anIter != theHypList.end(); ++ anIter)
2395 if ( theHyp->_is_equivalent( (*anIter).first ) )
2406 //================================================================================
2408 * \brief Edits mesh or sub-mesh
2409 * \param theMess - Output parameter intended for returning error message
2410 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2412 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2414 //================================================================================
2415 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2419 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2420 if ( aSMESHGen->_is_nil() )
2423 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2424 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2428 SUIT_OverrideCursor aWaitCursor;
2431 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2432 SMESH::SetName( pObj, aName );
2433 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2435 // First, remove old algos in order to avoid messages on algorithm hiding
2436 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2438 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2440 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2441 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2442 if ( anAlgoVar->_is_nil() || // no new algo selected or
2443 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2445 // remove old algorithm
2446 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2447 myObjHyps[ dim ][ Algo ].clear();
2452 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2453 CORBA::Object_var anObject = aSObject->GetObject();
2454 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2455 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2456 bool isMesh = !aMeshVar->_is_nil();
2457 if ( !isMesh && !aSubMeshVar->_is_nil() )
2458 aMeshVar = aSubMeshVar->GetFather();
2460 // Assign new algorithms and hypotheses
2461 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2463 //if ( !isAccessibleDim( dim )) continue;
2465 // find or create algorithm
2466 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2468 // assign new algorithm
2469 if ( !anAlgoVar->_is_nil() && // some algo selected and
2470 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2473 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2474 else if ( !aSubMeshVar->_is_nil() )
2475 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2477 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2480 // remove deselected hypotheses
2481 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2483 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2485 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2486 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2487 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2489 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2493 // assign newly selected hypotheses
2494 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2496 const int curIndex = currentHyp( dim, dlgType );
2497 const int hypType = Min( dlgType, AddHyp );
2498 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2500 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2502 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2506 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2507 else if ( !aSubMeshVar->_is_nil() )
2508 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2511 // reread all hypotheses of mesh
2512 QStringList anExisting;
2513 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2517 myHasConcurrentSubBefore =
2518 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2523 //================================================================================
2525 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2526 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2527 * order of sub-mesh computation.
2528 * Returns \c true if a sub-mesh concurrency detected.
2530 //================================================================================
2532 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2533 SMESH::SMESH_subMesh_ptr submesh,
2536 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2539 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2540 if ( isNewConcurrent && askUser )
2542 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2543 tr("CONCURRENT_SUBMESH_APPEARS"),
2544 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2547 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2548 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2549 if ( meshSO && aSelectionMgr )
2551 myDlg->setEnabled( false ); // disactivate selection
2552 selectionMgr()->clearFilters();
2553 selectObject( meshSO );
2554 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2555 qApp->processEvents();
2557 myDlg->setEnabled( true );
2558 int obj = myDlg->getActiveObject();
2559 onActivateObject( obj ); // restore filter
2562 selectObject( SMESH::FindSObject( submesh ));
2569 return isNewConcurrent;
2572 //================================================================================
2574 * \brief Verifies whether given operator is valid for this one
2575 * \param theOtherOp - other operation
2576 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2578 * method redefined from base class verifies whether given operator is valid for
2579 * this one (i.e. can be started "above" this operator). In current implementation method
2580 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2583 //================================================================================
2584 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2586 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2589 //================================================================================
2591 * \brief SLOT. Is called when the user selects a way of geometry selection
2592 * \param theByMesh - true if the user wants to find geometry by mesh element
2594 //================================================================================
2595 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2598 if ( !myShapeByMeshOp ) {
2599 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2600 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2601 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2602 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2603 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2605 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2606 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2607 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2608 SMESH::SMESH_Mesh_var aMeshVar =
2609 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2610 if ( !aMeshVar->_is_nil() ) {
2611 myDlg->hide(); // stop processing selection
2612 myShapeByMeshOp->setModule( getSMESHGUI() );
2613 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2614 myShapeByMeshOp->SetMesh( aMeshVar );
2615 myShapeByMeshOp->start();
2621 //================================================================================
2623 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2625 //================================================================================
2626 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2628 if ( myShapeByMeshOp == op ) {
2629 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2631 // Select a found geometry object
2632 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2633 if ( !aGeomVar->_is_nil() )
2635 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2636 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2637 selectObject( aGeomSO );
2644 //================================================================================
2646 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2648 //================================================================================
2649 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2651 if ( myShapeByMeshOp == op && myDlg ) {
2656 //================================================================================
2658 * \brief Selects a SObject
2659 * \param theSObj - the SObject to select
2661 //================================================================================
2662 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2664 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2665 SALOME_ListIO anIOList;
2667 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2668 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2669 anIOList.Append( anIO );
2671 sm->setSelectedObjects( anIOList, false );
2674 //================================================================================
2676 * \brief Create available list types of mesh
2677 * \param theTypeMesh - Output list of available types of mesh
2679 //================================================================================
2680 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2682 theTypeMesh.clear();
2683 theTypeMesh.append( tr( "MT_ANY" ) );
2684 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2686 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2687 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2689 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2691 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2692 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2696 //================================================================================
2698 * \brief Set available types of mesh
2699 * \param theTypeMesh - List of available types of mesh
2701 //================================================================================
2702 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2704 myDlg->setAvailableMeshType( theTypeMesh );
2707 //================================================================================
2709 * \brief SLOT. Is called when the user select type of mesh
2710 * \param theTabIndex - Index of current active tab
2711 * \param theIndex - Index of current type of mesh
2713 //================================================================================
2714 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex )
2716 setFilteredAlgoData( theTabIndex, theIndex);
2719 //================================================================================
2721 * \brief Set a filtered list of available algorithms by mesh type
2722 * \param theTabIndex - Index of current active tab
2723 * \param theIndex - Index of current type of mesh
2725 //================================================================================
2726 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex )
2728 QStringList anAvailableAlgs;
2729 QString anCompareType = currentMeshTypeName( theIndex );
2730 int anCurrentAvailableAlgo = -1;
2732 int aDim = SMESH::DIM_3D;
2733 if ( theIndex == MT_TRIANGULAR || theIndex == MT_QUADRILATERAL)
2734 aDim = SMESH::DIM_2D;
2735 if ( anCompareType == "ANY" )
2737 bool isReqDisBound = false;
2738 int aReqDim = SMESH::DIM_3D;
2739 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2741 anCurrentAvailableAlgo = -1;
2742 isNone = currentHyp( dim, Algo ) < 0;
2743 //return current algo in current tab and set new algorithm list
2744 HypothesisData* algoCur = 0;
2745 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2746 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2748 HypothesisData* prevAlgo = 0;
2749 HypothesisData* nextAlgo = 0;
2750 if ( dim == SMESH::DIM_2D ) {
2751 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2752 if ( aDim == SMESH::DIM_3D )
2753 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2755 // retrieves a list of available algorithms from resources
2756 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCompareType);
2757 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoCur );
2758 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2759 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2760 if ( anCurrentAvailableAlgo > -1 )
2761 isReqDisBound = algoCur->InputTypes.isEmpty();
2762 if ( isReqDisBound ) {
2767 if ( !myIsOnGeometry )
2768 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2769 bool disable = myAvailableHypData[i][Algo].isEmpty();
2770 if ( disable ) myDlg->disableTab( i );
2771 else myDlg->enableTab( i );
2774 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2775 if ( i > myMaxShapeDim || ( isReqDisBound && i < aReqDim ) ) myDlg->disableTab( i );
2776 else myDlg->enableTab( i );
2778 myDlg->setCurrentTab( theTabIndex );
2782 HypothesisData* anCurrentAlgo = 0;
2783 bool isReqDisBound = true;
2784 QString anCurrentCompareType = anCompareType;
2785 isNone = currentHyp( aDim, Algo ) < 0;
2786 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() )
2787 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2788 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2790 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2791 anCurrentAvailableAlgo = -1;
2792 HypothesisData* prevAlgo = 0;
2793 HypothesisData* nextAlgo = 0;
2794 if ( dim == SMESH::DIM_2D ) {
2795 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2796 if ( aDim == SMESH::DIM_3D )
2797 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2799 // finding algorithm which is selected
2801 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2803 // retrieves a list of available algorithms from resources
2804 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType );
2805 // finding and adding algorithm depending on the type mesh
2806 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( anCurrentAlgo );
2807 //set new algorithm list and select the current algorithm
2808 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2809 anCurrentCompareType = ( anCompareType == "HEXA" || anCompareType == "QUAD" ) ? "QUAD" : "TRIA";
2810 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo, /*updateHyps=*/true );
2813 for ( int i = myMaxShapeDim; i >= SMESH::DIM_0D; i-- ) {
2814 bool isNoneAlg = currentHyp( i, Algo ) < 0;
2816 isReqDisBound = myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2818 isReqDisBound = true;
2819 if ( isReqDisBound && !isNoneAlg && i <= aDim) {
2820 for (int j = myMaxShapeDim; j >= SMESH::DIM_0D; j--) {
2821 if ( currentHyp( j, Algo ) < 0 ) {
2822 myDlg->disableTab( j );
2823 setCurrentHyp( j , Algo, -1, /*updateHyps=*/true );
2829 myDlg->enableTab( i );
2832 if ( aDim == SMESH::DIM_2D) {
2833 setCurrentHyp( SMESH::DIM_3D, Algo, -1, /*updateHyps=*/true );
2834 myDlg->disableTab( SMESH::DIM_3D );
2837 int currentTab = ( theTabIndex <= aDim ) ? theTabIndex : aDim;
2838 myDlg->setCurrentTab( currentTab );
2840 THypDataList anAvailableAlgsData;
2841 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2842 QStringList aFilteredHypothesesSetsList;
2843 aFilteredHypothesesSetsList.clear();
2844 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2845 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName ) {
2846 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2847 bool isAvailable = false;
2848 currentHypoSet->init( true );
2849 while ( currentHypoSet->next(), currentHypoSet->more() ) {
2850 isAvailable = false;
2851 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2852 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++) {
2853 int anCurrentAvailableAlgo = myAvailableHypData[i][Algo].indexOf( algoDataIn );
2854 if ( anCurrentAvailableAlgo > -1 ) {
2864 aFilteredHypothesesSetsList.append( *inHypoSetName );
2866 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2869 //================================================================================
2871 * \brief Get current name types of mesh
2872 * \param theIndex - current index types of mesh
2873 * \retval QString - result
2875 //================================================================================
2876 QString SMESHGUI_MeshOp::currentMeshTypeName( const int theIndex ) const
2878 QString aMeshType = "";
2879 switch ( theIndex ) {
2886 case MT_QUADRILATERAL:
2889 case MT_TETRAHEDRAL:
2890 aMeshType = "TETRA";