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 );
235 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
236 aTab->setAvailableHyps( Algo, hypList );
241 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
244 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
246 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
248 myDlg->setCurrentTab( SMESH::DIM_3D );
253 myIgnoreAlgoSelection = false;
256 //================================================================================
258 * \brief Creates selection filter
259 * \param theId - identifier of current selection widget
260 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
262 * Creates selection filter in accordance with identifier of current selection widget
264 //================================================================================
265 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
267 if ( theId == SMESHGUI_MeshDlg::Geom )
269 // TColStd_MapOfInteger allTypesMap;
270 // for ( int i = 0; i < 10; i++ )
271 // allTypesMap.Add( i );
272 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
273 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
275 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
276 return new SMESH_TypeFilter( MESHorSUBMESH );
277 else if ( theId == SMESHGUI_MeshDlg::Mesh )
278 return new SMESH_TypeFilter( MESH );
283 //================================================================================
285 * \brief check if selected shape is a subshape of the shape to mesh
286 * \retval bool - check result
288 //================================================================================
290 bool SMESHGUI_MeshOp::isSubshapeOk() const
292 if ( !myToCreate || myIsMesh ) // not submesh creation
295 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
296 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
297 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
298 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
299 if ( pMesh && pGeom ) {
300 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
301 if ( !mesh->_is_nil() ) {
302 GEOM::GEOM_Object_var mainGeom, subGeom;
303 mainGeom = mesh->GetShapeToMesh();
304 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
305 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
306 TopoDS_Shape mainShape, subShape;
307 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
308 GEOMBase::GetShape( subGeom, subShape ) )
310 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
312 // 1 is index of mainShape itself
313 return index > 1; // it is a subshape
316 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
317 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
318 if ( !geomGen->_is_nil() && aStudy ) {
319 GEOM::GEOM_IGroupOperations_var op =
320 geomGen->GetIGroupOperations( aStudy->StudyId() );
321 if ( ! op->_is_nil() ) {
322 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
323 if ( !mainObj->_is_nil() )
324 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
334 //================================================================================
336 * \brief find an existing submesh by the selected shape
337 * \retval _PTR(SObject) - the found submesh SObject
339 //================================================================================
341 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
343 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
344 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
345 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
346 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
347 if ( pMesh && pGeom ) {
348 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
349 if ( !geom->_is_nil() ) {
351 switch ( geom->GetShapeType() ) {
352 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
353 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
354 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
355 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
356 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
357 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
360 _PTR(SObject) aSubmeshRoot;
361 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
362 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
364 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
365 for (; smIter->More(); smIter->Next() )
367 _PTR(SObject) aSmObj = smIter->Value();
368 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
369 for (; anIter1->More(); anIter1->Next()) {
370 _PTR(SObject) pGeom2 = anIter1->Value();
371 if ( pGeom2->ReferencedObject( pGeom2 ) &&
372 pGeom2->GetID() == pGeom->GetID() )
379 return _PTR(SObject)();
382 //================================================================================
384 * \brief Updates dialog's look and feel
386 * Virtual method redefined from the base class updates dialog's look and feel
388 //================================================================================
389 void SMESHGUI_MeshOp::selectionDone()
391 if ( !dlg()->isShown() )
394 SMESHGUI_SelectionOp::selectionDone();
398 // Enable tabs according to shape dimension
402 GEOM::GEOM_Object_var aGeomVar;
403 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
404 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
406 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
409 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
410 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
411 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
413 if ( !aGeomVar->_is_nil() ) {
415 switch ( aGeomVar->GetShapeType() ) {
417 case GEOM::SHELL: shapeDim = 3; break;
418 case GEOM::FACE: shapeDim = 2; break;
420 case GEOM::EDGE: shapeDim = 1; break;
421 case GEOM::VERTEX: shapeDim = 0; break;
424 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
425 TopExp_Explorer exp( aShape, TopAbs_SHELL );
428 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
430 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
437 myDlg->setMaxHypoDim( shapeDim );
439 if ( !myToCreate ) // edition: read hypotheses
441 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
442 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
445 SMESH::SMESH_subMesh_var aVar =
446 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
447 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
448 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
449 myDlg->updateGeometry();
457 else if ( !myIsMesh ) // submesh creation
459 // if a submesh on the selected shape already exist, pass to submesh edition mode
460 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
461 SMESH::SMESH_subMesh_var sm =
462 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
463 bool editSubmesh = ( !sm->_is_nil() &&
464 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
465 tr( "EDIT_SUBMESH_QUESTION"),
466 tr( "SMESH_BUT_YES" ),
467 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
470 selectionMgr()->clearFilters();
471 selectObject( pSubmesh );
472 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
477 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
478 selectObject( _PTR(SObject)() );
483 // enable/disable popup for choice of geom selection way
485 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
486 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
487 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
488 if ( !mesh->_is_nil() )
489 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
491 myDlg->setGeomPopupEnabled( enable );
494 catch ( const SALOME::SALOME_Exception& S_ex )
496 SalomeApp_Tools::QtCatchCorbaException( S_ex );
503 //================================================================================
505 * \brief Verifies validity of input data
506 * \param theMess - Output parameter intended for returning error message
507 * \retval bool - TRUE if input data is valid, false otherwise
509 * Verifies validity of input data. This method is called when "Apply" or "OK" button
510 * is pressed before mesh creation or editing.
512 //================================================================================
513 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
515 // Selected object to be edited
516 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
518 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
523 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
524 aMeshName = aMeshName.stripWhiteSpace();
525 if ( aMeshName == "" )
527 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
531 // Imported mesh, if create sub-mesh or edit mesh
532 if ( !myToCreate || ( myToCreate && !myIsMesh ))
534 QString aMeshEntry = myDlg->selectedObject
535 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
536 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
537 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
538 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
539 theMess = tr( "IMPORTED_MESH" );
548 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
549 if ( aGeomEntry == "" )
551 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
554 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
555 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
557 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
562 if ( !myIsMesh ) // i.e sub-mesh creation,
564 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
565 if ( aMeshEntry == "" )
567 theMess = tr( "MESH_IS_NOT_DEFINED" );
570 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
571 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
573 theMess = tr( "MESH_IS_NULL" );
576 if ( !isSubshapeOk() )
578 theMess = tr( "INVALID_SUBSHAPE" );
587 //================================================================================
589 * \brief check compatibility of the algorithm and another algorithm or hypothesis
590 * \param theAlgoData - algorithm data
591 * \param theHypData - hypothesis data
592 * \param theHypType - hypothesis type
593 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
594 * \retval bool - check result
596 //================================================================================
598 static bool isCompatible(const HypothesisData* theAlgoData,
599 const HypothesisData* theHypData,
600 const int theHypType)
605 if ( theHypType == SMESHGUI_MeshOp::Algo )
606 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
609 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
612 //================================================================================
614 * \brief Gets available hypotheses or algorithms
615 * \param theDim - specifies dimension of returned hypotheses/algorifms
616 * \param theHypType - specifies whether algorims or hypotheses or additional ones
617 * are retrieved (possible values are in HypType enumeration)
618 * \param theHyps - Output list of hypotheses' names
619 * \param theAlgoData - to select hypos able to be used by this algo (optional)
621 * Gets available hypotheses or algorithm in accordance with input parameters
623 //================================================================================
624 void SMESHGUI_MeshOp::availableHyps( const int theDim,
625 const int theHypType,
626 QStringList& theHyps,
627 THypDataList& theDataList,
628 HypothesisData* theAlgoData ) const
632 bool isAlgo = ( theHypType == Algo );
633 bool isAux = ( theHypType == AddHyp );
634 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
636 QStringList::const_iterator anIter;
637 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
639 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
640 if ( isCompatible ( theAlgoData, aData, theHypType )) {
641 theDataList.append( aData );
642 theHyps.append( aData->Label );
647 //================================================================================
649 * \brief Gets existing hypotheses or algorithms
650 * \param theDim - specifies dimension of returned hypotheses/algorifms
651 * \param theHypType - specifies whether algorims or hypotheses or additional ones
652 * are retrieved (possible values are in HypType enumeration)
653 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
654 * \param theDataList - output list of hypotheses data
655 * \param theHyps - output list of names.
656 * \param theHypVars - output list of variables.
657 * \param theAlgoData - to select hypos able to be used by this algo (optional)
659 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
662 //================================================================================
663 void SMESHGUI_MeshOp::existingHyps( const int theDim,
664 const int theHypType,
665 _PTR(SObject) theFather,
666 QStringList& theHyps,
667 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
668 HypothesisData* theAlgoData)
670 // Clear hypoheses list
677 const bool isAux = ( theHypType == AddHyp );
679 _PTR(SObject) aHypRoot;
680 _PTR(GenericAttribute) anAttr;
681 _PTR(AttributeName) aName;
682 _PTR(AttributeIOR) anIOR;
684 bool isMesh = !_CAST( SComponent, theFather );
687 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
689 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
691 if ( theFather->FindSubObject( aPart, aHypRoot ) )
693 _PTR(ChildIterator) anIter =
694 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
695 for (; anIter->More(); anIter->Next() )
697 _PTR(SObject) anObj = anIter->Value();
698 if ( isMesh ) // i.e. mesh or submesh
700 _PTR(SObject) aRefObj;
701 if ( anObj->ReferencedObject( aRefObj ) )
706 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
709 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
710 if ( !CORBA::is_nil( aVar ) )
712 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
713 if ( !aHypVar->_is_nil() )
715 QString aHypType( aHypVar->GetName() );
716 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
717 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
718 ( isCompatible ( theAlgoData, aData, theHypType )) &&
719 ( isAux == aData->IsAux ))
721 //theDataList.append( aData );
722 theHyps.append( aName->Value().c_str() );
723 theHypVars.append( aHypVar );
732 //================================================================================
734 * \brief If create or edit a submesh, return a hypothesis holding parameters used
736 * \param aHypType - The hypothesis type name
737 * \param aServerLib - Server library name
738 * \param hypData - The structure holding the hypothesis type etc.
739 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
741 //================================================================================
743 SMESH::SMESH_Hypothesis_var
744 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
745 const QString& aServerLib ) const
747 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
748 return SMESH::SMESH_Hypothesis::_nil();
750 const int nbColonsInMeshEntry = 3;
751 bool isSubMesh = myToCreate ?
753 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
757 // get mesh and geom object
758 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
759 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
761 QString anEntry = myDlg->selectedObject
762 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
763 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
765 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
766 if ( myToCreate ) // mesh and geom may be selected
768 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
769 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
770 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
771 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
773 else // edition: sub-mesh may be selected
775 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
776 if ( !sm->_is_nil() ) {
777 aMeshVar = sm->GetFather();
778 aGeomVar = sm->GetSubShape();
783 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
784 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
789 return SMESH::SMESH_Hypothesis::_nil();
792 //================================================================================
794 * \Brief Returns tab dimention
795 * \param tab - the tab in the dlg
796 * \param dlg - my dialogue
797 * \retval int - dimention
799 //================================================================================
801 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
804 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
805 if (tab == dlg->tab(i))
810 //================================================================================
812 * \brief Create hypothesis
813 * \param theHypType - hypothesis category (main or additional)
814 * \param theIndex - index of type of hypothesis to be cerated
816 * Specifies dimension of hypothesis to be created (using sender() method),
817 * specifies its type and calls method for hypothesis creation
819 //================================================================================
820 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
822 // Specifies dimension of hypothesis to be created
823 int aDim = getTabDim( sender(), myDlg );
827 // Specifies type of hypothesis to be created
828 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
829 if (theIndex < 0 || theIndex >= dataList.count())
831 QString aHypTypeName = dataList[ theIndex ]->TypeName;
834 createHypothesis(aDim, theHypType, aHypTypeName);
837 //================================================================================
839 * Create hypothesis and update dialog.
840 * \param theDim - dimension of hypothesis to be created
841 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
842 * \param theTypeName - specifies hypothesis to be created
844 //================================================================================
845 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
847 const QString& theTypeName)
849 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
854 int nbHyp = myExistingHyps[theDim][theType].count();
856 QString aClientLibName = aData->ClientLibName;
857 if (aClientLibName == "") {
858 // Call hypothesis creation server method (without GUI)
859 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
861 // Get hypotheses creator client (GUI)
862 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
866 // When create or edit a submesh, try to initialize a new hypothesis
867 // with values used to mesh a subshape
868 SMESH::SMESH_Hypothesis_var initParamHyp =
869 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
870 aCreator->create(initParamHyp, myDlg);
872 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
876 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
878 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
879 QStringList aNewHyps;
880 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
881 if (aNewHyps.count() > nbHyp) {
882 for (int i = nbHyp; i < aNewHyps.count(); i++)
883 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
887 //================================================================================
889 * \brief Calls plugin methods for hypothesis editing
890 * \param theHypType - specifies whether main hypothesis or additional one
892 * \param theIndex - index of existing hypothesis
894 * Calls plugin methods for hypothesis editing
896 //================================================================================
897 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
899 // Speicfies dimension of hypothesis to be created
900 int aDim = getTabDim( sender(), myDlg );
904 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
905 if ( theIndex < 0 || theIndex >= aList.count() )
907 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
908 if ( aHyp->_is_nil() )
911 char* aTypeName = aHyp->GetName();
912 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
914 aCreator->edit( aHyp.in(), dlg() );
917 //================================================================================
919 * \brief access to hypothesis data
920 * \param theDim - hyp dimension
921 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
922 * \param theIndex - index in the list
923 * \retval HypothesisData* - result data, may be 0
925 //================================================================================
927 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
928 const int theHypType,
931 if ( theDim > -1 && theDim < 3 &&
932 theHypType > -1 && theHypType < NbHypTypes &&
933 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
934 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
938 //================================================================================
940 * \brief Set available algos and hypos according to the selected algorithm
941 * \param theIndex - algorithm index
943 //================================================================================
945 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
948 if ( myIgnoreAlgoSelection )
951 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
955 // find highest available dimension, all algos of this dimension are available for choice
957 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
958 if (isAccessibleDim( i ))
963 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
965 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
966 HypothesisData* algoByDim[3];
967 algoByDim[ aDim ] = algoData;
969 QStringList anAvailable;
970 if ( !algoData ) { // all algos becomes available
971 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
972 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
975 // check that algorithms of other dimentions are compatible with
978 // 2 loops: backward and forward from algo dimension
979 for ( int forward = false; forward <= true; ++forward )
981 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
983 dim = aDim - 1; lastDim = SMESH::DIM_1D; dir = -1;
985 HypothesisData* prevAlgo = algoData;
986 bool noCompatible = false;
987 for ( ; dim * dir <= lastDim * dir ; dim += dir )
989 if ( !isAccessibleDim( dim ))
991 if ( noCompatible ) { // the selected algo has no compatible ones
993 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
994 myAvailableHypData[dim][Algo].clear();
995 algoByDim[ dim ] = 0;
998 // get currently selected algo
999 int algoIndex = currentHyp( dim, Algo );
1000 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1001 if ( curAlgo ) { // some algo selected
1002 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1005 // set new available algoritms
1006 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1007 HypothesisData* soleCompatible = 0;
1008 if ( anAvailable.count() == 1 )
1009 soleCompatible = myAvailableHypData[dim][Algo][0];
1010 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1011 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1012 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1013 noCompatible = anAvailable.isEmpty();
1015 // restore previously selected algo
1016 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1017 if ( !isSubmesh && algoIndex < 0 && soleCompatible )
1018 // select the sole compatible algo
1019 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1020 setCurrentHyp( dim, Algo, algoIndex );
1022 // remember current algo
1023 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1027 // set hypotheses corresponding to the found algoritms
1029 //QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1030 _PTR(SObject) pObj;// = studyDS()->FindObjectID( anObjEntry.latin1() );
1032 pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1034 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1036 if ( !isAccessibleDim( dim ))
1038 for ( int type = MainHyp; type < NbHypTypes; type++ )
1040 myAvailableHypData[ dim ][ type ].clear();
1041 QStringList anAvailable, anExisting;
1042 SMESH::SMESH_Hypothesis_var curHyp;
1044 // get hyps compatible with curAlgo
1045 if ( HypothesisData* curAlgo = algoByDim[ dim ] )
1047 // get current existing hypothesis
1048 int hypIndex = currentHyp( dim, type );
1049 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() ) {
1050 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1051 QString hypTypeName = curHyp->GetName();
1052 HypothesisData* hypData = SMESH::GetHypothesisData( hypTypeName );
1053 if ( !isCompatible( curAlgo, hypData, type ))
1054 curHyp = SMESH::SMESH_Hypothesis::_nil();
1056 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1057 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1059 // set list of hypotheses
1060 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1061 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1063 // set current existing hypothesis
1065 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1066 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1067 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1068 // none is yet selected => select the sole existing if it is not optional
1069 QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1070 bool isOptional = true;
1071 if ( algoByDim[ dim ] &&
1072 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1076 setCurrentHyp( dim, type, hypIndex );
1081 //================================================================================
1083 * \brief Creates and selects hypothesis of hypotheses set
1084 * \param theSetName - The name of hypotheses set
1086 //================================================================================
1087 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1089 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1090 if (!aHypoSet) return;
1092 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1093 bool isAlgo = (aHypType == Algo);
1096 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++)
1097 setCurrentHyp(dim, aHypType, -1);
1099 // set hyps from the set
1100 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1101 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1102 const QString& aHypoTypeName = (*aHypoList)[ i ];
1103 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1107 int aDim = aHypData->Dim[0];
1108 // create or/and set
1111 availableHyps( aDim, Algo, tmp, myAvailableHypData[aDim][Algo] );
1112 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1113 setCurrentHyp( aDim, Algo, index );
1114 onAlgoSelected( index, aDim );
1117 bool mainHyp = true;
1118 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1121 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1124 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1126 } // loop on hypos in the set
1127 } // loop on algo/hypo
1130 //================================================================================
1132 * \brief Creates mesh
1133 * \param theMess - Output parameter intended for returning error message
1134 * \retval bool - TRUE if mesh is created, FALSE otherwise
1138 //================================================================================
1139 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1143 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1144 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1145 GEOM::GEOM_Object_var aGeomVar =
1146 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1148 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1149 if ( aSMESHGen->_is_nil() )
1152 SUIT_OverrideCursor aWaitCursor;
1155 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1156 if ( aMeshVar->_is_nil() )
1158 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1160 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1162 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1164 if ( !isAccessibleDim( aDim )) continue;
1166 // assign hypotheses
1167 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1169 int aHypIndex = currentHyp( aDim, aHypType );
1170 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1172 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1173 if ( !aHypVar->_is_nil() )
1174 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1177 // find or create algorithm
1178 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1179 if ( !anAlgoVar->_is_nil() )
1180 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1185 //================================================================================
1187 * \brief Creates sub-mesh
1188 * \param theMess - Output parameter intended for returning error message
1189 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1193 //================================================================================
1194 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1198 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1199 if ( aSMESHGen->_is_nil() )
1203 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1204 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1205 SMESH::SMESH_Mesh_var aMeshVar =
1206 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1209 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1210 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1211 GEOM::GEOM_Object_var aGeomVar =
1212 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1214 SUIT_OverrideCursor aWaitCursor;
1217 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1218 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1220 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1222 if ( !isAccessibleDim( aDim )) continue;
1224 // find or create algorithm
1225 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1226 if ( !anAlgoVar->_is_nil() )
1227 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1228 // assign hypotheses
1229 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1231 int aHypIndex = currentHyp( aDim, aHypType );
1232 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1234 SMESH::SMESH_Hypothesis_var aHypVar =
1235 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1236 if ( !aHypVar->_is_nil() )
1237 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1242 // deselect geometry: next submesh sould be created on other subshape
1243 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1244 selectObject( _PTR(SObject)() );
1250 //================================================================================
1252 * \brief Gets current hypothesis or algorithms
1253 * \param theDim - dimension of hypothesis or algorithm
1254 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1255 * \retval int - current hypothesis or algorithms
1257 * Gets current hypothesis or algorithms
1259 //================================================================================
1260 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1262 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1265 //================================================================================
1267 * \brief Returns true if hypotheses of given dim can be assigned
1268 * \param theDim - hypotheses dimension
1269 * \retval bool - result
1271 //================================================================================
1272 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1274 return myDlg->tab( theDim )->isEnabled();
1277 //================================================================================
1279 * \brief Sets current hypothesis or algorithms
1280 * \param theDim - dimension of hypothesis or algorithm
1281 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1282 * \param theIndex - Index of hypothesis
1284 * Gets current hypothesis or algorithms
1286 //================================================================================
1287 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1288 const int theHypType,
1289 const int theIndex )
1291 myIgnoreAlgoSelection = true;
1292 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1293 myIgnoreAlgoSelection = false;
1296 //================================================================================
1298 * \brief Generates default and sets mesh/submesh name
1300 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1302 //================================================================================
1303 void SMESHGUI_MeshOp::setDefaultName() const
1307 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1309 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1310 _PTR(SObject) anObj;
1313 aResName = aPrefix + QString::number( i++ );
1314 anObj = aStudy->FindObject( aResName.latin1() );
1318 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1319 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1320 aControl->setText( aResName );
1323 //================================================================================
1325 * \brief Gets algorithm or creates it if necessary
1326 * \param theDim - specifies dimension of returned hypotheses/algorifms
1327 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1329 * Gets algorithm or creates it if necessary
1331 //================================================================================
1332 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1334 SMESH::SMESH_Hypothesis_var anAlgoVar;
1336 // get type of the selected algo
1337 int aHypIndex = currentHyp( theDim, Algo );
1338 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1339 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1341 QString aHypName = dataList[ aHypIndex ]->TypeName;
1343 // get existing algoritms
1344 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1346 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1348 // look for anexisting algo of such a type
1349 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1350 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1351 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1353 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1354 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1356 anAlgoVar = aHypVar;
1361 if (anAlgoVar->_is_nil()) {
1362 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1364 QString aClientLibName = aHypData->ClientLibName;
1365 if (aClientLibName == "") {
1366 // Call hypothesis creation server method (without GUI)
1367 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1369 // Get hypotheses creator client (GUI)
1370 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1374 aCreator->create(true, myDlg);
1376 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1378 QStringList tmpList;
1379 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1380 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1383 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1384 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1386 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1387 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1389 anAlgoVar = aHypVar;
1395 return anAlgoVar._retn();
1398 //================================================================================
1400 * \brief Reads parameters of edited mesh and assigns them to the dialog
1402 * Reads parameters of edited mesh and assigns them to the dialog (called when
1403 * mesh is edited only)
1405 //================================================================================
1406 void SMESHGUI_MeshOp::readMesh()
1408 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1409 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1413 // Get name of mesh if current object is sub-mesh
1414 SMESH::SMESH_subMesh_var aSubMeshVar =
1415 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1416 if ( !aSubMeshVar->_is_nil() )
1418 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1419 if ( !aMeshVar->_is_nil() )
1421 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1422 QString aMeshName = name( aMeshSO );
1423 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1427 // Get name of geometry object
1428 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1429 if ( !aGeomVar->_is_nil() )
1431 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1432 QString aShapeName = name( aGeomSO );
1433 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1436 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1437 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1440 QStringList anExisting;
1442 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1443 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1445 // find algo index among available ones
1446 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1447 QString aHypTypeName = aVar->GetName();
1448 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1449 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1450 // if ( aHypIndex < 0 && algoData ) {
1451 // // assigned algo is incompatible with other algorithms
1452 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1453 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1456 setCurrentHyp( dim, Algo, aHypIndex );
1457 // set existing and available hypothesis according to the selected algo
1458 onAlgoSelected( aHypIndex, dim );
1461 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1464 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1465 // find index of requered hypothesis among existing ones for this dimension and type
1467 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1468 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1469 myExistingHyps[ dim ][ hypType ] );
1470 // if ( aHypIndex < 0 ) {
1471 // // assigned hypothesis is incompatible with the algorithm
1472 // myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1473 // aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1476 setCurrentHyp( dim, hypType, aHypIndex );
1481 //================================================================================
1483 * \brief Gets name of object
1484 * \param theSO - SObject
1485 * \retval QString - name of object
1487 * Gets name of object
1489 //================================================================================
1490 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1495 _PTR(GenericAttribute) anAttr;
1496 _PTR(AttributeName) aNameAttr;
1497 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1500 aResName = aNameAttr->Value().c_str();
1506 //================================================================================
1508 * \brief Finds hypothesis in input list
1509 * \param theHyp - hypothesis to be found
1510 * \param theHypList - input list of hypotheses
1511 * \retval int - index of hypothesis or -1 if it is not found
1513 * Finds position of hypothesis in input list
1515 //================================================================================
1516 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1517 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1520 if ( !theHyp->_is_nil() )
1523 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1524 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1526 if ( theHyp->_is_equivalent( *anIter ) )
1537 //================================================================================
1539 * \brief Edits mesh or sub-mesh
1540 * \param theMess - Output parameter intended for returning error message
1541 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1543 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1545 //================================================================================
1546 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1550 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1551 if ( aSMESHGen->_is_nil() )
1554 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1555 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1559 SUIT_OverrideCursor aWaitCursor;
1562 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1564 // Assign new hypotheses and algorithms
1565 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1567 if ( !isAccessibleDim( dim )) continue;
1569 // find or create algorithm
1570 bool toDelete = false, toAdd = true;
1571 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1572 if ( anAlgoVar->_is_nil() ) {
1575 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1576 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1578 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1587 // remove old algorithm
1589 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1590 myObjHyps[ dim ][ Algo ].clear();
1593 // assign new algorithm
1595 SMESH::SMESH_Mesh_var aMeshVar =
1596 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1597 bool isMesh = !aMeshVar->_is_nil();
1599 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1601 SMESH::SMESH_subMesh_var aVar =
1602 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1603 if ( !aVar->_is_nil() )
1604 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1606 myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1609 // assign hypotheses
1610 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1612 int aNewHypIndex = currentHyp( dim, hypType );
1613 int anOldHypIndex = -1;
1614 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1615 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1616 myExistingHyps[ dim ][ hypType ] );
1617 if ( aNewHypIndex != anOldHypIndex )
1619 // remove old hypotheses
1620 if ( anOldHypIndex >= 0 ) {
1621 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1622 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1623 myObjHyps[ dim ][ hypType ].clear();
1626 // assign new hypotheses
1627 if ( aNewHypIndex != -1 )
1629 SMESH::SMESH_Mesh_var aMeshVar =
1630 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1631 bool isMesh = !aMeshVar->_is_nil();
1634 SMESH::AddHypothesisOnMesh(
1635 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1639 SMESH::SMESH_subMesh_var aVar =
1640 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1641 if ( !aVar->_is_nil() )
1642 SMESH::AddHypothesisOnSubMesh(
1643 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1646 // reread all hypotheses of mesh if necessary
1647 QStringList anExisting;
1648 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1656 //================================================================================
1658 * \brief Verifies whether given operator is valid for this one
1659 * \param theOtherOp - other operation
1660 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1662 * method redefined from base class verifies whether given operator is valid for
1663 * this one (i.e. can be started "above" this operator). In current implementation method
1664 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1667 //================================================================================
1668 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1670 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1673 //================================================================================
1675 * \brief SLOT. Is called when the user selects a way of geometry selection
1676 * \param theByMesh - true if the user wants to find geometry by mesh element
1678 //================================================================================
1680 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1683 if ( !myShapeByMeshOp ) {
1684 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1685 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1686 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1687 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1688 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1690 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1691 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1692 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1693 SMESH::SMESH_Mesh_var aMeshVar =
1694 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1695 if ( !aMeshVar->_is_nil() ) {
1696 myDlg->hide(); // stop processing selection
1697 myShapeByMeshOp->setModule( getSMESHGUI() );
1698 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1699 myShapeByMeshOp->SetMesh( aMeshVar );
1700 myShapeByMeshOp->start();
1706 //================================================================================
1708 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1710 //================================================================================
1712 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1714 if ( myShapeByMeshOp == op ) {
1716 // Select a found geometry object
1717 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1718 if ( !aGeomVar->_is_nil() )
1720 QString ID = aGeomVar->GetStudyEntry();
1721 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1722 selectObject( aGeomSO );
1729 //================================================================================
1731 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1733 //================================================================================
1735 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1737 if ( myShapeByMeshOp == op && myDlg ) {
1742 //================================================================================
1744 * \brief Selects a SObject
1745 * \param theSObj - the SObject to select
1747 //================================================================================
1749 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1751 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1752 SALOME_ListIO anIOList;
1754 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1755 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1756 anIOList.Append( anIO );
1758 sm->setSelectedObjects( anIOList, false );