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 );
228 QStringList anAvailable;
229 // clear available hypotheses
230 aTab->setAvailableHyps( MainHyp, anAvailable );
231 aTab->setAvailableHyps( AddHyp, anAvailable );
233 availableHyps( i, Algo, anAvailable, myAvailableHypData[i][Algo] );
234 aTab->setAvailableHyps( Algo, anAvailable );
239 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
242 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
244 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
246 myDlg->setCurrentTab( SMESH::DIM_3D );
252 //================================================================================
254 * \brief Creates selection filter
255 * \param theId - identifier of current selection widget
256 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
258 * Creates selection filter in accordance with identifier of current selection widget
260 //================================================================================
261 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
263 if ( theId == SMESHGUI_MeshDlg::Geom )
265 // TColStd_MapOfInteger allTypesMap;
266 // for ( int i = 0; i < 10; i++ )
267 // allTypesMap.Add( i );
268 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
269 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
271 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
272 return new SMESH_TypeFilter( MESHorSUBMESH );
273 else if ( theId == SMESHGUI_MeshDlg::Mesh )
274 return new SMESH_TypeFilter( MESH );
279 //================================================================================
281 * \brief check if selected shape is a subshape of the shape to mesh
282 * \retval bool - check result
284 //================================================================================
286 bool SMESHGUI_MeshOp::isSubshapeOk() const
288 if ( !myToCreate || myIsMesh ) // not submesh creation
291 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
292 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
293 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
294 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
295 if ( pMesh && pGeom ) {
296 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
297 if ( !mesh->_is_nil() ) {
298 GEOM::GEOM_Object_var mainGeom, subGeom;
299 mainGeom = mesh->GetShapeToMesh();
300 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
301 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
302 TopoDS_Shape mainShape, subShape;
303 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
304 GEOMBase::GetShape( subGeom, subShape ) )
306 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
308 // 1 is index of mainShape itself
309 return index > 1; // it is a subshape
312 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
313 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
314 if ( !geomGen->_is_nil() && aStudy ) {
315 GEOM::GEOM_IGroupOperations_var op =
316 geomGen->GetIGroupOperations( aStudy->StudyId() );
317 if ( ! op->_is_nil() ) {
318 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
319 if ( !mainObj->_is_nil() )
320 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
330 //================================================================================
332 * \brief find an existing submesh by the selected shape
333 * \retval _PTR(SObject) - the found submesh SObject
335 //================================================================================
337 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
339 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
340 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
341 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
342 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
343 if ( pMesh && pGeom ) {
344 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
345 if ( !geom->_is_nil() ) {
347 switch ( geom->GetShapeType() ) {
348 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
349 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
350 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
351 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
352 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
353 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
356 _PTR(SObject) aSubmeshRoot;
357 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
358 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
360 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
361 for (; smIter->More(); smIter->Next() )
363 _PTR(SObject) aSmObj = smIter->Value();
364 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
365 for (; anIter1->More(); anIter1->Next()) {
366 _PTR(SObject) pGeom2 = anIter1->Value();
367 if ( pGeom2->ReferencedObject( pGeom2 ) &&
368 pGeom2->GetID() == pGeom->GetID() )
375 return _PTR(SObject)();
378 //================================================================================
380 * \brief Updates dialog's look and feel
382 * Virtual method redefined from the base class updates dialog's look and feel
384 //================================================================================
385 void SMESHGUI_MeshOp::selectionDone()
387 if ( !dlg()->isShown() )
390 SMESHGUI_SelectionOp::selectionDone();
394 // Enable tabs according to shape dimension
398 GEOM::GEOM_Object_var aGeomVar;
399 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
400 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
402 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
405 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
406 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
407 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
409 if ( !aGeomVar->_is_nil() ) {
411 switch ( aGeomVar->GetShapeType() ) {
413 case GEOM::SHELL: shapeDim = 3; break;
414 case GEOM::FACE: shapeDim = 2; break;
416 case GEOM::EDGE: shapeDim = 1; break;
417 case GEOM::VERTEX: shapeDim = 0; break;
420 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
421 TopExp_Explorer exp( aShape, TopAbs_SHELL );
424 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
426 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
433 myDlg->setMaxHypoDim( shapeDim );
435 if ( !myToCreate ) // edition: read hypotheses
437 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
438 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
441 SMESH::SMESH_subMesh_var aVar =
442 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
443 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
444 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
445 myDlg->updateGeometry();
453 else if ( !myIsMesh ) // submesh creation
455 // if a submesh on the selected shape already exist, pass to submesh edition mode
456 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
457 SMESH::SMESH_subMesh_var sm =
458 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
459 bool editSubmesh = ( !sm->_is_nil() &&
460 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
461 tr( "EDIT_SUBMESH_QUESTION"),
462 tr( "SMESH_BUT_YES" ),
463 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
466 selectionMgr()->clearFilters();
467 selectObject( pSubmesh );
468 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
473 selectObject( _PTR(SObject)() );
474 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
478 // enable/disable popup for choice of geom selection way
480 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
481 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
482 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
483 if ( !mesh->_is_nil() )
484 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
486 myDlg->setGeomPopupEnabled( enable );
489 catch ( const SALOME::SALOME_Exception& S_ex )
491 SalomeApp_Tools::QtCatchCorbaException( S_ex );
498 //================================================================================
500 * \brief Verifies validity of input data
501 * \param theMess - Output parameter intended for returning error message
502 * \retval bool - TRUE if input data is valid, false otherwise
504 * Verifies validity of input data. This method is called when "Apply" or "OK" button
505 * is pressed before mesh creation or editing.
507 //================================================================================
508 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
510 // Selected object to be edited
511 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
513 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
518 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
519 aMeshName = aMeshName.stripWhiteSpace();
520 if ( aMeshName == "" )
522 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
526 // Imported mesh, if create sub-mesh or edit mesh
527 if ( !myToCreate || ( myToCreate && !myIsMesh ))
529 QString aMeshEntry = myDlg->selectedObject
530 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
531 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
532 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
533 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
534 theMess = tr( "IMPORTED_MESH" );
543 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
544 if ( aGeomEntry == "" )
546 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
549 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
550 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
552 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
557 if ( !myIsMesh ) // i.e sub-mesh creation,
559 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
560 if ( aMeshEntry == "" )
562 theMess = tr( "MESH_IS_NOT_DEFINED" );
565 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
566 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
568 theMess = tr( "MESH_IS_NULL" );
571 if ( !isSubshapeOk() )
573 theMess = tr( "INVALID_SUBSHAPE" );
582 //================================================================================
584 * \brief check compatibility of the algorithm and another algorithm or hypothesis
585 * \param theAlgoData - algorithm data
586 * \param theHypData - hypothesis data
587 * \param theHypType - hypothesis type
588 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
589 * \retval bool - check result
591 //================================================================================
593 static bool isCompatible(const HypothesisData* theAlgoData,
594 const HypothesisData* theHypData,
595 const int theHypType)
600 if ( theHypType == SMESHGUI_MeshOp::Algo )
601 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
604 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
607 //================================================================================
609 * \brief Gets available hypotheses or algorithms
610 * \param theDim - specifies dimension of returned hypotheses/algorifms
611 * \param theHypType - specifies whether algorims or hypotheses or additional ones
612 * are retrieved (possible values are in HypType enumeration)
613 * \param theHyps - Output list of hypotheses' names
614 * \param theAlgoData - to select hypos able to be used by this algo (optional)
616 * Gets available hypotheses or algorithm in accordance with input parameters
618 //================================================================================
619 void SMESHGUI_MeshOp::availableHyps( const int theDim,
620 const int theHypType,
621 QStringList& theHyps,
622 THypDataList& theDataList,
623 HypothesisData* theAlgoData ) const
627 bool isAlgo = ( theHypType == Algo );
628 bool isAux = ( theHypType == AddHyp );
629 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
631 QStringList::const_iterator anIter;
632 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
634 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
635 if ( isCompatible ( theAlgoData, aData, theHypType )) {
636 theDataList.append( aData );
637 theHyps.append( aData->Label );
642 //================================================================================
644 * \brief Gets existing hypotheses or algorithms
645 * \param theDim - specifies dimension of returned hypotheses/algorifms
646 * \param theHypType - specifies whether algorims or hypotheses or additional ones
647 * are retrieved (possible values are in HypType enumeration)
648 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
649 * \param theDataList - output list of hypotheses data
650 * \param theHyps - output list of names.
651 * \param theHypVars - output list of variables.
652 * \param theAlgoData - to select hypos able to be used by this algo (optional)
654 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
657 //================================================================================
658 void SMESHGUI_MeshOp::existingHyps( const int theDim,
659 const int theHypType,
660 _PTR(SObject) theFather,
661 QStringList& theHyps,
662 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
663 HypothesisData* theAlgoData)
665 // Clear hypoheses list
672 const bool isAux = ( theHypType == AddHyp );
674 _PTR(SObject) aHypRoot;
675 _PTR(GenericAttribute) anAttr;
676 _PTR(AttributeName) aName;
677 _PTR(AttributeIOR) anIOR;
679 bool isMesh = !_CAST( SComponent, theFather );
682 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
684 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
686 if ( theFather->FindSubObject( aPart, aHypRoot ) )
688 _PTR(ChildIterator) anIter =
689 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
690 for (; anIter->More(); anIter->Next() )
692 _PTR(SObject) anObj = anIter->Value();
693 if ( isMesh ) // i.e. mesh or submesh
695 _PTR(SObject) aRefObj;
696 if ( anObj->ReferencedObject( aRefObj ) )
701 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
704 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
705 if ( !CORBA::is_nil( aVar ) )
707 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
708 if ( !aHypVar->_is_nil() )
710 QString aHypType( aHypVar->GetName() );
711 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
712 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
713 ( isCompatible ( theAlgoData, aData, theHypType )) &&
714 ( isAux == aData->IsAux ))
716 //theDataList.append( aData );
717 theHyps.append( aName->Value().c_str() );
718 theHypVars.append( aHypVar );
727 //================================================================================
729 * \brief If create or edit a submesh, return a hypothesis holding parameters used
731 * \param aHypType - The hypothesis type name
732 * \param aServerLib - Server library name
733 * \param hypData - The structure holding the hypothesis type etc.
734 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
736 //================================================================================
738 SMESH::SMESH_Hypothesis_var
739 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
740 const QString& aServerLib ) const
742 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
743 return SMESH::SMESH_Hypothesis::_nil();
745 const int nbColonsInMeshEntry = 3;
746 bool isSubMesh = myToCreate ?
748 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
752 // get mesh and geom object
753 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
754 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
756 QString anEntry = myDlg->selectedObject
757 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
758 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
760 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
761 if ( myToCreate ) // mesh and geom may be selected
763 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
764 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
765 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
766 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
768 else // edition: sub-mesh may be selected
770 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
771 if ( !sm->_is_nil() ) {
772 aMeshVar = sm->GetFather();
773 aGeomVar = sm->GetSubShape();
778 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
779 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
784 return SMESH::SMESH_Hypothesis::_nil();
787 //================================================================================
789 * \Brief Returns tab dimention
790 * \param tab - the tab in the dlg
791 * \param dlg - my dialogue
792 * \retval int - dimention
794 //================================================================================
796 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
799 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
800 if (tab == dlg->tab(i))
805 //================================================================================
807 * \brief Create hypothesis
808 * \param theHypType - hypothesis category (main or additional)
809 * \param theIndex - index of type of hypothesis to be cerated
811 * Specifies dimension of hypothesis to be created (using sender() method),
812 * specifies its type and calls method for hypothesis creation
814 //================================================================================
815 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
817 // Specifies dimension of hypothesis to be created
818 int aDim = getTabDim( sender(), myDlg );
822 // Specifies type of hypothesis to be created
823 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
824 if (theIndex < 0 || theIndex >= dataList.count())
826 QString aHypTypeName = dataList[ theIndex ]->TypeName;
829 createHypothesis(aDim, theHypType, aHypTypeName);
832 //================================================================================
834 * Create hypothesis and update dialog.
835 * \param theDim - dimension of hypothesis to be created
836 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
837 * \param theTypeName - specifies hypothesis to be created
839 //================================================================================
840 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
842 const QString& theTypeName)
844 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
849 int nbHyp = myExistingHyps[theDim][theType].count();
851 QString aClientLibName = aData->ClientLibName;
852 if (aClientLibName == "") {
853 // Call hypothesis creation server method (without GUI)
854 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
856 // Get hypotheses creator client (GUI)
857 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
861 // When create or edit a submesh, try to initialize a new hypothesis
862 // with values used to mesh a subshape
863 SMESH::SMESH_Hypothesis_var initParamHyp =
864 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
865 aCreator->create(initParamHyp, myDlg);
867 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
871 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
873 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
874 QStringList aNewHyps;
875 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
876 if (aNewHyps.count() > nbHyp) {
877 for (int i = nbHyp; i < aNewHyps.count(); i++)
878 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
882 //================================================================================
884 * \brief Calls plugin methods for hypothesis editing
885 * \param theHypType - specifies whether main hypothesis or additional one
887 * \param theIndex - index of existing hypothesis
889 * Calls plugin methods for hypothesis editing
891 //================================================================================
892 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
894 // Speicfies dimension of hypothesis to be created
895 int aDim = getTabDim( sender(), myDlg );
899 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
900 if ( theIndex < 0 || theIndex >= aList.count() )
902 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
903 if ( aHyp->_is_nil() )
906 char* aTypeName = aHyp->GetName();
907 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
909 aCreator->edit( aHyp.in(), dlg() );
912 //================================================================================
914 * \brief access to hypothesis data
915 * \param theDim - hyp dimension
916 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
917 * \param theIndex - index in the list
918 * \retval HypothesisData* - result data, may be 0
920 //================================================================================
922 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
923 const int theHypType,
926 if ( theDim > -1 && theDim < 3 &&
927 theHypType > -1 && theHypType < NbHypTypes &&
928 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
929 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
933 //================================================================================
935 * \brief Set available algos and hypos according to the selected algorithm
936 * \param theIndex - algorithm index
938 //================================================================================
940 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
943 if ( myIgnoreAlgoSelection )
946 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
950 // find highest available dimension, all algos of this dimension are available for choice
952 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
953 if (isAccessibleDim( i ))
958 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
959 HypothesisData* algoByDim[3];
960 algoByDim[ aDim ] = algoData;
962 QStringList anAvailable;
963 if ( !algoData ) { // all algos becomes available
964 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
965 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
968 // check that algorithms of other dimentions are compatible with
971 // 2 loops: backward and forward from algo dimension
972 for ( int forward = false; forward <= true; ++forward )
974 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
976 dim = aDim - 1; lastDim = SMESH::DIM_1D; dir = -1;
978 HypothesisData* prevAlgo = algoData;
979 bool noCompatible = false;
980 for ( ; dim * dir <= lastDim * dir ; dim += dir )
982 if ( !isAccessibleDim( dim ))
984 if ( noCompatible ) { // the selected algo has no compatible ones
986 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
987 myAvailableHypData[dim][Algo].clear();
988 algoByDim[ dim ] = 0;
991 // get currently selected algo
992 int algoIndex = currentHyp( dim, Algo );
993 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
994 if ( curAlgo ) { // some algo selected
995 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
998 // set new available algoritms
999 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1000 HypothesisData* soleCompatible = 0;
1001 if ( anAvailable.count() == 1 )
1002 soleCompatible = myAvailableHypData[dim][Algo][0];
1003 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1004 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1005 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1006 noCompatible = anAvailable.isEmpty();
1008 // restore previously selected algo
1009 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1010 if ( algoIndex < 0 && soleCompatible )
1011 // select the sole compatible algo
1012 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1013 setCurrentHyp( dim, Algo, algoIndex );
1015 // remember current algo
1016 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1020 // set hypotheses corresponding to the found algoritms
1022 //QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1023 _PTR(SObject) pObj;// = studyDS()->FindObjectID( anObjEntry.latin1() );
1025 pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1027 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1029 if ( !isAccessibleDim( dim ))
1031 for ( int type = MainHyp; type < NbHypTypes; type++ )
1033 myAvailableHypData[ dim ][ type ].clear();
1034 QStringList anAvailable, anExisting;
1035 SMESH::SMESH_Hypothesis_var curHyp;
1037 // get hyps compatible with curAlgo
1038 if ( HypothesisData* curAlgo = algoByDim[ dim ] )
1040 // get current existing hypothesis
1041 int hypIndex = currentHyp( dim, type );
1042 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() ) {
1043 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1044 QString hypTypeName = curHyp->GetName();
1045 HypothesisData* hypData = SMESH::GetHypothesisData( hypTypeName );
1046 if ( !isCompatible( curAlgo, hypData, type ))
1047 curHyp = SMESH::SMESH_Hypothesis::_nil();
1049 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1050 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1052 // set list of hypotheses
1053 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1054 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1056 // set current existing hypothesis
1058 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1059 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1060 if ( hypIndex < 0 && anExisting.count() == 1 ) {
1061 // none is yet selected => select the sole existing if it is not optional
1062 QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1063 bool isOptional = true;
1064 if ( algoByDim[ dim ] &&
1065 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1069 setCurrentHyp( dim, type, hypIndex );
1074 //================================================================================
1076 * \brief Creates and selects hypothesis of hypotheses set
1077 * \param theSetName - The name of hypotheses set
1079 //================================================================================
1080 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1082 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1083 if (!aHypoSet) return;
1085 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1086 bool isAlgo = (aHypType == Algo);
1089 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++)
1090 setCurrentHyp(dim, aHypType, -1);
1092 // set hyps from the set
1093 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1094 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1095 const QString& aHypoTypeName = (*aHypoList)[ i ];
1096 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1100 int aDim = aHypData->Dim[0];
1101 // create or/and set
1104 availableHyps( aDim, Algo, tmp, myAvailableHypData[aDim][Algo] );
1105 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1106 setCurrentHyp( aDim, Algo, index );
1107 onAlgoSelected( index, aDim );
1110 bool mainHyp = true;
1111 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1114 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1117 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1119 } // loop on hypos in the set
1120 } // loop on algo/hypo
1123 //================================================================================
1125 * \brief Creates mesh
1126 * \param theMess - Output parameter intended for returning error message
1127 * \retval bool - TRUE if mesh is created, FALSE otherwise
1131 //================================================================================
1132 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1136 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1137 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1138 GEOM::GEOM_Object_var aGeomVar =
1139 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1141 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1142 if ( aSMESHGen->_is_nil() )
1145 SUIT_OverrideCursor aWaitCursor;
1148 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1149 if ( aMeshVar->_is_nil() )
1151 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1153 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1155 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1157 if ( !isAccessibleDim( aDim )) continue;
1159 // assign hypotheses
1160 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1162 int aHypIndex = currentHyp( aDim, aHypType );
1163 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1165 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1166 if ( !aHypVar->_is_nil() )
1167 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1170 // find or create algorithm
1171 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1172 if ( !anAlgoVar->_is_nil() )
1173 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1178 //================================================================================
1180 * \brief Creates sub-mesh
1181 * \param theMess - Output parameter intended for returning error message
1182 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1186 //================================================================================
1187 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1191 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1192 if ( aSMESHGen->_is_nil() )
1196 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1197 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1198 SMESH::SMESH_Mesh_var aMeshVar =
1199 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1202 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1203 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1204 GEOM::GEOM_Object_var aGeomVar =
1205 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1207 SUIT_OverrideCursor aWaitCursor;
1210 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1211 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1213 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1215 if ( !isAccessibleDim( aDim )) continue;
1217 // find or create algorithm
1218 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1219 if ( !anAlgoVar->_is_nil() )
1220 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1221 // assign hypotheses
1222 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1224 int aHypIndex = currentHyp( aDim, aHypType );
1225 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1227 SMESH::SMESH_Hypothesis_var aHypVar =
1228 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1229 if ( !aHypVar->_is_nil() )
1230 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1237 //================================================================================
1239 * \brief Gets current hypothesis or algorithms
1240 * \param theDim - dimension of hypothesis or algorithm
1241 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1242 * \retval int - current hypothesis or algorithms
1244 * Gets current hypothesis or algorithms
1246 //================================================================================
1247 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1249 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1252 //================================================================================
1254 * \brief Returns true if hypotheses of given dim can be assigned
1255 * \param theDim - hypotheses dimension
1256 * \retval bool - result
1258 //================================================================================
1259 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1261 return myDlg->tab( theDim )->isEnabled();
1264 //================================================================================
1266 * \brief Sets current hypothesis or algorithms
1267 * \param theDim - dimension of hypothesis or algorithm
1268 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1269 * \param theIndex - Index of hypothesis
1271 * Gets current hypothesis or algorithms
1273 //================================================================================
1274 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1275 const int theHypType,
1276 const int theIndex )
1278 myIgnoreAlgoSelection = true;
1279 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1280 myIgnoreAlgoSelection = false;
1283 //================================================================================
1285 * \brief Generates default and sets mesh/submesh name
1287 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1289 //================================================================================
1290 void SMESHGUI_MeshOp::setDefaultName() const
1294 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1296 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1297 _PTR(SObject) anObj;
1300 aResName = aPrefix + QString::number( i++ );
1301 anObj = aStudy->FindObject( aResName.latin1() );
1305 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1306 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1307 aControl->setText( aResName );
1310 //================================================================================
1312 * \brief Gets algorithm or creates it if necessary
1313 * \param theDim - specifies dimension of returned hypotheses/algorifms
1314 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1316 * Gets algorithm or creates it if necessary
1318 //================================================================================
1319 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1321 SMESH::SMESH_Hypothesis_var anAlgoVar;
1323 // get type of the selected algo
1324 int aHypIndex = currentHyp( theDim, Algo );
1325 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1326 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1328 QString aHypName = dataList[ aHypIndex ]->TypeName;
1330 // get existing algoritms
1331 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1333 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1335 // look for anexisting algo of such a type
1336 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1337 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1338 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1340 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1341 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1343 anAlgoVar = aHypVar;
1348 if (anAlgoVar->_is_nil()) {
1349 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1351 QString aClientLibName = aHypData->ClientLibName;
1352 if (aClientLibName == "") {
1353 // Call hypothesis creation server method (without GUI)
1354 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1356 // Get hypotheses creator client (GUI)
1357 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1361 aCreator->create(true, myDlg);
1363 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1365 QStringList tmpList;
1366 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1367 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1370 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1371 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1373 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1374 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1376 anAlgoVar = aHypVar;
1382 return anAlgoVar._retn();
1385 //================================================================================
1387 * \brief Reads parameters of edited mesh and assigns them to the dialog
1389 * Reads parameters of edited mesh and assigns them to the dialog (called when
1390 * mesh is edited only)
1392 //================================================================================
1393 void SMESHGUI_MeshOp::readMesh()
1395 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1396 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1400 // Get name of mesh if current object is sub-mesh
1401 SMESH::SMESH_subMesh_var aSubMeshVar =
1402 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1403 if ( !aSubMeshVar->_is_nil() )
1405 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1406 if ( !aMeshVar->_is_nil() )
1408 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1409 QString aMeshName = name( aMeshSO );
1410 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1414 // Get name of geometry object
1415 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1416 if ( !aGeomVar->_is_nil() )
1418 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1419 QString aShapeName = name( aGeomSO );
1420 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1423 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1424 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1427 QStringList anExisting;
1429 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1430 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1432 // find algo index among available ones
1433 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1434 QString aHypTypeName = aVar->GetName();
1435 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1436 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1437 // if ( aHypIndex < 0 && algoData ) {
1438 // // assigned algo is incompatible with other algorithms
1439 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1440 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1443 setCurrentHyp( dim, Algo, aHypIndex );
1444 // set existing and available hypothesis according to the selected algo
1445 onAlgoSelected( aHypIndex, dim );
1448 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1451 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1452 // find index of requered hypothesis among existing ones for this dimension and type
1454 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1455 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1456 myExistingHyps[ dim ][ hypType ] );
1457 // if ( aHypIndex < 0 ) {
1458 // // assigned hypothesis is incompatible with the algorithm
1459 // myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1460 // aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1463 setCurrentHyp( dim, hypType, aHypIndex );
1468 //================================================================================
1470 * \brief Gets name of object
1471 * \param theSO - SObject
1472 * \retval QString - name of object
1474 * Gets name of object
1476 //================================================================================
1477 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1482 _PTR(GenericAttribute) anAttr;
1483 _PTR(AttributeName) aNameAttr;
1484 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1487 aResName = aNameAttr->Value().c_str();
1493 //================================================================================
1495 * \brief Finds hypothesis in input list
1496 * \param theHyp - hypothesis to be found
1497 * \param theHypList - input list of hypotheses
1498 * \retval int - index of hypothesis or -1 if it is not found
1500 * Finds position of hypothesis in input list
1502 //================================================================================
1503 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1504 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1507 if ( !theHyp->_is_nil() )
1510 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1511 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1513 if ( theHyp->_is_equivalent( *anIter ) )
1524 //================================================================================
1526 * \brief Edits mesh or sub-mesh
1527 * \param theMess - Output parameter intended for returning error message
1528 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1530 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1532 //================================================================================
1533 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1537 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1538 if ( aSMESHGen->_is_nil() )
1541 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1542 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1546 SUIT_OverrideCursor aWaitCursor;
1549 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1551 // Assign new hypotheses and algorithms
1552 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1554 if ( !isAccessibleDim( dim )) continue;
1556 // find or create algorithm
1557 bool toDelete = false, toAdd = true;
1558 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1559 if ( anAlgoVar->_is_nil() ) {
1562 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1563 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1565 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1574 // remove old algorithm
1576 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1577 myObjHyps[ dim ][ Algo ].clear();
1580 // assign new algorithm
1582 SMESH::SMESH_Mesh_var aMeshVar =
1583 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1584 bool isMesh = !aMeshVar->_is_nil();
1586 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1588 SMESH::SMESH_subMesh_var aVar =
1589 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1590 if ( !aVar->_is_nil() )
1591 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1593 myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1596 // assign hypotheses
1597 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1599 int aNewHypIndex = currentHyp( dim, hypType );
1600 int anOldHypIndex = -1;
1601 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1602 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1603 myExistingHyps[ dim ][ hypType ] );
1604 if ( aNewHypIndex != anOldHypIndex )
1606 // remove old hypotheses
1607 if ( anOldHypIndex >= 0 ) {
1608 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1609 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1610 myExistingHyps.remove( anOldHypIndex );
1613 // assign new hypotheses
1614 if ( aNewHypIndex != -1 )
1616 SMESH::SMESH_Mesh_var aMeshVar =
1617 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1618 bool isMesh = !aMeshVar->_is_nil();
1621 SMESH::AddHypothesisOnMesh(
1622 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1626 SMESH::SMESH_subMesh_var aVar =
1627 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1628 if ( !aVar->_is_nil() )
1629 SMESH::AddHypothesisOnSubMesh(
1630 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1633 // reread all hypotheses of mesh if necessary
1634 QStringList anExisting;
1635 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1643 //================================================================================
1645 * \brief Verifies whether given operator is valid for this one
1646 * \param theOtherOp - other operation
1647 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1649 * method redefined from base class verifies whether given operator is valid for
1650 * this one (i.e. can be started "above" this operator). In current implementation method
1651 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1654 //================================================================================
1655 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1657 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1660 //================================================================================
1662 * \brief SLOT. Is called when the user selects a way of geometry selection
1663 * \param theByMesh - true if the user wants to find geometry by mesh element
1665 //================================================================================
1667 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1670 if ( !myShapeByMeshOp ) {
1671 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1672 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1673 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1674 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1675 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1677 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1678 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1679 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1680 SMESH::SMESH_Mesh_var aMeshVar =
1681 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1682 if ( !aMeshVar->_is_nil() ) {
1683 myDlg->hide(); // stop processing selection
1684 myShapeByMeshOp->setModule( getSMESHGUI() );
1685 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1686 myShapeByMeshOp->SetMesh( aMeshVar );
1687 myShapeByMeshOp->start();
1693 //================================================================================
1695 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1697 //================================================================================
1699 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1701 if ( myShapeByMeshOp == op ) {
1703 // Select a found geometry object
1704 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1705 if ( !aGeomVar->_is_nil() )
1707 QString ID = aGeomVar->GetStudyEntry();
1708 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1709 selectObject( aGeomSO );
1716 //================================================================================
1718 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1720 //================================================================================
1722 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1724 if ( myShapeByMeshOp == op && myDlg ) {
1729 //================================================================================
1731 * \brief Selects a SObject
1732 * \param theSObj - the SObject to select
1734 //================================================================================
1736 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1738 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1739 SALOME_ListIO anIOList;
1741 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1742 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1743 anIOList.Append( anIO );
1745 sm->setSelectedObjects( anIOList, false );