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 );
145 bool aResult = false;
149 QStringList anEntryList;
150 if ( myToCreate && myIsMesh )
151 aResult = createMesh( aMess, anEntryList );
152 if ( myToCreate && !myIsMesh )
153 aResult = createSubMesh( aMess, anEntryList );
154 else if ( !myToCreate )
155 aResult = editMeshOrSubMesh( aMess );
158 SMESHGUI::Modified();
159 update( UF_ObjBrowser | UF_Model );
160 if( LightApp_Application* anApp =
161 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
162 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
165 catch ( const SALOME::SALOME_Exception& S_ex )
167 SalomeApp_Tools::QtCatchCorbaException( S_ex );
183 aMess = tr( "SMESH_OPERATION_FAILED" );
184 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
190 //================================================================================
192 * \brief Creates dialog if necessary and shows it
194 * Virtual method redefined from base class called when operation is started creates
195 * dialog if necessary and shows it, activates selection
197 //================================================================================
198 void SMESHGUI_MeshOp::startOperation()
202 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
203 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
205 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
206 this, SLOT( onCreateHyp( const int, const int ) ) );
207 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
208 this, SLOT( onEditHyp( const int, const int ) ) );
209 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
210 this, SLOT( onAlgoSelected( const int ) ) );
212 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
213 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
216 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
217 else myHelpFileName = "constructing_submeshes_page.html";
218 else myHelpFileName = "editing_meshes_page.html";
220 SMESHGUI_SelectionOp::startOperation();
222 // iterate through dimensions and get available algoritms, set them to the dialog
223 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
224 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
226 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
228 // clear available hypotheses
229 aTab->setAvailableHyps( MainHyp, hypList );
230 aTab->setAvailableHyps( AddHyp, hypList );
231 aTab->setExistingHyps( MainHyp, hypList );
232 aTab->setExistingHyps( AddHyp, hypList );
233 myExistingHyps[ i ][ MainHyp ].clear();
234 myExistingHyps[ i ][ AddHyp ].clear();
236 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
237 aTab->setAvailableHyps( Algo, hypList );
242 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
245 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
247 myDlg->setCurrentTab( SMESH::DIM_3D );
249 myDlg->setGeomPopupEnabled(false);
252 myIgnoreAlgoSelection = false;
254 myObjectToSelect.clear();
257 //=================================================================================
259 * \brief Selects a recently created mesh or sub-mesh if necessary
261 * Virtual method redefined from base class called when operation is commited
262 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
263 * selection when the custom selection filters are removed.
265 //=================================================================================
266 void SMESHGUI_MeshOp::commitOperation()
268 SMESHGUI_SelectionOp::commitOperation();
270 if ( !myObjectToSelect.isEmpty() ) {
271 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
272 SUIT_DataOwnerPtrList aList;
273 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
274 aSelectionMgr->setSelected( aList );
279 //================================================================================
281 * \brief Creates selection filter
282 * \param theId - identifier of current selection widget
283 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
285 * Creates selection filter in accordance with identifier of current selection widget
287 //================================================================================
288 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
290 if ( theId == SMESHGUI_MeshDlg::Geom )
292 // TColStd_MapOfInteger allTypesMap;
293 // for ( int i = 0; i < 10; i++ )
294 // allTypesMap.Add( i );
295 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
296 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
298 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
299 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
300 else if ( theId == SMESHGUI_MeshDlg::Mesh )
301 return new SMESH_TypeFilter( SMESH::MESH );
306 //================================================================================
308 * \brief check if selected shape is a sub-shape of the shape to mesh
309 * \retval bool - check result
311 //================================================================================
312 bool SMESHGUI_MeshOp::isSubshapeOk() const
314 if ( !myToCreate || myIsMesh ) // not submesh creation
318 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
319 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
320 if (!pMesh) return false;
322 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
323 if (mesh->_is_nil()) return false;
325 // main shape of the mesh
326 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
327 if (mainGeom->_is_nil()) return false;
331 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
333 if (aGEOMs.count() > 0) {
334 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
335 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
336 if (geomGen->_is_nil() || !aStudy) return false;
338 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
339 if (op->_is_nil()) return false;
341 // check all selected shapes
342 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
343 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
344 QString aSubGeomEntry = (*aSubShapesIter);
345 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
346 if (!pSubGeom) return false;
348 GEOM::GEOM_Object_var aSubGeomVar =
349 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
350 if (aSubGeomVar->_is_nil()) return false;
352 // skl for NPAL14695 - implementation of searching of mainObj
353 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
354 mainObj already exists! */
356 if (mainObj->_is_nil())
358 CORBA::String_var entry1 = mainObj->GetEntry();
359 CORBA::String_var entry2 = mainGeom->GetEntry();
360 if (std::string( entry1.in() ) == entry2.in() )
362 mainObj = op->GetMainShape(mainObj);
370 //================================================================================
372 * \brief Return name of the algorithm that does not support submeshes and makes
373 * submesh creation useless
374 * \retval char* - string is to be deleted!!!
376 //================================================================================
377 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
379 if ( myToCreate && !myIsMesh ) {
381 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
382 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
383 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
386 QStringList algoNames;
388 existingHyps(3, Algo, pMesh, algoNames, algoList);
389 if (!algoList.empty()) {
390 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
392 algo->InputTypes.empty() && // builds all dimensions it-self
393 !algo->IsSupportSubmeshes )
394 return CORBA::string_dup( algoNames[0].toLatin1().data() );
397 // GEOM::GEOM_Object_var geom;
398 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
399 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
401 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
402 existingHyps(2, Algo, pMesh, algoNames, algoList);
403 if (!algoList.empty()) {
404 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
406 algo->InputTypes.empty() && // builds all dimensions it-self
407 !algo->IsSupportSubmeshes )
408 return CORBA::string_dup( algoNames[0].toLatin1().data() );
416 //================================================================================
418 * \brief find an existing submesh by the selected shape
419 * \retval _PTR(SObject) - the found submesh SObject
421 //================================================================================
422 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
424 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
425 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
426 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
427 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
428 if ( pMesh && pGeom ) {
429 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
430 if ( !geom->_is_nil() ) {
432 switch ( geom->GetShapeType() ) {
433 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
434 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
435 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
436 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
437 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
438 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
439 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
442 _PTR(GenericAttribute) anAttr;
443 _PTR(SObject) aSubmeshRoot;
444 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
445 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
447 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
448 for ( ; smIter->More(); smIter->Next() )
450 _PTR(SObject) aSmObj = smIter->Value();
451 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
453 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
454 for ( ; anIter1->More(); anIter1->Next()) {
455 _PTR(SObject) pGeom2 = anIter1->Value();
456 if ( pGeom2->ReferencedObject( pGeom2 ) &&
457 pGeom2->GetID() == pGeom->GetID() )
464 return _PTR(SObject)();
467 //================================================================================
469 * \brief Updates dialog's look and feel
471 * Virtual method redefined from the base class updates dialog's look and feel
473 //================================================================================
474 void SMESHGUI_MeshOp::selectionDone()
476 if (!dlg()->isVisible() || !myDlg->isEnabled())
479 SMESHGUI_SelectionOp::selectionDone();
483 myIsOnGeometry = true;
485 //Check geometry for mesh
486 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
487 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
490 SMESH::SMESH_Mesh_var aMeshVar =
491 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
492 if (!aMeshVar->_is_nil()) {
493 if (!myToCreate && !aMeshVar->HasShapeToMesh())
494 myIsOnGeometry = false;
500 // Enable tabs according to shape dimension
505 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
506 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
508 if (aGEOMs.count() > 0) {
509 // one or more GEOM shape selected
510 aSeq->length(aGEOMs.count());
511 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
513 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
514 QString aSubGeomEntry = (*aSubShapesIter);
515 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
516 GEOM::GEOM_Object_var aSubGeomVar =
517 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
518 aSeq[iSubSh] = aSubGeomVar;
521 // get geometry by selected sub-mesh
522 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
523 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
524 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
525 if (!aGeomVar->_is_nil()) {
531 if (aSeq->length() > 0) {
533 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
534 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
535 switch ( aGeomVar->GetShapeType() ) {
536 case GEOM::SOLID: shapeDim = 3; break;
538 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
540 // TopoDS_Shape aShape;
541 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
542 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
545 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
547 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
548 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
552 if (GEOMBase::GetShape(aGeomVar, aShape))
554 TopExp_Explorer exp (aShape, TopAbs_SOLID);
558 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
559 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
562 // for (; exp.More() && shapeDim == 2; exp.Next()) {
563 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
567 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
568 shapeDim = qMax(2, shapeDim);
569 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
570 shapeDim = qMax(1, shapeDim);
571 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
572 shapeDim = qMax(0, shapeDim);
580 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
581 // reset algos before disabling tabs (0020138)
582 onAlgoSelected(-1, i);
584 myDlg->setMaxHypoDim( shapeDim );
585 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
587 if (!myToCreate) // edition: read hypotheses
591 SMESH::SMESH_subMesh_var aVar =
592 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
593 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
594 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
595 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
596 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
597 myDlg->updateGeometry();
604 else if ( !myIsMesh ) // submesh creation
606 // if a submesh on the selected shape already exist, pass to submesh edition mode
607 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
608 SMESH::SMESH_subMesh_var sm =
609 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
610 bool editSubmesh = ( !sm->_is_nil() &&
611 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
612 tr( "EDIT_SUBMESH_QUESTION"),
613 SUIT_MessageBox::Yes |
615 SUIT_MessageBox::No )
616 == SUIT_MessageBox::Yes );
619 selectionMgr()->clearFilters();
620 selectObject( pSubmesh );
621 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
626 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
627 selectObject( _PTR(SObject)() );
632 // discard selected mesh if submesh creation not allowed because of
633 // a global algorithm that does not support submeshes
634 if ( char* algoName = isSubmeshIgnored() ) {
635 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
636 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
637 CORBA::string_free( algoName );
638 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
639 selectObject( _PTR(SObject)() );
644 // enable/disable popup for choice of geom selection way
646 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
647 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
648 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
649 if ( !mesh->_is_nil() ) {
650 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
651 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
652 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
653 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
654 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
655 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
658 myDlg->setGeomPopupEnabled( enable );
661 else { // no geometry defined
662 myDlg->enableTab( SMESH::DIM_3D );
664 availableHyps( SMESH::DIM_3D, Algo, hypList,
665 myAvailableHypData[SMESH::DIM_3D][Algo]);
667 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
668 aTab->setAvailableHyps( Algo, hypList );
669 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
670 myDlg->disableTab(i);
672 //Hide labels and fields (Mesh ang Geometry)
673 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
674 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
679 catch ( const SALOME::SALOME_Exception& S_ex )
681 SalomeApp_Tools::QtCatchCorbaException( S_ex );
688 //================================================================================
690 * \brief Verifies validity of input data
691 * \param theMess - Output parameter intended for returning error message
692 * \retval bool - TRUE if input data is valid, false otherwise
694 * Verifies validity of input data. This method is called when "Apply" or "OK" button
695 * is pressed before mesh creation or editing.
697 //================================================================================
698 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
700 // Selected object to be edited
701 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
703 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
708 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
709 if ( aMeshName.isEmpty() )
711 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
715 /* // Imported mesh, if create sub-mesh or edit mesh
716 if ( !myToCreate || ( myToCreate && !myIsMesh ))
718 QString aMeshEntry = myDlg->selectedObject
719 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
720 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
721 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
722 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
723 theMess = tr( "IMPORTED_MESH" );
732 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
733 if ( aGeomEntry == "" )
735 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
738 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
739 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
741 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
746 if ( !myIsMesh ) // i.e sub-mesh creation,
748 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
749 if ( aMeshEntry == "" )
751 theMess = tr( "MESH_IS_NOT_DEFINED" );
754 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
755 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
757 theMess = tr( "MESH_IS_NULL" );
760 if ( !isSubshapeOk() )
762 theMess = tr( "INVALID_SUBSHAPE" );
771 //================================================================================
773 * \brief check compatibility of the algorithm and another algorithm or hypothesis
774 * \param theAlgoData - algorithm data
775 * \param theHypData - hypothesis data
776 * \param theHypType - hypothesis type
777 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
778 * \retval bool - check result
780 //================================================================================
781 static bool isCompatible(const HypothesisData* theAlgoData,
782 const HypothesisData* theHypData,
783 const int theHypType)
788 if ( theHypType == SMESHGUI_MeshOp::Algo )
789 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
792 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
795 //================================================================================
797 * \brief Gets available hypotheses or algorithms
798 * \param theDim - specifies dimension of returned hypotheses/algorifms
799 * \param theHypType - specifies whether algorims or hypotheses or additional ones
800 * are retrieved (possible values are in HypType enumeration)
801 * \param theHyps - Output list of hypotheses' names
802 * \param theAlgoData - to select hypos able to be used by this algo (optional)
804 * Gets available hypotheses or algorithm in accordance with input parameters
806 //================================================================================
807 void SMESHGUI_MeshOp::availableHyps( const int theDim,
808 const int theHypType,
809 QStringList& theHyps,
810 THypDataList& theDataList,
811 HypothesisData* theAlgoData ) const
815 bool isAlgo = ( theHypType == Algo );
816 bool isAux = ( theHypType == AddHyp );
817 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
819 QStringList::const_iterator anIter;
820 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
822 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
823 if ( isCompatible ( theAlgoData, aData, theHypType )) {
824 theDataList.append( aData );
825 theHyps.append( aData->Label );
830 //================================================================================
832 * \brief Gets existing hypotheses or algorithms
833 * \param theDim - specifies dimension of returned hypotheses/algorifms
834 * \param theHypType - specifies whether algorims or hypotheses or additional ones
835 * are retrieved (possible values are in HypType enumeration)
836 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
837 * \param theHyps - output list of names.
838 * \param theHypVars - output list of variables.
839 * \param theAlgoData - to select hypos able to be used by this algo (optional)
841 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
844 //================================================================================
845 void SMESHGUI_MeshOp::existingHyps( const int theDim,
846 const int theHypType,
847 _PTR(SObject) theFather,
848 QStringList& theHyps,
849 THypList& theHypList,
850 HypothesisData* theAlgoData)
852 // Clear hypoheses list
859 const bool isAux = ( theHypType == AddHyp );
861 _PTR(SObject) aHypRoot;
862 _PTR(GenericAttribute) anAttr;
863 _PTR(AttributeName) aName;
864 _PTR(AttributeIOR) anIOR;
866 bool isMesh = !_CAST( SComponent, theFather );
869 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
871 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
873 if ( theFather->FindSubObject( aPart, aHypRoot ) )
875 _PTR(ChildIterator) anIter =
876 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
877 for ( ; anIter->More(); anIter->Next() )
879 _PTR(SObject) anObj = anIter->Value();
880 if ( isMesh ) // i.e. mesh or submesh
882 _PTR(SObject) aRefObj;
883 if ( anObj->ReferencedObject( aRefObj ) )
888 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
891 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
892 if ( !CORBA::is_nil( aVar ) )
894 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
895 if ( !aHypVar->_is_nil() )
897 CORBA::String_var hypType = aHypVar->GetName();
898 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
899 if ( !aData) continue;
900 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
901 ( isCompatible ( theAlgoData, aData, theHypType )) &&
902 ( isAux == aData->IsAux ))
904 std::string aHypName = aName->Value();
905 theHyps.append( aHypName.c_str() );
906 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
915 //================================================================================
917 * \brief If create or edit a submesh, return a hypothesis holding parameters used
918 * to mesh a sub-shape
919 * \param aHypType - The hypothesis type name
920 * \param aServerLib - Server library name
921 * \param hypData - The structure holding the hypothesis type etc.
922 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
924 //================================================================================
925 SMESH::SMESH_Hypothesis_var
926 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
927 const QString& aServerLib ) const
929 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
930 return SMESH::SMESH_Hypothesis::_nil();
932 const int nbColonsInMeshEntry = 3;
933 bool isSubMesh = myToCreate ?
935 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
937 // get mesh and geom object
938 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
939 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
944 anEntry = myDlg->selectedObject
945 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
946 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
948 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
949 if ( myToCreate ) // mesh and geom may be selected
951 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
952 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
953 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
954 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
956 else // edition: sub-mesh may be selected
958 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
959 if ( !sm->_is_nil() ) {
960 aMeshVar = sm->GetFather();
961 aGeomVar = sm->GetSubShape();
968 if ( !myToCreate ) // mesh to edit can be selected
970 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
971 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
973 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
974 if ( !aMeshVar->_is_nil() )
975 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
978 if ( aGeomVar->_is_nil() ) {
979 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
980 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
982 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
987 SMESH::SMESH_Hypothesis_var hyp =
988 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
989 aServerLib.toLatin1().data(),
992 /*byMesh = */isSubMesh);
993 if ( hyp->_is_nil() && isSubMesh )
994 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
995 aServerLib.toLatin1().data(),
1002 //================================================================================
1004 * \Brief Returns tab dimention
1005 * \param tab - the tab in the dlg
1006 * \param dlg - my dialogue
1007 * \retval int - dimention
1009 //================================================================================
1010 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1013 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1014 if (tab == dlg->tab(i))
1019 //================================================================================
1021 * \brief Create hypothesis
1022 * \param theHypType - hypothesis category (main or additional)
1023 * \param theIndex - index of type of hypothesis to be cerated
1025 * Specifies dimension of hypothesis to be created (using sender() method),
1026 * specifies its type and calls method for hypothesis creation
1028 //================================================================================
1029 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1031 // Specifies dimension of hypothesis to be created
1032 int aDim = getTabDim( sender(), myDlg );
1036 // Specifies type of hypothesis to be created
1037 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1038 if (theIndex < 0 || theIndex >= dataList.count())
1040 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1042 // Create hypothesis
1043 createHypothesis(aDim, theHypType, aHypTypeName);
1048 QString GetUniqueName (const QStringList& theHypNames,
1049 const QString& theName,
1050 size_t theIteration = 1)
1052 QString aName = theName + "_" + QString::number( theIteration );
1053 if ( theHypNames.contains( aName ) )
1054 return GetUniqueName( theHypNames, theName, ++theIteration );
1059 //================================================================================
1061 * Create hypothesis and update dialog.
1062 * \param theDim - dimension of hypothesis to be created
1063 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1064 * \param theTypeName - specifies hypothesis to be created
1066 //================================================================================
1067 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1069 const QString& theTypeName)
1071 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1077 QStringList aHypNames;
1078 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1079 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1080 const TType2HypList& aType2HypList = aDimIter.value();
1081 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1082 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1083 const THypList& aHypList = aTypeIter.value();
1084 THypList::const_iterator anIter = aHypList.begin();
1085 for ( ; anIter != aHypList.end(); anIter++) {
1086 const THypItem& aHypItem = *anIter;
1087 const QString& aHypName = aHypItem.second;
1088 aHypNames.append(aHypName);
1092 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1095 bool dialog = false;
1097 QString aClientLibName = aData->ClientLibName;
1098 if (aClientLibName == "") {
1099 // Call hypothesis creation server method (without GUI)
1100 SMESH::SMESH_Hypothesis_var aHyp =
1101 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1105 // Get hypotheses creator client (GUI)
1106 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1108 // Create hypothesis
1110 // Get parameters appropriate to initialize a new hypothesis
1111 SMESH::SMESH_Hypothesis_var initParamHyp =
1112 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1114 removeCustomFilters(); // Issue 0020170
1116 // Get Entry of the Geom object
1117 QString aGeomEntry = "";
1118 QString aMeshEntry = "";
1119 QString anObjEntry = "";
1120 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1121 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1122 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1124 if ( myToCreate && myIsMesh )
1125 aMeshEntry = aGeomEntry;
1127 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1128 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1129 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1130 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1133 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1134 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1136 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1137 if ( !aGeomVar->_is_nil() )
1139 aGeomEntry = aGeomVar->GetStudyEntry();
1141 aMeshEntry = aGeomEntry;
1145 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1146 // take geometry from submesh being created
1147 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1149 // if current object is sub-mesh
1150 SMESH::SMESH_subMesh_var aSubMeshVar =
1151 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1152 if ( !aSubMeshVar->_is_nil() ) {
1153 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1154 if ( !aMeshVar->_is_nil() ) {
1155 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1156 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1157 if ( !aGeomVar->_is_nil() )
1158 aMeshEntry = aGeomVar->GetStudyEntry();
1164 aCreator->setShapeEntry( aGeomEntry );
1165 if ( aMeshEntry != "" )
1166 aCreator->setMainShapeEntry( aMeshEntry );
1167 myDlg->setEnabled( false );
1168 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1172 SMESH::SMESH_Hypothesis_var aHyp =
1173 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1182 //================================================================================
1184 * Necessary steps after hypothesis creation
1185 * \param result - creation result:
1188 * 2 = additional value meaning that slot is called not from dialog box
1190 //================================================================================
1191 void SMESHGUI_MeshOp::onHypoCreated( int result )
1195 int obj = myDlg->getActiveObject();
1196 onActivateObject( obj ); // Issue 0020170. Restore filters
1197 myDlg->setEnabled( true );
1200 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1202 int nbHyp = myExistingHyps[myDim][myType].count();
1203 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1204 QStringList aNewHyps;
1205 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1206 if (aNewHyps.count() > nbHyp)
1208 for (int i = nbHyp; i < aNewHyps.count(); i++)
1209 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1212 if( result!=2 && myHypoSet )
1216 //================================================================================
1218 * \brief Calls plugin methods for hypothesis editing
1219 * \param theHypType - specifies whether main hypothesis or additional one
1221 * \param theIndex - index of existing hypothesis
1223 * Calls plugin methods for hypothesis editing
1225 //================================================================================
1226 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1228 // Speicfies dimension of hypothesis to be created
1229 int aDim = getTabDim( sender(), myDlg );
1233 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1234 if ( theIndex < 0 || theIndex >= aList.count() )
1236 const THypItem& aHypItem = aList[ theIndex ];
1237 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1238 if ( aHyp->_is_nil() )
1241 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1244 // Get initial parameters
1245 SMESH::SMESH_Hypothesis_var initParamHyp =
1246 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1247 aCreator->setInitParamsHypothesis( initParamHyp );
1249 // Get Entry of the Geom object
1250 QString aGeomEntry = "";
1251 QString aMeshEntry = "";
1252 QString anObjEntry = "";
1253 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1254 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1255 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1257 if ( myToCreate && myIsMesh )
1258 aMeshEntry = aGeomEntry;
1260 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1261 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1262 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1263 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1266 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1267 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1269 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1270 if ( !aGeomVar->_is_nil() )
1272 aGeomEntry = aGeomVar->GetStudyEntry();
1274 aMeshEntry = aGeomEntry;
1278 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1279 // take geometry from submesh being created
1280 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1282 // if current object is sub-mesh
1283 SMESH::SMESH_subMesh_var aSubMeshVar =
1284 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1285 if ( !aSubMeshVar->_is_nil() ) {
1286 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1287 if ( !aMeshVar->_is_nil() ) {
1288 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1289 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1290 if ( !aGeomVar->_is_nil() )
1291 aMeshEntry = aGeomVar->GetStudyEntry();
1297 aCreator->setShapeEntry( aGeomEntry );
1298 if ( aMeshEntry != "" )
1299 aCreator->setMainShapeEntry( aMeshEntry );
1300 removeCustomFilters(); // Issue 0020170
1301 myDlg->setEnabled( false );
1302 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1306 //================================================================================
1308 * Necessary steps after hypothesis edition
1309 * \param result - creation result:
1313 //================================================================================
1314 void SMESHGUI_MeshOp::onHypoEdited( int result )
1316 int obj = myDlg->getActiveObject();
1317 onActivateObject( obj ); // Issue 0020170. Restore filters
1318 myDlg->setEnabled( true );
1321 //================================================================================
1323 * \brief access to hypothesis data
1324 * \param theDim - hyp dimension
1325 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1326 * \param theIndex - index in the list
1327 * \retval HypothesisData* - result data, may be 0
1329 //================================================================================
1330 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1331 const int theHypType,
1334 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1335 theHypType > -1 && theHypType < NbHypTypes &&
1336 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1337 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1341 //================================================================================
1343 * \brief Set available algos and hypos according to the selected algorithm
1344 * \param theIndex - algorithm index
1346 //================================================================================
1347 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1350 if ( myIgnoreAlgoSelection )
1353 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1357 // find highest available dimension, all algos of this dimension are available for choice
1359 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1360 if (isAccessibleDim( i ))
1365 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1367 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1368 HypothesisData* algoByDim[4];
1369 algoByDim[ aDim ] = algoData;
1371 QStringList anAvailable;
1372 if ( !algoData ) { // all algos becomes available
1373 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1374 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1377 // check that algorithms of other dimentions are compatible with
1380 // 2 loops: backward and forward from algo dimension
1381 for ( int forward = false; forward <= true; ++forward )
1383 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1385 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1387 HypothesisData* prevAlgo = algoData;
1388 bool noCompatible = false;
1389 for ( ; dim * dir <= lastDim * dir; dim += dir)
1391 if ( !isAccessibleDim( dim ))
1393 if ( noCompatible ) { // the selected algo has no compatible ones
1394 anAvailable.clear();
1395 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1396 myAvailableHypData[dim][Algo].clear();
1397 algoByDim[ dim ] = 0;
1400 // get currently selected algo
1401 int algoIndex = currentHyp( dim, Algo );
1402 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1403 if ( curAlgo ) { // some algo selected
1404 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1407 // set new available algoritms
1408 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1409 HypothesisData* soleCompatible = 0;
1410 if ( anAvailable.count() == 1 )
1411 soleCompatible = myAvailableHypData[dim][Algo][0];
1412 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1413 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1414 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1415 noCompatible = anAvailable.isEmpty();
1417 // restore previously selected algo
1418 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1419 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1420 // select the sole compatible algo
1421 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1422 setCurrentHyp( dim, Algo, algoIndex );
1424 // remember current algo
1425 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1429 // set hypotheses corresponding to the found algoritms
1431 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1433 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1435 if ( !isAccessibleDim( dim ))
1437 for ( int type = MainHyp; type < NbHypTypes; type++ )
1439 myAvailableHypData[ dim ][ type ].clear();
1440 QStringList anAvailable, anExisting;
1442 HypothesisData* curAlgo = algoByDim[ dim ];
1443 int hypIndex = currentHyp( dim, type );
1445 SMESH::SMESH_Hypothesis_var curHyp;
1446 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1447 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1449 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1450 // try to find algo by selected hypothesis in order to keep it selected
1451 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1452 CORBA::String_var curHypType = curHyp->GetName();
1453 if ( !algoDeselectedByUser &&
1454 myObjHyps[ dim ][ type ].count() > 0 &&
1455 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1457 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1458 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1459 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1460 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1467 // get hyps compatible with curAlgo
1470 // check if a selected hyp is compatible with the curAlgo
1471 if ( !curHyp->_is_nil() ) {
1472 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1473 if ( !isCompatible( curAlgo, hypData, type ))
1474 curHyp = SMESH::SMESH_Hypothesis::_nil();
1476 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1477 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1479 // set list of hypotheses
1480 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1481 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1483 // set current existing hypothesis
1484 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1485 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1488 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1489 // none is yet selected => select the sole existing if it is not optional
1490 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1491 bool isOptional = true;
1492 if ( algoByDim[ dim ] &&
1493 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1497 setCurrentHyp( dim, type, hypIndex );
1502 //================================================================================
1504 * \brief Creates and selects hypothesis of hypotheses set
1505 * \param theSetName - The name of hypotheses set
1507 //================================================================================
1508 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1510 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1515 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1516 setCurrentHyp(dim, Algo, -1);
1517 setCurrentHyp(dim, AddHyp, -1);
1518 setCurrentHyp(dim, MainHyp, -1);
1521 myHypoSet->init(true); //algorithms
1523 myHypoSet->init(false); //hypotheses
1528 //================================================================================
1530 * \brief One step of hypothesis/algorithm list creation
1532 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1534 //================================================================================
1535 void SMESHGUI_MeshOp::processSet()
1538 if( !myHypoSet->more() )
1541 bool isAlgo = myHypoSet->isAlgo();
1542 QString aHypoTypeName = myHypoSet->current();
1543 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1550 int aDim = aHypData->Dim[0];
1551 // create or/and set
1554 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1557 QStringList anAvailable;
1558 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1559 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1560 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1562 setCurrentHyp( aDim, Algo, index );
1563 onAlgoSelected( index, aDim );
1568 bool mainHyp = true;
1569 QStringList anAvailable;
1570 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1571 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1572 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1576 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1579 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1585 //================================================================================
1587 * \brief Creates mesh
1588 * \param theMess - Output parameter intended for returning error message
1589 * \param theEntryList - List of entries of published objects
1590 * \retval bool - TRUE if mesh is created, FALSE otherwise
1594 //================================================================================
1595 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1599 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1600 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1603 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1604 QStringList::Iterator it = aList.begin();
1605 for ( ; it!=aList.end(); it++)
1607 QString aGeomEntry = *it;
1608 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1609 GEOM::GEOM_Object_var aGeomVar =
1610 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1612 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1613 if ( aSMESHGen->_is_nil() )
1616 SUIT_OverrideCursor aWaitCursor;
1619 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1620 if ( aMeshVar->_is_nil() )
1622 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1624 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1625 theEntryList.append( aMeshSO->GetID().c_str() );
1628 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1629 if ( !isAccessibleDim( aDim )) continue;
1631 // assign hypotheses
1632 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1633 int aHypIndex = currentHyp( aDim, aHypType );
1634 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1635 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1636 if ( !aHypVar->_is_nil() )
1637 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1640 // find or create algorithm
1641 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1642 if ( !anAlgoVar->_is_nil() )
1643 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1649 //================================================================================
1651 * \brief Creates sub-mesh
1652 * \param theMess - Output parameter intended for returning error message
1653 * \param theEntryList - List of entries of published objects
1654 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1658 //================================================================================
1659 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1663 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1664 if ( aSMESHGen->_is_nil() )
1668 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1669 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1670 SMESH::SMESH_Mesh_var aMeshVar =
1671 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1672 if (aMeshVar->_is_nil())
1675 // GEOM shape of the main mesh
1676 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1678 // Name for the new sub-mesh
1679 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1682 GEOM::GEOM_Object_var aGeomVar;
1684 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1685 if (aGEOMs.count() == 1)
1687 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1688 QString aGeomEntry = aGEOMs.first();
1689 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1690 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1692 else if (aGEOMs.count() > 1)
1694 // create a GEOM group
1695 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1696 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1697 if (!geomGen->_is_nil() && aStudy) {
1698 GEOM::GEOM_IGroupOperations_wrap op =
1699 geomGen->GetIGroupOperations(aStudy->StudyId());
1700 if (!op->_is_nil()) {
1701 // check and add all selected GEOM objects: they must be
1702 // a sub-shapes of the main GEOM and must be of one type
1704 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1705 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1706 aSeq->length(aGEOMs.count());
1707 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1708 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1709 QString aSubGeomEntry = (*aSubShapesIter);
1710 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1711 GEOM::GEOM_Object_var aSubGeomVar =
1712 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1713 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1715 aGroupType = aSubShapeType;
1717 if (aSubShapeType != aGroupType)
1718 aGroupType = TopAbs_SHAPE;
1720 aSeq[iSubSh] = aSubGeomVar;
1723 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1724 op->UnionList(aGroupVar, aSeq);
1728 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1730 // publish the GEOM group in study
1731 QString aNewGeomGroupName ("Auto_group_for_");
1732 aNewGeomGroupName += aName;
1733 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1734 SALOMEDS::SObject_wrap aNewGroupSO =
1735 geomGen->AddInStudy( aStudyVar, aGeomVar,
1736 aNewGeomGroupName.toLatin1().data(), mainGeom);
1743 if (aGeomVar->_is_nil())
1746 SUIT_OverrideCursor aWaitCursor;
1749 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1750 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1752 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1753 theEntryList.append( aSubMeshSO->GetID().c_str() );
1756 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1758 if ( !isAccessibleDim( aDim )) continue;
1760 // find or create algorithm
1761 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1762 if ( !anAlgoVar->_is_nil() )
1763 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1764 // assign hypotheses
1765 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1767 int aHypIndex = currentHyp( aDim, aHypType );
1768 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1770 SMESH::SMESH_Hypothesis_var aHypVar =
1771 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1772 if ( !aHypVar->_is_nil() )
1773 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1778 // deselect geometry: next submesh should be created on other sub-shape
1779 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1780 selectObject( _PTR(SObject)() );
1786 //================================================================================
1788 * \brief Gets current hypothesis or algorithms
1789 * \param theDim - dimension of hypothesis or algorithm
1790 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1791 * \retval int - current hypothesis or algorithms
1793 * Gets current hypothesis or algorithms
1795 //================================================================================
1796 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1798 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1801 //================================================================================
1803 * \brief Returns true if hypotheses of given dim can be assigned
1804 * \param theDim - hypotheses dimension
1805 * \retval bool - result
1807 //================================================================================
1808 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1810 return myDlg->isTabEnabled( theDim );
1813 //================================================================================
1815 * \brief Sets current hypothesis or algorithms
1816 * \param theDim - dimension of hypothesis or algorithm
1817 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1818 * \param theIndex - Index of hypothesis
1820 * Gets current hypothesis or algorithms
1822 //================================================================================
1823 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1824 const int theHypType,
1825 const int theIndex )
1827 myIgnoreAlgoSelection = true;
1828 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1829 myIgnoreAlgoSelection = false;
1832 //================================================================================
1834 * \brief Generates default and sets mesh/submesh name
1836 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1838 //================================================================================
1839 void SMESHGUI_MeshOp::setDefaultName() const
1843 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1845 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1846 _PTR(SObject) anObj;
1849 aResName = aPrefix + QString::number( i++ );
1850 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1854 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1855 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1856 aControl->setText( aResName );
1859 //================================================================================
1861 * \brief Gets algorithm or creates it if necessary
1862 * \param theDim - specifies dimension of returned hypotheses/algorifms
1863 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1865 * Gets algorithm or creates it if necessary
1867 //================================================================================
1868 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1870 SMESH::SMESH_Hypothesis_var anAlgoVar;
1872 // get type of the selected algo
1873 int aHypIndex = currentHyp( theDim, Algo );
1874 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1875 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1877 QString aHypName = dataList[ aHypIndex ]->TypeName;
1879 // get existing algoritms
1880 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1882 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1884 // look for an existing algo of such a type
1885 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1886 THypList::iterator anIter = aHypVarList.begin();
1887 for ( ; anIter != aHypVarList.end(); anIter++)
1889 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1890 CORBA::String_var aName = aHypVar->GetName();
1891 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1893 anAlgoVar = aHypVar;
1898 if (anAlgoVar->_is_nil())
1900 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1903 QString aClientLibName = aHypData->ClientLibName;
1904 if ( aClientLibName.isEmpty() )
1906 // Call hypothesis creation server method (without GUI)
1907 SMESH::SMESH_Hypothesis_var aHyp =
1908 SMESH::CreateHypothesis(aHypName, aHypName, true);
1913 // Get hypotheses creator client (GUI)
1914 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1918 aCreator->create( true, aHypName, myDlg, 0, QString::null );
1920 SMESH::SMESH_Hypothesis_var aHyp =
1921 SMESH::CreateHypothesis(aHypName, aHypName, true);
1925 QStringList tmpList;
1926 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1927 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1930 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1931 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1933 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1934 CORBA::String_var aName = aHypVar->GetName();
1935 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1937 anAlgoVar = aHypVar;
1943 return anAlgoVar._retn();
1946 //================================================================================
1948 * \brief Reads parameters of an edited mesh and assigns them to the dialog
1950 * Called when mesh is edited only.
1952 //================================================================================
1953 void SMESHGUI_MeshOp::readMesh()
1955 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1956 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1960 if (myIsOnGeometry) {
1961 // Get name of mesh if current object is sub-mesh
1962 SMESH::SMESH_subMesh_var aSubMeshVar =
1963 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1964 if ( !aSubMeshVar->_is_nil() )
1966 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1967 if ( !aMeshVar->_is_nil() )
1969 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1970 QString aMeshName = name( aMeshSO );
1971 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1975 // Get name of geometry object
1976 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1977 if ( !aGeomVar->_is_nil() )
1979 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1980 QString aShapeName = name( aGeomSO );
1981 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1985 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1986 QStringList anExisting;
1987 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1988 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
1991 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1992 // find algo index among available ones
1994 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1996 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1997 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1998 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1999 // if ( aHypIndex < 0 && algoData ) {
2000 // // assigned algo is incompatible with other algorithms
2001 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2002 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2005 setCurrentHyp( dim, Algo, aHypIndex );
2006 // set existing and available hypothesis according to the selected algo
2007 onAlgoSelected( aHypIndex, dim );
2011 bool hypWithoutAlgo = false;
2012 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2014 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2017 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2018 // find index of requered hypothesis among existing ones for this dimension and type
2020 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2021 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2022 myExistingHyps[ dim ][ hypType ] );
2023 if ( aHypIndex < 0 ) {
2024 // assigned hypothesis is incompatible with the algorithm
2025 if ( currentHyp( dim, Algo ) < 0 )
2026 { // none algo selected; it is edition for sure, of submesh maybe
2027 hypWithoutAlgo = true;
2028 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2029 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2030 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2034 setCurrentHyp( dim, hypType, aHypIndex );
2037 // make available other hyps of same type as one without algo
2038 if ( hypWithoutAlgo )
2039 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2042 //================================================================================
2044 * \brief Gets name of object
2045 * \param theSO - SObject
2046 * \retval QString - name of object
2048 * Gets name of object
2050 //================================================================================
2051 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2056 _PTR(GenericAttribute) anAttr;
2057 _PTR(AttributeName) aNameAttr;
2058 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2061 aResName = aNameAttr->Value().c_str();
2067 //================================================================================
2069 * \brief Finds hypothesis in input list
2070 * \param theHyp - hypothesis to be found
2071 * \param theHypList - input list of hypotheses
2072 * \retval int - index of hypothesis or -1 if it is not found
2074 * Finds position of hypothesis in input list
2076 //================================================================================
2077 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2078 const THypList& theHypList ) const
2081 if ( !theHyp->_is_nil() )
2084 THypList::const_iterator anIter = theHypList.begin();
2085 for ( ; anIter != theHypList.end(); ++ anIter)
2087 if ( theHyp->_is_equivalent( (*anIter).first ) )
2098 //================================================================================
2100 * \brief Edits mesh or sub-mesh
2101 * \param theMess - Output parameter intended for returning error message
2102 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2104 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2106 //================================================================================
2107 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2111 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2112 if ( aSMESHGen->_is_nil() )
2115 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2116 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2120 SUIT_OverrideCursor aWaitCursor;
2123 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2124 SMESH::SetName( pObj, aName );
2125 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2127 // First, remove old algos in order to avoid messages on algorithm hiding
2128 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2130 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2132 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2133 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2134 if ( anAlgoVar->_is_nil() || // no new algo selected or
2135 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2137 // remove old algorithm
2138 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2139 myObjHyps[ dim ][ Algo ].clear();
2144 // Assign new algorithms and hypotheses
2145 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2147 if ( !isAccessibleDim( dim )) continue;
2149 // find or create algorithm
2150 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2152 // assign new algorithm
2153 if ( !anAlgoVar->_is_nil() && // some algo selected and
2154 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2156 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2157 CORBA::Object_var anObject = aSObject->GetObject();
2158 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2159 bool isMesh = !aMeshVar->_is_nil();
2161 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2163 SMESH::SMESH_subMesh_var aVar =
2164 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2165 if ( !aVar->_is_nil() )
2166 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2168 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2171 // assign hypotheses
2172 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2174 int aNewHypIndex = currentHyp( dim, hypType );
2175 int anOldHypIndex = -1;
2177 // remove old hypotheses
2178 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2180 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2181 myExistingHyps[ dim ][ hypType ] );
2182 if ( aNewHypIndex != anOldHypIndex || // different hyps
2183 anOldHypIndex == -1 ) // hyps of different algos
2185 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2186 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2187 myObjHyps[ dim ][ hypType ].clear();
2191 // assign new hypotheses
2192 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2194 SMESH::SMESH_Mesh_var aMeshVar =
2195 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2196 bool isMesh = !aMeshVar->_is_nil();
2199 SMESH::AddHypothesisOnMesh
2200 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2204 SMESH::SMESH_subMesh_var aVar =
2205 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2206 if ( !aVar->_is_nil() )
2207 SMESH::AddHypothesisOnSubMesh
2208 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2211 // reread all hypotheses of mesh if necessary
2212 QStringList anExisting;
2213 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2220 //================================================================================
2222 * \brief Verifies whether given operator is valid for this one
2223 * \param theOtherOp - other operation
2224 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2226 * method redefined from base class verifies whether given operator is valid for
2227 * this one (i.e. can be started "above" this operator). In current implementation method
2228 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2231 //================================================================================
2232 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2234 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2237 //================================================================================
2239 * \brief SLOT. Is called when the user selects a way of geometry selection
2240 * \param theByMesh - true if the user wants to find geometry by mesh element
2242 //================================================================================
2243 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2246 if ( !myShapeByMeshOp ) {
2247 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2248 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2249 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2250 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2251 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2253 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2254 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2255 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2256 SMESH::SMESH_Mesh_var aMeshVar =
2257 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2258 if ( !aMeshVar->_is_nil() ) {
2259 myDlg->hide(); // stop processing selection
2260 myShapeByMeshOp->setModule( getSMESHGUI() );
2261 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2262 myShapeByMeshOp->SetMesh( aMeshVar );
2263 myShapeByMeshOp->start();
2269 //================================================================================
2271 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2273 //================================================================================
2274 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2276 if ( myShapeByMeshOp == op ) {
2277 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2279 // Select a found geometry object
2280 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2281 if ( !aGeomVar->_is_nil() )
2283 QString ID = aGeomVar->GetStudyEntry();
2284 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2285 selectObject( aGeomSO );
2292 //================================================================================
2294 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2296 //================================================================================
2297 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2299 if ( myShapeByMeshOp == op && myDlg ) {
2304 //================================================================================
2306 * \brief Selects a SObject
2307 * \param theSObj - the SObject to select
2309 //================================================================================
2310 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2312 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2313 SALOME_ListIO anIOList;
2315 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2316 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2317 anIOList.Append( anIO );
2319 sm->setSelectedObjects( anIOList, false );