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 "SalomeApp_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 (QWidget* parent, const char* name,
51 GEOM::ListOfGO ListShapes,
52 bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 myListShapes = ListShapes;
58 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
60 setCaption(tr("GEOM_MATERIAL_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->close(TRUE);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_1List1Spin1Btn_QTD(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
71 myShapeCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_SHAPE"));
72 myMaterCol = GroupPoints->ListView1->addColumn(tr("GEOM_MATERIAL_MATERIAL"));
73 GroupPoints->ListView1->setSelectionMode(QListView::Extended);
75 GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
76 GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
78 Layout1->addWidget(GroupPoints, 1, 0);
79 /***************************************************************/
85 //=================================================================================
86 // function : ~OperationGUI_MaterialDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void OperationGUI_MaterialDlg::Init()
101 // get materials list from the parent dialog
102 OperationGUI_PartitionDlg* aParentDlg =
103 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
105 myListMaterials = aParentDlg->GetListMaterials();
108 MESSAGE("Filling list with " << myListShapes.length() << " objects");
110 for (int ind = 0; ind < myListShapes.length(); ind++) {
111 GEOM::GEOM_Object_var anObject = myListShapes[ind];
112 if (!anObject->_is_nil()) {
113 MESSAGE("Insert " << GEOMBase::GetName( anObject ));
114 if (ind < myListMaterials.length())
115 aMaterialId = QString::number(myListMaterials[ind]);
118 QListViewItem* aItem =
119 new QListViewItem(GroupPoints->ListView1, GEOMBase::GetName( anObject ), aMaterialId);
124 /* signals and slots connections */
125 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126 buttonApply->close(TRUE);
127 buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
129 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
131 // connect(GroupPoints->ListView1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 // connect(GroupPoints->SpinBox1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
135 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
137 /* displays Dialog */
138 MESSAGE("GroupPoints->show() ...");
140 MESSAGE("this->show() ...");
148 //=================================================================================
149 // function : ClickOnOk()
151 //=================================================================================
152 void OperationGUI_MaterialDlg::ClickOnOk()
154 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
156 int nbSh = myListShapes.length();
157 myListMaterials.length(nbSh);
159 QListViewItemIterator it (GroupPoints->ListView1);
160 for (int i = 0; it.current() != 0; it++, i++) {
161 QString aMatIdStr = it.current()->text(myMaterCol);
162 myListMaterials[i] = aMatIdStr.toInt();
163 MESSAGE("For shape # " << i << " material ID = " << myListMaterials[i]);
166 // set materials list to the parent dialog
167 OperationGUI_PartitionDlg* aParentDlg =
168 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
171 aParentDlg->SetListMaterials(myListMaterials);
179 //=================================================================================
180 // function : SelectionIntoArgument()
181 // purpose : Called when selection as changed or other case
182 //=================================================================================
183 void OperationGUI_MaterialDlg::SelectionIntoArgument()
185 QString aString = ""; /* name of selection */
187 int nbSel = myGeomBase->GetNameOfSelectedIObjects(selectedIO(), aString);
192 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
199 //=================================================================================
200 // function : SetMaterial()
202 //=================================================================================
203 void OperationGUI_MaterialDlg::SetMaterial()
205 int aMatId = GroupPoints->SpinBox1->value();
207 aMatIdStr.setNum(aMatId);
208 QListViewItemIterator it (GroupPoints->ListView1);
209 for (; it.current() != 0; it++) {
210 if (it.current()->isSelected())
211 it.current()->setText(myMaterCol, aMatIdStr);
217 //=================================================================================
218 // function : ActivateThisDialog()
220 //=================================================================================
221 void OperationGUI_MaterialDlg::ActivateThisDialog()
223 GEOMBase_Skeleton::ActivateThisDialog();
224 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
225 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
230 //=================================================================================
231 // function : enterEvent()
233 //=================================================================================
234 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
236 if(!GroupConstructors->isEnabled())
237 this->ActivateThisDialog();