1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 CEA
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.
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.
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
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : OperationGUI_MaterialDlg.cxx
24 // Author : Julia DOROVSKIKH
29 #include "OperationGUI_MaterialDlg.h"
30 #include "OperationGUI_PartitionDlg.h"
32 #include "utilities.h"
33 #include "QAD_Desktop.h"
35 #include <qlistview.h>
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)
51 myListShapes = ListShapes;
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
56 setCaption(tr("GEOM_MATERIAL_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_1List1Spin1Btn_QTD(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
67 myShapeCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_SHAPE"));
68 myMaterCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_MATERIAL"));
69 GroupPoints->ListView1->setSelectionMode(QListView::Extended);
71 GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
72 GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
74 Layout1->addWidget(GroupPoints, 1, 0);
75 /***************************************************************/
81 //=================================================================================
82 // function : ~OperationGUI_MaterialDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
87 // no need to delete child widgets, Qt does it all for us
91 //=================================================================================
94 //=================================================================================
95 void OperationGUI_MaterialDlg::Init()
97 // get materials list from the parent dialog
98 OperationGUI_PartitionDlg* aParentDlg =
99 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
101 myListMaterials = aParentDlg->GetListMaterials();
104 MESSAGE("Filling list with " << myListShapes.length() << " objects");
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]);
114 QListViewItem* aItem =
115 new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
120 /* signals and slots connections */
121 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 buttonApply->close(TRUE);
123 buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
125 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
127 // connect(GroupPoints->ListView1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 // connect(GroupPoints->SpinBox1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132 /* displays Dialog */
133 MESSAGE("GroupPoints->show() ...");
135 MESSAGE("this->show() ...");
143 //=================================================================================
144 // function : ClickOnOk()
146 //=================================================================================
147 void OperationGUI_MaterialDlg::ClickOnOk()
149 QAD_Application::getDesktop()->putInfo(tr(""));
151 int nbSh = myListShapes.length();
152 myListMaterials.length(nbSh);
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]);
161 // set materials list to the parent dialog
162 OperationGUI_PartitionDlg* aParentDlg =
163 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
166 aParentDlg->SetListMaterials(myListMaterials);
174 //=================================================================================
175 // function : SelectionIntoArgument()
176 // purpose : Called when selection as changed or other case
177 //=================================================================================
178 void OperationGUI_MaterialDlg::SelectionIntoArgument()
180 QString aString = ""; /* name of selection */
182 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
187 // myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes);
194 //=================================================================================
195 // function : SetMaterial()
197 //=================================================================================
198 void OperationGUI_MaterialDlg::SetMaterial()
200 int aMatId = GroupPoints->SpinBox1->value();
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);
212 //=================================================================================
213 // function : ActivateThisDialog()
215 //=================================================================================
216 void OperationGUI_MaterialDlg::ActivateThisDialog()
218 GEOMBase_Skeleton::ActivateThisDialog();
219 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
224 //=================================================================================
225 // function : enterEvent()
227 //=================================================================================
228 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
230 if(!GroupConstructors->isEnabled())
231 this->ActivateThisDialog();