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 "SMESH_TypeFilter.hxx"
37 #include "SMESHGUI_HypothesesUtils.h"
38 #include "SMESHGUI_Hypotheses.h"
39 #include "SMESHGUI_Utils.h"
40 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESH_TypeFilter.hxx"
43 #include "SMESH_NumberFilter.hxx"
45 #include "GEOM_SelectionFilter.h"
47 #include "SalomeApp_Tools.h"
48 #include "SALOMEDSClient_Study.hxx"
49 #include "SALOMEDSClient_AttributeIOR.hxx"
50 #include "SALOMEDSClient_AttributeName.hxx"
51 #include "SALOMEDS_SComponent.hxx"
52 #include "SALOMEDS_SObject.hxx"
55 #include "LightApp_SelectionMgr.h"
56 #include "LightApp_UpdateFlags.h"
57 #include "SUIT_MessageBox.h"
58 #include "SUIT_Desktop.h"
59 #include "SUIT_OverrideCursor.h"
63 #include "utilities.h"
65 #include <qstringlist.h>
66 #include <qlineedit.h>
68 #include <TopoDS_Shape.hxx>
69 #include <TopExp_Explorer.hxx>
71 //================================================================================
74 * \param theToCreate - if this parameter is true then operation is used for creation,
75 * for editing otherwise
77 * Initialize operation
79 //================================================================================
80 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
81 : SMESHGUI_SelectionOp(),
82 myToCreate( theToCreate ),
83 myIsMesh( theIsMesh ),
88 //================================================================================
92 //================================================================================
93 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
99 //================================================================================
101 * \brief Gets dialog of this operation
102 * \retval LightApp_Dialog* - pointer to dialog of this operation
104 //================================================================================
105 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
110 //================================================================================
112 * \brief Creates or edits mesh
113 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
115 * Virtual slot redefined from the base class called when "Apply" button is clicked
116 * creates or edits mesh
118 //================================================================================
119 bool SMESHGUI_MeshOp::onApply()
121 if( isStudyLocked() )
125 if ( !isValid( aMess ) )
128 SUIT_MessageBox::warn1( myDlg,
129 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
133 bool aResult = false;
137 if ( myToCreate && myIsMesh )
138 aResult = createMesh( aMess );
139 if ( myToCreate && !myIsMesh )
140 aResult = createSubMesh( aMess );
141 else if ( !myToCreate )
142 aResult = editMeshOrSubMesh( aMess );
144 update( UF_ObjBrowser | UF_Model );
146 catch ( const SALOME::SALOME_Exception& S_ex )
148 SalomeApp_Tools::QtCatchCorbaException( S_ex );
164 aMess = tr( "SMESH_OPERATION_FAILED" );
165 SUIT_MessageBox::warn1( myDlg,
166 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
172 //================================================================================
174 * \brief Creates dialog if necessary and shows it
176 * Virtual method redefined from base class called when operation is started creates
177 * dialog if necessary and shows it, activates selection
179 //================================================================================
180 void SMESHGUI_MeshOp::startOperation()
184 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
185 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
187 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
188 this, SLOT( onCreateHyp( const int, const int) ) );
189 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
190 this, SLOT( onEditHyp( const int, const int) ) );
192 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
194 SMESHGUI_SelectionOp::startOperation();
196 // iterate through dimensions and get available and existing algoritms and hypotheses,
197 // set them to the dialog
199 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
200 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
202 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
203 QStringList anAvailable, anExisting;
204 for ( j = Algo; j <= AddHyp; j++ )
206 availableHyps( i, j, anAvailable );
207 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
209 aTab->setAvailableHyps( j, anAvailable );
210 aTab->setExistingHyps( j, anExisting );
216 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
219 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
221 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
225 myDlg->setCurrentTab( SMESH::DIM_1D );
229 //================================================================================
231 * \brief Creates selection filter
232 * \param theId - identifier of current selection widget
233 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
235 * Creates selection filter in accordance with identifier of current selection widget
237 //================================================================================
238 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
240 if ( theId == SMESHGUI_MeshDlg::Geom )
242 // TColStd_MapOfInteger allTypesMap;
243 // for ( int i = 0; i < 10; i++ )
244 // allTypesMap.Add( i );
245 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
246 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
248 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
249 return new SMESH_TypeFilter( MESHorSUBMESH );
250 else if ( theId == SMESHGUI_MeshDlg::Mesh )
251 return new SMESH_TypeFilter( MESH );
256 //================================================================================
258 * \brief Updates dialog's look and feel
260 * Virtual method redefined from the base class updates dialog's look and feel
262 //================================================================================
263 void SMESHGUI_MeshOp::selectionDone()
265 SMESHGUI_SelectionOp::selectionDone();
271 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
272 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
275 SMESH::SMESH_subMesh_var aVar =
276 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
277 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
278 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
279 myDlg->updateGeometry();
286 catch ( const SALOME::SALOME_Exception& S_ex )
288 SalomeApp_Tools::QtCatchCorbaException( S_ex );
295 // Enable tabs according to shape dimension
300 GEOM::GEOM_Object_var aGeomVar;
301 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
302 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
304 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
307 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
308 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
309 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
311 if ( !aGeomVar->_is_nil() ) {
313 switch ( aGeomVar->GetShapeType() ) {
315 case GEOM::SHELL: shapeDim = 3; break;
316 case GEOM::FACE: shapeDim = 2; break;
318 case GEOM::EDGE: shapeDim = 1; break;
319 case GEOM::VERTEX: shapeDim = 0; break;
322 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
323 TopExp_Explorer exp( aShape, TopAbs_SHELL );
326 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
328 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
336 catch ( const SALOME::SALOME_Exception& S_ex )
338 SalomeApp_Tools::QtCatchCorbaException( S_ex );
343 myDlg->setMaxHypoDim( shapeDim );
346 //================================================================================
348 * \brief Verifies validity of input data
349 * \param theMess - Output parameter intended for returning error message
350 * \retval bool - TRUE if input data is valid, false otherwise
352 * Verifies validity of input data. This method is called when "Apply" or "OK" button
353 * is pressed before mesh creation or editing.
355 //================================================================================
356 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
358 // Selected object to be edited
359 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
361 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
366 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
367 aMeshName = aMeshName.stripWhiteSpace();
368 if ( aMeshName == "" )
370 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
377 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
378 if ( aGeomEntry == "" )
380 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
383 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
384 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
386 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
391 if ( !myIsMesh ) // i.e sub-mesh creation,
393 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
394 if ( aMeshEntry == "" )
396 theMess = tr( "MESH_IS_NOT_DEFINED" );
399 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
400 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
402 theMess = tr( "MESH_IS_NULL" );
410 //================================================================================
412 * \brief Gets available hypotheses or algorithms
413 * \param theDim - specifies dimension of returned hypotheses/algorifms
414 * \param theHypType - specifies whether algorims or hypotheses or additional ones
415 * are retrieved (possible values are in HypType enumeration)
416 * \param theHyps - Output list of hypotheses' names
418 * Gets available hypotheses or algorithm in accordance with input parameters
420 //================================================================================
421 void SMESHGUI_MeshOp::availableHyps( const int theDim,
422 const int theHypType,
423 QStringList& theHyps ) const
426 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
427 theHypType == Algo , theDim, theHypType == AddHyp );
428 QStringList::const_iterator anIter;
429 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
431 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
432 theHyps.append( aData->Label );
436 //================================================================================
438 * \brief Gets existing hypotheses or algorithms
439 * \param theDim - specifies dimension of returned hypotheses/algorifms
440 * \param theHypType - specifies whether algorims or hypotheses or additional ones
441 * are retrieved (possible values are in HypType enumeration)
442 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
443 * \param theHyps - output list of names.
444 * \param theHypVars - output list of variables.
446 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
449 //================================================================================
450 void SMESHGUI_MeshOp::existingHyps( const int theDim,
451 const int theHypType,
452 _PTR(SObject) theFather,
453 QStringList& theHyps,
454 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
456 // Clear hypoheses list
463 _PTR(SObject) aHypRoot;
464 _PTR(GenericAttribute) anAttr;
465 _PTR(AttributeName) aName;
466 _PTR(AttributeIOR) anIOR;
468 bool isMesh = !_CAST( SComponent, theFather );
471 aPart = theHypType == Algo ? 3 : 2;
473 aPart = theHypType == Algo ? 2 : 1;
475 if ( theFather->FindSubObject( aPart, aHypRoot ) )
477 _PTR(ChildIterator) anIter =
478 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
479 for (; anIter->More(); anIter->Next() )
481 _PTR(SObject) anObj = anIter->Value();
482 if ( isMesh ) // i.e. mesh or submesh
484 _PTR(SObject) aRefObj;
485 if ( anObj->ReferencedObject( aRefObj ) )
490 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
493 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
494 if ( !CORBA::is_nil( aVar ) )
496 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
497 if ( !aHypVar->_is_nil() )
499 QString aHypType( aHypVar->GetName() );
500 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
501 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
502 ( theHypType == AddHyp ) == aData->IsAux )
504 theHyps.append( aName->Value().c_str() );
505 theHypVars.append( aHypVar );
514 //================================================================================
516 * \brief Calls plugin methods for hypothesis creation
517 * \param theHypType - specifies whether main hypotheses or additional ones
519 * \param theIndex - index of type of hypothesis to be cerated
521 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
522 * its type and calls plugin methods for hypothesis creation
524 //================================================================================
525 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
527 // Speicfies dimension of hypothesis to be created
528 const QObject* aSender = sender();
530 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
531 if ( aSender == myDlg->tab( i ) )
536 // Speicfies type of hypothesis to be created
537 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
538 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
541 QString aHypTypeName = aHypTypeNames[ theIndex ];
542 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
546 QString aClientLibName = aData->ClientLibName;
547 QStringList anOldHyps;
548 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
549 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
551 if ( aClientLibName == "" )
553 // Call hypothesis creation server method (without GUI)
554 QString aHypName = aData->Label;
555 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
559 // Get hypotheses creator client (GUI)
560 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
563 aCreator->CreateHypothesis( false, myDlg );
566 QStringList aNewHyps;
567 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
568 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
569 if ( aNewHyps.count() > anOldHyps.count() )
571 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
572 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
576 //================================================================================
578 * \brief Calls plugin methods for hypothesis editing
579 * \param theHypType - specifies whether main hypothesis or additional one
581 * \param theIndex - index of existing hypothesis
583 * Calls plugin methods for hypothesis editing
585 //================================================================================
586 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
588 // Speicfies dimension of hypothesis to be created
589 const QObject* aSender = sender();
591 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
592 if ( aSender == myDlg->tab( i ) )
597 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
598 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
599 if ( aHyp->_is_nil() )
602 char* aTypeName = aHyp->GetName();
603 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
605 aCreator->EditHypothesis( aHyp );
608 //================================================================================
610 * \brief Creates and selects hypothesis of hypotheses set
611 * \param theSetName - The name of hypotheses set
613 //================================================================================
615 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
617 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
618 if ( !aHypoSet ) return;
620 for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
622 bool isAlgo = (aHypType == Algo);
625 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
626 setCurrentHyp( dim, aHypType, -1 );
628 // set hyps from the set
630 QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
631 for ( int i = 0, n = aHypoList->count(); i < n; i++ )
633 const QString& aHypoTypeName = (*aHypoList)[ i ];
634 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
635 if ( !aHypData ) continue;
636 int aDim = aHypData->Dim[0];
641 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
642 index = aHypTypeNameList.findIndex( aHypoTypeName );
643 if ( index < 0 ) continue;
644 setCurrentHyp ( aDim, aHypType, index );
648 // try to find an existing hypo
649 QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
650 int iHyp = 0, nbHyp = aList.count();
651 for ( ; iHyp < nbHyp; ++iHyp )
653 SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
654 if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
659 if ( index >= 0 ) // found
661 // select an algorithm
662 setCurrentHyp ( aDim, aHypType, index );
666 // create a hypothesis
667 QString aClientLibName = aHypData->ClientLibName;
668 if ( aClientLibName == "" ) {
669 // Call hypothesis creation server method (without GUI)
670 SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
673 // Get hypotheses creator client (GUI)
674 SMESHGUI_GenericHypothesisCreator* aCreator =
675 SMESH::GetHypothesisCreator( aHypoTypeName );
676 aCreator->CreateHypothesis( false, myDlg );
678 QStringList aNewHyps;
679 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
680 existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
681 if ( aList.count() > nbHyp )
683 for ( int i = nbHyp; i < aNewHyps.count(); i++ )
684 myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
688 } // loop on hypos in the set
689 } // loop on algo/hypo
692 //================================================================================
694 * \brief Creates mesh
695 * \param theMess - Output parameter intended for returning error message
696 * \retval bool - TRUE if mesh is created, FALSE otherwise
700 //================================================================================
701 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
705 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
706 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
707 GEOM::GEOM_Object_var aGeomVar =
708 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
710 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
711 if ( aSMESHGen->_is_nil() )
714 SUIT_OverrideCursor aWaitCursor;
717 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
718 if ( aMeshVar->_is_nil() )
720 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
722 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
724 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
726 if ( !isAccessibleDim( aDim )) continue;
729 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
731 int aHypIndex = currentHyp( aDim, aHypType );
732 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
734 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
735 if ( !aHypVar->_is_nil() )
736 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
739 // find or create algorithm
740 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
741 if ( !anAlgoVar->_is_nil() )
742 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
747 //================================================================================
749 * \brief Creates sub-mesh
750 * \param theMess - Output parameter intended for returning error message
751 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
755 //================================================================================
756 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
760 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
761 if ( aSMESHGen->_is_nil() )
765 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
766 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
767 SMESH::SMESH_Mesh_var aMeshVar =
768 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
771 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
772 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
773 GEOM::GEOM_Object_var aGeomVar =
774 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
776 SUIT_OverrideCursor aWaitCursor;
779 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
780 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
782 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
784 if ( !isAccessibleDim( aDim )) continue;
786 // find or create algorithm
787 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
788 if ( !anAlgoVar->_is_nil() )
789 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
791 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
793 int aHypIndex = currentHyp( aDim, aHypType );
794 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
796 SMESH::SMESH_Hypothesis_var aHypVar =
797 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
798 if ( !aHypVar->_is_nil() )
799 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
806 //================================================================================
808 * \brief Gets current hypothesis or algorithms
809 * \param theDim - dimension of hypothesis or algorithm
810 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
811 * \retval int - current hypothesis or algorithms
813 * Gets current hypothesis or algorithms
815 //================================================================================
816 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
818 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
821 //================================================================================
823 * \brief Returns true if hypotheses of given dim can be assigned
824 * \param theDim - hypotheses dimension
825 * \retval bool - result
827 //================================================================================
828 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
830 return myDlg->tab( theDim )->isEnabled();
833 //================================================================================
835 * \brief Sets current hypothesis or algorithms
836 * \param theDim - dimension of hypothesis or algorithm
837 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
838 * \param theIndex - Index of hypothesis
840 * Gets current hypothesis or algorithms
842 //================================================================================
843 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
844 const int theHypType,
847 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
850 //================================================================================
852 * \brief Generates default and sets mesh/submesh name
854 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
856 //================================================================================
857 void SMESHGUI_MeshOp::setDefaultName() const
861 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
863 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
867 aResName = aPrefix + QString::number( i++ );
868 anObj = aStudy->FindObject( aResName.latin1() );
872 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
873 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
874 aControl->setText( aResName );
877 //================================================================================
879 * \brief Gets algorithm or creates it if necessary
880 * \param theDim - specifies dimension of returned hypotheses/algorifms
881 * \retval SMESH::SMESH_Hypothesis_var - algorithm
883 * Gets algorithm or creates it if necessary
885 //================================================================================
886 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
888 SMESH::SMESH_Hypothesis_var anAlgoVar;
889 int aHypIndex = currentHyp( theDim, Algo );
890 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
891 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
893 QString aHypName = aHypTypeNameList[ aHypIndex ];
894 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
895 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
896 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
898 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
899 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
905 if ( anAlgoVar->_is_nil() )
907 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
910 QString aClientLibName = aHypData->ClientLibName;
911 if ( aClientLibName == "" )
912 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
915 SMESHGUI_GenericHypothesisCreator* aCreator =
916 SMESH::GetHypothesisCreator( aHypName );
918 aCreator->CreateHypothesis( true, myDlg );
921 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
922 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
925 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
926 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
928 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
929 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
937 return anAlgoVar._retn();
940 //================================================================================
942 * \brief Reads parameters of edited mesh and assigns them to the dialog
944 * Reads parameters of edited mesh and assigns them to the dialog (called when
945 * mesh is edited only)
947 //================================================================================
948 void SMESHGUI_MeshOp::readMesh()
950 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
951 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
955 // Get name of mesh if current object is sub-mesh
956 SMESH::SMESH_subMesh_var aSubMeshVar =
957 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
958 if ( !aSubMeshVar->_is_nil() )
960 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
961 if ( !aMeshVar->_is_nil() )
963 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
964 QString aMeshName = name( aMeshSO );
965 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
969 // Get name of geometry object
970 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
971 if ( !aGeomVar->_is_nil() )
973 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
974 QString aShapeName = name( aGeomSO );
975 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
978 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
979 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
982 QStringList anExisting;
984 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
985 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
987 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
988 QString aHypTypeName = aVar->GetName();
990 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
991 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
992 if ( aHypTypeName == aHypTypeNameList[ i ] )
998 setCurrentHyp( dim, Algo, aHypIndex );
1001 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1004 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1005 // find index of requered hypothesis among existing ones for this dimension
1008 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1009 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1010 myExistingHyps[ dim ][ hypType ] );
1011 setCurrentHyp( dim, hypType, aHypIndex );
1016 //================================================================================
1018 * \brief Gets name of object
1019 * \param theSO - SObject
1020 * \retval QString - name of object
1022 * Gets name of object
1024 //================================================================================
1025 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1030 _PTR(GenericAttribute) anAttr;
1031 _PTR(AttributeName) aNameAttr;
1032 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1035 aResName = aNameAttr->Value().c_str();
1041 //================================================================================
1043 * \brief Finds hypothesis in input list
1044 * \param theHyp - hypothesis to be found
1045 * \param theHypList - input list of hypotheses
1046 * \retval int - index of hypothesis or -1 if it is not found
1048 * Finds position of hypothesis in input list
1050 //================================================================================
1051 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1052 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1055 if ( !theHyp->_is_nil() )
1058 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1059 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1061 if ( theHyp->_is_equivalent( *anIter ) )
1072 //================================================================================
1074 * \brief Edits mesh or sub-mesh
1075 * \param theMess - Output parameter intended for returning error message
1076 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1078 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1080 //================================================================================
1081 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1085 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1086 if ( aSMESHGen->_is_nil() )
1089 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1090 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1094 SUIT_OverrideCursor aWaitCursor;
1097 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1099 // Assign new hypotheses and algorithms
1100 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1102 if ( !isAccessibleDim( dim )) continue;
1104 // find or create algorithm
1105 bool toDelete = false, toAdd = true;
1106 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1107 if ( anAlgoVar->_is_nil() ) {
1110 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1111 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1113 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1122 // remove old algorithm
1124 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1125 ( pObj, myObjHyps[ dim ][ Algo ].first() );
1127 // assign new algorithm
1129 SMESH::SMESH_Mesh_var aMeshVar =
1130 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1131 bool isMesh = !aMeshVar->_is_nil();
1133 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1135 SMESH::SMESH_subMesh_var aVar =
1136 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1137 if ( !aVar->_is_nil() )
1138 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1142 // assign hypotheses
1143 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1145 int aNewHypIndex = currentHyp( dim, hypType );
1146 int anOldHypIndex = -1;
1147 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1148 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1149 myExistingHyps[ dim ][ hypType ] );
1150 if ( aNewHypIndex != anOldHypIndex )
1152 // remove old hypotheses
1153 if ( anOldHypIndex >= 0 )
1154 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1155 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1157 // assign new hypotheses
1158 if ( aNewHypIndex != -1 )
1160 SMESH::SMESH_Mesh_var aMeshVar =
1161 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1162 bool isMesh = !aMeshVar->_is_nil();
1165 SMESH::AddHypothesisOnMesh(
1166 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1170 SMESH::SMESH_subMesh_var aVar =
1171 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1172 if ( !aVar->_is_nil() )
1173 SMESH::AddHypothesisOnSubMesh(
1174 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1177 // reread all hypotheses of mesh if necessary
1178 QStringList anExisting;
1179 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1187 //================================================================================
1189 * \brief Verifies whether given operator is valid for this one
1190 * \param theOtherOp - other operation
1191 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1193 * method redefined from base class verifies whether given operator is valid for
1194 * this one (i.e. can be started "above" this operator). In current implementation method
1195 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1198 //================================================================================
1199 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1201 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );