1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_MeshOp.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_MeshOp.h"
31 #include "SMESHGUI_MeshDlg.h"
32 #include "SMESHGUI_ShapeByMeshDlg.h"
33 #include "SMESHGUI_HypothesesUtils.h"
34 #include "SMESHGUI_Hypotheses.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESHGUI_GEOMGenUtils.h"
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_NumberFilter.hxx>
41 // SALOME GEOM includes
42 #include <GEOM_SelectionFilter.h>
44 #include <GeometryGUI.h>
46 // SALOME GUI includes
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LightApp_UpdateFlags.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SALOME_InteractiveObject.hxx>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDS_SComponent.hxx>
58 #include <SALOMEDS_SObject.hxx>
61 #include <QStringList>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Shell.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <BRep_Tool.hxx>
72 #include <SALOMEconfig.h>
73 #include CORBA_CLIENT_HEADER(SMESH_Gen)
75 //================================================================================
78 * \param theToCreate - if this parameter is true then operation is used for creation,
79 * for editing otherwise
81 * Initialize operation
83 //================================================================================
84 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
85 : SMESHGUI_SelectionOp(),
86 myToCreate( theToCreate ),
87 myIsMesh( theIsMesh ),
92 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
93 GeometryGUI::InitGeomGen();
94 myIsOnGeometry = true;
97 //================================================================================
101 //================================================================================
102 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
108 //================================================================================
110 * \brief Gets dialog of this operation
111 * \retval LightApp_Dialog* - pointer to dialog of this operation
113 //================================================================================
114 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
119 //================================================================================
121 * \brief Creates or edits mesh
122 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
124 * Virtual slot redefined from the base class called when "Apply" button is clicked
125 * creates or edits mesh
127 //================================================================================
128 bool SMESHGUI_MeshOp::onApply()
134 if ( !isValid( aMess ) )
138 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
142 bool aResult = false;
146 if ( myToCreate && myIsMesh )
147 aResult = createMesh( aMess );
148 if ( myToCreate && !myIsMesh )
149 aResult = createSubMesh( aMess );
150 else if ( !myToCreate )
151 aResult = editMeshOrSubMesh( aMess );
153 update( UF_ObjBrowser | UF_Model );
155 catch ( const SALOME::SALOME_Exception& S_ex )
157 SalomeApp_Tools::QtCatchCorbaException( S_ex );
173 aMess = tr( "SMESH_OPERATION_FAILED" );
174 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
180 //================================================================================
182 * \brief Creates dialog if necessary and shows it
184 * Virtual method redefined from base class called when operation is started creates
185 * dialog if necessary and shows it, activates selection
187 //================================================================================
188 void SMESHGUI_MeshOp::startOperation()
192 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
193 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
195 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
196 this, SLOT( onCreateHyp( const int, const int ) ) );
197 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
198 this, SLOT( onEditHyp( const int, const int ) ) );
199 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
200 this, SLOT( onAlgoSelected( const int ) ) );
202 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
203 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
206 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
207 else myHelpFileName = "constructing_submeshes_page.html";
208 else myHelpFileName = "editing_meshes_page.html";
210 SMESHGUI_SelectionOp::startOperation();
212 // iterate through dimensions and get available algoritms, set them to the dialog
213 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
214 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
216 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
218 // clear available hypotheses
219 aTab->setAvailableHyps( MainHyp, hypList );
220 aTab->setAvailableHyps( AddHyp, hypList );
221 aTab->setExistingHyps( MainHyp, hypList );
222 aTab->setExistingHyps( AddHyp, hypList );
223 myExistingHyps[ i ][ MainHyp ].clear();
224 myExistingHyps[ i ][ AddHyp ].clear();
226 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
227 aTab->setAvailableHyps( Algo, hypList );
232 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
235 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
237 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
239 myDlg->setCurrentTab( SMESH::DIM_3D );
244 myIgnoreAlgoSelection = false;
247 //================================================================================
249 * \brief Creates selection filter
250 * \param theId - identifier of current selection widget
251 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
253 * Creates selection filter in accordance with identifier of current selection widget
255 //================================================================================
256 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
258 if ( theId == SMESHGUI_MeshDlg::Geom )
260 // TColStd_MapOfInteger allTypesMap;
261 // for ( int i = 0; i < 10; i++ )
262 // allTypesMap.Add( i );
263 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
264 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
266 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
267 return new SMESH_TypeFilter( MESHorSUBMESH );
268 else if ( theId == SMESHGUI_MeshDlg::Mesh )
269 return new SMESH_TypeFilter( MESH );
274 //================================================================================
276 * \brief check if selected shape is a subshape of the shape to mesh
277 * \retval bool - check result
279 //================================================================================
281 bool SMESHGUI_MeshOp::isSubshapeOk() const
283 if ( !myToCreate || myIsMesh ) // not submesh creation
287 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
288 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
289 if (!pMesh) return false;
291 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
292 if (mesh->_is_nil()) return false;
294 // main shape of the mesh
295 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
296 if (mainGeom->_is_nil()) return false;
300 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
302 if (aGEOMs.count() > 0) {
303 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
304 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
305 if (geomGen->_is_nil() || !aStudy) return false;
307 GEOM::GEOM_IGroupOperations_var op =
308 geomGen->GetIGroupOperations(aStudy->StudyId());
309 if (op->_is_nil()) return false;
311 // check all selected shapes
312 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
313 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
314 QString aSubGeomEntry = (*aSubShapesIter);
315 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
316 if (!pSubGeom) return false;
318 GEOM::GEOM_Object_var aSubGeomVar =
319 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
320 if (aSubGeomVar->_is_nil()) return false;
322 // skl for NPAL14695 - implementation of searching of mainObj
323 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
324 //if (mainObj->_is_nil() ||
325 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
327 if (mainObj->_is_nil())
329 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
331 mainObj = op->GetMainShape(mainObj);
340 //================================================================================
342 * \brief Return name of the algorithm that does not support submeshes and makes
343 * submesh creation useless
344 * \retval char* - string is to be deleted!!!
346 //================================================================================
348 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
350 if ( myToCreate && !myIsMesh ) {
352 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
353 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
354 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
357 QStringList algoNames;
359 existingHyps(3, Algo, pMesh, algoNames, algoList);
360 if (!algoList.empty()) {
361 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
363 algo->InputTypes.empty() && // builds all dimensions it-self
364 !algo->IsSupportSubmeshes )
365 return CORBA::string_dup( algoNames[0].toLatin1().data() );
368 // GEOM::GEOM_Object_var geom;
369 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
370 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
372 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
373 existingHyps(2, Algo, pMesh, algoNames, algoList);
374 if (!algoList.empty()) {
375 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
377 algo->InputTypes.empty() && // builds all dimensions it-self
378 !algo->IsSupportSubmeshes )
379 return CORBA::string_dup( algoNames[0].toLatin1().data() );
387 //================================================================================
389 * \brief find an existing submesh by the selected shape
390 * \retval _PTR(SObject) - the found submesh SObject
392 //================================================================================
394 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
396 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
397 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
398 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
399 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
400 if ( pMesh && pGeom ) {
401 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
402 if ( !geom->_is_nil() ) {
404 switch ( geom->GetShapeType() ) {
405 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
406 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
407 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
408 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
409 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
410 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
411 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
414 _PTR(GenericAttribute) anAttr;
415 _PTR(SObject) aSubmeshRoot;
416 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
417 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
419 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
420 for ( ; smIter->More(); smIter->Next() )
422 _PTR(SObject) aSmObj = smIter->Value();
423 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
425 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
426 for ( ; anIter1->More(); anIter1->Next()) {
427 _PTR(SObject) pGeom2 = anIter1->Value();
428 if ( pGeom2->ReferencedObject( pGeom2 ) &&
429 pGeom2->GetID() == pGeom->GetID() )
436 return _PTR(SObject)();
439 //================================================================================
441 * \brief Updates dialog's look and feel
443 * Virtual method redefined from the base class updates dialog's look and feel
445 //================================================================================
446 void SMESHGUI_MeshOp::selectionDone()
448 if (!dlg()->isVisible() || !myDlg->isEnabled())
451 SMESHGUI_SelectionOp::selectionDone();
455 myIsOnGeometry = true;
457 //Check geometry for mesh
458 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
459 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
462 SMESH::SMESH_Mesh_var aMeshVar =
463 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
464 if (!aMeshVar->_is_nil()) {
465 if (!myToCreate && !aMeshVar->HasShapeToMesh())
466 myIsOnGeometry = false;
472 // Enable tabs according to shape dimension
477 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
478 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
480 if (aGEOMs.count() > 0) {
481 // one or more GEOM shape selected
482 aSeq->length(aGEOMs.count());
483 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
485 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
486 QString aSubGeomEntry = (*aSubShapesIter);
487 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
488 GEOM::GEOM_Object_var aSubGeomVar =
489 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
490 aSeq[iSubSh] = aSubGeomVar;
493 // get geometry by selected sub-mesh
494 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
495 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
496 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
497 if (!aGeomVar->_is_nil()) {
503 if (aSeq->length() > 0) {
505 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
506 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
507 switch ( aGeomVar->GetShapeType() ) {
508 case GEOM::SOLID: shapeDim = 3; break;
511 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
512 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
514 if (GEOMBase::GetShape(aGeomVar, aShape)) {
515 if (/*aShape.Closed()*/BRep_Tool::IsClosed(aShape))
520 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
522 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
523 case GEOM::VERTEX: break;
527 if (GEOMBase::GetShape(aGeomVar, aShape)) {
528 TopExp_Explorer exp (aShape, TopAbs_SHELL);
530 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
531 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
532 for (; exp.More() && shapeDim == 2; exp.Next()) {
533 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
537 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
538 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
539 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
540 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
548 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
549 // reset algos before disabling tabs (0020138)
550 onAlgoSelected(-1, i);
552 myDlg->setMaxHypoDim( shapeDim );
555 if (!myToCreate) // edition: read hypotheses
559 SMESH::SMESH_subMesh_var aVar =
560 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
561 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
562 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
563 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
564 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
565 myDlg->updateGeometry();
572 else if ( !myIsMesh ) // submesh creation
574 // if a submesh on the selected shape already exist, pass to submesh edition mode
575 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
576 SMESH::SMESH_subMesh_var sm =
577 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
578 bool editSubmesh = ( !sm->_is_nil() &&
579 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
580 tr( "EDIT_SUBMESH_QUESTION"),
581 SUIT_MessageBox::Yes |
583 SUIT_MessageBox::No )
584 == SUIT_MessageBox::Yes );
587 selectionMgr()->clearFilters();
588 selectObject( pSubmesh );
589 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
594 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
595 selectObject( _PTR(SObject)() );
600 // discard selected mesh if submesh creation not allowed because of
601 // a global algorithm that does not support submeshes
602 if ( char* algoName = isSubmeshIgnored() ) {
603 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
604 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
605 CORBA::string_free( algoName );
606 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
607 selectObject( _PTR(SObject)() );
612 // enable/disable popup for choice of geom selection way
614 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
615 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
616 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
617 if ( !mesh->_is_nil() )
618 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
620 myDlg->setGeomPopupEnabled( enable );
624 myDlg->enableTab( SMESH::DIM_3D );
626 availableHyps( SMESH::DIM_3D, Algo, hypList,
627 myAvailableHypData[SMESH::DIM_3D][Algo]);
629 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
630 aTab->setAvailableHyps( Algo, hypList );
631 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
632 myDlg->disableTab(i);
634 //Hide labels and fields (Mesh ang Geometry)
635 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
636 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
641 catch ( const SALOME::SALOME_Exception& S_ex )
643 SalomeApp_Tools::QtCatchCorbaException( S_ex );
650 //================================================================================
652 * \brief Verifies validity of input data
653 * \param theMess - Output parameter intended for returning error message
654 * \retval bool - TRUE if input data is valid, false otherwise
656 * Verifies validity of input data. This method is called when "Apply" or "OK" button
657 * is pressed before mesh creation or editing.
659 //================================================================================
660 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
662 // Selected object to be edited
663 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
665 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
670 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
671 if ( aMeshName.isEmpty() )
673 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
677 /* // Imported mesh, if create sub-mesh or edit mesh
678 if ( !myToCreate || ( myToCreate && !myIsMesh ))
680 QString aMeshEntry = myDlg->selectedObject
681 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
682 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
683 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
684 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
685 theMess = tr( "IMPORTED_MESH" );
694 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
695 if ( aGeomEntry == "" )
697 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
700 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
701 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
703 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
708 if ( !myIsMesh ) // i.e sub-mesh creation,
710 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
711 if ( aMeshEntry == "" )
713 theMess = tr( "MESH_IS_NOT_DEFINED" );
716 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
717 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
719 theMess = tr( "MESH_IS_NULL" );
722 if ( !isSubshapeOk() )
724 theMess = tr( "INVALID_SUBSHAPE" );
733 //================================================================================
735 * \brief check compatibility of the algorithm and another algorithm or hypothesis
736 * \param theAlgoData - algorithm data
737 * \param theHypData - hypothesis data
738 * \param theHypType - hypothesis type
739 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
740 * \retval bool - check result
742 //================================================================================
744 static bool isCompatible(const HypothesisData* theAlgoData,
745 const HypothesisData* theHypData,
746 const int theHypType)
751 if ( theHypType == SMESHGUI_MeshOp::Algo )
752 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
755 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
758 //================================================================================
760 * \brief Gets available hypotheses or algorithms
761 * \param theDim - specifies dimension of returned hypotheses/algorifms
762 * \param theHypType - specifies whether algorims or hypotheses or additional ones
763 * are retrieved (possible values are in HypType enumeration)
764 * \param theHyps - Output list of hypotheses' names
765 * \param theAlgoData - to select hypos able to be used by this algo (optional)
767 * Gets available hypotheses or algorithm in accordance with input parameters
769 //================================================================================
770 void SMESHGUI_MeshOp::availableHyps( const int theDim,
771 const int theHypType,
772 QStringList& theHyps,
773 THypDataList& theDataList,
774 HypothesisData* theAlgoData ) const
778 bool isAlgo = ( theHypType == Algo );
779 bool isAux = ( theHypType == AddHyp );
780 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
782 QStringList::const_iterator anIter;
783 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
785 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
786 if ( isCompatible ( theAlgoData, aData, theHypType )) {
787 theDataList.append( aData );
788 theHyps.append( aData->Label );
793 //================================================================================
795 * \brief Gets existing hypotheses or algorithms
796 * \param theDim - specifies dimension of returned hypotheses/algorifms
797 * \param theHypType - specifies whether algorims or hypotheses or additional ones
798 * are retrieved (possible values are in HypType enumeration)
799 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
800 * \param theHyps - output list of names.
801 * \param theHypVars - output list of variables.
802 * \param theAlgoData - to select hypos able to be used by this algo (optional)
804 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
807 //================================================================================
808 void SMESHGUI_MeshOp::existingHyps( const int theDim,
809 const int theHypType,
810 _PTR(SObject) theFather,
811 QStringList& theHyps,
812 THypList& theHypList,
813 HypothesisData* theAlgoData)
815 // Clear hypoheses list
822 const bool isAux = ( theHypType == AddHyp );
824 _PTR(SObject) aHypRoot;
825 _PTR(GenericAttribute) anAttr;
826 _PTR(AttributeName) aName;
827 _PTR(AttributeIOR) anIOR;
829 bool isMesh = !_CAST( SComponent, theFather );
832 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
834 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
836 if ( theFather->FindSubObject( aPart, aHypRoot ) )
838 _PTR(ChildIterator) anIter =
839 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
840 for ( ; anIter->More(); anIter->Next() )
842 _PTR(SObject) anObj = anIter->Value();
843 if ( isMesh ) // i.e. mesh or submesh
845 _PTR(SObject) aRefObj;
846 if ( anObj->ReferencedObject( aRefObj ) )
851 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
854 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
855 if ( !CORBA::is_nil( aVar ) )
857 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
858 if ( !aHypVar->_is_nil() )
860 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
861 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
862 ( isCompatible ( theAlgoData, aData, theHypType )) &&
863 ( isAux == aData->IsAux ))
865 std::string aHypName = aName->Value();
866 theHyps.append( aHypName.c_str() );
867 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
876 //================================================================================
878 * \brief If create or edit a submesh, return a hypothesis holding parameters used
880 * \param aHypType - The hypothesis type name
881 * \param aServerLib - Server library name
882 * \param hypData - The structure holding the hypothesis type etc.
883 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
885 //================================================================================
887 SMESH::SMESH_Hypothesis_var
888 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
889 const QString& aServerLib ) const
891 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
892 return SMESH::SMESH_Hypothesis::_nil();
894 const int nbColonsInMeshEntry = 3;
895 bool isSubMesh = myToCreate ?
897 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
899 // get mesh and geom object
900 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
901 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
906 anEntry = myDlg->selectedObject
907 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
908 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
910 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
911 if ( myToCreate ) // mesh and geom may be selected
913 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
914 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
915 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
916 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
918 else // edition: sub-mesh may be selected
920 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
921 if ( !sm->_is_nil() ) {
922 aMeshVar = sm->GetFather();
923 aGeomVar = sm->GetSubShape();
930 if ( !myToCreate ) // mesh to edit can be selected
932 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
933 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
935 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
936 if ( !aMeshVar->_is_nil() )
937 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
940 if ( aGeomVar->_is_nil() ) {
941 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
942 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
944 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
949 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
950 aServerLib.toLatin1().data(),
953 /*byMesh = */isSubMesh);
957 //================================================================================
959 * \Brief Returns tab dimention
960 * \param tab - the tab in the dlg
961 * \param dlg - my dialogue
962 * \retval int - dimention
964 //================================================================================
966 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
969 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
970 if (tab == dlg->tab(i))
975 //================================================================================
977 * \brief Create hypothesis
978 * \param theHypType - hypothesis category (main or additional)
979 * \param theIndex - index of type of hypothesis to be cerated
981 * Specifies dimension of hypothesis to be created (using sender() method),
982 * specifies its type and calls method for hypothesis creation
984 //================================================================================
985 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
987 // Specifies dimension of hypothesis to be created
988 int aDim = getTabDim( sender(), myDlg );
992 // Specifies type of hypothesis to be created
993 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
994 if (theIndex < 0 || theIndex >= dataList.count())
996 QString aHypTypeName = dataList[ theIndex ]->TypeName;
999 createHypothesis(aDim, theHypType, aHypTypeName);
1004 QString GetUniqueName (const QStringList& theHypNames,
1005 const QString& theName,
1006 size_t theIteration = 1)
1008 QString aName = theName + "_" + QString::number( theIteration );
1009 if ( theHypNames.contains( aName ) )
1010 return GetUniqueName( theHypNames, theName, ++theIteration );
1015 //================================================================================
1017 * Create hypothesis and update dialog.
1018 * \param theDim - dimension of hypothesis to be created
1019 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1020 * \param theTypeName - specifies hypothesis to be created
1022 //================================================================================
1024 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1026 const QString& theTypeName)
1028 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1034 QStringList aHypNames;
1035 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1036 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1037 const TType2HypList& aType2HypList = aDimIter.value();
1038 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1039 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1040 const THypList& aHypList = aTypeIter.value();
1041 THypList::const_iterator anIter = aHypList.begin();
1042 for ( ; anIter != aHypList.end(); anIter++) {
1043 const THypItem& aHypItem = *anIter;
1044 const QString& aHypName = aHypItem.second;
1045 aHypNames.append(aHypName);
1049 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1052 bool dialog = false;
1054 QString aClientLibName = aData->ClientLibName;
1055 if (aClientLibName == "") {
1056 // Call hypothesis creation server method (without GUI)
1057 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1059 // Get hypotheses creator client (GUI)
1061 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1062 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1064 // Create hypothesis
1066 // Get parameters appropriate to initialize a new hypothesis
1067 SMESH::SMESH_Hypothesis_var initParamHyp =
1068 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1070 removeCustomFilters(); // Issue 0020170
1072 // Get Entry of the Geom object
1073 QString aGeomEntry = "";
1074 QString aMeshEntry = "";
1075 QString anObjEntry = "";
1076 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1077 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1078 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1080 if ( aMeshEntry != "" ) { // Get Geom object from Mesh
1081 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1082 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1083 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1086 if ( aMeshEntry == "" && aGeomEntry == "" ) {
1087 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1088 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1089 if ( !aGeomVar->_is_nil() )
1090 aGeomEntry = aGeomVar->GetStudyEntry();
1093 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
1094 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1096 // if current object is sub-mesh
1097 SMESH::SMESH_subMesh_var aSubMeshVar =
1098 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1099 if ( !aSubMeshVar->_is_nil() ) {
1100 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1101 if ( !aMeshVar->_is_nil() ) {
1102 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1103 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1104 if ( !aGeomVar->_is_nil() )
1105 aMeshEntry = aGeomVar->GetStudyEntry();
1111 aCreator->setShapeEntry( aGeomEntry );
1112 if ( aMeshEntry != "" )
1113 aCreator->setMainShapeEntry( aMeshEntry );
1114 myDlg->setEnabled( false );
1115 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1119 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1126 //================================================================================
1128 * Necessary steps after hypothesis creation
1129 * \param result - creation result:
1132 * 2 = additional value meaning that slot is called not from dialog box
1134 //================================================================================
1135 void SMESHGUI_MeshOp::onHypoCreated( int result )
1139 int obj = myDlg->getActiveObject();
1140 onActivateObject( obj ); // Issue 0020170. Restore filters
1141 myDlg->setEnabled( true );
1144 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1146 int nbHyp = myExistingHyps[myDim][myType].count();
1147 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1148 QStringList aNewHyps;
1149 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1150 if (aNewHyps.count() > nbHyp)
1152 for (int i = nbHyp; i < aNewHyps.count(); i++)
1153 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1156 if( result!=2 && myHypoSet )
1160 //================================================================================
1162 * \brief Calls plugin methods for hypothesis editing
1163 * \param theHypType - specifies whether main hypothesis or additional one
1165 * \param theIndex - index of existing hypothesis
1167 * Calls plugin methods for hypothesis editing
1169 //================================================================================
1170 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1172 // Speicfies dimension of hypothesis to be created
1173 int aDim = getTabDim( sender(), myDlg );
1177 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1178 if ( theIndex < 0 || theIndex >= aList.count() )
1180 const THypItem& aHypItem = aList[ theIndex ];
1181 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1182 if ( aHyp->_is_nil() )
1186 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1187 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1190 // Get initial parameters
1191 SMESH::SMESH_Hypothesis_var initParamHyp =
1192 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1193 aCreator->setInitParamsHypothesis( initParamHyp );
1195 // Get Entry of the Geom object
1196 QString aGeomEntry = "";
1197 QString aMeshEntry = "";
1198 QString anObjEntry = "";
1199 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1200 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1201 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1203 if ( aMeshEntry != "" ) { // Get Geom object from Mesh
1204 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1205 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1206 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1209 if ( aMeshEntry == "" && aGeomEntry == "" ) {
1210 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1211 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1212 if ( !aGeomVar->_is_nil() )
1213 aGeomEntry = aGeomVar->GetStudyEntry();
1216 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
1217 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1219 // if current object is sub-mesh
1220 SMESH::SMESH_subMesh_var aSubMeshVar =
1221 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1222 if ( !aSubMeshVar->_is_nil() ) {
1223 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1224 if ( !aMeshVar->_is_nil() ) {
1225 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1226 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1227 if ( !aGeomVar->_is_nil() )
1228 aMeshEntry = aGeomVar->GetStudyEntry();
1234 aCreator->setShapeEntry( aGeomEntry );
1235 if ( aMeshEntry != "" )
1236 aCreator->setMainShapeEntry( aMeshEntry );
1237 removeCustomFilters(); // Issue 0020170
1238 myDlg->setEnabled( false );
1239 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1243 //================================================================================
1245 * Necessary steps after hypothesis edition
1246 * \param result - creation result:
1250 //================================================================================
1251 void SMESHGUI_MeshOp::onHypoEdited( int result )
1253 int obj = myDlg->getActiveObject();
1254 onActivateObject( obj ); // Issue 0020170. Restore filters
1255 myDlg->setEnabled( true );
1258 //================================================================================
1260 * \brief access to hypothesis data
1261 * \param theDim - hyp dimension
1262 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1263 * \param theIndex - index in the list
1264 * \retval HypothesisData* - result data, may be 0
1266 //================================================================================
1268 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1269 const int theHypType,
1272 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1273 theHypType > -1 && theHypType < NbHypTypes &&
1274 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1275 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1279 //================================================================================
1281 * \brief Set available algos and hypos according to the selected algorithm
1282 * \param theIndex - algorithm index
1284 //================================================================================
1286 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1289 if ( myIgnoreAlgoSelection )
1292 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1296 // find highest available dimension, all algos of this dimension are available for choice
1298 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1299 if (isAccessibleDim( i ))
1304 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1306 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1307 HypothesisData* algoByDim[4];
1308 algoByDim[ aDim ] = algoData;
1310 QStringList anAvailable;
1311 if ( !algoData ) { // all algos becomes available
1312 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1313 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1316 // check that algorithms of other dimentions are compatible with
1319 // 2 loops: backward and forward from algo dimension
1320 for ( int forward = false; forward <= true; ++forward )
1322 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1324 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1326 HypothesisData* prevAlgo = algoData;
1327 bool noCompatible = false;
1328 for ( ; dim * dir <= lastDim * dir; dim += dir)
1330 if ( !isAccessibleDim( dim ))
1332 if ( noCompatible ) { // the selected algo has no compatible ones
1333 anAvailable.clear();
1334 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1335 myAvailableHypData[dim][Algo].clear();
1336 algoByDim[ dim ] = 0;
1339 // get currently selected algo
1340 int algoIndex = currentHyp( dim, Algo );
1341 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1342 if ( curAlgo ) { // some algo selected
1343 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1346 // set new available algoritms
1347 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1348 HypothesisData* soleCompatible = 0;
1349 if ( anAvailable.count() == 1 )
1350 soleCompatible = myAvailableHypData[dim][Algo][0];
1351 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1352 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1353 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1354 noCompatible = anAvailable.isEmpty();
1356 // restore previously selected algo
1357 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1358 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1359 // select the sole compatible algo
1360 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1361 setCurrentHyp( dim, Algo, algoIndex );
1363 // remember current algo
1364 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1368 // set hypotheses corresponding to the found algoritms
1370 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1372 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1374 if ( !isAccessibleDim( dim ))
1376 for ( int type = MainHyp; type < NbHypTypes; type++ )
1378 myAvailableHypData[ dim ][ type ].clear();
1379 QStringList anAvailable, anExisting;
1381 HypothesisData* curAlgo = algoByDim[ dim ];
1382 int hypIndex = currentHyp( dim, type );
1384 SMESH::SMESH_Hypothesis_var curHyp;
1385 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1386 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1388 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1389 // try to find algo by selected hypothesis in order to keep it selected
1390 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1391 CORBA::String_var curHypType = curHyp->GetName();
1392 if ( !algoDeselectedByUser &&
1393 myObjHyps[ dim ][ type ].count() > 0 &&
1394 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1396 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1397 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1398 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1399 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1406 // get hyps compatible with curAlgo
1409 // check if a selected hyp is compatible with the curAlgo
1410 if ( !curHyp->_is_nil() ) {
1411 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1412 if ( !isCompatible( curAlgo, hypData, type ))
1413 curHyp = SMESH::SMESH_Hypothesis::_nil();
1415 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1416 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1418 // set list of hypotheses
1419 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1420 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1422 // set current existing hypothesis
1423 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1424 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1427 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1428 // none is yet selected => select the sole existing if it is not optional
1429 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1430 bool isOptional = true;
1431 if ( algoByDim[ dim ] &&
1432 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1436 setCurrentHyp( dim, type, hypIndex );
1441 //================================================================================
1443 * \brief Creates and selects hypothesis of hypotheses set
1444 * \param theSetName - The name of hypotheses set
1446 //================================================================================
1447 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1449 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1454 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1455 setCurrentHyp(dim, Algo, -1);
1456 setCurrentHyp(dim, AddHyp, -1);
1457 setCurrentHyp(dim, MainHyp, -1);
1460 myHypoSet->init(true); //algorithms
1462 myHypoSet->init(false); //hypotheses
1467 //================================================================================
1469 * \brief One step of hypothesis/algorithm list creation
1471 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1473 //================================================================================
1474 void SMESHGUI_MeshOp::processSet()
1477 if( !myHypoSet->more() )
1480 bool isAlgo = myHypoSet->isAlgo();
1481 QString aHypoTypeName = myHypoSet->current();
1482 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1489 int aDim = aHypData->Dim[0];
1490 // create or/and set
1493 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1496 QStringList anAvailable;
1497 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1498 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1499 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1501 setCurrentHyp( aDim, Algo, index );
1502 onAlgoSelected( index, aDim );
1507 bool mainHyp = true;
1508 QStringList anAvailable;
1509 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1510 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1511 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1515 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1518 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1524 //================================================================================
1526 * \brief Creates mesh
1527 * \param theMess - Output parameter intended for returning error message
1528 * \retval bool - TRUE if mesh is created, FALSE otherwise
1532 //================================================================================
1533 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1537 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1538 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1541 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1542 QStringList::Iterator it = aList.begin();
1543 for ( ; it!=aList.end(); it++)
1545 QString aGeomEntry = *it;
1546 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1547 GEOM::GEOM_Object_var aGeomVar =
1548 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1550 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1551 if ( aSMESHGen->_is_nil() )
1554 SUIT_OverrideCursor aWaitCursor;
1557 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1558 if ( aMeshVar->_is_nil() )
1560 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1562 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1564 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1565 if ( !isAccessibleDim( aDim )) continue;
1567 // assign hypotheses
1568 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1569 int aHypIndex = currentHyp( aDim, aHypType );
1570 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1571 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1572 if ( !aHypVar->_is_nil() )
1573 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1576 // find or create algorithm
1577 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1578 if ( !anAlgoVar->_is_nil() )
1579 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1586 //================================================================================
1588 * \brief Creates sub-mesh
1589 * \param theMess - Output parameter intended for returning error message
1590 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1594 //================================================================================
1595 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1599 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1600 if ( aSMESHGen->_is_nil() )
1604 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1605 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1606 SMESH::SMESH_Mesh_var aMeshVar =
1607 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1608 if (aMeshVar->_is_nil())
1611 // GEOM shape of the main mesh
1612 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1614 // Name for the new sub-mesh
1615 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1618 GEOM::GEOM_Object_var aGeomVar;
1620 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1621 if (aGEOMs.count() == 1)
1623 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1624 QString aGeomEntry = aGEOMs.first();
1625 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1626 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1628 else if (aGEOMs.count() > 1)
1630 // create a GEOM group
1631 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1632 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1633 if (!geomGen->_is_nil() && aStudy) {
1634 GEOM::GEOM_IGroupOperations_var op =
1635 geomGen->GetIGroupOperations(aStudy->StudyId());
1636 if (!op->_is_nil()) {
1637 // check and add all selected GEOM objects: they must be
1638 // a sub-shapes of the main GEOM and must be of one type
1640 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1641 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1642 aSeq->length(aGEOMs.count());
1643 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1644 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1645 QString aSubGeomEntry = (*aSubShapesIter);
1646 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1647 GEOM::GEOM_Object_var aSubGeomVar =
1648 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1649 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1651 aGroupType = aSubShapeType;
1653 if (aSubShapeType != aGroupType)
1654 aGroupType = TopAbs_SHAPE;
1656 aSeq[iSubSh] = aSubGeomVar;
1659 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1660 op->UnionList(aGroupVar, aSeq);
1663 aGeomVar = aGroupVar;
1665 // publish the GEOM group in study
1666 QString aNewGeomGroupName ("Auto_group_for_");
1667 aNewGeomGroupName += aName;
1668 SALOMEDS::SObject_var aNewGroupSO =
1669 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1670 aNewGeomGroupName.toLatin1().data(), mainGeom);
1677 if (aGeomVar->_is_nil())
1680 SUIT_OverrideCursor aWaitCursor;
1683 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1684 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1686 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1688 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1690 if ( !isAccessibleDim( aDim )) continue;
1692 // find or create algorithm
1693 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1694 if ( !anAlgoVar->_is_nil() )
1695 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1696 // assign hypotheses
1697 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1699 int aHypIndex = currentHyp( aDim, aHypType );
1700 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1702 SMESH::SMESH_Hypothesis_var aHypVar =
1703 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1704 if ( !aHypVar->_is_nil() )
1705 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1710 // deselect geometry: next submesh should be created on other subshape
1711 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1712 selectObject( _PTR(SObject)() );
1718 //================================================================================
1720 * \brief Gets current hypothesis or algorithms
1721 * \param theDim - dimension of hypothesis or algorithm
1722 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1723 * \retval int - current hypothesis or algorithms
1725 * Gets current hypothesis or algorithms
1727 //================================================================================
1728 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1730 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1733 //================================================================================
1735 * \brief Returns true if hypotheses of given dim can be assigned
1736 * \param theDim - hypotheses dimension
1737 * \retval bool - result
1739 //================================================================================
1740 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1742 return myDlg->isTabEnabled( theDim );
1745 //================================================================================
1747 * \brief Sets current hypothesis or algorithms
1748 * \param theDim - dimension of hypothesis or algorithm
1749 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1750 * \param theIndex - Index of hypothesis
1752 * Gets current hypothesis or algorithms
1754 //================================================================================
1755 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1756 const int theHypType,
1757 const int theIndex )
1759 myIgnoreAlgoSelection = true;
1760 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1761 myIgnoreAlgoSelection = false;
1764 //================================================================================
1766 * \brief Generates default and sets mesh/submesh name
1768 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1770 //================================================================================
1771 void SMESHGUI_MeshOp::setDefaultName() const
1775 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1777 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1778 _PTR(SObject) anObj;
1781 aResName = aPrefix + QString::number( i++ );
1782 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1786 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1787 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1788 aControl->setText( aResName );
1791 //================================================================================
1793 * \brief Gets algorithm or creates it if necessary
1794 * \param theDim - specifies dimension of returned hypotheses/algorifms
1795 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1797 * Gets algorithm or creates it if necessary
1799 //================================================================================
1800 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1802 SMESH::SMESH_Hypothesis_var anAlgoVar;
1804 // get type of the selected algo
1805 int aHypIndex = currentHyp( theDim, Algo );
1806 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1807 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1809 QString aHypName = dataList[ aHypIndex ]->TypeName;
1811 // get existing algoritms
1812 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1814 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1816 // look for an existing algo of such a type
1817 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1818 THypList::iterator anIter = aHypVarList.begin();
1819 for ( ; anIter != aHypVarList.end(); anIter++)
1821 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1822 CORBA::String_var aName = aHypVar->GetName();
1823 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1825 anAlgoVar = aHypVar;
1830 if (anAlgoVar->_is_nil())
1832 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1835 QString aClientLibName = aHypData->ClientLibName;
1836 if (aClientLibName == "")
1838 // Call hypothesis creation server method (without GUI)
1839 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1843 // Get hypotheses creator client (GUI)
1845 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1846 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1850 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1852 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1854 QStringList tmpList;
1855 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1856 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1859 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1860 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1862 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1863 CORBA::String_var aName = aHypVar->GetName();
1864 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1866 anAlgoVar = aHypVar;
1872 return anAlgoVar._retn();
1875 //================================================================================
1877 * \brief Reads parameters of edited mesh and assigns them to the dialog
1879 * Reads parameters of edited mesh and assigns them to the dialog (called when
1880 * mesh is edited only)
1882 //================================================================================
1883 void SMESHGUI_MeshOp::readMesh()
1885 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1886 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1890 if (myIsOnGeometry) {
1891 // Get name of mesh if current object is sub-mesh
1892 SMESH::SMESH_subMesh_var aSubMeshVar =
1893 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1894 if ( !aSubMeshVar->_is_nil() )
1896 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1897 if ( !aMeshVar->_is_nil() )
1899 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1900 QString aMeshName = name( aMeshSO );
1901 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1905 // Get name of geometry object
1906 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1907 if ( !aGeomVar->_is_nil() )
1909 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1910 QString aShapeName = name( aGeomSO );
1911 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1915 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1916 QStringList anExisting;
1917 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1918 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1921 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1922 // find algo index among available ones
1924 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1926 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1927 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1928 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1929 // if ( aHypIndex < 0 && algoData ) {
1930 // // assigned algo is incompatible with other algorithms
1931 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1932 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1935 setCurrentHyp( dim, Algo, aHypIndex );
1936 // set existing and available hypothesis according to the selected algo
1937 onAlgoSelected( aHypIndex, dim );
1941 bool hypWithoutAlgo = false;
1942 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1944 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1947 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1948 // find index of requered hypothesis among existing ones for this dimension and type
1950 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1951 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1952 myExistingHyps[ dim ][ hypType ] );
1953 if ( aHypIndex < 0 ) {
1954 // assigned hypothesis is incompatible with the algorithm
1955 if ( currentHyp( dim, Algo ) < 0 )
1956 { // none algo selected; it is edition for sure, of submesh maybe
1957 hypWithoutAlgo = true;
1958 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1959 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1960 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1964 setCurrentHyp( dim, hypType, aHypIndex );
1967 // make available other hyps of same type as one without algo
1968 if ( hypWithoutAlgo )
1969 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1972 //================================================================================
1974 * \brief Gets name of object
1975 * \param theSO - SObject
1976 * \retval QString - name of object
1978 * Gets name of object
1980 //================================================================================
1981 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1986 _PTR(GenericAttribute) anAttr;
1987 _PTR(AttributeName) aNameAttr;
1988 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1991 aResName = aNameAttr->Value().c_str();
1997 //================================================================================
1999 * \brief Finds hypothesis in input list
2000 * \param theHyp - hypothesis to be found
2001 * \param theHypList - input list of hypotheses
2002 * \retval int - index of hypothesis or -1 if it is not found
2004 * Finds position of hypothesis in input list
2006 //================================================================================
2007 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2008 const THypList& theHypList ) const
2011 if ( !theHyp->_is_nil() )
2014 THypList::const_iterator anIter = theHypList.begin();
2015 for ( ; anIter != theHypList.end(); ++ anIter)
2017 if ( theHyp->_is_equivalent( (*anIter).first ) )
2028 //================================================================================
2030 * \brief Edits mesh or sub-mesh
2031 * \param theMess - Output parameter intended for returning error message
2032 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2034 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2036 //================================================================================
2037 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2041 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2042 if ( aSMESHGen->_is_nil() )
2045 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2046 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2050 SUIT_OverrideCursor aWaitCursor;
2053 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2054 SMESH::SetName( pObj, aName );
2055 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2057 // First, remove old algos in order to avoid messages on algorithm hiding
2058 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2060 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2062 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2063 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2064 if ( anAlgoVar->_is_nil() || // no new algo selected or
2065 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2067 // remove old algorithm
2068 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2069 myObjHyps[ dim ][ Algo ].clear();
2074 // Assign new algorithms and hypotheses
2075 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2077 if ( !isAccessibleDim( dim )) continue;
2079 // find or create algorithm
2080 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2082 // assign new algorithm
2083 if ( !anAlgoVar->_is_nil() && // some algo selected and
2084 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2086 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2087 CORBA::Object_var anObject = aSObject->GetObject();
2088 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2089 bool isMesh = !aMeshVar->_is_nil();
2091 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2093 SMESH::SMESH_subMesh_var aVar =
2094 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2095 if ( !aVar->_is_nil() )
2096 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2098 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2101 // assign hypotheses
2102 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2104 int aNewHypIndex = currentHyp( dim, hypType );
2105 int anOldHypIndex = -1;
2107 // remove old hypotheses
2108 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2110 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2111 myExistingHyps[ dim ][ hypType ] );
2112 if ( aNewHypIndex != anOldHypIndex || // different hyps
2113 anOldHypIndex == -1 ) // hyps of different algos
2115 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2116 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2117 myObjHyps[ dim ][ hypType ].clear();
2121 // assign new hypotheses
2122 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2124 SMESH::SMESH_Mesh_var aMeshVar =
2125 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2126 bool isMesh = !aMeshVar->_is_nil();
2129 SMESH::AddHypothesisOnMesh
2130 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2134 SMESH::SMESH_subMesh_var aVar =
2135 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2136 if ( !aVar->_is_nil() )
2137 SMESH::AddHypothesisOnSubMesh
2138 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2141 // reread all hypotheses of mesh if necessary
2142 QStringList anExisting;
2143 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2150 //================================================================================
2152 * \brief Verifies whether given operator is valid for this one
2153 * \param theOtherOp - other operation
2154 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2156 * method redefined from base class verifies whether given operator is valid for
2157 * this one (i.e. can be started "above" this operator). In current implementation method
2158 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2161 //================================================================================
2162 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2164 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2167 //================================================================================
2169 * \brief SLOT. Is called when the user selects a way of geometry selection
2170 * \param theByMesh - true if the user wants to find geometry by mesh element
2172 //================================================================================
2174 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2177 if ( !myShapeByMeshOp ) {
2178 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2179 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2180 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2181 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2182 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2184 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2185 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2186 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2187 SMESH::SMESH_Mesh_var aMeshVar =
2188 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2189 if ( !aMeshVar->_is_nil() ) {
2190 myDlg->hide(); // stop processing selection
2191 myShapeByMeshOp->setModule( getSMESHGUI() );
2192 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2193 myShapeByMeshOp->SetMesh( aMeshVar );
2194 myShapeByMeshOp->start();
2200 //================================================================================
2202 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2204 //================================================================================
2206 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2208 if ( myShapeByMeshOp == op ) {
2209 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2211 // Select a found geometry object
2212 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2213 if ( !aGeomVar->_is_nil() )
2215 QString ID = aGeomVar->GetStudyEntry();
2216 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2217 selectObject( aGeomSO );
2224 //================================================================================
2226 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2228 //================================================================================
2230 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2232 if ( myShapeByMeshOp == op && myDlg ) {
2237 //================================================================================
2239 * \brief Selects a SObject
2240 * \param theSObj - the SObject to select
2242 //================================================================================
2244 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2246 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2247 SALOME_ListIO anIOList;
2249 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2250 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2251 anIOList.Append( anIO );
2253 sm->setSelectedObjects( anIOList, false );