4 * Copyright (C) 2005 CEA/DEN, EDF R&D
8 * File : SMESHGUI_MeshOp.h
9 * Author : Sergey LITONIN
13 #include "SMESHGUI_MeshOp.h"
14 #include "SMESHGUI_MeshDlg.h"
15 #include "SMESH_TypeFilter.hxx"
18 #include "SMESHGUI_HypothesesUtils.h"
19 #include "SMESHGUI_Hypotheses.h"
20 #include "SMESHGUI_Utils.h"
21 #include "SMESHGUI_GEOMGenUtils.h"
23 #include "SMESH_TypeFilter.hxx"
24 #include "SMESH_NumberFilter.hxx"
26 #include "GEOM_SelectionFilter.h"
28 #include "SalomeApp_Tools.h"
29 #include "SALOMEDSClient_Study.hxx"
30 #include "SALOMEDSClient_AttributeIOR.hxx"
31 #include "SALOMEDSClient_AttributeName.hxx"
32 #include "SALOMEDS_SComponent.hxx"
33 #include "SALOMEDS_SObject.hxx"
36 #include "LightApp_SelectionMgr.h"
37 #include "LightApp_UpdateFlags.h"
38 #include "SUIT_MessageBox.h"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_OverrideCursor.h"
44 #include "utilities.h"
46 #include <qstringlist.h>
47 #include <qlineedit.h>
49 #include <TopoDS_Shape.hxx>
50 #include <TopExp_Explorer.hxx>
52 //================================================================================
55 * \param theToCreate - if this parameter is true then operation is used for creation,
56 * for editing otherwise
58 * Initialize operation
60 //================================================================================
61 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
62 : SMESHGUI_SelectionOp(),
63 myToCreate( theToCreate ),
64 myIsMesh( theIsMesh ),
69 //================================================================================
73 //================================================================================
74 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
80 //================================================================================
82 * \brief Gets dialog of this operation
83 * \retval LightApp_Dialog* - pointer to dialog of this operation
85 //================================================================================
86 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
91 //================================================================================
93 * \brief Creates or edits mesh
94 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
96 * Virtual slot redefined from the base class called when "Apply" button is clicked
97 * creates or edits mesh
99 //================================================================================
100 bool SMESHGUI_MeshOp::onApply()
102 if( isStudyLocked() )
106 if ( !isValid( aMess ) )
109 SUIT_MessageBox::warn1( myDlg,
110 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
114 bool aResult = false;
118 if ( myToCreate && myIsMesh )
119 aResult = createMesh( aMess );
120 if ( myToCreate && !myIsMesh )
121 aResult = createSubMesh( aMess );
122 else if ( !myToCreate )
123 aResult = editMeshOrSubMesh( aMess );
125 update( UF_ObjBrowser | UF_Model );
127 catch ( const SALOME::SALOME_Exception& S_ex )
129 SalomeApp_Tools::QtCatchCorbaException( S_ex );
145 aMess = tr( "SMESH_OPERATION_FAILED" );
146 SUIT_MessageBox::warn1( myDlg,
147 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
153 //================================================================================
155 * \brief Creates dialog if necessary and shows it
157 * Virtual method redefined from base class called when operation is started creates
158 * dialog if necessary and shows it, activates selection
160 //================================================================================
161 void SMESHGUI_MeshOp::startOperation()
165 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
166 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
168 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
169 this, SLOT( onCreateHyp( const int, const int) ) );
170 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
171 this, SLOT( onEditHyp( const int, const int) ) );
173 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
175 SMESHGUI_SelectionOp::startOperation();
177 // iterate through dimensions and get available and existing algoritms and hypotheses,
178 // set them to the dialog
180 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
181 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
183 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
184 QStringList anAvailable, anExisting;
185 for ( j = Algo; j <= AddHyp; j++ )
187 availableHyps( i, j, anAvailable );
188 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
190 aTab->setAvailableHyps( j, anAvailable );
191 aTab->setExistingHyps( j, anExisting );
197 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
200 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
202 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
206 myDlg->setCurrentTab( SMESH::DIM_1D );
210 //================================================================================
212 * \brief Creates selection filter
213 * \param theId - identifier of current selection widget
214 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
216 * Creates selection filter in accordance with identifier of current selection widget
218 //================================================================================
219 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
221 if ( theId == SMESHGUI_MeshDlg::Geom )
223 // TColStd_MapOfInteger allTypesMap;
224 // for ( int i = 0; i < 10; i++ )
225 // allTypesMap.Add( i );
226 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
227 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
229 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
230 return new SMESH_TypeFilter( MESHorSUBMESH );
231 else if ( theId == SMESHGUI_MeshDlg::Mesh )
232 return new SMESH_TypeFilter( MESH );
237 //================================================================================
239 * \brief Updates dialog's look and feel
241 * Virtual method redefined from the base class updates dialog's look and feel
243 //================================================================================
244 void SMESHGUI_MeshOp::selectionDone()
246 SMESHGUI_SelectionOp::selectionDone();
252 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
253 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
256 SMESH::SMESH_subMesh_var aVar =
257 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
258 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
259 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
260 myDlg->updateGeometry();
267 catch ( const SALOME::SALOME_Exception& S_ex )
269 SalomeApp_Tools::QtCatchCorbaException( S_ex );
276 // Enable tabs according to shape dimension
281 GEOM::GEOM_Object_var aGeomVar;
282 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
283 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
285 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
288 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
289 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
290 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
292 if ( !aGeomVar->_is_nil() ) {
294 switch ( aGeomVar->GetShapeType() ) {
296 case GEOM::SHELL: shapeDim = 3; break;
297 case GEOM::FACE: shapeDim = 2; break;
299 case GEOM::EDGE: shapeDim = 1; break;
300 case GEOM::VERTEX: shapeDim = 0; break;
303 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
304 TopExp_Explorer exp( aShape, TopAbs_SHELL );
307 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
309 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
317 catch ( const SALOME::SALOME_Exception& S_ex )
319 SalomeApp_Tools::QtCatchCorbaException( S_ex );
324 myDlg->setMaxHypoDim( shapeDim );
327 //================================================================================
329 * \brief Verifies validity of input data
330 * \param theMess - Output parameter intended for returning error message
331 * \retval bool - TRUE if input data is valid, false otherwise
333 * Verifies validity of input data. This method is called when "Apply" or "OK" button
334 * is pressed before mesh creation or editing.
336 //================================================================================
337 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
339 // Selected object to be edited
340 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
342 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
347 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
348 aMeshName = aMeshName.stripWhiteSpace();
349 if ( aMeshName == "" )
351 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
358 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
359 if ( aGeomEntry == "" )
361 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
364 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
365 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
367 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
372 if ( !myIsMesh ) // i.e sub-mesh creation,
374 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
375 if ( aMeshEntry == "" )
377 theMess = tr( "MESH_IS_NOT_DEFINED" );
380 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
381 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
383 theMess = tr( "MESH_IS_NULL" );
391 //================================================================================
393 * \brief Gets available hypotheses or algorithms
394 * \param theDim - specifies dimension of returned hypotheses/algorifms
395 * \param theHypType - specifies whether algorims or hypotheses or additional ones
396 * are retrieved (possible values are in HypType enumeration)
397 * \param theHyps - Output list of hypotheses' names
399 * Gets available hypotheses or algorithm in accordance with input parameters
401 //================================================================================
402 void SMESHGUI_MeshOp::availableHyps( const int theDim,
403 const int theHypType,
404 QStringList& theHyps ) const
407 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
408 theHypType == Algo , theDim, theHypType == AddHyp );
409 QStringList::const_iterator anIter;
410 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
412 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
413 theHyps.append( aData->Label );
417 //================================================================================
419 * \brief Gets existing hypotheses or algorithms
420 * \param theDim - specifies dimension of returned hypotheses/algorifms
421 * \param theHypType - specifies whether algorims or hypotheses or additional ones
422 * are retrieved (possible values are in HypType enumeration)
423 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
424 * \param theHyps - output list of names.
425 * \param theHypVars - output list of variables.
427 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
430 //================================================================================
431 void SMESHGUI_MeshOp::existingHyps( const int theDim,
432 const int theHypType,
433 _PTR(SObject) theFather,
434 QStringList& theHyps,
435 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
437 // Clear hypoheses list
444 _PTR(SObject) aHypRoot;
445 _PTR(GenericAttribute) anAttr;
446 _PTR(AttributeName) aName;
447 _PTR(AttributeIOR) anIOR;
449 bool isMesh = !_CAST( SComponent, theFather );
452 aPart = theHypType == Algo ? 3 : 2;
454 aPart = theHypType == Algo ? 2 : 1;
456 if ( theFather->FindSubObject( aPart, aHypRoot ) )
458 _PTR(ChildIterator) anIter =
459 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
460 for (; anIter->More(); anIter->Next() )
462 _PTR(SObject) anObj = anIter->Value();
463 if ( isMesh ) // i.e. mesh or submesh
465 _PTR(SObject) aRefObj;
466 if ( anObj->ReferencedObject( aRefObj ) )
471 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
474 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
475 if ( !CORBA::is_nil( aVar ) )
477 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
478 if ( !aHypVar->_is_nil() )
480 QString aHypType( aHypVar->GetName() );
481 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
482 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
483 ( theHypType == AddHyp ) == aData->IsAux )
485 theHyps.append( aName->Value().c_str() );
486 theHypVars.append( aHypVar );
495 //================================================================================
497 * \brief Calls plugin methods for hypothesis creation
498 * \param theHypType - specifies whether main hypotheses or additional ones
500 * \param theIndex - index of type of hypothesis to be cerated
502 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
503 * its type and calls plugin methods for hypothesis creation
505 //================================================================================
506 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
508 // Speicfies dimension of hypothesis to be created
509 const QObject* aSender = sender();
511 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
512 if ( aSender == myDlg->tab( i ) )
517 // Speicfies type of hypothesis to be created
518 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
519 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
522 QString aHypTypeName = aHypTypeNames[ theIndex ];
523 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
527 QString aClientLibName = aData->ClientLibName;
528 QStringList anOldHyps;
529 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
530 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
532 if ( aClientLibName == "" )
534 // Call hypothesis creation server method (without GUI)
535 QString aHypName = aData->Label;
536 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
540 // Get hypotheses creator client (GUI)
541 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
544 aCreator->CreateHypothesis( false, myDlg );
547 QStringList aNewHyps;
548 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
549 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
550 if ( aNewHyps.count() > anOldHyps.count() )
552 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
553 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
557 //================================================================================
559 * \brief Calls plugin methods for hypothesis editing
560 * \param theHypType - specifies whether main hypothesis or additional one
562 * \param theIndex - index of existing hypothesis
564 * Calls plugin methods for hypothesis editing
566 //================================================================================
567 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
569 // Speicfies dimension of hypothesis to be created
570 const QObject* aSender = sender();
572 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
573 if ( aSender == myDlg->tab( i ) )
578 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
579 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
580 if ( aHyp->_is_nil() )
583 char* aTypeName = aHyp->GetName();
584 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
586 aCreator->EditHypothesis( aHyp );
589 //================================================================================
591 * \brief Creates and selects hypothesis of hypotheses set
592 * \param theSetName - The name of hypotheses set
594 //================================================================================
596 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
598 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
599 if ( !aHypoSet ) return;
601 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
603 bool isAlgo = (aHypType == Algo);
606 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
607 setCurrentHyp( dim, aHypType, -1 );
609 // set hyps from the set
611 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
612 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
614 const QString& aHypoTypeName = (*aHypoList)[ i ];
615 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
616 int aDim = aHypData->Dim[0];
621 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
622 index = aHypTypeNameList.findIndex( aHypoTypeName );
623 if ( index < 0 ) continue;
624 setCurrentHyp ( aDim, aHypType, index );
628 // try to find an existing hypo
629 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
630 int iHyp = 0, nbHyp = aList.count();
631 for ( ; iHyp < nbHyp; ++iHyp )
633 SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
634 if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
639 if ( index >= 0 ) // found
641 setCurrentHyp ( aDim, aHypType, index );
645 // silently create a hypothesis
646 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
647 QStringList aNewHyps;
648 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
649 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
650 if ( aList.count() > nbHyp )
652 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
653 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
657 } // loop on hypos in the set
658 } // loop on algo/hypo
661 //================================================================================
663 * \brief Creates mesh
664 * \param theMess - Output parameter intended for returning error message
665 * \retval bool - TRUE if mesh is created, FALSE otherwise
669 //================================================================================
670 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
674 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
675 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
676 GEOM::GEOM_Object_var aGeomVar =
677 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
679 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
680 if ( aSMESHGen->_is_nil() )
683 SUIT_OverrideCursor aWaitCursor;
686 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
687 if ( aMeshVar->_is_nil() )
689 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
691 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
693 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
695 if ( !isAccessibleDim( aDim )) continue;
698 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
700 int aHypIndex = currentHyp( aDim, aHypType );
701 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
703 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
704 if ( !aHypVar->_is_nil() )
705 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
708 // find or create algorithm
709 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
710 if ( !anAlgoVar->_is_nil() )
711 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
716 //================================================================================
718 * \brief Creates sub-mesh
719 * \param theMess - Output parameter intended for returning error message
720 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
724 //================================================================================
725 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
729 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
730 if ( aSMESHGen->_is_nil() )
734 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
735 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
736 SMESH::SMESH_Mesh_var aMeshVar =
737 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
740 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
741 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
742 GEOM::GEOM_Object_var aGeomVar =
743 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
745 SUIT_OverrideCursor aWaitCursor;
748 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
749 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
751 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
753 if ( !isAccessibleDim( aDim )) continue;
755 // find or create algorithm
756 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
757 if ( !anAlgoVar->_is_nil() )
758 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
760 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
762 int aHypIndex = currentHyp( aDim, aHypType );
763 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
765 SMESH::SMESH_Hypothesis_var aHypVar =
766 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
767 if ( !aHypVar->_is_nil() )
768 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
775 //================================================================================
777 * \brief Gets current hypothesis or algorithms
778 * \param theDim - dimension of hypothesis or algorithm
779 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
780 * \retval int - current hypothesis or algorithms
782 * Gets current hypothesis or algorithms
784 //================================================================================
785 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
787 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
790 //================================================================================
792 * \brief Returns true if hypotheses of given dim can be assigned
793 * \param theDim - hypotheses dimension
794 * \retval bool - result
796 //================================================================================
797 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
799 return myDlg->tab( theDim )->isEnabled();
802 //================================================================================
804 * \brief Sets current hypothesis or algorithms
805 * \param theDim - dimension of hypothesis or algorithm
806 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
807 * \param theIndex - Index of hypothesis
809 * Gets current hypothesis or algorithms
811 //================================================================================
812 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
813 const int theHypType,
816 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
819 //================================================================================
821 * \brief Generates default and sets mesh/submesh name
823 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
825 //================================================================================
826 void SMESHGUI_MeshOp::setDefaultName() const
830 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
832 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
836 aResName = aPrefix + QString::number( i++ );
837 anObj = aStudy->FindObject( aResName.latin1() );
841 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
842 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
843 aControl->setText( aResName );
846 //================================================================================
848 * \brief Gets algorithm or creates it if necessary
849 * \param theDim - specifies dimension of returned hypotheses/algorifms
850 * \retval SMESH::SMESH_Hypothesis_var - algorithm
852 * Gets algorithm or creates it if necessary
854 //================================================================================
855 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
857 SMESH::SMESH_Hypothesis_var anAlgoVar;
858 int aHypIndex = currentHyp( theDim, Algo );
859 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
860 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
862 QString aHypName = aHypTypeNameList[ aHypIndex ];
863 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
864 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
865 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
867 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
868 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
874 if ( anAlgoVar->_is_nil() )
876 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
879 QString aClientLibName = aHypData->ClientLibName;
880 if ( aClientLibName == "" )
881 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
884 SMESHGUI_GenericHypothesisCreator* aCreator =
885 SMESH::GetHypothesisCreator( aHypName );
887 aCreator->CreateHypothesis( true, myDlg );
890 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
891 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
894 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
895 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
897 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
898 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
906 return anAlgoVar._retn();
909 //================================================================================
911 * \brief Reads parameters of edited mesh and assigns them to the dialog
913 * Reads parameters of edited mesh and assigns them to the dialog (called when
914 * mesh is edited only)
916 //================================================================================
917 void SMESHGUI_MeshOp::readMesh()
919 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
920 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
924 // Get name of mesh if current object is sub-mesh
925 SMESH::SMESH_subMesh_var aSubMeshVar =
926 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
927 if ( !aSubMeshVar->_is_nil() )
929 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
930 if ( !aMeshVar->_is_nil() )
932 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
933 QString aMeshName = name( aMeshSO );
934 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
938 // Get name of geometry object
939 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
940 if ( !aGeomVar->_is_nil() )
942 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
943 QString aShapeName = name( aGeomSO );
944 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
947 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
948 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
951 QStringList anExisting;
953 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
954 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
956 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
957 QString aHypTypeName = aVar->GetName();
959 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
960 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
961 if ( aHypTypeName == aHypTypeNameList[ i ] )
967 setCurrentHyp( dim, Algo, aHypIndex );
970 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
973 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
974 // find index of requered hypothesis among existing ones for this dimension
977 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
978 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
979 myExistingHyps[ dim ][ hypType ] );
980 setCurrentHyp( dim, hypType, aHypIndex );
985 //================================================================================
987 * \brief Gets name of object
988 * \param theSO - SObject
989 * \retval QString - name of object
991 * Gets name of object
993 //================================================================================
994 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
999 _PTR(GenericAttribute) anAttr;
1000 _PTR(AttributeName) aNameAttr;
1001 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1004 aResName = aNameAttr->Value().c_str();
1010 //================================================================================
1012 * \brief Finds hypothesis in input list
1013 * \param theHyp - hypothesis to be found
1014 * \param theHypList - input list of hypotheses
1015 * \retval int - index of hypothesis or -1 if it is not found
1017 * Finds position of hypothesis in input list
1019 //================================================================================
1020 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1021 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1024 if ( !theHyp->_is_nil() )
1027 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1028 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1030 if ( theHyp->_is_equivalent( *anIter ) )
1041 //================================================================================
1043 * \brief Edits mesh or sub-mesh
1044 * \param theMess - Output parameter intended for returning error message
1045 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1047 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1049 //================================================================================
1050 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1054 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1055 if ( aSMESHGen->_is_nil() )
1058 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1059 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1063 SUIT_OverrideCursor aWaitCursor;
1066 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1068 // Assign new hypotheses and algorithms
1069 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1071 if ( !isAccessibleDim( dim )) continue;
1073 // find or create algorithm
1074 bool toDelete = false, toAdd = true;
1075 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1076 if ( anAlgoVar->_is_nil() ) {
1079 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1080 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1082 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1091 // remove old algorithm
1093 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1094 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1096 // assign new algorithm
1098 SMESH::SMESH_Mesh_var aMeshVar =
1099 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1100 bool isMesh = !aMeshVar->_is_nil();
1102 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1104 SMESH::SMESH_subMesh_var aVar =
1105 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1106 if ( !aVar->_is_nil() )
1107 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1111 // assign hypotheses
1112 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1114 int aNewHypIndex = currentHyp( dim, hypType );
1115 int anOldHypIndex = -1;
1116 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1117 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1118 myExistingHyps[ dim ][ hypType ] );
1119 if ( aNewHypIndex != anOldHypIndex )
1121 // remove old hypotheses
1122 if ( anOldHypIndex >= 0 )
1123 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1124 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1126 // assign new hypotheses
1127 if ( aNewHypIndex != -1 )
1129 SMESH::SMESH_Mesh_var aMeshVar =
1130 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1131 bool isMesh = !aMeshVar->_is_nil();
1134 SMESH::AddHypothesisOnMesh(
1135 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1139 SMESH::SMESH_subMesh_var aVar =
1140 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1141 if ( !aVar->_is_nil() )
1142 SMESH::AddHypothesisOnSubMesh(
1143 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1146 // reread all hypotheses of mesh if necessary
1147 QStringList anExisting;
1148 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1156 //================================================================================
1158 * \brief Verifies whether given operator is valid for this one
1159 * \param theOtherOp - other operation
1160 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1162 * method redefined from base class verifies whether given operator is valid for
1163 * this one (i.e. can be started "above" this operator). In current implementation method
1164 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1167 //================================================================================
1168 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1170 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );