1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MeshOp.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshOp.h"
30 #include "SMESHGUI_MeshDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Hypotheses.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_NumberFilter.hxx>
40 // SALOME GEOM includes
41 #include <GEOM_SelectionFilter.h>
43 #include <GeometryGUI.h>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SALOME_InteractiveObject.hxx>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDS_SComponent.hxx>
57 #include <SALOMEDS_SObject.hxx>
60 #include <QStringList>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Shell.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <BRep_Tool.hxx>
71 #include <SALOMEconfig.h>
72 #include CORBA_CLIENT_HEADER(SMESH_Gen)
74 //To disable automatic genericobj management, the following line should be commented.
75 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
76 #define WITHGENERICOBJ
78 //================================================================================
81 * \param theToCreate - if this parameter is true then operation is used for creation,
82 * for editing otherwise
84 * Initialize operation
86 //================================================================================
87 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
88 : SMESHGUI_SelectionOp(),
89 myToCreate( theToCreate ),
90 myIsMesh( theIsMesh ),
95 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
96 GeometryGUI::InitGeomGen();
97 myIsOnGeometry = true;
100 //================================================================================
104 //================================================================================
105 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
111 //================================================================================
113 * \brief Gets dialog of this operation
114 * \retval LightApp_Dialog* - pointer to dialog of this operation
116 //================================================================================
117 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
122 //================================================================================
124 * \brief Creates or edits mesh
125 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
127 * Virtual slot redefined from the base class called when "Apply" button is clicked
128 * creates or edits mesh
130 //================================================================================
131 bool SMESHGUI_MeshOp::onApply()
137 if ( !isValid( aMess ) )
141 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
145 bool aResult = false;
149 if ( myToCreate && myIsMesh )
150 aResult = createMesh( aMess );
151 if ( myToCreate && !myIsMesh )
152 aResult = createSubMesh( aMess );
153 else if ( !myToCreate )
154 aResult = editMeshOrSubMesh( aMess );
157 SMESHGUI::Modified();
158 update( UF_ObjBrowser | UF_Model );
161 catch ( const SALOME::SALOME_Exception& S_ex )
163 SalomeApp_Tools::QtCatchCorbaException( S_ex );
179 aMess = tr( "SMESH_OPERATION_FAILED" );
180 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
186 //================================================================================
188 * \brief Creates dialog if necessary and shows it
190 * Virtual method redefined from base class called when operation is started creates
191 * dialog if necessary and shows it, activates selection
193 //================================================================================
194 void SMESHGUI_MeshOp::startOperation()
198 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
199 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
201 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
202 this, SLOT( onCreateHyp( const int, const int ) ) );
203 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
204 this, SLOT( onEditHyp( const int, const int ) ) );
205 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
206 this, SLOT( onAlgoSelected( const int ) ) );
208 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
209 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
212 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
213 else myHelpFileName = "constructing_submeshes_page.html";
214 else myHelpFileName = "editing_meshes_page.html";
216 SMESHGUI_SelectionOp::startOperation();
218 // iterate through dimensions and get available algoritms, set them to the dialog
219 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
220 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
222 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
224 // clear available hypotheses
225 aTab->setAvailableHyps( MainHyp, hypList );
226 aTab->setAvailableHyps( AddHyp, hypList );
227 aTab->setExistingHyps( MainHyp, hypList );
228 aTab->setExistingHyps( AddHyp, hypList );
229 myExistingHyps[ i ][ MainHyp ].clear();
230 myExistingHyps[ i ][ AddHyp ].clear();
232 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
233 aTab->setAvailableHyps( Algo, hypList );
238 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
241 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
243 myDlg->setCurrentTab( SMESH::DIM_3D );
248 myIgnoreAlgoSelection = false;
251 //================================================================================
253 * \brief Creates selection filter
254 * \param theId - identifier of current selection widget
255 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
257 * Creates selection filter in accordance with identifier of current selection widget
259 //================================================================================
260 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
262 if ( theId == SMESHGUI_MeshDlg::Geom )
264 // TColStd_MapOfInteger allTypesMap;
265 // for ( int i = 0; i < 10; i++ )
266 // allTypesMap.Add( i );
267 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
268 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
270 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
271 return new SMESH_TypeFilter( MESHorSUBMESH );
272 else if ( theId == SMESHGUI_MeshDlg::Mesh )
273 return new SMESH_TypeFilter( MESH );
278 //================================================================================
280 * \brief check if selected shape is a subshape of the shape to mesh
281 * \retval bool - check result
283 //================================================================================
284 bool SMESHGUI_MeshOp::isSubshapeOk() const
286 if ( !myToCreate || myIsMesh ) // not submesh creation
290 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
291 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
292 if (!pMesh) return false;
294 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
295 if (mesh->_is_nil()) return false;
297 // main shape of the mesh
298 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
299 if (mainGeom->_is_nil()) return false;
303 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
305 if (aGEOMs.count() > 0) {
306 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
307 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
308 if (geomGen->_is_nil() || !aStudy) return false;
310 GEOM::GEOM_IGroupOperations_var op =
311 geomGen->GetIGroupOperations(aStudy->StudyId());
312 if (op->_is_nil()) return false;
314 // check all selected shapes
315 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
316 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
317 QString aSubGeomEntry = (*aSubShapesIter);
318 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
319 if (!pSubGeom) return false;
321 GEOM::GEOM_Object_var aSubGeomVar =
322 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
323 if (aSubGeomVar->_is_nil()) return false;
325 // skl for NPAL14695 - implementation of searching of mainObj
326 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
327 //if (mainObj->_is_nil() ||
328 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
330 if (mainObj->_is_nil())
332 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
334 mainObj = op->GetMainShape(mainObj);
343 //================================================================================
345 * \brief Return name of the algorithm that does not support submeshes and makes
346 * submesh creation useless
347 * \retval char* - string is to be deleted!!!
349 //================================================================================
350 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
352 if ( myToCreate && !myIsMesh ) {
354 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
355 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
356 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
359 QStringList algoNames;
361 existingHyps(3, Algo, pMesh, algoNames, algoList);
362 if (!algoList.empty()) {
363 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
365 algo->InputTypes.empty() && // builds all dimensions it-self
366 !algo->IsSupportSubmeshes )
367 return CORBA::string_dup( algoNames[0].toLatin1().data() );
370 // GEOM::GEOM_Object_var geom;
371 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
372 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
374 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
375 existingHyps(2, Algo, pMesh, algoNames, algoList);
376 if (!algoList.empty()) {
377 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
379 algo->InputTypes.empty() && // builds all dimensions it-self
380 !algo->IsSupportSubmeshes )
381 return CORBA::string_dup( algoNames[0].toLatin1().data() );
389 //================================================================================
391 * \brief find an existing submesh by the selected shape
392 * \retval _PTR(SObject) - the found submesh SObject
394 //================================================================================
395 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
397 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
398 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
399 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
400 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
401 if ( pMesh && pGeom ) {
402 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
403 if ( !geom->_is_nil() ) {
405 switch ( geom->GetShapeType() ) {
406 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
407 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
408 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
409 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
410 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
411 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
412 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
415 _PTR(GenericAttribute) anAttr;
416 _PTR(SObject) aSubmeshRoot;
417 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
418 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
420 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
421 for ( ; smIter->More(); smIter->Next() )
423 _PTR(SObject) aSmObj = smIter->Value();
424 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
426 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
427 for ( ; anIter1->More(); anIter1->Next()) {
428 _PTR(SObject) pGeom2 = anIter1->Value();
429 if ( pGeom2->ReferencedObject( pGeom2 ) &&
430 pGeom2->GetID() == pGeom->GetID() )
437 return _PTR(SObject)();
440 //================================================================================
442 * \brief Updates dialog's look and feel
444 * Virtual method redefined from the base class updates dialog's look and feel
446 //================================================================================
447 void SMESHGUI_MeshOp::selectionDone()
449 if (!dlg()->isVisible() || !myDlg->isEnabled())
452 SMESHGUI_SelectionOp::selectionDone();
456 myIsOnGeometry = true;
458 //Check geometry for mesh
459 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
460 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
463 SMESH::SMESH_Mesh_var aMeshVar =
464 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
465 if (!aMeshVar->_is_nil()) {
466 if (!myToCreate && !aMeshVar->HasShapeToMesh())
467 myIsOnGeometry = false;
473 // Enable tabs according to shape dimension
478 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
479 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
481 if (aGEOMs.count() > 0) {
482 // one or more GEOM shape selected
483 aSeq->length(aGEOMs.count());
484 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
486 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
487 QString aSubGeomEntry = (*aSubShapesIter);
488 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
489 GEOM::GEOM_Object_var aSubGeomVar =
490 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
491 aSeq[iSubSh] = aSubGeomVar;
494 // get geometry by selected sub-mesh
495 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
496 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
497 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
498 if (!aGeomVar->_is_nil()) {
504 if (aSeq->length() > 0) {
506 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
507 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
508 switch ( aGeomVar->GetShapeType() ) {
509 case GEOM::SOLID: shapeDim = 3; break;
512 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
514 bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
515 shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
518 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
520 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
521 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
525 if (GEOMBase::GetShape(aGeomVar, aShape)) {
526 TopExp_Explorer exp (aShape, TopAbs_SHELL);
528 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
529 shapeDim = qMax(2, shapeDim);
530 for (; exp.More() && shapeDim == 2; exp.Next()) {
531 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
535 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
536 shapeDim = qMax(2, shapeDim);
537 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
538 shapeDim = qMax(1, shapeDim);
539 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
540 shapeDim = qMax(0, shapeDim);
546 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
547 // reset algos before disabling tabs (0020138)
548 onAlgoSelected(-1, i);
550 myDlg->setMaxHypoDim( shapeDim );
551 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
553 if (!myToCreate) // edition: read hypotheses
557 SMESH::SMESH_subMesh_var aVar =
558 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
559 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
560 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
561 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
562 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
563 myDlg->updateGeometry();
570 else if ( !myIsMesh ) // submesh creation
572 // if a submesh on the selected shape already exist, pass to submesh edition mode
573 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
574 SMESH::SMESH_subMesh_var sm =
575 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
576 bool editSubmesh = ( !sm->_is_nil() &&
577 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
578 tr( "EDIT_SUBMESH_QUESTION"),
579 SUIT_MessageBox::Yes |
581 SUIT_MessageBox::No )
582 == SUIT_MessageBox::Yes );
585 selectionMgr()->clearFilters();
586 selectObject( pSubmesh );
587 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
592 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
593 selectObject( _PTR(SObject)() );
598 // discard selected mesh if submesh creation not allowed because of
599 // a global algorithm that does not support submeshes
600 if ( char* algoName = isSubmeshIgnored() ) {
601 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
602 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
603 CORBA::string_free( algoName );
604 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
605 selectObject( _PTR(SObject)() );
610 // enable/disable popup for choice of geom selection way
612 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
613 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
614 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
615 if ( !mesh->_is_nil() )
616 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
618 myDlg->setGeomPopupEnabled( enable );
621 else { // no geometry defined
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 //================================================================================
741 static bool isCompatible(const HypothesisData* theAlgoData,
742 const HypothesisData* theHypData,
743 const int theHypType)
748 if ( theHypType == SMESHGUI_MeshOp::Algo )
749 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
752 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
755 //================================================================================
757 * \brief Gets available hypotheses or algorithms
758 * \param theDim - specifies dimension of returned hypotheses/algorifms
759 * \param theHypType - specifies whether algorims or hypotheses or additional ones
760 * are retrieved (possible values are in HypType enumeration)
761 * \param theHyps - Output list of hypotheses' names
762 * \param theAlgoData - to select hypos able to be used by this algo (optional)
764 * Gets available hypotheses or algorithm in accordance with input parameters
766 //================================================================================
767 void SMESHGUI_MeshOp::availableHyps( const int theDim,
768 const int theHypType,
769 QStringList& theHyps,
770 THypDataList& theDataList,
771 HypothesisData* theAlgoData ) const
775 bool isAlgo = ( theHypType == Algo );
776 bool isAux = ( theHypType == AddHyp );
777 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
779 QStringList::const_iterator anIter;
780 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
782 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
783 if ( isCompatible ( theAlgoData, aData, theHypType )) {
784 theDataList.append( aData );
785 theHyps.append( aData->Label );
790 //================================================================================
792 * \brief Gets existing hypotheses or algorithms
793 * \param theDim - specifies dimension of returned hypotheses/algorifms
794 * \param theHypType - specifies whether algorims or hypotheses or additional ones
795 * are retrieved (possible values are in HypType enumeration)
796 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
797 * \param theHyps - output list of names.
798 * \param theHypVars - output list of variables.
799 * \param theAlgoData - to select hypos able to be used by this algo (optional)
801 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
804 //================================================================================
805 void SMESHGUI_MeshOp::existingHyps( const int theDim,
806 const int theHypType,
807 _PTR(SObject) theFather,
808 QStringList& theHyps,
809 THypList& theHypList,
810 HypothesisData* theAlgoData)
812 // Clear hypoheses list
819 const bool isAux = ( theHypType == AddHyp );
821 _PTR(SObject) aHypRoot;
822 _PTR(GenericAttribute) anAttr;
823 _PTR(AttributeName) aName;
824 _PTR(AttributeIOR) anIOR;
826 bool isMesh = !_CAST( SComponent, theFather );
829 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
831 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
833 if ( theFather->FindSubObject( aPart, aHypRoot ) )
835 _PTR(ChildIterator) anIter =
836 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
837 for ( ; anIter->More(); anIter->Next() )
839 _PTR(SObject) anObj = anIter->Value();
840 if ( isMesh ) // i.e. mesh or submesh
842 _PTR(SObject) aRefObj;
843 if ( anObj->ReferencedObject( aRefObj ) )
848 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
851 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
852 if ( !CORBA::is_nil( aVar ) )
854 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
855 if ( !aHypVar->_is_nil() )
857 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
858 if ( !aData) continue;
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 //================================================================================
884 SMESH::SMESH_Hypothesis_var
885 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
886 const QString& aServerLib ) const
888 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
889 return SMESH::SMESH_Hypothesis::_nil();
891 const int nbColonsInMeshEntry = 3;
892 bool isSubMesh = myToCreate ?
894 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
896 // get mesh and geom object
897 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
898 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
903 anEntry = myDlg->selectedObject
904 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
905 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
907 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
908 if ( myToCreate ) // mesh and geom may be selected
910 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
911 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
912 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
913 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
915 else // edition: sub-mesh may be selected
917 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
918 if ( !sm->_is_nil() ) {
919 aMeshVar = sm->GetFather();
920 aGeomVar = sm->GetSubShape();
927 if ( !myToCreate ) // mesh to edit can be selected
929 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
930 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
932 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
933 if ( !aMeshVar->_is_nil() )
934 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
937 if ( aGeomVar->_is_nil() ) {
938 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
939 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
941 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
946 SMESH::SMESH_Hypothesis_var hyp =
947 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
948 aServerLib.toLatin1().data(),
951 /*byMesh = */isSubMesh);
952 if ( hyp->_is_nil() && isSubMesh )
953 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
954 aServerLib.toLatin1().data(),
961 //================================================================================
963 * \Brief Returns tab dimention
964 * \param tab - the tab in the dlg
965 * \param dlg - my dialogue
966 * \retval int - dimention
968 //================================================================================
969 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
972 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
973 if (tab == dlg->tab(i))
978 //================================================================================
980 * \brief Create hypothesis
981 * \param theHypType - hypothesis category (main or additional)
982 * \param theIndex - index of type of hypothesis to be cerated
984 * Specifies dimension of hypothesis to be created (using sender() method),
985 * specifies its type and calls method for hypothesis creation
987 //================================================================================
988 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
990 // Specifies dimension of hypothesis to be created
991 int aDim = getTabDim( sender(), myDlg );
995 // Specifies type of hypothesis to be created
996 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
997 if (theIndex < 0 || theIndex >= dataList.count())
999 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1001 // Create hypothesis
1002 createHypothesis(aDim, theHypType, aHypTypeName);
1007 QString GetUniqueName (const QStringList& theHypNames,
1008 const QString& theName,
1009 size_t theIteration = 1)
1011 QString aName = theName + "_" + QString::number( theIteration );
1012 if ( theHypNames.contains( aName ) )
1013 return GetUniqueName( theHypNames, theName, ++theIteration );
1018 //================================================================================
1020 * Create hypothesis and update dialog.
1021 * \param theDim - dimension of hypothesis to be created
1022 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1023 * \param theTypeName - specifies hypothesis to be created
1025 //================================================================================
1026 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1028 const QString& theTypeName)
1030 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1036 QStringList aHypNames;
1037 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1038 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1039 const TType2HypList& aType2HypList = aDimIter.value();
1040 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1041 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1042 const THypList& aHypList = aTypeIter.value();
1043 THypList::const_iterator anIter = aHypList.begin();
1044 for ( ; anIter != aHypList.end(); anIter++) {
1045 const THypItem& aHypItem = *anIter;
1046 const QString& aHypName = aHypItem.second;
1047 aHypNames.append(aHypName);
1051 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1054 bool dialog = false;
1056 QString aClientLibName = aData->ClientLibName;
1057 if (aClientLibName == "") {
1058 // Call hypothesis creation server method (without GUI)
1059 SMESH::SMESH_Hypothesis_var aHyp =
1060 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1061 #ifdef WITHGENERICOBJ
1062 if (!CORBA::is_nil(aHyp))
1066 // Get hypotheses creator client (GUI)
1068 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1069 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1071 // Create hypothesis
1073 // Get parameters appropriate to initialize a new hypothesis
1074 SMESH::SMESH_Hypothesis_var initParamHyp =
1075 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1077 removeCustomFilters(); // Issue 0020170
1079 // Get Entry of the Geom object
1080 QString aGeomEntry = "";
1081 QString aMeshEntry = "";
1082 QString anObjEntry = "";
1083 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1084 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1085 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1087 if ( myToCreate && myIsMesh )
1088 aMeshEntry = aGeomEntry;
1090 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1091 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1092 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1093 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1096 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1097 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1099 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1100 if ( !aGeomVar->_is_nil() )
1102 aGeomEntry = aGeomVar->GetStudyEntry();
1104 aMeshEntry = aGeomEntry;
1108 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1109 // take geometry from submesh being created
1110 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1112 // if current object is sub-mesh
1113 SMESH::SMESH_subMesh_var aSubMeshVar =
1114 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1115 if ( !aSubMeshVar->_is_nil() ) {
1116 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1117 if ( !aMeshVar->_is_nil() ) {
1118 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1119 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1120 if ( !aGeomVar->_is_nil() )
1121 aMeshEntry = aGeomVar->GetStudyEntry();
1127 aCreator->setShapeEntry( aGeomEntry );
1128 if ( aMeshEntry != "" )
1129 aCreator->setMainShapeEntry( aMeshEntry );
1130 myDlg->setEnabled( false );
1131 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1135 SMESH::SMESH_Hypothesis_var aHyp =
1136 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1137 #ifdef WITHGENERICOBJ
1138 if (!CORBA::is_nil(aHyp))
1148 //================================================================================
1150 * Necessary steps after hypothesis creation
1151 * \param result - creation result:
1154 * 2 = additional value meaning that slot is called not from dialog box
1156 //================================================================================
1157 void SMESHGUI_MeshOp::onHypoCreated( int result )
1161 int obj = myDlg->getActiveObject();
1162 onActivateObject( obj ); // Issue 0020170. Restore filters
1163 myDlg->setEnabled( true );
1166 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1168 int nbHyp = myExistingHyps[myDim][myType].count();
1169 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1170 QStringList aNewHyps;
1171 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1172 if (aNewHyps.count() > nbHyp)
1174 for (int i = nbHyp; i < aNewHyps.count(); i++)
1175 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1178 if( result!=2 && myHypoSet )
1182 //================================================================================
1184 * \brief Calls plugin methods for hypothesis editing
1185 * \param theHypType - specifies whether main hypothesis or additional one
1187 * \param theIndex - index of existing hypothesis
1189 * Calls plugin methods for hypothesis editing
1191 //================================================================================
1192 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1194 // Speicfies dimension of hypothesis to be created
1195 int aDim = getTabDim( sender(), myDlg );
1199 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1200 if ( theIndex < 0 || theIndex >= aList.count() )
1202 const THypItem& aHypItem = aList[ theIndex ];
1203 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1204 if ( aHyp->_is_nil() )
1207 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1210 // Get initial parameters
1211 SMESH::SMESH_Hypothesis_var initParamHyp =
1212 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1213 aCreator->setInitParamsHypothesis( initParamHyp );
1215 // Get Entry of the Geom object
1216 QString aGeomEntry = "";
1217 QString aMeshEntry = "";
1218 QString anObjEntry = "";
1219 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1220 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1221 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1223 if ( myToCreate && myIsMesh )
1224 aMeshEntry = aGeomEntry;
1226 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1227 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1228 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1229 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1232 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1233 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1235 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1236 if ( !aGeomVar->_is_nil() )
1238 aGeomEntry = aGeomVar->GetStudyEntry();
1240 aMeshEntry = aGeomEntry;
1244 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1245 // take geometry from submesh being created
1246 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1248 // if current object is sub-mesh
1249 SMESH::SMESH_subMesh_var aSubMeshVar =
1250 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1251 if ( !aSubMeshVar->_is_nil() ) {
1252 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1253 if ( !aMeshVar->_is_nil() ) {
1254 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1255 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1256 if ( !aGeomVar->_is_nil() )
1257 aMeshEntry = aGeomVar->GetStudyEntry();
1263 aCreator->setShapeEntry( aGeomEntry );
1264 if ( aMeshEntry != "" )
1265 aCreator->setMainShapeEntry( aMeshEntry );
1266 removeCustomFilters(); // Issue 0020170
1267 myDlg->setEnabled( false );
1268 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1272 //================================================================================
1274 * Necessary steps after hypothesis edition
1275 * \param result - creation result:
1279 //================================================================================
1280 void SMESHGUI_MeshOp::onHypoEdited( int result )
1282 int obj = myDlg->getActiveObject();
1283 onActivateObject( obj ); // Issue 0020170. Restore filters
1284 myDlg->setEnabled( true );
1287 //================================================================================
1289 * \brief access to hypothesis data
1290 * \param theDim - hyp dimension
1291 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1292 * \param theIndex - index in the list
1293 * \retval HypothesisData* - result data, may be 0
1295 //================================================================================
1296 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1297 const int theHypType,
1300 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1301 theHypType > -1 && theHypType < NbHypTypes &&
1302 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1303 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1307 //================================================================================
1309 * \brief Set available algos and hypos according to the selected algorithm
1310 * \param theIndex - algorithm index
1312 //================================================================================
1313 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1316 if ( myIgnoreAlgoSelection )
1319 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1323 // find highest available dimension, all algos of this dimension are available for choice
1325 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1326 if (isAccessibleDim( i ))
1331 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1333 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1334 HypothesisData* algoByDim[4];
1335 algoByDim[ aDim ] = algoData;
1337 QStringList anAvailable;
1338 if ( !algoData ) { // all algos becomes available
1339 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1340 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1343 // check that algorithms of other dimentions are compatible with
1346 // 2 loops: backward and forward from algo dimension
1347 for ( int forward = false; forward <= true; ++forward )
1349 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1351 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1353 HypothesisData* prevAlgo = algoData;
1354 bool noCompatible = false;
1355 for ( ; dim * dir <= lastDim * dir; dim += dir)
1357 if ( !isAccessibleDim( dim ))
1359 if ( noCompatible ) { // the selected algo has no compatible ones
1360 anAvailable.clear();
1361 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1362 myAvailableHypData[dim][Algo].clear();
1363 algoByDim[ dim ] = 0;
1366 // get currently selected algo
1367 int algoIndex = currentHyp( dim, Algo );
1368 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1369 if ( curAlgo ) { // some algo selected
1370 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1373 // set new available algoritms
1374 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1375 HypothesisData* soleCompatible = 0;
1376 if ( anAvailable.count() == 1 )
1377 soleCompatible = myAvailableHypData[dim][Algo][0];
1378 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1379 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1380 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1381 noCompatible = anAvailable.isEmpty();
1383 // restore previously selected algo
1384 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1385 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1386 // select the sole compatible algo
1387 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1388 setCurrentHyp( dim, Algo, algoIndex );
1390 // remember current algo
1391 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1395 // set hypotheses corresponding to the found algoritms
1397 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1399 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1401 if ( !isAccessibleDim( dim ))
1403 for ( int type = MainHyp; type < NbHypTypes; type++ )
1405 myAvailableHypData[ dim ][ type ].clear();
1406 QStringList anAvailable, anExisting;
1408 HypothesisData* curAlgo = algoByDim[ dim ];
1409 int hypIndex = currentHyp( dim, type );
1411 SMESH::SMESH_Hypothesis_var curHyp;
1412 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1413 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1415 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1416 // try to find algo by selected hypothesis in order to keep it selected
1417 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1418 CORBA::String_var curHypType = curHyp->GetName();
1419 if ( !algoDeselectedByUser &&
1420 myObjHyps[ dim ][ type ].count() > 0 &&
1421 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1423 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1424 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1425 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1426 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1433 // get hyps compatible with curAlgo
1436 // check if a selected hyp is compatible with the curAlgo
1437 if ( !curHyp->_is_nil() ) {
1438 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1439 if ( !isCompatible( curAlgo, hypData, type ))
1440 curHyp = SMESH::SMESH_Hypothesis::_nil();
1442 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1443 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1445 // set list of hypotheses
1446 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1447 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1449 // set current existing hypothesis
1450 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1451 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1454 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1455 // none is yet selected => select the sole existing if it is not optional
1456 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1457 bool isOptional = true;
1458 if ( algoByDim[ dim ] &&
1459 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1463 setCurrentHyp( dim, type, hypIndex );
1468 //================================================================================
1470 * \brief Creates and selects hypothesis of hypotheses set
1471 * \param theSetName - The name of hypotheses set
1473 //================================================================================
1474 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1476 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1481 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1482 setCurrentHyp(dim, Algo, -1);
1483 setCurrentHyp(dim, AddHyp, -1);
1484 setCurrentHyp(dim, MainHyp, -1);
1487 myHypoSet->init(true); //algorithms
1489 myHypoSet->init(false); //hypotheses
1494 //================================================================================
1496 * \brief One step of hypothesis/algorithm list creation
1498 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1500 //================================================================================
1501 void SMESHGUI_MeshOp::processSet()
1504 if( !myHypoSet->more() )
1507 bool isAlgo = myHypoSet->isAlgo();
1508 QString aHypoTypeName = myHypoSet->current();
1509 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1516 int aDim = aHypData->Dim[0];
1517 // create or/and set
1520 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1523 QStringList anAvailable;
1524 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1525 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1526 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1528 setCurrentHyp( aDim, Algo, index );
1529 onAlgoSelected( index, aDim );
1534 bool mainHyp = true;
1535 QStringList anAvailable;
1536 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1537 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1538 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1542 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1545 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1551 //================================================================================
1553 * \brief Creates mesh
1554 * \param theMess - Output parameter intended for returning error message
1555 * \retval bool - TRUE if mesh is created, FALSE otherwise
1559 //================================================================================
1560 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1564 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1565 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1568 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1569 QStringList::Iterator it = aList.begin();
1570 for ( ; it!=aList.end(); it++)
1572 QString aGeomEntry = *it;
1573 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1574 GEOM::GEOM_Object_var aGeomVar =
1575 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1577 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1578 if ( aSMESHGen->_is_nil() )
1581 SUIT_OverrideCursor aWaitCursor;
1584 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1585 if ( aMeshVar->_is_nil() )
1587 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1589 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1591 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1592 if ( !isAccessibleDim( aDim )) continue;
1594 // assign hypotheses
1595 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1596 int aHypIndex = currentHyp( aDim, aHypType );
1597 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1598 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1599 if ( !aHypVar->_is_nil() )
1600 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1603 // find or create algorithm
1604 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1605 if ( !anAlgoVar->_is_nil() )
1606 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1608 #ifdef WITHGENERICOBJ
1609 // obj has been published in study. Its refcount has been incremented.
1610 // It is safe to decrement its refcount
1611 // so that it will be destroyed when the entry in study will be removed
1613 aMeshVar->UnRegister();
1619 //================================================================================
1621 * \brief Creates sub-mesh
1622 * \param theMess - Output parameter intended for returning error message
1623 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1627 //================================================================================
1628 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1632 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1633 if ( aSMESHGen->_is_nil() )
1637 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1638 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1639 SMESH::SMESH_Mesh_var aMeshVar =
1640 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1641 if (aMeshVar->_is_nil())
1644 // GEOM shape of the main mesh
1645 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1647 // Name for the new sub-mesh
1648 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1651 GEOM::GEOM_Object_var aGeomVar;
1653 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1654 if (aGEOMs.count() == 1)
1656 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1657 QString aGeomEntry = aGEOMs.first();
1658 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1659 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1661 else if (aGEOMs.count() > 1)
1663 // create a GEOM group
1664 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1665 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1666 if (!geomGen->_is_nil() && aStudy) {
1667 GEOM::GEOM_IGroupOperations_var op =
1668 geomGen->GetIGroupOperations(aStudy->StudyId());
1669 if (!op->_is_nil()) {
1670 // check and add all selected GEOM objects: they must be
1671 // a sub-shapes of the main GEOM and must be of one type
1673 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1674 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1675 aSeq->length(aGEOMs.count());
1676 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1677 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1678 QString aSubGeomEntry = (*aSubShapesIter);
1679 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1680 GEOM::GEOM_Object_var aSubGeomVar =
1681 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1682 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1684 aGroupType = aSubShapeType;
1686 if (aSubShapeType != aGroupType)
1687 aGroupType = TopAbs_SHAPE;
1689 aSeq[iSubSh] = aSubGeomVar;
1692 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1693 op->UnionList(aGroupVar, aSeq);
1696 aGeomVar = aGroupVar;
1698 // publish the GEOM group in study
1699 QString aNewGeomGroupName ("Auto_group_for_");
1700 aNewGeomGroupName += aName;
1701 SALOMEDS::SObject_var aNewGroupSO =
1702 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1703 aNewGeomGroupName.toLatin1().data(), mainGeom);
1710 if (aGeomVar->_is_nil())
1713 SUIT_OverrideCursor aWaitCursor;
1716 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1717 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1719 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1721 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1723 if ( !isAccessibleDim( aDim )) continue;
1725 // find or create algorithm
1726 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1727 if ( !anAlgoVar->_is_nil() )
1728 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1729 // assign hypotheses
1730 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1732 int aHypIndex = currentHyp( aDim, aHypType );
1733 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1735 SMESH::SMESH_Hypothesis_var aHypVar =
1736 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1737 if ( !aHypVar->_is_nil() )
1738 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1743 // deselect geometry: next submesh should be created on other subshape
1744 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1745 selectObject( _PTR(SObject)() );
1751 //================================================================================
1753 * \brief Gets current hypothesis or algorithms
1754 * \param theDim - dimension of hypothesis or algorithm
1755 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1756 * \retval int - current hypothesis or algorithms
1758 * Gets current hypothesis or algorithms
1760 //================================================================================
1761 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1763 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1766 //================================================================================
1768 * \brief Returns true if hypotheses of given dim can be assigned
1769 * \param theDim - hypotheses dimension
1770 * \retval bool - result
1772 //================================================================================
1773 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1775 return myDlg->isTabEnabled( theDim );
1778 //================================================================================
1780 * \brief Sets current hypothesis or algorithms
1781 * \param theDim - dimension of hypothesis or algorithm
1782 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1783 * \param theIndex - Index of hypothesis
1785 * Gets current hypothesis or algorithms
1787 //================================================================================
1788 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1789 const int theHypType,
1790 const int theIndex )
1792 myIgnoreAlgoSelection = true;
1793 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1794 myIgnoreAlgoSelection = false;
1797 //================================================================================
1799 * \brief Generates default and sets mesh/submesh name
1801 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1803 //================================================================================
1804 void SMESHGUI_MeshOp::setDefaultName() const
1808 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1810 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1811 _PTR(SObject) anObj;
1814 aResName = aPrefix + QString::number( i++ );
1815 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1819 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1820 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1821 aControl->setText( aResName );
1824 //================================================================================
1826 * \brief Gets algorithm or creates it if necessary
1827 * \param theDim - specifies dimension of returned hypotheses/algorifms
1828 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1830 * Gets algorithm or creates it if necessary
1832 //================================================================================
1833 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1835 SMESH::SMESH_Hypothesis_var anAlgoVar;
1837 // get type of the selected algo
1838 int aHypIndex = currentHyp( theDim, Algo );
1839 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1840 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1842 QString aHypName = dataList[ aHypIndex ]->TypeName;
1844 // get existing algoritms
1845 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1847 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1849 // look for an existing algo of such a type
1850 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1851 THypList::iterator anIter = aHypVarList.begin();
1852 for ( ; anIter != aHypVarList.end(); anIter++)
1854 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1855 CORBA::String_var aName = aHypVar->GetName();
1856 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1858 anAlgoVar = aHypVar;
1863 if (anAlgoVar->_is_nil())
1865 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1868 QString aClientLibName = aHypData->ClientLibName;
1869 if (aClientLibName == "")
1871 // Call hypothesis creation server method (without GUI)
1872 SMESH::SMESH_Hypothesis_var aHyp =
1873 SMESH::CreateHypothesis(aHypName, aHypName, true);
1874 #ifdef WITHGENERICOBJ
1875 if (!CORBA::is_nil(aHyp))
1881 // Get hypotheses creator client (GUI)
1883 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1887 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1889 SMESH::SMESH_Hypothesis_var aHyp =
1890 SMESH::CreateHypothesis(aHypName, aHypName, true);
1891 #ifdef WITHGENERICOBJ
1892 if (!CORBA::is_nil(aHyp))
1897 QStringList tmpList;
1898 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1899 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1902 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1903 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1905 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1906 CORBA::String_var aName = aHypVar->GetName();
1907 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1909 anAlgoVar = aHypVar;
1915 return anAlgoVar._retn();
1918 //================================================================================
1920 * \brief Reads parameters of edited mesh and assigns them to the dialog
1922 * Reads parameters of edited mesh and assigns them to the dialog (called when
1923 * mesh is edited only)
1925 //================================================================================
1926 void SMESHGUI_MeshOp::readMesh()
1928 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1929 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1933 if (myIsOnGeometry) {
1934 // Get name of mesh if current object is sub-mesh
1935 SMESH::SMESH_subMesh_var aSubMeshVar =
1936 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1937 if ( !aSubMeshVar->_is_nil() )
1939 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1940 if ( !aMeshVar->_is_nil() )
1942 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1943 QString aMeshName = name( aMeshSO );
1944 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1948 // Get name of geometry object
1949 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1950 if ( !aGeomVar->_is_nil() )
1952 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1953 QString aShapeName = name( aGeomSO );
1954 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1958 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1959 QStringList anExisting;
1960 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1961 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1964 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1965 // find algo index among available ones
1967 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1969 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1970 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1971 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1972 // if ( aHypIndex < 0 && algoData ) {
1973 // // assigned algo is incompatible with other algorithms
1974 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1975 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1978 setCurrentHyp( dim, Algo, aHypIndex );
1979 // set existing and available hypothesis according to the selected algo
1980 onAlgoSelected( aHypIndex, dim );
1984 bool hypWithoutAlgo = false;
1985 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1987 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1990 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1991 // find index of requered hypothesis among existing ones for this dimension and type
1993 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1994 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1995 myExistingHyps[ dim ][ hypType ] );
1996 if ( aHypIndex < 0 ) {
1997 // assigned hypothesis is incompatible with the algorithm
1998 if ( currentHyp( dim, Algo ) < 0 )
1999 { // none algo selected; it is edition for sure, of submesh maybe
2000 hypWithoutAlgo = true;
2001 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2002 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2003 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2007 setCurrentHyp( dim, hypType, aHypIndex );
2010 // make available other hyps of same type as one without algo
2011 if ( hypWithoutAlgo )
2012 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2015 //================================================================================
2017 * \brief Gets name of object
2018 * \param theSO - SObject
2019 * \retval QString - name of object
2021 * Gets name of object
2023 //================================================================================
2024 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2029 _PTR(GenericAttribute) anAttr;
2030 _PTR(AttributeName) aNameAttr;
2031 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2034 aResName = aNameAttr->Value().c_str();
2040 //================================================================================
2042 * \brief Finds hypothesis in input list
2043 * \param theHyp - hypothesis to be found
2044 * \param theHypList - input list of hypotheses
2045 * \retval int - index of hypothesis or -1 if it is not found
2047 * Finds position of hypothesis in input list
2049 //================================================================================
2050 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2051 const THypList& theHypList ) const
2054 if ( !theHyp->_is_nil() )
2057 THypList::const_iterator anIter = theHypList.begin();
2058 for ( ; anIter != theHypList.end(); ++ anIter)
2060 if ( theHyp->_is_equivalent( (*anIter).first ) )
2071 //================================================================================
2073 * \brief Edits mesh or sub-mesh
2074 * \param theMess - Output parameter intended for returning error message
2075 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2077 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2079 //================================================================================
2080 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2084 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2085 if ( aSMESHGen->_is_nil() )
2088 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2089 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2093 SUIT_OverrideCursor aWaitCursor;
2096 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2097 SMESH::SetName( pObj, aName );
2098 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2100 // First, remove old algos in order to avoid messages on algorithm hiding
2101 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2103 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2105 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2106 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2107 if ( anAlgoVar->_is_nil() || // no new algo selected or
2108 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2110 // remove old algorithm
2111 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2112 myObjHyps[ dim ][ Algo ].clear();
2117 // Assign new algorithms and hypotheses
2118 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2120 if ( !isAccessibleDim( dim )) continue;
2122 // find or create algorithm
2123 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2125 // assign new algorithm
2126 if ( !anAlgoVar->_is_nil() && // some algo selected and
2127 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2129 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2130 CORBA::Object_var anObject = aSObject->GetObject();
2131 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2132 bool isMesh = !aMeshVar->_is_nil();
2134 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2136 SMESH::SMESH_subMesh_var aVar =
2137 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2138 if ( !aVar->_is_nil() )
2139 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2141 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2144 // assign hypotheses
2145 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2147 int aNewHypIndex = currentHyp( dim, hypType );
2148 int anOldHypIndex = -1;
2150 // remove old hypotheses
2151 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2153 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2154 myExistingHyps[ dim ][ hypType ] );
2155 if ( aNewHypIndex != anOldHypIndex || // different hyps
2156 anOldHypIndex == -1 ) // hyps of different algos
2158 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2159 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2160 myObjHyps[ dim ][ hypType ].clear();
2164 // assign new hypotheses
2165 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2167 SMESH::SMESH_Mesh_var aMeshVar =
2168 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2169 bool isMesh = !aMeshVar->_is_nil();
2172 SMESH::AddHypothesisOnMesh
2173 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2177 SMESH::SMESH_subMesh_var aVar =
2178 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2179 if ( !aVar->_is_nil() )
2180 SMESH::AddHypothesisOnSubMesh
2181 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2184 // reread all hypotheses of mesh if necessary
2185 QStringList anExisting;
2186 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2193 //================================================================================
2195 * \brief Verifies whether given operator is valid for this one
2196 * \param theOtherOp - other operation
2197 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2199 * method redefined from base class verifies whether given operator is valid for
2200 * this one (i.e. can be started "above" this operator). In current implementation method
2201 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2204 //================================================================================
2205 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2207 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2210 //================================================================================
2212 * \brief SLOT. Is called when the user selects a way of geometry selection
2213 * \param theByMesh - true if the user wants to find geometry by mesh element
2215 //================================================================================
2216 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2219 if ( !myShapeByMeshOp ) {
2220 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2221 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2222 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2223 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2224 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2226 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2227 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2228 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2229 SMESH::SMESH_Mesh_var aMeshVar =
2230 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2231 if ( !aMeshVar->_is_nil() ) {
2232 myDlg->hide(); // stop processing selection
2233 myShapeByMeshOp->setModule( getSMESHGUI() );
2234 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2235 myShapeByMeshOp->SetMesh( aMeshVar );
2236 myShapeByMeshOp->start();
2242 //================================================================================
2244 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2246 //================================================================================
2247 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2249 if ( myShapeByMeshOp == op ) {
2250 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2252 // Select a found geometry object
2253 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2254 if ( !aGeomVar->_is_nil() )
2256 QString ID = aGeomVar->GetStudyEntry();
2257 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2258 selectObject( aGeomSO );
2265 //================================================================================
2267 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2269 //================================================================================
2270 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2272 if ( myShapeByMeshOp == op && myDlg ) {
2277 //================================================================================
2279 * \brief Selects a SObject
2280 * \param theSObj - the SObject to select
2282 //================================================================================
2283 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2285 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2286 SALOME_ListIO anIOList;
2288 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2289 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2290 anIOList.Append( anIO );
2292 sm->setSelectedObjects( anIOList, false );