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 ) )
145 SUIT_MessageBox::warn1( myDlg,
146 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
150 bool aResult = false;
154 if ( myToCreate && myIsMesh )
155 aResult = createMesh( aMess );
156 if ( myToCreate && !myIsMesh )
157 aResult = createSubMesh( aMess );
158 else if ( !myToCreate )
159 aResult = editMeshOrSubMesh( aMess );
161 update( UF_ObjBrowser | UF_Model );
163 catch ( const SALOME::SALOME_Exception& S_ex )
165 SalomeApp_Tools::QtCatchCorbaException( S_ex );
181 aMess = tr( "SMESH_OPERATION_FAILED" );
182 SUIT_MessageBox::warn1( myDlg,
183 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
189 //================================================================================
191 * \brief Creates dialog if necessary and shows it
193 * Virtual method redefined from base class called when operation is started creates
194 * dialog if necessary and shows it, activates selection
196 //================================================================================
197 void SMESHGUI_MeshOp::startOperation()
201 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
202 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
204 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
205 this, SLOT( onCreateHyp( const int, const int) ) );
206 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
207 this, SLOT( onEditHyp( const int, const int) ) );
209 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
210 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
212 SMESHGUI_SelectionOp::startOperation();
214 // iterate through dimensions and get available and existing algoritms and hypotheses,
215 // set them to the dialog
217 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
218 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
220 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
221 QStringList anAvailable, anExisting;
222 for ( j = Algo; j <= AddHyp; j++ )
224 availableHyps( i, j, anAvailable );
225 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
227 aTab->setAvailableHyps( j, anAvailable );
228 aTab->setExistingHyps( j, anExisting );
234 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
237 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
239 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
243 myDlg->setCurrentTab( SMESH::DIM_1D );
247 //================================================================================
249 * \brief Creates selection filter
250 * \param theId - identifier of current selection widget
251 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
253 * Creates selection filter in accordance with identifier of current selection widget
255 //================================================================================
256 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
258 if ( theId == SMESHGUI_MeshDlg::Geom )
260 // TColStd_MapOfInteger allTypesMap;
261 // for ( int i = 0; i < 10; i++ )
262 // allTypesMap.Add( i );
263 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
264 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
266 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
267 return new SMESH_TypeFilter( MESHorSUBMESH );
268 else if ( theId == SMESHGUI_MeshDlg::Mesh )
269 return new SMESH_TypeFilter( MESH );
274 //================================================================================
276 * \brief check if selected shape is a subshape of the shape to mesh
277 * \retval bool - check result
279 //================================================================================
281 bool SMESHGUI_MeshOp::isSubshapeOk() const
283 if ( !myToCreate || myIsMesh ) // not submesh creation
286 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
287 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
288 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
289 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
290 if ( pMesh && pGeom ) {
291 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
292 if ( !mesh->_is_nil() ) {
293 GEOM::GEOM_Object_var mainGeom, subGeom;
294 mainGeom = mesh->GetShapeToMesh();
295 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
296 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
297 TopoDS_Shape mainShape, subShape;
298 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
299 GEOMBase::GetShape( subGeom, subShape ) )
301 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
303 // 1 is index of mainShape itself
304 return index > 1; // it is a subshape
307 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
308 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
309 if ( !geomGen->_is_nil() && aStudy ) {
310 GEOM::GEOM_IGroupOperations_var op =
311 geomGen->GetIGroupOperations( aStudy->StudyId() );
312 if ( ! op->_is_nil() ) {
313 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
314 if ( !mainObj->_is_nil() )
315 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
325 //================================================================================
327 * \brief find an existing submesh by the selected shape
328 * \retval _PTR(SObject) - the found submesh SObject
330 //================================================================================
332 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
334 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
335 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
336 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
337 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
338 if ( pMesh && pGeom ) {
339 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
340 if ( !geom->_is_nil() ) {
342 switch ( geom->GetShapeType() ) {
343 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
344 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
345 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
346 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
347 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
348 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
351 _PTR(SObject) aSubmeshRoot;
352 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
353 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
355 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
356 for (; smIter->More(); smIter->Next() )
358 _PTR(SObject) aSmObj = smIter->Value();
359 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
360 for (; anIter1->More(); anIter1->Next()) {
361 _PTR(SObject) pGeom2 = anIter1->Value();
362 if ( pGeom2->ReferencedObject( pGeom2 ) &&
363 pGeom2->GetID() == pGeom->GetID() )
370 return _PTR(SObject)();
373 //================================================================================
375 * \brief Updates dialog's look and feel
377 * Virtual method redefined from the base class updates dialog's look and feel
379 //================================================================================
380 void SMESHGUI_MeshOp::selectionDone()
382 if ( myShapeByMeshDlg && myShapeByMeshDlg->isShown() )
385 SMESHGUI_SelectionOp::selectionDone();
389 // Enable tabs according to shape dimension
393 GEOM::GEOM_Object_var aGeomVar;
394 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
395 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
397 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
400 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
401 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
402 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
404 if ( !aGeomVar->_is_nil() ) {
406 switch ( aGeomVar->GetShapeType() ) {
408 case GEOM::SHELL: shapeDim = 3; break;
409 case GEOM::FACE: shapeDim = 2; break;
411 case GEOM::EDGE: shapeDim = 1; break;
412 case GEOM::VERTEX: shapeDim = 0; break;
415 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
416 TopExp_Explorer exp( aShape, TopAbs_SHELL );
419 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
421 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
428 myDlg->setMaxHypoDim( shapeDim );
430 if ( !myToCreate ) // edition: read hypotheses
432 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
433 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
436 SMESH::SMESH_subMesh_var aVar =
437 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
438 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
439 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
440 myDlg->updateGeometry();
448 else if ( !myIsMesh ) // submesh creation
450 // if a submesh on the selected shape already exist, pass to submesh edition mode
451 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
452 SMESH::SMESH_subMesh_var sm =
453 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
454 bool editSubmesh = ( !sm->_is_nil() &&
455 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
456 tr( "EDIT_SUBMESH_QUESTION"),
457 tr( "SMESH_BUT_YES" ),
458 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
461 selectionMgr()->clearFilters();
462 selectObject( pSubmesh );
463 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
468 selectObject( _PTR(SObject)() );
469 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
473 // enable/disable popup for choice of geom selection way
475 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
476 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
477 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
478 if ( !mesh->_is_nil() )
479 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
481 myDlg->setGeomPopupEnabled( enable );
484 catch ( const SALOME::SALOME_Exception& S_ex )
486 SalomeApp_Tools::QtCatchCorbaException( S_ex );
493 //================================================================================
495 * \brief Verifies validity of input data
496 * \param theMess - Output parameter intended for returning error message
497 * \retval bool - TRUE if input data is valid, false otherwise
499 * Verifies validity of input data. This method is called when "Apply" or "OK" button
500 * is pressed before mesh creation or editing.
502 //================================================================================
503 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
505 // Selected object to be edited
506 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
508 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
513 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
514 aMeshName = aMeshName.stripWhiteSpace();
515 if ( aMeshName == "" )
517 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
521 // Imported mesh, if create sub-mesh or edit mesh
522 if ( !myToCreate || ( myToCreate && !myIsMesh ))
524 QString aMeshEntry = myDlg->selectedObject
525 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
526 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
527 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
528 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
529 theMess = tr( "IMPORTED_MESH" );
538 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
539 if ( aGeomEntry == "" )
541 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
544 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
545 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
547 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
552 if ( !myIsMesh ) // i.e sub-mesh creation,
554 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
555 if ( aMeshEntry == "" )
557 theMess = tr( "MESH_IS_NOT_DEFINED" );
560 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
561 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
563 theMess = tr( "MESH_IS_NULL" );
566 if ( !isSubshapeOk() )
568 theMess = tr( "INVALID_SUBSHAPE" );
577 //================================================================================
579 * \brief Gets available hypotheses or algorithms
580 * \param theDim - specifies dimension of returned hypotheses/algorifms
581 * \param theHypType - specifies whether algorims or hypotheses or additional ones
582 * are retrieved (possible values are in HypType enumeration)
583 * \param theHyps - Output list of hypotheses' names
585 * Gets available hypotheses or algorithm in accordance with input parameters
587 //================================================================================
588 void SMESHGUI_MeshOp::availableHyps( const int theDim,
589 const int theHypType,
590 QStringList& theHyps ) const
593 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
594 theHypType == Algo , theDim, theHypType == AddHyp );
595 QStringList::const_iterator anIter;
596 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
598 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
599 theHyps.append( aData->Label );
603 //================================================================================
605 * \brief Gets existing hypotheses or algorithms
606 * \param theDim - specifies dimension of returned hypotheses/algorifms
607 * \param theHypType - specifies whether algorims or hypotheses or additional ones
608 * are retrieved (possible values are in HypType enumeration)
609 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
610 * \param theHyps - output list of names.
611 * \param theHypVars - output list of variables.
613 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
616 //================================================================================
617 void SMESHGUI_MeshOp::existingHyps( const int theDim,
618 const int theHypType,
619 _PTR(SObject) theFather,
620 QStringList& theHyps,
621 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
623 // Clear hypoheses list
630 _PTR(SObject) aHypRoot;
631 _PTR(GenericAttribute) anAttr;
632 _PTR(AttributeName) aName;
633 _PTR(AttributeIOR) anIOR;
635 bool isMesh = !_CAST( SComponent, theFather );
638 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
640 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
642 if ( theFather->FindSubObject( aPart, aHypRoot ) )
644 _PTR(ChildIterator) anIter =
645 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
646 for (; anIter->More(); anIter->Next() )
648 _PTR(SObject) anObj = anIter->Value();
649 if ( isMesh ) // i.e. mesh or submesh
651 _PTR(SObject) aRefObj;
652 if ( anObj->ReferencedObject( aRefObj ) )
657 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
660 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
661 if ( !CORBA::is_nil( aVar ) )
663 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
664 if ( !aHypVar->_is_nil() )
666 QString aHypType( aHypVar->GetName() );
667 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
668 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
669 ( theHypType == AddHyp ) == aData->IsAux )
671 theHyps.append( aName->Value().c_str() );
672 theHypVars.append( aHypVar );
681 //================================================================================
683 * \brief If create or edit a submesh, return a hypothesis holding parameters used
685 * \param aHypType - The hypothesis type name
686 * \param aServerLib - Server library name
687 * \param hypData - The structure holding the hypothesis type etc.
688 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
690 //================================================================================
692 SMESH::SMESH_Hypothesis_var
693 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
694 const QString& aServerLib ) const
696 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
697 return SMESH::SMESH_Hypothesis::_nil();
699 const int nbColonsInMeshEntry = 3;
700 bool isSubMesh = myToCreate ?
702 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
706 // get mesh and geom object
707 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
708 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
710 QString anEntry = myDlg->selectedObject
711 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
712 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
714 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
715 if ( myToCreate ) // mesh and geom may be selected
717 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
718 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
719 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
720 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
722 else // edition: sub-mesh may be selected
724 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
725 if ( !sm->_is_nil() ) {
726 aMeshVar = sm->GetFather();
727 aGeomVar = sm->GetSubShape();
732 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
733 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
738 return SMESH::SMESH_Hypothesis::_nil();
741 //================================================================================
743 * \brief Calls plugin methods for hypothesis creation
744 * \param theHypType - specifies whether main hypotheses or additional ones
746 * \param theIndex - index of type of hypothesis to be cerated
748 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
749 * its type and calls plugin methods for hypothesis creation
751 //================================================================================
752 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
754 // Speicfies dimension of hypothesis to be created
755 const QObject* aSender = sender();
757 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
758 if ( aSender == myDlg->tab( i ) )
763 // Speicfies type of hypothesis to be created
764 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
765 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
768 QString aHypTypeName = aHypTypeNames[ theIndex ];
769 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
773 QString aClientLibName = aData->ClientLibName;
774 QStringList anOldHyps;
775 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
776 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
778 if ( aClientLibName == "" )
780 // Call hypothesis creation server method (without GUI)
781 QString aHypName = aData->Label;
782 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
786 // Get hypotheses creator client (GUI)
787 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
792 // When create or edit a submesh, try to initialize a new hypothesis
793 // with values used to mesh a subshape
794 SMESH::SMESH_Hypothesis_var initParamHyp =
795 getInitParamsHypothesis( aHypTypeName, aData->ServerLibName );
797 if ( initParamHyp->_is_nil() )
798 aCreator->create( false, myDlg );
800 aCreator->create( initParamHyp, myDlg );
804 SMESH::CreateHypothesis( aHypTypeName, aData->Label, false );
808 QStringList aNewHyps;
809 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
810 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
811 if ( aNewHyps.count() > anOldHyps.count() )
813 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
814 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
818 //================================================================================
820 * \brief Calls plugin methods for hypothesis editing
821 * \param theHypType - specifies whether main hypothesis or additional one
823 * \param theIndex - index of existing hypothesis
825 * Calls plugin methods for hypothesis editing
827 //================================================================================
828 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
830 // Speicfies dimension of hypothesis to be created
831 const QObject* aSender = sender();
833 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
834 if ( aSender == myDlg->tab( i ) )
839 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
840 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
841 if ( aHyp->_is_nil() )
844 char* aTypeName = aHyp->GetName();
845 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
847 aCreator->edit( aHyp.in(), dlg() );
850 //================================================================================
852 * \brief Creates and selects hypothesis of hypotheses set
853 * \param theSetName - The name of hypotheses set
855 //================================================================================
857 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
859 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
860 if ( !aHypoSet ) return;
862 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
864 bool isAlgo = (aHypType == Algo);
867 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
868 setCurrentHyp( dim, aHypType, -1 );
870 // set hyps from the set
872 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
873 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
875 const QString& aHypoTypeName = (*aHypoList)[ i ];
876 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
880 int aDim = aHypData->Dim[0];
885 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
886 index = aHypTypeNameList.findIndex( aHypoTypeName );
887 if ( index < 0 ) continue;
888 setCurrentHyp ( aDim, aHypType, index );
892 // try to find an existing hypo
893 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
894 int /*iHyp = 0,*/ nbHyp = aList.count();
895 // for ( ; iHyp < nbHyp; ++iHyp )
897 // SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
898 // if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
903 if ( index >= 0 ) // found
905 // select the found hypothesis
906 setCurrentHyp ( aDim, aHypType, index );
910 // create a hypothesis
911 QString aClientLibName = aHypData->ClientLibName;
912 if ( aClientLibName == "" ) {
913 // Call hypothesis creation server method (without GUI)
914 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
917 // Get hypotheses creator client (GUI)
918 SMESHGUI_GenericHypothesisCreator* aCreator =
919 SMESH::GetHypothesisCreator( aHypoTypeName );
922 // When create or edit a submesh, try to initialize a new hypothesis
923 // with values used to mesh a subshape
924 SMESH::SMESH_Hypothesis_var initParamHyp =
925 getInitParamsHypothesis( aHypoTypeName, aHypData->ServerLibName );
926 aCreator->create( initParamHyp, myDlg );
930 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
933 QStringList aNewHyps;
934 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
935 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
936 if ( aList.count() > nbHyp )
938 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
939 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
943 } // loop on hypos in the set
944 } // loop on algo/hypo
947 //================================================================================
949 * \brief Creates mesh
950 * \param theMess - Output parameter intended for returning error message
951 * \retval bool - TRUE if mesh is created, FALSE otherwise
955 //================================================================================
956 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
960 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
961 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
962 GEOM::GEOM_Object_var aGeomVar =
963 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
965 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
966 if ( aSMESHGen->_is_nil() )
969 SUIT_OverrideCursor aWaitCursor;
972 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
973 if ( aMeshVar->_is_nil() )
975 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
977 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
979 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
981 if ( !isAccessibleDim( aDim )) continue;
984 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
986 int aHypIndex = currentHyp( aDim, aHypType );
987 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
989 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
990 if ( !aHypVar->_is_nil() )
991 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
994 // find or create algorithm
995 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
996 if ( !anAlgoVar->_is_nil() )
997 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1002 //================================================================================
1004 * \brief Creates sub-mesh
1005 * \param theMess - Output parameter intended for returning error message
1006 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1010 //================================================================================
1011 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1015 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1016 if ( aSMESHGen->_is_nil() )
1020 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1021 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1022 SMESH::SMESH_Mesh_var aMeshVar =
1023 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1026 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1027 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1028 GEOM::GEOM_Object_var aGeomVar =
1029 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1031 SUIT_OverrideCursor aWaitCursor;
1034 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1035 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1037 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1039 if ( !isAccessibleDim( aDim )) continue;
1041 // find or create algorithm
1042 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1043 if ( !anAlgoVar->_is_nil() )
1044 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1045 // assign hypotheses
1046 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1048 int aHypIndex = currentHyp( aDim, aHypType );
1049 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1051 SMESH::SMESH_Hypothesis_var aHypVar =
1052 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1053 if ( !aHypVar->_is_nil() )
1054 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1061 //================================================================================
1063 * \brief Gets current hypothesis or algorithms
1064 * \param theDim - dimension of hypothesis or algorithm
1065 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1066 * \retval int - current hypothesis or algorithms
1068 * Gets current hypothesis or algorithms
1070 //================================================================================
1071 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1073 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1076 //================================================================================
1078 * \brief Returns true if hypotheses of given dim can be assigned
1079 * \param theDim - hypotheses dimension
1080 * \retval bool - result
1082 //================================================================================
1083 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
1085 return myDlg->tab( theDim )->isEnabled();
1088 //================================================================================
1090 * \brief Sets current hypothesis or algorithms
1091 * \param theDim - dimension of hypothesis or algorithm
1092 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1093 * \param theIndex - Index of hypothesis
1095 * Gets current hypothesis or algorithms
1097 //================================================================================
1098 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1099 const int theHypType,
1100 const int theIndex )
1102 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1105 //================================================================================
1107 * \brief Generates default and sets mesh/submesh name
1109 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1111 //================================================================================
1112 void SMESHGUI_MeshOp::setDefaultName() const
1116 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1118 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1119 _PTR(SObject) anObj;
1122 aResName = aPrefix + QString::number( i++ );
1123 anObj = aStudy->FindObject( aResName.latin1() );
1127 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1128 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1129 aControl->setText( aResName );
1132 //================================================================================
1134 * \brief Gets algorithm or creates it if necessary
1135 * \param theDim - specifies dimension of returned hypotheses/algorifms
1136 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1138 * Gets algorithm or creates it if necessary
1140 //================================================================================
1141 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1143 SMESH::SMESH_Hypothesis_var anAlgoVar;
1144 int aHypIndex = currentHyp( theDim, Algo );
1145 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
1146 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
1148 QString aHypName = aHypTypeNameList[ aHypIndex ];
1149 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1150 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1151 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1153 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1154 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1156 anAlgoVar = aHypVar;
1160 if ( anAlgoVar->_is_nil() )
1162 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1165 QString aClientLibName = aHypData->ClientLibName;
1166 if ( aClientLibName == "" )
1167 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
1170 SMESHGUI_GenericHypothesisCreator* aCreator =
1171 SMESH::GetHypothesisCreator( aHypName );
1173 aCreator->create( true, myDlg );
1175 QStringList tmpList;
1176 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1177 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1180 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1181 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1183 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1184 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1186 anAlgoVar = aHypVar;
1192 return anAlgoVar._retn();
1195 //================================================================================
1197 * \brief Reads parameters of edited mesh and assigns them to the dialog
1199 * Reads parameters of edited mesh and assigns them to the dialog (called when
1200 * mesh is edited only)
1202 //================================================================================
1203 void SMESHGUI_MeshOp::readMesh()
1205 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1206 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1210 // Get name of mesh if current object is sub-mesh
1211 SMESH::SMESH_subMesh_var aSubMeshVar =
1212 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1213 if ( !aSubMeshVar->_is_nil() )
1215 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1216 if ( !aMeshVar->_is_nil() )
1218 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1219 QString aMeshName = name( aMeshSO );
1220 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1224 // Get name of geometry object
1225 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1226 if ( !aGeomVar->_is_nil() )
1228 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1229 QString aShapeName = name( aGeomSO );
1230 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1233 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1234 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1237 QStringList anExisting;
1239 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1240 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1242 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1243 QString aHypTypeName = aVar->GetName();
1245 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
1246 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
1247 if ( aHypTypeName == aHypTypeNameList[ i ] )
1253 setCurrentHyp( dim, Algo, aHypIndex );
1256 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1259 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1260 // find index of requered hypothesis among existing ones for this dimension
1263 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1264 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1265 myExistingHyps[ dim ][ hypType ] );
1266 setCurrentHyp( dim, hypType, aHypIndex );
1271 //================================================================================
1273 * \brief Gets name of object
1274 * \param theSO - SObject
1275 * \retval QString - name of object
1277 * Gets name of object
1279 //================================================================================
1280 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1285 _PTR(GenericAttribute) anAttr;
1286 _PTR(AttributeName) aNameAttr;
1287 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1290 aResName = aNameAttr->Value().c_str();
1296 //================================================================================
1298 * \brief Finds hypothesis in input list
1299 * \param theHyp - hypothesis to be found
1300 * \param theHypList - input list of hypotheses
1301 * \retval int - index of hypothesis or -1 if it is not found
1303 * Finds position of hypothesis in input list
1305 //================================================================================
1306 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1307 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1310 if ( !theHyp->_is_nil() )
1313 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1314 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1316 if ( theHyp->_is_equivalent( *anIter ) )
1327 //================================================================================
1329 * \brief Edits mesh or sub-mesh
1330 * \param theMess - Output parameter intended for returning error message
1331 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1333 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1335 //================================================================================
1336 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1340 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1341 if ( aSMESHGen->_is_nil() )
1344 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1345 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1349 SUIT_OverrideCursor aWaitCursor;
1352 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1354 // Assign new hypotheses and algorithms
1355 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1357 if ( !isAccessibleDim( dim )) continue;
1359 // find or create algorithm
1360 bool toDelete = false, toAdd = true;
1361 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1362 if ( anAlgoVar->_is_nil() ) {
1365 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1366 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1368 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1377 // remove old algorithm
1379 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1380 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1382 // assign new algorithm
1384 SMESH::SMESH_Mesh_var aMeshVar =
1385 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1386 bool isMesh = !aMeshVar->_is_nil();
1388 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1390 SMESH::SMESH_subMesh_var aVar =
1391 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1392 if ( !aVar->_is_nil() )
1393 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1397 // assign hypotheses
1398 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1400 int aNewHypIndex = currentHyp( dim, hypType );
1401 int anOldHypIndex = -1;
1402 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1403 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1404 myExistingHyps[ dim ][ hypType ] );
1405 if ( aNewHypIndex != anOldHypIndex )
1407 // remove old hypotheses
1408 if ( anOldHypIndex >= 0 )
1409 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1410 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1412 // assign new hypotheses
1413 if ( aNewHypIndex != -1 )
1415 SMESH::SMESH_Mesh_var aMeshVar =
1416 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1417 bool isMesh = !aMeshVar->_is_nil();
1420 SMESH::AddHypothesisOnMesh(
1421 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1425 SMESH::SMESH_subMesh_var aVar =
1426 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1427 if ( !aVar->_is_nil() )
1428 SMESH::AddHypothesisOnSubMesh(
1429 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1432 // reread all hypotheses of mesh if necessary
1433 QStringList anExisting;
1434 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1442 //================================================================================
1444 * \brief Verifies whether given operator is valid for this one
1445 * \param theOtherOp - other operation
1446 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1448 * method redefined from base class verifies whether given operator is valid for
1449 * this one (i.e. can be started "above" this operator). In current implementation method
1450 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1453 //================================================================================
1454 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1456 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1459 //================================================================================
1461 * \brief SLOT. Is called when the user selects a way of geometry selection
1462 * \param theByMesh - true if the user wants to find geometry by mesh element
1464 //================================================================================
1466 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1469 if ( !myShapeByMeshDlg ) {
1470 myShapeByMeshDlg = new SMESHGUI_ShapeByMeshDlg( SMESHGUI::GetSMESHGUI(), "ShapeByMeshDlg");
1471 connect(myShapeByMeshDlg, SIGNAL(PublishShape()), SLOT(onPublishShapeByMeshDlg()));
1472 connect(myShapeByMeshDlg, SIGNAL(Close()), SLOT(onCloseShapeByMeshDlg()));
1474 // set mesh object to dlg
1475 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1476 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1477 SMESH::SMESH_Mesh_var aMeshVar =
1478 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1479 if ( !aMeshVar->_is_nil() ) {
1481 myDlg->activateObject( SMESHGUI_MeshDlg::Mesh );
1482 myShapeByMeshDlg->Init();
1483 myShapeByMeshDlg->SetMesh( aMeshVar );
1484 myShapeByMeshDlg->show();
1490 //================================================================================
1492 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1494 //================================================================================
1496 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg()
1498 if ( myShapeByMeshDlg ) {
1499 // Select a found geometry object
1500 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshDlg->GetShape();
1501 if ( !aGeomVar->_is_nil() )
1503 QString ID = aGeomVar->GetStudyEntry();
1504 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID )) {
1505 SMESH::SMESH_Mesh_ptr aMeshPtr = myShapeByMeshDlg->GetMesh();
1506 if ( !CORBA::is_nil( aMeshPtr )) {
1507 if (_PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshPtr )) {
1508 myDlg->activateObject( SMESHGUI_MeshDlg::Mesh );
1509 myDlg->selectObject( aMeshSO->GetName(), SMESHGUI_MeshDlg::Mesh, aMeshSO->GetID() );
1512 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
1513 selectObject( aGeomSO );
1518 onCloseShapeByMeshDlg();
1524 //================================================================================
1526 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1528 //================================================================================
1530 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg()
1534 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
1535 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1539 //================================================================================
1541 * \brief Selects a SObject
1542 * \param theSObj - the SObject to select
1544 //================================================================================
1546 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1548 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1549 SALOME_ListIO anIOList;
1551 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1552 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1553 anIOList.Append( anIO );
1555 sm->setSelectedObjects( anIOList, false );