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 )));
213 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
214 else myHelpFileName = "/files/constructing_submeshes.htm";
215 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
217 SMESHGUI_SelectionOp::startOperation();
219 // iterate through dimensions and get available and existing algoritms and hypotheses,
220 // set them to the dialog
222 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
223 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
225 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
226 QStringList anAvailable, anExisting;
227 for ( j = Algo; j <= AddHyp; j++ )
229 availableHyps( i, j, anAvailable );
230 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
232 aTab->setAvailableHyps( j, anAvailable );
233 aTab->setExistingHyps( j, anExisting );
239 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
242 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
244 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
246 myDlg->setCurrentTab( SMESH::DIM_1D );
252 //================================================================================
254 * \brief Creates selection filter
255 * \param theId - identifier of current selection widget
256 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
258 * Creates selection filter in accordance with identifier of current selection widget
260 //================================================================================
261 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
263 if ( theId == SMESHGUI_MeshDlg::Geom )
265 // TColStd_MapOfInteger allTypesMap;
266 // for ( int i = 0; i < 10; i++ )
267 // allTypesMap.Add( i );
268 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
269 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
271 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
272 return new SMESH_TypeFilter( MESHorSUBMESH );
273 else if ( theId == SMESHGUI_MeshDlg::Mesh )
274 return new SMESH_TypeFilter( MESH );
279 //================================================================================
281 * \brief check if selected shape is a subshape of the shape to mesh
282 * \retval bool - check result
284 //================================================================================
286 bool SMESHGUI_MeshOp::isSubshapeOk() const
288 if ( !myToCreate || myIsMesh ) // not submesh creation
291 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
292 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
293 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
294 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
295 if ( pMesh && pGeom ) {
296 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
297 if ( !mesh->_is_nil() ) {
298 GEOM::GEOM_Object_var mainGeom, subGeom;
299 mainGeom = mesh->GetShapeToMesh();
300 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
301 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
302 TopoDS_Shape mainShape, subShape;
303 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
304 GEOMBase::GetShape( subGeom, subShape ) )
306 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
308 // 1 is index of mainShape itself
309 return index > 1; // it is a subshape
312 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
313 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
314 if ( !geomGen->_is_nil() && aStudy ) {
315 GEOM::GEOM_IGroupOperations_var op =
316 geomGen->GetIGroupOperations( aStudy->StudyId() );
317 if ( ! op->_is_nil() ) {
318 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
319 if ( !mainObj->_is_nil() )
320 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
330 //================================================================================
332 * \brief find an existing submesh by the selected shape
333 * \retval _PTR(SObject) - the found submesh SObject
335 //================================================================================
337 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
339 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
340 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
341 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
342 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
343 if ( pMesh && pGeom ) {
344 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
345 if ( !geom->_is_nil() ) {
347 switch ( geom->GetShapeType() ) {
348 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
349 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
350 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
351 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
352 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
353 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
356 _PTR(SObject) aSubmeshRoot;
357 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
358 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
360 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
361 for (; smIter->More(); smIter->Next() )
363 _PTR(SObject) aSmObj = smIter->Value();
364 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
365 for (; anIter1->More(); anIter1->Next()) {
366 _PTR(SObject) pGeom2 = anIter1->Value();
367 if ( pGeom2->ReferencedObject( pGeom2 ) &&
368 pGeom2->GetID() == pGeom->GetID() )
375 return _PTR(SObject)();
378 //================================================================================
380 * \brief Updates dialog's look and feel
382 * Virtual method redefined from the base class updates dialog's look and feel
384 //================================================================================
385 void SMESHGUI_MeshOp::selectionDone()
387 if ( !dlg()->isShown() )
390 SMESHGUI_SelectionOp::selectionDone();
394 // Enable tabs according to shape dimension
398 GEOM::GEOM_Object_var aGeomVar;
399 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
400 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
402 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
405 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
406 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
407 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
409 if ( !aGeomVar->_is_nil() ) {
411 switch ( aGeomVar->GetShapeType() ) {
413 case GEOM::SHELL: shapeDim = 3; break;
414 case GEOM::FACE: shapeDim = 2; break;
416 case GEOM::EDGE: shapeDim = 1; break;
417 case GEOM::VERTEX: shapeDim = 0; break;
420 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
421 TopExp_Explorer exp( aShape, TopAbs_SHELL );
424 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
426 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
433 myDlg->setMaxHypoDim( shapeDim );
435 if ( !myToCreate ) // edition: read hypotheses
437 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
438 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
441 SMESH::SMESH_subMesh_var aVar =
442 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
443 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
444 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
445 myDlg->updateGeometry();
453 else if ( !myIsMesh ) // submesh creation
455 // if a submesh on the selected shape already exist, pass to submesh edition mode
456 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
457 SMESH::SMESH_subMesh_var sm =
458 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
459 bool editSubmesh = ( !sm->_is_nil() &&
460 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
461 tr( "EDIT_SUBMESH_QUESTION"),
462 tr( "SMESH_BUT_YES" ),
463 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
466 selectionMgr()->clearFilters();
467 selectObject( pSubmesh );
468 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
473 selectObject( _PTR(SObject)() );
474 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
478 // enable/disable popup for choice of geom selection way
480 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
481 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
482 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
483 if ( !mesh->_is_nil() )
484 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
486 myDlg->setGeomPopupEnabled( enable );
489 catch ( const SALOME::SALOME_Exception& S_ex )
491 SalomeApp_Tools::QtCatchCorbaException( S_ex );
498 //================================================================================
500 * \brief Verifies validity of input data
501 * \param theMess - Output parameter intended for returning error message
502 * \retval bool - TRUE if input data is valid, false otherwise
504 * Verifies validity of input data. This method is called when "Apply" or "OK" button
505 * is pressed before mesh creation or editing.
507 //================================================================================
508 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
510 // Selected object to be edited
511 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
513 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
518 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
519 aMeshName = aMeshName.stripWhiteSpace();
520 if ( aMeshName == "" )
522 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
526 // Imported mesh, if create sub-mesh or edit mesh
527 if ( !myToCreate || ( myToCreate && !myIsMesh ))
529 QString aMeshEntry = myDlg->selectedObject
530 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
531 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
532 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
533 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
534 theMess = tr( "IMPORTED_MESH" );
543 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
544 if ( aGeomEntry == "" )
546 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
549 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
550 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
552 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
557 if ( !myIsMesh ) // i.e sub-mesh creation,
559 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
560 if ( aMeshEntry == "" )
562 theMess = tr( "MESH_IS_NOT_DEFINED" );
565 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
566 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
568 theMess = tr( "MESH_IS_NULL" );
571 if ( !isSubshapeOk() )
573 theMess = tr( "INVALID_SUBSHAPE" );
582 //================================================================================
584 * \brief Gets available hypotheses or algorithms
585 * \param theDim - specifies dimension of returned hypotheses/algorifms
586 * \param theHypType - specifies whether algorims or hypotheses or additional ones
587 * are retrieved (possible values are in HypType enumeration)
588 * \param theHyps - Output list of hypotheses' names
590 * Gets available hypotheses or algorithm in accordance with input parameters
592 //================================================================================
593 void SMESHGUI_MeshOp::availableHyps( const int theDim,
594 const int theHypType,
595 QStringList& theHyps ) const
598 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
599 theHypType == Algo , theDim, theHypType == AddHyp );
600 QStringList::const_iterator anIter;
601 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
603 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
604 theHyps.append( aData->Label );
608 //================================================================================
610 * \brief Gets existing hypotheses or algorithms
611 * \param theDim - specifies dimension of returned hypotheses/algorifms
612 * \param theHypType - specifies whether algorims or hypotheses or additional ones
613 * are retrieved (possible values are in HypType enumeration)
614 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
615 * \param theHyps - output list of names.
616 * \param theHypVars - output list of variables.
618 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
621 //================================================================================
622 void SMESHGUI_MeshOp::existingHyps( const int theDim,
623 const int theHypType,
624 _PTR(SObject) theFather,
625 QStringList& theHyps,
626 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
628 // Clear hypoheses list
635 _PTR(SObject) aHypRoot;
636 _PTR(GenericAttribute) anAttr;
637 _PTR(AttributeName) aName;
638 _PTR(AttributeIOR) anIOR;
640 bool isMesh = !_CAST( SComponent, theFather );
643 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
645 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
647 if ( theFather->FindSubObject( aPart, aHypRoot ) )
649 _PTR(ChildIterator) anIter =
650 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
651 for (; anIter->More(); anIter->Next() )
653 _PTR(SObject) anObj = anIter->Value();
654 if ( isMesh ) // i.e. mesh or submesh
656 _PTR(SObject) aRefObj;
657 if ( anObj->ReferencedObject( aRefObj ) )
662 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
665 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
666 if ( !CORBA::is_nil( aVar ) )
668 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
669 if ( !aHypVar->_is_nil() )
671 QString aHypType( aHypVar->GetName() );
672 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
673 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
674 ( theHypType == AddHyp ) == aData->IsAux )
676 theHyps.append( aName->Value().c_str() );
677 theHypVars.append( aHypVar );
686 //================================================================================
688 * \brief If create or edit a submesh, return a hypothesis holding parameters used
690 * \param aHypType - The hypothesis type name
691 * \param aServerLib - Server library name
692 * \param hypData - The structure holding the hypothesis type etc.
693 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
695 //================================================================================
697 SMESH::SMESH_Hypothesis_var
698 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
699 const QString& aServerLib ) const
701 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
702 return SMESH::SMESH_Hypothesis::_nil();
704 const int nbColonsInMeshEntry = 3;
705 bool isSubMesh = myToCreate ?
707 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
711 // get mesh and geom object
712 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
713 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
715 QString anEntry = myDlg->selectedObject
716 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
717 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
719 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
720 if ( myToCreate ) // mesh and geom may be selected
722 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
723 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
724 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
725 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
727 else // edition: sub-mesh may be selected
729 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
730 if ( !sm->_is_nil() ) {
731 aMeshVar = sm->GetFather();
732 aGeomVar = sm->GetSubShape();
737 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
738 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
743 return SMESH::SMESH_Hypothesis::_nil();
746 //================================================================================
748 * \brief Create hypothesis
749 * \param theHypType - hypothesis category (main or additional)
750 * \param theIndex - index of type of hypothesis to be cerated
752 * Specifies dimension of hypothesis to be created (using sender() method),
753 * specifies its type and calls method for hypothesis creation
755 //================================================================================
756 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
758 // Specifies dimension of hypothesis to be created
759 const QObject* aSender = sender();
761 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
762 if (aSender == myDlg->tab(i))
767 // Specifies type of hypothesis to be created
768 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses(false, aDim, theHypType == AddHyp);
769 if (theIndex < 0 || theIndex >= aHypTypeNames.count())
771 QString aHypTypeName = aHypTypeNames[ theIndex ];
774 createHypothesis(aDim, theHypType, aHypTypeName);
777 //================================================================================
779 * Create hypothesis and update dialog.
780 * \param theDim - dimension of hypothesis to be created
781 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
782 * \param theTypeName - specifies hypothesis to be created
784 //================================================================================
785 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
787 const QString& theTypeName)
789 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
794 QValueList<SMESH::SMESH_Hypothesis_var>& aList = myExistingHyps[theDim][theType];
795 int nbHyp = aList.count();
797 QString aClientLibName = aData->ClientLibName;
798 if (aClientLibName == "") {
799 // Call hypothesis creation server method (without GUI)
800 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
802 // Get hypotheses creator client (GUI)
803 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
807 // When create or edit a submesh, try to initialize a new hypothesis
808 // with values used to mesh a subshape
809 SMESH::SMESH_Hypothesis_var initParamHyp =
810 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
811 aCreator->create(initParamHyp, myDlg);
813 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
817 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
819 QStringList aNewHyps;
820 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType]);
821 if (aNewHyps.count() > nbHyp) {
822 for (int i = nbHyp; i < aNewHyps.count(); i++)
823 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
827 //================================================================================
829 * \brief Calls plugin methods for hypothesis editing
830 * \param theHypType - specifies whether main hypothesis or additional one
832 * \param theIndex - index of existing hypothesis
834 * Calls plugin methods for hypothesis editing
836 //================================================================================
837 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
839 // Speicfies dimension of hypothesis to be created
840 const QObject* aSender = sender();
842 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
843 if ( aSender == myDlg->tab( i ) )
848 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
849 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
850 if ( aHyp->_is_nil() )
853 char* aTypeName = aHyp->GetName();
854 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
856 aCreator->edit( aHyp.in(), dlg() );
859 //================================================================================
861 * \brief Creates and selects hypothesis of hypotheses set
862 * \param theSetName - The name of hypotheses set
864 //================================================================================
865 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
867 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
868 if (!aHypoSet) return;
870 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
871 bool isAlgo = (aHypType == Algo);
874 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++)
875 setCurrentHyp(dim, aHypType, -1);
877 // set hyps from the set
878 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
879 for (int i = 0, n = aHypoList->count(); i < n; i++) {
880 const QString& aHypoTypeName = (*aHypoList)[ i ];
881 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
885 int aDim = aHypData->Dim[0];
888 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(isAlgo, aDim);
889 int index = aHypTypeNameList.findIndex(aHypoTypeName);
890 if (index < 0) continue;
891 setCurrentHyp(aDim, aHypType, index);
893 createHypothesis(aDim, aHypType, aHypoTypeName);
895 } // loop on hypos in the set
896 } // loop on algo/hypo
899 //================================================================================
901 * \brief Creates mesh
902 * \param theMess - Output parameter intended for returning error message
903 * \retval bool - TRUE if mesh is created, FALSE otherwise
907 //================================================================================
908 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
912 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
913 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
914 GEOM::GEOM_Object_var aGeomVar =
915 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
917 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
918 if ( aSMESHGen->_is_nil() )
921 SUIT_OverrideCursor aWaitCursor;
924 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
925 if ( aMeshVar->_is_nil() )
927 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
929 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
931 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
933 if ( !isAccessibleDim( aDim )) continue;
936 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
938 int aHypIndex = currentHyp( aDim, aHypType );
939 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
941 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
942 if ( !aHypVar->_is_nil() )
943 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
946 // find or create algorithm
947 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
948 if ( !anAlgoVar->_is_nil() )
949 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
954 //================================================================================
956 * \brief Creates sub-mesh
957 * \param theMess - Output parameter intended for returning error message
958 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
962 //================================================================================
963 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
967 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
968 if ( aSMESHGen->_is_nil() )
972 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
973 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
974 SMESH::SMESH_Mesh_var aMeshVar =
975 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
978 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
979 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
980 GEOM::GEOM_Object_var aGeomVar =
981 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
983 SUIT_OverrideCursor aWaitCursor;
986 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
987 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
989 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
991 if ( !isAccessibleDim( aDim )) continue;
993 // find or create algorithm
994 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
995 if ( !anAlgoVar->_is_nil() )
996 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
998 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1000 int aHypIndex = currentHyp( aDim, aHypType );
1001 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1003 SMESH::SMESH_Hypothesis_var aHypVar =
1004 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1005 if ( !aHypVar->_is_nil() )
1006 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1013 //================================================================================
1015 * \brief Gets current hypothesis or algorithms
1016 * \param theDim - dimension of hypothesis or algorithm
1017 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1018 * \retval int - current hypothesis or algorithms
1020 * Gets current hypothesis or algorithms
1022 //================================================================================
1023 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1025 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1028 //================================================================================
1030 * \brief Returns true if hypotheses of given dim can be assigned
1031 * \param theDim - hypotheses dimension
1032 * \retval bool - result
1034 //================================================================================
1035 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
1037 return myDlg->tab( theDim )->isEnabled();
1040 //================================================================================
1042 * \brief Sets current hypothesis or algorithms
1043 * \param theDim - dimension of hypothesis or algorithm
1044 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1045 * \param theIndex - Index of hypothesis
1047 * Gets current hypothesis or algorithms
1049 //================================================================================
1050 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1051 const int theHypType,
1052 const int theIndex )
1054 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1057 //================================================================================
1059 * \brief Generates default and sets mesh/submesh name
1061 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1063 //================================================================================
1064 void SMESHGUI_MeshOp::setDefaultName() const
1068 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1070 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1071 _PTR(SObject) anObj;
1074 aResName = aPrefix + QString::number( i++ );
1075 anObj = aStudy->FindObject( aResName.latin1() );
1079 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1080 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1081 aControl->setText( aResName );
1084 //================================================================================
1086 * \brief Gets algorithm or creates it if necessary
1087 * \param theDim - specifies dimension of returned hypotheses/algorifms
1088 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1090 * Gets algorithm or creates it if necessary
1092 //================================================================================
1093 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1095 SMESH::SMESH_Hypothesis_var anAlgoVar;
1096 int aHypIndex = currentHyp( theDim, Algo );
1097 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
1098 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
1100 QString aHypName = aHypTypeNameList[ aHypIndex ];
1101 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1102 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1103 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1105 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1106 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1108 anAlgoVar = aHypVar;
1113 if (anAlgoVar->_is_nil()) {
1114 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1116 QString aClientLibName = aHypData->ClientLibName;
1117 if (aClientLibName == "") {
1118 // Call hypothesis creation server method (without GUI)
1119 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1121 // Get hypotheses creator client (GUI)
1122 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1126 aCreator->create(true, myDlg);
1128 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1130 QStringList tmpList;
1131 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1132 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1135 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1136 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1138 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1139 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1141 anAlgoVar = aHypVar;
1147 return anAlgoVar._retn();
1150 //================================================================================
1152 * \brief Reads parameters of edited mesh and assigns them to the dialog
1154 * Reads parameters of edited mesh and assigns them to the dialog (called when
1155 * mesh is edited only)
1157 //================================================================================
1158 void SMESHGUI_MeshOp::readMesh()
1160 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1161 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1165 // Get name of mesh if current object is sub-mesh
1166 SMESH::SMESH_subMesh_var aSubMeshVar =
1167 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1168 if ( !aSubMeshVar->_is_nil() )
1170 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1171 if ( !aMeshVar->_is_nil() )
1173 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1174 QString aMeshName = name( aMeshSO );
1175 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1179 // Get name of geometry object
1180 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1181 if ( !aGeomVar->_is_nil() )
1183 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1184 QString aShapeName = name( aGeomSO );
1185 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1188 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1189 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1192 QStringList anExisting;
1194 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1195 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1197 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1198 QString aHypTypeName = aVar->GetName();
1200 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
1201 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
1202 if ( aHypTypeName == aHypTypeNameList[ i ] )
1208 setCurrentHyp( dim, Algo, aHypIndex );
1211 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1214 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1215 // find index of requered hypothesis among existing ones for this dimension
1218 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1219 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1220 myExistingHyps[ dim ][ hypType ] );
1221 setCurrentHyp( dim, hypType, aHypIndex );
1226 //================================================================================
1228 * \brief Gets name of object
1229 * \param theSO - SObject
1230 * \retval QString - name of object
1232 * Gets name of object
1234 //================================================================================
1235 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1240 _PTR(GenericAttribute) anAttr;
1241 _PTR(AttributeName) aNameAttr;
1242 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1245 aResName = aNameAttr->Value().c_str();
1251 //================================================================================
1253 * \brief Finds hypothesis in input list
1254 * \param theHyp - hypothesis to be found
1255 * \param theHypList - input list of hypotheses
1256 * \retval int - index of hypothesis or -1 if it is not found
1258 * Finds position of hypothesis in input list
1260 //================================================================================
1261 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1262 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1265 if ( !theHyp->_is_nil() )
1268 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1269 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1271 if ( theHyp->_is_equivalent( *anIter ) )
1282 //================================================================================
1284 * \brief Edits mesh or sub-mesh
1285 * \param theMess - Output parameter intended for returning error message
1286 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1288 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1290 //================================================================================
1291 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1295 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1296 if ( aSMESHGen->_is_nil() )
1299 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1300 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1304 SUIT_OverrideCursor aWaitCursor;
1307 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1309 // Assign new hypotheses and algorithms
1310 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1312 if ( !isAccessibleDim( dim )) continue;
1314 // find or create algorithm
1315 bool toDelete = false, toAdd = true;
1316 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1317 if ( anAlgoVar->_is_nil() ) {
1320 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1321 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1323 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1332 // remove old algorithm
1334 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1335 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1337 // assign new algorithm
1339 SMESH::SMESH_Mesh_var aMeshVar =
1340 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1341 bool isMesh = !aMeshVar->_is_nil();
1343 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1345 SMESH::SMESH_subMesh_var aVar =
1346 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1347 if ( !aVar->_is_nil() )
1348 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1352 // assign hypotheses
1353 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1355 int aNewHypIndex = currentHyp( dim, hypType );
1356 int anOldHypIndex = -1;
1357 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1358 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1359 myExistingHyps[ dim ][ hypType ] );
1360 if ( aNewHypIndex != anOldHypIndex )
1362 // remove old hypotheses
1363 if ( anOldHypIndex >= 0 )
1364 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1365 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1367 // assign new hypotheses
1368 if ( aNewHypIndex != -1 )
1370 SMESH::SMESH_Mesh_var aMeshVar =
1371 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1372 bool isMesh = !aMeshVar->_is_nil();
1375 SMESH::AddHypothesisOnMesh(
1376 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1380 SMESH::SMESH_subMesh_var aVar =
1381 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1382 if ( !aVar->_is_nil() )
1383 SMESH::AddHypothesisOnSubMesh(
1384 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1387 // reread all hypotheses of mesh if necessary
1388 QStringList anExisting;
1389 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1397 //================================================================================
1399 * \brief Verifies whether given operator is valid for this one
1400 * \param theOtherOp - other operation
1401 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1403 * method redefined from base class verifies whether given operator is valid for
1404 * this one (i.e. can be started "above" this operator). In current implementation method
1405 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1408 //================================================================================
1409 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1411 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1414 //================================================================================
1416 * \brief SLOT. Is called when the user selects a way of geometry selection
1417 * \param theByMesh - true if the user wants to find geometry by mesh element
1419 //================================================================================
1421 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1424 if ( !myShapeByMeshOp ) {
1425 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1426 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1427 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1428 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1429 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1431 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1432 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1433 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1434 SMESH::SMESH_Mesh_var aMeshVar =
1435 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1436 if ( !aMeshVar->_is_nil() ) {
1438 myShapeByMeshOp->setModule( getSMESHGUI() );
1439 myShapeByMeshOp->setStudy( 0 );
1440 myShapeByMeshOp->SetMesh( aMeshVar );
1441 myShapeByMeshOp->start();
1447 //================================================================================
1449 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1451 //================================================================================
1453 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1455 if ( myShapeByMeshOp == op ) {
1457 // Select a found geometry object
1458 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1459 if ( !aGeomVar->_is_nil() )
1461 QString ID = aGeomVar->GetStudyEntry();
1462 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1463 selectObject( aGeomSO );
1470 //================================================================================
1472 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1474 //================================================================================
1476 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1478 if ( myShapeByMeshOp == op && myDlg ) {
1483 //================================================================================
1485 * \brief Selects a SObject
1486 * \param theSObj - the SObject to select
1488 //================================================================================
1490 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1492 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1493 SALOME_ListIO anIOList;
1495 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1496 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1497 anIOList.Append( anIO );
1499 sm->setSelectedObjects( anIOList, false );