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