1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MeshOp.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MeshOp.h"
29 #include "SMESHGUI_MeshDlg.h"
30 #include "SMESHGUI_ShapeByMeshDlg.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_NumberFilter.hxx>
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LightApp_UpdateFlags.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_Session.h>
54 #include <SALOME_InteractiveObject.hxx>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SComponent.hxx>
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDS_Study.hxx>
61 #include <SALOMEDS_wrap.hxx>
64 #include <QStringList>
69 #include <TopoDS_Shape.hxx>
70 #include <TopoDS_Shell.hxx>
71 #include <TopExp_Explorer.hxx>
72 #include <BRep_Tool.hxx>
75 #include <SALOMEconfig.h>
76 #include CORBA_CLIENT_HEADER(SMESH_Gen)
78 //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_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
358 mainObj already exists! */
360 if (mainObj->_is_nil())
362 CORBA::String_var entry1 = mainObj->GetEntry();
363 CORBA::String_var entry2 = mainGeom->GetEntry();
364 if (std::string( entry1.in() ) == entry2.in() )
366 mainObj = op->GetMainShape(mainObj);
374 //================================================================================
376 * \brief Return name of the algorithm that does not support submeshes and makes
377 * submesh creation useless
378 * \retval char* - string is to be deleted!!!
380 //================================================================================
381 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
383 if ( myToCreate && !myIsMesh ) {
385 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
386 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
387 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
390 QStringList algoNames;
392 existingHyps(3, Algo, pMesh, algoNames, algoList);
393 if (!algoList.empty()) {
394 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
396 algo->InputTypes.empty() && // builds all dimensions it-self
397 !algo->IsSupportSubmeshes )
398 return CORBA::string_dup( algoNames[0].toLatin1().data() );
401 // GEOM::GEOM_Object_var geom;
402 // if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
403 // geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
405 // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
406 existingHyps(2, Algo, pMesh, algoNames, algoList);
407 if (!algoList.empty()) {
408 HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
410 algo->InputTypes.empty() && // builds all dimensions it-self
411 !algo->IsSupportSubmeshes )
412 return CORBA::string_dup( algoNames[0].toLatin1().data() );
420 //================================================================================
422 * \brief find an existing submesh by the selected shape
423 * \retval _PTR(SObject) - the found submesh SObject
425 //================================================================================
426 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
428 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
429 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
430 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
431 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
432 if ( pMesh && pGeom ) {
433 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
434 if ( !geom->_is_nil() ) {
436 switch ( geom->GetShapeType() ) {
437 case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
438 case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
439 case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
440 case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
441 case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
442 case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
443 case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
446 _PTR(GenericAttribute) anAttr;
447 _PTR(SObject) aSubmeshRoot;
448 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
449 if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
451 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
452 for ( ; smIter->More(); smIter->Next() )
454 _PTR(SObject) aSmObj = smIter->Value();
455 if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
457 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
458 for ( ; anIter1->More(); anIter1->Next()) {
459 _PTR(SObject) pGeom2 = anIter1->Value();
460 if ( pGeom2->ReferencedObject( pGeom2 ) &&
461 pGeom2->GetID() == pGeom->GetID() )
468 return _PTR(SObject)();
471 //================================================================================
473 * \brief Updates dialog's look and feel
475 * Virtual method redefined from the base class updates dialog's look and feel
477 //================================================================================
478 void SMESHGUI_MeshOp::selectionDone()
480 if (!dlg()->isVisible() || !myDlg->isEnabled())
483 SMESHGUI_SelectionOp::selectionDone();
487 myIsOnGeometry = true;
489 //Check geometry for mesh
490 QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
491 _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
494 SMESH::SMESH_Mesh_var aMeshVar =
495 SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
496 if (!aMeshVar->_is_nil()) {
497 if (!myToCreate && !aMeshVar->HasShapeToMesh())
498 myIsOnGeometry = false;
504 // Enable tabs according to shape dimension
509 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
510 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
512 if (aGEOMs.count() > 0) {
513 // one or more GEOM shape selected
514 aSeq->length(aGEOMs.count());
515 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
517 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
518 QString aSubGeomEntry = (*aSubShapesIter);
519 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
520 GEOM::GEOM_Object_var aSubGeomVar =
521 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
522 aSeq[iSubSh] = aSubGeomVar;
525 // get geometry by selected sub-mesh
526 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
527 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
528 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
529 if (!aGeomVar->_is_nil()) {
535 if (aSeq->length() > 0) {
537 for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
538 GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
539 switch ( aGeomVar->GetShapeType() ) {
540 case GEOM::SOLID: shapeDim = 3; break;
542 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
544 // TopoDS_Shape aShape;
545 // bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
546 // shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
549 case GEOM::FACE: shapeDim = qMax(2, shapeDim); break;
551 case GEOM::EDGE: shapeDim = qMax(1, shapeDim); break;
552 case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
556 if (GEOMBase::GetShape(aGeomVar, aShape))
558 TopExp_Explorer exp (aShape, TopAbs_SOLID);
562 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
563 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
566 // for (; exp.More() && shapeDim == 2; exp.Next()) {
567 // if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
571 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
572 shapeDim = qMax(2, shapeDim);
573 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
574 shapeDim = qMax(1, shapeDim);
575 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
576 shapeDim = qMax(0, shapeDim);
584 for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
585 // reset algos before disabling tabs (0020138)
586 onAlgoSelected(-1, i);
588 myDlg->setMaxHypoDim( shapeDim );
589 myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
591 if (!myToCreate) // edition: read hypotheses
595 SMESH::SMESH_subMesh_var aVar =
596 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
597 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
598 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
599 myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
600 myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
601 myDlg->updateGeometry();
608 else if ( !myIsMesh ) // submesh creation
610 // if a submesh on the selected shape already exist, pass to submesh edition mode
611 if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
612 SMESH::SMESH_subMesh_var sm =
613 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
614 bool editSubmesh = ( !sm->_is_nil() &&
615 SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
616 tr( "EDIT_SUBMESH_QUESTION"),
617 SUIT_MessageBox::Yes |
619 SUIT_MessageBox::No )
620 == SUIT_MessageBox::Yes );
623 selectionMgr()->clearFilters();
624 selectObject( pSubmesh );
625 SMESHGUI::GetSMESHGUI()->switchToOperation(704);
630 myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
631 selectObject( _PTR(SObject)() );
636 // discard selected mesh if submesh creation not allowed because of
637 // a global algorithm that does not support submeshes
638 if ( char* algoName = isSubmeshIgnored() ) {
639 SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
640 tr("SUBMESH_NOT_ALLOWED").arg(algoName));
641 CORBA::string_free( algoName );
642 myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
643 selectObject( _PTR(SObject)() );
648 // enable/disable popup for choice of geom selection way
650 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
651 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
652 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
653 if ( !mesh->_is_nil() ) {
654 //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
655 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
656 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
657 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
658 myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
659 enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
662 myDlg->setGeomPopupEnabled( enable );
665 else { // no geometry defined
666 myDlg->enableTab( SMESH::DIM_3D );
668 availableHyps( SMESH::DIM_3D, Algo, hypList,
669 myAvailableHypData[SMESH::DIM_3D][Algo]);
671 SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
672 aTab->setAvailableHyps( Algo, hypList );
673 for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
674 myDlg->disableTab(i);
676 //Hide labels and fields (Mesh ang Geometry)
677 myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
678 myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
683 catch ( const SALOME::SALOME_Exception& S_ex )
685 SalomeApp_Tools::QtCatchCorbaException( S_ex );
692 //================================================================================
694 * \brief Verifies validity of input data
695 * \param theMess - Output parameter intended for returning error message
696 * \retval bool - TRUE if input data is valid, false otherwise
698 * Verifies validity of input data. This method is called when "Apply" or "OK" button
699 * is pressed before mesh creation or editing.
701 //================================================================================
702 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
704 // Selected object to be edited
705 if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
707 theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
712 QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
713 if ( aMeshName.isEmpty() )
715 theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
719 /* // Imported mesh, if create sub-mesh or edit mesh
720 if ( !myToCreate || ( myToCreate && !myIsMesh ))
722 QString aMeshEntry = myDlg->selectedObject
723 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
724 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
725 SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
726 if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
727 theMess = tr( "IMPORTED_MESH" );
736 QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
737 if ( aGeomEntry == "" )
739 theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
742 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
743 if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
745 theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
750 if ( !myIsMesh ) // i.e sub-mesh creation,
752 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
753 if ( aMeshEntry == "" )
755 theMess = tr( "MESH_IS_NOT_DEFINED" );
758 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
759 if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
761 theMess = tr( "MESH_IS_NULL" );
764 if ( !isSubshapeOk() )
766 theMess = tr( "INVALID_SUBSHAPE" );
775 //================================================================================
777 * \brief check compatibility of the algorithm and another algorithm or hypothesis
778 * \param theAlgoData - algorithm data
779 * \param theHypData - hypothesis data
780 * \param theHypType - hypothesis type
781 * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
782 * \retval bool - check result
784 //================================================================================
785 static bool isCompatible(const HypothesisData* theAlgoData,
786 const HypothesisData* theHypData,
787 const int theHypType)
792 if ( theHypType == SMESHGUI_MeshOp::Algo )
793 return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
796 return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
799 //================================================================================
801 * \brief Gets available hypotheses or algorithms
802 * \param theDim - specifies dimension of returned hypotheses/algorifms
803 * \param theHypType - specifies whether algorims or hypotheses or additional ones
804 * are retrieved (possible values are in HypType enumeration)
805 * \param theHyps - Output list of hypotheses' names
806 * \param theAlgoData - to select hypos able to be used by this algo (optional)
808 * Gets available hypotheses or algorithm in accordance with input parameters
810 //================================================================================
811 void SMESHGUI_MeshOp::availableHyps( const int theDim,
812 const int theHypType,
813 QStringList& theHyps,
814 THypDataList& theDataList,
815 HypothesisData* theAlgoData ) const
819 bool isAlgo = ( theHypType == Algo );
820 bool isAux = ( theHypType == AddHyp );
821 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry );
823 QStringList::const_iterator anIter;
824 for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
826 HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
827 if ( isCompatible ( theAlgoData, aData, theHypType )) {
828 theDataList.append( aData );
829 theHyps.append( aData->Label );
834 //================================================================================
836 * \brief Gets existing hypotheses or algorithms
837 * \param theDim - specifies dimension of returned hypotheses/algorifms
838 * \param theHypType - specifies whether algorims or hypotheses or additional ones
839 * are retrieved (possible values are in HypType enumeration)
840 * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
841 * \param theHyps - output list of names.
842 * \param theHypVars - output list of variables.
843 * \param theAlgoData - to select hypos able to be used by this algo (optional)
845 * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
848 //================================================================================
849 void SMESHGUI_MeshOp::existingHyps( const int theDim,
850 const int theHypType,
851 _PTR(SObject) theFather,
852 QStringList& theHyps,
853 THypList& theHypList,
854 HypothesisData* theAlgoData)
856 // Clear hypoheses list
863 const bool isAux = ( theHypType == AddHyp );
865 _PTR(SObject) aHypRoot;
866 _PTR(GenericAttribute) anAttr;
867 _PTR(AttributeName) aName;
868 _PTR(AttributeIOR) anIOR;
870 bool isMesh = !_CAST( SComponent, theFather );
873 aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
875 aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
877 if ( theFather->FindSubObject( aPart, aHypRoot ) )
879 _PTR(ChildIterator) anIter =
880 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
881 for ( ; anIter->More(); anIter->Next() )
883 _PTR(SObject) anObj = anIter->Value();
884 if ( isMesh ) // i.e. mesh or submesh
886 _PTR(SObject) aRefObj;
887 if ( anObj->ReferencedObject( aRefObj ) )
892 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
895 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
896 if ( !CORBA::is_nil( aVar ) )
898 SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
899 if ( !aHypVar->_is_nil() )
901 CORBA::String_var hypType = aHypVar->GetName();
902 HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
903 if ( !aData) continue;
904 if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
905 ( isCompatible ( theAlgoData, aData, theHypType )) &&
906 ( isAux == aData->IsAux ))
908 std::string aHypName = aName->Value();
909 theHyps.append( aHypName.c_str() );
910 theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
919 //================================================================================
921 * \brief If create or edit a submesh, return a hypothesis holding parameters used
922 * to mesh a sub-shape
923 * \param aHypType - The hypothesis type name
924 * \param aServerLib - Server library name
925 * \param hypData - The structure holding the hypothesis type etc.
926 * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
928 //================================================================================
929 SMESH::SMESH_Hypothesis_var
930 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
931 const QString& aServerLib ) const
933 if ( aHypType.isEmpty() || aServerLib.isEmpty() )
934 return SMESH::SMESH_Hypothesis::_nil();
936 const int nbColonsInMeshEntry = 3;
937 bool isSubMesh = myToCreate ?
939 myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
941 // get mesh and geom object
942 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
943 GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
948 anEntry = myDlg->selectedObject
949 ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
950 if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
952 CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
953 if ( myToCreate ) // mesh and geom may be selected
955 aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
956 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
957 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
958 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
960 else // edition: sub-mesh may be selected
962 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
963 if ( !sm->_is_nil() ) {
964 aMeshVar = sm->GetFather();
965 aGeomVar = sm->GetSubShape();
972 if ( !myToCreate ) // mesh to edit can be selected
974 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
975 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
977 aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
978 if ( !aMeshVar->_is_nil() )
979 aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
982 if ( aGeomVar->_is_nil() ) {
983 anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
984 if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
986 aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
991 SMESH::SMESH_Hypothesis_var hyp =
992 SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
993 aServerLib.toLatin1().data(),
996 /*byMesh = */isSubMesh);
997 if ( hyp->_is_nil() && isSubMesh )
998 hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
999 aServerLib.toLatin1().data(),
1002 /*byMesh = */false);
1006 //================================================================================
1008 * \Brief Returns tab dimention
1009 * \param tab - the tab in the dlg
1010 * \param dlg - my dialogue
1011 * \retval int - dimention
1013 //================================================================================
1014 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1017 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1018 if (tab == dlg->tab(i))
1023 //================================================================================
1025 * \brief Create hypothesis
1026 * \param theHypType - hypothesis category (main or additional)
1027 * \param theIndex - index of type of hypothesis to be cerated
1029 * Specifies dimension of hypothesis to be created (using sender() method),
1030 * specifies its type and calls method for hypothesis creation
1032 //================================================================================
1033 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1035 // Specifies dimension of hypothesis to be created
1036 int aDim = getTabDim( sender(), myDlg );
1040 // Specifies type of hypothesis to be created
1041 THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1042 if (theIndex < 0 || theIndex >= dataList.count())
1044 QString aHypTypeName = dataList[ theIndex ]->TypeName;
1046 // Create hypothesis
1047 createHypothesis(aDim, theHypType, aHypTypeName);
1052 QString GetUniqueName (const QStringList& theHypNames,
1053 const QString& theName,
1054 size_t theIteration = 1)
1056 QString aName = theName + "_" + QString::number( theIteration );
1057 if ( theHypNames.contains( aName ) )
1058 return GetUniqueName( theHypNames, theName, ++theIteration );
1063 //================================================================================
1065 * Create hypothesis and update dialog.
1066 * \param theDim - dimension of hypothesis to be created
1067 * \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1068 * \param theTypeName - specifies hypothesis to be created
1070 //================================================================================
1071 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1073 const QString& theTypeName)
1075 HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1081 QStringList aHypNames;
1082 TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1083 for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1084 const TType2HypList& aType2HypList = aDimIter.value();
1085 TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1086 for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1087 const THypList& aHypList = aTypeIter.value();
1088 THypList::const_iterator anIter = aHypList.begin();
1089 for ( ; anIter != aHypList.end(); anIter++) {
1090 const THypItem& aHypItem = *anIter;
1091 const QString& aHypName = aHypItem.second;
1092 aHypNames.append(aHypName);
1096 QString aHypName = GetUniqueName( aHypNames, aData->Label);
1099 bool dialog = false;
1101 QString aClientLibName = aData->ClientLibName;
1102 if (aClientLibName == "") {
1103 // Call hypothesis creation server method (without GUI)
1104 SMESH::SMESH_Hypothesis_var aHyp =
1105 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1106 #ifdef WITHGENERICOBJ
1107 if (!CORBA::is_nil(aHyp))
1111 // Get hypotheses creator client (GUI)
1113 //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1114 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1116 // Create hypothesis
1118 // Get parameters appropriate to initialize a new hypothesis
1119 SMESH::SMESH_Hypothesis_var initParamHyp =
1120 getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1122 removeCustomFilters(); // Issue 0020170
1124 // Get Entry of the Geom object
1125 QString aGeomEntry = "";
1126 QString aMeshEntry = "";
1127 QString anObjEntry = "";
1128 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1129 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1130 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1132 if ( myToCreate && myIsMesh )
1133 aMeshEntry = aGeomEntry;
1135 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1136 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1137 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1138 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1141 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1142 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1144 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1145 if ( !aGeomVar->_is_nil() )
1147 aGeomEntry = aGeomVar->GetStudyEntry();
1149 aMeshEntry = aGeomEntry;
1153 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1154 // take geometry from submesh being created
1155 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1157 // if current object is sub-mesh
1158 SMESH::SMESH_subMesh_var aSubMeshVar =
1159 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1160 if ( !aSubMeshVar->_is_nil() ) {
1161 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1162 if ( !aMeshVar->_is_nil() ) {
1163 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1164 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1165 if ( !aGeomVar->_is_nil() )
1166 aMeshEntry = aGeomVar->GetStudyEntry();
1172 aCreator->setShapeEntry( aGeomEntry );
1173 if ( aMeshEntry != "" )
1174 aCreator->setMainShapeEntry( aMeshEntry );
1175 myDlg->setEnabled( false );
1176 aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1180 SMESH::SMESH_Hypothesis_var aHyp =
1181 SMESH::CreateHypothesis(theTypeName, aHypName, false);
1182 #ifdef WITHGENERICOBJ
1183 if (!CORBA::is_nil(aHyp))
1193 //================================================================================
1195 * Necessary steps after hypothesis creation
1196 * \param result - creation result:
1199 * 2 = additional value meaning that slot is called not from dialog box
1201 //================================================================================
1202 void SMESHGUI_MeshOp::onHypoCreated( int result )
1206 int obj = myDlg->getActiveObject();
1207 onActivateObject( obj ); // Issue 0020170. Restore filters
1208 myDlg->setEnabled( true );
1211 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1213 int nbHyp = myExistingHyps[myDim][myType].count();
1214 HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1215 QStringList aNewHyps;
1216 existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1217 if (aNewHyps.count() > nbHyp)
1219 for (int i = nbHyp; i < aNewHyps.count(); i++)
1220 myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1223 if( result!=2 && myHypoSet )
1227 //================================================================================
1229 * \brief Calls plugin methods for hypothesis editing
1230 * \param theHypType - specifies whether main hypothesis or additional one
1232 * \param theIndex - index of existing hypothesis
1234 * Calls plugin methods for hypothesis editing
1236 //================================================================================
1237 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1239 // Speicfies dimension of hypothesis to be created
1240 int aDim = getTabDim( sender(), myDlg );
1244 const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1245 if ( theIndex < 0 || theIndex >= aList.count() )
1247 const THypItem& aHypItem = aList[ theIndex ];
1248 SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1249 if ( aHyp->_is_nil() )
1252 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1255 // Get initial parameters
1256 SMESH::SMESH_Hypothesis_var initParamHyp =
1257 getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1258 aCreator->setInitParamsHypothesis( initParamHyp );
1260 // Get Entry of the Geom object
1261 QString aGeomEntry = "";
1262 QString aMeshEntry = "";
1263 QString anObjEntry = "";
1264 aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1265 aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1266 anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1268 if ( myToCreate && myIsMesh )
1269 aMeshEntry = aGeomEntry;
1271 if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1272 _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1273 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1274 aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1277 if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1278 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1280 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1281 if ( !aGeomVar->_is_nil() )
1283 aGeomEntry = aGeomVar->GetStudyEntry();
1285 aMeshEntry = aGeomEntry;
1289 if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1290 // take geometry from submesh being created
1291 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1293 // if current object is sub-mesh
1294 SMESH::SMESH_subMesh_var aSubMeshVar =
1295 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1296 if ( !aSubMeshVar->_is_nil() ) {
1297 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1298 if ( !aMeshVar->_is_nil() ) {
1299 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1300 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1301 if ( !aGeomVar->_is_nil() )
1302 aMeshEntry = aGeomVar->GetStudyEntry();
1308 aCreator->setShapeEntry( aGeomEntry );
1309 if ( aMeshEntry != "" )
1310 aCreator->setMainShapeEntry( aMeshEntry );
1311 removeCustomFilters(); // Issue 0020170
1312 myDlg->setEnabled( false );
1313 aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1317 //================================================================================
1319 * Necessary steps after hypothesis edition
1320 * \param result - creation result:
1324 //================================================================================
1325 void SMESHGUI_MeshOp::onHypoEdited( int result )
1327 int obj = myDlg->getActiveObject();
1328 onActivateObject( obj ); // Issue 0020170. Restore filters
1329 myDlg->setEnabled( true );
1332 //================================================================================
1334 * \brief access to hypothesis data
1335 * \param theDim - hyp dimension
1336 * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1337 * \param theIndex - index in the list
1338 * \retval HypothesisData* - result data, may be 0
1340 //================================================================================
1341 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1342 const int theHypType,
1345 if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
1346 theHypType > -1 && theHypType < NbHypTypes &&
1347 theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
1348 return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1352 //================================================================================
1354 * \brief Set available algos and hypos according to the selected algorithm
1355 * \param theIndex - algorithm index
1357 //================================================================================
1358 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1361 if ( myIgnoreAlgoSelection )
1364 int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1368 // find highest available dimension, all algos of this dimension are available for choice
1370 for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1371 if (isAccessibleDim( i ))
1376 const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1378 HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1379 HypothesisData* algoByDim[4];
1380 algoByDim[ aDim ] = algoData;
1382 QStringList anAvailable;
1383 if ( !algoData ) { // all algos becomes available
1384 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1385 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1388 // check that algorithms of other dimentions are compatible with
1391 // 2 loops: backward and forward from algo dimension
1392 for ( int forward = false; forward <= true; ++forward )
1394 int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1396 dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1398 HypothesisData* prevAlgo = algoData;
1399 bool noCompatible = false;
1400 for ( ; dim * dir <= lastDim * dir; dim += dir)
1402 if ( !isAccessibleDim( dim ))
1404 if ( noCompatible ) { // the selected algo has no compatible ones
1405 anAvailable.clear();
1406 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1407 myAvailableHypData[dim][Algo].clear();
1408 algoByDim[ dim ] = 0;
1411 // get currently selected algo
1412 int algoIndex = currentHyp( dim, Algo );
1413 HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1414 if ( curAlgo ) { // some algo selected
1415 if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1418 // set new available algoritms
1419 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1420 HypothesisData* soleCompatible = 0;
1421 if ( anAvailable.count() == 1 )
1422 soleCompatible = myAvailableHypData[dim][Algo][0];
1423 if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1424 availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1425 myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1426 noCompatible = anAvailable.isEmpty();
1428 // restore previously selected algo
1429 algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1430 if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1431 // select the sole compatible algo
1432 algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1433 setCurrentHyp( dim, Algo, algoIndex );
1435 // remember current algo
1436 prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1440 // set hypotheses corresponding to the found algoritms
1442 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1444 for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1446 if ( !isAccessibleDim( dim ))
1448 for ( int type = MainHyp; type < NbHypTypes; type++ )
1450 myAvailableHypData[ dim ][ type ].clear();
1451 QStringList anAvailable, anExisting;
1453 HypothesisData* curAlgo = algoByDim[ dim ];
1454 int hypIndex = currentHyp( dim, type );
1456 SMESH::SMESH_Hypothesis_var curHyp;
1457 if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1458 curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1460 if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1461 // try to find algo by selected hypothesis in order to keep it selected
1462 bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1463 CORBA::String_var curHypType = curHyp->GetName();
1464 if ( !algoDeselectedByUser &&
1465 myObjHyps[ dim ][ type ].count() > 0 &&
1466 !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1468 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1469 for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1470 curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1471 if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1478 // get hyps compatible with curAlgo
1481 // check if a selected hyp is compatible with the curAlgo
1482 if ( !curHyp->_is_nil() ) {
1483 HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1484 if ( !isCompatible( curAlgo, hypData, type ))
1485 curHyp = SMESH::SMESH_Hypothesis::_nil();
1487 existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1488 availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1490 // set list of hypotheses
1491 myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1492 myDlg->tab( dim )->setExistingHyps( type, anExisting );
1494 // set current existing hypothesis
1495 if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1496 hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1499 if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1500 // none is yet selected => select the sole existing if it is not optional
1501 CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1502 bool isOptional = true;
1503 if ( algoByDim[ dim ] &&
1504 SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1508 setCurrentHyp( dim, type, hypIndex );
1513 //================================================================================
1515 * \brief Creates and selects hypothesis of hypotheses set
1516 * \param theSetName - The name of hypotheses set
1518 //================================================================================
1519 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1521 myHypoSet = SMESH::GetHypothesesSet(theSetName);
1526 for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1527 setCurrentHyp(dim, Algo, -1);
1528 setCurrentHyp(dim, AddHyp, -1);
1529 setCurrentHyp(dim, MainHyp, -1);
1532 myHypoSet->init(true); //algorithms
1534 myHypoSet->init(false); //hypotheses
1539 //================================================================================
1541 * \brief One step of hypothesis/algorithm list creation
1543 * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1545 //================================================================================
1546 void SMESHGUI_MeshOp::processSet()
1549 if( !myHypoSet->more() )
1552 bool isAlgo = myHypoSet->isAlgo();
1553 QString aHypoTypeName = myHypoSet->current();
1554 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1561 int aDim = aHypData->Dim[0];
1562 // create or/and set
1565 int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1568 QStringList anAvailable;
1569 availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1570 myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1571 index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1573 setCurrentHyp( aDim, Algo, index );
1574 onAlgoSelected( index, aDim );
1579 bool mainHyp = true;
1580 QStringList anAvailable;
1581 availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1582 myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1583 int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1587 index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1590 createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1596 //================================================================================
1598 * \brief Creates mesh
1599 * \param theMess - Output parameter intended for returning error message
1600 * \param theEntryList - List of entries of published objects
1601 * \retval bool - TRUE if mesh is created, FALSE otherwise
1605 //================================================================================
1606 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1610 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1611 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1614 myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1615 QStringList::Iterator it = aList.begin();
1616 for ( ; it!=aList.end(); it++)
1618 QString aGeomEntry = *it;
1619 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1620 GEOM::GEOM_Object_var aGeomVar =
1621 GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1623 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1624 if ( aSMESHGen->_is_nil() )
1627 SUIT_OverrideCursor aWaitCursor;
1630 SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1631 if ( aMeshVar->_is_nil() )
1633 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1635 SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1636 theEntryList.append( aMeshSO->GetID().c_str() );
1639 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1640 if ( !isAccessibleDim( aDim )) continue;
1642 // assign hypotheses
1643 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1644 int aHypIndex = currentHyp( aDim, aHypType );
1645 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1646 SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1647 if ( !aHypVar->_is_nil() )
1648 SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1651 // find or create algorithm
1652 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1653 if ( !anAlgoVar->_is_nil() )
1654 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1656 #ifdef WITHGENERICOBJ
1657 // obj has been published in study. Its refcount has been incremented.
1658 // It is safe to decrement its refcount
1659 // so that it will be destroyed when the entry in study will be removed
1661 aMeshVar->UnRegister();
1667 //================================================================================
1669 * \brief Creates sub-mesh
1670 * \param theMess - Output parameter intended for returning error message
1671 * \param theEntryList - List of entries of published objects
1672 * \retval bool - TRUE if sub-mesh is created, FALSE otherwise
1676 //================================================================================
1677 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1681 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1682 if ( aSMESHGen->_is_nil() )
1686 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1687 _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1688 SMESH::SMESH_Mesh_var aMeshVar =
1689 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1690 if (aMeshVar->_is_nil())
1693 // GEOM shape of the main mesh
1694 GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1696 // Name for the new sub-mesh
1697 QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1700 GEOM::GEOM_Object_var aGeomVar;
1702 myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1703 if (aGEOMs.count() == 1)
1705 //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1706 QString aGeomEntry = aGEOMs.first();
1707 _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1708 aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1710 else if (aGEOMs.count() > 1)
1712 // create a GEOM group
1713 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1714 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1715 if (!geomGen->_is_nil() && aStudy) {
1716 GEOM::GEOM_IGroupOperations_wrap op =
1717 geomGen->GetIGroupOperations(aStudy->StudyId());
1718 if (!op->_is_nil()) {
1719 // check and add all selected GEOM objects: they must be
1720 // a sub-shapes of the main GEOM and must be of one type
1722 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1723 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1724 aSeq->length(aGEOMs.count());
1725 QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1726 for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1727 QString aSubGeomEntry = (*aSubShapesIter);
1728 _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1729 GEOM::GEOM_Object_var aSubGeomVar =
1730 GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1731 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1733 aGroupType = aSubShapeType;
1735 if (aSubShapeType != aGroupType)
1736 aGroupType = TopAbs_SHAPE;
1738 aSeq[iSubSh] = aSubGeomVar;
1741 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1742 op->UnionList(aGroupVar, aSeq);
1745 aGeomVar = aGroupVar.in();
1747 // publish the GEOM group in study
1748 QString aNewGeomGroupName ("Auto_group_for_");
1749 aNewGeomGroupName += aName;
1750 SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1751 SALOMEDS::SObject_wrap aNewGroupSO =
1752 geomGen->AddInStudy( aStudyVar, aGeomVar,
1753 aNewGeomGroupName.toLatin1().data(), mainGeom);
1760 if (aGeomVar->_is_nil())
1763 SUIT_OverrideCursor aWaitCursor;
1766 SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1767 _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1769 SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1770 theEntryList.append( aSubMeshSO->GetID().c_str() );
1773 for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1775 if ( !isAccessibleDim( aDim )) continue;
1777 // find or create algorithm
1778 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1779 if ( !anAlgoVar->_is_nil() )
1780 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1781 // assign hypotheses
1782 for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1784 int aHypIndex = currentHyp( aDim, aHypType );
1785 if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1787 SMESH::SMESH_Hypothesis_var aHypVar =
1788 myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1789 if ( !aHypVar->_is_nil() )
1790 SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1795 // deselect geometry: next submesh should be created on other sub-shape
1796 myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1797 selectObject( _PTR(SObject)() );
1803 //================================================================================
1805 * \brief Gets current hypothesis or algorithms
1806 * \param theDim - dimension of hypothesis or algorithm
1807 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1808 * \retval int - current hypothesis or algorithms
1810 * Gets current hypothesis or algorithms
1812 //================================================================================
1813 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1815 return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1818 //================================================================================
1820 * \brief Returns true if hypotheses of given dim can be assigned
1821 * \param theDim - hypotheses dimension
1822 * \retval bool - result
1824 //================================================================================
1825 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1827 return myDlg->isTabEnabled( theDim );
1830 //================================================================================
1832 * \brief Sets current hypothesis or algorithms
1833 * \param theDim - dimension of hypothesis or algorithm
1834 * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1835 * \param theIndex - Index of hypothesis
1837 * Gets current hypothesis or algorithms
1839 //================================================================================
1840 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1841 const int theHypType,
1842 const int theIndex )
1844 myIgnoreAlgoSelection = true;
1845 myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1846 myIgnoreAlgoSelection = false;
1849 //================================================================================
1851 * \brief Generates default and sets mesh/submesh name
1853 * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1855 //================================================================================
1856 void SMESHGUI_MeshOp::setDefaultName() const
1860 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1862 QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1863 _PTR(SObject) anObj;
1866 aResName = aPrefix + QString::number( i++ );
1867 anObj = aStudy->FindObject( aResName.toLatin1().data() );
1871 QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1872 SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1873 aControl->setText( aResName );
1876 //================================================================================
1878 * \brief Gets algorithm or creates it if necessary
1879 * \param theDim - specifies dimension of returned hypotheses/algorifms
1880 * \retval SMESH::SMESH_Hypothesis_var - algorithm
1882 * Gets algorithm or creates it if necessary
1884 //================================================================================
1885 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1887 SMESH::SMESH_Hypothesis_var anAlgoVar;
1889 // get type of the selected algo
1890 int aHypIndex = currentHyp( theDim, Algo );
1891 THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1892 if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1894 QString aHypName = dataList[ aHypIndex ]->TypeName;
1896 // get existing algoritms
1897 _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1899 existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1901 // look for an existing algo of such a type
1902 THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1903 THypList::iterator anIter = aHypVarList.begin();
1904 for ( ; anIter != aHypVarList.end(); anIter++)
1906 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1907 CORBA::String_var aName = aHypVar->GetName();
1908 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1910 anAlgoVar = aHypVar;
1915 if (anAlgoVar->_is_nil())
1917 HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1920 QString aClientLibName = aHypData->ClientLibName;
1921 if (aClientLibName == "")
1923 // Call hypothesis creation server method (without GUI)
1924 SMESH::SMESH_Hypothesis_var aHyp =
1925 SMESH::CreateHypothesis(aHypName, aHypName, true);
1926 #ifdef WITHGENERICOBJ
1927 if (!CORBA::is_nil(aHyp))
1933 // Get hypotheses creator client (GUI)
1935 SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1939 aCreator->create(true, aHypName, myDlg, 0, QString::null );
1941 SMESH::SMESH_Hypothesis_var aHyp =
1942 SMESH::CreateHypothesis(aHypName, aHypName, true);
1943 #ifdef WITHGENERICOBJ
1944 if (!CORBA::is_nil(aHyp))
1949 QStringList tmpList;
1950 _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1951 existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1954 THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1955 for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1957 SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1958 CORBA::String_var aName = aHypVar->GetName();
1959 if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1961 anAlgoVar = aHypVar;
1967 return anAlgoVar._retn();
1970 //================================================================================
1972 * \brief Reads parameters of an edited mesh and assigns them to the dialog
1974 * Called when mesh is edited only.
1976 //================================================================================
1977 void SMESHGUI_MeshOp::readMesh()
1979 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1980 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1984 if (myIsOnGeometry) {
1985 // Get name of mesh if current object is sub-mesh
1986 SMESH::SMESH_subMesh_var aSubMeshVar =
1987 SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1988 if ( !aSubMeshVar->_is_nil() )
1990 SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather();
1991 if ( !aMeshVar->_is_nil() )
1993 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1994 QString aMeshName = name( aMeshSO );
1995 myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1999 // Get name of geometry object
2000 GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2001 if ( !aGeomVar->_is_nil() )
2003 _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2004 QString aShapeName = name( aGeomSO );
2005 myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2009 // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2010 QStringList anExisting;
2011 const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2012 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2015 existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2016 // find algo index among available ones
2018 if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2020 SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2021 HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2022 aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2023 // if ( aHypIndex < 0 && algoData ) {
2024 // // assigned algo is incompatible with other algorithms
2025 // myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2026 // aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2029 setCurrentHyp( dim, Algo, aHypIndex );
2030 // set existing and available hypothesis according to the selected algo
2031 onAlgoSelected( aHypIndex, dim );
2035 bool hypWithoutAlgo = false;
2036 for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2038 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2041 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2042 // find index of requered hypothesis among existing ones for this dimension and type
2044 if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2045 aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2046 myExistingHyps[ dim ][ hypType ] );
2047 if ( aHypIndex < 0 ) {
2048 // assigned hypothesis is incompatible with the algorithm
2049 if ( currentHyp( dim, Algo ) < 0 )
2050 { // none algo selected; it is edition for sure, of submesh maybe
2051 hypWithoutAlgo = true;
2052 myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2053 aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2054 myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2058 setCurrentHyp( dim, hypType, aHypIndex );
2061 // make available other hyps of same type as one without algo
2062 if ( hypWithoutAlgo )
2063 onAlgoSelected( currentHyp( 0, Algo ), 0 );
2066 //================================================================================
2068 * \brief Gets name of object
2069 * \param theSO - SObject
2070 * \retval QString - name of object
2072 * Gets name of object
2074 //================================================================================
2075 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2080 _PTR(GenericAttribute) anAttr;
2081 _PTR(AttributeName) aNameAttr;
2082 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2085 aResName = aNameAttr->Value().c_str();
2091 //================================================================================
2093 * \brief Finds hypothesis in input list
2094 * \param theHyp - hypothesis to be found
2095 * \param theHypList - input list of hypotheses
2096 * \retval int - index of hypothesis or -1 if it is not found
2098 * Finds position of hypothesis in input list
2100 //================================================================================
2101 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2102 const THypList& theHypList ) const
2105 if ( !theHyp->_is_nil() )
2108 THypList::const_iterator anIter = theHypList.begin();
2109 for ( ; anIter != theHypList.end(); ++ anIter)
2111 if ( theHyp->_is_equivalent( (*anIter).first ) )
2122 //================================================================================
2124 * \brief Edits mesh or sub-mesh
2125 * \param theMess - Output parameter intended for returning error message
2126 * \retval bool - TRUE if mesh is edited succesfully, FALSE otherwise
2128 * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2130 //================================================================================
2131 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2135 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2136 if ( aSMESHGen->_is_nil() )
2139 QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2140 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2144 SUIT_OverrideCursor aWaitCursor;
2147 QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2148 SMESH::SetName( pObj, aName );
2149 int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2151 // First, remove old algos in order to avoid messages on algorithm hiding
2152 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2154 if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2156 SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2157 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2158 if ( anAlgoVar->_is_nil() || // no new algo selected or
2159 strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2161 // remove old algorithm
2162 SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2163 myObjHyps[ dim ][ Algo ].clear();
2168 // Assign new algorithms and hypotheses
2169 for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2171 if ( !isAccessibleDim( dim )) continue;
2173 // find or create algorithm
2174 SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2176 // assign new algorithm
2177 if ( !anAlgoVar->_is_nil() && // some algo selected and
2178 myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2180 SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2181 CORBA::Object_var anObject = aSObject->GetObject();
2182 SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2183 bool isMesh = !aMeshVar->_is_nil();
2185 SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2187 SMESH::SMESH_subMesh_var aVar =
2188 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2189 if ( !aVar->_is_nil() )
2190 SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2192 myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2195 // assign hypotheses
2196 for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2198 int aNewHypIndex = currentHyp( dim, hypType );
2199 int anOldHypIndex = -1;
2201 // remove old hypotheses
2202 if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2204 anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2205 myExistingHyps[ dim ][ hypType ] );
2206 if ( aNewHypIndex != anOldHypIndex || // different hyps
2207 anOldHypIndex == -1 ) // hyps of different algos
2209 SMESH::RemoveHypothesisOrAlgorithmOnMesh
2210 ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2211 myObjHyps[ dim ][ hypType ].clear();
2215 // assign new hypotheses
2216 if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2218 SMESH::SMESH_Mesh_var aMeshVar =
2219 SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2220 bool isMesh = !aMeshVar->_is_nil();
2223 SMESH::AddHypothesisOnMesh
2224 (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2228 SMESH::SMESH_subMesh_var aVar =
2229 SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2230 if ( !aVar->_is_nil() )
2231 SMESH::AddHypothesisOnSubMesh
2232 ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2235 // reread all hypotheses of mesh if necessary
2236 QStringList anExisting;
2237 existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2244 //================================================================================
2246 * \brief Verifies whether given operator is valid for this one
2247 * \param theOtherOp - other operation
2248 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2250 * method redefined from base class verifies whether given operator is valid for
2251 * this one (i.e. can be started "above" this operator). In current implementation method
2252 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2255 //================================================================================
2256 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2258 return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2261 //================================================================================
2263 * \brief SLOT. Is called when the user selects a way of geometry selection
2264 * \param theByMesh - true if the user wants to find geometry by mesh element
2266 //================================================================================
2267 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2270 if ( !myShapeByMeshOp ) {
2271 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2272 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2273 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2274 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2275 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2277 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2278 QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2279 if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2280 SMESH::SMESH_Mesh_var aMeshVar =
2281 SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2282 if ( !aMeshVar->_is_nil() ) {
2283 myDlg->hide(); // stop processing selection
2284 myShapeByMeshOp->setModule( getSMESHGUI() );
2285 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2286 myShapeByMeshOp->SetMesh( aMeshVar );
2287 myShapeByMeshOp->start();
2293 //================================================================================
2295 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2297 //================================================================================
2298 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2300 if ( myShapeByMeshOp == op ) {
2301 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
2303 // Select a found geometry object
2304 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2305 if ( !aGeomVar->_is_nil() )
2307 QString ID = aGeomVar->GetStudyEntry();
2308 if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2309 selectObject( aGeomSO );
2316 //================================================================================
2318 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2320 //================================================================================
2321 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2323 if ( myShapeByMeshOp == op && myDlg ) {
2328 //================================================================================
2330 * \brief Selects a SObject
2331 * \param theSObj - the SObject to select
2333 //================================================================================
2334 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2336 if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2337 SALOME_ListIO anIOList;
2339 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2340 ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2341 anIOList.Append( anIO );
2343 sm->setSelectedObjects( anIOList, false );