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/ or email : webmaster.salome@opencascade.com
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 "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESH_TypeFilter.hxx"
38 #include "SMESHGUI_HypothesesUtils.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
41 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESHGUI_VTKUtils.h"
44 #include "SMESH_TypeFilter.hxx"
45 #include "SMESH_NumberFilter.hxx"
47 #include "GEOM_SelectionFilter.h"
49 #include "GeometryGUI.h"
51 #include "SalomeApp_Tools.h"
52 #include "SalomeApp_Application.h"
53 #include "SALOMEDSClient_Study.hxx"
54 #include "SALOMEDSClient_AttributeIOR.hxx"
55 #include "SALOMEDSClient_AttributeName.hxx"
56 #include "SALOMEDS_SComponent.hxx"
57 #include "SALOMEDS_SObject.hxx"
59 #include "LightApp_SelectionMgr.h"
60 #include "LightApp_UpdateFlags.h"
61 #include "SUIT_MessageBox.h"
62 #include "SUIT_Desktop.h"
63 #include "SUIT_OverrideCursor.h"
64 #include "SALOME_InteractiveObject.hxx"
65 #include "SALOME_ListIO.hxx"
67 #include "utilities.h"
69 #include <qstringlist.h>
70 #include <qlineedit.h>
72 #include <TopoDS_Shape.hxx>
73 #include <TopExp_Explorer.hxx>
75 enum { GLOBAL_ALGO_TAG =3,
79 SUBMESH_ON_EDGE_TAG =5,
80 SUBMESH_ON_WIRE_TAG =6,
81 SUBMESH_ON_FACE_TAG =7,
82 SUBMESH_ON_SHELL_TAG =8,
83 SUBMESH_ON_SOLID_TAG =9,
84 SUBMESH_ON_COMPOUND_TAG=10 };
86 //================================================================================
89 * \param theToCreate - if this parameter is true then operation is used for creation,
90 * for editing otherwise
92 * Initialize operation
94 //================================================================================
95 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
96 : SMESHGUI_SelectionOp(),
97 myToCreate( theToCreate ),
98 myIsMesh( theIsMesh ),
102 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
103 GeometryGUI::InitGeomGen();
106 //================================================================================
110 //================================================================================
111 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
117 //================================================================================
119 * \brief Gets dialog of this operation
120 * \retval LightApp_Dialog* - pointer to dialog of this operation
122 //================================================================================
123 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
128 //================================================================================
130 * \brief Creates or edits mesh
131 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
133 * Virtual slot redefined from the base class called when "Apply" button is clicked
134 * creates or edits mesh
136 //================================================================================
137 bool SMESHGUI_MeshOp::onApply()
139 if( isStudyLocked() )
143 if ( !isValid( aMess ) )
147 SUIT_MessageBox::warn1( myDlg,
148 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
152 bool aResult = false;
156 if ( myToCreate && myIsMesh )
157 aResult = createMesh( aMess );
158 if ( myToCreate && !myIsMesh )
159 aResult = createSubMesh( aMess );
160 else if ( !myToCreate )
161 aResult = editMeshOrSubMesh( aMess );
163 update( UF_ObjBrowser | UF_Model );
165 catch ( const SALOME::SALOME_Exception& S_ex )
167 SalomeApp_Tools::QtCatchCorbaException( S_ex );
183 aMess = tr( "SMESH_OPERATION_FAILED" );
184 SUIT_MessageBox::warn1( myDlg,
185 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
191 //================================================================================
193 * \brief Creates dialog if necessary and shows it
195 * Virtual method redefined from base class called when operation is started creates
196 * dialog if necessary and shows it, activates selection
198 //================================================================================
199 void SMESHGUI_MeshOp::startOperation()
203 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
204 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
206 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
207 this, SLOT( onCreateHyp( const int, const int ) ) );
208 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
209 this, SLOT( onEditHyp( const int, const int ) ) );
210 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
211 this, SLOT( onAlgoSelected( const int ) ) );
213 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
214 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
218 else myHelpFileName = "/files/constructing_submeshes.htm";
219 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
221 SMESHGUI_SelectionOp::startOperation();
223 // iterate through dimensions and get available algoritms,
224 // set them to the dialog
225 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
226 for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
228 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
230 // clear available hypotheses
231 aTab->setAvailableHyps( MainHyp, hypList );
232 aTab->setAvailableHyps( AddHyp, hypList );
233 aTab->setExistingHyps( MainHyp, hypList );
234 aTab->setExistingHyps( AddHyp, hypList );
235 myExistingHyps[ i ][ MainHyp ].clear();
236 myExistingHyps[ i ][ AddHyp ].clear();
238 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
239 aTab->setAvailableHyps( Algo, hypList );
244 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
247 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
249 myDlg->setHypoSets( SMESH::GetHypothesesSets() );
251 myDlg->setCurrentTab( SMESH::DIM_3D );
256 myIgnoreAlgoSelection = false;
259 //================================================================================
261 * \brief Creates selection filter
262 * \param theId - identifier of current selection widget
263 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
265 * Creates selection filter in accordance with identifier of current selection widget
267 //================================================================================
268 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
270 if ( theId == SMESHGUI_MeshDlg::Geom )
272 // TColStd_MapOfInteger allTypesMap;
273 // for ( int i = 0; i < 10; i++ )
274 // allTypesMap.Add( i );
275 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
276 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
278 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
279 return new SMESH_TypeFilter( MESHorSUBMESH );
280 else if ( theId == SMESHGUI_MeshDlg::Mesh )
281 return new SMESH_TypeFilter( MESH );
286 //================================================================================
288 * \brief check if selected shape is a subshape of the shape to mesh
289 * \retval bool - check result
291 //================================================================================
293 bool SMESHGUI_MeshOp::isSubshapeOk() const
295 if ( !myToCreate || myIsMesh ) // not submesh creation
299 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
300 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
301 if (!pMesh) return false;
303 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
304 if (mesh->_is_nil()) return false;
306 // main shape of the mesh
307 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
308 if (mainGeom->_is_nil()) return false;
312 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
314 if (aGEOMs.count() > 0) {
315 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
316 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
317 if (geomGen->_is_nil() || !aStudy) return false;
319 GEOM::GEOM_IGroupOperations_var op =
320 geomGen->GetIGroupOperations(aStudy->StudyId());
321 if (op->_is_nil()) return false;
323 // check all selected shapes
324 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
325 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
326 QString aSubGeomEntry = (*aSubShapesIter);
327 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
328 if (!pSubGeom) return false;
330 GEOM::GEOM_Object_var aSubGeomVar =
331 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
332 if (aSubGeomVar->_is_nil()) return false;
334 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
335 if (mainObj->_is_nil() ||
336 string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
344 //================================================================================
346 * \brief find an existing submesh by the selected shape
347 * \retval _PTR(SObject) - the found submesh SObject
349 //================================================================================
351 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
353 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
354 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
355 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
356 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
357 if ( pMesh && pGeom ) {
358 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
359 if ( !geom->_is_nil() ) {
361 switch ( geom->GetShapeType() ) {
362 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
363 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
364 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
365 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
366 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
367 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
370 _PTR(GenericAttribute) anAttr;
371 _PTR(SObject) aSubmeshRoot;
372 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
373 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
375 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
376 for (; smIter->More(); smIter->Next() )
378 _PTR(SObject) aSmObj = smIter->Value();
379 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
381 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
382 for (; anIter1->More(); anIter1->Next()) {
383 _PTR(SObject) pGeom2 = anIter1->Value();
384 if ( pGeom2->ReferencedObject( pGeom2 ) &&
385 pGeom2->GetID() == pGeom->GetID() )
392 return _PTR(SObject)();
395 //================================================================================
397 * \brief Updates dialog's look and feel
399 * Virtual method redefined from the base class updates dialog's look and feel
401 //================================================================================
402 void SMESHGUI_MeshOp::selectionDone()
404 if ( !dlg()->isShown() )
407 SMESHGUI_SelectionOp::selectionDone();
411 // Enable tabs according to shape dimension
416 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
417 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
419 if (aGEOMs.count() > 0) {
420 // one or more GEOM shape selected
421 aSeq->length(aGEOMs.count());
422 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
424 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
425 QString aSubGeomEntry = (*aSubShapesIter);
426 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
427 GEOM::GEOM_Object_var aSubGeomVar =
428 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
429 aSeq[iSubSh] = aSubGeomVar;
432 // get geometry by selected sub-mesh
433 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
434 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
435 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
436 if (!aGeomVar->_is_nil()) {
442 if (aSeq->length() > 0) {
444 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
445 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
446 switch ( aGeomVar->GetShapeType() ) {
448 case GEOM::SHELL: shapeDim = 3; break;
449 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
451 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
452 case GEOM::VERTEX: break;
455 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
456 TopExp_Explorer exp( aShape, TopAbs_SHELL );
459 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
460 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
461 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
462 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
469 myDlg->setMaxHypoDim( shapeDim );
472 if ( !myToCreate ) // edition: read hypotheses
474 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
475 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
478 SMESH::SMESH_subMesh_var aVar =
479 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
480 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
481 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
482 myDlg->updateGeometry();
490 else if ( !myIsMesh ) // submesh creation
492 // if a submesh on the selected shape already exist, pass to submesh edition mode
493 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
494 SMESH::SMESH_subMesh_var sm =
495 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
496 bool editSubmesh = ( !sm->_is_nil() &&
497 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
498 tr( "EDIT_SUBMESH_QUESTION"),
499 tr( "SMESH_BUT_YES" ),
500 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
503 selectionMgr()->clearFilters();
504 selectObject( pSubmesh );
505 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
510 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
511 selectObject( _PTR(SObject)() );
516 // enable/disable popup for choice of geom selection way
518 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
519 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
520 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
521 if ( !mesh->_is_nil() )
522 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
524 myDlg->setGeomPopupEnabled( enable );
527 catch ( const SALOME::SALOME_Exception& S_ex )
529 SalomeApp_Tools::QtCatchCorbaException( S_ex );
536 //================================================================================
538 * \brief Verifies validity of input data
539 * \param theMess - Output parameter intended for returning error message
540 * \retval bool - TRUE if input data is valid, false otherwise
542 * Verifies validity of input data. This method is called when "Apply" or "OK" button
543 * is pressed before mesh creation or editing.
545 //================================================================================
546 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
548 // Selected object to be edited
549 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
551 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
556 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
557 aMeshName = aMeshName.stripWhiteSpace();
558 if ( aMeshName == "" )
560 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
564 // Imported mesh, if create sub-mesh or edit mesh
565 if ( !myToCreate || ( myToCreate && !myIsMesh ))
567 QString aMeshEntry = myDlg->selectedObject
568 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
569 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
570 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
571 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
572 theMess = tr( "IMPORTED_MESH" );
581 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
582 if ( aGeomEntry == "" )
584 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
587 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
588 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
590 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
595 if ( !myIsMesh ) // i.e sub-mesh creation,
597 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
598 if ( aMeshEntry == "" )
600 theMess = tr( "MESH_IS_NOT_DEFINED" );
603 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
604 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
606 theMess = tr( "MESH_IS_NULL" );
609 if ( !isSubshapeOk() )
611 theMess = tr( "INVALID_SUBSHAPE" );
620 //================================================================================
622 * \brief check compatibility of the algorithm and another algorithm or hypothesis
623 * \param theAlgoData - algorithm data
624 * \param theHypData - hypothesis data
625 * \param theHypType - hypothesis type
626 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
627 * \retval bool - check result
629 //================================================================================
631 static bool isCompatible(const HypothesisData* theAlgoData,
632 const HypothesisData* theHypData,
633 const int theHypType)
638 if ( theHypType == SMESHGUI_MeshOp::Algo )
639 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
642 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
645 //================================================================================
647 * \brief Gets available hypotheses or algorithms
648 * \param theDim - specifies dimension of returned hypotheses/algorifms
649 * \param theHypType - specifies whether algorims or hypotheses or additional ones
650 * are retrieved (possible values are in HypType enumeration)
651 * \param theHyps - Output list of hypotheses' names
652 * \param theAlgoData - to select hypos able to be used by this algo (optional)
654 * Gets available hypotheses or algorithm in accordance with input parameters
656 //================================================================================
657 void SMESHGUI_MeshOp::availableHyps( const int theDim,
658 const int theHypType,
659 QStringList& theHyps,
660 THypDataList& theDataList,
661 HypothesisData* theAlgoData ) const
665 bool isAlgo = ( theHypType == Algo );
666 bool isAux = ( theHypType == AddHyp );
667 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
669 QStringList::const_iterator anIter;
670 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
672 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
673 if ( isCompatible ( theAlgoData, aData, theHypType )) {
674 theDataList.append( aData );
675 theHyps.append( aData->Label );
680 //================================================================================
682 * \brief Gets existing hypotheses or algorithms
683 * \param theDim - specifies dimension of returned hypotheses/algorifms
684 * \param theHypType - specifies whether algorims or hypotheses or additional ones
685 * are retrieved (possible values are in HypType enumeration)
686 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
687 * \param theDataList - output list of hypotheses data
688 * \param theHyps - output list of names.
689 * \param theHypVars - output list of variables.
690 * \param theAlgoData - to select hypos able to be used by this algo (optional)
692 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
695 //================================================================================
696 void SMESHGUI_MeshOp::existingHyps( const int theDim,
697 const int theHypType,
698 _PTR(SObject) theFather,
699 QStringList& theHyps,
700 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
701 HypothesisData* theAlgoData)
703 // Clear hypoheses list
710 const bool isAux = ( theHypType == AddHyp );
712 _PTR(SObject) aHypRoot;
713 _PTR(GenericAttribute) anAttr;
714 _PTR(AttributeName) aName;
715 _PTR(AttributeIOR) anIOR;
717 bool isMesh = !_CAST( SComponent, theFather );
720 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
722 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
724 if ( theFather->FindSubObject( aPart, aHypRoot ) )
726 _PTR(ChildIterator) anIter =
727 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
728 for (; anIter->More(); anIter->Next() )
730 _PTR(SObject) anObj = anIter->Value();
731 if ( isMesh ) // i.e. mesh or submesh
733 _PTR(SObject) aRefObj;
734 if ( anObj->ReferencedObject( aRefObj ) )
739 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
742 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
743 if ( !CORBA::is_nil( aVar ) )
745 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
746 if ( !aHypVar->_is_nil() )
748 QString aHypType( aHypVar->GetName() );
749 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
750 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
751 ( isCompatible ( theAlgoData, aData, theHypType )) &&
752 ( isAux == aData->IsAux ))
754 //theDataList.append( aData );
755 theHyps.append( aName->Value().c_str() );
756 theHypVars.append( aHypVar );
765 //================================================================================
767 * \brief If create or edit a submesh, return a hypothesis holding parameters used
769 * \param aHypType - The hypothesis type name
770 * \param aServerLib - Server library name
771 * \param hypData - The structure holding the hypothesis type etc.
772 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
774 //================================================================================
776 SMESH::SMESH_Hypothesis_var
777 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
778 const QString& aServerLib ) const
780 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
781 return SMESH::SMESH_Hypothesis::_nil();
783 const int nbColonsInMeshEntry = 3;
784 bool isSubMesh = myToCreate ?
786 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
790 // get mesh and geom object
791 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
792 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
794 QString anEntry = myDlg->selectedObject
795 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
796 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
798 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
799 if ( myToCreate ) // mesh and geom may be selected
801 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
802 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
803 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
804 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
806 else // edition: sub-mesh may be selected
808 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
809 if ( !sm->_is_nil() ) {
810 aMeshVar = sm->GetFather();
811 aGeomVar = sm->GetSubShape();
816 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
817 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
822 return SMESH::SMESH_Hypothesis::_nil();
825 //================================================================================
827 * \Brief Returns tab dimention
828 * \param tab - the tab in the dlg
829 * \param dlg - my dialogue
830 * \retval int - dimention
832 //================================================================================
834 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
837 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
838 if (tab == dlg->tab(i))
843 //================================================================================
845 * \brief Create hypothesis
846 * \param theHypType - hypothesis category (main or additional)
847 * \param theIndex - index of type of hypothesis to be cerated
849 * Specifies dimension of hypothesis to be created (using sender() method),
850 * specifies its type and calls method for hypothesis creation
852 //================================================================================
853 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
855 // Specifies dimension of hypothesis to be created
856 int aDim = getTabDim( sender(), myDlg );
860 // Specifies type of hypothesis to be created
861 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
862 if (theIndex < 0 || theIndex >= dataList.count())
864 QString aHypTypeName = dataList[ theIndex ]->TypeName;
867 createHypothesis(aDim, theHypType, aHypTypeName);
870 //================================================================================
872 * Create hypothesis and update dialog.
873 * \param theDim - dimension of hypothesis to be created
874 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
875 * \param theTypeName - specifies hypothesis to be created
877 //================================================================================
878 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
880 const QString& theTypeName)
882 // During a hypothesis creation we might need to select some objects.
883 // Main dialog must not update it's own selected objects in this case.
884 dlg()->deactivateAll();
886 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
891 int nbHyp = myExistingHyps[theDim][theType].count();
893 QString aClientLibName = aData->ClientLibName;
894 if (aClientLibName == "") {
895 // Call hypothesis creation server method (without GUI)
896 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
898 // Get hypotheses creator client (GUI)
899 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
903 // When create or edit a submesh, try to initialize a new hypothesis
904 // with values used to mesh a subshape
905 SMESH::SMESH_Hypothesis_var initParamHyp =
906 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
907 aCreator->create(initParamHyp, myDlg);
909 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
913 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
915 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
916 QStringList aNewHyps;
917 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
918 if (aNewHyps.count() > nbHyp) {
919 for (int i = nbHyp; i < aNewHyps.count(); i++)
920 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
924 //================================================================================
926 * \brief Calls plugin methods for hypothesis editing
927 * \param theHypType - specifies whether main hypothesis or additional one
929 * \param theIndex - index of existing hypothesis
931 * Calls plugin methods for hypothesis editing
933 //================================================================================
934 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
936 // Speicfies dimension of hypothesis to be created
937 int aDim = getTabDim( sender(), myDlg );
941 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
942 if ( theIndex < 0 || theIndex >= aList.count() )
944 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
945 if ( aHyp->_is_nil() )
948 char* aTypeName = aHyp->GetName();
949 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
951 aCreator->edit( aHyp.in(), dlg() );
954 //================================================================================
956 * \brief access to hypothesis data
957 * \param theDim - hyp dimension
958 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
959 * \param theIndex - index in the list
960 * \retval HypothesisData* - result data, may be 0
962 //================================================================================
964 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
965 const int theHypType,
968 if ( theDim > -1 && theDim < 3 &&
969 theHypType > -1 && theHypType < NbHypTypes &&
970 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
971 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
975 //================================================================================
977 * \brief Set available algos and hypos according to the selected algorithm
978 * \param theIndex - algorithm index
980 //================================================================================
982 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
985 if ( myIgnoreAlgoSelection )
988 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
992 // find highest available dimension, all algos of this dimension are available for choice
994 for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
995 if (isAccessibleDim( i ))
1000 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1002 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1003 HypothesisData* algoByDim[3];
1004 algoByDim[ aDim ] = algoData;
1006 QStringList anAvailable;
1007 if ( !algoData ) { // all algos becomes available
1008 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1009 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1012 // check that algorithms of other dimentions are compatible with
1015 // 2 loops: backward and forward from algo dimension
1016 for ( int forward = false; forward <= true; ++forward )
1018 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1020 dim = aDim - 1; lastDim = SMESH::DIM_1D; dir = -1;
1022 HypothesisData* prevAlgo = algoData;
1023 bool noCompatible = false;
1024 for ( ; dim * dir <= lastDim * dir ; dim += dir )
1026 if ( !isAccessibleDim( dim ))
1028 if ( noCompatible ) { // the selected algo has no compatible ones
1029 anAvailable.clear();
1030 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1031 myAvailableHypData[dim][Algo].clear();
1032 algoByDim[ dim ] = 0;
1035 // get currently selected algo
1036 int algoIndex = currentHyp( dim, Algo );
1037 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1038 if ( curAlgo ) { // some algo selected
1039 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1042 // set new available algoritms
1043 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1044 HypothesisData* soleCompatible = 0;
1045 if ( anAvailable.count() == 1 )
1046 soleCompatible = myAvailableHypData[dim][Algo][0];
1047 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1048 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1049 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1050 noCompatible = anAvailable.isEmpty();
1052 // restore previously selected algo
1053 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1054 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward )
1055 // select the sole compatible algo
1056 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1057 setCurrentHyp( dim, Algo, algoIndex );
1059 // remember current algo
1060 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1064 // set hypotheses corresponding to the found algoritms
1066 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1068 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1070 if ( !isAccessibleDim( dim ))
1072 for ( int type = MainHyp; type < NbHypTypes; type++ )
1074 myAvailableHypData[ dim ][ type ].clear();
1075 QStringList anAvailable, anExisting;
1077 HypothesisData* curAlgo = algoByDim[ dim ];
1078 int hypIndex = currentHyp( dim, type );
1080 SMESH::SMESH_Hypothesis_var curHyp;
1081 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1082 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1084 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1085 // try to find algo by selected hypothesis in order to keep it selected
1086 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1087 QString curHypType = curHyp->GetName();
1088 if ( !algoDeselectedByUser &&
1089 myObjHyps[ dim ][ type ].count() > 0 &&
1090 curHypType == myObjHyps[ dim ][ type ][ 0 ]->GetName())
1092 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1093 for ( int i = 0 ; i < myAvailableHypData[ dim ][ Algo ].count(); ++i ) {
1094 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1095 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1102 // get hyps compatible with curAlgo
1105 // check if a selected hyp is compatible with the curAlgo
1106 if ( !curHyp->_is_nil() ) {
1107 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1108 if ( !isCompatible( curAlgo, hypData, type ))
1109 curHyp = SMESH::SMESH_Hypothesis::_nil();
1111 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1112 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1114 // set list of hypotheses
1115 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1116 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1118 // set current existing hypothesis
1119 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1120 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1123 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1124 // none is yet selected => select the sole existing if it is not optional
1125 QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1126 bool isOptional = true;
1127 if ( algoByDim[ dim ] &&
1128 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1132 setCurrentHyp( dim, type, hypIndex );
1137 //================================================================================
1139 * \brief Creates and selects hypothesis of hypotheses set
1140 * \param theSetName - The name of hypotheses set
1142 //================================================================================
1143 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1145 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1146 if (!aHypoSet) return;
1149 for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++) {
1150 setCurrentHyp(dim, Algo, -1);
1151 setCurrentHyp(dim, AddHyp, -1);
1152 setCurrentHyp(dim, MainHyp, -1);
1155 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1156 bool isAlgo = (aHypType == Algo);
1158 // set hyps from the set
1159 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1160 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1161 const QString& aHypoTypeName = (*aHypoList)[ i ];
1162 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1166 int aDim = aHypData->Dim[0];
1167 // create or/and set
1169 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1171 QStringList anAvailable;
1172 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1173 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1174 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1176 setCurrentHyp( aDim, Algo, index );
1177 onAlgoSelected( index, aDim );
1180 bool mainHyp = true;
1181 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1184 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1187 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1189 } // loop on hypos in the set
1190 } // loop on algo/hypo
1193 //================================================================================
1195 * \brief Creates mesh
1196 * \param theMess - Output parameter intended for returning error message
1197 * \retval bool - TRUE if mesh is created, FALSE otherwise
1201 //================================================================================
1202 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1206 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1207 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1210 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1211 QStringList::Iterator it = aList.begin();
1212 for(; it!=aList.end(); it++) {
1214 QString aGeomEntry = *it;
1215 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1216 GEOM::GEOM_Object_var aGeomVar =
1217 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1219 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1220 if ( aSMESHGen->_is_nil() )
1223 SUIT_OverrideCursor aWaitCursor;
1226 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1227 if ( aMeshVar->_is_nil() )
1229 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1231 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1233 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ ) {
1234 if ( !isAccessibleDim( aDim )) continue;
1236 // assign hypotheses
1237 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1238 int aHypIndex = currentHyp( aDim, aHypType );
1239 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1240 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1241 if ( !aHypVar->_is_nil() )
1242 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1245 // find or create algorithm
1246 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1247 if ( !anAlgoVar->_is_nil() )
1248 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1255 //================================================================================
1257 * \brief Creates sub-mesh
1258 * \param theMess - Output parameter intended for returning error message
1259 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1263 //================================================================================
1264 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1268 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1269 if ( aSMESHGen->_is_nil() )
1273 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1274 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1275 SMESH::SMESH_Mesh_var aMeshVar =
1276 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1277 if (aMeshVar->_is_nil())
1280 // GEOM shape of the main mesh
1281 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1283 // Name for the new sub-mesh
1284 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1287 GEOM::GEOM_Object_var aGeomVar;
1289 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1290 if (aGEOMs.count() == 1)
1292 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1293 QString aGeomEntry = aGEOMs.first();
1294 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1295 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1297 else if (aGEOMs.count() > 1)
1299 // create a GEOM group
1300 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1301 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1302 if (!geomGen->_is_nil() && aStudy) {
1303 GEOM::GEOM_IGroupOperations_var op =
1304 geomGen->GetIGroupOperations(aStudy->StudyId());
1305 if (!op->_is_nil()) {
1306 // check and add all selected GEOM objects: they must be
1307 // a sub-shapes of the main GEOM and must be of one type
1309 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1310 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1311 aSeq->length(aGEOMs.count());
1312 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1313 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1314 QString aSubGeomEntry = (*aSubShapesIter);
1315 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
1316 GEOM::GEOM_Object_var aSubGeomVar =
1317 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1318 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1320 aGroupType = aSubShapeType;
1322 if (aSubShapeType != aGroupType)
1323 aGroupType = TopAbs_SHAPE;
1325 aSeq[iSubSh] = aSubGeomVar;
1328 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1329 op->UnionList(aGroupVar, aSeq);
1332 aGeomVar = aGroupVar;
1334 // publish the GEOM group in study
1335 QString aNewGeomGroupName ("Auto_group_for_");
1336 aNewGeomGroupName += aName;
1337 SALOMEDS::SObject_var aNewGroupSO =
1338 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
1345 if (aGeomVar->_is_nil())
1348 SUIT_OverrideCursor aWaitCursor;
1351 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1353 for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1355 if ( !isAccessibleDim( aDim )) continue;
1357 // find or create algorithm
1358 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1359 if ( !anAlgoVar->_is_nil() )
1360 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1361 // assign hypotheses
1362 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1364 int aHypIndex = currentHyp( aDim, aHypType );
1365 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1367 SMESH::SMESH_Hypothesis_var aHypVar =
1368 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1369 if ( !aHypVar->_is_nil() )
1370 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1375 // deselect geometry: next submesh sould be created on other subshape
1376 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1377 selectObject( _PTR(SObject)() );
1383 //================================================================================
1385 * \brief Gets current hypothesis or algorithms
1386 * \param theDim - dimension of hypothesis or algorithm
1387 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1388 * \retval int - current hypothesis or algorithms
1390 * Gets current hypothesis or algorithms
1392 //================================================================================
1393 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1395 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1398 //================================================================================
1400 * \brief Returns true if hypotheses of given dim can be assigned
1401 * \param theDim - hypotheses dimension
1402 * \retval bool - result
1404 //================================================================================
1405 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1407 return myDlg->tab( theDim )->isEnabled();
1410 //================================================================================
1412 * \brief Sets current hypothesis or algorithms
1413 * \param theDim - dimension of hypothesis or algorithm
1414 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1415 * \param theIndex - Index of hypothesis
1417 * Gets current hypothesis or algorithms
1419 //================================================================================
1420 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1421 const int theHypType,
1422 const int theIndex )
1424 myIgnoreAlgoSelection = true;
1425 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1426 myIgnoreAlgoSelection = false;
1429 //================================================================================
1431 * \brief Generates default and sets mesh/submesh name
1433 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1435 //================================================================================
1436 void SMESHGUI_MeshOp::setDefaultName() const
1440 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1442 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1443 _PTR(SObject) anObj;
1446 aResName = aPrefix + QString::number( i++ );
1447 anObj = aStudy->FindObject( aResName.latin1() );
1451 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1452 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1453 aControl->setText( aResName );
1456 //================================================================================
1458 * \brief Gets algorithm or creates it if necessary
1459 * \param theDim - specifies dimension of returned hypotheses/algorifms
1460 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1462 * Gets algorithm or creates it if necessary
1464 //================================================================================
1465 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1467 SMESH::SMESH_Hypothesis_var anAlgoVar;
1469 // get type of the selected algo
1470 int aHypIndex = currentHyp( theDim, Algo );
1471 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1472 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1474 QString aHypName = dataList[ aHypIndex ]->TypeName;
1476 // get existing algoritms
1477 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1479 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1481 // look for anexisting algo of such a type
1482 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1483 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1484 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1486 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1487 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1489 anAlgoVar = aHypVar;
1494 if (anAlgoVar->_is_nil()) {
1495 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1497 QString aClientLibName = aHypData->ClientLibName;
1498 if (aClientLibName == "") {
1499 // Call hypothesis creation server method (without GUI)
1500 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1502 // Get hypotheses creator client (GUI)
1503 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1507 aCreator->create(true, myDlg);
1509 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1511 QStringList tmpList;
1512 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1513 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1516 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1517 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1519 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1520 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1522 anAlgoVar = aHypVar;
1528 return anAlgoVar._retn();
1531 //================================================================================
1533 * \brief Reads parameters of edited mesh and assigns them to the dialog
1535 * Reads parameters of edited mesh and assigns them to the dialog (called when
1536 * mesh is edited only)
1538 //================================================================================
1539 void SMESHGUI_MeshOp::readMesh()
1541 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1542 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1546 // Get name of mesh if current object is sub-mesh
1547 SMESH::SMESH_subMesh_var aSubMeshVar =
1548 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1549 if ( !aSubMeshVar->_is_nil() )
1551 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1552 if ( !aMeshVar->_is_nil() )
1554 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1555 QString aMeshName = name( aMeshSO );
1556 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1560 // Get name of geometry object
1561 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1562 if ( !aGeomVar->_is_nil() )
1564 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1565 QString aShapeName = name( aGeomSO );
1566 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1569 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1570 QStringList anExisting;
1571 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1574 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1575 // find algo index among available ones
1577 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1579 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1580 QString aHypTypeName = aVar->GetName();
1581 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1582 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1583 // if ( aHypIndex < 0 && algoData ) {
1584 // // assigned algo is incompatible with other algorithms
1585 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1586 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1589 setCurrentHyp( dim, Algo, aHypIndex );
1590 // set existing and available hypothesis according to the selected algo
1591 onAlgoSelected( aHypIndex, dim );
1595 bool hypWithoutAlgo = false;
1596 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1598 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1601 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1602 // find index of requered hypothesis among existing ones for this dimension and type
1604 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1605 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1606 myExistingHyps[ dim ][ hypType ] );
1607 if ( aHypIndex < 0 ) {
1608 // assigned hypothesis is incompatible with the algorithm
1609 if ( currentHyp( dim, Algo ) < 0 )
1610 { // none algo selected; it is edition for sure, of submesh maybe
1611 hypWithoutAlgo = true;
1612 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1613 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1614 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1618 setCurrentHyp( dim, hypType, aHypIndex );
1621 // make available other hyps of same type as one without algo
1622 if ( hypWithoutAlgo )
1623 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1626 //================================================================================
1628 * \brief Gets name of object
1629 * \param theSO - SObject
1630 * \retval QString - name of object
1632 * Gets name of object
1634 //================================================================================
1635 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1640 _PTR(GenericAttribute) anAttr;
1641 _PTR(AttributeName) aNameAttr;
1642 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1645 aResName = aNameAttr->Value().c_str();
1651 //================================================================================
1653 * \brief Finds hypothesis in input list
1654 * \param theHyp - hypothesis to be found
1655 * \param theHypList - input list of hypotheses
1656 * \retval int - index of hypothesis or -1 if it is not found
1658 * Finds position of hypothesis in input list
1660 //================================================================================
1661 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1662 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1665 if ( !theHyp->_is_nil() )
1668 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1669 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1671 if ( theHyp->_is_equivalent( *anIter ) )
1682 //================================================================================
1684 * \brief Edits mesh or sub-mesh
1685 * \param theMess - Output parameter intended for returning error message
1686 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1688 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1690 //================================================================================
1691 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1695 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1696 if ( aSMESHGen->_is_nil() )
1699 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1700 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1704 SUIT_OverrideCursor aWaitCursor;
1707 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1709 // Assign new hypotheses and algorithms
1710 for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1712 if ( !isAccessibleDim( dim )) continue;
1714 // find or create algorithm
1715 bool toDelete = false, toAdd = true;
1716 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1717 if ( anAlgoVar->_is_nil() ) {
1720 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1721 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1723 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1732 // remove old algorithm
1734 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1735 myObjHyps[ dim ][ Algo ].clear();
1738 // assign new algorithm
1740 SMESH::SMESH_Mesh_var aMeshVar =
1741 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1742 bool isMesh = !aMeshVar->_is_nil();
1744 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1746 SMESH::SMESH_subMesh_var aVar =
1747 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1748 if ( !aVar->_is_nil() )
1749 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1751 myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1754 // assign hypotheses
1755 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1757 int aNewHypIndex = currentHyp( dim, hypType );
1758 int anOldHypIndex = -1;
1759 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1760 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1761 myExistingHyps[ dim ][ hypType ] );
1762 if ( aNewHypIndex != anOldHypIndex )
1764 // remove old hypotheses
1765 if ( anOldHypIndex >= 0 ) {
1766 SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1767 pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1768 myObjHyps[ dim ][ hypType ].clear();
1771 // assign new hypotheses
1772 if ( aNewHypIndex != -1 )
1774 SMESH::SMESH_Mesh_var aMeshVar =
1775 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1776 bool isMesh = !aMeshVar->_is_nil();
1779 SMESH::AddHypothesisOnMesh(
1780 aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1784 SMESH::SMESH_subMesh_var aVar =
1785 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1786 if ( !aVar->_is_nil() )
1787 SMESH::AddHypothesisOnSubMesh(
1788 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1791 // reread all hypotheses of mesh if necessary
1792 QStringList anExisting;
1793 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1801 //================================================================================
1803 * \brief Verifies whether given operator is valid for this one
1804 * \param theOtherOp - other operation
1805 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1807 * method redefined from base class verifies whether given operator is valid for
1808 * this one (i.e. can be started "above" this operator). In current implementation method
1809 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1812 //================================================================================
1813 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1815 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1818 //================================================================================
1820 * \brief SLOT. Is called when the user selects a way of geometry selection
1821 * \param theByMesh - true if the user wants to find geometry by mesh element
1823 //================================================================================
1825 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1828 if ( !myShapeByMeshOp ) {
1829 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1830 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1831 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1832 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1833 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1835 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1836 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1837 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1838 SMESH::SMESH_Mesh_var aMeshVar =
1839 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1840 if ( !aMeshVar->_is_nil() ) {
1841 myDlg->hide(); // stop processing selection
1842 myShapeByMeshOp->setModule( getSMESHGUI() );
1843 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1844 myShapeByMeshOp->SetMesh( aMeshVar );
1845 myShapeByMeshOp->start();
1851 //================================================================================
1853 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1855 //================================================================================
1857 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1859 if ( myShapeByMeshOp == op ) {
1860 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
1862 // Select a found geometry object
1863 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1864 if ( !aGeomVar->_is_nil() )
1866 QString ID = aGeomVar->GetStudyEntry();
1867 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1868 selectObject( aGeomSO );
1875 //================================================================================
1877 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1879 //================================================================================
1881 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1883 if ( myShapeByMeshOp == op && myDlg ) {
1888 //================================================================================
1890 * \brief Selects a SObject
1891 * \param theSObj - the SObject to select
1893 //================================================================================
1895 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1897 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1898 SALOME_ListIO anIOList;
1900 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1901 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1902 anIOList.Append( anIO );
1904 sm->setSelectedObjects( anIOList, false );