1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_MaterialDlg.cxx
24 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
26 #include "OperationGUI_MaterialDlg.h"
27 #include "OperationGUI_PartitionDlg.h"
31 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 //=================================================================================
39 // class : OperationGUI_MaterialDlg()
40 // purpose : Constructs a OperationGUI_MaterialDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 OperationGUI_MaterialDlg::OperationGUI_MaterialDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
46 GEOM::ListOfGO ListShapes, bool modal )
47 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
49 myListShapes = ListShapes;
51 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
53 setWindowTitle( tr( "GEOM_MATERIAL_TITLE" ) );
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
57 mainFrame()->RadioButton1->setIcon( image0 );
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupPoints = new DlgRef_1List1Spin1Btn( centralWidget() );
64 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
67 columns << tr( "GEOM_MATERIAL_SHAPE" ) << tr( "GEOM_MATERIAL_MATERIAL" );
68 GroupPoints->ListView1->setHeaderLabels( columns );
69 GroupPoints->ListView1->setSelectionMode( QAbstractItemView::ExtendedSelection );
70 GroupPoints->ListView1->setSortingEnabled( false );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_MATERIAL_ID" ) );
73 GroupPoints->PushButton1->setText( tr( "GEOM_MATERIAL_SET" ) );
75 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76 layout->setMargin( 0 ); layout->setSpacing( 6 );
77 layout->addWidget( GroupPoints );
78 /***************************************************************/
80 setHelpFileName("partition_page.html");
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
94 //=================================================================================
97 //=================================================================================
98 void OperationGUI_MaterialDlg::Init()
100 // get materials list from the parent dialog
101 OperationGUI_PartitionDlg* aParentDlg =
102 qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
104 myListMaterials = aParentDlg->GetListMaterials();
107 for ( int ind = 0; ind < myListShapes.length(); ind++ ) {
108 GEOM::GEOM_Object_var anObject = myListShapes[ind];
109 if ( !anObject->_is_nil() ) {
111 labels << GEOMBase::GetName( anObject );
112 labels << ( ind < myListMaterials.length() ?
113 QString::number( myListMaterials[ind] ) : QString( "0" ) );
114 GroupPoints->ListView1->addTopLevelItem( new QTreeWidgetItem( labels ) );
118 /* signals and slots connections */
119 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
120 buttonApply()->setAttribute( Qt::WA_DeleteOnClose );
121 buttonApply()->close();
122 buttonCancel()->setText( tr( "GEOM_BUT_CANCEL" ) );
124 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetMaterial() ) );
126 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
127 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
131 //=================================================================================
132 // function : ClickOnOk()
134 //=================================================================================
135 void OperationGUI_MaterialDlg::ClickOnOk()
137 SUIT_Session::session()->activeApplication()->putInfo( "" );
139 int nbSh = myListShapes.length();
140 myListMaterials.length( nbSh );
142 QTreeWidgetItemIterator it( GroupPoints->ListView1 );
143 for ( int i = 0; *it; it++, i++ )
144 myListMaterials[i] = (*it)->text( 1 ).toInt();
146 // set materials list to the parent dialog
147 OperationGUI_PartitionDlg* aParentDlg =
148 qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
150 aParentDlg->SetListMaterials( myListMaterials );
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void OperationGUI_MaterialDlg::SelectionIntoArgument()
162 /*QString aString = ""; // name of selection
164 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
169 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
176 //=================================================================================
177 // function : SetMaterial()
179 //=================================================================================
180 void OperationGUI_MaterialDlg::SetMaterial()
182 QString aMatIdStr = QString::number( GroupPoints->SpinBox1->value() );
183 QList<QTreeWidgetItem*> selectedItems = GroupPoints->ListView1->selectedItems();
185 QListIterator<QTreeWidgetItem*> it( selectedItems );
186 while ( it.hasNext() ) {
187 it.next()->setText( 1, aMatIdStr );
192 //=================================================================================
193 // function : ActivateThisDialog()
195 //=================================================================================
196 void OperationGUI_MaterialDlg::ActivateThisDialog()
198 GEOMBase_Skeleton::ActivateThisDialog();
199 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
200 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
205 //=================================================================================
206 // function : enterEvent()
208 //=================================================================================
209 void OperationGUI_MaterialDlg::enterEvent( QEvent* )
211 if ( !mainFrame()->GroupConstructors->isEnabled() )
212 this->ActivateThisDialog();