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" );
737 if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
738 SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
745 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
746 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
748 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
753 if ( !myIsMesh ) // i.e sub-mesh creation,
755 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
756 if ( aMeshEntry == "" )
758 theMess = tr( "MESH_IS_NOT_DEFINED" );
761 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
762 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
764 theMess = tr( "MESH_IS_NULL" );
767 if ( !isSubshapeOk() )
769 theMess = tr( "INVALID_SUBSHAPE" );
778 //================================================================================
780 * \brief check compatibility of the algorithm and another algorithm or hypothesis
781 * \param theAlgoData - algorithm data
782 * \param theHypData - hypothesis data
783 * \param theHypType - hypothesis type
784 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
785 * \retval bool - check result
787 //================================================================================
788 static bool isCompatible(const HypothesisData* theAlgoData,
789 const HypothesisData* theHypData,
790 const int theHypType)
795 if ( theHypType == SMESHGUI_MeshOp::Algo )
796 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
799 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
802 //================================================================================
804 * \brief Gets available hypotheses or algorithms
805 * \param theDim - specifies dimension of returned hypotheses/algorifms
806 * \param theHypType - specifies whether algorims or hypotheses or additional ones
807 * are retrieved (possible values are in HypType enumeration)
808 * \param theHyps - Output list of hypotheses' names
809 * \param theAlgoData - to select hypos able to be used by this algo (optional)
811 * Gets available hypotheses or algorithm in accordance with input parameters
813 //================================================================================
814 void SMESHGUI_MeshOp::availableHyps( const int theDim,
815 const int theHypType,
816 QStringList& theHyps,
817 THypDataList& theDataList,
818 HypothesisData* theAlgoData ) const
822 bool isAlgo = ( theHypType == Algo );
823 bool isAux = ( theHypType == AddHyp );
824 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
826 QStringList::const_iterator anIter;
827 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
829 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
830 if ( isCompatible ( theAlgoData, aData, theHypType )) {
831 theDataList.append( aData );
832 theHyps.append( aData->Label );
837 //================================================================================
839 * \brief Gets existing hypotheses or algorithms
840 * \param theDim - specifies dimension of returned hypotheses/algorifms
841 * \param theHypType - specifies whether algorims or hypotheses or additional ones
842 * are retrieved (possible values are in HypType enumeration)
843 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
844 * \param theHyps - output list of names.
845 * \param theHypVars - output list of variables.
846 * \param theAlgoData - to select hypos able to be used by this algo (optional)
848 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
851 //================================================================================
852 void SMESHGUI_MeshOp::existingHyps( const int theDim,
853 const int theHypType,
854 _PTR(SObject) theFather,
855 QStringList& theHyps,
856 THypList& theHypList,
857 HypothesisData* theAlgoData)
859 // Clear hypoheses list
866 const bool isAux = ( theHypType == AddHyp );
868 _PTR(SObject) aHypRoot;
869 _PTR(GenericAttribute) anAttr;
870 _PTR(AttributeName) aName;
871 _PTR(AttributeIOR) anIOR;
873 bool isMesh = !_CAST( SComponent, theFather );
876 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
878 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
880 if ( theFather->FindSubObject( aPart, aHypRoot ) )
882 _PTR(ChildIterator) anIter =
883 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
884 for ( ; anIter->More(); anIter->Next() )
886 _PTR(SObject) anObj = anIter->Value();
887 if ( isMesh ) // i.e. mesh or submesh
889 _PTR(SObject) aRefObj;
890 if ( anObj->ReferencedObject( aRefObj ) )
895 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
898 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
899 if ( !CORBA::is_nil( aVar ) )
901 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
902 if ( !aHypVar->_is_nil() )
904 CORBA::String_var hypType = aHypVar->GetName();
905 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
906 if ( !aData) continue;
907 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
908 ( isCompatible ( theAlgoData, aData, theHypType )) &&
909 ( isAux == aData->IsAux ))
911 std::string aHypName = aName->Value();
912 theHyps.append( aHypName.c_str() );
913 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
922 //================================================================================
924 * \brief If create or edit a submesh, return a hypothesis holding parameters used
925 * to mesh a sub-shape
926 * \param aHypType - The hypothesis type name
927 * \param aServerLib - Server library name
928 * \param hypData - The structure holding the hypothesis type etc.
929 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
931 //================================================================================
932 SMESH::SMESH_Hypothesis_var
933 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
934 const QString& aServerLib ) const
936 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
937 return SMESH::SMESH_Hypothesis::_nil();
939 const int nbColonsInMeshEntry = 3;
940 bool isSubMesh = myToCreate ?
942 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
944 // get mesh and geom object
945 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
946 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
951 anEntry = myDlg->selectedObject
952 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
953 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
955 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
956 if ( myToCreate ) // mesh and geom may be selected
958 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
959 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
960 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
961 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
963 else // edition: sub-mesh may be selected
965 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
966 if ( !sm->_is_nil() ) {
967 aMeshVar = sm->GetFather();
968 aGeomVar = sm->GetSubShape();
975 if ( !myToCreate ) // mesh to edit can be selected
977 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
978 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
980 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
981 if ( !aMeshVar->_is_nil() )
982 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
985 if ( aGeomVar->_is_nil() ) {
986 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
987 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
989 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
994 SMESH::SMESH_Hypothesis_var hyp =
995 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
996 aServerLib.toLatin1().data(),
999 /*byMesh = */isSubMesh);
1000 if ( hyp->_is_nil() && isSubMesh )
1001 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1002 aServerLib.toLatin1().data(),
1005 /*byMesh = */false);
1009 //================================================================================
1011 * \Brief Returns tab dimention
1012 * \param tab - the tab in the dlg
1013 * \param dlg - my dialogue
1014 * \retval int - dimention
1016 //================================================================================
1017 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1020 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1021 if (tab == dlg->tab(i))
1026 //================================================================================
1028 * \brief Create hypothesis
1029 * \param theHypType - hypothesis category (main or additional)
1030 * \param theIndex - index of type of hypothesis to be cerated
1032 * Specifies dimension of hypothesis to be created (using sender() method),
1033 * specifies its type and calls method for hypothesis creation
1035 //================================================================================
1036 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1038 // Specifies dimension of hypothesis to be created
1039 int aDim = getTabDim( sender(), myDlg );
1043 // Specifies type of hypothesis to be created
1044 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1045 if (theIndex < 0 || theIndex >= dataList.count())
1047 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1049 // Create hypothesis
1050 createHypothesis(aDim, theHypType, aHypTypeName);
1055 QString GetUniqueName (const QStringList& theHypNames,
1056 const QString& theName,
1057 size_t theIteration = 1)
1059 QString aName = theName + "_" + QString::number( theIteration );
1060 if ( theHypNames.contains( aName ) )
1061 return GetUniqueName( theHypNames, theName, ++theIteration );
1066 //================================================================================
1068 * Create hypothesis and update dialog.
1069 * \param theDim - dimension of hypothesis to be created
1070 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1071 * \param theTypeName - specifies hypothesis to be created
1073 //================================================================================
1074 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1076 const QString& theTypeName)
1078 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1084 QStringList aHypNames;
1085 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1086 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1087 const TType2HypList& aType2HypList = aDimIter.value();
1088 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1089 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1090 const THypList& aHypList = aTypeIter.value();
1091 THypList::const_iterator anIter = aHypList.begin();
1092 for ( ; anIter != aHypList.end(); anIter++) {
1093 const THypItem& aHypItem = *anIter;
1094 const QString& aHypName = aHypItem.second;
1095 aHypNames.append(aHypName);
1099 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1102 bool dialog = false;
1104 QString aClientLibName = aData->ClientLibName;
1105 if (aClientLibName == "") {
1106 // Call hypothesis creation server method (without GUI)
1107 SMESH::SMESH_Hypothesis_var aHyp =
1108 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1112 // Get hypotheses creator client (GUI)
1113 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1115 // Create hypothesis
1117 // Get parameters appropriate to initialize a new hypothesis
1118 SMESH::SMESH_Hypothesis_var initParamHyp =
1119 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1121 removeCustomFilters(); // Issue 0020170
1123 // Get Entry of the Geom object
1124 QString aGeomEntry = "";
1125 QString aMeshEntry = "";
1126 QString anObjEntry = "";
1127 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1128 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1129 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1131 if ( myToCreate && myIsMesh )
1132 aMeshEntry = aGeomEntry;
1134 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1135 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1136 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1137 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1140 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1141 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1143 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1144 if ( !aGeomVar->_is_nil() )
1146 aGeomEntry = aGeomVar->GetStudyEntry();
1148 aMeshEntry = aGeomEntry;
1152 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1153 // take geometry from submesh being created
1154 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1156 // if current object is sub-mesh
1157 SMESH::SMESH_subMesh_var aSubMeshVar =
1158 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1159 if ( !aSubMeshVar->_is_nil() ) {
1160 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1161 if ( !aMeshVar->_is_nil() ) {
1162 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1163 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1164 if ( !aGeomVar->_is_nil() )
1165 aMeshEntry = aGeomVar->GetStudyEntry();
1171 aCreator->setShapeEntry( aGeomEntry );
1172 if ( aMeshEntry != "" )
1173 aCreator->setMainShapeEntry( aMeshEntry );
1174 myDlg->setEnabled( false );
1175 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1179 SMESH::SMESH_Hypothesis_var aHyp =
1180 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1189 //================================================================================
1191 * Necessary steps after hypothesis creation
1192 * \param result - creation result:
1195 * 2 = additional value meaning that slot is called not from dialog box
1197 //================================================================================
1198 void SMESHGUI_MeshOp::onHypoCreated( int result )
1202 int obj = myDlg->getActiveObject();
1203 onActivateObject( obj ); // Issue 0020170. Restore filters
1204 myDlg->setEnabled( true );
1207 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1209 int nbHyp = myExistingHyps[myDim][myType].count();
1210 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1211 QStringList aNewHyps;
1212 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1213 if (aNewHyps.count() > nbHyp)
1215 for (int i = nbHyp; i < aNewHyps.count(); i++)
1216 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1219 if( result!=2 && myHypoSet )
1223 //================================================================================
1225 * \brief Calls plugin methods for hypothesis editing
1226 * \param theHypType - specifies whether main hypothesis or additional one
1228 * \param theIndex - index of existing hypothesis
1230 * Calls plugin methods for hypothesis editing
1232 //================================================================================
1233 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1235 // Speicfies dimension of hypothesis to be created
1236 int aDim = getTabDim( sender(), myDlg );
1240 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1241 if ( theIndex < 0 || theIndex >= aList.count() )
1243 const THypItem& aHypItem = aList[ theIndex ];
1244 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1245 if ( aHyp->_is_nil() )
1248 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1251 // Get initial parameters
1252 SMESH::SMESH_Hypothesis_var initParamHyp =
1253 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1254 aCreator->setInitParamsHypothesis( initParamHyp );
1256 // Get Entry of the Geom object
1257 QString aGeomEntry = "";
1258 QString aMeshEntry = "";
1259 QString anObjEntry = "";
1260 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1261 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1262 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1264 if ( myToCreate && myIsMesh )
1265 aMeshEntry = aGeomEntry;
1267 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1268 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1269 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1270 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1273 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1274 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1276 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1277 if ( !aGeomVar->_is_nil() )
1279 aGeomEntry = aGeomVar->GetStudyEntry();
1281 aMeshEntry = aGeomEntry;
1285 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1286 // take geometry from submesh being created
1287 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1289 // if current object is sub-mesh
1290 SMESH::SMESH_subMesh_var aSubMeshVar =
1291 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1292 if ( !aSubMeshVar->_is_nil() ) {
1293 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1294 if ( !aMeshVar->_is_nil() ) {
1295 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1296 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1297 if ( !aGeomVar->_is_nil() )
1298 aMeshEntry = aGeomVar->GetStudyEntry();
1304 aCreator->setShapeEntry( aGeomEntry );
1305 if ( aMeshEntry != "" )
1306 aCreator->setMainShapeEntry( aMeshEntry );
1307 removeCustomFilters(); // Issue 0020170
1308 myDlg->setEnabled( false );
1309 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1313 //================================================================================
1315 * Necessary steps after hypothesis edition
1316 * \param result - creation result:
1320 //================================================================================
1321 void SMESHGUI_MeshOp::onHypoEdited( int result )
1323 int obj = myDlg->getActiveObject();
1324 onActivateObject( obj ); // Issue 0020170. Restore filters
1325 myDlg->setEnabled( true );
1328 //================================================================================
1330 * \brief access to hypothesis data
1331 * \param theDim - hyp dimension
1332 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1333 * \param theIndex - index in the list
1334 * \retval HypothesisData* - result data, may be 0
1336 //================================================================================
1337 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1338 const int theHypType,
1341 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1342 theHypType > -1 && theHypType < NbHypTypes &&
1343 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1344 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1348 //================================================================================
1350 * \brief Set available algos and hypos according to the selected algorithm
1351 * \param theIndex - algorithm index
1353 //================================================================================
1354 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1357 if ( myIgnoreAlgoSelection )
1360 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1364 // find highest available dimension, all algos of this dimension are available for choice
1366 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1367 if (isAccessibleDim( i ))
1372 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1374 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1375 HypothesisData* algoByDim[4];
1376 algoByDim[ aDim ] = algoData;
1378 QStringList anAvailable;
1379 if ( !algoData ) { // all algos becomes available
1380 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1381 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1384 // check that algorithms of other dimentions are compatible with
1387 // 2 loops: backward and forward from algo dimension
1388 for ( int forward = false; forward <= true; ++forward )
1390 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1392 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1394 HypothesisData* prevAlgo = algoData;
1395 bool noCompatible = false;
1396 for ( ; dim * dir <= lastDim * dir; dim += dir)
1398 if ( !isAccessibleDim( dim ))
1400 if ( noCompatible ) { // the selected algo has no compatible ones
1401 anAvailable.clear();
1402 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1403 myAvailableHypData[dim][Algo].clear();
1404 algoByDim[ dim ] = 0;
1407 // get currently selected algo
1408 int algoIndex = currentHyp( dim, Algo );
1409 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1410 if ( curAlgo ) { // some algo selected
1411 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1414 // set new available algoritms
1415 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1416 HypothesisData* soleCompatible = 0;
1417 if ( anAvailable.count() == 1 )
1418 soleCompatible = myAvailableHypData[dim][Algo][0];
1419 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1420 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1421 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1422 noCompatible = anAvailable.isEmpty();
1424 // restore previously selected algo
1425 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1426 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1427 // select the sole compatible algo
1428 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1429 setCurrentHyp( dim, Algo, algoIndex );
1431 // remember current algo
1432 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1436 // set hypotheses corresponding to the found algoritms
1438 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1440 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1442 if ( !isAccessibleDim( dim ))
1444 for ( int type = MainHyp; type < NbHypTypes; type++ )
1446 myAvailableHypData[ dim ][ type ].clear();
1447 QStringList anAvailable, anExisting;
1449 HypothesisData* curAlgo = algoByDim[ dim ];
1450 int hypIndex = currentHyp( dim, type );
1452 SMESH::SMESH_Hypothesis_var curHyp;
1453 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1454 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1456 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1457 // try to find algo by selected hypothesis in order to keep it selected
1458 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1459 CORBA::String_var curHypType = curHyp->GetName();
1460 if ( !algoDeselectedByUser &&
1461 myObjHyps[ dim ][ type ].count() > 0 &&
1462 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1464 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1465 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1466 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1467 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1474 // get hyps compatible with curAlgo
1477 // check if a selected hyp is compatible with the curAlgo
1478 if ( !curHyp->_is_nil() ) {
1479 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1480 if ( !isCompatible( curAlgo, hypData, type ))
1481 curHyp = SMESH::SMESH_Hypothesis::_nil();
1483 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1484 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1486 // set list of hypotheses
1487 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1488 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1490 // set current existing hypothesis
1491 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1492 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1495 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1496 // none is yet selected => select the sole existing if it is not optional
1497 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1498 bool isOptional = true;
1499 if ( algoByDim[ dim ] &&
1500 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1504 setCurrentHyp( dim, type, hypIndex );
1509 //================================================================================
1511 * \brief Creates and selects hypothesis of hypotheses set
1512 * \param theSetName - The name of hypotheses set
1514 //================================================================================
1515 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1517 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1522 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1523 setCurrentHyp(dim, Algo, -1);
1524 setCurrentHyp(dim, AddHyp, -1);
1525 setCurrentHyp(dim, MainHyp, -1);
1528 myHypoSet->init(true); //algorithms
1530 myHypoSet->init(false); //hypotheses
1535 //================================================================================
1537 * \brief One step of hypothesis/algorithm list creation
1539 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1541 //================================================================================
1542 void SMESHGUI_MeshOp::processSet()
1545 if( !myHypoSet->more() )
1548 bool isAlgo = myHypoSet->isAlgo();
1549 QString aHypoTypeName = myHypoSet->current();
1550 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1557 int aDim = aHypData->Dim[0];
1558 // create or/and set
1561 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1564 QStringList anAvailable;
1565 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1566 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1567 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1569 setCurrentHyp( aDim, Algo, index );
1570 onAlgoSelected( index, aDim );
1575 bool mainHyp = true;
1576 QStringList anAvailable;
1577 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1578 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1579 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1583 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1586 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1592 //================================================================================
1594 * \brief Creates mesh
1595 * \param theMess - Output parameter intended for returning error message
1596 * \param theEntryList - List of entries of published objects
1597 * \retval bool - TRUE if mesh is created, FALSE otherwise
1601 //================================================================================
1602 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1606 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1607 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1610 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1611 if ( aList.isEmpty() )
1613 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1614 if ( aSMESHGen->_is_nil() )
1617 SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1618 if ( aMeshVar->_is_nil() )
1621 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1623 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1624 theEntryList.append( aMeshSO->GetID().c_str() );
1628 QStringList::Iterator it = aList.begin();
1629 for ( ; it!=aList.end(); it++)
1631 QString aGeomEntry = *it;
1632 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1633 GEOM::GEOM_Object_var aGeomVar =
1634 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1636 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1637 if ( aSMESHGen->_is_nil() )
1640 SUIT_OverrideCursor aWaitCursor;
1643 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1644 if ( aMeshVar->_is_nil() )
1646 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1648 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1649 theEntryList.append( aMeshSO->GetID().c_str() );
1652 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1653 if ( !isAccessibleDim( aDim )) continue;
1655 // assign hypotheses
1656 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1657 int aHypIndex = currentHyp( aDim, aHypType );
1658 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1659 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1660 if ( !aHypVar->_is_nil() )
1661 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1664 // find or create algorithm
1665 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1666 if ( !anAlgoVar->_is_nil() )
1667 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1673 //================================================================================
1675 * \brief Creates sub-mesh
1676 * \param theMess - Output parameter intended for returning error message
1677 * \param theEntryList - List of entries of published objects
1678 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1682 //================================================================================
1683 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1687 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1688 if ( aSMESHGen->_is_nil() )
1692 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1693 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1694 SMESH::SMESH_Mesh_var aMeshVar =
1695 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1696 if (aMeshVar->_is_nil())
1699 // GEOM shape of the main mesh
1700 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1702 // Name for the new sub-mesh
1703 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1706 GEOM::GEOM_Object_var aGeomVar;
1708 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1709 if (aGEOMs.count() == 1)
1711 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1712 QString aGeomEntry = aGEOMs.first();
1713 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1714 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1716 else if (aGEOMs.count() > 1)
1718 // create a GEOM group
1719 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1720 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1721 if (!geomGen->_is_nil() && aStudy) {
1722 GEOM::GEOM_IGroupOperations_wrap op =
1723 geomGen->GetIGroupOperations(aStudy->StudyId());
1724 if (!op->_is_nil()) {
1725 // check and add all selected GEOM objects: they must be
1726 // a sub-shapes of the main GEOM and must be of one type
1728 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1729 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1730 aSeq->length(aGEOMs.count());
1731 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1732 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1733 QString aSubGeomEntry = (*aSubShapesIter);
1734 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1735 GEOM::GEOM_Object_var aSubGeomVar =
1736 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1737 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1739 aGroupType = aSubShapeType;
1741 if (aSubShapeType != aGroupType)
1742 aGroupType = TopAbs_SHAPE;
1744 aSeq[iSubSh] = aSubGeomVar;
1747 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1748 op->UnionList(aGroupVar, aSeq);
1752 aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1754 // publish the GEOM group in study
1755 QString aNewGeomGroupName ("Auto_group_for_");
1756 aNewGeomGroupName += aName;
1757 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1758 SALOMEDS::SObject_wrap aNewGroupSO =
1759 geomGen->AddInStudy( aStudyVar, aGeomVar,
1760 aNewGeomGroupName.toLatin1().data(), mainGeom);
1767 if (aGeomVar->_is_nil())
1770 SUIT_OverrideCursor aWaitCursor;
1773 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1774 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1776 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1777 theEntryList.append( aSubMeshSO->GetID().c_str() );
1780 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1782 if ( !isAccessibleDim( aDim )) continue;
1784 // find or create algorithm
1785 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1786 if ( !anAlgoVar->_is_nil() )
1787 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1788 // assign hypotheses
1789 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1791 int aHypIndex = currentHyp( aDim, aHypType );
1792 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1794 SMESH::SMESH_Hypothesis_var aHypVar =
1795 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1796 if ( !aHypVar->_is_nil() )
1797 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1802 // deselect geometry: next submesh should be created on other sub-shape
1803 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1804 selectObject( _PTR(SObject)() );
1810 //================================================================================
1812 * \brief Gets current hypothesis or algorithms
1813 * \param theDim - dimension of hypothesis or algorithm
1814 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1815 * \retval int - current hypothesis or algorithms
1817 * Gets current hypothesis or algorithms
1819 //================================================================================
1820 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1822 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1825 //================================================================================
1827 * \brief Returns true if hypotheses of given dim can be assigned
1828 * \param theDim - hypotheses dimension
1829 * \retval bool - result
1831 //================================================================================
1832 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1834 return myDlg->isTabEnabled( theDim );
1837 //================================================================================
1839 * \brief Sets current hypothesis or algorithms
1840 * \param theDim - dimension of hypothesis or algorithm
1841 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1842 * \param theIndex - Index of hypothesis
1844 * Gets current hypothesis or algorithms
1846 //================================================================================
1847 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1848 const int theHypType,
1849 const int theIndex )
1851 myIgnoreAlgoSelection = true;
1852 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1853 myIgnoreAlgoSelection = false;
1856 //================================================================================
1858 * \brief Generates default and sets mesh/submesh name
1860 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1862 //================================================================================
1863 void SMESHGUI_MeshOp::setDefaultName() const
1867 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1869 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1870 _PTR(SObject) anObj;
1873 aResName = aPrefix + QString::number( i++ );
1874 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1878 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1879 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1880 aControl->setText( aResName );
1883 //================================================================================
1885 * \brief Gets algorithm or creates it if necessary
1886 * \param theDim - specifies dimension of returned hypotheses/algorifms
1887 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1889 * Gets algorithm or creates it if necessary
1891 //================================================================================
1892 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1894 SMESH::SMESH_Hypothesis_var anAlgoVar;
1896 // get type of the selected algo
1897 int aHypIndex = currentHyp( theDim, Algo );
1898 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1899 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1901 QString aHypName = dataList[ aHypIndex ]->TypeName;
1903 // get existing algoritms
1904 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1906 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1908 // look for an existing algo of such a type
1909 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1910 THypList::iterator anIter = aHypVarList.begin();
1911 for ( ; anIter != aHypVarList.end(); anIter++)
1913 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1914 CORBA::String_var aName = aHypVar->GetName();
1915 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1917 anAlgoVar = aHypVar;
1922 if (anAlgoVar->_is_nil())
1924 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1927 QString aClientLibName = aHypData->ClientLibName;
1928 if ( aClientLibName.isEmpty() )
1930 // Call hypothesis creation server method (without GUI)
1931 SMESH::SMESH_Hypothesis_var aHyp =
1932 SMESH::CreateHypothesis(aHypName, aHypName, true);
1937 // Get hypotheses creator client (GUI)
1938 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1942 aCreator->create( true, aHypName, myDlg, 0, QString::null );
1944 SMESH::SMESH_Hypothesis_var aHyp =
1945 SMESH::CreateHypothesis(aHypName, aHypName, true);
1949 QStringList tmpList;
1950 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1951 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1954 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1955 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1957 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1958 CORBA::String_var aName = aHypVar->GetName();
1959 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1961 anAlgoVar = aHypVar;
1967 return anAlgoVar._retn();
1970 //================================================================================
1972 * \brief Reads parameters of an edited mesh and assigns them to the dialog
1974 * Called when mesh is edited only.
1976 //================================================================================
1977 void SMESHGUI_MeshOp::readMesh()
1979 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1980 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1984 if (myIsOnGeometry) {
1985 // Get name of mesh if current object is sub-mesh
1986 SMESH::SMESH_subMesh_var aSubMeshVar =
1987 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1988 if ( !aSubMeshVar->_is_nil() )
1990 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1991 if ( !aMeshVar->_is_nil() )
1993 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1994 QString aMeshName = name( aMeshSO );
1995 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1999 // Get name of geometry object
2000 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2001 if ( !aGeomVar->_is_nil() )
2003 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2004 QString aShapeName = name( aGeomSO );
2005 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2009 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2010 QStringList anExisting;
2011 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2012 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2015 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2016 // find algo index among available ones
2018 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2020 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2021 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2022 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2023 // if ( aHypIndex < 0 && algoData ) {
2024 // // assigned algo is incompatible with other algorithms
2025 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2026 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2029 setCurrentHyp( dim, Algo, aHypIndex );
2030 // set existing and available hypothesis according to the selected algo
2031 onAlgoSelected( aHypIndex, dim );
2035 bool hypWithoutAlgo = false;
2036 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2038 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2041 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2042 // find index of requered hypothesis among existing ones for this dimension and type
2044 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2045 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2046 myExistingHyps[ dim ][ hypType ] );
2047 if ( aHypIndex < 0 ) {
2048 // assigned hypothesis is incompatible with the algorithm
2049 if ( currentHyp( dim, Algo ) < 0 )
2050 { // none algo selected; it is edition for sure, of submesh maybe
2051 hypWithoutAlgo = true;
2052 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2053 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2054 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2058 setCurrentHyp( dim, hypType, aHypIndex );
2061 // make available other hyps of same type as one without algo
2062 if ( hypWithoutAlgo )
2063 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2066 //================================================================================
2068 * \brief Gets name of object
2069 * \param theSO - SObject
2070 * \retval QString - name of object
2072 * Gets name of object
2074 //================================================================================
2075 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2080 _PTR(GenericAttribute) anAttr;
2081 _PTR(AttributeName) aNameAttr;
2082 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2085 aResName = aNameAttr->Value().c_str();
2091 //================================================================================
2093 * \brief Finds hypothesis in input list
2094 * \param theHyp - hypothesis to be found
2095 * \param theHypList - input list of hypotheses
2096 * \retval int - index of hypothesis or -1 if it is not found
2098 * Finds position of hypothesis in input list
2100 //================================================================================
2101 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2102 const THypList& theHypList ) const
2105 if ( !theHyp->_is_nil() )
2108 THypList::const_iterator anIter = theHypList.begin();
2109 for ( ; anIter != theHypList.end(); ++ anIter)
2111 if ( theHyp->_is_equivalent( (*anIter).first ) )
2122 //================================================================================
2124 * \brief Edits mesh or sub-mesh
2125 * \param theMess - Output parameter intended for returning error message
2126 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2128 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2130 //================================================================================
2131 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2135 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2136 if ( aSMESHGen->_is_nil() )
2139 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2140 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2144 SUIT_OverrideCursor aWaitCursor;
2147 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2148 SMESH::SetName( pObj, aName );
2149 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2151 // First, remove old algos in order to avoid messages on algorithm hiding
2152 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2154 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2156 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2157 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2158 if ( anAlgoVar->_is_nil() || // no new algo selected or
2159 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2161 // remove old algorithm
2162 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2163 myObjHyps[ dim ][ Algo ].clear();
2168 // Assign new algorithms and hypotheses
2169 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2171 if ( !isAccessibleDim( dim )) continue;
2173 // find or create algorithm
2174 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2176 // assign new algorithm
2177 if ( !anAlgoVar->_is_nil() && // some algo selected and
2178 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2180 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2181 CORBA::Object_var anObject = aSObject->GetObject();
2182 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2183 bool isMesh = !aMeshVar->_is_nil();
2185 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2187 SMESH::SMESH_subMesh_var aVar =
2188 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2189 if ( !aVar->_is_nil() )
2190 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2192 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2195 // assign hypotheses
2196 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2198 int aNewHypIndex = currentHyp( dim, hypType );
2199 int anOldHypIndex = -1;
2201 // remove old hypotheses
2202 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2204 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2205 myExistingHyps[ dim ][ hypType ] );
2206 if ( aNewHypIndex != anOldHypIndex || // different hyps
2207 anOldHypIndex == -1 ) // hyps of different algos
2209 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2210 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2211 myObjHyps[ dim ][ hypType ].clear();
2215 // assign new hypotheses
2216 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2218 SMESH::SMESH_Mesh_var aMeshVar =
2219 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2220 bool isMesh = !aMeshVar->_is_nil();
2223 SMESH::AddHypothesisOnMesh
2224 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2228 SMESH::SMESH_subMesh_var aVar =
2229 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2230 if ( !aVar->_is_nil() )
2231 SMESH::AddHypothesisOnSubMesh
2232 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2235 // reread all hypotheses of mesh if necessary
2236 QStringList anExisting;
2237 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2244 //================================================================================
2246 * \brief Verifies whether given operator is valid for this one
2247 * \param theOtherOp - other operation
2248 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2250 * method redefined from base class verifies whether given operator is valid for
2251 * this one (i.e. can be started "above" this operator). In current implementation method
2252 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2255 //================================================================================
2256 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2258 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2261 //================================================================================
2263 * \brief SLOT. Is called when the user selects a way of geometry selection
2264 * \param theByMesh - true if the user wants to find geometry by mesh element
2266 //================================================================================
2267 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2270 if ( !myShapeByMeshOp ) {
2271 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2272 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2273 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2274 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2275 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2277 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2278 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2279 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2280 SMESH::SMESH_Mesh_var aMeshVar =
2281 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2282 if ( !aMeshVar->_is_nil() ) {
2283 myDlg->hide(); // stop processing selection
2284 myShapeByMeshOp->setModule( getSMESHGUI() );
2285 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2286 myShapeByMeshOp->SetMesh( aMeshVar );
2287 myShapeByMeshOp->start();
2293 //================================================================================
2295 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2297 //================================================================================
2298 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2300 if ( myShapeByMeshOp == op ) {
2301 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2303 // Select a found geometry object
2304 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2305 if ( !aGeomVar->_is_nil() )
2307 QString ID = aGeomVar->GetStudyEntry();
2308 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2309 selectObject( aGeomSO );
2316 //================================================================================
2318 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2320 //================================================================================
2321 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2323 if ( myShapeByMeshOp == op && myDlg ) {
2328 //================================================================================
2330 * \brief Selects a SObject
2331 * \param theSObj - the SObject to select
2333 //================================================================================
2334 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2336 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2337 SALOME_ListIO anIOList;
2339 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2340 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2341 anIOList.Append( anIO );
2343 sm->setSelectedObjects( anIOList, false );