1 // Copyright (C) 2007-2011 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 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_MeshDlg.h"
30 #include "SMESHGUI_ShapeByMeshDlg.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_NumberFilter.hxx>
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
42 #include <GeometryGUI.h>
44 // SALOME GUI includes
45 #include <SalomeApp_Tools.h>
46 #include <SalomeApp_Application.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SUIT_Session.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 //To disable automatic genericobj management, the following line should be commented.
76 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
77 #define WITHGENERICOBJ
79 //================================================================================
82 * \param theToCreate - if this parameter is true then operation is used for creation,
83 * for editing otherwise
85 * Initialize operation
87 //================================================================================
88 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
89 : SMESHGUI_SelectionOp(),
90 myToCreate( theToCreate ),
91 myIsMesh( theIsMesh ),
96 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
97 GeometryGUI::InitGeomGen();
98 myIsOnGeometry = true;
101 //================================================================================
105 //================================================================================
106 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
112 //================================================================================
114 * \brief Gets dialog of this operation
115 * \retval LightApp_Dialog* - pointer to dialog of this operation
117 //================================================================================
118 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
123 //================================================================================
125 * \brief Creates or edits mesh
126 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
128 * Virtual slot redefined from the base class called when "Apply" button is clicked
129 * creates or edits mesh
131 //================================================================================
132 bool SMESHGUI_MeshOp::onApply()
138 if ( !isValid( aMess ) )
142 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
146 bool aResult = false;
150 QStringList anEntryList;
151 if ( myToCreate && myIsMesh )
152 aResult = createMesh( aMess, anEntryList );
153 if ( myToCreate && !myIsMesh )
154 aResult = createSubMesh( aMess, anEntryList );
155 else if ( !myToCreate )
156 aResult = editMeshOrSubMesh( aMess );
159 SMESHGUI::Modified();
160 update( UF_ObjBrowser | UF_Model );
161 if( LightApp_Application* anApp =
162 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
163 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
166 catch ( const SALOME::SALOME_Exception& S_ex )
168 SalomeApp_Tools::QtCatchCorbaException( S_ex );
184 aMess = tr( "SMESH_OPERATION_FAILED" );
185 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
191 //================================================================================
193 * \brief Creates dialog if necessary and shows it
195 * Virtual method redefined from base class called when operation is started creates
196 * dialog if necessary and shows it, activates selection
198 //================================================================================
199 void SMESHGUI_MeshOp::startOperation()
203 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
204 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
206 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
207 this, SLOT( onCreateHyp( const int, const int ) ) );
208 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
209 this, SLOT( onEditHyp( const int, const int ) ) );
210 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
211 this, SLOT( onAlgoSelected( const int ) ) );
213 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
214 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
218 else myHelpFileName = "constructing_submeshes_page.html";
219 else myHelpFileName = "editing_meshes_page.html";
221 SMESHGUI_SelectionOp::startOperation();
223 // iterate through dimensions and get available algoritms, set them to the dialog
224 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
225 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
227 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
229 // clear available hypotheses
230 aTab->setAvailableHyps( MainHyp, hypList );
231 aTab->setAvailableHyps( AddHyp, hypList );
232 aTab->setExistingHyps( MainHyp, hypList );
233 aTab->setExistingHyps( AddHyp, hypList );
234 myExistingHyps[ i ][ MainHyp ].clear();
235 myExistingHyps[ i ][ AddHyp ].clear();
237 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
238 aTab->setAvailableHyps( Algo, hypList );
243 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
246 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
248 myDlg->setCurrentTab( SMESH::DIM_3D );
250 myDlg->setGeomPopupEnabled(false);
253 myIgnoreAlgoSelection = false;
255 myObjectToSelect.clear();
258 //=================================================================================
260 * \brief Selects a recently created mesh or sub-mesh if necessary
262 * Virtual method redefined from base class called when operation is commited
263 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
264 * selection when the custom selection filters are removed.
266 //=================================================================================
267 void SMESHGUI_MeshOp::commitOperation()
269 SMESHGUI_SelectionOp::commitOperation();
271 if ( !myObjectToSelect.isEmpty() ) {
272 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
273 SUIT_DataOwnerPtrList aList;
274 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
275 aSelectionMgr->setSelected( aList );
280 //================================================================================
282 * \brief Creates selection filter
283 * \param theId - identifier of current selection widget
284 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
286 * Creates selection filter in accordance with identifier of current selection widget
288 //================================================================================
289 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
291 if ( theId == SMESHGUI_MeshDlg::Geom )
293 // TColStd_MapOfInteger allTypesMap;
294 // for ( int i = 0; i < 10; i++ )
295 // allTypesMap.Add( i );
296 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
297 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
299 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
300 return new SMESH_TypeFilter( MESHorSUBMESH );
301 else if ( theId == SMESHGUI_MeshDlg::Mesh )
302 return new SMESH_TypeFilter( MESH );
307 //================================================================================
309 * \brief check if selected shape is a subshape of the shape to mesh
310 * \retval bool - check result
312 //================================================================================
313 bool SMESHGUI_MeshOp::isSubshapeOk() const
315 if ( !myToCreate || myIsMesh ) // not submesh creation
319 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
320 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
321 if (!pMesh) return false;
323 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
324 if (mesh->_is_nil()) return false;
326 // main shape of the mesh
327 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
328 if (mainGeom->_is_nil()) return false;
332 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
334 if (aGEOMs.count() > 0) {
335 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
336 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
337 if (geomGen->_is_nil() || !aStudy) return false;
339 GEOM::GEOM_IGroupOperations_var op =
340 geomGen->GetIGroupOperations(aStudy->StudyId());
341 if (op->_is_nil()) return false;
343 // check all selected shapes
344 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
345 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
346 QString aSubGeomEntry = (*aSubShapesIter);
347 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
348 if (!pSubGeom) return false;
350 GEOM::GEOM_Object_var aSubGeomVar =
351 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
352 if (aSubGeomVar->_is_nil()) return false;
354 // skl for NPAL14695 - implementation of searching of mainObj
355 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
356 //if (mainObj->_is_nil() ||
357 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
359 if (mainObj->_is_nil())
361 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
363 mainObj = op->GetMainShape(mainObj);
372 //================================================================================
374 * \brief Return name of the algorithm that does not support submeshes and makes
375 * submesh creation useless
376 * \retval char* - string is to be deleted!!!
378 //================================================================================
379 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
381 if ( myToCreate && !myIsMesh ) {
383 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
384 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
385 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
388 QStringList algoNames;
390 existingHyps(3, Algo, pMesh, algoNames, algoList);
391 if (!algoList.empty()) {
392 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
394 algo->InputTypes.empty() && // builds all dimensions it-self
395 !algo->IsSupportSubmeshes )
396 return CORBA::string_dup( algoNames[0].toLatin1().data() );
399 // GEOM::GEOM_Object_var geom;
400 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
401 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
403 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
404 existingHyps(2, Algo, pMesh, algoNames, algoList);
405 if (!algoList.empty()) {
406 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
408 algo->InputTypes.empty() && // builds all dimensions it-self
409 !algo->IsSupportSubmeshes )
410 return CORBA::string_dup( algoNames[0].toLatin1().data() );
418 //================================================================================
420 * \brief find an existing submesh by the selected shape
421 * \retval _PTR(SObject) - the found submesh SObject
423 //================================================================================
424 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
426 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
427 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
428 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
429 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
430 if ( pMesh && pGeom ) {
431 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
432 if ( !geom->_is_nil() ) {
434 switch ( geom->GetShapeType() ) {
435 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
436 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
437 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
438 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
439 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
440 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
441 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
444 _PTR(GenericAttribute) anAttr;
445 _PTR(SObject) aSubmeshRoot;
446 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
447 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
449 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
450 for ( ; smIter->More(); smIter->Next() )
452 _PTR(SObject) aSmObj = smIter->Value();
453 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
455 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
456 for ( ; anIter1->More(); anIter1->Next()) {
457 _PTR(SObject) pGeom2 = anIter1->Value();
458 if ( pGeom2->ReferencedObject( pGeom2 ) &&
459 pGeom2->GetID() == pGeom->GetID() )
466 return _PTR(SObject)();
469 //================================================================================
471 * \brief Updates dialog's look and feel
473 * Virtual method redefined from the base class updates dialog's look and feel
475 //================================================================================
476 void SMESHGUI_MeshOp::selectionDone()
478 if (!dlg()->isVisible() || !myDlg->isEnabled())
481 SMESHGUI_SelectionOp::selectionDone();
485 myIsOnGeometry = true;
487 //Check geometry for mesh
488 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
489 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
492 SMESH::SMESH_Mesh_var aMeshVar =
493 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
494 if (!aMeshVar->_is_nil()) {
495 if (!myToCreate && !aMeshVar->HasShapeToMesh())
496 myIsOnGeometry = false;
502 // Enable tabs according to shape dimension
507 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
508 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
510 if (aGEOMs.count() > 0) {
511 // one or more GEOM shape selected
512 aSeq->length(aGEOMs.count());
513 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
515 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
516 QString aSubGeomEntry = (*aSubShapesIter);
517 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
518 GEOM::GEOM_Object_var aSubGeomVar =
519 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
520 aSeq[iSubSh] = aSubGeomVar;
523 // get geometry by selected sub-mesh
524 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
525 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
526 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
527 if (!aGeomVar->_is_nil()) {
533 if (aSeq->length() > 0) {
535 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
536 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
537 switch ( aGeomVar->GetShapeType() ) {
538 case GEOM::SOLID: shapeDim = 3; break;
540 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
542 // TopoDS_Shape aShape;
543 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
544 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
547 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
549 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
550 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
554 if (GEOMBase::GetShape(aGeomVar, aShape))
556 TopExp_Explorer exp (aShape, TopAbs_SOLID);
560 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
561 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
564 // for (; exp.More() && shapeDim == 2; exp.Next()) {
565 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
569 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
570 shapeDim = qMax(2, shapeDim);
571 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
572 shapeDim = qMax(1, shapeDim);
573 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
574 shapeDim = qMax(0, shapeDim);
582 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
583 // reset algos before disabling tabs (0020138)
584 onAlgoSelected(-1, i);
586 myDlg->setMaxHypoDim( shapeDim );
587 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
589 if (!myToCreate) // edition: read hypotheses
593 SMESH::SMESH_subMesh_var aVar =
594 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
595 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
596 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
597 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
598 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
599 myDlg->updateGeometry();
606 else if ( !myIsMesh ) // submesh creation
608 // if a submesh on the selected shape already exist, pass to submesh edition mode
609 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
610 SMESH::SMESH_subMesh_var sm =
611 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
612 bool editSubmesh = ( !sm->_is_nil() &&
613 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
614 tr( "EDIT_SUBMESH_QUESTION"),
615 SUIT_MessageBox::Yes |
617 SUIT_MessageBox::No )
618 == SUIT_MessageBox::Yes );
621 selectionMgr()->clearFilters();
622 selectObject( pSubmesh );
623 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
628 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
629 selectObject( _PTR(SObject)() );
634 // discard selected mesh if submesh creation not allowed because of
635 // a global algorithm that does not support submeshes
636 if ( char* algoName = isSubmeshIgnored() ) {
637 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
638 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
639 CORBA::string_free( algoName );
640 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
641 selectObject( _PTR(SObject)() );
646 // enable/disable popup for choice of geom selection way
648 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
649 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
650 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
651 if ( !mesh->_is_nil() ) {
652 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
653 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
654 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
655 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
656 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
657 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
660 myDlg->setGeomPopupEnabled( enable );
663 else { // no geometry defined
664 myDlg->enableTab( SMESH::DIM_3D );
666 availableHyps( SMESH::DIM_3D, Algo, hypList,
667 myAvailableHypData[SMESH::DIM_3D][Algo]);
669 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
670 aTab->setAvailableHyps( Algo, hypList );
671 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
672 myDlg->disableTab(i);
674 //Hide labels and fields (Mesh ang Geometry)
675 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
676 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
681 catch ( const SALOME::SALOME_Exception& S_ex )
683 SalomeApp_Tools::QtCatchCorbaException( S_ex );
690 //================================================================================
692 * \brief Verifies validity of input data
693 * \param theMess - Output parameter intended for returning error message
694 * \retval bool - TRUE if input data is valid, false otherwise
696 * Verifies validity of input data. This method is called when "Apply" or "OK" button
697 * is pressed before mesh creation or editing.
699 //================================================================================
700 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
702 // Selected object to be edited
703 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
705 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
710 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
711 if ( aMeshName.isEmpty() )
713 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
717 /* // Imported mesh, if create sub-mesh or edit mesh
718 if ( !myToCreate || ( myToCreate && !myIsMesh ))
720 QString aMeshEntry = myDlg->selectedObject
721 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
722 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
723 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
724 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
725 theMess = tr( "IMPORTED_MESH" );
734 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
735 if ( aGeomEntry == "" )
737 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
740 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
741 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
743 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
748 if ( !myIsMesh ) // i.e sub-mesh creation,
750 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
751 if ( aMeshEntry == "" )
753 theMess = tr( "MESH_IS_NOT_DEFINED" );
756 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
757 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
759 theMess = tr( "MESH_IS_NULL" );
762 if ( !isSubshapeOk() )
764 theMess = tr( "INVALID_SUBSHAPE" );
773 //================================================================================
775 * \brief check compatibility of the algorithm and another algorithm or hypothesis
776 * \param theAlgoData - algorithm data
777 * \param theHypData - hypothesis data
778 * \param theHypType - hypothesis type
779 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
780 * \retval bool - check result
782 //================================================================================
783 static bool isCompatible(const HypothesisData* theAlgoData,
784 const HypothesisData* theHypData,
785 const int theHypType)
790 if ( theHypType == SMESHGUI_MeshOp::Algo )
791 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
794 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
797 //================================================================================
799 * \brief Gets available hypotheses or algorithms
800 * \param theDim - specifies dimension of returned hypotheses/algorifms
801 * \param theHypType - specifies whether algorims or hypotheses or additional ones
802 * are retrieved (possible values are in HypType enumeration)
803 * \param theHyps - Output list of hypotheses' names
804 * \param theAlgoData - to select hypos able to be used by this algo (optional)
806 * Gets available hypotheses or algorithm in accordance with input parameters
808 //================================================================================
809 void SMESHGUI_MeshOp::availableHyps( const int theDim,
810 const int theHypType,
811 QStringList& theHyps,
812 THypDataList& theDataList,
813 HypothesisData* theAlgoData ) const
817 bool isAlgo = ( theHypType == Algo );
818 bool isAux = ( theHypType == AddHyp );
819 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
821 QStringList::const_iterator anIter;
822 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
824 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
825 if ( isCompatible ( theAlgoData, aData, theHypType )) {
826 theDataList.append( aData );
827 theHyps.append( aData->Label );
832 //================================================================================
834 * \brief Gets existing hypotheses or algorithms
835 * \param theDim - specifies dimension of returned hypotheses/algorifms
836 * \param theHypType - specifies whether algorims or hypotheses or additional ones
837 * are retrieved (possible values are in HypType enumeration)
838 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
839 * \param theHyps - output list of names.
840 * \param theHypVars - output list of variables.
841 * \param theAlgoData - to select hypos able to be used by this algo (optional)
843 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
846 //================================================================================
847 void SMESHGUI_MeshOp::existingHyps( const int theDim,
848 const int theHypType,
849 _PTR(SObject) theFather,
850 QStringList& theHyps,
851 THypList& theHypList,
852 HypothesisData* theAlgoData)
854 // Clear hypoheses list
861 const bool isAux = ( theHypType == AddHyp );
863 _PTR(SObject) aHypRoot;
864 _PTR(GenericAttribute) anAttr;
865 _PTR(AttributeName) aName;
866 _PTR(AttributeIOR) anIOR;
868 bool isMesh = !_CAST( SComponent, theFather );
871 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
873 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
875 if ( theFather->FindSubObject( aPart, aHypRoot ) )
877 _PTR(ChildIterator) anIter =
878 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
879 for ( ; anIter->More(); anIter->Next() )
881 _PTR(SObject) anObj = anIter->Value();
882 if ( isMesh ) // i.e. mesh or submesh
884 _PTR(SObject) aRefObj;
885 if ( anObj->ReferencedObject( aRefObj ) )
890 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
893 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
894 if ( !CORBA::is_nil( aVar ) )
896 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
897 if ( !aHypVar->_is_nil() )
899 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
900 if ( !aData) continue;
901 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
902 ( isCompatible ( theAlgoData, aData, theHypType )) &&
903 ( isAux == aData->IsAux ))
905 std::string aHypName = aName->Value();
906 theHyps.append( aHypName.c_str() );
907 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
916 //================================================================================
918 * \brief If create or edit a submesh, return a hypothesis holding parameters used
920 * \param aHypType - The hypothesis type name
921 * \param aServerLib - Server library name
922 * \param hypData - The structure holding the hypothesis type etc.
923 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
925 //================================================================================
926 SMESH::SMESH_Hypothesis_var
927 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
928 const QString& aServerLib ) const
930 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
931 return SMESH::SMESH_Hypothesis::_nil();
933 const int nbColonsInMeshEntry = 3;
934 bool isSubMesh = myToCreate ?
936 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
938 // get mesh and geom object
939 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
940 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
945 anEntry = myDlg->selectedObject
946 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
947 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
949 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
950 if ( myToCreate ) // mesh and geom may be selected
952 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
953 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
954 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
955 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
957 else // edition: sub-mesh may be selected
959 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
960 if ( !sm->_is_nil() ) {
961 aMeshVar = sm->GetFather();
962 aGeomVar = sm->GetSubShape();
969 if ( !myToCreate ) // mesh to edit can be selected
971 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
972 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
974 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
975 if ( !aMeshVar->_is_nil() )
976 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
979 if ( aGeomVar->_is_nil() ) {
980 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
981 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
983 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
988 SMESH::SMESH_Hypothesis_var hyp =
989 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
990 aServerLib.toLatin1().data(),
993 /*byMesh = */isSubMesh);
994 if ( hyp->_is_nil() && isSubMesh )
995 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
996 aServerLib.toLatin1().data(),
1003 //================================================================================
1005 * \Brief Returns tab dimention
1006 * \param tab - the tab in the dlg
1007 * \param dlg - my dialogue
1008 * \retval int - dimention
1010 //================================================================================
1011 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1014 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1015 if (tab == dlg->tab(i))
1020 //================================================================================
1022 * \brief Create hypothesis
1023 * \param theHypType - hypothesis category (main or additional)
1024 * \param theIndex - index of type of hypothesis to be cerated
1026 * Specifies dimension of hypothesis to be created (using sender() method),
1027 * specifies its type and calls method for hypothesis creation
1029 //================================================================================
1030 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1032 // Specifies dimension of hypothesis to be created
1033 int aDim = getTabDim( sender(), myDlg );
1037 // Specifies type of hypothesis to be created
1038 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1039 if (theIndex < 0 || theIndex >= dataList.count())
1041 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1043 // Create hypothesis
1044 createHypothesis(aDim, theHypType, aHypTypeName);
1049 QString GetUniqueName (const QStringList& theHypNames,
1050 const QString& theName,
1051 size_t theIteration = 1)
1053 QString aName = theName + "_" + QString::number( theIteration );
1054 if ( theHypNames.contains( aName ) )
1055 return GetUniqueName( theHypNames, theName, ++theIteration );
1060 //================================================================================
1062 * Create hypothesis and update dialog.
1063 * \param theDim - dimension of hypothesis to be created
1064 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1065 * \param theTypeName - specifies hypothesis to be created
1067 //================================================================================
1068 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1070 const QString& theTypeName)
1072 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1078 QStringList aHypNames;
1079 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1080 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1081 const TType2HypList& aType2HypList = aDimIter.value();
1082 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1083 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1084 const THypList& aHypList = aTypeIter.value();
1085 THypList::const_iterator anIter = aHypList.begin();
1086 for ( ; anIter != aHypList.end(); anIter++) {
1087 const THypItem& aHypItem = *anIter;
1088 const QString& aHypName = aHypItem.second;
1089 aHypNames.append(aHypName);
1093 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1096 bool dialog = false;
1098 QString aClientLibName = aData->ClientLibName;
1099 if (aClientLibName == "") {
1100 // Call hypothesis creation server method (without GUI)
1101 SMESH::SMESH_Hypothesis_var aHyp =
1102 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1103 #ifdef WITHGENERICOBJ
1104 if (!CORBA::is_nil(aHyp))
1108 // Get hypotheses creator client (GUI)
1110 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1111 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1113 // Create hypothesis
1115 // Get parameters appropriate to initialize a new hypothesis
1116 SMESH::SMESH_Hypothesis_var initParamHyp =
1117 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1119 removeCustomFilters(); // Issue 0020170
1121 // Get Entry of the Geom object
1122 QString aGeomEntry = "";
1123 QString aMeshEntry = "";
1124 QString anObjEntry = "";
1125 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1126 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1127 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1129 if ( myToCreate && myIsMesh )
1130 aMeshEntry = aGeomEntry;
1132 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1133 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1134 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1135 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1138 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1139 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1141 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1142 if ( !aGeomVar->_is_nil() )
1144 aGeomEntry = aGeomVar->GetStudyEntry();
1146 aMeshEntry = aGeomEntry;
1150 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1151 // take geometry from submesh being created
1152 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1154 // if current object is sub-mesh
1155 SMESH::SMESH_subMesh_var aSubMeshVar =
1156 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1157 if ( !aSubMeshVar->_is_nil() ) {
1158 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1159 if ( !aMeshVar->_is_nil() ) {
1160 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1161 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1162 if ( !aGeomVar->_is_nil() )
1163 aMeshEntry = aGeomVar->GetStudyEntry();
1169 aCreator->setShapeEntry( aGeomEntry );
1170 if ( aMeshEntry != "" )
1171 aCreator->setMainShapeEntry( aMeshEntry );
1172 myDlg->setEnabled( false );
1173 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1177 SMESH::SMESH_Hypothesis_var aHyp =
1178 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1179 #ifdef WITHGENERICOBJ
1180 if (!CORBA::is_nil(aHyp))
1190 //================================================================================
1192 * Necessary steps after hypothesis creation
1193 * \param result - creation result:
1196 * 2 = additional value meaning that slot is called not from dialog box
1198 //================================================================================
1199 void SMESHGUI_MeshOp::onHypoCreated( int result )
1203 int obj = myDlg->getActiveObject();
1204 onActivateObject( obj ); // Issue 0020170. Restore filters
1205 myDlg->setEnabled( true );
1208 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1210 int nbHyp = myExistingHyps[myDim][myType].count();
1211 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1212 QStringList aNewHyps;
1213 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1214 if (aNewHyps.count() > nbHyp)
1216 for (int i = nbHyp; i < aNewHyps.count(); i++)
1217 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1220 if( result!=2 && myHypoSet )
1224 //================================================================================
1226 * \brief Calls plugin methods for hypothesis editing
1227 * \param theHypType - specifies whether main hypothesis or additional one
1229 * \param theIndex - index of existing hypothesis
1231 * Calls plugin methods for hypothesis editing
1233 //================================================================================
1234 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1236 // Speicfies dimension of hypothesis to be created
1237 int aDim = getTabDim( sender(), myDlg );
1241 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1242 if ( theIndex < 0 || theIndex >= aList.count() )
1244 const THypItem& aHypItem = aList[ theIndex ];
1245 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1246 if ( aHyp->_is_nil() )
1249 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1252 // Get initial parameters
1253 SMESH::SMESH_Hypothesis_var initParamHyp =
1254 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1255 aCreator->setInitParamsHypothesis( initParamHyp );
1257 // Get Entry of the Geom object
1258 QString aGeomEntry = "";
1259 QString aMeshEntry = "";
1260 QString anObjEntry = "";
1261 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1262 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1263 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1265 if ( myToCreate && myIsMesh )
1266 aMeshEntry = aGeomEntry;
1268 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1269 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1270 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1271 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1274 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1275 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1277 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1278 if ( !aGeomVar->_is_nil() )
1280 aGeomEntry = aGeomVar->GetStudyEntry();
1282 aMeshEntry = aGeomEntry;
1286 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1287 // take geometry from submesh being created
1288 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1290 // if current object is sub-mesh
1291 SMESH::SMESH_subMesh_var aSubMeshVar =
1292 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1293 if ( !aSubMeshVar->_is_nil() ) {
1294 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1295 if ( !aMeshVar->_is_nil() ) {
1296 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1297 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1298 if ( !aGeomVar->_is_nil() )
1299 aMeshEntry = aGeomVar->GetStudyEntry();
1305 aCreator->setShapeEntry( aGeomEntry );
1306 if ( aMeshEntry != "" )
1307 aCreator->setMainShapeEntry( aMeshEntry );
1308 removeCustomFilters(); // Issue 0020170
1309 myDlg->setEnabled( false );
1310 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1314 //================================================================================
1316 * Necessary steps after hypothesis edition
1317 * \param result - creation result:
1321 //================================================================================
1322 void SMESHGUI_MeshOp::onHypoEdited( int result )
1324 int obj = myDlg->getActiveObject();
1325 onActivateObject( obj ); // Issue 0020170. Restore filters
1326 myDlg->setEnabled( true );
1329 //================================================================================
1331 * \brief access to hypothesis data
1332 * \param theDim - hyp dimension
1333 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1334 * \param theIndex - index in the list
1335 * \retval HypothesisData* - result data, may be 0
1337 //================================================================================
1338 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1339 const int theHypType,
1342 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1343 theHypType > -1 && theHypType < NbHypTypes &&
1344 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1345 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1349 //================================================================================
1351 * \brief Set available algos and hypos according to the selected algorithm
1352 * \param theIndex - algorithm index
1354 //================================================================================
1355 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1358 if ( myIgnoreAlgoSelection )
1361 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1365 // find highest available dimension, all algos of this dimension are available for choice
1367 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1368 if (isAccessibleDim( i ))
1373 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1375 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1376 HypothesisData* algoByDim[4];
1377 algoByDim[ aDim ] = algoData;
1379 QStringList anAvailable;
1380 if ( !algoData ) { // all algos becomes available
1381 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1382 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1385 // check that algorithms of other dimentions are compatible with
1388 // 2 loops: backward and forward from algo dimension
1389 for ( int forward = false; forward <= true; ++forward )
1391 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1393 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1395 HypothesisData* prevAlgo = algoData;
1396 bool noCompatible = false;
1397 for ( ; dim * dir <= lastDim * dir; dim += dir)
1399 if ( !isAccessibleDim( dim ))
1401 if ( noCompatible ) { // the selected algo has no compatible ones
1402 anAvailable.clear();
1403 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1404 myAvailableHypData[dim][Algo].clear();
1405 algoByDim[ dim ] = 0;
1408 // get currently selected algo
1409 int algoIndex = currentHyp( dim, Algo );
1410 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1411 if ( curAlgo ) { // some algo selected
1412 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1415 // set new available algoritms
1416 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1417 HypothesisData* soleCompatible = 0;
1418 if ( anAvailable.count() == 1 )
1419 soleCompatible = myAvailableHypData[dim][Algo][0];
1420 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1421 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1422 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1423 noCompatible = anAvailable.isEmpty();
1425 // restore previously selected algo
1426 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1427 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1428 // select the sole compatible algo
1429 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1430 setCurrentHyp( dim, Algo, algoIndex );
1432 // remember current algo
1433 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1437 // set hypotheses corresponding to the found algoritms
1439 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1441 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1443 if ( !isAccessibleDim( dim ))
1445 for ( int type = MainHyp; type < NbHypTypes; type++ )
1447 myAvailableHypData[ dim ][ type ].clear();
1448 QStringList anAvailable, anExisting;
1450 HypothesisData* curAlgo = algoByDim[ dim ];
1451 int hypIndex = currentHyp( dim, type );
1453 SMESH::SMESH_Hypothesis_var curHyp;
1454 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1455 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1457 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1458 // try to find algo by selected hypothesis in order to keep it selected
1459 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1460 CORBA::String_var curHypType = curHyp->GetName();
1461 if ( !algoDeselectedByUser &&
1462 myObjHyps[ dim ][ type ].count() > 0 &&
1463 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1465 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1466 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1467 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1468 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1475 // get hyps compatible with curAlgo
1478 // check if a selected hyp is compatible with the curAlgo
1479 if ( !curHyp->_is_nil() ) {
1480 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1481 if ( !isCompatible( curAlgo, hypData, type ))
1482 curHyp = SMESH::SMESH_Hypothesis::_nil();
1484 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1485 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1487 // set list of hypotheses
1488 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1489 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1491 // set current existing hypothesis
1492 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1493 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1496 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1497 // none is yet selected => select the sole existing if it is not optional
1498 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1499 bool isOptional = true;
1500 if ( algoByDim[ dim ] &&
1501 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1505 setCurrentHyp( dim, type, hypIndex );
1510 //================================================================================
1512 * \brief Creates and selects hypothesis of hypotheses set
1513 * \param theSetName - The name of hypotheses set
1515 //================================================================================
1516 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1518 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1523 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1524 setCurrentHyp(dim, Algo, -1);
1525 setCurrentHyp(dim, AddHyp, -1);
1526 setCurrentHyp(dim, MainHyp, -1);
1529 myHypoSet->init(true); //algorithms
1531 myHypoSet->init(false); //hypotheses
1536 //================================================================================
1538 * \brief One step of hypothesis/algorithm list creation
1540 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1542 //================================================================================
1543 void SMESHGUI_MeshOp::processSet()
1546 if( !myHypoSet->more() )
1549 bool isAlgo = myHypoSet->isAlgo();
1550 QString aHypoTypeName = myHypoSet->current();
1551 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1558 int aDim = aHypData->Dim[0];
1559 // create or/and set
1562 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1565 QStringList anAvailable;
1566 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1567 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1568 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1570 setCurrentHyp( aDim, Algo, index );
1571 onAlgoSelected( index, aDim );
1576 bool mainHyp = true;
1577 QStringList anAvailable;
1578 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1579 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1580 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1584 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1587 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1593 //================================================================================
1595 * \brief Creates mesh
1596 * \param theMess - Output parameter intended for returning error message
1597 * \param theEntryList - List of entries of published objects
1598 * \retval bool - TRUE if mesh is created, FALSE otherwise
1602 //================================================================================
1603 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1607 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1608 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1611 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1612 QStringList::Iterator it = aList.begin();
1613 for ( ; it!=aList.end(); it++)
1615 QString aGeomEntry = *it;
1616 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1617 GEOM::GEOM_Object_var aGeomVar =
1618 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1620 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1621 if ( aSMESHGen->_is_nil() )
1624 SUIT_OverrideCursor aWaitCursor;
1627 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1628 if ( aMeshVar->_is_nil() )
1630 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1632 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1633 theEntryList.append( aMeshSO->GetID().c_str() );
1636 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1637 if ( !isAccessibleDim( aDim )) continue;
1639 // assign hypotheses
1640 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1641 int aHypIndex = currentHyp( aDim, aHypType );
1642 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1643 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1644 if ( !aHypVar->_is_nil() )
1645 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1648 // find or create algorithm
1649 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1650 if ( !anAlgoVar->_is_nil() )
1651 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1653 #ifdef WITHGENERICOBJ
1654 // obj has been published in study. Its refcount has been incremented.
1655 // It is safe to decrement its refcount
1656 // so that it will be destroyed when the entry in study will be removed
1658 aMeshVar->UnRegister();
1664 //================================================================================
1666 * \brief Creates sub-mesh
1667 * \param theMess - Output parameter intended for returning error message
1668 * \param theEntryList - List of entries of published objects
1669 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1673 //================================================================================
1674 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1678 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1679 if ( aSMESHGen->_is_nil() )
1683 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1684 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1685 SMESH::SMESH_Mesh_var aMeshVar =
1686 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1687 if (aMeshVar->_is_nil())
1690 // GEOM shape of the main mesh
1691 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1693 // Name for the new sub-mesh
1694 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1697 GEOM::GEOM_Object_var aGeomVar;
1699 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1700 if (aGEOMs.count() == 1)
1702 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1703 QString aGeomEntry = aGEOMs.first();
1704 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1705 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1707 else if (aGEOMs.count() > 1)
1709 // create a GEOM group
1710 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1711 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1712 if (!geomGen->_is_nil() && aStudy) {
1713 GEOM::GEOM_IGroupOperations_var op =
1714 geomGen->GetIGroupOperations(aStudy->StudyId());
1715 if (!op->_is_nil()) {
1716 // check and add all selected GEOM objects: they must be
1717 // a sub-shapes of the main GEOM and must be of one type
1719 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1720 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1721 aSeq->length(aGEOMs.count());
1722 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1723 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1724 QString aSubGeomEntry = (*aSubShapesIter);
1725 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1726 GEOM::GEOM_Object_var aSubGeomVar =
1727 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1728 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1730 aGroupType = aSubShapeType;
1732 if (aSubShapeType != aGroupType)
1733 aGroupType = TopAbs_SHAPE;
1735 aSeq[iSubSh] = aSubGeomVar;
1738 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1739 op->UnionList(aGroupVar, aSeq);
1742 aGeomVar = aGroupVar;
1744 // publish the GEOM group in study
1745 QString aNewGeomGroupName ("Auto_group_for_");
1746 aNewGeomGroupName += aName;
1747 SALOMEDS::SObject_var aNewGroupSO =
1748 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1749 aNewGeomGroupName.toLatin1().data(), mainGeom);
1756 if (aGeomVar->_is_nil())
1759 SUIT_OverrideCursor aWaitCursor;
1762 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1763 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1765 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1766 theEntryList.append( aSubMeshSO->GetID().c_str() );
1769 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1771 if ( !isAccessibleDim( aDim )) continue;
1773 // find or create algorithm
1774 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1775 if ( !anAlgoVar->_is_nil() )
1776 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1777 // assign hypotheses
1778 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1780 int aHypIndex = currentHyp( aDim, aHypType );
1781 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1783 SMESH::SMESH_Hypothesis_var aHypVar =
1784 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1785 if ( !aHypVar->_is_nil() )
1786 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1791 // deselect geometry: next submesh should be created on other subshape
1792 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1793 selectObject( _PTR(SObject)() );
1799 //================================================================================
1801 * \brief Gets current hypothesis or algorithms
1802 * \param theDim - dimension of hypothesis or algorithm
1803 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1804 * \retval int - current hypothesis or algorithms
1806 * Gets current hypothesis or algorithms
1808 //================================================================================
1809 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1811 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1814 //================================================================================
1816 * \brief Returns true if hypotheses of given dim can be assigned
1817 * \param theDim - hypotheses dimension
1818 * \retval bool - result
1820 //================================================================================
1821 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1823 return myDlg->isTabEnabled( theDim );
1826 //================================================================================
1828 * \brief Sets current hypothesis or algorithms
1829 * \param theDim - dimension of hypothesis or algorithm
1830 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1831 * \param theIndex - Index of hypothesis
1833 * Gets current hypothesis or algorithms
1835 //================================================================================
1836 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1837 const int theHypType,
1838 const int theIndex )
1840 myIgnoreAlgoSelection = true;
1841 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1842 myIgnoreAlgoSelection = false;
1845 //================================================================================
1847 * \brief Generates default and sets mesh/submesh name
1849 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1851 //================================================================================
1852 void SMESHGUI_MeshOp::setDefaultName() const
1856 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1858 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1859 _PTR(SObject) anObj;
1862 aResName = aPrefix + QString::number( i++ );
1863 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1867 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1868 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1869 aControl->setText( aResName );
1872 //================================================================================
1874 * \brief Gets algorithm or creates it if necessary
1875 * \param theDim - specifies dimension of returned hypotheses/algorifms
1876 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1878 * Gets algorithm or creates it if necessary
1880 //================================================================================
1881 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1883 SMESH::SMESH_Hypothesis_var anAlgoVar;
1885 // get type of the selected algo
1886 int aHypIndex = currentHyp( theDim, Algo );
1887 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1888 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1890 QString aHypName = dataList[ aHypIndex ]->TypeName;
1892 // get existing algoritms
1893 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1895 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1897 // look for an existing algo of such a type
1898 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1899 THypList::iterator anIter = aHypVarList.begin();
1900 for ( ; anIter != aHypVarList.end(); anIter++)
1902 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1903 CORBA::String_var aName = aHypVar->GetName();
1904 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1906 anAlgoVar = aHypVar;
1911 if (anAlgoVar->_is_nil())
1913 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1916 QString aClientLibName = aHypData->ClientLibName;
1917 if (aClientLibName == "")
1919 // Call hypothesis creation server method (without GUI)
1920 SMESH::SMESH_Hypothesis_var aHyp =
1921 SMESH::CreateHypothesis(aHypName, aHypName, true);
1922 #ifdef WITHGENERICOBJ
1923 if (!CORBA::is_nil(aHyp))
1929 // Get hypotheses creator client (GUI)
1931 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1935 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1937 SMESH::SMESH_Hypothesis_var aHyp =
1938 SMESH::CreateHypothesis(aHypName, aHypName, true);
1939 #ifdef WITHGENERICOBJ
1940 if (!CORBA::is_nil(aHyp))
1945 QStringList tmpList;
1946 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1947 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1950 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1951 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1953 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1954 CORBA::String_var aName = aHypVar->GetName();
1955 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1957 anAlgoVar = aHypVar;
1963 return anAlgoVar._retn();
1966 //================================================================================
1968 * \brief Reads parameters of edited mesh and assigns them to the dialog
1970 * Reads parameters of edited mesh and assigns them to the dialog (called when
1971 * mesh is edited only)
1973 //================================================================================
1974 void SMESHGUI_MeshOp::readMesh()
1976 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1977 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1981 if (myIsOnGeometry) {
1982 // Get name of mesh if current object is sub-mesh
1983 SMESH::SMESH_subMesh_var aSubMeshVar =
1984 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1985 if ( !aSubMeshVar->_is_nil() )
1987 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1988 if ( !aMeshVar->_is_nil() )
1990 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1991 QString aMeshName = name( aMeshSO );
1992 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1996 // Get name of geometry object
1997 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1998 if ( !aGeomVar->_is_nil() )
2000 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2001 QString aShapeName = name( aGeomSO );
2002 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2006 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2007 QStringList anExisting;
2008 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2009 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2012 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2013 // find algo index among available ones
2015 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2017 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2018 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2019 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2020 // if ( aHypIndex < 0 && algoData ) {
2021 // // assigned algo is incompatible with other algorithms
2022 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2023 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2026 setCurrentHyp( dim, Algo, aHypIndex );
2027 // set existing and available hypothesis according to the selected algo
2028 onAlgoSelected( aHypIndex, dim );
2032 bool hypWithoutAlgo = false;
2033 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2035 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2038 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2039 // find index of requered hypothesis among existing ones for this dimension and type
2041 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2042 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2043 myExistingHyps[ dim ][ hypType ] );
2044 if ( aHypIndex < 0 ) {
2045 // assigned hypothesis is incompatible with the algorithm
2046 if ( currentHyp( dim, Algo ) < 0 )
2047 { // none algo selected; it is edition for sure, of submesh maybe
2048 hypWithoutAlgo = true;
2049 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2050 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2051 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2055 setCurrentHyp( dim, hypType, aHypIndex );
2058 // make available other hyps of same type as one without algo
2059 if ( hypWithoutAlgo )
2060 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2063 //================================================================================
2065 * \brief Gets name of object
2066 * \param theSO - SObject
2067 * \retval QString - name of object
2069 * Gets name of object
2071 //================================================================================
2072 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2077 _PTR(GenericAttribute) anAttr;
2078 _PTR(AttributeName) aNameAttr;
2079 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2082 aResName = aNameAttr->Value().c_str();
2088 //================================================================================
2090 * \brief Finds hypothesis in input list
2091 * \param theHyp - hypothesis to be found
2092 * \param theHypList - input list of hypotheses
2093 * \retval int - index of hypothesis or -1 if it is not found
2095 * Finds position of hypothesis in input list
2097 //================================================================================
2098 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2099 const THypList& theHypList ) const
2102 if ( !theHyp->_is_nil() )
2105 THypList::const_iterator anIter = theHypList.begin();
2106 for ( ; anIter != theHypList.end(); ++ anIter)
2108 if ( theHyp->_is_equivalent( (*anIter).first ) )
2119 //================================================================================
2121 * \brief Edits mesh or sub-mesh
2122 * \param theMess - Output parameter intended for returning error message
2123 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2125 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2127 //================================================================================
2128 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2132 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2133 if ( aSMESHGen->_is_nil() )
2136 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2137 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2141 SUIT_OverrideCursor aWaitCursor;
2144 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2145 SMESH::SetName( pObj, aName );
2146 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2148 // First, remove old algos in order to avoid messages on algorithm hiding
2149 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2151 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2153 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2154 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2155 if ( anAlgoVar->_is_nil() || // no new algo selected or
2156 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2158 // remove old algorithm
2159 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2160 myObjHyps[ dim ][ Algo ].clear();
2165 // Assign new algorithms and hypotheses
2166 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2168 if ( !isAccessibleDim( dim )) continue;
2170 // find or create algorithm
2171 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2173 // assign new algorithm
2174 if ( !anAlgoVar->_is_nil() && // some algo selected and
2175 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2177 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2178 CORBA::Object_var anObject = aSObject->GetObject();
2179 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2180 bool isMesh = !aMeshVar->_is_nil();
2182 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2184 SMESH::SMESH_subMesh_var aVar =
2185 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2186 if ( !aVar->_is_nil() )
2187 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2189 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2192 // assign hypotheses
2193 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2195 int aNewHypIndex = currentHyp( dim, hypType );
2196 int anOldHypIndex = -1;
2198 // remove old hypotheses
2199 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2201 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2202 myExistingHyps[ dim ][ hypType ] );
2203 if ( aNewHypIndex != anOldHypIndex || // different hyps
2204 anOldHypIndex == -1 ) // hyps of different algos
2206 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2207 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2208 myObjHyps[ dim ][ hypType ].clear();
2212 // assign new hypotheses
2213 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2215 SMESH::SMESH_Mesh_var aMeshVar =
2216 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2217 bool isMesh = !aMeshVar->_is_nil();
2220 SMESH::AddHypothesisOnMesh
2221 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2225 SMESH::SMESH_subMesh_var aVar =
2226 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2227 if ( !aVar->_is_nil() )
2228 SMESH::AddHypothesisOnSubMesh
2229 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2232 // reread all hypotheses of mesh if necessary
2233 QStringList anExisting;
2234 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2241 //================================================================================
2243 * \brief Verifies whether given operator is valid for this one
2244 * \param theOtherOp - other operation
2245 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2247 * method redefined from base class verifies whether given operator is valid for
2248 * this one (i.e. can be started "above" this operator). In current implementation method
2249 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2252 //================================================================================
2253 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2255 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2258 //================================================================================
2260 * \brief SLOT. Is called when the user selects a way of geometry selection
2261 * \param theByMesh - true if the user wants to find geometry by mesh element
2263 //================================================================================
2264 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2267 if ( !myShapeByMeshOp ) {
2268 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2269 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2270 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2271 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2272 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2274 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2275 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2276 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2277 SMESH::SMESH_Mesh_var aMeshVar =
2278 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2279 if ( !aMeshVar->_is_nil() ) {
2280 myDlg->hide(); // stop processing selection
2281 myShapeByMeshOp->setModule( getSMESHGUI() );
2282 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2283 myShapeByMeshOp->SetMesh( aMeshVar );
2284 myShapeByMeshOp->start();
2290 //================================================================================
2292 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2294 //================================================================================
2295 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2297 if ( myShapeByMeshOp == op ) {
2298 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2300 // Select a found geometry object
2301 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2302 if ( !aGeomVar->_is_nil() )
2304 QString ID = aGeomVar->GetStudyEntry();
2305 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2306 selectObject( aGeomSO );
2313 //================================================================================
2315 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2317 //================================================================================
2318 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2320 if ( myShapeByMeshOp == op && myDlg ) {
2325 //================================================================================
2327 * \brief Selects a SObject
2328 * \param theSObj - the SObject to select
2330 //================================================================================
2331 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2333 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2334 SALOME_ListIO anIOList;
2336 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2337 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2338 anIOList.Append( anIO );
2340 sm->setSelectedObjects( anIOList, false );