1 // Copyright (C) 2007-2011 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : OperationGUI_MaterialDlg.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
27 #include "OperationGUI_MaterialDlg.h"
28 #include "OperationGUI_PartitionDlg.h"
32 #include <GeometryGUI.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 //=================================================================================
40 // class : OperationGUI_MaterialDlg()
41 // purpose : Constructs a OperationGUI_MaterialDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_MaterialDlg::OperationGUI_MaterialDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 GEOM::ListOfGO ListShapes, bool modal )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
50 myListShapes = ListShapes;
52 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
54 setWindowTitle( tr( "GEOM_MATERIAL_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_1List1Spin1Btn( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
68 columns << tr( "GEOM_MATERIAL_SHAPE" ) << tr( "GEOM_MATERIAL_MATERIAL" );
69 GroupPoints->ListView1->setHeaderLabels( columns );
70 GroupPoints->ListView1->setSelectionMode( QAbstractItemView::ExtendedSelection );
71 GroupPoints->ListView1->setSortingEnabled( false );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_MATERIAL_ID" ) );
74 GroupPoints->PushButton1->setText( tr( "GEOM_MATERIAL_SET" ) );
76 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77 layout->setMargin( 0 ); layout->setSpacing( 6 );
78 layout->addWidget( GroupPoints );
79 /***************************************************************/
81 setHelpFileName("partition_page.html");
86 //=================================================================================
87 // function : ~OperationGUI_MaterialDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
92 // 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 qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
105 myListMaterials = aParentDlg->GetListMaterials();
108 for ( int ind = 0; ind < myListShapes.length(); ind++ ) {
109 GEOM::GEOM_Object_var anObject = myListShapes[ind];
110 if ( !anObject->_is_nil() ) {
112 labels << GEOMBase::GetName( anObject );
113 labels << ( ind < myListMaterials.length() ?
114 QString::number( myListMaterials[ind] ) : QString( "0" ) );
115 GroupPoints->ListView1->addTopLevelItem( new QTreeWidgetItem( labels ) );
119 /* signals and slots connections */
120 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
121 buttonApply()->setAttribute( Qt::WA_DeleteOnClose );
122 buttonApply()->close();
123 buttonCancel()->setText( tr( "GEOM_BUT_CANCEL" ) );
125 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetMaterial() ) );
127 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
128 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
132 //=================================================================================
133 // function : ClickOnOk()
135 //=================================================================================
136 void OperationGUI_MaterialDlg::ClickOnOk()
138 SUIT_Session::session()->activeApplication()->putInfo( "" );
140 int nbSh = myListShapes.length();
141 myListMaterials.length( nbSh );
143 QTreeWidgetItemIterator it( GroupPoints->ListView1 );
144 for ( int i = 0; *it; it++, i++ )
145 myListMaterials[i] = (*it)->text( 1 ).toInt();
147 // set materials list to the parent dialog
148 OperationGUI_PartitionDlg* aParentDlg =
149 qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
151 aParentDlg->SetListMaterials( myListMaterials );
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose : Called when selection as changed or other case
160 //=================================================================================
161 void OperationGUI_MaterialDlg::SelectionIntoArgument()
163 /*QString aString = ""; // name of selection
165 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
170 //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
177 //=================================================================================
178 // function : SetMaterial()
180 //=================================================================================
181 void OperationGUI_MaterialDlg::SetMaterial()
183 QString aMatIdStr = QString::number( GroupPoints->SpinBox1->value() );
184 QList<QTreeWidgetItem*> selectedItems = GroupPoints->ListView1->selectedItems();
186 QListIterator<QTreeWidgetItem*> it( selectedItems );
187 while ( it.hasNext() ) {
188 it.next()->setText( 1, aMatIdStr );
193 //=================================================================================
194 // function : ActivateThisDialog()
196 //=================================================================================
197 void OperationGUI_MaterialDlg::ActivateThisDialog()
199 GEOMBase_Skeleton::ActivateThisDialog();
200 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
201 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
206 //=================================================================================
207 // function : enterEvent()
209 //=================================================================================
210 void OperationGUI_MaterialDlg::enterEvent( QEvent* )
212 if ( !mainFrame()->GroupConstructors->isEnabled() )
213 this->ActivateThisDialog();