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
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 //To disable automatic genericobj management, the following line should be commented.
75 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
76 #define WITHGENERICOBJ
78 //================================================================================
81 * \param theToCreate - if this parameter is true then operation is used for creation,
82 * for editing otherwise
84 * Initialize operation
86 //================================================================================
87 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
88 : SMESHGUI_SelectionOp(),
89 myToCreate( theToCreate ),
90 myIsMesh( theIsMesh ),
95 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
96 GeometryGUI::InitGeomGen();
97 myIsOnGeometry = true;
100 //================================================================================
104 //================================================================================
105 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
111 //================================================================================
113 * \brief Gets dialog of this operation
114 * \retval LightApp_Dialog* - pointer to dialog of this operation
116 //================================================================================
117 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
122 //================================================================================
124 * \brief Creates or edits mesh
125 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
127 * Virtual slot redefined from the base class called when "Apply" button is clicked
128 * creates or edits mesh
130 //================================================================================
131 bool SMESHGUI_MeshOp::onApply()
137 if ( !isValid( aMess ) )
141 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
145 bool aResult = false;
149 if ( myToCreate && myIsMesh )
150 aResult = createMesh( aMess );
151 if ( myToCreate && !myIsMesh )
152 aResult = createSubMesh( aMess );
153 else if ( !myToCreate )
154 aResult = editMeshOrSubMesh( aMess );
157 SMESHGUI::Modified();
158 update( UF_ObjBrowser | UF_Model );
161 catch ( const SALOME::SALOME_Exception& S_ex )
163 SalomeApp_Tools::QtCatchCorbaException( S_ex );
179 aMess = tr( "SMESH_OPERATION_FAILED" );
180 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
186 //================================================================================
188 * \brief Creates dialog if necessary and shows it
190 * Virtual method redefined from base class called when operation is started creates
191 * dialog if necessary and shows it, activates selection
193 //================================================================================
194 void SMESHGUI_MeshOp::startOperation()
198 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
199 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
201 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
202 this, SLOT( onCreateHyp( const int, const int ) ) );
203 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
204 this, SLOT( onEditHyp( const int, const int ) ) );
205 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
206 this, SLOT( onAlgoSelected( const int ) ) );
208 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
209 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
212 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
213 else myHelpFileName = "constructing_submeshes_page.html";
214 else myHelpFileName = "editing_meshes_page.html";
216 SMESHGUI_SelectionOp::startOperation();
218 // iterate through dimensions and get available algoritms, set them to the dialog
219 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
220 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
222 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
224 // clear available hypotheses
225 aTab->setAvailableHyps( MainHyp, hypList );
226 aTab->setAvailableHyps( AddHyp, hypList );
227 aTab->setExistingHyps( MainHyp, hypList );
228 aTab->setExistingHyps( AddHyp, hypList );
229 myExistingHyps[ i ][ MainHyp ].clear();
230 myExistingHyps[ i ][ AddHyp ].clear();
232 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
233 aTab->setAvailableHyps( Algo, hypList );
238 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
241 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
243 myDlg->setCurrentTab( SMESH::DIM_3D );
245 myDlg->setGeomPopupEnabled(false);
248 myIgnoreAlgoSelection = false;
251 //================================================================================
253 * \brief Creates selection filter
254 * \param theId - identifier of current selection widget
255 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
257 * Creates selection filter in accordance with identifier of current selection widget
259 //================================================================================
260 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
262 if ( theId == SMESHGUI_MeshDlg::Geom )
264 // TColStd_MapOfInteger allTypesMap;
265 // for ( int i = 0; i < 10; i++ )
266 // allTypesMap.Add( i );
267 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
268 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
270 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
271 return new SMESH_TypeFilter( MESHorSUBMESH );
272 else if ( theId == SMESHGUI_MeshDlg::Mesh )
273 return new SMESH_TypeFilter( MESH );
278 //================================================================================
280 * \brief check if selected shape is a subshape of the shape to mesh
281 * \retval bool - check result
283 //================================================================================
284 bool SMESHGUI_MeshOp::isSubshapeOk() const
286 if ( !myToCreate || myIsMesh ) // not submesh creation
290 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
291 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
292 if (!pMesh) return false;
294 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
295 if (mesh->_is_nil()) return false;
297 // main shape of the mesh
298 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
299 if (mainGeom->_is_nil()) return false;
303 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
305 if (aGEOMs.count() > 0) {
306 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
307 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
308 if (geomGen->_is_nil() || !aStudy) return false;
310 GEOM::GEOM_IGroupOperations_var op =
311 geomGen->GetIGroupOperations(aStudy->StudyId());
312 if (op->_is_nil()) return false;
314 // check all selected shapes
315 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
316 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
317 QString aSubGeomEntry = (*aSubShapesIter);
318 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
319 if (!pSubGeom) return false;
321 GEOM::GEOM_Object_var aSubGeomVar =
322 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
323 if (aSubGeomVar->_is_nil()) return false;
325 // skl for NPAL14695 - implementation of searching of mainObj
326 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
327 //if (mainObj->_is_nil() ||
328 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
330 if (mainObj->_is_nil())
332 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
334 mainObj = op->GetMainShape(mainObj);
343 //================================================================================
345 * \brief Return name of the algorithm that does not support submeshes and makes
346 * submesh creation useless
347 * \retval char* - string is to be deleted!!!
349 //================================================================================
350 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
352 if ( myToCreate && !myIsMesh ) {
354 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
355 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
356 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
359 QStringList algoNames;
361 existingHyps(3, Algo, pMesh, algoNames, algoList);
362 if (!algoList.empty()) {
363 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
365 algo->InputTypes.empty() && // builds all dimensions it-self
366 !algo->IsSupportSubmeshes )
367 return CORBA::string_dup( algoNames[0].toLatin1().data() );
370 // GEOM::GEOM_Object_var geom;
371 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
372 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
374 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
375 existingHyps(2, Algo, pMesh, algoNames, algoList);
376 if (!algoList.empty()) {
377 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
379 algo->InputTypes.empty() && // builds all dimensions it-self
380 !algo->IsSupportSubmeshes )
381 return CORBA::string_dup( algoNames[0].toLatin1().data() );
389 //================================================================================
391 * \brief find an existing submesh by the selected shape
392 * \retval _PTR(SObject) - the found submesh SObject
394 //================================================================================
395 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
397 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
398 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
399 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
400 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
401 if ( pMesh && pGeom ) {
402 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
403 if ( !geom->_is_nil() ) {
405 switch ( geom->GetShapeType() ) {
406 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
407 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
408 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
409 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
410 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
411 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
412 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
415 _PTR(GenericAttribute) anAttr;
416 _PTR(SObject) aSubmeshRoot;
417 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
418 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
420 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
421 for ( ; smIter->More(); smIter->Next() )
423 _PTR(SObject) aSmObj = smIter->Value();
424 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
426 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
427 for ( ; anIter1->More(); anIter1->Next()) {
428 _PTR(SObject) pGeom2 = anIter1->Value();
429 if ( pGeom2->ReferencedObject( pGeom2 ) &&
430 pGeom2->GetID() == pGeom->GetID() )
437 return _PTR(SObject)();
440 //================================================================================
442 * \brief Updates dialog's look and feel
444 * Virtual method redefined from the base class updates dialog's look and feel
446 //================================================================================
447 void SMESHGUI_MeshOp::selectionDone()
449 if (!dlg()->isVisible() || !myDlg->isEnabled())
452 SMESHGUI_SelectionOp::selectionDone();
456 myIsOnGeometry = true;
458 //Check geometry for mesh
459 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
460 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
463 SMESH::SMESH_Mesh_var aMeshVar =
464 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
465 if (!aMeshVar->_is_nil()) {
466 if (!myToCreate && !aMeshVar->HasShapeToMesh())
467 myIsOnGeometry = false;
473 // Enable tabs according to shape dimension
478 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
479 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
481 if (aGEOMs.count() > 0) {
482 // one or more GEOM shape selected
483 aSeq->length(aGEOMs.count());
484 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
486 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
487 QString aSubGeomEntry = (*aSubShapesIter);
488 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
489 GEOM::GEOM_Object_var aSubGeomVar =
490 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
491 aSeq[iSubSh] = aSubGeomVar;
494 // get geometry by selected sub-mesh
495 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
496 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
497 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
498 if (!aGeomVar->_is_nil()) {
504 if (aSeq->length() > 0) {
506 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
507 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
508 switch ( aGeomVar->GetShapeType() ) {
509 case GEOM::SOLID: shapeDim = 3; break;
512 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
514 bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
515 shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
518 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
520 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
521 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
525 if (GEOMBase::GetShape(aGeomVar, aShape)) {
526 TopExp_Explorer exp (aShape, TopAbs_SHELL);
528 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
529 shapeDim = qMax(2, shapeDim);
530 for (; exp.More() && shapeDim == 2; exp.Next()) {
531 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
535 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
536 shapeDim = qMax(2, shapeDim);
537 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
538 shapeDim = qMax(1, shapeDim);
539 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
540 shapeDim = qMax(0, shapeDim);
546 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
547 // reset algos before disabling tabs (0020138)
548 onAlgoSelected(-1, i);
550 myDlg->setMaxHypoDim( shapeDim );
551 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
553 if (!myToCreate) // edition: read hypotheses
557 SMESH::SMESH_subMesh_var aVar =
558 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
559 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
560 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
561 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
562 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
563 myDlg->updateGeometry();
570 else if ( !myIsMesh ) // submesh creation
572 // if a submesh on the selected shape already exist, pass to submesh edition mode
573 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
574 SMESH::SMESH_subMesh_var sm =
575 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
576 bool editSubmesh = ( !sm->_is_nil() &&
577 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
578 tr( "EDIT_SUBMESH_QUESTION"),
579 SUIT_MessageBox::Yes |
581 SUIT_MessageBox::No )
582 == SUIT_MessageBox::Yes );
585 selectionMgr()->clearFilters();
586 selectObject( pSubmesh );
587 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
592 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
593 selectObject( _PTR(SObject)() );
598 // discard selected mesh if submesh creation not allowed because of
599 // a global algorithm that does not support submeshes
600 if ( char* algoName = isSubmeshIgnored() ) {
601 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
602 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
603 CORBA::string_free( algoName );
604 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
605 selectObject( _PTR(SObject)() );
610 // enable/disable popup for choice of geom selection way
612 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
613 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
614 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
615 if ( !mesh->_is_nil() ) {
616 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
617 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
618 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
619 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
620 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
621 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
624 myDlg->setGeomPopupEnabled( enable );
627 else { // no geometry defined
628 myDlg->enableTab( SMESH::DIM_3D );
630 availableHyps( SMESH::DIM_3D, Algo, hypList,
631 myAvailableHypData[SMESH::DIM_3D][Algo]);
633 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
634 aTab->setAvailableHyps( Algo, hypList );
635 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
636 myDlg->disableTab(i);
638 //Hide labels and fields (Mesh ang Geometry)
639 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
640 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
645 catch ( const SALOME::SALOME_Exception& S_ex )
647 SalomeApp_Tools::QtCatchCorbaException( S_ex );
654 //================================================================================
656 * \brief Verifies validity of input data
657 * \param theMess - Output parameter intended for returning error message
658 * \retval bool - TRUE if input data is valid, false otherwise
660 * Verifies validity of input data. This method is called when "Apply" or "OK" button
661 * is pressed before mesh creation or editing.
663 //================================================================================
664 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
666 // Selected object to be edited
667 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
669 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
674 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
675 if ( aMeshName.isEmpty() )
677 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
681 /* // Imported mesh, if create sub-mesh or edit mesh
682 if ( !myToCreate || ( myToCreate && !myIsMesh ))
684 QString aMeshEntry = myDlg->selectedObject
685 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
686 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
687 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
688 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
689 theMess = tr( "IMPORTED_MESH" );
698 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
699 if ( aGeomEntry == "" )
701 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
704 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
705 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
707 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
712 if ( !myIsMesh ) // i.e sub-mesh creation,
714 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
715 if ( aMeshEntry == "" )
717 theMess = tr( "MESH_IS_NOT_DEFINED" );
720 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
721 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
723 theMess = tr( "MESH_IS_NULL" );
726 if ( !isSubshapeOk() )
728 theMess = tr( "INVALID_SUBSHAPE" );
737 //================================================================================
739 * \brief check compatibility of the algorithm and another algorithm or hypothesis
740 * \param theAlgoData - algorithm data
741 * \param theHypData - hypothesis data
742 * \param theHypType - hypothesis type
743 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
744 * \retval bool - check result
746 //================================================================================
747 static bool isCompatible(const HypothesisData* theAlgoData,
748 const HypothesisData* theHypData,
749 const int theHypType)
754 if ( theHypType == SMESHGUI_MeshOp::Algo )
755 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
758 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
761 //================================================================================
763 * \brief Gets available hypotheses or algorithms
764 * \param theDim - specifies dimension of returned hypotheses/algorifms
765 * \param theHypType - specifies whether algorims or hypotheses or additional ones
766 * are retrieved (possible values are in HypType enumeration)
767 * \param theHyps - Output list of hypotheses' names
768 * \param theAlgoData - to select hypos able to be used by this algo (optional)
770 * Gets available hypotheses or algorithm in accordance with input parameters
772 //================================================================================
773 void SMESHGUI_MeshOp::availableHyps( const int theDim,
774 const int theHypType,
775 QStringList& theHyps,
776 THypDataList& theDataList,
777 HypothesisData* theAlgoData ) const
781 bool isAlgo = ( theHypType == Algo );
782 bool isAux = ( theHypType == AddHyp );
783 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
785 QStringList::const_iterator anIter;
786 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
788 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
789 if ( isCompatible ( theAlgoData, aData, theHypType )) {
790 theDataList.append( aData );
791 theHyps.append( aData->Label );
796 //================================================================================
798 * \brief Gets existing hypotheses or algorithms
799 * \param theDim - specifies dimension of returned hypotheses/algorifms
800 * \param theHypType - specifies whether algorims or hypotheses or additional ones
801 * are retrieved (possible values are in HypType enumeration)
802 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
803 * \param theHyps - output list of names.
804 * \param theHypVars - output list of variables.
805 * \param theAlgoData - to select hypos able to be used by this algo (optional)
807 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
810 //================================================================================
811 void SMESHGUI_MeshOp::existingHyps( const int theDim,
812 const int theHypType,
813 _PTR(SObject) theFather,
814 QStringList& theHyps,
815 THypList& theHypList,
816 HypothesisData* theAlgoData)
818 // Clear hypoheses list
825 const bool isAux = ( theHypType == AddHyp );
827 _PTR(SObject) aHypRoot;
828 _PTR(GenericAttribute) anAttr;
829 _PTR(AttributeName) aName;
830 _PTR(AttributeIOR) anIOR;
832 bool isMesh = !_CAST( SComponent, theFather );
835 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
837 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
839 if ( theFather->FindSubObject( aPart, aHypRoot ) )
841 _PTR(ChildIterator) anIter =
842 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
843 for ( ; anIter->More(); anIter->Next() )
845 _PTR(SObject) anObj = anIter->Value();
846 if ( isMesh ) // i.e. mesh or submesh
848 _PTR(SObject) aRefObj;
849 if ( anObj->ReferencedObject( aRefObj ) )
854 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
857 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
858 if ( !CORBA::is_nil( aVar ) )
860 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
861 if ( !aHypVar->_is_nil() )
863 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
864 if ( !aData) continue;
865 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
866 ( isCompatible ( theAlgoData, aData, theHypType )) &&
867 ( isAux == aData->IsAux ))
869 std::string aHypName = aName->Value();
870 theHyps.append( aHypName.c_str() );
871 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
880 //================================================================================
882 * \brief If create or edit a submesh, return a hypothesis holding parameters used
884 * \param aHypType - The hypothesis type name
885 * \param aServerLib - Server library name
886 * \param hypData - The structure holding the hypothesis type etc.
887 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
889 //================================================================================
890 SMESH::SMESH_Hypothesis_var
891 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
892 const QString& aServerLib ) const
894 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
895 return SMESH::SMESH_Hypothesis::_nil();
897 const int nbColonsInMeshEntry = 3;
898 bool isSubMesh = myToCreate ?
900 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
902 // get mesh and geom object
903 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
904 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
909 anEntry = myDlg->selectedObject
910 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
911 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
913 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
914 if ( myToCreate ) // mesh and geom may be selected
916 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
917 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
918 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
919 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
921 else // edition: sub-mesh may be selected
923 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
924 if ( !sm->_is_nil() ) {
925 aMeshVar = sm->GetFather();
926 aGeomVar = sm->GetSubShape();
933 if ( !myToCreate ) // mesh to edit can be selected
935 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
936 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
938 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
939 if ( !aMeshVar->_is_nil() )
940 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
943 if ( aGeomVar->_is_nil() ) {
944 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
945 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
947 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
952 SMESH::SMESH_Hypothesis_var hyp =
953 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
954 aServerLib.toLatin1().data(),
957 /*byMesh = */isSubMesh);
958 if ( hyp->_is_nil() && isSubMesh )
959 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
960 aServerLib.toLatin1().data(),
967 //================================================================================
969 * \Brief Returns tab dimention
970 * \param tab - the tab in the dlg
971 * \param dlg - my dialogue
972 * \retval int - dimention
974 //================================================================================
975 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
978 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
979 if (tab == dlg->tab(i))
984 //================================================================================
986 * \brief Create hypothesis
987 * \param theHypType - hypothesis category (main or additional)
988 * \param theIndex - index of type of hypothesis to be cerated
990 * Specifies dimension of hypothesis to be created (using sender() method),
991 * specifies its type and calls method for hypothesis creation
993 //================================================================================
994 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
996 // Specifies dimension of hypothesis to be created
997 int aDim = getTabDim( sender(), myDlg );
1001 // Specifies type of hypothesis to be created
1002 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1003 if (theIndex < 0 || theIndex >= dataList.count())
1005 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1007 // Create hypothesis
1008 createHypothesis(aDim, theHypType, aHypTypeName);
1013 QString GetUniqueName (const QStringList& theHypNames,
1014 const QString& theName,
1015 size_t theIteration = 1)
1017 QString aName = theName + "_" + QString::number( theIteration );
1018 if ( theHypNames.contains( aName ) )
1019 return GetUniqueName( theHypNames, theName, ++theIteration );
1024 //================================================================================
1026 * Create hypothesis and update dialog.
1027 * \param theDim - dimension of hypothesis to be created
1028 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1029 * \param theTypeName - specifies hypothesis to be created
1031 //================================================================================
1032 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1034 const QString& theTypeName)
1036 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1042 QStringList aHypNames;
1043 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1044 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1045 const TType2HypList& aType2HypList = aDimIter.value();
1046 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1047 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1048 const THypList& aHypList = aTypeIter.value();
1049 THypList::const_iterator anIter = aHypList.begin();
1050 for ( ; anIter != aHypList.end(); anIter++) {
1051 const THypItem& aHypItem = *anIter;
1052 const QString& aHypName = aHypItem.second;
1053 aHypNames.append(aHypName);
1057 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1060 bool dialog = false;
1062 QString aClientLibName = aData->ClientLibName;
1063 if (aClientLibName == "") {
1064 // Call hypothesis creation server method (without GUI)
1065 SMESH::SMESH_Hypothesis_var aHyp =
1066 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1067 #ifdef WITHGENERICOBJ
1068 if (!CORBA::is_nil(aHyp))
1072 // Get hypotheses creator client (GUI)
1074 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1075 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1077 // Create hypothesis
1079 // Get parameters appropriate to initialize a new hypothesis
1080 SMESH::SMESH_Hypothesis_var initParamHyp =
1081 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1083 removeCustomFilters(); // Issue 0020170
1085 // Get Entry of the Geom object
1086 QString aGeomEntry = "";
1087 QString aMeshEntry = "";
1088 QString anObjEntry = "";
1089 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1090 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1091 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1093 if ( myToCreate && myIsMesh )
1094 aMeshEntry = aGeomEntry;
1096 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1097 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1098 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1099 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1102 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1103 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1105 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1106 if ( !aGeomVar->_is_nil() )
1108 aGeomEntry = aGeomVar->GetStudyEntry();
1110 aMeshEntry = aGeomEntry;
1114 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1115 // take geometry from submesh being created
1116 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1118 // if current object is sub-mesh
1119 SMESH::SMESH_subMesh_var aSubMeshVar =
1120 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1121 if ( !aSubMeshVar->_is_nil() ) {
1122 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1123 if ( !aMeshVar->_is_nil() ) {
1124 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1125 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1126 if ( !aGeomVar->_is_nil() )
1127 aMeshEntry = aGeomVar->GetStudyEntry();
1133 aCreator->setShapeEntry( aGeomEntry );
1134 if ( aMeshEntry != "" )
1135 aCreator->setMainShapeEntry( aMeshEntry );
1136 myDlg->setEnabled( false );
1137 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1141 SMESH::SMESH_Hypothesis_var aHyp =
1142 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1143 #ifdef WITHGENERICOBJ
1144 if (!CORBA::is_nil(aHyp))
1154 //================================================================================
1156 * Necessary steps after hypothesis creation
1157 * \param result - creation result:
1160 * 2 = additional value meaning that slot is called not from dialog box
1162 //================================================================================
1163 void SMESHGUI_MeshOp::onHypoCreated( int result )
1167 int obj = myDlg->getActiveObject();
1168 onActivateObject( obj ); // Issue 0020170. Restore filters
1169 myDlg->setEnabled( true );
1172 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1174 int nbHyp = myExistingHyps[myDim][myType].count();
1175 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1176 QStringList aNewHyps;
1177 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1178 if (aNewHyps.count() > nbHyp)
1180 for (int i = nbHyp; i < aNewHyps.count(); i++)
1181 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1184 if( result!=2 && myHypoSet )
1188 //================================================================================
1190 * \brief Calls plugin methods for hypothesis editing
1191 * \param theHypType - specifies whether main hypothesis or additional one
1193 * \param theIndex - index of existing hypothesis
1195 * Calls plugin methods for hypothesis editing
1197 //================================================================================
1198 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1200 // Speicfies dimension of hypothesis to be created
1201 int aDim = getTabDim( sender(), myDlg );
1205 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1206 if ( theIndex < 0 || theIndex >= aList.count() )
1208 const THypItem& aHypItem = aList[ theIndex ];
1209 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1210 if ( aHyp->_is_nil() )
1213 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1216 // Get initial parameters
1217 SMESH::SMESH_Hypothesis_var initParamHyp =
1218 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1219 aCreator->setInitParamsHypothesis( initParamHyp );
1221 // Get Entry of the Geom object
1222 QString aGeomEntry = "";
1223 QString aMeshEntry = "";
1224 QString anObjEntry = "";
1225 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1226 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1227 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1229 if ( myToCreate && myIsMesh )
1230 aMeshEntry = aGeomEntry;
1232 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1233 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1234 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1235 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1238 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1239 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1241 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1242 if ( !aGeomVar->_is_nil() )
1244 aGeomEntry = aGeomVar->GetStudyEntry();
1246 aMeshEntry = aGeomEntry;
1250 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1251 // take geometry from submesh being created
1252 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1254 // if current object is sub-mesh
1255 SMESH::SMESH_subMesh_var aSubMeshVar =
1256 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1257 if ( !aSubMeshVar->_is_nil() ) {
1258 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1259 if ( !aMeshVar->_is_nil() ) {
1260 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1261 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1262 if ( !aGeomVar->_is_nil() )
1263 aMeshEntry = aGeomVar->GetStudyEntry();
1269 aCreator->setShapeEntry( aGeomEntry );
1270 if ( aMeshEntry != "" )
1271 aCreator->setMainShapeEntry( aMeshEntry );
1272 removeCustomFilters(); // Issue 0020170
1273 myDlg->setEnabled( false );
1274 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1278 //================================================================================
1280 * Necessary steps after hypothesis edition
1281 * \param result - creation result:
1285 //================================================================================
1286 void SMESHGUI_MeshOp::onHypoEdited( int result )
1288 int obj = myDlg->getActiveObject();
1289 onActivateObject( obj ); // Issue 0020170. Restore filters
1290 myDlg->setEnabled( true );
1293 //================================================================================
1295 * \brief access to hypothesis data
1296 * \param theDim - hyp dimension
1297 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1298 * \param theIndex - index in the list
1299 * \retval HypothesisData* - result data, may be 0
1301 //================================================================================
1302 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1303 const int theHypType,
1306 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1307 theHypType > -1 && theHypType < NbHypTypes &&
1308 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1309 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1313 //================================================================================
1315 * \brief Set available algos and hypos according to the selected algorithm
1316 * \param theIndex - algorithm index
1318 //================================================================================
1319 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1322 if ( myIgnoreAlgoSelection )
1325 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1329 // find highest available dimension, all algos of this dimension are available for choice
1331 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1332 if (isAccessibleDim( i ))
1337 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1339 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1340 HypothesisData* algoByDim[4];
1341 algoByDim[ aDim ] = algoData;
1343 QStringList anAvailable;
1344 if ( !algoData ) { // all algos becomes available
1345 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1346 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1349 // check that algorithms of other dimentions are compatible with
1352 // 2 loops: backward and forward from algo dimension
1353 for ( int forward = false; forward <= true; ++forward )
1355 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1357 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1359 HypothesisData* prevAlgo = algoData;
1360 bool noCompatible = false;
1361 for ( ; dim * dir <= lastDim * dir; dim += dir)
1363 if ( !isAccessibleDim( dim ))
1365 if ( noCompatible ) { // the selected algo has no compatible ones
1366 anAvailable.clear();
1367 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1368 myAvailableHypData[dim][Algo].clear();
1369 algoByDim[ dim ] = 0;
1372 // get currently selected algo
1373 int algoIndex = currentHyp( dim, Algo );
1374 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1375 if ( curAlgo ) { // some algo selected
1376 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1379 // set new available algoritms
1380 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1381 HypothesisData* soleCompatible = 0;
1382 if ( anAvailable.count() == 1 )
1383 soleCompatible = myAvailableHypData[dim][Algo][0];
1384 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1385 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1386 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1387 noCompatible = anAvailable.isEmpty();
1389 // restore previously selected algo
1390 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1391 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1392 // select the sole compatible algo
1393 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1394 setCurrentHyp( dim, Algo, algoIndex );
1396 // remember current algo
1397 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1401 // set hypotheses corresponding to the found algoritms
1403 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1405 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1407 if ( !isAccessibleDim( dim ))
1409 for ( int type = MainHyp; type < NbHypTypes; type++ )
1411 myAvailableHypData[ dim ][ type ].clear();
1412 QStringList anAvailable, anExisting;
1414 HypothesisData* curAlgo = algoByDim[ dim ];
1415 int hypIndex = currentHyp( dim, type );
1417 SMESH::SMESH_Hypothesis_var curHyp;
1418 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1419 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1421 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1422 // try to find algo by selected hypothesis in order to keep it selected
1423 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1424 CORBA::String_var curHypType = curHyp->GetName();
1425 if ( !algoDeselectedByUser &&
1426 myObjHyps[ dim ][ type ].count() > 0 &&
1427 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1429 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1430 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1431 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1432 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1439 // get hyps compatible with curAlgo
1442 // check if a selected hyp is compatible with the curAlgo
1443 if ( !curHyp->_is_nil() ) {
1444 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1445 if ( !isCompatible( curAlgo, hypData, type ))
1446 curHyp = SMESH::SMESH_Hypothesis::_nil();
1448 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1449 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1451 // set list of hypotheses
1452 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1453 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1455 // set current existing hypothesis
1456 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1457 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1460 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1461 // none is yet selected => select the sole existing if it is not optional
1462 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1463 bool isOptional = true;
1464 if ( algoByDim[ dim ] &&
1465 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1469 setCurrentHyp( dim, type, hypIndex );
1474 //================================================================================
1476 * \brief Creates and selects hypothesis of hypotheses set
1477 * \param theSetName - The name of hypotheses set
1479 //================================================================================
1480 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1482 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1487 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1488 setCurrentHyp(dim, Algo, -1);
1489 setCurrentHyp(dim, AddHyp, -1);
1490 setCurrentHyp(dim, MainHyp, -1);
1493 myHypoSet->init(true); //algorithms
1495 myHypoSet->init(false); //hypotheses
1500 //================================================================================
1502 * \brief One step of hypothesis/algorithm list creation
1504 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1506 //================================================================================
1507 void SMESHGUI_MeshOp::processSet()
1510 if( !myHypoSet->more() )
1513 bool isAlgo = myHypoSet->isAlgo();
1514 QString aHypoTypeName = myHypoSet->current();
1515 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1522 int aDim = aHypData->Dim[0];
1523 // create or/and set
1526 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1529 QStringList anAvailable;
1530 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1531 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1532 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1534 setCurrentHyp( aDim, Algo, index );
1535 onAlgoSelected( index, aDim );
1540 bool mainHyp = true;
1541 QStringList anAvailable;
1542 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1543 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1544 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1548 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1551 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1557 //================================================================================
1559 * \brief Creates mesh
1560 * \param theMess - Output parameter intended for returning error message
1561 * \retval bool - TRUE if mesh is created, FALSE otherwise
1565 //================================================================================
1566 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1570 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1571 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1574 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1575 QStringList::Iterator it = aList.begin();
1576 for ( ; it!=aList.end(); it++)
1578 QString aGeomEntry = *it;
1579 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1580 GEOM::GEOM_Object_var aGeomVar =
1581 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1583 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1584 if ( aSMESHGen->_is_nil() )
1587 SUIT_OverrideCursor aWaitCursor;
1590 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1591 if ( aMeshVar->_is_nil() )
1593 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1595 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1597 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1598 if ( !isAccessibleDim( aDim )) continue;
1600 // assign hypotheses
1601 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1602 int aHypIndex = currentHyp( aDim, aHypType );
1603 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1604 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1605 if ( !aHypVar->_is_nil() )
1606 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1609 // find or create algorithm
1610 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1611 if ( !anAlgoVar->_is_nil() )
1612 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1614 #ifdef WITHGENERICOBJ
1615 // obj has been published in study. Its refcount has been incremented.
1616 // It is safe to decrement its refcount
1617 // so that it will be destroyed when the entry in study will be removed
1619 aMeshVar->UnRegister();
1625 //================================================================================
1627 * \brief Creates sub-mesh
1628 * \param theMess - Output parameter intended for returning error message
1629 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1633 //================================================================================
1634 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1638 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1639 if ( aSMESHGen->_is_nil() )
1643 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1644 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1645 SMESH::SMESH_Mesh_var aMeshVar =
1646 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1647 if (aMeshVar->_is_nil())
1650 // GEOM shape of the main mesh
1651 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1653 // Name for the new sub-mesh
1654 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1657 GEOM::GEOM_Object_var aGeomVar;
1659 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1660 if (aGEOMs.count() == 1)
1662 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1663 QString aGeomEntry = aGEOMs.first();
1664 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1665 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1667 else if (aGEOMs.count() > 1)
1669 // create a GEOM group
1670 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1671 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1672 if (!geomGen->_is_nil() && aStudy) {
1673 GEOM::GEOM_IGroupOperations_var op =
1674 geomGen->GetIGroupOperations(aStudy->StudyId());
1675 if (!op->_is_nil()) {
1676 // check and add all selected GEOM objects: they must be
1677 // a sub-shapes of the main GEOM and must be of one type
1679 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1680 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1681 aSeq->length(aGEOMs.count());
1682 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1683 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1684 QString aSubGeomEntry = (*aSubShapesIter);
1685 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1686 GEOM::GEOM_Object_var aSubGeomVar =
1687 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1688 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1690 aGroupType = aSubShapeType;
1692 if (aSubShapeType != aGroupType)
1693 aGroupType = TopAbs_SHAPE;
1695 aSeq[iSubSh] = aSubGeomVar;
1698 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1699 op->UnionList(aGroupVar, aSeq);
1702 aGeomVar = aGroupVar;
1704 // publish the GEOM group in study
1705 QString aNewGeomGroupName ("Auto_group_for_");
1706 aNewGeomGroupName += aName;
1707 SALOMEDS::SObject_var aNewGroupSO =
1708 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1709 aNewGeomGroupName.toLatin1().data(), mainGeom);
1716 if (aGeomVar->_is_nil())
1719 SUIT_OverrideCursor aWaitCursor;
1722 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1723 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1725 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1727 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1729 if ( !isAccessibleDim( aDim )) continue;
1731 // find or create algorithm
1732 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1733 if ( !anAlgoVar->_is_nil() )
1734 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1735 // assign hypotheses
1736 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1738 int aHypIndex = currentHyp( aDim, aHypType );
1739 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1741 SMESH::SMESH_Hypothesis_var aHypVar =
1742 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1743 if ( !aHypVar->_is_nil() )
1744 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1749 // deselect geometry: next submesh should be created on other subshape
1750 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1751 selectObject( _PTR(SObject)() );
1757 //================================================================================
1759 * \brief Gets current hypothesis or algorithms
1760 * \param theDim - dimension of hypothesis or algorithm
1761 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1762 * \retval int - current hypothesis or algorithms
1764 * Gets current hypothesis or algorithms
1766 //================================================================================
1767 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1769 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1772 //================================================================================
1774 * \brief Returns true if hypotheses of given dim can be assigned
1775 * \param theDim - hypotheses dimension
1776 * \retval bool - result
1778 //================================================================================
1779 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1781 return myDlg->isTabEnabled( theDim );
1784 //================================================================================
1786 * \brief Sets current hypothesis or algorithms
1787 * \param theDim - dimension of hypothesis or algorithm
1788 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1789 * \param theIndex - Index of hypothesis
1791 * Gets current hypothesis or algorithms
1793 //================================================================================
1794 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1795 const int theHypType,
1796 const int theIndex )
1798 myIgnoreAlgoSelection = true;
1799 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1800 myIgnoreAlgoSelection = false;
1803 //================================================================================
1805 * \brief Generates default and sets mesh/submesh name
1807 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1809 //================================================================================
1810 void SMESHGUI_MeshOp::setDefaultName() const
1814 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1816 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1817 _PTR(SObject) anObj;
1820 aResName = aPrefix + QString::number( i++ );
1821 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1825 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1826 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1827 aControl->setText( aResName );
1830 //================================================================================
1832 * \brief Gets algorithm or creates it if necessary
1833 * \param theDim - specifies dimension of returned hypotheses/algorifms
1834 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1836 * Gets algorithm or creates it if necessary
1838 //================================================================================
1839 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1841 SMESH::SMESH_Hypothesis_var anAlgoVar;
1843 // get type of the selected algo
1844 int aHypIndex = currentHyp( theDim, Algo );
1845 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1846 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1848 QString aHypName = dataList[ aHypIndex ]->TypeName;
1850 // get existing algoritms
1851 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1853 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1855 // look for an existing algo of such a type
1856 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1857 THypList::iterator anIter = aHypVarList.begin();
1858 for ( ; anIter != aHypVarList.end(); anIter++)
1860 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1861 CORBA::String_var aName = aHypVar->GetName();
1862 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1864 anAlgoVar = aHypVar;
1869 if (anAlgoVar->_is_nil())
1871 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1874 QString aClientLibName = aHypData->ClientLibName;
1875 if (aClientLibName == "")
1877 // Call hypothesis creation server method (without GUI)
1878 SMESH::SMESH_Hypothesis_var aHyp =
1879 SMESH::CreateHypothesis(aHypName, aHypName, true);
1880 #ifdef WITHGENERICOBJ
1881 if (!CORBA::is_nil(aHyp))
1887 // Get hypotheses creator client (GUI)
1889 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1893 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1895 SMESH::SMESH_Hypothesis_var aHyp =
1896 SMESH::CreateHypothesis(aHypName, aHypName, true);
1897 #ifdef WITHGENERICOBJ
1898 if (!CORBA::is_nil(aHyp))
1903 QStringList tmpList;
1904 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1905 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1908 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1909 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1911 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1912 CORBA::String_var aName = aHypVar->GetName();
1913 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1915 anAlgoVar = aHypVar;
1921 return anAlgoVar._retn();
1924 //================================================================================
1926 * \brief Reads parameters of edited mesh and assigns them to the dialog
1928 * Reads parameters of edited mesh and assigns them to the dialog (called when
1929 * mesh is edited only)
1931 //================================================================================
1932 void SMESHGUI_MeshOp::readMesh()
1934 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1935 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1939 if (myIsOnGeometry) {
1940 // Get name of mesh if current object is sub-mesh
1941 SMESH::SMESH_subMesh_var aSubMeshVar =
1942 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1943 if ( !aSubMeshVar->_is_nil() )
1945 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1946 if ( !aMeshVar->_is_nil() )
1948 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1949 QString aMeshName = name( aMeshSO );
1950 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1954 // Get name of geometry object
1955 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1956 if ( !aGeomVar->_is_nil() )
1958 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1959 QString aShapeName = name( aGeomSO );
1960 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1964 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1965 QStringList anExisting;
1966 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1967 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1970 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1971 // find algo index among available ones
1973 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1975 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1976 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1977 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1978 // if ( aHypIndex < 0 && algoData ) {
1979 // // assigned algo is incompatible with other algorithms
1980 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1981 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1984 setCurrentHyp( dim, Algo, aHypIndex );
1985 // set existing and available hypothesis according to the selected algo
1986 onAlgoSelected( aHypIndex, dim );
1990 bool hypWithoutAlgo = false;
1991 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1993 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1996 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1997 // find index of requered hypothesis among existing ones for this dimension and type
1999 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2000 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2001 myExistingHyps[ dim ][ hypType ] );
2002 if ( aHypIndex < 0 ) {
2003 // assigned hypothesis is incompatible with the algorithm
2004 if ( currentHyp( dim, Algo ) < 0 )
2005 { // none algo selected; it is edition for sure, of submesh maybe
2006 hypWithoutAlgo = true;
2007 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2008 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2009 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2013 setCurrentHyp( dim, hypType, aHypIndex );
2016 // make available other hyps of same type as one without algo
2017 if ( hypWithoutAlgo )
2018 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2021 //================================================================================
2023 * \brief Gets name of object
2024 * \param theSO - SObject
2025 * \retval QString - name of object
2027 * Gets name of object
2029 //================================================================================
2030 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2035 _PTR(GenericAttribute) anAttr;
2036 _PTR(AttributeName) aNameAttr;
2037 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2040 aResName = aNameAttr->Value().c_str();
2046 //================================================================================
2048 * \brief Finds hypothesis in input list
2049 * \param theHyp - hypothesis to be found
2050 * \param theHypList - input list of hypotheses
2051 * \retval int - index of hypothesis or -1 if it is not found
2053 * Finds position of hypothesis in input list
2055 //================================================================================
2056 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2057 const THypList& theHypList ) const
2060 if ( !theHyp->_is_nil() )
2063 THypList::const_iterator anIter = theHypList.begin();
2064 for ( ; anIter != theHypList.end(); ++ anIter)
2066 if ( theHyp->_is_equivalent( (*anIter).first ) )
2077 //================================================================================
2079 * \brief Edits mesh or sub-mesh
2080 * \param theMess - Output parameter intended for returning error message
2081 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2083 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2085 //================================================================================
2086 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2090 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2091 if ( aSMESHGen->_is_nil() )
2094 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2095 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2099 SUIT_OverrideCursor aWaitCursor;
2102 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2103 SMESH::SetName( pObj, aName );
2104 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2106 // First, remove old algos in order to avoid messages on algorithm hiding
2107 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2109 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2111 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2112 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2113 if ( anAlgoVar->_is_nil() || // no new algo selected or
2114 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2116 // remove old algorithm
2117 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2118 myObjHyps[ dim ][ Algo ].clear();
2123 // Assign new algorithms and hypotheses
2124 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2126 if ( !isAccessibleDim( dim )) continue;
2128 // find or create algorithm
2129 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2131 // assign new algorithm
2132 if ( !anAlgoVar->_is_nil() && // some algo selected and
2133 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2135 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2136 CORBA::Object_var anObject = aSObject->GetObject();
2137 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2138 bool isMesh = !aMeshVar->_is_nil();
2140 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2142 SMESH::SMESH_subMesh_var aVar =
2143 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2144 if ( !aVar->_is_nil() )
2145 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2147 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2150 // assign hypotheses
2151 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2153 int aNewHypIndex = currentHyp( dim, hypType );
2154 int anOldHypIndex = -1;
2156 // remove old hypotheses
2157 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2159 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2160 myExistingHyps[ dim ][ hypType ] );
2161 if ( aNewHypIndex != anOldHypIndex || // different hyps
2162 anOldHypIndex == -1 ) // hyps of different algos
2164 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2165 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2166 myObjHyps[ dim ][ hypType ].clear();
2170 // assign new hypotheses
2171 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2173 SMESH::SMESH_Mesh_var aMeshVar =
2174 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2175 bool isMesh = !aMeshVar->_is_nil();
2178 SMESH::AddHypothesisOnMesh
2179 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2183 SMESH::SMESH_subMesh_var aVar =
2184 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2185 if ( !aVar->_is_nil() )
2186 SMESH::AddHypothesisOnSubMesh
2187 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2190 // reread all hypotheses of mesh if necessary
2191 QStringList anExisting;
2192 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2199 //================================================================================
2201 * \brief Verifies whether given operator is valid for this one
2202 * \param theOtherOp - other operation
2203 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2205 * method redefined from base class verifies whether given operator is valid for
2206 * this one (i.e. can be started "above" this operator). In current implementation method
2207 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2210 //================================================================================
2211 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2213 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2216 //================================================================================
2218 * \brief SLOT. Is called when the user selects a way of geometry selection
2219 * \param theByMesh - true if the user wants to find geometry by mesh element
2221 //================================================================================
2222 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2225 if ( !myShapeByMeshOp ) {
2226 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2227 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2228 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2229 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2230 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2232 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2233 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2234 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2235 SMESH::SMESH_Mesh_var aMeshVar =
2236 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2237 if ( !aMeshVar->_is_nil() ) {
2238 myDlg->hide(); // stop processing selection
2239 myShapeByMeshOp->setModule( getSMESHGUI() );
2240 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2241 myShapeByMeshOp->SetMesh( aMeshVar );
2242 myShapeByMeshOp->start();
2248 //================================================================================
2250 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2252 //================================================================================
2253 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2255 if ( myShapeByMeshOp == op ) {
2256 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2258 // Select a found geometry object
2259 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2260 if ( !aGeomVar->_is_nil() )
2262 QString ID = aGeomVar->GetStudyEntry();
2263 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2264 selectObject( aGeomSO );
2271 //================================================================================
2273 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2275 //================================================================================
2276 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2278 if ( myShapeByMeshOp == op && myDlg ) {
2283 //================================================================================
2285 * \brief Selects a SObject
2286 * \param theSObj - the SObject to select
2288 //================================================================================
2289 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2291 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2292 SALOME_ListIO anIOList;
2294 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2295 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2296 anIOList.Append( anIO );
2298 sm->setSelectedObjects( anIOList, false );