1 // Copyright (C) 2007-2016 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_Hypotheses.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_MeshDlg.h"
33 #include "SMESHGUI_Operations.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESH_NumberFilter.hxx"
37 #include "SMESH_TypeFilter.hxx"
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
44 #include <GEOMImpl_Types.hxx>
46 // SALOME GUI includes
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <LightApp_UpdateFlags.h>
52 #include <SUIT_MessageBox.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_Session.h>
55 #include <SALOME_InteractiveObject.hxx>
56 #include <SALOME_ListIO.hxx>
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SComponent.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDS_Study.hxx>
62 #include <SALOMEDS_wrap.hxx>
65 #include <QStringList>
67 #include <QApplication>
71 #include <TopoDS_Shape.hxx>
72 #include <TopoDS_Shell.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <BRep_Tool.hxx>
77 #include <SALOMEconfig.h>
78 #include CORBA_CLIENT_HEADER(SMESH_Gen)
80 //================================================================================
83 * \param theToCreate - if this parameter is true then operation is used for creation,
84 * for editing otherwise
86 * Initialize operation
88 //================================================================================
89 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
90 : SMESHGUI_SelectionOp(),
93 myToCreate( theToCreate ),
94 myIsMesh( theIsMesh ),
95 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()
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 );
194 //================================================================================
196 * \brief Creates dialog if necessary and shows it
198 * Virtual method redefined from base class called when operation is started creates
199 * dialog if necessary and shows it, activates selection
201 //================================================================================
202 void SMESHGUI_MeshOp::startOperation()
204 myIgnoreAlgoSelection = false;
208 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
209 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
211 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
212 this, SLOT( onCreateHyp( const int, const int ) ) );
213 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
214 this, SLOT( onEditHyp( const int, const int ) ) );
215 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
216 this, SLOT( onAlgoSelected( const int ) ) );
218 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
219 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
220 connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
222 if ( myIsMesh ) myHelpFileName = "constructing_meshes.html";
223 else myHelpFileName = "constructing_submeshes.html";
226 myHelpFileName = "editing_meshes.html";
229 SMESHGUI_SelectionOp::startOperation();
230 // iterate through dimensions and get available algorithms, set them to the dialog
231 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
232 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
234 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
236 // clear available hypotheses
237 aTab->setAvailableHyps( MainHyp, hypList );
238 aTab->setAvailableHyps( AddHyp, hypList );
239 aTab->setExistingHyps( MainHyp, hypList );
240 aTab->setExistingHyps( AddHyp, hypList );
241 myExistingHyps[ i ][ MainHyp ].clear();
242 myExistingHyps[ i ][ AddHyp ].clear();
244 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
245 aTab->setAvailableHyps( Algo, hypList );
250 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
254 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
256 myDlg->setCurrentTab( SMESH::DIM_3D );
258 QStringList TypeMeshList;
259 createMeshTypeList( TypeMeshList );
260 setAvailableMeshType( TypeMeshList );
263 myDlg->setGeomPopupEnabled(false);
266 myHasConcurrentSubBefore = false;
268 myObjectToSelect.clear();
271 //=================================================================================
273 * \brief Selects a recently created mesh or sub-mesh if necessary
275 * Virtual method redefined from base class called when operation is committed
276 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
277 * selection when the custom selection filters are removed.
279 //=================================================================================
280 void SMESHGUI_MeshOp::commitOperation()
282 SMESHGUI_SelectionOp::commitOperation();
284 if ( !myObjectToSelect.isEmpty() ) {
285 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
286 SUIT_DataOwnerPtrList aList;
287 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
288 aSelectionMgr->setSelected( aList );
293 //================================================================================
295 * \brief Creates selection filter
296 * \param theId - identifier of current selection widget
297 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
299 * Creates selection filter in accordance with identifier of current selection widget
301 //================================================================================
302 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
304 if ( theId == SMESHGUI_MeshDlg::Geom )
306 // TColStd_MapOfInteger allTypesMap;
307 // for ( int i = 0; i < 10; i++ )
308 // allTypesMap.Add( i );
309 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
310 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
312 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
313 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
314 else if ( theId == SMESHGUI_MeshDlg::Mesh )
315 return new SMESH_TypeFilter( SMESH::MESH );
320 //================================================================================
322 * \brief check if selected shape is a sub-shape of the shape to mesh
323 * \retval bool - check result
325 //================================================================================
326 bool SMESHGUI_MeshOp::isSubshapeOk() const
328 if ( !myToCreate || myIsMesh ) // not submesh creation
332 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
333 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
334 if (!pMesh) return false;
336 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
337 if (mesh->_is_nil()) return false;
339 // main shape of the mesh
340 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
341 if (mainGeom->_is_nil()) return false;
345 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
347 if (aGEOMs.count() > 0) {
348 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
349 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
350 if (geomGen->_is_nil() || !aStudy) return false;
352 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
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 = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().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(aStudy->StudyId());
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 = studyDS()->FindObjectID( aMeshEntry.toLatin1().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].toLatin1().data() );
436 // GEOM::GEOM_Object_var geom;
437 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().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].toLatin1().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 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
466 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
467 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
468 if ( pMesh && pGeom ) {
469 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
470 if ( !geom->_is_nil() ) {
472 switch ( geom->GetShapeType() ) {
473 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
474 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
475 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
476 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
477 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
478 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
479 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
482 _PTR(GenericAttribute) anAttr;
483 _PTR(SObject) aSubmeshRoot;
484 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
485 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
487 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
488 for ( ; smIter->More(); smIter->Next() )
490 _PTR(SObject) aSmObj = smIter->Value();
491 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
493 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
494 for ( ; anIter1->More(); anIter1->Next()) {
495 _PTR(SObject) pGeom2 = anIter1->Value();
496 if ( pGeom2->ReferencedObject( pGeom2 ) &&
497 pGeom2->GetID() == pGeom->GetID() )
504 return _PTR(SObject)();
507 //================================================================================
509 * \brief Updates dialog's look and feel
511 * Virtual method redefined from the base class updates dialog's look and feel
513 //================================================================================
514 void SMESHGUI_MeshOp::selectionDone()
516 if (!dlg()->isVisible() || !myDlg->isEnabled())
519 SMESHGUI_SelectionOp::selectionDone();
523 myIsOnGeometry = true;
524 myIsInvalidSubMesh = false;
526 //Check geometry for mesh
527 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
528 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
531 SMESH::SMESH_Mesh_var aMeshVar =
532 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
533 if (!aMeshVar->_is_nil()) {
534 if (!myToCreate && !aMeshVar->HasShapeToMesh())
535 myIsOnGeometry = false;
541 // Enable tabs according to shape dimension
546 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
547 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
549 if (aGEOMs.count() > 0) {
550 // one or more GEOM shape selected
551 aSeq->length(aGEOMs.count());
552 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
554 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
555 QString aSubGeomEntry = (*aSubShapesIter);
556 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
559 SALOMEDS_SObject* sobj = _CAST(SObject,pSubGeom);
561 GEOM::GEOM_Object_var aSubGeomVar =
562 GEOM::GEOM_Object::_narrow(sobj->GetObject());
563 if( !aSubGeomVar->_is_nil() ){
564 aSeq[iSubSh] = aSubGeomVar;
570 // get geometry by selected sub-mesh
571 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
572 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
573 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
574 if (!aGeomVar->_is_nil()) {
580 if (aSeq->length() > 0) {
582 for ( CORBA::ULong iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
583 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
584 switch ( aGeomVar->GetShapeType() ) {
585 case GEOM::SOLID: shapeDim = 3; break;
587 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
589 // TopoDS_Shape aShape;
590 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
591 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
594 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
596 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
597 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
601 if (GEOMBase::GetShape(aGeomVar, aShape))
603 TopExp_Explorer exp (aShape, TopAbs_SOLID);
607 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
608 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
611 // for (; exp.More() && shapeDim == 2; exp.Next()) {
612 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
616 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
617 shapeDim = qMax(2, shapeDim);
618 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
619 shapeDim = qMax(1, shapeDim);
620 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
621 shapeDim = qMax(0, shapeDim);
629 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
630 // reset algos before disabling tabs (0020138)
631 onAlgoSelected(-1, i);
633 myDlg->setMaxHypoDim( shapeDim );
634 myMaxShapeDim = shapeDim;
635 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
637 if (!myToCreate) // edition: read hypotheses
641 SMESH::SMESH_subMesh_var submeshVar =
642 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
643 myIsMesh = submeshVar->_is_nil();
644 myIsInvalidSubMesh = ( !myIsMesh && submeshVar->GetId() < 1 );
645 myDlg->setTitile( myToCreate, myIsMesh );
646 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
647 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
648 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
649 if ( myIsInvalidSubMesh )
651 // it is necessary to select a new geometry
652 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->show();
653 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
657 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
659 myDlg->updateGeometry();
666 else if ( !myIsMesh ) // submesh creation
668 // if a submesh on the selected shape already exist, pass to submesh edition mode
669 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
670 SMESH::SMESH_subMesh_var sm =
671 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
672 bool editSubmesh = ( !sm->_is_nil() &&
673 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
674 tr( "EDIT_SUBMESH_QUESTION"),
675 SUIT_MessageBox::Yes |
677 SUIT_MessageBox::No )
678 == SUIT_MessageBox::Yes );
681 selectionMgr()->clearFilters();
682 selectObject( pSubmesh );
683 SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
688 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
689 selectObject( _PTR(SObject)() );
694 // discard selected mesh if submesh creation not allowed because of
695 // a global algorithm that does not support submeshes
696 if ( char* algoName = isSubmeshIgnored() ) {
697 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
698 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
699 CORBA::string_free( algoName );
700 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
701 selectObject( _PTR(SObject)() );
706 // enable/disable popup for choice of geom selection way
708 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
709 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
710 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
711 if ( !mesh->_is_nil() ) {
712 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
713 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
714 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
715 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
716 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
717 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
720 myDlg->setGeomPopupEnabled( enable );
723 else { // no geometry defined
726 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
728 availableHyps( dim, Algo, hypList, myAvailableHypData[dim][Algo]);
729 myDlg->tab( dim )->setAvailableHyps( Algo, hypList );
730 if ( hypList.empty() ) myDlg->disableTab( dim );
731 else myDlg->enableTab( dim );
734 //Hide labels and fields (Mesh and Geometry)
735 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
736 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
740 int curIndex = myDlg->currentMeshType( );
741 QStringList TypeMeshList;
742 createMeshTypeList( TypeMeshList );
743 setAvailableMeshType( TypeMeshList );
744 curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
745 myDlg->setCurrentMeshType( curIndex );
746 setFilteredAlgoData( myMaxShapeDim, curIndex);
748 catch ( const SALOME::SALOME_Exception& S_ex )
750 SalomeApp_Tools::QtCatchCorbaException( S_ex );
757 //================================================================================
759 * \brief Verifies validity of input data
760 * \param theMess - Output parameter intended for returning error message
761 * \retval bool - TRUE if input data is valid, false otherwise
763 * Verifies validity of input data. This method is called when "Apply" or "OK" button
764 * is pressed before mesh creation or editing.
766 //================================================================================
767 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
769 // Selected object to be edited
770 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
772 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
777 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
778 if ( aMeshName.isEmpty() )
780 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
784 /* // Imported mesh, if create sub-mesh or edit mesh
785 if ( !myToCreate || ( myToCreate && !myIsMesh ))
787 QString aMeshEntry = myDlg->selectedObject
788 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
789 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
790 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
791 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
792 theMess = tr( "IMPORTED_MESH" );
801 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
802 if ( aGeomEntry.isEmpty() )
804 theMess = tr( myIsMesh ?
805 "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
806 "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
810 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
811 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
818 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
819 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
821 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
826 if ( !myIsMesh ) // i.e sub-mesh creation,
828 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
829 if ( aMeshEntry == "" )
831 theMess = tr( "MESH_IS_NOT_DEFINED" );
834 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
835 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
837 theMess = tr( "MESH_IS_NULL" );
840 if ( !isSubshapeOk() )
842 theMess = tr( "INVALID_SUBSHAPE" );
851 //================================================================================
853 * \brief check compatibility of the algorithm and another algorithm or hypothesis
854 * \param theAlgoData - algorithm data
855 * \param theHypData - hypothesis data
856 * \param theHypType - hypothesis type
857 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
858 * \retval bool - check result
860 //================================================================================
861 static bool isCompatible(const HypothesisData* theAlgoData,
862 const HypothesisData* theHypData,
863 const int theHypType)
868 if ( theHypType == SMESHGUI_MeshOp::Algo )
869 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
872 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
875 //================================================================================
877 * \brief check compatibility of the geometry
878 * \param theAlgoData - to select hypos able to be used by this algo
879 * \param theCurrentGeomToSelect - the current name of the selected geometry
880 * \param theGeomVar - currently selected geometry
881 * \retval bool - check result
883 //================================================================================
884 bool SMESHGUI_MeshOp::isCompatibleToGeometry(HypothesisData* theAlgoData,
885 QString theCurrentGeomToSelect,
886 GEOM::GEOM_Object_var theGeomVar)
888 if ( theGeomVar->_is_nil() )
891 bool isApplicable = false;
892 if ( theCurrentGeomToSelect == myLastGeomToSelect && !theCurrentGeomToSelect.isEmpty() ) {
893 THypLabelIsAppMap::const_iterator iter = myHypMapIsApplicable.find( theAlgoData->Label );
894 if ( iter != myHypMapIsApplicable.end() && iter.key() == theAlgoData->Label ) {
895 isApplicable = iter.value();
899 bool toCheckIsApplicableToAll = !myIsMesh;
900 if ( toCheckIsApplicableToAll )
901 toCheckIsApplicableToAll = ( theGeomVar->GetType() == GEOM_GROUP );
902 isApplicable = SMESH::IsApplicable( theAlgoData->TypeName, theGeomVar, toCheckIsApplicableToAll );
903 myHypMapIsApplicable.insert( theAlgoData->Label, isApplicable );
907 //================================================================================
909 * \brief check compatibility of the mesh type
910 * \param theAlgoData - to select hypos able to be used by this algo
911 * \param theMeshType - type of mesh for filtering algorithms
912 * \retval bool - check result
914 //================================================================================
915 bool SMESHGUI_MeshOp::isCompatibleToMeshType(HypothesisData* theAlgoData,
918 bool isAvailableAlgo = ( theAlgoData->OutputTypes.count() == 0 );
919 QStringList::const_iterator inElemType = theAlgoData->OutputTypes.begin();
920 for ( ; inElemType != theAlgoData->OutputTypes.end(); inElemType++ ) {
921 if ( *inElemType == theMeshType ) {
922 isAvailableAlgo = true;
926 return isAvailableAlgo;
929 //================================================================================
931 * \brief Gets available hypotheses or algorithms
932 * \param theDim - specifies dimension of returned hypotheses/algorifms
933 * \param theHypType - specifies whether algorims or hypotheses or additional ones
934 * are retrieved (possible values are in HypType enumeration)
935 * \param theHyps - Output list of hypotheses' names
936 * \param thePrevAlgoData - to select hypos able to be used by previously algo (optional)
937 * \param theNextAlgoData - to select hypos able to be used by next algo (optional)
938 * \param theMeshType - type of mesh for filtering algorithms (optional)
940 * Gets available hypotheses or algorithm in accordance with input parameters
942 //================================================================================
943 void SMESHGUI_MeshOp::availableHyps( const int theDim,
944 const int theHypType,
945 QStringList& theHyps,
946 THypDataList& theDataList,
947 HypothesisData* thePrevAlgoData,
948 HypothesisData* theNextAlgoData,
949 const QString& theMeshType)
953 bool isAlgo = ( theHypType == Algo );
954 bool isAux = ( theHypType >= AddHyp );
955 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
957 GEOM::GEOM_Object_var aGeomVar;
958 QString aCurrentGeomToSelect;
959 if ( !theMeshType.isEmpty() ) {
960 aCurrentGeomToSelect = myDlg->selectedObject( myToCreate ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Obj );
961 if ( _PTR(SObject) so = studyDS()->FindObjectID( aCurrentGeomToSelect.toLatin1().data() )) {
962 aGeomVar = SMESH::GetGeom( so );
964 if ( aCurrentGeomToSelect != myLastGeomToSelect )
965 myHypMapIsApplicable.clear();
968 std::multimap< double, HypothesisData* > sortedHyps;
969 QStringList::const_iterator anIter;
970 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
972 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
973 if ( ( isCompatible ( thePrevAlgoData, aData, theHypType ) &&
974 isCompatible ( theNextAlgoData, aData, theHypType ) ) ||
975 ( theMeshType == "ANY" && aData->InputTypes.isEmpty()))
977 if ( ( !theMeshType.isEmpty() ) &&
978 ( theDim >= SMESH::DIM_2D ) &&
979 ( ( theMeshType != "ANY" && !isCompatibleToMeshType( aData, theMeshType )) ||
980 !isCompatibleToGeometry( aData, aCurrentGeomToSelect, aGeomVar )))
983 int groupID = aData->GroupID;
984 int priority = aData->Priority;
985 if ( groupID < 0 || groupID > 9 ) groupID = 9;
986 if ( priority < 0 || priority > 999 ) priority = 999;
988 sortedHyps.insert( std::make_pair( groupID + priority * 1e-3, aData ));
992 if ( !sortedHyps.empty() )
994 HypothesisData* aPrevGroup = SMESH::GetGroupTitle( sortedHyps.rbegin()->second, isAlgo );
995 std::multimap< double, HypothesisData* >::iterator key_hyp = sortedHyps.begin();
996 for ( ; key_hyp != sortedHyps.end(); ++key_hyp )
998 HypothesisData* aData = key_hyp->second;
999 HypothesisData* aGroup = SMESH::GetGroupTitle( aData, isAlgo );
1000 if ( aPrevGroup != aGroup )
1002 theDataList.append( aGroup );
1003 theHyps.append( aGroup->Label );
1004 aPrevGroup = aGroup;
1006 theDataList.append( aData );
1007 theHyps.append( aData->Label );
1011 if ( !theMeshType.isEmpty() && !aCurrentGeomToSelect.isEmpty() )
1012 myLastGeomToSelect = aCurrentGeomToSelect;
1015 //================================================================================
1017 * \brief Gets existing hypotheses or algorithms
1018 * \param theDim - specifies dimension of returned hypotheses/algorifms
1019 * \param theHypType - specifies whether algorims or hypotheses or additional ones
1020 * are retrieved (possible values are in HypType enumeration)
1021 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
1022 * \param theHyps - output list of names.
1023 * \param theHypVars - output list of variables.
1024 * \param theAlgoData - to select hypos able to be used by this algo (optional)
1026 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
1029 * WARNING: when using this method to get hyps existing in Mesh component,
1030 * call availableHyps() before in order to get only hyps of available types
1031 * that was filtered by availableHyps()
1033 //================================================================================
1034 void SMESHGUI_MeshOp::existingHyps( const int theDim,
1035 const int theHypType,
1036 _PTR(SObject) theFather,
1037 QStringList& theHyps,
1038 THypList& theHypList,
1039 HypothesisData* theAlgoData) const
1041 // Clear hypoheses list
1048 _PTR(SObject) aHypRoot;
1049 _PTR(GenericAttribute) anAttr;
1050 _PTR(AttributeName) aName;
1051 _PTR(AttributeIOR) anIOR;
1053 const bool isMesh = !_CAST( SComponent, theFather );
1056 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
1058 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
1060 const bool isAux = ( theHypType >= AddHyp );
1061 const bool allHyps = ( !isMesh && theHypType != Algo && theDim > -1);
1063 if ( theFather->FindSubObject( aPart, aHypRoot ) )
1065 _PTR(ChildIterator) anIter =
1066 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1067 for ( ; anIter->More(); anIter->Next() )
1069 _PTR(SObject) anObj = anIter->Value();
1070 if ( isMesh ) // i.e. mesh or submesh
1072 _PTR(SObject) aRefObj;
1073 if ( anObj->ReferencedObject( aRefObj ) )
1078 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1081 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1082 if ( !CORBA::is_nil( aVar ) )
1084 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
1085 if ( !aHypVar->_is_nil() )
1087 CORBA::String_var hypType = aHypVar->GetName();
1088 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
1089 if ( !aData) continue;
1090 if (( theDim == -1 || aData->Dim.contains( theDim ) ) &&
1091 ( isCompatible ( theAlgoData, aData, theHypType )) &&
1092 ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ) &&
1093 ( !allHyps || myAvailableHypData[theDim][theHypType].count(aData) ))
1095 std::string aHypName = aName->Value();
1096 theHyps.append( aHypName.c_str() );
1097 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
1106 //================================================================================
1108 * \brief If create or edit a submesh, return a hypothesis holding parameters used
1109 * to mesh a sub-shape
1110 * \param aHypType - The hypothesis type name
1111 * \param aServerLib - Server library name
1112 * \param hypData - The structure holding the hypothesis type etc.
1113 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
1115 //================================================================================
1116 SMESH::SMESH_Hypothesis_var
1117 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
1118 const QString& aServerLib ) const
1120 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
1121 return SMESH::SMESH_Hypothesis::_nil();
1123 const int nbColonsInMeshEntry = 3;
1124 bool isSubMesh = myToCreate ?
1126 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
1128 // get mesh and geom object
1129 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
1130 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
1135 anEntry = myDlg->selectedObject
1136 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
1137 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1139 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
1140 if ( myToCreate ) // mesh and geom may be selected
1142 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
1143 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1144 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1145 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1147 else // edition: sub-mesh may be selected
1149 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
1150 if ( !sm->_is_nil() ) {
1151 aMeshVar = sm->GetFather();
1152 aGeomVar = sm->GetSubShape();
1159 if ( !myToCreate ) // mesh to edit can be selected
1161 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1162 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1164 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1165 if ( !aMeshVar->_is_nil() )
1166 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1169 if ( aGeomVar->_is_nil() ) {
1170 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1171 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1173 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1178 SMESH::SMESH_Hypothesis_var hyp =
1179 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1180 aServerLib.toLatin1().data(),
1183 /*byMesh = */isSubMesh);
1184 if ( hyp->_is_nil() && isSubMesh )
1185 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1186 aServerLib.toLatin1().data(),
1189 /*byMesh = */false);
1193 //================================================================================
1195 * \brief initialize a hypothesis creator
1197 //================================================================================
1199 void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
1201 if ( !theCreator ) return;
1203 // Set shapes, of mesh and sub-mesh if any
1205 // get Entry of the Geom object
1206 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1207 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1208 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1210 if ( myToCreate && myIsMesh )
1211 aMeshEntry = aGeomEntry;
1213 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1214 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1215 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1216 aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
1219 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1220 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1222 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1223 if ( !aGeomVar->_is_nil() )
1225 aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1227 aMeshEntry = aGeomEntry;
1231 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1232 // take geometry from submesh being created
1233 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1235 // if current object is sub-mesh
1236 SMESH::SMESH_subMesh_var aSubMeshVar =
1237 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1238 if ( !aSubMeshVar->_is_nil() ) {
1239 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1240 if ( !aMeshVar->_is_nil() ) {
1241 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1242 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1243 if ( !aGeomVar->_is_nil() )
1244 aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
1250 theCreator->setShapeEntry( aGeomEntry );
1251 if ( aMeshEntry != "" )
1252 theCreator->setMainShapeEntry( aMeshEntry );
1254 theCreator->setNoGeomMesh( !myIsOnGeometry && myIsMesh && !myToCreate );
1257 //================================================================================
1259 * \Brief Returns tab dimension
1260 * \param tab - the tab in the dlg
1261 * \param dlg - my dialogue
1262 * \retval int - dimension
1264 //================================================================================
1265 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1268 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1269 if (tab == dlg->tab(i))
1274 //================================================================================
1276 * \brief Create hypothesis
1277 * \param theHypType - hypothesis category (main or additional)
1278 * \param theIndex - index of type of hypothesis to be cerated
1280 * Specifies dimension of hypothesis to be created (using sender() method),
1281 * specifies its type and calls method for hypothesis creation
1283 //================================================================================
1284 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1286 // Specifies dimension of hypothesis to be created
1287 int aDim = getTabDim( sender(), myDlg );
1291 // Specifies type of hypothesis to be created
1292 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1293 if (theIndex < 0 || theIndex >= dataList.count())
1295 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1297 // Create hypothesis
1298 createHypothesis(aDim, theHypType, aHypTypeName);
1303 QString GetUniqueName (const QStringList& theHypNames,
1304 const QString& theName,
1305 size_t theIteration = 1)
1307 QString aName = theName + "_" + QString::number( theIteration );
1308 if ( theHypNames.contains( aName ) )
1309 return GetUniqueName( theHypNames, theName, ++theIteration );
1314 //================================================================================
1316 * Create hypothesis and update dialog.
1317 * \param theDim - dimension of hypothesis to be created
1318 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1319 * \param theTypeName - specifies hypothesis to be created
1321 //================================================================================
1322 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1324 const QString& theTypeName)
1326 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1333 // get a unique hyp name
1334 QStringList aHypNames;
1335 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1336 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1337 const TType2HypList& aType2HypList = aDimIter.value();
1338 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1339 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1340 const THypList& aHypList = aTypeIter.value();
1341 THypList::const_iterator anIter = aHypList.begin();
1342 for ( ; anIter != aHypList.end(); anIter++) {
1343 const THypItem& aHypItem = *anIter;
1344 const QString& aHypName = aHypItem.second;
1345 aHypNames.append(aHypName);
1349 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1352 bool dialog = false;
1354 QString aClientLibName = aData->ClientLibName;
1355 if (aClientLibName == "") {
1356 // Call hypothesis creation server method (without GUI)
1357 SMESH::SMESH_Hypothesis_var aHyp =
1358 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1362 // Get hypotheses creator client (GUI)
1363 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1365 // Create hypothesis
1368 // Get parameters appropriate to initialize a new hypothesis
1369 SMESH::SMESH_Hypothesis_var initParamHyp =
1370 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1372 removeCustomFilters(); // Issue 0020170
1374 // set shapes, of mesh and sub-mesh if any
1375 initHypCreator( aCreator );
1377 myDlg->setEnabled( false );
1378 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1383 SMESH::SMESH_Hypothesis_var aHyp =
1384 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1393 //================================================================================
1395 * Necessary steps after hypothesis creation
1396 * \param result - creation result:
1399 * 2 = additional value meaning that slot is called not from dialog box
1401 //================================================================================
1402 void SMESHGUI_MeshOp::onHypoCreated( int result )
1406 int obj = myDlg->getActiveObject();
1407 onActivateObject( obj ); // Issue 0020170. Restore filters
1408 myDlg->setEnabled( true );
1411 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1413 int nbHyp = myExistingHyps[myDim][myType].count();
1414 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1415 QStringList aNewHyps;
1416 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1417 if (aNewHyps.count() > nbHyp)
1419 for (int i = nbHyp; i < aNewHyps.count(); i++)
1420 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1423 if( result!=2 && myHypoSet )
1427 //================================================================================
1429 * \brief Calls plugin methods for hypothesis editing
1430 * \param theHypType - specifies whether main hypothesis or additional one
1432 * \param theIndex - index of existing hypothesis
1434 * Calls plugin methods for hypothesis editing
1436 //================================================================================
1437 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1439 // Speicfies dimension of hypothesis to be created
1440 int aDim = getTabDim( sender(), myDlg );
1444 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1445 if ( theIndex < 0 || theIndex >= aList.count() )
1447 const THypItem& aHypItem = aList[ theIndex ];
1448 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1449 if ( aHyp->_is_nil() )
1452 SMESHGUI_GenericHypothesisCreator* aCreator =
1453 SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
1456 // set initial parameters
1457 SMESH::SMESH_Hypothesis_var initParamHyp =
1458 getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
1459 SMESH::toQStr( aHyp->GetLibName() ));
1460 aCreator->setInitParamsHypothesis( initParamHyp );
1462 // set shapes, of mesh and sub-mesh if any
1463 initHypCreator( aCreator );
1465 removeCustomFilters(); // Issue 0020170
1466 myDlg->setEnabled( false );
1468 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1472 //================================================================================
1474 * Necessary steps after hypothesis edition
1475 * \param result - creation result:
1479 //================================================================================
1480 void SMESHGUI_MeshOp::onHypoEdited( int result )
1482 int obj = myDlg->getActiveObject();
1483 onActivateObject( obj ); // Issue 0020170. Restore filters
1484 myDlg->setEnabled( true );
1487 //================================================================================
1489 * \brief access to hypothesis data
1490 * \param theDim - hyp dimension
1491 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1492 * \param theIndex - index in the list
1493 * \retval HypothesisData* - result data, may be 0
1495 //================================================================================
1496 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1497 const int theHypType,
1500 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1501 theHypType > -1 && theHypType < NbHypTypes &&
1502 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1503 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1507 //================================================================================
1509 * \brief Set available algos and hypos according to the selected algorithm
1510 * \param theIndex - algorithm index
1512 //================================================================================
1513 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1516 if ( myIgnoreAlgoSelection )
1519 int curDim = getTabDim( sender(), myDlg );
1520 int aDim = theDim < 0 ? curDim : theDim;
1524 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1526 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1527 HypothesisData* algoByDim[4];
1528 algoByDim[ aDim ] = algoData;
1530 QStringList anAvailable;
1532 // enable / disable tabs
1533 if ( myIsOnGeometry ) {
1534 for (int i = SMESH::DIM_3D; i >= SMESH::DIM_0D; i--) {
1536 if ( i > myMaxShapeDim ) myDlg->disableTab( i );
1537 else myDlg->enableTab( i );
1539 else if ( i == aDim ) {
1542 else {//( i < aDim )
1543 if ( algoData && algoData->InputTypes.isEmpty() ) {
1544 myDlg->disableTab( i );
1545 for ( int type = Algo, nbTypes = nbDlgHypTypes(i); type < nbTypes; type++ )
1546 setCurrentHyp(i, type, -1);
1549 myDlg->enableTab( i );
1556 HypothesisData* a3DAlgo = 0;
1557 // 2 loops: backward and forward from algo dimension
1558 for ( int forward = 0; forward <= 1; ++forward )
1560 int dim = algoDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1562 dim = algoDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1564 HypothesisData* prevAlgo = algoData;
1565 bool noCompatible = false;
1566 for ( ; dim * dir <= lastDim * dir; dim += dir)
1568 if ( !isAccessibleDim( dim ))
1570 if ( noCompatible ) { // the selected algo has no compatible ones
1571 anAvailable.clear();
1572 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1573 myAvailableHypData[dim][Algo].clear();
1574 algoByDim[ dim ] = 0;
1577 HypothesisData* nextAlgo = 0;
1578 if ( myMaxShapeDim == SMESH::DIM_3D && a3DAlgo && dim == SMESH::DIM_2D ) {
1581 // get currently selected algo
1582 int algoIndex = currentHyp( dim, Algo );
1583 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1585 QString anCompareType = currentMeshTypeName(myDlg->currentMeshType());
1586 QString anCurrentCompareType = "";
1587 if ( dim == SMESH::DIM_3D || anCompareType == "ANY" )
1588 anCurrentCompareType = anCompareType;
1589 else if ( dim == SMESH::DIM_2D ) {
1590 anCurrentCompareType = (anCompareType == "HEXA" || anCompareType == "QUAD") ? "QUAD" : "TRIA";
1594 // set new available algorithms
1595 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType);
1596 HypothesisData* soleCompatible = 0;
1597 if ( anAvailable.count() == 1 )
1598 soleCompatible = myAvailableHypData[dim][Algo][0];
1599 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1600 noCompatible = anAvailable.isEmpty();
1601 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1602 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim == curDim ) {
1603 // select the sole compatible algo
1606 setCurrentHyp( dim, Algo, algoIndex );
1608 // remember current algo
1609 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1613 if ( myMaxShapeDim == SMESH::DIM_3D && forward && algoDim == SMESH::DIM_1D )
1615 algoDim = SMESH::DIM_3D;
1620 } // loops backward and forward
1623 // set hypotheses corresponding to the found algorithms
1625 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1627 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1629 if ( !isAccessibleDim( dim ))
1632 // get indices of selected hyps
1633 const int nbTypes = nbDlgHypTypes(dim);
1634 std::vector<int> hypIndexByType( nbTypes, -1 );
1635 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1637 hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
1641 for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
1643 const int type = Min( dlgType, AddHyp );
1644 myAvailableHypData[ dim ][ type ].clear();
1645 QStringList anAvailable, anExisting;
1647 HypothesisData* curAlgo = algoByDim[ dim ];
1648 int hypIndex = hypIndexByType[ dlgType ];
1650 SMESH::SMESH_Hypothesis_var curHyp;
1651 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1652 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1654 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 QString curHypType = SMESH::toQStr( curHyp->GetName() );
1658 if ( !algoDeselectedByUser &&
1659 myObjHyps[ dim ][ type ].count() > 0 &&
1660 curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
1662 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1663 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1664 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1665 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1672 // get hyps compatible with curAlgo
1673 bool defaulHypAvlbl = false;
1676 // check if a selected hyp is compatible with the curAlgo
1677 if ( !curHyp->_is_nil() ) {
1678 HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
1679 if ( !isCompatible( curAlgo, hypData, type ))
1680 curHyp = SMESH::SMESH_Hypothesis::_nil();
1682 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1683 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1684 defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1686 // set list of hypotheses
1687 if ( dlgType <= AddHyp )
1689 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1690 myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1692 // set current existing hypothesis
1693 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1694 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1697 if ( !isSubmesh && myToCreate && hypIndex < 0 && anExisting.count() == 1 && dim == curDim )
1699 // none is yet selected => select the sole existing if it is not optional
1700 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1701 bool isOptional = true;
1702 if ( algoByDim[ dim ] &&
1703 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1707 setCurrentHyp( dim, dlgType, hypIndex );
1712 //================================================================================
1714 * \brief Creates and selects hypothesis of hypotheses set
1715 * \param theSetName - The name of hypotheses set
1717 //================================================================================
1718 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1720 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1725 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1726 setCurrentHyp(dim, Algo, -1);
1727 setCurrentHyp(dim, AddHyp, -1);
1728 setCurrentHyp(dim, MainHyp, -1);
1731 myHypoSet->init(true); //algorithms
1733 myHypoSet->init(false); //hypotheses
1738 //================================================================================
1740 * \brief One step of hypothesis/algorithm list creation
1742 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1744 //================================================================================
1745 void SMESHGUI_MeshOp::processSet()
1748 if( !myHypoSet->more() )
1751 bool isAlgo = myHypoSet->isAlgo();
1752 QString aHypoTypeName = myHypoSet->current();
1753 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1760 int aDim = aHypData->Dim[0];
1761 // create or/and set
1764 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1767 QStringList anAvailable;
1768 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1769 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1770 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1772 setCurrentHyp( aDim, Algo, index );
1773 onAlgoSelected( index, aDim );
1778 bool mainHyp = true;
1779 QStringList anAvailable;
1780 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1781 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1782 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1786 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1789 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1795 //================================================================================
1797 * \brief Creates mesh
1798 * \param theMess - Output parameter intended for returning error message
1799 * \param theEntryList - List of entries of published objects
1800 * \retval bool - TRUE if mesh is created, FALSE otherwise
1804 //================================================================================
1805 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1810 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1811 if ( aList.isEmpty() )
1813 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1814 if ( aSMESHGen->_is_nil() )
1817 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1818 if ( aMeshVar->_is_nil() )
1821 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1823 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1824 theEntryList.append( aMeshSO->GetID().c_str() );
1829 if ( aList.count() > 1 )
1831 namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1832 int i = namePrefix.length() - 1;
1833 while ( i > 0 && namePrefix[i].isDigit() )
1835 if ( i < namePrefix.length() - 1 )
1836 namePrefix.chop( namePrefix.length() - 1 - i );
1840 QStringList::Iterator it = aList.begin();
1841 for ( int i = 0; it!=aList.end(); it++, ++i )
1843 QString aGeomEntry = *it;
1844 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1845 GEOM::GEOM_Object_var aGeomVar =
1846 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1848 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1849 if ( aSMESHGen->_is_nil() )
1852 SUIT_OverrideCursor aWaitCursor;
1855 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1856 if ( aMeshVar->_is_nil() )
1858 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1860 theEntryList.append( aMeshSO->GetID().c_str() );
1861 if ( i > 0 ) setDefaultName( namePrefix );
1862 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1865 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1867 if ( !isAccessibleDim( aDim )) continue;
1869 // assign hypotheses
1870 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
1872 const int aHypIndex = currentHyp( aDim, dlgType );
1873 const int aHypType = Min( dlgType, AddHyp );
1874 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1876 SMESH::SMESH_Hypothesis_var aHypVar =
1877 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1878 if ( !aHypVar->_is_nil() )
1879 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1882 // find or create algorithm
1883 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1884 if ( !anAlgoVar->_is_nil() )
1885 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1891 //================================================================================
1893 * \brief Creates sub-mesh
1894 * \param theMess - Output parameter intended for returning error message
1895 * \param theEntryList - List of entries of published objects
1896 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1900 //================================================================================
1901 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1905 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1906 if ( aSMESHGen->_is_nil() )
1910 SMESH::SMESH_Mesh_var aMeshVar =
1911 SMESH::EntryToInterface<SMESH::SMESH_Mesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ));
1912 if ( aMeshVar->_is_nil() && myIsInvalidSubMesh )
1914 SMESH::SMESH_subMesh_var aSMVar =
1915 SMESH::EntryToInterface<SMESH::SMESH_subMesh>( myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ));
1916 if ( !aSMVar->_is_nil() )
1917 aMeshVar = aSMVar->GetMesh();
1919 if (aMeshVar->_is_nil())
1922 // GEOM shape of the main mesh
1923 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1925 // Name for the new sub-mesh
1926 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1929 GEOM::GEOM_Object_var aGeomVar;
1931 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1932 if (aGEOMs.count() == 1)
1934 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1935 QString aGeomEntry = aGEOMs.first();
1936 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1937 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1939 else if (aGEOMs.count() > 1)
1941 // create a GEOM group
1942 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1943 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1944 if (!geomGen->_is_nil() && aStudy) {
1945 GEOM::GEOM_IGroupOperations_wrap op =
1946 geomGen->GetIGroupOperations(aStudy->StudyId());
1947 if (!op->_is_nil()) {
1948 // check and add all selected GEOM objects: they must be
1949 // a sub-shapes of the main GEOM and must be of one type
1951 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1952 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1953 aSeq->length(aGEOMs.count());
1954 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1955 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1956 QString aSubGeomEntry = (*aSubShapesIter);
1957 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1958 GEOM::GEOM_Object_var aSubGeomVar =
1959 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1960 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1962 aGroupType = aSubShapeType;
1964 if (aSubShapeType != aGroupType)
1965 aGroupType = TopAbs_SHAPE;
1967 aSeq[iSubSh] = aSubGeomVar;
1970 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1971 op->UnionList(aGroupVar, aSeq);
1975 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1977 // publish the GEOM group in study
1978 QString aNewGeomGroupName ("Auto_group_for_");
1979 aNewGeomGroupName += aName;
1980 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1981 SALOMEDS::SObject_wrap aNewGroupSO =
1982 geomGen->AddInStudy( aStudyVar, aGeomVar,
1983 aNewGeomGroupName.toLatin1().data(), mainGeom);
1990 if (aGeomVar->_is_nil())
1993 SUIT_OverrideCursor aWaitCursor;
1995 QString aNameOrID = aName;
1996 if ( myIsInvalidSubMesh )
1997 // pass a sub-mesh entry to mesh->GetSubMesh() to replace the invalid sub-mesh
1998 // by a valid one in an existing SO
1999 aNameOrID = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
2002 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aNameOrID.toLatin1().data() );
2003 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
2005 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
2006 theEntryList.append( aSubMeshSO->GetID().c_str() );
2009 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
2011 if ( !isAccessibleDim( aDim )) continue;
2013 // find or create algorithm
2014 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
2015 if ( !anAlgoVar->_is_nil() )
2016 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2017 // assign hypotheses
2018 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(aDim); dlgType++ )
2020 const int aHypIndex = currentHyp( aDim, dlgType );
2021 const int aHypType = Min( dlgType, AddHyp );
2022 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
2024 SMESH::SMESH_Hypothesis_var aHypVar =
2025 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
2026 if ( !aHypVar->_is_nil() )
2027 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
2032 // deselect geometry: next submesh should be created on other sub-shape
2033 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
2034 selectObject( _PTR(SObject)() );
2037 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
2042 //================================================================================
2044 * \brief Gets current hypothesis or algorithms
2045 * \param theDim - dimension of hypothesis or algorithm
2046 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2047 * \retval int - current hypothesis or algorithms
2049 * Gets current hypothesis or algorithms
2051 //================================================================================
2052 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
2054 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
2057 //================================================================================
2059 * \brief Checks if a hypothesis is selected
2061 //================================================================================
2063 bool SMESHGUI_MeshOp::isSelectedHyp( int theDim, int theHypType, int theIndex) const
2068 if ( theHypType < AddHyp ) // only one hyp can be selected
2069 return currentHyp( theDim, theHypType ) == theIndex;
2071 for ( int dlgHypType = AddHyp; dlgHypType < nbDlgHypTypes( theDim ); ++dlgHypType )
2072 if ( currentHyp( theDim, dlgHypType ) == theIndex )
2078 //================================================================================
2080 * \brief Returns nb of HypType's taking into account possible several
2081 * selected additional hypotheses which are coded as additional HypType's.
2083 //================================================================================
2085 int SMESHGUI_MeshOp::nbDlgHypTypes( const int dim ) const
2087 return NbHypTypes + myDlg->tab( dim )->nbAddHypTypes();
2090 //================================================================================
2092 * \brief Returns true if hypotheses of given dim can be assigned
2093 * \param theDim - hypotheses dimension
2094 * \retval bool - result
2096 //================================================================================
2097 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
2099 return myDlg->isTabEnabled( theDim );
2102 //================================================================================
2104 * \brief Sets current hypothesis or algorithms
2105 * \param theDim - dimension of hypothesis or algorithm
2106 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
2107 * \param theIndex - Index of hypothesis
2108 * \param updateHypsOnAlgoDeselection - to clear and disable hyps if algo deselected
2110 * Gets current hypothesis or algorithms
2112 //================================================================================
2113 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
2114 const int theHypType,
2116 const bool updateHypsOnAlgoDeselection)
2118 myIgnoreAlgoSelection = true;
2119 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
2120 myIgnoreAlgoSelection = false;
2122 if ( updateHypsOnAlgoDeselection && theHypType == Algo && theIndex < 0 )
2124 const QStringList noHyps;
2125 myDlg->tab( theDim )->setAvailableHyps( MainHyp, noHyps );
2126 myDlg->tab( theDim )->setExistingHyps ( MainHyp, noHyps );
2127 myDlg->tab( theDim )->setAvailableHyps( AddHyp, noHyps );
2128 myDlg->tab( theDim )->setExistingHyps ( AddHyp, noHyps );
2132 //================================================================================
2134 * \brief Generates default and sets mesh/submesh name
2136 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
2138 //================================================================================
2139 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
2143 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2146 QString aPrefix = thePrefix;
2147 if ( aPrefix.isEmpty() )
2148 aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
2150 _PTR(SObject) anObj;
2153 aResName = aPrefix + QString::number( i++ );
2154 anObj = aStudy->FindObject( aResName.toLatin1().data() );
2158 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
2159 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
2160 aControl->setText( aResName );
2163 //================================================================================
2165 * \brief Gets algorithm or creates it if necessary
2166 * \param theDim - specifies dimension of returned hypotheses/algorifms
2167 * \retval SMESH::SMESH_Hypothesis_var - algorithm
2169 * Gets algorithm or creates it if necessary
2171 //================================================================================
2172 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
2174 SMESH::SMESH_Hypothesis_var anAlgoVar;
2176 // get type of the selected algo
2177 int aHypIndex = currentHyp( theDim, Algo );
2178 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
2179 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
2181 QString aHypName = dataList[ aHypIndex ]->TypeName;
2183 // get existing algorithms
2184 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
2186 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
2188 // look for an existing algo of such a type
2189 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
2190 THypList::iterator anIter = aHypVarList.begin();
2191 for ( ; anIter != aHypVarList.end(); anIter++)
2193 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2194 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2196 anAlgoVar = aHypVar;
2201 if (anAlgoVar->_is_nil())
2203 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2206 QString aClientLibName = aHypData->ClientLibName;
2207 if ( aClientLibName.isEmpty() )
2209 // Call hypothesis creation server method (without GUI)
2210 SMESH::SMESH_Hypothesis_var aHyp =
2211 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2216 // Get hypotheses creator client (GUI)
2217 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2221 aCreator->create( true, aHypName, myDlg, 0, QString::null );
2223 SMESH::SMESH_Hypothesis_var aHyp =
2224 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
2229 QStringList tmpList;
2230 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2231 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2234 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2235 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2237 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2238 if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
2240 anAlgoVar = aHypVar;
2246 return anAlgoVar._retn();
2249 //================================================================================
2251 * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2253 * Called when mesh is edited only.
2255 //================================================================================
2256 void SMESHGUI_MeshOp::readMesh()
2258 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2259 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2263 if (myIsOnGeometry) {
2264 // Get name of mesh if current object is sub-mesh
2265 SMESH::SMESH_subMesh_var aSubMeshVar =
2266 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2267 if ( !aSubMeshVar->_is_nil() )
2269 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
2270 if ( !aMeshVar->_is_nil() )
2272 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2273 QString aMeshName = name( aMeshSO );
2274 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2276 myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2279 if ( !myIsInvalidSubMesh )
2281 // Get name of geometry object
2282 CORBA::String_var name = SMESH::GetGeomName( pObj );
2284 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2288 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2289 QStringList anExisting;
2290 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2291 bool algoFound = false;
2292 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2295 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2296 // find algo index among available ones
2298 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2300 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2301 HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( aVar->GetName() ));
2302 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2303 // if ( aHypIndex < 0 && algoData ) {
2304 // // assigned algo is incompatible with other algorithms
2305 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2306 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2308 algoFound = ( aHypIndex > -1 );
2310 setCurrentHyp( dim, Algo, aHypIndex );
2311 // set existing and available hypothesis according to the selected algo
2312 if ( aHypIndex > -1 || !algoFound )
2313 onAlgoSelected( aHypIndex, dim );
2317 bool hypWithoutAlgo = false;
2318 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2320 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2323 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2324 if ( myObjHyps[ dim ][ hypType ].count() == 0 ) {
2325 setCurrentHyp( dim, hypType, -1 );
2327 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2329 // find index of required hypothesis among existing ones for this dimension and type
2330 int aHypIndex = find( myObjHyps[ dim ][ hypType ][ i ].first,
2331 myExistingHyps[ dim ][ hypType ] );
2332 if ( aHypIndex < 0 ) {
2333 // assigned hypothesis is incompatible with the algorithm
2334 if ( currentHyp( dim, Algo ) < 0 )
2335 { // none algo selected; it is edition for sure, of submesh maybe
2336 hypWithoutAlgo = true;
2337 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ][ i ] );
2338 anExisting.push_back( myObjHyps[ dim ][ hypType ][ i ].second );
2339 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2340 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2343 setCurrentHyp( dim, hypType + i, aHypIndex );
2345 if ( hypType == MainHyp ) break; // only one main hyp allowed
2349 // make available other hyps of same type as one without algo
2350 if ( hypWithoutAlgo )
2351 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2354 //================================================================================
2356 * \brief Gets name of object
2357 * \param theSO - SObject
2358 * \retval QString - name of object
2360 * Gets name of object
2362 //================================================================================
2363 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2368 _PTR(GenericAttribute) anAttr;
2369 _PTR(AttributeName) aNameAttr;
2370 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2373 aResName = aNameAttr->Value().c_str();
2379 //================================================================================
2381 * \brief Finds hypothesis in input list
2382 * \param theHyp - hypothesis to be found
2383 * \param theHypList - input list of hypotheses
2384 * \retval int - index of hypothesis or -1 if it is not found
2386 * Finds position of hypothesis in input list
2388 //================================================================================
2389 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2390 const THypList& theHypList ) const
2393 if ( !theHyp->_is_nil() )
2396 THypList::const_iterator anIter = theHypList.begin();
2397 for ( ; anIter != theHypList.end(); ++ anIter)
2399 if ( theHyp->_is_equivalent( (*anIter).first ) )
2410 //================================================================================
2412 * \brief Edits mesh or sub-mesh
2413 * \param theMess - Output parameter intended for returning error message
2414 * \retval bool - TRUE if mesh is edited successfully, FALSE otherwise
2416 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2418 //================================================================================
2419 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2423 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2424 if ( aSMESHGen->_is_nil() )
2427 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2428 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2432 SUIT_OverrideCursor aWaitCursor;
2435 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2436 SMESH::SetName( pObj, aName );
2437 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_2D;
2439 // First, remove old algos in order to avoid messages on algorithm hiding
2440 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2442 if ( /*isAccessibleDim( dim ) &&*/ myObjHyps[ dim ][ Algo ].count() > 0 )
2444 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2445 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2446 if ( anAlgoVar->_is_nil() || // no new algo selected or
2447 SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
2449 // remove old algorithm
2450 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2451 myObjHyps[ dim ][ Algo ].clear();
2456 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2457 CORBA::Object_var anObject = aSObject->GetObject();
2458 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2459 SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2460 bool isMesh = !aMeshVar->_is_nil();
2461 if ( !isMesh && !aSubMeshVar->_is_nil() )
2462 aMeshVar = aSubMeshVar->GetFather();
2464 // Assign new algorithms and hypotheses
2465 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2467 //if ( !isAccessibleDim( dim )) continue;
2469 // find or create algorithm
2470 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2472 // assign new algorithm
2473 if ( !anAlgoVar->_is_nil() && // some algo selected and
2474 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2477 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2478 else if ( !aSubMeshVar->_is_nil() )
2479 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2481 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2484 // remove deselected hypotheses
2485 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2487 for ( int i = 0, nb = myObjHyps[ dim ][ hypType ].count(); i < nb; ++i )
2489 SMESH::SMESH_Hypothesis_var hyp = myObjHyps[ dim ][ hypType ][ i ].first;
2490 int hypIndex = this->find( hyp, myExistingHyps[ dim ][ hypType ]);
2491 if ( !isSelectedHyp( dim, hypType, hypIndex ) && !hyp->_is_nil() )
2493 SMESH::RemoveHypothesisOrAlgorithmOnMesh( pObj, hyp );
2497 // assign newly selected hypotheses
2498 for ( int dlgType = MainHyp; dlgType < nbDlgHypTypes(dim); dlgType++ )
2500 const int curIndex = currentHyp( dim, dlgType );
2501 const int hypType = Min( dlgType, AddHyp );
2502 if ( curIndex >= 0 && curIndex < myExistingHyps[ dim ][ hypType ].count() )
2504 SMESH::SMESH_Hypothesis_var hyp = myExistingHyps[ dim ][ hypType ][ curIndex ].first;
2506 bool isAssigned = ( this->find( hyp, myObjHyps[ dim ][ hypType ]) >= 0 );
2510 SMESH::AddHypothesisOnMesh (aMeshVar, hyp );
2511 else if ( !aSubMeshVar->_is_nil() )
2512 SMESH::AddHypothesisOnSubMesh ( aSubMeshVar, hyp );
2515 // reread all hypotheses of mesh
2516 QStringList anExisting;
2517 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2521 myHasConcurrentSubBefore =
2522 checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2527 //================================================================================
2529 * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2530 * creation/edition and, if (askUser) , proposes the uses to set up a desired
2531 * order of sub-mesh computation.
2532 * Returns \c true if a sub-mesh concurrency detected.
2534 //================================================================================
2536 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr mesh,
2537 SMESH::SMESH_subMesh_ptr submesh,
2540 if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2543 bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2544 if ( isNewConcurrent && askUser )
2546 int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2547 tr("CONCURRENT_SUBMESH_APPEARS"),
2548 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2551 _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2552 LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2553 if ( meshSO && aSelectionMgr )
2555 myDlg->setEnabled( false ); // disactivate selection
2556 selectionMgr()->clearFilters();
2557 selectObject( meshSO );
2558 SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
2559 qApp->processEvents();
2561 myDlg->setEnabled( true );
2562 int obj = myDlg->getActiveObject();
2563 onActivateObject( obj ); // restore filter
2566 selectObject( SMESH::FindSObject( submesh ));
2573 return isNewConcurrent;
2576 //================================================================================
2578 * \brief Verifies whether given operator is valid for this one
2579 * \param theOtherOp - other operation
2580 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2582 * method redefined from base class verifies whether given operator is valid for
2583 * this one (i.e. can be started "above" this operator). In current implementation method
2584 * returns false if theOtherOp operation is not intended for deleting objects or mesh
2587 //================================================================================
2588 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2590 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2593 //================================================================================
2595 * \brief SLOT. Is called when the user selects a way of geometry selection
2596 * \param theByMesh - true if the user wants to find geometry by mesh element
2598 //================================================================================
2599 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2602 if ( !myShapeByMeshOp ) {
2603 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2604 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2605 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2606 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2607 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2609 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2610 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2611 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2612 SMESH::SMESH_Mesh_var aMeshVar =
2613 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2614 if ( !aMeshVar->_is_nil() ) {
2615 myDlg->hide(); // stop processing selection
2616 myShapeByMeshOp->setModule( getSMESHGUI() );
2617 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2618 myShapeByMeshOp->SetMesh( aMeshVar );
2619 myShapeByMeshOp->start();
2625 //================================================================================
2627 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2629 //================================================================================
2630 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2632 if ( myShapeByMeshOp == op ) {
2633 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2635 // Select a found geometry object
2636 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2637 if ( !aGeomVar->_is_nil() )
2639 QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
2640 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2641 selectObject( aGeomSO );
2648 //================================================================================
2650 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2652 //================================================================================
2653 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2655 if ( myShapeByMeshOp == op && myDlg ) {
2660 //================================================================================
2662 * \brief Selects a SObject
2663 * \param theSObj - the SObject to select
2665 //================================================================================
2666 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2668 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2669 SALOME_ListIO anIOList;
2671 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2672 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2673 anIOList.Append( anIO );
2675 sm->setSelectedObjects( anIOList, false );
2678 //================================================================================
2680 * \brief Create available list types of mesh
2681 * \param theTypeMesh - Output list of available types of mesh
2683 //================================================================================
2684 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2686 theTypeMesh.clear();
2687 theTypeMesh.append( tr( "MT_ANY" ) );
2688 if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2690 theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2691 theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2693 if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2695 theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2696 theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2700 //================================================================================
2702 * \brief Set available types of mesh
2703 * \param theTypeMesh - List of available types of mesh
2705 //================================================================================
2706 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2708 myDlg->setAvailableMeshType( theTypeMesh );
2711 //================================================================================
2713 * \brief SLOT. Is called when the user select type of mesh
2714 * \param theTabIndex - Index of current active tab
2715 * \param theIndex - Index of current type of mesh
2717 //================================================================================
2718 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex )
2720 setFilteredAlgoData( theTabIndex, theIndex);
2723 //================================================================================
2725 * \brief Set a filtered list of available algorithms by mesh type
2726 * \param theTabIndex - Index of current active tab
2727 * \param theIndex - Index of current type of mesh
2729 //================================================================================
2730 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex )
2732 QStringList anAvailableAlgs;
2733 QString anCompareType = currentMeshTypeName( theIndex );
2734 int anCurrentAvailableAlgo = -1;
2736 int aDim = SMESH::DIM_3D;
2737 if ( theIndex == MT_TRIANGULAR || theIndex == MT_QUADRILATERAL)
2738 aDim = SMESH::DIM_2D;
2739 if ( anCompareType == "ANY" )
2741 bool isReqDisBound = false;
2742 int aReqDim = SMESH::DIM_3D;
2743 for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2745 anCurrentAvailableAlgo = -1;
2746 isNone = currentHyp( dim, Algo ) < 0;
2747 //return current algo in current tab and set new algorithm list
2748 HypothesisData* algoCur = 0;
2749 if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2750 algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2752 HypothesisData* prevAlgo = 0;
2753 HypothesisData* nextAlgo = 0;
2754 if ( dim == SMESH::DIM_2D ) {
2755 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2756 if ( aDim == SMESH::DIM_3D )
2757 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2759 // retrieves a list of available algorithms from resources
2760 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCompareType);
2761 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoCur );
2762 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2763 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2764 if ( anCurrentAvailableAlgo > -1 )
2765 isReqDisBound = algoCur->InputTypes.isEmpty();
2766 if ( isReqDisBound ) {
2771 if ( !myIsOnGeometry )
2772 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2773 bool disable = myAvailableHypData[i][Algo].isEmpty();
2774 if ( disable ) myDlg->disableTab( i );
2775 else myDlg->enableTab( i );
2778 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2779 if ( i > myMaxShapeDim || ( isReqDisBound && i < aReqDim ) ) myDlg->disableTab( i );
2780 else myDlg->enableTab( i );
2782 myDlg->setCurrentTab( theTabIndex );
2786 HypothesisData* anCurrentAlgo = 0;
2787 bool isReqDisBound = true;
2788 QString anCurrentCompareType = anCompareType;
2789 isNone = currentHyp( aDim, Algo ) < 0;
2790 if ( !isNone && !myAvailableHypData[aDim][Algo].empty() )
2791 isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2792 for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2794 bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2795 anCurrentAvailableAlgo = -1;
2796 HypothesisData* prevAlgo = 0;
2797 HypothesisData* nextAlgo = 0;
2798 if ( dim == SMESH::DIM_2D ) {
2799 prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
2800 if ( aDim == SMESH::DIM_3D )
2801 nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
2803 // finding algorithm which is selected
2805 anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2807 // retrieves a list of available algorithms from resources
2808 availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType );
2809 // finding and adding algorithm depending on the type mesh
2810 anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( anCurrentAlgo );
2811 //set new algorithm list and select the current algorithm
2812 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2813 anCurrentCompareType = ( anCompareType == "HEXA" || anCompareType == "QUAD" ) ? "QUAD" : "TRIA";
2814 setCurrentHyp( dim, Algo, anCurrentAvailableAlgo, /*updateHyps=*/true );
2817 for ( int i = myMaxShapeDim; i >= SMESH::DIM_0D; i-- ) {
2818 bool isNoneAlg = currentHyp( i, Algo ) < 0;
2820 isReqDisBound = myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2822 isReqDisBound = true;
2823 if ( isReqDisBound && !isNoneAlg && i <= aDim) {
2824 for (int j = myMaxShapeDim; j >= SMESH::DIM_0D; j--) {
2825 if ( currentHyp( j, Algo ) < 0 ) {
2826 myDlg->disableTab( j );
2827 setCurrentHyp( j , Algo, -1, /*updateHyps=*/true );
2833 myDlg->enableTab( i );
2836 if ( aDim == SMESH::DIM_2D) {
2837 setCurrentHyp( SMESH::DIM_3D, Algo, -1, /*updateHyps=*/true );
2838 myDlg->disableTab( SMESH::DIM_3D );
2841 int currentTab = ( theTabIndex <= aDim ) ? theTabIndex : aDim;
2842 myDlg->setCurrentTab( currentTab );
2844 THypDataList anAvailableAlgsData;
2845 QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2846 QStringList aFilteredHypothesesSetsList;
2847 aFilteredHypothesesSetsList.clear();
2848 QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2849 for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName ) {
2850 HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2851 bool isAvailable = false;
2852 currentHypoSet->init( true );
2853 while ( currentHypoSet->next(), currentHypoSet->more() ) {
2854 isAvailable = false;
2855 if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() )) {
2856 for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++) {
2857 int anCurrentAvailableAlgo = myAvailableHypData[i][Algo].indexOf( algoDataIn );
2858 if ( anCurrentAvailableAlgo > -1 ) {
2868 aFilteredHypothesesSetsList.append( *inHypoSetName );
2870 myDlg->setHypoSets( aFilteredHypothesesSetsList );
2873 //================================================================================
2875 * \brief Get current name types of mesh
2876 * \param theIndex - current index types of mesh
2877 * \retval QString - result
2879 //================================================================================
2880 QString SMESHGUI_MeshOp::currentMeshTypeName( const int theIndex ) const
2882 QString aMeshType = "";
2883 switch ( theIndex ) {
2890 case MT_QUADRILATERAL:
2893 case MT_TETRAHEDRAL:
2894 aMeshType = "TETRA";