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
28 #include "OperationGUI_MaterialDlg.h"
29 #include "OperationGUI_PartitionDlg.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include "utilities.h"
38 #include <qlistview.h>
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)
56 myListShapes = ListShapes;
59 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
61 setCaption(tr("GEOM_MATERIAL_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_1List1Spin1Btn_QTD(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
72 myShapeCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_SHAPE"));
73 myMaterCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_MATERIAL"));
74 GroupPoints->ListView1->setSelectionMode(QListView::Extended);
76 GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
77 GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
79 Layout1->addWidget(GroupPoints, 1, 0);
80 /***************************************************************/
82 setHelpFileName("none.htm");
87 //=================================================================================
88 // function : ~OperationGUI_MaterialDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
93 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void OperationGUI_MaterialDlg::Init()
102 // get materials list from the parent dialog
103 OperationGUI_PartitionDlg* aParentDlg =
104 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
106 myListMaterials = aParentDlg->GetListMaterials();
109 MESSAGE("Filling list with " << myListShapes.length() << " objects");
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]);
119 QListViewItem* aItem =
120 new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
125 /* signals and slots connections */
126 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 buttonApply->close(TRUE);
128 buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
132 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
133 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
137 //=================================================================================
138 // function : ClickOnOk()
140 //=================================================================================
141 void OperationGUI_MaterialDlg::ClickOnOk()
143 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
145 int nbSh = myListShapes.length();
146 myListMaterials.length(nbSh);
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]);
155 // set materials list to the parent dialog
156 OperationGUI_PartitionDlg* aParentDlg =
157 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
160 aParentDlg->SetListMaterials(myListMaterials);
168 //=================================================================================
169 // function : SelectionIntoArgument()
170 // purpose : Called when selection as changed or other case
171 //=================================================================================
172 void OperationGUI_MaterialDlg::SelectionIntoArgument()
174 /*QString aString = ""; // name of selection
176 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
181 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
188 //=================================================================================
189 // function : SetMaterial()
191 //=================================================================================
192 void OperationGUI_MaterialDlg::SetMaterial()
194 int aMatId = GroupPoints->SpinBox1->value();
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);
206 //=================================================================================
207 // function : ActivateThisDialog()
209 //=================================================================================
210 void OperationGUI_MaterialDlg::ActivateThisDialog()
212 GEOMBase_Skeleton::ActivateThisDialog();
213 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
214 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
219 //=================================================================================
220 // function : enterEvent()
222 //=================================================================================
223 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
225 if (!GroupConstructors->isEnabled())
226 this->ActivateThisDialog();