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 "SMESH_TypeFilter.hxx"
37 #include "SMESH_NumberFilter.hxx"
39 #include "SALOME_ListIO.hxx"
40 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "SALOMEDSClient_Study.hxx"
43 #include "SALOMEDSClient_AttributeIOR.hxx"
44 #include "SALOMEDSClient_AttributeName.hxx"
46 #include "SUIT_Session.h"
47 #include "SUIT_OverrideCursor.h"
48 #include "SUIT_Operation.h"
49 #include "SUIT_Desktop.h"
51 #include "utilities.h"
53 #include "SVTK_ViewModel.h"
56 #include <qgroupbox.h>
58 #include <qlineedit.h>
59 #include <qpushbutton.h>
65 //VRV: porting on Qt 3.0.5
66 #if QT_VERSION >= 0x030005
69 //VRV: porting on Qt 3.0.5
71 class ListBoxIOR : public QListBoxText
74 enum { RTTI_IOR = 1000 };
77 ListBoxIOR (QListBox* listbox,
79 const QString& text = QString::null)
80 : QListBoxText(listbox, text), myIOR(ior) {}
81 virtual ~ListBoxIOR() {};
82 virtual int rtti() const { return RTTI_IOR; }
83 const char* GetIOR() { return myIOR.c_str(); }
89 #define ALLOW_CHANGE_SHAPE 0
91 int findItem (QListBox* listBox, const string& ior)
93 for (int i = 0; i < listBox->count(); i++) {
94 if (listBox->item(i)->rtti() == ListBoxIOR::RTTI_IOR) {
95 ListBoxIOR* anItem = (ListBoxIOR*)(listBox->item(i));
96 if (anItem && ior == string(anItem->GetIOR()))
103 //=================================================================================
104 // function : SMESHGUI_EditHypothesesDlg()
105 // purpose : Constructs a SMESHGUI_EditHypothesesDlg which is a child of 'parent', with the
106 // name 'name' and widget flags set to 'f'.
107 // The dialog will by default be modeless, unless you set 'modal' to
108 // TRUE to construct a modal dialog.
109 //=================================================================================
110 SMESHGUI_EditHypothesesDlg::SMESHGUI_EditHypothesesDlg (SMESHGUI* theModule, const char* name,
111 bool modal, WFlags fl)
112 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
113 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
114 myImportedMesh(false),
115 mySMESHGUI( theModule ),
116 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
118 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
120 setName("SMESHGUI_EditHypothesesDlg");
121 setCaption(tr("SMESH_EDIT_HYPOTHESES"));
122 setSizeGripEnabled(TRUE);
123 QGridLayout* SMESHGUI_EditHypothesesDlgLayout = new QGridLayout(this);
124 SMESHGUI_EditHypothesesDlgLayout->setSpacing(6);
125 SMESHGUI_EditHypothesesDlgLayout->setMargin(11);
127 /***************************************************************/
128 GroupC1 = new QGroupBox(tr("SMESH_ARGUMENTS"), this, "GroupC1");
129 GroupC1->setColumnLayout(0, Qt::Vertical);
130 GroupC1->layout()->setSpacing(0);
131 GroupC1->layout()->setMargin(0);
132 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
133 GroupC1Layout->setAlignment(Qt::AlignTop);
134 GroupC1Layout->setSpacing(6);
135 GroupC1Layout->setMargin(11);
137 TextLabelC1A1 = new QLabel(tr("SMESH_OBJECT_MESHorSUBMESH"), GroupC1, "TextLabelC1A1");
138 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
139 SelectButtonC1A1 = new QPushButton(GroupC1, "SelectButtonC1A1");
140 SelectButtonC1A1->setPixmap(image0);
141 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
142 LineEditC1A1 = new QLineEdit(GroupC1, "LineEditC1A1");
143 LineEditC1A1->setReadOnly(true);
144 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
146 TextLabelC1A2 = new QLabel(tr("SMESH_OBJECT_GEOM"), GroupC1, "TextLabelC1A2");
147 GroupC1Layout->addWidget(TextLabelC1A2, 1, 0);
148 SelectButtonC1A2 = new QPushButton(GroupC1, "SelectButtonC1A2");
149 SelectButtonC1A2->setPixmap(image0);
150 SelectButtonC1A2->setToggleButton(FALSE);
151 GroupC1Layout->addWidget(SelectButtonC1A2, 1, 1);
152 LineEditC1A2 = new QLineEdit(GroupC1, "LineEditC1A2");
153 LineEditC1A2->setReadOnly(true);
154 GroupC1Layout->addWidget(LineEditC1A2, 1, 2);
156 SMESHGUI_EditHypothesesDlgLayout->addWidget(GroupC1, 0, 0);
158 /***************************************************************/
159 GroupHypotheses = new QGroupBox(tr("SMESH_HYPOTHESES"), this, "GroupHypotheses");
160 GroupHypotheses->setColumnLayout(0, Qt::Vertical);
161 GroupHypotheses->layout()->setSpacing(0);
162 GroupHypotheses->layout()->setMargin(0);
163 QGridLayout* grid_3 = new QGridLayout(GroupHypotheses->layout());
164 grid_3->setAlignment(Qt::AlignTop);
165 grid_3->setSpacing(6);
166 grid_3->setMargin(11);
168 TextHypDefinition = new QLabel(tr("SMESH_AVAILABLE"), GroupHypotheses, "TextHypDefinition");
169 grid_3->addWidget(TextHypDefinition, 0, 0);
171 ListHypDefinition = new QListBox(GroupHypotheses, "ListHypDefinition");
172 ListHypDefinition->setMinimumSize(100, 100);
173 grid_3->addWidget(ListHypDefinition, 1, 0);
175 TextHypAssignation = new QLabel(tr("SMESH_EDIT_USED"), GroupHypotheses, "TextHypAssignation");
176 grid_3->addWidget(TextHypAssignation, 0, 1);
178 ListHypAssignation = new QListBox(GroupHypotheses, "ListHypAssignation");
179 ListHypAssignation->setMinimumSize(100, 100);
180 grid_3->addWidget(ListHypAssignation, 1, 1);
182 SMESHGUI_EditHypothesesDlgLayout->addWidget(GroupHypotheses, 1, 0);
184 /***************************************************************/
185 GroupAlgorithms = new QGroupBox(tr("SMESH_ADD_ALGORITHM"), this, "GroupAlgorithms");
186 GroupAlgorithms->setColumnLayout(0, Qt::Vertical);
187 GroupAlgorithms->layout()->setSpacing(0);
188 GroupAlgorithms->layout()->setMargin(0);
189 QGridLayout* grid_4 = new QGridLayout(GroupAlgorithms->layout());
190 grid_4->setAlignment(Qt::AlignTop);
191 grid_4->setSpacing(6);
192 grid_4->setMargin(11);
194 TextAlgoDefinition = new QLabel(tr("SMESH_AVAILABLE"), GroupAlgorithms, "TextAlgoDefinition");
195 grid_4->addWidget(TextAlgoDefinition, 0, 0);
197 ListAlgoDefinition = new QListBox(GroupAlgorithms, "ListAlgoDefinition");
198 ListAlgoDefinition->setMinimumSize(100, 100);
199 grid_4->addWidget(ListAlgoDefinition, 1, 0);
201 TextAlgoAssignation = new QLabel(tr("SMESH_EDIT_USED"), GroupAlgorithms, "TextAlgoAssignation");
202 grid_4->addWidget(TextAlgoAssignation, 0, 1);
204 ListAlgoAssignation = new QListBox(GroupAlgorithms, "ListAlgoAssignation");
205 ListAlgoAssignation ->setMinimumSize(100, 100);
206 grid_4->addWidget(ListAlgoAssignation, 1, 1);
208 SMESHGUI_EditHypothesesDlgLayout->addWidget(GroupAlgorithms, 2, 0);
210 /***************************************************************/
211 GroupButtons = new QGroupBox(this, "GroupButtons");
212 GroupButtons->setColumnLayout(0, Qt::Vertical);
213 GroupButtons->layout()->setSpacing(0);
214 GroupButtons->layout()->setMargin(0);
215 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
216 GroupButtonsLayout->setAlignment(Qt::AlignTop);
217 GroupButtonsLayout->setSpacing(6);
218 GroupButtonsLayout->setMargin(11);
220 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons, "buttonOk");
221 buttonOk->setAutoDefault(TRUE);
222 buttonOk->setDefault(FALSE);
223 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
225 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons, "buttonApply");
226 buttonApply->setAutoDefault(TRUE);
227 buttonApply->setDefault(FALSE);
228 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
230 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
232 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons, "buttonCancel");
233 buttonCancel->setAutoDefault(TRUE);
234 buttonCancel->setDefault(TRUE);
235 buttonCancel->setEnabled(TRUE);
236 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
238 SMESHGUI_EditHypothesesDlgLayout->addWidget(GroupButtons, 4, 0);
240 /***************************************************************/
244 //=================================================================================
245 // function : ~SMESHGUI_EditHypothesesDlg()
246 // purpose : Destroys the object and frees any allocated resources
247 //=================================================================================
248 SMESHGUI_EditHypothesesDlg::~SMESHGUI_EditHypothesesDlg()
250 // no need to delete child widgets, Qt does it all for us
253 //=================================================================================
256 //=================================================================================
257 void SMESHGUI_EditHypothesesDlg::Init()
259 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
262 InitAlgoDefinition();
264 //myGeomFilter = new SALOME_TypeFilter ("GEOM");
265 TColStd_MapOfInteger allTypesMap;
266 for (int i = 0; i < 10; i++)
268 myGeomFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 0, allTypesMap);
269 myMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
271 myGeomShape = GEOM::GEOM_Object::_nil();
272 myMesh = SMESH::SMESH_Mesh::_nil();
273 mySubMesh = SMESH::SMESH_subMesh::_nil();
275 /* signals and slots connections */
276 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
277 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
278 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
280 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
281 connect(SelectButtonC1A2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
283 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
284 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
285 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
287 connect(ListHypAssignation, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(removeItem(QListBoxItem*)));
288 connect(ListAlgoAssignation, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(removeItem(QListBoxItem*)));
290 connect(ListHypDefinition, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(addItem(QListBoxItem*)));
291 connect(ListAlgoDefinition, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(addItem(QListBoxItem*)));
294 mySMESHGUI->DefineDlgPosition(this, x, y);
298 LineEditC1A1->setFocus();
299 myEditCurrentArgument = LineEditC1A1;
300 mySelectionMgr->clearFilters();
301 mySelectionMgr->installFilter(myMeshOrSubMeshFilter);
303 SelectionIntoArgument();
305 UpdateControlState();
308 //=================================================================================
309 // function : ClickOnOk()
311 //=================================================================================
312 void SMESHGUI_EditHypothesesDlg::ClickOnOk()
318 //=================================================================================
319 // function : ClickOnApply()
321 //=================================================================================
322 bool SMESHGUI_EditHypothesesDlg::ClickOnApply()
324 if (mySMESHGUI->isActiveStudyLocked())
329 SUIT_OverrideCursor wc;
331 SUIT_Operation* op = new SUIT_Operation
332 (SUIT_Session::session()->activeApplication());
337 if (!myMesh->_is_nil())
339 else if (!mySubMesh->_is_nil())
340 aRes = StoreSubMesh();
342 if (true/*aRes*/) { // abort desynchronizes contents of a Study and a mesh on server
343 // commit transaction
345 InitHypAssignation();
346 InitAlgoAssignation();
352 UpdateControlState();
353 mySMESHGUI->updateObjBrowser();
358 //=================================================================================
359 // function : ClickOnCancel()
361 //=================================================================================
362 void SMESHGUI_EditHypothesesDlg::ClickOnCancel()
367 //=================================================================================
368 // function : SelectionIntoArgument()
369 // purpose : Called when selection as changed or other case
370 //=================================================================================
371 void SMESHGUI_EditHypothesesDlg::SelectionIntoArgument()
373 QString aString = "";
376 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
378 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
380 if (myEditCurrentArgument == LineEditC1A1) {
382 myMesh = SMESH::SMESH_Mesh::_nil();
383 mySubMesh = SMESH::SMESH_subMesh::_nil();
386 Handle(SALOME_InteractiveObject) IO = aList.First();
387 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
388 if (myMesh->_is_nil()) {
389 mySubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
390 if (mySubMesh->_is_nil()) {
395 myEditCurrentArgument->setText(aString);
397 // InitGeom() will try to retrieve a shape from myMesh or mySubMesh
398 myGeomShape = GEOM::GEOM_Object::_nil();
401 myImportedMesh = myGeomShape->_is_nil();
403 InitHypAssignation();
404 InitAlgoAssignation();
406 } else if (myEditCurrentArgument == LineEditC1A2) {
408 myGeomShape = GEOM::GEOM_Object::_nil();
410 Handle(SALOME_InteractiveObject) IO = aList.First();
411 myGeomShape = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
416 UpdateControlState();
419 //=================================================================================
420 // function : SetEditCurrentArgument()
422 //=================================================================================
423 void SMESHGUI_EditHypothesesDlg::SetEditCurrentArgument()
425 QPushButton* send = (QPushButton*)sender();
426 if(send == SelectButtonC1A1) {
427 LineEditC1A1->setFocus();
428 myEditCurrentArgument = LineEditC1A1;
429 mySelectionMgr->clearFilters();
430 mySelectionMgr->installFilter(myMeshOrSubMeshFilter);
431 } else if (send == SelectButtonC1A2) {
432 LineEditC1A2->setFocus();
433 myEditCurrentArgument = LineEditC1A2;
434 mySelectionMgr->clearFilters();
435 mySelectionMgr->installFilter(myGeomFilter);
437 SelectionIntoArgument();
440 //=================================================================================
441 // function : DeactivateActiveDialog()
443 //=================================================================================
444 void SMESHGUI_EditHypothesesDlg::DeactivateActiveDialog()
446 if (GroupC1->isEnabled()) {
447 disconnect(mySelectionMgr, 0, this, 0);
448 GroupC1->setEnabled(false);
449 GroupButtons->setEnabled(false);
453 //=================================================================================
454 // function : ActivateThisDialog()
456 //=================================================================================
457 void SMESHGUI_EditHypothesesDlg::ActivateThisDialog()
459 mySMESHGUI->EmitSignalDeactivateDialog();
460 GroupC1->setEnabled(true);
461 GroupButtons->setEnabled(true);
462 connect (mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
465 //=================================================================================
466 // function : enterEvent()
468 //=================================================================================
469 void SMESHGUI_EditHypothesesDlg::enterEvent (QEvent*)
471 if (!GroupC1->isEnabled())
472 ActivateThisDialog();
475 //=================================================================================
476 // function : closeEvent()
478 //=================================================================================
479 void SMESHGUI_EditHypothesesDlg::closeEvent (QCloseEvent* e)
481 disconnect(mySelectionMgr, 0, this, 0);
482 mySMESHGUI->ResetState();
483 mySelectionMgr->clearFilters();
484 QDialog::closeEvent(e);
487 //=======================================================================
488 // function : IsOld()
490 //=======================================================================
491 bool SMESHGUI_EditHypothesesDlg::IsOld (QListBoxItem* hypItem)
493 if (hypItem->rtti() == ListBoxIOR::RTTI_IOR) {
494 ListBoxIOR* hyp = (ListBoxIOR*) hypItem;
495 return (myMapOldHypos.find(hyp->GetIOR()) != myMapOldHypos.end() ||
496 myMapOldAlgos.find(hyp->GetIOR()) != myMapOldAlgos.end());
502 //=================================================================================
503 // function : removeItem()
505 //=================================================================================
506 void SMESHGUI_EditHypothesesDlg::removeItem (QListBoxItem* item)
508 const QObject* aSender = sender();
512 if (aSender == ListHypAssignation) {
513 myNbModification += IsOld(item) ? 1 : -1;
514 ListHypAssignation->removeItem(ListHypAssignation->index(item));
516 else if (aSender == ListAlgoAssignation) {
517 myNbModification += IsOld(item) ? 1 : -1;
518 ListAlgoAssignation->removeItem(ListAlgoAssignation->index(item));
521 UpdateControlState();
524 //=================================================================================
525 // function : addItem()
527 //=================================================================================
528 void SMESHGUI_EditHypothesesDlg::addItem (QListBoxItem* item)
530 const QObject* aSender = sender();
535 if (item->rtti() == ListBoxIOR::RTTI_IOR)
536 i = (ListBoxIOR*)item;
539 bool isFound = false;
542 if (aSender == ListHypDefinition) {
543 for (int j = 0, n = ListHypAssignation->count(); !isFound && j < n; j++) {
544 if (ListHypAssignation->item(j)->rtti() == ListBoxIOR::RTTI_IOR) {
545 anItem = (ListBoxIOR*)ListHypAssignation->item(j);
546 isFound = !strcmp(anItem->GetIOR(), i->GetIOR());
550 anItem = new ListBoxIOR (ListHypAssignation,
551 CORBA::string_dup(i->GetIOR()),
552 CORBA::string_dup(i->text().latin1()));
554 } else if (aSender == ListAlgoDefinition) {
555 for (int j = 0, n = ListAlgoAssignation->count(); !isFound && j < n; j++) {
556 if (ListAlgoAssignation->item(j)->rtti() == ListBoxIOR::RTTI_IOR) {
557 anItem = (ListBoxIOR*)ListAlgoAssignation->item(j);
558 isFound = !strcmp(anItem->GetIOR(), i->GetIOR());
562 anItem = new ListBoxIOR (ListAlgoAssignation,
563 CORBA::string_dup(i->GetIOR()),
564 CORBA::string_dup(i->text().latin1()));
569 myNbModification += IsOld(item) ? -1 : 1;
571 UpdateControlState();
574 //=================================================================================
575 // function : InitHypDefinition()
577 //=================================================================================
578 void SMESHGUI_EditHypothesesDlg::InitHypDefinition()
580 ListHypDefinition->clear();
582 _PTR(SComponent) father = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
586 _PTR(SObject) HypothesisRoot;
587 _PTR(GenericAttribute) anAttr;
588 _PTR(AttributeName) aName;
589 _PTR(AttributeIOR) anIOR;
591 //int Tag_HypothesisRoot = 1;
592 if (father->FindSubObject(1, HypothesisRoot)) {
593 _PTR(ChildIterator) it =
594 SMESH::GetActiveStudyDocument()->NewChildIterator(HypothesisRoot);
596 for (; it->More();it->Next()) {
597 _PTR(SObject) Obj = it->Value();
598 if (Obj->FindAttribute(anAttr, "AttributeName")) {
600 if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
602 anItem = new ListBoxIOR (ListHypDefinition,
603 anIOR->Value().c_str(),
604 aName->Value().c_str());
611 //=================================================================================
612 // function : InitHypAssignation()
614 //=================================================================================
615 void SMESHGUI_EditHypothesesDlg::InitHypAssignation()
617 myNbModification = 0;
619 myMapOldHypos.clear();
620 ListHypAssignation->clear();
624 _PTR(SObject) aMorSM, AHR, aRef;
625 _PTR(GenericAttribute) anAttr;
626 _PTR(AttributeName) aName;
627 _PTR(AttributeIOR) anIOR;
629 if (!myMesh->_is_nil())
630 aMorSM = SMESH::FindSObject(myMesh);
631 else if (!mySubMesh->_is_nil())
632 aMorSM = SMESH::FindSObject(mySubMesh);
634 if (aMorSM && aMorSM->FindSubObject(2, AHR)) {
635 _PTR(ChildIterator) it =
636 SMESH::GetActiveStudyDocument()->NewChildIterator(AHR);
637 for (; it->More();it->Next()) {
638 _PTR(SObject) Obj = it->Value();
639 if (Obj->ReferencedObject(aRef)) {
640 if (aRef->FindAttribute(anAttr, "AttributeName")) {
642 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
644 ListBoxIOR* anItem = new ListBoxIOR (ListHypAssignation,
645 anIOR->Value().c_str(),
646 aName->Value().c_str());
647 myMapOldHypos[ anIOR->Value() ] = ListHypAssignation->index(anItem);
655 //=================================================================================
656 // function : InitAlgoDefinition()
658 //=================================================================================
659 void SMESHGUI_EditHypothesesDlg::InitAlgoDefinition()
661 ListAlgoDefinition->clear();
663 _PTR(SComponent) father = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
667 _PTR(SObject) AlgorithmsRoot;
668 _PTR(GenericAttribute) anAttr;
669 _PTR(AttributeName) aName;
670 _PTR(AttributeIOR) anIOR;
672 if (father->FindSubObject (2, AlgorithmsRoot)) {
673 _PTR(ChildIterator) it =
674 SMESH::GetActiveStudyDocument()->NewChildIterator(AlgorithmsRoot);
676 for (; it->More();it->Next()) {
677 _PTR(SObject) Obj = it->Value();
678 if (Obj->FindAttribute(anAttr, "AttributeName")) {
680 if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
682 anItem = new ListBoxIOR (ListAlgoDefinition,
683 anIOR->Value().c_str(),
684 aName->Value().c_str());
691 //=================================================================================
692 // function : InitAlgoAssignation()
694 //=================================================================================
695 void SMESHGUI_EditHypothesesDlg::InitAlgoAssignation()
697 myMapOldAlgos.clear();
698 ListAlgoAssignation->clear();
702 _PTR(SObject) aMorSM, AHR, aRef;
703 _PTR(GenericAttribute) anAttr;
704 _PTR(AttributeName) aName;
705 _PTR(AttributeIOR) anIOR;
707 if (!myMesh->_is_nil())
708 aMorSM = SMESH::FindSObject(myMesh);
709 else if (!mySubMesh->_is_nil())
710 aMorSM = SMESH::FindSObject(mySubMesh);
712 if (aMorSM && aMorSM->FindSubObject(3, AHR)) {
713 _PTR(ChildIterator) it =
714 SMESH::GetActiveStudyDocument()->NewChildIterator(AHR);
715 for (; it->More();it->Next()) {
716 _PTR(SObject) Obj = it->Value();
717 if (Obj->ReferencedObject(aRef)) {
718 if (aRef->FindAttribute(anAttr, "AttributeName")) {
720 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
722 ListBoxIOR* anItem = new ListBoxIOR (ListAlgoAssignation,
723 anIOR->Value().c_str(),
724 aName->Value().c_str());
725 myMapOldAlgos[ anIOR->Value() ] = ListAlgoAssignation->index(anItem);
733 //=================================================================================
734 // function : InitGeom()
736 //=================================================================================
737 void SMESHGUI_EditHypothesesDlg::InitGeom()
739 LineEditC1A2->setText("");
741 if (myGeomShape->_is_nil() && !myMesh->_is_nil()) {
742 _PTR(SObject) aMesh = SMESH::FindSObject(myMesh);
744 myGeomShape = SMESH::GetShapeOnMeshOrSubMesh(aMesh);
746 if (myGeomShape->_is_nil() && !mySubMesh->_is_nil()) {
747 _PTR(SObject) aSubMesh = SMESH::FindSObject(mySubMesh);
749 myGeomShape = SMESH::GetShapeOnMeshOrSubMesh(aSubMesh);
752 _PTR(GenericAttribute) anAttr;
753 _PTR(AttributeName) aName;
754 if (!myGeomShape->_is_nil() && (!myMesh->_is_nil() || !mySubMesh->_is_nil())) {
755 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
756 //_PTR(SObject) aSO = aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomShape));
757 _PTR(SObject) aSO = aStudy->FindObjectID(myGeomShape->GetStudyEntry());
759 if (aSO->FindAttribute(anAttr, "AttributeName")) {
761 LineEditC1A2->setText(QString(aName->Value().c_str()));
767 //=================================================================================
768 // function : UpdateControlState()
770 //=================================================================================
771 void SMESHGUI_EditHypothesesDlg::UpdateControlState()
773 // asl the check of "count" is commented because of PAL9787
774 bool isEnabled = (!myMesh->_is_nil() && !myGeomShape->_is_nil() /*&&
775 ListHypAssignation->count() && ListAlgoAssignation->count()*/ )
777 (!mySubMesh->_is_nil() && !myGeomShape->_is_nil() /*&&
778 (ListHypAssignation->count() || ListAlgoAssignation->count())*/);
780 buttonOk ->setEnabled(myNbModification && isEnabled && !myImportedMesh);
781 buttonApply->setEnabled(myNbModification && isEnabled && !myImportedMesh);
783 SelectButtonC1A2 ->setEnabled(ALLOW_CHANGE_SHAPE && !myImportedMesh);
784 LineEditC1A2 ->setEnabled(ALLOW_CHANGE_SHAPE && !myImportedMesh);
785 ListHypDefinition ->setEnabled(!myImportedMesh);
786 ListHypAssignation ->setEnabled(!myImportedMesh);
787 ListAlgoDefinition ->setEnabled(!myImportedMesh);
788 ListAlgoAssignation->setEnabled(!myImportedMesh);
791 //=================================================================================
792 // function : StoreMesh()
794 //=================================================================================
795 bool SMESHGUI_EditHypothesesDlg::StoreMesh()
797 MapIOR anOldHypos, aNewHypos;
798 if (myGeomShape->_is_nil())
801 // 1. Check whether the geometric shape has changed
802 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
803 GEOM::GEOM_Object_var aIniGeomShape = SMESH::GetShapeOnMeshOrSubMesh(aMeshSO);
804 bool bShapeChanged = aIniGeomShape->_is_nil() ||
805 !aIniGeomShape->_is_equivalent(myGeomShape);
807 // VSR : TODO : Set new shape - not supported yet by SMESH engine
808 // 1. remove all old hypotheses and algorithms and also submeshes
815 // 2. remove not used hypotheses from the mesh
816 for (it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it) {
817 string ior = it->first;
818 int index = findItem(ListHypAssignation, ior);
820 SMESH::SMESH_Hypothesis_var aHyp =
821 SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
822 if (!aHyp->_is_nil()) {
823 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh(aMeshSO, aHyp))
829 // 3. remove not used algorithms from the mesh
830 for (it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it) {
831 string ior = it->first;
832 int index = findItem(ListAlgoAssignation, ior);
834 SMESH::SMESH_Hypothesis_var aHyp =
835 SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
836 if (!aHyp->_is_nil()) {
837 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh(aMeshSO, aHyp))
843 // 4. Add new algorithms
844 for (int i = 0; i < ListAlgoAssignation->count(); i++) {
845 if (ListAlgoAssignation->item(i)->rtti() == ListBoxIOR::RTTI_IOR) {
846 ListBoxIOR* anItem = (ListBoxIOR*)(ListAlgoAssignation->item(i));
848 string ior = anItem->GetIOR();
849 if (myMapOldAlgos.find(ior) == myMapOldAlgos.end()) {
850 SMESH::SMESH_Hypothesis_var aHyp =
851 SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
852 if (!aHyp->_is_nil()) {
853 if (!SMESH::AddHypothesisOnMesh(myMesh, aHyp))
861 // 5. Add new hypotheses
862 for (int i = 0; i < ListHypAssignation->count(); i++) {
863 if (ListHypAssignation->item(i)->rtti() == ListBoxIOR::RTTI_IOR) {
864 ListBoxIOR* anItem = (ListBoxIOR*)(ListHypAssignation->item(i));
866 string ior = anItem->GetIOR();
867 if (myMapOldHypos.find(ior) == myMapOldHypos.end()) {
868 SMESH::SMESH_Hypothesis_var aHyp =
869 SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
870 if (!aHyp->_is_nil()) {
871 if (!SMESH::AddHypothesisOnMesh(myMesh, aHyp))
878 return (nbFail == 0);
881 //=================================================================================
882 // function : StoreSubMesh()
884 //=================================================================================
885 bool SMESHGUI_EditHypothesesDlg::StoreSubMesh()
887 MapIOR anOldHypos, aNewHypos;
888 if (myGeomShape->_is_nil())
891 // 1. Check whether the geometric shape has changed
892 _PTR(SObject) aSubMeshSO = SMESH::FindSObject(mySubMesh);
893 GEOM::GEOM_Object_var aIniGeomShape = SMESH::GetShapeOnMeshOrSubMesh(aSubMeshSO);
894 bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent(myGeomShape);
896 // VSR : TODO : Set new shape - not supported yet by engine
897 // 1. remove all old hypotheses and algorithms
903 // 2. remove not used hypotheses from the submesh
904 for (it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it) {
905 string ior = it->first;
906 int index = findItem(ListHypAssignation, ior);
908 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
909 if (!aHyp->_is_nil()) {
910 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh(aSubMeshSO, aHyp))
916 // 3. remove not used algorithms from the submesh
917 for (it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it) {
918 string ior = it->first;
919 int index = findItem(ListAlgoAssignation, ior);
921 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
922 if (!aHyp->_is_nil()){
923 if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh(aSubMeshSO, aHyp))
929 // 4. Add new algorithms
930 for (int i = 0; i < ListAlgoAssignation->count(); i++) {
931 if (ListAlgoAssignation->item(i)->rtti() == ListBoxIOR::RTTI_IOR) {
932 ListBoxIOR* anItem = (ListBoxIOR*)(ListAlgoAssignation->item(i));
934 string ior = anItem->GetIOR();
935 if (myMapOldAlgos.find(ior) == myMapOldAlgos.end()) {
936 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
937 if (!aHyp->_is_nil()){
938 if (!SMESH::AddHypothesisOnSubMesh(mySubMesh, aHyp))
946 // 5. Add new hypotheses
947 for (int i = 0; i < ListHypAssignation->count(); i++) {
948 if (ListHypAssignation->item(i)->rtti() == ListBoxIOR::RTTI_IOR) {
949 ListBoxIOR* anItem = (ListBoxIOR*)(ListHypAssignation->item(i));
951 string ior = anItem->GetIOR();
952 if (myMapOldHypos.find(ior) == myMapOldHypos.end()) {
953 SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
954 if (!aHyp->_is_nil()){
955 if (!SMESH::AddHypothesisOnSubMesh(mySubMesh, aHyp))
962 return (nbFail == 0);