1 // Copyright (C) 2007-2008 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.
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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MeshOp.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshOp.h"
30 #include "SMESHGUI_MeshDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Hypotheses.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_NumberFilter.hxx>
40 // SALOME GEOM includes
41 #include <GEOM_SelectionFilter.h>
43 #include <GeometryGUI.h>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SALOME_InteractiveObject.hxx>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDS_SComponent.hxx>
57 #include <SALOMEDS_SObject.hxx>
60 #include <QStringList>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Shell.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <BRep_Tool.hxx>
71 #include <SALOMEconfig.h>
72 #include CORBA_CLIENT_HEADER(SMESH_Gen)
74 //================================================================================
77 * \param theToCreate - if this parameter is true then operation is used for creation,
78 * for editing otherwise
80 * Initialize operation
82 //================================================================================
83 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
84 : SMESHGUI_SelectionOp(),
85 myToCreate( theToCreate ),
86 myIsMesh( theIsMesh ),
91 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
92 GeometryGUI::InitGeomGen();
93 myIsOnGeometry = true;
96 //================================================================================
100 //================================================================================
101 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
107 //================================================================================
109 * \brief Gets dialog of this operation
110 * \retval LightApp_Dialog* - pointer to dialog of this operation
112 //================================================================================
113 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
118 //================================================================================
120 * \brief Creates or edits mesh
121 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
123 * Virtual slot redefined from the base class called when "Apply" button is clicked
124 * creates or edits mesh
126 //================================================================================
127 bool SMESHGUI_MeshOp::onApply()
133 if ( !isValid( aMess ) )
137 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
141 bool aResult = false;
145 if ( myToCreate && myIsMesh )
146 aResult = createMesh( aMess );
147 if ( myToCreate && !myIsMesh )
148 aResult = createSubMesh( aMess );
149 else if ( !myToCreate )
150 aResult = editMeshOrSubMesh( aMess );
152 update( UF_ObjBrowser | UF_Model );
154 catch ( const SALOME::SALOME_Exception& S_ex )
156 SalomeApp_Tools::QtCatchCorbaException( S_ex );
172 aMess = tr( "SMESH_OPERATION_FAILED" );
173 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
179 //================================================================================
181 * \brief Creates dialog if necessary and shows it
183 * Virtual method redefined from base class called when operation is started creates
184 * dialog if necessary and shows it, activates selection
186 //================================================================================
187 void SMESHGUI_MeshOp::startOperation()
191 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
192 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
194 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
195 this, SLOT( onCreateHyp( const int, const int ) ) );
196 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
197 this, SLOT( onEditHyp( const int, const int ) ) );
198 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
199 this, SLOT( onAlgoSelected( const int ) ) );
201 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
202 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
205 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
206 else myHelpFileName = "constructing_submeshes_page.html";
207 else myHelpFileName = "editing_meshes_page.html";
209 SMESHGUI_SelectionOp::startOperation();
211 // iterate through dimensions and get available algoritms, set them to the dialog
212 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
213 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
215 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
217 // clear available hypotheses
218 aTab->setAvailableHyps( MainHyp, hypList );
219 aTab->setAvailableHyps( AddHyp, hypList );
220 aTab->setExistingHyps( MainHyp, hypList );
221 aTab->setExistingHyps( AddHyp, hypList );
222 myExistingHyps[ i ][ MainHyp ].clear();
223 myExistingHyps[ i ][ AddHyp ].clear();
225 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
226 aTab->setAvailableHyps( Algo, hypList );
231 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
234 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
236 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
238 myDlg->setCurrentTab( SMESH::DIM_3D );
243 myIgnoreAlgoSelection = false;
246 //================================================================================
248 * \brief Creates selection filter
249 * \param theId - identifier of current selection widget
250 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
252 * Creates selection filter in accordance with identifier of current selection widget
254 //================================================================================
255 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
257 if ( theId == SMESHGUI_MeshDlg::Geom )
259 // TColStd_MapOfInteger allTypesMap;
260 // for ( int i = 0; i < 10; i++ )
261 // allTypesMap.Add( i );
262 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
263 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
265 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
266 return new SMESH_TypeFilter( MESHorSUBMESH );
267 else if ( theId == SMESHGUI_MeshDlg::Mesh )
268 return new SMESH_TypeFilter( MESH );
273 //================================================================================
275 * \brief check if selected shape is a subshape of the shape to mesh
276 * \retval bool - check result
278 //================================================================================
280 bool SMESHGUI_MeshOp::isSubshapeOk() const
282 if ( !myToCreate || myIsMesh ) // not submesh creation
286 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
287 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
288 if (!pMesh) return false;
290 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
291 if (mesh->_is_nil()) return false;
293 // main shape of the mesh
294 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
295 if (mainGeom->_is_nil()) return false;
299 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
301 if (aGEOMs.count() > 0) {
302 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
303 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
304 if (geomGen->_is_nil() || !aStudy) return false;
306 GEOM::GEOM_IGroupOperations_var op =
307 geomGen->GetIGroupOperations(aStudy->StudyId());
308 if (op->_is_nil()) return false;
310 // check all selected shapes
311 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
312 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
313 QString aSubGeomEntry = (*aSubShapesIter);
314 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
315 if (!pSubGeom) return false;
317 GEOM::GEOM_Object_var aSubGeomVar =
318 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
319 if (aSubGeomVar->_is_nil()) return false;
321 // skl for NPAL14695 - implementation of searching of mainObj
322 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
323 //if (mainObj->_is_nil() ||
324 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
326 if (mainObj->_is_nil())
328 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
330 mainObj = op->GetMainShape(mainObj);
339 //================================================================================
341 * \brief Return name of the algorithm that does not support submeshes and makes
342 * submesh creation useless
343 * \retval char* - string is to be deleted!!!
345 //================================================================================
347 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
349 if ( myToCreate && !myIsMesh ) {
351 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
352 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
353 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
356 QStringList algoNames;
358 existingHyps(3, Algo, pMesh, algoNames, algoList);
359 if (!algoList.empty()) {
360 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
362 algo->InputTypes.empty() && // builds all dimensions it-self
363 !algo->IsSupportSubmeshes )
364 return CORBA::string_dup( algoNames[0].toLatin1().data() );
367 // GEOM::GEOM_Object_var geom;
368 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
369 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
371 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
372 existingHyps(2, Algo, pMesh, algoNames, algoList);
373 if (!algoList.empty()) {
374 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
376 algo->InputTypes.empty() && // builds all dimensions it-self
377 !algo->IsSupportSubmeshes )
378 return CORBA::string_dup( algoNames[0].toLatin1().data() );
386 //================================================================================
388 * \brief find an existing submesh by the selected shape
389 * \retval _PTR(SObject) - the found submesh SObject
391 //================================================================================
393 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
395 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
396 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
397 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
398 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
399 if ( pMesh && pGeom ) {
400 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
401 if ( !geom->_is_nil() ) {
403 switch ( geom->GetShapeType() ) {
404 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
405 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
406 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
407 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
408 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
409 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
410 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
413 _PTR(GenericAttribute) anAttr;
414 _PTR(SObject) aSubmeshRoot;
415 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
416 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
418 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
419 for ( ; smIter->More(); smIter->Next() )
421 _PTR(SObject) aSmObj = smIter->Value();
422 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
424 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
425 for ( ; anIter1->More(); anIter1->Next()) {
426 _PTR(SObject) pGeom2 = anIter1->Value();
427 if ( pGeom2->ReferencedObject( pGeom2 ) &&
428 pGeom2->GetID() == pGeom->GetID() )
435 return _PTR(SObject)();
438 //================================================================================
440 * \brief Updates dialog's look and feel
442 * Virtual method redefined from the base class updates dialog's look and feel
444 //================================================================================
445 void SMESHGUI_MeshOp::selectionDone()
447 if (!dlg()->isVisible() || !myDlg->isEnabled())
450 SMESHGUI_SelectionOp::selectionDone();
454 myIsOnGeometry = true;
456 //Check geometry for mesh
457 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
458 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
461 SMESH::SMESH_Mesh_var aMeshVar =
462 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
463 if (!aMeshVar->_is_nil()) {
464 if (!myToCreate && !aMeshVar->HasShapeToMesh())
465 myIsOnGeometry = false;
471 // Enable tabs according to shape dimension
476 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
477 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
479 if (aGEOMs.count() > 0) {
480 // one or more GEOM shape selected
481 aSeq->length(aGEOMs.count());
482 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
484 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
485 QString aSubGeomEntry = (*aSubShapesIter);
486 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
487 GEOM::GEOM_Object_var aSubGeomVar =
488 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
489 aSeq[iSubSh] = aSubGeomVar;
492 // get geometry by selected sub-mesh
493 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
494 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
495 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
496 if (!aGeomVar->_is_nil()) {
502 if (aSeq->length() > 0) {
504 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
505 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
506 switch ( aGeomVar->GetShapeType() ) {
507 case GEOM::SOLID: shapeDim = 3; break;
510 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
511 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
513 if (GEOMBase::GetShape(aGeomVar, aShape)) {
514 if (/*aShape.Closed()*/BRep_Tool::IsClosed(aShape))
519 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
521 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
522 case GEOM::VERTEX: break;
526 if (GEOMBase::GetShape(aGeomVar, aShape)) {
527 TopExp_Explorer exp (aShape, TopAbs_SHELL);
529 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
530 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
531 for (; exp.More() && shapeDim == 2; exp.Next()) {
532 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
536 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
537 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
538 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
539 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
547 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
548 // reset algos before disabling tabs (0020138)
549 onAlgoSelected(-1, i);
551 myDlg->setMaxHypoDim( shapeDim );
554 if (!myToCreate) // edition: read hypotheses
558 SMESH::SMESH_subMesh_var aVar =
559 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
560 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
561 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
562 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
563 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
564 myDlg->updateGeometry();
571 else if ( !myIsMesh ) // submesh creation
573 // if a submesh on the selected shape already exist, pass to submesh edition mode
574 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
575 SMESH::SMESH_subMesh_var sm =
576 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
577 bool editSubmesh = ( !sm->_is_nil() &&
578 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
579 tr( "EDIT_SUBMESH_QUESTION"),
580 SUIT_MessageBox::Yes |
582 SUIT_MessageBox::No )
583 == SUIT_MessageBox::Yes );
586 selectionMgr()->clearFilters();
587 selectObject( pSubmesh );
588 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
593 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
594 selectObject( _PTR(SObject)() );
599 // discard selected mesh if submesh creation not allowed because of
600 // a global algorithm that does not support submeshes
601 if ( char* algoName = isSubmeshIgnored() ) {
602 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
603 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
604 CORBA::string_free( algoName );
605 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
606 selectObject( _PTR(SObject)() );
611 // enable/disable popup for choice of geom selection way
613 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
614 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
615 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
616 if ( !mesh->_is_nil() )
617 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
619 myDlg->setGeomPopupEnabled( enable );
623 myDlg->enableTab( SMESH::DIM_3D );
625 availableHyps( SMESH::DIM_3D, Algo, hypList,
626 myAvailableHypData[SMESH::DIM_3D][Algo]);
628 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
629 aTab->setAvailableHyps( Algo, hypList );
630 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
631 myDlg->disableTab(i);
633 //Hide labels and fields (Mesh ang Geometry)
634 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
635 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
640 catch ( const SALOME::SALOME_Exception& S_ex )
642 SalomeApp_Tools::QtCatchCorbaException( S_ex );
649 //================================================================================
651 * \brief Verifies validity of input data
652 * \param theMess - Output parameter intended for returning error message
653 * \retval bool - TRUE if input data is valid, false otherwise
655 * Verifies validity of input data. This method is called when "Apply" or "OK" button
656 * is pressed before mesh creation or editing.
658 //================================================================================
659 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
661 // Selected object to be edited
662 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
664 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
669 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
670 if ( aMeshName.isEmpty() )
672 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
676 /* // Imported mesh, if create sub-mesh or edit mesh
677 if ( !myToCreate || ( myToCreate && !myIsMesh ))
679 QString aMeshEntry = myDlg->selectedObject
680 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
681 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
682 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
683 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
684 theMess = tr( "IMPORTED_MESH" );
693 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
694 if ( aGeomEntry == "" )
696 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
699 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
700 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
702 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
707 if ( !myIsMesh ) // i.e sub-mesh creation,
709 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
710 if ( aMeshEntry == "" )
712 theMess = tr( "MESH_IS_NOT_DEFINED" );
715 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
716 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
718 theMess = tr( "MESH_IS_NULL" );
721 if ( !isSubshapeOk() )
723 theMess = tr( "INVALID_SUBSHAPE" );
732 //================================================================================
734 * \brief check compatibility of the algorithm and another algorithm or hypothesis
735 * \param theAlgoData - algorithm data
736 * \param theHypData - hypothesis data
737 * \param theHypType - hypothesis type
738 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
739 * \retval bool - check result
741 //================================================================================
743 static bool isCompatible(const HypothesisData* theAlgoData,
744 const HypothesisData* theHypData,
745 const int theHypType)
750 if ( theHypType == SMESHGUI_MeshOp::Algo )
751 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
754 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
757 //================================================================================
759 * \brief Gets available hypotheses or algorithms
760 * \param theDim - specifies dimension of returned hypotheses/algorifms
761 * \param theHypType - specifies whether algorims or hypotheses or additional ones
762 * are retrieved (possible values are in HypType enumeration)
763 * \param theHyps - Output list of hypotheses' names
764 * \param theAlgoData - to select hypos able to be used by this algo (optional)
766 * Gets available hypotheses or algorithm in accordance with input parameters
768 //================================================================================
769 void SMESHGUI_MeshOp::availableHyps( const int theDim,
770 const int theHypType,
771 QStringList& theHyps,
772 THypDataList& theDataList,
773 HypothesisData* theAlgoData ) const
777 bool isAlgo = ( theHypType == Algo );
778 bool isAux = ( theHypType == AddHyp );
779 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
781 QStringList::const_iterator anIter;
782 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
784 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
785 if ( isCompatible ( theAlgoData, aData, theHypType )) {
786 theDataList.append( aData );
787 theHyps.append( aData->Label );
792 //================================================================================
794 * \brief Gets existing hypotheses or algorithms
795 * \param theDim - specifies dimension of returned hypotheses/algorifms
796 * \param theHypType - specifies whether algorims or hypotheses or additional ones
797 * are retrieved (possible values are in HypType enumeration)
798 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
799 * \param theHyps - output list of names.
800 * \param theHypVars - output list of variables.
801 * \param theAlgoData - to select hypos able to be used by this algo (optional)
803 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
806 //================================================================================
807 void SMESHGUI_MeshOp::existingHyps( const int theDim,
808 const int theHypType,
809 _PTR(SObject) theFather,
810 QStringList& theHyps,
811 THypList& theHypList,
812 HypothesisData* theAlgoData)
814 // Clear hypoheses list
821 const bool isAux = ( theHypType == AddHyp );
823 _PTR(SObject) aHypRoot;
824 _PTR(GenericAttribute) anAttr;
825 _PTR(AttributeName) aName;
826 _PTR(AttributeIOR) anIOR;
828 bool isMesh = !_CAST( SComponent, theFather );
831 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
833 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
835 if ( theFather->FindSubObject( aPart, aHypRoot ) )
837 _PTR(ChildIterator) anIter =
838 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
839 for ( ; anIter->More(); anIter->Next() )
841 _PTR(SObject) anObj = anIter->Value();
842 if ( isMesh ) // i.e. mesh or submesh
844 _PTR(SObject) aRefObj;
845 if ( anObj->ReferencedObject( aRefObj ) )
850 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
853 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
854 if ( !CORBA::is_nil( aVar ) )
856 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
857 if ( !aHypVar->_is_nil() )
859 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
860 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
861 ( isCompatible ( theAlgoData, aData, theHypType )) &&
862 ( isAux == aData->IsAux ))
864 std::string aHypName = aName->Value();
865 theHyps.append( aHypName.c_str() );
866 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
875 //================================================================================
877 * \brief If create or edit a submesh, return a hypothesis holding parameters used
879 * \param aHypType - The hypothesis type name
880 * \param aServerLib - Server library name
881 * \param hypData - The structure holding the hypothesis type etc.
882 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
884 //================================================================================
886 SMESH::SMESH_Hypothesis_var
887 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
888 const QString& aServerLib ) const
890 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
891 return SMESH::SMESH_Hypothesis::_nil();
893 const int nbColonsInMeshEntry = 3;
894 bool isSubMesh = myToCreate ?
896 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
898 // get mesh and geom object
899 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
900 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
905 anEntry = myDlg->selectedObject
906 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
907 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
909 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
910 if ( myToCreate ) // mesh and geom may be selected
912 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
913 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
914 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
915 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
917 else // edition: sub-mesh may be selected
919 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
920 if ( !sm->_is_nil() ) {
921 aMeshVar = sm->GetFather();
922 aGeomVar = sm->GetSubShape();
929 if ( !myToCreate ) // mesh to edit can be selected
931 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
932 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
934 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
935 if ( !aMeshVar->_is_nil() )
936 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
939 if ( aGeomVar->_is_nil() ) {
940 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
941 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
943 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
948 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
949 aServerLib.toLatin1().data(),
952 /*byMesh = */isSubMesh);
956 //================================================================================
958 * \Brief Returns tab dimention
959 * \param tab - the tab in the dlg
960 * \param dlg - my dialogue
961 * \retval int - dimention
963 //================================================================================
965 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
968 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
969 if (tab == dlg->tab(i))
974 //================================================================================
976 * \brief Create hypothesis
977 * \param theHypType - hypothesis category (main or additional)
978 * \param theIndex - index of type of hypothesis to be cerated
980 * Specifies dimension of hypothesis to be created (using sender() method),
981 * specifies its type and calls method for hypothesis creation
983 //================================================================================
984 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
986 // Specifies dimension of hypothesis to be created
987 int aDim = getTabDim( sender(), myDlg );
991 // Specifies type of hypothesis to be created
992 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
993 if (theIndex < 0 || theIndex >= dataList.count())
995 QString aHypTypeName = dataList[ theIndex ]->TypeName;
998 createHypothesis(aDim, theHypType, aHypTypeName);
1003 QString GetUniqueName (const QStringList& theHypNames,
1004 const QString& theName,
1005 size_t theIteration = 1)
1007 QString aName = theName + "_" + QString::number( theIteration );
1008 if ( theHypNames.contains( aName ) )
1009 return GetUniqueName( theHypNames, theName, ++theIteration );
1014 //================================================================================
1016 * Create hypothesis and update dialog.
1017 * \param theDim - dimension of hypothesis to be created
1018 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1019 * \param theTypeName - specifies hypothesis to be created
1021 //================================================================================
1023 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1025 const QString& theTypeName)
1027 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1033 QStringList aHypNames;
1034 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1035 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1036 const TType2HypList& aType2HypList = aDimIter.value();
1037 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1038 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1039 const THypList& aHypList = aTypeIter.value();
1040 THypList::const_iterator anIter = aHypList.begin();
1041 for ( ; anIter != aHypList.end(); anIter++) {
1042 const THypItem& aHypItem = *anIter;
1043 const QString& aHypName = aHypItem.second;
1044 aHypNames.append(aHypName);
1048 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1051 bool dialog = false;
1053 QString aClientLibName = aData->ClientLibName;
1054 if (aClientLibName == "") {
1055 // Call hypothesis creation server method (without GUI)
1056 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1058 // Get hypotheses creator client (GUI)
1060 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1061 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1063 // Create hypothesis
1065 // Get parameters appropriate to initialize a new hypothesis
1066 SMESH::SMESH_Hypothesis_var initParamHyp =
1067 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1069 removeCustomFilters(); // Issue 0020170
1071 // Get Entry of the Geom object
1072 QString aGeomEntry = "";
1073 QString aMeshEntry = "";
1074 QString anObjEntry = "";
1075 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1076 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1077 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1079 if ( aMeshEntry != "" ) { // Get Geom object from Mesh
1080 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1081 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1082 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1085 if ( aMeshEntry == "" && aGeomEntry == "" ) {
1086 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1087 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1088 if ( !aGeomVar->_is_nil() )
1089 aGeomEntry = aGeomVar->GetStudyEntry();
1092 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
1093 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1095 // if current object is sub-mesh
1096 SMESH::SMESH_subMesh_var aSubMeshVar =
1097 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1098 if ( !aSubMeshVar->_is_nil() ) {
1099 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1100 if ( !aMeshVar->_is_nil() ) {
1101 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1102 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1103 if ( !aGeomVar->_is_nil() )
1104 aMeshEntry = aGeomVar->GetStudyEntry();
1110 aCreator->setShapeEntry( aGeomEntry );
1111 if ( aMeshEntry != "" )
1112 aCreator->setMainShapeEntry( aMeshEntry );
1113 myDlg->setEnabled( false );
1114 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1118 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1125 //================================================================================
1127 * Necessary steps after hypothesis creation
1128 * \param result - creation result:
1131 * 2 = additional value meaning that slot is called not from dialog box
1133 //================================================================================
1134 void SMESHGUI_MeshOp::onHypoCreated( int result )
1138 int obj = myDlg->getActiveObject();
1139 onActivateObject( obj ); // Issue 0020170. Restore filters
1140 myDlg->setEnabled( true );
1143 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1145 int nbHyp = myExistingHyps[myDim][myType].count();
1146 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1147 QStringList aNewHyps;
1148 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1149 if (aNewHyps.count() > nbHyp)
1151 for (int i = nbHyp; i < aNewHyps.count(); i++)
1152 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1155 if( result!=2 && myHypoSet )
1159 //================================================================================
1161 * \brief Calls plugin methods for hypothesis editing
1162 * \param theHypType - specifies whether main hypothesis or additional one
1164 * \param theIndex - index of existing hypothesis
1166 * Calls plugin methods for hypothesis editing
1168 //================================================================================
1169 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1171 // Speicfies dimension of hypothesis to be created
1172 int aDim = getTabDim( sender(), myDlg );
1176 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1177 if ( theIndex < 0 || theIndex >= aList.count() )
1179 const THypItem& aHypItem = aList[ theIndex ];
1180 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1181 if ( aHyp->_is_nil() )
1185 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1186 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1189 // Get initial parameters
1190 SMESH::SMESH_Hypothesis_var initParamHyp =
1191 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1192 aCreator->setInitParamsHypothesis( initParamHyp );
1194 // Get Entry of the Geom object
1195 QString aGeomEntry = "";
1196 QString aMeshEntry = "";
1197 QString anObjEntry = "";
1198 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1199 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1200 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1202 if ( aMeshEntry != "" ) { // Get Geom object from Mesh
1203 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1204 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1205 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1208 if ( aMeshEntry == "" && aGeomEntry == "" ) {
1209 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1210 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1211 if ( !aGeomVar->_is_nil() )
1212 aGeomEntry = aGeomVar->GetStudyEntry();
1215 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
1216 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1218 // if current object is sub-mesh
1219 SMESH::SMESH_subMesh_var aSubMeshVar =
1220 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1221 if ( !aSubMeshVar->_is_nil() ) {
1222 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1223 if ( !aMeshVar->_is_nil() ) {
1224 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1225 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1226 if ( !aGeomVar->_is_nil() )
1227 aMeshEntry = aGeomVar->GetStudyEntry();
1233 aCreator->setShapeEntry( aGeomEntry );
1234 if ( aMeshEntry != "" )
1235 aCreator->setMainShapeEntry( aMeshEntry );
1236 removeCustomFilters(); // Issue 0020170
1237 myDlg->setEnabled( false );
1238 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1242 //================================================================================
1244 * Necessary steps after hypothesis edition
1245 * \param result - creation result:
1249 //================================================================================
1250 void SMESHGUI_MeshOp::onHypoEdited( int result )
1252 int obj = myDlg->getActiveObject();
1253 onActivateObject( obj ); // Issue 0020170. Restore filters
1254 myDlg->setEnabled( true );
1257 //================================================================================
1259 * \brief access to hypothesis data
1260 * \param theDim - hyp dimension
1261 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1262 * \param theIndex - index in the list
1263 * \retval HypothesisData* - result data, may be 0
1265 //================================================================================
1267 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1268 const int theHypType,
1271 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1272 theHypType > -1 && theHypType < NbHypTypes &&
1273 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1274 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1278 //================================================================================
1280 * \brief Set available algos and hypos according to the selected algorithm
1281 * \param theIndex - algorithm index
1283 //================================================================================
1285 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1288 if ( myIgnoreAlgoSelection )
1291 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1295 // find highest available dimension, all algos of this dimension are available for choice
1297 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1298 if (isAccessibleDim( i ))
1303 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1305 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1306 HypothesisData* algoByDim[4];
1307 algoByDim[ aDim ] = algoData;
1309 QStringList anAvailable;
1310 if ( !algoData ) { // all algos becomes available
1311 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1312 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1315 // check that algorithms of other dimentions are compatible with
1318 // 2 loops: backward and forward from algo dimension
1319 for ( int forward = false; forward <= true; ++forward )
1321 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1323 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1325 HypothesisData* prevAlgo = algoData;
1326 bool noCompatible = false;
1327 for ( ; dim * dir <= lastDim * dir; dim += dir)
1329 if ( !isAccessibleDim( dim ))
1331 if ( noCompatible ) { // the selected algo has no compatible ones
1332 anAvailable.clear();
1333 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1334 myAvailableHypData[dim][Algo].clear();
1335 algoByDim[ dim ] = 0;
1338 // get currently selected algo
1339 int algoIndex = currentHyp( dim, Algo );
1340 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1341 if ( curAlgo ) { // some algo selected
1342 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1345 // set new available algoritms
1346 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1347 HypothesisData* soleCompatible = 0;
1348 if ( anAvailable.count() == 1 )
1349 soleCompatible = myAvailableHypData[dim][Algo][0];
1350 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1351 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1352 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1353 noCompatible = anAvailable.isEmpty();
1355 // restore previously selected algo
1356 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1357 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1358 // select the sole compatible algo
1359 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1360 setCurrentHyp( dim, Algo, algoIndex );
1362 // remember current algo
1363 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1367 // set hypotheses corresponding to the found algoritms
1369 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1371 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1373 if ( !isAccessibleDim( dim ))
1375 for ( int type = MainHyp; type < NbHypTypes; type++ )
1377 myAvailableHypData[ dim ][ type ].clear();
1378 QStringList anAvailable, anExisting;
1380 HypothesisData* curAlgo = algoByDim[ dim ];
1381 int hypIndex = currentHyp( dim, type );
1383 SMESH::SMESH_Hypothesis_var curHyp;
1384 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1385 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1387 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1388 // try to find algo by selected hypothesis in order to keep it selected
1389 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1390 CORBA::String_var curHypType = curHyp->GetName();
1391 if ( !algoDeselectedByUser &&
1392 myObjHyps[ dim ][ type ].count() > 0 &&
1393 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1395 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1396 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1397 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1398 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1405 // get hyps compatible with curAlgo
1408 // check if a selected hyp is compatible with the curAlgo
1409 if ( !curHyp->_is_nil() ) {
1410 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1411 if ( !isCompatible( curAlgo, hypData, type ))
1412 curHyp = SMESH::SMESH_Hypothesis::_nil();
1414 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1415 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1417 // set list of hypotheses
1418 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1419 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1421 // set current existing hypothesis
1422 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1423 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1426 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1427 // none is yet selected => select the sole existing if it is not optional
1428 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1429 bool isOptional = true;
1430 if ( algoByDim[ dim ] &&
1431 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1435 setCurrentHyp( dim, type, hypIndex );
1440 //================================================================================
1442 * \brief Creates and selects hypothesis of hypotheses set
1443 * \param theSetName - The name of hypotheses set
1445 //================================================================================
1446 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1448 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1453 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1454 setCurrentHyp(dim, Algo, -1);
1455 setCurrentHyp(dim, AddHyp, -1);
1456 setCurrentHyp(dim, MainHyp, -1);
1459 myHypoSet->init(true); //algorithms
1461 myHypoSet->init(false); //hypotheses
1466 //================================================================================
1468 * \brief One step of hypothesis/algorithm list creation
1470 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1472 //================================================================================
1473 void SMESHGUI_MeshOp::processSet()
1476 if( !myHypoSet->more() )
1479 bool isAlgo = myHypoSet->isAlgo();
1480 QString aHypoTypeName = myHypoSet->current();
1481 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1488 int aDim = aHypData->Dim[0];
1489 // create or/and set
1492 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1495 QStringList anAvailable;
1496 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1497 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1498 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1500 setCurrentHyp( aDim, Algo, index );
1501 onAlgoSelected( index, aDim );
1506 bool mainHyp = true;
1507 QStringList anAvailable;
1508 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1509 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1510 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1514 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1517 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1523 //================================================================================
1525 * \brief Creates mesh
1526 * \param theMess - Output parameter intended for returning error message
1527 * \retval bool - TRUE if mesh is created, FALSE otherwise
1531 //================================================================================
1532 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1536 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1537 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1540 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1541 QStringList::Iterator it = aList.begin();
1542 for ( ; it!=aList.end(); it++)
1544 QString aGeomEntry = *it;
1545 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1546 GEOM::GEOM_Object_var aGeomVar =
1547 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1549 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1550 if ( aSMESHGen->_is_nil() )
1553 SUIT_OverrideCursor aWaitCursor;
1556 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1557 if ( aMeshVar->_is_nil() )
1559 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1561 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1563 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1564 if ( !isAccessibleDim( aDim )) continue;
1566 // assign hypotheses
1567 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1568 int aHypIndex = currentHyp( aDim, aHypType );
1569 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1570 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1571 if ( !aHypVar->_is_nil() )
1572 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1575 // find or create algorithm
1576 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1577 if ( !anAlgoVar->_is_nil() )
1578 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1585 //================================================================================
1587 * \brief Creates sub-mesh
1588 * \param theMess - Output parameter intended for returning error message
1589 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1593 //================================================================================
1594 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1598 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1599 if ( aSMESHGen->_is_nil() )
1603 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1604 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1605 SMESH::SMESH_Mesh_var aMeshVar =
1606 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1607 if (aMeshVar->_is_nil())
1610 // GEOM shape of the main mesh
1611 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1613 // Name for the new sub-mesh
1614 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1617 GEOM::GEOM_Object_var aGeomVar;
1619 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1620 if (aGEOMs.count() == 1)
1622 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1623 QString aGeomEntry = aGEOMs.first();
1624 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1625 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1627 else if (aGEOMs.count() > 1)
1629 // create a GEOM group
1630 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1631 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1632 if (!geomGen->_is_nil() && aStudy) {
1633 GEOM::GEOM_IGroupOperations_var op =
1634 geomGen->GetIGroupOperations(aStudy->StudyId());
1635 if (!op->_is_nil()) {
1636 // check and add all selected GEOM objects: they must be
1637 // a sub-shapes of the main GEOM and must be of one type
1639 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1640 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1641 aSeq->length(aGEOMs.count());
1642 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1643 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1644 QString aSubGeomEntry = (*aSubShapesIter);
1645 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1646 GEOM::GEOM_Object_var aSubGeomVar =
1647 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1648 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1650 aGroupType = aSubShapeType;
1652 if (aSubShapeType != aGroupType)
1653 aGroupType = TopAbs_SHAPE;
1655 aSeq[iSubSh] = aSubGeomVar;
1658 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1659 op->UnionList(aGroupVar, aSeq);
1662 aGeomVar = aGroupVar;
1664 // publish the GEOM group in study
1665 QString aNewGeomGroupName ("Auto_group_for_");
1666 aNewGeomGroupName += aName;
1667 SALOMEDS::SObject_var aNewGroupSO =
1668 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1669 aNewGeomGroupName.toLatin1().data(), mainGeom);
1676 if (aGeomVar->_is_nil())
1679 SUIT_OverrideCursor aWaitCursor;
1682 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1683 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1685 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1687 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1689 if ( !isAccessibleDim( aDim )) continue;
1691 // find or create algorithm
1692 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1693 if ( !anAlgoVar->_is_nil() )
1694 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1695 // assign hypotheses
1696 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1698 int aHypIndex = currentHyp( aDim, aHypType );
1699 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1701 SMESH::SMESH_Hypothesis_var aHypVar =
1702 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1703 if ( !aHypVar->_is_nil() )
1704 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1709 // deselect geometry: next submesh should be created on other subshape
1710 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1711 selectObject( _PTR(SObject)() );
1717 //================================================================================
1719 * \brief Gets current hypothesis or algorithms
1720 * \param theDim - dimension of hypothesis or algorithm
1721 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1722 * \retval int - current hypothesis or algorithms
1724 * Gets current hypothesis or algorithms
1726 //================================================================================
1727 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1729 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1732 //================================================================================
1734 * \brief Returns true if hypotheses of given dim can be assigned
1735 * \param theDim - hypotheses dimension
1736 * \retval bool - result
1738 //================================================================================
1739 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1741 return myDlg->isTabEnabled( theDim );
1744 //================================================================================
1746 * \brief Sets current hypothesis or algorithms
1747 * \param theDim - dimension of hypothesis or algorithm
1748 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1749 * \param theIndex - Index of hypothesis
1751 * Gets current hypothesis or algorithms
1753 //================================================================================
1754 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1755 const int theHypType,
1756 const int theIndex )
1758 myIgnoreAlgoSelection = true;
1759 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1760 myIgnoreAlgoSelection = false;
1763 //================================================================================
1765 * \brief Generates default and sets mesh/submesh name
1767 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1769 //================================================================================
1770 void SMESHGUI_MeshOp::setDefaultName() const
1774 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1776 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1777 _PTR(SObject) anObj;
1780 aResName = aPrefix + QString::number( i++ );
1781 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1785 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1786 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1787 aControl->setText( aResName );
1790 //================================================================================
1792 * \brief Gets algorithm or creates it if necessary
1793 * \param theDim - specifies dimension of returned hypotheses/algorifms
1794 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1796 * Gets algorithm or creates it if necessary
1798 //================================================================================
1799 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1801 SMESH::SMESH_Hypothesis_var anAlgoVar;
1803 // get type of the selected algo
1804 int aHypIndex = currentHyp( theDim, Algo );
1805 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1806 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1808 QString aHypName = dataList[ aHypIndex ]->TypeName;
1810 // get existing algoritms
1811 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1813 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1815 // look for an existing algo of such a type
1816 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1817 THypList::iterator anIter = aHypVarList.begin();
1818 for ( ; anIter != aHypVarList.end(); anIter++)
1820 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1821 CORBA::String_var aName = aHypVar->GetName();
1822 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1824 anAlgoVar = aHypVar;
1829 if (anAlgoVar->_is_nil())
1831 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1834 QString aClientLibName = aHypData->ClientLibName;
1835 if (aClientLibName == "")
1837 // Call hypothesis creation server method (without GUI)
1838 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1842 // Get hypotheses creator client (GUI)
1844 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1845 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1849 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1851 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1853 QStringList tmpList;
1854 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1855 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1858 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1859 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1861 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1862 CORBA::String_var aName = aHypVar->GetName();
1863 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1865 anAlgoVar = aHypVar;
1871 return anAlgoVar._retn();
1874 //================================================================================
1876 * \brief Reads parameters of edited mesh and assigns them to the dialog
1878 * Reads parameters of edited mesh and assigns them to the dialog (called when
1879 * mesh is edited only)
1881 //================================================================================
1882 void SMESHGUI_MeshOp::readMesh()
1884 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1885 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1889 if (myIsOnGeometry) {
1890 // Get name of mesh if current object is sub-mesh
1891 SMESH::SMESH_subMesh_var aSubMeshVar =
1892 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1893 if ( !aSubMeshVar->_is_nil() )
1895 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1896 if ( !aMeshVar->_is_nil() )
1898 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1899 QString aMeshName = name( aMeshSO );
1900 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1904 // Get name of geometry object
1905 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1906 if ( !aGeomVar->_is_nil() )
1908 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1909 QString aShapeName = name( aGeomSO );
1910 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1914 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1915 QStringList anExisting;
1916 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1917 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1920 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1921 // find algo index among available ones
1923 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1925 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1926 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1927 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1928 // if ( aHypIndex < 0 && algoData ) {
1929 // // assigned algo is incompatible with other algorithms
1930 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1931 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1934 setCurrentHyp( dim, Algo, aHypIndex );
1935 // set existing and available hypothesis according to the selected algo
1936 onAlgoSelected( aHypIndex, dim );
1940 bool hypWithoutAlgo = false;
1941 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1943 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1946 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1947 // find index of requered hypothesis among existing ones for this dimension and type
1949 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1950 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1951 myExistingHyps[ dim ][ hypType ] );
1952 if ( aHypIndex < 0 ) {
1953 // assigned hypothesis is incompatible with the algorithm
1954 if ( currentHyp( dim, Algo ) < 0 )
1955 { // none algo selected; it is edition for sure, of submesh maybe
1956 hypWithoutAlgo = true;
1957 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1958 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1959 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1963 setCurrentHyp( dim, hypType, aHypIndex );
1966 // make available other hyps of same type as one without algo
1967 if ( hypWithoutAlgo )
1968 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1971 //================================================================================
1973 * \brief Gets name of object
1974 * \param theSO - SObject
1975 * \retval QString - name of object
1977 * Gets name of object
1979 //================================================================================
1980 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1985 _PTR(GenericAttribute) anAttr;
1986 _PTR(AttributeName) aNameAttr;
1987 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1990 aResName = aNameAttr->Value().c_str();
1996 //================================================================================
1998 * \brief Finds hypothesis in input list
1999 * \param theHyp - hypothesis to be found
2000 * \param theHypList - input list of hypotheses
2001 * \retval int - index of hypothesis or -1 if it is not found
2003 * Finds position of hypothesis in input list
2005 //================================================================================
2006 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2007 const THypList& theHypList ) const
2010 if ( !theHyp->_is_nil() )
2013 THypList::const_iterator anIter = theHypList.begin();
2014 for ( ; anIter != theHypList.end(); ++ anIter)
2016 if ( theHyp->_is_equivalent( (*anIter).first ) )
2027 //================================================================================
2029 * \brief Edits mesh or sub-mesh
2030 * \param theMess - Output parameter intended for returning error message
2031 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2033 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2035 //================================================================================
2036 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2040 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2041 if ( aSMESHGen->_is_nil() )
2044 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2045 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2049 SUIT_OverrideCursor aWaitCursor;
2052 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2053 SMESH::SetName( pObj, aName );
2054 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2056 // First, remove old algos in order to avoid messages on algorithm hiding
2057 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2059 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2061 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2062 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2063 if ( anAlgoVar->_is_nil() || // no new algo selected or
2064 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2066 // remove old algorithm
2067 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2068 myObjHyps[ dim ][ Algo ].clear();
2073 // Assign new algorithms and hypotheses
2074 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2076 if ( !isAccessibleDim( dim )) continue;
2078 // find or create algorithm
2079 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2081 // assign new algorithm
2082 if ( !anAlgoVar->_is_nil() && // some algo selected and
2083 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2085 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2086 CORBA::Object_var anObject = aSObject->GetObject();
2087 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2088 bool isMesh = !aMeshVar->_is_nil();
2090 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2092 SMESH::SMESH_subMesh_var aVar =
2093 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2094 if ( !aVar->_is_nil() )
2095 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2097 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2100 // assign hypotheses
2101 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2103 int aNewHypIndex = currentHyp( dim, hypType );
2104 int anOldHypIndex = -1;
2106 // remove old hypotheses
2107 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2109 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2110 myExistingHyps[ dim ][ hypType ] );
2111 if ( aNewHypIndex != anOldHypIndex || // different hyps
2112 anOldHypIndex == -1 ) // hyps of different algos
2114 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2115 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2116 myObjHyps[ dim ][ hypType ].clear();
2120 // assign new hypotheses
2121 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2123 SMESH::SMESH_Mesh_var aMeshVar =
2124 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2125 bool isMesh = !aMeshVar->_is_nil();
2128 SMESH::AddHypothesisOnMesh
2129 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2133 SMESH::SMESH_subMesh_var aVar =
2134 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2135 if ( !aVar->_is_nil() )
2136 SMESH::AddHypothesisOnSubMesh
2137 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2140 // reread all hypotheses of mesh if necessary
2141 QStringList anExisting;
2142 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2149 //================================================================================
2151 * \brief Verifies whether given operator is valid for this one
2152 * \param theOtherOp - other operation
2153 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2155 * method redefined from base class verifies whether given operator is valid for
2156 * this one (i.e. can be started "above" this operator). In current implementation method
2157 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2160 //================================================================================
2161 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2163 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2166 //================================================================================
2168 * \brief SLOT. Is called when the user selects a way of geometry selection
2169 * \param theByMesh - true if the user wants to find geometry by mesh element
2171 //================================================================================
2173 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2176 if ( !myShapeByMeshOp ) {
2177 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2178 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2179 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2180 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2181 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2183 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2184 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2185 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2186 SMESH::SMESH_Mesh_var aMeshVar =
2187 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2188 if ( !aMeshVar->_is_nil() ) {
2189 myDlg->hide(); // stop processing selection
2190 myShapeByMeshOp->setModule( getSMESHGUI() );
2191 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2192 myShapeByMeshOp->SetMesh( aMeshVar );
2193 myShapeByMeshOp->start();
2199 //================================================================================
2201 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2203 //================================================================================
2205 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2207 if ( myShapeByMeshOp == op ) {
2208 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2210 // Select a found geometry object
2211 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2212 if ( !aGeomVar->_is_nil() )
2214 QString ID = aGeomVar->GetStudyEntry();
2215 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2216 selectObject( aGeomSO );
2223 //================================================================================
2225 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2227 //================================================================================
2229 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2231 if ( myShapeByMeshOp == op && myDlg ) {
2236 //================================================================================
2238 * \brief Selects a SObject
2239 * \param theSObj - the SObject to select
2241 //================================================================================
2243 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2245 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2246 SALOME_ListIO anIOList;
2248 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2249 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2250 anIOList.Append( anIO );
2252 sm->setSelectedObjects( anIOList, false );