1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Copyright (C) 2005 CEA/DEN, EDF R&D
27 * File : SMESHGUI_MeshOp.h
28 * Author : Sergey LITONIN
32 #include "SMESHGUI_MeshOp.h"
33 #include "SMESHGUI_MeshDlg.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESH_TypeFilter.hxx"
38 #include "SMESHGUI_HypothesesUtils.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
41 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESHGUI_VTKUtils.h"
44 #include "SMESH_TypeFilter.hxx"
45 #include "SMESH_NumberFilter.hxx"
47 #include "GEOM_SelectionFilter.h"
49 #include "GeometryGUI.h"
51 #include "SalomeApp_Tools.h"
52 #include "SalomeApp_Application.h"
53 #include "SALOMEDSClient_Study.hxx"
54 #include "SALOMEDSClient_AttributeIOR.hxx"
55 #include "SALOMEDSClient_AttributeName.hxx"
56 #include "SALOMEDS_SComponent.hxx"
57 #include "SALOMEDS_SObject.hxx"
59 #include "LightApp_SelectionMgr.h"
60 #include "LightApp_UpdateFlags.h"
61 #include "SUIT_MessageBox.h"
62 #include "SUIT_Desktop.h"
63 #include "SUIT_OverrideCursor.h"
64 #include "SALOME_InteractiveObject.hxx"
65 #include "SALOME_ListIO.hxx"
67 #include "utilities.h"
69 #include <qstringlist.h>
70 #include <qlineedit.h>
72 #include <TopoDS_Shape.hxx>
73 #include <TopExp_Explorer.hxx>
75 enum { GLOBAL_ALGO_TAG =3,
79 SUBMESH_ON_EDGE_TAG =5,
80 SUBMESH_ON_WIRE_TAG =6,
81 SUBMESH_ON_FACE_TAG =7,
82 SUBMESH_ON_SHELL_TAG =8,
83 SUBMESH_ON_SOLID_TAG =9,
84 SUBMESH_ON_COMPOUND_TAG=10 };
86 //================================================================================
89 * \param theToCreate - if this parameter is true then operation is used for creation,
90 * for editing otherwise
92 * Initialize operation
94 //================================================================================
95 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
96 : SMESHGUI_SelectionOp(),
97 myToCreate( theToCreate ),
98 myIsMesh( theIsMesh ),
102 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
103 GeometryGUI::InitGeomGen();
106 //================================================================================
110 //================================================================================
111 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
117 //================================================================================
119 * \brief Gets dialog of this operation
120 * \retval LightApp_Dialog* - pointer to dialog of this operation
122 //================================================================================
123 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
128 //================================================================================
130 * \brief Creates or edits mesh
131 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
133 * Virtual slot redefined from the base class called when "Apply" button is clicked
134 * creates or edits mesh
136 //================================================================================
137 bool SMESHGUI_MeshOp::onApply()
139 if( isStudyLocked() )
143 if ( !isValid( aMess ) )
147 SUIT_MessageBox::warn1( myDlg,
148 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
152 bool aResult = false;
156 if ( myToCreate && myIsMesh )
157 aResult = createMesh( aMess );
158 if ( myToCreate && !myIsMesh )
159 aResult = createSubMesh( aMess );
160 else if ( !myToCreate )
161 aResult = editMeshOrSubMesh( aMess );
163 update( UF_ObjBrowser | UF_Model );
165 catch ( const SALOME::SALOME_Exception& S_ex )
167 SalomeApp_Tools::QtCatchCorbaException( S_ex );
183 aMess = tr( "SMESH_OPERATION_FAILED" );
184 SUIT_MessageBox::warn1( myDlg,
185 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
191 //================================================================================
193 * \brief Creates dialog if necessary and shows it
195 * Virtual method redefined from base class called when operation is started creates
196 * dialog if necessary and shows it, activates selection
198 //================================================================================
199 void SMESHGUI_MeshOp::startOperation()
203 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
204 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
206 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
207 this, SLOT( onCreateHyp( const int, const int ) ) );
208 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
209 this, SLOT( onEditHyp( const int, const int ) ) );
210 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
211 this, SLOT( onAlgoSelected( const int ) ) );
213 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
214 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
218 else myHelpFileName = "/files/constructing_submeshes.htm";
219 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
221 SMESHGUI_SelectionOp::startOperation();
223 // iterate through dimensions and get available algoritms,
224 // set them to the dialog
225 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
226 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
228 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
230 // clear available hypotheses
231 aTab->setAvailableHyps( MainHyp, hypList );
232 aTab->setAvailableHyps( AddHyp, hypList );
233 aTab->setExistingHyps( MainHyp, hypList );
234 aTab->setExistingHyps( AddHyp, hypList );
235 myExistingHyps[ i ][ MainHyp ].clear();
236 myExistingHyps[ i ][ AddHyp ].clear();
238 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
239 aTab->setAvailableHyps( Algo, hypList );
244 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
247 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
249 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
251 myDlg->setCurrentTab( SMESH::DIM_3D );
256 myIgnoreAlgoSelection = false;
259 //================================================================================
261 * \brief Creates selection filter
262 * \param theId - identifier of current selection widget
263 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
265 * Creates selection filter in accordance with identifier of current selection widget
267 //================================================================================
268 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
270 if ( theId == SMESHGUI_MeshDlg::Geom )
272 // TColStd_MapOfInteger allTypesMap;
273 // for ( int i = 0; i < 10; i++ )
274 // allTypesMap.Add( i );
275 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
276 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
278 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
279 return new SMESH_TypeFilter( MESHorSUBMESH );
280 else if ( theId == SMESHGUI_MeshDlg::Mesh )
281 return new SMESH_TypeFilter( MESH );
286 //================================================================================
288 * \brief check if selected shape is a subshape of the shape to mesh
289 * \retval bool - check result
291 //================================================================================
293 bool SMESHGUI_MeshOp::isSubshapeOk() const
295 if ( !myToCreate || myIsMesh ) // not submesh creation
299 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
300 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
301 if (!pMesh) return false;
303 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
304 if (mesh->_is_nil()) return false;
306 // main shape of the mesh
307 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
308 if (mainGeom->_is_nil()) return false;
312 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
314 if (aGEOMs.count() > 0) {
315 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
316 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
317 if (geomGen->_is_nil() || !aStudy) return false;
319 GEOM::GEOM_IGroupOperations_var op =
320 geomGen->GetIGroupOperations(aStudy->StudyId());
321 if (op->_is_nil()) return false;
323 // check all selected shapes
324 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
325 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
326 QString aSubGeomEntry = (*aSubShapesIter);
327 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
328 if (!pSubGeom) return false;
330 GEOM::GEOM_Object_var aSubGeomVar =
331 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
332 if (aSubGeomVar->_is_nil()) return false;
334 // skl for NPAL14695 - implementation of searching of mainObj
335 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
336 //if (mainObj->_is_nil() ||
337 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
339 if(mainObj->_is_nil())
341 if( string(mainObj->GetEntry()) == string(mainGeom->GetEntry()) )
343 mainObj = op->GetMainShape(mainObj);
352 //================================================================================
354 * \brief find an existing submesh by the selected shape
355 * \retval _PTR(SObject) - the found submesh SObject
357 //================================================================================
359 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
361 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
362 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
363 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
364 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
365 if ( pMesh && pGeom ) {
366 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
367 if ( !geom->_is_nil() ) {
369 switch ( geom->GetShapeType() ) {
370 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
371 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
372 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
373 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
374 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
375 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
378 _PTR(GenericAttribute) anAttr;
379 _PTR(SObject) aSubmeshRoot;
380 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
381 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
383 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
384 for (; smIter->More(); smIter->Next() )
386 _PTR(SObject) aSmObj = smIter->Value();
387 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
389 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
390 for (; anIter1->More(); anIter1->Next()) {
391 _PTR(SObject) pGeom2 = anIter1->Value();
392 if ( pGeom2->ReferencedObject( pGeom2 ) &&
393 pGeom2->GetID() == pGeom->GetID() )
400 return _PTR(SObject)();
403 //================================================================================
405 * \brief Updates dialog's look and feel
407 * Virtual method redefined from the base class updates dialog's look and feel
409 //================================================================================
410 void SMESHGUI_MeshOp::selectionDone()
412 if ( !dlg()->isShown() || !myDlg->isEnabled() )
415 SMESHGUI_SelectionOp::selectionDone();
419 // Enable tabs according to shape dimension
424 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
425 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
427 if (aGEOMs.count() > 0) {
428 // one or more GEOM shape selected
429 aSeq->length(aGEOMs.count());
430 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
432 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
433 QString aSubGeomEntry = (*aSubShapesIter);
434 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
435 GEOM::GEOM_Object_var aSubGeomVar =
436 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
437 aSeq[iSubSh] = aSubGeomVar;
440 // get geometry by selected sub-mesh
441 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
442 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
443 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
444 if (!aGeomVar->_is_nil()) {
450 if (aSeq->length() > 0) {
452 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
453 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
454 switch ( aGeomVar->GetShapeType() ) {
456 case GEOM::SHELL: shapeDim = 3; break;
457 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
459 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
460 case GEOM::VERTEX: break;
463 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
464 TopExp_Explorer exp( aShape, TopAbs_SHELL );
467 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
468 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
469 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
470 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
477 myDlg->setMaxHypoDim( shapeDim );
480 if ( !myToCreate ) // edition: read hypotheses
482 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
483 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
486 SMESH::SMESH_subMesh_var aVar =
487 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
488 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
489 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
490 myDlg->updateGeometry();
498 else if ( !myIsMesh ) // submesh creation
500 // if a submesh on the selected shape already exist, pass to submesh edition mode
501 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
502 SMESH::SMESH_subMesh_var sm =
503 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
504 bool editSubmesh = ( !sm->_is_nil() &&
505 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
506 tr( "EDIT_SUBMESH_QUESTION"),
507 tr( "SMESH_BUT_YES" ),
508 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
511 selectionMgr()->clearFilters();
512 selectObject( pSubmesh );
513 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
518 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
519 selectObject( _PTR(SObject)() );
524 // enable/disable popup for choice of geom selection way
526 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
527 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
528 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
529 if ( !mesh->_is_nil() )
530 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
532 myDlg->setGeomPopupEnabled( enable );
535 catch ( const SALOME::SALOME_Exception& S_ex )
537 SalomeApp_Tools::QtCatchCorbaException( S_ex );
544 //================================================================================
546 * \brief Verifies validity of input data
547 * \param theMess - Output parameter intended for returning error message
548 * \retval bool - TRUE if input data is valid, false otherwise
550 * Verifies validity of input data. This method is called when "Apply" or "OK" button
551 * is pressed before mesh creation or editing.
553 //================================================================================
554 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
556 // Selected object to be edited
557 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
559 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
564 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
565 aMeshName = aMeshName.stripWhiteSpace();
566 if ( aMeshName == "" )
568 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
572 // Imported mesh, if create sub-mesh or edit mesh
573 if ( !myToCreate || ( myToCreate && !myIsMesh ))
575 QString aMeshEntry = myDlg->selectedObject
576 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
577 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
578 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
579 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
580 theMess = tr( "IMPORTED_MESH" );
589 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
590 if ( aGeomEntry == "" )
592 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
595 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
596 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
598 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
603 if ( !myIsMesh ) // i.e sub-mesh creation,
605 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
606 if ( aMeshEntry == "" )
608 theMess = tr( "MESH_IS_NOT_DEFINED" );
611 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
612 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
614 theMess = tr( "MESH_IS_NULL" );
617 if ( !isSubshapeOk() )
619 theMess = tr( "INVALID_SUBSHAPE" );
628 //================================================================================
630 * \brief check compatibility of the algorithm and another algorithm or hypothesis
631 * \param theAlgoData - algorithm data
632 * \param theHypData - hypothesis data
633 * \param theHypType - hypothesis type
634 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
635 * \retval bool - check result
637 //================================================================================
639 static bool isCompatible(const HypothesisData* theAlgoData,
640 const HypothesisData* theHypData,
641 const int theHypType)
646 if ( theHypType == SMESHGUI_MeshOp::Algo )
647 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
650 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
653 //================================================================================
655 * \brief Gets available hypotheses or algorithms
656 * \param theDim - specifies dimension of returned hypotheses/algorifms
657 * \param theHypType - specifies whether algorims or hypotheses or additional ones
658 * are retrieved (possible values are in HypType enumeration)
659 * \param theHyps - Output list of hypotheses' names
660 * \param theAlgoData - to select hypos able to be used by this algo (optional)
662 * Gets available hypotheses or algorithm in accordance with input parameters
664 //================================================================================
665 void SMESHGUI_MeshOp::availableHyps( const int theDim,
666 const int theHypType,
667 QStringList& theHyps,
668 THypDataList& theDataList,
669 HypothesisData* theAlgoData ) const
673 bool isAlgo = ( theHypType == Algo );
674 bool isAux = ( theHypType == AddHyp );
675 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
677 QStringList::const_iterator anIter;
678 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
680 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
681 if ( isCompatible ( theAlgoData, aData, theHypType )) {
682 theDataList.append( aData );
683 theHyps.append( aData->Label );
688 //================================================================================
690 * \brief Gets existing hypotheses or algorithms
691 * \param theDim - specifies dimension of returned hypotheses/algorifms
692 * \param theHypType - specifies whether algorims or hypotheses or additional ones
693 * are retrieved (possible values are in HypType enumeration)
694 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
695 * \param theDataList - output list of hypotheses data
696 * \param theHyps - output list of names.
697 * \param theHypVars - output list of variables.
698 * \param theAlgoData - to select hypos able to be used by this algo (optional)
700 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
703 //================================================================================
704 void SMESHGUI_MeshOp::existingHyps( const int theDim,
705 const int theHypType,
706 _PTR(SObject) theFather,
707 QStringList& theHyps,
708 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
709 HypothesisData* theAlgoData)
711 // Clear hypoheses list
718 const bool isAux = ( theHypType == AddHyp );
720 _PTR(SObject) aHypRoot;
721 _PTR(GenericAttribute) anAttr;
722 _PTR(AttributeName) aName;
723 _PTR(AttributeIOR) anIOR;
725 bool isMesh = !_CAST( SComponent, theFather );
728 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
730 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
732 if ( theFather->FindSubObject( aPart, aHypRoot ) )
734 _PTR(ChildIterator) anIter =
735 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
736 for (; anIter->More(); anIter->Next() )
738 _PTR(SObject) anObj = anIter->Value();
739 if ( isMesh ) // i.e. mesh or submesh
741 _PTR(SObject) aRefObj;
742 if ( anObj->ReferencedObject( aRefObj ) )
747 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
750 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
751 if ( !CORBA::is_nil( aVar ) )
753 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
754 if ( !aHypVar->_is_nil() )
756 QString aHypType( aHypVar->GetName() );
757 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
758 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
759 ( isCompatible ( theAlgoData, aData, theHypType )) &&
760 ( isAux == aData->IsAux ))
762 //theDataList.append( aData );
763 theHyps.append( aName->Value().c_str() );
764 theHypVars.append( aHypVar );
773 //================================================================================
775 * \brief If create or edit a submesh, return a hypothesis holding parameters used
777 * \param aHypType - The hypothesis type name
778 * \param aServerLib - Server library name
779 * \param hypData - The structure holding the hypothesis type etc.
780 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
782 //================================================================================
784 SMESH::SMESH_Hypothesis_var
785 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
786 const QString& aServerLib ) const
788 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
789 return SMESH::SMESH_Hypothesis::_nil();
791 const int nbColonsInMeshEntry = 3;
792 bool isSubMesh = myToCreate ?
794 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
798 // get mesh and geom object
799 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
800 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
802 QString anEntry = myDlg->selectedObject
803 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
804 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
806 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
807 if ( myToCreate ) // mesh and geom may be selected
809 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
810 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
811 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
812 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
814 else // edition: sub-mesh may be selected
816 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
817 if ( !sm->_is_nil() ) {
818 aMeshVar = sm->GetFather();
819 aGeomVar = sm->GetSubShape();
824 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
825 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
830 return SMESH::SMESH_Hypothesis::_nil();
833 //================================================================================
835 * \Brief Returns tab dimention
836 * \param tab - the tab in the dlg
837 * \param dlg - my dialogue
838 * \retval int - dimention
840 //================================================================================
842 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
845 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
846 if (tab == dlg->tab(i))
851 //================================================================================
853 * \brief Create hypothesis
854 * \param theHypType - hypothesis category (main or additional)
855 * \param theIndex - index of type of hypothesis to be cerated
857 * Specifies dimension of hypothesis to be created (using sender() method),
858 * specifies its type and calls method for hypothesis creation
860 //================================================================================
861 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
863 // Specifies dimension of hypothesis to be created
864 int aDim = getTabDim( sender(), myDlg );
868 // Specifies type of hypothesis to be created
869 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
870 if (theIndex < 0 || theIndex >= dataList.count())
872 QString aHypTypeName = dataList[ theIndex ]->TypeName;
875 createHypothesis(aDim, theHypType, aHypTypeName);
878 //================================================================================
880 * Create hypothesis and update dialog.
881 * \param theDim - dimension of hypothesis to be created
882 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
883 * \param theTypeName - specifies hypothesis to be created
885 //================================================================================
886 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
888 const QString& theTypeName)
890 // During a hypothesis creation we might need to select some objects.
891 // Main dialog must not update it's own selected objects in this case.
892 dlg()->deactivateAll();
894 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
899 int nbHyp = myExistingHyps[theDim][theType].count();
901 QString aClientLibName = aData->ClientLibName;
902 if (aClientLibName == "") {
903 // Call hypothesis creation server method (without GUI)
904 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
906 // Get hypotheses creator client (GUI)
907 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
911 // When create or edit a submesh, try to initialize a new hypothesis
912 // with values used to mesh a subshape
913 SMESH::SMESH_Hypothesis_var initParamHyp =
914 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
915 myDlg->setEnabled( false );
916 aCreator->create(initParamHyp, myDlg);
917 myDlg->setEnabled( true );
919 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
923 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
925 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
926 QStringList aNewHyps;
927 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
928 if (aNewHyps.count() > nbHyp) {
929 for (int i = nbHyp; i < aNewHyps.count(); i++)
930 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
934 //================================================================================
936 * \brief Calls plugin methods for hypothesis editing
937 * \param theHypType - specifies whether main hypothesis or additional one
939 * \param theIndex - index of existing hypothesis
941 * Calls plugin methods for hypothesis editing
943 //================================================================================
944 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
946 // Speicfies dimension of hypothesis to be created
947 int aDim = getTabDim( sender(), myDlg );
951 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
952 if ( theIndex < 0 || theIndex >= aList.count() )
954 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
955 if ( aHyp->_is_nil() )
958 char* aTypeName = aHyp->GetName();
959 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
961 myDlg->setEnabled( false );
962 aCreator->edit( aHyp.in(), dlg() );
963 myDlg->setEnabled( true );
967 //================================================================================
969 * \brief access to hypothesis data
970 * \param theDim - hyp dimension
971 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
972 * \param theIndex - index in the list
973 * \retval HypothesisData* - result data, may be 0
975 //================================================================================
977 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
978 const int theHypType,
981 if ( theDim > -1 && theDim < 3 &&
982 theHypType > -1 && theHypType < NbHypTypes &&
983 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
984 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
988 //================================================================================
990 * \brief Set available algos and hypos according to the selected algorithm
991 * \param theIndex - algorithm index
993 //================================================================================
995 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
998 if ( myIgnoreAlgoSelection )
1001 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1005 // find highest available dimension, all algos of this dimension are available for choice
1007 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
1008 if (isAccessibleDim( i ))
1013 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1015 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1016 HypothesisData* algoByDim[3];
1017 algoByDim[ aDim ] = algoData;
1019 QStringList anAvailable;
1020 if ( !algoData ) { // all algos becomes available
1021 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1022 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1025 // check that algorithms of other dimentions are compatible with
1028 // 2 loops: backward and forward from algo dimension
1029 for ( int forward = false; forward <= true; ++forward )
1031 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1033 dim = aDim - 1; lastDim = SMESH::DIM_1D; dir = -1;
1035 HypothesisData* prevAlgo = algoData;
1036 bool noCompatible = false;
1037 for ( ; dim * dir <= lastDim * dir ; dim += dir )
1039 if ( !isAccessibleDim( dim ))
1041 if ( noCompatible ) { // the selected algo has no compatible ones
1042 anAvailable.clear();
1043 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1044 myAvailableHypData[dim][Algo].clear();
1045 algoByDim[ dim ] = 0;
1048 // get currently selected algo
1049 int algoIndex = currentHyp( dim, Algo );
1050 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1051 if ( curAlgo ) { // some algo selected
1052 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1055 // set new available algoritms
1056 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1057 HypothesisData* soleCompatible = 0;
1058 if ( anAvailable.count() == 1 )
1059 soleCompatible = myAvailableHypData[dim][Algo][0];
1060 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1061 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1062 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1063 noCompatible = anAvailable.isEmpty();
1065 // restore previously selected algo
1066 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1067 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward )
1068 // select the sole compatible algo
1069 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1070 setCurrentHyp( dim, Algo, algoIndex );
1072 // remember current algo
1073 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1077 // set hypotheses corresponding to the found algoritms
1079 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1081 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1083 if ( !isAccessibleDim( dim ))
1085 for ( int type = MainHyp; type < NbHypTypes; type++ )
1087 myAvailableHypData[ dim ][ type ].clear();
1088 QStringList anAvailable, anExisting;
1090 HypothesisData* curAlgo = algoByDim[ dim ];
1091 int hypIndex = currentHyp( dim, type );
1093 SMESH::SMESH_Hypothesis_var curHyp;
1094 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1095 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1097 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1098 // try to find algo by selected hypothesis in order to keep it selected
1099 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1100 QString curHypType = curHyp->GetName();
1101 if ( !algoDeselectedByUser &&
1102 myObjHyps[ dim ][ type ].count() > 0 &&
1103 curHypType == myObjHyps[ dim ][ type ][ 0 ]->GetName())
1105 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1106 for ( int i = 0 ; i < myAvailableHypData[ dim ][ Algo ].count(); ++i ) {
1107 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1108 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1115 // get hyps compatible with curAlgo
1118 // check if a selected hyp is compatible with the curAlgo
1119 if ( !curHyp->_is_nil() ) {
1120 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1121 if ( !isCompatible( curAlgo, hypData, type ))
1122 curHyp = SMESH::SMESH_Hypothesis::_nil();
1124 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1125 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1127 // set list of hypotheses
1128 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1129 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1131 // set current existing hypothesis
1132 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1133 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1136 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1137 // none is yet selected => select the sole existing if it is not optional
1138 QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1139 bool isOptional = true;
1140 if ( algoByDim[ dim ] &&
1141 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1145 setCurrentHyp( dim, type, hypIndex );
1150 //================================================================================
1152 * \brief Creates and selects hypothesis of hypotheses set
1153 * \param theSetName - The name of hypotheses set
1155 //================================================================================
1156 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1158 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1159 if (!aHypoSet) return;
1162 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++) {
1163 setCurrentHyp(dim, Algo, -1);
1164 setCurrentHyp(dim, AddHyp, -1);
1165 setCurrentHyp(dim, MainHyp, -1);
1168 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1169 bool isAlgo = (aHypType == Algo);
1171 // set hyps from the set
1172 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1173 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1174 const QString& aHypoTypeName = (*aHypoList)[ i ];
1175 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1179 int aDim = aHypData->Dim[0];
1180 // create or/and set
1182 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1184 QStringList anAvailable;
1185 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1186 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1187 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1189 setCurrentHyp( aDim, Algo, index );
1190 onAlgoSelected( index, aDim );
1193 bool mainHyp = true;
1194 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1197 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1200 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1202 } // loop on hypos in the set
1203 } // loop on algo/hypo
1206 //================================================================================
1208 * \brief Creates mesh
1209 * \param theMess - Output parameter intended for returning error message
1210 * \retval bool - TRUE if mesh is created, FALSE otherwise
1214 //================================================================================
1215 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1219 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1220 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1223 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1224 QStringList::Iterator it = aList.begin();
1225 for(; it!=aList.end(); it++) {
1227 QString aGeomEntry = *it;
1228 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1229 GEOM::GEOM_Object_var aGeomVar =
1230 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1232 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1233 if ( aSMESHGen->_is_nil() )
1236 SUIT_OverrideCursor aWaitCursor;
1239 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1240 if ( aMeshVar->_is_nil() )
1242 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1244 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1246 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ ) {
1247 if ( !isAccessibleDim( aDim )) continue;
1249 // assign hypotheses
1250 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1251 int aHypIndex = currentHyp( aDim, aHypType );
1252 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1253 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1254 if ( !aHypVar->_is_nil() )
1255 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1258 // find or create algorithm
1259 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1260 if ( !anAlgoVar->_is_nil() )
1261 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1268 //================================================================================
1270 * \brief Creates sub-mesh
1271 * \param theMess - Output parameter intended for returning error message
1272 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1276 //================================================================================
1277 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1281 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1282 if ( aSMESHGen->_is_nil() )
1286 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1287 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1288 SMESH::SMESH_Mesh_var aMeshVar =
1289 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1290 if (aMeshVar->_is_nil())
1293 // GEOM shape of the main mesh
1294 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1296 // Name for the new sub-mesh
1297 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1300 GEOM::GEOM_Object_var aGeomVar;
1302 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1303 if (aGEOMs.count() == 1)
1305 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1306 QString aGeomEntry = aGEOMs.first();
1307 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1308 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1310 else if (aGEOMs.count() > 1)
1312 // create a GEOM group
1313 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1314 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1315 if (!geomGen->_is_nil() && aStudy) {
1316 GEOM::GEOM_IGroupOperations_var op =
1317 geomGen->GetIGroupOperations(aStudy->StudyId());
1318 if (!op->_is_nil()) {
1319 // check and add all selected GEOM objects: they must be
1320 // a sub-shapes of the main GEOM and must be of one type
1322 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1323 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1324 aSeq->length(aGEOMs.count());
1325 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1326 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1327 QString aSubGeomEntry = (*aSubShapesIter);
1328 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
1329 GEOM::GEOM_Object_var aSubGeomVar =
1330 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1331 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1333 aGroupType = aSubShapeType;
1335 if (aSubShapeType != aGroupType)
1336 aGroupType = TopAbs_SHAPE;
1338 aSeq[iSubSh] = aSubGeomVar;
1341 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1342 op->UnionList(aGroupVar, aSeq);
1345 aGeomVar = aGroupVar;
1347 // publish the GEOM group in study
1348 QString aNewGeomGroupName ("Auto_group_for_");
1349 aNewGeomGroupName += aName;
1350 SALOMEDS::SObject_var aNewGroupSO =
1351 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
1358 if (aGeomVar->_is_nil())
1361 SUIT_OverrideCursor aWaitCursor;
1364 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1366 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1368 if ( !isAccessibleDim( aDim )) continue;
1370 // find or create algorithm
1371 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1372 if ( !anAlgoVar->_is_nil() )
1373 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1374 // assign hypotheses
1375 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1377 int aHypIndex = currentHyp( aDim, aHypType );
1378 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1380 SMESH::SMESH_Hypothesis_var aHypVar =
1381 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1382 if ( !aHypVar->_is_nil() )
1383 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1388 // deselect geometry: next submesh sould be created on other subshape
1389 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1390 selectObject( _PTR(SObject)() );
1396 //================================================================================
1398 * \brief Gets current hypothesis or algorithms
1399 * \param theDim - dimension of hypothesis or algorithm
1400 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1401 * \retval int - current hypothesis or algorithms
1403 * Gets current hypothesis or algorithms
1405 //================================================================================
1406 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1408 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1411 //================================================================================
1413 * \brief Returns true if hypotheses of given dim can be assigned
1414 * \param theDim - hypotheses dimension
1415 * \retval bool - result
1417 //================================================================================
1418 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1420 return myDlg->tab( theDim )->isEnabled();
1423 //================================================================================
1425 * \brief Sets current hypothesis or algorithms
1426 * \param theDim - dimension of hypothesis or algorithm
1427 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1428 * \param theIndex - Index of hypothesis
1430 * Gets current hypothesis or algorithms
1432 //================================================================================
1433 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1434 const int theHypType,
1435 const int theIndex )
1437 myIgnoreAlgoSelection = true;
1438 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1439 myIgnoreAlgoSelection = false;
1442 //================================================================================
1444 * \brief Generates default and sets mesh/submesh name
1446 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1448 //================================================================================
1449 void SMESHGUI_MeshOp::setDefaultName() const
1453 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1455 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1456 _PTR(SObject) anObj;
1459 aResName = aPrefix + QString::number( i++ );
1460 anObj = aStudy->FindObject( aResName.latin1() );
1464 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1465 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1466 aControl->setText( aResName );
1469 //================================================================================
1471 * \brief Gets algorithm or creates it if necessary
1472 * \param theDim - specifies dimension of returned hypotheses/algorifms
1473 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1475 * Gets algorithm or creates it if necessary
1477 //================================================================================
1478 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1480 SMESH::SMESH_Hypothesis_var anAlgoVar;
1482 // get type of the selected algo
1483 int aHypIndex = currentHyp( theDim, Algo );
1484 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1485 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1487 QString aHypName = dataList[ aHypIndex ]->TypeName;
1489 // get existing algoritms
1490 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1492 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1494 // look for anexisting algo of such a type
1495 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1496 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1497 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1499 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1500 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1502 anAlgoVar = aHypVar;
1507 if (anAlgoVar->_is_nil()) {
1508 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1510 QString aClientLibName = aHypData->ClientLibName;
1511 if (aClientLibName == "") {
1512 // Call hypothesis creation server method (without GUI)
1513 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1515 // Get hypotheses creator client (GUI)
1516 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1520 aCreator->create(true, myDlg);
1522 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1524 QStringList tmpList;
1525 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1526 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1529 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1530 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1532 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1533 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1535 anAlgoVar = aHypVar;
1541 return anAlgoVar._retn();
1544 //================================================================================
1546 * \brief Reads parameters of edited mesh and assigns them to the dialog
1548 * Reads parameters of edited mesh and assigns them to the dialog (called when
1549 * mesh is edited only)
1551 //================================================================================
1552 void SMESHGUI_MeshOp::readMesh()
1554 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1555 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1559 // Get name of mesh if current object is sub-mesh
1560 SMESH::SMESH_subMesh_var aSubMeshVar =
1561 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1562 if ( !aSubMeshVar->_is_nil() )
1564 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1565 if ( !aMeshVar->_is_nil() )
1567 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1568 QString aMeshName = name( aMeshSO );
1569 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1573 // Get name of geometry object
1574 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1575 if ( !aGeomVar->_is_nil() )
1577 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1578 QString aShapeName = name( aGeomSO );
1579 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1582 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1583 QStringList anExisting;
1584 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1587 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1588 // find algo index among available ones
1590 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1592 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1593 QString aHypTypeName = aVar->GetName();
1594 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1595 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1596 // if ( aHypIndex < 0 && algoData ) {
1597 // // assigned algo is incompatible with other algorithms
1598 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1599 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1602 setCurrentHyp( dim, Algo, aHypIndex );
1603 // set existing and available hypothesis according to the selected algo
1604 onAlgoSelected( aHypIndex, dim );
1608 bool hypWithoutAlgo = false;
1609 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1611 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1614 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1615 // find index of requered hypothesis among existing ones for this dimension and type
1617 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1618 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1619 myExistingHyps[ dim ][ hypType ] );
1620 if ( aHypIndex < 0 ) {
1621 // assigned hypothesis is incompatible with the algorithm
1622 if ( currentHyp( dim, Algo ) < 0 )
1623 { // none algo selected; it is edition for sure, of submesh maybe
1624 hypWithoutAlgo = true;
1625 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1626 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1627 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1631 setCurrentHyp( dim, hypType, aHypIndex );
1634 // make available other hyps of same type as one without algo
1635 if ( hypWithoutAlgo )
1636 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1639 //================================================================================
1641 * \brief Gets name of object
1642 * \param theSO - SObject
1643 * \retval QString - name of object
1645 * Gets name of object
1647 //================================================================================
1648 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1653 _PTR(GenericAttribute) anAttr;
1654 _PTR(AttributeName) aNameAttr;
1655 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1658 aResName = aNameAttr->Value().c_str();
1664 //================================================================================
1666 * \brief Finds hypothesis in input list
1667 * \param theHyp - hypothesis to be found
1668 * \param theHypList - input list of hypotheses
1669 * \retval int - index of hypothesis or -1 if it is not found
1671 * Finds position of hypothesis in input list
1673 //================================================================================
1674 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1675 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1678 if ( !theHyp->_is_nil() )
1681 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1682 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1684 if ( theHyp->_is_equivalent( *anIter ) )
1695 //================================================================================
1697 * \brief Edits mesh or sub-mesh
1698 * \param theMess - Output parameter intended for returning error message
1699 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1701 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1703 //================================================================================
1704 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1708 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1709 if ( aSMESHGen->_is_nil() )
1712 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1713 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1717 SUIT_OverrideCursor aWaitCursor;
1720 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1722 // Assign new hypotheses and algorithms
1723 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1725 if ( !isAccessibleDim( dim )) continue;
1727 // find or create algorithm
1728 bool toDelete = false, toAdd = true;
1729 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1730 if ( anAlgoVar->_is_nil() ) {
1733 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1734 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1736 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1745 // remove old algorithm
1747 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1748 myObjHyps[ dim ][ Algo ].clear();
1751 // assign new algorithm
1753 SMESH::SMESH_Mesh_var aMeshVar =
1754 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1755 bool isMesh = !aMeshVar->_is_nil();
1757 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1759 SMESH::SMESH_subMesh_var aVar =
1760 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1761 if ( !aVar->_is_nil() )
1762 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1764 myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1767 // assign hypotheses
1768 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1770 int aNewHypIndex = currentHyp( dim, hypType );
1771 int anOldHypIndex = -1;
1773 // remove old hypotheses
1774 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1776 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1777 myExistingHyps[ dim ][ hypType ] );
1778 if ( aNewHypIndex != anOldHypIndex || // different hyps
1779 anOldHypIndex == -1 ) // hyps of different algos
1781 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1782 ( pObj, myObjHyps[ dim ][ hypType ].first() );
1783 myObjHyps[ dim ][ hypType ].clear();
1787 // assign new hypotheses
1788 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1790 SMESH::SMESH_Mesh_var aMeshVar =
1791 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1792 bool isMesh = !aMeshVar->_is_nil();
1795 SMESH::AddHypothesisOnMesh
1796 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1800 SMESH::SMESH_subMesh_var aVar =
1801 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1802 if ( !aVar->_is_nil() )
1803 SMESH::AddHypothesisOnSubMesh
1804 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1807 // reread all hypotheses of mesh if necessary
1808 QStringList anExisting;
1809 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1816 //================================================================================
1818 * \brief Verifies whether given operator is valid for this one
1819 * \param theOtherOp - other operation
1820 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1822 * method redefined from base class verifies whether given operator is valid for
1823 * this one (i.e. can be started "above" this operator). In current implementation method
1824 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1827 //================================================================================
1828 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1830 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1833 //================================================================================
1835 * \brief SLOT. Is called when the user selects a way of geometry selection
1836 * \param theByMesh - true if the user wants to find geometry by mesh element
1838 //================================================================================
1840 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1843 if ( !myShapeByMeshOp ) {
1844 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1845 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1846 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1847 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1848 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1850 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1851 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1852 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1853 SMESH::SMESH_Mesh_var aMeshVar =
1854 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1855 if ( !aMeshVar->_is_nil() ) {
1856 myDlg->hide(); // stop processing selection
1857 myShapeByMeshOp->setModule( getSMESHGUI() );
1858 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1859 myShapeByMeshOp->SetMesh( aMeshVar );
1860 myShapeByMeshOp->start();
1866 //================================================================================
1868 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1870 //================================================================================
1872 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1874 if ( myShapeByMeshOp == op ) {
1875 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
1877 // Select a found geometry object
1878 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1879 if ( !aGeomVar->_is_nil() )
1881 QString ID = aGeomVar->GetStudyEntry();
1882 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1883 selectObject( aGeomSO );
1890 //================================================================================
1892 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1894 //================================================================================
1896 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1898 if ( myShapeByMeshOp == op && myDlg ) {
1903 //================================================================================
1905 * \brief Selects a SObject
1906 * \param theSObj - the SObject to select
1908 //================================================================================
1910 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1912 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1913 SALOME_ListIO anIOList;
1915 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1916 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1917 anIOList.Append( anIO );
1919 sm->setSelectedObjects( anIOList, false );