1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_MeshDlg.h"
30 #include "SMESHGUI_ShapeByMeshDlg.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_NumberFilter.hxx>
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LightApp_UpdateFlags.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_Session.h>
54 #include <SALOME_InteractiveObject.hxx>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SComponent.hxx>
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDS_Study.hxx>
61 #include <SALOMEDS_wrap.hxx>
64 #include <QStringList>
69 #include <TopoDS_Shape.hxx>
70 #include <TopoDS_Shell.hxx>
71 #include <TopExp_Explorer.hxx>
72 #include <BRep_Tool.hxx>
75 #include <SALOMEconfig.h>
76 #include CORBA_CLIENT_HEADER(SMESH_Gen)
78 //================================================================================
81 * \param theToCreate - if this parameter is true then operation is used for creation,
82 * for editing otherwise
84 * Initialize operation
86 //================================================================================
87 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
88 : SMESHGUI_SelectionOp(),
89 myToCreate( theToCreate ),
90 myIsMesh( theIsMesh ),
95 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
96 GeometryGUI::InitGeomGen();
97 myIsOnGeometry = true;
100 //================================================================================
104 //================================================================================
105 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
111 //================================================================================
113 * \brief Gets dialog of this operation
114 * \retval LightApp_Dialog* - pointer to dialog of this operation
116 //================================================================================
117 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
122 //================================================================================
124 * \brief Creates or edits mesh
125 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
127 * Virtual slot redefined from the base class called when "Apply" button is clicked
128 * creates or edits mesh
130 //================================================================================
131 bool SMESHGUI_MeshOp::onApply()
137 if ( !isValid( aMess ) )
141 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
144 /* else if ( aMess == tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" ) || aMess == tr( "GEOMETRY_OBJECT_IS_NULL" ) )
147 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess,
148 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
152 bool aResult = false;
156 QStringList anEntryList;
157 if ( myToCreate && myIsMesh )
158 aResult = createMesh( aMess, anEntryList );
159 if ( myToCreate && !myIsMesh )
160 aResult = createSubMesh( aMess, anEntryList );
161 else if ( !myToCreate )
162 aResult = editMeshOrSubMesh( aMess );
165 SMESHGUI::Modified();
166 update( UF_ObjBrowser | UF_Model );
167 if( LightApp_Application* anApp =
168 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
169 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
172 catch ( const SALOME::SALOME_Exception& S_ex )
174 SalomeApp_Tools::QtCatchCorbaException( S_ex );
190 aMess = tr( "SMESH_OPERATION_FAILED" );
191 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
197 //================================================================================
199 * \brief Creates dialog if necessary and shows it
201 * Virtual method redefined from base class called when operation is started creates
202 * dialog if necessary and shows it, activates selection
204 //================================================================================
205 void SMESHGUI_MeshOp::startOperation()
209 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
210 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
212 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
213 this, SLOT( onCreateHyp( const int, const int ) ) );
214 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
215 this, SLOT( onEditHyp( const int, const int ) ) );
216 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
217 this, SLOT( onAlgoSelected( const int ) ) );
219 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
220 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
223 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
224 else myHelpFileName = "constructing_submeshes_page.html";
225 else myHelpFileName = "editing_meshes_page.html";
227 SMESHGUI_SelectionOp::startOperation();
229 // iterate through dimensions and get available algoritms, set them to the dialog
230 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
231 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
233 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
235 // clear available hypotheses
236 aTab->setAvailableHyps( MainHyp, hypList );
237 aTab->setAvailableHyps( AddHyp, hypList );
238 aTab->setExistingHyps( MainHyp, hypList );
239 aTab->setExistingHyps( AddHyp, hypList );
240 myExistingHyps[ i ][ MainHyp ].clear();
241 myExistingHyps[ i ][ AddHyp ].clear();
243 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
244 aTab->setAvailableHyps( Algo, hypList );
249 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
252 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
254 myDlg->setCurrentTab( SMESH::DIM_3D );
256 myDlg->setGeomPopupEnabled(false);
259 myIgnoreAlgoSelection = false;
261 myObjectToSelect.clear();
264 //=================================================================================
266 * \brief Selects a recently created mesh or sub-mesh if necessary
268 * Virtual method redefined from base class called when operation is commited
269 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
270 * selection when the custom selection filters are removed.
272 //=================================================================================
273 void SMESHGUI_MeshOp::commitOperation()
275 SMESHGUI_SelectionOp::commitOperation();
277 if ( !myObjectToSelect.isEmpty() ) {
278 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
279 SUIT_DataOwnerPtrList aList;
280 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
281 aSelectionMgr->setSelected( aList );
286 //================================================================================
288 * \brief Creates selection filter
289 * \param theId - identifier of current selection widget
290 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
292 * Creates selection filter in accordance with identifier of current selection widget
294 //================================================================================
295 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
297 if ( theId == SMESHGUI_MeshDlg::Geom )
299 // TColStd_MapOfInteger allTypesMap;
300 // for ( int i = 0; i < 10; i++ )
301 // allTypesMap.Add( i );
302 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
303 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
305 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
306 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
307 else if ( theId == SMESHGUI_MeshDlg::Mesh )
308 return new SMESH_TypeFilter( SMESH::MESH );
313 //================================================================================
315 * \brief check if selected shape is a sub-shape of the shape to mesh
316 * \retval bool - check result
318 //================================================================================
319 bool SMESHGUI_MeshOp::isSubshapeOk() const
321 if ( !myToCreate || myIsMesh ) // not submesh creation
325 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
326 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
327 if (!pMesh) return false;
329 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
330 if (mesh->_is_nil()) return false;
332 // main shape of the mesh
333 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
334 if (mainGeom->_is_nil()) return false;
338 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
340 if (aGEOMs.count() > 0) {
341 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
342 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
343 if (geomGen->_is_nil() || !aStudy) return false;
345 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
346 if (op->_is_nil()) return false;
348 // check all selected shapes
349 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
350 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
351 QString aSubGeomEntry = (*aSubShapesIter);
352 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
353 if (!pSubGeom) return false;
355 GEOM::GEOM_Object_var aSubGeomVar =
356 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
357 if (aSubGeomVar->_is_nil()) return false;
359 // skl for NPAL14695 - implementation of searching of mainObj
360 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
361 mainObj already exists! */
363 if (mainObj->_is_nil())
365 CORBA::String_var entry1 = mainObj->GetEntry();
366 CORBA::String_var entry2 = mainGeom->GetEntry();
367 if (std::string( entry1.in() ) == entry2.in() )
369 mainObj = op->GetMainShape(mainObj);
377 //================================================================================
379 * \brief Return name of the algorithm that does not support submeshes and makes
380 * submesh creation useless
381 * \retval char* - string is to be deleted!!!
383 //================================================================================
384 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
386 if ( myToCreate && !myIsMesh ) {
388 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
389 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
390 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
393 QStringList algoNames;
395 existingHyps(3, Algo, pMesh, algoNames, algoList);
396 if (!algoList.empty()) {
397 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
399 algo->InputTypes.empty() && // builds all dimensions it-self
400 !algo->IsSupportSubmeshes )
401 return CORBA::string_dup( algoNames[0].toLatin1().data() );
404 // GEOM::GEOM_Object_var geom;
405 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
406 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
408 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
409 existingHyps(2, Algo, pMesh, algoNames, algoList);
410 if (!algoList.empty()) {
411 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
413 algo->InputTypes.empty() && // builds all dimensions it-self
414 !algo->IsSupportSubmeshes )
415 return CORBA::string_dup( algoNames[0].toLatin1().data() );
423 //================================================================================
425 * \brief find an existing submesh by the selected shape
426 * \retval _PTR(SObject) - the found submesh SObject
428 //================================================================================
429 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
431 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
432 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
433 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
434 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
435 if ( pMesh && pGeom ) {
436 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
437 if ( !geom->_is_nil() ) {
439 switch ( geom->GetShapeType() ) {
440 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
441 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
442 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
443 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
444 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
445 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
446 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
449 _PTR(GenericAttribute) anAttr;
450 _PTR(SObject) aSubmeshRoot;
451 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
452 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
454 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
455 for ( ; smIter->More(); smIter->Next() )
457 _PTR(SObject) aSmObj = smIter->Value();
458 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
460 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
461 for ( ; anIter1->More(); anIter1->Next()) {
462 _PTR(SObject) pGeom2 = anIter1->Value();
463 if ( pGeom2->ReferencedObject( pGeom2 ) &&
464 pGeom2->GetID() == pGeom->GetID() )
471 return _PTR(SObject)();
474 //================================================================================
476 * \brief Updates dialog's look and feel
478 * Virtual method redefined from the base class updates dialog's look and feel
480 //================================================================================
481 void SMESHGUI_MeshOp::selectionDone()
483 if (!dlg()->isVisible() || !myDlg->isEnabled())
486 SMESHGUI_SelectionOp::selectionDone();
490 myIsOnGeometry = true;
492 //Check geometry for mesh
493 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
494 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
497 SMESH::SMESH_Mesh_var aMeshVar =
498 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
499 if (!aMeshVar->_is_nil()) {
500 if (!myToCreate && !aMeshVar->HasShapeToMesh())
501 myIsOnGeometry = false;
507 // Enable tabs according to shape dimension
512 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
513 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
515 if (aGEOMs.count() > 0) {
516 // one or more GEOM shape selected
517 aSeq->length(aGEOMs.count());
518 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
520 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
521 QString aSubGeomEntry = (*aSubShapesIter);
522 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
523 GEOM::GEOM_Object_var aSubGeomVar =
524 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
525 aSeq[iSubSh] = aSubGeomVar;
528 // get geometry by selected sub-mesh
529 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
530 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
531 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
532 if (!aGeomVar->_is_nil()) {
538 if (aSeq->length() > 0) {
540 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
541 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
542 switch ( aGeomVar->GetShapeType() ) {
543 case GEOM::SOLID: shapeDim = 3; break;
545 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
547 // TopoDS_Shape aShape;
548 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
549 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
552 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
554 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
555 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
559 if (GEOMBase::GetShape(aGeomVar, aShape))
561 TopExp_Explorer exp (aShape, TopAbs_SOLID);
565 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
566 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
569 // for (; exp.More() && shapeDim == 2; exp.Next()) {
570 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
574 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
575 shapeDim = qMax(2, shapeDim);
576 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
577 shapeDim = qMax(1, shapeDim);
578 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
579 shapeDim = qMax(0, shapeDim);
587 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
588 // reset algos before disabling tabs (0020138)
589 onAlgoSelected(-1, i);
591 myDlg->setMaxHypoDim( shapeDim );
592 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
594 if (!myToCreate) // edition: read hypotheses
598 SMESH::SMESH_subMesh_var aVar =
599 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
600 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
601 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
602 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
603 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
604 myDlg->updateGeometry();
611 else if ( !myIsMesh ) // submesh creation
613 // if a submesh on the selected shape already exist, pass to submesh edition mode
614 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
615 SMESH::SMESH_subMesh_var sm =
616 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
617 bool editSubmesh = ( !sm->_is_nil() &&
618 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
619 tr( "EDIT_SUBMESH_QUESTION"),
620 SUIT_MessageBox::Yes |
622 SUIT_MessageBox::No )
623 == SUIT_MessageBox::Yes );
626 selectionMgr()->clearFilters();
627 selectObject( pSubmesh );
628 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
633 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
634 selectObject( _PTR(SObject)() );
639 // discard selected mesh if submesh creation not allowed because of
640 // a global algorithm that does not support submeshes
641 if ( char* algoName = isSubmeshIgnored() ) {
642 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
643 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
644 CORBA::string_free( algoName );
645 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
646 selectObject( _PTR(SObject)() );
651 // enable/disable popup for choice of geom selection way
653 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
654 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
655 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
656 if ( !mesh->_is_nil() ) {
657 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
658 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
659 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
660 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
661 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
662 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
665 myDlg->setGeomPopupEnabled( enable );
668 else { // no geometry defined
669 myDlg->enableTab( SMESH::DIM_3D );
671 availableHyps( SMESH::DIM_3D, Algo, hypList,
672 myAvailableHypData[SMESH::DIM_3D][Algo]);
674 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
675 aTab->setAvailableHyps( Algo, hypList );
676 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
677 myDlg->disableTab(i);
679 //Hide labels and fields (Mesh ang Geometry)
680 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
681 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
686 catch ( const SALOME::SALOME_Exception& S_ex )
688 SalomeApp_Tools::QtCatchCorbaException( S_ex );
695 //================================================================================
697 * \brief Verifies validity of input data
698 * \param theMess - Output parameter intended for returning error message
699 * \retval bool - TRUE if input data is valid, false otherwise
701 * Verifies validity of input data. This method is called when "Apply" or "OK" button
702 * is pressed before mesh creation or editing.
704 //================================================================================
705 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
707 // Selected object to be edited
708 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
710 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
715 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
716 if ( aMeshName.isEmpty() )
718 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
722 /* // Imported mesh, if create sub-mesh or edit mesh
723 if ( !myToCreate || ( myToCreate && !myIsMesh ))
725 QString aMeshEntry = myDlg->selectedObject
726 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
727 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
728 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
729 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
730 theMess = tr( "IMPORTED_MESH" );
739 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
740 if ( aGeomEntry == "" )
742 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
744 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
745 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
752 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
753 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
755 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
760 if ( !myIsMesh ) // i.e sub-mesh creation,
762 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
763 if ( aMeshEntry == "" )
765 theMess = tr( "MESH_IS_NOT_DEFINED" );
768 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
769 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
771 theMess = tr( "MESH_IS_NULL" );
774 if ( !isSubshapeOk() )
776 theMess = tr( "INVALID_SUBSHAPE" );
785 //================================================================================
787 * \brief check compatibility of the algorithm and another algorithm or hypothesis
788 * \param theAlgoData - algorithm data
789 * \param theHypData - hypothesis data
790 * \param theHypType - hypothesis type
791 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
792 * \retval bool - check result
794 //================================================================================
795 static bool isCompatible(const HypothesisData* theAlgoData,
796 const HypothesisData* theHypData,
797 const int theHypType)
802 if ( theHypType == SMESHGUI_MeshOp::Algo )
803 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
806 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
809 //================================================================================
811 * \brief Gets available hypotheses or algorithms
812 * \param theDim - specifies dimension of returned hypotheses/algorifms
813 * \param theHypType - specifies whether algorims or hypotheses or additional ones
814 * are retrieved (possible values are in HypType enumeration)
815 * \param theHyps - Output list of hypotheses' names
816 * \param theAlgoData - to select hypos able to be used by this algo (optional)
818 * Gets available hypotheses or algorithm in accordance with input parameters
820 //================================================================================
821 void SMESHGUI_MeshOp::availableHyps( const int theDim,
822 const int theHypType,
823 QStringList& theHyps,
824 THypDataList& theDataList,
825 HypothesisData* theAlgoData ) const
829 bool isAlgo = ( theHypType == Algo );
830 bool isAux = ( theHypType == AddHyp );
831 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
833 QStringList::const_iterator anIter;
834 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
836 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
837 if ( isCompatible ( theAlgoData, aData, theHypType )) {
838 theDataList.append( aData );
839 theHyps.append( aData->Label );
844 //================================================================================
846 * \brief Gets existing hypotheses or algorithms
847 * \param theDim - specifies dimension of returned hypotheses/algorifms
848 * \param theHypType - specifies whether algorims or hypotheses or additional ones
849 * are retrieved (possible values are in HypType enumeration)
850 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
851 * \param theHyps - output list of names.
852 * \param theHypVars - output list of variables.
853 * \param theAlgoData - to select hypos able to be used by this algo (optional)
855 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
858 //================================================================================
859 void SMESHGUI_MeshOp::existingHyps( const int theDim,
860 const int theHypType,
861 _PTR(SObject) theFather,
862 QStringList& theHyps,
863 THypList& theHypList,
864 HypothesisData* theAlgoData)
866 // Clear hypoheses list
873 const bool isAux = ( theHypType == AddHyp );
875 _PTR(SObject) aHypRoot;
876 _PTR(GenericAttribute) anAttr;
877 _PTR(AttributeName) aName;
878 _PTR(AttributeIOR) anIOR;
880 bool isMesh = !_CAST( SComponent, theFather );
883 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
885 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
887 if ( theFather->FindSubObject( aPart, aHypRoot ) )
889 _PTR(ChildIterator) anIter =
890 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
891 for ( ; anIter->More(); anIter->Next() )
893 _PTR(SObject) anObj = anIter->Value();
894 if ( isMesh ) // i.e. mesh or submesh
896 _PTR(SObject) aRefObj;
897 if ( anObj->ReferencedObject( aRefObj ) )
902 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
905 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
906 if ( !CORBA::is_nil( aVar ) )
908 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
909 if ( !aHypVar->_is_nil() )
911 CORBA::String_var hypType = aHypVar->GetName();
912 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
913 if ( !aData) continue;
914 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
915 ( isCompatible ( theAlgoData, aData, theHypType )) &&
916 ( isAux == aData->IsAux ))
918 std::string aHypName = aName->Value();
919 theHyps.append( aHypName.c_str() );
920 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
929 //================================================================================
931 * \brief If create or edit a submesh, return a hypothesis holding parameters used
932 * to mesh a sub-shape
933 * \param aHypType - The hypothesis type name
934 * \param aServerLib - Server library name
935 * \param hypData - The structure holding the hypothesis type etc.
936 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
938 //================================================================================
939 SMESH::SMESH_Hypothesis_var
940 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
941 const QString& aServerLib ) const
943 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
944 return SMESH::SMESH_Hypothesis::_nil();
946 const int nbColonsInMeshEntry = 3;
947 bool isSubMesh = myToCreate ?
949 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
951 // get mesh and geom object
952 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
953 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
958 anEntry = myDlg->selectedObject
959 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
960 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
962 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
963 if ( myToCreate ) // mesh and geom may be selected
965 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
966 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
967 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
968 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
970 else // edition: sub-mesh may be selected
972 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
973 if ( !sm->_is_nil() ) {
974 aMeshVar = sm->GetFather();
975 aGeomVar = sm->GetSubShape();
982 if ( !myToCreate ) // mesh to edit can be selected
984 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
985 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
987 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
988 if ( !aMeshVar->_is_nil() )
989 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
992 if ( aGeomVar->_is_nil() ) {
993 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
994 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
996 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1001 SMESH::SMESH_Hypothesis_var hyp =
1002 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1003 aServerLib.toLatin1().data(),
1006 /*byMesh = */isSubMesh);
1007 if ( hyp->_is_nil() && isSubMesh )
1008 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1009 aServerLib.toLatin1().data(),
1012 /*byMesh = */false);
1016 //================================================================================
1018 * \Brief Returns tab dimention
1019 * \param tab - the tab in the dlg
1020 * \param dlg - my dialogue
1021 * \retval int - dimention
1023 //================================================================================
1024 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1027 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1028 if (tab == dlg->tab(i))
1033 //================================================================================
1035 * \brief Create hypothesis
1036 * \param theHypType - hypothesis category (main or additional)
1037 * \param theIndex - index of type of hypothesis to be cerated
1039 * Specifies dimension of hypothesis to be created (using sender() method),
1040 * specifies its type and calls method for hypothesis creation
1042 //================================================================================
1043 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1045 // Specifies dimension of hypothesis to be created
1046 int aDim = getTabDim( sender(), myDlg );
1050 // Specifies type of hypothesis to be created
1051 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1052 if (theIndex < 0 || theIndex >= dataList.count())
1054 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1056 // Create hypothesis
1057 createHypothesis(aDim, theHypType, aHypTypeName);
1062 QString GetUniqueName (const QStringList& theHypNames,
1063 const QString& theName,
1064 size_t theIteration = 1)
1066 QString aName = theName + "_" + QString::number( theIteration );
1067 if ( theHypNames.contains( aName ) )
1068 return GetUniqueName( theHypNames, theName, ++theIteration );
1073 //================================================================================
1075 * Create hypothesis and update dialog.
1076 * \param theDim - dimension of hypothesis to be created
1077 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1078 * \param theTypeName - specifies hypothesis to be created
1080 //================================================================================
1081 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1083 const QString& theTypeName)
1085 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1091 QStringList aHypNames;
1092 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1093 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1094 const TType2HypList& aType2HypList = aDimIter.value();
1095 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1096 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1097 const THypList& aHypList = aTypeIter.value();
1098 THypList::const_iterator anIter = aHypList.begin();
1099 for ( ; anIter != aHypList.end(); anIter++) {
1100 const THypItem& aHypItem = *anIter;
1101 const QString& aHypName = aHypItem.second;
1102 aHypNames.append(aHypName);
1106 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1109 bool dialog = false;
1111 QString aClientLibName = aData->ClientLibName;
1112 if (aClientLibName == "") {
1113 // Call hypothesis creation server method (without GUI)
1114 SMESH::SMESH_Hypothesis_var aHyp =
1115 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1119 // Get hypotheses creator client (GUI)
1120 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1122 // Create hypothesis
1124 // Get parameters appropriate to initialize a new hypothesis
1125 SMESH::SMESH_Hypothesis_var initParamHyp =
1126 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1128 removeCustomFilters(); // Issue 0020170
1130 // Get Entry of the Geom object
1131 QString aGeomEntry = "";
1132 QString aMeshEntry = "";
1133 QString anObjEntry = "";
1134 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1135 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1136 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1138 if ( myToCreate && myIsMesh )
1139 aMeshEntry = aGeomEntry;
1141 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1142 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1143 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1144 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1147 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1148 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1150 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1151 if ( !aGeomVar->_is_nil() )
1153 aGeomEntry = aGeomVar->GetStudyEntry();
1155 aMeshEntry = aGeomEntry;
1159 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1160 // take geometry from submesh being created
1161 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1163 // if current object is sub-mesh
1164 SMESH::SMESH_subMesh_var aSubMeshVar =
1165 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1166 if ( !aSubMeshVar->_is_nil() ) {
1167 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1168 if ( !aMeshVar->_is_nil() ) {
1169 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1170 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1171 if ( !aGeomVar->_is_nil() )
1172 aMeshEntry = aGeomVar->GetStudyEntry();
1178 aCreator->setShapeEntry( aGeomEntry );
1179 if ( aMeshEntry != "" )
1180 aCreator->setMainShapeEntry( aMeshEntry );
1181 myDlg->setEnabled( false );
1182 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1186 SMESH::SMESH_Hypothesis_var aHyp =
1187 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1196 //================================================================================
1198 * Necessary steps after hypothesis creation
1199 * \param result - creation result:
1202 * 2 = additional value meaning that slot is called not from dialog box
1204 //================================================================================
1205 void SMESHGUI_MeshOp::onHypoCreated( int result )
1209 int obj = myDlg->getActiveObject();
1210 onActivateObject( obj ); // Issue 0020170. Restore filters
1211 myDlg->setEnabled( true );
1214 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1216 int nbHyp = myExistingHyps[myDim][myType].count();
1217 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1218 QStringList aNewHyps;
1219 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1220 if (aNewHyps.count() > nbHyp)
1222 for (int i = nbHyp; i < aNewHyps.count(); i++)
1223 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1226 if( result!=2 && myHypoSet )
1230 //================================================================================
1232 * \brief Calls plugin methods for hypothesis editing
1233 * \param theHypType - specifies whether main hypothesis or additional one
1235 * \param theIndex - index of existing hypothesis
1237 * Calls plugin methods for hypothesis editing
1239 //================================================================================
1240 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1242 // Speicfies dimension of hypothesis to be created
1243 int aDim = getTabDim( sender(), myDlg );
1247 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1248 if ( theIndex < 0 || theIndex >= aList.count() )
1250 const THypItem& aHypItem = aList[ theIndex ];
1251 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1252 if ( aHyp->_is_nil() )
1255 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1258 // Get initial parameters
1259 SMESH::SMESH_Hypothesis_var initParamHyp =
1260 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1261 aCreator->setInitParamsHypothesis( initParamHyp );
1263 // Get Entry of the Geom object
1264 QString aGeomEntry = "";
1265 QString aMeshEntry = "";
1266 QString anObjEntry = "";
1267 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1268 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1269 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1271 if ( myToCreate && myIsMesh )
1272 aMeshEntry = aGeomEntry;
1274 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1275 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1276 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1277 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1280 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1281 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1283 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1284 if ( !aGeomVar->_is_nil() )
1286 aGeomEntry = aGeomVar->GetStudyEntry();
1288 aMeshEntry = aGeomEntry;
1292 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1293 // take geometry from submesh being created
1294 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1296 // if current object is sub-mesh
1297 SMESH::SMESH_subMesh_var aSubMeshVar =
1298 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1299 if ( !aSubMeshVar->_is_nil() ) {
1300 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1301 if ( !aMeshVar->_is_nil() ) {
1302 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1303 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1304 if ( !aGeomVar->_is_nil() )
1305 aMeshEntry = aGeomVar->GetStudyEntry();
1311 aCreator->setShapeEntry( aGeomEntry );
1312 if ( aMeshEntry != "" )
1313 aCreator->setMainShapeEntry( aMeshEntry );
1314 removeCustomFilters(); // Issue 0020170
1315 myDlg->setEnabled( false );
1316 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1320 //================================================================================
1322 * Necessary steps after hypothesis edition
1323 * \param result - creation result:
1327 //================================================================================
1328 void SMESHGUI_MeshOp::onHypoEdited( int result )
1330 int obj = myDlg->getActiveObject();
1331 onActivateObject( obj ); // Issue 0020170. Restore filters
1332 myDlg->setEnabled( true );
1335 //================================================================================
1337 * \brief access to hypothesis data
1338 * \param theDim - hyp dimension
1339 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1340 * \param theIndex - index in the list
1341 * \retval HypothesisData* - result data, may be 0
1343 //================================================================================
1344 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1345 const int theHypType,
1348 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1349 theHypType > -1 && theHypType < NbHypTypes &&
1350 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1351 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1355 //================================================================================
1357 * \brief Set available algos and hypos according to the selected algorithm
1358 * \param theIndex - algorithm index
1360 //================================================================================
1361 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1364 if ( myIgnoreAlgoSelection )
1367 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1371 // find highest available dimension, all algos of this dimension are available for choice
1373 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1374 if (isAccessibleDim( i ))
1379 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1381 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1382 HypothesisData* algoByDim[4];
1383 algoByDim[ aDim ] = algoData;
1385 QStringList anAvailable;
1386 if ( !algoData ) { // all algos becomes available
1387 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1388 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1391 // check that algorithms of other dimentions are compatible with
1394 // 2 loops: backward and forward from algo dimension
1395 for ( int forward = false; forward <= true; ++forward )
1397 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1399 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1401 HypothesisData* prevAlgo = algoData;
1402 bool noCompatible = false;
1403 for ( ; dim * dir <= lastDim * dir; dim += dir)
1405 if ( !isAccessibleDim( dim ))
1407 if ( noCompatible ) { // the selected algo has no compatible ones
1408 anAvailable.clear();
1409 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1410 myAvailableHypData[dim][Algo].clear();
1411 algoByDim[ dim ] = 0;
1414 // get currently selected algo
1415 int algoIndex = currentHyp( dim, Algo );
1416 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1417 if ( curAlgo ) { // some algo selected
1418 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1421 // set new available algoritms
1422 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1423 HypothesisData* soleCompatible = 0;
1424 if ( anAvailable.count() == 1 )
1425 soleCompatible = myAvailableHypData[dim][Algo][0];
1426 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1427 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1428 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1429 noCompatible = anAvailable.isEmpty();
1431 // restore previously selected algo
1432 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1433 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1434 // select the sole compatible algo
1435 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1436 setCurrentHyp( dim, Algo, algoIndex );
1438 // remember current algo
1439 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1443 // set hypotheses corresponding to the found algoritms
1445 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1447 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1449 if ( !isAccessibleDim( dim ))
1451 for ( int type = MainHyp; type < NbHypTypes; type++ )
1453 myAvailableHypData[ dim ][ type ].clear();
1454 QStringList anAvailable, anExisting;
1456 HypothesisData* curAlgo = algoByDim[ dim ];
1457 int hypIndex = currentHyp( dim, type );
1459 SMESH::SMESH_Hypothesis_var curHyp;
1460 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1461 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1463 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1464 // try to find algo by selected hypothesis in order to keep it selected
1465 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1466 CORBA::String_var curHypType = curHyp->GetName();
1467 if ( !algoDeselectedByUser &&
1468 myObjHyps[ dim ][ type ].count() > 0 &&
1469 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1471 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1472 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1473 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1474 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1481 // get hyps compatible with curAlgo
1484 // check if a selected hyp is compatible with the curAlgo
1485 if ( !curHyp->_is_nil() ) {
1486 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1487 if ( !isCompatible( curAlgo, hypData, type ))
1488 curHyp = SMESH::SMESH_Hypothesis::_nil();
1490 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1491 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1493 // set list of hypotheses
1494 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1495 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1497 // set current existing hypothesis
1498 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1499 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1502 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1503 // none is yet selected => select the sole existing if it is not optional
1504 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1505 bool isOptional = true;
1506 if ( algoByDim[ dim ] &&
1507 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1511 setCurrentHyp( dim, type, hypIndex );
1516 //================================================================================
1518 * \brief Creates and selects hypothesis of hypotheses set
1519 * \param theSetName - The name of hypotheses set
1521 //================================================================================
1522 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1524 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1529 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1530 setCurrentHyp(dim, Algo, -1);
1531 setCurrentHyp(dim, AddHyp, -1);
1532 setCurrentHyp(dim, MainHyp, -1);
1535 myHypoSet->init(true); //algorithms
1537 myHypoSet->init(false); //hypotheses
1542 //================================================================================
1544 * \brief One step of hypothesis/algorithm list creation
1546 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1548 //================================================================================
1549 void SMESHGUI_MeshOp::processSet()
1552 if( !myHypoSet->more() )
1555 bool isAlgo = myHypoSet->isAlgo();
1556 QString aHypoTypeName = myHypoSet->current();
1557 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1564 int aDim = aHypData->Dim[0];
1565 // create or/and set
1568 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1571 QStringList anAvailable;
1572 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1573 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1574 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1576 setCurrentHyp( aDim, Algo, index );
1577 onAlgoSelected( index, aDim );
1582 bool mainHyp = true;
1583 QStringList anAvailable;
1584 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1585 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1586 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1590 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1593 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1599 //================================================================================
1601 * \brief Creates mesh
1602 * \param theMess - Output parameter intended for returning error message
1603 * \param theEntryList - List of entries of published objects
1604 * \retval bool - TRUE if mesh is created, FALSE otherwise
1608 //================================================================================
1609 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1613 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1614 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1617 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1618 if ( aList.isEmpty() )
1620 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1621 if ( aSMESHGen->_is_nil() )
1624 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1625 if ( aMeshVar->_is_nil() )
1628 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1630 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1631 theEntryList.append( aMeshSO->GetID().c_str() );
1635 QStringList::Iterator it = aList.begin();
1636 for ( ; it!=aList.end(); it++)
1638 QString aGeomEntry = *it;
1639 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1640 GEOM::GEOM_Object_var aGeomVar =
1641 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1643 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1644 if ( aSMESHGen->_is_nil() )
1647 SUIT_OverrideCursor aWaitCursor;
1650 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1651 if ( aMeshVar->_is_nil() )
1653 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1655 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1656 theEntryList.append( aMeshSO->GetID().c_str() );
1659 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1660 if ( !isAccessibleDim( aDim )) continue;
1662 // assign hypotheses
1663 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1664 int aHypIndex = currentHyp( aDim, aHypType );
1665 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1666 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1667 if ( !aHypVar->_is_nil() )
1668 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1671 // find or create algorithm
1672 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1673 if ( !anAlgoVar->_is_nil() )
1674 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1680 //================================================================================
1682 * \brief Creates sub-mesh
1683 * \param theMess - Output parameter intended for returning error message
1684 * \param theEntryList - List of entries of published objects
1685 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1689 //================================================================================
1690 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1694 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1695 if ( aSMESHGen->_is_nil() )
1699 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1700 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1701 SMESH::SMESH_Mesh_var aMeshVar =
1702 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1703 if (aMeshVar->_is_nil())
1706 // GEOM shape of the main mesh
1707 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1709 // Name for the new sub-mesh
1710 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1713 GEOM::GEOM_Object_var aGeomVar;
1715 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1716 if (aGEOMs.count() == 1)
1718 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1719 QString aGeomEntry = aGEOMs.first();
1720 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1721 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1723 else if (aGEOMs.count() > 1)
1725 // create a GEOM group
1726 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1727 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1728 if (!geomGen->_is_nil() && aStudy) {
1729 GEOM::GEOM_IGroupOperations_wrap op =
1730 geomGen->GetIGroupOperations(aStudy->StudyId());
1731 if (!op->_is_nil()) {
1732 // check and add all selected GEOM objects: they must be
1733 // a sub-shapes of the main GEOM and must be of one type
1735 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1736 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1737 aSeq->length(aGEOMs.count());
1738 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1739 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1740 QString aSubGeomEntry = (*aSubShapesIter);
1741 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1742 GEOM::GEOM_Object_var aSubGeomVar =
1743 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1744 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1746 aGroupType = aSubShapeType;
1748 if (aSubShapeType != aGroupType)
1749 aGroupType = TopAbs_SHAPE;
1751 aSeq[iSubSh] = aSubGeomVar;
1754 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1755 op->UnionList(aGroupVar, aSeq);
1759 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1761 // publish the GEOM group in study
1762 QString aNewGeomGroupName ("Auto_group_for_");
1763 aNewGeomGroupName += aName;
1764 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1765 SALOMEDS::SObject_wrap aNewGroupSO =
1766 geomGen->AddInStudy( aStudyVar, aGeomVar,
1767 aNewGeomGroupName.toLatin1().data(), mainGeom);
1774 if (aGeomVar->_is_nil())
1777 SUIT_OverrideCursor aWaitCursor;
1780 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1781 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1783 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1784 theEntryList.append( aSubMeshSO->GetID().c_str() );
1787 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1789 if ( !isAccessibleDim( aDim )) continue;
1791 // find or create algorithm
1792 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1793 if ( !anAlgoVar->_is_nil() )
1794 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1795 // assign hypotheses
1796 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1798 int aHypIndex = currentHyp( aDim, aHypType );
1799 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1801 SMESH::SMESH_Hypothesis_var aHypVar =
1802 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1803 if ( !aHypVar->_is_nil() )
1804 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1809 // deselect geometry: next submesh should be created on other sub-shape
1810 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1811 selectObject( _PTR(SObject)() );
1817 //================================================================================
1819 * \brief Gets current hypothesis or algorithms
1820 * \param theDim - dimension of hypothesis or algorithm
1821 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1822 * \retval int - current hypothesis or algorithms
1824 * Gets current hypothesis or algorithms
1826 //================================================================================
1827 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1829 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1832 //================================================================================
1834 * \brief Returns true if hypotheses of given dim can be assigned
1835 * \param theDim - hypotheses dimension
1836 * \retval bool - result
1838 //================================================================================
1839 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1841 return myDlg->isTabEnabled( theDim );
1844 //================================================================================
1846 * \brief Sets current hypothesis or algorithms
1847 * \param theDim - dimension of hypothesis or algorithm
1848 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1849 * \param theIndex - Index of hypothesis
1851 * Gets current hypothesis or algorithms
1853 //================================================================================
1854 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1855 const int theHypType,
1856 const int theIndex )
1858 myIgnoreAlgoSelection = true;
1859 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1860 myIgnoreAlgoSelection = false;
1863 //================================================================================
1865 * \brief Generates default and sets mesh/submesh name
1867 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1869 //================================================================================
1870 void SMESHGUI_MeshOp::setDefaultName() const
1874 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1876 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1877 _PTR(SObject) anObj;
1880 aResName = aPrefix + QString::number( i++ );
1881 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1885 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1886 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1887 aControl->setText( aResName );
1890 //================================================================================
1892 * \brief Gets algorithm or creates it if necessary
1893 * \param theDim - specifies dimension of returned hypotheses/algorifms
1894 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1896 * Gets algorithm or creates it if necessary
1898 //================================================================================
1899 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1901 SMESH::SMESH_Hypothesis_var anAlgoVar;
1903 // get type of the selected algo
1904 int aHypIndex = currentHyp( theDim, Algo );
1905 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1906 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1908 QString aHypName = dataList[ aHypIndex ]->TypeName;
1910 // get existing algoritms
1911 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1913 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1915 // look for an existing algo of such a type
1916 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1917 THypList::iterator anIter = aHypVarList.begin();
1918 for ( ; anIter != aHypVarList.end(); anIter++)
1920 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1921 CORBA::String_var aName = aHypVar->GetName();
1922 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1924 anAlgoVar = aHypVar;
1929 if (anAlgoVar->_is_nil())
1931 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1934 QString aClientLibName = aHypData->ClientLibName;
1935 if ( aClientLibName.isEmpty() )
1937 // Call hypothesis creation server method (without GUI)
1938 SMESH::SMESH_Hypothesis_var aHyp =
1939 SMESH::CreateHypothesis(aHypName, aHypName, true);
1944 // Get hypotheses creator client (GUI)
1945 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1949 aCreator->create( true, aHypName, myDlg, 0, QString::null );
1951 SMESH::SMESH_Hypothesis_var aHyp =
1952 SMESH::CreateHypothesis(aHypName, aHypName, true);
1956 QStringList tmpList;
1957 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1958 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1961 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1962 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1964 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1965 CORBA::String_var aName = aHypVar->GetName();
1966 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1968 anAlgoVar = aHypVar;
1974 return anAlgoVar._retn();
1977 //================================================================================
1979 * \brief Reads parameters of an edited mesh and assigns them to the dialog
1981 * Called when mesh is edited only.
1983 //================================================================================
1984 void SMESHGUI_MeshOp::readMesh()
1986 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1987 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1991 if (myIsOnGeometry) {
1992 // Get name of mesh if current object is sub-mesh
1993 SMESH::SMESH_subMesh_var aSubMeshVar =
1994 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1995 if ( !aSubMeshVar->_is_nil() )
1997 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1998 if ( !aMeshVar->_is_nil() )
2000 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2001 QString aMeshName = name( aMeshSO );
2002 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2006 // Get name of geometry object
2007 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2008 if ( !aGeomVar->_is_nil() )
2010 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2011 QString aShapeName = name( aGeomSO );
2012 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2016 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2017 QStringList anExisting;
2018 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2019 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2022 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2023 // find algo index among available ones
2025 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2027 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2028 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2029 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2030 // if ( aHypIndex < 0 && algoData ) {
2031 // // assigned algo is incompatible with other algorithms
2032 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2033 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2036 setCurrentHyp( dim, Algo, aHypIndex );
2037 // set existing and available hypothesis according to the selected algo
2038 onAlgoSelected( aHypIndex, dim );
2042 bool hypWithoutAlgo = false;
2043 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2045 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2048 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2049 // find index of requered hypothesis among existing ones for this dimension and type
2051 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2052 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2053 myExistingHyps[ dim ][ hypType ] );
2054 if ( aHypIndex < 0 ) {
2055 // assigned hypothesis is incompatible with the algorithm
2056 if ( currentHyp( dim, Algo ) < 0 )
2057 { // none algo selected; it is edition for sure, of submesh maybe
2058 hypWithoutAlgo = true;
2059 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2060 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2061 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2065 setCurrentHyp( dim, hypType, aHypIndex );
2068 // make available other hyps of same type as one without algo
2069 if ( hypWithoutAlgo )
2070 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2073 //================================================================================
2075 * \brief Gets name of object
2076 * \param theSO - SObject
2077 * \retval QString - name of object
2079 * Gets name of object
2081 //================================================================================
2082 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2087 _PTR(GenericAttribute) anAttr;
2088 _PTR(AttributeName) aNameAttr;
2089 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2092 aResName = aNameAttr->Value().c_str();
2098 //================================================================================
2100 * \brief Finds hypothesis in input list
2101 * \param theHyp - hypothesis to be found
2102 * \param theHypList - input list of hypotheses
2103 * \retval int - index of hypothesis or -1 if it is not found
2105 * Finds position of hypothesis in input list
2107 //================================================================================
2108 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2109 const THypList& theHypList ) const
2112 if ( !theHyp->_is_nil() )
2115 THypList::const_iterator anIter = theHypList.begin();
2116 for ( ; anIter != theHypList.end(); ++ anIter)
2118 if ( theHyp->_is_equivalent( (*anIter).first ) )
2129 //================================================================================
2131 * \brief Edits mesh or sub-mesh
2132 * \param theMess - Output parameter intended for returning error message
2133 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2135 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2137 //================================================================================
2138 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2142 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2143 if ( aSMESHGen->_is_nil() )
2146 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2147 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2151 SUIT_OverrideCursor aWaitCursor;
2154 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2155 SMESH::SetName( pObj, aName );
2156 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2158 // First, remove old algos in order to avoid messages on algorithm hiding
2159 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2161 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2163 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2164 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2165 if ( anAlgoVar->_is_nil() || // no new algo selected or
2166 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2168 // remove old algorithm
2169 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2170 myObjHyps[ dim ][ Algo ].clear();
2175 // Assign new algorithms and hypotheses
2176 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2178 if ( !isAccessibleDim( dim )) continue;
2180 // find or create algorithm
2181 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2183 // assign new algorithm
2184 if ( !anAlgoVar->_is_nil() && // some algo selected and
2185 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2187 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2188 CORBA::Object_var anObject = aSObject->GetObject();
2189 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2190 bool isMesh = !aMeshVar->_is_nil();
2192 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2194 SMESH::SMESH_subMesh_var aVar =
2195 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2196 if ( !aVar->_is_nil() )
2197 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2199 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2202 // assign hypotheses
2203 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2205 int aNewHypIndex = currentHyp( dim, hypType );
2206 int anOldHypIndex = -1;
2208 // remove old hypotheses
2209 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2211 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2212 myExistingHyps[ dim ][ hypType ] );
2213 if ( aNewHypIndex != anOldHypIndex || // different hyps
2214 anOldHypIndex == -1 ) // hyps of different algos
2216 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2217 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2218 myObjHyps[ dim ][ hypType ].clear();
2222 // assign new hypotheses
2223 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2225 SMESH::SMESH_Mesh_var aMeshVar =
2226 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2227 bool isMesh = !aMeshVar->_is_nil();
2230 SMESH::AddHypothesisOnMesh
2231 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2235 SMESH::SMESH_subMesh_var aVar =
2236 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2237 if ( !aVar->_is_nil() )
2238 SMESH::AddHypothesisOnSubMesh
2239 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2242 // reread all hypotheses of mesh if necessary
2243 QStringList anExisting;
2244 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2251 //================================================================================
2253 * \brief Verifies whether given operator is valid for this one
2254 * \param theOtherOp - other operation
2255 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2257 * method redefined from base class verifies whether given operator is valid for
2258 * this one (i.e. can be started "above" this operator). In current implementation method
2259 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2262 //================================================================================
2263 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2265 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2268 //================================================================================
2270 * \brief SLOT. Is called when the user selects a way of geometry selection
2271 * \param theByMesh - true if the user wants to find geometry by mesh element
2273 //================================================================================
2274 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2277 if ( !myShapeByMeshOp ) {
2278 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2279 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2280 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2281 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2282 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2284 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2285 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2286 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2287 SMESH::SMESH_Mesh_var aMeshVar =
2288 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2289 if ( !aMeshVar->_is_nil() ) {
2290 myDlg->hide(); // stop processing selection
2291 myShapeByMeshOp->setModule( getSMESHGUI() );
2292 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2293 myShapeByMeshOp->SetMesh( aMeshVar );
2294 myShapeByMeshOp->start();
2300 //================================================================================
2302 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2304 //================================================================================
2305 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2307 if ( myShapeByMeshOp == op ) {
2308 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2310 // Select a found geometry object
2311 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2312 if ( !aGeomVar->_is_nil() )
2314 QString ID = aGeomVar->GetStudyEntry();
2315 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2316 selectObject( aGeomSO );
2323 //================================================================================
2325 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2327 //================================================================================
2328 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2330 if ( myShapeByMeshOp == op && myDlg ) {
2335 //================================================================================
2337 * \brief Selects a SObject
2338 * \param theSObj - the SObject to select
2340 //================================================================================
2341 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2343 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2344 SALOME_ListIO anIOList;
2346 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2347 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2348 anIOList.Append( anIO );
2350 sm->setSelectedObjects( anIOList, false );