Salome HOME
e581adcd5e6781b45bd948be26d19d12061c3c74
[modules/geom.git] / src / OperationGUI / OperationGUI_MaterialDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
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)
26 //
27 #include "OperationGUI_MaterialDlg.h"
28 #include "OperationGUI_PartitionDlg.h"
29
30 #include <DlgRef.h>
31 #include <GEOMBase.h>
32 #include <GeometryGUI.h>
33
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
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 )
49 {
50   myListShapes = ListShapes;
51   
52   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
53
54   setWindowTitle( tr( "GEOM_MATERIAL_TITLE" ) );
55
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();
63
64   GroupPoints = new DlgRef_1List1Spin1Btn( centralWidget() );
65   GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
66
67   QStringList columns;
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 );
72
73   GroupPoints->TextLabel1->setText( tr( "GEOM_MATERIAL_ID" ) );
74   GroupPoints->PushButton1->setText( tr( "GEOM_MATERIAL_SET" ) );
75
76   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77   layout->setMargin( 0 ); layout->setSpacing( 6 );
78   layout->addWidget( GroupPoints );
79   /***************************************************************/
80
81   setHelpFileName("partition_page.html"); 
82
83   Init();
84 }
85
86 //=================================================================================
87 // function : ~OperationGUI_MaterialDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
91 {
92   // no need to delete child widgets, Qt does it all for us
93 }
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void OperationGUI_MaterialDlg::Init()
100 {
101   // get materials list from the parent dialog
102   OperationGUI_PartitionDlg* aParentDlg =
103     qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
104   if ( aParentDlg )
105     myListMaterials = aParentDlg->GetListMaterials();
106
107   /* list filling */
108   for ( int ind = 0; ind < myListShapes.length(); ind++ ) {
109     GEOM::GEOM_Object_var anObject = myListShapes[ind];
110     if ( !anObject->_is_nil() ) {
111       QStringList labels;
112       labels << GEOMBase::GetName( anObject );
113       labels << ( ind < myListMaterials.length() ? 
114                   QString::number( myListMaterials[ind] ) : QString( "0" ) );
115       GroupPoints->ListView1->addTopLevelItem( new QTreeWidgetItem( labels ) );
116     }
117   }
118
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" ) );
124   
125   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetMaterial() ) );
126   
127   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
128            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
129 }
130
131
132 //=================================================================================
133 // function : ClickOnOk()
134 // purpose  :
135 //=================================================================================
136 void OperationGUI_MaterialDlg::ClickOnOk()
137 {
138   SUIT_Session::session()->activeApplication()->putInfo( "" );
139
140   int nbSh = myListShapes.length();  
141   myListMaterials.length( nbSh );
142
143   QTreeWidgetItemIterator it( GroupPoints->ListView1 );
144   for ( int i = 0; *it; it++, i++ )
145     myListMaterials[i] = (*it)->text( 1 ).toInt();
146
147   // set materials list to the parent dialog
148   OperationGUI_PartitionDlg* aParentDlg =
149     qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
150   if ( aParentDlg )
151     aParentDlg->SetListMaterials( myListMaterials );
152
153   ClickOnCancel();
154 }
155
156
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose  : Called when selection as changed or other case
160 //=================================================================================
161 void OperationGUI_MaterialDlg::SelectionIntoArgument()
162 {
163   /*QString aString = ""; // name of selection
164
165   int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
166   if (nbSel < 1) {
167     return;
168   }
169
170   //myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
171
172   // no simulation
173   return;*/
174 }
175
176
177 //=================================================================================
178 // function : SetMaterial()
179 // purpose  :
180 //=================================================================================
181 void OperationGUI_MaterialDlg::SetMaterial()
182 {
183   QString aMatIdStr = QString::number( GroupPoints->SpinBox1->value() );
184   QList<QTreeWidgetItem*> selectedItems = GroupPoints->ListView1->selectedItems();
185
186   QListIterator<QTreeWidgetItem*> it( selectedItems );
187   while ( it.hasNext() ) {
188     it.next()->setText( 1, aMatIdStr );
189   }
190 }
191
192
193 //=================================================================================
194 // function : ActivateThisDialog()
195 // purpose  :
196 //=================================================================================
197 void OperationGUI_MaterialDlg::ActivateThisDialog()
198 {
199   GEOMBase_Skeleton::ActivateThisDialog();
200   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
201            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
202   return;
203 }
204
205
206 //=================================================================================
207 // function : enterEvent()
208 // purpose  :
209 //=================================================================================
210 void OperationGUI_MaterialDlg::enterEvent( QEvent* )
211 {
212   if ( !mainFrame()->GroupConstructors->isEnabled() )
213     this->ActivateThisDialog();
214 }