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"
33 #include <qgroupbox.h>
36 #include <SALOMEconfig.h>
37 #include CORBA_SERVER_HEADER(SMESH_Gen)
39 //=================================================================================
40 // function : SMESHGUI_EditHypothesesDlg()
41 // purpose : Constructs a SMESHGUI_EditHypothesesDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 SMESHGUI_EditHypothesesDlg::SMESHGUI_EditHypothesesDlg()
47 : SMESHGUI_Dialog( false, true )
49 setName("SMESHGUI_EditHypothesesDlg");
50 setCaption(tr("SMESH_EDIT_HYPOTHESES"));
52 QVBoxLayout* main = new QVBoxLayout( mainFrame(), 0, 5 );
54 /***************************************************************/
55 QGroupBox* GroupC1 = new QGroupBox(tr("SMESH_ARGUMENTS"), mainFrame(), "GroupC1");
56 GroupC1->setColumnLayout( 3, Qt::Horizontal );
58 createObject( tr("SMESH_OBJECT_MESHorSUBMESH"), GroupC1, MeshOrSubMesh );
59 createObject( tr("SMESH_OBJECT_GEOM"), GroupC1, GeomShape );
61 main->addWidget( GroupC1 );
63 /***************************************************************/
64 GroupHypotheses = new QGroupBox(tr("SMESH_HYPOTHESES"), mainFrame(), "GroupHypotheses");
65 GroupHypotheses->setColumnLayout(0, Qt::Vertical);
66 GroupHypotheses->layout()->setSpacing(0);
67 GroupHypotheses->layout()->setMargin(0);
68 QGridLayout* grid_3 = new QGridLayout(GroupHypotheses->layout());
69 grid_3->setAlignment(Qt::AlignTop);
70 grid_3->setSpacing(6);
71 grid_3->setMargin(11);
73 TextHypDefinition = new QLabel(tr("SMESH_AVAILABLE"), GroupHypotheses, "TextHypDefinition");
74 grid_3->addWidget(TextHypDefinition, 0, 0);
76 ListHypDefinition = new QListBox(GroupHypotheses, "ListHypDefinition");
77 ListHypDefinition->setMinimumSize(100, 100);
78 grid_3->addWidget(ListHypDefinition, 1, 0);
80 TextHypAssignation = new QLabel(tr("SMESH_EDIT_USED"), GroupHypotheses, "TextHypAssignation");
81 grid_3->addWidget(TextHypAssignation, 0, 1);
83 ListHypAssignation = new QListBox(GroupHypotheses, "ListHypAssignation");
84 ListHypAssignation->setMinimumSize(100, 100);
85 grid_3->addWidget(ListHypAssignation, 1, 1);
87 main->addWidget( GroupHypotheses );
89 /***************************************************************/
90 GroupAlgorithms = new QGroupBox(tr("SMESH_ADD_ALGORITHM"), mainFrame(), "GroupAlgorithms");
91 GroupAlgorithms->setColumnLayout(0, Qt::Vertical);
92 GroupAlgorithms->layout()->setSpacing(0);
93 GroupAlgorithms->layout()->setMargin(0);
94 QGridLayout* grid_4 = new QGridLayout(GroupAlgorithms->layout());
95 grid_4->setAlignment(Qt::AlignTop);
96 grid_4->setSpacing(6);
97 grid_4->setMargin(11);
99 TextAlgoDefinition = new QLabel(tr("SMESH_AVAILABLE"), GroupAlgorithms, "TextAlgoDefinition");
100 grid_4->addWidget(TextAlgoDefinition, 0, 0);
102 ListAlgoDefinition = new QListBox(GroupAlgorithms, "ListAlgoDefinition");
103 ListAlgoDefinition->setMinimumSize(100, 100);
104 grid_4->addWidget(ListAlgoDefinition, 1, 0);
106 TextAlgoAssignation = new QLabel(tr("SMESH_EDIT_USED"), GroupAlgorithms, "TextAlgoAssignation");
107 grid_4->addWidget(TextAlgoAssignation, 0, 1);
109 ListAlgoAssignation = new QListBox(GroupAlgorithms, "ListAlgoAssignation");
110 ListAlgoAssignation ->setMinimumSize(100, 100);
111 grid_4->addWidget(ListAlgoAssignation, 1, 1);
113 main->addWidget( GroupAlgorithms );
115 connect(ListHypAssignation, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(removeItem(QListBoxItem*)));
116 connect(ListAlgoAssignation, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(removeItem(QListBoxItem*)));
118 connect(ListHypDefinition, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(addItem(QListBoxItem*)));
119 connect(ListAlgoDefinition, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(addItem(QListBoxItem*)));
122 //=================================================================================
123 // function : ~SMESHGUI_EditHypothesesDlg()
124 // purpose : Destroys the object and frees any allocated resources
125 //=================================================================================
126 SMESHGUI_EditHypothesesDlg::~SMESHGUI_EditHypothesesDlg()
128 // no need to delete child widgets, Qt does it all for us
131 //=======================================================================
132 // function : isOld()
134 //=======================================================================
135 bool SMESHGUI_EditHypothesesDlg::isOld (QListBoxItem* hypItem)
137 if (hypItem->rtti() == ListBoxIOR::RTTI_IOR) {
138 ListBoxIOR* hyp = (ListBoxIOR*) hypItem;
139 return (myMapOldHypos.find(hyp->GetIOR()) != myMapOldHypos.end() ||
140 myMapOldAlgos.find(hyp->GetIOR()) != myMapOldAlgos.end());
146 //=================================================================================
147 // function : removeItem()
149 //=================================================================================
150 void SMESHGUI_EditHypothesesDlg::removeItem (QListBoxItem* item)
152 const QObject* aSender = sender();
156 if (aSender == ListHypAssignation) {
157 myNbModification += isOld(item) ? 1 : -1;
158 ListHypAssignation->removeItem(ListHypAssignation->index(item));
160 else if (aSender == ListAlgoAssignation) {
161 myNbModification += isOld(item) ? 1 : -1;
162 ListAlgoAssignation->removeItem(ListAlgoAssignation->index(item));
165 emit( needToUpdate() );
168 //=================================================================================
169 // function : addItem()
171 //=================================================================================
172 void SMESHGUI_EditHypothesesDlg::addItem (QListBoxItem* item)
174 const QObject* aSender = sender();
179 if (item->rtti() == ListBoxIOR::RTTI_IOR)
180 i = (ListBoxIOR*)item;
183 bool isFound = false;
186 if (aSender == ListHypDefinition) {
187 for (int j = 0, n = ListHypAssignation->count(); !isFound && j < n; j++) {
188 if (ListHypAssignation->item(j)->rtti() == ListBoxIOR::RTTI_IOR) {
189 anItem = (ListBoxIOR*)ListHypAssignation->item(j);
190 isFound = !strcmp(anItem->GetIOR(), i->GetIOR());
194 anItem = new ListBoxIOR (ListHypAssignation,
195 CORBA::string_dup(i->GetIOR()),
196 CORBA::string_dup(i->text().latin1()));
198 } else if (aSender == ListAlgoDefinition) {
199 for (int j = 0, n = ListAlgoAssignation->count(); !isFound && j < n; j++) {
200 if (ListAlgoAssignation->item(j)->rtti() == ListBoxIOR::RTTI_IOR) {
201 anItem = (ListBoxIOR*)ListAlgoAssignation->item(j);
202 isFound = !strcmp(anItem->GetIOR(), i->GetIOR());
206 anItem = new ListBoxIOR (ListAlgoAssignation,
207 CORBA::string_dup(i->GetIOR()),
208 CORBA::string_dup(i->text().latin1()));
213 myNbModification += isOld(item) ? -1 : 1;
215 emit( needToUpdate() );
218 //=================================================================================
219 // function : setListsEnabled()
221 //=================================================================================
222 void SMESHGUI_EditHypothesesDlg::setListsEnabled( const bool en )
224 ListHypDefinition ->setEnabled( en );
225 ListHypAssignation ->setEnabled( en );
226 ListAlgoDefinition ->setEnabled( en );
227 ListAlgoAssignation->setEnabled( en );
230 //=================================================================================
231 // function : hypoCount()
233 //=================================================================================
234 int SMESHGUI_EditHypothesesDlg::hypoCount() const
236 return ListHypAssignation->count();
239 //=================================================================================
240 // function : algoCount()
242 //=================================================================================
243 int SMESHGUI_EditHypothesesDlg::algoCount() const
245 return ListAlgoAssignation->count();
248 //=================================================================================
249 // function : isModified()
251 //=================================================================================
252 bool SMESHGUI_EditHypothesesDlg::isModified() const
254 return myNbModification!=0;
257 //=================================================================================
258 // function : findItem()
260 //=================================================================================
261 int SMESHGUI_EditHypothesesDlg::findItem( QListBox* listBox, const QString& ior )
263 for (int i = 0; i < listBox->count(); i++)
265 if (listBox->item(i)->rtti() == ListBoxIOR::RTTI_IOR)
267 ListBoxIOR* anItem = (ListBoxIOR*)(listBox->item(i));
268 if( anItem && ior == anItem->GetIOR() )