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
21 // File : OperationGUI_MaterialDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "OperationGUI_MaterialDlg.h"
26 #include "OperationGUI_PartitionDlg.h"
28 #include <GEOM_DlgRef.h>
30 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 //=================================================================================
38 // class : OperationGUI_MaterialDlg()
39 // purpose : Constructs a OperationGUI_MaterialDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 OperationGUI_MaterialDlg::OperationGUI_MaterialDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
45 GEOM::ListOfGO ListShapes, bool modal )
46 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
48 myListShapes = ListShapes;
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
52 setWindowTitle( tr( "GEOM_MATERIAL_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
56 mainFrame()->RadioButton1->setIcon( image0 );
57 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58 mainFrame()->RadioButton2->close();
59 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton3->close();
62 GroupPoints = new DlgRef_1List1Spin1Btn( centralWidget() );
63 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
66 columns << tr( "GEOM_MATERIAL_SHAPE" ) << tr( "GEOM_MATERIAL_MATERIAL" );
67 GroupPoints->ListView1->setHeaderLabels( columns );
68 GroupPoints->ListView1->setSelectionMode( QAbstractItemView::ExtendedSelection );
69 GroupPoints->ListView1->setSortingEnabled( false );
71 GroupPoints->TextLabel1->setText( tr( "GEOM_MATERIAL_ID" ) );
72 GroupPoints->PushButton1->setText( tr( "GEOM_MATERIAL_SET" ) );
74 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
75 layout->setMargin( 0 ); layout->setSpacing( 6 );
76 layout->addWidget( GroupPoints );
77 /***************************************************************/
79 setHelpFileName( "partition.htm" );
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
93 //=================================================================================
96 //=================================================================================
97 void OperationGUI_MaterialDlg::Init()
99 // get materials list from the parent dialog
100 OperationGUI_PartitionDlg* aParentDlg =
101 qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
103 myListMaterials = aParentDlg->GetListMaterials();
106 for ( int ind = 0; ind < myListShapes.length(); ind++ ) {
107 GEOM::GEOM_Object_var anObject = myListShapes[ind];
108 if ( !anObject->_is_nil() ) {
110 labels << GEOMBase::GetName( anObject );
111 labels << ( ind < myListMaterials.length() ?
112 QString::number( myListMaterials[ind] ) : QString( "0" ) );
113 GroupPoints->ListView1->addTopLevelItem( new QTreeWidgetItem( labels ) );
117 /* signals and slots connections */
118 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119 buttonApply()->setAttribute( Qt::WA_DeleteOnClose );
120 buttonApply()->close();
121 buttonCancel()->setText( tr( "GEOM_BUT_CANCEL" ) );
123 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetMaterial() ) );
125 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
126 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
130 //=================================================================================
131 // function : ClickOnOk()
133 //=================================================================================
134 void OperationGUI_MaterialDlg::ClickOnOk()
136 SUIT_Session::session()->activeApplication()->putInfo( "" );
138 int nbSh = myListShapes.length();
139 myListMaterials.length( nbSh );
141 QTreeWidgetItemIterator it( GroupPoints->ListView1 );
142 for ( int i = 0; *it; it++, i++ )
143 myListMaterials[i] = (*it)->text( 1 ).toInt();
145 // set materials list to the parent dialog
146 OperationGUI_PartitionDlg* aParentDlg =
147 qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
149 aParentDlg->SetListMaterials( myListMaterials );
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection as changed or other case
158 //=================================================================================
159 void OperationGUI_MaterialDlg::SelectionIntoArgument()
161 /*QString aString = ""; // name of selection
163 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
168 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
175 //=================================================================================
176 // function : SetMaterial()
178 //=================================================================================
179 void OperationGUI_MaterialDlg::SetMaterial()
181 QString aMatIdStr = QString::number( GroupPoints->SpinBox1->value() );
182 QList<QTreeWidgetItem*> selectedItems = GroupPoints->ListView1->selectedItems();
184 QListIterator<QTreeWidgetItem*> it( selectedItems );
185 while ( it.hasNext() ) {
186 it.next()->setText( 1, aMatIdStr );
191 //=================================================================================
192 // function : ActivateThisDialog()
194 //=================================================================================
195 void OperationGUI_MaterialDlg::ActivateThisDialog()
197 GEOMBase_Skeleton::ActivateThisDialog();
198 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
199 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
204 //=================================================================================
205 // function : enterEvent()
207 //=================================================================================
208 void OperationGUI_MaterialDlg::enterEvent( QEvent* )
210 if ( !mainFrame()->GroupConstructors->isEnabled() )
211 this->ActivateThisDialog();