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" );
506 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
507 if ( aGeomEntry == "" )
509 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
512 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
513 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
515 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
520 if ( !myIsMesh ) // i.e sub-mesh creation,
522 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
523 if ( aMeshEntry == "" )
525 theMess = tr( "MESH_IS_NOT_DEFINED" );
528 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
529 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
531 theMess = tr( "MESH_IS_NULL" );
534 if ( !isSubshapeOk() )
536 theMess = tr( "INVALID_SUBSHAPE" );
544 //================================================================================
546 * \brief Gets available hypotheses or algorithms
547 * \param theDim - specifies dimension of returned hypotheses/algorifms
548 * \param theHypType - specifies whether algorims or hypotheses or additional ones
549 * are retrieved (possible values are in HypType enumeration)
550 * \param theHyps - Output list of hypotheses' names
552 * Gets available hypotheses or algorithm in accordance with input parameters
554 //================================================================================
555 void SMESHGUI_MeshOp::availableHyps( const int theDim,
556 const int theHypType,
557 QStringList& theHyps ) const
560 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
561 theHypType == Algo , theDim, theHypType == AddHyp );
562 QStringList::const_iterator anIter;
563 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
565 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
566 theHyps.append( aData->Label );
570 //================================================================================
572 * \brief Gets existing hypotheses or algorithms
573 * \param theDim - specifies dimension of returned hypotheses/algorifms
574 * \param theHypType - specifies whether algorims or hypotheses or additional ones
575 * are retrieved (possible values are in HypType enumeration)
576 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
577 * \param theHyps - output list of names.
578 * \param theHypVars - output list of variables.
580 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
583 //================================================================================
584 void SMESHGUI_MeshOp::existingHyps( const int theDim,
585 const int theHypType,
586 _PTR(SObject) theFather,
587 QStringList& theHyps,
588 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
590 // Clear hypoheses list
597 _PTR(SObject) aHypRoot;
598 _PTR(GenericAttribute) anAttr;
599 _PTR(AttributeName) aName;
600 _PTR(AttributeIOR) anIOR;
602 bool isMesh = !_CAST( SComponent, theFather );
605 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
607 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
609 if ( theFather->FindSubObject( aPart, aHypRoot ) )
611 _PTR(ChildIterator) anIter =
612 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
613 for (; anIter->More(); anIter->Next() )
615 _PTR(SObject) anObj = anIter->Value();
616 if ( isMesh ) // i.e. mesh or submesh
618 _PTR(SObject) aRefObj;
619 if ( anObj->ReferencedObject( aRefObj ) )
624 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
627 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
628 if ( !CORBA::is_nil( aVar ) )
630 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
631 if ( !aHypVar->_is_nil() )
633 QString aHypType( aHypVar->GetName() );
634 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
635 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
636 ( theHypType == AddHyp ) == aData->IsAux )
638 theHyps.append( aName->Value().c_str() );
639 theHypVars.append( aHypVar );
648 //================================================================================
650 * \brief If create or edit a submesh, return a hypothesis holding parameters used
652 * \param aHypType - The hypothesis type name
653 * \param aServerLib - Server library name
654 * \param hypData - The structure holding the hypothesis type etc.
655 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
657 //================================================================================
659 SMESH::SMESH_Hypothesis_var
660 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
661 const QString& aServerLib ) const
663 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
664 return SMESH::SMESH_Hypothesis::_nil();
666 const int nbColonsInMeshEntry = 3;
667 bool isSubMesh = myToCreate ?
669 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
673 // get mesh and geom object
674 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
675 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
677 QString anEntry = myDlg->selectedObject
678 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
679 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
681 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
682 if ( myToCreate ) // mesh and geom may be selected
684 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
685 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
686 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
687 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
689 else // edition: sub-mesh may be selected
691 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
692 if ( !sm->_is_nil() ) {
693 aMeshVar = sm->GetFather();
694 aGeomVar = sm->GetSubShape();
699 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
700 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
705 return SMESH::SMESH_Hypothesis::_nil();
708 //================================================================================
710 * \brief Calls plugin methods for hypothesis creation
711 * \param theHypType - specifies whether main hypotheses or additional ones
713 * \param theIndex - index of type of hypothesis to be cerated
715 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
716 * its type and calls plugin methods for hypothesis creation
718 //================================================================================
719 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
721 // Speicfies dimension of hypothesis to be created
722 const QObject* aSender = sender();
724 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
725 if ( aSender == myDlg->tab( i ) )
730 // Speicfies type of hypothesis to be created
731 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
732 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
735 QString aHypTypeName = aHypTypeNames[ theIndex ];
736 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
740 QString aClientLibName = aData->ClientLibName;
741 QStringList anOldHyps;
742 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
743 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
745 if ( aClientLibName == "" )
747 // Call hypothesis creation server method (without GUI)
748 QString aHypName = aData->Label;
749 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
753 // Get hypotheses creator client (GUI)
754 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
759 // When create or edit a submesh, try to initialize a new hypothesis
760 // with values used to mesh a subshape
761 SMESH::SMESH_Hypothesis_var initParamHyp =
762 getInitParamsHypothesis( aHypTypeName, aData->ServerLibName );
764 if ( initParamHyp->_is_nil() )
765 aCreator->create( false, myDlg );
767 aCreator->create( initParamHyp, myDlg );
771 SMESH::CreateHypothesis( aHypTypeName, aData->Label, false );
775 QStringList aNewHyps;
776 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
777 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
778 if ( aNewHyps.count() > anOldHyps.count() )
780 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
781 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
785 //================================================================================
787 * \brief Calls plugin methods for hypothesis editing
788 * \param theHypType - specifies whether main hypothesis or additional one
790 * \param theIndex - index of existing hypothesis
792 * Calls plugin methods for hypothesis editing
794 //================================================================================
795 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
797 // Speicfies dimension of hypothesis to be created
798 const QObject* aSender = sender();
800 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
801 if ( aSender == myDlg->tab( i ) )
806 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
807 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
808 if ( aHyp->_is_nil() )
811 char* aTypeName = aHyp->GetName();
812 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
814 aCreator->edit( aHyp.in(), dlg() );
817 //================================================================================
819 * \brief Creates and selects hypothesis of hypotheses set
820 * \param theSetName - The name of hypotheses set
822 //================================================================================
824 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
826 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
827 if ( !aHypoSet ) return;
829 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
831 bool isAlgo = (aHypType == Algo);
834 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
835 setCurrentHyp( dim, aHypType, -1 );
837 // set hyps from the set
839 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
840 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
842 const QString& aHypoTypeName = (*aHypoList)[ i ];
843 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
847 int aDim = aHypData->Dim[0];
852 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
853 index = aHypTypeNameList.findIndex( aHypoTypeName );
854 if ( index < 0 ) continue;
855 setCurrentHyp ( aDim, aHypType, index );
859 // try to find an existing hypo
860 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
861 int /*iHyp = 0,*/ nbHyp = aList.count();
862 // for ( ; iHyp < nbHyp; ++iHyp )
864 // SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
865 // if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
870 if ( index >= 0 ) // found
872 // select the found hypothesis
873 setCurrentHyp ( aDim, aHypType, index );
877 // create a hypothesis
878 QString aClientLibName = aHypData->ClientLibName;
879 if ( aClientLibName == "" ) {
880 // Call hypothesis creation server method (without GUI)
881 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
884 // Get hypotheses creator client (GUI)
885 SMESHGUI_GenericHypothesisCreator* aCreator =
886 SMESH::GetHypothesisCreator( aHypoTypeName );
889 // When create or edit a submesh, try to initialize a new hypothesis
890 // with values used to mesh a subshape
891 SMESH::SMESH_Hypothesis_var initParamHyp =
892 getInitParamsHypothesis( aHypoTypeName, aHypData->ServerLibName );
893 aCreator->create( initParamHyp, myDlg );
897 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
900 QStringList aNewHyps;
901 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
902 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
903 if ( aList.count() > nbHyp )
905 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
906 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
910 } // loop on hypos in the set
911 } // loop on algo/hypo
914 //================================================================================
916 * \brief Creates mesh
917 * \param theMess - Output parameter intended for returning error message
918 * \retval bool - TRUE if mesh is created, FALSE otherwise
922 //================================================================================
923 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
927 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
928 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
929 GEOM::GEOM_Object_var aGeomVar =
930 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
932 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
933 if ( aSMESHGen->_is_nil() )
936 SUIT_OverrideCursor aWaitCursor;
939 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
940 if ( aMeshVar->_is_nil() )
942 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
944 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
946 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
948 if ( !isAccessibleDim( aDim )) continue;
951 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
953 int aHypIndex = currentHyp( aDim, aHypType );
954 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
956 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
957 if ( !aHypVar->_is_nil() )
958 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
961 // find or create algorithm
962 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
963 if ( !anAlgoVar->_is_nil() )
964 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
969 //================================================================================
971 * \brief Creates sub-mesh
972 * \param theMess - Output parameter intended for returning error message
973 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
977 //================================================================================
978 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
982 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
983 if ( aSMESHGen->_is_nil() )
987 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
988 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
989 SMESH::SMESH_Mesh_var aMeshVar =
990 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
993 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
994 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
995 GEOM::GEOM_Object_var aGeomVar =
996 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
998 SUIT_OverrideCursor aWaitCursor;
1001 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1002 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1004 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1006 if ( !isAccessibleDim( aDim )) continue;
1008 // find or create algorithm
1009 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1010 if ( !anAlgoVar->_is_nil() )
1011 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1012 // assign hypotheses
1013 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1015 int aHypIndex = currentHyp( aDim, aHypType );
1016 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1018 SMESH::SMESH_Hypothesis_var aHypVar =
1019 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1020 if ( !aHypVar->_is_nil() )
1021 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1028 //================================================================================
1030 * \brief Gets current hypothesis or algorithms
1031 * \param theDim - dimension of hypothesis or algorithm
1032 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1033 * \retval int - current hypothesis or algorithms
1035 * Gets current hypothesis or algorithms
1037 //================================================================================
1038 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1040 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1043 //================================================================================
1045 * \brief Returns true if hypotheses of given dim can be assigned
1046 * \param theDim - hypotheses dimension
1047 * \retval bool - result
1049 //================================================================================
1050 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
1052 return myDlg->tab( theDim )->isEnabled();
1055 //================================================================================
1057 * \brief Sets current hypothesis or algorithms
1058 * \param theDim - dimension of hypothesis or algorithm
1059 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1060 * \param theIndex - Index of hypothesis
1062 * Gets current hypothesis or algorithms
1064 //================================================================================
1065 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1066 const int theHypType,
1067 const int theIndex )
1069 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1072 //================================================================================
1074 * \brief Generates default and sets mesh/submesh name
1076 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1078 //================================================================================
1079 void SMESHGUI_MeshOp::setDefaultName() const
1083 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1085 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1086 _PTR(SObject) anObj;
1089 aResName = aPrefix + QString::number( i++ );
1090 anObj = aStudy->FindObject( aResName.latin1() );
1094 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1095 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1096 aControl->setText( aResName );
1099 //================================================================================
1101 * \brief Gets algorithm or creates it if necessary
1102 * \param theDim - specifies dimension of returned hypotheses/algorifms
1103 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1105 * Gets algorithm or creates it if necessary
1107 //================================================================================
1108 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1110 SMESH::SMESH_Hypothesis_var anAlgoVar;
1111 int aHypIndex = currentHyp( theDim, Algo );
1112 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
1113 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
1115 QString aHypName = aHypTypeNameList[ aHypIndex ];
1116 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1117 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1118 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1120 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1121 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1123 anAlgoVar = aHypVar;
1127 if ( anAlgoVar->_is_nil() )
1129 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1132 QString aClientLibName = aHypData->ClientLibName;
1133 if ( aClientLibName == "" )
1134 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
1137 SMESHGUI_GenericHypothesisCreator* aCreator =
1138 SMESH::GetHypothesisCreator( aHypName );
1140 aCreator->create( true, myDlg );
1142 QStringList tmpList;
1143 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1144 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1147 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1148 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1150 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1151 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1153 anAlgoVar = aHypVar;
1159 return anAlgoVar._retn();
1162 //================================================================================
1164 * \brief Reads parameters of edited mesh and assigns them to the dialog
1166 * Reads parameters of edited mesh and assigns them to the dialog (called when
1167 * mesh is edited only)
1169 //================================================================================
1170 void SMESHGUI_MeshOp::readMesh()
1172 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1173 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1177 // Get name of mesh if current object is sub-mesh
1178 SMESH::SMESH_subMesh_var aSubMeshVar =
1179 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1180 if ( !aSubMeshVar->_is_nil() )
1182 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1183 if ( !aMeshVar->_is_nil() )
1185 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1186 QString aMeshName = name( aMeshSO );
1187 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1191 // Get name of geometry object
1192 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1193 if ( !aGeomVar->_is_nil() )
1195 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1196 QString aShapeName = name( aGeomSO );
1197 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1200 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1201 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1204 QStringList anExisting;
1206 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1207 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1209 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1210 QString aHypTypeName = aVar->GetName();
1212 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
1213 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
1214 if ( aHypTypeName == aHypTypeNameList[ i ] )
1220 setCurrentHyp( dim, Algo, aHypIndex );
1223 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1226 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1227 // find index of requered hypothesis among existing ones for this dimension
1230 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1231 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1232 myExistingHyps[ dim ][ hypType ] );
1233 setCurrentHyp( dim, hypType, aHypIndex );
1238 //================================================================================
1240 * \brief Gets name of object
1241 * \param theSO - SObject
1242 * \retval QString - name of object
1244 * Gets name of object
1246 //================================================================================
1247 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1252 _PTR(GenericAttribute) anAttr;
1253 _PTR(AttributeName) aNameAttr;
1254 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1257 aResName = aNameAttr->Value().c_str();
1263 //================================================================================
1265 * \brief Finds hypothesis in input list
1266 * \param theHyp - hypothesis to be found
1267 * \param theHypList - input list of hypotheses
1268 * \retval int - index of hypothesis or -1 if it is not found
1270 * Finds position of hypothesis in input list
1272 //================================================================================
1273 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1274 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1277 if ( !theHyp->_is_nil() )
1280 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1281 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1283 if ( theHyp->_is_equivalent( *anIter ) )
1294 //================================================================================
1296 * \brief Edits mesh or sub-mesh
1297 * \param theMess - Output parameter intended for returning error message
1298 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1300 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1302 //================================================================================
1303 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1307 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1308 if ( aSMESHGen->_is_nil() )
1311 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1312 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1316 SUIT_OverrideCursor aWaitCursor;
1319 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1321 // Assign new hypotheses and algorithms
1322 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1324 if ( !isAccessibleDim( dim )) continue;
1326 // find or create algorithm
1327 bool toDelete = false, toAdd = true;
1328 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1329 if ( anAlgoVar->_is_nil() ) {
1332 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1333 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1335 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1344 // remove old algorithm
1346 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1347 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1349 // assign new algorithm
1351 SMESH::SMESH_Mesh_var aMeshVar =
1352 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1353 bool isMesh = !aMeshVar->_is_nil();
1355 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1357 SMESH::SMESH_subMesh_var aVar =
1358 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1359 if ( !aVar->_is_nil() )
1360 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1364 // assign hypotheses
1365 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1367 int aNewHypIndex = currentHyp( dim, hypType );
1368 int anOldHypIndex = -1;
1369 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1370 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1371 myExistingHyps[ dim ][ hypType ] );
1372 if ( aNewHypIndex != anOldHypIndex )
1374 // remove old hypotheses
1375 if ( anOldHypIndex >= 0 )
1376 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1377 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1379 // assign new hypotheses
1380 if ( aNewHypIndex != -1 )
1382 SMESH::SMESH_Mesh_var aMeshVar =
1383 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1384 bool isMesh = !aMeshVar->_is_nil();
1387 SMESH::AddHypothesisOnMesh(
1388 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1392 SMESH::SMESH_subMesh_var aVar =
1393 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1394 if ( !aVar->_is_nil() )
1395 SMESH::AddHypothesisOnSubMesh(
1396 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1399 // reread all hypotheses of mesh if necessary
1400 QStringList anExisting;
1401 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1409 //================================================================================
1411 * \brief Verifies whether given operator is valid for this one
1412 * \param theOtherOp - other operation
1413 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1415 * method redefined from base class verifies whether given operator is valid for
1416 * this one (i.e. can be started "above" this operator). In current implementation method
1417 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1420 //================================================================================
1421 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1423 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1426 //================================================================================
1428 * \brief SLOT. Is called when the user selects a way of geometry selection
1429 * \param theByMesh - true if the user wants to find geometry by mesh element
1431 //================================================================================
1433 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1436 if ( !myShapeByMeshDlg ) {
1437 myShapeByMeshDlg = new SMESHGUI_ShapeByMeshDlg( SMESHGUI::GetSMESHGUI(), "ShapeByMeshDlg");
1438 connect(myShapeByMeshDlg, SIGNAL(PublishShape()), SLOT(onPublishShapeByMeshDlg()));
1439 connect(myShapeByMeshDlg, SIGNAL(Close()), SLOT(onCloseShapeByMeshDlg()));
1441 // set mesh object to dlg
1442 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1443 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1444 SMESH::SMESH_Mesh_var aMeshVar =
1445 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1446 if ( !aMeshVar->_is_nil() ) {
1448 myShapeByMeshDlg->Init();
1449 myShapeByMeshDlg->SetMesh( aMeshVar );
1450 myShapeByMeshDlg->show();
1456 //================================================================================
1458 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1460 //================================================================================
1462 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg()
1464 onCloseShapeByMeshDlg();
1466 if ( myShapeByMeshDlg ) {
1467 // Select a found geometry object
1468 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshDlg->GetShape();
1469 if ( !aGeomVar->_is_nil() )
1471 QString ID = aGeomVar->GetStudyEntry();
1472 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID )) {
1473 selectObject( aGeomSO );
1480 //================================================================================
1482 * \brief SLOT. Is called Close Ok is pressed in SMESHGUI_ShapeByMeshDlg
1484 //================================================================================
1486 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg()
1490 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1491 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
1495 //================================================================================
1497 * \brief Selects a SObject
1498 * \param theSObj - the SObject to select
1500 //================================================================================
1502 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1504 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1505 SALOME_ListIO anIOList;
1507 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1508 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1509 anIOList.Append( anIO );
1511 sm->setSelectedObjects( anIOList, false );