Salome HOME
*** empty log message ***
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_ExtrusionDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_ExtrusionDlg.h"
30 #include <SMESHGUI_SpinBox.h>
31
32 #include <SUIT_ResourceMgr.h>
33
34 #include <SMDSAbs_ElementType.hxx>
35 #include <SMESH_Type.h>
36
37 #include <qcheckbox.h>
38 #include <qvalidator.h>
39 #include <qlabel.h>
40 #include <qlayout.h>
41 #include <qgroupbox.h>
42 #include <qbuttongroup.h>
43 #include <qradiobutton.h>
44
45 //=================================================================================
46 // function : SMESHGUI_ExtrusionDlg()
47 // purpose  : constructor
48 //=================================================================================
49 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg()
50 : SMESHGUI_Dialog( false, true, OK | Apply | Close )
51 {
52   QPixmap image0( resMgr()->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE") ) ),
53           image1( resMgr()->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE") ) );
54
55   resize(303, 185);
56   setCaption(tr("EXTRUSION_ALONG_LINE"));
57   
58   QVBoxLayout* main = new QVBoxLayout( mainFrame() );
59
60   /***************************************************************/
61   myGroupConstructors = new QButtonGroup("GroupConstructors", mainFrame() );
62   myGroupConstructors->setTitle(tr("SMESH_EXTRUSION"));
63   myGroupConstructors->setExclusive(TRUE);
64   myGroupConstructors->setColumnLayout(0, Qt::Vertical);
65   myGroupConstructors->layout()->setSpacing(0);
66   myGroupConstructors->layout()->setMargin(0);
67   QGridLayout* GroupConstructorsLayout = new QGridLayout(myGroupConstructors->layout());
68   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
69   GroupConstructorsLayout->setSpacing(6);
70   GroupConstructorsLayout->setMargin(11);
71   QRadioButton* RadioButton1 = new QRadioButton(myGroupConstructors, "RadioButton1");
72   RadioButton1->setText(tr(""));
73   RadioButton1->setPixmap(image0);
74   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
75   QRadioButton* RadioButton2 = new QRadioButton(myGroupConstructors, "RadioButton2");
76   RadioButton2->setText(tr(""));
77   RadioButton2->setPixmap(image1);
78   GroupConstructorsLayout->addWidget(RadioButton2, 0, 2);
79   main->addWidget(myGroupConstructors);
80
81   /***************************************************************/
82   myGroupArguments = new QGroupBox( mainFrame(), "GroupArguments");
83   myGroupArguments->setTitle(tr("EXTRUSION_1D"));
84   myGroupArguments->setColumnLayout( 1, Qt::Horizontal );
85   myGroupArguments->layout()->setSpacing(0);
86   myGroupArguments->layout()->setMargin(11);
87
88   QGroupBox* sel = new QGroupBox( myGroupArguments );
89   sel->setColumnLayout( 3, Qt::Horizontal );
90   sel->setFrameShape( QFrame::NoFrame );
91   sel->layout()->setSpacing(0);
92   sel->layout()->setMargin(0);
93   
94   // Controls for elements selection
95   createObject( tr( "SMESH_ID_ELEMENTS" ), sel, 0 );
96   createObject( tr( "SMESH_NAME" ), sel, 1 );
97
98   int epr = prefix( "SMESH element" );
99   setObjectType( 0, epr + SMDSAbs_Edge, epr + SMDSAbs_Face, -1 );
100   setNameIndication( 0, ListOfNames );
101   setReadOnly( 0, false );
102   int mpr = prefix( "SMESH" );
103   setObjectType( 1, mpr + MESH, mpr + SUBMESH, mpr + SUBMESH_EDGE, mpr + GROUP, -1 );
104   setNameIndication( 1, OneName );
105
106   QGroupBox* box1 = new QGroupBox( myGroupArguments );
107   box1->setColumnLayout( 1, Qt::Vertical );
108   box1->setFrameShape( QFrame::NoFrame );  
109   box1->layout()->setSpacing(0);
110   box1->layout()->setMargin(0);
111   
112   // Control for the whole mesh selection
113   myCheckBoxMesh = new QCheckBox( box1, "CheckBoxMesh" );
114   myCheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
115
116   QGroupBox* box2 = new QGroupBox( myGroupArguments );
117   box2->setColumnLayout( 1, Qt::Vertical );    
118   box2->setFrameShape( QFrame::NoFrame );
119   box2->layout()->setSpacing(0);
120   box2->layout()->setMargin(0);
121   
122   // Controls for vector selection
123   QLabel* TextLabelVector = new QLabel( box2, "TextLabelVector" );
124   TextLabelVector->setText( tr( "SMESH_VECTOR" ) );
125
126   QLabel* TextLabelDx = new QLabel( box2, "TextLabelDx" );
127   TextLabelDx->setText(tr("SMESH_DX"));
128
129   myDx = new SMESHGUI_SpinBox( box2, "SpinBox_Dx" );
130
131   QLabel* TextLabelDy = new QLabel( box2, "TextLabelDy" );
132   TextLabelDy->setText(tr("SMESH_DY"));
133
134   myDy = new SMESHGUI_SpinBox( box2, "SpinBox_Dy" );
135
136   QLabel* TextLabelDz = new QLabel( box2, "TextLabelDz" );
137   TextLabelDz->setText(tr("SMESH_DZ"));
138
139   myDz = new SMESHGUI_SpinBox( box2, "SpinBox_Dz" );
140
141   QGroupBox* box3 = new QGroupBox( myGroupArguments );
142   box3->setColumnLayout( 1, Qt::Vertical );
143   box3->setFrameShape( QFrame::NoFrame );
144   box3->layout()->setSpacing(0);
145   box3->layout()->setMargin(0);
146   
147   // Controls for nb. steps defining
148   QLabel* TextLabelNbSteps = new QLabel( box3, "TextLabelNbSteps" );
149   TextLabelNbSteps->setText(tr("SMESH_NUMBEROFSTEPS" ));
150
151   myNbSteps = new QSpinBox( box3, "SpinBox_NbSteps" );
152
153   main->addWidget( myGroupArguments );
154
155   /* Initialisations */
156   myDx->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
157   myDy->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
158   myDz->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
159
160   QIntValidator* anIntValidator = new QIntValidator( myNbSteps );
161   myNbSteps->setValidator( anIntValidator );
162   myNbSteps->setRange( 1, 999999 );
163
164   connect( myGroupConstructors, SIGNAL( clicked( int ) ),  this, SLOT  ( onConstructorsClicked( int ) ) );
165   connect( myGroupConstructors, SIGNAL( clicked( int ) ),  this, SIGNAL( constructorClicked( int ) ) );
166   connect( myCheckBoxMesh,      SIGNAL( toggled( bool ) ), this, SLOT  ( onSelectMesh( bool ) ) );
167 }
168
169 //=================================================================================
170 // function : ~SMESHGUI_ExtrusionDlg()
171 // purpose  : destructor
172 //=================================================================================
173 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
174 {
175 }
176
177 //=================================================================================
178 // function : onConstructorsClicked()
179 // purpose  : Radio button management
180 //=================================================================================
181 void SMESHGUI_ExtrusionDlg::onConstructorsClicked( int id )
182 {
183   myGroupArguments->setTitle( tr( QString( "EXTRUSION_%1D" ).arg( id+1 ) ) );
184   int mpr = prefix( "SMESH" );
185   setObjectType( 1, mpr + MESH, mpr + SUBMESH, mpr + ( id==0 ? SUBMESH_EDGE : SUBMESH_FACE ), mpr + GROUP, -1 );
186   clearSelection();
187 }
188
189 //=================================================================================
190 // function : onSelectMesh()
191 // purpose  :
192 //=================================================================================
193 void SMESHGUI_ExtrusionDlg::onSelectMesh( bool toSelectMesh )
194 {
195   setObjectShown( 0, !toSelectMesh );
196   setObjectShown( 1, toSelectMesh );
197   clearSelection();
198 }
199
200 //=================================================================================
201 // function : constructorId()
202 // purpose  :
203 //=================================================================================
204 int SMESHGUI_ExtrusionDlg::constructorId() const
205 {
206   if( myGroupConstructors && myGroupConstructors->selected() )
207     return myGroupConstructors->id( myGroupConstructors->selected() );
208   else
209     return -1;
210 }
211
212 //=================================================================================
213 // function : init()
214 // purpose  :
215 //=================================================================================
216 void SMESHGUI_ExtrusionDlg::init()
217 {
218   myGroupConstructors->setButton( 0 );
219   myCheckBoxMesh->setChecked( false );
220   onSelectMesh( false );
221   myDx->setValue( 0.0 );
222   myDy->setValue( 0.0 );
223   myDz->setValue( 0.0 );
224 }  
225
226 //=================================================================================
227 // function : coords()
228 // purpose  :
229 //=================================================================================
230 void SMESHGUI_ExtrusionDlg::coords( double& x, double& y, double& z ) const
231 {
232   x = myDx->value();
233   y = myDy->value();
234   z = myDz->value();
235 }
236
237 //=================================================================================
238 // function : nbStep()
239 // purpose  :
240 //=================================================================================
241 int SMESHGUI_ExtrusionDlg::nbStep() const
242 {
243   return myNbSteps->value();
244 }  
245
246 //=================================================================================
247 // function : isSelectMesh()
248 // purpose  :
249 //=================================================================================
250 bool SMESHGUI_ExtrusionDlg::isSelectMesh() const
251 {
252   return myCheckBoxMesh->isChecked();
253 }