]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_MaterialDlg.cxx
Salome HOME
PAL8395: Improve RemoveExtraEdges
[modules/geom.git] / src / OperationGUI / OperationGUI_MaterialDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  CEA
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 //
21 //
22 //
23 //  File   : OperationGUI_MaterialDlg.cxx
24 //  Author : Julia DOROVSKIKH
25 //  Module : GEOM
26 //  $Header$
27
28 using namespace std;
29 #include "OperationGUI_MaterialDlg.h"
30 #include "OperationGUI_PartitionDlg.h"
31
32 #include "utilities.h"
33 #include "QAD_Desktop.h"
34
35 #include <qlistview.h>
36 #include <qspinbox.h>
37
38 //=================================================================================
39 // class    : OperationGUI_MaterialDlg()
40 // purpose  : Constructs a OperationGUI_MaterialDlg which is a child of 'parent', with the 
41 //            name 'name' and widget flags set to 'f'.
42 //            The dialog will by default be modeless, unless you set 'modal' to
43 //            TRUE to construct a modal dialog.
44 //=================================================================================
45 OperationGUI_MaterialDlg::OperationGUI_MaterialDlg (QWidget* parent, const char* name,
46                                                     SALOME_Selection* Sel,
47                                                     GEOM::ListOfGO ListShapes,
48                                                     bool modal, WFlags fl)
49   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 {
51   myListShapes = ListShapes;
52   myParentDlg = parent;
53
54   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
55
56   setCaption(tr("GEOM_MATERIAL_TITLE"));
57
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_PARTITION"));
60   RadioButton1->setPixmap(image0);
61   RadioButton2->close(TRUE);
62   RadioButton3->close(TRUE);
63
64   GroupPoints = new DlgRef_1List1Spin1Btn_QTD(this, "GroupPoints");
65   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
66
67   myShapeCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_SHAPE"));
68   myMaterCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_MATERIAL"));
69   GroupPoints->ListView1->setSelectionMode(QListView::Extended);
70
71   GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
72   GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
73
74   Layout1->addWidget(GroupPoints, 1, 0);
75   /***************************************************************/
76  
77   Init();
78 }
79
80
81 //=================================================================================
82 // function : ~OperationGUI_MaterialDlg()
83 // purpose  : Destroys the object and frees any allocated resources
84 //=================================================================================
85 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
86 {
87   // no need to delete child widgets, Qt does it all for us
88 }
89
90
91 //=================================================================================
92 // function : Init()
93 // purpose  :
94 //=================================================================================
95 void OperationGUI_MaterialDlg::Init()
96 {
97   // get materials list from the parent dialog
98   OperationGUI_PartitionDlg* aParentDlg =
99     dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
100   if (aParentDlg)
101     myListMaterials = aParentDlg->GetListMaterials();
102   
103   /* list filling */
104   MESSAGE("Filling list with " << myListShapes.length() << " objects");
105   QString aMaterialId;
106   for (int ind = 0; ind < myListShapes.length(); ind++) {
107     GEOM::GEOM_Object_var anObject = myListShapes[ind];
108     if (!anObject->_is_nil()) {
109       MESSAGE("Insert " << GEOMBase::GetName( anObject ));
110       if (ind < myListMaterials.length())
111         aMaterialId = QString::number(myListMaterials[ind]);
112       else 
113         aMaterialId = "0";
114       QListViewItem* aItem =
115         new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
116     }
117   }
118   MESSAGE("Filled");
119
120   /* signals and slots connections */
121   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122   buttonApply->close(TRUE);
123   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
124
125   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
126
127 //  connect(GroupPoints->ListView1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 //  connect(GroupPoints->SpinBox1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129
130   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
131
132   /* displays Dialog */
133   MESSAGE("GroupPoints->show() ...");
134   GroupPoints->show();
135   MESSAGE("this->show() ...");
136   this->show();
137   MESSAGE("return");
138
139   return;
140 }
141
142
143 //=================================================================================
144 // function : ClickOnOk()
145 // purpose  :
146 //=================================================================================
147 void OperationGUI_MaterialDlg::ClickOnOk()
148 {
149   QAD_Application::getDesktop()->putInfo(tr(""));
150
151   int nbSh = myListShapes.length();  
152   myListMaterials.length(nbSh);
153
154   QListViewItemIterator it (GroupPoints->ListView1);
155   for (int i = 0; it.current() != 0; it++, i++) {
156     QString aMatIdStr = it.current()->text(myMaterCol);
157     myListMaterials[i] = aMatIdStr.toInt();
158     MESSAGE("For shape # " << i << " material ID = " << myListMaterials[i]);
159   }
160
161   // set materials list to the parent dialog
162   OperationGUI_PartitionDlg* aParentDlg =
163     dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
164   if (aParentDlg)
165   {
166     aParentDlg->SetListMaterials(myListMaterials);
167   }
168
169   ClickOnCancel();
170   return;
171 }
172
173
174 //=================================================================================
175 // function : SelectionIntoArgument()
176 // purpose  : Called when selection as changed or other case
177 //=================================================================================
178 void OperationGUI_MaterialDlg::SelectionIntoArgument()
179 {
180   QString aString = ""; /* name of selection */
181
182   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
183   if(nbSel < 1) {
184     return;
185   }
186
187 //  myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes);
188
189   /* no simulation */
190   return;
191 }
192
193
194 //=================================================================================
195 // function : SetMaterial()
196 // purpose  :
197 //=================================================================================
198 void OperationGUI_MaterialDlg::SetMaterial()
199 {
200   int aMatId = GroupPoints->SpinBox1->value();
201   QString aMatIdStr;
202   aMatIdStr.setNum(aMatId);
203   QListViewItemIterator it (GroupPoints->ListView1);
204   for (; it.current() != 0; it++) {
205     if (it.current()->isSelected())
206       it.current()->setText(myMaterCol, aMatIdStr);
207   }
208   return;
209 }
210
211
212 //=================================================================================
213 // function : ActivateThisDialog()
214 // purpose  :
215 //=================================================================================
216 void OperationGUI_MaterialDlg::ActivateThisDialog()
217 {
218   GEOMBase_Skeleton::ActivateThisDialog();
219   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
220   return;
221 }
222
223
224 //=================================================================================
225 // function : enterEvent()
226 // purpose  :
227 //=================================================================================
228 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
229 {
230   if(!GroupConstructors->isEnabled())
231     this->ActivateThisDialog();
232 }