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_VERTEX_TAG =4,
80 SUBMESH_ON_EDGE_TAG =5,
81 SUBMESH_ON_WIRE_TAG =6,
82 SUBMESH_ON_FACE_TAG =7,
83 SUBMESH_ON_SHELL_TAG =8,
84 SUBMESH_ON_SOLID_TAG =9,
85 SUBMESH_ON_COMPOUND_TAG=10 };
87 //================================================================================
90 * \param theToCreate - if this parameter is true then operation is used for creation,
91 * for editing otherwise
93 * Initialize operation
95 //================================================================================
96 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
97 : SMESHGUI_SelectionOp(),
98 myToCreate( theToCreate ),
99 myIsMesh( theIsMesh ),
103 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
104 GeometryGUI::InitGeomGen();
107 //================================================================================
111 //================================================================================
112 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
118 //================================================================================
120 * \brief Gets dialog of this operation
121 * \retval LightApp_Dialog* - pointer to dialog of this operation
123 //================================================================================
124 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
129 //================================================================================
131 * \brief Creates or edits mesh
132 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
134 * Virtual slot redefined from the base class called when "Apply" button is clicked
135 * creates or edits mesh
137 //================================================================================
138 bool SMESHGUI_MeshOp::onApply()
140 if( isStudyLocked() )
144 if ( !isValid( aMess ) )
148 SUIT_MessageBox::warn1( myDlg,
149 tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
153 bool aResult = false;
157 if ( myToCreate && myIsMesh )
158 aResult = createMesh( aMess );
159 if ( myToCreate && !myIsMesh )
160 aResult = createSubMesh( aMess );
161 else if ( !myToCreate )
162 aResult = editMeshOrSubMesh( aMess );
164 update( UF_ObjBrowser | UF_Model );
166 catch ( const SALOME::SALOME_Exception& S_ex )
168 SalomeApp_Tools::QtCatchCorbaException( S_ex );
184 aMess = tr( "SMESH_OPERATION_FAILED" );
185 SUIT_MessageBox::warn1( myDlg,
186 tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
192 //================================================================================
194 * \brief Creates dialog if necessary and shows it
196 * Virtual method redefined from base class called when operation is started creates
197 * dialog if necessary and shows it, activates selection
199 //================================================================================
200 void SMESHGUI_MeshOp::startOperation()
204 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
205 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
207 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
208 this, SLOT( onCreateHyp( const int, const int ) ) );
209 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
210 this, SLOT( onEditHyp( const int, const int ) ) );
211 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
212 this, SLOT( onAlgoSelected( const int ) ) );
214 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
215 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
218 if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
219 else myHelpFileName = "/files/constructing_submeshes.htm";
220 else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
222 SMESHGUI_SelectionOp::startOperation();
224 // iterate through dimensions and get available algoritms, set them to the dialog
225 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
226 for ( int i = SMESH::DIM_0D; 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 // skl for NPAL14695 - implementation of searching of mainObj
335 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
336 //if (mainObj->_is_nil() ||
337 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
339 if(mainObj->_is_nil())
341 if( string(mainObj->GetEntry()) == string(mainGeom->GetEntry()) )
343 mainObj = op->GetMainShape(mainObj);
352 //================================================================================
354 * \brief find an existing submesh by the selected shape
355 * \retval _PTR(SObject) - the found submesh SObject
357 //================================================================================
359 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
361 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
362 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
363 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
364 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
365 if ( pMesh && pGeom ) {
366 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
367 if ( !geom->_is_nil() ) {
369 switch ( geom->GetShapeType() ) {
370 case GEOM::VERTEX: tag = SUBMESH_ON_VERTEX_TAG ; break;
371 case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
372 case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
373 case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
374 case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
375 case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
376 case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
379 _PTR(GenericAttribute) anAttr;
380 _PTR(SObject) aSubmeshRoot;
381 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
382 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
384 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
385 for (; smIter->More(); smIter->Next() )
387 _PTR(SObject) aSmObj = smIter->Value();
388 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
390 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
391 for (; anIter1->More(); anIter1->Next()) {
392 _PTR(SObject) pGeom2 = anIter1->Value();
393 if ( pGeom2->ReferencedObject( pGeom2 ) &&
394 pGeom2->GetID() == pGeom->GetID() )
401 return _PTR(SObject)();
404 //================================================================================
406 * \brief Updates dialog's look and feel
408 * Virtual method redefined from the base class updates dialog's look and feel
410 //================================================================================
411 void SMESHGUI_MeshOp::selectionDone()
413 if ( !dlg()->isShown() || !myDlg->isEnabled() )
416 SMESHGUI_SelectionOp::selectionDone();
420 // Enable tabs according to shape dimension
425 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
426 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
428 if (aGEOMs.count() > 0) {
429 // one or more GEOM shape selected
430 aSeq->length(aGEOMs.count());
431 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
433 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
434 QString aSubGeomEntry = (*aSubShapesIter);
435 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
436 GEOM::GEOM_Object_var aSubGeomVar =
437 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
438 aSeq[iSubSh] = aSubGeomVar;
441 // get geometry by selected sub-mesh
442 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
443 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
444 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
445 if (!aGeomVar->_is_nil()) {
451 if (aSeq->length() > 0) {
453 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
454 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
455 switch ( aGeomVar->GetShapeType() ) {
457 case GEOM::SHELL: shapeDim = 3; break;
458 case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
460 case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
461 case GEOM::VERTEX: break;
464 if ( GEOMBase::GetShape(aGeomVar, aShape)) {
465 TopExp_Explorer exp( aShape, TopAbs_SHELL );
468 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
469 shapeDim = (shapeDim < 2) ? 2 : shapeDim;
470 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
471 shapeDim = (shapeDim < 1) ? 1 : shapeDim;
478 myDlg->setMaxHypoDim( shapeDim );
481 if ( !myToCreate ) // edition: read hypotheses
483 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
484 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
487 SMESH::SMESH_subMesh_var aVar =
488 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
489 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
490 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
491 myDlg->updateGeometry();
499 else if ( !myIsMesh ) // submesh creation
501 // if a submesh on the selected shape already exist, pass to submesh edition mode
502 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
503 SMESH::SMESH_subMesh_var sm =
504 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
505 bool editSubmesh = ( !sm->_is_nil() &&
506 SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
507 tr( "EDIT_SUBMESH_QUESTION"),
508 tr( "SMESH_BUT_YES" ),
509 tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
512 selectionMgr()->clearFilters();
513 selectObject( pSubmesh );
514 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
519 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
520 selectObject( _PTR(SObject)() );
525 // enable/disable popup for choice of geom selection way
527 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
528 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
529 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
530 if ( !mesh->_is_nil() )
531 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
533 myDlg->setGeomPopupEnabled( enable );
536 catch ( const SALOME::SALOME_Exception& S_ex )
538 SalomeApp_Tools::QtCatchCorbaException( S_ex );
545 //================================================================================
547 * \brief Verifies validity of input data
548 * \param theMess - Output parameter intended for returning error message
549 * \retval bool - TRUE if input data is valid, false otherwise
551 * Verifies validity of input data. This method is called when "Apply" or "OK" button
552 * is pressed before mesh creation or editing.
554 //================================================================================
555 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
557 // Selected object to be edited
558 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
560 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
565 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
566 aMeshName = aMeshName.stripWhiteSpace();
567 if ( aMeshName == "" )
569 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
573 // Imported mesh, if create sub-mesh or edit mesh
574 if ( !myToCreate || ( myToCreate && !myIsMesh ))
576 QString aMeshEntry = myDlg->selectedObject
577 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
578 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
579 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
580 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
581 theMess = tr( "IMPORTED_MESH" );
590 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
591 if ( aGeomEntry == "" )
593 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
596 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
597 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
599 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
604 if ( !myIsMesh ) // i.e sub-mesh creation,
606 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
607 if ( aMeshEntry == "" )
609 theMess = tr( "MESH_IS_NOT_DEFINED" );
612 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
613 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
615 theMess = tr( "MESH_IS_NULL" );
618 if ( !isSubshapeOk() )
620 theMess = tr( "INVALID_SUBSHAPE" );
629 //================================================================================
631 * \brief check compatibility of the algorithm and another algorithm or hypothesis
632 * \param theAlgoData - algorithm data
633 * \param theHypData - hypothesis data
634 * \param theHypType - hypothesis type
635 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
636 * \retval bool - check result
638 //================================================================================
640 static bool isCompatible(const HypothesisData* theAlgoData,
641 const HypothesisData* theHypData,
642 const int theHypType)
647 if ( theHypType == SMESHGUI_MeshOp::Algo )
648 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
651 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
654 //================================================================================
656 * \brief Gets available hypotheses or algorithms
657 * \param theDim - specifies dimension of returned hypotheses/algorifms
658 * \param theHypType - specifies whether algorims or hypotheses or additional ones
659 * are retrieved (possible values are in HypType enumeration)
660 * \param theHyps - Output list of hypotheses' names
661 * \param theAlgoData - to select hypos able to be used by this algo (optional)
663 * Gets available hypotheses or algorithm in accordance with input parameters
665 //================================================================================
666 void SMESHGUI_MeshOp::availableHyps( const int theDim,
667 const int theHypType,
668 QStringList& theHyps,
669 THypDataList& theDataList,
670 HypothesisData* theAlgoData ) const
674 bool isAlgo = ( theHypType == Algo );
675 bool isAux = ( theHypType == AddHyp );
676 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
678 QStringList::const_iterator anIter;
679 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
681 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
682 if ( isCompatible ( theAlgoData, aData, theHypType )) {
683 theDataList.append( aData );
684 theHyps.append( aData->Label );
689 //================================================================================
691 * \brief Gets existing hypotheses or algorithms
692 * \param theDim - specifies dimension of returned hypotheses/algorifms
693 * \param theHypType - specifies whether algorims or hypotheses or additional ones
694 * are retrieved (possible values are in HypType enumeration)
695 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
696 * \param theDataList - output list of hypotheses data
697 * \param theHyps - output list of names.
698 * \param theHypVars - output list of variables.
699 * \param theAlgoData - to select hypos able to be used by this algo (optional)
701 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
704 //================================================================================
705 void SMESHGUI_MeshOp::existingHyps( const int theDim,
706 const int theHypType,
707 _PTR(SObject) theFather,
708 QStringList& theHyps,
709 QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
710 HypothesisData* theAlgoData)
712 // Clear hypoheses list
719 const bool isAux = ( theHypType == AddHyp );
721 _PTR(SObject) aHypRoot;
722 _PTR(GenericAttribute) anAttr;
723 _PTR(AttributeName) aName;
724 _PTR(AttributeIOR) anIOR;
726 bool isMesh = !_CAST( SComponent, theFather );
729 aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
731 aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
733 if ( theFather->FindSubObject( aPart, aHypRoot ) )
735 _PTR(ChildIterator) anIter =
736 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
737 for (; anIter->More(); anIter->Next() )
739 _PTR(SObject) anObj = anIter->Value();
740 if ( isMesh ) // i.e. mesh or submesh
742 _PTR(SObject) aRefObj;
743 if ( anObj->ReferencedObject( aRefObj ) )
748 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
751 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
752 if ( !CORBA::is_nil( aVar ) )
754 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
755 if ( !aHypVar->_is_nil() )
757 QString aHypType( aHypVar->GetName() );
758 HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
759 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
760 ( isCompatible ( theAlgoData, aData, theHypType )) &&
761 ( isAux == aData->IsAux ))
763 //theDataList.append( aData );
764 theHyps.append( aName->Value().c_str() );
765 theHypVars.append( aHypVar );
774 //================================================================================
776 * \brief If create or edit a submesh, return a hypothesis holding parameters used
778 * \param aHypType - The hypothesis type name
779 * \param aServerLib - Server library name
780 * \param hypData - The structure holding the hypothesis type etc.
781 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
783 //================================================================================
785 SMESH::SMESH_Hypothesis_var
786 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
787 const QString& aServerLib ) const
789 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
790 return SMESH::SMESH_Hypothesis::_nil();
792 const int nbColonsInMeshEntry = 3;
793 bool isSubMesh = myToCreate ?
795 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry;
799 // get mesh and geom object
800 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
801 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
803 QString anEntry = myDlg->selectedObject
804 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
805 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
807 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
808 if ( myToCreate ) // mesh and geom may be selected
810 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
811 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
812 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
813 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
815 else // edition: sub-mesh may be selected
817 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
818 if ( !sm->_is_nil() ) {
819 aMeshVar = sm->GetFather();
820 aGeomVar = sm->GetSubShape();
825 if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
826 return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
831 return SMESH::SMESH_Hypothesis::_nil();
834 //================================================================================
836 * \Brief Returns tab dimention
837 * \param tab - the tab in the dlg
838 * \param dlg - my dialogue
839 * \retval int - dimention
841 //================================================================================
843 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
846 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
847 if (tab == dlg->tab(i))
852 //================================================================================
854 * \brief Create hypothesis
855 * \param theHypType - hypothesis category (main or additional)
856 * \param theIndex - index of type of hypothesis to be cerated
858 * Specifies dimension of hypothesis to be created (using sender() method),
859 * specifies its type and calls method for hypothesis creation
861 //================================================================================
862 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
864 // Specifies dimension of hypothesis to be created
865 int aDim = getTabDim( sender(), myDlg );
869 // Specifies type of hypothesis to be created
870 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
871 if (theIndex < 0 || theIndex >= dataList.count())
873 QString aHypTypeName = dataList[ theIndex ]->TypeName;
876 createHypothesis(aDim, theHypType, aHypTypeName);
879 //================================================================================
881 * Create hypothesis and update dialog.
882 * \param theDim - dimension of hypothesis to be created
883 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
884 * \param theTypeName - specifies hypothesis to be created
886 //================================================================================
887 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
889 const QString& theTypeName)
891 // During a hypothesis creation we might need to select some objects.
892 // Main dialog must not update it's own selected objects in this case.
893 dlg()->deactivateAll();
895 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
900 int nbHyp = myExistingHyps[theDim][theType].count();
902 QString aClientLibName = aData->ClientLibName;
903 if (aClientLibName == "") {
904 // Call hypothesis creation server method (without GUI)
905 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
907 // Get hypotheses creator client (GUI)
908 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
912 // When create or edit a submesh, try to initialize a new hypothesis
913 // with values used to mesh a subshape
914 SMESH::SMESH_Hypothesis_var initParamHyp =
915 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
916 myDlg->setEnabled( false );
917 aCreator->create(initParamHyp, myDlg);
918 myDlg->setEnabled( true );
920 SMESH::CreateHypothesis(theTypeName, aData->Label, false);
924 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
926 HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
927 QStringList aNewHyps;
928 existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
929 if (aNewHyps.count() > nbHyp) {
930 for (int i = nbHyp; i < aNewHyps.count(); i++)
931 myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
935 //================================================================================
937 * \brief Calls plugin methods for hypothesis editing
938 * \param theHypType - specifies whether main hypothesis or additional one
940 * \param theIndex - index of existing hypothesis
942 * Calls plugin methods for hypothesis editing
944 //================================================================================
945 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
947 // Speicfies dimension of hypothesis to be created
948 int aDim = getTabDim( sender(), myDlg );
952 QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
953 if ( theIndex < 0 || theIndex >= aList.count() )
955 SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
956 if ( aHyp->_is_nil() )
959 char* aTypeName = aHyp->GetName();
960 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
962 myDlg->setEnabled( false );
963 aCreator->edit( aHyp.in(), dlg() );
964 myDlg->setEnabled( true );
968 //================================================================================
970 * \brief access to hypothesis data
971 * \param theDim - hyp dimension
972 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
973 * \param theIndex - index in the list
974 * \retval HypothesisData* - result data, may be 0
976 //================================================================================
978 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
979 const int theHypType,
982 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
983 theHypType > -1 && theHypType < NbHypTypes &&
984 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
985 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
989 //================================================================================
991 * \brief Set available algos and hypos according to the selected algorithm
992 * \param theIndex - algorithm index
994 //================================================================================
996 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
999 if ( myIgnoreAlgoSelection )
1002 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1006 // find highest available dimension, all algos of this dimension are available for choice
1008 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1009 if (isAccessibleDim( i ))
1014 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1016 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1017 HypothesisData* algoByDim[4];
1018 algoByDim[ aDim ] = algoData;
1020 QStringList anAvailable;
1021 if ( !algoData ) { // all algos becomes available
1022 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1023 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1026 // check that algorithms of other dimentions are compatible with
1029 // 2 loops: backward and forward from algo dimension
1030 for ( int forward = false; forward <= true; ++forward )
1032 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1034 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1036 HypothesisData* prevAlgo = algoData;
1037 bool noCompatible = false;
1038 for ( ; dim * dir <= lastDim * dir ; dim += dir )
1040 if ( !isAccessibleDim( dim ))
1042 if ( noCompatible ) { // the selected algo has no compatible ones
1043 anAvailable.clear();
1044 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1045 myAvailableHypData[dim][Algo].clear();
1046 algoByDim[ dim ] = 0;
1049 // get currently selected algo
1050 int algoIndex = currentHyp( dim, Algo );
1051 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1052 if ( curAlgo ) { // some algo selected
1053 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1056 // set new available algoritms
1057 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1058 HypothesisData* soleCompatible = 0;
1059 if ( anAvailable.count() == 1 )
1060 soleCompatible = myAvailableHypData[dim][Algo][0];
1061 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1062 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1063 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1064 noCompatible = anAvailable.isEmpty();
1066 // restore previously selected algo
1067 algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1068 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1069 // select the sole compatible algo
1070 algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1071 setCurrentHyp( dim, Algo, algoIndex );
1073 // remember current algo
1074 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1078 // set hypotheses corresponding to the found algoritms
1080 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1082 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1084 if ( !isAccessibleDim( dim ))
1086 for ( int type = MainHyp; type < NbHypTypes; type++ )
1088 myAvailableHypData[ dim ][ type ].clear();
1089 QStringList anAvailable, anExisting;
1091 HypothesisData* curAlgo = algoByDim[ dim ];
1092 int hypIndex = currentHyp( dim, type );
1094 SMESH::SMESH_Hypothesis_var curHyp;
1095 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1096 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1098 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1099 // try to find algo by selected hypothesis in order to keep it selected
1100 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1101 QString curHypType = curHyp->GetName();
1102 if ( !algoDeselectedByUser &&
1103 myObjHyps[ dim ][ type ].count() > 0 &&
1104 curHypType == myObjHyps[ dim ][ type ][ 0 ]->GetName())
1106 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1107 for ( int i = 0 ; i < myAvailableHypData[ dim ][ Algo ].count(); ++i ) {
1108 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1109 if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1116 // get hyps compatible with curAlgo
1119 // check if a selected hyp is compatible with the curAlgo
1120 if ( !curHyp->_is_nil() ) {
1121 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1122 if ( !isCompatible( curAlgo, hypData, type ))
1123 curHyp = SMESH::SMESH_Hypothesis::_nil();
1125 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1126 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1128 // set list of hypotheses
1129 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1130 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1132 // set current existing hypothesis
1133 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1134 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1137 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1138 // none is yet selected => select the sole existing if it is not optional
1139 QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1140 bool isOptional = true;
1141 if ( algoByDim[ dim ] &&
1142 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1146 setCurrentHyp( dim, type, hypIndex );
1151 //================================================================================
1153 * \brief Creates and selects hypothesis of hypotheses set
1154 * \param theSetName - The name of hypotheses set
1156 //================================================================================
1157 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1159 HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1160 if (!aHypoSet) return;
1163 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1164 setCurrentHyp(dim, Algo, -1);
1165 setCurrentHyp(dim, AddHyp, -1);
1166 setCurrentHyp(dim, MainHyp, -1);
1169 for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1170 bool isAlgo = (aHypType == Algo);
1172 // set hyps from the set
1173 QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1174 for (int i = 0, n = aHypoList->count(); i < n; i++) {
1175 const QString& aHypoTypeName = (*aHypoList)[ i ];
1176 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1180 int aDim = aHypData->Dim[0];
1181 // create or/and set
1183 int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1185 QStringList anAvailable;
1186 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1187 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1188 index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1190 setCurrentHyp( aDim, Algo, index );
1191 onAlgoSelected( index, aDim );
1194 bool mainHyp = true;
1195 int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1198 index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1201 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1203 } // loop on hypos in the set
1204 } // loop on algo/hypo
1207 //================================================================================
1209 * \brief Creates mesh
1210 * \param theMess - Output parameter intended for returning error message
1211 * \retval bool - TRUE if mesh is created, FALSE otherwise
1215 //================================================================================
1216 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1220 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1221 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1224 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1225 QStringList::Iterator it = aList.begin();
1226 for(; it!=aList.end(); it++) {
1228 QString aGeomEntry = *it;
1229 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1230 GEOM::GEOM_Object_var aGeomVar =
1231 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1233 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1234 if ( aSMESHGen->_is_nil() )
1237 SUIT_OverrideCursor aWaitCursor;
1240 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1241 if ( aMeshVar->_is_nil() )
1243 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1245 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1247 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1248 if ( !isAccessibleDim( aDim )) continue;
1250 // assign hypotheses
1251 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1252 int aHypIndex = currentHyp( aDim, aHypType );
1253 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1254 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1255 if ( !aHypVar->_is_nil() )
1256 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1259 // find or create algorithm
1260 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1261 if ( !anAlgoVar->_is_nil() )
1262 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1269 //================================================================================
1271 * \brief Creates sub-mesh
1272 * \param theMess - Output parameter intended for returning error message
1273 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1277 //================================================================================
1278 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1282 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1283 if ( aSMESHGen->_is_nil() )
1287 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1288 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1289 SMESH::SMESH_Mesh_var aMeshVar =
1290 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1291 if (aMeshVar->_is_nil())
1294 // GEOM shape of the main mesh
1295 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1297 // Name for the new sub-mesh
1298 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1301 GEOM::GEOM_Object_var aGeomVar;
1303 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1304 if (aGEOMs.count() == 1)
1306 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1307 QString aGeomEntry = aGEOMs.first();
1308 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1309 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1311 else if (aGEOMs.count() > 1)
1313 // create a GEOM group
1314 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1315 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1316 if (!geomGen->_is_nil() && aStudy) {
1317 GEOM::GEOM_IGroupOperations_var op =
1318 geomGen->GetIGroupOperations(aStudy->StudyId());
1319 if (!op->_is_nil()) {
1320 // check and add all selected GEOM objects: they must be
1321 // a sub-shapes of the main GEOM and must be of one type
1323 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1324 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1325 aSeq->length(aGEOMs.count());
1326 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1327 for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1328 QString aSubGeomEntry = (*aSubShapesIter);
1329 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
1330 GEOM::GEOM_Object_var aSubGeomVar =
1331 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1332 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1334 aGroupType = aSubShapeType;
1336 if (aSubShapeType != aGroupType)
1337 aGroupType = TopAbs_SHAPE;
1339 aSeq[iSubSh] = aSubGeomVar;
1342 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1343 op->UnionList(aGroupVar, aSeq);
1346 aGeomVar = aGroupVar;
1348 // publish the GEOM group in study
1349 QString aNewGeomGroupName ("Auto_group_for_");
1350 aNewGeomGroupName += aName;
1351 SALOMEDS::SObject_var aNewGroupSO =
1352 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
1359 if (aGeomVar->_is_nil())
1362 SUIT_OverrideCursor aWaitCursor;
1365 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1367 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1369 if ( !isAccessibleDim( aDim )) continue;
1371 // find or create algorithm
1372 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1373 if ( !anAlgoVar->_is_nil() )
1374 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1375 // assign hypotheses
1376 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1378 int aHypIndex = currentHyp( aDim, aHypType );
1379 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1381 SMESH::SMESH_Hypothesis_var aHypVar =
1382 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1383 if ( !aHypVar->_is_nil() )
1384 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1389 // deselect geometry: next submesh sould be created on other subshape
1390 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1391 selectObject( _PTR(SObject)() );
1397 //================================================================================
1399 * \brief Gets current hypothesis or algorithms
1400 * \param theDim - dimension of hypothesis or algorithm
1401 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1402 * \retval int - current hypothesis or algorithms
1404 * Gets current hypothesis or algorithms
1406 //================================================================================
1407 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1409 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1412 //================================================================================
1414 * \brief Returns true if hypotheses of given dim can be assigned
1415 * \param theDim - hypotheses dimension
1416 * \retval bool - result
1418 //================================================================================
1419 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1421 return myDlg->tab( theDim )->isEnabled();
1424 //================================================================================
1426 * \brief Sets current hypothesis or algorithms
1427 * \param theDim - dimension of hypothesis or algorithm
1428 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1429 * \param theIndex - Index of hypothesis
1431 * Gets current hypothesis or algorithms
1433 //================================================================================
1434 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1435 const int theHypType,
1436 const int theIndex )
1438 myIgnoreAlgoSelection = true;
1439 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1440 myIgnoreAlgoSelection = false;
1443 //================================================================================
1445 * \brief Generates default and sets mesh/submesh name
1447 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1449 //================================================================================
1450 void SMESHGUI_MeshOp::setDefaultName() const
1454 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1456 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1457 _PTR(SObject) anObj;
1460 aResName = aPrefix + QString::number( i++ );
1461 anObj = aStudy->FindObject( aResName.latin1() );
1465 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1466 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1467 aControl->setText( aResName );
1470 //================================================================================
1472 * \brief Gets algorithm or creates it if necessary
1473 * \param theDim - specifies dimension of returned hypotheses/algorifms
1474 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1476 * Gets algorithm or creates it if necessary
1478 //================================================================================
1479 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1481 SMESH::SMESH_Hypothesis_var anAlgoVar;
1483 // get type of the selected algo
1484 int aHypIndex = currentHyp( theDim, Algo );
1485 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1486 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1488 QString aHypName = dataList[ aHypIndex ]->TypeName;
1490 // get existing algoritms
1491 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1493 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1495 // look for anexisting algo of such a type
1496 QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1497 QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1498 for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1500 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1501 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1503 anAlgoVar = aHypVar;
1508 if (anAlgoVar->_is_nil()) {
1509 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1511 QString aClientLibName = aHypData->ClientLibName;
1512 if (aClientLibName == "") {
1513 // Call hypothesis creation server method (without GUI)
1514 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1516 // Get hypotheses creator client (GUI)
1517 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1521 aCreator->create(true, myDlg);
1523 SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1525 QStringList tmpList;
1526 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1527 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1530 QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1531 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1533 SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1534 if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1536 anAlgoVar = aHypVar;
1542 return anAlgoVar._retn();
1545 //================================================================================
1547 * \brief Reads parameters of edited mesh and assigns them to the dialog
1549 * Reads parameters of edited mesh and assigns them to the dialog (called when
1550 * mesh is edited only)
1552 //================================================================================
1553 void SMESHGUI_MeshOp::readMesh()
1555 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1556 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1560 // Get name of mesh if current object is sub-mesh
1561 SMESH::SMESH_subMesh_var aSubMeshVar =
1562 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1563 if ( !aSubMeshVar->_is_nil() )
1565 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1566 if ( !aMeshVar->_is_nil() )
1568 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1569 QString aMeshName = name( aMeshSO );
1570 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1574 // Get name of geometry object
1575 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1576 if ( !aGeomVar->_is_nil() )
1578 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1579 QString aShapeName = name( aGeomSO );
1580 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1583 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1584 QStringList anExisting;
1585 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1588 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1589 // find algo index among available ones
1591 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1593 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1594 QString aHypTypeName = aVar->GetName();
1595 HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1596 aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1597 // if ( aHypIndex < 0 && algoData ) {
1598 // // assigned algo is incompatible with other algorithms
1599 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1600 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1603 setCurrentHyp( dim, Algo, aHypIndex );
1604 // set existing and available hypothesis according to the selected algo
1605 onAlgoSelected( aHypIndex, dim );
1609 bool hypWithoutAlgo = false;
1610 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1612 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1615 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1616 // find index of requered hypothesis among existing ones for this dimension and type
1618 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1619 aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1620 myExistingHyps[ dim ][ hypType ] );
1621 if ( aHypIndex < 0 ) {
1622 // assigned hypothesis is incompatible with the algorithm
1623 if ( currentHyp( dim, Algo ) < 0 )
1624 { // none algo selected; it is edition for sure, of submesh maybe
1625 hypWithoutAlgo = true;
1626 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1627 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1628 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1632 setCurrentHyp( dim, hypType, aHypIndex );
1635 // make available other hyps of same type as one without algo
1636 if ( hypWithoutAlgo )
1637 onAlgoSelected( currentHyp( 0, Algo ), 0 );
1640 //================================================================================
1642 * \brief Gets name of object
1643 * \param theSO - SObject
1644 * \retval QString - name of object
1646 * Gets name of object
1648 //================================================================================
1649 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1654 _PTR(GenericAttribute) anAttr;
1655 _PTR(AttributeName) aNameAttr;
1656 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1659 aResName = aNameAttr->Value().c_str();
1665 //================================================================================
1667 * \brief Finds hypothesis in input list
1668 * \param theHyp - hypothesis to be found
1669 * \param theHypList - input list of hypotheses
1670 * \retval int - index of hypothesis or -1 if it is not found
1672 * Finds position of hypothesis in input list
1674 //================================================================================
1675 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1676 const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1679 if ( !theHyp->_is_nil() )
1682 QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1683 for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1685 if ( theHyp->_is_equivalent( *anIter ) )
1696 //================================================================================
1698 * \brief Edits mesh or sub-mesh
1699 * \param theMess - Output parameter intended for returning error message
1700 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
1702 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1704 //================================================================================
1705 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1709 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1710 if ( aSMESHGen->_is_nil() )
1713 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1714 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1718 SUIT_OverrideCursor aWaitCursor;
1721 SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1723 // Assign new hypotheses and algorithms
1724 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1726 if ( !isAccessibleDim( dim )) continue;
1728 // find or create algorithm
1729 bool toDelete = false, toAdd = true;
1730 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1731 if ( anAlgoVar->_is_nil() ) {
1734 if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1735 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1737 if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1746 // remove old algorithm
1748 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1749 myObjHyps[ dim ][ Algo ].clear();
1752 // assign new algorithm
1754 SMESH::SMESH_Mesh_var aMeshVar =
1755 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1756 bool isMesh = !aMeshVar->_is_nil();
1758 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1760 SMESH::SMESH_subMesh_var aVar =
1761 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1762 if ( !aVar->_is_nil() )
1763 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1765 myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1768 // assign hypotheses
1769 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1771 int aNewHypIndex = currentHyp( dim, hypType );
1772 int anOldHypIndex = -1;
1774 // remove old hypotheses
1775 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1777 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1778 myExistingHyps[ dim ][ hypType ] );
1779 if ( aNewHypIndex != anOldHypIndex || // different hyps
1780 anOldHypIndex == -1 ) // hyps of different algos
1782 SMESH::RemoveHypothesisOrAlgorithmOnMesh
1783 ( pObj, myObjHyps[ dim ][ hypType ].first() );
1784 myObjHyps[ dim ][ hypType ].clear();
1788 // assign new hypotheses
1789 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
1791 SMESH::SMESH_Mesh_var aMeshVar =
1792 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1793 bool isMesh = !aMeshVar->_is_nil();
1796 SMESH::AddHypothesisOnMesh
1797 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1801 SMESH::SMESH_subMesh_var aVar =
1802 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1803 if ( !aVar->_is_nil() )
1804 SMESH::AddHypothesisOnSubMesh
1805 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1808 // reread all hypotheses of mesh if necessary
1809 QStringList anExisting;
1810 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1817 //================================================================================
1819 * \brief Verifies whether given operator is valid for this one
1820 * \param theOtherOp - other operation
1821 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1823 * method redefined from base class verifies whether given operator is valid for
1824 * this one (i.e. can be started "above" this operator). In current implementation method
1825 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1828 //================================================================================
1829 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1831 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1834 //================================================================================
1836 * \brief SLOT. Is called when the user selects a way of geometry selection
1837 * \param theByMesh - true if the user wants to find geometry by mesh element
1839 //================================================================================
1841 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1844 if ( !myShapeByMeshOp ) {
1845 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1846 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1847 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1848 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1849 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1851 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1852 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1853 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1854 SMESH::SMESH_Mesh_var aMeshVar =
1855 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1856 if ( !aMeshVar->_is_nil() ) {
1857 myDlg->hide(); // stop processing selection
1858 myShapeByMeshOp->setModule( getSMESHGUI() );
1859 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1860 myShapeByMeshOp->SetMesh( aMeshVar );
1861 myShapeByMeshOp->start();
1867 //================================================================================
1869 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1871 //================================================================================
1873 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1875 if ( myShapeByMeshOp == op ) {
1876 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
1878 // Select a found geometry object
1879 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1880 if ( !aGeomVar->_is_nil() )
1882 QString ID = aGeomVar->GetStudyEntry();
1883 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1884 selectObject( aGeomSO );
1891 //================================================================================
1893 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1895 //================================================================================
1897 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1899 if ( myShapeByMeshOp == op && myDlg ) {
1904 //================================================================================
1906 * \brief Selects a SObject
1907 * \param theSObj - the SObject to select
1909 //================================================================================
1911 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1913 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1914 SALOME_ListIO anIOList;
1916 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1917 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1918 anIOList.Append( anIO );
1920 sm->setSelectedObjects( anIOList, false );