1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MeshOp.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshOp.h"
30 #include "SMESHGUI_MeshDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Hypotheses.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_NumberFilter.hxx>
40 // SALOME GEOM includes
41 #include <GEOM_SelectionFilter.h>
43 #include <GeometryGUI.h>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SALOME_InteractiveObject.hxx>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDS_SComponent.hxx>
57 #include <SALOMEDS_SObject.hxx>
60 #include <QStringList>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Shell.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <BRep_Tool.hxx>
71 #include <SALOMEconfig.h>
72 #include CORBA_CLIENT_HEADER(SMESH_Gen)
74 //================================================================================
77 * \param theToCreate - if this parameter is true then operation is used for creation,
78 * for editing otherwise
80 * Initialize operation
82 //================================================================================
83 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
84 : SMESHGUI_SelectionOp(),
85 myToCreate( theToCreate ),
86 myIsMesh( theIsMesh ),
90 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
91 GeometryGUI::InitGeomGen();
92 myIsOnGeometry = true;
95 //================================================================================
99 //================================================================================
100 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
106 //================================================================================
108 * \brief Gets dialog of this operation
109 * \retval LightApp_Dialog* - pointer to dialog of this operation
111 //================================================================================
112 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
117 //================================================================================
119 * \brief Creates or edits mesh
120 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
122 * Virtual slot redefined from the base class called when "Apply" button is clicked
123 * creates or edits mesh
125 //================================================================================
126 bool SMESHGUI_MeshOp::onApply()
132 if ( !isValid( aMess ) )
136 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
140 bool aResult = false;
144 if ( myToCreate && myIsMesh )
145 aResult = createMesh( aMess );
146 if ( myToCreate && !myIsMesh )
147 aResult = createSubMesh( aMess );
148 else if ( !myToCreate )
149 aResult = editMeshOrSubMesh( aMess );
151 update( UF_ObjBrowser | UF_Model );
153 catch ( const SALOME::SALOME_Exception& S_ex )
155 SalomeApp_Tools::QtCatchCorbaException( S_ex );
171 aMess = tr( "SMESH_OPERATION_FAILED" );
172 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
178 //================================================================================
180 * \brief Creates dialog if necessary and shows it
182 * Virtual method redefined from base class called when operation is started creates
183 * dialog if necessary and shows it, activates selection
185 //================================================================================
186 void SMESHGUI_MeshOp::startOperation()
190 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
191 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
193 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
194 this, SLOT( onCreateHyp( const int, const int ) ) );
195 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
196 this, SLOT( onEditHyp( const int, const int ) ) );
197 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
198 this, SLOT( onAlgoSelected( const int ) ) );
200 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
201 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
204 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
205 else myHelpFileName = "constructing_submeshes_page.html";
206 else myHelpFileName = "editing_meshes_page.html";
208 SMESHGUI_SelectionOp::startOperation();
210 // iterate through dimensions and get available algoritms, set them to the dialog
211 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
212 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
214 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
216 // clear available hypotheses
217 aTab->setAvailableHyps( MainHyp, hypList );
218 aTab->setAvailableHyps( AddHyp, hypList );
219 aTab->setExistingHyps( MainHyp, hypList );
220 aTab->setExistingHyps( AddHyp, hypList );
221 myExistingHyps[ i ][ MainHyp ].clear();
222 myExistingHyps[ i ][ AddHyp ].clear();
224 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
225 aTab->setAvailableHyps( Algo, hypList );
230 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
233 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
235 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
237 myDlg->setCurrentTab( SMESH::DIM_3D );
242 myIgnoreAlgoSelection = false;
245 //================================================================================
247 * \brief Creates selection filter
248 * \param theId - identifier of current selection widget
249 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
251 * Creates selection filter in accordance with identifier of current selection widget
253 //================================================================================
254 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
256 if ( theId == SMESHGUI_MeshDlg::Geom )
258 // TColStd_MapOfInteger allTypesMap;
259 // for ( int i = 0; i < 10; i++ )
260 // allTypesMap.Add( i );
261 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
262 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
264 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
265 return new SMESH_TypeFilter( MESHorSUBMESH );
266 else if ( theId == SMESHGUI_MeshDlg::Mesh )
267 return new SMESH_TypeFilter( MESH );
272 //================================================================================
274 * \brief check if selected shape is a subshape of the shape to mesh
275 * \retval bool - check result
277 //================================================================================
279 bool SMESHGUI_MeshOp::isSubshapeOk() const
281 if ( !myToCreate || myIsMesh ) // not submesh creation
285 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
286 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
287 if (!pMesh) return false;
289 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
290 if (mesh->_is_nil()) return false;
292 // main shape of the mesh
293 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
294 if (mainGeom->_is_nil()) return false;
298 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
300 if (aGEOMs.count() > 0) {
301 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
302 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
303 if (geomGen->_is_nil() || !aStudy) return false;
305 GEOM::GEOM_IGroupOperations_var op =
306 geomGen->GetIGroupOperations(aStudy->StudyId());
307 if (op->_is_nil()) return false;
309 // check all selected shapes
310 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
311 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
312 QString aSubGeomEntry = (*aSubShapesIter);
313 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
314 if (!pSubGeom) return false;
316 GEOM::GEOM_Object_var aSubGeomVar =
317 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
318 if (aSubGeomVar->_is_nil()) return false;
320 // skl for NPAL14695 - implementation of searching of mainObj
321 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
322 //if (mainObj->_is_nil() ||
323 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
325 if (mainObj->_is_nil())
327 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
329 mainObj = op->GetMainShape(mainObj);
338 //================================================================================
340 * \brief Return name of the algorithm that does not support submeshes and makes
341 * submesh creation useless
342 * \retval char* - string is to be deleted!!!
344 //================================================================================
346 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
348 if ( myToCreate && !myIsMesh ) {
350 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
351 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
352 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
355 QStringList algoNames;
357 existingHyps(3, Algo, pMesh, algoNames, algoList);
358 if (!algoList.empty()) {
359 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
361 algo->InputTypes.empty() && // builds all dimensions it-self
362 !algo->IsSupportSubmeshes )
363 return CORBA::string_dup( algoNames[0].toLatin1().data() );
366 // GEOM::GEOM_Object_var geom;
367 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
368 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
370 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
371 existingHyps(2, Algo, pMesh, algoNames, algoList);
372 if (!algoList.empty()) {
373 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
375 algo->InputTypes.empty() && // builds all dimensions it-self
376 !algo->IsSupportSubmeshes )
377 return CORBA::string_dup( algoNames[0].toLatin1().data() );
385 //================================================================================
387 * \brief find an existing submesh by the selected shape
388 * \retval _PTR(SObject) - the found submesh SObject
390 //================================================================================
392 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
394 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
395 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
396 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
397 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
398 if ( pMesh && pGeom ) {
399 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
400 if ( !geom->_is_nil() ) {
402 switch ( geom->GetShapeType() ) {
403 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
404 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
405 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
406 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
407 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
408 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
409 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
412 _PTR(GenericAttribute) anAttr;
413 _PTR(SObject) aSubmeshRoot;
414 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
415 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
417 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
418 for ( ; smIter->More(); smIter->Next() )
420 _PTR(SObject) aSmObj = smIter->Value();
421 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
423 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
424 for ( ; anIter1->More(); anIter1->Next()) {
425 _PTR(SObject) pGeom2 = anIter1->Value();
426 if ( pGeom2->ReferencedObject( pGeom2 ) &&
427 pGeom2->GetID() == pGeom->GetID() )
434 return _PTR(SObject)();
437 //================================================================================
439 * \brief Updates dialog's look and feel
441 * Virtual method redefined from the base class updates dialog's look and feel
443 //================================================================================
444 void SMESHGUI_MeshOp::selectionDone()
446 if (!dlg()->isVisible() || !myDlg->isEnabled())
449 SMESHGUI_SelectionOp::selectionDone();
453 myIsOnGeometry = true;
455 //Check geometry for mesh
456 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
457 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
460 SMESH::SMESH_Mesh_var aMeshVar =
461 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
462 if (!aMeshVar->_is_nil()) {
463 if (!myToCreate && !aMeshVar->HasShapeToMesh())
464 myIsOnGeometry = false;
470 // Enable tabs according to shape dimension
475 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
476 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
478 if (aGEOMs.count() > 0) {
479 // one or more GEOM shape selected
480 aSeq->length(aGEOMs.count());
481 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
483 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
484 QString aSubGeomEntry = (*aSubShapesIter);
485 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
486 GEOM::GEOM_Object_var aSubGeomVar =
487 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
488 aSeq[iSubSh] = aSubGeomVar;
491 // get geometry by selected sub-mesh
492 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
493 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
494 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
495 if (!aGeomVar->_is_nil()) {
501 if (aSeq->length() > 0) {
503 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
504 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
505 switch ( aGeomVar->GetShapeType() ) {
506 case GEOM::SOLID: shapeDim = 3; break;
509 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
510 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
512 if (GEOMBase::GetShape(aGeomVar, aShape)) {
513 if (/*aShape.Closed()*/BRep_Tool::IsClosed(aShape))
518 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
520 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
521 case GEOM::VERTEX: 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 = (shapeDim < 2) ? 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 = (shapeDim < 2) ? 2 : shapeDim;
537 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
538 shapeDim = (shapeDim < 1) ? 1 : 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 );
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 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
618 myDlg->setGeomPopupEnabled( enable );
622 myDlg->enableTab( SMESH::DIM_3D );
624 availableHyps( SMESH::DIM_3D, Algo, hypList,
625 myAvailableHypData[SMESH::DIM_3D][Algo]);
627 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
628 aTab->setAvailableHyps( Algo, hypList );
629 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
630 myDlg->disableTab(i);
632 //Hide labels and fields (Mesh ang Geometry)
633 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
634 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
639 catch ( const SALOME::SALOME_Exception& S_ex )
641 SalomeApp_Tools::QtCatchCorbaException( S_ex );
648 //================================================================================
650 * \brief Verifies validity of input data
651 * \param theMess - Output parameter intended for returning error message
652 * \retval bool - TRUE if input data is valid, false otherwise
654 * Verifies validity of input data. This method is called when "Apply" or "OK" button
655 * is pressed before mesh creation or editing.
657 //================================================================================
658 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
660 // Selected object to be edited
661 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
663 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
668 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
669 if ( aMeshName.isEmpty() )
671 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
675 /* // Imported mesh, if create sub-mesh or edit mesh
676 if ( !myToCreate || ( myToCreate && !myIsMesh ))
678 QString aMeshEntry = myDlg->selectedObject
679 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
680 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
681 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
682 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
683 theMess = tr( "IMPORTED_MESH" );
692 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
693 if ( aGeomEntry == "" )
695 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
698 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
699 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
701 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
706 if ( !myIsMesh ) // i.e sub-mesh creation,
708 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
709 if ( aMeshEntry == "" )
711 theMess = tr( "MESH_IS_NOT_DEFINED" );
714 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
715 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
717 theMess = tr( "MESH_IS_NULL" );
720 if ( !isSubshapeOk() )
722 theMess = tr( "INVALID_SUBSHAPE" );
731 //================================================================================
733 * \brief check compatibility of the algorithm and another algorithm or hypothesis
734 * \param theAlgoData - algorithm data
735 * \param theHypData - hypothesis data
736 * \param theHypType - hypothesis type
737 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
738 * \retval bool - check result
740 //================================================================================
742 static bool isCompatible(const HypothesisData* theAlgoData,
743 const HypothesisData* theHypData,
744 const int theHypType)
749 if ( theHypType == SMESHGUI_MeshOp::Algo )
750 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
753 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
756 //================================================================================
758 * \brief Gets available hypotheses or algorithms
759 * \param theDim - specifies dimension of returned hypotheses/algorifms
760 * \param theHypType - specifies whether algorims or hypotheses or additional ones
761 * are retrieved (possible values are in HypType enumeration)
762 * \param theHyps - Output list of hypotheses' names
763 * \param theAlgoData - to select hypos able to be used by this algo (optional)
765 * Gets available hypotheses or algorithm in accordance with input parameters
767 //================================================================================
768 void SMESHGUI_MeshOp::availableHyps( const int theDim,
769 const int theHypType,
770 QStringList& theHyps,
771 THypDataList& theDataList,
772 HypothesisData* theAlgoData ) const
776 bool isAlgo = ( theHypType == Algo );
777 bool isAux = ( theHypType == AddHyp );
778 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
780 QStringList::const_iterator anIter;
781 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
783 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
784 if ( isCompatible ( theAlgoData, aData, theHypType )) {
785 theDataList.append( aData );
786 theHyps.append( aData->Label );
791 //================================================================================
793 * \brief Gets existing hypotheses or algorithms
794 * \param theDim - specifies dimension of returned hypotheses/algorifms
795 * \param theHypType - specifies whether algorims or hypotheses or additional ones
796 * are retrieved (possible values are in HypType enumeration)
797 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
798 * \param theHyps - output list of names.
799 * \param theHypVars - output list of variables.
800 * \param theAlgoData - to select hypos able to be used by this algo (optional)
802 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
805 //================================================================================
806 void SMESHGUI_MeshOp::existingHyps( const int theDim,
807 const int theHypType,
808 _PTR(SObject) theFather,
809 QStringList& theHyps,
810 THypList& theHypList,
811 HypothesisData* theAlgoData)
813 // Clear hypoheses list
820 const bool isAux = ( theHypType == AddHyp );
822 _PTR(SObject) aHypRoot;
823 _PTR(GenericAttribute) anAttr;
824 _PTR(AttributeName) aName;
825 _PTR(AttributeIOR) anIOR;
827 bool isMesh = !_CAST( SComponent, theFather );
830 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
832 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
834 if ( theFather->FindSubObject( aPart, aHypRoot ) )
836 _PTR(ChildIterator) anIter =
837 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
838 for ( ; anIter->More(); anIter->Next() )
840 _PTR(SObject) anObj = anIter->Value();
841 if ( isMesh ) // i.e. mesh or submesh
843 _PTR(SObject) aRefObj;
844 if ( anObj->ReferencedObject( aRefObj ) )
849 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
852 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
853 if ( !CORBA::is_nil( aVar ) )
855 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
856 if ( !aHypVar->_is_nil() )
858 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
859 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
860 ( isCompatible ( theAlgoData, aData, theHypType )) &&
861 ( isAux == aData->IsAux ))
863 std::string aHypName = aName->Value();
864 theHyps.append( aHypName.c_str() );
865 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
874 //================================================================================
876 * \brief If create or edit a submesh, return a hypothesis holding parameters used
878 * \param aHypType - The hypothesis type name
879 * \param aServerLib - Server library name
880 * \param hypData - The structure holding the hypothesis type etc.
881 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
883 //================================================================================
885 SMESH::SMESH_Hypothesis_var
886 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
887 const QString& aServerLib ) const
889 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
890 return SMESH::SMESH_Hypothesis::_nil();
892 const int nbColonsInMeshEntry = 3;
893 bool isSubMesh = myToCreate ?
895 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
897 // get mesh and geom object
898 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
899 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
904 anEntry = myDlg->selectedObject
905 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
906 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
908 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
909 if ( myToCreate ) // mesh and geom may be selected
911 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
912 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
913 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
914 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
916 else // edition: sub-mesh may be selected
918 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
919 if ( !sm->_is_nil() ) {
920 aMeshVar = sm->GetFather();
921 aGeomVar = sm->GetSubShape();
928 if ( !myToCreate ) // mesh to edit can be selected
930 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
931 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
933 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
934 if ( !aMeshVar->_is_nil() )
935 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
938 if ( aGeomVar->_is_nil() ) {
939 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
940 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
942 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
947 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
948 aServerLib.toLatin1().data(),
951 /*byMesh = */isSubMesh);
955 //================================================================================
957 * \Brief Returns tab dimention
958 * \param tab - the tab in the dlg
959 * \param dlg - my dialogue
960 * \retval int - dimention
962 //================================================================================
964 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
967 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
968 if (tab == dlg->tab(i))
973 //================================================================================
975 * \brief Create hypothesis
976 * \param theHypType - hypothesis category (main or additional)
977 * \param theIndex - index of type of hypothesis to be cerated
979 * Specifies dimension of hypothesis to be created (using sender() method),
980 * specifies its type and calls method for hypothesis creation
982 //================================================================================
983 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
985 // Specifies dimension of hypothesis to be created
986 int aDim = getTabDim( sender(), myDlg );
990 // Specifies type of hypothesis to be created
991 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
992 if (theIndex < 0 || theIndex >= dataList.count())
994 QString aHypTypeName = dataList[ theIndex ]->TypeName;
997 createHypothesis(aDim, theHypType, aHypTypeName);
1002 QString GetUniqueName (const QStringList& theHypNames,
1003 const QString& theName,
1004 size_t theIteration = 1)
1006 QString aName = theName + "_" + QString::number( theIteration );
1007 if ( theHypNames.contains( aName ) )
1008 return GetUniqueName( theHypNames, theName, ++theIteration );
1013 //================================================================================
1015 * Create hypothesis and update dialog.
1016 * \param theDim - dimension of hypothesis to be created
1017 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1018 * \param theTypeName - specifies hypothesis to be created
1020 //================================================================================
1022 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1024 const QString& theTypeName)
1026 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1032 QStringList aHypNames;
1033 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1034 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1035 const TType2HypList& aType2HypList = aDimIter.value();
1036 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1037 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1038 const THypList& aHypList = aTypeIter.value();
1039 THypList::const_iterator anIter = aHypList.begin();
1040 for ( ; anIter != aHypList.end(); anIter++) {
1041 const THypItem& aHypItem = *anIter;
1042 const QString& aHypName = aHypItem.second;
1043 aHypNames.append(aHypName);
1047 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1050 bool dialog = false;
1052 QString aClientLibName = aData->ClientLibName;
1053 if (aClientLibName == "") {
1054 // Call hypothesis creation server method (without GUI)
1055 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1057 // Get hypotheses creator client (GUI)
1059 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1060 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1062 // Create hypothesis
1064 // Get parameters appropriate to initialize a new hypothesis
1065 SMESH::SMESH_Hypothesis_var initParamHyp =
1066 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1068 removeCustomFilters(); // Issue 0020170
1070 // Get Entry of the Geom object
1071 QString anObjEntry = "";
1072 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1073 if ( anObjEntry == "" ) {
1074 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1075 if ( anObjEntry != "" ) {
1076 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1077 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1078 anObjEntry = ( aGeomVar->_is_nil() ) ? "" : anObjEntry = aGeomVar->GetStudyEntry();
1082 aCreator->setShapeEntry( anObjEntry );
1083 myDlg->setEnabled( false );
1084 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1088 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1095 //================================================================================
1097 * Necessary steps after hypothesis creation
1098 * \param result - creation result:
1101 * 2 = additional value meaning that slot is called not from dialog box
1103 //================================================================================
1104 void SMESHGUI_MeshOp::onHypoCreated( int result )
1108 int obj = myDlg->getActiveObject();
1109 onActivateObject( obj ); // Issue 0020170. Restore filters
1110 myDlg->setEnabled( true );
1113 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1115 int nbHyp = myExistingHyps[myDim][myType].count();
1116 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1117 QStringList aNewHyps;
1118 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1119 if (aNewHyps.count() > nbHyp)
1121 for (int i = nbHyp; i < aNewHyps.count(); i++)
1122 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1125 if( result!=2 && myHypoSet )
1129 //================================================================================
1131 * \brief Calls plugin methods for hypothesis editing
1132 * \param theHypType - specifies whether main hypothesis or additional one
1134 * \param theIndex - index of existing hypothesis
1136 * Calls plugin methods for hypothesis editing
1138 //================================================================================
1139 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1141 // Speicfies dimension of hypothesis to be created
1142 int aDim = getTabDim( sender(), myDlg );
1146 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1147 if ( theIndex < 0 || theIndex >= aList.count() )
1149 const THypItem& aHypItem = aList[ theIndex ];
1150 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1151 if ( aHyp->_is_nil() )
1155 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1156 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1159 // Get initial parameters
1160 SMESH::SMESH_Hypothesis_var initParamHyp =
1161 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1162 aCreator->setInitParamsHypothesis( initParamHyp );
1164 // Get Entry of the Geom object
1165 QString anObjEntry = "";
1166 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1167 if ( anObjEntry == "" ) {
1168 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1169 if ( anObjEntry != "" ) {
1170 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1171 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1172 anObjEntry = aGeomVar->GetStudyEntry();
1176 aCreator->setShapeEntry( anObjEntry );
1177 removeCustomFilters(); // Issue 0020170
1178 myDlg->setEnabled( false );
1179 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1183 //================================================================================
1185 * Necessary steps after hypothesis edition
1186 * \param result - creation result:
1190 //================================================================================
1191 void SMESHGUI_MeshOp::onHypoEdited( int result )
1193 int obj = myDlg->getActiveObject();
1194 onActivateObject( obj ); // Issue 0020170. Restore filters
1195 myDlg->setEnabled( true );
1198 //================================================================================
1200 * \brief access to hypothesis data
1201 * \param theDim - hyp dimension
1202 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1203 * \param theIndex - index in the list
1204 * \retval HypothesisData* - result data, may be 0
1206 //================================================================================
1208 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1209 const int theHypType,
1212 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1213 theHypType > -1 && theHypType < NbHypTypes &&
1214 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1215 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1219 //================================================================================
1221 * \brief Set available algos and hypos according to the selected algorithm
1222 * \param theIndex - algorithm index
1224 //================================================================================
1226 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1229 if ( myIgnoreAlgoSelection )
1232 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1236 // find highest available dimension, all algos of this dimension are available for choice
1238 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1239 if (isAccessibleDim( i ))
1244 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1246 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1247 HypothesisData* algoByDim[4];
1248 algoByDim[ aDim ] = algoData;
1250 QStringList anAvailable;
1251 if ( !algoData ) { // all algos becomes available
1252 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1253 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1256 // check that algorithms of other dimentions are compatible with
1259 // 2 loops: backward and forward from algo dimension
1260 for ( int forward = false; forward <= true; ++forward )
1262 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1264 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1266 HypothesisData* prevAlgo = algoData;
1267 bool noCompatible = false;
1268 for ( ; dim * dir <= lastDim * dir; dim += dir)
1270 if ( !isAccessibleDim( dim ))
1272 if ( noCompatible ) { // the selected algo has no compatible ones
1273 anAvailable.clear();
1274 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1275 myAvailableHypData[dim][Algo].clear();
1276 algoByDim[ dim ] = 0;
1279 // get currently selected algo
1280 int algoIndex = currentHyp( dim, Algo );
1281 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1282 if ( curAlgo ) { // some algo selected
1283 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1286 // set new available algoritms
1287 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1288 HypothesisData* soleCompatible = 0;
1289 if ( anAvailable.count() == 1 )
1290 soleCompatible = myAvailableHypData[dim][Algo][0];
1291 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1292 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1293 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1294 noCompatible = anAvailable.isEmpty();
1296 // restore previously selected algo
1297 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1298 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1299 // select the sole compatible algo
1300 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1301 setCurrentHyp( dim, Algo, algoIndex );
1303 // remember current algo
1304 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1308 // set hypotheses corresponding to the found algoritms
1310 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1312 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1314 if ( !isAccessibleDim( dim ))
1316 for ( int type = MainHyp; type < NbHypTypes; type++ )
1318 myAvailableHypData[ dim ][ type ].clear();
1319 QStringList anAvailable, anExisting;
1321 HypothesisData* curAlgo = algoByDim[ dim ];
1322 int hypIndex = currentHyp( dim, type );
1324 SMESH::SMESH_Hypothesis_var curHyp;
1325 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1326 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1328 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1329 // try to find algo by selected hypothesis in order to keep it selected
1330 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1331 CORBA::String_var curHypType = curHyp->GetName();
1332 if ( !algoDeselectedByUser &&
1333 myObjHyps[ dim ][ type ].count() > 0 &&
1334 curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
1336 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1337 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1338 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1339 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1346 // get hyps compatible with curAlgo
1349 // check if a selected hyp is compatible with the curAlgo
1350 if ( !curHyp->_is_nil() ) {
1351 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1352 if ( !isCompatible( curAlgo, hypData, type ))
1353 curHyp = SMESH::SMESH_Hypothesis::_nil();
1355 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1356 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1358 // set list of hypotheses
1359 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1360 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1362 // set current existing hypothesis
1363 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1364 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1367 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1368 // none is yet selected => select the sole existing if it is not optional
1369 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1370 bool isOptional = true;
1371 if ( algoByDim[ dim ] &&
1372 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1376 setCurrentHyp( dim, type, hypIndex );
1381 //================================================================================
1383 * \brief Creates and selects hypothesis of hypotheses set
1384 * \param theSetName - The name of hypotheses set
1386 //================================================================================
1387 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1389 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1394 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1395 setCurrentHyp(dim, Algo, -1);
1396 setCurrentHyp(dim, AddHyp, -1);
1397 setCurrentHyp(dim, MainHyp, -1);
1400 myHypoSet->init(true); //algorithms
1402 myHypoSet->init(false); //hypotheses
1407 //================================================================================
1409 * \brief One step of hypothesis/algorithm list creation
1411 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1413 //================================================================================
1414 void SMESHGUI_MeshOp::processSet()
1417 if( !myHypoSet->more() )
1420 bool isAlgo = myHypoSet->isAlgo();
1421 QString aHypoTypeName = myHypoSet->current();
1422 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1429 int aDim = aHypData->Dim[0];
1430 // create or/and set
1433 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1436 QStringList anAvailable;
1437 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1438 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1439 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1441 setCurrentHyp( aDim, Algo, index );
1442 onAlgoSelected( index, aDim );
1447 bool mainHyp = true;
1448 QStringList anAvailable;
1449 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1450 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1451 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1455 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1458 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1464 //================================================================================
1466 * \brief Creates mesh
1467 * \param theMess - Output parameter intended for returning error message
1468 * \retval bool - TRUE if mesh is created, FALSE otherwise
1472 //================================================================================
1473 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1477 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1478 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1481 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1482 QStringList::Iterator it = aList.begin();
1483 for ( ; it!=aList.end(); it++)
1485 QString aGeomEntry = *it;
1486 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1487 GEOM::GEOM_Object_var aGeomVar =
1488 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1490 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1491 if ( aSMESHGen->_is_nil() )
1494 SUIT_OverrideCursor aWaitCursor;
1497 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1498 if ( aMeshVar->_is_nil() )
1500 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1502 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1504 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1505 if ( !isAccessibleDim( aDim )) continue;
1507 // assign hypotheses
1508 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1509 int aHypIndex = currentHyp( aDim, aHypType );
1510 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1511 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1512 if ( !aHypVar->_is_nil() )
1513 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1516 // find or create algorithm
1517 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1518 if ( !anAlgoVar->_is_nil() )
1519 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1526 //================================================================================
1528 * \brief Creates sub-mesh
1529 * \param theMess - Output parameter intended for returning error message
1530 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1534 //================================================================================
1535 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1539 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1540 if ( aSMESHGen->_is_nil() )
1544 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1545 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1546 SMESH::SMESH_Mesh_var aMeshVar =
1547 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1548 if (aMeshVar->_is_nil())
1551 // GEOM shape of the main mesh
1552 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1554 // Name for the new sub-mesh
1555 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1558 GEOM::GEOM_Object_var aGeomVar;
1560 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1561 if (aGEOMs.count() == 1)
1563 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1564 QString aGeomEntry = aGEOMs.first();
1565 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1566 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1568 else if (aGEOMs.count() > 1)
1570 // create a GEOM group
1571 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1572 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1573 if (!geomGen->_is_nil() && aStudy) {
1574 GEOM::GEOM_IGroupOperations_var op =
1575 geomGen->GetIGroupOperations(aStudy->StudyId());
1576 if (!op->_is_nil()) {
1577 // check and add all selected GEOM objects: they must be
1578 // a sub-shapes of the main GEOM and must be of one type
1580 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1581 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1582 aSeq->length(aGEOMs.count());
1583 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1584 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1585 QString aSubGeomEntry = (*aSubShapesIter);
1586 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1587 GEOM::GEOM_Object_var aSubGeomVar =
1588 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1589 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1591 aGroupType = aSubShapeType;
1593 if (aSubShapeType != aGroupType)
1594 aGroupType = TopAbs_SHAPE;
1596 aSeq[iSubSh] = aSubGeomVar;
1599 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1600 op->UnionList(aGroupVar, aSeq);
1603 aGeomVar = aGroupVar;
1605 // publish the GEOM group in study
1606 QString aNewGeomGroupName ("Auto_group_for_");
1607 aNewGeomGroupName += aName;
1608 SALOMEDS::SObject_var aNewGroupSO =
1609 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1610 aNewGeomGroupName.toLatin1().data(), mainGeom);
1617 if (aGeomVar->_is_nil())
1620 SUIT_OverrideCursor aWaitCursor;
1623 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1624 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1626 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1628 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1630 if ( !isAccessibleDim( aDim )) continue;
1632 // find or create algorithm
1633 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1634 if ( !anAlgoVar->_is_nil() )
1635 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1636 // assign hypotheses
1637 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1639 int aHypIndex = currentHyp( aDim, aHypType );
1640 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1642 SMESH::SMESH_Hypothesis_var aHypVar =
1643 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1644 if ( !aHypVar->_is_nil() )
1645 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1650 // deselect geometry: next submesh should be created on other subshape
1651 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1652 selectObject( _PTR(SObject)() );
1658 //================================================================================
1660 * \brief Gets current hypothesis or algorithms
1661 * \param theDim - dimension of hypothesis or algorithm
1662 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1663 * \retval int - current hypothesis or algorithms
1665 * Gets current hypothesis or algorithms
1667 //================================================================================
1668 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1670 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1673 //================================================================================
1675 * \brief Returns true if hypotheses of given dim can be assigned
1676 * \param theDim - hypotheses dimension
1677 * \retval bool - result
1679 //================================================================================
1680 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1682 return myDlg->isTabEnabled( theDim );
1685 //================================================================================
1687 * \brief Sets current hypothesis or algorithms
1688 * \param theDim - dimension of hypothesis or algorithm
1689 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1690 * \param theIndex - Index of hypothesis
1692 * Gets current hypothesis or algorithms
1694 //================================================================================
1695 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1696 const int theHypType,
1697 const int theIndex )
1699 myIgnoreAlgoSelection = true;
1700 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1701 myIgnoreAlgoSelection = false;
1704 //================================================================================
1706 * \brief Generates default and sets mesh/submesh name
1708 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1710 //================================================================================
1711 void SMESHGUI_MeshOp::setDefaultName() const
1715 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1717 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1718 _PTR(SObject) anObj;
1721 aResName = aPrefix + QString::number( i++ );
1722 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1726 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1727 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1728 aControl->setText( aResName );
1731 //================================================================================
1733 * \brief Gets algorithm or creates it if necessary
1734 * \param theDim - specifies dimension of returned hypotheses/algorifms
1735 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1737 * Gets algorithm or creates it if necessary
1739 //================================================================================
1740 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1742 SMESH::SMESH_Hypothesis_var anAlgoVar;
1744 // get type of the selected algo
1745 int aHypIndex = currentHyp( theDim, Algo );
1746 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1747 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1749 QString aHypName = dataList[ aHypIndex ]->TypeName;
1751 // get existing algoritms
1752 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1754 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1756 // look for an existing algo of such a type
1757 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1758 THypList::iterator anIter = aHypVarList.begin();
1759 for ( ; anIter != aHypVarList.end(); anIter++)
1761 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1762 CORBA::String_var aName = aHypVar->GetName();
1763 if ( !aHypVar->_is_nil() && aHypName == aName )
1765 anAlgoVar = aHypVar;
1770 if (anAlgoVar->_is_nil())
1772 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1775 QString aClientLibName = aHypData->ClientLibName;
1776 if (aClientLibName == "")
1778 // Call hypothesis creation server method (without GUI)
1779 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1783 // Get hypotheses creator client (GUI)
1785 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1786 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1790 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1792 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1794 QStringList tmpList;
1795 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1796 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1799 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1800 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1802 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1803 CORBA::String_var aName = aHypVar->GetName();
1804 if ( !aHypVar->_is_nil() && aHypName == aName )
1806 anAlgoVar = aHypVar;
1812 return anAlgoVar._retn();
1815 //================================================================================
1817 * \brief Reads parameters of edited mesh and assigns them to the dialog
1819 * Reads parameters of edited mesh and assigns them to the dialog (called when
1820 * mesh is edited only)
1822 //================================================================================
1823 void SMESHGUI_MeshOp::readMesh()
1825 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1826 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1830 if (myIsOnGeometry) {
1831 // Get name of mesh if current object is sub-mesh
1832 SMESH::SMESH_subMesh_var aSubMeshVar =
1833 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1834 if ( !aSubMeshVar->_is_nil() )
1836 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1837 if ( !aMeshVar->_is_nil() )
1839 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1840 QString aMeshName = name( aMeshSO );
1841 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1845 // Get name of geometry object
1846 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1847 if ( !aGeomVar->_is_nil() )
1849 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1850 QString aShapeName = name( aGeomSO );
1851 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1855 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1856 QStringList anExisting;
1857 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1858 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1861 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1862 // find algo index among available ones
1864 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1866 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1867 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1868 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1869 // if ( aHypIndex < 0 && algoData ) {
1870 // // assigned algo is incompatible with other algorithms
1871 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1872 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1875 setCurrentHyp( dim, Algo, aHypIndex );
1876 // set existing and available hypothesis according to the selected algo
1877 onAlgoSelected( aHypIndex, dim );
1881 bool hypWithoutAlgo = false;
1882 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1884 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1887 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1888 // find index of requered hypothesis among existing ones for this dimension and type
1890 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1891 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1892 myExistingHyps[ dim ][ hypType ] );
1893 if ( aHypIndex < 0 ) {
1894 // assigned hypothesis is incompatible with the algorithm
1895 if ( currentHyp( dim, Algo ) < 0 )
1896 { // none algo selected; it is edition for sure, of submesh maybe
1897 hypWithoutAlgo = true;
1898 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1899 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1900 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1904 setCurrentHyp( dim, hypType, aHypIndex );
1907 // make available other hyps of same type as one without algo
1908 if ( hypWithoutAlgo )
1909 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1912 //================================================================================
1914 * \brief Gets name of object
1915 * \param theSO - SObject
1916 * \retval QString - name of object
1918 * Gets name of object
1920 //================================================================================
1921 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1926 _PTR(GenericAttribute) anAttr;
1927 _PTR(AttributeName) aNameAttr;
1928 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1931 aResName = aNameAttr->Value().c_str();
1937 //================================================================================
1939 * \brief Finds hypothesis in input list
1940 * \param theHyp - hypothesis to be found
1941 * \param theHypList - input list of hypotheses
1942 * \retval int - index of hypothesis or -1 if it is not found
1944 * Finds position of hypothesis in input list
1946 //================================================================================
1947 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1948 const THypList& theHypList ) const
1951 if ( !theHyp->_is_nil() )
1954 THypList::const_iterator anIter = theHypList.begin();
1955 for ( ; anIter != theHypList.end(); ++ anIter)
1957 if ( theHyp->_is_equivalent( (*anIter).first ) )
1968 //================================================================================
1970 * \brief Edits mesh or sub-mesh
1971 * \param theMess - Output parameter intended for returning error message
1972 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1974 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1976 //================================================================================
1977 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1981 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1982 if ( aSMESHGen->_is_nil() )
1985 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1986 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1990 SUIT_OverrideCursor aWaitCursor;
1993 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1994 SMESH::SetName( pObj, aName );
1995 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1997 // First, remove old algos in order to avoid messages on algorithm hiding
1998 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2000 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2002 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2003 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2004 if ( anAlgoVar->_is_nil() || // no new algo selected or
2005 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2007 // remove old algorithm
2008 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2009 myObjHyps[ dim ][ Algo ].clear();
2014 // Assign new algorithms and hypotheses
2015 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2017 if ( !isAccessibleDim( dim )) continue;
2019 // find or create algorithm
2020 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2022 // assign new algorithm
2023 if ( !anAlgoVar->_is_nil() && // some algo selected and
2024 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2026 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2027 CORBA::Object_var anObject = aSObject->GetObject();
2028 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2029 bool isMesh = !aMeshVar->_is_nil();
2031 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2033 SMESH::SMESH_subMesh_var aVar =
2034 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2035 if ( !aVar->_is_nil() )
2036 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2038 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2041 // assign hypotheses
2042 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2044 int aNewHypIndex = currentHyp( dim, hypType );
2045 int anOldHypIndex = -1;
2047 // remove old hypotheses
2048 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2050 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2051 myExistingHyps[ dim ][ hypType ] );
2052 if ( aNewHypIndex != anOldHypIndex || // different hyps
2053 anOldHypIndex == -1 ) // hyps of different algos
2055 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2056 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2057 myObjHyps[ dim ][ hypType ].clear();
2061 // assign new hypotheses
2062 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2064 SMESH::SMESH_Mesh_var aMeshVar =
2065 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2066 bool isMesh = !aMeshVar->_is_nil();
2069 SMESH::AddHypothesisOnMesh
2070 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2074 SMESH::SMESH_subMesh_var aVar =
2075 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2076 if ( !aVar->_is_nil() )
2077 SMESH::AddHypothesisOnSubMesh
2078 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2081 // reread all hypotheses of mesh if necessary
2082 QStringList anExisting;
2083 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2090 //================================================================================
2092 * \brief Verifies whether given operator is valid for this one
2093 * \param theOtherOp - other operation
2094 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2096 * method redefined from base class verifies whether given operator is valid for
2097 * this one (i.e. can be started "above" this operator). In current implementation method
2098 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2101 //================================================================================
2102 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2104 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2107 //================================================================================
2109 * \brief SLOT. Is called when the user selects a way of geometry selection
2110 * \param theByMesh - true if the user wants to find geometry by mesh element
2112 //================================================================================
2114 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2117 if ( !myShapeByMeshOp ) {
2118 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2119 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2120 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2121 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2122 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2124 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2125 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2126 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2127 SMESH::SMESH_Mesh_var aMeshVar =
2128 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2129 if ( !aMeshVar->_is_nil() ) {
2130 myDlg->hide(); // stop processing selection
2131 myShapeByMeshOp->setModule( getSMESHGUI() );
2132 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2133 myShapeByMeshOp->SetMesh( aMeshVar );
2134 myShapeByMeshOp->start();
2140 //================================================================================
2142 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2144 //================================================================================
2146 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2148 if ( myShapeByMeshOp == op ) {
2149 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2151 // Select a found geometry object
2152 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2153 if ( !aGeomVar->_is_nil() )
2155 QString ID = aGeomVar->GetStudyEntry();
2156 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2157 selectObject( aGeomSO );
2164 //================================================================================
2166 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2168 //================================================================================
2170 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2172 if ( myShapeByMeshOp == op && myDlg ) {
2177 //================================================================================
2179 * \brief Selects a SObject
2180 * \param theSObj - the SObject to select
2182 //================================================================================
2184 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2186 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2187 SALOME_ListIO anIOList;
2189 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2190 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2191 anIOList.Append( anIO );
2193 sm->setSelectedObjects( anIOList, false );