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 "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
36 #include "utilities.h"
39 #include <qlistview.h>
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)
54 myListShapes = ListShapes;
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
59 setCaption(tr("GEOM_MATERIAL_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_1List1Spin1Btn_QTD(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
70 myShapeCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_SHAPE"));
71 myMaterCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_MATERIAL"));
72 GroupPoints->ListView1->setSelectionMode(QListView::Extended);
74 GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
75 GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
77 Layout1->addWidget(GroupPoints, 1, 0);
78 /***************************************************************/
84 //=================================================================================
85 // function : ~OperationGUI_MaterialDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void OperationGUI_MaterialDlg::Init()
100 // get materials list from the parent dialog
101 OperationGUI_PartitionDlg* aParentDlg =
102 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
104 myListMaterials = aParentDlg->GetListMaterials();
107 MESSAGE("Filling list with " << myListShapes.length() << " objects");
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]);
117 QListViewItem* aItem =
118 new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
123 /* signals and slots connections */
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 buttonApply->close(TRUE);
126 buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
130 // connect(GroupPoints->ListView1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 // connect(GroupPoints->SpinBox1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
134 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136 /* displays Dialog */
137 MESSAGE("GroupPoints->show() ...");
139 MESSAGE("this->show() ...");
147 //=================================================================================
148 // function : ClickOnOk()
150 //=================================================================================
151 void OperationGUI_MaterialDlg::ClickOnOk()
153 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
155 int nbSh = myListShapes.length();
156 myListMaterials.length(nbSh);
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]);
165 // set materials list to the parent dialog
166 OperationGUI_PartitionDlg* aParentDlg =
167 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
170 aParentDlg->SetListMaterials(myListMaterials);
178 //=================================================================================
179 // function : SelectionIntoArgument()
180 // purpose : Called when selection as changed or other case
181 //=================================================================================
182 void OperationGUI_MaterialDlg::SelectionIntoArgument()
184 QString aString = ""; /* name of selection */
186 int nbSel = myGeomBase->GetNameOfSelectedIObjects(selectedIO(), aString);
191 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
198 //=================================================================================
199 // function : SetMaterial()
201 //=================================================================================
202 void OperationGUI_MaterialDlg::SetMaterial()
204 int aMatId = GroupPoints->SpinBox1->value();
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);
216 //=================================================================================
217 // function : ActivateThisDialog()
219 //=================================================================================
220 void OperationGUI_MaterialDlg::ActivateThisDialog()
222 GEOMBase_Skeleton::ActivateThisDialog();
223 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
224 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
229 //=================================================================================
230 // function : enterEvent()
232 //=================================================================================
233 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
235 if(!GroupConstructors->isEnabled())
236 this->ActivateThisDialog();