1 // Copyright (C) 2007-2020 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 = mainGeom->GetGen();
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->TypeName );
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->TypeName, 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 if ( initParams.way == BY_AVERAGE_LENGTH )
1108 hyp = SMESHGUI::GetSMESHGen()->CreateHypothesisByAverageLength( aHypType.toUtf8().data(),
1109 aServerLib.toUtf8().data(),
1110 initParams.averageLength,
1111 initParams.quadDominated );
1113 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toUtf8().data(),
1114 aServerLib.toUtf8().data(),
1118 if ( hyp->_is_nil() && initParams.way == BY_MESH )
1120 initParams.way = BY_GEOM;
1121 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1122 aServerLib.toUtf8().data(),
1127 if ( hyp->_is_nil() && initParams.way == BY_GEOM )
1129 initParams.way = BY_AVERAGE_LENGTH;
1130 initParams.averageLength = 1.;
1131 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1132 aServerLib.toUtf8().data(),
1140 //================================================================================
1142 * \brief initialize a hypothesis creator
1144 //================================================================================
1146 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1148 if ( !theCreator ) return;
1150 // Set shapes, of mesh and sub-mesh if any
1152 // get Entry of the Geom object
1153 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1154 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1155 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1157 if ( myToCreate && myIsMesh )
1158 aMeshEntry = aGeomEntry;
1160 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1161 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
1162 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1163 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1166 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1167 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1169 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1170 if ( !aGeomVar->_is_nil() )
1172 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1174 aMeshEntry = aGeomEntry;
1178 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1179 // take geometry from submesh being created
1180 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
1182 // if current object is sub-mesh
1183 SMESH::SMESH_subMesh_var aSubMeshVar =
1184 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1185 if ( !aSubMeshVar->_is_nil() ) {
1186 SMESH::SMESH_Mesh_var aMesh = aSubMeshVar->GetFather();
1187 if ( !aMesh->_is_nil() ) {
1188 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
1189 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1190 if ( !aGeomVar->_is_nil() )
1191 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1197 theCreator->setShapeEntry( aGeomEntry );
1198 if ( aMeshEntry != "" )
1199 theCreator->setMainShapeEntry( aMeshEntry );
1201 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1204 //================================================================================
1206 * \Brief Returns tab dimension
1207 * \param tab - the tab in the dlg
1208 * \param dlg - my dialogue
1209 * \retval int - dimension
1211 //================================================================================
1212 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1215 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1216 if (tab == dlg->tab(i))
1221 //================================================================================
1223 * \brief Create hypothesis
1224 * \param theHypType - hypothesis category (main or additional)
1225 * \param theIndex - index of type of hypothesis to be created
1227 * Specifies dimension of hypothesis to be created (using sender() method),
1228 * specifies its type and calls method for hypothesis creation
1230 //================================================================================
1231 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1233 // Specifies dimension of hypothesis to be created
1234 int aDim = getTabDim( sender(), myDlg );
1238 // Specifies type of hypothesis to be created
1239 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1240 if (theIndex < 0 || theIndex >= dataList.count())
1242 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1244 // Create hypothesis
1245 createHypothesis(aDim, theHypType, aHypTypeName);
1250 QString GetUniqueName (const QStringList& theHypNames,
1251 const QString& theName,
1252 size_t theIteration = 1)
1254 QString aName = theName + "_" + QString::number( theIteration );
1255 if ( theHypNames.contains( aName ) )
1256 return GetUniqueName( theHypNames, theName, ++theIteration );
1261 //================================================================================
1263 * \brief Return names of all existing hypotheses
1265 //================================================================================
1267 QStringList SMESHGUI_MeshOp::getHypoNames()
1269 QStringList aHypNames;
1271 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1272 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1273 const TType2HypList& aType2HypList = aDimIter.value();
1274 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1275 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1276 const THypList& aHypList = aTypeIter.value();
1277 THypList::const_iterator anIter = aHypList.begin();
1278 for ( ; anIter != aHypList.end(); anIter++) {
1279 const THypItem& aHypItem = *anIter;
1280 const QString& aHypName = aHypItem.second;
1281 aHypNames.append(aHypName);
1288 //================================================================================
1290 * Create hypothesis and update dialog.
1291 * \param theDim - dimension of hypothesis to be created
1292 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1293 * \param theTypeName - specifies hypothesis to be created
1295 //================================================================================
1296 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1298 const QString& theTypeName)
1300 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1307 // get a unique hyp name
1308 QString aHypName = GetUniqueName( getHypoNames(), aData->Label);
1311 bool dialog = false;
1313 QString aClientLibName = aData->ClientLibName;
1314 if (aClientLibName == "") {
1315 // Call hypothesis creation server method (without GUI)
1316 SMESH::SMESH_Hypothesis_var aHyp =
1317 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1321 // Get hypotheses creator client (GUI)
1322 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1324 // Create hypothesis
1327 // Get parameters appropriate to initialize a new hypothesis
1328 SMESH::SMESH_Hypothesis_var initParamHyp =
1329 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1331 removeCustomFilters(); // Issue 0020170
1333 // set shapes, of mesh and sub-mesh if any
1334 initHypCreator( aCreator );
1336 myDlg->setEnabled( false );
1337 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1342 SMESH::SMESH_Hypothesis_var aHyp =
1343 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1352 //================================================================================
1354 * Necessary steps after hypothesis creation
1355 * \param result - creation result:
1358 * 2 = additional value meaning that slot is called not from dialog box
1360 //================================================================================
1361 void SMESHGUI_MeshOp::onHypoCreated( int result )
1365 int obj = myDlg->getActiveObject();
1366 onActivateObject( obj ); // Issue 0020170. Restore filters
1367 myDlg->setEnabled( true );
1370 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent("SMESH");
1372 int nbHyp = myExistingHyps[myDim][myType].count();
1373 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1374 QStringList aNewHyps;
1375 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1376 if (aNewHyps.count() > nbHyp)
1378 for (int i = nbHyp; i < aNewHyps.count(); i++)
1379 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1384 //================================================================================
1386 * \brief Calls plugin methods for hypothesis editing
1387 * \param theHypType - specifies whether main hypothesis or additional one
1389 * \param theIndex - index of existing hypothesis
1391 * Calls plugin methods for hypothesis editing
1393 //================================================================================
1394 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1396 // Speicfies dimension of hypothesis to be created
1397 int aDim = getTabDim( sender(), myDlg );
1401 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1402 if ( theIndex < 0 || theIndex >= aList.count() )
1404 const THypItem& aHypItem = aList[ theIndex ];
1405 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1406 if ( aHyp->_is_nil() )
1409 SMESHGUI_GenericHypothesisCreator* aCreator =
1410 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1413 // set initial parameters
1414 SMESH::SMESH_Hypothesis_var initParamHyp =
1415 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1416 SMESH::toQStr( aHyp->GetLibName() ));
1417 aCreator->setInitParamsHypothesis( initParamHyp );
1419 // set shapes, of mesh and sub-mesh if any
1420 initHypCreator( aCreator );
1422 removeCustomFilters(); // Issue 0020170
1423 myDlg->setEnabled( false );
1425 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1429 //================================================================================
1431 * Necessary steps after hypothesis edition
1432 * \param result - creation result:
1436 //================================================================================
1437 void SMESHGUI_MeshOp::onHypoEdited( int /*result*/ )
1439 int obj = myDlg->getActiveObject();
1440 onActivateObject( obj ); // Issue 0020170. Restore filters
1441 myDlg->setEnabled( true );
1444 //================================================================================
1446 * \brief access to hypothesis data
1447 * \param theDim - hyp dimension
1448 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1449 * \param theIndex - index in the list
1450 * \retval HypothesisData* - result data, may be 0
1452 //================================================================================
1453 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1454 const int theHypType,
1457 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1458 theHypType > -1 && theHypType < NbHypTypes &&
1459 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1460 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1464 //================================================================================
1466 * \brief Update list of algorithms and hypotheses according to currently selected
1467 * algorithm, geometry and mesh type
1469 //================================================================================
1470 void SMESHGUI_MeshOp::setFilteredAlgoData()
1472 // keep current algorithms
1473 HypothesisData* curAlgos[ 4 ];
1474 for ( int dim = 0; dim <= 3; ++dim )
1475 curAlgos[ dim ] = hypData( dim, Algo, currentHyp( dim, Algo ));
1477 // find out myMaxShapeDim by checking algorithm applicability to geometry
1479 int curMeshType = myDlg->currentMeshType();
1480 myDlg->setCurrentMeshType( MT_ANY );
1481 QStringList algosAvailable;
1482 // get available algorithms taking into account geometry only
1483 if ( myGeom->_is_nil() )
1487 if ( myToCreate ) // readMesh() has done it if !myToCreate
1488 for ( int dim = 0; dim <= 3; ++dim )
1489 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1493 if ( myGeomEntry != myLastGeomEntry )
1494 myHypMapIsApplicable.clear();
1496 for ( int dim = 0; dim <= 3; ++dim )
1498 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
1499 if ( algosAvailable.count() )
1500 myMaxShapeDim = dim;
1502 if ( !myGeomEntry.isEmpty() )
1503 myLastGeomEntry = myGeomEntry;
1505 myDlg->setMaxHypoDim( myMaxShapeDim );
1507 // set mesh types according to myMaxShapeDim
1508 updateMeshTypeList();
1510 // update available hypo-sets that depend on geometry and mesh type
1511 myDlg->setCurrentMeshType( Max( MT_ANY, curMeshType ));
1512 updateHypoSets(); // it sets myAvailableHypData by curMeshType
1514 // restore current algorithms according to changed myAvailableHypData
1515 algosAvailable.clear();
1516 for ( int dim = 0; dim <= 3; ++dim )
1518 int algoIndex = myAvailableHypData[ dim ][ Algo ].indexOf( curAlgos[ dim ]);
1519 while ( algosAvailable.count() <= algoIndex )
1520 algosAvailable << "";
1521 myDlg->tab( dim )->setAvailableHyps( Algo, algosAvailable );
1522 setCurrentHyp( dim, Algo, algoIndex );
1523 if ( algoIndex < 0 )
1524 curAlgos[ dim ] = 0;
1527 // find a selected algo, current or of highest dimension
1528 int algoDim = myDlg->currentTab();
1529 if ( !curAlgos[ algoDim ])
1530 for ( algoDim = SMESH::DIM_3D; algoDim >= SMESH::DIM_0D; algoDim-- )
1531 if ( curAlgos[ algoDim ] )
1533 if ( algoDim < SMESH::DIM_0D )
1534 algoDim = myMaxShapeDim;
1536 // set algorithms and hypotheses according to all parameters (mesh type etc)
1537 onAlgoSelected( currentHyp( algoDim, Algo ), algoDim );
1540 //================================================================================
1542 * \brief Set available algos and hypos according to the selected algorithm
1543 * \param theIndex - algorithm index
1544 * \param theDim - algorithm dimension
1546 //================================================================================
1547 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1550 if ( myIgnoreAlgoSelection )
1553 int curDim = getTabDim( sender(), myDlg );
1554 int aDim = theDim < 0 ? curDim : theDim;
1558 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1560 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1561 HypothesisData* algoByDim[4];
1562 algoByDim[ aDim ] = algoData;
1564 QStringList anAvailable;
1565 const int algoDim = aDim;
1567 // 2 loops: backward and forward from algo dimension (forward == to higher dimension)
1568 for ( int forward = 1; forward >= 0; --forward )
1570 int dim = algoDim, lastDim = SMESH::DIM_3D, dir = 1;
1572 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1574 //bool noCompatible = false;
1575 for ( ; dim * dir <= lastDim * dir; dim += dir)
1577 // if ( noCompatible ) // the selected algo has no compatible ones (like 1D2D3D algo)
1579 // anAvailable.clear();
1580 // myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1581 // myAvailableHypData[dim][Algo].clear();
1582 // algoByDim[ dim ] = 0;
1586 int algoIndex = currentHyp( dim, Algo );
1587 HypothesisData *curAlgo = hypData( dim, Algo, algoIndex );
1589 // set new available algorithms
1590 HypothesisData *prevAlgo = 0;
1591 if ( dim != algoDim )
1592 for ( int prevDim = dim + 1; prevDim <=3 && !prevAlgo; ++prevDim )
1593 prevAlgo = hypData( prevDim, Algo, currentHyp( prevDim, Algo ));
1594 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1595 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1597 //noCompatible = ( prevAlgo && !forward && anAvailable.isEmpty() );
1600 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1601 setCurrentHyp( dim, Algo, algoIndex, /*updateHyps=*/true );
1603 algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1606 // activate tabs according to algorithms availability
1607 if ( anAvailable.isEmpty() ) myDlg->disableTab( dim );
1608 else myDlg->enableTab( dim );
1611 } // loops backward and forward
1614 // set hypotheses corresponding to the found algorithms
1616 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
1618 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1620 if ( !isAccessibleDim( dim ))
1623 // get indices of selected hyps
1624 const int nbTypes = nbDlgHypTypes(dim);
1625 std::vector<int> hypIndexByType( nbTypes, -1 );
1626 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1628 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1632 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1634 const int type = Min( dlgType, AddHyp );
1635 myAvailableHypData[ dim ][ type ].clear();
1636 QStringList anAvailable, anExisting;
1638 HypothesisData* curAlgo = algoByDim[ dim ];
1639 int hypIndex = hypIndexByType[ dlgType ];
1641 SMESH::SMESH_Hypothesis_var curHyp;
1643 HypothesisData* hypData = 0;
1644 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1646 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1647 if ( !curHyp->_is_nil() )
1649 curHypType = SMESH::toQStr( curHyp->GetName() );
1650 hypData = SMESH::GetHypothesisData( curHypType );
1653 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) // edition, algo not selected
1655 // try to find algo by selected hypothesis in order to keep it selected
1656 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1657 if ( !algoDeselectedByUser &&
1658 myObjHyps[ dim ][ type ].count() > 0 &&
1659 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1661 for ( int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i )
1663 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1664 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1672 // get hyps compatible with curAlgo
1673 bool defaulHypAvlbl = false;
1676 if ( hypData && !isCompatible( curAlgo, hypData, type ))
1677 curHyp = SMESH::SMESH_Hypothesis::_nil();
1678 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo );
1679 existingHyps ( dim, type, pComp, anExisting, myExistingHyps[ dim ][ type ], curAlgo );
1680 defaulHypAvlbl = ( type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1682 // set list of hypotheses
1683 if ( dlgType <= AddHyp )
1685 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1686 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1688 // set current existing hypothesis
1689 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1690 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1693 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1695 // none is yet selected => select the sole existing if it is not optional
1696 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1697 bool isOptional = true;
1698 if ( algoByDim[ dim ] &&
1699 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1703 setCurrentHyp( dim, dlgType, hypIndex );
1709 //================================================================================
1711 * \brief Create a sub-mesh on internal edges in the case where the global algorithm
1712 * is of type 1D-2D[-3D] so that the internal edges would remain not meshed.
1714 //================================================================================
1716 void SMESHGUI_MeshOp::createSubMeshOnInternalEdges( SMESH::SMESH_Mesh_ptr theMesh,
1717 GEOM::GEOM_Object_ptr theMainShape )
1719 if ( theMesh->_is_nil() || theMainShape->_is_nil() )
1722 if ( isAccessibleDim( 1 ))
1723 return; // global 1D algorithm is/can be assigned
1725 const HypothesesSet::SetType internSet = HypothesesSet::INTERN;
1726 bool toCreate = true;
1727 bool toCreateMandatory = ( myHypoSet &&
1728 myAverageSize > 0 &&
1729 ( myHypoSet->init( /*algo=*/ true, internSet ), myHypoSet->more()) &&
1730 ( myHypoSet->init( /*algo=*/false, internSet ), myHypoSet->more()));
1731 if ( !toCreateMandatory ) // ask the user
1732 toCreate = false; // can't pass both mesh and geometry to Create Submesh operation (so far?)
1733 // toCreate = SUIT_MessageBox::warning( SMESHGUI::desktop(),
1734 // QObject::tr("SMESH_WRN_WARNING"),
1735 // QObject::tr("SMESH_CREATE_SUBMESH_ON_INTERNAL_EDGES"),
1736 // QObject::tr("SMESH_BUT_YES"),
1737 // QObject::tr("SMESH_BUT_NO"), 1, 0);
1742 if ( !GEOMBase::GetShape( theMainShape, shape ))
1745 std::vector< TopoDS_Shape > internalEdges;
1746 for ( TopExp_Explorer edge( shape, TopAbs_EDGE, TopAbs_WIRE ); edge.More(); edge.Next() )
1747 internalEdges.push_back( edge.Current() );
1749 if ( internalEdges.empty() )
1752 TopTools_IndexedMapOfShape shapeIDs;
1753 TopExp::MapShapes( shape, shapeIDs );
1755 std::set< int > intIDSet;
1756 for ( size_t i = 0; i < internalEdges.size(); ++i )
1757 intIDSet.insert( shapeIDs.FindIndex( internalEdges[ i ]));
1759 GEOM::GEOM_Gen_var geomGen = theMainShape->GetGen();
1760 if (geomGen->_is_nil()) return;
1762 GEOM::GEOM_Object_var edgeGroup;
1763 GEOM::GEOM_IShapesOperations_wrap sOp = geomGen->GetIShapesOperations();
1764 GEOM::GEOM_IGroupOperations_wrap gOp = geomGen->GetIGroupOperations();
1765 GEOM::ListOfGO_var geomGroups = sOp->GetExistingSubObjects( theMainShape,
1766 /*groupsOnly=*/true );
1767 for ( CORBA::ULong i = 0; i < geomGroups->length(); ++i )
1769 GEOM::ListOfLong_var ids = gOp->GetObjects( geomGroups[ i ]);
1770 std::set< int > idSet( & ids[0], & ids[0] + ids->length() );
1771 if ( idSet == intIDSet )
1773 edgeGroup = geomGroups[ i ];
1778 if ( edgeGroup->_is_nil() )
1780 GEOM::GEOM_Object_var edgeGroup = gOp->CreateGroup( theMainShape, TopAbs_EDGE );
1782 GEOM::ListOfLong_var edgeIDs = new GEOM::ListOfLong;
1783 edgeIDs->length( internalEdges.size() );
1784 std::set< int >::iterator id = intIDSet.begin();
1785 for ( size_t i = 0; i < intIDSet.size(); ++i, ++id )
1787 gOp->UnionIDs( edgeGroup, edgeIDs );
1789 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( edgeGroup, "Internal edges", theMainShape );
1792 if ( !toCreateMandatory )
1794 // show Create Sub-mesh dislog
1795 // _PTR(SObject) aMeshSO = SMESH::FindSObject( theMesh );
1796 // selectionMgr()->clearFilters();
1797 // selectObject( pSubmesh );
1798 // SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
1802 // create a sub-mesh using myAverageSize w/o GUI
1804 SMESH::SMESH_subMesh_var subMesh = theMesh->GetSubMesh( edgeGroup, "" );
1806 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1807 for ( myHypoSet->init( isAlgo, internSet ); myHypoSet->more(); myHypoSet->next() )
1809 QString aHypoTypeName = myHypoSet->current();
1810 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1814 myDim = aHypData->Dim[0];
1818 // create or/and set
1819 SMESH::SMESH_Hypothesis_var newHypo;
1822 myAvailableHypData[ myDim ][ Algo ].clear();
1823 myAvailableHypData[ myDim ][ Algo ] << aHypData;
1824 QStringList hypList; hypList << aHypoTypeName;
1825 myDlg->tab( myDim )->setAvailableHyps( Algo, hypList );
1826 setCurrentHyp( myDim, Algo, 0 );
1827 newHypo = getAlgo( myDim );
1831 SMESH::HypInitParams params = { 2, myAverageSize, false };
1832 newHypo = getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1833 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1834 SALOMEDS::SObject_wrap so =
1835 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), newHypo,
1836 hypName.toUtf8().data() );
1838 SMESH::AddHypothesisOnSubMesh( subMesh, newHypo );
1844 //================================================================================
1846 * \brief Ask the user to enter an average size which will be used to create
1847 * hypotheses of a hypo-set basing on this size
1848 * \param [out] averageSize - average element size
1849 * \return bool - false if the user canceled the dialog
1851 //================================================================================
1853 bool SMESHGUI_MeshOp::getAverageSize( double & averageSize )
1855 HypothesisData* hypData = SMESH::GetHypothesisData( "MaxLength" );
1859 SMESH::SMESH_Hypothesis_var hyp = getInitParamsHypothesis( hypData->TypeName,
1860 hypData->ServerLibName );
1861 if ( hyp->_is_nil() )
1864 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( hypData->TypeName );
1868 initHypCreator( aCreator );
1869 myDlg->setEnabled( false );
1871 aCreator->edit( hyp.in(), HypothesesSet::getCommonHypoSetHypoType(),
1872 dlg(), this, SLOT( onHypoEdited( int )));
1874 StdMeshers::StdMeshers_MaxLength_var lenHyp = StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
1875 if ( lenHyp->_is_nil() )
1878 averageSize = lenHyp->GetLength();
1882 //================================================================================
1884 * \brief Creates and selects hypothesis of hypotheses set
1885 * \param theSetName - The name of hypotheses set
1887 //================================================================================
1888 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1890 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1891 myHypoSet = aHypoSet;
1896 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++)
1898 setCurrentHyp(dim, Algo, -1);
1899 setCurrentHyp(dim, AddHyp, -1);
1900 setCurrentHyp(dim, MainHyp, -1);
1901 onAlgoSelected( -1, dim );
1904 HypothesesSet::SetType setType = aHypoSet->getPreferredHypType();
1905 if ( !aHypoSet->getAlgoAvailable( setType ))
1907 setType = ( setType == HypothesesSet::ALT ) ? HypothesesSet::MAIN : HypothesesSet::ALT;
1908 if ( !aHypoSet->getAlgoAvailable( setType ))
1913 if ( aHypoSet->toUseCommonSize() && !getAverageSize( myAverageSize ))
1917 for ( int isAlgo = 1; isAlgo >= 0; --isAlgo )
1918 for ( aHypoSet->init( isAlgo, setType ); aHypoSet->more(); aHypoSet->next() )
1920 QString aHypoTypeName = aHypoSet->current();
1921 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
1925 myDim = aHypData->Dim[0];
1926 // create or/and set
1929 int index = myAvailableHypData[myDim][Algo].indexOf( aHypData );
1932 setCurrentHyp( myDim, Algo, index );
1933 onAlgoSelected( index, myDim );
1934 maxDim = Max( maxDim, myDim );
1940 int index = myAvailableHypData[myDim][MainHyp].indexOf( aHypData );
1944 index = myAvailableHypData[myDim][AddHyp].indexOf( aHypData );
1948 if ( myAverageSize > 0 )
1950 SMESH::HypInitParams params = { 2, myAverageSize, aHypoSet->isQuadDominated() };
1951 SMESH::SMESH_Hypothesis_var hyp =
1952 getInitParamsHypothesis( aHypData->TypeName, aHypData->ServerLibName, & params );
1954 QString hypName = GetUniqueName( getHypoNames(), aHypData->Label );
1955 SALOMEDS::SObject_wrap so =
1956 SMESHGUI::GetSMESHGen()->PublishInStudy( SALOMEDS::SObject::_nil(), hyp,
1957 hypName.toUtf8().data() );
1962 createHypothesis( myDim, myType, aHypoTypeName );
1969 myDlg->setCurrentTab( maxDim );
1974 //================================================================================
1976 * \brief Creates mesh
1977 * \param theMess - Output parameter intended for returning error message
1978 * \param theEntryList - List of entries of published objects
1979 * \retval bool - TRUE if mesh is created, FALSE otherwise
1981 //================================================================================
1982 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1987 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1988 if ( aList.isEmpty() )
1990 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1991 if ( aSMESHGen->_is_nil() )
1994 SMESH::SMESH_Mesh_var aMesh= aSMESHGen->CreateEmptyMesh();
1995 if ( aMesh->_is_nil() )
1998 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
2000 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
2001 theEntryList.append( aMeshSO->GetID().c_str() );
2006 if ( aList.count() > 1 )
2008 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2009 int i = namePrefix.length() - 1;
2010 while ( i > 0 && namePrefix[i].isDigit() )
2012 if ( i < namePrefix.length() - 1 )
2013 namePrefix.chop( namePrefix.length() - 1 - i );
2017 QStringList::Iterator it = aList.begin();
2018 for ( int i = 0; it != aList.end(); it++, ++i )
2020 QString aGeomEntry = *it;
2021 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2022 GEOM::GEOM_Object_var aGeomVar =
2023 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2025 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2026 if ( aSMESHGen->_is_nil() )
2029 SUIT_OverrideCursor aWaitCursor;
2032 SMESH::SMESH_Mesh_var aMesh = aSMESHGen->CreateMesh( aGeomVar );
2033 if ( aMesh->_is_nil() )
2035 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh.in() );
2037 theEntryList.append( aMeshSO->GetID().c_str() );
2038 if ( i > 0 ) setDefaultName( namePrefix );
2039 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
2042 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2044 if ( !isAccessibleDim( aDim )) continue;
2046 // assign hypotheses
2047 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2049 const int aHypIndex = currentHyp( aDim, dlgType );
2050 const int aHypType = Min( dlgType, AddHyp );
2051 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2053 SMESH::SMESH_Hypothesis_var aHypVar =
2054 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2055 if ( !aHypVar->_is_nil() )
2056 SMESH::AddHypothesisOnMesh( aMesh, aHypVar );
2059 // find or create algorithm
2060 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2061 if ( !anAlgoVar->_is_nil() )
2062 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2066 if ( myDlg->toCreateAllGroups() && !aGeomVar->_is_nil() )
2068 // Create groups on all geom groups
2070 GEOM::GEOM_Gen_var geomGen = aGeomVar->GetGen();
2071 GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
2072 GEOM::ListOfGO_var geomGroups = op->GetExistingSubObjects( aGeomVar,
2073 /*groupsOnly=*/false );
2074 SMESH::SMESH_GroupOnGeom_var meshGroup;
2075 for ( CORBA::ULong iG = 0; iG < geomGroups->length(); ++iG )
2077 SMESH::ElementType elemType = SMESHGUI_GroupOnShapeOp::ElementType( geomGroups[ iG ] );
2078 if ( elemType == SMESH::ALL )
2080 if ( elemType == SMESH::ELEM0D )
2081 elemType = SMESH::NODE;
2083 CORBA::String_var name = geomGroups[ iG ]->GetName();
2084 meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
2085 // if ( elemType != SMESH::NODE )
2086 // meshGroup = aMesh->CreateGroupFromGEOM( SMESH::NODE, name, geomGroups[ iG ]);
2090 createSubMeshOnInternalEdges( aMesh, aGeomVar );
2097 //================================================================================
2099 * \brief Create sub-mesh
2100 * \param theMess - Output parameter intended for returning error message
2101 * \param theEntryList - List of entries of published objects
2102 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
2104 //================================================================================
2105 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
2109 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2110 if ( aSMESHGen->_is_nil() )
2114 SMESH::SMESH_Mesh_var aMesh =
2115 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
2116 if ( aMesh->_is_nil() && myIsInvalidSubMesh )
2118 SMESH::SMESH_subMesh_var aSMVar =
2119 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
2120 if ( !aSMVar->_is_nil() )
2121 aMesh = aSMVar->GetMesh();
2123 if ( aMesh->_is_nil() )
2126 // GEOM shape of the main mesh
2127 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2129 // Name for the new sub-mesh
2130 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
2133 GEOM::GEOM_Object_var aGeomVar;
2135 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
2136 if (aGEOMs.count() == 1)
2138 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2139 QString aGeomEntry = aGEOMs.first();
2140 _PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() );
2141 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2143 else if (aGEOMs.count() > 1)
2145 // create a GEOM group
2146 GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
2147 if ( !geomGen->_is_nil() ) {
2148 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
2149 if ( !op->_is_nil() )
2151 // check and add all selected GEOM objects: they must be
2152 // a sub-shapes of the main GEOM and must be of one type
2154 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
2155 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2156 aSeq->length(aGEOMs.count());
2157 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
2158 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
2159 QString aSubGeomEntry = (*aSubShapesIter);
2160 _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
2161 GEOM::GEOM_Object_var aSubGeomVar =
2162 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
2163 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
2165 aGroupType = aSubShapeType;
2167 if (aSubShapeType != aGroupType)
2168 aGroupType = TopAbs_SHAPE;
2170 aSeq[iSubSh] = aSubGeomVar;
2173 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
2174 op->UnionList(aGroupVar, aSeq);
2178 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
2180 // publish the GEOM group in study
2181 QString aNewGeomGroupName ("Auto_group_for_");
2182 aNewGeomGroupName += aName;
2183 SALOMEDS::SObject_wrap aNewGroupSO =
2184 geomGen->AddInStudy( aGeomVar,
2185 aNewGeomGroupName.toUtf8().data(), mainGeom);
2192 if (aGeomVar->_is_nil())
2195 SUIT_OverrideCursor aWaitCursor;
2197 QString aNameOrID = aName;
2198 if ( myIsInvalidSubMesh )
2199 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
2200 // by a valid one in an existing SO
2201 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
2204 SMESH::SMESH_subMesh_var aSubMeshVar = aMesh->GetSubMesh( aGeomVar, aNameOrID.toUtf8().data() );
2205 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2207 SMESH::SetName( aSubMeshSO, aName.toUtf8().data() );
2208 theEntryList.append( aSubMeshSO->GetID().c_str() );
2211 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2213 if ( !isAccessibleDim( aDim )) continue;
2215 // find or create algorithm
2216 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2217 if ( !anAlgoVar->_is_nil() )
2218 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2219 // assign hypotheses
2220 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2222 const int aHypIndex = currentHyp( aDim, dlgType );
2223 const int aHypType = Min( dlgType, AddHyp );
2224 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2226 SMESH::SMESH_Hypothesis_var aHypVar =
2227 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2228 if ( !aHypVar->_is_nil() )
2229 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2234 // deselect geometry: next submesh should be created on other sub-shape
2235 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2236 selectObject( _PTR(SObject)() );
2239 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/true );
2244 //================================================================================
2246 * \brief Return index of current hypothesis or algorithm
2247 * \param theDim - dimension of hypothesis or algorithm
2248 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2249 * \retval int - index of current hypothesis or algorithm, -1 if None selected
2251 //================================================================================
2252 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2254 if ( 0 <= theDim && theDim <= 3 )
2255 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2260 //================================================================================
2262 * \brief Checks if a hypothesis is selected
2264 //================================================================================
2266 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2271 if ( theHypType < AddHyp ) // only one hyp can be selected
2272 return currentHyp( theDim, theHypType ) == theIndex;
2274 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2275 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2281 //================================================================================
2283 * \brief Returns nb of HypType's taking into account possible several
2284 * selected additional hypotheses which are coded as additional HypType's.
2286 //================================================================================
2288 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2290 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2293 //================================================================================
2295 * \brief Returns true if hypotheses of given dim can be assigned
2296 * \param theDim - hypotheses dimension
2297 * \retval bool - result
2299 //================================================================================
2300 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2302 return myDlg->isTabEnabled( theDim );
2305 //================================================================================
2307 * \brief Sets current hypothesis or algorithms
2308 * \param theDim - dimension of hypothesis or algorithm
2309 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2310 * \param theIndex - Index of hypothesis
2311 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2313 * Gets current hypothesis or algorithms
2315 //================================================================================
2316 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2317 const int theHypType,
2319 const bool updateHypsOnAlgoDeselection)
2321 myIgnoreAlgoSelection = true;
2322 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2323 myIgnoreAlgoSelection = false;
2325 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2327 const QStringList noHyps;
2328 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2329 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2330 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2331 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2335 //================================================================================
2337 * \brief Generates default and sets mesh/submesh name
2339 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2341 //================================================================================
2342 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2346 _PTR(Study) aStudy = SMESH::getStudy();
2349 QString aPrefix = thePrefix;
2350 if ( aPrefix.isEmpty() )
2351 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2353 _PTR(SObject) anObj;
2356 aResName = aPrefix + QString::number( i++ );
2357 anObj = aStudy->FindObject( aResName.toUtf8().data() );
2361 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2362 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2363 aControl->setText( aResName );
2366 //================================================================================
2368 * \brief Gets algorithm or creates it if necessary
2369 * \param theDim - specifies dimension of returned hypotheses/algorifms
2370 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2372 * Gets algorithm or creates it if necessary
2374 //================================================================================
2375 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2377 SMESH::SMESH_Hypothesis_var anAlgoVar;
2379 // get type of the selected algo
2380 int aHypIndex = currentHyp( theDim, Algo );
2381 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2382 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2384 QString aHypName = dataList[ aHypIndex ]->TypeName;
2386 // get existing algorithms
2387 _PTR(SObject) pComp = SMESH::getStudy()->FindComponent("SMESH");
2389 existingHyps( theDim, Algo, pComp, tmp, myExistingHyps[ theDim ][ Algo ]);
2391 // look for an existing algo of such a type
2392 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2393 THypList::iterator anIter = aHypVarList.begin();
2394 for ( ; anIter != aHypVarList.end(); anIter++)
2396 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2397 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2399 anAlgoVar = aHypVar;
2404 if (anAlgoVar->_is_nil())
2406 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2409 QString aClientLibName = aHypData->ClientLibName;
2410 if ( aClientLibName.isEmpty() )
2412 // Call hypothesis creation server method (without GUI)
2413 SMESH::SMESH_Hypothesis_var aHyp =
2414 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2419 // Get hypotheses creator client (GUI)
2420 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2424 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2426 SMESH::SMESH_Hypothesis_var aHyp =
2427 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2432 QStringList tmpList;
2433 _PTR(SComponent) aFather = SMESH::getStudy()->FindComponent( "SMESH" );
2434 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2437 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2438 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2440 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2441 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2443 anAlgoVar = aHypVar;
2449 return anAlgoVar._retn();
2452 //================================================================================
2454 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2456 * Called when mesh is edited only.
2458 //================================================================================
2459 void SMESHGUI_MeshOp::readMesh()
2461 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2462 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2466 if ( myIsOnGeometry )
2468 // Set name of mesh if current object is sub-mesh
2469 SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface< SMESH::SMESH_subMesh >( pObj );
2470 if ( !subMesh->_is_nil() )
2472 SMESH::SMESH_Mesh_var aMesh = subMesh->GetFather();
2473 if ( !aMesh->_is_nil() )
2475 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMesh );
2476 QString aMeshName = name( aMeshSO );
2477 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2479 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMesh, subMesh );
2482 if ( !myIsInvalidSubMesh )
2484 // Set name of geometry object
2485 CORBA::String_var name = SMESH::GetGeomName( pObj );
2487 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2491 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2492 QStringList anExisting, anAvailable;
2493 bool algoFound = false;
2494 const int dim1st = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2495 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2498 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2499 // find algo index among available ones
2501 anAvailable.clear();
2502 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2504 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ Algo ].first().first;
2505 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( hyp->GetName() ));
2506 availableHyps( dim, Algo, anAvailable, myAvailableHypData[ dim ][ Algo ] );
2507 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf( algoData );
2508 // if ( aHypIndex < 0 && algoData ) {
2509 // // assigned algo is incompatible with other algorithms
2510 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2511 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2513 algoFound = ( aHypIndex > -1 );
2515 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
2516 setCurrentHyp( dim, Algo, aHypIndex );
2517 // set existing and available hypothesis according to the selected algo
2518 if ( aHypIndex > -1 || !algoFound )
2519 onAlgoSelected( aHypIndex, dim );
2523 bool hypWithoutAlgo = false;
2524 for ( int dim = dim1st; dim <= SMESH::DIM_3D; ++dim )
2526 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2529 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2530 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2531 setCurrentHyp( dim, hypType, -1 );
2533 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2535 // find index of required hypothesis among existing ones for this dimension and type
2536 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2537 myExistingHyps[ dim ][ hypType ] );
2538 if ( aHypIndex < 0 ) {
2539 // assigned hypothesis is incompatible with the algorithm
2540 if ( currentHyp( dim, Algo ) < 0 )
2541 { // none algo selected; it is edition for sure, of submesh maybe
2542 hypWithoutAlgo = true;
2543 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2544 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2545 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2546 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2549 setCurrentHyp( dim, hypType + i, aHypIndex );
2551 if ( hypType == MainHyp ) break; // only one main hyp allowed
2555 // make available other hyps of same type as one without algo
2556 if ( hypWithoutAlgo )
2557 onAlgoSelected( currentHyp( /*dim=*/0, Algo ), /*dim=*/0 );
2560 //================================================================================
2562 * \brief Gets name of object
2563 * \param theSO - SObject
2564 * \retval QString - name of object
2566 * Gets name of object
2568 //================================================================================
2569 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2574 _PTR(GenericAttribute) anAttr;
2575 _PTR(AttributeName) aNameAttr;
2576 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2579 aResName = aNameAttr->Value().c_str();
2585 //================================================================================
2587 * \brief Finds hypothesis in input list
2588 * \param theHyp - hypothesis to be found
2589 * \param theHypList - input list of hypotheses
2590 * \retval int - index of hypothesis or -1 if it is not found
2592 * Finds position of hypothesis in input list
2594 //================================================================================
2595 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2596 const THypList& theHypList ) const
2599 if ( !theHyp->_is_nil() )
2602 THypList::const_iterator anIter = theHypList.begin();
2603 for ( ; anIter != theHypList.end(); ++ anIter)
2605 if ( theHyp->_is_equivalent( (*anIter).first ) )
2616 //================================================================================
2618 * \brief Edits mesh or sub-mesh
2619 * \param theMess - Output parameter intended for returning error message
2620 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2622 * Assigns new name hypotheses and algorithms to the mesh or sub-mesh
2624 //================================================================================
2625 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2629 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2630 if ( aSMESHGen->_is_nil() )
2633 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2634 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
2638 SUIT_OverrideCursor aWaitCursor;
2641 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2642 SMESH::SetName( pObj, aName );
2643 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2645 // First, remove old algos in order to avoid messages on algorithm hiding
2646 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2648 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2650 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2651 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2652 if ( anAlgoVar->_is_nil() || // no new algo selected or
2653 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2655 // remove old algorithm
2656 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2657 myObjHyps[ dim ][ Algo ].clear();
2662 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2663 CORBA::Object_var anObject = aSObject->GetObject();
2664 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObject );
2665 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2666 bool isMesh = !aMesh->_is_nil();
2667 if ( !isMesh && !aSubMeshVar->_is_nil() )
2668 aMesh = aSubMeshVar->GetFather();
2670 // Assign new algorithms and hypotheses
2671 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2673 //if ( !isAccessibleDim( dim )) continue;
2675 // find or create algorithm
2676 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2678 // assign new algorithm
2679 if ( !anAlgoVar->_is_nil() && // some algo selected and
2680 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2683 SMESH::AddHypothesisOnMesh( aMesh, anAlgoVar );
2684 else if ( !aSubMeshVar->_is_nil() )
2685 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2687 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2690 // remove deselected hypotheses
2691 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2693 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2695 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2696 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2697 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2699 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2703 // assign newly selected hypotheses
2704 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2706 const int curIndex = currentHyp( dim, dlgType );
2707 const int hypType = Min( dlgType, AddHyp );
2708 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2710 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2712 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2716 SMESH::AddHypothesisOnMesh (aMesh, hyp );
2717 else if ( !aSubMeshVar->_is_nil() )
2718 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2721 // reread all hypotheses of mesh
2722 QStringList anExisting;
2723 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2727 if ( aSubMeshVar->_is_nil() )
2729 GEOM::GEOM_Object_var mainGeom = aMesh->GetShapeToMesh();
2730 createSubMeshOnInternalEdges( aMesh, mainGeom );
2733 myHasConcurrentSubBefore =
2734 checkSubMeshConcurrency( aMesh, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2739 //================================================================================
2741 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2742 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2743 * order of sub-mesh computation.
2744 * Returns \c true if a sub-mesh concurrency detected.
2746 //================================================================================
2748 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2749 SMESH::SMESH_subMesh_ptr submesh,
2752 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2755 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2756 if ( isNewConcurrent && askUser )
2758 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2759 tr("CONCURRENT_SUBMESH_APPEARS"),
2760 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2763 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2764 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2765 if ( meshSO && aSelectionMgr )
2767 myDlg->setEnabled( false ); // disactivate selection
2768 selectionMgr()->clearFilters();
2769 selectObject( meshSO );
2770 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2771 qApp->processEvents();
2773 myDlg->setEnabled( true );
2774 int obj = myDlg->getActiveObject();
2775 onActivateObject( obj ); // restore filter
2778 selectObject( SMESH::FindSObject( submesh ));
2785 return isNewConcurrent;
2788 //================================================================================
2790 * \brief Verifies whether given operator is valid for this one
2791 * \param theOtherOp - other operation
2792 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2794 * method redefined from base class verifies whether given operator is valid for
2795 * this one (i.e. can be started "above" this operator). In current implementation method
2796 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2799 //================================================================================
2800 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2802 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2805 //================================================================================
2807 * \brief SLOT. Is called when the user selects a way of geometry selection
2808 * \param theByMesh - true if the user wants to find geometry by mesh element
2810 //================================================================================
2811 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2814 if ( !myShapeByMeshOp ) {
2815 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2816 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2817 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2818 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2819 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2821 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2822 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2823 if ( _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() )) {
2824 SMESH::SMESH_Mesh_var aMesh =
2825 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2826 if ( !aMesh->_is_nil() ) {
2827 myDlg->hide(); // stop processing selection
2828 myShapeByMeshOp->setModule( getSMESHGUI() );
2829 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2830 myShapeByMeshOp->SetMesh( aMesh );
2831 myShapeByMeshOp->start();
2837 //================================================================================
2839 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2841 //================================================================================
2842 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2844 if ( myShapeByMeshOp == op ) {
2845 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2847 // Select a found geometry object
2848 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2849 if ( !aGeomVar->_is_nil() )
2851 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2852 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toUtf8().data() )) {
2853 selectObject( aGeomSO );
2860 //================================================================================
2862 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2864 //================================================================================
2865 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2867 if ( myShapeByMeshOp == op && myDlg ) {
2872 //================================================================================
2874 * \brief Selects a SObject
2875 * \param theSObj - the SObject to select
2877 //================================================================================
2878 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2880 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2881 SALOME_ListIO anIOList;
2883 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2884 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2885 anIOList.Append( anIO );
2887 sm->setSelectedObjects( anIOList, false );
2890 //================================================================================
2892 * \brief Update available list of mesh types
2894 //================================================================================
2895 void SMESHGUI_MeshOp::updateMeshTypeList()
2897 QStringList meshTypes;
2898 meshTypes.append( tr( "MT_ANY" ) );
2899 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2901 meshTypes.append( tr( "MT_TRIANGULAR" ) );
2902 meshTypes.append( tr( "MT_QUADRILATERAL" ) );
2904 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2906 meshTypes.append( tr( "MT_TETRAHEDRAL" ) );
2907 meshTypes.append( tr( "MT_HEXAHEDRAL" ) );
2910 myDlg->setAvailableMeshType( meshTypes );
2913 //================================================================================
2915 * \brief Update available list of hypothesis sets
2917 //================================================================================
2918 void SMESHGUI_MeshOp::updateHypoSets()
2920 // get available algorithms taking into account geometry and mesh type
2921 QStringList algosAvailable;
2922 if ( myDlg->currentMeshType() != MT_ANY )
2923 for ( int dim = 0; dim <= 3; ++dim )
2924 availableHyps( dim, Algo, algosAvailable, myAvailableHypData[ dim ][ Algo ] );
2926 THypDataList anAvailableAlgsData;
2927 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( myMaxShapeDim );
2928 QStringList aFilteredHypothesesSetsList;
2929 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2930 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2932 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2933 HypothesesSet::SetType sType;
2934 for ( sType = HypothesesSet::MAIN; sType <= HypothesesSet::ALT; SMESHUtils::Increment( sType ))
2936 bool isAvailable = false;
2937 for ( currentHypoSet->init( true, sType ); currentHypoSet->more(); currentHypoSet->next() )
2939 isAvailable = false;
2940 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2941 for ( int dim = SMESH::DIM_0D; dim <= myMaxShapeDim; dim++) {
2942 int aCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoDataIn );
2943 if ( aCurrentAvailableAlgo > -1 ) {
2952 currentHypoSet->setAlgoAvailable( sType, isAvailable );
2954 if ( currentHypoSet->hasAlgo( HypothesesSet::MAIN ) &&
2955 currentHypoSet->hasAlgo( HypothesesSet::ALT ))
2957 HypothesesSet::SetType setType = HypothesesSet::getPreferredHypType();
2958 if ( !currentHypoSet->getAlgoAvailable( setType ))
2959 continue; // not add if a preferred type not available currently
2962 if ( currentHypoSet->getAlgoAvailable( HypothesesSet::MAIN ) ||
2963 currentHypoSet->getAlgoAvailable( HypothesesSet::ALT ))
2965 aFilteredHypothesesSetsList.append( *inHypoSetName );
2968 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2971 //================================================================================
2973 * \brief SLOT. Is called when the user select type of mesh
2974 * \param theTabIndex - Index of current active tab
2975 * \param theIndex - Index of current type of mesh
2977 //================================================================================
2978 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int /*theTabIndex*/, const int /*theIndex*/ )
2980 setFilteredAlgoData();