]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_MaterialDlg.cxx
Salome HOME
Windows porting
[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 #include "OperationGUI_MaterialDlg.h"
29 #include "OperationGUI_PartitionDlg.h"
30
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_SelectionMgr.h"
34
35 #include "utilities.h"
36
37 #include <qlabel.h>
38 #include <qlistview.h>
39 #include <qspinbox.h>
40
41 using namespace std;
42
43 //=================================================================================
44 // class    : OperationGUI_MaterialDlg()
45 // purpose  : Constructs a OperationGUI_MaterialDlg which is a child of 'parent', with the 
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            TRUE to construct a modal dialog.
49 //=================================================================================
50 OperationGUI_MaterialDlg::OperationGUI_MaterialDlg (QWidget* parent, const char* name,
51                                                     GEOM::ListOfGO ListShapes,
52                                                     bool modal, WFlags fl)
53   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   myListShapes = ListShapes;
56   myParentDlg = parent;
57
58   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
59
60   setCaption(tr("GEOM_MATERIAL_TITLE"));
61
62   /***************************************************************/
63   GroupConstructors->setTitle(tr("GEOM_PARTITION"));
64   RadioButton1->setPixmap(image0);
65   RadioButton2->close(TRUE);
66   RadioButton3->close(TRUE);
67
68   GroupPoints = new DlgRef_1List1Spin1Btn_QTD(this, "GroupPoints");
69   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
70
71   myShapeCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_SHAPE"));
72   myMaterCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_MATERIAL"));
73   GroupPoints->ListView1->setSelectionMode(QListView::Extended);
74
75   GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
76   GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
77
78   Layout1->addWidget(GroupPoints, 1, 0);
79   /***************************************************************/
80  
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~OperationGUI_MaterialDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
90 {
91   // no need to delete child widgets, Qt does it all for us
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void OperationGUI_MaterialDlg::Init()
100 {
101   // get materials list from the parent dialog
102   OperationGUI_PartitionDlg* aParentDlg =
103     dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
104   if (aParentDlg)
105     myListMaterials = aParentDlg->GetListMaterials();
106   
107   /* list filling */
108   MESSAGE("Filling list with " << myListShapes.length() << " objects");
109   QString aMaterialId;
110   for (int ind = 0; ind < myListShapes.length(); ind++) {
111     GEOM::GEOM_Object_var anObject = myListShapes[ind];
112     if (!anObject->_is_nil()) {
113       MESSAGE("Insert " << GEOMBase::GetName( anObject ));
114       if (ind < myListMaterials.length())
115         aMaterialId = QString::number(myListMaterials[ind]);
116       else 
117         aMaterialId = "0";
118       QListViewItem* aItem =
119         new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
120     }
121   }
122   MESSAGE("Filled");
123
124   /* signals and slots connections */
125   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126   buttonApply->close(TRUE);
127   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
128
129   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
130
131 //  connect(GroupPoints->ListView1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 //  connect(GroupPoints->SpinBox1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133
134   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
135           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136
137   /* displays Dialog */
138   MESSAGE("GroupPoints->show() ...");
139   GroupPoints->show();
140   MESSAGE("this->show() ...");
141   this->show();
142   MESSAGE("return");
143
144   return;
145 }
146
147
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose  :
151 //=================================================================================
152 void OperationGUI_MaterialDlg::ClickOnOk()
153 {
154   SUIT_Session::session()->activeApplication()->putInfo(tr(""));
155
156   int nbSh = myListShapes.length();  
157   myListMaterials.length(nbSh);
158
159   QListViewItemIterator it (GroupPoints->ListView1);
160   for (int i = 0; it.current() != 0; it++, i++) {
161     QString aMatIdStr = it.current()->text(myMaterCol);
162     myListMaterials[i] = aMatIdStr.toInt();
163     MESSAGE("For shape # " << i << " material ID = " << myListMaterials[i]);
164   }
165
166   // set materials list to the parent dialog
167   OperationGUI_PartitionDlg* aParentDlg =
168     dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
169   if (aParentDlg)
170   {
171     aParentDlg->SetListMaterials(myListMaterials);
172   }
173
174   ClickOnCancel();
175   return;
176 }
177
178
179 //=================================================================================
180 // function : SelectionIntoArgument()
181 // purpose  : Called when selection as changed or other case
182 //=================================================================================
183 void OperationGUI_MaterialDlg::SelectionIntoArgument()
184 {
185   QString aString = ""; /* name of selection */
186
187   int nbSel = myGeomBase->GetNameOfSelectedIObjects(selectedIO(), aString);
188   if(nbSel < 1) {
189     return;
190   }
191
192   //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
193
194   /* no simulation */
195   return;
196 }
197
198
199 //=================================================================================
200 // function : SetMaterial()
201 // purpose  :
202 //=================================================================================
203 void OperationGUI_MaterialDlg::SetMaterial()
204 {
205   int aMatId = GroupPoints->SpinBox1->value();
206   QString aMatIdStr;
207   aMatIdStr.setNum(aMatId);
208   QListViewItemIterator it (GroupPoints->ListView1);
209   for (; it.current() != 0; it++) {
210     if (it.current()->isSelected())
211       it.current()->setText(myMaterCol, aMatIdStr);
212   }
213   return;
214 }
215
216
217 //=================================================================================
218 // function : ActivateThisDialog()
219 // purpose  :
220 //=================================================================================
221 void OperationGUI_MaterialDlg::ActivateThisDialog()
222 {
223   GEOMBase_Skeleton::ActivateThisDialog();
224   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
225           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
226   return;
227 }
228
229
230 //=================================================================================
231 // function : enterEvent()
232 // purpose  :
233 //=================================================================================
234 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
235 {
236   if(!GroupConstructors->isEnabled())
237     this->ActivateThisDialog();
238 }