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
283 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
284 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
286 GEOM::GEOM_Object_var aGeomVar =
287 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
288 if ( !aGeomVar->_is_nil() ) {
290 switch ( aGeomVar->GetShapeType() ) {
292 case GEOM::SHELL: shapeDim = 3; break;
293 case GEOM::FACE: shapeDim = 2; break;
295 case GEOM::EDGE: shapeDim = 1; break;
296 case GEOM::VERTEX: shapeDim = 0; break;
299 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
300 TopExp_Explorer exp( aShape, TopAbs_SHELL );
303 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
305 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
314 catch ( const SALOME::SALOME_Exception& S_ex )
316 SalomeApp_Tools::QtCatchCorbaException( S_ex );
322 myDlg->setMaxHypoDim( shapeDim );
325 //================================================================================
327 * \brief Verifies validity of input data
328 * \param theMess - Output parameter intended for returning error message
329 * \retval bool - TRUE if input data is valid, false otherwise
331 * Verifies validity of input data. This method is called when "Apply" or "OK" button
332 * is pressed before mesh creation or editing.
334 //================================================================================
335 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
337 // Selected object to be edited
338 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
340 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
345 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
346 aMeshName = aMeshName.stripWhiteSpace();
347 if ( aMeshName == "" )
349 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
356 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
357 if ( aGeomEntry == "" )
359 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
362 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
363 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
365 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
370 if ( !myIsMesh ) // i.e sub-mesh creation,
372 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
373 if ( aMeshEntry == "" )
375 theMess = tr( "MESH_IS_NOT_DEFINED" );
378 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
379 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
381 theMess = tr( "MESH_IS_NULL" );
389 //================================================================================
391 * \brief Gets available hypotheses or algorithms
392 * \param theDim - specifies dimension of returned hypotheses/algorifms
393 * \param theHypType - specifies whether algorims or hypotheses or additional ones
394 * are retrieved (possible values are in HypType enumeration)
395 * \param theHyps - Output list of hypotheses' names
397 * Gets available hypotheses or algorithm in accordance with input parameters
399 //================================================================================
400 void SMESHGUI_MeshOp::availableHyps( const int theDim,
401 const int theHypType,
402 QStringList& theHyps ) const
405 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
406 theHypType == Algo , theDim, theHypType == AddHyp );
407 QStringList::const_iterator anIter;
408 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
410 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
411 theHyps.append( aData->Label );
415 //================================================================================
417 * \brief Gets existing hypotheses or algorithms
418 * \param theDim - specifies dimension of returned hypotheses/algorifms
419 * \param theHypType - specifies whether algorims or hypotheses or additional ones
420 * are retrieved (possible values are in HypType enumeration)
421 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
422 * \param theHyps - output list of names.
423 * \param theHypVars - output list of variables.
425 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
428 //================================================================================
429 void SMESHGUI_MeshOp::existingHyps( const int theDim,
430 const int theHypType,
431 _PTR(SObject) theFather,
432 QStringList& theHyps,
433 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
435 // Clear hypoheses list
442 _PTR(SObject) aHypRoot;
443 _PTR(GenericAttribute) anAttr;
444 _PTR(AttributeName) aName;
445 _PTR(AttributeIOR) anIOR;
447 bool isMesh = !_CAST( SComponent, theFather );
450 aPart = theHypType == Algo ? 3 : 2;
452 aPart = theHypType == Algo ? 2 : 1;
454 if ( theFather->FindSubObject( aPart, aHypRoot ) )
456 _PTR(ChildIterator) anIter =
457 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
458 for (; anIter->More(); anIter->Next() )
460 _PTR(SObject) anObj = anIter->Value();
461 if ( isMesh ) // i.e. mesh or submesh
463 _PTR(SObject) aRefObj;
464 if ( anObj->ReferencedObject( aRefObj ) )
469 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
472 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
473 if ( !CORBA::is_nil( aVar ) )
475 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
476 if ( !aHypVar->_is_nil() )
478 QString aHypType( aHypVar->GetName() );
479 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
480 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
481 ( theHypType == AddHyp ) == aData->IsAux )
483 theHyps.append( aName->Value().c_str() );
484 theHypVars.append( aHypVar );
493 //================================================================================
495 * \brief Calls plugin methods for hypothesis creation
496 * \param theHypType - specifies whether main hypotheses or additional ones
498 * \param theIndex - index of type of hypothesis to be cerated
500 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
501 * its type and calls plugin methods for hypothesis creation
503 //================================================================================
504 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
506 // Speicfies dimension of hypothesis to be created
507 const QObject* aSender = sender();
509 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
510 if ( aSender == myDlg->tab( i ) )
515 // Speicfies type of hypothesis to be created
516 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
517 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
520 QString aHypTypeName = aHypTypeNames[ theIndex ];
521 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
525 QString aClientLibName = aData->ClientLibName;
526 QStringList anOldHyps;
527 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
528 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
530 if ( aClientLibName == "" )
532 // Call hypothesis creation server method (without GUI)
533 QString aHypName = aData->Label;
534 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
538 // Get hypotheses creator client (GUI)
539 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
542 aCreator->CreateHypothesis( false, myDlg );
545 QStringList aNewHyps;
546 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
547 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
548 if ( aNewHyps.count() > anOldHyps.count() )
550 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
551 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
555 //================================================================================
557 * \brief Calls plugin methods for hypothesis editing
558 * \param theHypType - specifies whether main hypothesis or additional one
560 * \param theIndex - index of existing hypothesis
562 * Calls plugin methods for hypothesis editing
564 //================================================================================
565 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
567 // Speicfies dimension of hypothesis to be created
568 const QObject* aSender = sender();
570 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
571 if ( aSender == myDlg->tab( i ) )
576 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
577 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
578 if ( aHyp->_is_nil() )
581 char* aTypeName = aHyp->GetName();
582 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
584 aCreator->EditHypothesis( aHyp );
587 //================================================================================
589 * \brief Creates and selects hypothesis of hypotheses set
590 * \param theSetName - The name of hypotheses set
592 //================================================================================
594 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
596 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
597 if ( !aHypoSet ) return;
599 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
601 bool isAlgo = (aHypType == Algo);
604 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
605 setCurrentHyp( dim, aHypType, -1 );
607 // set hyps from the set
609 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
610 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
612 const QString& aHypoTypeName = (*aHypoList)[ i ];
613 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
614 int aDim = aHypData->Dim[0];
619 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
620 index = aHypTypeNameList.findIndex( aHypoTypeName );
621 if ( index < 0 ) continue;
622 setCurrentHyp ( aDim, aHypType, index );
626 // try to find an existing hypo
627 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
628 int iHyp = 0, nbHyp = aList.count();
629 for ( ; iHyp < nbHyp; ++iHyp )
631 SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
632 if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
637 if ( index >= 0 ) // found
639 setCurrentHyp ( aDim, aHypType, index );
643 // silently create a hypothesis
644 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
645 QStringList aNewHyps;
646 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
647 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
648 if ( aList.count() > nbHyp )
650 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
651 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
655 } // loop on hypos in the set
656 } // loop on algo/hypo
659 //================================================================================
661 * \brief Creates mesh
662 * \param theMess - Output parameter intended for returning error message
663 * \retval bool - TRUE if mesh is created, FALSE otherwise
667 //================================================================================
668 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
672 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
673 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
674 GEOM::GEOM_Object_var aGeomVar =
675 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
677 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
678 if ( aSMESHGen->_is_nil() )
681 SUIT_OverrideCursor aWaitCursor;
684 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
685 if ( aMeshVar->_is_nil() )
687 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
689 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
691 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
693 if ( !isAccessibleDim( aDim )) continue;
696 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
698 int aHypIndex = currentHyp( aDim, aHypType );
699 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
701 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
702 if ( !aHypVar->_is_nil() )
703 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
706 // find or create algorithm
707 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
708 if ( !anAlgoVar->_is_nil() )
709 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
714 //================================================================================
716 * \brief Creates sub-mesh
717 * \param theMess - Output parameter intended for returning error message
718 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
722 //================================================================================
723 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
727 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
728 if ( aSMESHGen->_is_nil() )
732 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
733 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
734 SMESH::SMESH_Mesh_var aMeshVar =
735 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
738 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
739 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
740 GEOM::GEOM_Object_var aGeomVar =
741 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
743 SUIT_OverrideCursor aWaitCursor;
746 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
747 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
749 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
751 if ( !isAccessibleDim( aDim )) continue;
753 // find or create algorithm
754 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
755 if ( !anAlgoVar->_is_nil() )
756 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
758 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
760 int aHypIndex = currentHyp( aDim, aHypType );
761 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
763 SMESH::SMESH_Hypothesis_var aHypVar =
764 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
765 if ( !aHypVar->_is_nil() )
766 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
773 //================================================================================
775 * \brief Gets current hypothesis or algorithms
776 * \param theDim - dimension of hypothesis or algorithm
777 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
778 * \retval int - current hypothesis or algorithms
780 * Gets current hypothesis or algorithms
782 //================================================================================
783 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
785 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
788 //================================================================================
790 * \brief Returns true if hypotheses of given dim can be assigned
791 * \param theDim - hypotheses dimension
792 * \retval bool - result
794 //================================================================================
795 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
797 return myDlg->tab( theDim )->isEnabled();
800 //================================================================================
802 * \brief Sets current hypothesis or algorithms
803 * \param theDim - dimension of hypothesis or algorithm
804 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
805 * \param theIndex - Index of hypothesis
807 * Gets current hypothesis or algorithms
809 //================================================================================
810 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
811 const int theHypType,
814 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
817 //================================================================================
819 * \brief Generates default and sets mesh/submesh name
821 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
823 //================================================================================
824 void SMESHGUI_MeshOp::setDefaultName() const
828 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
830 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
834 aResName = aPrefix + QString::number( i++ );
835 anObj = aStudy->FindObject( aResName.latin1() );
839 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
840 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
841 aControl->setText( aResName );
844 //================================================================================
846 * \brief Gets algorithm or creates it if necessary
847 * \param theDim - specifies dimension of returned hypotheses/algorifms
848 * \retval SMESH::SMESH_Hypothesis_var - algorithm
850 * Gets algorithm or creates it if necessary
852 //================================================================================
853 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
855 SMESH::SMESH_Hypothesis_var anAlgoVar;
856 int aHypIndex = currentHyp( theDim, Algo );
857 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
858 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
860 QString aHypName = aHypTypeNameList[ aHypIndex ];
861 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
862 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
863 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
865 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
866 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
872 if ( anAlgoVar->_is_nil() )
874 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
877 QString aClientLibName = aHypData->ClientLibName;
878 if ( aClientLibName == "" )
879 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
882 SMESHGUI_GenericHypothesisCreator* aCreator =
883 SMESH::GetHypothesisCreator( aHypName );
885 aCreator->CreateHypothesis( true, myDlg );
888 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
889 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
892 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
893 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
895 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
896 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
904 return anAlgoVar._retn();
907 //================================================================================
909 * \brief Reads parameters of edited mesh and assigns them to the dialog
911 * Reads parameters of edited mesh and assigns them to the dialog (called when
912 * mesh is edited only)
914 //================================================================================
915 void SMESHGUI_MeshOp::readMesh()
917 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
918 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
922 // Get name of mesh if current object is sub-mesh
923 SMESH::SMESH_subMesh_var aSubMeshVar =
924 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
925 if ( !aSubMeshVar->_is_nil() )
927 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
928 if ( !aMeshVar->_is_nil() )
930 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
931 QString aMeshName = name( aMeshSO );
932 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
936 // Get name of geometry object
937 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
938 if ( !aGeomVar->_is_nil() )
940 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
941 QString aShapeName = name( aGeomSO );
942 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
945 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
946 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
949 QStringList anExisting;
951 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
952 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
954 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
955 QString aHypTypeName = aVar->GetName();
957 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
958 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
959 if ( aHypTypeName == aHypTypeNameList[ i ] )
965 setCurrentHyp( dim, Algo, aHypIndex );
968 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
971 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
972 // find index of requered hypothesis among existing ones for this dimension
975 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
976 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
977 myExistingHyps[ dim ][ hypType ] );
978 setCurrentHyp( dim, hypType, aHypIndex );
983 //================================================================================
985 * \brief Gets name of object
986 * \param theSO - SObject
987 * \retval QString - name of object
989 * Gets name of object
991 //================================================================================
992 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
997 _PTR(GenericAttribute) anAttr;
998 _PTR(AttributeName) aNameAttr;
999 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1002 aResName = aNameAttr->Value().c_str();
1008 //================================================================================
1010 * \brief Finds hypothesis in input list
1011 * \param theHyp - hypothesis to be found
1012 * \param theHypList - input list of hypotheses
1013 * \retval int - index of hypothesis or -1 if it is not found
1015 * Finds position of hypothesis in input list
1017 //================================================================================
1018 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1019 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1022 if ( !theHyp->_is_nil() )
1025 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1026 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1028 if ( theHyp->_is_equivalent( *anIter ) )
1039 //================================================================================
1041 * \brief Edits mesh or sub-mesh
1042 * \param theMess - Output parameter intended for returning error message
1043 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1045 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1047 //================================================================================
1048 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1052 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1053 if ( aSMESHGen->_is_nil() )
1056 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1057 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1061 SUIT_OverrideCursor aWaitCursor;
1064 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1066 // Assign new hypotheses and algorithms
1067 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1069 if ( !isAccessibleDim( dim )) continue;
1071 // find or create algorithm
1072 bool toDelete = false, toAdd = true;
1073 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1074 if ( anAlgoVar->_is_nil() ) {
1077 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1078 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1080 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1089 // remove old algorithm
1091 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1092 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1094 // assign new algorithm
1096 SMESH::SMESH_Mesh_var aMeshVar =
1097 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1098 bool isMesh = !aMeshVar->_is_nil();
1100 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1102 SMESH::SMESH_subMesh_var aVar =
1103 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1104 if ( !aVar->_is_nil() )
1105 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1109 // assign hypotheses
1110 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1112 int aNewHypIndex = currentHyp( dim, hypType );
1113 int anOldHypIndex = -1;
1114 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1115 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1116 myExistingHyps[ dim ][ hypType ] );
1117 if ( aNewHypIndex != anOldHypIndex )
1119 // remove old hypotheses
1120 if ( anOldHypIndex >= 0 )
1121 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1122 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1124 // assign new hypotheses
1125 if ( aNewHypIndex != -1 )
1127 SMESH::SMESH_Mesh_var aMeshVar =
1128 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1129 bool isMesh = !aMeshVar->_is_nil();
1132 SMESH::AddHypothesisOnMesh(
1133 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1137 SMESH::SMESH_subMesh_var aVar =
1138 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1139 if ( !aVar->_is_nil() )
1140 SMESH::AddHypothesisOnSubMesh(
1141 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1144 // reread all hypotheses of mesh if necessary
1145 QStringList anExisting;
1146 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1154 //================================================================================
1156 * \brief Verifies whether given operator is valid for this one
1157 * \param theOtherOp - other operation
1158 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1160 * method redefined from base class verifies whether given operator is valid for
1161 * this one (i.e. can be started "above" this operator). In current implementation method
1162 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1165 //================================================================================
1166 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1168 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );