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
30 #include "SMESHGUI_EditHypothesesDlg.h"
32 #include "SALOME_ListIteratorOfListIO.hxx"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_WaitCursor.h"
37 #include "QAD_Operation.h"
39 #include "utilities.h"
42 #include <qgroupbox.h>
44 #include <qlineedit.h>
45 #include <qpushbutton.h>
49 //VRV: porting on Qt 3.0.5
50 #if QT_VERSION >= 0x030005
53 //VRV: porting on Qt 3.0.5
55 class ListBoxIOR : public QListBoxText
58 enum { RTTI_IOR = 1000 };
61 ListBoxIOR( QListBox* listbox,
63 const QString& text = QString::null)
64 : QListBoxText( listbox, text ), myIOR( ior ) {}
65 virtual ~ListBoxIOR() {};
66 virtual int rtti() const { return RTTI_IOR; }
67 const char* GetIOR() { return myIOR.c_str(); }
73 #define ALLOW_CHANGE_SHAPE 0
75 int findItem( QListBox* listBox, const string& ior )
77 for ( int i = 0; i < listBox->count(); i++ ) {
78 if ( listBox->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
79 ListBoxIOR* anItem = ( ListBoxIOR* )( listBox->item( i ) );
80 if ( anItem && ior == string( anItem->GetIOR() ) )
87 //=================================================================================
88 // class : SMESHGUI_EditHypothesesDlg()
89 // purpose : Constructs a SMESHGUI_EditHypothesesDlg which is a child of 'parent', with the
90 // name 'name' and widget flags set to 'f'.
91 // The dialog will by default be modeless, unless you set 'modal' to
92 // TRUE to construct a modal dialog.
93 //=================================================================================
94 SMESHGUI_EditHypothesesDlg::SMESHGUI_EditHypothesesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
95 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
96 myImportedMesh( false )
98 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
100 setName( "SMESHGUI_EditHypothesesDlg" );
101 setCaption( tr( "SMESH_EDIT_HYPOTHESES" ) );
102 setSizeGripEnabled( TRUE );
103 QGridLayout* SMESHGUI_EditHypothesesDlgLayout = new QGridLayout( this );
104 SMESHGUI_EditHypothesesDlgLayout->setSpacing( 6 );
105 SMESHGUI_EditHypothesesDlgLayout->setMargin( 11 );
107 /***************************************************************/
108 GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), this, "GroupC1" );
109 GroupC1->setColumnLayout(0, Qt::Vertical );
110 GroupC1->layout()->setSpacing( 0 );
111 GroupC1->layout()->setMargin( 0 );
112 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
113 GroupC1Layout->setAlignment( Qt::AlignTop );
114 GroupC1Layout->setSpacing( 6 );
115 GroupC1Layout->setMargin( 11 );
117 TextLabelC1A1 = new QLabel( tr( "SMESH_OBJECT_MESHorSUBMESH" ), GroupC1, "TextLabelC1A1" );
118 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
119 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
120 SelectButtonC1A1->setPixmap( image0 );
121 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
122 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
123 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
125 TextLabelC1A2 = new QLabel( tr( "SMESH_OBJECT_GEOM" ), GroupC1, "TextLabelC1A2" );
126 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
127 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
128 SelectButtonC1A2->setPixmap( image0 );
129 SelectButtonC1A2->setToggleButton( FALSE );
130 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
131 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
132 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
134 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupC1, 0, 0 );
136 /***************************************************************/
137 GroupHypotheses = new QGroupBox( tr( "SMESH_HYPOTHESES" ), this, "GroupHypotheses" );
138 GroupHypotheses->setColumnLayout(0, Qt::Vertical );
139 GroupHypotheses->layout()->setSpacing( 0 );
140 GroupHypotheses->layout()->setMargin( 0 );
141 QGridLayout* grid_3 = new QGridLayout( GroupHypotheses->layout() );
142 grid_3->setAlignment( Qt::AlignTop );
143 grid_3->setSpacing( 6 );
144 grid_3->setMargin( 11 );
146 TextHypDefinition = new QLabel( tr( "SMESH_AVAILABLE" ), GroupHypotheses, "TextHypDefinition" );
147 grid_3->addWidget( TextHypDefinition, 0, 0 );
149 ListHypDefinition = new QListBox( GroupHypotheses, "ListHypDefinition" );
150 ListHypDefinition->setMinimumSize( 100, 100 );
151 grid_3->addWidget( ListHypDefinition, 1, 0 );
153 TextHypAssignation = new QLabel( tr( "SMESH_EDIT_USED" ), GroupHypotheses, "TextHypAssignation" );
154 grid_3->addWidget( TextHypAssignation, 0, 1 );
156 ListHypAssignation = new QListBox( GroupHypotheses, "ListHypAssignation" );
157 ListHypAssignation->setMinimumSize( 100, 100 );
158 grid_3->addWidget( ListHypAssignation, 1, 1 );
160 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupHypotheses, 1, 0 );
162 /***************************************************************/
163 GroupAlgorithms = new QGroupBox( tr( "SMESH_ADD_ALGORITHM" ), this, "GroupAlgorithms" );
164 GroupAlgorithms->setColumnLayout(0, Qt::Vertical );
165 GroupAlgorithms->layout()->setSpacing( 0 );
166 GroupAlgorithms->layout()->setMargin( 0 );
167 QGridLayout* grid_4 = new QGridLayout( GroupAlgorithms->layout() );
168 grid_4->setAlignment( Qt::AlignTop );
169 grid_4->setSpacing( 6 );
170 grid_4->setMargin( 11 );
172 TextAlgoDefinition = new QLabel( tr( "SMESH_AVAILABLE" ), GroupAlgorithms, "TextAlgoDefinition" );
173 grid_4->addWidget( TextAlgoDefinition, 0, 0 );
175 ListAlgoDefinition = new QListBox( GroupAlgorithms, "ListAlgoDefinition" );
176 ListAlgoDefinition->setMinimumSize( 100, 100 );
177 grid_4->addWidget( ListAlgoDefinition, 1, 0 );
179 TextAlgoAssignation = new QLabel( tr( "SMESH_EDIT_USED" ), GroupAlgorithms, "TextAlgoAssignation" );
180 grid_4->addWidget( TextAlgoAssignation, 0, 1 );
182 ListAlgoAssignation = new QListBox( GroupAlgorithms, "ListAlgoAssignation" );
183 ListAlgoAssignation ->setMinimumSize( 100, 100 );
184 grid_4->addWidget( ListAlgoAssignation, 1, 1 );
186 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupAlgorithms, 2, 0 );
188 /***************************************************************/
189 GroupButtons = new QGroupBox( this, "GroupButtons" );
190 GroupButtons->setColumnLayout(0, Qt::Vertical );
191 GroupButtons->layout()->setSpacing( 0 );
192 GroupButtons->layout()->setMargin( 0 );
193 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
194 GroupButtonsLayout->setAlignment( Qt::AlignTop );
195 GroupButtonsLayout->setSpacing( 6 );
196 GroupButtonsLayout->setMargin( 11 );
198 buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons, "buttonOk" );
199 buttonOk->setAutoDefault( TRUE );
200 buttonOk->setDefault( FALSE );
201 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
203 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons, "buttonApply" );
204 buttonApply->setAutoDefault( TRUE );
205 buttonApply->setDefault( FALSE );
206 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
208 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
210 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons, "buttonCancel" );
211 buttonCancel->setAutoDefault( TRUE );
212 buttonCancel->setDefault( TRUE );
213 buttonCancel->setEnabled( TRUE ) ;
214 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
216 SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupButtons, 4, 0 );
218 /***************************************************************/
223 //=================================================================================
224 // function : ~SMESHGUI_EditHypothesesDlg()
225 // purpose : Destroys the object and frees any allocated resources
226 //=================================================================================
227 SMESHGUI_EditHypothesesDlg::~SMESHGUI_EditHypothesesDlg()
229 // no need to delete child widgets, Qt does it all for us
233 //=================================================================================
236 //=================================================================================
237 void SMESHGUI_EditHypothesesDlg::Init( SALOME_Selection* Sel )
240 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
241 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
244 InitAlgoDefinition();
246 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
247 myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
249 myGeomShape = GEOM::GEOM_Shape::_nil();
250 myMesh = SMESH::SMESH_Mesh::_nil();
251 mySubMesh = SMESH::SMESH_subMesh::_nil();
253 /* signals and slots connections */
254 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
255 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
256 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
258 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
259 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
261 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
262 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
263 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
265 connect( ListHypAssignation, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( removeItem(QListBoxItem*) ) );
266 connect( ListAlgoAssignation, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( removeItem(QListBoxItem*) ) );
268 connect( ListHypDefinition, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( addItem(QListBoxItem*) ) );
269 connect( ListAlgoDefinition, SIGNAL( doubleClicked(QListBoxItem*) ), this, SLOT( addItem(QListBoxItem*) ) );
272 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
276 LineEditC1A1->setFocus() ;
277 myEditCurrentArgument = LineEditC1A1;
278 mySelection->ClearFilters() ;
279 mySelection->AddFilter(myMeshOrSubMeshFilter) ;
281 SelectionIntoArgument();
283 UpdateControlState();
287 //=================================================================================
288 // function : ClickOnOk()
290 //=================================================================================
291 void SMESHGUI_EditHypothesesDlg::ClickOnOk()
293 if ( ClickOnApply() )
297 //=================================================================================
298 // function : ClickOnApply()
300 //=================================================================================
301 bool SMESHGUI_EditHypothesesDlg::ClickOnApply()
307 QAD_Operation* op = new QAD_Operation( mySMESHGUI->GetActiveStudy() );
312 if ( !myMesh->_is_nil() )
314 else if ( !mySubMesh->_is_nil() )
315 aRes = StoreSubMesh();
318 // commit transaction
328 //=================================================================================
329 // function : ClickOnCancel()
331 //=================================================================================
332 void SMESHGUI_EditHypothesesDlg::ClickOnCancel()
338 //=================================================================================
339 // function : SelectionIntoArgument()
340 // purpose : Called when selection as changed or other case
341 //=================================================================================
342 void SMESHGUI_EditHypothesesDlg::SelectionIntoArgument()
344 QString aString = "";
346 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
348 if ( myEditCurrentArgument == LineEditC1A1 ) {
350 myMesh = SMESH::SMESH_Mesh::_nil();
351 mySubMesh = SMESH::SMESH_subMesh::_nil();
354 Standard_Boolean testResult ;
355 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
356 myMesh = mySMESHGUI->ConvertIOinMesh(IO, testResult) ;
358 myMesh = SMESH::SMESH_Mesh::_nil();
359 mySubMesh = mySMESHGUI->ConvertIOinSubMesh(IO, testResult) ;
361 mySubMesh = SMESH::SMESH_subMesh::_nil();
366 myEditCurrentArgument->setText( aString );
368 myGeomShape = GEOM::GEOM_Shape::_nil(); // InitGeom() will try to retrieve a shape from myMesh or mySubMesh
371 myImportedMesh = myGeomShape->_is_nil();
373 InitHypAssignation();
374 InitAlgoAssignation();
376 else if ( myEditCurrentArgument == LineEditC1A2 ) {
378 myGeomShape = GEOM::GEOM_Shape::_nil();
380 Standard_Boolean testResult ;
381 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
382 myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
384 myGeomShape = GEOM::GEOM_Shape::_nil();
389 UpdateControlState();
393 //=================================================================================
394 // function : SetEditCurrentArgument()
396 //=================================================================================
397 void SMESHGUI_EditHypothesesDlg::SetEditCurrentArgument()
399 QPushButton* send = (QPushButton*)sender();
400 if(send == SelectButtonC1A1) {
401 LineEditC1A1->setFocus() ;
402 myEditCurrentArgument = LineEditC1A1;
403 mySelection->ClearFilters() ;
404 mySelection->AddFilter(myMeshOrSubMeshFilter) ;
405 } else if (send == SelectButtonC1A2) {
406 LineEditC1A2->setFocus() ;
407 myEditCurrentArgument = LineEditC1A2;
408 mySelection->ClearFilters() ;
409 mySelection->AddFilter(myGeomFilter) ;
411 SelectionIntoArgument() ;
414 //=================================================================================
415 // function : DeactivateActiveDialog()
417 //=================================================================================
418 void SMESHGUI_EditHypothesesDlg::DeactivateActiveDialog()
420 if ( GroupC1->isEnabled() ) {
421 disconnect( mySelection, 0, this, 0 );
422 GroupC1->setEnabled(false) ;
423 GroupButtons->setEnabled(false) ;
428 //=================================================================================
429 // function : ActivateThisDialog()
431 //=================================================================================
432 void SMESHGUI_EditHypothesesDlg::ActivateThisDialog()
434 mySMESHGUI->EmitSignalDeactivateDialog() ;
435 GroupC1->setEnabled(true) ;
436 GroupButtons->setEnabled(true) ;
437 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
441 //=================================================================================
442 // function : enterEvent()
444 //=================================================================================
445 void SMESHGUI_EditHypothesesDlg::enterEvent(QEvent* e)
447 if ( !GroupC1->isEnabled() )
448 ActivateThisDialog();
452 //=================================================================================
453 // function : closeEvent()
455 //=================================================================================
456 void SMESHGUI_EditHypothesesDlg::closeEvent( QCloseEvent* e )
458 disconnect( mySelection, 0, this, 0 );
459 mySMESHGUI->ResetState() ;
460 mySelection->ClearFilters() ;
461 QDialog::closeEvent( e );
465 //=================================================================================
466 // function : removeItem()
468 //=================================================================================
469 void SMESHGUI_EditHypothesesDlg::removeItem(QListBoxItem* item)
471 const QObject* aSender = sender();
475 if ( aSender == ListHypAssignation ) {
476 ListHypAssignation->removeItem( ListHypAssignation->index( item ) );
478 else if ( aSender == ListAlgoAssignation ) {
479 ListAlgoAssignation->removeItem( ListAlgoAssignation->index( item ) );
482 UpdateControlState();
486 //=================================================================================
487 // function : addItem()
489 //=================================================================================
490 void SMESHGUI_EditHypothesesDlg::addItem(QListBoxItem* item)
492 const QObject* aSender = sender();
497 if ( item->rtti() == ListBoxIOR::RTTI_IOR )
498 i = (ListBoxIOR*)item;
501 bool isFound = false;
503 if ( aSender == ListHypDefinition ) {
504 for ( int j = 0, n = ListHypAssignation->count(); !isFound && j < n; j++ ) {
505 if ( ListHypAssignation->item( j )->rtti() == ListBoxIOR::RTTI_IOR ) {
506 ListBoxIOR* anItem = (ListBoxIOR*)ListHypAssignation->item( j );
507 isFound = !strcmp( anItem->GetIOR(), i->GetIOR() );
511 ListBoxIOR* anItem = new ListBoxIOR( ListHypAssignation,
512 strdup( i->GetIOR() ),
513 strdup( i->text().latin1() ) );
515 else if ( aSender == ListAlgoDefinition ) {
516 for ( int j = 0, n = ListAlgoAssignation->count(); !isFound && j < n; j++ ) {
517 if ( ListAlgoAssignation->item( j )->rtti() == ListBoxIOR::RTTI_IOR ) {
518 ListBoxIOR* anItem = (ListBoxIOR*)ListAlgoAssignation->item( j );
519 isFound = !strcmp( anItem->GetIOR(), i->GetIOR() );
523 ListBoxIOR* anItem = new ListBoxIOR( ListAlgoAssignation,
524 strdup( i->GetIOR() ),
525 strdup( i->text().latin1() ) );
528 UpdateControlState();
532 //=================================================================================
533 // function : InitHypDefinition()
535 //=================================================================================
536 void SMESHGUI_EditHypothesesDlg::InitHypDefinition()
538 ListHypDefinition->clear();
540 SALOMEDS::SComponent_var father = mySMESHGUI->GetStudy()->FindComponent("MESH");
541 if ( father->_is_nil() )
544 SALOMEDS::SObject_var HypothesisRoot;
545 SALOMEDS::GenericAttribute_var anAttr;
546 SALOMEDS::AttributeName_var aName;
547 SALOMEDS::AttributeIOR_var anIOR;
549 int Tag_HypothesisRoot = 1;
550 if (father->FindSubObject (1, HypothesisRoot)) {
551 SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(HypothesisRoot);
552 for (; it->More();it->Next()) {
553 SALOMEDS::SObject_var Obj = it->Value();
554 if (Obj->FindAttribute(anAttr, "AttributeName") ) {
555 aName = SALOMEDS::AttributeName::_narrow(anAttr);
556 if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
557 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
558 ListBoxIOR* anItem = new ListBoxIOR( ListHypDefinition,
567 //=================================================================================
568 // function : InitHypAssignation()
570 //=================================================================================
571 void SMESHGUI_EditHypothesesDlg::InitHypAssignation()
573 MESSAGE ( " InitHypAssignation " << myMesh->_is_nil() )
574 MESSAGE ( " InitHypAssignation " << mySubMesh->_is_nil() )
576 myMapOldHypos.clear();
577 ListHypAssignation->clear();
578 if ( myImportedMesh )
581 SALOMEDS::SObject_var aMorSM, AHR, aRef;
582 SALOMEDS::GenericAttribute_var anAttr;
583 SALOMEDS::AttributeName_var aName;
584 SALOMEDS::AttributeIOR_var anIOR;
585 SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
587 if ( !myMesh->_is_nil() )
588 aMorSM = myStudyAPI.FindObject( myMesh );
589 else if ( !mySubMesh->_is_nil() )
590 aMorSM = myStudyAPI.FindObject( mySubMesh );
592 if ( !aMorSM->_is_nil() && aMorSM->FindSubObject (2, AHR)) {
593 SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AHR);
594 for (; it->More();it->Next()) {
595 SALOMEDS::SObject_var Obj = it->Value();
596 if ( Obj->ReferencedObject(aRef) ) {
597 if (aRef->FindAttribute(anAttr, "AttributeName") ) {
598 aName = SALOMEDS::AttributeName::_narrow(anAttr);
599 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
600 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
601 ListBoxIOR* anItem = new ListBoxIOR( ListHypAssignation,
604 myMapOldHypos[ anIOR->Value() ] = ListHypAssignation->index( anItem );
612 //=================================================================================
613 // function : InitAlgoDefinition()
615 //=================================================================================
616 void SMESHGUI_EditHypothesesDlg::InitAlgoDefinition()
618 ListAlgoDefinition->clear();
620 SALOMEDS::SComponent_var father = mySMESHGUI->GetStudy()->FindComponent("MESH");
621 if ( father->_is_nil() )
624 SALOMEDS::SObject_var AlgorithmsRoot;
625 SALOMEDS::GenericAttribute_var anAttr;
626 SALOMEDS::AttributeName_var aName;
627 SALOMEDS::AttributeIOR_var anIOR;
629 if (father->FindSubObject (2, AlgorithmsRoot)) {
630 SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AlgorithmsRoot);
631 for (; it->More();it->Next()) {
632 SALOMEDS::SObject_var Obj = it->Value();
633 if (Obj->FindAttribute(anAttr, "AttributeName") ) {
634 aName = SALOMEDS::AttributeName::_narrow(anAttr);
635 if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
636 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
637 ListBoxIOR* anItem = new ListBoxIOR( ListAlgoDefinition,
647 //=================================================================================
648 // function : InitAlgoAssignation()
650 //=================================================================================
651 void SMESHGUI_EditHypothesesDlg::InitAlgoAssignation()
653 MESSAGE ( " InitAlgoAssignation " << myMesh->_is_nil() )
654 MESSAGE ( " InitAlgoAssignation " << mySubMesh->_is_nil() )
656 myMapOldAlgos.clear();
657 ListAlgoAssignation->clear();
658 if ( myImportedMesh )
661 SALOMEDS::SObject_var aMorSM, AHR, aRef;
662 SALOMEDS::GenericAttribute_var anAttr;
663 SALOMEDS::AttributeName_var aName;
664 SALOMEDS::AttributeIOR_var anIOR;
665 SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
667 if ( !myMesh->_is_nil() )
668 aMorSM = myStudyAPI.FindObject( myMesh );
669 else if ( !mySubMesh->_is_nil() )
670 aMorSM = myStudyAPI.FindObject( mySubMesh );
672 if ( !aMorSM->_is_nil() && aMorSM->FindSubObject (3, AHR)) {
673 SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AHR);
674 for (; it->More();it->Next()) {
675 SALOMEDS::SObject_var Obj = it->Value();
676 if ( Obj->ReferencedObject(aRef) ) {
677 if (aRef->FindAttribute(anAttr, "AttributeName") ) {
678 aName = SALOMEDS::AttributeName::_narrow(anAttr);
679 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
680 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
681 ListBoxIOR* anItem = new ListBoxIOR( ListAlgoAssignation,
684 myMapOldAlgos[ anIOR->Value() ] = ListAlgoAssignation->index( anItem );
692 //=================================================================================
693 // function : InitGeom()
695 //=================================================================================
696 void SMESHGUI_EditHypothesesDlg::InitGeom()
698 LineEditC1A2->setText("") ;
699 SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
701 if ( myGeomShape->_is_nil() && !myMesh->_is_nil() ) {
702 SALOMEDS::SObject_var aMesh = myStudyAPI.FindObject( myMesh );
703 if ( !aMesh->_is_nil() )
704 myGeomShape = myStudyAPI.GetShapeOnMeshOrSubMesh(aMesh);
706 if ( myGeomShape->_is_nil() && !mySubMesh->_is_nil() ) {
707 SALOMEDS::SObject_var aSubMesh = myStudyAPI.FindObject( mySubMesh );
708 if ( !aSubMesh->_is_nil() )
709 myGeomShape = myStudyAPI.GetShapeOnMeshOrSubMesh(aSubMesh);
712 SALOMEDS::GenericAttribute_var anAttr;
713 SALOMEDS::AttributeName_var aName;
714 if ( !myGeomShape->_is_nil() && (!myMesh->_is_nil() || !mySubMesh->_is_nil()) ) {
715 SALOMEDS::SObject_var aSO = mySMESHGUI->GetStudy()->FindObjectIOR( myGeomShape->Name() );
716 if ( !aSO->_is_nil() ) {
717 if (aSO->FindAttribute(anAttr, "AttributeName") ) {
718 aName = SALOMEDS::AttributeName::_narrow(anAttr);
719 LineEditC1A2->setText( QString(aName->Value()) ) ;
725 //=================================================================================
726 // function : UpdateControlState()
728 //=================================================================================
729 void SMESHGUI_EditHypothesesDlg::UpdateControlState()
731 bool isEnabled = ( !myMesh ->_is_nil() && !myGeomShape->_is_nil() && ListHypAssignation->count() && ListAlgoAssignation->count() ) ||
732 ( !mySubMesh->_is_nil() && !myGeomShape->_is_nil() && ( ListHypAssignation->count() || ListAlgoAssignation->count() ) );
734 buttonOk ->setEnabled( isEnabled && !myImportedMesh );
735 buttonApply->setEnabled( isEnabled && !myImportedMesh );
737 SelectButtonC1A2 ->setEnabled( ALLOW_CHANGE_SHAPE && !myImportedMesh );
738 LineEditC1A2 ->setEnabled( ALLOW_CHANGE_SHAPE && !myImportedMesh );
739 ListHypDefinition ->setEnabled( !myImportedMesh );
740 ListHypAssignation ->setEnabled( !myImportedMesh );
741 ListAlgoDefinition ->setEnabled( !myImportedMesh );
742 ListAlgoAssignation->setEnabled( !myImportedMesh );
745 //=================================================================================
746 // function : StoreMesh()
748 //=================================================================================
749 bool SMESHGUI_EditHypothesesDlg::StoreMesh()
751 SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
752 MapIOR anOldHypos, aNewHypos;
753 if ( myGeomShape->_is_nil() )
755 // 1. Check whether the geometric shape has changed
756 SALOMEDS::SObject_var aMeshSO = myStudyAPI.FindObject( myMesh );
757 GEOM::GEOM_Shape_var aIniGeomShape = myStudyAPI.GetShapeOnMeshOrSubMesh( aMeshSO );
758 bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent( myGeomShape );
759 if ( bShapeChanged ) {
760 // VSR : TODO : Set new shape - not supported yet by SMESH engine
761 // 1) remove all old hypotheses and algorithms and also submeshes
765 // 2. remove not used hypotheses from the mesh
766 for ( it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it ) {
767 string ior = it->first;
768 int index = findItem( ListHypAssignation, ior );
770 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
771 if ( !CORBA::is_nil( anObject ) ) {
772 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
773 if ( !aHyp->_is_nil() )
774 if ( !mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh( aMeshSO, aHyp ) )
779 // 3. remove not used algorithms from the mesh
780 for ( it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it ) {
781 string ior = it->first;
782 int index = findItem( ListAlgoAssignation, ior );
784 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
785 if ( !CORBA::is_nil( anObject ) ) {
786 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
787 if ( !aHyp->_is_nil() )
788 if ( !mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh( aMeshSO, aHyp ) )
793 // 4. Add new hypotheses
794 for ( int i = 0; i < ListHypAssignation->count(); i++ ) {
795 if ( ListHypAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
796 ListBoxIOR* anItem = ( ListBoxIOR* )( ListHypAssignation->item( i ) );
798 string ior = anItem->GetIOR();
799 if ( myMapOldHypos.find( ior ) == myMapOldHypos.end() ) {
800 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
801 if ( !CORBA::is_nil( anObject ) ) {
802 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
803 if ( !aHyp->_is_nil() )
804 if ( !mySMESHGUI->AddHypothesisOnMesh( myMesh, aHyp ) )
811 // 4. Add new algorithms
812 for ( int i = 0; i < ListAlgoAssignation->count(); i++ ) {
813 if ( ListAlgoAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
814 ListBoxIOR* anItem = ( ListBoxIOR* )( ListAlgoAssignation->item( i ) );
816 string ior = anItem->GetIOR();
817 if ( myMapOldAlgos.find( ior ) == myMapOldAlgos.end() ) {
818 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
819 if ( !CORBA::is_nil( anObject ) ) {
820 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
821 if ( !aHyp->_is_nil() )
822 if ( !mySMESHGUI->AddAlgorithmOnMesh( myMesh, aHyp ) )
832 //=================================================================================
833 // function : StoreSubMesh()
835 //=================================================================================
836 bool SMESHGUI_EditHypothesesDlg::StoreSubMesh()
838 SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
839 MapIOR anOldHypos, aNewHypos;
840 if ( myGeomShape->_is_nil() )
842 // 1. Check whether the geometric shape has changed
843 SALOMEDS::SObject_var aSubMeshSO = myStudyAPI.FindObject( mySubMesh );
844 GEOM::GEOM_Shape_var aIniGeomShape = myStudyAPI.GetShapeOnMeshOrSubMesh( aSubMeshSO );
845 bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent( myGeomShape );
846 if ( bShapeChanged ) {
847 // VSR : TODO : Set new shape - not supported yet by engine
848 // 1) remove all old hypotheses and algorithms
852 // 2. remove not used hypotheses from the submesh
853 for ( it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it ) {
854 string ior = it->first;
855 int index = findItem( ListHypAssignation, ior );
857 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
858 if ( !CORBA::is_nil( anObject ) ) {
859 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
860 if ( !aHyp->_is_nil() )
861 if ( !mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh( aSubMeshSO, aHyp ) )
866 // 3. remove not used algorithms from the submesh
867 for ( it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it ) {
868 string ior = it->first;
869 int index = findItem( ListAlgoAssignation, ior );
871 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
872 if ( !CORBA::is_nil( anObject ) ) {
873 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
874 if ( !aHyp->_is_nil() )
875 if ( !mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh( aSubMeshSO, aHyp ) )
880 // 4. Add new hypotheses
881 for ( int i = 0; i < ListHypAssignation->count(); i++ ) {
882 if ( ListHypAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
883 ListBoxIOR* anItem = ( ListBoxIOR* )( ListHypAssignation->item( i ) );
885 string ior = anItem->GetIOR();
886 if ( myMapOldHypos.find( ior ) == myMapOldHypos.end() ) {
887 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
888 if ( !CORBA::is_nil( anObject ) ) {
889 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
890 if ( !aHyp->_is_nil() )
891 if ( !mySMESHGUI->AddHypothesisOnSubMesh( mySubMesh, aHyp ) )
898 // 4. Add new algorithms
899 for ( int i = 0; i < ListAlgoAssignation->count(); i++ ) {
900 if ( ListAlgoAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
901 ListBoxIOR* anItem = ( ListBoxIOR* )( ListAlgoAssignation->item( i ) );
903 string ior = anItem->GetIOR();
904 if ( myMapOldAlgos.find( ior ) == myMapOldAlgos.end() ) {
905 CORBA::Object_var anObject = myStudyAPI.StringToIOR( ior.c_str() );
906 if ( !CORBA::is_nil( anObject ) ) {
907 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
908 if ( !aHyp->_is_nil() )
909 if ( !mySMESHGUI->AddAlgorithmOnSubMesh( mySubMesh, aHyp ) )