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