1 // Copyright (C) 2007-2024 CEA, EDF, 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_GroupOnShapeDlg.h"
31 #include "SMESHGUI_Hypotheses.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_MeshDlg.h"
34 #include "SMESHGUI_Operations.h"
35 #include "SMESHGUI_ShapeByMeshDlg.h"
36 #include "SMESHGUI_Utils.h"
37 #include "SMESH_NumberFilter.hxx"
38 #include "SMESH_TypeDefs.hxx"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_Gen_i.hxx"
42 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
44 // SALOME GEOM includes
46 #include <GEOMImpl_Types.hxx>
47 #include <GEOM_Client.hxx>
48 #include <GEOM_SelectionFilter.h>
49 #include <GEOM_wrap.hxx>
50 #include <GeometryGUI.h>
52 // SALOME GUI includes
53 #include <LightApp_Application.h>
54 #include <LightApp_SelectionMgr.h>
55 #include <LightApp_UpdateFlags.h>
56 #include <SALOME_InteractiveObject.hxx>
57 #include <SALOME_ListIO.hxx>
58 #include <SUIT_MessageBox.h>
59 #include <SUIT_OverrideCursor.h>
60 #include <SUIT_ResourceMgr.h>
61 #include <SUIT_Session.h>
62 #include <SalomeApp_Application.h>
63 #include <SalomeApp_Tools.h>
65 // SALOME KERNEL includes
66 #include <SALOMEDS_SComponent.hxx>
67 #include <SALOMEDS_SObject.hxx>
68 #include <SALOMEDS_Study.hxx>
69 #include <SALOMEDS_wrap.hxx>
72 #include <QApplication>
74 #include <QStringList>
77 #include <BRep_Tool.hxx>
79 #include <TopExp_Explorer.hxx>
80 #include <TopTools_IndexedMapOfShape.hxx>
83 //================================================================================
86 * \param theToCreate - if this parameter is true then operation is used for creation,
87 * for editing otherwise
89 * Initialize operation
91 //================================================================================
92 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
93 : SMESHGUI_SelectionOp(),
96 myToCreate( theToCreate ),
97 myIsMesh( theIsMesh ),
98 myIsInvalidSubMesh( false )
100 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
101 GeometryGUI::InitGeomGen();
102 myIsOnGeometry = true;
106 //================================================================================
110 //================================================================================
111 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
117 //================================================================================
119 * \brief Gets dialog of this operation
120 * \retval LightApp_Dialog* - pointer to dialog of this operation
122 //================================================================================
123 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
128 //================================================================================
130 * \brief Log meshers info
132 //================================================================================
133 void SMESHGUI_MeshOp::logSmeshParams()
136 int curMeshType = myDlg->currentMeshType();
137 switch ( curMeshType ) {
142 mesherType = "Triangular";
144 case MT_QUADRILATERAL:
145 mesherType = "Quadrilateral";
148 mesherType = "Tetrahedral";
151 mesherType = "Hexahedral";
157 QString aMessage = QString("Mesh type is %1").arg(mesherType);
158 CAM_Application::logStructuredUserEvent( "Mesh",
164 for ( int dim = 0; dim <= 3; ++dim )
166 HypothesisData * curAlgo = hypData( dim, Algo, currentHyp( dim, Algo ));
169 aMessage = QString("%1D algorithm is %2").arg(dim).arg(curAlgo->Label);
170 CAM_Application::logStructuredUserEvent( "Mesh",
179 //================================================================================
181 * \brief Creates or edits mesh
182 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
184 * Virtual slot redefined from the base class called when "Apply" button is clicked
185 * creates or edits mesh
187 //================================================================================
188 bool SMESHGUI_MeshOp::onApply()
190 if (SMESHGUI::isStudyLocked())
194 if ( !isValid( aMess ) )
198 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
202 bool aResult = false;
206 QStringList anEntryList;
207 if ( myToCreate && myIsMesh )
208 aResult = createMesh( aMess, anEntryList );
209 if (( myToCreate && !myIsMesh ) || myIsInvalidSubMesh )
210 aResult = createSubMesh( aMess, anEntryList );
211 else if ( !myToCreate )
212 aResult = editMeshOrSubMesh( aMess, anEntryList );
215 SMESHGUI::Modified();
216 update( UF_ObjBrowser | UF_Model );
217 if( LightApp_Application* anApp =
218 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
219 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
222 catch ( const SALOME::SALOME_Exception& S_ex )
224 SalomeApp_Tools::QtCatchCorbaException( S_ex );
236 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(logSmeshParams()));
241 aMess = tr( "SMESH_OPERATION_FAILED" );
242 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
251 //================================================================================
253 * \brief Creates dialog if necessary and shows it
255 * Virtual method redefined from base class called when operation is started creates
256 * dialog if necessary and shows it, activates selection
258 //================================================================================
259 void SMESHGUI_MeshOp::startOperation()
261 myIgnoreAlgoSelection = false;
265 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
266 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
268 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
269 this, SLOT( onCreateHyp( const int, const int ) ) );
270 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
271 this, SLOT( onEditHyp( const int, const int ) ) );
272 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
273 this, SLOT( onAlgoSelected( const int ) ) );
275 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
276 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
277 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
280 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
281 else myHelpFileName = "constructing_submeshes.html";
284 myHelpFileName = "editing_meshes.html";
287 SMESHGUI_SelectionOp::startOperation();
289 // clear available hypotheses
291 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
293 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
295 aTab->setAvailableHyps( Algo, hypList );
296 aTab->setAvailableHyps( MainHyp, hypList );
297 aTab->setAvailableHyps( AddHyp, hypList );
298 aTab->setExistingHyps( MainHyp, hypList );
299 aTab->setExistingHyps( AddHyp, hypList );
300 myExistingHyps[ i ][ MainHyp ].clear();
301 myExistingHyps[ i ][ AddHyp ].clear();
306 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
310 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
313 updateMeshTypeList();
314 myDlg->setCurrentMeshType( MT_ANY );
316 myDlg->setCurrentTab( SMESH::DIM_3D );
317 myDlg->setGeomPopupEnabled(false);
323 myHasConcurrentSubBefore = false;
324 myObjectToSelect.clear();
327 //=================================================================================
329 * \brief Selects a recently created mesh or sub-mesh if necessary
331 * Virtual method redefined from base class called when operation is committed
332 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
333 * selection when the custom selection filters are removed.
335 //=================================================================================
336 void SMESHGUI_MeshOp::commitOperation()
338 SMESHGUI_SelectionOp::commitOperation();
340 if ( !myObjectToSelect.isEmpty() ) {
341 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
342 SUIT_DataOwnerPtrList aList;
343 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
344 aSelectionMgr->setSelected( aList );
349 //================================================================================
351 * \brief Creates selection filter
352 * \param theId - identifier of current selection widget
353 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
355 * Creates selection filter in accordance with identifier of current selection widget
357 //================================================================================
358 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
360 if ( theId == SMESHGUI_MeshDlg::Geom )
362 // TColStd_MapOfInteger allTypesMap;
363 // for ( int i = 0; i < 10; i++ )
364 // allTypesMap.Add( i );
365 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
366 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
368 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
369 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
370 else if ( theId == SMESHGUI_MeshDlg::Mesh )
371 return new SMESH_TypeFilter( SMESH::MESH );
376 //================================================================================
378 * \brief check if selected shape is a sub-shape of the shape to mesh
379 * \retval bool - check result
381 //================================================================================
382 bool SMESHGUI_MeshOp::isSubshapeOk() const
384 if ( !myToCreate || myIsMesh ) // not submesh creation
388 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
389 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
390 if (!pMesh) return false;
392 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
393 if (mesh->_is_nil()) return false;
395 // main shape of the mesh
396 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
397 if (mainGeom->_is_nil()) return false;
401 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
403 // check all selected shapes
404 for ( QString& aSubGeomEntry : aGEOMs )
406 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID( aSubGeomEntry.toUtf8().data() );
407 if ( !pSubGeom ) return false;
409 GEOM::GEOM_Object_var subGeom =
410 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
412 if ( SMESH::ContainsSubShape( mainGeom, subGeom, false ))
419 //================================================================================
421 * \brief Return name of the algorithm that does not support sub-meshes and makes
422 * sub-mesh creation useless
423 * \retval char* - string is to be deleted!!!
425 //================================================================================
426 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
428 if ( myToCreate && !myIsMesh ) {
430 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
431 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
432 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
435 QStringList algoNames;
437 existingHyps(3, Algo, pMesh, algoNames, algoList);
438 if (!algoList.empty()) {
439 HypothesisData* algo =
440 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
442 algo->InputTypes.empty() && // builds all dimensions it-self
443 !algo->IsSupportSubmeshes )
444 return CORBA::string_dup( algoNames[0].toUtf8().data() );
447 // GEOM::GEOM_Object_var geom;
448 // if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() ))
449 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
451 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
452 existingHyps(2, Algo, pMesh, algoNames, algoList);
453 if (!algoList.empty()) {
454 HypothesisData* algo =
455 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
457 algo->InputTypes.empty() && // builds all dimensions it-self
458 !algo->IsSupportSubmeshes )
459 return CORBA::string_dup( algoNames[0].toUtf8().data() );
467 //================================================================================
469 * \brief find an existing submesh by the selected shape
470 * \retval _PTR(SObject) - the found submesh SObject
472 //================================================================================
473 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
475 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
476 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
477 if ( pMesh && !myGeom->_is_nil() ) {
479 switch ( myGeom->GetShapeType() ) {
480 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
481 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
482 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
483 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
484 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
485 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
486 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
489 _PTR(GenericAttribute) anAttr;
490 _PTR(SObject) aSubmeshRoot;
491 _PTR(Study) aStudy = SMESH::getStudy();
492 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
494 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
495 for ( ; smIter->More(); smIter->Next() )
497 _PTR(SObject) aSmObj = smIter->Value();
498 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
500 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
501 for ( ; anIter1->More(); anIter1->Next()) {
502 _PTR(SObject) pGeom2 = anIter1->Value();
503 if ( pGeom2->ReferencedObject( pGeom2 ) &&
504 myGeomEntry == pGeom2->GetID().c_str() )
510 return _PTR(SObject)();
513 //================================================================================
515 * \brief Updates dialog's look and feel
517 * Virtual method redefined from the base class updates dialog's look and feel
519 //================================================================================
520 void SMESHGUI_MeshOp::selectionDone()
522 if (!dlg()->isVisible() || !myDlg->isEnabled())
525 SMESHGUI_SelectionOp::selectionDone();
528 myGeom = GEOM::GEOM_Object::_nil();
529 myIsInvalidSubMesh = false;
530 myIsOnGeometry = true;
534 // allow selecting multiple geom objects only for sub-mesh creation
536 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aGEOMs );
537 int nbGeoms = aGEOMs.count();
540 myGeomEntry = aGEOMs[0];
541 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( myGeomEntry.toUtf8().data() );
542 if ( nbGeoms > 1 && myToCreate && myIsMesh )
544 selectObject( pGeom );
548 myGeom = SMESH::SObjectToInterface< GEOM::GEOM_Object >( pGeom ); // creation case
551 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
552 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
554 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface< SMESH::SMESH_Mesh >( pObj );
555 SMESH::SMESH_subMesh_var subMesh;
557 if ( !myToCreate ) // edition: read hypotheses
561 subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
562 myIsMesh = subMesh->_is_nil();
563 myGeom = SMESH::GetShapeOnMeshOrSubMesh( pObj );
564 myIsInvalidSubMesh = ( !myIsMesh && subMesh->GetId() < 1 );
565 if ( !mesh->_is_nil() && !mesh->HasShapeToMesh() )
567 myIsOnGeometry = false;
568 myGeom = GEOM::GEOM_Object::_nil();
570 if ( !myGeom->_is_nil() )
571 myGeomEntry = myGeom->GetStudyEntry();
573 myDlg->setTitile( myToCreate, myIsMesh );
574 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !subMesh->_is_nil() );
575 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, !myGeom->_is_nil() );
576 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
577 if ( myIsInvalidSubMesh )
579 // it is necessary to select a new geometry
580 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->show();
581 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
585 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
587 myDlg->updateGeometry();
594 else if ( !myIsMesh ) // sub-mesh creation
596 // if a submesh on the selected shape already exist, pass to submesh edition mode
597 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
598 subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
599 bool editSubmesh = ( !subMesh->_is_nil() &&
600 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
601 tr( "EDIT_SUBMESH_QUESTION"),
602 SUIT_MessageBox::Yes |
604 SUIT_MessageBox::No )
605 == SUIT_MessageBox::Yes );
608 selectionMgr()->clearFilters();
609 selectObject( pSubmesh );
610 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
615 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
616 selectObject( _PTR(SObject)() );
621 // discard selected mesh if submesh creation not allowed because of
622 // a global algorithm that does not support submeshes
623 if ( char* algoName = isSubmeshIgnored() ) {
624 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
625 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
626 CORBA::string_free( algoName );
627 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
628 selectObject( _PTR(SObject)() );
633 // enable/disable popup for choice of geom selection way
635 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
636 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toLatin1().data() ))
638 mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
639 if ( !mesh->_is_nil() )
640 enable = /*( shapeDim > 1 ) && */( mesh->NbEdges() > 0 );
642 myDlg->setGeomPopupEnabled( enable );
644 //rnv: issue 21056: "Create Sub Mesh": focus should automatically switch to geometry
645 if ( pObj && myGeomEntry.isEmpty() )
646 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
649 setFilteredAlgoData();
652 catch ( const SALOME::SALOME_Exception& S_ex )
654 SalomeApp_Tools::QtCatchCorbaException( S_ex );
661 //================================================================================
663 * \brief Verifies validity of input data
664 * \param theMess - Output parameter intended for returning error message
665 * \retval bool - TRUE if input data is valid, false otherwise
667 * Verifies validity of input data. This method is called when "Apply" or "OK" button
668 * is pressed before mesh creation or editing.
670 //================================================================================
671 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
673 // Selected object to be edited
674 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
676 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
681 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
682 if ( aMeshName.isEmpty() )
684 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
688 /* // Imported mesh, if create sub-mesh or edit mesh
689 if ( !myToCreate || ( myToCreate && !myIsMesh ))
691 QString aMeshEntry = myDlg->selectedObject
692 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
693 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
694 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
695 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
696 theMess = tr( "IMPORTED_MESH" );
703 if ( myToCreate || myIsInvalidSubMesh )
705 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
706 if ( aGeomEntry.isEmpty() )
708 theMess = tr( myIsMesh ?
709 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
710 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
714 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
715 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
722 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
723 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
725 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
730 if ( !myIsMesh ) // i.e sub-mesh creation,
732 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
733 if ( aMeshEntry == "" )
735 theMess = tr( "MESH_IS_NOT_DEFINED" );
738 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
739 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
741 theMess = tr( "MESH_IS_NULL" );
744 if ( !isSubshapeOk() )
746 theMess = tr( "INVALID_SUBSHAPE" );
755 //================================================================================
757 * \brief check compatibility of the algorithm and another algorithm or hypothesis
758 * \param theAlgoData - algorithm data
759 * \param theHypData - hypothesis data
760 * \param theHypType - hypothesis type
761 * \retval bool - check result
763 //================================================================================
764 static bool isCompatible(const HypothesisData* theAlgoData,
765 const HypothesisData* theHypData,
766 const int theHypType)
771 if ( theHypType == SMESHGUI_MeshOp::Algo ) // compatibility of 2 algos
772 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
774 bool isOptional; // compatibility of algo and hyp
775 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
778 //================================================================================
780 * \brief check compatibility of the geometry
781 * \param theAlgoData - to select hypos able to be used by this algo
782 * \param theDim - algo dimension
783 * \retval bool - check result
785 //================================================================================
786 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
789 if ( theDim < 1 || myGeom->_is_nil() )
792 bool isApplicable = false;
793 if ( myGeomEntry == myLastGeomEntry && !myGeomEntry.isEmpty() ) {
794 THypLabelIsAppMap::const_iterator lab2isApp = myHypMapIsApplicable.find( theAlgoData->TypeName );
795 if ( lab2isApp != myHypMapIsApplicable.end() ) {
796 isApplicable = lab2isApp.value();
800 bool toCheckIsApplicableToAll = !myIsMesh;
801 if ( toCheckIsApplicableToAll )
802 toCheckIsApplicableToAll = ( myGeom->GetType() == GEOM_GROUP );
804 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, myGeom, toCheckIsApplicableToAll );
805 myHypMapIsApplicable.insert( theAlgoData->TypeName, isApplicable );
809 //================================================================================
811 * \brief check compatibility of the mesh type
812 * \param theAlgoData - to select hypos able to be used by this algo
813 * \param theDim - algo dimension
814 * \retval bool - check result
816 //================================================================================
817 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
824 int curMeshType = myDlg->currentMeshType();
825 switch ( curMeshType ) {
835 case MT_QUADRILATERAL:
859 bool isAvailableAlgo = theAlgoData->OutputTypes.isEmpty();
860 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
861 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ )
863 if ( *inElemType == elemType )
865 isAvailableAlgo = true;
869 return isAvailableAlgo;
872 //================================================================================
874 * \brief Get available hypotheses or algorithms
875 * \param theDim - specifies dimension of returned hypotheses/algorifms
876 * \param theHypType - specifies whether algorims or hypotheses or additional ones
877 * are retrieved (possible values are in HypType enumeration)
878 * \param theHyps - output list of hypotheses' names
879 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
880 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
881 * \param theMeshType - type of mesh for filtering algorithms (optional)
883 * Get available hypotheses or algorithm in accordance with input parameters.
884 * Result (\a theHyps) optionally depends on the following:
885 * - selected algorithm(s)
886 * - selected geometry
887 * - selected mesh type
889 //================================================================================
890 void SMESHGUI_MeshOp::availableHyps( const int theDim,
891 const int theHypType,
892 QStringList& theHyps,
893 THypDataList& theDataList,
894 HypothesisData* thePrevAlgoData,
895 HypothesisData* theNextAlgoData,
896 const QString& /*theMeshType*/)
900 bool isAlgo = ( theHypType == Algo );
901 bool isAux = ( theHypType >= AddHyp );
902 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
904 std::multimap< double, HypothesisData* > sortedHyps;
905 QStringList::const_iterator anIter;
906 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
908 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
909 if ( isCompatible( thePrevAlgoData, aData, theHypType ) &&
910 isCompatible( theNextAlgoData, aData, theHypType ) &&
911 isCompatibleToGeometry( aData, theDim ) &&
912 isCompatibleToMeshType( aData, theDim ))
914 int groupID = aData->GroupID;
915 int priority = aData->Priority;
916 if ( groupID < 0 || groupID > 9 ) groupID = 9;
917 if ( priority < 0 || priority > 999 ) priority = 999;
919 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
923 if ( !sortedHyps.empty() )
925 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
926 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
927 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
929 HypothesisData* aData = key_hyp->second;
930 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
931 if ( aPrevGroup != aGroup )
933 theDataList.append( aGroup );
934 theHyps.append( aGroup->Label );
937 theDataList.append( aData );
938 theHyps.append( aData->Label );
943 //================================================================================
945 * \brief Gets existing hypotheses or algorithms
946 * \param theDim - specifies dimension of returned hypotheses/algorifms
947 * \param theHypType - specifies whether algorims or hypotheses or additional ones
948 * are retrieved (possible values are in HypType enumeration)
949 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
950 * \param theHyps - output list of names.
951 * \param theHypVars - output list of variables.
952 * \param theAlgoData - to select hypos able to be used by this algo (optional)
954 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
957 * WARNING: when using this method to get hyps existing in Mesh component,
958 * call availableHyps() before in order to get only hyps of available types
959 * that was filtered by availableHyps()
961 //================================================================================
962 void SMESHGUI_MeshOp::existingHyps( const int theDim,
963 const int theHypType,
964 _PTR(SObject) theFather,
965 QStringList& theHyps,
966 THypList& theHypList,
967 HypothesisData* theAlgoData) const
969 // Clear hypoheses list
976 _PTR(SObject) aHypRoot;
977 _PTR(GenericAttribute) anAttr;
978 _PTR(AttributeName) aName;
979 _PTR(AttributeIOR) anIOR;
981 const bool isMesh = !_CAST( SComponent, theFather );
984 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
986 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
988 const bool isAux = ( theHypType >= AddHyp );
989 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
991 if ( theFather->FindSubObject( aPart, aHypRoot ) )
993 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypRoot );
994 for ( ; anIter->More(); anIter->Next() )
996 _PTR(SObject) anObj = anIter->Value();
997 if ( isMesh ) // i.e. mesh or submesh
999 _PTR(SObject) aRefObj;
1000 if ( anObj->ReferencedObject( aRefObj ) )
1005 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1008 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1009 if ( !CORBA::is_nil( aVar ) )
1011 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
1012 if ( !aHypVar->_is_nil() )
1014 CORBA::String_var hypType = aHypVar->GetName();
1015 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
1016 if ( !aData) continue;
1017 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
1018 ( isCompatible ( theAlgoData, aData, theHypType )) &&
1019 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
1020 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
1022 std::string aHypName = aName->Value();
1023 theHyps.append( aHypName.c_str() );
1024 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
1033 //================================================================================
1035 * \brief If create or edit a submesh, return a hypothesis holding parameters used
1036 * to mesh a sub-shape
1037 * \param aHypType - The hypothesis type name
1038 * \param aServerLib - Server library name
1039 * \param hypData - The structure holding the hypothesis type etc.
1040 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
1042 //================================================================================
1043 SMESH::SMESH_Hypothesis_var
1044 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1045 const QString& aServerLib,
1046 const SMESH::HypInitParams* aParams ) const
1048 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1049 return SMESH::SMESH_Hypothesis::_nil();
1051 const int nbColonsInMeshEntry = 3;
1052 bool isSubMesh = myToCreate ?
1054 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1056 // get mesh and geom object
1057 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1058 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1063 anEntry = myDlg->selectedObject
1064 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1065 if ( _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1067 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1068 if ( myToCreate ) // mesh and geom may be selected
1070 aMesh = SMESH::SMESH_Mesh::_narrow( Obj );
1071 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1072 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1073 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1075 else // edition: sub-mesh may be selected
1077 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1078 if ( !sm->_is_nil() ) {
1079 aMesh = sm->GetFather();
1080 aGeomVar = sm->GetSubShape();
1087 if ( !myToCreate ) // mesh to edit can be selected
1089 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1090 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1092 aMesh = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1093 if ( !aMesh->_is_nil() )
1094 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1097 if ( aGeomVar->_is_nil() ) {
1098 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1099 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1101 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1106 SMESH::HypInitParams initParams;
1107 enum { BY_MESH, BY_GEOM, BY_AVERAGE_LENGTH }; // same as ::SMESH_Hypothesis::InitWay
1110 initParams = *aParams;
1114 initParams.way = isSubMesh ? BY_MESH : BY_GEOM;
1117 SMESH::SMESH_Hypothesis_var hyp;
1118 if ( initParams.way == BY_AVERAGE_LENGTH )
1119 hyp = SMESHGUI::GetSMESHGen()->CreateHypothesisByAverageLength( aHypType.toUtf8().data(),
1120 aServerLib.toUtf8().data(),
1121 initParams.averageLength,
1122 initParams.quadDominated );
1124 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1125 aServerLib.toUtf8().data(),
1129 if ( hyp->_is_nil() && initParams.way == BY_MESH )
1131 initParams.way = BY_GEOM;
1132 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1133 aServerLib.toUtf8().data(),
1138 if ( hyp->_is_nil() && initParams.way == BY_GEOM )
1140 initParams.way = BY_AVERAGE_LENGTH;
1141 initParams.averageLength = 1.;
1142 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1143 aServerLib.toUtf8().data(),
1151 //================================================================================
1153 * \brief initialize a hypothesis creator
1155 //================================================================================
1157 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1159 if ( !theCreator ) return;
1161 // Set shapes, of mesh and sub-mesh if any
1163 // get Entry of the Geom object
1164 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1165 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1166 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1168 if ( myToCreate && myIsMesh )
1169 aMeshEntry = aGeomEntry;
1171 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1172 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1173 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1174 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1177 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1178 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1180 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1181 if ( !aGeomVar->_is_nil() )
1183 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1185 aMeshEntry = aGeomEntry;
1189 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1190 // take geometry from submesh being created
1191 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1193 // if current object is sub-mesh
1194 SMESH::SMESH_subMesh_var aSubMeshVar =
1195 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1196 if ( !aSubMeshVar->_is_nil() ) {
1197 SMESH::SMESH_Mesh_var aMesh = aSubMeshVar->GetFather();
1198 if ( !aMesh->_is_nil() ) {
1199 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
1200 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1201 if ( !aGeomVar->_is_nil() )
1202 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1208 theCreator->setShapeEntry( aGeomEntry );
1209 if ( aMeshEntry != "" )
1210 theCreator->setMainShapeEntry( aMeshEntry );
1212 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1215 //================================================================================
1217 * \Brief Returns tab dimension
1218 * \param tab - the tab in the dlg
1219 * \param dlg - my dialogue
1220 * \retval int - dimension
1222 //================================================================================
1223 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1226 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1227 if (tab == dlg->tab(i))
1232 //================================================================================
1234 * \brief Create hypothesis
1235 * \param theHypType - hypothesis category (main or additional)
1236 * \param theIndex - index of type of hypothesis to be created
1238 * Specifies dimension of hypothesis to be created (using sender() method),
1239 * specifies its type and calls method for hypothesis creation
1241 //================================================================================
1242 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1244 // Specifies dimension of hypothesis to be created
1245 int aDim = getTabDim( sender(), myDlg );
1249 // Specifies type of hypothesis to be created
1250 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1251 if (theIndex < 0 || theIndex >= dataList.count())
1253 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1255 // Create hypothesis
1256 createHypothesis(aDim, theHypType, aHypTypeName);
1261 QString GetUniqueName (const QStringList& theHypNames,
1262 const QString& theName,
1263 size_t theIteration = 1)
1265 QString aName = theName + "_" + QString::number( theIteration );
1266 if ( theHypNames.contains( aName ) )
1267 return GetUniqueName( theHypNames, theName, ++theIteration );
1272 //================================================================================
1274 * \brief Return names of all existing hypotheses
1276 //================================================================================
1278 QStringList SMESHGUI_MeshOp::getHypoNames()
1280 QStringList aHypNames;
1282 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1283 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1284 const TType2HypList& aType2HypList = aDimIter.value();
1285 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1286 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1287 const THypList& aHypList = aTypeIter.value();
1288 THypList::const_iterator anIter = aHypList.begin();
1289 for ( ; anIter != aHypList.end(); anIter++) {
1290 const THypItem& aHypItem = *anIter;
1291 const QString& aHypName = aHypItem.second;
1292 aHypNames.append(aHypName);
1299 //================================================================================
1301 * Create hypothesis and update dialog.
1302 * \param theDim - dimension of hypothesis to be created
1303 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1304 * \param theTypeName - specifies hypothesis to be created
1306 //================================================================================
1307 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1309 const QString& theTypeName)
1311 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1318 // get a unique hyp name
1319 QString aHypName = GetUniqueName( getHypoNames(), aData->Label);
1322 bool dialog = false;
1324 QString aClientLibName = aData->ClientLibName;
1325 if (aClientLibName == "") {
1326 // Call hypothesis creation server method (without GUI)
1327 SMESH::SMESH_Hypothesis_var aHyp =
1328 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1332 // Get hypotheses creator client (GUI)
1333 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1335 // Create hypothesis
1338 // Get parameters appropriate to initialize a new hypothesis
1339 SMESH::SMESH_Hypothesis_var initParamHyp =
1340 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1342 removeCustomFilters(); // Issue 0020170
1344 // set shapes, of mesh and sub-mesh if any
1345 initHypCreator( aCreator );
1347 myDlg->setEnabled( false );
1349 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1354 SMESH::SMESH_Hypothesis_var aHyp =
1355 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1364 //================================================================================
1366 * Necessary steps after hypothesis creation
1367 * \param result - creation result:
1370 * 2 = additional value meaning that slot is called not from dialog box
1372 //================================================================================
1373 void SMESHGUI_MeshOp::onHypoCreated( int result )
1377 int obj = myDlg->getActiveObject();
1378 onActivateObject( obj ); // Issue 0020170. Restore filters
1379 myDlg->setEnabled( true );
1383 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1385 int nbHyp = myExistingHyps[myDim][myType].count();
1386 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1387 QStringList aNewHyps;
1388 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1389 if (aNewHyps.count() > nbHyp)
1391 for (int i = nbHyp; i < aNewHyps.count(); i++)
1392 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1397 //================================================================================
1399 * \brief Calls plugin methods for hypothesis editing
1400 * \param theHypType - specifies whether main hypothesis or additional one
1402 * \param theIndex - index of existing hypothesis
1404 * Calls plugin methods for hypothesis editing
1406 //================================================================================
1407 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1409 // Speicfies dimension of hypothesis to be created
1410 int aDim = getTabDim( sender(), myDlg );
1414 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1415 if ( theIndex < 0 || theIndex >= aList.count() )
1417 const THypItem& aHypItem = aList[ theIndex ];
1418 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1419 if ( aHyp->_is_nil() )
1422 SMESHGUI_GenericHypothesisCreator* aCreator =
1423 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1426 // set initial parameters
1427 SMESH::SMESH_Hypothesis_var initParamHyp =
1428 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1429 SMESH::toQStr( aHyp->GetLibName() ));
1430 aCreator->setInitParamsHypothesis( initParamHyp );
1432 // set shapes, of mesh and sub-mesh if any
1433 initHypCreator( aCreator );
1435 removeCustomFilters(); // Issue 0020170
1436 myDlg->setEnabled( false );
1439 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1443 //================================================================================
1445 * Necessary steps after hypothesis edition
1446 * \param result - creation result:
1450 //================================================================================
1451 void SMESHGUI_MeshOp::onHypoEdited( int /*result*/ )
1453 int obj = myDlg->getActiveObject();
1454 onActivateObject( obj ); // Issue 0020170. Restore filters
1455 myDlg->setEnabled( true );
1459 //================================================================================
1461 * \brief access to hypothesis data
1462 * \param theDim - hyp dimension
1463 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1464 * \param theIndex - index in the list
1465 * \retval HypothesisData* - result data, may be 0
1467 //================================================================================
1468 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1469 const int theHypType,
1472 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1473 theHypType > -1 && theHypType < NbHypTypes &&
1474 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1475 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1479 //================================================================================
1481 * \brief Update list of algorithms and hypotheses according to currently selected
1482 * algorithm, geometry and mesh type
1484 //================================================================================
1485 void SMESHGUI_MeshOp::setFilteredAlgoData()
1487 // keep current algorithms
1488 HypothesisData* curAlgos[ 4 ];
1489 for ( int dim = 0; dim <= 3; ++dim )
1490 curAlgos[ dim ] = hypData( dim, Algo, currentHyp( dim, Algo ));
1492 // find out myMaxShapeDim by checking algorithm applicability to geometry
1494 int curMeshType = myDlg->currentMeshType();
1495 myDlg->setCurrentMeshType( MT_ANY );
1496 QStringList algosAvailable;
1497 // get available algorithms taking into account geometry only
1498 if ( myGeom->_is_nil() )
1502 if ( myToCreate ) // readMesh() has done it if !myToCreate
1503 for ( int dim = 0; dim <= 3; ++dim )
1504 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1508 if ( myGeomEntry != myLastGeomEntry )
1509 myHypMapIsApplicable.clear();
1511 for ( int dim = 0; dim <= 3; ++dim )
1513 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1514 if ( algosAvailable.count() )
1515 myMaxShapeDim = dim;
1517 if ( !myGeomEntry.isEmpty() )
1518 myLastGeomEntry = myGeomEntry;
1520 myDlg->setMaxHypoDim( myMaxShapeDim );
1522 // set mesh types according to myMaxShapeDim
1523 updateMeshTypeList();
1525 // update available hypo-sets that depend on geometry and mesh type
1526 myDlg->setCurrentMeshType( Max( MT_ANY, curMeshType ));
1527 updateHypoSets(); // it sets myAvailableHypData by curMeshType
1529 // restore current algorithms according to changed myAvailableHypData
1530 algosAvailable.clear();
1531 for ( int dim = 0; dim <= 3; ++dim )
1533 int algoIndex = myAvailableHypData[ dim ][ Algo ].indexOf( curAlgos[ dim ]);
1534 while ( algosAvailable.count() <= algoIndex )
1535 algosAvailable << "";
1536 myDlg->tab( dim )->setAvailableHyps( Algo, algosAvailable );
1537 setCurrentHyp( dim, Algo, algoIndex );
1538 if ( algoIndex < 0 )
1539 curAlgos[ dim ] = 0;
1542 // find a selected algo, current or of highest dimension
1543 int algoDim = myDlg->currentTab();
1544 if ( !curAlgos[ algoDim ])
1545 for ( algoDim = SMESH::DIM_3D; algoDim >= SMESH::DIM_0D; algoDim-- )
1546 if ( curAlgos[ algoDim ] )
1548 if ( algoDim < SMESH::DIM_0D )
1549 algoDim = myMaxShapeDim;
1551 // set algorithms and hypotheses according to all parameters (mesh type etc)
1552 onAlgoSelected( currentHyp( algoDim, Algo ), algoDim );
1555 //================================================================================
1557 * \brief Set available algos and hypos according to the selected algorithm
1558 * \param theIndex - algorithm index
1559 * \param theDim - algorithm dimension
1561 //================================================================================
1562 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1565 if ( myIgnoreAlgoSelection )
1568 int curDim = getTabDim( sender(), myDlg );
1569 int aDim = theDim < 0 ? curDim : theDim;
1573 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1575 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1576 HypothesisData* algoByDim[4];
1577 algoByDim[ aDim ] = algoData;
1579 QStringList anAvailable;
1580 const int algoDim = aDim;
1582 // 2 loops: backward and forward from algo dimension (forward == to higher dimension)
1583 for ( int forward = 1; forward >= 0; --forward )
1585 int dim = algoDim, lastDim = SMESH::DIM_3D, dir = 1;
1587 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1589 //bool noCompatible = false;
1590 for ( ; dim * dir <= lastDim * dir; dim += dir)
1592 // if ( noCompatible ) // the selected algo has no compatible ones (like 1D2D3D algo)
1594 // anAvailable.clear();
1595 // myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1596 // myAvailableHypData[dim][Algo].clear();
1597 // algoByDim[ dim ] = 0;
1601 int algoIndex = currentHyp( dim, Algo );
1602 HypothesisData *curAlgo = hypData( dim, Algo, algoIndex );
1604 // set new available algorithms
1605 HypothesisData *prevAlgo = 0;
1606 if ( dim != algoDim )
1607 for ( int prevDim = dim + 1; prevDim <=3 && !prevAlgo; ++prevDim )
1608 prevAlgo = hypData( prevDim, Algo, currentHyp( prevDim, Algo ));
1609 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1610 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1612 //noCompatible = ( prevAlgo && !forward && anAvailable.isEmpty() );
1615 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1616 setCurrentHyp( dim, Algo, algoIndex, /*updateHyps=*/true );
1618 algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1621 // activate tabs according to algorithms availability
1622 if ( anAvailable.isEmpty() ) myDlg->disableTab( dim );
1623 else myDlg->enableTab( dim );
1626 } // loops backward and forward
1629 // set hypotheses corresponding to the found algorithms
1631 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
1633 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1635 if ( !isAccessibleDim( dim ))
1638 // get indices of selected hyps
1639 const int nbTypes = nbDlgHypTypes(dim);
1640 std::vector<int> hypIndexByType( nbTypes, -1 );
1641 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1643 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1647 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1649 const int type = Min( dlgType, AddHyp );
1650 myAvailableHypData[ dim ][ type ].clear();
1651 QStringList anAvailable, anExisting;
1653 HypothesisData* curAlgo = algoByDim[ dim ];
1654 int hypIndex = hypIndexByType[ dlgType ];
1656 SMESH::SMESH_Hypothesis_var curHyp;
1658 HypothesisData* hypData = 0;
1659 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1661 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1662 if ( !curHyp->_is_nil() )
1664 curHypType = SMESH::toQStr( curHyp->GetName() );
1665 hypData = SMESH::GetHypothesisData( curHypType );
1668 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) // edition, algo not selected
1670 // try to find algo by selected hypothesis in order to keep it selected
1671 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1672 if ( !algoDeselectedByUser &&
1673 myObjHyps[ dim ][ type ].count() > 0 &&
1674 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1676 for ( int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i )
1678 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1679 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1687 // get hyps compatible with curAlgo
1688 bool defaulHypAvlbl = false;
1691 if ( hypData && !isCompatible( curAlgo, hypData, type ))
1692 curHyp = SMESH::SMESH_Hypothesis::_nil();
1693 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo );
1694 existingHyps ( dim, type, pComp, anExisting, myExistingHyps[ dim ][ type ], curAlgo );
1695 defaulHypAvlbl = ( type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1697 // set list of hypotheses
1698 if ( dlgType <= AddHyp )
1700 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1701 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1703 // set current existing hypothesis
1704 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1705 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1708 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1710 // none is yet selected => select the sole existing if it is not optional
1711 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1712 bool isOptional = true;
1713 if ( algoByDim[ dim ] &&
1714 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1718 setCurrentHyp( dim, dlgType, hypIndex );
1724 //================================================================================
1726 * \brief Create a sub-mesh on internal edges in the case where the global algorithm
1727 * is of type 1D-2D[-3D] so that the internal edges would remain not meshed.
1729 //================================================================================
1731 void SMESHGUI_MeshOp::createSubMeshOnInternalEdges( SMESH::SMESH_Mesh_ptr theMesh,
1732 GEOM::GEOM_Object_ptr theMainShape )
1734 if ( theMesh->_is_nil() || theMainShape->_is_nil() )
1737 if ( isAccessibleDim( 1 ))
1738 return; // global 1D algorithm is/can be assigned
1740 const HypothesesSet::SetType internSet = HypothesesSet::INTERN;
1741 bool toCreate = true;
1742 bool toCreateMandatory = ( myHypoSet &&
1743 myAverageSize > 0 &&
1744 ( myHypoSet->init( /*algo=*/ true, internSet ), myHypoSet->more()) &&
1745 ( myHypoSet->init( /*algo=*/false, internSet ), myHypoSet->more()));
1746 if ( !toCreateMandatory ) // ask the user
1747 toCreate = false; // can't pass both mesh and geometry to Create Submesh operation (so far?)
1748 // toCreate = SUIT_MessageBox::warning( SMESHGUI::desktop(),
1749 // QObject::tr("SMESH_WRN_WARNING"),
1750 // QObject::tr("SMESH_CREATE_SUBMESH_ON_INTERNAL_EDGES"),
1751 // QObject::tr("SMESH_BUT_YES"),
1752 // QObject::tr("SMESH_BUT_NO"), 1, 0);
1757 if ( !GEOMBase::GetShape( theMainShape, shape ))
1760 std::vector< TopoDS_Shape > internalEdges;
1761 for ( TopExp_Explorer edge( shape, TopAbs_EDGE, TopAbs_WIRE ); edge.More(); edge.Next() )
1762 internalEdges.push_back( edge.Current() );
1764 if ( internalEdges.empty() )
1767 TopTools_IndexedMapOfShape shapeIDs;
1768 TopExp::MapShapes( shape, shapeIDs );
1770 std::set< int > intIDSet;
1771 for ( size_t i = 0; i < internalEdges.size(); ++i )
1772 intIDSet.insert( shapeIDs.FindIndex( internalEdges[ i ]));
1774 GEOM::GEOM_Gen_var geomGen = theMainShape->GetGen();
1775 if (geomGen->_is_nil()) return;
1777 GEOM::GEOM_Object_var edgeGroup;
1778 GEOM::GEOM_IShapesOperations_wrap sOp = geomGen->GetIShapesOperations();
1779 GEOM::GEOM_IGroupOperations_wrap gOp = geomGen->GetIGroupOperations();
1780 GEOM::ListOfGO_var geomGroups = sOp->GetExistingSubObjects( theMainShape,
1781 /*groupsOnly=*/true );
1782 for ( CORBA::ULong i = 0; i < geomGroups->length(); ++i )
1784 GEOM::ListOfLong_var ids = gOp->GetObjects( geomGroups[ i ]);
1785 std::set< int > idSet( & ids[0], & ids[0] + ids->length() );
1786 if ( idSet == intIDSet )
1788 edgeGroup = geomGroups[ i ];
1793 if ( edgeGroup->_is_nil() )
1795 GEOM::GEOM_Object_var edgeGroup = gOp->CreateGroup( theMainShape, TopAbs_EDGE );
1797 GEOM::ListOfLong_var edgeIDs = new GEOM::ListOfLong;
1798 edgeIDs->length( internalEdges.size() );
1799 std::set< int >::iterator id = intIDSet.begin();
1800 for ( size_t i = 0; i < intIDSet.size(); ++i, ++id )
1802 gOp->UnionIDs( edgeGroup, edgeIDs );
1804 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( edgeGroup, "Internal edges", theMainShape );
1807 if ( !toCreateMandatory )
1809 // show Create Sub-mesh dislog
1810 // _PTR(SObject) aMeshSO = SMESH::FindSObject( theMesh );
1811 // selectionMgr()->clearFilters();
1812 // selectObject( pSubmesh );
1813 // SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
1817 // create a sub-mesh using myAverageSize w/o GUI
1819 SMESH::SMESH_subMesh_var subMesh = theMesh->GetSubMesh( edgeGroup, "" );
1821 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1822 for ( myHypoSet->init( isAlgo, internSet ); myHypoSet->more(); myHypoSet->next() )
1824 QString aHypoTypeName = myHypoSet->current();
1825 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1829 myDim = aHypData->Dim[0];
1833 // create or/and set
1834 SMESH::SMESH_Hypothesis_var newHypo;
1837 myAvailableHypData[ myDim ][ Algo ].clear();
1838 myAvailableHypData[ myDim ][ Algo ] << aHypData;
1839 QStringList hypList; hypList << aHypoTypeName;
1840 myDlg->tab( myDim )->setAvailableHyps( Algo, hypList );
1841 setCurrentHyp( myDim, Algo, 0 );
1842 newHypo = getAlgo( myDim );
1846 SMESH::HypInitParams params = { 2, myAverageSize, false };
1847 newHypo = getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1848 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1849 SALOMEDS::SObject_wrap so =
1850 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), newHypo,
1851 hypName.toUtf8().data() );
1853 SMESH::AddHypothesisOnSubMesh( subMesh, newHypo );
1859 //================================================================================
1861 * \brief Ask the user to enter an average size which will be used to create
1862 * hypotheses of a hypo-set basing on this size
1863 * \param [out] averageSize - average element size
1864 * \return bool - false if the user canceled the dialog
1866 //================================================================================
1868 bool SMESHGUI_MeshOp::getAverageSize( double & averageSize )
1870 HypothesisData* hypData = SMESH::GetHypothesisData( "MaxLength" );
1874 SMESH::SMESH_Hypothesis_var hyp = getInitParamsHypothesis( hypData->TypeName,
1875 hypData->ServerLibName );
1876 if ( hyp->_is_nil() )
1879 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( hypData->TypeName );
1883 initHypCreator( aCreator );
1884 myDlg->setEnabled( false );
1886 aCreator->edit( hyp.in(), HypothesesSet::getCommonHypoSetHypoType(),
1887 dlg(), this, SLOT( onHypoEdited( int )));
1889 StdMeshers::StdMeshers_MaxLength_var lenHyp = StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
1890 if ( lenHyp->_is_nil() )
1893 averageSize = lenHyp->GetLength();
1897 //================================================================================
1899 * \brief Creates and selects hypothesis of hypotheses set
1900 * \param theSetName - The name of hypotheses set
1902 //================================================================================
1903 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1905 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1906 myHypoSet = aHypoSet;
1911 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++)
1913 setCurrentHyp(dim, Algo, -1);
1914 setCurrentHyp(dim, AddHyp, -1);
1915 setCurrentHyp(dim, MainHyp, -1);
1916 onAlgoSelected( -1, dim );
1919 HypothesesSet::SetType setType = aHypoSet->getPreferredHypType();
1920 if ( !aHypoSet->getAlgoAvailable( setType ))
1922 setType = ( setType == HypothesesSet::ALT ) ? HypothesesSet::MAIN : HypothesesSet::ALT;
1923 if ( !aHypoSet->getAlgoAvailable( setType ))
1928 if ( aHypoSet->toUseCommonSize() && !getAverageSize( myAverageSize ))
1932 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1933 for ( aHypoSet->init( isAlgo, setType ); aHypoSet->more(); aHypoSet->next() )
1935 QString aHypoTypeName = aHypoSet->current();
1936 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1940 myDim = aHypData->Dim[0];
1941 // create or/and set
1944 int index = myAvailableHypData[myDim][Algo].indexOf( aHypData );
1947 setCurrentHyp( myDim, Algo, index );
1948 onAlgoSelected( index, myDim );
1949 maxDim = Max( maxDim, myDim );
1955 int index = myAvailableHypData[myDim][MainHyp].indexOf( aHypData );
1959 index = myAvailableHypData[myDim][AddHyp].indexOf( aHypData );
1963 if ( myAverageSize > 0 )
1965 SMESH::HypInitParams params = { 2, myAverageSize, aHypoSet->isQuadDominated() };
1966 SMESH::SMESH_Hypothesis_var hyp =
1967 getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1969 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1970 SALOMEDS::SObject_wrap so =
1971 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), hyp,
1972 hypName.toUtf8().data() );
1977 createHypothesis( myDim, myType, aHypoTypeName );
1984 myDlg->setCurrentTab( maxDim );
1989 //================================================================================
1991 * \brief Creates mesh
1992 * \param theMess - Output parameter intended for returning error message
1993 * \param theEntryList - List of entries of published objects
1994 * \retval bool - TRUE if mesh is created, FALSE otherwise
1996 //================================================================================
1997 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
2002 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
2003 if ( aList.isEmpty() )
2005 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2006 if ( aSMESHGen->_is_nil() )
2009 SMESH::SMESH_Mesh_var aMesh= aSMESHGen->CreateEmptyMesh();
2010 if ( aMesh->_is_nil() )
2013 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
2015 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
2016 theEntryList.append( aMeshSO->GetID().c_str() );
2021 if ( aList.count() > 1 )
2023 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2024 int i = namePrefix.length() - 1;
2025 while ( i > 0 && namePrefix[i].isDigit() )
2027 if ( i < namePrefix.length() - 1 )
2028 namePrefix.chop( namePrefix.length() - 1 - i );
2032 QStringList::Iterator it = aList.begin();
2033 for ( int i = 0; it != aList.end(); it++, ++i )
2035 QString aGeomEntry = *it;
2036 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2037 GEOM::GEOM_Object_var aGeomVar =
2038 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2040 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2041 if ( aSMESHGen->_is_nil() )
2044 SUIT_OverrideCursor aWaitCursor;
2047 SMESH::SMESH_Mesh_var aMesh = aSMESHGen->CreateMesh( aGeomVar );
2048 if ( aMesh->_is_nil() )
2050 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
2052 theEntryList.append( aMeshSO->GetID().c_str() );
2053 if ( i > 0 ) setDefaultName( namePrefix );
2054 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
2057 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2059 if ( !isAccessibleDim( aDim )) continue;
2061 // assign hypotheses
2062 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2064 const int aHypIndex = currentHyp( aDim, dlgType );
2065 const int aHypType = Min( dlgType, AddHyp );
2066 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2068 SMESH::SMESH_Hypothesis_var aHypVar =
2069 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2070 if ( !aHypVar->_is_nil() )
2071 SMESH::AddHypothesisOnMesh( aMesh, aHypVar );
2074 // find or create algorithm
2075 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2076 if ( !anAlgoVar->_is_nil() )
2077 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2081 if ( myDlg->toCreateAllGroups() && !aGeomVar->_is_nil() )
2083 // Create groups on all geom groups
2085 GEOM::GEOM_Gen_var geomGen = aGeomVar->GetGen();
2086 GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
2087 GEOM::ListOfGO_var geomGroups = op->GetExistingSubObjects( aGeomVar,
2088 /*groupsOnly=*/false );
2089 SMESH::SMESH_GroupOnGeom_var meshGroup;
2090 for ( CORBA::ULong iG = 0; iG < geomGroups->length(); ++iG )
2092 SMESH::ElementType elemType = SMESHGUI_GroupOnShapeOp::ElementType( geomGroups[ iG ] );
2093 if ( elemType == SMESH::ALL )
2095 if ( elemType == SMESH::ELEM0D )
2096 elemType = SMESH::NODE;
2098 CORBA::String_var name = geomGroups[ iG ]->GetName();
2100 SALOMEDS::SObject_wrap groupSO = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject( geomGroups[iG] );
2101 if (!groupSO->_is_nil())
2102 meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
2103 // if ( elemType != SMESH::NODE )
2104 // meshGroup = aMesh->CreateGroupFromGEOM( SMESH::NODE, name, geomGroups[ iG ]);
2108 createSubMeshOnInternalEdges( aMesh, aGeomVar );
2115 //================================================================================
2117 * \brief Create sub-mesh
2118 * \param theMess - Output parameter intended for returning error message
2119 * \param theEntryList - List of entries of published objects
2120 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
2122 //================================================================================
2123 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
2127 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2128 if ( aSMESHGen->_is_nil() )
2132 SMESH::SMESH_Mesh_var aMesh =
2133 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
2134 if ( aMesh->_is_nil() && myIsInvalidSubMesh )
2136 SMESH::SMESH_subMesh_var aSMVar =
2137 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
2138 if ( !aSMVar->_is_nil() )
2139 aMesh = aSMVar->GetMesh();
2141 if ( aMesh->_is_nil() )
2144 // GEOM shape of the main mesh
2145 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2147 // Name for the new sub-mesh
2148 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
2151 GEOM::GEOM_Object_var aGeomVar;
2153 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
2154 if (aGEOMs.count() == 1)
2156 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2157 QString aGeomEntry = aGEOMs.first();
2158 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2159 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2161 else if (aGEOMs.count() > 1)
2163 // create a GEOM group
2164 GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
2165 if ( !geomGen->_is_nil() ) {
2166 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
2167 if ( !op->_is_nil() )
2169 // check and add all selected GEOM objects: they must be
2170 // a sub-shapes of the main GEOM and must be of one type
2172 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
2173 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2174 aSeq->length(aGEOMs.count());
2175 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
2176 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
2177 QString aSubGeomEntry = (*aSubShapesIter);
2178 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
2179 GEOM::GEOM_Object_var aSubGeomVar =
2180 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
2181 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
2183 aGroupType = aSubShapeType;
2185 if (aSubShapeType != aGroupType)
2186 aGroupType = TopAbs_SHAPE;
2188 aSeq[iSubSh] = aSubGeomVar;
2191 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
2192 op->UnionList(aGroupVar, aSeq);
2196 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
2198 // publish the GEOM group in study
2199 QString aNewGeomGroupName ("Auto_group_for_");
2200 aNewGeomGroupName += aName;
2201 SALOMEDS::SObject_wrap aNewGroupSO =
2202 geomGen->AddInStudy( aGeomVar,
2203 aNewGeomGroupName.toUtf8().data(), mainGeom);
2210 if (aGeomVar->_is_nil())
2213 SUIT_OverrideCursor aWaitCursor;
2215 QString aNameOrID = aName;
2216 if ( myIsInvalidSubMesh )
2217 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
2218 // by a valid one in an existing SO
2219 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
2222 SMESH::SMESH_subMesh_var aSubMeshVar = aMesh->GetSubMesh( aGeomVar, aNameOrID.toUtf8().data() );
2223 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2225 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
2226 theEntryList.append( aSubMeshSO->GetID().c_str() );
2229 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2231 if ( !isAccessibleDim( aDim )) continue;
2233 // find or create algorithm
2234 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2235 if ( !anAlgoVar->_is_nil() )
2236 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2237 // assign hypotheses
2238 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2240 const int aHypIndex = currentHyp( aDim, dlgType );
2241 const int aHypType = Min( dlgType, AddHyp );
2242 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2244 SMESH::SMESH_Hypothesis_var aHypVar =
2245 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2246 if ( !aHypVar->_is_nil() )
2247 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2252 // deselect geometry: next submesh should be created on other sub-shape
2253 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2254 selectObject( _PTR(SObject)() );
2257 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/true );
2262 //================================================================================
2264 * \brief Return index of current hypothesis or algorithm
2265 * \param theDim - dimension of hypothesis or algorithm
2266 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2267 * \retval int - index of current hypothesis or algorithm, -1 if None selected
2269 //================================================================================
2270 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2272 if ( 0 <= theDim && theDim <= 3 )
2273 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2278 //================================================================================
2280 * \brief Checks if a hypothesis is selected
2282 //================================================================================
2284 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2289 if ( theHypType < AddHyp ) // only one hyp can be selected
2290 return currentHyp( theDim, theHypType ) == theIndex;
2292 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2293 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2299 //================================================================================
2301 * \brief Returns nb of HypType's taking into account possible several
2302 * selected additional hypotheses which are coded as additional HypType's.
2304 //================================================================================
2306 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2308 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2311 //================================================================================
2313 * \brief Returns true if hypotheses of given dim can be assigned
2314 * \param theDim - hypotheses dimension
2315 * \retval bool - result
2317 //================================================================================
2318 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2320 return myDlg->isTabEnabled( theDim );
2323 //================================================================================
2325 * \brief Sets current hypothesis or algorithms
2326 * \param theDim - dimension of hypothesis or algorithm
2327 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2328 * \param theIndex - Index of hypothesis
2329 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2331 * Gets current hypothesis or algorithms
2333 //================================================================================
2334 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2335 const int theHypType,
2337 const bool updateHypsOnAlgoDeselection)
2339 myIgnoreAlgoSelection = true;
2340 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2341 myIgnoreAlgoSelection = false;
2343 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2345 const QStringList noHyps;
2346 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2347 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2348 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2349 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2353 //================================================================================
2355 * \brief Generates default and sets mesh/submesh name
2357 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2359 //================================================================================
2360 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2364 _PTR(Study) aStudy = SMESH::getStudy();
2367 QString aPrefix = thePrefix;
2368 if ( aPrefix.isEmpty() )
2369 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2371 _PTR(SObject) anObj;
2374 aResName = aPrefix + QString::number( i++ );
2375 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2379 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2380 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2381 aControl->setText( aResName );
2384 //================================================================================
2386 * \brief Gets algorithm or creates it if necessary
2387 * \param theDim - specifies dimension of returned hypotheses/algorifms
2388 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2390 * Gets algorithm or creates it if necessary
2392 //================================================================================
2393 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2395 SMESH::SMESH_Hypothesis_var anAlgoVar;
2397 // get type of the selected algo
2398 int aHypIndex = currentHyp( theDim, Algo );
2399 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2400 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2402 QString aHypName = dataList[ aHypIndex ]->TypeName;
2404 // get existing algorithms
2405 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
2407 existingHyps( theDim, Algo, pComp, tmp, myExistingHyps[ theDim ][ Algo ]);
2409 // look for an existing algo of such a type
2410 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2411 THypList::iterator anIter = aHypVarList.begin();
2412 for ( ; anIter != aHypVarList.end(); anIter++)
2414 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2415 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2417 anAlgoVar = aHypVar;
2422 if (anAlgoVar->_is_nil())
2424 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2427 QString aClientLibName = aHypData->ClientLibName;
2428 if ( aClientLibName.isEmpty() )
2430 // Call hypothesis creation server method (without GUI)
2431 SMESH::SMESH_Hypothesis_var aHyp =
2432 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2437 // Get hypotheses creator client (GUI)
2438 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2442 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2444 SMESH::SMESH_Hypothesis_var aHyp =
2445 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2450 QStringList tmpList;
2451 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2452 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2455 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2456 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2458 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2459 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2461 anAlgoVar = aHypVar;
2467 return anAlgoVar._retn();
2470 //================================================================================
2472 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2474 * Called when mesh is edited only.
2476 //================================================================================
2477 void SMESHGUI_MeshOp::readMesh()
2479 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2480 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2484 if ( myIsOnGeometry )
2486 // Set name of mesh if current object is sub-mesh
2487 SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
2488 if ( !subMesh->_is_nil() )
2490 SMESH::SMESH_Mesh_var aMesh = subMesh->GetFather();
2491 if ( !aMesh->_is_nil() )
2493 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
2494 QString aMeshName = name( aMeshSO );
2495 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2497 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMesh, subMesh );
2500 if ( !myIsInvalidSubMesh )
2502 // Set name of geometry object
2503 CORBA::String_var name = SMESH::GetGeomName( pObj );
2505 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2509 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2510 QStringList anExisting, anAvailable;
2511 bool algoFound = false;
2512 const int dim1st = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2513 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2516 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2517 // find algo index among available ones
2519 anAvailable.clear();
2520 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2522 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ Algo ].first().first;
2523 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( hyp->GetName() ));
2524 availableHyps( dim, Algo, anAvailable, myAvailableHypData[ dim ][ Algo ] );
2525 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf( algoData );
2526 // if ( aHypIndex < 0 && algoData ) {
2527 // // assigned algo is incompatible with other algorithms
2528 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2529 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2531 algoFound = ( aHypIndex > -1 );
2533 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
2534 setCurrentHyp( dim, Algo, aHypIndex );
2535 // set existing and available hypothesis according to the selected algo
2536 if ( aHypIndex > -1 || !algoFound )
2537 onAlgoSelected( aHypIndex, dim );
2541 bool hypWithoutAlgo = false;
2542 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2544 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2547 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2548 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2549 setCurrentHyp( dim, hypType, -1 );
2551 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2553 // find index of required hypothesis among existing ones for this dimension and type
2554 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2555 myExistingHyps[ dim ][ hypType ] );
2556 if ( aHypIndex < 0 ) {
2557 // assigned hypothesis is incompatible with the algorithm
2558 if ( currentHyp( dim, Algo ) < 0 )
2559 { // none algo selected; it is edition for sure, of submesh maybe
2560 hypWithoutAlgo = true;
2561 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2562 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2563 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2564 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2567 setCurrentHyp( dim, hypType + i, aHypIndex );
2569 if ( hypType == MainHyp ) break; // only one main hyp allowed
2573 // make available other hyps of same type as one without algo
2574 if ( hypWithoutAlgo )
2575 onAlgoSelected( currentHyp( /*dim=*/0, Algo ), /*dim=*/0 );
2578 //================================================================================
2580 * \brief Gets name of object
2581 * \param theSO - SObject
2582 * \retval QString - name of object
2584 * Gets name of object
2586 //================================================================================
2587 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2592 _PTR(GenericAttribute) anAttr;
2593 _PTR(AttributeName) aNameAttr;
2594 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2597 aResName = aNameAttr->Value().c_str();
2603 //================================================================================
2605 * \brief Finds hypothesis in input list
2606 * \param theHyp - hypothesis to be found
2607 * \param theHypList - input list of hypotheses
2608 * \retval int - index of hypothesis or -1 if it is not found
2610 * Finds position of hypothesis in input list
2612 //================================================================================
2613 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2614 const THypList& theHypList ) const
2617 if ( !theHyp->_is_nil() )
2620 THypList::const_iterator anIter = theHypList.begin();
2621 for ( ; anIter != theHypList.end(); ++ anIter)
2623 if ( theHyp->_is_equivalent( (*anIter).first ) )
2634 //================================================================================
2636 * \brief Edits mesh or sub-mesh
2637 * \param theMess - Output parameter intended for returning error message
2638 * \param theEntryList - List of entries of published objects
2639 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2641 * Assigns new name hypotheses and algorithms to the mesh or sub-mesh
2643 //================================================================================
2644 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess, QStringList& theEntryList)
2648 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2649 if ( aSMESHGen->_is_nil() )
2652 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2653 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2657 SUIT_OverrideCursor aWaitCursor;
2660 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2661 SMESH::SetName( pObj, aName );
2662 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2664 // First, remove old algos in order to avoid messages on algorithm hiding
2665 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2667 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2669 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2670 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2671 if ( anAlgoVar->_is_nil() || // no new algo selected or
2672 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2674 // remove old algorithm
2675 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2676 myObjHyps[ dim ][ Algo ].clear();
2681 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2682 CORBA::Object_var anObject = aSObject->GetObject();
2683 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObject );
2684 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2685 bool isMesh = !aMesh->_is_nil();
2686 if ( !isMesh && !aSubMeshVar->_is_nil() )
2687 aMesh = aSubMeshVar->GetFather();
2689 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh.in());
2691 if (aSubMeshVar->_is_nil()) SMESH::SetName(aMeshSO, myDlg->objectText(SMESHGUI_MeshDlg::Obj));
2692 theEntryList.append(aMeshSO->GetID().c_str());
2695 // Assign new algorithms and hypotheses
2696 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2698 //if ( !isAccessibleDim( dim )) continue;
2700 // find or create algorithm
2701 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2703 // assign new algorithm
2704 if ( !anAlgoVar->_is_nil() && // some algo selected and
2705 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2708 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2709 else if ( !aSubMeshVar->_is_nil() )
2710 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2712 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2715 // remove deselected hypotheses
2716 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2718 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2720 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2721 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2722 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2724 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2728 // assign newly selected hypotheses
2729 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2731 const int curIndex = currentHyp( dim, dlgType );
2732 const int hypType = Min( dlgType, AddHyp );
2733 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2735 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2737 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2741 SMESH::AddHypothesisOnMesh (aMesh, hyp );
2742 else if ( !aSubMeshVar->_is_nil() )
2743 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2746 // reread all hypotheses of mesh
2747 QStringList anExisting;
2748 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2752 if ( aSubMeshVar->_is_nil() )
2754 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2755 createSubMeshOnInternalEdges( aMesh, mainGeom );
2758 myHasConcurrentSubBefore =
2759 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2764 //================================================================================
2766 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2767 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2768 * order of sub-mesh computation.
2769 * Returns \c true if a sub-mesh concurrency detected.
2771 //================================================================================
2773 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2774 SMESH::SMESH_subMesh_ptr submesh,
2777 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2780 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2781 if ( isNewConcurrent && askUser )
2783 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2784 tr("CONCURRENT_SUBMESH_APPEARS"),
2785 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2788 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2789 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2790 if ( meshSO && aSelectionMgr )
2792 myDlg->setEnabled( false ); // disactivate selection
2793 selectionMgr()->clearFilters();
2794 selectObject( meshSO );
2795 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2796 qApp->processEvents();
2798 myDlg->setEnabled( true );
2799 int obj = myDlg->getActiveObject();
2800 onActivateObject( obj ); // restore filter
2803 selectObject( SMESH::FindSObject( submesh ));
2810 return isNewConcurrent;
2813 //================================================================================
2815 * \brief Verifies whether given operator is valid for this one
2816 * \param theOtherOp - other operation
2817 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2819 * method redefined from base class verifies whether given operator is valid for
2820 * this one (i.e. can be started "above" this operator). In current implementation method
2821 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2824 //================================================================================
2825 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2827 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2830 //================================================================================
2832 * \brief SLOT. Is called when the user selects a way of geometry selection
2833 * \param theByMesh - true if the user wants to find geometry by mesh element
2835 //================================================================================
2836 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2839 if ( !myShapeByMeshOp ) {
2840 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2841 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2842 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2843 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2844 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2846 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2847 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2848 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2849 SMESH::SMESH_Mesh_var aMesh =
2850 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2851 if ( !aMesh->_is_nil() ) {
2852 myDlg->hide(); // stop processing selection
2853 myShapeByMeshOp->setModule( getSMESHGUI() );
2854 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2855 myShapeByMeshOp->SetMesh( aMesh );
2856 myShapeByMeshOp->start();
2862 //================================================================================
2864 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2866 //================================================================================
2867 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2869 if ( myShapeByMeshOp == op ) {
2870 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2872 // Select a found geometry object
2873 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2874 if ( !aGeomVar->_is_nil() )
2876 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2877 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2878 selectObject( aGeomSO );
2885 //================================================================================
2887 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2889 //================================================================================
2890 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2892 if ( myShapeByMeshOp == op && myDlg ) {
2897 //================================================================================
2899 * \brief Selects a SObject
2900 * \param theSObj - the SObject to select
2902 //================================================================================
2903 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2905 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2906 SALOME_ListIO anIOList;
2908 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2909 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2910 anIOList.Append( anIO );
2912 sm->setSelectedObjects( anIOList, false );
2915 //================================================================================
2917 * \brief Update available list of mesh types
2919 //================================================================================
2920 void SMESHGUI_MeshOp::updateMeshTypeList()
2922 QStringList meshTypes;
2923 meshTypes.append( tr( "MT_ANY" ) );
2924 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2926 meshTypes.append( tr( "MT_TRIANGULAR" ) );
2927 meshTypes.append( tr( "MT_QUADRILATERAL" ) );
2929 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2931 meshTypes.append( tr( "MT_TETRAHEDRAL" ) );
2932 meshTypes.append( tr( "MT_HEXAHEDRAL" ) );
2935 myDlg->setAvailableMeshType( meshTypes );
2938 //================================================================================
2940 * \brief Update available list of hypothesis sets
2942 //================================================================================
2943 void SMESHGUI_MeshOp::updateHypoSets()
2945 // get available algorithms taking into account geometry and mesh type
2946 QStringList algosAvailable;
2947 if ( myDlg->currentMeshType() != MT_ANY )
2948 for ( int dim = 0; dim <= 3; ++dim )
2949 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
2951 THypDataList anAvailableAlgsData;
2952 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( myMaxShapeDim );
2953 QStringList aFilteredHypothesesSetsList;
2954 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2955 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2957 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2958 HypothesesSet::SetType sType;
2959 for ( sType = HypothesesSet::MAIN; sType <= HypothesesSet::ALT; SMESHUtils::Increment( sType ))
2961 bool isAvailable = false;
2962 for ( currentHypoSet->init( true, sType ); currentHypoSet->more(); currentHypoSet->next() )
2964 isAvailable = false;
2965 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2966 for ( int dim = SMESH::DIM_0D; dim <= myMaxShapeDim; dim++) {
2967 int aCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoDataIn );
2968 if ( aCurrentAvailableAlgo > -1 ) {
2977 currentHypoSet->setAlgoAvailable( sType, isAvailable );
2979 if ( currentHypoSet->hasAlgo( HypothesesSet::MAIN ) &&
2980 currentHypoSet->hasAlgo( HypothesesSet::ALT ))
2982 HypothesesSet::SetType setType = HypothesesSet::getPreferredHypType();
2983 if ( !currentHypoSet->getAlgoAvailable( setType ))
2984 continue; // not add if a preferred type not available currently
2987 if ( currentHypoSet->getAlgoAvailable( HypothesesSet::MAIN ) ||
2988 currentHypoSet->getAlgoAvailable( HypothesesSet::ALT ))
2990 aFilteredHypothesesSetsList.append( *inHypoSetName );
2993 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2996 //================================================================================
2998 * \brief SLOT. Is called when the user select type of mesh
2999 * \param theTabIndex - Index of current active tab
3000 * \param theIndex - Index of current type of mesh
3002 //================================================================================
3003 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int /*theTabIndex*/, const int /*theIndex*/ )
3005 setFilteredAlgoData();