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->setHypoSets( SMESH::GetHypothesesSets() );
245 myDlg->setCurrentTab( SMESH::DIM_3D );
250 myIgnoreAlgoSelection = false;
253 //================================================================================
255 * \brief Creates selection filter
256 * \param theId - identifier of current selection widget
257 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
259 * Creates selection filter in accordance with identifier of current selection widget
261 //================================================================================
262 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
264 if ( theId == SMESHGUI_MeshDlg::Geom )
266 // TColStd_MapOfInteger allTypesMap;
267 // for ( int i = 0; i < 10; i++ )
268 // allTypesMap.Add( i );
269 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
270 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
272 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
273 return new SMESH_TypeFilter( MESHorSUBMESH );
274 else if ( theId == SMESHGUI_MeshDlg::Mesh )
275 return new SMESH_TypeFilter( MESH );
280 //================================================================================
282 * \brief check if selected shape is a subshape of the shape to mesh
283 * \retval bool - check result
285 //================================================================================
286 bool SMESHGUI_MeshOp::isSubshapeOk() const
288 if ( !myToCreate || myIsMesh ) // not submesh creation
292 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
293 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
294 if (!pMesh) return false;
296 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
297 if (mesh->_is_nil()) return false;
299 // main shape of the mesh
300 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
301 if (mainGeom->_is_nil()) return false;
305 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
307 if (aGEOMs.count() > 0) {
308 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
309 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
310 if (geomGen->_is_nil() || !aStudy) return false;
312 GEOM::GEOM_IGroupOperations_var op =
313 geomGen->GetIGroupOperations(aStudy->StudyId());
314 if (op->_is_nil()) return false;
316 // check all selected shapes
317 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
318 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
319 QString aSubGeomEntry = (*aSubShapesIter);
320 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
321 if (!pSubGeom) return false;
323 GEOM::GEOM_Object_var aSubGeomVar =
324 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
325 if (aSubGeomVar->_is_nil()) return false;
327 // skl for NPAL14695 - implementation of searching of mainObj
328 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
329 //if (mainObj->_is_nil() ||
330 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
332 if (mainObj->_is_nil())
334 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
336 mainObj = op->GetMainShape(mainObj);
345 //================================================================================
347 * \brief Return name of the algorithm that does not support submeshes and makes
348 * submesh creation useless
349 * \retval char* - string is to be deleted!!!
351 //================================================================================
352 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
354 if ( myToCreate && !myIsMesh ) {
356 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
357 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
358 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
361 QStringList algoNames;
363 existingHyps(3, Algo, pMesh, algoNames, algoList);
364 if (!algoList.empty()) {
365 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
367 algo->InputTypes.empty() && // builds all dimensions it-self
368 !algo->IsSupportSubmeshes )
369 return CORBA::string_dup( algoNames[0].toLatin1().data() );
372 // GEOM::GEOM_Object_var geom;
373 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
374 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
376 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
377 existingHyps(2, Algo, pMesh, algoNames, algoList);
378 if (!algoList.empty()) {
379 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
381 algo->InputTypes.empty() && // builds all dimensions it-self
382 !algo->IsSupportSubmeshes )
383 return CORBA::string_dup( algoNames[0].toLatin1().data() );
391 //================================================================================
393 * \brief find an existing submesh by the selected shape
394 * \retval _PTR(SObject) - the found submesh SObject
396 //================================================================================
397 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
399 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
400 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
401 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
402 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
403 if ( pMesh && pGeom ) {
404 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
405 if ( !geom->_is_nil() ) {
407 switch ( geom->GetShapeType() ) {
408 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
409 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
410 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
411 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
412 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
413 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
414 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
417 _PTR(GenericAttribute) anAttr;
418 _PTR(SObject) aSubmeshRoot;
419 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
420 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
422 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
423 for ( ; smIter->More(); smIter->Next() )
425 _PTR(SObject) aSmObj = smIter->Value();
426 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
428 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
429 for ( ; anIter1->More(); anIter1->Next()) {
430 _PTR(SObject) pGeom2 = anIter1->Value();
431 if ( pGeom2->ReferencedObject( pGeom2 ) &&
432 pGeom2->GetID() == pGeom->GetID() )
439 return _PTR(SObject)();
442 //================================================================================
444 * \brief Updates dialog's look and feel
446 * Virtual method redefined from the base class updates dialog's look and feel
448 //================================================================================
449 void SMESHGUI_MeshOp::selectionDone()
451 if (!dlg()->isVisible() || !myDlg->isEnabled())
454 SMESHGUI_SelectionOp::selectionDone();
458 myIsOnGeometry = true;
460 //Check geometry for mesh
461 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
462 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
465 SMESH::SMESH_Mesh_var aMeshVar =
466 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
467 if (!aMeshVar->_is_nil()) {
468 if (!myToCreate && !aMeshVar->HasShapeToMesh())
469 myIsOnGeometry = false;
475 // Enable tabs according to shape dimension
480 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
481 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
483 if (aGEOMs.count() > 0) {
484 // one or more GEOM shape selected
485 aSeq->length(aGEOMs.count());
486 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
488 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
489 QString aSubGeomEntry = (*aSubShapesIter);
490 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
491 GEOM::GEOM_Object_var aSubGeomVar =
492 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
493 aSeq[iSubSh] = aSubGeomVar;
496 // get geometry by selected sub-mesh
497 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
498 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
499 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
500 if (!aGeomVar->_is_nil()) {
506 if (aSeq->length() > 0) {
508 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
509 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
510 switch ( aGeomVar->GetShapeType() ) {
511 case GEOM::SOLID: shapeDim = 3; break;
514 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
516 bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
517 shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
520 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
522 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
523 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
527 if (GEOMBase::GetShape(aGeomVar, aShape)) {
528 TopExp_Explorer exp (aShape, TopAbs_SHELL);
530 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
531 shapeDim = qMax(2, shapeDim);
532 for (; exp.More() && shapeDim == 2; exp.Next()) {
533 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
537 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
538 shapeDim = qMax(2, shapeDim);
539 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
540 shapeDim = qMax(1, shapeDim);
541 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
542 shapeDim = qMax(0, shapeDim);
548 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
549 // reset algos before disabling tabs (0020138)
550 onAlgoSelected(-1, i);
552 myDlg->setMaxHypoDim( shapeDim );
555 if (!myToCreate) // edition: read hypotheses
559 SMESH::SMESH_subMesh_var aVar =
560 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
561 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
562 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
563 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
564 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
565 myDlg->updateGeometry();
572 else if ( !myIsMesh ) // submesh creation
574 // if a submesh on the selected shape already exist, pass to submesh edition mode
575 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
576 SMESH::SMESH_subMesh_var sm =
577 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
578 bool editSubmesh = ( !sm->_is_nil() &&
579 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
580 tr( "EDIT_SUBMESH_QUESTION"),
581 SUIT_MessageBox::Yes |
583 SUIT_MessageBox::No )
584 == SUIT_MessageBox::Yes );
587 selectionMgr()->clearFilters();
588 selectObject( pSubmesh );
589 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
594 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
595 selectObject( _PTR(SObject)() );
600 // discard selected mesh if submesh creation not allowed because of
601 // a global algorithm that does not support submeshes
602 if ( char* algoName = isSubmeshIgnored() ) {
603 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
604 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
605 CORBA::string_free( algoName );
606 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
607 selectObject( _PTR(SObject)() );
612 // enable/disable popup for choice of geom selection way
614 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
615 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
616 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
617 if ( !mesh->_is_nil() )
618 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
620 myDlg->setGeomPopupEnabled( enable );
624 myDlg->enableTab( SMESH::DIM_3D );
626 availableHyps( SMESH::DIM_3D, Algo, hypList,
627 myAvailableHypData[SMESH::DIM_3D][Algo]);
629 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
630 aTab->setAvailableHyps( Algo, hypList );
631 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
632 myDlg->disableTab(i);
634 //Hide labels and fields (Mesh ang Geometry)
635 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
636 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
641 catch ( const SALOME::SALOME_Exception& S_ex )
643 SalomeApp_Tools::QtCatchCorbaException( S_ex );
650 //================================================================================
652 * \brief Verifies validity of input data
653 * \param theMess - Output parameter intended for returning error message
654 * \retval bool - TRUE if input data is valid, false otherwise
656 * Verifies validity of input data. This method is called when "Apply" or "OK" button
657 * is pressed before mesh creation or editing.
659 //================================================================================
660 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
662 // Selected object to be edited
663 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
665 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
670 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
671 if ( aMeshName.isEmpty() )
673 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
677 /* // Imported mesh, if create sub-mesh or edit mesh
678 if ( !myToCreate || ( myToCreate && !myIsMesh ))
680 QString aMeshEntry = myDlg->selectedObject
681 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
682 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
683 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
684 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
685 theMess = tr( "IMPORTED_MESH" );
694 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
695 if ( aGeomEntry == "" )
697 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
700 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
701 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
703 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
708 if ( !myIsMesh ) // i.e sub-mesh creation,
710 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
711 if ( aMeshEntry == "" )
713 theMess = tr( "MESH_IS_NOT_DEFINED" );
716 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
717 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
719 theMess = tr( "MESH_IS_NULL" );
722 if ( !isSubshapeOk() )
724 theMess = tr( "INVALID_SUBSHAPE" );
733 //================================================================================
735 * \brief check compatibility of the algorithm and another algorithm or hypothesis
736 * \param theAlgoData - algorithm data
737 * \param theHypData - hypothesis data
738 * \param theHypType - hypothesis type
739 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
740 * \retval bool - check result
742 //================================================================================
743 static bool isCompatible(const HypothesisData* theAlgoData,
744 const HypothesisData* theHypData,
745 const int theHypType)
750 if ( theHypType == SMESHGUI_MeshOp::Algo )
751 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
754 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
757 //================================================================================
759 * \brief Gets available hypotheses or algorithms
760 * \param theDim - specifies dimension of returned hypotheses/algorifms
761 * \param theHypType - specifies whether algorims or hypotheses or additional ones
762 * are retrieved (possible values are in HypType enumeration)
763 * \param theHyps - Output list of hypotheses' names
764 * \param theAlgoData - to select hypos able to be used by this algo (optional)
766 * Gets available hypotheses or algorithm in accordance with input parameters
768 //================================================================================
769 void SMESHGUI_MeshOp::availableHyps( const int theDim,
770 const int theHypType,
771 QStringList& theHyps,
772 THypDataList& theDataList,
773 HypothesisData* theAlgoData ) const
777 bool isAlgo = ( theHypType == Algo );
778 bool isAux = ( theHypType == AddHyp );
779 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
781 QStringList::const_iterator anIter;
782 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
784 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
785 if ( isCompatible ( theAlgoData, aData, theHypType )) {
786 theDataList.append( aData );
787 theHyps.append( aData->Label );
792 //================================================================================
794 * \brief Gets existing hypotheses or algorithms
795 * \param theDim - specifies dimension of returned hypotheses/algorifms
796 * \param theHypType - specifies whether algorims or hypotheses or additional ones
797 * are retrieved (possible values are in HypType enumeration)
798 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
799 * \param theHyps - output list of names.
800 * \param theHypVars - output list of variables.
801 * \param theAlgoData - to select hypos able to be used by this algo (optional)
803 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
806 //================================================================================
807 void SMESHGUI_MeshOp::existingHyps( const int theDim,
808 const int theHypType,
809 _PTR(SObject) theFather,
810 QStringList& theHyps,
811 THypList& theHypList,
812 HypothesisData* theAlgoData)
814 // Clear hypoheses list
821 const bool isAux = ( theHypType == AddHyp );
823 _PTR(SObject) aHypRoot;
824 _PTR(GenericAttribute) anAttr;
825 _PTR(AttributeName) aName;
826 _PTR(AttributeIOR) anIOR;
828 bool isMesh = !_CAST( SComponent, theFather );
831 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
833 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
835 if ( theFather->FindSubObject( aPart, aHypRoot ) )
837 _PTR(ChildIterator) anIter =
838 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
839 for ( ; anIter->More(); anIter->Next() )
841 _PTR(SObject) anObj = anIter->Value();
842 if ( isMesh ) // i.e. mesh or submesh
844 _PTR(SObject) aRefObj;
845 if ( anObj->ReferencedObject( aRefObj ) )
850 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
853 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
854 if ( !CORBA::is_nil( aVar ) )
856 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
857 if ( !aHypVar->_is_nil() )
859 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
860 if ( !aData) continue;
861 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
862 ( isCompatible ( theAlgoData, aData, theHypType )) &&
863 ( isAux == aData->IsAux ))
865 std::string aHypName = aName->Value();
866 theHyps.append( aHypName.c_str() );
867 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
876 //================================================================================
878 * \brief If create or edit a submesh, return a hypothesis holding parameters used
880 * \param aHypType - The hypothesis type name
881 * \param aServerLib - Server library name
882 * \param hypData - The structure holding the hypothesis type etc.
883 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
885 //================================================================================
886 SMESH::SMESH_Hypothesis_var
887 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
888 const QString& aServerLib ) const
890 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
891 return SMESH::SMESH_Hypothesis::_nil();
893 const int nbColonsInMeshEntry = 3;
894 bool isSubMesh = myToCreate ?
896 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
898 // get mesh and geom object
899 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
900 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
905 anEntry = myDlg->selectedObject
906 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
907 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
909 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
910 if ( myToCreate ) // mesh and geom may be selected
912 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
913 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
914 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
915 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
917 else // edition: sub-mesh may be selected
919 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
920 if ( !sm->_is_nil() ) {
921 aMeshVar = sm->GetFather();
922 aGeomVar = sm->GetSubShape();
929 if ( !myToCreate ) // mesh to edit can be selected
931 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
932 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
934 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
935 if ( !aMeshVar->_is_nil() )
936 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
939 if ( aGeomVar->_is_nil() ) {
940 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
941 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
943 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
948 SMESH::SMESH_Hypothesis_var hyp =
949 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
950 aServerLib.toLatin1().data(),
953 /*byMesh = */isSubMesh);
954 if ( hyp->_is_nil() && isSubMesh )
955 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
956 aServerLib.toLatin1().data(),
963 //================================================================================
965 * \Brief Returns tab dimention
966 * \param tab - the tab in the dlg
967 * \param dlg - my dialogue
968 * \retval int - dimention
970 //================================================================================
971 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
974 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
975 if (tab == dlg->tab(i))
980 //================================================================================
982 * \brief Create hypothesis
983 * \param theHypType - hypothesis category (main or additional)
984 * \param theIndex - index of type of hypothesis to be cerated
986 * Specifies dimension of hypothesis to be created (using sender() method),
987 * specifies its type and calls method for hypothesis creation
989 //================================================================================
990 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
992 // Specifies dimension of hypothesis to be created
993 int aDim = getTabDim( sender(), myDlg );
997 // Specifies type of hypothesis to be created
998 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
999 if (theIndex < 0 || theIndex >= dataList.count())
1001 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1003 // Create hypothesis
1004 createHypothesis(aDim, theHypType, aHypTypeName);
1009 QString GetUniqueName (const QStringList& theHypNames,
1010 const QString& theName,
1011 size_t theIteration = 1)
1013 QString aName = theName + "_" + QString::number( theIteration );
1014 if ( theHypNames.contains( aName ) )
1015 return GetUniqueName( theHypNames, theName, ++theIteration );
1020 //================================================================================
1022 * Create hypothesis and update dialog.
1023 * \param theDim - dimension of hypothesis to be created
1024 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1025 * \param theTypeName - specifies hypothesis to be created
1027 //================================================================================
1028 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1030 const QString& theTypeName)
1032 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1038 QStringList aHypNames;
1039 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1040 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1041 const TType2HypList& aType2HypList = aDimIter.value();
1042 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1043 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1044 const THypList& aHypList = aTypeIter.value();
1045 THypList::const_iterator anIter = aHypList.begin();
1046 for ( ; anIter != aHypList.end(); anIter++) {
1047 const THypItem& aHypItem = *anIter;
1048 const QString& aHypName = aHypItem.second;
1049 aHypNames.append(aHypName);
1053 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1056 bool dialog = false;
1058 QString aClientLibName = aData->ClientLibName;
1059 if (aClientLibName == "") {
1060 // Call hypothesis creation server method (without GUI)
1061 SMESH::SMESH_Hypothesis_var aHyp =
1062 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1063 #ifdef WITHGENERICOBJ
1064 if (!CORBA::is_nil(aHyp))
1068 // Get hypotheses creator client (GUI)
1070 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1071 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1073 // Create hypothesis
1075 // Get parameters appropriate to initialize a new hypothesis
1076 SMESH::SMESH_Hypothesis_var initParamHyp =
1077 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1079 removeCustomFilters(); // Issue 0020170
1081 // Get Entry of the Geom object
1082 QString aGeomEntry = "";
1083 QString aMeshEntry = "";
1084 QString anObjEntry = "";
1085 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1086 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1087 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1089 if ( myToCreate && myIsMesh )
1090 aMeshEntry = aGeomEntry;
1092 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1093 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1094 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1095 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1098 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1099 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1101 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1102 if ( !aGeomVar->_is_nil() )
1104 aGeomEntry = aGeomVar->GetStudyEntry();
1106 aMeshEntry = aGeomEntry;
1110 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1111 // take geometry from submesh being created
1112 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1114 // if current object is sub-mesh
1115 SMESH::SMESH_subMesh_var aSubMeshVar =
1116 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1117 if ( !aSubMeshVar->_is_nil() ) {
1118 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1119 if ( !aMeshVar->_is_nil() ) {
1120 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1121 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1122 if ( !aGeomVar->_is_nil() )
1123 aMeshEntry = aGeomVar->GetStudyEntry();
1129 aCreator->setShapeEntry( aGeomEntry );
1130 if ( aMeshEntry != "" )
1131 aCreator->setMainShapeEntry( aMeshEntry );
1132 myDlg->setEnabled( false );
1133 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1137 SMESH::SMESH_Hypothesis_var aHyp =
1138 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1139 #ifdef WITHGENERICOBJ
1140 if (!CORBA::is_nil(aHyp))
1150 //================================================================================
1152 * Necessary steps after hypothesis creation
1153 * \param result - creation result:
1156 * 2 = additional value meaning that slot is called not from dialog box
1158 //================================================================================
1159 void SMESHGUI_MeshOp::onHypoCreated( int result )
1163 int obj = myDlg->getActiveObject();
1164 onActivateObject( obj ); // Issue 0020170. Restore filters
1165 myDlg->setEnabled( true );
1168 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1170 int nbHyp = myExistingHyps[myDim][myType].count();
1171 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1172 QStringList aNewHyps;
1173 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1174 if (aNewHyps.count() > nbHyp)
1176 for (int i = nbHyp; i < aNewHyps.count(); i++)
1177 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1180 if( result!=2 && myHypoSet )
1184 //================================================================================
1186 * \brief Calls plugin methods for hypothesis editing
1187 * \param theHypType - specifies whether main hypothesis or additional one
1189 * \param theIndex - index of existing hypothesis
1191 * Calls plugin methods for hypothesis editing
1193 //================================================================================
1194 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1196 // Speicfies dimension of hypothesis to be created
1197 int aDim = getTabDim( sender(), myDlg );
1201 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1202 if ( theIndex < 0 || theIndex >= aList.count() )
1204 const THypItem& aHypItem = aList[ theIndex ];
1205 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1206 if ( aHyp->_is_nil() )
1209 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1212 // Get initial parameters
1213 SMESH::SMESH_Hypothesis_var initParamHyp =
1214 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1215 aCreator->setInitParamsHypothesis( initParamHyp );
1217 // Get Entry of the Geom object
1218 QString aGeomEntry = "";
1219 QString aMeshEntry = "";
1220 QString anObjEntry = "";
1221 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1222 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1223 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1225 if ( myToCreate && myIsMesh )
1226 aMeshEntry = aGeomEntry;
1228 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1229 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1230 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1231 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1234 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1235 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1237 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1238 if ( !aGeomVar->_is_nil() )
1240 aGeomEntry = aGeomVar->GetStudyEntry();
1242 aMeshEntry = aGeomEntry;
1246 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1247 // take geometry from submesh being created
1248 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1250 // if current object is sub-mesh
1251 SMESH::SMESH_subMesh_var aSubMeshVar =
1252 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1253 if ( !aSubMeshVar->_is_nil() ) {
1254 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1255 if ( !aMeshVar->_is_nil() ) {
1256 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1257 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1258 if ( !aGeomVar->_is_nil() )
1259 aMeshEntry = aGeomVar->GetStudyEntry();
1265 aCreator->setShapeEntry( aGeomEntry );
1266 if ( aMeshEntry != "" )
1267 aCreator->setMainShapeEntry( aMeshEntry );
1268 removeCustomFilters(); // Issue 0020170
1269 myDlg->setEnabled( false );
1270 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1274 //================================================================================
1276 * Necessary steps after hypothesis edition
1277 * \param result - creation result:
1281 //================================================================================
1282 void SMESHGUI_MeshOp::onHypoEdited( int result )
1284 int obj = myDlg->getActiveObject();
1285 onActivateObject( obj ); // Issue 0020170. Restore filters
1286 myDlg->setEnabled( true );
1289 //================================================================================
1291 * \brief access to hypothesis data
1292 * \param theDim - hyp dimension
1293 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1294 * \param theIndex - index in the list
1295 * \retval HypothesisData* - result data, may be 0
1297 //================================================================================
1298 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1299 const int theHypType,
1302 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1303 theHypType > -1 && theHypType < NbHypTypes &&
1304 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1305 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1309 //================================================================================
1311 * \brief Set available algos and hypos according to the selected algorithm
1312 * \param theIndex - algorithm index
1314 //================================================================================
1315 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1318 if ( myIgnoreAlgoSelection )
1321 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1325 // find highest available dimension, all algos of this dimension are available for choice
1327 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1328 if (isAccessibleDim( i ))
1333 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1335 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1336 HypothesisData* algoByDim[4];
1337 algoByDim[ aDim ] = algoData;
1339 QStringList anAvailable;
1340 if ( !algoData ) { // all algos becomes available
1341 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1342 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1345 // check that algorithms of other dimentions are compatible with
1348 // 2 loops: backward and forward from algo dimension
1349 for ( int forward = false; forward <= true; ++forward )
1351 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1353 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1355 HypothesisData* prevAlgo = algoData;
1356 bool noCompatible = false;
1357 for ( ; dim * dir <= lastDim * dir; dim += dir)
1359 if ( !isAccessibleDim( dim ))
1361 if ( noCompatible ) { // the selected algo has no compatible ones
1362 anAvailable.clear();
1363 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1364 myAvailableHypData[dim][Algo].clear();
1365 algoByDim[ dim ] = 0;
1368 // get currently selected algo
1369 int algoIndex = currentHyp( dim, Algo );
1370 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1371 if ( curAlgo ) { // some algo selected
1372 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1375 // set new available algoritms
1376 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1377 HypothesisData* soleCompatible = 0;
1378 if ( anAvailable.count() == 1 )
1379 soleCompatible = myAvailableHypData[dim][Algo][0];
1380 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1381 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1382 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1383 noCompatible = anAvailable.isEmpty();
1385 // restore previously selected algo
1386 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1387 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1388 // select the sole compatible algo
1389 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1390 setCurrentHyp( dim, Algo, algoIndex );
1392 // remember current algo
1393 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1397 // set hypotheses corresponding to the found algoritms
1399 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1401 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1403 if ( !isAccessibleDim( dim ))
1405 for ( int type = MainHyp; type < NbHypTypes; type++ )
1407 myAvailableHypData[ dim ][ type ].clear();
1408 QStringList anAvailable, anExisting;
1410 HypothesisData* curAlgo = algoByDim[ dim ];
1411 int hypIndex = currentHyp( dim, type );
1413 SMESH::SMESH_Hypothesis_var curHyp;
1414 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1415 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1417 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1418 // try to find algo by selected hypothesis in order to keep it selected
1419 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1420 CORBA::String_var curHypType = curHyp->GetName();
1421 if ( !algoDeselectedByUser &&
1422 myObjHyps[ dim ][ type ].count() > 0 &&
1423 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1425 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1426 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1427 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1428 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1435 // get hyps compatible with curAlgo
1438 // check if a selected hyp is compatible with the curAlgo
1439 if ( !curHyp->_is_nil() ) {
1440 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1441 if ( !isCompatible( curAlgo, hypData, type ))
1442 curHyp = SMESH::SMESH_Hypothesis::_nil();
1444 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1445 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1447 // set list of hypotheses
1448 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1449 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1451 // set current existing hypothesis
1452 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1453 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1456 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1457 // none is yet selected => select the sole existing if it is not optional
1458 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1459 bool isOptional = true;
1460 if ( algoByDim[ dim ] &&
1461 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1465 setCurrentHyp( dim, type, hypIndex );
1470 //================================================================================
1472 * \brief Creates and selects hypothesis of hypotheses set
1473 * \param theSetName - The name of hypotheses set
1475 //================================================================================
1476 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1478 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1483 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1484 setCurrentHyp(dim, Algo, -1);
1485 setCurrentHyp(dim, AddHyp, -1);
1486 setCurrentHyp(dim, MainHyp, -1);
1489 myHypoSet->init(true); //algorithms
1491 myHypoSet->init(false); //hypotheses
1496 //================================================================================
1498 * \brief One step of hypothesis/algorithm list creation
1500 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1502 //================================================================================
1503 void SMESHGUI_MeshOp::processSet()
1506 if( !myHypoSet->more() )
1509 bool isAlgo = myHypoSet->isAlgo();
1510 QString aHypoTypeName = myHypoSet->current();
1511 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1518 int aDim = aHypData->Dim[0];
1519 // create or/and set
1522 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1525 QStringList anAvailable;
1526 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1527 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1528 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1530 setCurrentHyp( aDim, Algo, index );
1531 onAlgoSelected( index, aDim );
1536 bool mainHyp = true;
1537 QStringList anAvailable;
1538 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1539 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1540 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1544 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1547 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1553 //================================================================================
1555 * \brief Creates mesh
1556 * \param theMess - Output parameter intended for returning error message
1557 * \retval bool - TRUE if mesh is created, FALSE otherwise
1561 //================================================================================
1562 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1566 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1567 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1570 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1571 QStringList::Iterator it = aList.begin();
1572 for ( ; it!=aList.end(); it++)
1574 QString aGeomEntry = *it;
1575 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1576 GEOM::GEOM_Object_var aGeomVar =
1577 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1579 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1580 if ( aSMESHGen->_is_nil() )
1583 SUIT_OverrideCursor aWaitCursor;
1586 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1587 if ( aMeshVar->_is_nil() )
1589 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1591 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1593 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1594 if ( !isAccessibleDim( aDim )) continue;
1596 // assign hypotheses
1597 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1598 int aHypIndex = currentHyp( aDim, aHypType );
1599 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1600 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1601 if ( !aHypVar->_is_nil() )
1602 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1605 // find or create algorithm
1606 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1607 if ( !anAlgoVar->_is_nil() )
1608 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1610 #ifdef WITHGENERICOBJ
1611 // obj has been published in study. Its refcount has been incremented.
1612 // It is safe to decrement its refcount
1613 // so that it will be destroyed when the entry in study will be removed
1615 aMeshVar->Destroy();
1621 //================================================================================
1623 * \brief Creates sub-mesh
1624 * \param theMess - Output parameter intended for returning error message
1625 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1629 //================================================================================
1630 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1634 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1635 if ( aSMESHGen->_is_nil() )
1639 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1640 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1641 SMESH::SMESH_Mesh_var aMeshVar =
1642 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1643 if (aMeshVar->_is_nil())
1646 // GEOM shape of the main mesh
1647 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1649 // Name for the new sub-mesh
1650 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1653 GEOM::GEOM_Object_var aGeomVar;
1655 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1656 if (aGEOMs.count() == 1)
1658 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1659 QString aGeomEntry = aGEOMs.first();
1660 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1661 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1663 else if (aGEOMs.count() > 1)
1665 // create a GEOM group
1666 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1667 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1668 if (!geomGen->_is_nil() && aStudy) {
1669 GEOM::GEOM_IGroupOperations_var op =
1670 geomGen->GetIGroupOperations(aStudy->StudyId());
1671 if (!op->_is_nil()) {
1672 // check and add all selected GEOM objects: they must be
1673 // a sub-shapes of the main GEOM and must be of one type
1675 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1676 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1677 aSeq->length(aGEOMs.count());
1678 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1679 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1680 QString aSubGeomEntry = (*aSubShapesIter);
1681 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1682 GEOM::GEOM_Object_var aSubGeomVar =
1683 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1684 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1686 aGroupType = aSubShapeType;
1688 if (aSubShapeType != aGroupType)
1689 aGroupType = TopAbs_SHAPE;
1691 aSeq[iSubSh] = aSubGeomVar;
1694 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1695 op->UnionList(aGroupVar, aSeq);
1698 aGeomVar = aGroupVar;
1700 // publish the GEOM group in study
1701 QString aNewGeomGroupName ("Auto_group_for_");
1702 aNewGeomGroupName += aName;
1703 SALOMEDS::SObject_var aNewGroupSO =
1704 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1705 aNewGeomGroupName.toLatin1().data(), mainGeom);
1712 if (aGeomVar->_is_nil())
1715 SUIT_OverrideCursor aWaitCursor;
1718 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1719 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1721 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1723 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1725 if ( !isAccessibleDim( aDim )) continue;
1727 // find or create algorithm
1728 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1729 if ( !anAlgoVar->_is_nil() )
1730 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1731 // assign hypotheses
1732 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1734 int aHypIndex = currentHyp( aDim, aHypType );
1735 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1737 SMESH::SMESH_Hypothesis_var aHypVar =
1738 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1739 if ( !aHypVar->_is_nil() )
1740 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1745 // deselect geometry: next submesh should be created on other subshape
1746 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1747 selectObject( _PTR(SObject)() );
1753 //================================================================================
1755 * \brief Gets current hypothesis or algorithms
1756 * \param theDim - dimension of hypothesis or algorithm
1757 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1758 * \retval int - current hypothesis or algorithms
1760 * Gets current hypothesis or algorithms
1762 //================================================================================
1763 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1765 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1768 //================================================================================
1770 * \brief Returns true if hypotheses of given dim can be assigned
1771 * \param theDim - hypotheses dimension
1772 * \retval bool - result
1774 //================================================================================
1775 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1777 return myDlg->isTabEnabled( theDim );
1780 //================================================================================
1782 * \brief Sets current hypothesis or algorithms
1783 * \param theDim - dimension of hypothesis or algorithm
1784 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1785 * \param theIndex - Index of hypothesis
1787 * Gets current hypothesis or algorithms
1789 //================================================================================
1790 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1791 const int theHypType,
1792 const int theIndex )
1794 myIgnoreAlgoSelection = true;
1795 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1796 myIgnoreAlgoSelection = false;
1799 //================================================================================
1801 * \brief Generates default and sets mesh/submesh name
1803 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1805 //================================================================================
1806 void SMESHGUI_MeshOp::setDefaultName() const
1810 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1812 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1813 _PTR(SObject) anObj;
1816 aResName = aPrefix + QString::number( i++ );
1817 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1821 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1822 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1823 aControl->setText( aResName );
1826 //================================================================================
1828 * \brief Gets algorithm or creates it if necessary
1829 * \param theDim - specifies dimension of returned hypotheses/algorifms
1830 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1832 * Gets algorithm or creates it if necessary
1834 //================================================================================
1835 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1837 SMESH::SMESH_Hypothesis_var anAlgoVar;
1839 // get type of the selected algo
1840 int aHypIndex = currentHyp( theDim, Algo );
1841 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1842 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1844 QString aHypName = dataList[ aHypIndex ]->TypeName;
1846 // get existing algoritms
1847 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1849 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1851 // look for an existing algo of such a type
1852 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1853 THypList::iterator anIter = aHypVarList.begin();
1854 for ( ; anIter != aHypVarList.end(); anIter++)
1856 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1857 CORBA::String_var aName = aHypVar->GetName();
1858 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1860 anAlgoVar = aHypVar;
1865 if (anAlgoVar->_is_nil())
1867 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1870 QString aClientLibName = aHypData->ClientLibName;
1871 if (aClientLibName == "")
1873 // Call hypothesis creation server method (without GUI)
1874 SMESH::SMESH_Hypothesis_var aHyp =
1875 SMESH::CreateHypothesis(aHypName, aHypName, true);
1876 #ifdef WITHGENERICOBJ
1877 if (!CORBA::is_nil(aHyp))
1883 // Get hypotheses creator client (GUI)
1885 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1886 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1890 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1892 SMESH::SMESH_Hypothesis_var aHyp =
1893 SMESH::CreateHypothesis(aHypName, aHypName, true);
1894 #ifdef WITHGENERICOBJ
1895 if (!CORBA::is_nil(aHyp))
1900 QStringList tmpList;
1901 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1902 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1905 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1906 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1908 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1909 CORBA::String_var aName = aHypVar->GetName();
1910 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1912 anAlgoVar = aHypVar;
1918 return anAlgoVar._retn();
1921 //================================================================================
1923 * \brief Reads parameters of edited mesh and assigns them to the dialog
1925 * Reads parameters of edited mesh and assigns them to the dialog (called when
1926 * mesh is edited only)
1928 //================================================================================
1929 void SMESHGUI_MeshOp::readMesh()
1931 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1932 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1936 if (myIsOnGeometry) {
1937 // Get name of mesh if current object is sub-mesh
1938 SMESH::SMESH_subMesh_var aSubMeshVar =
1939 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1940 if ( !aSubMeshVar->_is_nil() )
1942 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1943 if ( !aMeshVar->_is_nil() )
1945 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1946 QString aMeshName = name( aMeshSO );
1947 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1951 // Get name of geometry object
1952 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1953 if ( !aGeomVar->_is_nil() )
1955 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1956 QString aShapeName = name( aGeomSO );
1957 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1961 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1962 QStringList anExisting;
1963 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1964 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1967 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1968 // find algo index among available ones
1970 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1972 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1973 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1974 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1975 // if ( aHypIndex < 0 && algoData ) {
1976 // // assigned algo is incompatible with other algorithms
1977 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1978 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1981 setCurrentHyp( dim, Algo, aHypIndex );
1982 // set existing and available hypothesis according to the selected algo
1983 onAlgoSelected( aHypIndex, dim );
1987 bool hypWithoutAlgo = false;
1988 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1990 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1993 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1994 // find index of requered hypothesis among existing ones for this dimension and type
1996 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1997 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1998 myExistingHyps[ dim ][ hypType ] );
1999 if ( aHypIndex < 0 ) {
2000 // assigned hypothesis is incompatible with the algorithm
2001 if ( currentHyp( dim, Algo ) < 0 )
2002 { // none algo selected; it is edition for sure, of submesh maybe
2003 hypWithoutAlgo = true;
2004 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2005 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2006 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2010 setCurrentHyp( dim, hypType, aHypIndex );
2013 // make available other hyps of same type as one without algo
2014 if ( hypWithoutAlgo )
2015 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2018 //================================================================================
2020 * \brief Gets name of object
2021 * \param theSO - SObject
2022 * \retval QString - name of object
2024 * Gets name of object
2026 //================================================================================
2027 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2032 _PTR(GenericAttribute) anAttr;
2033 _PTR(AttributeName) aNameAttr;
2034 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2037 aResName = aNameAttr->Value().c_str();
2043 //================================================================================
2045 * \brief Finds hypothesis in input list
2046 * \param theHyp - hypothesis to be found
2047 * \param theHypList - input list of hypotheses
2048 * \retval int - index of hypothesis or -1 if it is not found
2050 * Finds position of hypothesis in input list
2052 //================================================================================
2053 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2054 const THypList& theHypList ) const
2057 if ( !theHyp->_is_nil() )
2060 THypList::const_iterator anIter = theHypList.begin();
2061 for ( ; anIter != theHypList.end(); ++ anIter)
2063 if ( theHyp->_is_equivalent( (*anIter).first ) )
2074 //================================================================================
2076 * \brief Edits mesh or sub-mesh
2077 * \param theMess - Output parameter intended for returning error message
2078 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2080 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2082 //================================================================================
2083 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2087 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2088 if ( aSMESHGen->_is_nil() )
2091 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2092 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2096 SUIT_OverrideCursor aWaitCursor;
2099 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2100 SMESH::SetName( pObj, aName );
2101 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2103 // First, remove old algos in order to avoid messages on algorithm hiding
2104 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2106 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2108 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2109 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2110 if ( anAlgoVar->_is_nil() || // no new algo selected or
2111 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2113 // remove old algorithm
2114 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2115 myObjHyps[ dim ][ Algo ].clear();
2120 // Assign new algorithms and hypotheses
2121 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2123 if ( !isAccessibleDim( dim )) continue;
2125 // find or create algorithm
2126 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2128 // assign new algorithm
2129 if ( !anAlgoVar->_is_nil() && // some algo selected and
2130 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2132 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2133 CORBA::Object_var anObject = aSObject->GetObject();
2134 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2135 bool isMesh = !aMeshVar->_is_nil();
2137 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2139 SMESH::SMESH_subMesh_var aVar =
2140 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2141 if ( !aVar->_is_nil() )
2142 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2144 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2147 // assign hypotheses
2148 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2150 int aNewHypIndex = currentHyp( dim, hypType );
2151 int anOldHypIndex = -1;
2153 // remove old hypotheses
2154 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2156 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2157 myExistingHyps[ dim ][ hypType ] );
2158 if ( aNewHypIndex != anOldHypIndex || // different hyps
2159 anOldHypIndex == -1 ) // hyps of different algos
2161 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2162 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2163 myObjHyps[ dim ][ hypType ].clear();
2167 // assign new hypotheses
2168 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2170 SMESH::SMESH_Mesh_var aMeshVar =
2171 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2172 bool isMesh = !aMeshVar->_is_nil();
2175 SMESH::AddHypothesisOnMesh
2176 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2180 SMESH::SMESH_subMesh_var aVar =
2181 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2182 if ( !aVar->_is_nil() )
2183 SMESH::AddHypothesisOnSubMesh
2184 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2187 // reread all hypotheses of mesh if necessary
2188 QStringList anExisting;
2189 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2196 //================================================================================
2198 * \brief Verifies whether given operator is valid for this one
2199 * \param theOtherOp - other operation
2200 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2202 * method redefined from base class verifies whether given operator is valid for
2203 * this one (i.e. can be started "above" this operator). In current implementation method
2204 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2207 //================================================================================
2208 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2210 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2213 //================================================================================
2215 * \brief SLOT. Is called when the user selects a way of geometry selection
2216 * \param theByMesh - true if the user wants to find geometry by mesh element
2218 //================================================================================
2219 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2222 if ( !myShapeByMeshOp ) {
2223 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2224 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2225 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2226 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2227 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2229 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2230 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2231 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2232 SMESH::SMESH_Mesh_var aMeshVar =
2233 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2234 if ( !aMeshVar->_is_nil() ) {
2235 myDlg->hide(); // stop processing selection
2236 myShapeByMeshOp->setModule( getSMESHGUI() );
2237 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2238 myShapeByMeshOp->SetMesh( aMeshVar );
2239 myShapeByMeshOp->start();
2245 //================================================================================
2247 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2249 //================================================================================
2250 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2252 if ( myShapeByMeshOp == op ) {
2253 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2255 // Select a found geometry object
2256 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2257 if ( !aGeomVar->_is_nil() )
2259 QString ID = aGeomVar->GetStudyEntry();
2260 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2261 selectObject( aGeomSO );
2268 //================================================================================
2270 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2272 //================================================================================
2273 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2275 if ( myShapeByMeshOp == op && myDlg ) {
2280 //================================================================================
2282 * \brief Selects a SObject
2283 * \param theSObj - the SObject to select
2285 //================================================================================
2286 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2288 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2289 SALOME_ListIO anIOList;
2291 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2292 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2293 anIOList.Append( anIO );
2295 sm->setSelectedObjects( anIOList, false );