1 // Copyright (C) 2007-2011 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>
44 // SALOME GUI includes
45 #include <SalomeApp_Tools.h>
46 #include <SalomeApp_Application.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SUIT_Session.h>
53 #include <SALOME_InteractiveObject.hxx>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDS_SComponent.hxx>
58 #include <SALOMEDS_SObject.hxx>
61 #include <QStringList>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Shell.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <BRep_Tool.hxx>
72 #include <SALOMEconfig.h>
73 #include CORBA_CLIENT_HEADER(SMESH_Gen)
75 //To disable automatic genericobj management, the following line should be commented.
76 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
77 #define WITHGENERICOBJ
79 //================================================================================
82 * \param theToCreate - if this parameter is true then operation is used for creation,
83 * for editing otherwise
85 * Initialize operation
87 //================================================================================
88 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
89 : SMESHGUI_SelectionOp(),
90 myToCreate( theToCreate ),
91 myIsMesh( theIsMesh ),
96 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
97 GeometryGUI::InitGeomGen();
98 myIsOnGeometry = true;
101 //================================================================================
105 //================================================================================
106 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
112 //================================================================================
114 * \brief Gets dialog of this operation
115 * \retval LightApp_Dialog* - pointer to dialog of this operation
117 //================================================================================
118 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
123 //================================================================================
125 * \brief Creates or edits mesh
126 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
128 * Virtual slot redefined from the base class called when "Apply" button is clicked
129 * creates or edits mesh
131 //================================================================================
132 bool SMESHGUI_MeshOp::onApply()
138 if ( !isValid( aMess ) )
142 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
146 bool aResult = false;
150 QStringList anEntryList;
151 if ( myToCreate && myIsMesh )
152 aResult = createMesh( aMess, anEntryList );
153 if ( myToCreate && !myIsMesh )
154 aResult = createSubMesh( aMess, anEntryList );
155 else if ( !myToCreate )
156 aResult = editMeshOrSubMesh( aMess );
159 SMESHGUI::Modified();
160 update( UF_ObjBrowser | UF_Model );
161 if( LightApp_Application* anApp =
162 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
163 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
166 catch ( const SALOME::SALOME_Exception& S_ex )
168 SalomeApp_Tools::QtCatchCorbaException( S_ex );
184 aMess = tr( "SMESH_OPERATION_FAILED" );
185 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
191 //================================================================================
193 * \brief Creates dialog if necessary and shows it
195 * Virtual method redefined from base class called when operation is started creates
196 * dialog if necessary and shows it, activates selection
198 //================================================================================
199 void SMESHGUI_MeshOp::startOperation()
203 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
204 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
206 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
207 this, SLOT( onCreateHyp( const int, const int ) ) );
208 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
209 this, SLOT( onEditHyp( const int, const int ) ) );
210 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
211 this, SLOT( onAlgoSelected( const int ) ) );
213 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
214 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
218 else myHelpFileName = "constructing_submeshes_page.html";
219 else myHelpFileName = "editing_meshes_page.html";
221 SMESHGUI_SelectionOp::startOperation();
223 // iterate through dimensions and get available algoritms, set them to the dialog
224 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
225 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
227 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
229 // clear available hypotheses
230 aTab->setAvailableHyps( MainHyp, hypList );
231 aTab->setAvailableHyps( AddHyp, hypList );
232 aTab->setExistingHyps( MainHyp, hypList );
233 aTab->setExistingHyps( AddHyp, hypList );
234 myExistingHyps[ i ][ MainHyp ].clear();
235 myExistingHyps[ i ][ AddHyp ].clear();
237 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
238 aTab->setAvailableHyps( Algo, hypList );
243 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
246 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
248 myDlg->setCurrentTab( SMESH::DIM_3D );
250 myDlg->setGeomPopupEnabled(false);
253 myIgnoreAlgoSelection = false;
255 myObjectToSelect.clear();
258 //=================================================================================
260 * \brief Selects a recently created mesh or sub-mesh if necessary
262 * Virtual method redefined from base class called when operation is commited
263 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
264 * selection when the custom selection filters are removed.
266 //=================================================================================
267 void SMESHGUI_MeshOp::commitOperation()
269 SMESHGUI_SelectionOp::commitOperation();
271 if ( !myObjectToSelect.isEmpty() ) {
272 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
273 SUIT_DataOwnerPtrList aList;
274 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
275 aSelectionMgr->setSelected( aList );
280 //================================================================================
282 * \brief Creates selection filter
283 * \param theId - identifier of current selection widget
284 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
286 * Creates selection filter in accordance with identifier of current selection widget
288 //================================================================================
289 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
291 if ( theId == SMESHGUI_MeshDlg::Geom )
293 // TColStd_MapOfInteger allTypesMap;
294 // for ( int i = 0; i < 10; i++ )
295 // allTypesMap.Add( i );
296 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
297 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
299 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
300 return new SMESH_TypeFilter( MESHorSUBMESH );
301 else if ( theId == SMESHGUI_MeshDlg::Mesh )
302 return new SMESH_TypeFilter( MESH );
307 //================================================================================
309 * \brief check if selected shape is a subshape of the shape to mesh
310 * \retval bool - check result
312 //================================================================================
313 bool SMESHGUI_MeshOp::isSubshapeOk() const
315 if ( !myToCreate || myIsMesh ) // not submesh creation
319 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
320 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
321 if (!pMesh) return false;
323 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
324 if (mesh->_is_nil()) return false;
326 // main shape of the mesh
327 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
328 if (mainGeom->_is_nil()) return false;
332 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
334 if (aGEOMs.count() > 0) {
335 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
336 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
337 if (geomGen->_is_nil() || !aStudy) return false;
339 GEOM::GEOM_IGroupOperations_var op =
340 geomGen->GetIGroupOperations(aStudy->StudyId());
341 if (op->_is_nil()) return false;
343 // check all selected shapes
344 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
345 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
346 QString aSubGeomEntry = (*aSubShapesIter);
347 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
348 if (!pSubGeom) return false;
350 GEOM::GEOM_Object_var aSubGeomVar =
351 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
352 if (aSubGeomVar->_is_nil()) return false;
354 // skl for NPAL14695 - implementation of searching of mainObj
355 GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
356 //if (mainObj->_is_nil() ||
357 // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
359 if (mainObj->_is_nil())
361 if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry()))
363 mainObj = op->GetMainShape(mainObj);
372 //================================================================================
374 * \brief Return name of the algorithm that does not support submeshes and makes
375 * submesh creation useless
376 * \retval char* - string is to be deleted!!!
378 //================================================================================
379 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
381 if ( myToCreate && !myIsMesh ) {
383 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
384 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
385 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
388 QStringList algoNames;
390 existingHyps(3, Algo, pMesh, algoNames, algoList);
391 if (!algoList.empty()) {
392 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
394 algo->InputTypes.empty() && // builds all dimensions it-self
395 !algo->IsSupportSubmeshes )
396 return CORBA::string_dup( algoNames[0].toLatin1().data() );
399 // GEOM::GEOM_Object_var geom;
400 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
401 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
403 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
404 existingHyps(2, Algo, pMesh, algoNames, algoList);
405 if (!algoList.empty()) {
406 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
408 algo->InputTypes.empty() && // builds all dimensions it-self
409 !algo->IsSupportSubmeshes )
410 return CORBA::string_dup( algoNames[0].toLatin1().data() );
418 //================================================================================
420 * \brief find an existing submesh by the selected shape
421 * \retval _PTR(SObject) - the found submesh SObject
423 //================================================================================
424 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
426 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
427 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
428 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
429 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
430 if ( pMesh && pGeom ) {
431 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
432 if ( !geom->_is_nil() ) {
434 switch ( geom->GetShapeType() ) {
435 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
436 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
437 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
438 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
439 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
440 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
441 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
444 _PTR(GenericAttribute) anAttr;
445 _PTR(SObject) aSubmeshRoot;
446 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
447 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
449 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
450 for ( ; smIter->More(); smIter->Next() )
452 _PTR(SObject) aSmObj = smIter->Value();
453 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
455 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
456 for ( ; anIter1->More(); anIter1->Next()) {
457 _PTR(SObject) pGeom2 = anIter1->Value();
458 if ( pGeom2->ReferencedObject( pGeom2 ) &&
459 pGeom2->GetID() == pGeom->GetID() )
466 return _PTR(SObject)();
469 //================================================================================
471 * \brief Updates dialog's look and feel
473 * Virtual method redefined from the base class updates dialog's look and feel
475 //================================================================================
476 void SMESHGUI_MeshOp::selectionDone()
478 if (!dlg()->isVisible() || !myDlg->isEnabled())
481 SMESHGUI_SelectionOp::selectionDone();
485 myIsOnGeometry = true;
487 //Check geometry for mesh
488 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
489 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
492 SMESH::SMESH_Mesh_var aMeshVar =
493 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
494 if (!aMeshVar->_is_nil()) {
495 if (!myToCreate && !aMeshVar->HasShapeToMesh())
496 myIsOnGeometry = false;
502 // Enable tabs according to shape dimension
507 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
508 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
510 if (aGEOMs.count() > 0) {
511 // one or more GEOM shape selected
512 aSeq->length(aGEOMs.count());
513 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
515 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
516 QString aSubGeomEntry = (*aSubShapesIter);
517 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
518 GEOM::GEOM_Object_var aSubGeomVar =
519 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
520 aSeq[iSubSh] = aSubGeomVar;
523 // get geometry by selected sub-mesh
524 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
525 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
526 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
527 if (!aGeomVar->_is_nil()) {
533 if (aSeq->length() > 0) {
535 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
536 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
537 switch ( aGeomVar->GetShapeType() ) {
538 case GEOM::SOLID: shapeDim = 3; break;
541 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
543 bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
544 shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
547 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
549 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
550 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
554 if (GEOMBase::GetShape(aGeomVar, aShape)) {
555 TopExp_Explorer exp (aShape, TopAbs_SHELL);
557 //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
558 shapeDim = qMax(2, shapeDim);
559 for (; exp.More() && shapeDim == 2; exp.Next()) {
560 if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
564 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
565 shapeDim = qMax(2, shapeDim);
566 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
567 shapeDim = qMax(1, shapeDim);
568 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
569 shapeDim = qMax(0, shapeDim);
575 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
576 // reset algos before disabling tabs (0020138)
577 onAlgoSelected(-1, i);
579 myDlg->setMaxHypoDim( shapeDim );
580 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
582 if (!myToCreate) // edition: read hypotheses
586 SMESH::SMESH_subMesh_var aVar =
587 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
588 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
589 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
590 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
591 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
592 myDlg->updateGeometry();
599 else if ( !myIsMesh ) // submesh creation
601 // if a submesh on the selected shape already exist, pass to submesh edition mode
602 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
603 SMESH::SMESH_subMesh_var sm =
604 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
605 bool editSubmesh = ( !sm->_is_nil() &&
606 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
607 tr( "EDIT_SUBMESH_QUESTION"),
608 SUIT_MessageBox::Yes |
610 SUIT_MessageBox::No )
611 == SUIT_MessageBox::Yes );
614 selectionMgr()->clearFilters();
615 selectObject( pSubmesh );
616 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
621 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
622 selectObject( _PTR(SObject)() );
627 // discard selected mesh if submesh creation not allowed because of
628 // a global algorithm that does not support submeshes
629 if ( char* algoName = isSubmeshIgnored() ) {
630 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
631 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
632 CORBA::string_free( algoName );
633 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
634 selectObject( _PTR(SObject)() );
639 // enable/disable popup for choice of geom selection way
641 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
642 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
643 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
644 if ( !mesh->_is_nil() ) {
645 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
646 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
647 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
648 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
649 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
650 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
653 myDlg->setGeomPopupEnabled( enable );
656 else { // no geometry defined
657 myDlg->enableTab( SMESH::DIM_3D );
659 availableHyps( SMESH::DIM_3D, Algo, hypList,
660 myAvailableHypData[SMESH::DIM_3D][Algo]);
662 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
663 aTab->setAvailableHyps( Algo, hypList );
664 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
665 myDlg->disableTab(i);
667 //Hide labels and fields (Mesh ang Geometry)
668 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
669 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
674 catch ( const SALOME::SALOME_Exception& S_ex )
676 SalomeApp_Tools::QtCatchCorbaException( S_ex );
683 //================================================================================
685 * \brief Verifies validity of input data
686 * \param theMess - Output parameter intended for returning error message
687 * \retval bool - TRUE if input data is valid, false otherwise
689 * Verifies validity of input data. This method is called when "Apply" or "OK" button
690 * is pressed before mesh creation or editing.
692 //================================================================================
693 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
695 // Selected object to be edited
696 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
698 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
703 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
704 if ( aMeshName.isEmpty() )
706 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
710 /* // Imported mesh, if create sub-mesh or edit mesh
711 if ( !myToCreate || ( myToCreate && !myIsMesh ))
713 QString aMeshEntry = myDlg->selectedObject
714 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
715 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
716 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
717 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
718 theMess = tr( "IMPORTED_MESH" );
727 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
728 if ( aGeomEntry == "" )
730 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
733 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
734 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
736 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
741 if ( !myIsMesh ) // i.e sub-mesh creation,
743 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
744 if ( aMeshEntry == "" )
746 theMess = tr( "MESH_IS_NOT_DEFINED" );
749 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
750 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
752 theMess = tr( "MESH_IS_NULL" );
755 if ( !isSubshapeOk() )
757 theMess = tr( "INVALID_SUBSHAPE" );
766 //================================================================================
768 * \brief check compatibility of the algorithm and another algorithm or hypothesis
769 * \param theAlgoData - algorithm data
770 * \param theHypData - hypothesis data
771 * \param theHypType - hypothesis type
772 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
773 * \retval bool - check result
775 //================================================================================
776 static bool isCompatible(const HypothesisData* theAlgoData,
777 const HypothesisData* theHypData,
778 const int theHypType)
783 if ( theHypType == SMESHGUI_MeshOp::Algo )
784 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
787 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
790 //================================================================================
792 * \brief Gets available hypotheses or algorithms
793 * \param theDim - specifies dimension of returned hypotheses/algorifms
794 * \param theHypType - specifies whether algorims or hypotheses or additional ones
795 * are retrieved (possible values are in HypType enumeration)
796 * \param theHyps - Output list of hypotheses' names
797 * \param theAlgoData - to select hypos able to be used by this algo (optional)
799 * Gets available hypotheses or algorithm in accordance with input parameters
801 //================================================================================
802 void SMESHGUI_MeshOp::availableHyps( const int theDim,
803 const int theHypType,
804 QStringList& theHyps,
805 THypDataList& theDataList,
806 HypothesisData* theAlgoData ) const
810 bool isAlgo = ( theHypType == Algo );
811 bool isAux = ( theHypType == AddHyp );
812 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
814 QStringList::const_iterator anIter;
815 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
817 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
818 if ( isCompatible ( theAlgoData, aData, theHypType )) {
819 theDataList.append( aData );
820 theHyps.append( aData->Label );
825 //================================================================================
827 * \brief Gets existing hypotheses or algorithms
828 * \param theDim - specifies dimension of returned hypotheses/algorifms
829 * \param theHypType - specifies whether algorims or hypotheses or additional ones
830 * are retrieved (possible values are in HypType enumeration)
831 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
832 * \param theHyps - output list of names.
833 * \param theHypVars - output list of variables.
834 * \param theAlgoData - to select hypos able to be used by this algo (optional)
836 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
839 //================================================================================
840 void SMESHGUI_MeshOp::existingHyps( const int theDim,
841 const int theHypType,
842 _PTR(SObject) theFather,
843 QStringList& theHyps,
844 THypList& theHypList,
845 HypothesisData* theAlgoData)
847 // Clear hypoheses list
854 const bool isAux = ( theHypType == AddHyp );
856 _PTR(SObject) aHypRoot;
857 _PTR(GenericAttribute) anAttr;
858 _PTR(AttributeName) aName;
859 _PTR(AttributeIOR) anIOR;
861 bool isMesh = !_CAST( SComponent, theFather );
864 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
866 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
868 if ( theFather->FindSubObject( aPart, aHypRoot ) )
870 _PTR(ChildIterator) anIter =
871 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
872 for ( ; anIter->More(); anIter->Next() )
874 _PTR(SObject) anObj = anIter->Value();
875 if ( isMesh ) // i.e. mesh or submesh
877 _PTR(SObject) aRefObj;
878 if ( anObj->ReferencedObject( aRefObj ) )
883 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
886 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
887 if ( !CORBA::is_nil( aVar ) )
889 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
890 if ( !aHypVar->_is_nil() )
892 HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() );
893 if ( !aData) continue;
894 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
895 ( isCompatible ( theAlgoData, aData, theHypType )) &&
896 ( isAux == aData->IsAux ))
898 std::string aHypName = aName->Value();
899 theHyps.append( aHypName.c_str() );
900 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
909 //================================================================================
911 * \brief If create or edit a submesh, return a hypothesis holding parameters used
913 * \param aHypType - The hypothesis type name
914 * \param aServerLib - Server library name
915 * \param hypData - The structure holding the hypothesis type etc.
916 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
918 //================================================================================
919 SMESH::SMESH_Hypothesis_var
920 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
921 const QString& aServerLib ) const
923 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
924 return SMESH::SMESH_Hypothesis::_nil();
926 const int nbColonsInMeshEntry = 3;
927 bool isSubMesh = myToCreate ?
929 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
931 // get mesh and geom object
932 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
933 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
938 anEntry = myDlg->selectedObject
939 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
940 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
942 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
943 if ( myToCreate ) // mesh and geom may be selected
945 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
946 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
947 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
948 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
950 else // edition: sub-mesh may be selected
952 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
953 if ( !sm->_is_nil() ) {
954 aMeshVar = sm->GetFather();
955 aGeomVar = sm->GetSubShape();
962 if ( !myToCreate ) // mesh to edit can be selected
964 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
965 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
967 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
968 if ( !aMeshVar->_is_nil() )
969 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
972 if ( aGeomVar->_is_nil() ) {
973 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
974 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
976 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
981 SMESH::SMESH_Hypothesis_var hyp =
982 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
983 aServerLib.toLatin1().data(),
986 /*byMesh = */isSubMesh);
987 if ( hyp->_is_nil() && isSubMesh )
988 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
989 aServerLib.toLatin1().data(),
996 //================================================================================
998 * \Brief Returns tab dimention
999 * \param tab - the tab in the dlg
1000 * \param dlg - my dialogue
1001 * \retval int - dimention
1003 //================================================================================
1004 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1007 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1008 if (tab == dlg->tab(i))
1013 //================================================================================
1015 * \brief Create hypothesis
1016 * \param theHypType - hypothesis category (main or additional)
1017 * \param theIndex - index of type of hypothesis to be cerated
1019 * Specifies dimension of hypothesis to be created (using sender() method),
1020 * specifies its type and calls method for hypothesis creation
1022 //================================================================================
1023 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1025 // Specifies dimension of hypothesis to be created
1026 int aDim = getTabDim( sender(), myDlg );
1030 // Specifies type of hypothesis to be created
1031 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1032 if (theIndex < 0 || theIndex >= dataList.count())
1034 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1036 // Create hypothesis
1037 createHypothesis(aDim, theHypType, aHypTypeName);
1042 QString GetUniqueName (const QStringList& theHypNames,
1043 const QString& theName,
1044 size_t theIteration = 1)
1046 QString aName = theName + "_" + QString::number( theIteration );
1047 if ( theHypNames.contains( aName ) )
1048 return GetUniqueName( theHypNames, theName, ++theIteration );
1053 //================================================================================
1055 * Create hypothesis and update dialog.
1056 * \param theDim - dimension of hypothesis to be created
1057 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1058 * \param theTypeName - specifies hypothesis to be created
1060 //================================================================================
1061 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1063 const QString& theTypeName)
1065 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1071 QStringList aHypNames;
1072 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1073 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1074 const TType2HypList& aType2HypList = aDimIter.value();
1075 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1076 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1077 const THypList& aHypList = aTypeIter.value();
1078 THypList::const_iterator anIter = aHypList.begin();
1079 for ( ; anIter != aHypList.end(); anIter++) {
1080 const THypItem& aHypItem = *anIter;
1081 const QString& aHypName = aHypItem.second;
1082 aHypNames.append(aHypName);
1086 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1089 bool dialog = false;
1091 QString aClientLibName = aData->ClientLibName;
1092 if (aClientLibName == "") {
1093 // Call hypothesis creation server method (without GUI)
1094 SMESH::SMESH_Hypothesis_var aHyp =
1095 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1096 #ifdef WITHGENERICOBJ
1097 if (!CORBA::is_nil(aHyp))
1101 // Get hypotheses creator client (GUI)
1103 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1104 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1106 // Create hypothesis
1108 // Get parameters appropriate to initialize a new hypothesis
1109 SMESH::SMESH_Hypothesis_var initParamHyp =
1110 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1112 removeCustomFilters(); // Issue 0020170
1114 // Get Entry of the Geom object
1115 QString aGeomEntry = "";
1116 QString aMeshEntry = "";
1117 QString anObjEntry = "";
1118 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1119 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1120 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1122 if ( myToCreate && myIsMesh )
1123 aMeshEntry = aGeomEntry;
1125 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1126 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1127 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1128 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1131 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1132 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1134 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1135 if ( !aGeomVar->_is_nil() )
1137 aGeomEntry = aGeomVar->GetStudyEntry();
1139 aMeshEntry = aGeomEntry;
1143 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1144 // take geometry from submesh being created
1145 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1147 // if current object is sub-mesh
1148 SMESH::SMESH_subMesh_var aSubMeshVar =
1149 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1150 if ( !aSubMeshVar->_is_nil() ) {
1151 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1152 if ( !aMeshVar->_is_nil() ) {
1153 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1154 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1155 if ( !aGeomVar->_is_nil() )
1156 aMeshEntry = aGeomVar->GetStudyEntry();
1162 aCreator->setShapeEntry( aGeomEntry );
1163 if ( aMeshEntry != "" )
1164 aCreator->setMainShapeEntry( aMeshEntry );
1165 myDlg->setEnabled( false );
1166 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1170 SMESH::SMESH_Hypothesis_var aHyp =
1171 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1172 #ifdef WITHGENERICOBJ
1173 if (!CORBA::is_nil(aHyp))
1183 //================================================================================
1185 * Necessary steps after hypothesis creation
1186 * \param result - creation result:
1189 * 2 = additional value meaning that slot is called not from dialog box
1191 //================================================================================
1192 void SMESHGUI_MeshOp::onHypoCreated( int result )
1196 int obj = myDlg->getActiveObject();
1197 onActivateObject( obj ); // Issue 0020170. Restore filters
1198 myDlg->setEnabled( true );
1201 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1203 int nbHyp = myExistingHyps[myDim][myType].count();
1204 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1205 QStringList aNewHyps;
1206 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1207 if (aNewHyps.count() > nbHyp)
1209 for (int i = nbHyp; i < aNewHyps.count(); i++)
1210 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1213 if( result!=2 && myHypoSet )
1217 //================================================================================
1219 * \brief Calls plugin methods for hypothesis editing
1220 * \param theHypType - specifies whether main hypothesis or additional one
1222 * \param theIndex - index of existing hypothesis
1224 * Calls plugin methods for hypothesis editing
1226 //================================================================================
1227 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1229 // Speicfies dimension of hypothesis to be created
1230 int aDim = getTabDim( sender(), myDlg );
1234 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1235 if ( theIndex < 0 || theIndex >= aList.count() )
1237 const THypItem& aHypItem = aList[ theIndex ];
1238 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1239 if ( aHyp->_is_nil() )
1242 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1245 // Get initial parameters
1246 SMESH::SMESH_Hypothesis_var initParamHyp =
1247 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1248 aCreator->setInitParamsHypothesis( initParamHyp );
1250 // Get Entry of the Geom object
1251 QString aGeomEntry = "";
1252 QString aMeshEntry = "";
1253 QString anObjEntry = "";
1254 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1255 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1256 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1258 if ( myToCreate && myIsMesh )
1259 aMeshEntry = aGeomEntry;
1261 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1262 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1263 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1264 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1267 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1268 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1270 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1271 if ( !aGeomVar->_is_nil() )
1273 aGeomEntry = aGeomVar->GetStudyEntry();
1275 aMeshEntry = aGeomEntry;
1279 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1280 // take geometry from submesh being created
1281 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1283 // if current object is sub-mesh
1284 SMESH::SMESH_subMesh_var aSubMeshVar =
1285 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1286 if ( !aSubMeshVar->_is_nil() ) {
1287 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1288 if ( !aMeshVar->_is_nil() ) {
1289 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1290 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1291 if ( !aGeomVar->_is_nil() )
1292 aMeshEntry = aGeomVar->GetStudyEntry();
1298 aCreator->setShapeEntry( aGeomEntry );
1299 if ( aMeshEntry != "" )
1300 aCreator->setMainShapeEntry( aMeshEntry );
1301 removeCustomFilters(); // Issue 0020170
1302 myDlg->setEnabled( false );
1303 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1307 //================================================================================
1309 * Necessary steps after hypothesis edition
1310 * \param result - creation result:
1314 //================================================================================
1315 void SMESHGUI_MeshOp::onHypoEdited( int result )
1317 int obj = myDlg->getActiveObject();
1318 onActivateObject( obj ); // Issue 0020170. Restore filters
1319 myDlg->setEnabled( true );
1322 //================================================================================
1324 * \brief access to hypothesis data
1325 * \param theDim - hyp dimension
1326 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1327 * \param theIndex - index in the list
1328 * \retval HypothesisData* - result data, may be 0
1330 //================================================================================
1331 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1332 const int theHypType,
1335 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1336 theHypType > -1 && theHypType < NbHypTypes &&
1337 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1338 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1342 //================================================================================
1344 * \brief Set available algos and hypos according to the selected algorithm
1345 * \param theIndex - algorithm index
1347 //================================================================================
1348 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1351 if ( myIgnoreAlgoSelection )
1354 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1358 // find highest available dimension, all algos of this dimension are available for choice
1360 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1361 if (isAccessibleDim( i ))
1366 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1368 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1369 HypothesisData* algoByDim[4];
1370 algoByDim[ aDim ] = algoData;
1372 QStringList anAvailable;
1373 if ( !algoData ) { // all algos becomes available
1374 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1375 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1378 // check that algorithms of other dimentions are compatible with
1381 // 2 loops: backward and forward from algo dimension
1382 for ( int forward = false; forward <= true; ++forward )
1384 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1386 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1388 HypothesisData* prevAlgo = algoData;
1389 bool noCompatible = false;
1390 for ( ; dim * dir <= lastDim * dir; dim += dir)
1392 if ( !isAccessibleDim( dim ))
1394 if ( noCompatible ) { // the selected algo has no compatible ones
1395 anAvailable.clear();
1396 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1397 myAvailableHypData[dim][Algo].clear();
1398 algoByDim[ dim ] = 0;
1401 // get currently selected algo
1402 int algoIndex = currentHyp( dim, Algo );
1403 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1404 if ( curAlgo ) { // some algo selected
1405 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1408 // set new available algoritms
1409 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1410 HypothesisData* soleCompatible = 0;
1411 if ( anAvailable.count() == 1 )
1412 soleCompatible = myAvailableHypData[dim][Algo][0];
1413 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1414 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1415 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1416 noCompatible = anAvailable.isEmpty();
1418 // restore previously selected algo
1419 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1420 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1421 // select the sole compatible algo
1422 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1423 setCurrentHyp( dim, Algo, algoIndex );
1425 // remember current algo
1426 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1430 // set hypotheses corresponding to the found algoritms
1432 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1434 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1436 if ( !isAccessibleDim( dim ))
1438 for ( int type = MainHyp; type < NbHypTypes; type++ )
1440 myAvailableHypData[ dim ][ type ].clear();
1441 QStringList anAvailable, anExisting;
1443 HypothesisData* curAlgo = algoByDim[ dim ];
1444 int hypIndex = currentHyp( dim, type );
1446 SMESH::SMESH_Hypothesis_var curHyp;
1447 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1448 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1450 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1451 // try to find algo by selected hypothesis in order to keep it selected
1452 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1453 CORBA::String_var curHypType = curHyp->GetName();
1454 if ( !algoDeselectedByUser &&
1455 myObjHyps[ dim ][ type ].count() > 0 &&
1456 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1458 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1459 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1460 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1461 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1468 // get hyps compatible with curAlgo
1471 // check if a selected hyp is compatible with the curAlgo
1472 if ( !curHyp->_is_nil() ) {
1473 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1474 if ( !isCompatible( curAlgo, hypData, type ))
1475 curHyp = SMESH::SMESH_Hypothesis::_nil();
1477 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1478 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1480 // set list of hypotheses
1481 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1482 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1484 // set current existing hypothesis
1485 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1486 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1489 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1490 // none is yet selected => select the sole existing if it is not optional
1491 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1492 bool isOptional = true;
1493 if ( algoByDim[ dim ] &&
1494 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1498 setCurrentHyp( dim, type, hypIndex );
1503 //================================================================================
1505 * \brief Creates and selects hypothesis of hypotheses set
1506 * \param theSetName - The name of hypotheses set
1508 //================================================================================
1509 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1511 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1516 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1517 setCurrentHyp(dim, Algo, -1);
1518 setCurrentHyp(dim, AddHyp, -1);
1519 setCurrentHyp(dim, MainHyp, -1);
1522 myHypoSet->init(true); //algorithms
1524 myHypoSet->init(false); //hypotheses
1529 //================================================================================
1531 * \brief One step of hypothesis/algorithm list creation
1533 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1535 //================================================================================
1536 void SMESHGUI_MeshOp::processSet()
1539 if( !myHypoSet->more() )
1542 bool isAlgo = myHypoSet->isAlgo();
1543 QString aHypoTypeName = myHypoSet->current();
1544 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1551 int aDim = aHypData->Dim[0];
1552 // create or/and set
1555 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1558 QStringList anAvailable;
1559 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1560 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1561 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1563 setCurrentHyp( aDim, Algo, index );
1564 onAlgoSelected( index, aDim );
1569 bool mainHyp = true;
1570 QStringList anAvailable;
1571 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1572 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1573 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1577 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1580 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1586 //================================================================================
1588 * \brief Creates mesh
1589 * \param theMess - Output parameter intended for returning error message
1590 * \param theEntryList - List of entries of published objects
1591 * \retval bool - TRUE if mesh is created, FALSE otherwise
1595 //================================================================================
1596 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1600 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1601 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1604 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1605 QStringList::Iterator it = aList.begin();
1606 for ( ; it!=aList.end(); it++)
1608 QString aGeomEntry = *it;
1609 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1610 GEOM::GEOM_Object_var aGeomVar =
1611 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1613 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1614 if ( aSMESHGen->_is_nil() )
1617 SUIT_OverrideCursor aWaitCursor;
1620 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1621 if ( aMeshVar->_is_nil() )
1623 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1625 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1626 theEntryList.append( aMeshSO->GetID().c_str() );
1629 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1630 if ( !isAccessibleDim( aDim )) continue;
1632 // assign hypotheses
1633 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1634 int aHypIndex = currentHyp( aDim, aHypType );
1635 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1636 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1637 if ( !aHypVar->_is_nil() )
1638 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1641 // find or create algorithm
1642 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1643 if ( !anAlgoVar->_is_nil() )
1644 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1646 #ifdef WITHGENERICOBJ
1647 // obj has been published in study. Its refcount has been incremented.
1648 // It is safe to decrement its refcount
1649 // so that it will be destroyed when the entry in study will be removed
1651 aMeshVar->UnRegister();
1657 //================================================================================
1659 * \brief Creates sub-mesh
1660 * \param theMess - Output parameter intended for returning error message
1661 * \param theEntryList - List of entries of published objects
1662 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1666 //================================================================================
1667 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1671 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1672 if ( aSMESHGen->_is_nil() )
1676 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1677 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1678 SMESH::SMESH_Mesh_var aMeshVar =
1679 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1680 if (aMeshVar->_is_nil())
1683 // GEOM shape of the main mesh
1684 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1686 // Name for the new sub-mesh
1687 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1690 GEOM::GEOM_Object_var aGeomVar;
1692 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1693 if (aGEOMs.count() == 1)
1695 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1696 QString aGeomEntry = aGEOMs.first();
1697 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1698 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1700 else if (aGEOMs.count() > 1)
1702 // create a GEOM group
1703 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1704 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1705 if (!geomGen->_is_nil() && aStudy) {
1706 GEOM::GEOM_IGroupOperations_var op =
1707 geomGen->GetIGroupOperations(aStudy->StudyId());
1708 if (!op->_is_nil()) {
1709 // check and add all selected GEOM objects: they must be
1710 // a sub-shapes of the main GEOM and must be of one type
1712 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1713 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1714 aSeq->length(aGEOMs.count());
1715 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1716 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1717 QString aSubGeomEntry = (*aSubShapesIter);
1718 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1719 GEOM::GEOM_Object_var aSubGeomVar =
1720 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1721 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1723 aGroupType = aSubShapeType;
1725 if (aSubShapeType != aGroupType)
1726 aGroupType = TopAbs_SHAPE;
1728 aSeq[iSubSh] = aSubGeomVar;
1731 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1732 op->UnionList(aGroupVar, aSeq);
1735 aGeomVar = aGroupVar;
1737 // publish the GEOM group in study
1738 QString aNewGeomGroupName ("Auto_group_for_");
1739 aNewGeomGroupName += aName;
1740 SALOMEDS::SObject_var aNewGroupSO =
1741 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar,
1742 aNewGeomGroupName.toLatin1().data(), mainGeom);
1749 if (aGeomVar->_is_nil())
1752 SUIT_OverrideCursor aWaitCursor;
1755 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1756 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1758 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1759 theEntryList.append( aSubMeshSO->GetID().c_str() );
1762 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1764 if ( !isAccessibleDim( aDim )) continue;
1766 // find or create algorithm
1767 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1768 if ( !anAlgoVar->_is_nil() )
1769 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1770 // assign hypotheses
1771 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1773 int aHypIndex = currentHyp( aDim, aHypType );
1774 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1776 SMESH::SMESH_Hypothesis_var aHypVar =
1777 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1778 if ( !aHypVar->_is_nil() )
1779 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1784 // deselect geometry: next submesh should be created on other subshape
1785 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1786 selectObject( _PTR(SObject)() );
1792 //================================================================================
1794 * \brief Gets current hypothesis or algorithms
1795 * \param theDim - dimension of hypothesis or algorithm
1796 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1797 * \retval int - current hypothesis or algorithms
1799 * Gets current hypothesis or algorithms
1801 //================================================================================
1802 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1804 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1807 //================================================================================
1809 * \brief Returns true if hypotheses of given dim can be assigned
1810 * \param theDim - hypotheses dimension
1811 * \retval bool - result
1813 //================================================================================
1814 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1816 return myDlg->isTabEnabled( theDim );
1819 //================================================================================
1821 * \brief Sets current hypothesis or algorithms
1822 * \param theDim - dimension of hypothesis or algorithm
1823 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1824 * \param theIndex - Index of hypothesis
1826 * Gets current hypothesis or algorithms
1828 //================================================================================
1829 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1830 const int theHypType,
1831 const int theIndex )
1833 myIgnoreAlgoSelection = true;
1834 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1835 myIgnoreAlgoSelection = false;
1838 //================================================================================
1840 * \brief Generates default and sets mesh/submesh name
1842 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1844 //================================================================================
1845 void SMESHGUI_MeshOp::setDefaultName() const
1849 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1851 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1852 _PTR(SObject) anObj;
1855 aResName = aPrefix + QString::number( i++ );
1856 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1860 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1861 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1862 aControl->setText( aResName );
1865 //================================================================================
1867 * \brief Gets algorithm or creates it if necessary
1868 * \param theDim - specifies dimension of returned hypotheses/algorifms
1869 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1871 * Gets algorithm or creates it if necessary
1873 //================================================================================
1874 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1876 SMESH::SMESH_Hypothesis_var anAlgoVar;
1878 // get type of the selected algo
1879 int aHypIndex = currentHyp( theDim, Algo );
1880 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1881 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1883 QString aHypName = dataList[ aHypIndex ]->TypeName;
1885 // get existing algoritms
1886 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1888 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1890 // look for an existing algo of such a type
1891 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1892 THypList::iterator anIter = aHypVarList.begin();
1893 for ( ; anIter != aHypVarList.end(); anIter++)
1895 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1896 CORBA::String_var aName = aHypVar->GetName();
1897 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1899 anAlgoVar = aHypVar;
1904 if (anAlgoVar->_is_nil())
1906 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1909 QString aClientLibName = aHypData->ClientLibName;
1910 if (aClientLibName == "")
1912 // Call hypothesis creation server method (without GUI)
1913 SMESH::SMESH_Hypothesis_var aHyp =
1914 SMESH::CreateHypothesis(aHypName, aHypName, true);
1915 #ifdef WITHGENERICOBJ
1916 if (!CORBA::is_nil(aHyp))
1922 // Get hypotheses creator client (GUI)
1924 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1928 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1930 SMESH::SMESH_Hypothesis_var aHyp =
1931 SMESH::CreateHypothesis(aHypName, aHypName, true);
1932 #ifdef WITHGENERICOBJ
1933 if (!CORBA::is_nil(aHyp))
1938 QStringList tmpList;
1939 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1940 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1943 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1944 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1946 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1947 CORBA::String_var aName = aHypVar->GetName();
1948 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1950 anAlgoVar = aHypVar;
1956 return anAlgoVar._retn();
1959 //================================================================================
1961 * \brief Reads parameters of edited mesh and assigns them to the dialog
1963 * Reads parameters of edited mesh and assigns them to the dialog (called when
1964 * mesh is edited only)
1966 //================================================================================
1967 void SMESHGUI_MeshOp::readMesh()
1969 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1970 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1974 if (myIsOnGeometry) {
1975 // Get name of mesh if current object is sub-mesh
1976 SMESH::SMESH_subMesh_var aSubMeshVar =
1977 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1978 if ( !aSubMeshVar->_is_nil() )
1980 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1981 if ( !aMeshVar->_is_nil() )
1983 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1984 QString aMeshName = name( aMeshSO );
1985 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1989 // Get name of geometry object
1990 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1991 if ( !aGeomVar->_is_nil() )
1993 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1994 QString aShapeName = name( aGeomSO );
1995 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1999 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2000 QStringList anExisting;
2001 const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2002 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2005 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2006 // find algo index among available ones
2008 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2010 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2011 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2012 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2013 // if ( aHypIndex < 0 && algoData ) {
2014 // // assigned algo is incompatible with other algorithms
2015 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2016 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2019 setCurrentHyp( dim, Algo, aHypIndex );
2020 // set existing and available hypothesis according to the selected algo
2021 onAlgoSelected( aHypIndex, dim );
2025 bool hypWithoutAlgo = false;
2026 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2028 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2031 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2032 // find index of requered hypothesis among existing ones for this dimension and type
2034 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2035 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2036 myExistingHyps[ dim ][ hypType ] );
2037 if ( aHypIndex < 0 ) {
2038 // assigned hypothesis is incompatible with the algorithm
2039 if ( currentHyp( dim, Algo ) < 0 )
2040 { // none algo selected; it is edition for sure, of submesh maybe
2041 hypWithoutAlgo = true;
2042 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2043 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2044 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2048 setCurrentHyp( dim, hypType, aHypIndex );
2051 // make available other hyps of same type as one without algo
2052 if ( hypWithoutAlgo )
2053 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2056 //================================================================================
2058 * \brief Gets name of object
2059 * \param theSO - SObject
2060 * \retval QString - name of object
2062 * Gets name of object
2064 //================================================================================
2065 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2070 _PTR(GenericAttribute) anAttr;
2071 _PTR(AttributeName) aNameAttr;
2072 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2075 aResName = aNameAttr->Value().c_str();
2081 //================================================================================
2083 * \brief Finds hypothesis in input list
2084 * \param theHyp - hypothesis to be found
2085 * \param theHypList - input list of hypotheses
2086 * \retval int - index of hypothesis or -1 if it is not found
2088 * Finds position of hypothesis in input list
2090 //================================================================================
2091 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2092 const THypList& theHypList ) const
2095 if ( !theHyp->_is_nil() )
2098 THypList::const_iterator anIter = theHypList.begin();
2099 for ( ; anIter != theHypList.end(); ++ anIter)
2101 if ( theHyp->_is_equivalent( (*anIter).first ) )
2112 //================================================================================
2114 * \brief Edits mesh or sub-mesh
2115 * \param theMess - Output parameter intended for returning error message
2116 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2118 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2120 //================================================================================
2121 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2125 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2126 if ( aSMESHGen->_is_nil() )
2129 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2130 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2134 SUIT_OverrideCursor aWaitCursor;
2137 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2138 SMESH::SetName( pObj, aName );
2139 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2141 // First, remove old algos in order to avoid messages on algorithm hiding
2142 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2144 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2146 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2147 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2148 if ( anAlgoVar->_is_nil() || // no new algo selected or
2149 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2151 // remove old algorithm
2152 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2153 myObjHyps[ dim ][ Algo ].clear();
2158 // Assign new algorithms and hypotheses
2159 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2161 if ( !isAccessibleDim( dim )) continue;
2163 // find or create algorithm
2164 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2166 // assign new algorithm
2167 if ( !anAlgoVar->_is_nil() && // some algo selected and
2168 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2170 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2171 CORBA::Object_var anObject = aSObject->GetObject();
2172 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2173 bool isMesh = !aMeshVar->_is_nil();
2175 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2177 SMESH::SMESH_subMesh_var aVar =
2178 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2179 if ( !aVar->_is_nil() )
2180 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2182 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2185 // assign hypotheses
2186 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2188 int aNewHypIndex = currentHyp( dim, hypType );
2189 int anOldHypIndex = -1;
2191 // remove old hypotheses
2192 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2194 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2195 myExistingHyps[ dim ][ hypType ] );
2196 if ( aNewHypIndex != anOldHypIndex || // different hyps
2197 anOldHypIndex == -1 ) // hyps of different algos
2199 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2200 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2201 myObjHyps[ dim ][ hypType ].clear();
2205 // assign new hypotheses
2206 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2208 SMESH::SMESH_Mesh_var aMeshVar =
2209 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2210 bool isMesh = !aMeshVar->_is_nil();
2213 SMESH::AddHypothesisOnMesh
2214 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2218 SMESH::SMESH_subMesh_var aVar =
2219 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2220 if ( !aVar->_is_nil() )
2221 SMESH::AddHypothesisOnSubMesh
2222 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2225 // reread all hypotheses of mesh if necessary
2226 QStringList anExisting;
2227 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2234 //================================================================================
2236 * \brief Verifies whether given operator is valid for this one
2237 * \param theOtherOp - other operation
2238 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2240 * method redefined from base class verifies whether given operator is valid for
2241 * this one (i.e. can be started "above" this operator). In current implementation method
2242 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2245 //================================================================================
2246 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2248 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2251 //================================================================================
2253 * \brief SLOT. Is called when the user selects a way of geometry selection
2254 * \param theByMesh - true if the user wants to find geometry by mesh element
2256 //================================================================================
2257 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2260 if ( !myShapeByMeshOp ) {
2261 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2262 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2263 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2264 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2265 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2267 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2268 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2269 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2270 SMESH::SMESH_Mesh_var aMeshVar =
2271 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2272 if ( !aMeshVar->_is_nil() ) {
2273 myDlg->hide(); // stop processing selection
2274 myShapeByMeshOp->setModule( getSMESHGUI() );
2275 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2276 myShapeByMeshOp->SetMesh( aMeshVar );
2277 myShapeByMeshOp->start();
2283 //================================================================================
2285 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2287 //================================================================================
2288 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2290 if ( myShapeByMeshOp == op ) {
2291 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2293 // Select a found geometry object
2294 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2295 if ( !aGeomVar->_is_nil() )
2297 QString ID = aGeomVar->GetStudyEntry();
2298 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2299 selectObject( aGeomSO );
2306 //================================================================================
2308 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2310 //================================================================================
2311 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2313 if ( myShapeByMeshOp == op && myDlg ) {
2318 //================================================================================
2320 * \brief Selects a SObject
2321 * \param theSObj - the SObject to select
2323 //================================================================================
2324 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2326 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2327 SALOME_ListIO anIOList;
2329 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2330 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2331 anIOList.Append( anIO );
2333 sm->setSelectedObjects( anIOList, false );