1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_EditHypothesesDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_EditHypothesesDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_GEOMGenUtils.h"
34 #include "SMESHGUI_HypothesesUtils.h"
36 #include "SALOME_ListIteratorOfListIO.hxx"
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "QAD_WaitCursor.h"
41 #include "QAD_Operation.h"
43 #include "SALOMEconfig.h"
44 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
46 #include "utilities.h"
49 #include <qgroupbox.h>
51 #include <qlineedit.h>
52 #include <qpushbutton.h>
58 //VRV: porting on Qt 3.0.5
59 #if QT_VERSION >= 0x030005
62 //VRV: porting on Qt 3.0.5
64 class ListBoxIOR : public QListBoxText
67 enum { RTTI_IOR = 1000 };
70 ListBoxIOR( QListBox* listbox,
72 const QString& text = QString::null)
73 : QListBoxText( listbox, text ), myIOR( ior ) {}
74 virtual ~ListBoxIOR() {};
75 virtual int rtti() const { return RTTI_IOR; }
76 const char* GetIOR() { return myIOR.c_str(); }
82 #define ALLOW_CHANGE_SHAPE 0
84 int findItem( QListBox* listBox, const string& ior )
86 for ( int i = 0; i < listBox->count(); i++ ) {
87 if ( listBox->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
88 ListBoxIOR* anItem = ( ListBoxIOR* )( listBox->item( i ) );
89 if ( anItem && ior == string( anItem->GetIOR() ) )
96 //=================================================================================
97 // class : SMESHGUI_EditHypothesesDlg()
98 // purpose : Constructs a SMESHGUI_EditHypothesesDlg which is a child of 'parent', with the
99 // name 'name' and widget flags set to 'f'.
100 // The dialog will by default be modeless, unless you set 'modal' to
101 // TRUE to construct a modal dialog.
102 //=================================================================================
103 SMESHGUI_EditHypothesesDlg::SMESHGUI_EditHypothesesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
104 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
105 myImportedMesh( false )
107 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
109 setName( "SMESHGUI_EditHypothesesDlg" );
110 setCaption( tr( "SMESH_EDIT_HYPOTHESES" ) );
111 setSizeGripEnabled( TRUE );
112 QGridLayout* SMESHGUI_EditHypothesesDlgLayout = new QGridLayout( this );
113 SMESHGUI_EditHypothesesDlgLayout->setSpacing( 6 );
114 SMESHGUI_EditHypothesesDlgLayout->setMargin( 11 );
116 /***************************************************************/
117 GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), this, "GroupC1" );
118 GroupC1->setColumnLayout(0, Qt::Vertical );
119 GroupC1->layout()->setSpacing( 0 );
120 GroupC1->layout()->setMargin( 0 );
121 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
122 GroupC1Layout->setAlignment( Qt::AlignTop );
123 GroupC1Layout->setSpacing( 6 );
124 GroupC1Layout->setMargin( 11 );
126 TextLabelC1A1 = new QLabel( tr( "SMESH_OBJECT_MESHorSUBMESH" ), GroupC1, "TextLabelC1A1" );
127 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
128 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
129 SelectButtonC1A1->setPixmap( image0 );
130 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
131 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
132 LineEditC1A1->setReadOnly( true );
133 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
135 TextLabelC1A2 = new QLabel( tr( "SMESH_OBJECT_GEOM" ), GroupC1, "TextLabelC1A2" );
136 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
137 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
138 SelectButtonC1A2->setPixmap( image0 );
139 SelectButtonC1A2->setToggleButton( FALSE );
140 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
141 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
142 LineEditC1A2->setReadOnly( true );
143 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
145 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupC1, 0, 0 );
147 /***************************************************************/
148 GroupHypotheses = new QGroupBox( tr( "SMESH_HYPOTHESES" ), this, "GroupHypotheses" );
149 GroupHypotheses->setColumnLayout(0, Qt::Vertical );
150 GroupHypotheses->layout()->setSpacing( 0 );
151 GroupHypotheses->layout()->setMargin( 0 );
152 QGridLayout* grid_3 = new QGridLayout( GroupHypotheses->layout() );
153 grid_3->setAlignment( Qt::AlignTop );
154 grid_3->setSpacing( 6 );
155 grid_3->setMargin( 11 );
157 TextHypDefinition = new QLabel( tr( "SMESH_AVAILABLE" ), GroupHypotheses, "TextHypDefinition" );
158 grid_3->addWidget( TextHypDefinition, 0, 0 );
160 ListHypDefinition = new QListBox( GroupHypotheses, "ListHypDefinition" );
161 ListHypDefinition->setMinimumSize( 100, 100 );
162 grid_3->addWidget( ListHypDefinition, 1, 0 );
164 TextHypAssignation = new QLabel( tr( "SMESH_EDIT_USED" ), GroupHypotheses, "TextHypAssignation" );
165 grid_3->addWidget( TextHypAssignation, 0, 1 );
167 ListHypAssignation = new QListBox( GroupHypotheses, "ListHypAssignation" );
168 ListHypAssignation->setMinimumSize( 100, 100 );
169 grid_3->addWidget( ListHypAssignation, 1, 1 );
171 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupHypotheses, 1, 0 );
173 /***************************************************************/
174 GroupAlgorithms = new QGroupBox( tr( "SMESH_ADD_ALGORITHM" ), this, "GroupAlgorithms" );
175 GroupAlgorithms->setColumnLayout(0, Qt::Vertical );
176 GroupAlgorithms->layout()->setSpacing( 0 );
177 GroupAlgorithms->layout()->setMargin( 0 );
178 QGridLayout* grid_4 = new QGridLayout( GroupAlgorithms->layout() );
179 grid_4->setAlignment( Qt::AlignTop );
180 grid_4->setSpacing( 6 );
181 grid_4->setMargin( 11 );
183 TextAlgoDefinition = new QLabel( tr( "SMESH_AVAILABLE" ), GroupAlgorithms, "TextAlgoDefinition" );
184 grid_4->addWidget( TextAlgoDefinition, 0, 0 );
186 ListAlgoDefinition = new QListBox( GroupAlgorithms, "ListAlgoDefinition" );
187 ListAlgoDefinition->setMinimumSize( 100, 100 );
188 grid_4->addWidget( ListAlgoDefinition, 1, 0 );
190 TextAlgoAssignation = new QLabel( tr( "SMESH_EDIT_USED" ), GroupAlgorithms, "TextAlgoAssignation" );
191 grid_4->addWidget( TextAlgoAssignation, 0, 1 );
193 ListAlgoAssignation = new QListBox( GroupAlgorithms, "ListAlgoAssignation" );
194 ListAlgoAssignation ->setMinimumSize( 100, 100 );
195 grid_4->addWidget( ListAlgoAssignation, 1, 1 );
197 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupAlgorithms, 2, 0 );
199 /***************************************************************/
200 GroupButtons = new QGroupBox( this, "GroupButtons" );
201 GroupButtons->setColumnLayout(0, Qt::Vertical );
202 GroupButtons->layout()->setSpacing( 0 );
203 GroupButtons->layout()->setMargin( 0 );
204 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
205 GroupButtonsLayout->setAlignment( Qt::AlignTop );
206 GroupButtonsLayout->setSpacing( 6 );
207 GroupButtonsLayout->setMargin( 11 );
209 buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons, "buttonOk" );
210 buttonOk->setAutoDefault( TRUE );
211 buttonOk->setDefault( FALSE );
212 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
214 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons, "buttonApply" );
215 buttonApply->setAutoDefault( TRUE );
216 buttonApply->setDefault( FALSE );
217 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
219 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
221 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons, "buttonCancel" );
222 buttonCancel->setAutoDefault( TRUE );
223 buttonCancel->setDefault( TRUE );
224 buttonCancel->setEnabled( TRUE ) ;
225 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
227 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupButtons, 4, 0 );
229 /***************************************************************/
234 //=================================================================================
235 // function : ~SMESHGUI_EditHypothesesDlg()
236 // purpose : Destroys the object and frees any allocated resources
237 //=================================================================================
238 SMESHGUI_EditHypothesesDlg::~SMESHGUI_EditHypothesesDlg()
240 // no need to delete child widgets, Qt does it all for us
244 //=================================================================================
247 //=================================================================================
248 void SMESHGUI_EditHypothesesDlg::Init( SALOME_Selection* Sel )
251 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
252 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
255 InitAlgoDefinition();
257 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
258 myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
260 myGeomShape = GEOM::GEOM_Object::_nil();
261 myMesh = SMESH::SMESH_Mesh::_nil();
262 mySubMesh = SMESH::SMESH_subMesh::_nil();
264 /* signals and slots connections */
265 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
266 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
267 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
269 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
270 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
272 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
273 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
274 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
276 connect( ListHypAssignation, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( removeItem(QListBoxItem*) ) );
277 connect( ListAlgoAssignation, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( removeItem(QListBoxItem*) ) );
279 connect( ListHypDefinition, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( addItem(QListBoxItem*) ) );
280 connect( ListAlgoDefinition, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( addItem(QListBoxItem*) ) );
283 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
287 LineEditC1A1->setFocus() ;
288 myEditCurrentArgument = LineEditC1A1;
289 mySelection->ClearFilters() ;
290 mySelection->AddFilter(myMeshOrSubMeshFilter) ;
292 SelectionIntoArgument();
294 UpdateControlState();
298 //=================================================================================
299 // function : ClickOnOk()
301 //=================================================================================
302 void SMESHGUI_EditHypothesesDlg::ClickOnOk()
304 if ( ClickOnApply() )
308 //=================================================================================
309 // function : ClickOnApply()
311 //=================================================================================
312 bool SMESHGUI_EditHypothesesDlg::ClickOnApply()
314 if (mySMESHGUI->ActiveStudyLocked())
321 QAD_Operation* op = new QAD_Operation( mySMESHGUI->GetActiveStudy() );
326 if ( !myMesh->_is_nil() )
328 else if ( !mySubMesh->_is_nil() )
329 aRes = StoreSubMesh();
331 if ( true/*aRes*/ ) // abort desynchronizes contents of a Study and a mesh on server
333 // commit transaction
335 InitHypAssignation();
336 InitAlgoAssignation();
342 UpdateControlState();
348 //=================================================================================
349 // function : ClickOnCancel()
351 //=================================================================================
352 void SMESHGUI_EditHypothesesDlg::ClickOnCancel()
358 //=================================================================================
359 // function : SelectionIntoArgument()
360 // purpose : Called when selection as changed or other case
361 //=================================================================================
362 void SMESHGUI_EditHypothesesDlg::SelectionIntoArgument()
364 QString aString = "";
366 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString) ;
368 if ( myEditCurrentArgument == LineEditC1A1 ) {
370 myMesh = SMESH::SMESH_Mesh::_nil();
371 mySubMesh = SMESH::SMESH_subMesh::_nil();
374 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
375 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
376 if(myMesh->_is_nil()){
377 mySubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
378 if(mySubMesh->_is_nil()){
383 myEditCurrentArgument->setText( aString );
385 myGeomShape = GEOM::GEOM_Object::_nil(); // InitGeom() will try to retrieve a shape from myMesh or mySubMesh
388 myImportedMesh = myGeomShape->_is_nil();
390 InitHypAssignation();
391 InitAlgoAssignation();
393 else if ( myEditCurrentArgument == LineEditC1A2 ) {
395 myGeomShape = GEOM::GEOM_Object::_nil();
397 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
398 myGeomShape = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO) ;
403 UpdateControlState();
407 //=================================================================================
408 // function : SetEditCurrentArgument()
410 //=================================================================================
411 void SMESHGUI_EditHypothesesDlg::SetEditCurrentArgument()
413 QPushButton* send = (QPushButton*)sender();
414 if(send == SelectButtonC1A1) {
415 LineEditC1A1->setFocus() ;
416 myEditCurrentArgument = LineEditC1A1;
417 mySelection->ClearFilters() ;
418 mySelection->AddFilter(myMeshOrSubMeshFilter) ;
419 } else if (send == SelectButtonC1A2) {
420 LineEditC1A2->setFocus() ;
421 myEditCurrentArgument = LineEditC1A2;
422 mySelection->ClearFilters() ;
423 mySelection->AddFilter(myGeomFilter) ;
425 SelectionIntoArgument() ;
428 //=================================================================================
429 // function : DeactivateActiveDialog()
431 //=================================================================================
432 void SMESHGUI_EditHypothesesDlg::DeactivateActiveDialog()
434 if ( GroupC1->isEnabled() ) {
435 disconnect( mySelection, 0, this, 0 );
436 GroupC1->setEnabled(false) ;
437 GroupButtons->setEnabled(false) ;
442 //=================================================================================
443 // function : ActivateThisDialog()
445 //=================================================================================
446 void SMESHGUI_EditHypothesesDlg::ActivateThisDialog()
448 mySMESHGUI->EmitSignalDeactivateDialog() ;
449 GroupC1->setEnabled(true) ;
450 GroupButtons->setEnabled(true) ;
451 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
455 //=================================================================================
456 // function : enterEvent()
458 //=================================================================================
459 void SMESHGUI_EditHypothesesDlg::enterEvent(QEvent* e)
461 if ( !GroupC1->isEnabled() )
462 ActivateThisDialog();
466 //=================================================================================
467 // function : closeEvent()
469 //=================================================================================
470 void SMESHGUI_EditHypothesesDlg::closeEvent( QCloseEvent* e )
472 disconnect( mySelection, 0, this, 0 );
473 mySMESHGUI->ResetState() ;
474 mySelection->ClearFilters() ;
475 QDialog::closeEvent( e );
478 //=======================================================================
481 //=======================================================================
483 bool SMESHGUI_EditHypothesesDlg::IsOld(QListBoxItem* hypItem)
485 if ( hypItem->rtti() == ListBoxIOR::RTTI_IOR ) {
486 ListBoxIOR* hyp = ( ListBoxIOR* ) hypItem;
487 return (myMapOldHypos.find( hyp->GetIOR() ) != myMapOldHypos.end() ||
488 myMapOldAlgos.find( hyp->GetIOR() ) != myMapOldAlgos.end() );
494 //=================================================================================
495 // function : removeItem()
497 //=================================================================================
498 void SMESHGUI_EditHypothesesDlg::removeItem(QListBoxItem* item)
500 const QObject* aSender = sender();
504 if ( aSender == ListHypAssignation ) {
505 myNbModification += IsOld( item ) ? 1 : -1;
506 ListHypAssignation->removeItem( ListHypAssignation->index( item ) );
508 else if ( aSender == ListAlgoAssignation ) {
509 myNbModification += IsOld( item ) ? 1 : -1;
510 ListAlgoAssignation->removeItem( ListAlgoAssignation->index( item ) );
514 UpdateControlState();
518 //=================================================================================
519 // function : addItem()
521 //=================================================================================
522 void SMESHGUI_EditHypothesesDlg::addItem(QListBoxItem* item)
524 const QObject* aSender = sender();
529 if ( item->rtti() == ListBoxIOR::RTTI_IOR )
530 i = (ListBoxIOR*)item;
533 bool isFound = false;
535 if ( aSender == ListHypDefinition ) {
536 for ( int j = 0, n = ListHypAssignation->count(); !isFound && j < n; j++ ) {
537 if ( ListHypAssignation->item( j )->rtti() == ListBoxIOR::RTTI_IOR ) {
538 ListBoxIOR* anItem = (ListBoxIOR*)ListHypAssignation->item( j );
539 isFound = !strcmp( anItem->GetIOR(), i->GetIOR() );
543 ListBoxIOR* anItem = new ListBoxIOR( ListHypAssignation,
544 CORBA::string_dup( i->GetIOR() ),
545 CORBA::string_dup( i->text().latin1() ) );
547 else if ( aSender == ListAlgoDefinition ) {
548 for ( int j = 0, n = ListAlgoAssignation->count(); !isFound && j < n; j++ ) {
549 if ( ListAlgoAssignation->item( j )->rtti() == ListBoxIOR::RTTI_IOR ) {
550 ListBoxIOR* anItem = (ListBoxIOR*)ListAlgoAssignation->item( j );
551 isFound = !strcmp( anItem->GetIOR(), i->GetIOR() );
555 ListBoxIOR* anItem = new ListBoxIOR( ListAlgoAssignation,
556 CORBA::string_dup( i->GetIOR() ),
557 CORBA::string_dup( i->text().latin1() ) );
561 myNbModification += IsOld( item ) ? -1 : 1;
563 UpdateControlState();
567 //=================================================================================
568 // function : InitHypDefinition()
570 //=================================================================================
571 void SMESHGUI_EditHypothesesDlg::InitHypDefinition()
573 ListHypDefinition->clear();
575 SALOMEDS::SComponent_var father = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
576 if ( father->_is_nil() )
579 SALOMEDS::SObject_var HypothesisRoot;
580 SALOMEDS::GenericAttribute_var anAttr;
581 SALOMEDS::AttributeName_var aName;
582 SALOMEDS::AttributeIOR_var anIOR;
584 int Tag_HypothesisRoot = 1;
585 if (father->FindSubObject (1, HypothesisRoot)) {
586 SALOMEDS::ChildIterator_var it = SMESH::GetActiveStudyDocument()->NewChildIterator(HypothesisRoot);
587 for (; it->More();it->Next()) {
588 SALOMEDS::SObject_var Obj = it->Value();
589 if (Obj->FindAttribute(anAttr, "AttributeName") ) {
590 aName = SALOMEDS::AttributeName::_narrow(anAttr);
591 if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
592 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
593 ListBoxIOR* anItem = new ListBoxIOR( ListHypDefinition,
602 //=================================================================================
603 // function : InitHypAssignation()
605 //=================================================================================
606 void SMESHGUI_EditHypothesesDlg::InitHypAssignation()
608 myNbModification = 0;
609 // MESSAGE ( " InitHypAssignation " << myMesh->_is_nil() )
610 // MESSAGE ( " InitHypAssignation " << mySubMesh->_is_nil() )
612 myMapOldHypos.clear();
613 ListHypAssignation->clear();
614 if ( myImportedMesh )
617 SALOMEDS::SObject_var aMorSM, AHR, aRef;
618 SALOMEDS::GenericAttribute_var anAttr;
619 SALOMEDS::AttributeName_var aName;
620 SALOMEDS::AttributeIOR_var anIOR;
622 if ( !myMesh->_is_nil() )
623 aMorSM = SMESH::FindSObject( myMesh );
624 else if ( !mySubMesh->_is_nil() )
625 aMorSM = SMESH::FindSObject( mySubMesh );
627 if ( !aMorSM->_is_nil() && aMorSM->FindSubObject (2, AHR)) {
628 SALOMEDS::ChildIterator_var it = SMESH::GetActiveStudyDocument()->NewChildIterator(AHR);
629 for (; it->More();it->Next()) {
630 SALOMEDS::SObject_var Obj = it->Value();
631 if ( Obj->ReferencedObject(aRef) ) {
632 if (aRef->FindAttribute(anAttr, "AttributeName") ) {
633 aName = SALOMEDS::AttributeName::_narrow(anAttr);
634 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
635 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
636 ListBoxIOR* anItem = new ListBoxIOR( ListHypAssignation,
639 myMapOldHypos[ anIOR->Value() ] = ListHypAssignation->index( anItem );
647 //=================================================================================
648 // function : InitAlgoDefinition()
650 //=================================================================================
651 void SMESHGUI_EditHypothesesDlg::InitAlgoDefinition()
653 ListAlgoDefinition->clear();
655 SALOMEDS::SComponent_var father = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
656 if ( father->_is_nil() )
659 SALOMEDS::SObject_var AlgorithmsRoot;
660 SALOMEDS::GenericAttribute_var anAttr;
661 SALOMEDS::AttributeName_var aName;
662 SALOMEDS::AttributeIOR_var anIOR;
664 if (father->FindSubObject (2, AlgorithmsRoot)) {
665 SALOMEDS::ChildIterator_var it = SMESH::GetActiveStudyDocument()->NewChildIterator(AlgorithmsRoot);
666 for (; it->More();it->Next()) {
667 SALOMEDS::SObject_var Obj = it->Value();
668 if (Obj->FindAttribute(anAttr, "AttributeName") ) {
669 aName = SALOMEDS::AttributeName::_narrow(anAttr);
670 if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
671 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
672 ListBoxIOR* anItem = new ListBoxIOR( ListAlgoDefinition,
682 //=================================================================================
683 // function : InitAlgoAssignation()
685 //=================================================================================
686 void SMESHGUI_EditHypothesesDlg::InitAlgoAssignation()
688 MESSAGE ( " InitAlgoAssignation " << myMesh->_is_nil() )
689 MESSAGE ( " InitAlgoAssignation " << mySubMesh->_is_nil() )
691 myMapOldAlgos.clear();
692 ListAlgoAssignation->clear();
693 if ( myImportedMesh )
696 SALOMEDS::SObject_var aMorSM, AHR, aRef;
697 SALOMEDS::GenericAttribute_var anAttr;
698 SALOMEDS::AttributeName_var aName;
699 SALOMEDS::AttributeIOR_var anIOR;
701 if ( !myMesh->_is_nil() )
702 aMorSM = SMESH::FindSObject( myMesh );
703 else if ( !mySubMesh->_is_nil() )
704 aMorSM = SMESH::FindSObject( mySubMesh );
706 if ( !aMorSM->_is_nil() && aMorSM->FindSubObject (3, AHR)) {
707 SALOMEDS::ChildIterator_var it = SMESH::GetActiveStudyDocument()->NewChildIterator(AHR);
708 for (; it->More();it->Next()) {
709 SALOMEDS::SObject_var Obj = it->Value();
710 if ( Obj->ReferencedObject(aRef) ) {
711 if (aRef->FindAttribute(anAttr, "AttributeName") ) {
712 aName = SALOMEDS::AttributeName::_narrow(anAttr);
713 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
714 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
715 ListBoxIOR* anItem = new ListBoxIOR( ListAlgoAssignation,
718 myMapOldAlgos[ anIOR->Value() ] = ListAlgoAssignation->index( anItem );
726 //=================================================================================
727 // function : InitGeom()
729 //=================================================================================
730 void SMESHGUI_EditHypothesesDlg::InitGeom()
732 LineEditC1A2->setText("") ;
734 if ( myGeomShape->_is_nil() && !myMesh->_is_nil() ) {
735 SALOMEDS::SObject_var aMesh = SMESH::FindSObject( myMesh );
736 if ( !aMesh->_is_nil() )
737 myGeomShape = SMESH::GetShapeOnMeshOrSubMesh(aMesh);
739 if ( myGeomShape->_is_nil() && !mySubMesh->_is_nil() ) {
740 SALOMEDS::SObject_var aSubMesh = SMESH::FindSObject( mySubMesh );
741 if ( !aSubMesh->_is_nil() )
742 myGeomShape = SMESH::GetShapeOnMeshOrSubMesh(aSubMesh);
745 SALOMEDS::GenericAttribute_var anAttr;
746 SALOMEDS::AttributeName_var aName;
747 if ( !myGeomShape->_is_nil() && (!myMesh->_is_nil() || !mySubMesh->_is_nil()) ) {
748 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
749 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomShape) );
750 if ( !aSO->_is_nil() ) {
751 if (aSO->FindAttribute(anAttr, "AttributeName") ) {
752 aName = SALOMEDS::AttributeName::_narrow(anAttr);
753 LineEditC1A2->setText( QString(aName->Value()) ) ;
759 //=================================================================================
760 // function : UpdateControlState()
762 //=================================================================================
763 void SMESHGUI_EditHypothesesDlg::UpdateControlState()
765 bool isEnabled = ( !myMesh ->_is_nil() && !myGeomShape->_is_nil() && ListHypAssignation->count() && ListAlgoAssignation->count() ) ||
766 ( !mySubMesh->_is_nil() && !myGeomShape->_is_nil() && ( ListHypAssignation->count() || ListAlgoAssignation->count() ) );
768 buttonOk ->setEnabled( myNbModification && isEnabled && !myImportedMesh );
769 buttonApply->setEnabled( myNbModification && isEnabled && !myImportedMesh );
771 SelectButtonC1A2 ->setEnabled( ALLOW_CHANGE_SHAPE && !myImportedMesh );
772 LineEditC1A2 ->setEnabled( ALLOW_CHANGE_SHAPE && !myImportedMesh );
773 ListHypDefinition ->setEnabled( !myImportedMesh );
774 ListHypAssignation ->setEnabled( !myImportedMesh );
775 ListAlgoDefinition ->setEnabled( !myImportedMesh );
776 ListAlgoAssignation->setEnabled( !myImportedMesh );
779 //=================================================================================
780 // function : StoreMesh()
782 //=================================================================================
783 bool SMESHGUI_EditHypothesesDlg::StoreMesh()
785 MapIOR anOldHypos, aNewHypos;
786 if ( myGeomShape->_is_nil() )
788 // 1. Check whether the geometric shape has changed
789 SALOMEDS::SObject_var aMeshSO = SMESH::FindSObject( myMesh );
790 GEOM::GEOM_Object_var aIniGeomShape = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
791 bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent( myGeomShape );
792 if ( bShapeChanged ) {
793 // VSR : TODO : Set new shape - not supported yet by SMESH engine
794 // 1. remove all old hypotheses and algorithms and also submeshes
800 // 2. remove not used hypotheses from the mesh
801 for ( it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it ) {
802 string ior = it->first;
803 int index = findItem( ListHypAssignation, ior );
805 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
806 if ( !aHyp->_is_nil() ){
807 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aMeshSO, aHyp ))
812 // 3. remove not used algorithms from the mesh
813 for ( it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it ) {
814 string ior = it->first;
815 int index = findItem( ListAlgoAssignation, ior );
817 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
818 if ( !aHyp->_is_nil() ){
819 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aMeshSO, aHyp ))
824 // 4. Add new algorithms
825 for ( int i = 0; i < ListAlgoAssignation->count(); i++ ) {
826 if ( ListAlgoAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
827 ListBoxIOR* anItem = ( ListBoxIOR* )( ListAlgoAssignation->item( i ) );
829 string ior = anItem->GetIOR();
830 if ( myMapOldAlgos.find( ior ) == myMapOldAlgos.end() ) {
831 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
832 if ( !aHyp->_is_nil() ){
833 if (!SMESH::AddHypothesisOnMesh( myMesh, aHyp ))
840 // 5. Add new hypotheses
841 for ( int i = 0; i < ListHypAssignation->count(); i++ ) {
842 if ( ListHypAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
843 ListBoxIOR* anItem = ( ListBoxIOR* )( ListHypAssignation->item( i ) );
845 string ior = anItem->GetIOR();
846 if ( myMapOldHypos.find( ior ) == myMapOldHypos.end() ) {
847 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
848 if ( !aHyp->_is_nil() ){
849 if (!SMESH::AddHypothesisOnMesh( myMesh, aHyp ))
856 return ( nbFail == 0 );
859 //=================================================================================
860 // function : StoreSubMesh()
862 //=================================================================================
863 bool SMESHGUI_EditHypothesesDlg::StoreSubMesh()
865 MapIOR anOldHypos, aNewHypos;
866 if ( myGeomShape->_is_nil() )
868 // 1. Check whether the geometric shape has changed
869 SALOMEDS::SObject_var aSubMeshSO = SMESH::FindSObject( mySubMesh );
870 GEOM::GEOM_Object_var aIniGeomShape = SMESH::GetShapeOnMeshOrSubMesh( aSubMeshSO );
871 bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent( myGeomShape );
872 if ( bShapeChanged ) {
873 // VSR : TODO : Set new shape - not supported yet by engine
874 // 1. remove all old hypotheses and algorithms
879 // 2. remove not used hypotheses from the submesh
880 for ( it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it ) {
881 string ior = it->first;
882 int index = findItem( ListHypAssignation, ior );
884 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
885 if ( !aHyp->_is_nil() ){
886 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aSubMeshSO, aHyp ))
891 // 3. remove not used algorithms from the submesh
892 for ( it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it ) {
893 string ior = it->first;
894 int index = findItem( ListAlgoAssignation, ior );
896 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
897 if ( !aHyp->_is_nil() ){
898 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aSubMeshSO, aHyp ))
903 // 4. Add new algorithms
904 for ( int i = 0; i < ListAlgoAssignation->count(); i++ ) {
905 if ( ListAlgoAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
906 ListBoxIOR* anItem = ( ListBoxIOR* )( ListAlgoAssignation->item( i ) );
908 string ior = anItem->GetIOR();
909 if ( myMapOldAlgos.find( ior ) == myMapOldAlgos.end() ) {
910 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
911 if ( !aHyp->_is_nil() ){
912 if (!SMESH::AddHypothesisOnSubMesh( mySubMesh, aHyp ))
919 // 5. Add new hypotheses
920 for ( int i = 0; i < ListHypAssignation->count(); i++ ) {
921 if ( ListHypAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
922 ListBoxIOR* anItem = ( ListBoxIOR* )( ListHypAssignation->item( i ) );
924 string ior = anItem->GetIOR();
925 if ( myMapOldHypos.find( ior ) == myMapOldHypos.end() ) {
926 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
927 if ( !aHyp->_is_nil() ){
928 if (!SMESH::AddHypothesisOnSubMesh( mySubMesh, aHyp ))
935 return ( nbFail == 0 );