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.com
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);
75 GroupPoints->ListView1->setSorting(-1);
77 GroupPoints->TextLabel1->setText(tr("GEOM_MATERIAL_ID"));
78 GroupPoints->PushButton1->setText(tr("GEOM_MATERIAL_SET"));
80 Layout1->addWidget(GroupPoints, 1, 0);
81 /***************************************************************/
83 setHelpFileName("none.htm");
88 //=================================================================================
89 // function : ~OperationGUI_MaterialDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
94 // no need to delete child widgets, Qt does it all for us
97 //=================================================================================
100 //=================================================================================
101 void OperationGUI_MaterialDlg::Init()
103 // get materials list from the parent dialog
104 OperationGUI_PartitionDlg* aParentDlg =
105 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
107 myListMaterials = aParentDlg->GetListMaterials();
110 MESSAGE("Filling list with " << myListShapes.length() << " objects");
112 QListViewItem *anItem = NULL;
113 for (int ind = 0; ind < myListShapes.length(); ind++) {
114 GEOM::GEOM_Object_var anObject = myListShapes[ind];
115 if (!anObject->_is_nil()) {
116 MESSAGE("Insert " << GEOMBase::GetName( anObject ));
117 if (ind < myListMaterials.length())
118 aMaterialId = QString::number(myListMaterials[ind]);
122 // insert after aPrevItem
123 anItem = new QListViewItem(GroupPoints->ListView1, anItem,
124 GEOMBase::GetName( anObject ), aMaterialId);
126 // the first item creation
127 anItem = new QListViewItem(GroupPoints->ListView1,
128 GEOMBase::GetName( anObject ), aMaterialId);
133 /* signals and slots connections */
134 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 buttonApply->close(TRUE);
136 buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
138 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetMaterial()));
140 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
141 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
145 //=================================================================================
146 // function : ClickOnOk()
148 //=================================================================================
149 void OperationGUI_MaterialDlg::ClickOnOk()
151 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
153 int nbSh = myListShapes.length();
154 myListMaterials.length(nbSh);
156 QListViewItemIterator it (GroupPoints->ListView1);
157 for (int i = 0; it.current() != 0; it++, i++) {
158 QString aMatIdStr = it.current()->text(myMaterCol);
159 myListMaterials[i] = aMatIdStr.toInt();
160 MESSAGE("For shape # " << i << " material ID = " << myListMaterials[i]);
163 // set materials list to the parent dialog
164 OperationGUI_PartitionDlg* aParentDlg =
165 dynamic_cast<OperationGUI_PartitionDlg*>(myParentDlg);
168 aParentDlg->SetListMaterials(myListMaterials);
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection as changed or other case
179 //=================================================================================
180 void OperationGUI_MaterialDlg::SelectionIntoArgument()
182 /*QString aString = ""; // name of selection
184 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
189 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
196 //=================================================================================
197 // function : SetMaterial()
199 //=================================================================================
200 void OperationGUI_MaterialDlg::SetMaterial()
202 int aMatId = GroupPoints->SpinBox1->value();
204 aMatIdStr.setNum(aMatId);
205 QListViewItemIterator it (GroupPoints->ListView1);
206 for (; it.current() != 0; it++) {
207 if (it.current()->isSelected())
208 it.current()->setText(myMaterCol, aMatIdStr);
214 //=================================================================================
215 // function : ActivateThisDialog()
217 //=================================================================================
218 void OperationGUI_MaterialDlg::ActivateThisDialog()
220 GEOMBase_Skeleton::ActivateThisDialog();
221 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
222 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
227 //=================================================================================
228 // function : enterEvent()
230 //=================================================================================
231 void OperationGUI_MaterialDlg::enterEvent(QEvent* e)
233 if (!GroupConstructors->isEnabled())
234 this->ActivateThisDialog();