1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_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"
41 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 // SALOME GEOM includes
45 #include <GEOMImpl_Types.hxx>
46 #include <GEOM_Client.hxx>
47 #include <GEOM_SelectionFilter.h>
48 #include <GEOM_wrap.hxx>
49 #include <GeometryGUI.h>
51 // SALOME GUI includes
52 #include <LightApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <LightApp_UpdateFlags.h>
55 #include <SALOME_InteractiveObject.hxx>
56 #include <SALOME_ListIO.hxx>
57 #include <SUIT_MessageBox.h>
58 #include <SUIT_OverrideCursor.h>
59 #include <SUIT_ResourceMgr.h>
60 #include <SUIT_Session.h>
61 #include <SalomeApp_Application.h>
62 #include <SalomeApp_Tools.h>
64 // SALOME KERNEL includes
65 #include <SALOMEDS_SComponent.hxx>
66 #include <SALOMEDS_SObject.hxx>
67 #include <SALOMEDS_Study.hxx>
68 #include <SALOMEDS_wrap.hxx>
71 #include <QApplication>
73 #include <QStringList>
76 #include <BRep_Tool.hxx>
78 #include <TopExp_Explorer.hxx>
79 #include <TopTools_IndexedMapOfShape.hxx>
82 //================================================================================
85 * \param theToCreate - if this parameter is true then operation is used for creation,
86 * for editing otherwise
88 * Initialize operation
90 //================================================================================
91 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
92 : SMESHGUI_SelectionOp(),
95 myToCreate( theToCreate ),
96 myIsMesh( theIsMesh ),
97 myIsInvalidSubMesh( false )
99 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
100 GeometryGUI::InitGeomGen();
101 myIsOnGeometry = true;
105 //================================================================================
109 //================================================================================
110 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
116 //================================================================================
118 * \brief Gets dialog of this operation
119 * \retval LightApp_Dialog* - pointer to dialog of this operation
121 //================================================================================
122 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
127 //================================================================================
129 * \brief Creates or edits mesh
130 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
132 * Virtual slot redefined from the base class called when "Apply" button is clicked
133 * creates or edits mesh
135 //================================================================================
136 bool SMESHGUI_MeshOp::onApply()
138 if (SMESHGUI::isStudyLocked())
142 if ( !isValid( aMess ) )
146 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
150 bool aResult = false;
154 QStringList anEntryList;
155 if ( myToCreate && myIsMesh )
156 aResult = createMesh( aMess, anEntryList );
157 if (( myToCreate && !myIsMesh ) || myIsInvalidSubMesh )
158 aResult = createSubMesh( aMess, anEntryList );
159 else if ( !myToCreate )
160 aResult = editMeshOrSubMesh( aMess );
163 SMESHGUI::Modified();
164 update( UF_ObjBrowser | UF_Model );
165 if( LightApp_Application* anApp =
166 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
167 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
170 catch ( const SALOME::SALOME_Exception& S_ex )
172 SalomeApp_Tools::QtCatchCorbaException( S_ex );
188 aMess = tr( "SMESH_OPERATION_FAILED" );
189 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
197 //================================================================================
199 * \brief Creates dialog if necessary and shows it
201 * Virtual method redefined from base class called when operation is started creates
202 * dialog if necessary and shows it, activates selection
204 //================================================================================
205 void SMESHGUI_MeshOp::startOperation()
207 myIgnoreAlgoSelection = false;
211 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
212 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
214 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
215 this, SLOT( onCreateHyp( const int, const int ) ) );
216 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
217 this, SLOT( onEditHyp( const int, const int ) ) );
218 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
219 this, SLOT( onAlgoSelected( const int ) ) );
221 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
222 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
223 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
226 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
227 else myHelpFileName = "constructing_submeshes.html";
230 myHelpFileName = "editing_meshes.html";
233 SMESHGUI_SelectionOp::startOperation();
235 // clear available hypotheses
237 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
239 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
241 aTab->setAvailableHyps( Algo, hypList );
242 aTab->setAvailableHyps( MainHyp, hypList );
243 aTab->setAvailableHyps( AddHyp, hypList );
244 aTab->setExistingHyps( MainHyp, hypList );
245 aTab->setExistingHyps( AddHyp, hypList );
246 myExistingHyps[ i ][ MainHyp ].clear();
247 myExistingHyps[ i ][ AddHyp ].clear();
252 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
256 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
259 updateMeshTypeList();
260 myDlg->setCurrentMeshType( MT_ANY );
262 myDlg->setCurrentTab( SMESH::DIM_3D );
263 myDlg->setGeomPopupEnabled(false);
269 myHasConcurrentSubBefore = false;
270 myObjectToSelect.clear();
273 //=================================================================================
275 * \brief Selects a recently created mesh or sub-mesh if necessary
277 * Virtual method redefined from base class called when operation is committed
278 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
279 * selection when the custom selection filters are removed.
281 //=================================================================================
282 void SMESHGUI_MeshOp::commitOperation()
284 SMESHGUI_SelectionOp::commitOperation();
286 if ( !myObjectToSelect.isEmpty() ) {
287 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
288 SUIT_DataOwnerPtrList aList;
289 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
290 aSelectionMgr->setSelected( aList );
295 //================================================================================
297 * \brief Creates selection filter
298 * \param theId - identifier of current selection widget
299 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
301 * Creates selection filter in accordance with identifier of current selection widget
303 //================================================================================
304 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
306 if ( theId == SMESHGUI_MeshDlg::Geom )
308 // TColStd_MapOfInteger allTypesMap;
309 // for ( int i = 0; i < 10; i++ )
310 // allTypesMap.Add( i );
311 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
312 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
314 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
315 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
316 else if ( theId == SMESHGUI_MeshDlg::Mesh )
317 return new SMESH_TypeFilter( SMESH::MESH );
322 //================================================================================
324 * \brief check if selected shape is a sub-shape of the shape to mesh
325 * \retval bool - check result
327 //================================================================================
328 bool SMESHGUI_MeshOp::isSubshapeOk() const
330 if ( !myToCreate || myIsMesh ) // not submesh creation
334 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
335 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
336 if (!pMesh) return false;
338 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
339 if (mesh->_is_nil()) return false;
341 // main shape of the mesh
342 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
343 if (mainGeom->_is_nil()) return false;
347 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
349 // check all selected shapes
350 for ( QString& aSubGeomEntry : aGEOMs )
352 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID( aSubGeomEntry.toUtf8().data() );
353 if ( !pSubGeom ) return false;
355 GEOM::GEOM_Object_var subGeom =
356 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
358 if ( SMESH::ContainsSubShape( mainGeom, subGeom ))
365 //================================================================================
367 * \brief Return name of the algorithm that does not support sub-meshes and makes
368 * sub-mesh creation useless
369 * \retval char* - string is to be deleted!!!
371 //================================================================================
372 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
374 if ( myToCreate && !myIsMesh ) {
376 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
377 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
378 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
381 QStringList algoNames;
383 existingHyps(3, Algo, pMesh, algoNames, algoList);
384 if (!algoList.empty()) {
385 HypothesisData* algo =
386 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
388 algo->InputTypes.empty() && // builds all dimensions it-self
389 !algo->IsSupportSubmeshes )
390 return CORBA::string_dup( algoNames[0].toUtf8().data() );
393 // GEOM::GEOM_Object_var geom;
394 // if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() ))
395 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
397 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
398 existingHyps(2, Algo, pMesh, algoNames, algoList);
399 if (!algoList.empty()) {
400 HypothesisData* algo =
401 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
403 algo->InputTypes.empty() && // builds all dimensions it-self
404 !algo->IsSupportSubmeshes )
405 return CORBA::string_dup( algoNames[0].toUtf8().data() );
413 //================================================================================
415 * \brief find an existing submesh by the selected shape
416 * \retval _PTR(SObject) - the found submesh SObject
418 //================================================================================
419 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
421 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
422 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
423 if ( pMesh && !myGeom->_is_nil() ) {
425 switch ( myGeom->GetShapeType() ) {
426 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
427 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
428 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
429 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
430 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
431 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
432 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
435 _PTR(GenericAttribute) anAttr;
436 _PTR(SObject) aSubmeshRoot;
437 _PTR(Study) aStudy = SMESH::getStudy();
438 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
440 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
441 for ( ; smIter->More(); smIter->Next() )
443 _PTR(SObject) aSmObj = smIter->Value();
444 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
446 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
447 for ( ; anIter1->More(); anIter1->Next()) {
448 _PTR(SObject) pGeom2 = anIter1->Value();
449 if ( pGeom2->ReferencedObject( pGeom2 ) &&
450 myGeomEntry == pGeom2->GetID().c_str() )
456 return _PTR(SObject)();
459 //================================================================================
461 * \brief Updates dialog's look and feel
463 * Virtual method redefined from the base class updates dialog's look and feel
465 //================================================================================
466 void SMESHGUI_MeshOp::selectionDone()
468 if (!dlg()->isVisible() || !myDlg->isEnabled())
471 SMESHGUI_SelectionOp::selectionDone();
474 myGeom = GEOM::GEOM_Object::_nil();
475 myIsInvalidSubMesh = false;
476 myIsOnGeometry = true;
480 // allow selecting multiple geom objects only for sub-mesh creation
482 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aGEOMs );
483 int nbGeoms = aGEOMs.count();
486 myGeomEntry = aGEOMs[0];
487 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( myGeomEntry.toUtf8().data() );
488 if ( nbGeoms > 1 && myToCreate && myIsMesh )
490 selectObject( pGeom );
494 myGeom = SMESH::SObjectToInterface< GEOM::GEOM_Object >( pGeom ); // creation case
497 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
498 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
500 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface< SMESH::SMESH_Mesh >( pObj );
501 SMESH::SMESH_subMesh_var subMesh;
503 if ( !myToCreate ) // edition: read hypotheses
507 subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
508 myIsMesh = subMesh->_is_nil();
509 myGeom = SMESH::GetShapeOnMeshOrSubMesh( pObj );
510 myIsInvalidSubMesh = ( !myIsMesh && subMesh->GetId() < 1 );
511 if ( !mesh->_is_nil() && !mesh->HasShapeToMesh() )
513 myIsOnGeometry = false;
514 myGeom = GEOM::GEOM_Object::_nil();
516 if ( !myGeom->_is_nil() )
517 myGeomEntry = myGeom->GetStudyEntry();
519 myDlg->setTitile( myToCreate, myIsMesh );
520 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !subMesh->_is_nil() );
521 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, !myGeom->_is_nil() );
522 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
523 if ( myIsInvalidSubMesh )
525 // it is necessary to select a new geometry
526 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->show();
527 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
531 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
533 myDlg->updateGeometry();
540 else if ( !myIsMesh ) // sub-mesh creation
542 // if a submesh on the selected shape already exist, pass to submesh edition mode
543 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
544 subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
545 bool editSubmesh = ( !subMesh->_is_nil() &&
546 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
547 tr( "EDIT_SUBMESH_QUESTION"),
548 SUIT_MessageBox::Yes |
550 SUIT_MessageBox::No )
551 == SUIT_MessageBox::Yes );
554 selectionMgr()->clearFilters();
555 selectObject( pSubmesh );
556 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
561 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
562 selectObject( _PTR(SObject)() );
567 // discard selected mesh if submesh creation not allowed because of
568 // a global algorithm that does not support submeshes
569 if ( char* algoName = isSubmeshIgnored() ) {
570 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
571 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
572 CORBA::string_free( algoName );
573 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
574 selectObject( _PTR(SObject)() );
579 // enable/disable popup for choice of geom selection way
581 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
582 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toLatin1().data() ))
584 mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
585 if ( !mesh->_is_nil() )
586 enable = /*( shapeDim > 1 ) && */( mesh->NbEdges() > 0 );
588 myDlg->setGeomPopupEnabled( enable );
590 //rnv: issue 21056: "Create Sub Mesh": focus should automatically switch to geometry
591 if ( pObj && myGeomEntry.isEmpty() )
592 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
595 setFilteredAlgoData();
598 catch ( const SALOME::SALOME_Exception& S_ex )
600 SalomeApp_Tools::QtCatchCorbaException( S_ex );
607 //================================================================================
609 * \brief Verifies validity of input data
610 * \param theMess - Output parameter intended for returning error message
611 * \retval bool - TRUE if input data is valid, false otherwise
613 * Verifies validity of input data. This method is called when "Apply" or "OK" button
614 * is pressed before mesh creation or editing.
616 //================================================================================
617 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
619 // Selected object to be edited
620 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
622 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
627 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
628 if ( aMeshName.isEmpty() )
630 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
634 /* // Imported mesh, if create sub-mesh or edit mesh
635 if ( !myToCreate || ( myToCreate && !myIsMesh ))
637 QString aMeshEntry = myDlg->selectedObject
638 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
639 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
640 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
641 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
642 theMess = tr( "IMPORTED_MESH" );
649 if ( myToCreate || myIsInvalidSubMesh )
651 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
652 if ( aGeomEntry.isEmpty() )
654 theMess = tr( myIsMesh ?
655 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
656 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
660 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
661 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
668 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
669 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
671 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
676 if ( !myIsMesh ) // i.e sub-mesh creation,
678 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
679 if ( aMeshEntry == "" )
681 theMess = tr( "MESH_IS_NOT_DEFINED" );
684 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
685 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
687 theMess = tr( "MESH_IS_NULL" );
690 if ( !isSubshapeOk() )
692 theMess = tr( "INVALID_SUBSHAPE" );
701 //================================================================================
703 * \brief check compatibility of the algorithm and another algorithm or hypothesis
704 * \param theAlgoData - algorithm data
705 * \param theHypData - hypothesis data
706 * \param theHypType - hypothesis type
707 * \retval bool - check result
709 //================================================================================
710 static bool isCompatible(const HypothesisData* theAlgoData,
711 const HypothesisData* theHypData,
712 const int theHypType)
717 if ( theHypType == SMESHGUI_MeshOp::Algo ) // compatibility of 2 algos
718 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
720 bool isOptional; // compatibility of algo and hyp
721 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
724 //================================================================================
726 * \brief check compatibility of the geometry
727 * \param theAlgoData - to select hypos able to be used by this algo
728 * \param theDim - algo dimension
729 * \retval bool - check result
731 //================================================================================
732 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
735 if ( theDim < 1 || myGeom->_is_nil() )
738 bool isApplicable = false;
739 if ( myGeomEntry == myLastGeomEntry && !myGeomEntry.isEmpty() ) {
740 THypLabelIsAppMap::const_iterator lab2isApp = myHypMapIsApplicable.find( theAlgoData->TypeName );
741 if ( lab2isApp != myHypMapIsApplicable.end() ) {
742 isApplicable = lab2isApp.value();
746 bool toCheckIsApplicableToAll = !myIsMesh;
747 if ( toCheckIsApplicableToAll )
748 toCheckIsApplicableToAll = ( myGeom->GetType() == GEOM_GROUP );
750 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, myGeom, toCheckIsApplicableToAll );
751 myHypMapIsApplicable.insert( theAlgoData->TypeName, isApplicable );
755 //================================================================================
757 * \brief check compatibility of the mesh type
758 * \param theAlgoData - to select hypos able to be used by this algo
759 * \param theDim - algo dimension
760 * \retval bool - check result
762 //================================================================================
763 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
770 int curMeshType = myDlg->currentMeshType();
771 switch ( curMeshType ) {
781 case MT_QUADRILATERAL:
805 bool isAvailableAlgo = theAlgoData->OutputTypes.isEmpty();
806 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
807 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ )
809 if ( *inElemType == elemType )
811 isAvailableAlgo = true;
815 return isAvailableAlgo;
818 //================================================================================
820 * \brief Get available hypotheses or algorithms
821 * \param theDim - specifies dimension of returned hypotheses/algorifms
822 * \param theHypType - specifies whether algorims or hypotheses or additional ones
823 * are retrieved (possible values are in HypType enumeration)
824 * \param theHyps - output list of hypotheses' names
825 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
826 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
827 * \param theMeshType - type of mesh for filtering algorithms (optional)
829 * Get available hypotheses or algorithm in accordance with input parameters.
830 * Result (\a theHyps) optionally depends on the following:
831 * - selected algorithm(s)
832 * - selected geometry
833 * - selected mesh type
835 //================================================================================
836 void SMESHGUI_MeshOp::availableHyps( const int theDim,
837 const int theHypType,
838 QStringList& theHyps,
839 THypDataList& theDataList,
840 HypothesisData* thePrevAlgoData,
841 HypothesisData* theNextAlgoData,
842 const QString& /*theMeshType*/)
846 bool isAlgo = ( theHypType == Algo );
847 bool isAux = ( theHypType >= AddHyp );
848 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
850 std::multimap< double, HypothesisData* > sortedHyps;
851 QStringList::const_iterator anIter;
852 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
854 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
855 if ( isCompatible( thePrevAlgoData, aData, theHypType ) &&
856 isCompatible( theNextAlgoData, aData, theHypType ) &&
857 isCompatibleToGeometry( aData, theDim ) &&
858 isCompatibleToMeshType( aData, theDim ))
860 int groupID = aData->GroupID;
861 int priority = aData->Priority;
862 if ( groupID < 0 || groupID > 9 ) groupID = 9;
863 if ( priority < 0 || priority > 999 ) priority = 999;
865 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
869 if ( !sortedHyps.empty() )
871 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
872 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
873 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
875 HypothesisData* aData = key_hyp->second;
876 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
877 if ( aPrevGroup != aGroup )
879 theDataList.append( aGroup );
880 theHyps.append( aGroup->Label );
883 theDataList.append( aData );
884 theHyps.append( aData->Label );
889 //================================================================================
891 * \brief Gets existing hypotheses or algorithms
892 * \param theDim - specifies dimension of returned hypotheses/algorifms
893 * \param theHypType - specifies whether algorims or hypotheses or additional ones
894 * are retrieved (possible values are in HypType enumeration)
895 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
896 * \param theHyps - output list of names.
897 * \param theHypVars - output list of variables.
898 * \param theAlgoData - to select hypos able to be used by this algo (optional)
900 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
903 * WARNING: when using this method to get hyps existing in Mesh component,
904 * call availableHyps() before in order to get only hyps of available types
905 * that was filtered by availableHyps()
907 //================================================================================
908 void SMESHGUI_MeshOp::existingHyps( const int theDim,
909 const int theHypType,
910 _PTR(SObject) theFather,
911 QStringList& theHyps,
912 THypList& theHypList,
913 HypothesisData* theAlgoData) const
915 // Clear hypoheses list
922 _PTR(SObject) aHypRoot;
923 _PTR(GenericAttribute) anAttr;
924 _PTR(AttributeName) aName;
925 _PTR(AttributeIOR) anIOR;
927 const bool isMesh = !_CAST( SComponent, theFather );
930 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
932 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
934 const bool isAux = ( theHypType >= AddHyp );
935 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
937 if ( theFather->FindSubObject( aPart, aHypRoot ) )
939 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypRoot );
940 for ( ; anIter->More(); anIter->Next() )
942 _PTR(SObject) anObj = anIter->Value();
943 if ( isMesh ) // i.e. mesh or submesh
945 _PTR(SObject) aRefObj;
946 if ( anObj->ReferencedObject( aRefObj ) )
951 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
954 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
955 if ( !CORBA::is_nil( aVar ) )
957 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
958 if ( !aHypVar->_is_nil() )
960 CORBA::String_var hypType = aHypVar->GetName();
961 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
962 if ( !aData) continue;
963 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
964 ( isCompatible ( theAlgoData, aData, theHypType )) &&
965 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
966 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
968 std::string aHypName = aName->Value();
969 theHyps.append( aHypName.c_str() );
970 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
979 //================================================================================
981 * \brief If create or edit a submesh, return a hypothesis holding parameters used
982 * to mesh a sub-shape
983 * \param aHypType - The hypothesis type name
984 * \param aServerLib - Server library name
985 * \param hypData - The structure holding the hypothesis type etc.
986 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
988 //================================================================================
989 SMESH::SMESH_Hypothesis_var
990 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
991 const QString& aServerLib,
992 const SMESH::HypInitParams* aParams ) const
994 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
995 return SMESH::SMESH_Hypothesis::_nil();
997 const int nbColonsInMeshEntry = 3;
998 bool isSubMesh = myToCreate ?
1000 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1002 // get mesh and geom object
1003 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1004 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1009 anEntry = myDlg->selectedObject
1010 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1011 if ( _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1013 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1014 if ( myToCreate ) // mesh and geom may be selected
1016 aMesh = SMESH::SMESH_Mesh::_narrow( Obj );
1017 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1018 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1019 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1021 else // edition: sub-mesh may be selected
1023 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1024 if ( !sm->_is_nil() ) {
1025 aMesh = sm->GetFather();
1026 aGeomVar = sm->GetSubShape();
1033 if ( !myToCreate ) // mesh to edit can be selected
1035 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1036 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1038 aMesh = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1039 if ( !aMesh->_is_nil() )
1040 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1043 if ( aGeomVar->_is_nil() ) {
1044 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1045 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1047 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1052 SMESH::HypInitParams initParams;
1053 enum { BY_MESH, BY_GEOM, BY_AVERAGE_LENGTH }; // same as ::SMESH_Hypothesis::InitWay
1056 initParams = *aParams;
1060 initParams.way = isSubMesh ? BY_MESH : BY_GEOM;
1063 SMESH::SMESH_Hypothesis_var hyp;
1064 if ( initParams.way == BY_AVERAGE_LENGTH )
1065 hyp = SMESHGUI::GetSMESHGen()->CreateHypothesisByAverageLength( aHypType.toUtf8().data(),
1066 aServerLib.toUtf8().data(),
1067 initParams.averageLength,
1068 initParams.quadDominated );
1070 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1071 aServerLib.toUtf8().data(),
1075 if ( hyp->_is_nil() && initParams.way == BY_MESH )
1077 initParams.way = BY_GEOM;
1078 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1079 aServerLib.toUtf8().data(),
1084 if ( hyp->_is_nil() && initParams.way == BY_GEOM )
1086 initParams.way = BY_AVERAGE_LENGTH;
1087 initParams.averageLength = 1.;
1088 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1089 aServerLib.toUtf8().data(),
1097 //================================================================================
1099 * \brief initialize a hypothesis creator
1101 //================================================================================
1103 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1105 if ( !theCreator ) return;
1107 // Set shapes, of mesh and sub-mesh if any
1109 // get Entry of the Geom object
1110 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1111 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1112 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1114 if ( myToCreate && myIsMesh )
1115 aMeshEntry = aGeomEntry;
1117 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1118 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1119 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1120 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1123 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1124 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1126 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1127 if ( !aGeomVar->_is_nil() )
1129 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1131 aMeshEntry = aGeomEntry;
1135 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1136 // take geometry from submesh being created
1137 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1139 // if current object is sub-mesh
1140 SMESH::SMESH_subMesh_var aSubMeshVar =
1141 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1142 if ( !aSubMeshVar->_is_nil() ) {
1143 SMESH::SMESH_Mesh_var aMesh = aSubMeshVar->GetFather();
1144 if ( !aMesh->_is_nil() ) {
1145 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
1146 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1147 if ( !aGeomVar->_is_nil() )
1148 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1154 theCreator->setShapeEntry( aGeomEntry );
1155 if ( aMeshEntry != "" )
1156 theCreator->setMainShapeEntry( aMeshEntry );
1158 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1161 //================================================================================
1163 * \Brief Returns tab dimension
1164 * \param tab - the tab in the dlg
1165 * \param dlg - my dialogue
1166 * \retval int - dimension
1168 //================================================================================
1169 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1172 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1173 if (tab == dlg->tab(i))
1178 //================================================================================
1180 * \brief Create hypothesis
1181 * \param theHypType - hypothesis category (main or additional)
1182 * \param theIndex - index of type of hypothesis to be created
1184 * Specifies dimension of hypothesis to be created (using sender() method),
1185 * specifies its type and calls method for hypothesis creation
1187 //================================================================================
1188 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1190 // Specifies dimension of hypothesis to be created
1191 int aDim = getTabDim( sender(), myDlg );
1195 // Specifies type of hypothesis to be created
1196 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1197 if (theIndex < 0 || theIndex >= dataList.count())
1199 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1201 // Create hypothesis
1202 createHypothesis(aDim, theHypType, aHypTypeName);
1207 QString GetUniqueName (const QStringList& theHypNames,
1208 const QString& theName,
1209 size_t theIteration = 1)
1211 QString aName = theName + "_" + QString::number( theIteration );
1212 if ( theHypNames.contains( aName ) )
1213 return GetUniqueName( theHypNames, theName, ++theIteration );
1218 //================================================================================
1220 * \brief Return names of all existing hypotheses
1222 //================================================================================
1224 QStringList SMESHGUI_MeshOp::getHypoNames()
1226 QStringList aHypNames;
1228 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1229 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1230 const TType2HypList& aType2HypList = aDimIter.value();
1231 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1232 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1233 const THypList& aHypList = aTypeIter.value();
1234 THypList::const_iterator anIter = aHypList.begin();
1235 for ( ; anIter != aHypList.end(); anIter++) {
1236 const THypItem& aHypItem = *anIter;
1237 const QString& aHypName = aHypItem.second;
1238 aHypNames.append(aHypName);
1245 //================================================================================
1247 * Create hypothesis and update dialog.
1248 * \param theDim - dimension of hypothesis to be created
1249 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1250 * \param theTypeName - specifies hypothesis to be created
1252 //================================================================================
1253 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1255 const QString& theTypeName)
1257 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1264 // get a unique hyp name
1265 QString aHypName = GetUniqueName( getHypoNames(), aData->Label);
1268 bool dialog = false;
1270 QString aClientLibName = aData->ClientLibName;
1271 if (aClientLibName == "") {
1272 // Call hypothesis creation server method (without GUI)
1273 SMESH::SMESH_Hypothesis_var aHyp =
1274 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1278 // Get hypotheses creator client (GUI)
1279 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1281 // Create hypothesis
1284 // Get parameters appropriate to initialize a new hypothesis
1285 SMESH::SMESH_Hypothesis_var initParamHyp =
1286 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1288 removeCustomFilters(); // Issue 0020170
1290 // set shapes, of mesh and sub-mesh if any
1291 initHypCreator( aCreator );
1293 myDlg->setEnabled( false );
1294 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1299 SMESH::SMESH_Hypothesis_var aHyp =
1300 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1309 //================================================================================
1311 * Necessary steps after hypothesis creation
1312 * \param result - creation result:
1315 * 2 = additional value meaning that slot is called not from dialog box
1317 //================================================================================
1318 void SMESHGUI_MeshOp::onHypoCreated( int result )
1322 int obj = myDlg->getActiveObject();
1323 onActivateObject( obj ); // Issue 0020170. Restore filters
1324 myDlg->setEnabled( true );
1327 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1329 int nbHyp = myExistingHyps[myDim][myType].count();
1330 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1331 QStringList aNewHyps;
1332 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1333 if (aNewHyps.count() > nbHyp)
1335 for (int i = nbHyp; i < aNewHyps.count(); i++)
1336 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1341 //================================================================================
1343 * \brief Calls plugin methods for hypothesis editing
1344 * \param theHypType - specifies whether main hypothesis or additional one
1346 * \param theIndex - index of existing hypothesis
1348 * Calls plugin methods for hypothesis editing
1350 //================================================================================
1351 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1353 // Speicfies dimension of hypothesis to be created
1354 int aDim = getTabDim( sender(), myDlg );
1358 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1359 if ( theIndex < 0 || theIndex >= aList.count() )
1361 const THypItem& aHypItem = aList[ theIndex ];
1362 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1363 if ( aHyp->_is_nil() )
1366 SMESHGUI_GenericHypothesisCreator* aCreator =
1367 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1370 // set initial parameters
1371 SMESH::SMESH_Hypothesis_var initParamHyp =
1372 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1373 SMESH::toQStr( aHyp->GetLibName() ));
1374 aCreator->setInitParamsHypothesis( initParamHyp );
1376 // set shapes, of mesh and sub-mesh if any
1377 initHypCreator( aCreator );
1379 removeCustomFilters(); // Issue 0020170
1380 myDlg->setEnabled( false );
1382 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1386 //================================================================================
1388 * Necessary steps after hypothesis edition
1389 * \param result - creation result:
1393 //================================================================================
1394 void SMESHGUI_MeshOp::onHypoEdited( int /*result*/ )
1396 int obj = myDlg->getActiveObject();
1397 onActivateObject( obj ); // Issue 0020170. Restore filters
1398 myDlg->setEnabled( true );
1401 //================================================================================
1403 * \brief access to hypothesis data
1404 * \param theDim - hyp dimension
1405 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1406 * \param theIndex - index in the list
1407 * \retval HypothesisData* - result data, may be 0
1409 //================================================================================
1410 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1411 const int theHypType,
1414 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1415 theHypType > -1 && theHypType < NbHypTypes &&
1416 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1417 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1421 //================================================================================
1423 * \brief Update list of algorithms and hypotheses according to currently selected
1424 * algorithm, geometry and mesh type
1426 //================================================================================
1427 void SMESHGUI_MeshOp::setFilteredAlgoData()
1429 // keep current algorithms
1430 HypothesisData* curAlgos[ 4 ];
1431 for ( int dim = 0; dim <= 3; ++dim )
1432 curAlgos[ dim ] = hypData( dim, Algo, currentHyp( dim, Algo ));
1434 // find out myMaxShapeDim by checking algorithm applicability to geometry
1436 int curMeshType = myDlg->currentMeshType();
1437 myDlg->setCurrentMeshType( MT_ANY );
1438 QStringList algosAvailable;
1439 // get available algorithms taking into account geometry only
1440 if ( myGeom->_is_nil() )
1444 if ( myToCreate ) // readMesh() has done it if !myToCreate
1445 for ( int dim = 0; dim <= 3; ++dim )
1446 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1450 if ( myGeomEntry != myLastGeomEntry )
1451 myHypMapIsApplicable.clear();
1453 for ( int dim = 0; dim <= 3; ++dim )
1455 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1456 if ( algosAvailable.count() )
1457 myMaxShapeDim = dim;
1459 if ( !myGeomEntry.isEmpty() )
1460 myLastGeomEntry = myGeomEntry;
1462 myDlg->setMaxHypoDim( myMaxShapeDim );
1464 // set mesh types according to myMaxShapeDim
1465 updateMeshTypeList();
1467 // update available hypo-sets that depend on geometry and mesh type
1468 myDlg->setCurrentMeshType( Max( MT_ANY, curMeshType ));
1469 updateHypoSets(); // it sets myAvailableHypData by curMeshType
1471 // restore current algorithms according to changed myAvailableHypData
1472 algosAvailable.clear();
1473 for ( int dim = 0; dim <= 3; ++dim )
1475 int algoIndex = myAvailableHypData[ dim ][ Algo ].indexOf( curAlgos[ dim ]);
1476 while ( algosAvailable.count() <= algoIndex )
1477 algosAvailable << "";
1478 myDlg->tab( dim )->setAvailableHyps( Algo, algosAvailable );
1479 setCurrentHyp( dim, Algo, algoIndex );
1480 if ( algoIndex < 0 )
1481 curAlgos[ dim ] = 0;
1484 // find a selected algo, current or of highest dimension
1485 int algoDim = myDlg->currentTab();
1486 if ( !curAlgos[ algoDim ])
1487 for ( algoDim = SMESH::DIM_3D; algoDim >= SMESH::DIM_0D; algoDim-- )
1488 if ( curAlgos[ algoDim ] )
1490 if ( algoDim < SMESH::DIM_0D )
1491 algoDim = myMaxShapeDim;
1493 // set algorithms and hypotheses according to all parameters (mesh type etc)
1494 onAlgoSelected( currentHyp( algoDim, Algo ), algoDim );
1497 //================================================================================
1499 * \brief Set available algos and hypos according to the selected algorithm
1500 * \param theIndex - algorithm index
1501 * \param theDim - algorithm dimension
1503 //================================================================================
1504 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1507 if ( myIgnoreAlgoSelection )
1510 int curDim = getTabDim( sender(), myDlg );
1511 int aDim = theDim < 0 ? curDim : theDim;
1515 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1517 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1518 HypothesisData* algoByDim[4];
1519 algoByDim[ aDim ] = algoData;
1521 QStringList anAvailable;
1522 const int algoDim = aDim;
1524 // 2 loops: backward and forward from algo dimension (forward == to higher dimension)
1525 for ( int forward = 1; forward >= 0; --forward )
1527 int dim = algoDim, lastDim = SMESH::DIM_3D, dir = 1;
1529 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1531 //bool noCompatible = false;
1532 for ( ; dim * dir <= lastDim * dir; dim += dir)
1534 // if ( noCompatible ) // the selected algo has no compatible ones (like 1D2D3D algo)
1536 // anAvailable.clear();
1537 // myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1538 // myAvailableHypData[dim][Algo].clear();
1539 // algoByDim[ dim ] = 0;
1543 int algoIndex = currentHyp( dim, Algo );
1544 HypothesisData *curAlgo = hypData( dim, Algo, algoIndex );
1546 // set new available algorithms
1547 HypothesisData *prevAlgo = 0;
1548 if ( dim != algoDim )
1549 for ( int prevDim = dim + 1; prevDim <=3 && !prevAlgo; ++prevDim )
1550 prevAlgo = hypData( prevDim, Algo, currentHyp( prevDim, Algo ));
1551 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1552 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1554 //noCompatible = ( prevAlgo && !forward && anAvailable.isEmpty() );
1557 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1558 setCurrentHyp( dim, Algo, algoIndex, /*updateHyps=*/true );
1560 algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1563 // activate tabs according to algorithms availability
1564 if ( anAvailable.isEmpty() ) myDlg->disableTab( dim );
1565 else myDlg->enableTab( dim );
1568 } // loops backward and forward
1571 // set hypotheses corresponding to the found algorithms
1573 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
1575 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1577 if ( !isAccessibleDim( dim ))
1580 // get indices of selected hyps
1581 const int nbTypes = nbDlgHypTypes(dim);
1582 std::vector<int> hypIndexByType( nbTypes, -1 );
1583 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1585 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1589 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1591 const int type = Min( dlgType, AddHyp );
1592 myAvailableHypData[ dim ][ type ].clear();
1593 QStringList anAvailable, anExisting;
1595 HypothesisData* curAlgo = algoByDim[ dim ];
1596 int hypIndex = hypIndexByType[ dlgType ];
1598 SMESH::SMESH_Hypothesis_var curHyp;
1600 HypothesisData* hypData = 0;
1601 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1603 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1604 if ( !curHyp->_is_nil() )
1606 curHypType = SMESH::toQStr( curHyp->GetName() );
1607 hypData = SMESH::GetHypothesisData( curHypType );
1610 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) // edition, algo not selected
1612 // try to find algo by selected hypothesis in order to keep it selected
1613 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1614 if ( !algoDeselectedByUser &&
1615 myObjHyps[ dim ][ type ].count() > 0 &&
1616 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1618 for ( int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i )
1620 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1621 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1629 // get hyps compatible with curAlgo
1630 bool defaulHypAvlbl = false;
1633 if ( hypData && !isCompatible( curAlgo, hypData, type ))
1634 curHyp = SMESH::SMESH_Hypothesis::_nil();
1635 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo );
1636 existingHyps ( dim, type, pComp, anExisting, myExistingHyps[ dim ][ type ], curAlgo );
1637 defaulHypAvlbl = ( type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1639 // set list of hypotheses
1640 if ( dlgType <= AddHyp )
1642 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1643 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1645 // set current existing hypothesis
1646 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1647 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1650 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1652 // none is yet selected => select the sole existing if it is not optional
1653 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1654 bool isOptional = true;
1655 if ( algoByDim[ dim ] &&
1656 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1660 setCurrentHyp( dim, dlgType, hypIndex );
1666 //================================================================================
1668 * \brief Create a sub-mesh on internal edges in the case where the global algorithm
1669 * is of type 1D-2D[-3D] so that the internal edges would remain not meshed.
1671 //================================================================================
1673 void SMESHGUI_MeshOp::createSubMeshOnInternalEdges( SMESH::SMESH_Mesh_ptr theMesh,
1674 GEOM::GEOM_Object_ptr theMainShape )
1676 if ( theMesh->_is_nil() || theMainShape->_is_nil() )
1679 if ( isAccessibleDim( 1 ))
1680 return; // global 1D algorithm is/can be assigned
1682 const HypothesesSet::SetType internSet = HypothesesSet::INTERN;
1683 bool toCreate = true;
1684 bool toCreateMandatory = ( myHypoSet &&
1685 myAverageSize > 0 &&
1686 ( myHypoSet->init( /*algo=*/ true, internSet ), myHypoSet->more()) &&
1687 ( myHypoSet->init( /*algo=*/false, internSet ), myHypoSet->more()));
1688 if ( !toCreateMandatory ) // ask the user
1689 toCreate = false; // can't pass both mesh and geometry to Create Submesh operation (so far?)
1690 // toCreate = SUIT_MessageBox::warning( SMESHGUI::desktop(),
1691 // QObject::tr("SMESH_WRN_WARNING"),
1692 // QObject::tr("SMESH_CREATE_SUBMESH_ON_INTERNAL_EDGES"),
1693 // QObject::tr("SMESH_BUT_YES"),
1694 // QObject::tr("SMESH_BUT_NO"), 1, 0);
1699 if ( !GEOMBase::GetShape( theMainShape, shape ))
1702 std::vector< TopoDS_Shape > internalEdges;
1703 for ( TopExp_Explorer edge( shape, TopAbs_EDGE, TopAbs_WIRE ); edge.More(); edge.Next() )
1704 internalEdges.push_back( edge.Current() );
1706 if ( internalEdges.empty() )
1709 TopTools_IndexedMapOfShape shapeIDs;
1710 TopExp::MapShapes( shape, shapeIDs );
1712 std::set< int > intIDSet;
1713 for ( size_t i = 0; i < internalEdges.size(); ++i )
1714 intIDSet.insert( shapeIDs.FindIndex( internalEdges[ i ]));
1716 GEOM::GEOM_Gen_var geomGen = theMainShape->GetGen();
1717 if (geomGen->_is_nil()) return;
1719 GEOM::GEOM_Object_var edgeGroup;
1720 GEOM::GEOM_IShapesOperations_wrap sOp = geomGen->GetIShapesOperations();
1721 GEOM::GEOM_IGroupOperations_wrap gOp = geomGen->GetIGroupOperations();
1722 GEOM::ListOfGO_var geomGroups = sOp->GetExistingSubObjects( theMainShape,
1723 /*groupsOnly=*/true );
1724 for ( CORBA::ULong i = 0; i < geomGroups->length(); ++i )
1726 GEOM::ListOfLong_var ids = gOp->GetObjects( geomGroups[ i ]);
1727 std::set< int > idSet( & ids[0], & ids[0] + ids->length() );
1728 if ( idSet == intIDSet )
1730 edgeGroup = geomGroups[ i ];
1735 if ( edgeGroup->_is_nil() )
1737 GEOM::GEOM_Object_var edgeGroup = gOp->CreateGroup( theMainShape, TopAbs_EDGE );
1739 GEOM::ListOfLong_var edgeIDs = new GEOM::ListOfLong;
1740 edgeIDs->length( internalEdges.size() );
1741 std::set< int >::iterator id = intIDSet.begin();
1742 for ( size_t i = 0; i < intIDSet.size(); ++i, ++id )
1744 gOp->UnionIDs( edgeGroup, edgeIDs );
1746 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( edgeGroup, "Internal edges", theMainShape );
1749 if ( !toCreateMandatory )
1751 // show Create Sub-mesh dislog
1752 // _PTR(SObject) aMeshSO = SMESH::FindSObject( theMesh );
1753 // selectionMgr()->clearFilters();
1754 // selectObject( pSubmesh );
1755 // SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
1759 // create a sub-mesh using myAverageSize w/o GUI
1761 SMESH::SMESH_subMesh_var subMesh = theMesh->GetSubMesh( edgeGroup, "" );
1763 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1764 for ( myHypoSet->init( isAlgo, internSet ); myHypoSet->more(); myHypoSet->next() )
1766 QString aHypoTypeName = myHypoSet->current();
1767 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1771 myDim = aHypData->Dim[0];
1775 // create or/and set
1776 SMESH::SMESH_Hypothesis_var newHypo;
1779 myAvailableHypData[ myDim ][ Algo ].clear();
1780 myAvailableHypData[ myDim ][ Algo ] << aHypData;
1781 QStringList hypList; hypList << aHypoTypeName;
1782 myDlg->tab( myDim )->setAvailableHyps( Algo, hypList );
1783 setCurrentHyp( myDim, Algo, 0 );
1784 newHypo = getAlgo( myDim );
1788 SMESH::HypInitParams params = { 2, myAverageSize, false };
1789 newHypo = getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1790 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1791 SALOMEDS::SObject_wrap so =
1792 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), newHypo,
1793 hypName.toUtf8().data() );
1795 SMESH::AddHypothesisOnSubMesh( subMesh, newHypo );
1801 //================================================================================
1803 * \brief Ask the user to enter an average size which will be used to create
1804 * hypotheses of a hypo-set basing on this size
1805 * \param [out] averageSize - average element size
1806 * \return bool - false if the user canceled the dialog
1808 //================================================================================
1810 bool SMESHGUI_MeshOp::getAverageSize( double & averageSize )
1812 HypothesisData* hypData = SMESH::GetHypothesisData( "MaxLength" );
1816 SMESH::SMESH_Hypothesis_var hyp = getInitParamsHypothesis( hypData->TypeName,
1817 hypData->ServerLibName );
1818 if ( hyp->_is_nil() )
1821 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( hypData->TypeName );
1825 initHypCreator( aCreator );
1826 myDlg->setEnabled( false );
1828 aCreator->edit( hyp.in(), HypothesesSet::getCommonHypoSetHypoType(),
1829 dlg(), this, SLOT( onHypoEdited( int )));
1831 StdMeshers::StdMeshers_MaxLength_var lenHyp = StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
1832 if ( lenHyp->_is_nil() )
1835 averageSize = lenHyp->GetLength();
1839 //================================================================================
1841 * \brief Creates and selects hypothesis of hypotheses set
1842 * \param theSetName - The name of hypotheses set
1844 //================================================================================
1845 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1847 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1848 myHypoSet = aHypoSet;
1853 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++)
1855 setCurrentHyp(dim, Algo, -1);
1856 setCurrentHyp(dim, AddHyp, -1);
1857 setCurrentHyp(dim, MainHyp, -1);
1858 onAlgoSelected( -1, dim );
1861 HypothesesSet::SetType setType = aHypoSet->getPreferredHypType();
1862 if ( !aHypoSet->getAlgoAvailable( setType ))
1864 setType = ( setType == HypothesesSet::ALT ) ? HypothesesSet::MAIN : HypothesesSet::ALT;
1865 if ( !aHypoSet->getAlgoAvailable( setType ))
1870 if ( aHypoSet->toUseCommonSize() && !getAverageSize( myAverageSize ))
1874 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1875 for ( aHypoSet->init( isAlgo, setType ); aHypoSet->more(); aHypoSet->next() )
1877 QString aHypoTypeName = aHypoSet->current();
1878 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1882 myDim = aHypData->Dim[0];
1883 // create or/and set
1886 int index = myAvailableHypData[myDim][Algo].indexOf( aHypData );
1889 setCurrentHyp( myDim, Algo, index );
1890 onAlgoSelected( index, myDim );
1891 maxDim = Max( maxDim, myDim );
1897 int index = myAvailableHypData[myDim][MainHyp].indexOf( aHypData );
1901 index = myAvailableHypData[myDim][AddHyp].indexOf( aHypData );
1905 if ( myAverageSize > 0 )
1907 SMESH::HypInitParams params = { 2, myAverageSize, aHypoSet->isQuadDominated() };
1908 SMESH::SMESH_Hypothesis_var hyp =
1909 getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1911 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1912 SALOMEDS::SObject_wrap so =
1913 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), hyp,
1914 hypName.toUtf8().data() );
1919 createHypothesis( myDim, myType, aHypoTypeName );
1926 myDlg->setCurrentTab( maxDim );
1931 //================================================================================
1933 * \brief Creates mesh
1934 * \param theMess - Output parameter intended for returning error message
1935 * \param theEntryList - List of entries of published objects
1936 * \retval bool - TRUE if mesh is created, FALSE otherwise
1938 //================================================================================
1939 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1944 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1945 if ( aList.isEmpty() )
1947 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1948 if ( aSMESHGen->_is_nil() )
1951 SMESH::SMESH_Mesh_var aMesh= aSMESHGen->CreateEmptyMesh();
1952 if ( aMesh->_is_nil() )
1955 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
1957 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1958 theEntryList.append( aMeshSO->GetID().c_str() );
1963 if ( aList.count() > 1 )
1965 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1966 int i = namePrefix.length() - 1;
1967 while ( i > 0 && namePrefix[i].isDigit() )
1969 if ( i < namePrefix.length() - 1 )
1970 namePrefix.chop( namePrefix.length() - 1 - i );
1974 QStringList::Iterator it = aList.begin();
1975 for ( int i = 0; it != aList.end(); it++, ++i )
1977 QString aGeomEntry = *it;
1978 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
1979 GEOM::GEOM_Object_var aGeomVar =
1980 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1982 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1983 if ( aSMESHGen->_is_nil() )
1986 SUIT_OverrideCursor aWaitCursor;
1989 SMESH::SMESH_Mesh_var aMesh = aSMESHGen->CreateMesh( aGeomVar );
1990 if ( aMesh->_is_nil() )
1992 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
1994 theEntryList.append( aMeshSO->GetID().c_str() );
1995 if ( i > 0 ) setDefaultName( namePrefix );
1996 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1999 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2001 if ( !isAccessibleDim( aDim )) continue;
2003 // assign hypotheses
2004 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2006 const int aHypIndex = currentHyp( aDim, dlgType );
2007 const int aHypType = Min( dlgType, AddHyp );
2008 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2010 SMESH::SMESH_Hypothesis_var aHypVar =
2011 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2012 if ( !aHypVar->_is_nil() )
2013 SMESH::AddHypothesisOnMesh( aMesh, aHypVar );
2016 // find or create algorithm
2017 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2018 if ( !anAlgoVar->_is_nil() )
2019 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2023 if ( myDlg->toCreateAllGroups() && !aGeomVar->_is_nil() )
2025 // Create groups on all geom groups
2027 GEOM::GEOM_Gen_var geomGen = aGeomVar->GetGen();
2028 GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
2029 GEOM::ListOfGO_var geomGroups = op->GetExistingSubObjects( aGeomVar,
2030 /*groupsOnly=*/false );
2031 SMESH::SMESH_GroupOnGeom_var meshGroup;
2032 for ( CORBA::ULong iG = 0; iG < geomGroups->length(); ++iG )
2034 SMESH::ElementType elemType = SMESHGUI_GroupOnShapeOp::ElementType( geomGroups[ iG ] );
2035 if ( elemType == SMESH::ALL )
2037 if ( elemType == SMESH::ELEM0D )
2038 elemType = SMESH::NODE;
2040 CORBA::String_var name = geomGroups[ iG ]->GetName();
2041 meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
2042 // if ( elemType != SMESH::NODE )
2043 // meshGroup = aMesh->CreateGroupFromGEOM( SMESH::NODE, name, geomGroups[ iG ]);
2047 createSubMeshOnInternalEdges( aMesh, aGeomVar );
2054 //================================================================================
2056 * \brief Create sub-mesh
2057 * \param theMess - Output parameter intended for returning error message
2058 * \param theEntryList - List of entries of published objects
2059 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
2061 //================================================================================
2062 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
2066 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2067 if ( aSMESHGen->_is_nil() )
2071 SMESH::SMESH_Mesh_var aMesh =
2072 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
2073 if ( aMesh->_is_nil() && myIsInvalidSubMesh )
2075 SMESH::SMESH_subMesh_var aSMVar =
2076 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
2077 if ( !aSMVar->_is_nil() )
2078 aMesh = aSMVar->GetMesh();
2080 if ( aMesh->_is_nil() )
2083 // GEOM shape of the main mesh
2084 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2086 // Name for the new sub-mesh
2087 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
2090 GEOM::GEOM_Object_var aGeomVar;
2092 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
2093 if (aGEOMs.count() == 1)
2095 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2096 QString aGeomEntry = aGEOMs.first();
2097 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2098 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2100 else if (aGEOMs.count() > 1)
2102 // create a GEOM group
2103 GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
2104 if ( !geomGen->_is_nil() ) {
2105 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
2106 if ( !op->_is_nil() )
2108 // check and add all selected GEOM objects: they must be
2109 // a sub-shapes of the main GEOM and must be of one type
2111 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
2112 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2113 aSeq->length(aGEOMs.count());
2114 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
2115 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
2116 QString aSubGeomEntry = (*aSubShapesIter);
2117 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
2118 GEOM::GEOM_Object_var aSubGeomVar =
2119 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
2120 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
2122 aGroupType = aSubShapeType;
2124 if (aSubShapeType != aGroupType)
2125 aGroupType = TopAbs_SHAPE;
2127 aSeq[iSubSh] = aSubGeomVar;
2130 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
2131 op->UnionList(aGroupVar, aSeq);
2135 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
2137 // publish the GEOM group in study
2138 QString aNewGeomGroupName ("Auto_group_for_");
2139 aNewGeomGroupName += aName;
2140 SALOMEDS::SObject_wrap aNewGroupSO =
2141 geomGen->AddInStudy( aGeomVar,
2142 aNewGeomGroupName.toUtf8().data(), mainGeom);
2149 if (aGeomVar->_is_nil())
2152 SUIT_OverrideCursor aWaitCursor;
2154 QString aNameOrID = aName;
2155 if ( myIsInvalidSubMesh )
2156 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
2157 // by a valid one in an existing SO
2158 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
2161 SMESH::SMESH_subMesh_var aSubMeshVar = aMesh->GetSubMesh( aGeomVar, aNameOrID.toUtf8().data() );
2162 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2164 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
2165 theEntryList.append( aSubMeshSO->GetID().c_str() );
2168 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2170 if ( !isAccessibleDim( aDim )) continue;
2172 // find or create algorithm
2173 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2174 if ( !anAlgoVar->_is_nil() )
2175 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2176 // assign hypotheses
2177 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2179 const int aHypIndex = currentHyp( aDim, dlgType );
2180 const int aHypType = Min( dlgType, AddHyp );
2181 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2183 SMESH::SMESH_Hypothesis_var aHypVar =
2184 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2185 if ( !aHypVar->_is_nil() )
2186 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2191 // deselect geometry: next submesh should be created on other sub-shape
2192 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2193 selectObject( _PTR(SObject)() );
2196 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/true );
2201 //================================================================================
2203 * \brief Return index of current hypothesis or algorithm
2204 * \param theDim - dimension of hypothesis or algorithm
2205 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2206 * \retval int - index of current hypothesis or algorithm, -1 if None selected
2208 //================================================================================
2209 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2211 if ( 0 <= theDim && theDim <= 3 )
2212 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2217 //================================================================================
2219 * \brief Checks if a hypothesis is selected
2221 //================================================================================
2223 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2228 if ( theHypType < AddHyp ) // only one hyp can be selected
2229 return currentHyp( theDim, theHypType ) == theIndex;
2231 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2232 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2238 //================================================================================
2240 * \brief Returns nb of HypType's taking into account possible several
2241 * selected additional hypotheses which are coded as additional HypType's.
2243 //================================================================================
2245 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2247 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2250 //================================================================================
2252 * \brief Returns true if hypotheses of given dim can be assigned
2253 * \param theDim - hypotheses dimension
2254 * \retval bool - result
2256 //================================================================================
2257 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2259 return myDlg->isTabEnabled( theDim );
2262 //================================================================================
2264 * \brief Sets current hypothesis or algorithms
2265 * \param theDim - dimension of hypothesis or algorithm
2266 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2267 * \param theIndex - Index of hypothesis
2268 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2270 * Gets current hypothesis or algorithms
2272 //================================================================================
2273 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2274 const int theHypType,
2276 const bool updateHypsOnAlgoDeselection)
2278 myIgnoreAlgoSelection = true;
2279 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2280 myIgnoreAlgoSelection = false;
2282 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2284 const QStringList noHyps;
2285 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2286 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2287 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2288 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2292 //================================================================================
2294 * \brief Generates default and sets mesh/submesh name
2296 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2298 //================================================================================
2299 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2303 _PTR(Study) aStudy = SMESH::getStudy();
2306 QString aPrefix = thePrefix;
2307 if ( aPrefix.isEmpty() )
2308 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2310 _PTR(SObject) anObj;
2313 aResName = aPrefix + QString::number( i++ );
2314 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2318 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2319 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2320 aControl->setText( aResName );
2323 //================================================================================
2325 * \brief Gets algorithm or creates it if necessary
2326 * \param theDim - specifies dimension of returned hypotheses/algorifms
2327 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2329 * Gets algorithm or creates it if necessary
2331 //================================================================================
2332 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2334 SMESH::SMESH_Hypothesis_var anAlgoVar;
2336 // get type of the selected algo
2337 int aHypIndex = currentHyp( theDim, Algo );
2338 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2339 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2341 QString aHypName = dataList[ aHypIndex ]->TypeName;
2343 // get existing algorithms
2344 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
2346 existingHyps( theDim, Algo, pComp, tmp, myExistingHyps[ theDim ][ Algo ]);
2348 // look for an existing algo of such a type
2349 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2350 THypList::iterator anIter = aHypVarList.begin();
2351 for ( ; anIter != aHypVarList.end(); anIter++)
2353 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2354 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2356 anAlgoVar = aHypVar;
2361 if (anAlgoVar->_is_nil())
2363 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2366 QString aClientLibName = aHypData->ClientLibName;
2367 if ( aClientLibName.isEmpty() )
2369 // Call hypothesis creation server method (without GUI)
2370 SMESH::SMESH_Hypothesis_var aHyp =
2371 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2376 // Get hypotheses creator client (GUI)
2377 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2381 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2383 SMESH::SMESH_Hypothesis_var aHyp =
2384 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2389 QStringList tmpList;
2390 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2391 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2394 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2395 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2397 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2398 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2400 anAlgoVar = aHypVar;
2406 return anAlgoVar._retn();
2409 //================================================================================
2411 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2413 * Called when mesh is edited only.
2415 //================================================================================
2416 void SMESHGUI_MeshOp::readMesh()
2418 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2419 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2423 if ( myIsOnGeometry )
2425 // Set name of mesh if current object is sub-mesh
2426 SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
2427 if ( !subMesh->_is_nil() )
2429 SMESH::SMESH_Mesh_var aMesh = subMesh->GetFather();
2430 if ( !aMesh->_is_nil() )
2432 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
2433 QString aMeshName = name( aMeshSO );
2434 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2436 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMesh, subMesh );
2439 if ( !myIsInvalidSubMesh )
2441 // Set name of geometry object
2442 CORBA::String_var name = SMESH::GetGeomName( pObj );
2444 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2448 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2449 QStringList anExisting, anAvailable;
2450 bool algoFound = false;
2451 const int dim1st = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2452 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2455 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2456 // find algo index among available ones
2458 anAvailable.clear();
2459 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2461 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ Algo ].first().first;
2462 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( hyp->GetName() ));
2463 availableHyps( dim, Algo, anAvailable, myAvailableHypData[ dim ][ Algo ] );
2464 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf( algoData );
2465 // if ( aHypIndex < 0 && algoData ) {
2466 // // assigned algo is incompatible with other algorithms
2467 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2468 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2470 algoFound = ( aHypIndex > -1 );
2472 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
2473 setCurrentHyp( dim, Algo, aHypIndex );
2474 // set existing and available hypothesis according to the selected algo
2475 if ( aHypIndex > -1 || !algoFound )
2476 onAlgoSelected( aHypIndex, dim );
2480 bool hypWithoutAlgo = false;
2481 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2483 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2486 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2487 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2488 setCurrentHyp( dim, hypType, -1 );
2490 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2492 // find index of required hypothesis among existing ones for this dimension and type
2493 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2494 myExistingHyps[ dim ][ hypType ] );
2495 if ( aHypIndex < 0 ) {
2496 // assigned hypothesis is incompatible with the algorithm
2497 if ( currentHyp( dim, Algo ) < 0 )
2498 { // none algo selected; it is edition for sure, of submesh maybe
2499 hypWithoutAlgo = true;
2500 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2501 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2502 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2503 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2506 setCurrentHyp( dim, hypType + i, aHypIndex );
2508 if ( hypType == MainHyp ) break; // only one main hyp allowed
2512 // make available other hyps of same type as one without algo
2513 if ( hypWithoutAlgo )
2514 onAlgoSelected( currentHyp( /*dim=*/0, Algo ), /*dim=*/0 );
2517 //================================================================================
2519 * \brief Gets name of object
2520 * \param theSO - SObject
2521 * \retval QString - name of object
2523 * Gets name of object
2525 //================================================================================
2526 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2531 _PTR(GenericAttribute) anAttr;
2532 _PTR(AttributeName) aNameAttr;
2533 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2536 aResName = aNameAttr->Value().c_str();
2542 //================================================================================
2544 * \brief Finds hypothesis in input list
2545 * \param theHyp - hypothesis to be found
2546 * \param theHypList - input list of hypotheses
2547 * \retval int - index of hypothesis or -1 if it is not found
2549 * Finds position of hypothesis in input list
2551 //================================================================================
2552 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2553 const THypList& theHypList ) const
2556 if ( !theHyp->_is_nil() )
2559 THypList::const_iterator anIter = theHypList.begin();
2560 for ( ; anIter != theHypList.end(); ++ anIter)
2562 if ( theHyp->_is_equivalent( (*anIter).first ) )
2573 //================================================================================
2575 * \brief Edits mesh or sub-mesh
2576 * \param theMess - Output parameter intended for returning error message
2577 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2579 * Assigns new name hypotheses and algorithms to the mesh or sub-mesh
2581 //================================================================================
2582 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2586 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2587 if ( aSMESHGen->_is_nil() )
2590 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2591 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2595 SUIT_OverrideCursor aWaitCursor;
2598 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2599 SMESH::SetName( pObj, aName );
2600 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2602 // First, remove old algos in order to avoid messages on algorithm hiding
2603 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2605 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2607 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2608 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2609 if ( anAlgoVar->_is_nil() || // no new algo selected or
2610 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2612 // remove old algorithm
2613 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2614 myObjHyps[ dim ][ Algo ].clear();
2619 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2620 CORBA::Object_var anObject = aSObject->GetObject();
2621 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObject );
2622 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2623 bool isMesh = !aMesh->_is_nil();
2624 if ( !isMesh && !aSubMeshVar->_is_nil() )
2625 aMesh = aSubMeshVar->GetFather();
2627 // Assign new algorithms and hypotheses
2628 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2630 //if ( !isAccessibleDim( dim )) continue;
2632 // find or create algorithm
2633 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2635 // assign new algorithm
2636 if ( !anAlgoVar->_is_nil() && // some algo selected and
2637 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2640 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2641 else if ( !aSubMeshVar->_is_nil() )
2642 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2644 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2647 // remove deselected hypotheses
2648 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2650 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2652 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2653 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2654 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2656 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2660 // assign newly selected hypotheses
2661 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2663 const int curIndex = currentHyp( dim, dlgType );
2664 const int hypType = Min( dlgType, AddHyp );
2665 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2667 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2669 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2673 SMESH::AddHypothesisOnMesh (aMesh, hyp );
2674 else if ( !aSubMeshVar->_is_nil() )
2675 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2678 // reread all hypotheses of mesh
2679 QStringList anExisting;
2680 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2684 if ( aSubMeshVar->_is_nil() )
2686 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2687 createSubMeshOnInternalEdges( aMesh, mainGeom );
2690 myHasConcurrentSubBefore =
2691 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2696 //================================================================================
2698 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2699 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2700 * order of sub-mesh computation.
2701 * Returns \c true if a sub-mesh concurrency detected.
2703 //================================================================================
2705 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2706 SMESH::SMESH_subMesh_ptr submesh,
2709 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2712 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2713 if ( isNewConcurrent && askUser )
2715 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2716 tr("CONCURRENT_SUBMESH_APPEARS"),
2717 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2720 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2721 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2722 if ( meshSO && aSelectionMgr )
2724 myDlg->setEnabled( false ); // disactivate selection
2725 selectionMgr()->clearFilters();
2726 selectObject( meshSO );
2727 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2728 qApp->processEvents();
2730 myDlg->setEnabled( true );
2731 int obj = myDlg->getActiveObject();
2732 onActivateObject( obj ); // restore filter
2735 selectObject( SMESH::FindSObject( submesh ));
2742 return isNewConcurrent;
2745 //================================================================================
2747 * \brief Verifies whether given operator is valid for this one
2748 * \param theOtherOp - other operation
2749 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2751 * method redefined from base class verifies whether given operator is valid for
2752 * this one (i.e. can be started "above" this operator). In current implementation method
2753 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2756 //================================================================================
2757 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2759 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2762 //================================================================================
2764 * \brief SLOT. Is called when the user selects a way of geometry selection
2765 * \param theByMesh - true if the user wants to find geometry by mesh element
2767 //================================================================================
2768 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2771 if ( !myShapeByMeshOp ) {
2772 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2773 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2774 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2775 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2776 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2778 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2779 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2780 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2781 SMESH::SMESH_Mesh_var aMesh =
2782 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2783 if ( !aMesh->_is_nil() ) {
2784 myDlg->hide(); // stop processing selection
2785 myShapeByMeshOp->setModule( getSMESHGUI() );
2786 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2787 myShapeByMeshOp->SetMesh( aMesh );
2788 myShapeByMeshOp->start();
2794 //================================================================================
2796 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2798 //================================================================================
2799 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2801 if ( myShapeByMeshOp == op ) {
2802 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2804 // Select a found geometry object
2805 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2806 if ( !aGeomVar->_is_nil() )
2808 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2809 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2810 selectObject( aGeomSO );
2817 //================================================================================
2819 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2821 //================================================================================
2822 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2824 if ( myShapeByMeshOp == op && myDlg ) {
2829 //================================================================================
2831 * \brief Selects a SObject
2832 * \param theSObj - the SObject to select
2834 //================================================================================
2835 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2837 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2838 SALOME_ListIO anIOList;
2840 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2841 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2842 anIOList.Append( anIO );
2844 sm->setSelectedObjects( anIOList, false );
2847 //================================================================================
2849 * \brief Update available list of mesh types
2851 //================================================================================
2852 void SMESHGUI_MeshOp::updateMeshTypeList()
2854 QStringList meshTypes;
2855 meshTypes.append( tr( "MT_ANY" ) );
2856 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2858 meshTypes.append( tr( "MT_TRIANGULAR" ) );
2859 meshTypes.append( tr( "MT_QUADRILATERAL" ) );
2861 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2863 meshTypes.append( tr( "MT_TETRAHEDRAL" ) );
2864 meshTypes.append( tr( "MT_HEXAHEDRAL" ) );
2867 myDlg->setAvailableMeshType( meshTypes );
2870 //================================================================================
2872 * \brief Update available list of hypothesis sets
2874 //================================================================================
2875 void SMESHGUI_MeshOp::updateHypoSets()
2877 // get available algorithms taking into account geometry and mesh type
2878 QStringList algosAvailable;
2879 if ( myDlg->currentMeshType() != MT_ANY )
2880 for ( int dim = 0; dim <= 3; ++dim )
2881 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
2883 THypDataList anAvailableAlgsData;
2884 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( myMaxShapeDim );
2885 QStringList aFilteredHypothesesSetsList;
2886 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2887 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2889 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2890 HypothesesSet::SetType sType;
2891 for ( sType = HypothesesSet::MAIN; sType <= HypothesesSet::ALT; SMESHUtils::Increment( sType ))
2893 bool isAvailable = false;
2894 for ( currentHypoSet->init( true, sType ); currentHypoSet->more(); currentHypoSet->next() )
2896 isAvailable = false;
2897 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2898 for ( int dim = SMESH::DIM_0D; dim <= myMaxShapeDim; dim++) {
2899 int aCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoDataIn );
2900 if ( aCurrentAvailableAlgo > -1 ) {
2909 currentHypoSet->setAlgoAvailable( sType, isAvailable );
2911 if ( currentHypoSet->hasAlgo( HypothesesSet::MAIN ) &&
2912 currentHypoSet->hasAlgo( HypothesesSet::ALT ))
2914 HypothesesSet::SetType setType = HypothesesSet::getPreferredHypType();
2915 if ( !currentHypoSet->getAlgoAvailable( setType ))
2916 continue; // not add if a preferred type not available currently
2919 if ( currentHypoSet->getAlgoAvailable( HypothesesSet::MAIN ) ||
2920 currentHypoSet->getAlgoAvailable( HypothesesSet::ALT ))
2922 aFilteredHypothesesSetsList.append( *inHypoSetName );
2925 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2928 //================================================================================
2930 * \brief SLOT. Is called when the user select type of mesh
2931 * \param theTabIndex - Index of current active tab
2932 * \param theIndex - Index of current type of mesh
2934 //================================================================================
2935 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int /*theTabIndex*/, const int /*theIndex*/ )
2937 setFilteredAlgoData();