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>
34 #include <SalomeApp_SelectionMgr.h>
35 #include <SalomeApp_UpdateFlags.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_OverrideCursor.h>
40 #include <utilities.h>
42 #include <qstringlist.h>
43 #include <qlineedit.h>
45 #include <SALOMEDS_SObject.hxx>
49 //================================================================================
52 * \param theToCreate - if this parameter is true then operation is used for creation,
53 * for editing otherwise
55 * Initialize operation
57 //================================================================================
58 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
59 : SMESHGUI_SelectionOp(),
60 myToCreate( theToCreate ),
61 myIsMesh( theIsMesh ),
66 //================================================================================
70 //================================================================================
71 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
77 //================================================================================
79 * \brief Gets dialog of this operation
80 * \retval SalomeApp_Dialog* - pointer to dialog of this operation
82 //================================================================================
83 SalomeApp_Dialog* SMESHGUI_MeshOp::dlg() const
88 //================================================================================
90 * \brief Creates or edits mesh
91 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
93 * Virtual slot redefined from the base class called when "Apply" button is clicked
94 * creates or edits mesh
96 //================================================================================
97 bool SMESHGUI_MeshOp::onApply()
103 if ( !isValid( aMess ) )
106 SUIT_MessageBox::warn1( myDlg,
107 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
111 bool aResult = false;
115 if ( myToCreate && myIsMesh )
116 aResult = createMesh( aMess );
117 if ( myToCreate && !myIsMesh )
118 aResult = createSubMesh( aMess );
119 else if ( !myToCreate )
120 aResult = editMeshOrSubMesh( aMess );
122 update( UF_ObjBrowser | UF_Model );
124 catch ( const SALOME::SALOME_Exception& S_ex )
126 SalomeApp_Tools::QtCatchCorbaException( S_ex );
142 aMess = tr( "SMESH_OPERATION_FAILED" );
143 SUIT_MessageBox::warn1( myDlg,
144 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
150 //================================================================================
152 * \brief Creates dialog if necessary and shows it
154 * Virtual method redefined from base class called when operation is started creates
155 * dialog if necessary and shows it, activates selection
157 //================================================================================
158 void SMESHGUI_MeshOp::startOperation()
162 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
163 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
165 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
166 this, SLOT( onCreateHyp( const int, const int) ) );
167 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
168 this, SLOT( onEditHyp( const int, const int) ) );
171 SMESHGUI_SelectionOp::startOperation();
173 // iterate through dimensions and get available and existing algoritms and hypotheses,
174 // set them to the dialog
176 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
177 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
179 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
180 QStringList anAvailable, anExisting;
181 for ( j = Algo; j <= AddHyp; j++ )
183 availableHyps( i, j, anAvailable );
184 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
186 aTab->setAvailableHyps( j, anAvailable );
187 aTab->setExistingHyps( j, anExisting );
193 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
196 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
200 myDlg->setCurrentTab( SMESH::DIM_1D );
204 //================================================================================
206 * \brief Creates selection filter
207 * \param theId - identifier of current selection widget
208 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
210 * Creates selection filter in accordance with identifier of current selection widget
212 //================================================================================
213 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
215 if ( theId == SMESHGUI_MeshDlg::Geom )
217 // TColStd_MapOfInteger allTypesMap;
218 // for ( int i = 0; i < 10; i++ )
219 // allTypesMap.Add( i );
220 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
221 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
223 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
224 return new SMESH_TypeFilter( MESHorSUBMESH );
225 else if ( theId == SMESHGUI_MeshDlg::Mesh )
226 return new SMESH_TypeFilter( MESH );
231 //================================================================================
233 * \brief Updates dialog's look and feel
235 * Virtual method redefined from the base class updates dialog's look and feel
237 //================================================================================
238 void SMESHGUI_MeshOp::selectionDone()
240 SMESHGUI_SelectionOp::selectionDone();
246 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
247 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry );
250 SMESH::SMESH_subMesh_var aVar =
251 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
252 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
253 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
254 myDlg->updateGeometry();
261 catch ( const SALOME::SALOME_Exception& S_ex )
263 SalomeApp_Tools::QtCatchCorbaException( S_ex );
271 //================================================================================
273 * \brief Verifies validity of input data
274 * \param theMess - Output parameter intended for returning error message
275 * \retval bool - TRUE if input data is valid, false otherwise
277 * Verifies validity of input data. This method is called when "Apply" or "OK" button
278 * is pressed before mesh creation or editing.
280 //================================================================================
281 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
283 // Selected object to be edited
284 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
286 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
291 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
292 aMeshName = aMeshName.stripWhiteSpace();
293 if ( aMeshName == "" )
295 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
302 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
303 if ( aGeomEntry == "" )
305 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
308 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry );
309 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
311 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
316 if ( !myIsMesh ) // i.e sub-mesh creation,
318 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
319 if ( aMeshEntry == "" )
321 theMess = tr( "MESH_IS_NOT_DEFINED" );
324 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry );
325 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
327 theMess = tr( "MESH_IS_NULL" );
335 //================================================================================
337 * \brief Gets available hypotheses or algorithms
338 * \param theDim - specifies dimension of returned hypotheses/algorifms
339 * \param theHypType - specifies whether algorims or hypotheses or additional ones
340 * are retrieved (possible values are in HypType enumeration)
341 * \param theHyps - Output list of hypotheses' names
343 * Gets available hypotheses or algorithm in accordance with input parameters
345 //================================================================================
346 void SMESHGUI_MeshOp::availableHyps( const int theDim,
347 const int theHypType,
348 QStringList& theHyps ) const
351 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
352 theHypType == Algo , theDim, theHypType == AddHyp );
353 QStringList::const_iterator anIter;
354 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
356 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
357 theHyps.append( aData->Label );
361 //================================================================================
363 * \brief Gets existing hypotheses or algorithms
364 * \param theDim - specifies dimension of returned hypotheses/algorifms
365 * \param theHypType - specifies whether algorims or hypotheses or additional ones
366 * are retrieved (possible values are in HypType enumeration)
367 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
368 * \param theHyps - output list of names.
369 * \param theHypVars - output list of variables.
371 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
374 //================================================================================
375 void SMESHGUI_MeshOp::existingHyps( const int theDim,
376 const int theHypType,
377 _PTR(SObject) theFather,
378 QStringList& theHyps,
379 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
381 // Clear hypoheses list
388 _PTR(SObject) aHypRoot;
389 _PTR(GenericAttribute) anAttr;
390 _PTR(AttributeName) aName;
391 _PTR(AttributeIOR) anIOR;
393 bool isMesh = !_CAST( SComponent, theFather );
396 aPart = theHypType == Algo ? 3 : 2;
398 aPart = theHypType == Algo ? 2 : 1;
400 if ( theFather->FindSubObject( aPart, aHypRoot ) )
402 _PTR(ChildIterator) anIter =
403 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
404 for (; anIter->More(); anIter->Next() )
406 _PTR(SObject) anObj = anIter->Value();
407 if ( isMesh ) // i.e. mesh or submesh
409 _PTR(SObject) aRefObj;
410 if ( anObj->ReferencedObject( aRefObj ) )
415 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
418 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
419 if ( !CORBA::is_nil( aVar ) )
421 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
422 if ( !aHypVar->_is_nil() )
424 QString aHypType( aHypVar->GetName() );
425 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
426 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
427 ( theHypType == AddHyp ) == aData->IsAux )
429 theHyps.append( aName->Value().c_str() );
430 theHypVars.append( aHypVar );
439 //================================================================================
441 * \brief Calls plugin methods for hypothesis creation
442 * \param theHypType - specifies whether main hypotheses or additional ones
444 * \param theIndex - index of type of hypothesis to be cerated
446 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
447 * its type and calls plugin methods for hypothesis creation
449 //================================================================================
450 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
452 // Speicfies dimension of hypothesis to be created
453 const QObject* aSender = sender();
455 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
456 if ( aSender == myDlg->tab( i ) )
461 // Speicfies type of hypothesis to be created
462 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
463 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
466 QString aHypTypeName = aHypTypeNames[ theIndex ];
467 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
471 QString aClientLibName = aData->ClientLibName;
472 QStringList anOldHyps;
473 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
474 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
476 if ( aClientLibName == "" )
478 // Call hypothesis creation server method (without GUI)
479 QString aHypName = aData->Label;
480 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
484 // Get hypotheses creator client (GUI)
485 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
488 aCreator->CreateHypothesis( false, myDlg );
491 QStringList aNewHyps;
492 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
493 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
494 if ( aNewHyps.count() > anOldHyps.count() )
496 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
497 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
501 //================================================================================
503 * \brief Calls plugin methods for hypothesis editing
504 * \param theHypType - specifies whether main hypothesis or additional one
506 * \param theIndex - index of existing hypothesis
508 * Calls plugin methods for hypothesis editing
510 //================================================================================
511 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
513 // Speicfies dimension of hypothesis to be created
514 const QObject* aSender = sender();
516 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
517 if ( aSender == myDlg->tab( i ) )
522 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
523 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
524 if ( aHyp->_is_nil() )
527 char* aTypeName = aHyp->GetName();
528 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
530 aCreator->EditHypothesis( aHyp );
533 //================================================================================
535 * \brief Creates mesh
536 * \param theMess - Output parameter intended for returning error message
537 * \retval bool - TRUE if mesh is created, FALSE otherwise
541 //================================================================================
542 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
546 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
547 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry );
548 GEOM::GEOM_Object_var aGeomVar =
549 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
551 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
552 if ( aSMESHGen->_is_nil() )
555 SUIT_OverrideCursor aWaitCursor;
558 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
559 if ( aMeshVar->_is_nil() )
561 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
563 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
565 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
568 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
570 int aHypIndex = currentHyp( aDim, aHypType );
571 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
573 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
574 if ( !aHypVar->_is_nil() )
575 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
578 // find or create algorithm
579 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
580 if ( !anAlgoVar->_is_nil() )
581 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
586 //================================================================================
588 * \brief Creates sub-mesh
589 * \param theMess - Output parameter intended for returning error message
590 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
594 //================================================================================
595 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
599 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
600 if ( aSMESHGen->_is_nil() )
604 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
605 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry );
606 SMESH::SMESH_Mesh_var aMeshVar =
607 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
610 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
611 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry );
612 GEOM::GEOM_Object_var aGeomVar =
613 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
615 SUIT_OverrideCursor aWaitCursor;
618 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
619 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
621 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
624 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
626 int aHypIndex = currentHyp( aDim, aHypType );
627 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
629 SMESH::SMESH_Hypothesis_var aHypVar =
630 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
631 if ( !aHypVar->_is_nil() )
632 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
635 // find or create algorithm
636 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
637 if ( !anAlgoVar->_is_nil() )
638 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
643 //================================================================================
645 * \brief Gets current hypothesis or algorithms
646 * \param theDim - dimension of hypothesis or algorithm
647 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
648 * \retval int - current hypothesis or algorithms
650 * Gets current hypothesis or algorithms
652 //================================================================================
653 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
655 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
658 //================================================================================
660 * \brief Sets current hypothesis or algorithms
661 * \param theDim - dimension of hypothesis or algorithm
662 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
663 * \param theIndex - Index of hypothesis
665 * Gets current hypothesis or algorithms
667 //================================================================================
668 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
669 const int theHypType,
672 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
675 //================================================================================
677 * \brief Generates default and sets mesh/submesh name
679 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
681 //================================================================================
682 void SMESHGUI_MeshOp::setDefaultName() const
686 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
688 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
692 aResName = aPrefix + QString::number( i++ );
693 anObj = aStudy->FindObject( aResName.latin1() );
697 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
698 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
699 aControl->setText( aResName );
702 //================================================================================
704 * \brief Gets algorithm or creates it if necessary
705 * \param theDim - specifies dimension of returned hypotheses/algorifms
706 * \retval SMESH::SMESH_Hypothesis_var - algorithm
708 * Gets algorithm or creates it if necessary
710 //================================================================================
711 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
713 SMESH::SMESH_Hypothesis_var anAlgoVar;
714 int aHypIndex = currentHyp( theDim, Algo );
715 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
716 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
718 QString aHypName = aHypTypeNameList[ aHypIndex ];
719 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
720 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
721 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
723 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
724 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
730 if ( anAlgoVar->_is_nil() )
732 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
735 QString aClientLibName = aHypData->ClientLibName;
736 if ( aClientLibName == "" )
737 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
740 SMESHGUI_GenericHypothesisCreator* aCreator =
741 SMESH::GetHypothesisCreator( aHypName );
743 aCreator->CreateHypothesis( true, myDlg );
746 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
747 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
750 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
751 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
753 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
754 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
762 return anAlgoVar._retn();
765 //================================================================================
767 * \brief Reads parameters of edited mesh and assigns them to the dialog
769 * Reads parameters of edited mesh and assigns them to the dialog (called when
770 * mesh is edited only)
772 //================================================================================
773 void SMESHGUI_MeshOp::readMesh()
775 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
776 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry );
780 // Get name of mesh if current object is sub-mesh
781 SMESH::SMESH_subMesh_var aSubMeshVar =
782 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
783 if ( !aSubMeshVar->_is_nil() )
785 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
786 if ( !aMeshVar->_is_nil() )
788 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
789 QString aMeshName = name( aMeshSO );
790 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
794 // Get name of geometry object
795 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
796 if ( !aGeomVar->_is_nil() )
798 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
799 QString aShapeName = name( aGeomSO );
800 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
803 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
804 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
807 QStringList anExisting;
809 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
810 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
812 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
813 QString aHypTypeName = aVar->GetName();
815 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
816 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
817 if ( aHypTypeName == aHypTypeNameList[ i ] )
823 setCurrentHyp( dim, Algo, aHypIndex );
826 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
829 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
830 // find index of requered hypothesis among existing ones for this dimension
833 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
834 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
835 myExistingHyps[ dim ][ hypType ] );
836 setCurrentHyp( dim, hypType, aHypIndex );
841 //================================================================================
843 * \brief Gets name of object
844 * \param theSO - SObject
845 * \retval QString - name of object
847 * Gets name of object
849 //================================================================================
850 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
855 _PTR(GenericAttribute) anAttr;
856 _PTR(AttributeName) aNameAttr;
857 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
860 aResName = aNameAttr->Value().c_str();
866 //================================================================================
868 * \brief Finds hypothesis in input list
869 * \param theHyp - hypothesis to be found
870 * \param theHypList - input list of hypotheses
871 * \retval int - index of hypothesis or -1 if it is not found
873 * Finds position of hypothesis in input list
875 //================================================================================
876 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
877 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
880 if ( !theHyp->_is_nil() )
883 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
884 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
886 if ( theHyp->_is_equivalent( *anIter ) )
897 //================================================================================
899 * \brief Edits mesh or sub-mesh
900 * \param theMess - Output parameter intended for returning error message
901 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
903 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
905 //================================================================================
906 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
910 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
911 if ( aSMESHGen->_is_nil() )
914 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
915 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry );
919 SUIT_OverrideCursor aWaitCursor;
922 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
924 // Assign new hypotheses and algorithms
925 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
927 // create algorithm if necessary
931 for ( int hypType = Algo; hypType <= AddHyp; hypType++ )
933 int aNewHypIndex = currentHyp( dim, hypType );
934 int anOldHypIndex = -1;
935 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
936 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
937 myExistingHyps[ dim ][ hypType ] );
938 if ( aNewHypIndex != anOldHypIndex )
940 // remove old hypotheses
941 if ( anOldHypIndex >= 0 )
942 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
943 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
945 // assign new hypotheses
946 if ( aNewHypIndex != -1 )
948 SMESH::SMESH_Mesh_var aMeshVar =
949 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
950 bool isMesh = !aMeshVar->_is_nil();
953 SMESH::AddHypothesisOnMesh(
954 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
958 SMESH::SMESH_subMesh_var aVar =
959 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
960 if ( !aVar->_is_nil() )
961 SMESH::AddHypothesisOnSubMesh(
962 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
965 // reread all hypotheses of mesh if necessary
966 QStringList anExisting;
967 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
975 //================================================================================
977 * \brief Verifies whether given operator is valid for this one
978 * \param theOtherOp - other operation
979 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
981 * Virtual method redefined from base class verifies whether given operator is valid for
982 * this one (i.e. can be started "above" this operator). In current implementation method
983 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
986 //================================================================================
987 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
989 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );