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/
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 "SALOMEDSClient_Study.hxx"
53 #include "SALOMEDSClient_AttributeIOR.hxx"
54 #include "SALOMEDSClient_AttributeName.hxx"
55 #include "SALOMEDS_SComponent.hxx"
56 #include "SALOMEDS_SObject.hxx"
58 #include "LightApp_SelectionMgr.h"
59 #include "LightApp_UpdateFlags.h"
60 #include "SUIT_MessageBox.h"
61 #include "SUIT_Desktop.h"
62 #include "SUIT_OverrideCursor.h"
63 #include "SALOME_InteractiveObject.hxx"
64 #include "SALOME_ListIO.hxx"
66 #include "utilities.h"
68 #include <qstringlist.h>
69 #include <qlineedit.h>
71 #include <TopoDS_Shape.hxx>
72 #include <TopExp_Explorer.hxx>
74 enum { GLOBAL_ALGO_TAG =3,
78 SUBMESH_ON_EDGE_TAG =5,
79 SUBMESH_ON_WIRE_TAG =6,
80 SUBMESH_ON_FACE_TAG =7,
81 SUBMESH_ON_SHELL_TAG =8,
82 SUBMESH_ON_SOLID_TAG =9,
83 SUBMESH_ON_COMPOUND_TAG=10 };
85 //================================================================================
88 * \param theToCreate - if this parameter is true then operation is used for creation,
89 * for editing otherwise
91 * Initialize operation
93 //================================================================================
94 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
95 : SMESHGUI_SelectionOp(),
96 myToCreate( theToCreate ),
97 myIsMesh( theIsMesh ),
101 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
102 GeometryGUI::InitGeomGen();
105 //================================================================================
109 //================================================================================
110 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
116 //================================================================================
118 * \brief Gets dialog of this operation
119 * \retval LightApp_Dialog* - pointer to dialog of this operation
121 //================================================================================
122 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
127 //================================================================================
129 * \brief Creates or edits mesh
130 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
132 * Virtual slot redefined from the base class called when "Apply" button is clicked
133 * creates or edits mesh
135 //================================================================================
136 bool SMESHGUI_MeshOp::onApply()
138 if( isStudyLocked() )
142 if ( !isValid( aMess ) )
146 SUIT_MessageBox::warn1( myDlg,
147 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
151 bool aResult = false;
155 if ( myToCreate && myIsMesh )
156 aResult = createMesh( aMess );
157 if ( myToCreate && !myIsMesh )
158 aResult = createSubMesh( aMess );
159 else if ( !myToCreate )
160 aResult = editMeshOrSubMesh( aMess );
162 update( UF_ObjBrowser | UF_Model );
164 catch ( const SALOME::SALOME_Exception& S_ex )
166 SalomeApp_Tools::QtCatchCorbaException( S_ex );
182 aMess = tr( "SMESH_OPERATION_FAILED" );
183 SUIT_MessageBox::warn1( myDlg,
184 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
190 //================================================================================
192 * \brief Creates dialog if necessary and shows it
194 * Virtual method redefined from base class called when operation is started creates
195 * dialog if necessary and shows it, activates selection
197 //================================================================================
198 void SMESHGUI_MeshOp::startOperation()
202 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
203 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
205 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
206 this, SLOT( onCreateHyp( const int, const int ) ) );
207 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
208 this, SLOT( onEditHyp( const int, const int ) ) );
209 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
210 this, SLOT( onAlgoSelected( const int ) ) );
212 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
213 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
216 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
217 else myHelpFileName = "/files/constructing_submeshes.htm";
218 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
220 SMESHGUI_SelectionOp::startOperation();
222 // iterate through dimensions and get available algoritms,
223 // set them to the dialog
224 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
225 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
227 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
229 // clear available hypotheses
230 aTab->setAvailableHyps( MainHyp, hypList );
231 aTab->setAvailableHyps( AddHyp, hypList );
232 aTab->setExistingHyps( MainHyp, hypList );
233 aTab->setExistingHyps( AddHyp, hypList );
234 myExistingHyps[ i ][ MainHyp ].clear();
235 myExistingHyps[ i ][ AddHyp ].clear();
237 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
238 aTab->setAvailableHyps( Algo, hypList );
243 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
246 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
248 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
250 myDlg->setCurrentTab( SMESH::DIM_3D );
255 myIgnoreAlgoSelection = false;
258 //================================================================================
260 * \brief Creates selection filter
261 * \param theId - identifier of current selection widget
262 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
264 * Creates selection filter in accordance with identifier of current selection widget
266 //================================================================================
267 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
269 if ( theId == SMESHGUI_MeshDlg::Geom )
271 // TColStd_MapOfInteger allTypesMap;
272 // for ( int i = 0; i < 10; i++ )
273 // allTypesMap.Add( i );
274 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
275 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
277 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
278 return new SMESH_TypeFilter( MESHorSUBMESH );
279 else if ( theId == SMESHGUI_MeshDlg::Mesh )
280 return new SMESH_TypeFilter( MESH );
285 //================================================================================
287 * \brief check if selected shape is a subshape of the shape to mesh
288 * \retval bool - check result
290 //================================================================================
292 bool SMESHGUI_MeshOp::isSubshapeOk() const
294 if ( !myToCreate || myIsMesh ) // not submesh creation
297 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
298 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
299 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
300 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
301 if ( pMesh && pGeom ) {
302 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
303 if ( !mesh->_is_nil() ) {
304 GEOM::GEOM_Object_var mainGeom, subGeom;
305 mainGeom = mesh->GetShapeToMesh();
306 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
307 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
308 TopoDS_Shape mainShape, subShape;
309 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
310 GEOMBase::GetShape( subGeom, subShape ) )
312 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
314 // 1 is index of mainShape itself
315 return index > 1; // it is a subshape
318 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
319 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
320 if ( !geomGen->_is_nil() && aStudy ) {
321 GEOM::GEOM_IGroupOperations_var op =
322 geomGen->GetIGroupOperations( aStudy->StudyId() );
323 if ( ! op->_is_nil() ) {
324 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
325 if ( !mainObj->_is_nil() )
326 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
336 //================================================================================
338 * \brief find an existing submesh by the selected shape
339 * \retval _PTR(SObject) - the found submesh SObject
341 //================================================================================
343 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
345 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
346 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
347 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
348 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
349 if ( pMesh && pGeom ) {
350 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
351 if ( !geom->_is_nil() ) {
353 switch ( geom->GetShapeType() ) {
354 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
355 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
356 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
357 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
358 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
359 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
362 _PTR(GenericAttribute) anAttr;
363 _PTR(SObject) aSubmeshRoot;
364 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
365 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
367 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
368 for (; smIter->More(); smIter->Next() )
370 _PTR(SObject) aSmObj = smIter->Value();
371 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
373 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
374 for (; anIter1->More(); anIter1->Next()) {
375 _PTR(SObject) pGeom2 = anIter1->Value();
376 if ( pGeom2->ReferencedObject( pGeom2 ) &&
377 pGeom2->GetID() == pGeom->GetID() )
384 return _PTR(SObject)();
387 //================================================================================
389 * \brief Updates dialog's look and feel
391 * Virtual method redefined from the base class updates dialog's look and feel
393 //================================================================================
394 void SMESHGUI_MeshOp::selectionDone()
396 if ( !dlg()->isShown() )
399 SMESHGUI_SelectionOp::selectionDone();
403 // Enable tabs according to shape dimension
407 GEOM::GEOM_Object_var aGeomVar;
408 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
409 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
411 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
414 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
415 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
416 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
418 if ( !aGeomVar->_is_nil() ) {
420 switch ( aGeomVar->GetShapeType() ) {
422 case GEOM::SHELL: shapeDim = 3; break;
423 case GEOM::FACE: shapeDim = 2; break;
425 case GEOM::EDGE: shapeDim = 1; break;
426 case GEOM::VERTEX: shapeDim = 0; break;
429 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
430 TopExp_Explorer exp( aShape, TopAbs_SHELL );
433 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
435 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
442 myDlg->setMaxHypoDim( shapeDim );
445 if ( !myToCreate ) // edition: read hypotheses
447 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
448 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
451 SMESH::SMESH_subMesh_var aVar =
452 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
453 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
454 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
455 myDlg->updateGeometry();
463 else if ( !myIsMesh ) // submesh creation
465 // if a submesh on the selected shape already exist, pass to submesh edition mode
466 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
467 SMESH::SMESH_subMesh_var sm =
468 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
469 bool editSubmesh = ( !sm->_is_nil() &&
470 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
471 tr( "EDIT_SUBMESH_QUESTION"),
472 tr( "SMESH_BUT_YES" ),
473 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
476 selectionMgr()->clearFilters();
477 selectObject( pSubmesh );
478 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
483 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
484 selectObject( _PTR(SObject)() );
489 // enable/disable popup for choice of geom selection way
491 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
492 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
493 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
494 if ( !mesh->_is_nil() )
495 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
497 myDlg->setGeomPopupEnabled( enable );
500 catch ( const SALOME::SALOME_Exception& S_ex )
502 SalomeApp_Tools::QtCatchCorbaException( S_ex );
509 //================================================================================
511 * \brief Verifies validity of input data
512 * \param theMess - Output parameter intended for returning error message
513 * \retval bool - TRUE if input data is valid, false otherwise
515 * Verifies validity of input data. This method is called when "Apply" or "OK" button
516 * is pressed before mesh creation or editing.
518 //================================================================================
519 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
521 // Selected object to be edited
522 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
524 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
529 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
530 aMeshName = aMeshName.stripWhiteSpace();
531 if ( aMeshName == "" )
533 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
537 // Imported mesh, if create sub-mesh or edit mesh
538 if ( !myToCreate || ( myToCreate && !myIsMesh ))
540 QString aMeshEntry = myDlg->selectedObject
541 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
542 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
543 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
544 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
545 theMess = tr( "IMPORTED_MESH" );
554 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
555 if ( aGeomEntry == "" )
557 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
560 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
561 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
563 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
568 if ( !myIsMesh ) // i.e sub-mesh creation,
570 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
571 if ( aMeshEntry == "" )
573 theMess = tr( "MESH_IS_NOT_DEFINED" );
576 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
577 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
579 theMess = tr( "MESH_IS_NULL" );
582 if ( !isSubshapeOk() )
584 theMess = tr( "INVALID_SUBSHAPE" );
593 //================================================================================
595 * \brief check compatibility of the algorithm and another algorithm or hypothesis
596 * \param theAlgoData - algorithm data
597 * \param theHypData - hypothesis data
598 * \param theHypType - hypothesis type
599 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
600 * \retval bool - check result
602 //================================================================================
604 static bool isCompatible(const HypothesisData* theAlgoData,
605 const HypothesisData* theHypData,
606 const int theHypType)
611 if ( theHypType == SMESHGUI_MeshOp::Algo )
612 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
615 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
618 //================================================================================
620 * \brief Gets available hypotheses or algorithms
621 * \param theDim - specifies dimension of returned hypotheses/algorifms
622 * \param theHypType - specifies whether algorims or hypotheses or additional ones
623 * are retrieved (possible values are in HypType enumeration)
624 * \param theHyps - Output list of hypotheses' names
625 * \param theAlgoData - to select hypos able to be used by this algo (optional)
627 * Gets available hypotheses or algorithm in accordance with input parameters
629 //================================================================================
630 void SMESHGUI_MeshOp::availableHyps( const int theDim,
631 const int theHypType,
632 QStringList& theHyps,
633 THypDataList& theDataList,
634 HypothesisData* theAlgoData ) const
638 bool isAlgo = ( theHypType == Algo );
639 bool isAux = ( theHypType == AddHyp );
640 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
642 QStringList::const_iterator anIter;
643 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
645 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
646 if ( isCompatible ( theAlgoData, aData, theHypType )) {
647 theDataList.append( aData );
648 theHyps.append( aData->Label );
653 //================================================================================
655 * \brief Gets existing 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 theFather - start object for finding ( may be component, mesh, or sub-mesh )
660 * \param theDataList - output list of hypotheses data
661 * \param theHyps - output list of names.
662 * \param theHypVars - output list of variables.
663 * \param theAlgoData - to select hypos able to be used by this algo (optional)
665 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
668 //================================================================================
669 void SMESHGUI_MeshOp::existingHyps( const int theDim,
670 const int theHypType,
671 _PTR(SObject) theFather,
672 QStringList& theHyps,
673 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
674 HypothesisData* theAlgoData)
676 // Clear hypoheses list
683 const bool isAux = ( theHypType == AddHyp );
685 _PTR(SObject) aHypRoot;
686 _PTR(GenericAttribute) anAttr;
687 _PTR(AttributeName) aName;
688 _PTR(AttributeIOR) anIOR;
690 bool isMesh = !_CAST( SComponent, theFather );
693 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
695 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
697 if ( theFather->FindSubObject( aPart, aHypRoot ) )
699 _PTR(ChildIterator) anIter =
700 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
701 for (; anIter->More(); anIter->Next() )
703 _PTR(SObject) anObj = anIter->Value();
704 if ( isMesh ) // i.e. mesh or submesh
706 _PTR(SObject) aRefObj;
707 if ( anObj->ReferencedObject( aRefObj ) )
712 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
715 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
716 if ( !CORBA::is_nil( aVar ) )
718 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
719 if ( !aHypVar->_is_nil() )
721 QString aHypType( aHypVar->GetName() );
722 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
723 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
724 ( isCompatible ( theAlgoData, aData, theHypType )) &&
725 ( isAux == aData->IsAux ))
727 //theDataList.append( aData );
728 theHyps.append( aName->Value().c_str() );
729 theHypVars.append( aHypVar );
738 //================================================================================
740 * \brief If create or edit a submesh, return a hypothesis holding parameters used
742 * \param aHypType - The hypothesis type name
743 * \param aServerLib - Server library name
744 * \param hypData - The structure holding the hypothesis type etc.
745 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
747 //================================================================================
749 SMESH::SMESH_Hypothesis_var
750 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
751 const QString& aServerLib ) const
753 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
754 return SMESH::SMESH_Hypothesis::_nil();
756 const int nbColonsInMeshEntry = 3;
757 bool isSubMesh = myToCreate ?
759 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
763 // get mesh and geom object
764 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
765 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
767 QString anEntry = myDlg->selectedObject
768 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
769 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
771 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
772 if ( myToCreate ) // mesh and geom may be selected
774 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
775 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
776 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
777 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
779 else // edition: sub-mesh may be selected
781 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
782 if ( !sm->_is_nil() ) {
783 aMeshVar = sm->GetFather();
784 aGeomVar = sm->GetSubShape();
789 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
790 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
795 return SMESH::SMESH_Hypothesis::_nil();
798 //================================================================================
800 * \Brief Returns tab dimention
801 * \param tab - the tab in the dlg
802 * \param dlg - my dialogue
803 * \retval int - dimention
805 //================================================================================
807 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
810 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
811 if (tab == dlg->tab(i))
816 //================================================================================
818 * \brief Create hypothesis
819 * \param theHypType - hypothesis category (main or additional)
820 * \param theIndex - index of type of hypothesis to be cerated
822 * Specifies dimension of hypothesis to be created (using sender() method),
823 * specifies its type and calls method for hypothesis creation
825 //================================================================================
826 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
828 // Specifies dimension of hypothesis to be created
829 int aDim = getTabDim( sender(), myDlg );
833 // Specifies type of hypothesis to be created
834 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
835 if (theIndex < 0 || theIndex >= dataList.count())
837 QString aHypTypeName = dataList[ theIndex ]->TypeName;
840 createHypothesis(aDim, theHypType, aHypTypeName);
843 //================================================================================
845 * Create hypothesis and update dialog.
846 * \param theDim - dimension of hypothesis to be created
847 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
848 * \param theTypeName - specifies hypothesis to be created
850 //================================================================================
851 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
853 const QString& theTypeName)
855 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
860 int nbHyp = myExistingHyps[theDim][theType].count();
862 QString aClientLibName = aData->ClientLibName;
863 if (aClientLibName == "") {
864 // Call hypothesis creation server method (without GUI)
865 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
867 // Get hypotheses creator client (GUI)
868 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
872 // When create or edit a submesh, try to initialize a new hypothesis
873 // with values used to mesh a subshape
874 SMESH::SMESH_Hypothesis_var initParamHyp =
875 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
876 aCreator->create(initParamHyp, myDlg);
878 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
882 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
884 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
885 QStringList aNewHyps;
886 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
887 if (aNewHyps.count() > nbHyp) {
888 for (int i = nbHyp; i < aNewHyps.count(); i++)
889 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
893 //================================================================================
895 * \brief Calls plugin methods for hypothesis editing
896 * \param theHypType - specifies whether main hypothesis or additional one
898 * \param theIndex - index of existing hypothesis
900 * Calls plugin methods for hypothesis editing
902 //================================================================================
903 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
905 // Speicfies dimension of hypothesis to be created
906 int aDim = getTabDim( sender(), myDlg );
910 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
911 if ( theIndex < 0 || theIndex >= aList.count() )
913 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
914 if ( aHyp->_is_nil() )
917 char* aTypeName = aHyp->GetName();
918 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
920 aCreator->edit( aHyp.in(), dlg() );
923 //================================================================================
925 * \brief access to hypothesis data
926 * \param theDim - hyp dimension
927 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
928 * \param theIndex - index in the list
929 * \retval HypothesisData* - result data, may be 0
931 //================================================================================
933 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
934 const int theHypType,
937 if ( theDim > -1 && theDim < 3 &&
938 theHypType > -1 && theHypType < NbHypTypes &&
939 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
940 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
944 //================================================================================
946 * \brief Set available algos and hypos according to the selected algorithm
947 * \param theIndex - algorithm index
949 //================================================================================
951 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
954 if ( myIgnoreAlgoSelection )
957 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
961 // find highest available dimension, all algos of this dimension are available for choice
963 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
964 if (isAccessibleDim( i ))
969 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
971 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
972 HypothesisData* algoByDim[3];
973 algoByDim[ aDim ] = algoData;
975 QStringList anAvailable;
976 if ( !algoData ) { // all algos becomes available
977 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
978 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
981 // check that algorithms of other dimentions are compatible with
984 // 2 loops: backward and forward from algo dimension
985 for ( int forward = false; forward <= true; ++forward )
987 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
989 dim = aDim - 1; lastDim = SMESH::DIM_1D; dir = -1;
991 HypothesisData* prevAlgo = algoData;
992 bool noCompatible = false;
993 for ( ; dim * dir <= lastDim * dir ; dim += dir )
995 if ( !isAccessibleDim( dim ))
997 if ( noCompatible ) { // the selected algo has no compatible ones
999 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1000 myAvailableHypData[dim][Algo].clear();
1001 algoByDim[ dim ] = 0;
1004 // get currently selected algo
1005 int algoIndex = currentHyp( dim, Algo );
1006 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1007 if ( curAlgo ) { // some algo selected
1008 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1011 // set new available algoritms
1012 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1013 HypothesisData* soleCompatible = 0;
1014 if ( anAvailable.count() == 1 )
1015 soleCompatible = myAvailableHypData[dim][Algo][0];
1016 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1017 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1018 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1019 noCompatible = anAvailable.isEmpty();
1021 // restore previously selected algo
1022 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1023 if ( !isSubmesh && algoIndex < 0 && soleCompatible )
1024 // select the sole compatible algo
1025 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1026 setCurrentHyp( dim, Algo, algoIndex );
1028 // remember current algo
1029 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1033 // set hypotheses corresponding to the found algoritms
1035 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1037 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1039 if ( !isAccessibleDim( dim ))
1041 for ( int type = MainHyp; type < NbHypTypes; type++ )
1043 myAvailableHypData[ dim ][ type ].clear();
1044 QStringList anAvailable, anExisting;
1046 HypothesisData* curAlgo = algoByDim[ dim ];
1047 int hypIndex = currentHyp( dim, type );
1049 SMESH::SMESH_Hypothesis_var curHyp;
1050 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1051 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1053 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1054 // try to find algo by selected hypothesis in order to keep it selected
1055 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1056 QString curHypType = curHyp->GetName();
1057 if ( !algoDeselectedByUser &&
1058 myObjHyps[ dim ][ type ].count() > 0 &&
1059 curHypType == myObjHyps[ dim ][ type ][ 0 ]->GetName())
1061 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1062 for ( int i = 0 ; i < myAvailableHypData[ dim ][ Algo ].count(); ++i ) {
1063 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1064 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1071 // get hyps compatible with curAlgo
1074 // check if a selected hyp is compatible with the curAlgo
1075 if ( !curHyp->_is_nil() ) {
1076 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1077 if ( !isCompatible( curAlgo, hypData, type ))
1078 curHyp = SMESH::SMESH_Hypothesis::_nil();
1080 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1081 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1083 // set list of hypotheses
1084 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1085 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1087 // set current existing hypothesis
1088 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1089 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1092 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1093 // none is yet selected => select the sole existing if it is not optional
1094 QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1095 bool isOptional = true;
1096 if ( algoByDim[ dim ] &&
1097 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1101 setCurrentHyp( dim, type, hypIndex );
1106 //================================================================================
1108 * \brief Creates and selects hypothesis of hypotheses set
1109 * \param theSetName - The name of hypotheses set
1111 //================================================================================
1112 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1114 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1115 if (!aHypoSet) return;
1118 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++) {
1119 setCurrentHyp(dim, Algo, -1);
1120 setCurrentHyp(dim, AddHyp, -1);
1121 setCurrentHyp(dim, MainHyp, -1);
1124 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1125 bool isAlgo = (aHypType == Algo);
1127 // set hyps from the set
1128 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1129 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1130 const QString& aHypoTypeName = (*aHypoList)[ i ];
1131 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1135 int aDim = aHypData->Dim[0];
1136 // create or/and set
1138 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1140 QStringList anAvailable;
1141 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1142 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1143 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1145 setCurrentHyp( aDim, Algo, index );
1146 onAlgoSelected( index, aDim );
1149 bool mainHyp = true;
1150 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1153 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1156 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1158 } // loop on hypos in the set
1159 } // loop on algo/hypo
1162 //================================================================================
1164 * \brief Creates mesh
1165 * \param theMess - Output parameter intended for returning error message
1166 * \retval bool - TRUE if mesh is created, FALSE otherwise
1170 //================================================================================
1171 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1175 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1176 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1177 GEOM::GEOM_Object_var aGeomVar =
1178 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1180 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1181 if ( aSMESHGen->_is_nil() )
1184 SUIT_OverrideCursor aWaitCursor;
1187 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1188 if ( aMeshVar->_is_nil() )
1190 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1192 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1194 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1196 if ( !isAccessibleDim( aDim )) continue;
1198 // assign hypotheses
1199 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1201 int aHypIndex = currentHyp( aDim, aHypType );
1202 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1204 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1205 if ( !aHypVar->_is_nil() )
1206 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1209 // find or create algorithm
1210 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1211 if ( !anAlgoVar->_is_nil() )
1212 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1217 //================================================================================
1219 * \brief Creates sub-mesh
1220 * \param theMess - Output parameter intended for returning error message
1221 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1225 //================================================================================
1226 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1230 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1231 if ( aSMESHGen->_is_nil() )
1235 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1236 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1237 SMESH::SMESH_Mesh_var aMeshVar =
1238 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1241 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1242 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1243 GEOM::GEOM_Object_var aGeomVar =
1244 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1246 SUIT_OverrideCursor aWaitCursor;
1249 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1250 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1252 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1254 if ( !isAccessibleDim( aDim )) continue;
1256 // find or create algorithm
1257 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1258 if ( !anAlgoVar->_is_nil() )
1259 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1260 // assign hypotheses
1261 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1263 int aHypIndex = currentHyp( aDim, aHypType );
1264 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1266 SMESH::SMESH_Hypothesis_var aHypVar =
1267 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1268 if ( !aHypVar->_is_nil() )
1269 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1274 // deselect geometry: next submesh sould be created on other subshape
1275 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1276 selectObject( _PTR(SObject)() );
1282 //================================================================================
1284 * \brief Gets current hypothesis or algorithms
1285 * \param theDim - dimension of hypothesis or algorithm
1286 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1287 * \retval int - current hypothesis or algorithms
1289 * Gets current hypothesis or algorithms
1291 //================================================================================
1292 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1294 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1297 //================================================================================
1299 * \brief Returns true if hypotheses of given dim can be assigned
1300 * \param theDim - hypotheses dimension
1301 * \retval bool - result
1303 //================================================================================
1304 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1306 return myDlg->tab( theDim )->isEnabled();
1309 //================================================================================
1311 * \brief Sets current hypothesis or algorithms
1312 * \param theDim - dimension of hypothesis or algorithm
1313 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1314 * \param theIndex - Index of hypothesis
1316 * Gets current hypothesis or algorithms
1318 //================================================================================
1319 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1320 const int theHypType,
1321 const int theIndex )
1323 myIgnoreAlgoSelection = true;
1324 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1325 myIgnoreAlgoSelection = false;
1328 //================================================================================
1330 * \brief Generates default and sets mesh/submesh name
1332 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1334 //================================================================================
1335 void SMESHGUI_MeshOp::setDefaultName() const
1339 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1341 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1342 _PTR(SObject) anObj;
1345 aResName = aPrefix + QString::number( i++ );
1346 anObj = aStudy->FindObject( aResName.latin1() );
1350 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1351 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1352 aControl->setText( aResName );
1355 //================================================================================
1357 * \brief Gets algorithm or creates it if necessary
1358 * \param theDim - specifies dimension of returned hypotheses/algorifms
1359 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1361 * Gets algorithm or creates it if necessary
1363 //================================================================================
1364 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1366 SMESH::SMESH_Hypothesis_var anAlgoVar;
1368 // get type of the selected algo
1369 int aHypIndex = currentHyp( theDim, Algo );
1370 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1371 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1373 QString aHypName = dataList[ aHypIndex ]->TypeName;
1375 // get existing algoritms
1376 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1378 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1380 // look for anexisting algo of such a type
1381 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1382 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1383 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1385 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1386 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1388 anAlgoVar = aHypVar;
1393 if (anAlgoVar->_is_nil()) {
1394 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1396 QString aClientLibName = aHypData->ClientLibName;
1397 if (aClientLibName == "") {
1398 // Call hypothesis creation server method (without GUI)
1399 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1401 // Get hypotheses creator client (GUI)
1402 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1406 aCreator->create(true, myDlg);
1408 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1410 QStringList tmpList;
1411 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1412 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1415 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1416 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1418 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1419 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1421 anAlgoVar = aHypVar;
1427 return anAlgoVar._retn();
1430 //================================================================================
1432 * \brief Reads parameters of edited mesh and assigns them to the dialog
1434 * Reads parameters of edited mesh and assigns them to the dialog (called when
1435 * mesh is edited only)
1437 //================================================================================
1438 void SMESHGUI_MeshOp::readMesh()
1440 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1441 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1445 // Get name of mesh if current object is sub-mesh
1446 SMESH::SMESH_subMesh_var aSubMeshVar =
1447 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1448 if ( !aSubMeshVar->_is_nil() )
1450 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1451 if ( !aMeshVar->_is_nil() )
1453 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1454 QString aMeshName = name( aMeshSO );
1455 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1459 // Get name of geometry object
1460 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1461 if ( !aGeomVar->_is_nil() )
1463 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1464 QString aShapeName = name( aGeomSO );
1465 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1468 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1469 QStringList anExisting;
1470 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1473 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1474 // find algo index among available ones
1476 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1478 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1479 QString aHypTypeName = aVar->GetName();
1480 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1481 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1482 // if ( aHypIndex < 0 && algoData ) {
1483 // // assigned algo is incompatible with other algorithms
1484 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1485 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1488 setCurrentHyp( dim, Algo, aHypIndex );
1489 // set existing and available hypothesis according to the selected algo
1490 onAlgoSelected( aHypIndex, dim );
1494 bool hypWithoutAlgo = false;
1495 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1497 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1500 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1501 // find index of requered hypothesis among existing ones for this dimension and type
1503 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1504 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1505 myExistingHyps[ dim ][ hypType ] );
1506 if ( aHypIndex < 0 ) {
1507 // assigned hypothesis is incompatible with the algorithm
1508 if ( currentHyp( dim, Algo ) < 0 )
1509 { // none algo selected; it is edition for sure, of submesh maybe
1510 hypWithoutAlgo = true;
1511 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1512 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1513 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1517 setCurrentHyp( dim, hypType, aHypIndex );
1520 // make available other hyps of same type as one without algo
1521 if ( hypWithoutAlgo )
1522 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1525 //================================================================================
1527 * \brief Gets name of object
1528 * \param theSO - SObject
1529 * \retval QString - name of object
1531 * Gets name of object
1533 //================================================================================
1534 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1539 _PTR(GenericAttribute) anAttr;
1540 _PTR(AttributeName) aNameAttr;
1541 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1544 aResName = aNameAttr->Value().c_str();
1550 //================================================================================
1552 * \brief Finds hypothesis in input list
1553 * \param theHyp - hypothesis to be found
1554 * \param theHypList - input list of hypotheses
1555 * \retval int - index of hypothesis or -1 if it is not found
1557 * Finds position of hypothesis in input list
1559 //================================================================================
1560 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1561 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1564 if ( !theHyp->_is_nil() )
1567 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1568 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1570 if ( theHyp->_is_equivalent( *anIter ) )
1581 //================================================================================
1583 * \brief Edits mesh or sub-mesh
1584 * \param theMess - Output parameter intended for returning error message
1585 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1587 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1589 //================================================================================
1590 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1594 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1595 if ( aSMESHGen->_is_nil() )
1598 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1599 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1603 SUIT_OverrideCursor aWaitCursor;
1606 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1608 // Assign new hypotheses and algorithms
1609 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1611 if ( !isAccessibleDim( dim )) continue;
1613 // find or create algorithm
1614 bool toDelete = false, toAdd = true;
1615 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1616 if ( anAlgoVar->_is_nil() ) {
1619 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1620 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1622 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1631 // remove old algorithm
1633 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1634 myObjHyps[ dim ][ Algo ].clear();
1637 // assign new algorithm
1639 SMESH::SMESH_Mesh_var aMeshVar =
1640 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1641 bool isMesh = !aMeshVar->_is_nil();
1643 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1645 SMESH::SMESH_subMesh_var aVar =
1646 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1647 if ( !aVar->_is_nil() )
1648 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1650 myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1653 // assign hypotheses
1654 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1656 int aNewHypIndex = currentHyp( dim, hypType );
1657 int anOldHypIndex = -1;
1658 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1659 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1660 myExistingHyps[ dim ][ hypType ] );
1661 if ( aNewHypIndex != anOldHypIndex )
1663 // remove old hypotheses
1664 if ( anOldHypIndex >= 0 ) {
1665 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1666 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1667 myObjHyps[ dim ][ hypType ].clear();
1670 // assign new hypotheses
1671 if ( aNewHypIndex != -1 )
1673 SMESH::SMESH_Mesh_var aMeshVar =
1674 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1675 bool isMesh = !aMeshVar->_is_nil();
1678 SMESH::AddHypothesisOnMesh(
1679 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1683 SMESH::SMESH_subMesh_var aVar =
1684 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1685 if ( !aVar->_is_nil() )
1686 SMESH::AddHypothesisOnSubMesh(
1687 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1690 // reread all hypotheses of mesh if necessary
1691 QStringList anExisting;
1692 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1700 //================================================================================
1702 * \brief Verifies whether given operator is valid for this one
1703 * \param theOtherOp - other operation
1704 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1706 * method redefined from base class verifies whether given operator is valid for
1707 * this one (i.e. can be started "above" this operator). In current implementation method
1708 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1711 //================================================================================
1712 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1714 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1717 //================================================================================
1719 * \brief SLOT. Is called when the user selects a way of geometry selection
1720 * \param theByMesh - true if the user wants to find geometry by mesh element
1722 //================================================================================
1724 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1727 if ( !myShapeByMeshOp ) {
1728 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1729 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1730 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1731 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1732 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1734 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1735 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1736 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1737 SMESH::SMESH_Mesh_var aMeshVar =
1738 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1739 if ( !aMeshVar->_is_nil() ) {
1740 myDlg->hide(); // stop processing selection
1741 myShapeByMeshOp->setModule( getSMESHGUI() );
1742 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1743 myShapeByMeshOp->SetMesh( aMeshVar );
1744 myShapeByMeshOp->start();
1750 //================================================================================
1752 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1754 //================================================================================
1756 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1758 if ( myShapeByMeshOp == op ) {
1760 // Select a found geometry object
1761 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1762 if ( !aGeomVar->_is_nil() )
1764 QString ID = aGeomVar->GetStudyEntry();
1765 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1766 selectObject( aGeomSO );
1773 //================================================================================
1775 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1777 //================================================================================
1779 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1781 if ( myShapeByMeshOp == op && myDlg ) {
1786 //================================================================================
1788 * \brief Selects a SObject
1789 * \param theSObj - the SObject to select
1791 //================================================================================
1793 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1795 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1796 SALOME_ListIO anIOList;
1798 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1799 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1800 anIOList.Append( anIO );
1802 sm->setSelectedObjects( anIOList, false );