1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_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_SelectionFilter.h>
47 #include <GEOM_wrap.hxx>
48 #include <GeometryGUI.h>
50 // SALOME GUI includes
51 #include <LightApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <LightApp_UpdateFlags.h>
54 #include <SALOME_InteractiveObject.hxx>
55 #include <SALOME_ListIO.hxx>
56 #include <SUIT_MessageBox.h>
57 #include <SUIT_OverrideCursor.h>
58 #include <SUIT_ResourceMgr.h>
59 #include <SUIT_Session.h>
60 #include <SalomeApp_Application.h>
61 #include <SalomeApp_Tools.h>
63 // SALOME KERNEL includes
64 #include <SALOMEDS_SComponent.hxx>
65 #include <SALOMEDS_SObject.hxx>
66 #include <SALOMEDS_Study.hxx>
67 #include <SALOMEDS_wrap.hxx>
70 #include <QApplication>
72 #include <QStringList>
75 #include <BRep_Tool.hxx>
77 #include <TopExp_Explorer.hxx>
78 #include <TopTools_IndexedMapOfShape.hxx>
81 //================================================================================
84 * \param theToCreate - if this parameter is true then operation is used for creation,
85 * for editing otherwise
87 * Initialize operation
89 //================================================================================
90 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
91 : SMESHGUI_SelectionOp(),
94 myToCreate( theToCreate ),
95 myIsMesh( theIsMesh ),
96 myIsInvalidSubMesh( false )
98 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
99 GeometryGUI::InitGeomGen();
100 myIsOnGeometry = true;
104 //================================================================================
108 //================================================================================
109 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
115 //================================================================================
117 * \brief Gets dialog of this operation
118 * \retval LightApp_Dialog* - pointer to dialog of this operation
120 //================================================================================
121 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
126 //================================================================================
128 * \brief Creates or edits mesh
129 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
131 * Virtual slot redefined from the base class called when "Apply" button is clicked
132 * creates or edits mesh
134 //================================================================================
135 bool SMESHGUI_MeshOp::onApply()
137 if (SMESHGUI::isStudyLocked())
141 if ( !isValid( aMess ) )
145 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
149 bool aResult = false;
153 QStringList anEntryList;
154 if ( myToCreate && myIsMesh )
155 aResult = createMesh( aMess, anEntryList );
156 if (( myToCreate && !myIsMesh ) || myIsInvalidSubMesh )
157 aResult = createSubMesh( aMess, anEntryList );
158 else if ( !myToCreate )
159 aResult = editMeshOrSubMesh( aMess );
162 SMESHGUI::Modified();
163 update( UF_ObjBrowser | UF_Model );
164 if( LightApp_Application* anApp =
165 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
166 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
169 catch ( const SALOME::SALOME_Exception& S_ex )
171 SalomeApp_Tools::QtCatchCorbaException( S_ex );
187 aMess = tr( "SMESH_OPERATION_FAILED" );
188 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
196 //================================================================================
198 * \brief Creates dialog if necessary and shows it
200 * Virtual method redefined from base class called when operation is started creates
201 * dialog if necessary and shows it, activates selection
203 //================================================================================
204 void SMESHGUI_MeshOp::startOperation()
206 myIgnoreAlgoSelection = false;
210 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
211 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
213 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
214 this, SLOT( onCreateHyp( const int, const int ) ) );
215 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
216 this, SLOT( onEditHyp( const int, const int ) ) );
217 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
218 this, SLOT( onAlgoSelected( const int ) ) );
220 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
221 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
222 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
225 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
226 else myHelpFileName = "constructing_submeshes.html";
229 myHelpFileName = "editing_meshes.html";
232 SMESHGUI_SelectionOp::startOperation();
234 // clear available hypotheses
236 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
238 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
240 aTab->setAvailableHyps( Algo, hypList );
241 aTab->setAvailableHyps( MainHyp, hypList );
242 aTab->setAvailableHyps( AddHyp, hypList );
243 aTab->setExistingHyps( MainHyp, hypList );
244 aTab->setExistingHyps( AddHyp, hypList );
245 myExistingHyps[ i ][ MainHyp ].clear();
246 myExistingHyps[ i ][ AddHyp ].clear();
251 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
255 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
258 updateMeshTypeList();
259 myDlg->setCurrentMeshType( MT_ANY );
261 myDlg->setCurrentTab( SMESH::DIM_3D );
262 myDlg->setGeomPopupEnabled(false);
268 myHasConcurrentSubBefore = false;
269 myObjectToSelect.clear();
272 //=================================================================================
274 * \brief Selects a recently created mesh or sub-mesh if necessary
276 * Virtual method redefined from base class called when operation is committed
277 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
278 * selection when the custom selection filters are removed.
280 //=================================================================================
281 void SMESHGUI_MeshOp::commitOperation()
283 SMESHGUI_SelectionOp::commitOperation();
285 if ( !myObjectToSelect.isEmpty() ) {
286 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
287 SUIT_DataOwnerPtrList aList;
288 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
289 aSelectionMgr->setSelected( aList );
294 //================================================================================
296 * \brief Creates selection filter
297 * \param theId - identifier of current selection widget
298 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
300 * Creates selection filter in accordance with identifier of current selection widget
302 //================================================================================
303 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
305 if ( theId == SMESHGUI_MeshDlg::Geom )
307 // TColStd_MapOfInteger allTypesMap;
308 // for ( int i = 0; i < 10; i++ )
309 // allTypesMap.Add( i );
310 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
311 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
313 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
314 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
315 else if ( theId == SMESHGUI_MeshDlg::Mesh )
316 return new SMESH_TypeFilter( SMESH::MESH );
321 //================================================================================
323 * \brief check if selected shape is a sub-shape of the shape to mesh
324 * \retval bool - check result
326 //================================================================================
327 bool SMESHGUI_MeshOp::isSubshapeOk() const
329 if ( !myToCreate || myIsMesh ) // not submesh creation
333 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
334 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
335 if (!pMesh) return false;
337 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
338 if (mesh->_is_nil()) return false;
340 // main shape of the mesh
341 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
342 if (mainGeom->_is_nil()) return false;
346 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
348 if (aGEOMs.count() > 0) {
349 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
350 if (geomGen->_is_nil()) return false;
352 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
353 if (op->_is_nil()) return false;
355 // check all selected shapes
356 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
357 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
358 QString aSubGeomEntry = (*aSubShapesIter);
359 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
360 if (!pSubGeom) return false;
362 GEOM::GEOM_Object_var aSubGeomVar =
363 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
364 if (aSubGeomVar->_is_nil()) return false;
366 // skl for NPAL14695 - implementation of searching of mainObj
367 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
368 mainObj already exists! */
369 while( !mainObj->_is_nil()) {
370 CORBA::String_var entry1 = mainObj->GetEntry();
371 CORBA::String_var entry2 = mainGeom->GetEntry();
372 if (std::string( entry1.in() ) == entry2.in() )
374 mainObj = op->GetMainShape(mainObj);
376 if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
378 // is aSubGeomVar a compound of sub-shapes?
379 GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
380 if (sop->_is_nil()) return false;
381 GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
382 GEOM::SHAPE,/*sorted=*/false);
383 if ( ids->length() > 0 )
386 GEOM::GEOM_Object_var compSub = geomGen->AddSubShape( aSubGeomVar, ids );
387 if ( !compSub->_is_nil() )
389 GEOM::ListOfGO_var shared = sop->GetSharedShapes( mainGeom,
391 compSub->GetShapeType() );
392 geomGen->RemoveObject( compSub );
393 compSub->UnRegister();
394 if ( shared->length() > 0 ) {
395 geomGen->RemoveObject( shared[0] );
396 shared[0]->UnRegister();
398 return ( shared->length() > 0 );
408 //================================================================================
410 * \brief Return name of the algorithm that does not support sub-meshes and makes
411 * sub-mesh creation useless
412 * \retval char* - string is to be deleted!!!
414 //================================================================================
415 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
417 if ( myToCreate && !myIsMesh ) {
419 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
420 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
421 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
424 QStringList algoNames;
426 existingHyps(3, Algo, pMesh, algoNames, algoList);
427 if (!algoList.empty()) {
428 HypothesisData* algo =
429 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
431 algo->InputTypes.empty() && // builds all dimensions it-self
432 !algo->IsSupportSubmeshes )
433 return CORBA::string_dup( algoNames[0].toUtf8().data() );
436 // GEOM::GEOM_Object_var geom;
437 // if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() ))
438 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
440 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
441 existingHyps(2, Algo, pMesh, algoNames, algoList);
442 if (!algoList.empty()) {
443 HypothesisData* algo =
444 SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
446 algo->InputTypes.empty() && // builds all dimensions it-self
447 !algo->IsSupportSubmeshes )
448 return CORBA::string_dup( algoNames[0].toUtf8().data() );
456 //================================================================================
458 * \brief find an existing submesh by the selected shape
459 * \retval _PTR(SObject) - the found submesh SObject
461 //================================================================================
462 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
464 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
465 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
466 if ( pMesh && !myGeom->_is_nil() ) {
468 switch ( myGeom->GetShapeType() ) {
469 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
470 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
471 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
472 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
473 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
474 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
475 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
478 _PTR(GenericAttribute) anAttr;
479 _PTR(SObject) aSubmeshRoot;
480 _PTR(Study) aStudy = SMESH::getStudy();
481 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
483 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
484 for ( ; smIter->More(); smIter->Next() )
486 _PTR(SObject) aSmObj = smIter->Value();
487 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
489 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
490 for ( ; anIter1->More(); anIter1->Next()) {
491 _PTR(SObject) pGeom2 = anIter1->Value();
492 if ( pGeom2->ReferencedObject( pGeom2 ) &&
493 myGeomEntry == pGeom2->GetID().c_str() )
499 return _PTR(SObject)();
502 //================================================================================
504 * \brief Updates dialog's look and feel
506 * Virtual method redefined from the base class updates dialog's look and feel
508 //================================================================================
509 void SMESHGUI_MeshOp::selectionDone()
511 if (!dlg()->isVisible() || !myDlg->isEnabled())
514 SMESHGUI_SelectionOp::selectionDone();
517 myGeom = GEOM::GEOM_Object::_nil();
518 myIsInvalidSubMesh = false;
519 myIsOnGeometry = true;
523 // allow selecting multiple geom objects only for sub-mesh creation
525 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aGEOMs );
526 int nbGeoms = aGEOMs.count();
529 myGeomEntry = aGEOMs[0];
530 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( myGeomEntry.toUtf8().data() );
531 if ( nbGeoms > 1 && myToCreate && myIsMesh )
533 selectObject( pGeom );
537 myGeom = SMESH::SObjectToInterface< GEOM::GEOM_Object >( pGeom ); // creation case
540 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
541 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
543 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface< SMESH::SMESH_Mesh >( pObj );
544 SMESH::SMESH_subMesh_var subMesh;
546 if ( !myToCreate ) // edition: read hypotheses
550 subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
551 myIsMesh = subMesh->_is_nil();
552 myGeom = SMESH::GetShapeOnMeshOrSubMesh( pObj );
553 myIsInvalidSubMesh = ( !myIsMesh && subMesh->GetId() < 1 );
554 if ( !mesh->_is_nil() && !mesh->HasShapeToMesh() )
556 myIsOnGeometry = false;
557 myGeom = GEOM::GEOM_Object::_nil();
559 if ( !myGeom->_is_nil() )
560 myGeomEntry = myGeom->GetStudyEntry();
562 myDlg->setTitile( myToCreate, myIsMesh );
563 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !subMesh->_is_nil() );
564 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, !myGeom->_is_nil() );
565 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
566 if ( myIsInvalidSubMesh )
568 // it is necessary to select a new geometry
569 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->show();
570 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
574 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
576 myDlg->updateGeometry();
583 else if ( !myIsMesh ) // sub-mesh creation
585 // if a submesh on the selected shape already exist, pass to submesh edition mode
586 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
587 subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
588 bool editSubmesh = ( !subMesh->_is_nil() &&
589 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
590 tr( "EDIT_SUBMESH_QUESTION"),
591 SUIT_MessageBox::Yes |
593 SUIT_MessageBox::No )
594 == SUIT_MessageBox::Yes );
597 selectionMgr()->clearFilters();
598 selectObject( pSubmesh );
599 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
604 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
605 selectObject( _PTR(SObject)() );
610 // discard selected mesh if submesh creation not allowed because of
611 // a global algorithm that does not support submeshes
612 if ( char* algoName = isSubmeshIgnored() ) {
613 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
614 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
615 CORBA::string_free( algoName );
616 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
617 selectObject( _PTR(SObject)() );
622 // enable/disable popup for choice of geom selection way
624 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
625 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toLatin1().data() ))
627 mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
628 if ( !mesh->_is_nil() )
629 enable = /*( shapeDim > 1 ) && */( mesh->NbEdges() > 0 );
631 myDlg->setGeomPopupEnabled( enable );
633 //rnv: issue 21056: "Create Sub Mesh": focus should automatically switch to geometry
634 if ( pObj && myGeomEntry.isEmpty() )
635 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
638 setFilteredAlgoData();
641 catch ( const SALOME::SALOME_Exception& S_ex )
643 SalomeApp_Tools::QtCatchCorbaException( S_ex );
650 //================================================================================
652 * \brief Verifies validity of input data
653 * \param theMess - Output parameter intended for returning error message
654 * \retval bool - TRUE if input data is valid, false otherwise
656 * Verifies validity of input data. This method is called when "Apply" or "OK" button
657 * is pressed before mesh creation or editing.
659 //================================================================================
660 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
662 // Selected object to be edited
663 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
665 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
670 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
671 if ( aMeshName.isEmpty() )
673 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
677 /* // Imported mesh, if create sub-mesh or edit mesh
678 if ( !myToCreate || ( myToCreate && !myIsMesh ))
680 QString aMeshEntry = myDlg->selectedObject
681 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
682 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
683 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
684 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
685 theMess = tr( "IMPORTED_MESH" );
692 if ( myToCreate || myIsInvalidSubMesh )
694 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
695 if ( aGeomEntry.isEmpty() )
697 theMess = tr( myIsMesh ?
698 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
699 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
703 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
704 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
711 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
712 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
714 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
719 if ( !myIsMesh ) // i.e sub-mesh creation,
721 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
722 if ( aMeshEntry == "" )
724 theMess = tr( "MESH_IS_NOT_DEFINED" );
727 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
728 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
730 theMess = tr( "MESH_IS_NULL" );
733 if ( !isSubshapeOk() )
735 theMess = tr( "INVALID_SUBSHAPE" );
744 //================================================================================
746 * \brief check compatibility of the algorithm and another algorithm or hypothesis
747 * \param theAlgoData - algorithm data
748 * \param theHypData - hypothesis data
749 * \param theHypType - hypothesis type
750 * \retval bool - check result
752 //================================================================================
753 static bool isCompatible(const HypothesisData* theAlgoData,
754 const HypothesisData* theHypData,
755 const int theHypType)
760 if ( theHypType == SMESHGUI_MeshOp::Algo ) // compatibility of 2 algos
761 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
763 bool isOptional; // compatibility of algo and hyp
764 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
767 //================================================================================
769 * \brief check compatibility of the geometry
770 * \param theAlgoData - to select hypos able to be used by this algo
771 * \param theDim - algo dimension
772 * \retval bool - check result
774 //================================================================================
775 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
778 if ( theDim < 1 || myGeom->_is_nil() )
781 bool isApplicable = false;
782 if ( myGeomEntry == myLastGeomEntry && !myGeomEntry.isEmpty() ) {
783 THypLabelIsAppMap::const_iterator lab2isApp = myHypMapIsApplicable.find( theAlgoData->Label );
784 if ( lab2isApp != myHypMapIsApplicable.end() ) {
785 isApplicable = lab2isApp.value();
789 bool toCheckIsApplicableToAll = !myIsMesh;
790 if ( toCheckIsApplicableToAll )
791 toCheckIsApplicableToAll = ( myGeom->GetType() == GEOM_GROUP );
793 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, myGeom, toCheckIsApplicableToAll );
794 myHypMapIsApplicable.insert( theAlgoData->Label, isApplicable );
798 //================================================================================
800 * \brief check compatibility of the mesh type
801 * \param theAlgoData - to select hypos able to be used by this algo
802 * \param theDim - algo dimension
803 * \retval bool - check result
805 //================================================================================
806 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
813 int curMeshType = myDlg->currentMeshType();
814 switch ( curMeshType ) {
824 case MT_QUADRILATERAL:
848 bool isAvailableAlgo = theAlgoData->OutputTypes.isEmpty();
849 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
850 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ )
852 if ( *inElemType == elemType )
854 isAvailableAlgo = true;
858 return isAvailableAlgo;
861 //================================================================================
863 * \brief Get available hypotheses or algorithms
864 * \param theDim - specifies dimension of returned hypotheses/algorifms
865 * \param theHypType - specifies whether algorims or hypotheses or additional ones
866 * are retrieved (possible values are in HypType enumeration)
867 * \param theHyps - output list of hypotheses' names
868 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
869 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
870 * \param theMeshType - type of mesh for filtering algorithms (optional)
872 * Get available hypotheses or algorithm in accordance with input parameters.
873 * Result (\a theHyps) optionally depends on the following:
874 * - selected algorithm(s)
875 * - selected geometry
876 * - selected mesh type
878 //================================================================================
879 void SMESHGUI_MeshOp::availableHyps( const int theDim,
880 const int theHypType,
881 QStringList& theHyps,
882 THypDataList& theDataList,
883 HypothesisData* thePrevAlgoData,
884 HypothesisData* theNextAlgoData,
885 const QString& theMeshType)
889 bool isAlgo = ( theHypType == Algo );
890 bool isAux = ( theHypType >= AddHyp );
891 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
893 std::multimap< double, HypothesisData* > sortedHyps;
894 QStringList::const_iterator anIter;
895 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
897 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
898 if ( isCompatible( thePrevAlgoData, aData, theHypType ) &&
899 isCompatible( theNextAlgoData, aData, theHypType ) &&
900 isCompatibleToGeometry( aData, theDim ) &&
901 isCompatibleToMeshType( aData, theDim ))
903 int groupID = aData->GroupID;
904 int priority = aData->Priority;
905 if ( groupID < 0 || groupID > 9 ) groupID = 9;
906 if ( priority < 0 || priority > 999 ) priority = 999;
908 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
912 if ( !sortedHyps.empty() )
914 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
915 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
916 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
918 HypothesisData* aData = key_hyp->second;
919 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
920 if ( aPrevGroup != aGroup )
922 theDataList.append( aGroup );
923 theHyps.append( aGroup->Label );
926 theDataList.append( aData );
927 theHyps.append( aData->Label );
932 //================================================================================
934 * \brief Gets existing hypotheses or algorithms
935 * \param theDim - specifies dimension of returned hypotheses/algorifms
936 * \param theHypType - specifies whether algorims or hypotheses or additional ones
937 * are retrieved (possible values are in HypType enumeration)
938 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
939 * \param theHyps - output list of names.
940 * \param theHypVars - output list of variables.
941 * \param theAlgoData - to select hypos able to be used by this algo (optional)
943 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
946 * WARNING: when using this method to get hyps existing in Mesh component,
947 * call availableHyps() before in order to get only hyps of available types
948 * that was filtered by availableHyps()
950 //================================================================================
951 void SMESHGUI_MeshOp::existingHyps( const int theDim,
952 const int theHypType,
953 _PTR(SObject) theFather,
954 QStringList& theHyps,
955 THypList& theHypList,
956 HypothesisData* theAlgoData) const
958 // Clear hypoheses list
965 _PTR(SObject) aHypRoot;
966 _PTR(GenericAttribute) anAttr;
967 _PTR(AttributeName) aName;
968 _PTR(AttributeIOR) anIOR;
970 const bool isMesh = !_CAST( SComponent, theFather );
973 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
975 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
977 const bool isAux = ( theHypType >= AddHyp );
978 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
980 if ( theFather->FindSubObject( aPart, aHypRoot ) )
982 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypRoot );
983 for ( ; anIter->More(); anIter->Next() )
985 _PTR(SObject) anObj = anIter->Value();
986 if ( isMesh ) // i.e. mesh or submesh
988 _PTR(SObject) aRefObj;
989 if ( anObj->ReferencedObject( aRefObj ) )
994 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
997 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
998 if ( !CORBA::is_nil( aVar ) )
1000 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
1001 if ( !aHypVar->_is_nil() )
1003 CORBA::String_var hypType = aHypVar->GetName();
1004 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
1005 if ( !aData) continue;
1006 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
1007 ( isCompatible ( theAlgoData, aData, theHypType )) &&
1008 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
1009 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
1011 std::string aHypName = aName->Value();
1012 theHyps.append( aHypName.c_str() );
1013 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
1022 //================================================================================
1024 * \brief If create or edit a submesh, return a hypothesis holding parameters used
1025 * to mesh a sub-shape
1026 * \param aHypType - The hypothesis type name
1027 * \param aServerLib - Server library name
1028 * \param hypData - The structure holding the hypothesis type etc.
1029 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
1031 //================================================================================
1032 SMESH::SMESH_Hypothesis_var
1033 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1034 const QString& aServerLib,
1035 const SMESH::HypInitParams* aParams ) const
1037 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1038 return SMESH::SMESH_Hypothesis::_nil();
1040 const int nbColonsInMeshEntry = 3;
1041 bool isSubMesh = myToCreate ?
1043 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1045 // get mesh and geom object
1046 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1047 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1052 anEntry = myDlg->selectedObject
1053 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1054 if ( _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1056 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1057 if ( myToCreate ) // mesh and geom may be selected
1059 aMesh = SMESH::SMESH_Mesh::_narrow( Obj );
1060 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1061 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1062 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1064 else // edition: sub-mesh may be selected
1066 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1067 if ( !sm->_is_nil() ) {
1068 aMesh = sm->GetFather();
1069 aGeomVar = sm->GetSubShape();
1076 if ( !myToCreate ) // mesh to edit can be selected
1078 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1079 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1081 aMesh = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1082 if ( !aMesh->_is_nil() )
1083 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1086 if ( aGeomVar->_is_nil() ) {
1087 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1088 if ( _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( anEntry.toUtf8().data() ))
1090 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1095 SMESH::HypInitParams initParams;
1096 enum { BY_MESH, BY_GEOM, BY_AVERAGE_LENGTH }; // same as ::SMESH_Hypothesis::InitWay
1099 initParams = *aParams;
1103 initParams.way = isSubMesh ? BY_MESH : BY_GEOM;
1106 SMESH::SMESH_Hypothesis_var hyp =
1107 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1108 aServerLib.toUtf8().data(),
1112 if ( hyp->_is_nil() && initParams.way == BY_MESH )
1114 initParams.way = BY_GEOM;
1115 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1116 aServerLib.toUtf8().data(),
1121 if ( hyp->_is_nil() && initParams.way == BY_GEOM )
1123 initParams.way = BY_AVERAGE_LENGTH;
1124 initParams.averageLength = 1.;
1125 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1126 aServerLib.toUtf8().data(),
1134 //================================================================================
1136 * \brief initialize a hypothesis creator
1138 //================================================================================
1140 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1142 if ( !theCreator ) return;
1144 // Set shapes, of mesh and sub-mesh if any
1146 // get Entry of the Geom object
1147 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1148 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1149 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1151 if ( myToCreate && myIsMesh )
1152 aMeshEntry = aGeomEntry;
1154 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1155 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1156 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1157 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1160 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1161 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1163 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1164 if ( !aGeomVar->_is_nil() )
1166 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1168 aMeshEntry = aGeomEntry;
1172 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1173 // take geometry from submesh being created
1174 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1176 // if current object is sub-mesh
1177 SMESH::SMESH_subMesh_var aSubMeshVar =
1178 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1179 if ( !aSubMeshVar->_is_nil() ) {
1180 SMESH::SMESH_Mesh_var aMesh = aSubMeshVar->GetFather();
1181 if ( !aMesh->_is_nil() ) {
1182 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
1183 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1184 if ( !aGeomVar->_is_nil() )
1185 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1191 theCreator->setShapeEntry( aGeomEntry );
1192 if ( aMeshEntry != "" )
1193 theCreator->setMainShapeEntry( aMeshEntry );
1195 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1198 //================================================================================
1200 * \Brief Returns tab dimension
1201 * \param tab - the tab in the dlg
1202 * \param dlg - my dialogue
1203 * \retval int - dimension
1205 //================================================================================
1206 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1209 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1210 if (tab == dlg->tab(i))
1215 //================================================================================
1217 * \brief Create hypothesis
1218 * \param theHypType - hypothesis category (main or additional)
1219 * \param theIndex - index of type of hypothesis to be created
1221 * Specifies dimension of hypothesis to be created (using sender() method),
1222 * specifies its type and calls method for hypothesis creation
1224 //================================================================================
1225 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1227 // Specifies dimension of hypothesis to be created
1228 int aDim = getTabDim( sender(), myDlg );
1232 // Specifies type of hypothesis to be created
1233 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1234 if (theIndex < 0 || theIndex >= dataList.count())
1236 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1238 // Create hypothesis
1239 createHypothesis(aDim, theHypType, aHypTypeName);
1244 QString GetUniqueName (const QStringList& theHypNames,
1245 const QString& theName,
1246 size_t theIteration = 1)
1248 QString aName = theName + "_" + QString::number( theIteration );
1249 if ( theHypNames.contains( aName ) )
1250 return GetUniqueName( theHypNames, theName, ++theIteration );
1255 //================================================================================
1257 * \brief Return names of all existing hypotheses
1259 //================================================================================
1261 QStringList SMESHGUI_MeshOp::getHypoNames()
1263 QStringList aHypNames;
1265 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1266 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1267 const TType2HypList& aType2HypList = aDimIter.value();
1268 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1269 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1270 const THypList& aHypList = aTypeIter.value();
1271 THypList::const_iterator anIter = aHypList.begin();
1272 for ( ; anIter != aHypList.end(); anIter++) {
1273 const THypItem& aHypItem = *anIter;
1274 const QString& aHypName = aHypItem.second;
1275 aHypNames.append(aHypName);
1282 //================================================================================
1284 * Create hypothesis and update dialog.
1285 * \param theDim - dimension of hypothesis to be created
1286 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1287 * \param theTypeName - specifies hypothesis to be created
1289 //================================================================================
1290 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1292 const QString& theTypeName)
1294 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1301 // get a unique hyp name
1302 QString aHypName = GetUniqueName( getHypoNames(), aData->Label);
1305 bool dialog = false;
1307 QString aClientLibName = aData->ClientLibName;
1308 if (aClientLibName == "") {
1309 // Call hypothesis creation server method (without GUI)
1310 SMESH::SMESH_Hypothesis_var aHyp =
1311 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1315 // Get hypotheses creator client (GUI)
1316 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1318 // Create hypothesis
1321 // Get parameters appropriate to initialize a new hypothesis
1322 SMESH::SMESH_Hypothesis_var initParamHyp =
1323 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1325 removeCustomFilters(); // Issue 0020170
1327 // set shapes, of mesh and sub-mesh if any
1328 initHypCreator( aCreator );
1330 myDlg->setEnabled( false );
1331 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1336 SMESH::SMESH_Hypothesis_var aHyp =
1337 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1346 //================================================================================
1348 * Necessary steps after hypothesis creation
1349 * \param result - creation result:
1352 * 2 = additional value meaning that slot is called not from dialog box
1354 //================================================================================
1355 void SMESHGUI_MeshOp::onHypoCreated( int result )
1359 int obj = myDlg->getActiveObject();
1360 onActivateObject( obj ); // Issue 0020170. Restore filters
1361 myDlg->setEnabled( true );
1364 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1366 int nbHyp = myExistingHyps[myDim][myType].count();
1367 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1368 QStringList aNewHyps;
1369 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1370 if (aNewHyps.count() > nbHyp)
1372 for (int i = nbHyp; i < aNewHyps.count(); i++)
1373 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1378 //================================================================================
1380 * \brief Calls plugin methods for hypothesis editing
1381 * \param theHypType - specifies whether main hypothesis or additional one
1383 * \param theIndex - index of existing hypothesis
1385 * Calls plugin methods for hypothesis editing
1387 //================================================================================
1388 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1390 // Speicfies dimension of hypothesis to be created
1391 int aDim = getTabDim( sender(), myDlg );
1395 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1396 if ( theIndex < 0 || theIndex >= aList.count() )
1398 const THypItem& aHypItem = aList[ theIndex ];
1399 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1400 if ( aHyp->_is_nil() )
1403 SMESHGUI_GenericHypothesisCreator* aCreator =
1404 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1407 // set initial parameters
1408 SMESH::SMESH_Hypothesis_var initParamHyp =
1409 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1410 SMESH::toQStr( aHyp->GetLibName() ));
1411 aCreator->setInitParamsHypothesis( initParamHyp );
1413 // set shapes, of mesh and sub-mesh if any
1414 initHypCreator( aCreator );
1416 removeCustomFilters(); // Issue 0020170
1417 myDlg->setEnabled( false );
1419 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1423 //================================================================================
1425 * Necessary steps after hypothesis edition
1426 * \param result - creation result:
1430 //================================================================================
1431 void SMESHGUI_MeshOp::onHypoEdited( int result )
1433 int obj = myDlg->getActiveObject();
1434 onActivateObject( obj ); // Issue 0020170. Restore filters
1435 myDlg->setEnabled( true );
1438 //================================================================================
1440 * \brief access to hypothesis data
1441 * \param theDim - hyp dimension
1442 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1443 * \param theIndex - index in the list
1444 * \retval HypothesisData* - result data, may be 0
1446 //================================================================================
1447 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1448 const int theHypType,
1451 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1452 theHypType > -1 && theHypType < NbHypTypes &&
1453 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1454 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1458 //================================================================================
1460 * \brief Update list of algorithms and hypotheses according to currently selected
1461 * algorithm, geometry and mesh type
1463 //================================================================================
1464 void SMESHGUI_MeshOp::setFilteredAlgoData()
1466 // keep current algorithms
1467 HypothesisData* curAlgos[ 4 ];
1468 for ( int dim = 0; dim <= 3; ++dim )
1469 curAlgos[ dim ] = hypData( dim, Algo, currentHyp( dim, Algo ));
1471 // find out myMaxShapeDim by checking algorithm applicability to geometry
1473 int curMeshType = myDlg->currentMeshType();
1474 myDlg->setCurrentMeshType( MT_ANY );
1475 QStringList algosAvailable;
1476 // get available algorithms taking into account geometry only
1477 if ( myGeom->_is_nil() )
1481 if ( myToCreate ) // readMesh() has done it if !myToCreate
1482 for ( int dim = 0; dim <= 3; ++dim )
1483 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1487 if ( myGeomEntry != myLastGeomEntry )
1488 myHypMapIsApplicable.clear();
1490 for ( int dim = 0; dim <= 3; ++dim )
1492 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1493 if ( algosAvailable.count() )
1494 myMaxShapeDim = dim;
1496 if ( !myGeomEntry.isEmpty() )
1497 myLastGeomEntry = myGeomEntry;
1499 myDlg->setMaxHypoDim( myMaxShapeDim );
1501 // set mesh types according to myMaxShapeDim
1502 updateMeshTypeList();
1504 // update available hypo-sets that depend on geometry and mesh type
1505 myDlg->setCurrentMeshType( Max( MT_ANY, curMeshType ));
1506 updateHypoSets(); // it sets myAvailableHypData by curMeshType
1508 // restore current algorithms according to changed myAvailableHypData
1509 algosAvailable.clear();
1510 for ( int dim = 0; dim <= 3; ++dim )
1512 int algoIndex = myAvailableHypData[ dim ][ Algo ].indexOf( curAlgos[ dim ]);
1513 while ( algosAvailable.count() <= algoIndex )
1514 algosAvailable << "";
1515 myDlg->tab( dim )->setAvailableHyps( Algo, algosAvailable );
1516 setCurrentHyp( dim, Algo, algoIndex );
1517 if ( algoIndex < 0 )
1518 curAlgos[ dim ] = 0;
1521 // find a selected algo, current or of highest dimension
1522 int algoDim = myDlg->currentTab();
1523 if ( !curAlgos[ algoDim ])
1524 for ( algoDim = SMESH::DIM_3D; algoDim >= SMESH::DIM_0D; algoDim-- )
1525 if ( curAlgos[ algoDim ] )
1527 if ( algoDim < SMESH::DIM_0D )
1528 algoDim = myMaxShapeDim;
1530 // set algorithms and hypotheses according to all parameters (mesh type etc)
1531 onAlgoSelected( currentHyp( algoDim, Algo ), algoDim );
1534 //================================================================================
1536 * \brief Set available algos and hypos according to the selected algorithm
1537 * \param theIndex - algorithm index
1538 * \param theDim - algorithm dimension
1540 //================================================================================
1541 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1544 if ( myIgnoreAlgoSelection )
1547 int curDim = getTabDim( sender(), myDlg );
1548 int aDim = theDim < 0 ? curDim : theDim;
1552 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1554 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1555 HypothesisData* algoByDim[4];
1556 algoByDim[ aDim ] = algoData;
1558 QStringList anAvailable;
1559 const int algoDim = aDim;
1561 // 2 loops: backward and forward from algo dimension (forward == to higher dimension)
1562 for ( int forward = 1; forward >= 0; --forward )
1564 int dim = algoDim, lastDim = SMESH::DIM_3D, dir = 1;
1566 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1568 //bool noCompatible = false;
1569 for ( ; dim * dir <= lastDim * dir; dim += dir)
1571 // if ( noCompatible ) // the selected algo has no compatible ones (like 1D2D3D algo)
1573 // anAvailable.clear();
1574 // myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1575 // myAvailableHypData[dim][Algo].clear();
1576 // algoByDim[ dim ] = 0;
1580 int algoIndex = currentHyp( dim, Algo );
1581 HypothesisData *curAlgo = hypData( dim, Algo, algoIndex );
1583 // set new available algorithms
1584 HypothesisData *prevAlgo = 0;
1585 if ( dim != algoDim )
1586 for ( int prevDim = dim + 1; prevDim <=3 && !prevAlgo; ++prevDim )
1587 prevAlgo = hypData( prevDim, Algo, currentHyp( prevDim, Algo ));
1588 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1589 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1591 //noCompatible = ( prevAlgo && !forward && anAvailable.isEmpty() );
1594 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1595 setCurrentHyp( dim, Algo, algoIndex, /*updateHyps=*/true );
1597 algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1600 // activate tabs according to algorithms availability
1601 if ( anAvailable.isEmpty() ) myDlg->disableTab( dim );
1602 else myDlg->enableTab( dim );
1605 } // loops backward and forward
1608 // set hypotheses corresponding to the found algorithms
1610 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
1612 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1614 if ( !isAccessibleDim( dim ))
1617 // get indices of selected hyps
1618 const int nbTypes = nbDlgHypTypes(dim);
1619 std::vector<int> hypIndexByType( nbTypes, -1 );
1620 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1622 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1626 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1628 const int type = Min( dlgType, AddHyp );
1629 myAvailableHypData[ dim ][ type ].clear();
1630 QStringList anAvailable, anExisting;
1632 HypothesisData* curAlgo = algoByDim[ dim ];
1633 int hypIndex = hypIndexByType[ dlgType ];
1635 SMESH::SMESH_Hypothesis_var curHyp;
1637 HypothesisData* hypData = 0;
1638 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1640 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1641 if ( !curHyp->_is_nil() )
1643 curHypType = SMESH::toQStr( curHyp->GetName() );
1644 hypData = SMESH::GetHypothesisData( curHypType );
1647 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) // edition, algo not selected
1649 // try to find algo by selected hypothesis in order to keep it selected
1650 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1651 if ( !algoDeselectedByUser &&
1652 myObjHyps[ dim ][ type ].count() > 0 &&
1653 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1655 for ( int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i )
1657 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1658 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1666 // get hyps compatible with curAlgo
1667 bool defaulHypAvlbl = false;
1670 if ( hypData && !isCompatible( curAlgo, hypData, type ))
1671 curHyp = SMESH::SMESH_Hypothesis::_nil();
1672 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo );
1673 existingHyps ( dim, type, pComp, anExisting, myExistingHyps[ dim ][ type ], curAlgo );
1674 defaulHypAvlbl = ( type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1676 // set list of hypotheses
1677 if ( dlgType <= AddHyp )
1679 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1680 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1682 // set current existing hypothesis
1683 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1684 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1687 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1689 // none is yet selected => select the sole existing if it is not optional
1690 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1691 bool isOptional = true;
1692 if ( algoByDim[ dim ] &&
1693 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1697 setCurrentHyp( dim, dlgType, hypIndex );
1703 //================================================================================
1705 * \brief Create a sub-mesh on internal edges in the case where the global algorithm
1706 * is of type 1D-2D[-3D] so that the internal edges would remain not meshed.
1708 //================================================================================
1710 void SMESHGUI_MeshOp::createSubMeshOnInternalEdges( SMESH::SMESH_Mesh_ptr theMesh,
1711 GEOM::GEOM_Object_ptr theMainShape )
1713 if ( theMesh->_is_nil() || theMainShape->_is_nil() )
1716 if ( isAccessibleDim( 1 ))
1717 return; // global 1D algorithm is/can be assigned
1719 const HypothesesSet::SetType internSet = HypothesesSet::INTERN;
1720 bool toCreate = true;
1721 bool toCreateMandatory = ( myHypoSet &&
1722 myAverageSize > 0 &&
1723 ( myHypoSet->init( /*algo=*/ true, internSet ), myHypoSet->more()) &&
1724 ( myHypoSet->init( /*algo=*/false, internSet ), myHypoSet->more()));
1725 if ( !toCreateMandatory ) // ask the user
1726 toCreate = false; // can't pass both mesh and geometry to Create Submesh operation (so far?)
1727 // toCreate = SUIT_MessageBox::warning( SMESHGUI::desktop(),
1728 // QObject::tr("SMESH_WRN_WARNING"),
1729 // QObject::tr("SMESH_CREATE_SUBMESH_ON_INTERNAL_EDGES"),
1730 // QObject::tr("SMESH_BUT_YES"),
1731 // QObject::tr("SMESH_BUT_NO"), 1, 0);
1736 if ( !GEOMBase::GetShape( theMainShape, shape ))
1739 std::vector< TopoDS_Shape > internalEdges;
1740 for ( TopExp_Explorer edge( shape, TopAbs_EDGE, TopAbs_WIRE ); edge.More(); edge.Next() )
1741 internalEdges.push_back( edge.Current() );
1743 if ( internalEdges.empty() )
1746 TopTools_IndexedMapOfShape shapeIDs;
1747 TopExp::MapShapes( shape, shapeIDs );
1749 std::set< int > intIDSet;
1750 for ( size_t i = 0; i < internalEdges.size(); ++i )
1751 intIDSet.insert( shapeIDs.FindIndex( internalEdges[ i ]));
1753 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1754 if (geomGen->_is_nil()) return;
1756 GEOM::GEOM_Object_var edgeGroup;
1757 GEOM::GEOM_IShapesOperations_wrap sOp = geomGen->GetIShapesOperations();
1758 GEOM::GEOM_IGroupOperations_wrap gOp = geomGen->GetIGroupOperations();
1759 GEOM::ListOfGO_var geomGroups = sOp->GetExistingSubObjects( theMainShape,
1760 /*groupsOnly=*/true );
1761 for ( CORBA::ULong i = 0; i < geomGroups->length(); ++i )
1763 GEOM::ListOfLong_var ids = gOp->GetObjects( geomGroups[ i ]);
1764 std::set< int > idSet( & ids[0], & ids[0] + ids->length() );
1765 if ( idSet == intIDSet )
1767 edgeGroup = geomGroups[ i ];
1772 if ( edgeGroup->_is_nil() )
1774 GEOM::GEOM_Object_var edgeGroup = gOp->CreateGroup( theMainShape, TopAbs_EDGE );
1776 GEOM::ListOfLong_var edgeIDs = new GEOM::ListOfLong;
1777 edgeIDs->length( internalEdges.size() );
1778 std::set< int >::iterator id = intIDSet.begin();
1779 for ( size_t i = 0; i < intIDSet.size(); ++i, ++id )
1781 gOp->UnionIDs( edgeGroup, edgeIDs );
1783 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( edgeGroup, "Internal edges", theMainShape );
1786 if ( !toCreateMandatory )
1788 // show Create Sub-mesh dislog
1789 // _PTR(SObject) aMeshSO = SMESH::FindSObject( theMesh );
1790 // selectionMgr()->clearFilters();
1791 // selectObject( pSubmesh );
1792 // SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
1796 // create a sub-mesh using myAverageSize w/o GUI
1798 SMESH::SMESH_subMesh_var subMesh = theMesh->GetSubMesh( edgeGroup, "" );
1800 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1801 for ( myHypoSet->init( isAlgo, internSet ); myHypoSet->more(); myHypoSet->next() )
1803 QString aHypoTypeName = myHypoSet->current();
1804 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1808 myDim = aHypData->Dim[0];
1812 // create or/and set
1813 SMESH::SMESH_Hypothesis_var newHypo;
1816 myAvailableHypData[ myDim ][ Algo ].clear();
1817 myAvailableHypData[ myDim ][ Algo ] << aHypData;
1818 QStringList hypList; hypList << aHypoTypeName;
1819 myDlg->tab( myDim )->setAvailableHyps( Algo, hypList );
1820 setCurrentHyp( myDim, Algo, 0 );
1821 newHypo = getAlgo( myDim );
1825 SMESH::HypInitParams params = { 2, myAverageSize, false };
1826 newHypo = getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1827 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1828 SALOMEDS::SObject_wrap so =
1829 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), newHypo,
1830 hypName.toUtf8().data() );
1832 SMESH::AddHypothesisOnSubMesh( subMesh, newHypo );
1838 //================================================================================
1840 * \brief Ask the user to enter an average size which will be used to create
1841 * hypotheses of a hypo-set basing on this size
1842 * \param [out] averageSize - average element size
1843 * \return bool - false if the user canceled the dialog
1845 //================================================================================
1847 bool SMESHGUI_MeshOp::getAverageSize( double & averageSize )
1849 HypothesisData* hypData = SMESH::GetHypothesisData( "MaxLength" );
1853 SMESH::SMESH_Hypothesis_var hyp = getInitParamsHypothesis( hypData->TypeName,
1854 hypData->ServerLibName );
1855 if ( hyp->_is_nil() )
1858 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( hypData->TypeName );
1862 initHypCreator( aCreator );
1863 myDlg->setEnabled( false );
1865 aCreator->edit( hyp.in(), HypothesesSet::getCommonHypoSetHypoType(),
1866 dlg(), this, SLOT( onHypoEdited( int )));
1868 StdMeshers::StdMeshers_MaxLength_var lenHyp = StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
1869 if ( lenHyp->_is_nil() )
1872 averageSize = lenHyp->GetLength();
1876 //================================================================================
1878 * \brief Creates and selects hypothesis of hypotheses set
1879 * \param theSetName - The name of hypotheses set
1881 //================================================================================
1882 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1884 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1885 myHypoSet = aHypoSet;
1890 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++)
1892 setCurrentHyp(dim, Algo, -1);
1893 setCurrentHyp(dim, AddHyp, -1);
1894 setCurrentHyp(dim, MainHyp, -1);
1895 onAlgoSelected( -1, dim );
1898 HypothesesSet::SetType setType = aHypoSet->getPreferredHypType();
1899 if ( !aHypoSet->getAlgoAvailable( setType ))
1901 setType = setType == HypothesesSet::ALT ? HypothesesSet::MAIN : HypothesesSet::ALT;
1902 if ( !aHypoSet->getAlgoAvailable( setType ))
1907 if ( aHypoSet->toUseCommonSize() && !getAverageSize( myAverageSize ))
1910 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1911 for ( aHypoSet->init( isAlgo, setType ); aHypoSet->more(); aHypoSet->next() )
1913 QString aHypoTypeName = aHypoSet->current();
1914 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1918 myDim = aHypData->Dim[0];
1919 // create or/and set
1922 int index = myAvailableHypData[myDim][Algo].indexOf( aHypData );
1925 setCurrentHyp( myDim, Algo, index );
1926 onAlgoSelected( index, myDim );
1932 int index = myAvailableHypData[myDim][MainHyp].indexOf( aHypData );
1936 index = myAvailableHypData[myDim][AddHyp].indexOf( aHypData );
1940 if ( myAverageSize > 0 )
1942 SMESH::HypInitParams params = { 2, myAverageSize, aHypoSet->isQuadDominated() };
1943 SMESH::SMESH_Hypothesis_var hyp =
1944 getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1946 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1947 SALOMEDS::SObject_wrap so =
1948 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), hyp,
1949 hypName.toUtf8().data() );
1954 createHypothesis( myDim, myType, aHypoTypeName );
1963 //================================================================================
1965 * \brief Creates mesh
1966 * \param theMess - Output parameter intended for returning error message
1967 * \param theEntryList - List of entries of published objects
1968 * \retval bool - TRUE if mesh is created, FALSE otherwise
1970 //================================================================================
1971 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1976 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1977 if ( aList.isEmpty() )
1979 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1980 if ( aSMESHGen->_is_nil() )
1983 SMESH::SMESH_Mesh_var aMesh= aSMESHGen->CreateEmptyMesh();
1984 if ( aMesh->_is_nil() )
1987 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
1989 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1990 theEntryList.append( aMeshSO->GetID().c_str() );
1995 if ( aList.count() > 1 )
1997 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1998 int i = namePrefix.length() - 1;
1999 while ( i > 0 && namePrefix[i].isDigit() )
2001 if ( i < namePrefix.length() - 1 )
2002 namePrefix.chop( namePrefix.length() - 1 - i );
2006 QStringList::Iterator it = aList.begin();
2007 for ( int i = 0; it != aList.end(); it++, ++i )
2009 QString aGeomEntry = *it;
2010 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2011 GEOM::GEOM_Object_var aGeomVar =
2012 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2014 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2015 if ( aSMESHGen->_is_nil() )
2018 SUIT_OverrideCursor aWaitCursor;
2021 SMESH::SMESH_Mesh_var aMesh = aSMESHGen->CreateMesh( aGeomVar );
2022 if ( aMesh->_is_nil() )
2024 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
2026 theEntryList.append( aMeshSO->GetID().c_str() );
2027 if ( i > 0 ) setDefaultName( namePrefix );
2028 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
2031 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2033 if ( !isAccessibleDim( aDim )) continue;
2035 // assign hypotheses
2036 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2038 const int aHypIndex = currentHyp( aDim, dlgType );
2039 const int aHypType = Min( dlgType, AddHyp );
2040 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2042 SMESH::SMESH_Hypothesis_var aHypVar =
2043 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2044 if ( !aHypVar->_is_nil() )
2045 SMESH::AddHypothesisOnMesh( aMesh, aHypVar );
2048 // find or create algorithm
2049 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2050 if ( !anAlgoVar->_is_nil() )
2051 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2055 if ( myDlg->toCreateAllGroups() && !aGeomVar->_is_nil() )
2057 // Create groups on all geom groups
2059 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
2060 GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
2061 GEOM::ListOfGO_var geomGroups = op->GetExistingSubObjects( aGeomVar,
2062 /*groupsOnly=*/true );
2063 SMESH::SMESH_GroupOnGeom_var meshGroup;
2064 for ( CORBA::ULong iG = 0; iG < geomGroups->length(); ++iG )
2066 SMESH::ElementType elemType = SMESHGUI_GroupOnShapeOp::ElementType( geomGroups[ iG ] );
2067 if ( elemType == SMESH::ALL )
2070 CORBA::String_var name = geomGroups[ iG ]->GetName();
2071 meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
2072 if ( elemType != SMESH::NODE )
2073 meshGroup = aMesh->CreateGroupFromGEOM( SMESH::NODE, name, geomGroups[ iG ]);
2077 createSubMeshOnInternalEdges( aMesh, aGeomVar );
2084 //================================================================================
2086 * \brief Create sub-mesh
2087 * \param theMess - Output parameter intended for returning error message
2088 * \param theEntryList - List of entries of published objects
2089 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
2091 //================================================================================
2092 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
2096 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2097 if ( aSMESHGen->_is_nil() )
2101 SMESH::SMESH_Mesh_var aMesh =
2102 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
2103 if ( aMesh->_is_nil() && myIsInvalidSubMesh )
2105 SMESH::SMESH_subMesh_var aSMVar =
2106 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
2107 if ( !aSMVar->_is_nil() )
2108 aMesh = aSMVar->GetMesh();
2110 if ( aMesh->_is_nil() )
2113 // GEOM shape of the main mesh
2114 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2116 // Name for the new sub-mesh
2117 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
2120 GEOM::GEOM_Object_var aGeomVar;
2122 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
2123 if (aGEOMs.count() == 1)
2125 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2126 QString aGeomEntry = aGEOMs.first();
2127 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2128 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2130 else if (aGEOMs.count() > 1)
2132 // create a GEOM group
2133 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
2134 if (!geomGen->_is_nil()) {
2135 GEOM::GEOM_IGroupOperations_wrap op =
2136 geomGen->GetIGroupOperations();
2137 if (!op->_is_nil()) {
2138 // check and add all selected GEOM objects: they must be
2139 // a sub-shapes of the main GEOM and must be of one type
2141 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
2142 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2143 aSeq->length(aGEOMs.count());
2144 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
2145 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
2146 QString aSubGeomEntry = (*aSubShapesIter);
2147 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
2148 GEOM::GEOM_Object_var aSubGeomVar =
2149 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
2150 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
2152 aGroupType = aSubShapeType;
2154 if (aSubShapeType != aGroupType)
2155 aGroupType = TopAbs_SHAPE;
2157 aSeq[iSubSh] = aSubGeomVar;
2160 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
2161 op->UnionList(aGroupVar, aSeq);
2165 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
2167 // publish the GEOM group in study
2168 QString aNewGeomGroupName ("Auto_group_for_");
2169 aNewGeomGroupName += aName;
2170 SALOMEDS::SObject_wrap aNewGroupSO =
2171 geomGen->AddInStudy( aGeomVar,
2172 aNewGeomGroupName.toUtf8().data(), mainGeom);
2179 if (aGeomVar->_is_nil())
2182 SUIT_OverrideCursor aWaitCursor;
2184 QString aNameOrID = aName;
2185 if ( myIsInvalidSubMesh )
2186 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
2187 // by a valid one in an existing SO
2188 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
2191 SMESH::SMESH_subMesh_var aSubMeshVar = aMesh->GetSubMesh( aGeomVar, aNameOrID.toUtf8().data() );
2192 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2194 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
2195 theEntryList.append( aSubMeshSO->GetID().c_str() );
2198 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2200 if ( !isAccessibleDim( aDim )) continue;
2202 // find or create algorithm
2203 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2204 if ( !anAlgoVar->_is_nil() )
2205 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2206 // assign hypotheses
2207 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2209 const int aHypIndex = currentHyp( aDim, dlgType );
2210 const int aHypType = Min( dlgType, AddHyp );
2211 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2213 SMESH::SMESH_Hypothesis_var aHypVar =
2214 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2215 if ( !aHypVar->_is_nil() )
2216 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2221 // deselect geometry: next submesh should be created on other sub-shape
2222 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2223 selectObject( _PTR(SObject)() );
2226 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/true );
2231 //================================================================================
2233 * \brief Return index of current hypothesis or algorithm
2234 * \param theDim - dimension of hypothesis or algorithm
2235 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2236 * \retval int - index of current hypothesis or algorithm, -1 if None selected
2238 //================================================================================
2239 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2241 if ( 0 <= theDim && theDim <= 3 )
2242 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2247 //================================================================================
2249 * \brief Checks if a hypothesis is selected
2251 //================================================================================
2253 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2258 if ( theHypType < AddHyp ) // only one hyp can be selected
2259 return currentHyp( theDim, theHypType ) == theIndex;
2261 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2262 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2268 //================================================================================
2270 * \brief Returns nb of HypType's taking into account possible several
2271 * selected additional hypotheses which are coded as additional HypType's.
2273 //================================================================================
2275 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2277 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2280 //================================================================================
2282 * \brief Returns true if hypotheses of given dim can be assigned
2283 * \param theDim - hypotheses dimension
2284 * \retval bool - result
2286 //================================================================================
2287 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2289 return myDlg->isTabEnabled( theDim );
2292 //================================================================================
2294 * \brief Sets current hypothesis or algorithms
2295 * \param theDim - dimension of hypothesis or algorithm
2296 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2297 * \param theIndex - Index of hypothesis
2298 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2300 * Gets current hypothesis or algorithms
2302 //================================================================================
2303 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2304 const int theHypType,
2306 const bool updateHypsOnAlgoDeselection)
2308 myIgnoreAlgoSelection = true;
2309 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2310 myIgnoreAlgoSelection = false;
2312 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2314 const QStringList noHyps;
2315 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2316 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2317 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2318 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2322 //================================================================================
2324 * \brief Generates default and sets mesh/submesh name
2326 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2328 //================================================================================
2329 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2333 _PTR(Study) aStudy = SMESH::getStudy();
2336 QString aPrefix = thePrefix;
2337 if ( aPrefix.isEmpty() )
2338 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2340 _PTR(SObject) anObj;
2343 aResName = aPrefix + QString::number( i++ );
2344 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2348 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2349 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2350 aControl->setText( aResName );
2353 //================================================================================
2355 * \brief Gets algorithm or creates it if necessary
2356 * \param theDim - specifies dimension of returned hypotheses/algorifms
2357 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2359 * Gets algorithm or creates it if necessary
2361 //================================================================================
2362 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2364 SMESH::SMESH_Hypothesis_var anAlgoVar;
2366 // get type of the selected algo
2367 int aHypIndex = currentHyp( theDim, Algo );
2368 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2369 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2371 QString aHypName = dataList[ aHypIndex ]->TypeName;
2373 // get existing algorithms
2374 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
2376 existingHyps( theDim, Algo, pComp, tmp, myExistingHyps[ theDim ][ Algo ]);
2378 // look for an existing algo of such a type
2379 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2380 THypList::iterator anIter = aHypVarList.begin();
2381 for ( ; anIter != aHypVarList.end(); anIter++)
2383 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2384 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2386 anAlgoVar = aHypVar;
2391 if (anAlgoVar->_is_nil())
2393 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2396 QString aClientLibName = aHypData->ClientLibName;
2397 if ( aClientLibName.isEmpty() )
2399 // Call hypothesis creation server method (without GUI)
2400 SMESH::SMESH_Hypothesis_var aHyp =
2401 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2406 // Get hypotheses creator client (GUI)
2407 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2411 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2413 SMESH::SMESH_Hypothesis_var aHyp =
2414 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2419 QStringList tmpList;
2420 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2421 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2424 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2425 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2427 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2428 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2430 anAlgoVar = aHypVar;
2436 return anAlgoVar._retn();
2439 //================================================================================
2441 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2443 * Called when mesh is edited only.
2445 //================================================================================
2446 void SMESHGUI_MeshOp::readMesh()
2448 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2449 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2453 if ( myIsOnGeometry )
2455 // Set name of mesh if current object is sub-mesh
2456 SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
2457 if ( !subMesh->_is_nil() )
2459 SMESH::SMESH_Mesh_var aMesh = subMesh->GetFather();
2460 if ( !aMesh->_is_nil() )
2462 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
2463 QString aMeshName = name( aMeshSO );
2464 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2466 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMesh, subMesh );
2469 if ( !myIsInvalidSubMesh )
2471 // Set name of geometry object
2472 CORBA::String_var name = SMESH::GetGeomName( pObj );
2474 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2478 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2479 QStringList anExisting, anAvailable;
2480 bool algoFound = false;
2481 const int dim1st = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2482 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2485 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2486 // find algo index among available ones
2488 anAvailable.clear();
2489 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2491 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ Algo ].first().first;
2492 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( hyp->GetName() ));
2493 availableHyps( dim, Algo, anAvailable, myAvailableHypData[ dim ][ Algo ] );
2494 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf( algoData );
2495 // if ( aHypIndex < 0 && algoData ) {
2496 // // assigned algo is incompatible with other algorithms
2497 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2498 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2500 algoFound = ( aHypIndex > -1 );
2502 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
2503 setCurrentHyp( dim, Algo, aHypIndex );
2504 // set existing and available hypothesis according to the selected algo
2505 if ( aHypIndex > -1 || !algoFound )
2506 onAlgoSelected( aHypIndex, dim );
2510 bool hypWithoutAlgo = false;
2511 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2513 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2516 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2517 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2518 setCurrentHyp( dim, hypType, -1 );
2520 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2522 // find index of required hypothesis among existing ones for this dimension and type
2523 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2524 myExistingHyps[ dim ][ hypType ] );
2525 if ( aHypIndex < 0 ) {
2526 // assigned hypothesis is incompatible with the algorithm
2527 if ( currentHyp( dim, Algo ) < 0 )
2528 { // none algo selected; it is edition for sure, of submesh maybe
2529 hypWithoutAlgo = true;
2530 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2531 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2532 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2533 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2536 setCurrentHyp( dim, hypType + i, aHypIndex );
2538 if ( hypType == MainHyp ) break; // only one main hyp allowed
2542 // make available other hyps of same type as one without algo
2543 if ( hypWithoutAlgo )
2544 onAlgoSelected( currentHyp( /*dim=*/0, Algo ), /*dim=*/0 );
2547 //================================================================================
2549 * \brief Gets name of object
2550 * \param theSO - SObject
2551 * \retval QString - name of object
2553 * Gets name of object
2555 //================================================================================
2556 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2561 _PTR(GenericAttribute) anAttr;
2562 _PTR(AttributeName) aNameAttr;
2563 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2566 aResName = aNameAttr->Value().c_str();
2572 //================================================================================
2574 * \brief Finds hypothesis in input list
2575 * \param theHyp - hypothesis to be found
2576 * \param theHypList - input list of hypotheses
2577 * \retval int - index of hypothesis or -1 if it is not found
2579 * Finds position of hypothesis in input list
2581 //================================================================================
2582 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2583 const THypList& theHypList ) const
2586 if ( !theHyp->_is_nil() )
2589 THypList::const_iterator anIter = theHypList.begin();
2590 for ( ; anIter != theHypList.end(); ++ anIter)
2592 if ( theHyp->_is_equivalent( (*anIter).first ) )
2603 //================================================================================
2605 * \brief Edits mesh or sub-mesh
2606 * \param theMess - Output parameter intended for returning error message
2607 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2609 * Assigns new name hypotheses and algorithms to the mesh or sub-mesh
2611 //================================================================================
2612 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2616 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2617 if ( aSMESHGen->_is_nil() )
2620 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2621 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2625 SUIT_OverrideCursor aWaitCursor;
2628 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2629 SMESH::SetName( pObj, aName );
2630 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2632 // First, remove old algos in order to avoid messages on algorithm hiding
2633 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2635 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2637 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2638 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2639 if ( anAlgoVar->_is_nil() || // no new algo selected or
2640 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2642 // remove old algorithm
2643 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2644 myObjHyps[ dim ][ Algo ].clear();
2649 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2650 CORBA::Object_var anObject = aSObject->GetObject();
2651 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObject );
2652 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2653 bool isMesh = !aMesh->_is_nil();
2654 if ( !isMesh && !aSubMeshVar->_is_nil() )
2655 aMesh = aSubMeshVar->GetFather();
2657 // Assign new algorithms and hypotheses
2658 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2660 //if ( !isAccessibleDim( dim )) continue;
2662 // find or create algorithm
2663 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2665 // assign new algorithm
2666 if ( !anAlgoVar->_is_nil() && // some algo selected and
2667 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2670 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2671 else if ( !aSubMeshVar->_is_nil() )
2672 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2674 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2677 // remove deselected hypotheses
2678 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2680 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2682 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2683 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2684 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2686 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2690 // assign newly selected hypotheses
2691 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2693 const int curIndex = currentHyp( dim, dlgType );
2694 const int hypType = Min( dlgType, AddHyp );
2695 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2697 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2699 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2703 SMESH::AddHypothesisOnMesh (aMesh, hyp );
2704 else if ( !aSubMeshVar->_is_nil() )
2705 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2708 // reread all hypotheses of mesh
2709 QStringList anExisting;
2710 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2714 if ( aSubMeshVar->_is_nil() )
2716 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2717 createSubMeshOnInternalEdges( aMesh, mainGeom );
2720 myHasConcurrentSubBefore =
2721 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2726 //================================================================================
2728 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2729 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2730 * order of sub-mesh computation.
2731 * Returns \c true if a sub-mesh concurrency detected.
2733 //================================================================================
2735 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2736 SMESH::SMESH_subMesh_ptr submesh,
2739 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2742 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2743 if ( isNewConcurrent && askUser )
2745 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2746 tr("CONCURRENT_SUBMESH_APPEARS"),
2747 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2750 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2751 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2752 if ( meshSO && aSelectionMgr )
2754 myDlg->setEnabled( false ); // disactivate selection
2755 selectionMgr()->clearFilters();
2756 selectObject( meshSO );
2757 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2758 qApp->processEvents();
2760 myDlg->setEnabled( true );
2761 int obj = myDlg->getActiveObject();
2762 onActivateObject( obj ); // restore filter
2765 selectObject( SMESH::FindSObject( submesh ));
2772 return isNewConcurrent;
2775 //================================================================================
2777 * \brief Verifies whether given operator is valid for this one
2778 * \param theOtherOp - other operation
2779 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2781 * method redefined from base class verifies whether given operator is valid for
2782 * this one (i.e. can be started "above" this operator). In current implementation method
2783 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2786 //================================================================================
2787 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2789 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2792 //================================================================================
2794 * \brief SLOT. Is called when the user selects a way of geometry selection
2795 * \param theByMesh - true if the user wants to find geometry by mesh element
2797 //================================================================================
2798 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2801 if ( !myShapeByMeshOp ) {
2802 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2803 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2804 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2805 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2806 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2808 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2809 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2810 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2811 SMESH::SMESH_Mesh_var aMesh =
2812 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2813 if ( !aMesh->_is_nil() ) {
2814 myDlg->hide(); // stop processing selection
2815 myShapeByMeshOp->setModule( getSMESHGUI() );
2816 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2817 myShapeByMeshOp->SetMesh( aMesh );
2818 myShapeByMeshOp->start();
2824 //================================================================================
2826 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2828 //================================================================================
2829 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2831 if ( myShapeByMeshOp == op ) {
2832 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2834 // Select a found geometry object
2835 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2836 if ( !aGeomVar->_is_nil() )
2838 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2839 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2840 selectObject( aGeomSO );
2847 //================================================================================
2849 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2851 //================================================================================
2852 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2854 if ( myShapeByMeshOp == op && myDlg ) {
2859 //================================================================================
2861 * \brief Selects a SObject
2862 * \param theSObj - the SObject to select
2864 //================================================================================
2865 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2867 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2868 SALOME_ListIO anIOList;
2870 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2871 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2872 anIOList.Append( anIO );
2874 sm->setSelectedObjects( anIOList, false );
2877 //================================================================================
2879 * \brief Update available list of mesh types
2881 //================================================================================
2882 void SMESHGUI_MeshOp::updateMeshTypeList()
2884 QStringList meshTypes;
2885 meshTypes.append( tr( "MT_ANY" ) );
2886 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2888 meshTypes.append( tr( "MT_TRIANGULAR" ) );
2889 meshTypes.append( tr( "MT_QUADRILATERAL" ) );
2891 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2893 meshTypes.append( tr( "MT_TETRAHEDRAL" ) );
2894 meshTypes.append( tr( "MT_HEXAHEDRAL" ) );
2897 myDlg->setAvailableMeshType( meshTypes );
2900 //================================================================================
2902 * \brief Update available list of hypothesis sets
2904 //================================================================================
2905 void SMESHGUI_MeshOp::updateHypoSets()
2907 // get available algorithms taking into account geometry and mesh type
2908 QStringList algosAvailable;
2909 if ( myDlg->currentMeshType() != MT_ANY )
2910 for ( int dim = 0; dim <= 3; ++dim )
2911 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
2913 THypDataList anAvailableAlgsData;
2914 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( myMaxShapeDim );
2915 QStringList aFilteredHypothesesSetsList;
2916 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2917 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2919 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2920 HypothesesSet::SetType sType;
2921 for ( sType = HypothesesSet::MAIN; sType <= HypothesesSet::ALT; SMESHUtils::Increment( sType ))
2923 bool isAvailable = false;
2924 for ( currentHypoSet->init( true, sType ); currentHypoSet->more(); currentHypoSet->next() )
2926 isAvailable = false;
2927 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2928 for ( int dim = SMESH::DIM_0D; dim <= myMaxShapeDim; dim++) {
2929 int aCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoDataIn );
2930 if ( aCurrentAvailableAlgo > -1 ) {
2939 currentHypoSet->setAlgoAvailable( sType, isAvailable );
2941 if ( currentHypoSet->getAlgoAvailable( HypothesesSet::MAIN ) ||
2942 currentHypoSet->getAlgoAvailable( HypothesesSet::ALT ))
2943 aFilteredHypothesesSetsList.append( *inHypoSetName );
2945 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2948 //================================================================================
2950 * \brief SLOT. Is called when the user select type of mesh
2951 * \param theTabIndex - Index of current active tab
2952 * \param theIndex - Index of current type of mesh
2954 //================================================================================
2955 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex )
2957 setFilteredAlgoData();