1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
23 * Copyright (C) 2005 CEA/DEN, EDF R&D
27 * File : SMESHGUI_MeshOp.h
28 * Author : Sergey LITONIN
32 #include "SMESHGUI_MeshOp.h"
33 #include "SMESHGUI_MeshDlg.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESH_TypeFilter.hxx"
38 #include "SMESHGUI_HypothesesUtils.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
41 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESHGUI_VTKUtils.h"
44 #include "SMESH_TypeFilter.hxx"
45 #include "SMESH_NumberFilter.hxx"
47 #include "GEOM_SelectionFilter.h"
49 #include "GeometryGUI.h"
51 #include "SalomeApp_Tools.h"
52 #include "SALOMEDSClient_Study.hxx"
53 #include "SALOMEDSClient_AttributeIOR.hxx"
54 #include "SALOMEDSClient_AttributeName.hxx"
55 #include "SALOMEDS_SComponent.hxx"
56 #include "SALOMEDS_SObject.hxx"
58 #include "LightApp_SelectionMgr.h"
59 #include "LightApp_UpdateFlags.h"
60 #include "SUIT_MessageBox.h"
61 #include "SUIT_Desktop.h"
62 #include "SUIT_OverrideCursor.h"
63 #include "SALOME_InteractiveObject.hxx"
64 #include "SALOME_ListIO.hxx"
66 #include "utilities.h"
68 #include <qstringlist.h>
69 #include <qlineedit.h>
71 #include <TopoDS_Shape.hxx>
72 #include <TopExp_Explorer.hxx>
74 enum { GLOBAL_ALGO_TAG =3,
78 SUBMESH_ON_EDGE_TAG =5,
79 SUBMESH_ON_WIRE_TAG =6,
80 SUBMESH_ON_FACE_TAG =7,
81 SUBMESH_ON_SHELL_TAG =8,
82 SUBMESH_ON_SOLID_TAG =9,
83 SUBMESH_ON_COMPOUND_TAG=10 };
85 //================================================================================
88 * \param theToCreate - if this parameter is true then operation is used for creation,
89 * for editing otherwise
91 * Initialize operation
93 //================================================================================
94 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
95 : SMESHGUI_SelectionOp(),
96 myToCreate( theToCreate ),
97 myIsMesh( theIsMesh ),
101 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
102 GeometryGUI::InitGeomGen();
105 //================================================================================
109 //================================================================================
110 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
116 //================================================================================
118 * \brief Gets dialog of this operation
119 * \retval LightApp_Dialog* - pointer to dialog of this operation
121 //================================================================================
122 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
127 //================================================================================
129 * \brief Creates or edits mesh
130 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
132 * Virtual slot redefined from the base class called when "Apply" button is clicked
133 * creates or edits mesh
135 //================================================================================
136 bool SMESHGUI_MeshOp::onApply()
138 if( isStudyLocked() )
142 if ( !isValid( aMess ) )
145 SUIT_MessageBox::warn1( myDlg,
146 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
150 bool aResult = false;
154 if ( myToCreate && myIsMesh )
155 aResult = createMesh( aMess );
156 if ( myToCreate && !myIsMesh )
157 aResult = createSubMesh( aMess );
158 else if ( !myToCreate )
159 aResult = editMeshOrSubMesh( aMess );
161 update( UF_ObjBrowser | UF_Model );
163 catch ( const SALOME::SALOME_Exception& S_ex )
165 SalomeApp_Tools::QtCatchCorbaException( S_ex );
181 aMess = tr( "SMESH_OPERATION_FAILED" );
182 SUIT_MessageBox::warn1( myDlg,
183 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
189 //================================================================================
191 * \brief Creates dialog if necessary and shows it
193 * Virtual method redefined from base class called when operation is started creates
194 * dialog if necessary and shows it, activates selection
196 //================================================================================
197 void SMESHGUI_MeshOp::startOperation()
201 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
202 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
204 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
205 this, SLOT( onCreateHyp( const int, const int) ) );
206 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
207 this, SLOT( onEditHyp( const int, const int) ) );
209 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
210 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
213 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
214 else myHelpFileName = "/files/constructing_submeshes.htm";
215 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
217 SMESHGUI_SelectionOp::startOperation();
219 // iterate through dimensions and get available and existing algoritms and hypotheses,
220 // set them to the dialog
222 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
223 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
225 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
226 QStringList anAvailable, anExisting;
227 for ( j = Algo; j <= AddHyp; j++ )
229 availableHyps( i, j, anAvailable );
230 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
232 aTab->setAvailableHyps( j, anAvailable );
233 aTab->setExistingHyps( j, anExisting );
239 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
242 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
244 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
248 myDlg->setCurrentTab( SMESH::DIM_1D );
252 //================================================================================
254 * \brief Creates selection filter
255 * \param theId - identifier of current selection widget
256 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
258 * Creates selection filter in accordance with identifier of current selection widget
260 //================================================================================
261 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
263 if ( theId == SMESHGUI_MeshDlg::Geom )
265 // TColStd_MapOfInteger allTypesMap;
266 // for ( int i = 0; i < 10; i++ )
267 // allTypesMap.Add( i );
268 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
269 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
271 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
272 return new SMESH_TypeFilter( MESHorSUBMESH );
273 else if ( theId == SMESHGUI_MeshDlg::Mesh )
274 return new SMESH_TypeFilter( MESH );
279 //================================================================================
281 * \brief check if selected shape is a subshape of the shape to mesh
282 * \retval bool - check result
284 //================================================================================
286 bool SMESHGUI_MeshOp::isSubshapeOk() const
288 if ( !myToCreate || myIsMesh ) // not submesh creation
291 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
292 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
293 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
294 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
295 if ( pMesh && pGeom ) {
296 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
297 if ( !mesh->_is_nil() ) {
298 GEOM::GEOM_Object_var mainGeom, subGeom;
299 mainGeom = mesh->GetShapeToMesh();
300 subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
301 if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
302 TopoDS_Shape mainShape, subShape;
303 if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
304 GEOMBase::GetShape( subGeom, subShape ) )
306 int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
308 // 1 is index of mainShape itself
309 return index > 1; // it is a subshape
312 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
313 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
314 if ( !geomGen->_is_nil() && aStudy ) {
315 GEOM::GEOM_IGroupOperations_var op =
316 geomGen->GetIGroupOperations( aStudy->StudyId() );
317 if ( ! op->_is_nil() ) {
318 GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
319 if ( !mainObj->_is_nil() )
320 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
330 //================================================================================
332 * \brief find an existing submesh by the selected shape
333 * \retval _PTR(SObject) - the found submesh SObject
335 //================================================================================
337 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
339 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
340 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
341 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
342 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
343 if ( pMesh && pGeom ) {
344 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
345 if ( !geom->_is_nil() ) {
347 switch ( geom->GetShapeType() ) {
348 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
349 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
350 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
351 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
352 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
353 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
356 _PTR(SObject) aSubmeshRoot;
357 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
358 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
360 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
361 for (; smIter->More(); smIter->Next() )
363 _PTR(SObject) aSmObj = smIter->Value();
364 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
365 for (; anIter1->More(); anIter1->Next()) {
366 _PTR(SObject) pGeom2 = anIter1->Value();
367 if ( pGeom2->ReferencedObject( pGeom2 ) &&
368 pGeom2->GetID() == pGeom->GetID() )
375 return _PTR(SObject)();
378 //================================================================================
380 * \brief Updates dialog's look and feel
382 * Virtual method redefined from the base class updates dialog's look and feel
384 //================================================================================
385 void SMESHGUI_MeshOp::selectionDone()
387 if ( myShapeByMeshDlg && myShapeByMeshDlg->isShown() )
390 SMESHGUI_SelectionOp::selectionDone();
394 // Enable tabs according to shape dimension
398 GEOM::GEOM_Object_var aGeomVar;
399 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
400 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
402 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
405 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
406 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
407 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
409 if ( !aGeomVar->_is_nil() ) {
411 switch ( aGeomVar->GetShapeType() ) {
413 case GEOM::SHELL: shapeDim = 3; break;
414 case GEOM::FACE: shapeDim = 2; break;
416 case GEOM::EDGE: shapeDim = 1; break;
417 case GEOM::VERTEX: shapeDim = 0; break;
420 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
421 TopExp_Explorer exp( aShape, TopAbs_SHELL );
424 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
426 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
433 myDlg->setMaxHypoDim( shapeDim );
435 if ( !myToCreate ) // edition: read hypotheses
437 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
438 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
441 SMESH::SMESH_subMesh_var aVar =
442 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
443 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
444 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
445 myDlg->updateGeometry();
453 else if ( !myIsMesh ) // submesh creation
455 // if a submesh on the selected shape already exist, pass to submesh edition mode
456 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
457 SMESH::SMESH_subMesh_var sm =
458 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
459 bool editSubmesh = ( !sm->_is_nil() &&
460 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
461 tr( "EDIT_SUBMESH_QUESTION"),
462 tr( "SMESH_BUT_YES" ),
463 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
466 selectionMgr()->clearFilters();
467 selectObject( pSubmesh );
468 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
473 selectObject( _PTR(SObject)() );
474 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
478 // enable/disable popup for choice of geom selection way
480 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
481 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
482 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
483 if ( !mesh->_is_nil() )
484 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
486 myDlg->setGeomPopupEnabled( enable );
489 catch ( const SALOME::SALOME_Exception& S_ex )
491 SalomeApp_Tools::QtCatchCorbaException( S_ex );
498 //================================================================================
500 * \brief Verifies validity of input data
501 * \param theMess - Output parameter intended for returning error message
502 * \retval bool - TRUE if input data is valid, false otherwise
504 * Verifies validity of input data. This method is called when "Apply" or "OK" button
505 * is pressed before mesh creation or editing.
507 //================================================================================
508 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
510 // Selected object to be edited
511 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
513 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
518 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
519 aMeshName = aMeshName.stripWhiteSpace();
520 if ( aMeshName == "" )
522 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
526 // Imported mesh, if create sub-mesh or edit mesh
527 if ( !myToCreate || ( myToCreate && !myIsMesh ))
529 QString aMeshEntry = myDlg->selectedObject
530 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
531 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
532 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
533 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
534 theMess = tr( "IMPORTED_MESH" );
543 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
544 if ( aGeomEntry == "" )
546 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
549 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
550 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
552 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
557 if ( !myIsMesh ) // i.e sub-mesh creation,
559 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
560 if ( aMeshEntry == "" )
562 theMess = tr( "MESH_IS_NOT_DEFINED" );
565 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
566 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
568 theMess = tr( "MESH_IS_NULL" );
571 if ( !isSubshapeOk() )
573 theMess = tr( "INVALID_SUBSHAPE" );
582 //================================================================================
584 * \brief Gets available hypotheses or algorithms
585 * \param theDim - specifies dimension of returned hypotheses/algorifms
586 * \param theHypType - specifies whether algorims or hypotheses or additional ones
587 * are retrieved (possible values are in HypType enumeration)
588 * \param theHyps - Output list of hypotheses' names
590 * Gets available hypotheses or algorithm in accordance with input parameters
592 //================================================================================
593 void SMESHGUI_MeshOp::availableHyps( const int theDim,
594 const int theHypType,
595 QStringList& theHyps ) const
598 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
599 theHypType == Algo , theDim, theHypType == AddHyp );
600 QStringList::const_iterator anIter;
601 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
603 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
604 theHyps.append( aData->Label );
608 //================================================================================
610 * \brief Gets existing hypotheses or algorithms
611 * \param theDim - specifies dimension of returned hypotheses/algorifms
612 * \param theHypType - specifies whether algorims or hypotheses or additional ones
613 * are retrieved (possible values are in HypType enumeration)
614 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
615 * \param theHyps - output list of names.
616 * \param theHypVars - output list of variables.
618 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
621 //================================================================================
622 void SMESHGUI_MeshOp::existingHyps( const int theDim,
623 const int theHypType,
624 _PTR(SObject) theFather,
625 QStringList& theHyps,
626 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
628 // Clear hypoheses list
635 _PTR(SObject) aHypRoot;
636 _PTR(GenericAttribute) anAttr;
637 _PTR(AttributeName) aName;
638 _PTR(AttributeIOR) anIOR;
640 bool isMesh = !_CAST( SComponent, theFather );
643 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
645 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
647 if ( theFather->FindSubObject( aPart, aHypRoot ) )
649 _PTR(ChildIterator) anIter =
650 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
651 for (; anIter->More(); anIter->Next() )
653 _PTR(SObject) anObj = anIter->Value();
654 if ( isMesh ) // i.e. mesh or submesh
656 _PTR(SObject) aRefObj;
657 if ( anObj->ReferencedObject( aRefObj ) )
662 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
665 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
666 if ( !CORBA::is_nil( aVar ) )
668 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
669 if ( !aHypVar->_is_nil() )
671 QString aHypType( aHypVar->GetName() );
672 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
673 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
674 ( theHypType == AddHyp ) == aData->IsAux )
676 theHyps.append( aName->Value().c_str() );
677 theHypVars.append( aHypVar );
686 //================================================================================
688 * \brief If create or edit a submesh, return a hypothesis holding parameters used
690 * \param aHypType - The hypothesis type name
691 * \param aServerLib - Server library name
692 * \param hypData - The structure holding the hypothesis type etc.
693 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
695 //================================================================================
697 SMESH::SMESH_Hypothesis_var
698 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
699 const QString& aServerLib ) const
701 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
702 return SMESH::SMESH_Hypothesis::_nil();
704 const int nbColonsInMeshEntry = 3;
705 bool isSubMesh = myToCreate ?
707 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
711 // get mesh and geom object
712 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
713 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
715 QString anEntry = myDlg->selectedObject
716 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
717 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
719 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
720 if ( myToCreate ) // mesh and geom may be selected
722 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
723 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
724 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
725 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
727 else // edition: sub-mesh may be selected
729 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
730 if ( !sm->_is_nil() ) {
731 aMeshVar = sm->GetFather();
732 aGeomVar = sm->GetSubShape();
737 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
738 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
743 return SMESH::SMESH_Hypothesis::_nil();
746 //================================================================================
748 * \brief Calls plugin methods for hypothesis creation
749 * \param theHypType - specifies whether main hypotheses or additional ones
751 * \param theIndex - index of type of hypothesis to be cerated
753 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
754 * its type and calls plugin methods for hypothesis creation
756 //================================================================================
757 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
759 // Speicfies 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 // Speicfies type of hypothesis to be created
769 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
770 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
773 QString aHypTypeName = aHypTypeNames[ theIndex ];
774 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
778 QString aClientLibName = aData->ClientLibName;
779 QStringList anOldHyps;
780 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
781 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
783 if ( aClientLibName == "" )
785 // Call hypothesis creation server method (without GUI)
786 QString aHypName = aData->Label;
787 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
791 // Get hypotheses creator client (GUI)
792 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
797 // When create or edit a submesh, try to initialize a new hypothesis
798 // with values used to mesh a subshape
799 SMESH::SMESH_Hypothesis_var initParamHyp =
800 getInitParamsHypothesis( aHypTypeName, aData->ServerLibName );
802 if ( initParamHyp->_is_nil() )
803 aCreator->create( false, myDlg );
805 aCreator->create( initParamHyp, myDlg );
809 SMESH::CreateHypothesis( aHypTypeName, aData->Label, false );
813 QStringList aNewHyps;
814 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
815 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
816 if ( aNewHyps.count() > anOldHyps.count() )
818 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
819 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
823 //================================================================================
825 * \brief Calls plugin methods for hypothesis editing
826 * \param theHypType - specifies whether main hypothesis or additional one
828 * \param theIndex - index of existing hypothesis
830 * Calls plugin methods for hypothesis editing
832 //================================================================================
833 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
835 // Speicfies dimension of hypothesis to be created
836 const QObject* aSender = sender();
838 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
839 if ( aSender == myDlg->tab( i ) )
844 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
845 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
846 if ( aHyp->_is_nil() )
849 char* aTypeName = aHyp->GetName();
850 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
852 aCreator->edit( aHyp.in(), dlg() );
855 //================================================================================
857 * \brief Creates and selects hypothesis of hypotheses set
858 * \param theSetName - The name of hypotheses set
860 //================================================================================
862 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
864 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
865 if ( !aHypoSet ) return;
867 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
869 bool isAlgo = (aHypType == Algo);
872 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
873 setCurrentHyp( dim, aHypType, -1 );
875 // set hyps from the set
877 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
878 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
880 const QString& aHypoTypeName = (*aHypoList)[ i ];
881 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
885 int aDim = aHypData->Dim[0];
890 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
891 index = aHypTypeNameList.findIndex( aHypoTypeName );
892 if ( index < 0 ) continue;
893 setCurrentHyp ( aDim, aHypType, index );
897 // try to find an existing hypo
898 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
899 int /*iHyp = 0,*/ nbHyp = aList.count();
900 // for ( ; iHyp < nbHyp; ++iHyp )
902 // SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
903 // if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
908 if ( index >= 0 ) // found
910 // select the found hypothesis
911 setCurrentHyp ( aDim, aHypType, index );
915 // create a hypothesis
916 QString aClientLibName = aHypData->ClientLibName;
917 if ( aClientLibName == "" ) {
918 // Call hypothesis creation server method (without GUI)
919 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
922 // Get hypotheses creator client (GUI)
923 SMESHGUI_GenericHypothesisCreator* aCreator =
924 SMESH::GetHypothesisCreator( aHypoTypeName );
927 // When create or edit a submesh, try to initialize a new hypothesis
928 // with values used to mesh a subshape
929 SMESH::SMESH_Hypothesis_var initParamHyp =
930 getInitParamsHypothesis( aHypoTypeName, aHypData->ServerLibName );
931 aCreator->create( initParamHyp, myDlg );
935 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
938 QStringList aNewHyps;
939 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
940 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
941 if ( aList.count() > nbHyp )
943 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
944 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
948 } // loop on hypos in the set
949 } // loop on algo/hypo
952 //================================================================================
954 * \brief Creates mesh
955 * \param theMess - Output parameter intended for returning error message
956 * \retval bool - TRUE if mesh is created, FALSE otherwise
960 //================================================================================
961 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
965 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
966 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
967 GEOM::GEOM_Object_var aGeomVar =
968 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
970 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
971 if ( aSMESHGen->_is_nil() )
974 SUIT_OverrideCursor aWaitCursor;
977 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
978 if ( aMeshVar->_is_nil() )
980 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
982 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
984 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
986 if ( !isAccessibleDim( aDim )) continue;
989 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
991 int aHypIndex = currentHyp( aDim, aHypType );
992 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
994 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
995 if ( !aHypVar->_is_nil() )
996 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
999 // find or create algorithm
1000 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1001 if ( !anAlgoVar->_is_nil() )
1002 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1007 //================================================================================
1009 * \brief Creates sub-mesh
1010 * \param theMess - Output parameter intended for returning error message
1011 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1015 //================================================================================
1016 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1020 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1021 if ( aSMESHGen->_is_nil() )
1025 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1026 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1027 SMESH::SMESH_Mesh_var aMeshVar =
1028 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1031 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1032 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1033 GEOM::GEOM_Object_var aGeomVar =
1034 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1036 SUIT_OverrideCursor aWaitCursor;
1039 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1040 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1042 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1044 if ( !isAccessibleDim( aDim )) continue;
1046 // find or create algorithm
1047 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1048 if ( !anAlgoVar->_is_nil() )
1049 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1050 // assign hypotheses
1051 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1053 int aHypIndex = currentHyp( aDim, aHypType );
1054 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1056 SMESH::SMESH_Hypothesis_var aHypVar =
1057 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1058 if ( !aHypVar->_is_nil() )
1059 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1066 //================================================================================
1068 * \brief Gets current hypothesis or algorithms
1069 * \param theDim - dimension of hypothesis or algorithm
1070 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1071 * \retval int - current hypothesis or algorithms
1073 * Gets current hypothesis or algorithms
1075 //================================================================================
1076 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1078 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1081 //================================================================================
1083 * \brief Returns true if hypotheses of given dim can be assigned
1084 * \param theDim - hypotheses dimension
1085 * \retval bool - result
1087 //================================================================================
1088 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
1090 return myDlg->tab( theDim )->isEnabled();
1093 //================================================================================
1095 * \brief Sets current hypothesis or algorithms
1096 * \param theDim - dimension of hypothesis or algorithm
1097 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1098 * \param theIndex - Index of hypothesis
1100 * Gets current hypothesis or algorithms
1102 //================================================================================
1103 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1104 const int theHypType,
1105 const int theIndex )
1107 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1110 //================================================================================
1112 * \brief Generates default and sets mesh/submesh name
1114 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1116 //================================================================================
1117 void SMESHGUI_MeshOp::setDefaultName() const
1121 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1123 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1124 _PTR(SObject) anObj;
1127 aResName = aPrefix + QString::number( i++ );
1128 anObj = aStudy->FindObject( aResName.latin1() );
1132 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1133 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1134 aControl->setText( aResName );
1137 //================================================================================
1139 * \brief Gets algorithm or creates it if necessary
1140 * \param theDim - specifies dimension of returned hypotheses/algorifms
1141 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1143 * Gets algorithm or creates it if necessary
1145 //================================================================================
1146 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1148 SMESH::SMESH_Hypothesis_var anAlgoVar;
1149 int aHypIndex = currentHyp( theDim, Algo );
1150 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
1151 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
1153 QString aHypName = aHypTypeNameList[ aHypIndex ];
1154 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1155 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1156 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1158 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1159 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1161 anAlgoVar = aHypVar;
1165 if ( anAlgoVar->_is_nil() )
1167 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1170 QString aClientLibName = aHypData->ClientLibName;
1171 if ( aClientLibName == "" )
1172 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
1175 SMESHGUI_GenericHypothesisCreator* aCreator =
1176 SMESH::GetHypothesisCreator( aHypName );
1178 aCreator->create( true, myDlg );
1180 QStringList tmpList;
1181 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1182 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1185 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1186 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1188 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1189 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1191 anAlgoVar = aHypVar;
1197 return anAlgoVar._retn();
1200 //================================================================================
1202 * \brief Reads parameters of edited mesh and assigns them to the dialog
1204 * Reads parameters of edited mesh and assigns them to the dialog (called when
1205 * mesh is edited only)
1207 //================================================================================
1208 void SMESHGUI_MeshOp::readMesh()
1210 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1211 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1215 // Get name of mesh if current object is sub-mesh
1216 SMESH::SMESH_subMesh_var aSubMeshVar =
1217 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1218 if ( !aSubMeshVar->_is_nil() )
1220 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1221 if ( !aMeshVar->_is_nil() )
1223 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1224 QString aMeshName = name( aMeshSO );
1225 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1229 // Get name of geometry object
1230 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1231 if ( !aGeomVar->_is_nil() )
1233 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1234 QString aShapeName = name( aGeomSO );
1235 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1238 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1239 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1242 QStringList anExisting;
1244 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1245 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1247 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1248 QString aHypTypeName = aVar->GetName();
1250 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
1251 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
1252 if ( aHypTypeName == aHypTypeNameList[ i ] )
1258 setCurrentHyp( dim, Algo, aHypIndex );
1261 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1264 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1265 // find index of requered hypothesis among existing ones for this dimension
1268 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1269 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1270 myExistingHyps[ dim ][ hypType ] );
1271 setCurrentHyp( dim, hypType, aHypIndex );
1276 //================================================================================
1278 * \brief Gets name of object
1279 * \param theSO - SObject
1280 * \retval QString - name of object
1282 * Gets name of object
1284 //================================================================================
1285 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1290 _PTR(GenericAttribute) anAttr;
1291 _PTR(AttributeName) aNameAttr;
1292 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1295 aResName = aNameAttr->Value().c_str();
1301 //================================================================================
1303 * \brief Finds hypothesis in input list
1304 * \param theHyp - hypothesis to be found
1305 * \param theHypList - input list of hypotheses
1306 * \retval int - index of hypothesis or -1 if it is not found
1308 * Finds position of hypothesis in input list
1310 //================================================================================
1311 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1312 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1315 if ( !theHyp->_is_nil() )
1318 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1319 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1321 if ( theHyp->_is_equivalent( *anIter ) )
1332 //================================================================================
1334 * \brief Edits mesh or sub-mesh
1335 * \param theMess - Output parameter intended for returning error message
1336 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1338 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1340 //================================================================================
1341 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1345 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1346 if ( aSMESHGen->_is_nil() )
1349 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1350 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1354 SUIT_OverrideCursor aWaitCursor;
1357 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1359 // Assign new hypotheses and algorithms
1360 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1362 if ( !isAccessibleDim( dim )) continue;
1364 // find or create algorithm
1365 bool toDelete = false, toAdd = true;
1366 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1367 if ( anAlgoVar->_is_nil() ) {
1370 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1371 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1373 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1382 // remove old algorithm
1384 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1385 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1387 // assign new algorithm
1389 SMESH::SMESH_Mesh_var aMeshVar =
1390 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1391 bool isMesh = !aMeshVar->_is_nil();
1393 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1395 SMESH::SMESH_subMesh_var aVar =
1396 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1397 if ( !aVar->_is_nil() )
1398 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1402 // assign hypotheses
1403 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1405 int aNewHypIndex = currentHyp( dim, hypType );
1406 int anOldHypIndex = -1;
1407 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1408 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1409 myExistingHyps[ dim ][ hypType ] );
1410 if ( aNewHypIndex != anOldHypIndex )
1412 // remove old hypotheses
1413 if ( anOldHypIndex >= 0 )
1414 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1415 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1417 // assign new hypotheses
1418 if ( aNewHypIndex != -1 )
1420 SMESH::SMESH_Mesh_var aMeshVar =
1421 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1422 bool isMesh = !aMeshVar->_is_nil();
1425 SMESH::AddHypothesisOnMesh(
1426 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1430 SMESH::SMESH_subMesh_var aVar =
1431 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1432 if ( !aVar->_is_nil() )
1433 SMESH::AddHypothesisOnSubMesh(
1434 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1437 // reread all hypotheses of mesh if necessary
1438 QStringList anExisting;
1439 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1447 //================================================================================
1449 * \brief Verifies whether given operator is valid for this one
1450 * \param theOtherOp - other operation
1451 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1453 * method redefined from base class verifies whether given operator is valid for
1454 * this one (i.e. can be started "above" this operator). In current implementation method
1455 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1458 //================================================================================
1459 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1461 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1464 //================================================================================
1466 * \brief SLOT. Is called when the user selects a way of geometry selection
1467 * \param theByMesh - true if the user wants to find geometry by mesh element
1469 //================================================================================
1471 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1474 if ( !myShapeByMeshDlg ) {
1475 myShapeByMeshDlg = new SMESHGUI_ShapeByMeshDlg( SMESHGUI::GetSMESHGUI(), "ShapeByMeshDlg");
1476 connect(myShapeByMeshDlg, SIGNAL(PublishShape()), SLOT(onPublishShapeByMeshDlg()));
1477 connect(myShapeByMeshDlg, SIGNAL(Close()), SLOT(onCloseShapeByMeshDlg()));
1479 // set mesh object to dlg
1480 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1481 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1482 SMESH::SMESH_Mesh_var aMeshVar =
1483 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1484 if ( !aMeshVar->_is_nil() ) {
1486 myDlg->activateObject( SMESHGUI_MeshDlg::Mesh );
1487 myShapeByMeshDlg->Init();
1488 myShapeByMeshDlg->SetMesh( aMeshVar );
1489 myShapeByMeshDlg->show();
1495 //================================================================================
1497 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1499 //================================================================================
1501 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg()
1503 if ( myShapeByMeshDlg ) {
1504 // Select a found geometry object
1505 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshDlg->GetShape();
1506 if ( !aGeomVar->_is_nil() )
1508 QString ID = aGeomVar->GetStudyEntry();
1509 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1510 SMESH::SMESH_Mesh_ptr aMeshPtr = myShapeByMeshDlg->GetMesh();
1511 if ( !CORBA::is_nil( aMeshPtr )) {
1512 if (_PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshPtr )) {
1513 myDlg->activateObject( SMESHGUI_MeshDlg::Mesh );
1514 myDlg->selectObject( aMeshSO->GetName().c_str(), SMESHGUI_MeshDlg::Mesh, aMeshSO->GetID().c_str() );
1517 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
1518 selectObject( aGeomSO );
1523 onCloseShapeByMeshDlg();
1529 //================================================================================
1531 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1533 //================================================================================
1535 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg()
1539 myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
1540 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1544 //================================================================================
1546 * \brief Selects a SObject
1547 * \param theSObj - the SObject to select
1549 //================================================================================
1551 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1553 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1554 SALOME_ListIO anIOList;
1556 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1557 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1558 anIOList.Append( anIO );
1560 sm->setSelectedObjects( anIOList, false );