1 // Copyright (C) 2007-2023 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 Creates or edits mesh
131 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
133 * Virtual slot redefined from the base class called when "Apply" button is clicked
134 * creates or edits mesh
136 //================================================================================
137 bool SMESHGUI_MeshOp::onApply()
139 if (SMESHGUI::isStudyLocked())
143 if ( !isValid( aMess ) )
147 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
151 bool aResult = false;
155 QStringList anEntryList;
156 if ( myToCreate && myIsMesh )
157 aResult = createMesh( aMess, anEntryList );
158 if (( myToCreate && !myIsMesh ) || myIsInvalidSubMesh )
159 aResult = createSubMesh( aMess, anEntryList );
160 else if ( !myToCreate )
161 aResult = editMeshOrSubMesh( aMess, anEntryList );
164 SMESHGUI::Modified();
165 update( UF_ObjBrowser | UF_Model );
166 if( LightApp_Application* anApp =
167 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
168 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
171 catch ( const SALOME::SALOME_Exception& S_ex )
173 SalomeApp_Tools::QtCatchCorbaException( S_ex );
189 aMess = tr( "SMESH_OPERATION_FAILED" );
190 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
198 //================================================================================
200 * \brief Creates dialog if necessary and shows it
202 * Virtual method redefined from base class called when operation is started creates
203 * dialog if necessary and shows it, activates selection
205 //================================================================================
206 void SMESHGUI_MeshOp::startOperation()
208 myIgnoreAlgoSelection = false;
212 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
213 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
215 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
216 this, SLOT( onCreateHyp( const int, const int ) ) );
217 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
218 this, SLOT( onEditHyp( const int, const int ) ) );
219 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
220 this, SLOT( onAlgoSelected( const int ) ) );
222 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
223 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
224 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
227 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
228 else myHelpFileName = "constructing_submeshes.html";
231 myHelpFileName = "editing_meshes.html";
234 SMESHGUI_SelectionOp::startOperation();
236 // clear available hypotheses
238 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
240 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
242 aTab->setAvailableHyps( Algo, hypList );
243 aTab->setAvailableHyps( MainHyp, hypList );
244 aTab->setAvailableHyps( AddHyp, hypList );
245 aTab->setExistingHyps( MainHyp, hypList );
246 aTab->setExistingHyps( AddHyp, hypList );
247 myExistingHyps[ i ][ MainHyp ].clear();
248 myExistingHyps[ i ][ AddHyp ].clear();
253 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
257 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
260 updateMeshTypeList();
261 myDlg->setCurrentMeshType( MT_ANY );
263 myDlg->setCurrentTab( SMESH::DIM_3D );
264 myDlg->setGeomPopupEnabled(false);
270 myHasConcurrentSubBefore = false;
271 myObjectToSelect.clear();
274 //=================================================================================
276 * \brief Selects a recently created mesh or sub-mesh if necessary
278 * Virtual method redefined from base class called when operation is committed
279 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
280 * selection when the custom selection filters are removed.
282 //=================================================================================
283 void SMESHGUI_MeshOp::commitOperation()
285 SMESHGUI_SelectionOp::commitOperation();
287 if ( !myObjectToSelect.isEmpty() ) {
288 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
289 SUIT_DataOwnerPtrList aList;
290 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
291 aSelectionMgr->setSelected( aList );
296 //================================================================================
298 * \brief Creates selection filter
299 * \param theId - identifier of current selection widget
300 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
302 * Creates selection filter in accordance with identifier of current selection widget
304 //================================================================================
305 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
307 if ( theId == SMESHGUI_MeshDlg::Geom )
309 // TColStd_MapOfInteger allTypesMap;
310 // for ( int i = 0; i < 10; i++ )
311 // allTypesMap.Add( i );
312 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
313 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
315 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
316 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
317 else if ( theId == SMESHGUI_MeshDlg::Mesh )
318 return new SMESH_TypeFilter( SMESH::MESH );
323 //================================================================================
325 * \brief check if selected shape is a sub-shape of the shape to mesh
326 * \retval bool - check result
328 //================================================================================
329 bool SMESHGUI_MeshOp::isSubshapeOk() const
331 if ( !myToCreate || myIsMesh ) // not submesh creation
335 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
336 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
337 if (!pMesh) return false;
339 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
340 if (mesh->_is_nil()) return false;
342 // main shape of the mesh
343 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
344 if (mainGeom->_is_nil()) return false;
348 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
350 // check all selected shapes
351 for ( QString& aSubGeomEntry : aGEOMs )
353 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID( aSubGeomEntry.toUtf8().data() );
354 if ( !pSubGeom ) return false;
356 GEOM::GEOM_Object_var subGeom =
357 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
359 if ( SMESH::ContainsSubShape( mainGeom, subGeom, false ))
366 //================================================================================
368 * \brief Return name of the algorithm that does not support sub-meshes and makes
369 * sub-mesh creation useless
370 * \retval char* - string is to be deleted!!!
372 //================================================================================
373 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
375 if ( myToCreate && !myIsMesh ) {
377 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
378 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
379 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
382 QStringList algoNames;
384 existingHyps(3, Algo, pMesh, algoNames, algoList);
385 if (!algoList.empty()) {
386 HypothesisData* algo =
387 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
389 algo->InputTypes.empty() && // builds all dimensions it-self
390 !algo->IsSupportSubmeshes )
391 return CORBA::string_dup( algoNames[0].toUtf8().data() );
394 // GEOM::GEOM_Object_var geom;
395 // if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() ))
396 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
398 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
399 existingHyps(2, Algo, pMesh, algoNames, algoList);
400 if (!algoList.empty()) {
401 HypothesisData* algo =
402 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
404 algo->InputTypes.empty() && // builds all dimensions it-self
405 !algo->IsSupportSubmeshes )
406 return CORBA::string_dup( algoNames[0].toUtf8().data() );
414 //================================================================================
416 * \brief find an existing submesh by the selected shape
417 * \retval _PTR(SObject) - the found submesh SObject
419 //================================================================================
420 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
422 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
423 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
424 if ( pMesh && !myGeom->_is_nil() ) {
426 switch ( myGeom->GetShapeType() ) {
427 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
428 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
429 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
430 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
431 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
432 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
433 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
436 _PTR(GenericAttribute) anAttr;
437 _PTR(SObject) aSubmeshRoot;
438 _PTR(Study) aStudy = SMESH::getStudy();
439 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
441 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
442 for ( ; smIter->More(); smIter->Next() )
444 _PTR(SObject) aSmObj = smIter->Value();
445 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
447 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
448 for ( ; anIter1->More(); anIter1->Next()) {
449 _PTR(SObject) pGeom2 = anIter1->Value();
450 if ( pGeom2->ReferencedObject( pGeom2 ) &&
451 myGeomEntry == pGeom2->GetID().c_str() )
457 return _PTR(SObject)();
460 //================================================================================
462 * \brief Updates dialog's look and feel
464 * Virtual method redefined from the base class updates dialog's look and feel
466 //================================================================================
467 void SMESHGUI_MeshOp::selectionDone()
469 if (!dlg()->isVisible() || !myDlg->isEnabled())
472 SMESHGUI_SelectionOp::selectionDone();
475 myGeom = GEOM::GEOM_Object::_nil();
476 myIsInvalidSubMesh = false;
477 myIsOnGeometry = true;
481 // allow selecting multiple geom objects only for sub-mesh creation
483 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aGEOMs );
484 int nbGeoms = aGEOMs.count();
487 myGeomEntry = aGEOMs[0];
488 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( myGeomEntry.toUtf8().data() );
489 if ( nbGeoms > 1 && myToCreate && myIsMesh )
491 selectObject( pGeom );
495 myGeom = SMESH::SObjectToInterface< GEOM::GEOM_Object >( pGeom ); // creation case
498 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
499 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
501 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface< SMESH::SMESH_Mesh >( pObj );
502 SMESH::SMESH_subMesh_var subMesh;
504 if ( !myToCreate ) // edition: read hypotheses
508 subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
509 myIsMesh = subMesh->_is_nil();
510 myGeom = SMESH::GetShapeOnMeshOrSubMesh( pObj );
511 myIsInvalidSubMesh = ( !myIsMesh && subMesh->GetId() < 1 );
512 if ( !mesh->_is_nil() && !mesh->HasShapeToMesh() )
514 myIsOnGeometry = false;
515 myGeom = GEOM::GEOM_Object::_nil();
517 if ( !myGeom->_is_nil() )
518 myGeomEntry = myGeom->GetStudyEntry();
520 myDlg->setTitile( myToCreate, myIsMesh );
521 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !subMesh->_is_nil() );
522 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, !myGeom->_is_nil() );
523 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
524 if ( myIsInvalidSubMesh )
526 // it is necessary to select a new geometry
527 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->show();
528 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
532 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
534 myDlg->updateGeometry();
541 else if ( !myIsMesh ) // sub-mesh creation
543 // if a submesh on the selected shape already exist, pass to submesh edition mode
544 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
545 subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
546 bool editSubmesh = ( !subMesh->_is_nil() &&
547 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
548 tr( "EDIT_SUBMESH_QUESTION"),
549 SUIT_MessageBox::Yes |
551 SUIT_MessageBox::No )
552 == SUIT_MessageBox::Yes );
555 selectionMgr()->clearFilters();
556 selectObject( pSubmesh );
557 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
562 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
563 selectObject( _PTR(SObject)() );
568 // discard selected mesh if submesh creation not allowed because of
569 // a global algorithm that does not support submeshes
570 if ( char* algoName = isSubmeshIgnored() ) {
571 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
572 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
573 CORBA::string_free( algoName );
574 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
575 selectObject( _PTR(SObject)() );
580 // enable/disable popup for choice of geom selection way
582 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
583 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toLatin1().data() ))
585 mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
586 if ( !mesh->_is_nil() )
587 enable = /*( shapeDim > 1 ) && */( mesh->NbEdges() > 0 );
589 myDlg->setGeomPopupEnabled( enable );
591 //rnv: issue 21056: "Create Sub Mesh": focus should automatically switch to geometry
592 if ( pObj && myGeomEntry.isEmpty() )
593 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
596 setFilteredAlgoData();
599 catch ( const SALOME::SALOME_Exception& S_ex )
601 SalomeApp_Tools::QtCatchCorbaException( S_ex );
608 //================================================================================
610 * \brief Verifies validity of input data
611 * \param theMess - Output parameter intended for returning error message
612 * \retval bool - TRUE if input data is valid, false otherwise
614 * Verifies validity of input data. This method is called when "Apply" or "OK" button
615 * is pressed before mesh creation or editing.
617 //================================================================================
618 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
620 // Selected object to be edited
621 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
623 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
628 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
629 if ( aMeshName.isEmpty() )
631 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
635 /* // Imported mesh, if create sub-mesh or edit mesh
636 if ( !myToCreate || ( myToCreate && !myIsMesh ))
638 QString aMeshEntry = myDlg->selectedObject
639 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
640 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
641 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
642 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
643 theMess = tr( "IMPORTED_MESH" );
650 if ( myToCreate || myIsInvalidSubMesh )
652 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
653 if ( aGeomEntry.isEmpty() )
655 theMess = tr( myIsMesh ?
656 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
657 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
661 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
662 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
669 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
670 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
672 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
677 if ( !myIsMesh ) // i.e sub-mesh creation,
679 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
680 if ( aMeshEntry == "" )
682 theMess = tr( "MESH_IS_NOT_DEFINED" );
685 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
686 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
688 theMess = tr( "MESH_IS_NULL" );
691 if ( !isSubshapeOk() )
693 theMess = tr( "INVALID_SUBSHAPE" );
702 //================================================================================
704 * \brief check compatibility of the algorithm and another algorithm or hypothesis
705 * \param theAlgoData - algorithm data
706 * \param theHypData - hypothesis data
707 * \param theHypType - hypothesis type
708 * \retval bool - check result
710 //================================================================================
711 static bool isCompatible(const HypothesisData* theAlgoData,
712 const HypothesisData* theHypData,
713 const int theHypType)
718 if ( theHypType == SMESHGUI_MeshOp::Algo ) // compatibility of 2 algos
719 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
721 bool isOptional; // compatibility of algo and hyp
722 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
725 //================================================================================
727 * \brief check compatibility of the geometry
728 * \param theAlgoData - to select hypos able to be used by this algo
729 * \param theDim - algo dimension
730 * \retval bool - check result
732 //================================================================================
733 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
736 if ( theDim < 1 || myGeom->_is_nil() )
739 bool isApplicable = false;
740 if ( myGeomEntry == myLastGeomEntry && !myGeomEntry.isEmpty() ) {
741 THypLabelIsAppMap::const_iterator lab2isApp = myHypMapIsApplicable.find( theAlgoData->TypeName );
742 if ( lab2isApp != myHypMapIsApplicable.end() ) {
743 isApplicable = lab2isApp.value();
747 bool toCheckIsApplicableToAll = !myIsMesh;
748 if ( toCheckIsApplicableToAll )
749 toCheckIsApplicableToAll = ( myGeom->GetType() == GEOM_GROUP );
751 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, myGeom, toCheckIsApplicableToAll );
752 myHypMapIsApplicable.insert( theAlgoData->TypeName, isApplicable );
756 //================================================================================
758 * \brief check compatibility of the mesh type
759 * \param theAlgoData - to select hypos able to be used by this algo
760 * \param theDim - algo dimension
761 * \retval bool - check result
763 //================================================================================
764 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
771 int curMeshType = myDlg->currentMeshType();
772 switch ( curMeshType ) {
782 case MT_QUADRILATERAL:
806 bool isAvailableAlgo = theAlgoData->OutputTypes.isEmpty();
807 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
808 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ )
810 if ( *inElemType == elemType )
812 isAvailableAlgo = true;
816 return isAvailableAlgo;
819 //================================================================================
821 * \brief Get available hypotheses or algorithms
822 * \param theDim - specifies dimension of returned hypotheses/algorifms
823 * \param theHypType - specifies whether algorims or hypotheses or additional ones
824 * are retrieved (possible values are in HypType enumeration)
825 * \param theHyps - output list of hypotheses' names
826 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
827 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
828 * \param theMeshType - type of mesh for filtering algorithms (optional)
830 * Get available hypotheses or algorithm in accordance with input parameters.
831 * Result (\a theHyps) optionally depends on the following:
832 * - selected algorithm(s)
833 * - selected geometry
834 * - selected mesh type
836 //================================================================================
837 void SMESHGUI_MeshOp::availableHyps( const int theDim,
838 const int theHypType,
839 QStringList& theHyps,
840 THypDataList& theDataList,
841 HypothesisData* thePrevAlgoData,
842 HypothesisData* theNextAlgoData,
843 const QString& /*theMeshType*/)
847 bool isAlgo = ( theHypType == Algo );
848 bool isAux = ( theHypType >= AddHyp );
849 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
851 std::multimap< double, HypothesisData* > sortedHyps;
852 QStringList::const_iterator anIter;
853 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
855 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
856 if ( isCompatible( thePrevAlgoData, aData, theHypType ) &&
857 isCompatible( theNextAlgoData, aData, theHypType ) &&
858 isCompatibleToGeometry( aData, theDim ) &&
859 isCompatibleToMeshType( aData, theDim ))
861 int groupID = aData->GroupID;
862 int priority = aData->Priority;
863 if ( groupID < 0 || groupID > 9 ) groupID = 9;
864 if ( priority < 0 || priority > 999 ) priority = 999;
866 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
870 if ( !sortedHyps.empty() )
872 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
873 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
874 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
876 HypothesisData* aData = key_hyp->second;
877 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
878 if ( aPrevGroup != aGroup )
880 theDataList.append( aGroup );
881 theHyps.append( aGroup->Label );
884 theDataList.append( aData );
885 theHyps.append( aData->Label );
890 //================================================================================
892 * \brief Gets existing hypotheses or algorithms
893 * \param theDim - specifies dimension of returned hypotheses/algorifms
894 * \param theHypType - specifies whether algorims or hypotheses or additional ones
895 * are retrieved (possible values are in HypType enumeration)
896 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
897 * \param theHyps - output list of names.
898 * \param theHypVars - output list of variables.
899 * \param theAlgoData - to select hypos able to be used by this algo (optional)
901 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
904 * WARNING: when using this method to get hyps existing in Mesh component,
905 * call availableHyps() before in order to get only hyps of available types
906 * that was filtered by availableHyps()
908 //================================================================================
909 void SMESHGUI_MeshOp::existingHyps( const int theDim,
910 const int theHypType,
911 _PTR(SObject) theFather,
912 QStringList& theHyps,
913 THypList& theHypList,
914 HypothesisData* theAlgoData) const
916 // Clear hypoheses list
923 _PTR(SObject) aHypRoot;
924 _PTR(GenericAttribute) anAttr;
925 _PTR(AttributeName) aName;
926 _PTR(AttributeIOR) anIOR;
928 const bool isMesh = !_CAST( SComponent, theFather );
931 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
933 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
935 const bool isAux = ( theHypType >= AddHyp );
936 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
938 if ( theFather->FindSubObject( aPart, aHypRoot ) )
940 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypRoot );
941 for ( ; anIter->More(); anIter->Next() )
943 _PTR(SObject) anObj = anIter->Value();
944 if ( isMesh ) // i.e. mesh or submesh
946 _PTR(SObject) aRefObj;
947 if ( anObj->ReferencedObject( aRefObj ) )
952 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
955 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
956 if ( !CORBA::is_nil( aVar ) )
958 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
959 if ( !aHypVar->_is_nil() )
961 CORBA::String_var hypType = aHypVar->GetName();
962 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
963 if ( !aData) continue;
964 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
965 ( isCompatible ( theAlgoData, aData, theHypType )) &&
966 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
967 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
969 std::string aHypName = aName->Value();
970 theHyps.append( aHypName.c_str() );
971 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
980 //================================================================================
982 * \brief If create or edit a submesh, return a hypothesis holding parameters used
983 * to mesh a sub-shape
984 * \param aHypType - The hypothesis type name
985 * \param aServerLib - Server library name
986 * \param hypData - The structure holding the hypothesis type etc.
987 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
989 //================================================================================
990 SMESH::SMESH_Hypothesis_var
991 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
992 const QString& aServerLib,
993 const SMESH::HypInitParams* aParams ) const
995 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
996 return SMESH::SMESH_Hypothesis::_nil();
998 const int nbColonsInMeshEntry = 3;
999 bool isSubMesh = myToCreate ?
1001 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1003 // get mesh and geom object
1004 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1005 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1010 anEntry = myDlg->selectedObject
1011 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1012 if ( _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1014 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1015 if ( myToCreate ) // mesh and geom may be selected
1017 aMesh = SMESH::SMESH_Mesh::_narrow( Obj );
1018 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1019 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1020 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1022 else // edition: sub-mesh may be selected
1024 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1025 if ( !sm->_is_nil() ) {
1026 aMesh = sm->GetFather();
1027 aGeomVar = sm->GetSubShape();
1034 if ( !myToCreate ) // mesh to edit can be selected
1036 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1037 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1039 aMesh = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1040 if ( !aMesh->_is_nil() )
1041 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1044 if ( aGeomVar->_is_nil() ) {
1045 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1046 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1048 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1053 SMESH::HypInitParams initParams;
1054 enum { BY_MESH, BY_GEOM, BY_AVERAGE_LENGTH }; // same as ::SMESH_Hypothesis::InitWay
1057 initParams = *aParams;
1061 initParams.way = isSubMesh ? BY_MESH : BY_GEOM;
1064 SMESH::SMESH_Hypothesis_var hyp;
1065 if ( initParams.way == BY_AVERAGE_LENGTH )
1066 hyp = SMESHGUI::GetSMESHGen()->CreateHypothesisByAverageLength( aHypType.toUtf8().data(),
1067 aServerLib.toUtf8().data(),
1068 initParams.averageLength,
1069 initParams.quadDominated );
1071 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1072 aServerLib.toUtf8().data(),
1076 if ( hyp->_is_nil() && initParams.way == BY_MESH )
1078 initParams.way = BY_GEOM;
1079 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1080 aServerLib.toUtf8().data(),
1085 if ( hyp->_is_nil() && initParams.way == BY_GEOM )
1087 initParams.way = BY_AVERAGE_LENGTH;
1088 initParams.averageLength = 1.;
1089 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1090 aServerLib.toUtf8().data(),
1098 //================================================================================
1100 * \brief initialize a hypothesis creator
1102 //================================================================================
1104 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1106 if ( !theCreator ) return;
1108 // Set shapes, of mesh and sub-mesh if any
1110 // get Entry of the Geom object
1111 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1112 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1113 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1115 if ( myToCreate && myIsMesh )
1116 aMeshEntry = aGeomEntry;
1118 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1119 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1120 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1121 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1124 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1125 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1127 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1128 if ( !aGeomVar->_is_nil() )
1130 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1132 aMeshEntry = aGeomEntry;
1136 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1137 // take geometry from submesh being created
1138 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1140 // if current object is sub-mesh
1141 SMESH::SMESH_subMesh_var aSubMeshVar =
1142 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1143 if ( !aSubMeshVar->_is_nil() ) {
1144 SMESH::SMESH_Mesh_var aMesh = aSubMeshVar->GetFather();
1145 if ( !aMesh->_is_nil() ) {
1146 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
1147 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1148 if ( !aGeomVar->_is_nil() )
1149 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1155 theCreator->setShapeEntry( aGeomEntry );
1156 if ( aMeshEntry != "" )
1157 theCreator->setMainShapeEntry( aMeshEntry );
1159 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1162 //================================================================================
1164 * \Brief Returns tab dimension
1165 * \param tab - the tab in the dlg
1166 * \param dlg - my dialogue
1167 * \retval int - dimension
1169 //================================================================================
1170 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1173 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1174 if (tab == dlg->tab(i))
1179 //================================================================================
1181 * \brief Create hypothesis
1182 * \param theHypType - hypothesis category (main or additional)
1183 * \param theIndex - index of type of hypothesis to be created
1185 * Specifies dimension of hypothesis to be created (using sender() method),
1186 * specifies its type and calls method for hypothesis creation
1188 //================================================================================
1189 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1191 // Specifies dimension of hypothesis to be created
1192 int aDim = getTabDim( sender(), myDlg );
1196 // Specifies type of hypothesis to be created
1197 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1198 if (theIndex < 0 || theIndex >= dataList.count())
1200 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1202 // Create hypothesis
1203 createHypothesis(aDim, theHypType, aHypTypeName);
1208 QString GetUniqueName (const QStringList& theHypNames,
1209 const QString& theName,
1210 size_t theIteration = 1)
1212 QString aName = theName + "_" + QString::number( theIteration );
1213 if ( theHypNames.contains( aName ) )
1214 return GetUniqueName( theHypNames, theName, ++theIteration );
1219 //================================================================================
1221 * \brief Return names of all existing hypotheses
1223 //================================================================================
1225 QStringList SMESHGUI_MeshOp::getHypoNames()
1227 QStringList aHypNames;
1229 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1230 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1231 const TType2HypList& aType2HypList = aDimIter.value();
1232 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1233 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1234 const THypList& aHypList = aTypeIter.value();
1235 THypList::const_iterator anIter = aHypList.begin();
1236 for ( ; anIter != aHypList.end(); anIter++) {
1237 const THypItem& aHypItem = *anIter;
1238 const QString& aHypName = aHypItem.second;
1239 aHypNames.append(aHypName);
1246 //================================================================================
1248 * Create hypothesis and update dialog.
1249 * \param theDim - dimension of hypothesis to be created
1250 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1251 * \param theTypeName - specifies hypothesis to be created
1253 //================================================================================
1254 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1256 const QString& theTypeName)
1258 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1265 // get a unique hyp name
1266 QString aHypName = GetUniqueName( getHypoNames(), aData->Label);
1269 bool dialog = false;
1271 QString aClientLibName = aData->ClientLibName;
1272 if (aClientLibName == "") {
1273 // Call hypothesis creation server method (without GUI)
1274 SMESH::SMESH_Hypothesis_var aHyp =
1275 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1279 // Get hypotheses creator client (GUI)
1280 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1282 // Create hypothesis
1285 // Get parameters appropriate to initialize a new hypothesis
1286 SMESH::SMESH_Hypothesis_var initParamHyp =
1287 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1289 removeCustomFilters(); // Issue 0020170
1291 // set shapes, of mesh and sub-mesh if any
1292 initHypCreator( aCreator );
1294 myDlg->setEnabled( false );
1295 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1300 SMESH::SMESH_Hypothesis_var aHyp =
1301 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1310 //================================================================================
1312 * Necessary steps after hypothesis creation
1313 * \param result - creation result:
1316 * 2 = additional value meaning that slot is called not from dialog box
1318 //================================================================================
1319 void SMESHGUI_MeshOp::onHypoCreated( int result )
1323 int obj = myDlg->getActiveObject();
1324 onActivateObject( obj ); // Issue 0020170. Restore filters
1325 myDlg->setEnabled( true );
1328 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1330 int nbHyp = myExistingHyps[myDim][myType].count();
1331 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1332 QStringList aNewHyps;
1333 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1334 if (aNewHyps.count() > nbHyp)
1336 for (int i = nbHyp; i < aNewHyps.count(); i++)
1337 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1342 //================================================================================
1344 * \brief Calls plugin methods for hypothesis editing
1345 * \param theHypType - specifies whether main hypothesis or additional one
1347 * \param theIndex - index of existing hypothesis
1349 * Calls plugin methods for hypothesis editing
1351 //================================================================================
1352 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1354 // Speicfies dimension of hypothesis to be created
1355 int aDim = getTabDim( sender(), myDlg );
1359 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1360 if ( theIndex < 0 || theIndex >= aList.count() )
1362 const THypItem& aHypItem = aList[ theIndex ];
1363 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1364 if ( aHyp->_is_nil() )
1367 SMESHGUI_GenericHypothesisCreator* aCreator =
1368 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1371 // set initial parameters
1372 SMESH::SMESH_Hypothesis_var initParamHyp =
1373 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1374 SMESH::toQStr( aHyp->GetLibName() ));
1375 aCreator->setInitParamsHypothesis( initParamHyp );
1377 // set shapes, of mesh and sub-mesh if any
1378 initHypCreator( aCreator );
1380 removeCustomFilters(); // Issue 0020170
1381 myDlg->setEnabled( false );
1383 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1387 //================================================================================
1389 * Necessary steps after hypothesis edition
1390 * \param result - creation result:
1394 //================================================================================
1395 void SMESHGUI_MeshOp::onHypoEdited( int /*result*/ )
1397 int obj = myDlg->getActiveObject();
1398 onActivateObject( obj ); // Issue 0020170. Restore filters
1399 myDlg->setEnabled( true );
1402 //================================================================================
1404 * \brief access to hypothesis data
1405 * \param theDim - hyp dimension
1406 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1407 * \param theIndex - index in the list
1408 * \retval HypothesisData* - result data, may be 0
1410 //================================================================================
1411 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1412 const int theHypType,
1415 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1416 theHypType > -1 && theHypType < NbHypTypes &&
1417 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1418 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1422 //================================================================================
1424 * \brief Update list of algorithms and hypotheses according to currently selected
1425 * algorithm, geometry and mesh type
1427 //================================================================================
1428 void SMESHGUI_MeshOp::setFilteredAlgoData()
1430 // keep current algorithms
1431 HypothesisData* curAlgos[ 4 ];
1432 for ( int dim = 0; dim <= 3; ++dim )
1433 curAlgos[ dim ] = hypData( dim, Algo, currentHyp( dim, Algo ));
1435 // find out myMaxShapeDim by checking algorithm applicability to geometry
1437 int curMeshType = myDlg->currentMeshType();
1438 myDlg->setCurrentMeshType( MT_ANY );
1439 QStringList algosAvailable;
1440 // get available algorithms taking into account geometry only
1441 if ( myGeom->_is_nil() )
1445 if ( myToCreate ) // readMesh() has done it if !myToCreate
1446 for ( int dim = 0; dim <= 3; ++dim )
1447 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1451 if ( myGeomEntry != myLastGeomEntry )
1452 myHypMapIsApplicable.clear();
1454 for ( int dim = 0; dim <= 3; ++dim )
1456 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1457 if ( algosAvailable.count() )
1458 myMaxShapeDim = dim;
1460 if ( !myGeomEntry.isEmpty() )
1461 myLastGeomEntry = myGeomEntry;
1463 myDlg->setMaxHypoDim( myMaxShapeDim );
1465 // set mesh types according to myMaxShapeDim
1466 updateMeshTypeList();
1468 // update available hypo-sets that depend on geometry and mesh type
1469 myDlg->setCurrentMeshType( Max( MT_ANY, curMeshType ));
1470 updateHypoSets(); // it sets myAvailableHypData by curMeshType
1472 // restore current algorithms according to changed myAvailableHypData
1473 algosAvailable.clear();
1474 for ( int dim = 0; dim <= 3; ++dim )
1476 int algoIndex = myAvailableHypData[ dim ][ Algo ].indexOf( curAlgos[ dim ]);
1477 while ( algosAvailable.count() <= algoIndex )
1478 algosAvailable << "";
1479 myDlg->tab( dim )->setAvailableHyps( Algo, algosAvailable );
1480 setCurrentHyp( dim, Algo, algoIndex );
1481 if ( algoIndex < 0 )
1482 curAlgos[ dim ] = 0;
1485 // find a selected algo, current or of highest dimension
1486 int algoDim = myDlg->currentTab();
1487 if ( !curAlgos[ algoDim ])
1488 for ( algoDim = SMESH::DIM_3D; algoDim >= SMESH::DIM_0D; algoDim-- )
1489 if ( curAlgos[ algoDim ] )
1491 if ( algoDim < SMESH::DIM_0D )
1492 algoDim = myMaxShapeDim;
1494 // set algorithms and hypotheses according to all parameters (mesh type etc)
1495 onAlgoSelected( currentHyp( algoDim, Algo ), algoDim );
1498 //================================================================================
1500 * \brief Set available algos and hypos according to the selected algorithm
1501 * \param theIndex - algorithm index
1502 * \param theDim - algorithm dimension
1504 //================================================================================
1505 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1508 if ( myIgnoreAlgoSelection )
1511 int curDim = getTabDim( sender(), myDlg );
1512 int aDim = theDim < 0 ? curDim : theDim;
1516 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1518 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1519 HypothesisData* algoByDim[4];
1520 algoByDim[ aDim ] = algoData;
1522 QStringList anAvailable;
1523 const int algoDim = aDim;
1525 // 2 loops: backward and forward from algo dimension (forward == to higher dimension)
1526 for ( int forward = 1; forward >= 0; --forward )
1528 int dim = algoDim, lastDim = SMESH::DIM_3D, dir = 1;
1530 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1532 //bool noCompatible = false;
1533 for ( ; dim * dir <= lastDim * dir; dim += dir)
1535 // if ( noCompatible ) // the selected algo has no compatible ones (like 1D2D3D algo)
1537 // anAvailable.clear();
1538 // myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1539 // myAvailableHypData[dim][Algo].clear();
1540 // algoByDim[ dim ] = 0;
1544 int algoIndex = currentHyp( dim, Algo );
1545 HypothesisData *curAlgo = hypData( dim, Algo, algoIndex );
1547 // set new available algorithms
1548 HypothesisData *prevAlgo = 0;
1549 if ( dim != algoDim )
1550 for ( int prevDim = dim + 1; prevDim <=3 && !prevAlgo; ++prevDim )
1551 prevAlgo = hypData( prevDim, Algo, currentHyp( prevDim, Algo ));
1552 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1553 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1555 //noCompatible = ( prevAlgo && !forward && anAvailable.isEmpty() );
1558 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1559 setCurrentHyp( dim, Algo, algoIndex, /*updateHyps=*/true );
1561 algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1564 // activate tabs according to algorithms availability
1565 if ( anAvailable.isEmpty() ) myDlg->disableTab( dim );
1566 else myDlg->enableTab( dim );
1569 } // loops backward and forward
1572 // set hypotheses corresponding to the found algorithms
1574 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
1576 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1578 if ( !isAccessibleDim( dim ))
1581 // get indices of selected hyps
1582 const int nbTypes = nbDlgHypTypes(dim);
1583 std::vector<int> hypIndexByType( nbTypes, -1 );
1584 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1586 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1590 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1592 const int type = Min( dlgType, AddHyp );
1593 myAvailableHypData[ dim ][ type ].clear();
1594 QStringList anAvailable, anExisting;
1596 HypothesisData* curAlgo = algoByDim[ dim ];
1597 int hypIndex = hypIndexByType[ dlgType ];
1599 SMESH::SMESH_Hypothesis_var curHyp;
1601 HypothesisData* hypData = 0;
1602 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1604 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1605 if ( !curHyp->_is_nil() )
1607 curHypType = SMESH::toQStr( curHyp->GetName() );
1608 hypData = SMESH::GetHypothesisData( curHypType );
1611 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) // edition, algo not selected
1613 // try to find algo by selected hypothesis in order to keep it selected
1614 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1615 if ( !algoDeselectedByUser &&
1616 myObjHyps[ dim ][ type ].count() > 0 &&
1617 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1619 for ( int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i )
1621 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1622 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1630 // get hyps compatible with curAlgo
1631 bool defaulHypAvlbl = false;
1634 if ( hypData && !isCompatible( curAlgo, hypData, type ))
1635 curHyp = SMESH::SMESH_Hypothesis::_nil();
1636 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo );
1637 existingHyps ( dim, type, pComp, anExisting, myExistingHyps[ dim ][ type ], curAlgo );
1638 defaulHypAvlbl = ( type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1640 // set list of hypotheses
1641 if ( dlgType <= AddHyp )
1643 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1644 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1646 // set current existing hypothesis
1647 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1648 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1651 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1653 // none is yet selected => select the sole existing if it is not optional
1654 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1655 bool isOptional = true;
1656 if ( algoByDim[ dim ] &&
1657 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1661 setCurrentHyp( dim, dlgType, hypIndex );
1667 //================================================================================
1669 * \brief Create a sub-mesh on internal edges in the case where the global algorithm
1670 * is of type 1D-2D[-3D] so that the internal edges would remain not meshed.
1672 //================================================================================
1674 void SMESHGUI_MeshOp::createSubMeshOnInternalEdges( SMESH::SMESH_Mesh_ptr theMesh,
1675 GEOM::GEOM_Object_ptr theMainShape )
1677 if ( theMesh->_is_nil() || theMainShape->_is_nil() )
1680 if ( isAccessibleDim( 1 ))
1681 return; // global 1D algorithm is/can be assigned
1683 const HypothesesSet::SetType internSet = HypothesesSet::INTERN;
1684 bool toCreate = true;
1685 bool toCreateMandatory = ( myHypoSet &&
1686 myAverageSize > 0 &&
1687 ( myHypoSet->init( /*algo=*/ true, internSet ), myHypoSet->more()) &&
1688 ( myHypoSet->init( /*algo=*/false, internSet ), myHypoSet->more()));
1689 if ( !toCreateMandatory ) // ask the user
1690 toCreate = false; // can't pass both mesh and geometry to Create Submesh operation (so far?)
1691 // toCreate = SUIT_MessageBox::warning( SMESHGUI::desktop(),
1692 // QObject::tr("SMESH_WRN_WARNING"),
1693 // QObject::tr("SMESH_CREATE_SUBMESH_ON_INTERNAL_EDGES"),
1694 // QObject::tr("SMESH_BUT_YES"),
1695 // QObject::tr("SMESH_BUT_NO"), 1, 0);
1700 if ( !GEOMBase::GetShape( theMainShape, shape ))
1703 std::vector< TopoDS_Shape > internalEdges;
1704 for ( TopExp_Explorer edge( shape, TopAbs_EDGE, TopAbs_WIRE ); edge.More(); edge.Next() )
1705 internalEdges.push_back( edge.Current() );
1707 if ( internalEdges.empty() )
1710 TopTools_IndexedMapOfShape shapeIDs;
1711 TopExp::MapShapes( shape, shapeIDs );
1713 std::set< int > intIDSet;
1714 for ( size_t i = 0; i < internalEdges.size(); ++i )
1715 intIDSet.insert( shapeIDs.FindIndex( internalEdges[ i ]));
1717 GEOM::GEOM_Gen_var geomGen = theMainShape->GetGen();
1718 if (geomGen->_is_nil()) return;
1720 GEOM::GEOM_Object_var edgeGroup;
1721 GEOM::GEOM_IShapesOperations_wrap sOp = geomGen->GetIShapesOperations();
1722 GEOM::GEOM_IGroupOperations_wrap gOp = geomGen->GetIGroupOperations();
1723 GEOM::ListOfGO_var geomGroups = sOp->GetExistingSubObjects( theMainShape,
1724 /*groupsOnly=*/true );
1725 for ( CORBA::ULong i = 0; i < geomGroups->length(); ++i )
1727 GEOM::ListOfLong_var ids = gOp->GetObjects( geomGroups[ i ]);
1728 std::set< int > idSet( & ids[0], & ids[0] + ids->length() );
1729 if ( idSet == intIDSet )
1731 edgeGroup = geomGroups[ i ];
1736 if ( edgeGroup->_is_nil() )
1738 GEOM::GEOM_Object_var edgeGroup = gOp->CreateGroup( theMainShape, TopAbs_EDGE );
1740 GEOM::ListOfLong_var edgeIDs = new GEOM::ListOfLong;
1741 edgeIDs->length( internalEdges.size() );
1742 std::set< int >::iterator id = intIDSet.begin();
1743 for ( size_t i = 0; i < intIDSet.size(); ++i, ++id )
1745 gOp->UnionIDs( edgeGroup, edgeIDs );
1747 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( edgeGroup, "Internal edges", theMainShape );
1750 if ( !toCreateMandatory )
1752 // show Create Sub-mesh dislog
1753 // _PTR(SObject) aMeshSO = SMESH::FindSObject( theMesh );
1754 // selectionMgr()->clearFilters();
1755 // selectObject( pSubmesh );
1756 // SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
1760 // create a sub-mesh using myAverageSize w/o GUI
1762 SMESH::SMESH_subMesh_var subMesh = theMesh->GetSubMesh( edgeGroup, "" );
1764 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1765 for ( myHypoSet->init( isAlgo, internSet ); myHypoSet->more(); myHypoSet->next() )
1767 QString aHypoTypeName = myHypoSet->current();
1768 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1772 myDim = aHypData->Dim[0];
1776 // create or/and set
1777 SMESH::SMESH_Hypothesis_var newHypo;
1780 myAvailableHypData[ myDim ][ Algo ].clear();
1781 myAvailableHypData[ myDim ][ Algo ] << aHypData;
1782 QStringList hypList; hypList << aHypoTypeName;
1783 myDlg->tab( myDim )->setAvailableHyps( Algo, hypList );
1784 setCurrentHyp( myDim, Algo, 0 );
1785 newHypo = getAlgo( myDim );
1789 SMESH::HypInitParams params = { 2, myAverageSize, false };
1790 newHypo = getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1791 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1792 SALOMEDS::SObject_wrap so =
1793 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), newHypo,
1794 hypName.toUtf8().data() );
1796 SMESH::AddHypothesisOnSubMesh( subMesh, newHypo );
1802 //================================================================================
1804 * \brief Ask the user to enter an average size which will be used to create
1805 * hypotheses of a hypo-set basing on this size
1806 * \param [out] averageSize - average element size
1807 * \return bool - false if the user canceled the dialog
1809 //================================================================================
1811 bool SMESHGUI_MeshOp::getAverageSize( double & averageSize )
1813 HypothesisData* hypData = SMESH::GetHypothesisData( "MaxLength" );
1817 SMESH::SMESH_Hypothesis_var hyp = getInitParamsHypothesis( hypData->TypeName,
1818 hypData->ServerLibName );
1819 if ( hyp->_is_nil() )
1822 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( hypData->TypeName );
1826 initHypCreator( aCreator );
1827 myDlg->setEnabled( false );
1829 aCreator->edit( hyp.in(), HypothesesSet::getCommonHypoSetHypoType(),
1830 dlg(), this, SLOT( onHypoEdited( int )));
1832 StdMeshers::StdMeshers_MaxLength_var lenHyp = StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
1833 if ( lenHyp->_is_nil() )
1836 averageSize = lenHyp->GetLength();
1840 //================================================================================
1842 * \brief Creates and selects hypothesis of hypotheses set
1843 * \param theSetName - The name of hypotheses set
1845 //================================================================================
1846 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1848 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1849 myHypoSet = aHypoSet;
1854 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++)
1856 setCurrentHyp(dim, Algo, -1);
1857 setCurrentHyp(dim, AddHyp, -1);
1858 setCurrentHyp(dim, MainHyp, -1);
1859 onAlgoSelected( -1, dim );
1862 HypothesesSet::SetType setType = aHypoSet->getPreferredHypType();
1863 if ( !aHypoSet->getAlgoAvailable( setType ))
1865 setType = ( setType == HypothesesSet::ALT ) ? HypothesesSet::MAIN : HypothesesSet::ALT;
1866 if ( !aHypoSet->getAlgoAvailable( setType ))
1871 if ( aHypoSet->toUseCommonSize() && !getAverageSize( myAverageSize ))
1875 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1876 for ( aHypoSet->init( isAlgo, setType ); aHypoSet->more(); aHypoSet->next() )
1878 QString aHypoTypeName = aHypoSet->current();
1879 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1883 myDim = aHypData->Dim[0];
1884 // create or/and set
1887 int index = myAvailableHypData[myDim][Algo].indexOf( aHypData );
1890 setCurrentHyp( myDim, Algo, index );
1891 onAlgoSelected( index, myDim );
1892 maxDim = Max( maxDim, myDim );
1898 int index = myAvailableHypData[myDim][MainHyp].indexOf( aHypData );
1902 index = myAvailableHypData[myDim][AddHyp].indexOf( aHypData );
1906 if ( myAverageSize > 0 )
1908 SMESH::HypInitParams params = { 2, myAverageSize, aHypoSet->isQuadDominated() };
1909 SMESH::SMESH_Hypothesis_var hyp =
1910 getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1912 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1913 SALOMEDS::SObject_wrap so =
1914 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), hyp,
1915 hypName.toUtf8().data() );
1920 createHypothesis( myDim, myType, aHypoTypeName );
1927 myDlg->setCurrentTab( maxDim );
1932 //================================================================================
1934 * \brief Creates mesh
1935 * \param theMess - Output parameter intended for returning error message
1936 * \param theEntryList - List of entries of published objects
1937 * \retval bool - TRUE if mesh is created, FALSE otherwise
1939 //================================================================================
1940 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1945 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1946 if ( aList.isEmpty() )
1948 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1949 if ( aSMESHGen->_is_nil() )
1952 SMESH::SMESH_Mesh_var aMesh= aSMESHGen->CreateEmptyMesh();
1953 if ( aMesh->_is_nil() )
1956 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
1958 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1959 theEntryList.append( aMeshSO->GetID().c_str() );
1964 if ( aList.count() > 1 )
1966 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1967 int i = namePrefix.length() - 1;
1968 while ( i > 0 && namePrefix[i].isDigit() )
1970 if ( i < namePrefix.length() - 1 )
1971 namePrefix.chop( namePrefix.length() - 1 - i );
1975 QStringList::Iterator it = aList.begin();
1976 for ( int i = 0; it != aList.end(); it++, ++i )
1978 QString aGeomEntry = *it;
1979 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
1980 GEOM::GEOM_Object_var aGeomVar =
1981 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1983 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1984 if ( aSMESHGen->_is_nil() )
1987 SUIT_OverrideCursor aWaitCursor;
1990 SMESH::SMESH_Mesh_var aMesh = aSMESHGen->CreateMesh( aGeomVar );
1991 if ( aMesh->_is_nil() )
1993 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
1995 theEntryList.append( aMeshSO->GetID().c_str() );
1996 if ( i > 0 ) setDefaultName( namePrefix );
1997 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
2000 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2002 if ( !isAccessibleDim( aDim )) continue;
2004 // assign hypotheses
2005 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2007 const int aHypIndex = currentHyp( aDim, dlgType );
2008 const int aHypType = Min( dlgType, AddHyp );
2009 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2011 SMESH::SMESH_Hypothesis_var aHypVar =
2012 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2013 if ( !aHypVar->_is_nil() )
2014 SMESH::AddHypothesisOnMesh( aMesh, aHypVar );
2017 // find or create algorithm
2018 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2019 if ( !anAlgoVar->_is_nil() )
2020 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2024 if ( myDlg->toCreateAllGroups() && !aGeomVar->_is_nil() )
2026 // Create groups on all geom groups
2028 GEOM::GEOM_Gen_var geomGen = aGeomVar->GetGen();
2029 GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
2030 GEOM::ListOfGO_var geomGroups = op->GetExistingSubObjects( aGeomVar,
2031 /*groupsOnly=*/false );
2032 SMESH::SMESH_GroupOnGeom_var meshGroup;
2033 for ( CORBA::ULong iG = 0; iG < geomGroups->length(); ++iG )
2035 SMESH::ElementType elemType = SMESHGUI_GroupOnShapeOp::ElementType( geomGroups[ iG ] );
2036 if ( elemType == SMESH::ALL )
2038 if ( elemType == SMESH::ELEM0D )
2039 elemType = SMESH::NODE;
2041 CORBA::String_var name = geomGroups[ iG ]->GetName();
2043 SALOMEDS::SObject_wrap groupSO = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject( geomGroups[iG] );
2044 if (!groupSO->_is_nil())
2045 meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
2046 // if ( elemType != SMESH::NODE )
2047 // meshGroup = aMesh->CreateGroupFromGEOM( SMESH::NODE, name, geomGroups[ iG ]);
2051 createSubMeshOnInternalEdges( aMesh, aGeomVar );
2058 //================================================================================
2060 * \brief Create sub-mesh
2061 * \param theMess - Output parameter intended for returning error message
2062 * \param theEntryList - List of entries of published objects
2063 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
2065 //================================================================================
2066 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
2070 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2071 if ( aSMESHGen->_is_nil() )
2075 SMESH::SMESH_Mesh_var aMesh =
2076 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
2077 if ( aMesh->_is_nil() && myIsInvalidSubMesh )
2079 SMESH::SMESH_subMesh_var aSMVar =
2080 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
2081 if ( !aSMVar->_is_nil() )
2082 aMesh = aSMVar->GetMesh();
2084 if ( aMesh->_is_nil() )
2087 // GEOM shape of the main mesh
2088 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2090 // Name for the new sub-mesh
2091 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
2094 GEOM::GEOM_Object_var aGeomVar;
2096 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
2097 if (aGEOMs.count() == 1)
2099 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2100 QString aGeomEntry = aGEOMs.first();
2101 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2102 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2104 else if (aGEOMs.count() > 1)
2106 // create a GEOM group
2107 GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
2108 if ( !geomGen->_is_nil() ) {
2109 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
2110 if ( !op->_is_nil() )
2112 // check and add all selected GEOM objects: they must be
2113 // a sub-shapes of the main GEOM and must be of one type
2115 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
2116 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2117 aSeq->length(aGEOMs.count());
2118 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
2119 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
2120 QString aSubGeomEntry = (*aSubShapesIter);
2121 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
2122 GEOM::GEOM_Object_var aSubGeomVar =
2123 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
2124 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
2126 aGroupType = aSubShapeType;
2128 if (aSubShapeType != aGroupType)
2129 aGroupType = TopAbs_SHAPE;
2131 aSeq[iSubSh] = aSubGeomVar;
2134 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
2135 op->UnionList(aGroupVar, aSeq);
2139 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
2141 // publish the GEOM group in study
2142 QString aNewGeomGroupName ("Auto_group_for_");
2143 aNewGeomGroupName += aName;
2144 SALOMEDS::SObject_wrap aNewGroupSO =
2145 geomGen->AddInStudy( aGeomVar,
2146 aNewGeomGroupName.toUtf8().data(), mainGeom);
2153 if (aGeomVar->_is_nil())
2156 SUIT_OverrideCursor aWaitCursor;
2158 QString aNameOrID = aName;
2159 if ( myIsInvalidSubMesh )
2160 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
2161 // by a valid one in an existing SO
2162 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
2165 SMESH::SMESH_subMesh_var aSubMeshVar = aMesh->GetSubMesh( aGeomVar, aNameOrID.toUtf8().data() );
2166 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2168 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
2169 theEntryList.append( aSubMeshSO->GetID().c_str() );
2172 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2174 if ( !isAccessibleDim( aDim )) continue;
2176 // find or create algorithm
2177 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2178 if ( !anAlgoVar->_is_nil() )
2179 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2180 // assign hypotheses
2181 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2183 const int aHypIndex = currentHyp( aDim, dlgType );
2184 const int aHypType = Min( dlgType, AddHyp );
2185 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2187 SMESH::SMESH_Hypothesis_var aHypVar =
2188 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2189 if ( !aHypVar->_is_nil() )
2190 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2195 // deselect geometry: next submesh should be created on other sub-shape
2196 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2197 selectObject( _PTR(SObject)() );
2200 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/true );
2205 //================================================================================
2207 * \brief Return index of current hypothesis or algorithm
2208 * \param theDim - dimension of hypothesis or algorithm
2209 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2210 * \retval int - index of current hypothesis or algorithm, -1 if None selected
2212 //================================================================================
2213 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2215 if ( 0 <= theDim && theDim <= 3 )
2216 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2221 //================================================================================
2223 * \brief Checks if a hypothesis is selected
2225 //================================================================================
2227 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2232 if ( theHypType < AddHyp ) // only one hyp can be selected
2233 return currentHyp( theDim, theHypType ) == theIndex;
2235 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2236 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2242 //================================================================================
2244 * \brief Returns nb of HypType's taking into account possible several
2245 * selected additional hypotheses which are coded as additional HypType's.
2247 //================================================================================
2249 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2251 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2254 //================================================================================
2256 * \brief Returns true if hypotheses of given dim can be assigned
2257 * \param theDim - hypotheses dimension
2258 * \retval bool - result
2260 //================================================================================
2261 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2263 return myDlg->isTabEnabled( theDim );
2266 //================================================================================
2268 * \brief Sets current hypothesis or algorithms
2269 * \param theDim - dimension of hypothesis or algorithm
2270 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2271 * \param theIndex - Index of hypothesis
2272 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2274 * Gets current hypothesis or algorithms
2276 //================================================================================
2277 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2278 const int theHypType,
2280 const bool updateHypsOnAlgoDeselection)
2282 myIgnoreAlgoSelection = true;
2283 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2284 myIgnoreAlgoSelection = false;
2286 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2288 const QStringList noHyps;
2289 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2290 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2291 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2292 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2296 //================================================================================
2298 * \brief Generates default and sets mesh/submesh name
2300 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2302 //================================================================================
2303 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2307 _PTR(Study) aStudy = SMESH::getStudy();
2310 QString aPrefix = thePrefix;
2311 if ( aPrefix.isEmpty() )
2312 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2314 _PTR(SObject) anObj;
2317 aResName = aPrefix + QString::number( i++ );
2318 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2322 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2323 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2324 aControl->setText( aResName );
2327 //================================================================================
2329 * \brief Gets algorithm or creates it if necessary
2330 * \param theDim - specifies dimension of returned hypotheses/algorifms
2331 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2333 * Gets algorithm or creates it if necessary
2335 //================================================================================
2336 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2338 SMESH::SMESH_Hypothesis_var anAlgoVar;
2340 // get type of the selected algo
2341 int aHypIndex = currentHyp( theDim, Algo );
2342 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2343 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2345 QString aHypName = dataList[ aHypIndex ]->TypeName;
2347 // get existing algorithms
2348 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
2350 existingHyps( theDim, Algo, pComp, tmp, myExistingHyps[ theDim ][ Algo ]);
2352 // look for an existing algo of such a type
2353 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2354 THypList::iterator anIter = aHypVarList.begin();
2355 for ( ; anIter != aHypVarList.end(); anIter++)
2357 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2358 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2360 anAlgoVar = aHypVar;
2365 if (anAlgoVar->_is_nil())
2367 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2370 QString aClientLibName = aHypData->ClientLibName;
2371 if ( aClientLibName.isEmpty() )
2373 // Call hypothesis creation server method (without GUI)
2374 SMESH::SMESH_Hypothesis_var aHyp =
2375 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2380 // Get hypotheses creator client (GUI)
2381 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2385 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2387 SMESH::SMESH_Hypothesis_var aHyp =
2388 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2393 QStringList tmpList;
2394 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2395 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2398 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2399 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2401 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2402 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2404 anAlgoVar = aHypVar;
2410 return anAlgoVar._retn();
2413 //================================================================================
2415 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2417 * Called when mesh is edited only.
2419 //================================================================================
2420 void SMESHGUI_MeshOp::readMesh()
2422 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2423 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2427 if ( myIsOnGeometry )
2429 // Set name of mesh if current object is sub-mesh
2430 SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
2431 if ( !subMesh->_is_nil() )
2433 SMESH::SMESH_Mesh_var aMesh = subMesh->GetFather();
2434 if ( !aMesh->_is_nil() )
2436 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
2437 QString aMeshName = name( aMeshSO );
2438 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2440 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMesh, subMesh );
2443 if ( !myIsInvalidSubMesh )
2445 // Set name of geometry object
2446 CORBA::String_var name = SMESH::GetGeomName( pObj );
2448 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2452 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2453 QStringList anExisting, anAvailable;
2454 bool algoFound = false;
2455 const int dim1st = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2456 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2459 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2460 // find algo index among available ones
2462 anAvailable.clear();
2463 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2465 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ Algo ].first().first;
2466 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( hyp->GetName() ));
2467 availableHyps( dim, Algo, anAvailable, myAvailableHypData[ dim ][ Algo ] );
2468 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf( algoData );
2469 // if ( aHypIndex < 0 && algoData ) {
2470 // // assigned algo is incompatible with other algorithms
2471 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2472 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2474 algoFound = ( aHypIndex > -1 );
2476 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
2477 setCurrentHyp( dim, Algo, aHypIndex );
2478 // set existing and available hypothesis according to the selected algo
2479 if ( aHypIndex > -1 || !algoFound )
2480 onAlgoSelected( aHypIndex, dim );
2484 bool hypWithoutAlgo = false;
2485 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2487 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2490 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2491 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2492 setCurrentHyp( dim, hypType, -1 );
2494 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2496 // find index of required hypothesis among existing ones for this dimension and type
2497 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2498 myExistingHyps[ dim ][ hypType ] );
2499 if ( aHypIndex < 0 ) {
2500 // assigned hypothesis is incompatible with the algorithm
2501 if ( currentHyp( dim, Algo ) < 0 )
2502 { // none algo selected; it is edition for sure, of submesh maybe
2503 hypWithoutAlgo = true;
2504 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2505 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2506 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2507 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2510 setCurrentHyp( dim, hypType + i, aHypIndex );
2512 if ( hypType == MainHyp ) break; // only one main hyp allowed
2516 // make available other hyps of same type as one without algo
2517 if ( hypWithoutAlgo )
2518 onAlgoSelected( currentHyp( /*dim=*/0, Algo ), /*dim=*/0 );
2521 //================================================================================
2523 * \brief Gets name of object
2524 * \param theSO - SObject
2525 * \retval QString - name of object
2527 * Gets name of object
2529 //================================================================================
2530 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2535 _PTR(GenericAttribute) anAttr;
2536 _PTR(AttributeName) aNameAttr;
2537 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2540 aResName = aNameAttr->Value().c_str();
2546 //================================================================================
2548 * \brief Finds hypothesis in input list
2549 * \param theHyp - hypothesis to be found
2550 * \param theHypList - input list of hypotheses
2551 * \retval int - index of hypothesis or -1 if it is not found
2553 * Finds position of hypothesis in input list
2555 //================================================================================
2556 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2557 const THypList& theHypList ) const
2560 if ( !theHyp->_is_nil() )
2563 THypList::const_iterator anIter = theHypList.begin();
2564 for ( ; anIter != theHypList.end(); ++ anIter)
2566 if ( theHyp->_is_equivalent( (*anIter).first ) )
2577 //================================================================================
2579 * \brief Edits mesh or sub-mesh
2580 * \param theMess - Output parameter intended for returning error message
2581 * \param theEntryList - List of entries of published objects
2582 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2584 * Assigns new name hypotheses and algorithms to the mesh or sub-mesh
2586 //================================================================================
2587 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess, QStringList& theEntryList)
2591 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2592 if ( aSMESHGen->_is_nil() )
2595 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2596 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2600 SUIT_OverrideCursor aWaitCursor;
2603 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2604 SMESH::SetName( pObj, aName );
2605 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2607 // First, remove old algos in order to avoid messages on algorithm hiding
2608 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2610 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2612 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2613 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2614 if ( anAlgoVar->_is_nil() || // no new algo selected or
2615 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2617 // remove old algorithm
2618 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2619 myObjHyps[ dim ][ Algo ].clear();
2624 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2625 CORBA::Object_var anObject = aSObject->GetObject();
2626 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObject );
2627 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2628 bool isMesh = !aMesh->_is_nil();
2629 if ( !isMesh && !aSubMeshVar->_is_nil() )
2630 aMesh = aSubMeshVar->GetFather();
2632 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh.in());
2634 SMESH::SetName(aMeshSO, myDlg->objectText(SMESHGUI_MeshDlg::Obj));
2635 theEntryList.append(aMeshSO->GetID().c_str());
2638 // Assign new algorithms and hypotheses
2639 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2641 //if ( !isAccessibleDim( dim )) continue;
2643 // find or create algorithm
2644 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2646 // assign new algorithm
2647 if ( !anAlgoVar->_is_nil() && // some algo selected and
2648 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2651 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2652 else if ( !aSubMeshVar->_is_nil() )
2653 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2655 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2658 // remove deselected hypotheses
2659 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2661 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2663 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2664 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2665 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2667 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2671 // assign newly selected hypotheses
2672 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2674 const int curIndex = currentHyp( dim, dlgType );
2675 const int hypType = Min( dlgType, AddHyp );
2676 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2678 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2680 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2684 SMESH::AddHypothesisOnMesh (aMesh, hyp );
2685 else if ( !aSubMeshVar->_is_nil() )
2686 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2689 // reread all hypotheses of mesh
2690 QStringList anExisting;
2691 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2695 if ( aSubMeshVar->_is_nil() )
2697 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2698 createSubMeshOnInternalEdges( aMesh, mainGeom );
2701 myHasConcurrentSubBefore =
2702 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2707 //================================================================================
2709 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2710 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2711 * order of sub-mesh computation.
2712 * Returns \c true if a sub-mesh concurrency detected.
2714 //================================================================================
2716 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2717 SMESH::SMESH_subMesh_ptr submesh,
2720 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2723 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2724 if ( isNewConcurrent && askUser )
2726 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2727 tr("CONCURRENT_SUBMESH_APPEARS"),
2728 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2731 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2732 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2733 if ( meshSO && aSelectionMgr )
2735 myDlg->setEnabled( false ); // disactivate selection
2736 selectionMgr()->clearFilters();
2737 selectObject( meshSO );
2738 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2739 qApp->processEvents();
2741 myDlg->setEnabled( true );
2742 int obj = myDlg->getActiveObject();
2743 onActivateObject( obj ); // restore filter
2746 selectObject( SMESH::FindSObject( submesh ));
2753 return isNewConcurrent;
2756 //================================================================================
2758 * \brief Verifies whether given operator is valid for this one
2759 * \param theOtherOp - other operation
2760 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2762 * method redefined from base class verifies whether given operator is valid for
2763 * this one (i.e. can be started "above" this operator). In current implementation method
2764 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2767 //================================================================================
2768 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2770 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2773 //================================================================================
2775 * \brief SLOT. Is called when the user selects a way of geometry selection
2776 * \param theByMesh - true if the user wants to find geometry by mesh element
2778 //================================================================================
2779 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2782 if ( !myShapeByMeshOp ) {
2783 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2784 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2785 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2786 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2787 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2789 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2790 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2791 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2792 SMESH::SMESH_Mesh_var aMesh =
2793 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2794 if ( !aMesh->_is_nil() ) {
2795 myDlg->hide(); // stop processing selection
2796 myShapeByMeshOp->setModule( getSMESHGUI() );
2797 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2798 myShapeByMeshOp->SetMesh( aMesh );
2799 myShapeByMeshOp->start();
2805 //================================================================================
2807 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2809 //================================================================================
2810 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2812 if ( myShapeByMeshOp == op ) {
2813 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2815 // Select a found geometry object
2816 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2817 if ( !aGeomVar->_is_nil() )
2819 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2820 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2821 selectObject( aGeomSO );
2828 //================================================================================
2830 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2832 //================================================================================
2833 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2835 if ( myShapeByMeshOp == op && myDlg ) {
2840 //================================================================================
2842 * \brief Selects a SObject
2843 * \param theSObj - the SObject to select
2845 //================================================================================
2846 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2848 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2849 SALOME_ListIO anIOList;
2851 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2852 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2853 anIOList.Append( anIO );
2855 sm->setSelectedObjects( anIOList, false );
2858 //================================================================================
2860 * \brief Update available list of mesh types
2862 //================================================================================
2863 void SMESHGUI_MeshOp::updateMeshTypeList()
2865 QStringList meshTypes;
2866 meshTypes.append( tr( "MT_ANY" ) );
2867 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2869 meshTypes.append( tr( "MT_TRIANGULAR" ) );
2870 meshTypes.append( tr( "MT_QUADRILATERAL" ) );
2872 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2874 meshTypes.append( tr( "MT_TETRAHEDRAL" ) );
2875 meshTypes.append( tr( "MT_HEXAHEDRAL" ) );
2878 myDlg->setAvailableMeshType( meshTypes );
2881 //================================================================================
2883 * \brief Update available list of hypothesis sets
2885 //================================================================================
2886 void SMESHGUI_MeshOp::updateHypoSets()
2888 // get available algorithms taking into account geometry and mesh type
2889 QStringList algosAvailable;
2890 if ( myDlg->currentMeshType() != MT_ANY )
2891 for ( int dim = 0; dim <= 3; ++dim )
2892 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
2894 THypDataList anAvailableAlgsData;
2895 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( myMaxShapeDim );
2896 QStringList aFilteredHypothesesSetsList;
2897 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2898 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2900 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2901 HypothesesSet::SetType sType;
2902 for ( sType = HypothesesSet::MAIN; sType <= HypothesesSet::ALT; SMESHUtils::Increment( sType ))
2904 bool isAvailable = false;
2905 for ( currentHypoSet->init( true, sType ); currentHypoSet->more(); currentHypoSet->next() )
2907 isAvailable = false;
2908 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2909 for ( int dim = SMESH::DIM_0D; dim <= myMaxShapeDim; dim++) {
2910 int aCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoDataIn );
2911 if ( aCurrentAvailableAlgo > -1 ) {
2920 currentHypoSet->setAlgoAvailable( sType, isAvailable );
2922 if ( currentHypoSet->hasAlgo( HypothesesSet::MAIN ) &&
2923 currentHypoSet->hasAlgo( HypothesesSet::ALT ))
2925 HypothesesSet::SetType setType = HypothesesSet::getPreferredHypType();
2926 if ( !currentHypoSet->getAlgoAvailable( setType ))
2927 continue; // not add if a preferred type not available currently
2930 if ( currentHypoSet->getAlgoAvailable( HypothesesSet::MAIN ) ||
2931 currentHypoSet->getAlgoAvailable( HypothesesSet::ALT ))
2933 aFilteredHypothesesSetsList.append( *inHypoSetName );
2936 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2939 //================================================================================
2941 * \brief SLOT. Is called when the user select type of mesh
2942 * \param theTabIndex - Index of current active tab
2943 * \param theIndex - Index of current type of mesh
2945 //================================================================================
2946 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int /*theTabIndex*/, const int /*theIndex*/ )
2948 setFilteredAlgoData();