1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
23 * Copyright (C) 2005 CEA/DEN, EDF R&D
27 * File : SMESHGUI_MeshOp.h
28 * Author : Sergey LITONIN
32 #include "SMESHGUI_MeshOp.h"
33 #include "SMESHGUI_MeshDlg.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESH_TypeFilter.hxx"
38 #include "SMESHGUI_HypothesesUtils.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
41 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESHGUI_VTKUtils.h"
44 #include "SMESH_TypeFilter.hxx"
45 #include "SMESH_NumberFilter.hxx"
47 #include "GEOM_SelectionFilter.h"
49 #include "GeometryGUI.h"
51 #include "SalomeApp_Tools.h"
52 #include "SALOMEDSClient_Study.hxx"
53 #include "SALOMEDSClient_AttributeIOR.hxx"
54 #include "SALOMEDSClient_AttributeName.hxx"
55 #include "SALOMEDS_SComponent.hxx"
56 #include "SALOMEDS_SObject.hxx"
58 #include "LightApp_SelectionMgr.h"
59 #include "LightApp_UpdateFlags.h"
60 #include "SUIT_MessageBox.h"
61 #include "SUIT_Desktop.h"
62 #include "SUIT_OverrideCursor.h"
63 #include "SALOME_InteractiveObject.hxx"
64 #include "SALOME_ListIO.hxx"
66 #include "utilities.h"
68 #include <qstringlist.h>
69 #include <qlineedit.h>
71 #include <TopoDS_Shape.hxx>
72 #include <TopExp_Explorer.hxx>
74 enum { GLOBAL_ALGO_TAG =3,
78 SUBMESH_ON_EDGE_TAG =5,
79 SUBMESH_ON_WIRE_TAG =6,
80 SUBMESH_ON_FACE_TAG =7,
81 SUBMESH_ON_SHELL_TAG =8,
82 SUBMESH_ON_SOLID_TAG =9,
83 SUBMESH_ON_COMPOUND_TAG=10 };
85 //================================================================================
88 * \param theToCreate - if this parameter is true then operation is used for creation,
89 * for editing otherwise
91 * Initialize operation
93 //================================================================================
94 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
95 : SMESHGUI_SelectionOp(),
96 myToCreate( theToCreate ),
97 myIsMesh( theIsMesh ),
101 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
102 GeometryGUI::InitGeomGen();
105 //================================================================================
109 //================================================================================
110 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
116 //================================================================================
118 * \brief Gets dialog of this operation
119 * \retval LightApp_Dialog* - pointer to dialog of this operation
121 //================================================================================
122 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
127 //================================================================================
129 * \brief Creates or edits mesh
130 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
132 * Virtual slot redefined from the base class called when "Apply" button is clicked
133 * creates or edits mesh
135 //================================================================================
136 bool SMESHGUI_MeshOp::onApply()
138 if( isStudyLocked() )
142 if ( !isValid( aMess ) )
146 SUIT_MessageBox::warn1( myDlg,
147 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
151 bool aResult = false;
155 if ( myToCreate && myIsMesh )
156 aResult = createMesh( aMess );
157 if ( myToCreate && !myIsMesh )
158 aResult = createSubMesh( aMess );
159 else if ( !myToCreate )
160 aResult = editMeshOrSubMesh( aMess );
162 update( UF_ObjBrowser | UF_Model );
164 catch ( const SALOME::SALOME_Exception& S_ex )
166 SalomeApp_Tools::QtCatchCorbaException( S_ex );
182 aMess = tr( "SMESH_OPERATION_FAILED" );
183 SUIT_MessageBox::warn1( myDlg,
184 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
190 //================================================================================
192 * \brief Creates dialog if necessary and shows it
194 * Virtual method redefined from base class called when operation is started creates
195 * dialog if necessary and shows it, activates selection
197 //================================================================================
198 void SMESHGUI_MeshOp::startOperation()
202 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
203 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
205 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
206 this, SLOT( onCreateHyp( const int, const int) ) );
207 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
208 this, SLOT( onEditHyp( const int, const int) ) );
210 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
211 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
214 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
215 else myHelpFileName = "/files/constructing_submeshes.htm";
216 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
218 SMESHGUI_SelectionOp::startOperation();
220 // iterate through dimensions and get available and existing algoritms and hypotheses,
221 // set them to the dialog
223 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
224 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
226 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
227 QStringList anAvailable, anExisting;
228 for ( j = Algo; j <= AddHyp; j++ )
230 availableHyps( i, j, anAvailable );
231 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
233 aTab->setAvailableHyps( j, anAvailable );
234 aTab->setExistingHyps( j, anExisting );
240 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
243 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
245 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
247 myDlg->setCurrentTab( SMESH::DIM_1D );
253 //================================================================================
255 * \brief Creates selection filter
256 * \param theId - identifier of current selection widget
257 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
259 * Creates selection filter in accordance with identifier of current selection widget
261 //================================================================================
262 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
264 if ( theId == SMESHGUI_MeshDlg::Geom )
266 // TColStd_MapOfInteger allTypesMap;
267 // for ( int i = 0; i < 10; i++ )
268 // allTypesMap.Add( i );
269 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
270 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
272 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
273 return new SMESH_TypeFilter( MESHorSUBMESH );
274 else if ( theId == SMESHGUI_MeshDlg::Mesh )
275 return new SMESH_TypeFilter( MESH );
280 //================================================================================
282 * \brief check if selected shape is a subshape of the shape to mesh
283 * \retval bool - check result
285 //================================================================================
287 bool SMESHGUI_MeshOp::isSubshapeOk() const
289 if ( !myToCreate || myIsMesh ) // not submesh creation
292 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
293 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
294 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
295 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
296 if ( pMesh && pGeom ) {
297 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
298 if ( !mesh->_is_nil() ) {
299 GEOM::GEOM_Object_var mainGeom, subGeom;
300 mainGeom = mesh->GetShapeToMesh();
301 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
302 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
303 TopoDS_Shape mainShape, subShape;
304 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
305 GEOMBase::GetShape( subGeom, subShape ) )
307 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
309 // 1 is index of mainShape itself
310 return index > 1; // it is a subshape
313 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
314 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
315 if ( !geomGen->_is_nil() && aStudy ) {
316 GEOM::GEOM_IGroupOperations_var op =
317 geomGen->GetIGroupOperations( aStudy->StudyId() );
318 if ( ! op->_is_nil() ) {
319 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
320 if ( !mainObj->_is_nil() )
321 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
331 //================================================================================
333 * \brief find an existing submesh by the selected shape
334 * \retval _PTR(SObject) - the found submesh SObject
336 //================================================================================
338 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
340 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
341 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
342 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
343 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
344 if ( pMesh && pGeom ) {
345 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
346 if ( !geom->_is_nil() ) {
348 switch ( geom->GetShapeType() ) {
349 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
350 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
351 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
352 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
353 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
354 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
357 _PTR(SObject) aSubmeshRoot;
358 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
359 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
361 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
362 for (; smIter->More(); smIter->Next() )
364 _PTR(SObject) aSmObj = smIter->Value();
365 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
366 for (; anIter1->More(); anIter1->Next()) {
367 _PTR(SObject) pGeom2 = anIter1->Value();
368 if ( pGeom2->ReferencedObject( pGeom2 ) &&
369 pGeom2->GetID() == pGeom->GetID() )
376 return _PTR(SObject)();
379 //================================================================================
381 * \brief Updates dialog's look and feel
383 * Virtual method redefined from the base class updates dialog's look and feel
385 //================================================================================
386 void SMESHGUI_MeshOp::selectionDone()
388 if ( !dlg()->isShown() )
391 SMESHGUI_SelectionOp::selectionDone();
395 // Enable tabs according to shape dimension
399 GEOM::GEOM_Object_var aGeomVar;
400 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
401 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
403 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
406 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
407 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
408 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
410 if ( !aGeomVar->_is_nil() ) {
412 switch ( aGeomVar->GetShapeType() ) {
414 case GEOM::SHELL: shapeDim = 3; break;
415 case GEOM::FACE: shapeDim = 2; break;
417 case GEOM::EDGE: shapeDim = 1; break;
418 case GEOM::VERTEX: shapeDim = 0; break;
421 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
422 TopExp_Explorer exp( aShape, TopAbs_SHELL );
425 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
427 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
434 myDlg->setMaxHypoDim( shapeDim );
436 if ( !myToCreate ) // edition: read hypotheses
438 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
439 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
442 SMESH::SMESH_subMesh_var aVar =
443 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
444 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
445 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
446 myDlg->updateGeometry();
454 else if ( !myIsMesh ) // submesh creation
456 // if a submesh on the selected shape already exist, pass to submesh edition mode
457 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
458 SMESH::SMESH_subMesh_var sm =
459 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
460 bool editSubmesh = ( !sm->_is_nil() &&
461 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
462 tr( "EDIT_SUBMESH_QUESTION"),
463 tr( "SMESH_BUT_YES" ),
464 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
467 selectionMgr()->clearFilters();
468 selectObject( pSubmesh );
469 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
474 selectObject( _PTR(SObject)() );
475 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
479 // enable/disable popup for choice of geom selection way
481 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
482 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
483 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
484 if ( !mesh->_is_nil() )
485 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
487 myDlg->setGeomPopupEnabled( enable );
490 catch ( const SALOME::SALOME_Exception& S_ex )
492 SalomeApp_Tools::QtCatchCorbaException( S_ex );
499 //================================================================================
501 * \brief Verifies validity of input data
502 * \param theMess - Output parameter intended for returning error message
503 * \retval bool - TRUE if input data is valid, false otherwise
505 * Verifies validity of input data. This method is called when "Apply" or "OK" button
506 * is pressed before mesh creation or editing.
508 //================================================================================
509 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
511 // Selected object to be edited
512 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
514 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
519 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
520 aMeshName = aMeshName.stripWhiteSpace();
521 if ( aMeshName == "" )
523 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
527 // Imported mesh, if create sub-mesh or edit mesh
528 if ( !myToCreate || ( myToCreate && !myIsMesh ))
530 QString aMeshEntry = myDlg->selectedObject
531 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
532 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
533 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
534 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
535 theMess = tr( "IMPORTED_MESH" );
544 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
545 if ( aGeomEntry == "" )
547 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
550 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
551 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
553 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
558 if ( !myIsMesh ) // i.e sub-mesh creation,
560 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
561 if ( aMeshEntry == "" )
563 theMess = tr( "MESH_IS_NOT_DEFINED" );
566 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
567 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
569 theMess = tr( "MESH_IS_NULL" );
572 if ( !isSubshapeOk() )
574 theMess = tr( "INVALID_SUBSHAPE" );
583 //================================================================================
585 * \brief Gets available hypotheses or algorithms
586 * \param theDim - specifies dimension of returned hypotheses/algorifms
587 * \param theHypType - specifies whether algorims or hypotheses or additional ones
588 * are retrieved (possible values are in HypType enumeration)
589 * \param theHyps - Output list of hypotheses' names
591 * Gets available hypotheses or algorithm in accordance with input parameters
593 //================================================================================
594 void SMESHGUI_MeshOp::availableHyps( const int theDim,
595 const int theHypType,
596 QStringList& theHyps ) const
599 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
600 theHypType == Algo , theDim, theHypType == AddHyp );
601 QStringList::const_iterator anIter;
602 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
604 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
605 theHyps.append( aData->Label );
609 //================================================================================
611 * \brief Gets existing hypotheses or algorithms
612 * \param theDim - specifies dimension of returned hypotheses/algorifms
613 * \param theHypType - specifies whether algorims or hypotheses or additional ones
614 * are retrieved (possible values are in HypType enumeration)
615 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
616 * \param theHyps - output list of names.
617 * \param theHypVars - output list of variables.
619 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
622 //================================================================================
623 void SMESHGUI_MeshOp::existingHyps( const int theDim,
624 const int theHypType,
625 _PTR(SObject) theFather,
626 QStringList& theHyps,
627 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
629 // Clear hypoheses list
636 _PTR(SObject) aHypRoot;
637 _PTR(GenericAttribute) anAttr;
638 _PTR(AttributeName) aName;
639 _PTR(AttributeIOR) anIOR;
641 bool isMesh = !_CAST( SComponent, theFather );
644 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
646 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
648 if ( theFather->FindSubObject( aPart, aHypRoot ) )
650 _PTR(ChildIterator) anIter =
651 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
652 for (; anIter->More(); anIter->Next() )
654 _PTR(SObject) anObj = anIter->Value();
655 if ( isMesh ) // i.e. mesh or submesh
657 _PTR(SObject) aRefObj;
658 if ( anObj->ReferencedObject( aRefObj ) )
663 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
666 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
667 if ( !CORBA::is_nil( aVar ) )
669 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
670 if ( !aHypVar->_is_nil() )
672 QString aHypType( aHypVar->GetName() );
673 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
674 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
675 ( theHypType == AddHyp ) == aData->IsAux )
677 theHyps.append( aName->Value().c_str() );
678 theHypVars.append( aHypVar );
687 //================================================================================
689 * \brief If create or edit a submesh, return a hypothesis holding parameters used
691 * \param aHypType - The hypothesis type name
692 * \param aServerLib - Server library name
693 * \param hypData - The structure holding the hypothesis type etc.
694 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
696 //================================================================================
698 SMESH::SMESH_Hypothesis_var
699 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
700 const QString& aServerLib ) const
702 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
703 return SMESH::SMESH_Hypothesis::_nil();
705 const int nbColonsInMeshEntry = 3;
706 bool isSubMesh = myToCreate ?
708 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
712 // get mesh and geom object
713 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
714 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
716 QString anEntry = myDlg->selectedObject
717 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
718 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
720 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
721 if ( myToCreate ) // mesh and geom may be selected
723 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
724 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
725 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
726 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
728 else // edition: sub-mesh may be selected
730 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
731 if ( !sm->_is_nil() ) {
732 aMeshVar = sm->GetFather();
733 aGeomVar = sm->GetSubShape();
738 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
739 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
744 return SMESH::SMESH_Hypothesis::_nil();
747 //================================================================================
749 * \brief Create hypothesis
750 * \param theHypType - hypothesis category (main or additional)
751 * \param theIndex - index of type of hypothesis to be cerated
753 * Specifies dimension of hypothesis to be created (using sender() method),
754 * specifies its type and calls method for hypothesis creation
756 //================================================================================
757 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
759 // Specifies dimension of hypothesis to be created
760 const QObject* aSender = sender();
762 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
763 if (aSender == myDlg->tab(i))
768 // Specifies type of hypothesis to be created
769 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses(false, aDim, theHypType == AddHyp);
770 if (theIndex < 0 || theIndex >= aHypTypeNames.count())
772 QString aHypTypeName = aHypTypeNames[ theIndex ];
775 createHypothesis(aDim, theHypType, aHypTypeName);
778 //================================================================================
780 * Create hypothesis and update dialog.
781 * \param theDim - dimension of hypothesis to be created
782 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
783 * \param theTypeName - specifies hypothesis to be created
785 //================================================================================
786 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
788 const QString& theTypeName)
790 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
795 QValueList<SMESH::SMESH_Hypothesis_var>& aList = myExistingHyps[theDim][theType];
796 int nbHyp = aList.count();
798 QString aClientLibName = aData->ClientLibName;
799 if (aClientLibName == "") {
800 // Call hypothesis creation server method (without GUI)
801 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
803 // Get hypotheses creator client (GUI)
804 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
808 // When create or edit a submesh, try to initialize a new hypothesis
809 // with values used to mesh a subshape
810 SMESH::SMESH_Hypothesis_var initParamHyp =
811 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
812 aCreator->create(initParamHyp, myDlg);
814 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
818 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
820 QStringList aNewHyps;
821 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType]);
822 if (aNewHyps.count() > nbHyp) {
823 for (int i = nbHyp; i < aNewHyps.count(); i++)
824 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
828 //================================================================================
830 * \brief Calls plugin methods for hypothesis editing
831 * \param theHypType - specifies whether main hypothesis or additional one
833 * \param theIndex - index of existing hypothesis
835 * Calls plugin methods for hypothesis editing
837 //================================================================================
838 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
840 // Speicfies dimension of hypothesis to be created
841 const QObject* aSender = sender();
843 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
844 if ( aSender == myDlg->tab( i ) )
849 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
850 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
851 if ( aHyp->_is_nil() )
854 char* aTypeName = aHyp->GetName();
855 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
857 aCreator->edit( aHyp.in(), dlg() );
860 //================================================================================
862 * \brief Creates and selects hypothesis of hypotheses set
863 * \param theSetName - The name of hypotheses set
865 //================================================================================
866 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
868 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
869 if (!aHypoSet) return;
871 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
872 bool isAlgo = (aHypType == Algo);
875 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++)
876 setCurrentHyp(dim, aHypType, -1);
878 // set hyps from the set
879 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
880 for (int i = 0, n = aHypoList->count(); i < n; i++) {
881 const QString& aHypoTypeName = (*aHypoList)[ i ];
882 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
886 int aDim = aHypData->Dim[0];
889 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(isAlgo, aDim);
890 int index = aHypTypeNameList.findIndex(aHypoTypeName);
891 if (index < 0) continue;
892 setCurrentHyp(aDim, aHypType, index);
894 createHypothesis(aDim, aHypType, aHypoTypeName);
896 } // loop on hypos in the set
897 } // loop on algo/hypo
900 //================================================================================
902 * \brief Creates mesh
903 * \param theMess - Output parameter intended for returning error message
904 * \retval bool - TRUE if mesh is created, FALSE otherwise
908 //================================================================================
909 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
913 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
914 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
915 GEOM::GEOM_Object_var aGeomVar =
916 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
918 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
919 if ( aSMESHGen->_is_nil() )
922 SUIT_OverrideCursor aWaitCursor;
925 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
926 if ( aMeshVar->_is_nil() )
928 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
930 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
932 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
934 if ( !isAccessibleDim( aDim )) continue;
937 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
939 int aHypIndex = currentHyp( aDim, aHypType );
940 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
942 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
943 if ( !aHypVar->_is_nil() )
944 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
947 // find or create algorithm
948 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
949 if ( !anAlgoVar->_is_nil() )
950 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
955 //================================================================================
957 * \brief Creates sub-mesh
958 * \param theMess - Output parameter intended for returning error message
959 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
963 //================================================================================
964 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
968 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
969 if ( aSMESHGen->_is_nil() )
973 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
974 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
975 SMESH::SMESH_Mesh_var aMeshVar =
976 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
979 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
980 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
981 GEOM::GEOM_Object_var aGeomVar =
982 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
984 SUIT_OverrideCursor aWaitCursor;
987 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
988 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
990 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
992 if ( !isAccessibleDim( aDim )) continue;
994 // find or create algorithm
995 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
996 if ( !anAlgoVar->_is_nil() )
997 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
999 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1001 int aHypIndex = currentHyp( aDim, aHypType );
1002 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1004 SMESH::SMESH_Hypothesis_var aHypVar =
1005 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1006 if ( !aHypVar->_is_nil() )
1007 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1014 //================================================================================
1016 * \brief Gets current hypothesis or algorithms
1017 * \param theDim - dimension of hypothesis or algorithm
1018 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1019 * \retval int - current hypothesis or algorithms
1021 * Gets current hypothesis or algorithms
1023 //================================================================================
1024 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1026 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1029 //================================================================================
1031 * \brief Returns true if hypotheses of given dim can be assigned
1032 * \param theDim - hypotheses dimension
1033 * \retval bool - result
1035 //================================================================================
1036 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
1038 return myDlg->tab( theDim )->isEnabled();
1041 //================================================================================
1043 * \brief Sets current hypothesis or algorithms
1044 * \param theDim - dimension of hypothesis or algorithm
1045 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1046 * \param theIndex - Index of hypothesis
1048 * Gets current hypothesis or algorithms
1050 //================================================================================
1051 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1052 const int theHypType,
1053 const int theIndex )
1055 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1058 //================================================================================
1060 * \brief Generates default and sets mesh/submesh name
1062 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1064 //================================================================================
1065 void SMESHGUI_MeshOp::setDefaultName() const
1069 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1071 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1072 _PTR(SObject) anObj;
1075 aResName = aPrefix + QString::number( i++ );
1076 anObj = aStudy->FindObject( aResName.latin1() );
1080 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1081 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1082 aControl->setText( aResName );
1085 //================================================================================
1087 * \brief Gets algorithm or creates it if necessary
1088 * \param theDim - specifies dimension of returned hypotheses/algorifms
1089 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1091 * Gets algorithm or creates it if necessary
1093 //================================================================================
1094 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1096 SMESH::SMESH_Hypothesis_var anAlgoVar;
1097 int aHypIndex = currentHyp( theDim, Algo );
1098 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
1099 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
1101 QString aHypName = aHypTypeNameList[ aHypIndex ];
1102 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1103 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1104 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1106 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1107 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1109 anAlgoVar = aHypVar;
1114 if (anAlgoVar->_is_nil()) {
1115 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1117 QString aClientLibName = aHypData->ClientLibName;
1118 if (aClientLibName == "") {
1119 // Call hypothesis creation server method (without GUI)
1120 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1122 // Get hypotheses creator client (GUI)
1123 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1127 aCreator->create(true, myDlg);
1129 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1131 QStringList tmpList;
1132 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1133 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1136 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1137 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1139 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1140 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1142 anAlgoVar = aHypVar;
1148 return anAlgoVar._retn();
1151 //================================================================================
1153 * \brief Reads parameters of edited mesh and assigns them to the dialog
1155 * Reads parameters of edited mesh and assigns them to the dialog (called when
1156 * mesh is edited only)
1158 //================================================================================
1159 void SMESHGUI_MeshOp::readMesh()
1161 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1162 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1166 // Get name of mesh if current object is sub-mesh
1167 SMESH::SMESH_subMesh_var aSubMeshVar =
1168 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1169 if ( !aSubMeshVar->_is_nil() )
1171 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1172 if ( !aMeshVar->_is_nil() )
1174 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1175 QString aMeshName = name( aMeshSO );
1176 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1180 // Get name of geometry object
1181 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1182 if ( !aGeomVar->_is_nil() )
1184 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1185 QString aShapeName = name( aGeomSO );
1186 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1189 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1190 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1193 QStringList anExisting;
1195 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1196 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1198 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1199 QString aHypTypeName = aVar->GetName();
1201 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
1202 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
1203 if ( aHypTypeName == aHypTypeNameList[ i ] )
1209 setCurrentHyp( dim, Algo, aHypIndex );
1212 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1215 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1216 // find index of requered hypothesis among existing ones for this dimension
1219 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1220 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1221 myExistingHyps[ dim ][ hypType ] );
1222 setCurrentHyp( dim, hypType, aHypIndex );
1227 //================================================================================
1229 * \brief Gets name of object
1230 * \param theSO - SObject
1231 * \retval QString - name of object
1233 * Gets name of object
1235 //================================================================================
1236 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1241 _PTR(GenericAttribute) anAttr;
1242 _PTR(AttributeName) aNameAttr;
1243 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1246 aResName = aNameAttr->Value().c_str();
1252 //================================================================================
1254 * \brief Finds hypothesis in input list
1255 * \param theHyp - hypothesis to be found
1256 * \param theHypList - input list of hypotheses
1257 * \retval int - index of hypothesis or -1 if it is not found
1259 * Finds position of hypothesis in input list
1261 //================================================================================
1262 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1263 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1266 if ( !theHyp->_is_nil() )
1269 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1270 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1272 if ( theHyp->_is_equivalent( *anIter ) )
1283 //================================================================================
1285 * \brief Edits mesh or sub-mesh
1286 * \param theMess - Output parameter intended for returning error message
1287 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1289 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1291 //================================================================================
1292 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1296 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1297 if ( aSMESHGen->_is_nil() )
1300 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1301 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1305 SUIT_OverrideCursor aWaitCursor;
1308 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1310 // Assign new hypotheses and algorithms
1311 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1313 if ( !isAccessibleDim( dim )) continue;
1315 // find or create algorithm
1316 bool toDelete = false, toAdd = true;
1317 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1318 if ( anAlgoVar->_is_nil() ) {
1321 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1322 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1324 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1333 // remove old algorithm
1335 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1336 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1338 // assign new algorithm
1340 SMESH::SMESH_Mesh_var aMeshVar =
1341 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1342 bool isMesh = !aMeshVar->_is_nil();
1344 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1346 SMESH::SMESH_subMesh_var aVar =
1347 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1348 if ( !aVar->_is_nil() )
1349 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1353 // assign hypotheses
1354 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1356 int aNewHypIndex = currentHyp( dim, hypType );
1357 int anOldHypIndex = -1;
1358 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1359 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1360 myExistingHyps[ dim ][ hypType ] );
1361 if ( aNewHypIndex != anOldHypIndex )
1363 // remove old hypotheses
1364 if ( anOldHypIndex >= 0 )
1365 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1366 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1368 // assign new hypotheses
1369 if ( aNewHypIndex != -1 )
1371 SMESH::SMESH_Mesh_var aMeshVar =
1372 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1373 bool isMesh = !aMeshVar->_is_nil();
1376 SMESH::AddHypothesisOnMesh(
1377 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1381 SMESH::SMESH_subMesh_var aVar =
1382 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1383 if ( !aVar->_is_nil() )
1384 SMESH::AddHypothesisOnSubMesh(
1385 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1388 // reread all hypotheses of mesh if necessary
1389 QStringList anExisting;
1390 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1398 //================================================================================
1400 * \brief Verifies whether given operator is valid for this one
1401 * \param theOtherOp - other operation
1402 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1404 * method redefined from base class verifies whether given operator is valid for
1405 * this one (i.e. can be started "above" this operator). In current implementation method
1406 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1409 //================================================================================
1410 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1412 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1415 //================================================================================
1417 * \brief SLOT. Is called when the user selects a way of geometry selection
1418 * \param theByMesh - true if the user wants to find geometry by mesh element
1420 //================================================================================
1422 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1425 if ( !myShapeByMeshOp ) {
1426 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1427 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1428 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1429 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1430 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1432 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1433 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1434 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1435 SMESH::SMESH_Mesh_var aMeshVar =
1436 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1437 if ( !aMeshVar->_is_nil() ) {
1439 myShapeByMeshOp->setModule( getSMESHGUI() );
1440 myShapeByMeshOp->setStudy( 0 );
1441 myShapeByMeshOp->SetMesh( aMeshVar );
1442 myShapeByMeshOp->start();
1448 //================================================================================
1450 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1452 //================================================================================
1454 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1456 if ( myShapeByMeshOp == op ) {
1458 // Select a found geometry object
1459 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1460 if ( !aGeomVar->_is_nil() )
1462 QString ID = aGeomVar->GetStudyEntry();
1463 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1464 selectObject( aGeomSO );
1471 //================================================================================
1473 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1475 //================================================================================
1477 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1479 if ( myShapeByMeshOp == op && myDlg ) {
1484 //================================================================================
1486 * \brief Selects a SObject
1487 * \param theSObj - the SObject to select
1489 //================================================================================
1491 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1493 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1494 SALOME_ListIO anIOList;
1496 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1497 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1498 anIOList.Append( anIO );
1500 sm->setSelectedObjects( anIOList, false );