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 <SALOMEDSClient_Study.hxx>
29 #include <SALOMEDSClient_AttributeIOR.hxx>
30 #include <SALOMEDSClient_AttributeName.hxx>
31 #include <SALOMEDS_SComponent.hxx>
33 #include <SalomeApp_SelectionMgr.h>
34 #include <SalomeApp_UpdateFlags.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_OverrideCursor.h>
39 #include <utilities.h>
41 #include <qstringlist.h>
42 #include <qlineedit.h>
44 #include <SALOMEDS_SObject.hxx>
48 //================================================================================
51 * \param theToCreate - if this parameter is true then operation is used for creation,
52 * for editing otherwise
54 * Initialize operation
56 //================================================================================
57 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
58 : SMESHGUI_SelectionOp(),
59 myToCreate( theToCreate ),
60 myIsMesh( theIsMesh ),
65 //================================================================================
69 //================================================================================
70 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
76 //================================================================================
78 * \brief Gets dialog of this operation
79 * \retval SalomeApp_Dialog* - pointer to dialog of this operation
81 //================================================================================
82 SalomeApp_Dialog* SMESHGUI_MeshOp::dlg() const
87 //================================================================================
89 * \brief Creates or edits mesh
90 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
92 * Virtual slot redefined from the base class called when "Apply" button is clicked
93 * creates or edits mesh
95 //================================================================================
96 bool SMESHGUI_MeshOp::onApply()
102 if ( !isValid( aMess ) )
105 SUIT_MessageBox::warn1( myDlg,
106 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
110 bool aResult = false;
112 if ( myToCreate && myIsMesh )
113 aResult = createMesh( aMess );
114 if ( myToCreate && !myIsMesh )
115 aResult = createSubMesh( aMess );
116 else if ( !myToCreate )
117 aResult = editMeshOrSubMesh( aMess );
121 update( UF_ObjBrowser | UF_Model );
123 // set default name if necessary
130 aMess = tr( "SMESH_OPERATION_FAILED" );
131 SUIT_MessageBox::warn1( myDlg,
132 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
138 //================================================================================
140 * \brief Creates dialog if necessary and shows it
142 * Virtual method redefined from base class called when operation is started creates
143 * dialog if necessary and shows it, activates selection
145 //================================================================================
146 void SMESHGUI_MeshOp::startOperation()
150 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
151 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
153 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
154 this, SLOT( onCreateHyp( const int, const int) ) );
155 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
156 this, SLOT( onEditHyp( const int, const int) ) );
159 SMESHGUI_SelectionOp::startOperation();
161 // iterate through dimensions and get available and existing algoritms and hypotheses,
162 // set them to the dialog
164 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
165 for ( i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
167 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
168 QStringList anAvailable, anExisting;
169 for ( j = Algo; j <= AddHyp; j++ )
171 availableHyps( i, j, anAvailable );
172 existingHyps( i, j, aFather, anExisting, myExistingHyps[ i ][ j ] );
174 aTab->setAvailableHyps( j, anAvailable );
175 aTab->setExistingHyps( j, anExisting );
181 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
184 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
188 myDlg->setCurrentTab( SMESH::DIM_1D );
192 //================================================================================
194 * \brief Creates selection filter
195 * \param theId - identifier of current selection widget
196 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
198 * Creates selection filter in accordance with identifier of current selection widget
200 //================================================================================
201 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
203 if ( theId == SMESHGUI_MeshDlg::Geom )
205 // TColStd_MapOfInteger allTypesMap;
206 // for ( int i = 0; i < 10; i++ )
207 // allTypesMap.Add( i );
208 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
209 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
211 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
212 return new SMESH_TypeFilter( MESHorSUBMESH );
213 else if ( theId == SMESHGUI_MeshDlg::Mesh )
214 return new SMESH_TypeFilter( MESH );
219 //================================================================================
221 * \brief Updates dialog's look and feel
223 * Virtual method redefined from the base class updates dialog's look and feel
225 //================================================================================
226 void SMESHGUI_MeshOp::selectionDone()
228 SMESHGUI_SelectionOp::selectionDone();
232 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
233 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry );
236 SMESH::SMESH_subMesh_var aVar =
237 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
238 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
239 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
240 myDlg->updateGeometry();
249 //================================================================================
251 * \brief Verifies validity of input data
252 * \param theMess - Output parameter intended for returning error message
253 * \retval bool - TRUE if input data is valid, false otherwise
255 * Verifies validity of input data. This method is called when "Apply" or "OK" button
256 * is pressed before mesh creation or editing.
258 //================================================================================
259 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
261 // Selected object to be edited
262 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
264 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
269 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
270 aMeshName = aMeshName.stripWhiteSpace();
271 if ( aMeshName == "" )
273 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
280 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
281 if ( aGeomEntry == "" )
283 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
286 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry );
287 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
289 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
294 if ( !myIsMesh ) // i.e sub-mesh creation,
296 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
297 if ( aMeshEntry == "" )
299 theMess = tr( "MESH_IS_NOT_DEFINED" );
302 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry );
303 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
305 theMess = tr( "MESH_IS_NULL" );
313 //================================================================================
315 * \brief Gets available hypotheses or algorithms
316 * \param theDim - specifies dimension of returned hypotheses/algorifms
317 * \param theHypType - specifies whether algorims or hypotheses or additional ones
318 * are retrieved (possible values are in HypType enumeration)
319 * \param theHyps - Output list of hypotheses' names
321 * Gets available hypotheses or algorithm in accordance with input parameters
323 //================================================================================
324 void SMESHGUI_MeshOp::availableHyps( const int theDim,
325 const int theHypType,
326 QStringList& theHyps ) const
329 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses(
330 theHypType == Algo , theDim, theHypType == AddHyp );
331 QStringList::const_iterator anIter;
332 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
334 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
335 theHyps.append( aData->Label );
339 //================================================================================
341 * \brief Gets existing hypotheses or algorithms
342 * \param theDim - specifies dimension of returned hypotheses/algorifms
343 * \param theHypType - specifies whether algorims or hypotheses or additional ones
344 * are retrieved (possible values are in HypType enumeration)
345 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
346 * \param theHyps - output list of names.
347 * \param theHypVars - output list of variables.
349 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
352 //================================================================================
353 void SMESHGUI_MeshOp::existingHyps( const int theDim,
354 const int theHypType,
355 _PTR(SObject) theFather,
356 QStringList& theHyps,
357 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars )
359 // Clear hypoheses list
366 _PTR(SObject) aHypRoot;
367 _PTR(GenericAttribute) anAttr;
368 _PTR(AttributeName) aName;
369 _PTR(AttributeIOR) anIOR;
371 bool isMesh = !_CAST( SComponent, theFather );
374 aPart = theHypType == Algo ? 3 : 2;
376 aPart = theHypType == Algo ? 2 : 1;
378 if ( theFather->FindSubObject( aPart, aHypRoot ) )
380 _PTR(ChildIterator) anIter =
381 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
382 for (; anIter->More(); anIter->Next() )
384 _PTR(SObject) anObj = anIter->Value();
385 if ( isMesh ) // i.e. mesh or submesh
387 _PTR(SObject) aRefObj;
388 if ( anObj->ReferencedObject( aRefObj ) )
393 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
396 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
397 if ( !CORBA::is_nil( aVar ) )
399 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
400 if ( !aHypVar->_is_nil() )
402 QString aHypType( aHypVar->GetName() );
403 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
404 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
405 ( theHypType == AddHyp ) == aData->IsAux )
407 theHyps.append( aName->Value().c_str() );
408 theHypVars.append( aHypVar );
417 //================================================================================
419 * \brief Calls plugin methods for hypothesis creation
420 * \param theHypType - specifies whether main hypotheses or additional ones
422 * \param theIndex - index of type of hypothesis to be cerated
424 * Speicfies dimension of hypothesis to be created (using sender() method), specifies
425 * its type and calls plugin methods for hypothesis creation
427 //================================================================================
428 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
430 // Speicfies dimension of hypothesis to be created
431 const QObject* aSender = sender();
433 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
434 if ( aSender == myDlg->tab( i ) )
439 // Speicfies type of hypothesis to be created
440 QStringList aHypTypeNames = SMESH::GetAvailableHypotheses( false , aDim, theHypType == AddHyp );
441 if ( theIndex < 0 || theIndex >= aHypTypeNames.count() )
444 QString aHypTypeName = aHypTypeNames[ theIndex ];
445 HypothesisData* aData = SMESH::GetHypothesisData( aHypTypeName.latin1() );
449 QString aClientLibName = aData->ClientLibName;
450 QStringList anOldHyps;
451 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
452 existingHyps( aDim, theHypType, aFather, anOldHyps, myExistingHyps[ aDim ][ theHypType ] );
454 if ( aClientLibName == "" )
456 // Call hypothesis creation server method (without GUI)
457 QString aHypName = aData->Label;
458 SMESH::CreateHypothesis( aHypTypeName, aHypName, false );
462 // Get hypotheses creator client (GUI)
463 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName );
466 aCreator->CreateHypothesis( false, myDlg );
469 QStringList aNewHyps;
470 aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
471 existingHyps( aDim, theHypType, aFather, aNewHyps, myExistingHyps[ aDim ][ theHypType ] );
472 if ( aNewHyps.count() > anOldHyps.count() )
474 for ( int i = anOldHyps.count(); i < aNewHyps.count(); i++ )
475 myDlg->tab( aDim )->addHyp( theHypType, aNewHyps[ i ] );
479 //================================================================================
481 * \brief Calls plugin methods for hypothesis editing
482 * \param theHypType - specifies whether main hypothesis or additional one
484 * \param theIndex - index of existing hypothesis
486 * Calls plugin methods for hypothesis editing
488 //================================================================================
489 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
491 // Speicfies dimension of hypothesis to be created
492 const QObject* aSender = sender();
494 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
495 if ( aSender == myDlg->tab( i ) )
500 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
501 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex - 1 ];
502 if ( aHyp->_is_nil() )
505 char* aTypeName = aHyp->GetName();
506 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
508 aCreator->EditHypothesis( aHyp );
511 //================================================================================
513 * \brief Creates mesh
514 * \param theMess - Output parameter intended for returning error message
515 * \retval bool - TRUE if mesh is created, FALSE otherwise
519 //================================================================================
520 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
524 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
525 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry );
526 GEOM::GEOM_Object_var aGeomVar =
527 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
529 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
530 if ( aSMESHGen->_is_nil() )
533 SUIT_OverrideCursor aWaitCursor;
536 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
537 if ( aMeshVar->_is_nil() )
539 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
541 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
543 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
546 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
548 int aHypIndex = currentHyp( aDim, aHypType );
549 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
551 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
552 if ( !aHypVar->_is_nil() )
553 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
556 // find or create algorithm
557 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
558 if ( !anAlgoVar->_is_nil() )
559 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
564 //================================================================================
566 * \brief Creates sub-mesh
567 * \param theMess - Output parameter intended for returning error message
568 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
572 //================================================================================
573 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
577 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
578 if ( aSMESHGen->_is_nil() )
582 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
583 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry );
584 SMESH::SMESH_Mesh_var aMeshVar =
585 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
588 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
589 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry );
590 GEOM::GEOM_Object_var aGeomVar =
591 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
593 SUIT_OverrideCursor aWaitCursor;
596 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
597 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
599 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
602 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
604 int aHypIndex = currentHyp( aDim, aHypType );
605 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
607 SMESH::SMESH_Hypothesis_var aHypVar =
608 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
609 if ( !aHypVar->_is_nil() )
610 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
613 // find or create algorithm
614 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
615 if ( !anAlgoVar->_is_nil() )
616 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
621 //================================================================================
623 * \brief Gets current hypothesis or algorithms
624 * \param theDim - dimension of hypothesis or algorithm
625 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
626 * \retval int - current hypothesis or algorithms
628 * Gets current hypothesis or algorithms
630 //================================================================================
631 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
633 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
636 //================================================================================
638 * \brief Sets current hypothesis or algorithms
639 * \param theDim - dimension of hypothesis or algorithm
640 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
641 * \param theIndex - Index of hypothesis
643 * Gets current hypothesis or algorithms
645 //================================================================================
646 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
647 const int theHypType,
650 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
653 //================================================================================
655 * \brief Generates default and sets mesh/submesh name
657 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
659 //================================================================================
660 void SMESHGUI_MeshOp::setDefaultName() const
664 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
666 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
670 aResName = aPrefix + QString::number( i++ );
671 anObj = aStudy->FindObject( aResName.latin1() );
675 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
676 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
677 aControl->setText( aResName );
680 //================================================================================
682 * \brief Gets algorithm or creates it if necessary
683 * \param theDim - specifies dimension of returned hypotheses/algorifms
684 * \retval SMESH::SMESH_Hypothesis_var - algorithm
686 * Gets algorithm or creates it if necessary
688 //================================================================================
689 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
691 SMESH::SMESH_Hypothesis_var anAlgoVar;
692 int aHypIndex = currentHyp( theDim, Algo );
693 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true, theDim, false );
694 if ( aHypIndex < 0 || aHypIndex >= aHypTypeNameList.count() )
696 QString aHypName = aHypTypeNameList[ aHypIndex ];
697 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
698 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
699 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
701 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
702 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
708 if ( anAlgoVar->_is_nil() )
710 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
713 QString aClientLibName = aHypData->ClientLibName;
714 if ( aClientLibName == "" )
715 SMESH::CreateHypothesis( aHypName, aHypData->Label, true );
718 SMESHGUI_GenericHypothesisCreator* aCreator =
719 SMESH::GetHypothesisCreator( aHypName );
721 aCreator->CreateHypothesis( true, myDlg );
724 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
725 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
728 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
729 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
731 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
732 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
740 return anAlgoVar._retn();
743 //================================================================================
745 * \brief Reads parameters of edited mesh and assigns them to the dialog
747 * Reads parameters of edited mesh and assigns them to the dialog (called when
748 * mesh is edited only)
750 //================================================================================
751 void SMESHGUI_MeshOp::readMesh()
753 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
754 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry );
758 // Get name of mesh if current object is sub-mesh
759 SMESH::SMESH_subMesh_var aSubMeshVar =
760 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
761 if ( !aSubMeshVar->_is_nil() )
763 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
764 if ( !aMeshVar->_is_nil() )
766 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
767 QString aMeshName = name( aMeshSO );
768 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
772 // Get name of geometry object
773 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
774 if ( !aGeomVar->_is_nil() )
776 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
777 QString aShapeName = name( aGeomSO );
778 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
781 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
782 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
785 QStringList anExisting;
786 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
787 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
788 QString aHypTypeName = aVar->GetName();
791 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( true , dim, false );
792 for ( int i = 0, n = aHypTypeNameList.count(); i < n; i++ )
793 if ( aHypTypeName == aHypTypeNameList[ i ] )
798 setCurrentHyp( dim, Algo, aHypIndex );
801 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
804 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
805 // find index of requered hypothesis among existing ones for this dimension
808 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
809 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
810 myExistingHyps[ dim ][ hypType ] );
811 setCurrentHyp( dim, hypType, aHypIndex );
816 //================================================================================
818 * \brief Gets name of object
819 * \param theSO - SObject
820 * \retval QString - name of object
822 * Gets name of object
824 //================================================================================
825 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
830 _PTR(GenericAttribute) anAttr;
831 _PTR(AttributeName) aNameAttr;
832 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
835 aResName = aNameAttr->Value().c_str();
841 //================================================================================
843 * \brief Finds hypothesis in input list
844 * \param theHyp - hypothesis to be found
845 * \param theHypList - input list of hypotheses
846 * \retval int - index of hypothesis or -1 if it is not found
848 * Finds position of hypothesis in input list
850 //================================================================================
851 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
852 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
855 if ( !theHyp->_is_nil() )
858 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
859 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
861 if ( theHyp->_is_equivalent( *anIter ) )
872 //================================================================================
874 * \brief Edits mesh or sub-mesh
875 * \param theMess - Output parameter intended for returning error message
876 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
878 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
880 //================================================================================
881 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
885 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
886 if ( aSMESHGen->_is_nil() )
889 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
890 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry );
894 SUIT_OverrideCursor aWaitCursor;
897 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
899 // Assign new hypotheses and algorithms
900 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
902 // create algorithm if necessary
906 for ( int hypType = Algo; hypType <= AddHyp; hypType++ )
908 int aNewHypIndex = currentHyp( dim, hypType );
909 int anOldHypIndex = -1;
910 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
911 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
912 myExistingHyps[ dim ][ hypType ] );
913 if ( aNewHypIndex != anOldHypIndex )
915 // remove old hypotheses
916 if ( anOldHypIndex >= 0 )
917 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
918 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
920 // assign new hypotheses
921 if ( aNewHypIndex != -1 )
925 SMESH::SMESH_Mesh_var aVar =
926 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
927 if ( !aVar->_is_nil() )
928 SMESH::AddHypothesisOnMesh(
929 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
933 SMESH::SMESH_subMesh_var aVar =
934 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
935 if ( !aVar->_is_nil() )
936 SMESH::AddHypothesisOnSubMesh(
937 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
940 // reread all hypotheses of mesh if necessary
941 QStringList anExisting;
942 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
950 //================================================================================
952 * \brief Verifies whether given operator is valid for this one
953 * \param theOtherOp - other operation
954 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
956 * Virtual method redefined from base class verifies whether given operator is valid for
957 * this one (i.e. can be started "above" this operator). In current implementation method
958 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
961 //================================================================================
962 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
964 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );