1 // Copyright (C) 2007-2012 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_GenericObjPtr.h>
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 //To disable automatic genericobj management, the following line should be commented.
79 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
80 #define WITHGENERICOBJ
82 //================================================================================
85 * \param theToCreate - if this parameter is true then operation is used for creation,
86 * for editing otherwise
88 * Initialize operation
90 //================================================================================
91 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
92 : SMESHGUI_SelectionOp(),
93 myToCreate( theToCreate ),
94 myIsMesh( theIsMesh ),
99 if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
100 GeometryGUI::InitGeomGen();
101 myIsOnGeometry = true;
104 //================================================================================
108 //================================================================================
109 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
115 //================================================================================
117 * \brief Gets dialog of this operation
118 * \retval LightApp_Dialog* - pointer to dialog of this operation
120 //================================================================================
121 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
126 //================================================================================
128 * \brief Creates or edits mesh
129 * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
131 * Virtual slot redefined from the base class called when "Apply" button is clicked
132 * creates or edits mesh
134 //================================================================================
135 bool SMESHGUI_MeshOp::onApply()
141 if ( !isValid( aMess ) )
145 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
149 bool aResult = false;
153 QStringList anEntryList;
154 if ( myToCreate && myIsMesh )
155 aResult = createMesh( aMess, anEntryList );
156 if ( myToCreate && !myIsMesh )
157 aResult = createSubMesh( aMess, anEntryList );
158 else if ( !myToCreate )
159 aResult = editMeshOrSubMesh( aMess );
162 SMESHGUI::Modified();
163 update( UF_ObjBrowser | UF_Model );
164 if( LightApp_Application* anApp =
165 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
166 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
169 catch ( const SALOME::SALOME_Exception& S_ex )
171 SalomeApp_Tools::QtCatchCorbaException( S_ex );
187 aMess = tr( "SMESH_OPERATION_FAILED" );
188 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
194 //================================================================================
196 * \brief Creates dialog if necessary and shows it
198 * Virtual method redefined from base class called when operation is started creates
199 * dialog if necessary and shows it, activates selection
201 //================================================================================
202 void SMESHGUI_MeshOp::startOperation()
206 myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
207 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
209 connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
210 this, SLOT( onCreateHyp( const int, const int ) ) );
211 connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
212 this, SLOT( onEditHyp( const int, const int ) ) );
213 connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
214 this, SLOT( onAlgoSelected( const int ) ) );
216 connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
217 connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
220 if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
221 else myHelpFileName = "constructing_submeshes_page.html";
222 else myHelpFileName = "editing_meshes_page.html";
224 SMESHGUI_SelectionOp::startOperation();
226 // iterate through dimensions and get available algoritms, set them to the dialog
227 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
228 for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
230 SMESHGUI_MeshTab* aTab = myDlg->tab( i );
232 // clear available hypotheses
233 aTab->setAvailableHyps( MainHyp, hypList );
234 aTab->setAvailableHyps( AddHyp, hypList );
235 aTab->setExistingHyps( MainHyp, hypList );
236 aTab->setExistingHyps( AddHyp, hypList );
237 myExistingHyps[ i ][ MainHyp ].clear();
238 myExistingHyps[ i ][ AddHyp ].clear();
240 availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
241 aTab->setAvailableHyps( Algo, hypList );
246 myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
249 myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
251 myDlg->setCurrentTab( SMESH::DIM_3D );
253 myDlg->setGeomPopupEnabled(false);
256 myIgnoreAlgoSelection = false;
258 myObjectToSelect.clear();
261 //=================================================================================
263 * \brief Selects a recently created mesh or sub-mesh if necessary
265 * Virtual method redefined from base class called when operation is commited
266 * selects a recently created mesh or sub-mesh if necessary. Allows to perform
267 * selection when the custom selection filters are removed.
269 //=================================================================================
270 void SMESHGUI_MeshOp::commitOperation()
272 SMESHGUI_SelectionOp::commitOperation();
274 if ( !myObjectToSelect.isEmpty() ) {
275 if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
276 SUIT_DataOwnerPtrList aList;
277 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
278 aSelectionMgr->setSelected( aList );
283 //================================================================================
285 * \brief Creates selection filter
286 * \param theId - identifier of current selection widget
287 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
289 * Creates selection filter in accordance with identifier of current selection widget
291 //================================================================================
292 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
294 if ( theId == SMESHGUI_MeshDlg::Geom )
296 // TColStd_MapOfInteger allTypesMap;
297 // for ( int i = 0; i < 10; i++ )
298 // allTypesMap.Add( i );
299 // return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
300 return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
302 else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
303 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
304 else if ( theId == SMESHGUI_MeshDlg::Mesh )
305 return new SMESH_TypeFilter( SMESH::MESH );
310 //================================================================================
312 * \brief check if selected shape is a sub-shape of the shape to mesh
313 * \retval bool - check result
315 //================================================================================
316 bool SMESHGUI_MeshOp::isSubshapeOk() const
318 if ( !myToCreate || myIsMesh ) // not submesh creation
322 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
323 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
324 if (!pMesh) return false;
326 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
327 if (mesh->_is_nil()) return false;
329 // main shape of the mesh
330 GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
331 if (mainGeom->_is_nil()) return false;
335 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
337 if (aGEOMs.count() > 0) {
338 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
339 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
340 if (geomGen->_is_nil() || !aStudy) return false;
342 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
343 if (op->_is_nil()) return false;
345 // check all selected shapes
346 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
347 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
348 QString aSubGeomEntry = (*aSubShapesIter);
349 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
350 if (!pSubGeom) return false;
352 GEOM::GEOM_Object_var aSubGeomVar =
353 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
354 if (aSubGeomVar->_is_nil()) return false;
356 // skl for NPAL14695 - implementation of searching of mainObj
357 GEOM::GEOM_Object_wrap mainObj = op->GetMainShape(aSubGeomVar);
359 if (mainObj->_is_nil())
361 CORBA::String_var entry1 = mainObj->GetEntry();
362 CORBA::String_var entry2 = mainGeom->GetEntry();
363 if (std::string( entry1.in() ) == entry2.in() )
365 mainObj = op->GetMainShape(mainObj);
373 //================================================================================
375 * \brief Return name of the algorithm that does not support submeshes and makes
376 * submesh creation useless
377 * \retval char* - string is to be deleted!!!
379 //================================================================================
380 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
382 if ( myToCreate && !myIsMesh ) {
384 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
385 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
386 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
389 QStringList algoNames;
391 existingHyps(3, Algo, pMesh, algoNames, algoList);
392 if (!algoList.empty()) {
393 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
395 algo->InputTypes.empty() && // builds all dimensions it-self
396 !algo->IsSupportSubmeshes )
397 return CORBA::string_dup( algoNames[0].toLatin1().data() );
400 // GEOM::GEOM_Object_var geom;
401 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
402 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
404 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
405 existingHyps(2, Algo, pMesh, algoNames, algoList);
406 if (!algoList.empty()) {
407 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
409 algo->InputTypes.empty() && // builds all dimensions it-self
410 !algo->IsSupportSubmeshes )
411 return CORBA::string_dup( algoNames[0].toLatin1().data() );
419 //================================================================================
421 * \brief find an existing submesh by the selected shape
422 * \retval _PTR(SObject) - the found submesh SObject
424 //================================================================================
425 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
427 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
428 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
429 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
430 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
431 if ( pMesh && pGeom ) {
432 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
433 if ( !geom->_is_nil() ) {
435 switch ( geom->GetShapeType() ) {
436 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
437 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
438 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
439 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
440 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
441 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
442 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
445 _PTR(GenericAttribute) anAttr;
446 _PTR(SObject) aSubmeshRoot;
447 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
448 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
450 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
451 for ( ; smIter->More(); smIter->Next() )
453 _PTR(SObject) aSmObj = smIter->Value();
454 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
456 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
457 for ( ; anIter1->More(); anIter1->Next()) {
458 _PTR(SObject) pGeom2 = anIter1->Value();
459 if ( pGeom2->ReferencedObject( pGeom2 ) &&
460 pGeom2->GetID() == pGeom->GetID() )
467 return _PTR(SObject)();
470 //================================================================================
472 * \brief Updates dialog's look and feel
474 * Virtual method redefined from the base class updates dialog's look and feel
476 //================================================================================
477 void SMESHGUI_MeshOp::selectionDone()
479 if (!dlg()->isVisible() || !myDlg->isEnabled())
482 SMESHGUI_SelectionOp::selectionDone();
486 myIsOnGeometry = true;
488 //Check geometry for mesh
489 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
490 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
493 SMESH::SMESH_Mesh_var aMeshVar =
494 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
495 if (!aMeshVar->_is_nil()) {
496 if (!myToCreate && !aMeshVar->HasShapeToMesh())
497 myIsOnGeometry = false;
503 // Enable tabs according to shape dimension
508 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
509 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
511 if (aGEOMs.count() > 0) {
512 // one or more GEOM shape selected
513 aSeq->length(aGEOMs.count());
514 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
516 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
517 QString aSubGeomEntry = (*aSubShapesIter);
518 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
519 GEOM::GEOM_Object_var aSubGeomVar =
520 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
521 aSeq[iSubSh] = aSubGeomVar;
524 // get geometry by selected sub-mesh
525 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
526 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
527 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
528 if (!aGeomVar->_is_nil()) {
534 if (aSeq->length() > 0) {
536 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
537 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
538 switch ( aGeomVar->GetShapeType() ) {
539 case GEOM::SOLID: shapeDim = 3; break;
541 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
543 // TopoDS_Shape aShape;
544 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
545 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
548 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
550 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
551 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
555 if (GEOMBase::GetShape(aGeomVar, aShape))
557 TopExp_Explorer exp (aShape, TopAbs_SOLID);
561 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
562 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
565 // for (; exp.More() && shapeDim == 2; exp.Next()) {
566 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
570 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
571 shapeDim = qMax(2, shapeDim);
572 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
573 shapeDim = qMax(1, shapeDim);
574 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
575 shapeDim = qMax(0, shapeDim);
583 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
584 // reset algos before disabling tabs (0020138)
585 onAlgoSelected(-1, i);
587 myDlg->setMaxHypoDim( shapeDim );
588 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
590 if (!myToCreate) // edition: read hypotheses
594 SMESH::SMESH_subMesh_var aVar =
595 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
596 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
597 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
598 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
599 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
600 myDlg->updateGeometry();
607 else if ( !myIsMesh ) // submesh creation
609 // if a submesh on the selected shape already exist, pass to submesh edition mode
610 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
611 SMESH::SMESH_subMesh_var sm =
612 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
613 bool editSubmesh = ( !sm->_is_nil() &&
614 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
615 tr( "EDIT_SUBMESH_QUESTION"),
616 SUIT_MessageBox::Yes |
618 SUIT_MessageBox::No )
619 == SUIT_MessageBox::Yes );
622 selectionMgr()->clearFilters();
623 selectObject( pSubmesh );
624 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
629 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
630 selectObject( _PTR(SObject)() );
635 // discard selected mesh if submesh creation not allowed because of
636 // a global algorithm that does not support submeshes
637 if ( char* algoName = isSubmeshIgnored() ) {
638 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
639 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
640 CORBA::string_free( algoName );
641 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
642 selectObject( _PTR(SObject)() );
647 // enable/disable popup for choice of geom selection way
649 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
650 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
651 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
652 if ( !mesh->_is_nil() ) {
653 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
654 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
655 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
656 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
657 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
658 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
661 myDlg->setGeomPopupEnabled( enable );
664 else { // no geometry defined
665 myDlg->enableTab( SMESH::DIM_3D );
667 availableHyps( SMESH::DIM_3D, Algo, hypList,
668 myAvailableHypData[SMESH::DIM_3D][Algo]);
670 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
671 aTab->setAvailableHyps( Algo, hypList );
672 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
673 myDlg->disableTab(i);
675 //Hide labels and fields (Mesh ang Geometry)
676 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
677 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
682 catch ( const SALOME::SALOME_Exception& S_ex )
684 SalomeApp_Tools::QtCatchCorbaException( S_ex );
691 //================================================================================
693 * \brief Verifies validity of input data
694 * \param theMess - Output parameter intended for returning error message
695 * \retval bool - TRUE if input data is valid, false otherwise
697 * Verifies validity of input data. This method is called when "Apply" or "OK" button
698 * is pressed before mesh creation or editing.
700 //================================================================================
701 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
703 // Selected object to be edited
704 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
706 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
711 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
712 if ( aMeshName.isEmpty() )
714 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
718 /* // Imported mesh, if create sub-mesh or edit mesh
719 if ( !myToCreate || ( myToCreate && !myIsMesh ))
721 QString aMeshEntry = myDlg->selectedObject
722 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
723 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
724 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
725 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
726 theMess = tr( "IMPORTED_MESH" );
735 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
736 if ( aGeomEntry == "" )
738 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
741 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
742 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
744 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
749 if ( !myIsMesh ) // i.e sub-mesh creation,
751 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
752 if ( aMeshEntry == "" )
754 theMess = tr( "MESH_IS_NOT_DEFINED" );
757 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
758 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
760 theMess = tr( "MESH_IS_NULL" );
763 if ( !isSubshapeOk() )
765 theMess = tr( "INVALID_SUBSHAPE" );
774 //================================================================================
776 * \brief check compatibility of the algorithm and another algorithm or hypothesis
777 * \param theAlgoData - algorithm data
778 * \param theHypData - hypothesis data
779 * \param theHypType - hypothesis type
780 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
781 * \retval bool - check result
783 //================================================================================
784 static bool isCompatible(const HypothesisData* theAlgoData,
785 const HypothesisData* theHypData,
786 const int theHypType)
791 if ( theHypType == SMESHGUI_MeshOp::Algo )
792 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
795 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
798 //================================================================================
800 * \brief Gets available hypotheses or algorithms
801 * \param theDim - specifies dimension of returned hypotheses/algorifms
802 * \param theHypType - specifies whether algorims or hypotheses or additional ones
803 * are retrieved (possible values are in HypType enumeration)
804 * \param theHyps - Output list of hypotheses' names
805 * \param theAlgoData - to select hypos able to be used by this algo (optional)
807 * Gets available hypotheses or algorithm in accordance with input parameters
809 //================================================================================
810 void SMESHGUI_MeshOp::availableHyps( const int theDim,
811 const int theHypType,
812 QStringList& theHyps,
813 THypDataList& theDataList,
814 HypothesisData* theAlgoData ) const
818 bool isAlgo = ( theHypType == Algo );
819 bool isAux = ( theHypType == AddHyp );
820 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
822 QStringList::const_iterator anIter;
823 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
825 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
826 if ( isCompatible ( theAlgoData, aData, theHypType )) {
827 theDataList.append( aData );
828 theHyps.append( aData->Label );
833 //================================================================================
835 * \brief Gets existing hypotheses or algorithms
836 * \param theDim - specifies dimension of returned hypotheses/algorifms
837 * \param theHypType - specifies whether algorims or hypotheses or additional ones
838 * are retrieved (possible values are in HypType enumeration)
839 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
840 * \param theHyps - output list of names.
841 * \param theHypVars - output list of variables.
842 * \param theAlgoData - to select hypos able to be used by this algo (optional)
844 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
847 //================================================================================
848 void SMESHGUI_MeshOp::existingHyps( const int theDim,
849 const int theHypType,
850 _PTR(SObject) theFather,
851 QStringList& theHyps,
852 THypList& theHypList,
853 HypothesisData* theAlgoData)
855 // Clear hypoheses list
862 const bool isAux = ( theHypType == AddHyp );
864 _PTR(SObject) aHypRoot;
865 _PTR(GenericAttribute) anAttr;
866 _PTR(AttributeName) aName;
867 _PTR(AttributeIOR) anIOR;
869 bool isMesh = !_CAST( SComponent, theFather );
872 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
874 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
876 if ( theFather->FindSubObject( aPart, aHypRoot ) )
878 _PTR(ChildIterator) anIter =
879 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
880 for ( ; anIter->More(); anIter->Next() )
882 _PTR(SObject) anObj = anIter->Value();
883 if ( isMesh ) // i.e. mesh or submesh
885 _PTR(SObject) aRefObj;
886 if ( anObj->ReferencedObject( aRefObj ) )
891 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
894 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
895 if ( !CORBA::is_nil( aVar ) )
897 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
898 if ( !aHypVar->_is_nil() )
900 CORBA::String_var hypType = aHypVar->GetName();
901 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
902 if ( !aData) continue;
903 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
904 ( isCompatible ( theAlgoData, aData, theHypType )) &&
905 ( isAux == aData->IsAux ))
907 std::string aHypName = aName->Value();
908 theHyps.append( aHypName.c_str() );
909 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
918 //================================================================================
920 * \brief If create or edit a submesh, return a hypothesis holding parameters used
921 * to mesh a sub-shape
922 * \param aHypType - The hypothesis type name
923 * \param aServerLib - Server library name
924 * \param hypData - The structure holding the hypothesis type etc.
925 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
927 //================================================================================
928 SMESH::SMESH_Hypothesis_var
929 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
930 const QString& aServerLib ) const
932 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
933 return SMESH::SMESH_Hypothesis::_nil();
935 const int nbColonsInMeshEntry = 3;
936 bool isSubMesh = myToCreate ?
938 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
940 // get mesh and geom object
941 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
942 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
947 anEntry = myDlg->selectedObject
948 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
949 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
951 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
952 if ( myToCreate ) // mesh and geom may be selected
954 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
955 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
956 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
957 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
959 else // edition: sub-mesh may be selected
961 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
962 if ( !sm->_is_nil() ) {
963 aMeshVar = sm->GetFather();
964 aGeomVar = sm->GetSubShape();
971 if ( !myToCreate ) // mesh to edit can be selected
973 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
974 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
976 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
977 if ( !aMeshVar->_is_nil() )
978 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
981 if ( aGeomVar->_is_nil() ) {
982 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
983 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
985 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
990 SMESH::SMESH_Hypothesis_var hyp =
991 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
992 aServerLib.toLatin1().data(),
995 /*byMesh = */isSubMesh);
996 if ( hyp->_is_nil() && isSubMesh )
997 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
998 aServerLib.toLatin1().data(),
1001 /*byMesh = */false);
1005 //================================================================================
1007 * \Brief Returns tab dimention
1008 * \param tab - the tab in the dlg
1009 * \param dlg - my dialogue
1010 * \retval int - dimention
1012 //================================================================================
1013 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1016 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1017 if (tab == dlg->tab(i))
1022 //================================================================================
1024 * \brief Create hypothesis
1025 * \param theHypType - hypothesis category (main or additional)
1026 * \param theIndex - index of type of hypothesis to be cerated
1028 * Specifies dimension of hypothesis to be created (using sender() method),
1029 * specifies its type and calls method for hypothesis creation
1031 //================================================================================
1032 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1034 // Specifies dimension of hypothesis to be created
1035 int aDim = getTabDim( sender(), myDlg );
1039 // Specifies type of hypothesis to be created
1040 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1041 if (theIndex < 0 || theIndex >= dataList.count())
1043 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1045 // Create hypothesis
1046 createHypothesis(aDim, theHypType, aHypTypeName);
1051 QString GetUniqueName (const QStringList& theHypNames,
1052 const QString& theName,
1053 size_t theIteration = 1)
1055 QString aName = theName + "_" + QString::number( theIteration );
1056 if ( theHypNames.contains( aName ) )
1057 return GetUniqueName( theHypNames, theName, ++theIteration );
1062 //================================================================================
1064 * Create hypothesis and update dialog.
1065 * \param theDim - dimension of hypothesis to be created
1066 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1067 * \param theTypeName - specifies hypothesis to be created
1069 //================================================================================
1070 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1072 const QString& theTypeName)
1074 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1080 QStringList aHypNames;
1081 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1082 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1083 const TType2HypList& aType2HypList = aDimIter.value();
1084 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1085 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1086 const THypList& aHypList = aTypeIter.value();
1087 THypList::const_iterator anIter = aHypList.begin();
1088 for ( ; anIter != aHypList.end(); anIter++) {
1089 const THypItem& aHypItem = *anIter;
1090 const QString& aHypName = aHypItem.second;
1091 aHypNames.append(aHypName);
1095 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1098 bool dialog = false;
1100 QString aClientLibName = aData->ClientLibName;
1101 if (aClientLibName == "") {
1102 // Call hypothesis creation server method (without GUI)
1103 SMESH::SMESH_Hypothesis_var aHyp =
1104 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1105 #ifdef WITHGENERICOBJ
1106 if (!CORBA::is_nil(aHyp))
1110 // Get hypotheses creator client (GUI)
1112 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
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);
1181 #ifdef WITHGENERICOBJ
1182 if (!CORBA::is_nil(aHyp))
1192 //================================================================================
1194 * Necessary steps after hypothesis creation
1195 * \param result - creation result:
1198 * 2 = additional value meaning that slot is called not from dialog box
1200 //================================================================================
1201 void SMESHGUI_MeshOp::onHypoCreated( int result )
1205 int obj = myDlg->getActiveObject();
1206 onActivateObject( obj ); // Issue 0020170. Restore filters
1207 myDlg->setEnabled( true );
1210 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1212 int nbHyp = myExistingHyps[myDim][myType].count();
1213 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1214 QStringList aNewHyps;
1215 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1216 if (aNewHyps.count() > nbHyp)
1218 for (int i = nbHyp; i < aNewHyps.count(); i++)
1219 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1222 if( result!=2 && myHypoSet )
1226 //================================================================================
1228 * \brief Calls plugin methods for hypothesis editing
1229 * \param theHypType - specifies whether main hypothesis or additional one
1231 * \param theIndex - index of existing hypothesis
1233 * Calls plugin methods for hypothesis editing
1235 //================================================================================
1236 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1238 // Speicfies dimension of hypothesis to be created
1239 int aDim = getTabDim( sender(), myDlg );
1243 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1244 if ( theIndex < 0 || theIndex >= aList.count() )
1246 const THypItem& aHypItem = aList[ theIndex ];
1247 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1248 if ( aHyp->_is_nil() )
1251 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1254 // Get initial parameters
1255 SMESH::SMESH_Hypothesis_var initParamHyp =
1256 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1257 aCreator->setInitParamsHypothesis( initParamHyp );
1259 // Get Entry of the Geom object
1260 QString aGeomEntry = "";
1261 QString aMeshEntry = "";
1262 QString anObjEntry = "";
1263 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1264 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1265 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1267 if ( myToCreate && myIsMesh )
1268 aMeshEntry = aGeomEntry;
1270 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1271 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1272 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1273 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1276 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1277 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1279 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1280 if ( !aGeomVar->_is_nil() )
1282 aGeomEntry = aGeomVar->GetStudyEntry();
1284 aMeshEntry = aGeomEntry;
1288 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1289 // take geometry from submesh being created
1290 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1292 // if current object is sub-mesh
1293 SMESH::SMESH_subMesh_var aSubMeshVar =
1294 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1295 if ( !aSubMeshVar->_is_nil() ) {
1296 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1297 if ( !aMeshVar->_is_nil() ) {
1298 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1299 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1300 if ( !aGeomVar->_is_nil() )
1301 aMeshEntry = aGeomVar->GetStudyEntry();
1307 aCreator->setShapeEntry( aGeomEntry );
1308 if ( aMeshEntry != "" )
1309 aCreator->setMainShapeEntry( aMeshEntry );
1310 removeCustomFilters(); // Issue 0020170
1311 myDlg->setEnabled( false );
1312 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1316 //================================================================================
1318 * Necessary steps after hypothesis edition
1319 * \param result - creation result:
1323 //================================================================================
1324 void SMESHGUI_MeshOp::onHypoEdited( int result )
1326 int obj = myDlg->getActiveObject();
1327 onActivateObject( obj ); // Issue 0020170. Restore filters
1328 myDlg->setEnabled( true );
1331 //================================================================================
1333 * \brief access to hypothesis data
1334 * \param theDim - hyp dimension
1335 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1336 * \param theIndex - index in the list
1337 * \retval HypothesisData* - result data, may be 0
1339 //================================================================================
1340 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1341 const int theHypType,
1344 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1345 theHypType > -1 && theHypType < NbHypTypes &&
1346 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1347 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1351 //================================================================================
1353 * \brief Set available algos and hypos according to the selected algorithm
1354 * \param theIndex - algorithm index
1356 //================================================================================
1357 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1360 if ( myIgnoreAlgoSelection )
1363 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1367 // find highest available dimension, all algos of this dimension are available for choice
1369 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1370 if (isAccessibleDim( i ))
1375 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1377 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1378 HypothesisData* algoByDim[4];
1379 algoByDim[ aDim ] = algoData;
1381 QStringList anAvailable;
1382 if ( !algoData ) { // all algos becomes available
1383 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1384 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1387 // check that algorithms of other dimentions are compatible with
1390 // 2 loops: backward and forward from algo dimension
1391 for ( int forward = false; forward <= true; ++forward )
1393 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1395 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1397 HypothesisData* prevAlgo = algoData;
1398 bool noCompatible = false;
1399 for ( ; dim * dir <= lastDim * dir; dim += dir)
1401 if ( !isAccessibleDim( dim ))
1403 if ( noCompatible ) { // the selected algo has no compatible ones
1404 anAvailable.clear();
1405 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1406 myAvailableHypData[dim][Algo].clear();
1407 algoByDim[ dim ] = 0;
1410 // get currently selected algo
1411 int algoIndex = currentHyp( dim, Algo );
1412 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1413 if ( curAlgo ) { // some algo selected
1414 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1417 // set new available algoritms
1418 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1419 HypothesisData* soleCompatible = 0;
1420 if ( anAvailable.count() == 1 )
1421 soleCompatible = myAvailableHypData[dim][Algo][0];
1422 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1423 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1424 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1425 noCompatible = anAvailable.isEmpty();
1427 // restore previously selected algo
1428 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1429 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1430 // select the sole compatible algo
1431 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1432 setCurrentHyp( dim, Algo, algoIndex );
1434 // remember current algo
1435 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1439 // set hypotheses corresponding to the found algoritms
1441 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1443 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1445 if ( !isAccessibleDim( dim ))
1447 for ( int type = MainHyp; type < NbHypTypes; type++ )
1449 myAvailableHypData[ dim ][ type ].clear();
1450 QStringList anAvailable, anExisting;
1452 HypothesisData* curAlgo = algoByDim[ dim ];
1453 int hypIndex = currentHyp( dim, type );
1455 SMESH::SMESH_Hypothesis_var curHyp;
1456 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1457 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1459 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1460 // try to find algo by selected hypothesis in order to keep it selected
1461 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1462 CORBA::String_var curHypType = curHyp->GetName();
1463 if ( !algoDeselectedByUser &&
1464 myObjHyps[ dim ][ type ].count() > 0 &&
1465 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1467 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1468 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1469 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1470 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1477 // get hyps compatible with curAlgo
1480 // check if a selected hyp is compatible with the curAlgo
1481 if ( !curHyp->_is_nil() ) {
1482 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1483 if ( !isCompatible( curAlgo, hypData, type ))
1484 curHyp = SMESH::SMESH_Hypothesis::_nil();
1486 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1487 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1489 // set list of hypotheses
1490 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1491 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1493 // set current existing hypothesis
1494 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1495 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1498 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1499 // none is yet selected => select the sole existing if it is not optional
1500 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1501 bool isOptional = true;
1502 if ( algoByDim[ dim ] &&
1503 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1507 setCurrentHyp( dim, type, hypIndex );
1512 //================================================================================
1514 * \brief Creates and selects hypothesis of hypotheses set
1515 * \param theSetName - The name of hypotheses set
1517 //================================================================================
1518 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1520 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1525 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1526 setCurrentHyp(dim, Algo, -1);
1527 setCurrentHyp(dim, AddHyp, -1);
1528 setCurrentHyp(dim, MainHyp, -1);
1531 myHypoSet->init(true); //algorithms
1533 myHypoSet->init(false); //hypotheses
1538 //================================================================================
1540 * \brief One step of hypothesis/algorithm list creation
1542 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1544 //================================================================================
1545 void SMESHGUI_MeshOp::processSet()
1548 if( !myHypoSet->more() )
1551 bool isAlgo = myHypoSet->isAlgo();
1552 QString aHypoTypeName = myHypoSet->current();
1553 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1560 int aDim = aHypData->Dim[0];
1561 // create or/and set
1564 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1567 QStringList anAvailable;
1568 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1569 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1570 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1572 setCurrentHyp( aDim, Algo, index );
1573 onAlgoSelected( index, aDim );
1578 bool mainHyp = true;
1579 QStringList anAvailable;
1580 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1581 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1582 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1586 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1589 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1595 //================================================================================
1597 * \brief Creates mesh
1598 * \param theMess - Output parameter intended for returning error message
1599 * \param theEntryList - List of entries of published objects
1600 * \retval bool - TRUE if mesh is created, FALSE otherwise
1604 //================================================================================
1605 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1609 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1610 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1613 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1614 QStringList::Iterator it = aList.begin();
1615 for ( ; it!=aList.end(); it++)
1617 QString aGeomEntry = *it;
1618 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1619 GEOM::GEOM_Object_var aGeomVar =
1620 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1622 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1623 if ( aSMESHGen->_is_nil() )
1626 SUIT_OverrideCursor aWaitCursor;
1629 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1630 if ( aMeshVar->_is_nil() )
1632 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1634 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1635 theEntryList.append( aMeshSO->GetID().c_str() );
1638 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1639 if ( !isAccessibleDim( aDim )) continue;
1641 // assign hypotheses
1642 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1643 int aHypIndex = currentHyp( aDim, aHypType );
1644 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1645 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1646 if ( !aHypVar->_is_nil() )
1647 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1650 // find or create algorithm
1651 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1652 if ( !anAlgoVar->_is_nil() )
1653 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1655 #ifdef WITHGENERICOBJ
1656 // obj has been published in study. Its refcount has been incremented.
1657 // It is safe to decrement its refcount
1658 // so that it will be destroyed when the entry in study will be removed
1660 aMeshVar->UnRegister();
1666 //================================================================================
1668 * \brief Creates sub-mesh
1669 * \param theMess - Output parameter intended for returning error message
1670 * \param theEntryList - List of entries of published objects
1671 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1675 //================================================================================
1676 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1680 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1681 if ( aSMESHGen->_is_nil() )
1685 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1686 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1687 SMESH::SMESH_Mesh_var aMeshVar =
1688 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1689 if (aMeshVar->_is_nil())
1692 // GEOM shape of the main mesh
1693 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1695 // Name for the new sub-mesh
1696 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1699 GEOM::GEOM_Object_var aGeomVar;
1701 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1702 if (aGEOMs.count() == 1)
1704 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1705 QString aGeomEntry = aGEOMs.first();
1706 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1707 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1709 else if (aGEOMs.count() > 1)
1711 // create a GEOM group
1712 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1713 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1714 if (!geomGen->_is_nil() && aStudy) {
1715 GEOM::GEOM_IGroupOperations_wrap op =
1716 geomGen->GetIGroupOperations(aStudy->StudyId());
1717 if (!op->_is_nil()) {
1718 // check and add all selected GEOM objects: they must be
1719 // a sub-shapes of the main GEOM and must be of one type
1721 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1722 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1723 aSeq->length(aGEOMs.count());
1724 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1725 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1726 QString aSubGeomEntry = (*aSubShapesIter);
1727 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1728 GEOM::GEOM_Object_var aSubGeomVar =
1729 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1730 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1732 aGroupType = aSubShapeType;
1734 if (aSubShapeType != aGroupType)
1735 aGroupType = TopAbs_SHAPE;
1737 aSeq[iSubSh] = aSubGeomVar;
1740 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1741 op->UnionList(aGroupVar, aSeq);
1744 aGeomVar = aGroupVar.in();
1746 // publish the GEOM group in study
1747 QString aNewGeomGroupName ("Auto_group_for_");
1748 aNewGeomGroupName += aName;
1749 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1750 SALOMEDS::SObject_wrap aNewGroupSO =
1751 geomGen->AddInStudy( aStudyVar, aGeomVar,
1752 aNewGeomGroupName.toLatin1().data(), mainGeom);
1759 if (aGeomVar->_is_nil())
1762 SUIT_OverrideCursor aWaitCursor;
1765 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1766 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1768 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1769 theEntryList.append( aSubMeshSO->GetID().c_str() );
1772 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1774 if ( !isAccessibleDim( aDim )) continue;
1776 // find or create algorithm
1777 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1778 if ( !anAlgoVar->_is_nil() )
1779 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1780 // assign hypotheses
1781 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1783 int aHypIndex = currentHyp( aDim, aHypType );
1784 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1786 SMESH::SMESH_Hypothesis_var aHypVar =
1787 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1788 if ( !aHypVar->_is_nil() )
1789 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1794 // deselect geometry: next submesh should be created on other sub-shape
1795 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1796 selectObject( _PTR(SObject)() );
1802 //================================================================================
1804 * \brief Gets current hypothesis or algorithms
1805 * \param theDim - dimension of hypothesis or algorithm
1806 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1807 * \retval int - current hypothesis or algorithms
1809 * Gets current hypothesis or algorithms
1811 //================================================================================
1812 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1814 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1817 //================================================================================
1819 * \brief Returns true if hypotheses of given dim can be assigned
1820 * \param theDim - hypotheses dimension
1821 * \retval bool - result
1823 //================================================================================
1824 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1826 return myDlg->isTabEnabled( theDim );
1829 //================================================================================
1831 * \brief Sets current hypothesis or algorithms
1832 * \param theDim - dimension of hypothesis or algorithm
1833 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1834 * \param theIndex - Index of hypothesis
1836 * Gets current hypothesis or algorithms
1838 //================================================================================
1839 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1840 const int theHypType,
1841 const int theIndex )
1843 myIgnoreAlgoSelection = true;
1844 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1845 myIgnoreAlgoSelection = false;
1848 //================================================================================
1850 * \brief Generates default and sets mesh/submesh name
1852 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1854 //================================================================================
1855 void SMESHGUI_MeshOp::setDefaultName() const
1859 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1861 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1862 _PTR(SObject) anObj;
1865 aResName = aPrefix + QString::number( i++ );
1866 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1870 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1871 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1872 aControl->setText( aResName );
1875 //================================================================================
1877 * \brief Gets algorithm or creates it if necessary
1878 * \param theDim - specifies dimension of returned hypotheses/algorifms
1879 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1881 * Gets algorithm or creates it if necessary
1883 //================================================================================
1884 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1886 SMESH::SMESH_Hypothesis_var anAlgoVar;
1888 // get type of the selected algo
1889 int aHypIndex = currentHyp( theDim, Algo );
1890 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1891 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1893 QString aHypName = dataList[ aHypIndex ]->TypeName;
1895 // get existing algoritms
1896 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1898 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1900 // look for an existing algo of such a type
1901 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1902 THypList::iterator anIter = aHypVarList.begin();
1903 for ( ; anIter != aHypVarList.end(); anIter++)
1905 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1906 CORBA::String_var aName = aHypVar->GetName();
1907 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1909 anAlgoVar = aHypVar;
1914 if (anAlgoVar->_is_nil())
1916 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1919 QString aClientLibName = aHypData->ClientLibName;
1920 if (aClientLibName == "")
1922 // Call hypothesis creation server method (without GUI)
1923 SMESH::SMESH_Hypothesis_var aHyp =
1924 SMESH::CreateHypothesis(aHypName, aHypName, true);
1925 #ifdef WITHGENERICOBJ
1926 if (!CORBA::is_nil(aHyp))
1932 // Get hypotheses creator client (GUI)
1934 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1938 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1940 SMESH::SMESH_Hypothesis_var aHyp =
1941 SMESH::CreateHypothesis(aHypName, aHypName, true);
1942 #ifdef WITHGENERICOBJ
1943 if (!CORBA::is_nil(aHyp))
1948 QStringList tmpList;
1949 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1950 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1953 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1954 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1956 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1957 CORBA::String_var aName = aHypVar->GetName();
1958 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1960 anAlgoVar = aHypVar;
1966 return anAlgoVar._retn();
1969 //================================================================================
1971 * \brief Reads parameters of an edited mesh and assigns them to the dialog
1973 * Called when mesh is edited only.
1975 //================================================================================
1976 void SMESHGUI_MeshOp::readMesh()
1978 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1979 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1983 if (myIsOnGeometry) {
1984 // Get name of mesh if current object is sub-mesh
1985 SMESH::SMESH_subMesh_var aSubMeshVar =
1986 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1987 if ( !aSubMeshVar->_is_nil() )
1989 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1990 if ( !aMeshVar->_is_nil() )
1992 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1993 QString aMeshName = name( aMeshSO );
1994 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1998 // Get name of geometry object
1999 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2000 if ( !aGeomVar->_is_nil() )
2002 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2003 QString aShapeName = name( aGeomSO );
2004 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2008 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2009 QStringList anExisting;
2010 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2011 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2014 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2015 // find algo index among available ones
2017 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2019 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2020 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2021 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2022 // if ( aHypIndex < 0 && algoData ) {
2023 // // assigned algo is incompatible with other algorithms
2024 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2025 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2028 setCurrentHyp( dim, Algo, aHypIndex );
2029 // set existing and available hypothesis according to the selected algo
2030 onAlgoSelected( aHypIndex, dim );
2034 bool hypWithoutAlgo = false;
2035 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2037 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2040 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2041 // find index of requered hypothesis among existing ones for this dimension and type
2043 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2044 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2045 myExistingHyps[ dim ][ hypType ] );
2046 if ( aHypIndex < 0 ) {
2047 // assigned hypothesis is incompatible with the algorithm
2048 if ( currentHyp( dim, Algo ) < 0 )
2049 { // none algo selected; it is edition for sure, of submesh maybe
2050 hypWithoutAlgo = true;
2051 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2052 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2053 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2057 setCurrentHyp( dim, hypType, aHypIndex );
2060 // make available other hyps of same type as one without algo
2061 if ( hypWithoutAlgo )
2062 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2065 //================================================================================
2067 * \brief Gets name of object
2068 * \param theSO - SObject
2069 * \retval QString - name of object
2071 * Gets name of object
2073 //================================================================================
2074 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2079 _PTR(GenericAttribute) anAttr;
2080 _PTR(AttributeName) aNameAttr;
2081 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2084 aResName = aNameAttr->Value().c_str();
2090 //================================================================================
2092 * \brief Finds hypothesis in input list
2093 * \param theHyp - hypothesis to be found
2094 * \param theHypList - input list of hypotheses
2095 * \retval int - index of hypothesis or -1 if it is not found
2097 * Finds position of hypothesis in input list
2099 //================================================================================
2100 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2101 const THypList& theHypList ) const
2104 if ( !theHyp->_is_nil() )
2107 THypList::const_iterator anIter = theHypList.begin();
2108 for ( ; anIter != theHypList.end(); ++ anIter)
2110 if ( theHyp->_is_equivalent( (*anIter).first ) )
2121 //================================================================================
2123 * \brief Edits mesh or sub-mesh
2124 * \param theMess - Output parameter intended for returning error message
2125 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2127 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2129 //================================================================================
2130 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2134 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2135 if ( aSMESHGen->_is_nil() )
2138 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2139 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2143 SUIT_OverrideCursor aWaitCursor;
2146 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2147 SMESH::SetName( pObj, aName );
2148 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2150 // First, remove old algos in order to avoid messages on algorithm hiding
2151 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2153 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2155 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2156 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2157 if ( anAlgoVar->_is_nil() || // no new algo selected or
2158 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2160 // remove old algorithm
2161 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2162 myObjHyps[ dim ][ Algo ].clear();
2167 // Assign new algorithms and hypotheses
2168 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2170 if ( !isAccessibleDim( dim )) continue;
2172 // find or create algorithm
2173 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2175 // assign new algorithm
2176 if ( !anAlgoVar->_is_nil() && // some algo selected and
2177 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2179 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2180 CORBA::Object_var anObject = aSObject->GetObject();
2181 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2182 bool isMesh = !aMeshVar->_is_nil();
2184 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2186 SMESH::SMESH_subMesh_var aVar =
2187 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2188 if ( !aVar->_is_nil() )
2189 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2191 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2194 // assign hypotheses
2195 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2197 int aNewHypIndex = currentHyp( dim, hypType );
2198 int anOldHypIndex = -1;
2200 // remove old hypotheses
2201 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2203 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2204 myExistingHyps[ dim ][ hypType ] );
2205 if ( aNewHypIndex != anOldHypIndex || // different hyps
2206 anOldHypIndex == -1 ) // hyps of different algos
2208 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2209 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2210 myObjHyps[ dim ][ hypType ].clear();
2214 // assign new hypotheses
2215 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2217 SMESH::SMESH_Mesh_var aMeshVar =
2218 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2219 bool isMesh = !aMeshVar->_is_nil();
2222 SMESH::AddHypothesisOnMesh
2223 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2227 SMESH::SMESH_subMesh_var aVar =
2228 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2229 if ( !aVar->_is_nil() )
2230 SMESH::AddHypothesisOnSubMesh
2231 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2234 // reread all hypotheses of mesh if necessary
2235 QStringList anExisting;
2236 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2243 //================================================================================
2245 * \brief Verifies whether given operator is valid for this one
2246 * \param theOtherOp - other operation
2247 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2249 * method redefined from base class verifies whether given operator is valid for
2250 * this one (i.e. can be started "above" this operator). In current implementation method
2251 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2254 //================================================================================
2255 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2257 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2260 //================================================================================
2262 * \brief SLOT. Is called when the user selects a way of geometry selection
2263 * \param theByMesh - true if the user wants to find geometry by mesh element
2265 //================================================================================
2266 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2269 if ( !myShapeByMeshOp ) {
2270 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2271 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2272 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2273 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2274 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2276 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2277 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2278 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2279 SMESH::SMESH_Mesh_var aMeshVar =
2280 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2281 if ( !aMeshVar->_is_nil() ) {
2282 myDlg->hide(); // stop processing selection
2283 myShapeByMeshOp->setModule( getSMESHGUI() );
2284 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2285 myShapeByMeshOp->SetMesh( aMeshVar );
2286 myShapeByMeshOp->start();
2292 //================================================================================
2294 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2296 //================================================================================
2297 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2299 if ( myShapeByMeshOp == op ) {
2300 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2302 // Select a found geometry object
2303 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2304 if ( !aGeomVar->_is_nil() )
2306 QString ID = aGeomVar->GetStudyEntry();
2307 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2308 selectObject( aGeomSO );
2315 //================================================================================
2317 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2319 //================================================================================
2320 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2322 if ( myShapeByMeshOp == op && myDlg ) {
2327 //================================================================================
2329 * \brief Selects a SObject
2330 * \param theSObj - the SObject to select
2332 //================================================================================
2333 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2335 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2336 SALOME_ListIO anIOList;
2338 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2339 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2340 anIOList.Append( anIO );
2342 sm->setSelectedObjects( anIOList, false );