Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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 "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
76   GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
77   GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
78
79   Layout1->addWidget(GroupPoints, 1, 0);
80   /***************************************************************/
81
82   setHelpFileName("none.htm"); 
83
84   Init();
85 }
86
87 //=================================================================================
88 // function : ~OperationGUI_MaterialDlg()
89 // purpose  : Destroys the object and frees any allocated resources
90 //=================================================================================
91 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
92 {
93   // no need to delete child widgets, Qt does it all for us
94 }
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void OperationGUI_MaterialDlg::Init()
101 {
102   // get materials list from the parent dialog
103   OperationGUI_PartitionDlg* aParentDlg =
104     dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
105   if (aParentDlg)
106     myListMaterials = aParentDlg->GetListMaterials();
107   
108   /* list filling */
109   MESSAGE("Filling list with " << myListShapes.length() << " objects");
110   QString aMaterialId;
111   for (int ind = 0; ind < myListShapes.length(); ind++) {
112     GEOM::GEOM_Object_var anObject = myListShapes[ind];
113     if (!anObject->_is_nil()) {
114       MESSAGE("Insert " << GEOMBase::GetName( anObject ));
115       if (ind < myListMaterials.length())
116         aMaterialId = QString::number(myListMaterials[ind]);
117       else 
118         aMaterialId = "0";
119       QListViewItem* aItem =
120         new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
121     }
122   }
123   MESSAGE("Filled");
124
125   /* signals and slots connections */
126   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127   buttonApply->close(TRUE);
128   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
129
130   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
131
132   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
133           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
134 }
135
136
137 //=================================================================================
138 // function : ClickOnOk()
139 // purpose  :
140 //=================================================================================
141 void OperationGUI_MaterialDlg::ClickOnOk()
142 {
143   SUIT_Session::session()->activeApplication()->putInfo(tr(""));
144
145   int nbSh = myListShapes.length();  
146   myListMaterials.length(nbSh);
147
148   QListViewItemIterator it (GroupPoints->ListView1);
149   for (int i = 0; it.current() != 0; it++, i++) {
150     QString aMatIdStr = it.current()->text(myMaterCol);
151     myListMaterials[i] = aMatIdStr.toInt();
152     MESSAGE("For shape # " << i << " material ID = " << myListMaterials[i]);
153   }
154
155   // set materials list to the parent dialog
156   OperationGUI_PartitionDlg* aParentDlg =
157     dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
158   if (aParentDlg)
159   {
160     aParentDlg->SetListMaterials(myListMaterials);
161   }
162
163   ClickOnCancel();
164   return;
165 }
166
167
168 //=================================================================================
169 // function : SelectionIntoArgument()
170 // purpose  : Called when selection as changed or other case
171 //=================================================================================
172 void OperationGUI_MaterialDlg::SelectionIntoArgument()
173 {
174   /*QString aString = ""; // name of selection
175
176   int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
177   if (nbSel < 1) {
178     return;
179   }
180
181   //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
182
183   // no simulation
184   return;*/
185 }
186
187
188 //=================================================================================
189 // function : SetMaterial()
190 // purpose  :
191 //=================================================================================
192 void OperationGUI_MaterialDlg::SetMaterial()
193 {
194   int aMatId = GroupPoints->SpinBox1->value();
195   QString aMatIdStr;
196   aMatIdStr.setNum(aMatId);
197   QListViewItemIterator it (GroupPoints->ListView1);
198   for (; it.current() != 0; it++) {
199     if (it.current()->isSelected())
200       it.current()->setText(myMaterCol, aMatIdStr);
201   }
202   return;
203 }
204
205
206 //=================================================================================
207 // function : ActivateThisDialog()
208 // purpose  :
209 //=================================================================================
210 void OperationGUI_MaterialDlg::ActivateThisDialog()
211 {
212   GEOMBase_Skeleton::ActivateThisDialog();
213   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
214           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
215   return;
216 }
217
218
219 //=================================================================================
220 // function : enterEvent()
221 // purpose  :
222 //=================================================================================
223 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
224 {
225   if (!GroupConstructors->isEnabled())
226     this->ActivateThisDialog();
227 }