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 ) )
300 // 1 is index of mainShape itself
301 return GEOMBase::GetIndex( subShape, mainShape, 0 ) > 1;
308 //================================================================================
310 * \brief find an existing submesh by the selected shape
311 * \retval _PTR(SObject) - the found submesh SObject
313 //================================================================================
315 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
317 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
318 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
319 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
320 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
321 if ( pMesh && pGeom ) {
322 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
323 if ( !geom->_is_nil() ) {
325 switch ( geom->GetShapeType() ) {
326 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
327 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
328 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
329 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
330 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
331 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
334 _PTR(SObject) aSubmeshRoot;
335 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
336 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
338 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
339 for (; smIter->More(); smIter->Next() )
341 _PTR(SObject) aSmObj = smIter->Value();
342 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
343 for (; anIter1->More(); anIter1->Next()) {
344 _PTR(SObject) pGeom2 = anIter1->Value();
345 if ( pGeom2->ReferencedObject( pGeom2 ) &&
346 pGeom2->GetID() == pGeom->GetID() )
353 return _PTR(SObject)();
356 //================================================================================
358 * \brief Updates dialog's look and feel
360 * Virtual method redefined from the base class updates dialog's look and feel
362 //================================================================================
363 void SMESHGUI_MeshOp::selectionDone()
365 SMESHGUI_SelectionOp::selectionDone();
369 if ( !myToCreate ) // edition
371 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
372 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
375 SMESH::SMESH_subMesh_var aVar =
376 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
377 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
378 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
379 myDlg->updateGeometry();
387 else if ( !myIsMesh ) // submesh creation
389 // if a submesh on the selected shape already exist, pass to submesh edition mode
390 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
391 SMESH::SMESH_subMesh_var sm =
392 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
393 bool editSubmesh = ( !sm->_is_nil() &&
394 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
395 tr( "EDIT_SUBMESH_QUESTION"),
396 tr( "SMESH_BUT_YES" ),
397 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
400 selectionMgr()->clearFilters();
401 selectObject( pSubmesh );
402 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
406 selectObject( _PTR(SObject)() );
407 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
410 // enable/disable popup for choice of geom selection way
411 myDlg->setGeomPopupEnabled( !myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ).isEmpty() );
415 catch ( const SALOME::SALOME_Exception& S_ex )
417 SalomeApp_Tools::QtCatchCorbaException( S_ex );
424 // Enable tabs according to shape dimension
429 GEOM::GEOM_Object_var aGeomVar;
430 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
431 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
433 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
436 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
437 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
438 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
440 if ( !aGeomVar->_is_nil() ) {
442 switch ( aGeomVar->GetShapeType() ) {
444 case GEOM::SHELL: shapeDim = 3; break;
445 case GEOM::FACE: shapeDim = 2; break;
447 case GEOM::EDGE: shapeDim = 1; break;
448 case GEOM::VERTEX: shapeDim = 0; break;
451 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
452 TopExp_Explorer exp( aShape, TopAbs_SHELL );
455 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
457 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
465 catch ( const SALOME::SALOME_Exception& S_ex )
467 SalomeApp_Tools::QtCatchCorbaException( S_ex );
472 myDlg->setMaxHypoDim( shapeDim );
475 //================================================================================
477 * \brief Verifies validity of input data
478 * \param theMess - Output parameter intended for returning error message
479 * \retval bool - TRUE if input data is valid, false otherwise
481 * Verifies validity of input data. This method is called when "Apply" or "OK" button
482 * is pressed before mesh creation or editing.
484 //================================================================================
485 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
487 // Selected object to be edited
488 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
490 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
495 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
496 aMeshName = aMeshName.stripWhiteSpace();
497 if ( aMeshName == "" )
499 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
503 // Imported mesh, if create sub-mesh or edit mesh
504 if ( !myToCreate || ( myToCreate && !myIsMesh ))
506 QString aMeshEntry = myDlg->selectedObject
507 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
508 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
509 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
510 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
511 theMess = tr( "IMPORTED_MESH" );
520 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
521 if ( aGeomEntry == "" )
523 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
526 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
527 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
529 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
534 if ( !myIsMesh ) // i.e sub-mesh creation,
536 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
537 if ( aMeshEntry == "" )
539 theMess = tr( "MESH_IS_NOT_DEFINED" );
542 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
543 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
545 theMess = tr( "MESH_IS_NULL" );
548 if ( !isSubshapeOk() )
550 theMess = tr( "INVALID_SUBSHAPE" );
559 //================================================================================
561 * \brief Gets available hypotheses or algorithms
562 * \param theDim - specifies dimension of returned hypotheses/algorifms
563 * \param theHypType - specifies whether algorims or hypotheses or additional ones
564 * are retrieved (possible values are in HypType enumeration)
565 * \param theHyps - Output list of hypotheses' names
567 * Gets available hypotheses or algorithm in accordance with input parameters
569 //================================================================================
570 void SMESHGUI_MeshOp::availableHyps( const int theDim,
571 const int theHypType,
572 QStringList& theHyps ) const
575 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
576 theHypType == Algo , theDim, theHypType == AddHyp );
577 QStringList::const_iterator anIter;
578 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
580 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
581 theHyps.append( aData->Label );
585 //================================================================================
587 * \brief Gets existing hypotheses or algorithms
588 * \param theDim - specifies dimension of returned hypotheses/algorifms
589 * \param theHypType - specifies whether algorims or hypotheses or additional ones
590 * are retrieved (possible values are in HypType enumeration)
591 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
592 * \param theHyps - output list of names.
593 * \param theHypVars - output list of variables.
595 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
598 //================================================================================
599 void SMESHGUI_MeshOp::existingHyps( const int theDim,
600 const int theHypType,
601 _PTR(SObject) theFather,
602 QStringList& theHyps,
603 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
605 // Clear hypoheses list
612 _PTR(SObject) aHypRoot;
613 _PTR(GenericAttribute) anAttr;
614 _PTR(AttributeName) aName;
615 _PTR(AttributeIOR) anIOR;
617 bool isMesh = !_CAST( SComponent, theFather );
620 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
622 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
624 if ( theFather->FindSubObject( aPart, aHypRoot ) )
626 _PTR(ChildIterator) anIter =
627 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
628 for (; anIter->More(); anIter->Next() )
630 _PTR(SObject) anObj = anIter->Value();
631 if ( isMesh ) // i.e. mesh or submesh
633 _PTR(SObject) aRefObj;
634 if ( anObj->ReferencedObject( aRefObj ) )
639 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
642 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
643 if ( !CORBA::is_nil( aVar ) )
645 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
646 if ( !aHypVar->_is_nil() )
648 QString aHypType( aHypVar->GetName() );
649 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
650 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
651 ( theHypType == AddHyp ) == aData->IsAux )
653 theHyps.append( aName->Value().c_str() );
654 theHypVars.append( aHypVar );
663 //================================================================================
665 * \brief If create or edit a submesh, return a hypothesis holding parameters used
667 * \param aHypType - The hypothesis type name
668 * \param aServerLib - Server library name
669 * \param hypData - The structure holding the hypothesis type etc.
670 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
672 //================================================================================
674 SMESH::SMESH_Hypothesis_var
675 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
676 const QString& aServerLib ) const
678 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
679 return SMESH::SMESH_Hypothesis::_nil();
681 const int nbColonsInMeshEntry = 3;
682 bool isSubMesh = myToCreate ?
684 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
688 // get mesh and geom object
689 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
690 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
692 QString anEntry = myDlg->selectedObject
693 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
694 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
696 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
697 if ( myToCreate ) // mesh and geom may be selected
699 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
700 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
701 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
702 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
704 else // edition: sub-mesh may be selected
706 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
707 if ( !sm->_is_nil() ) {
708 aMeshVar = sm->GetFather();
709 aGeomVar = sm->GetSubShape();
714 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
715 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
720 return SMESH::SMESH_Hypothesis::_nil();
723 //================================================================================
725 * \brief Calls plugin methods for hypothesis creation
726 * \param theHypType - specifies whether main hypotheses or additional ones
728 * \param theIndex - index of type of hypothesis to be cerated
730 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
731 * its type and calls plugin methods for hypothesis creation
733 //================================================================================
734 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
736 // Speicfies dimension of hypothesis to be created
737 const QObject* aSender = sender();
739 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
740 if ( aSender == myDlg->tab( i ) )
745 // Speicfies type of hypothesis to be created
746 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
747 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
750 QString aHypTypeName = aHypTypeNames[ theIndex ];
751 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
755 QString aClientLibName = aData->ClientLibName;
756 QStringList anOldHyps;
757 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
758 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
760 if ( aClientLibName == "" )
762 // Call hypothesis creation server method (without GUI)
763 QString aHypName = aData->Label;
764 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
768 // Get hypotheses creator client (GUI)
769 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
774 // When create or edit a submesh, try to initialize a new hypothesis
775 // with values used to mesh a subshape
776 SMESH::SMESH_Hypothesis_var initParamHyp =
777 getInitParamsHypothesis( aHypTypeName, aData->ServerLibName );
779 if ( initParamHyp->_is_nil() )
780 aCreator->create( false, myDlg );
782 aCreator->create( initParamHyp, myDlg );
786 SMESH::CreateHypothesis( aHypTypeName, aData->Label, false );
790 QStringList aNewHyps;
791 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
792 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
793 if ( aNewHyps.count() > anOldHyps.count() )
795 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
796 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
800 //================================================================================
802 * \brief Calls plugin methods for hypothesis editing
803 * \param theHypType - specifies whether main hypothesis or additional one
805 * \param theIndex - index of existing hypothesis
807 * Calls plugin methods for hypothesis editing
809 //================================================================================
810 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
812 // Speicfies dimension of hypothesis to be created
813 const QObject* aSender = sender();
815 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
816 if ( aSender == myDlg->tab( i ) )
821 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
822 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
823 if ( aHyp->_is_nil() )
826 char* aTypeName = aHyp->GetName();
827 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
829 aCreator->edit( aHyp.in(), dlg() );
832 //================================================================================
834 * \brief Creates and selects hypothesis of hypotheses set
835 * \param theSetName - The name of hypotheses set
837 //================================================================================
839 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
841 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
842 if ( !aHypoSet ) return;
844 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
846 bool isAlgo = (aHypType == Algo);
849 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
850 setCurrentHyp( dim, aHypType, -1 );
852 // set hyps from the set
854 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
855 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
857 const QString& aHypoTypeName = (*aHypoList)[ i ];
858 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
862 int aDim = aHypData->Dim[0];
867 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
868 index = aHypTypeNameList.findIndex( aHypoTypeName );
869 if ( index < 0 ) continue;
870 setCurrentHyp ( aDim, aHypType, index );
874 // try to find an existing hypo
875 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
876 int /*iHyp = 0,*/ nbHyp = aList.count();
877 // for ( ; iHyp < nbHyp; ++iHyp )
879 // SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
880 // if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
885 if ( index >= 0 ) // found
887 // select the found hypothesis
888 setCurrentHyp ( aDim, aHypType, index );
892 // create a hypothesis
893 QString aClientLibName = aHypData->ClientLibName;
894 if ( aClientLibName == "" ) {
895 // Call hypothesis creation server method (without GUI)
896 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
899 // Get hypotheses creator client (GUI)
900 SMESHGUI_GenericHypothesisCreator* aCreator =
901 SMESH::GetHypothesisCreator( aHypoTypeName );
904 // When create or edit a submesh, try to initialize a new hypothesis
905 // with values used to mesh a subshape
906 SMESH::SMESH_Hypothesis_var initParamHyp =
907 getInitParamsHypothesis( aHypoTypeName, aHypData->ServerLibName );
908 aCreator->create( initParamHyp, myDlg );
912 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
915 QStringList aNewHyps;
916 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
917 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
918 if ( aList.count() > nbHyp )
920 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
921 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
925 } // loop on hypos in the set
926 } // loop on algo/hypo
929 //================================================================================
931 * \brief Creates mesh
932 * \param theMess - Output parameter intended for returning error message
933 * \retval bool - TRUE if mesh is created, FALSE otherwise
937 //================================================================================
938 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
942 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
943 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
944 GEOM::GEOM_Object_var aGeomVar =
945 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
947 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
948 if ( aSMESHGen->_is_nil() )
951 SUIT_OverrideCursor aWaitCursor;
954 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
955 if ( aMeshVar->_is_nil() )
957 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
959 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
961 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
963 if ( !isAccessibleDim( aDim )) continue;
966 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
968 int aHypIndex = currentHyp( aDim, aHypType );
969 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
971 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
972 if ( !aHypVar->_is_nil() )
973 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
976 // find or create algorithm
977 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
978 if ( !anAlgoVar->_is_nil() )
979 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
984 //================================================================================
986 * \brief Creates sub-mesh
987 * \param theMess - Output parameter intended for returning error message
988 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
992 //================================================================================
993 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
997 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
998 if ( aSMESHGen->_is_nil() )
1002 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1003 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1004 SMESH::SMESH_Mesh_var aMeshVar =
1005 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1008 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1009 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1010 GEOM::GEOM_Object_var aGeomVar =
1011 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1013 SUIT_OverrideCursor aWaitCursor;
1016 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1017 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1019 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1021 if ( !isAccessibleDim( aDim )) continue;
1023 // find or create algorithm
1024 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1025 if ( !anAlgoVar->_is_nil() )
1026 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1027 // assign hypotheses
1028 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1030 int aHypIndex = currentHyp( aDim, aHypType );
1031 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1033 SMESH::SMESH_Hypothesis_var aHypVar =
1034 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1035 if ( !aHypVar->_is_nil() )
1036 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1043 //================================================================================
1045 * \brief Gets current hypothesis or algorithms
1046 * \param theDim - dimension of hypothesis or algorithm
1047 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1048 * \retval int - current hypothesis or algorithms
1050 * Gets current hypothesis or algorithms
1052 //================================================================================
1053 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1055 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1058 //================================================================================
1060 * \brief Returns true if hypotheses of given dim can be assigned
1061 * \param theDim - hypotheses dimension
1062 * \retval bool - result
1064 //================================================================================
1065 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
1067 return myDlg->tab( theDim )->isEnabled();
1070 //================================================================================
1072 * \brief Sets current hypothesis or algorithms
1073 * \param theDim - dimension of hypothesis or algorithm
1074 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1075 * \param theIndex - Index of hypothesis
1077 * Gets current hypothesis or algorithms
1079 //================================================================================
1080 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1081 const int theHypType,
1082 const int theIndex )
1084 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1087 //================================================================================
1089 * \brief Generates default and sets mesh/submesh name
1091 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1093 //================================================================================
1094 void SMESHGUI_MeshOp::setDefaultName() const
1098 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1100 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1101 _PTR(SObject) anObj;
1104 aResName = aPrefix + QString::number( i++ );
1105 anObj = aStudy->FindObject( aResName.latin1() );
1109 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1110 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1111 aControl->setText( aResName );
1114 //================================================================================
1116 * \brief Gets algorithm or creates it if necessary
1117 * \param theDim - specifies dimension of returned hypotheses/algorifms
1118 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1120 * Gets algorithm or creates it if necessary
1122 //================================================================================
1123 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1125 SMESH::SMESH_Hypothesis_var anAlgoVar;
1126 int aHypIndex = currentHyp( theDim, Algo );
1127 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
1128 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
1130 QString aHypName = aHypTypeNameList[ aHypIndex ];
1131 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1132 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1133 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1135 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1136 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1138 anAlgoVar = aHypVar;
1142 if ( anAlgoVar->_is_nil() )
1144 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1147 QString aClientLibName = aHypData->ClientLibName;
1148 if ( aClientLibName == "" )
1149 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
1152 SMESHGUI_GenericHypothesisCreator* aCreator =
1153 SMESH::GetHypothesisCreator( aHypName );
1155 aCreator->create( true, myDlg );
1157 QStringList tmpList;
1158 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1159 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1162 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1163 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1165 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1166 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1168 anAlgoVar = aHypVar;
1174 return anAlgoVar._retn();
1177 //================================================================================
1179 * \brief Reads parameters of edited mesh and assigns them to the dialog
1181 * Reads parameters of edited mesh and assigns them to the dialog (called when
1182 * mesh is edited only)
1184 //================================================================================
1185 void SMESHGUI_MeshOp::readMesh()
1187 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1188 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1192 // Get name of mesh if current object is sub-mesh
1193 SMESH::SMESH_subMesh_var aSubMeshVar =
1194 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1195 if ( !aSubMeshVar->_is_nil() )
1197 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1198 if ( !aMeshVar->_is_nil() )
1200 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1201 QString aMeshName = name( aMeshSO );
1202 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1206 // Get name of geometry object
1207 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1208 if ( !aGeomVar->_is_nil() )
1210 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1211 QString aShapeName = name( aGeomSO );
1212 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1215 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1216 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1219 QStringList anExisting;
1221 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1222 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1224 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1225 QString aHypTypeName = aVar->GetName();
1227 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
1228 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
1229 if ( aHypTypeName == aHypTypeNameList[ i ] )
1235 setCurrentHyp( dim, Algo, aHypIndex );
1238 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1241 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1242 // find index of requered hypothesis among existing ones for this dimension
1245 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1246 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1247 myExistingHyps[ dim ][ hypType ] );
1248 setCurrentHyp( dim, hypType, aHypIndex );
1253 //================================================================================
1255 * \brief Gets name of object
1256 * \param theSO - SObject
1257 * \retval QString - name of object
1259 * Gets name of object
1261 //================================================================================
1262 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1267 _PTR(GenericAttribute) anAttr;
1268 _PTR(AttributeName) aNameAttr;
1269 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1272 aResName = aNameAttr->Value().c_str();
1278 //================================================================================
1280 * \brief Finds hypothesis in input list
1281 * \param theHyp - hypothesis to be found
1282 * \param theHypList - input list of hypotheses
1283 * \retval int - index of hypothesis or -1 if it is not found
1285 * Finds position of hypothesis in input list
1287 //================================================================================
1288 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1289 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1292 if ( !theHyp->_is_nil() )
1295 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1296 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1298 if ( theHyp->_is_equivalent( *anIter ) )
1309 //================================================================================
1311 * \brief Edits mesh or sub-mesh
1312 * \param theMess - Output parameter intended for returning error message
1313 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1315 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1317 //================================================================================
1318 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1322 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1323 if ( aSMESHGen->_is_nil() )
1326 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1327 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1331 SUIT_OverrideCursor aWaitCursor;
1334 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1336 // Assign new hypotheses and algorithms
1337 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1339 if ( !isAccessibleDim( dim )) continue;
1341 // find or create algorithm
1342 bool toDelete = false, toAdd = true;
1343 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1344 if ( anAlgoVar->_is_nil() ) {
1347 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1348 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1350 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1359 // remove old algorithm
1361 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1362 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1364 // assign new algorithm
1366 SMESH::SMESH_Mesh_var aMeshVar =
1367 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1368 bool isMesh = !aMeshVar->_is_nil();
1370 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1372 SMESH::SMESH_subMesh_var aVar =
1373 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1374 if ( !aVar->_is_nil() )
1375 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1379 // assign hypotheses
1380 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1382 int aNewHypIndex = currentHyp( dim, hypType );
1383 int anOldHypIndex = -1;
1384 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1385 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1386 myExistingHyps[ dim ][ hypType ] );
1387 if ( aNewHypIndex != anOldHypIndex )
1389 // remove old hypotheses
1390 if ( anOldHypIndex >= 0 )
1391 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1392 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1394 // assign new hypotheses
1395 if ( aNewHypIndex != -1 )
1397 SMESH::SMESH_Mesh_var aMeshVar =
1398 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1399 bool isMesh = !aMeshVar->_is_nil();
1402 SMESH::AddHypothesisOnMesh(
1403 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1407 SMESH::SMESH_subMesh_var aVar =
1408 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1409 if ( !aVar->_is_nil() )
1410 SMESH::AddHypothesisOnSubMesh(
1411 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1414 // reread all hypotheses of mesh if necessary
1415 QStringList anExisting;
1416 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1424 //================================================================================
1426 * \brief Verifies whether given operator is valid for this one
1427 * \param theOtherOp - other operation
1428 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1430 * method redefined from base class verifies whether given operator is valid for
1431 * this one (i.e. can be started "above" this operator). In current implementation method
1432 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1435 //================================================================================
1436 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1438 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1441 //================================================================================
1443 * \brief SLOT. Is called when the user selects a way of geometry selection
1444 * \param theByMesh - true if the user wants to find geometry by mesh element
1446 //================================================================================
1448 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1451 if ( !myShapeByMeshDlg ) {
1452 myShapeByMeshDlg = new SMESHGUI_ShapeByMeshDlg( SMESHGUI::GetSMESHGUI(), "ShapeByMeshDlg");
1453 connect(myShapeByMeshDlg, SIGNAL(PublishShape()), SLOT(onPublishShapeByMeshDlg()));
1454 connect(myShapeByMeshDlg, SIGNAL(Close()), SLOT(onCloseShapeByMeshDlg()));
1456 // set mesh object to dlg
1457 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1458 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1459 SMESH::SMESH_Mesh_var aMeshVar =
1460 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1461 if ( !aMeshVar->_is_nil() ) {
1463 myShapeByMeshDlg->Init();
1464 myShapeByMeshDlg->SetMesh( aMeshVar );
1465 myShapeByMeshDlg->show();
1471 //================================================================================
1473 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1475 //================================================================================
1477 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg()
1479 onCloseShapeByMeshDlg();
1481 if ( myShapeByMeshDlg ) {
1482 // Select a found geometry object
1483 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshDlg->GetShape();
1484 if ( !aGeomVar->_is_nil() )
1486 QString ID = aGeomVar->GetStudyEntry();
1487 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID )) {
1488 selectObject( aGeomSO );
1495 //================================================================================
1497 * \brief SLOT. Is called Close Ok is pressed in SMESHGUI_ShapeByMeshDlg
1499 //================================================================================
1501 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg()
1505 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1506 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
1510 //================================================================================
1512 * \brief Selects a SObject
1513 * \param theSObj - the SObject to select
1515 //================================================================================
1517 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1519 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1520 SALOME_ListIO anIOList;
1522 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1523 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1524 anIOList.Append( anIO );
1526 sm->setSelectedObjects( anIOList, false );