]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_ScaleDlg.cxx
Salome HOME
aa4f154ae3bdc459d224942bfb4d0455a6d12987
[modules/geom.git] / src / TransformationGUI / TransformationGUI_ScaleDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : TransformationGUI_ScaleDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24
25 #include "TransformationGUI_ScaleDlg.h"
26
27 #include <GEOM_DlgRef.h>
28 #include <GeometryGUI.h>
29 #include <GEOMBase.h>
30
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35
36 #include <GEOMImpl_Types.hxx>
37
38 //=================================================================================
39 // class    : TransformationGUI_ScaleDlg()
40 // purpose  : Constructs a TransformationGUI_ScaleDlg 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 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
46                                                         bool modal, Qt::WindowFlags fl )
47   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
48 {
49   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SCALE" ) ) );
50   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
51
52   setWindowTitle( tr( "GEOM_SCALE_TITLE" ) );
53
54   /***************************************************************/
55   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SCALE" ) );
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();
61
62   GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
63   GroupPoints->CheckButton2->hide();
64   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
65   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
66   GroupPoints->TextLabel2->setText( tr( "GEOM_CENTRAL_POINT" ) );
67   GroupPoints->TextLabel3->setText( tr( "GEOM_SCALE_FACTOR" ) );
68   GroupPoints->LineEdit1->setReadOnly( true );
69   GroupPoints->LineEdit2->setReadOnly( true );
70   GroupPoints->PushButton1->setIcon( image1 );
71   GroupPoints->PushButton2->setIcon( image1 );
72   GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
73
74   // san -- modification of an exisitng object by offset is not allowed
75   GroupPoints->CheckButton1->hide();
76
77   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
78   layout->setMargin( 0 ); layout->setSpacing( 6 );
79   layout->addWidget( GroupPoints );
80
81   /***************************************************************/
82   double aFactor = 2.0;
83   double SpecificStep = 0.5;
84   /* min, max, step and decimals for spin boxes & initial values */
85   initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3 );
86   GroupPoints->SpinBox_DX->setValue( aFactor );
87   
88   // Activate Create a Copy mode
89   GroupPoints->CheckButton1->setChecked( true );
90   CreateCopyModeChanged( true );
91
92   /* signals and slots connections */
93   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
94   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
95   
96   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
97   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
98   
99   connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
100   connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
101
102   connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
103   // VSR: TODO ->>
104   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
105   // <<-
106   connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
107    
108   connect( myGeomGUI->getApp()->selectionMgr(), 
109            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
110
111   setHelpFileName( "scale_transform.htm" );
112
113   Init();
114 }
115
116
117 //=================================================================================
118 // function : ~TransformationGUI_ScaleDlg()
119 // purpose  : Destroys the object and frees any allocated resources
120 //=================================================================================
121 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
122 {  
123   /* no need to delete child widgets, Qt does it all for us */
124 }
125
126
127 //=================================================================================
128 // function : Init()
129 // purpose  :
130 //=================================================================================
131 void TransformationGUI_ScaleDlg::Init()
132 {
133   myEditCurrentArgument = GroupPoints->LineEdit1;
134   GroupPoints->LineEdit2->clear();
135   
136   myPoint = GEOM::GEOM_Object::_nil();
137   
138   initName( tr( "GEOM_SCALE" ) );
139 }
140
141
142 //=================================================================================
143 // function : ClickOnOk()
144 // purpose  :
145 //=================================================================================
146 void TransformationGUI_ScaleDlg::ClickOnOk()
147 {
148   if ( ClickOnApply() )
149     ClickOnCancel();
150 }
151
152
153 //=================================================================================
154 // function : ClickOnApply()
155 // purpose  :
156 //=================================================================================
157 bool TransformationGUI_ScaleDlg::ClickOnApply()
158 {
159   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
160     return false;
161
162   Init();
163   return true;
164 }
165
166
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose  : Called when selection as changed or other case
170 //=================================================================================
171 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
172 {
173   myEditCurrentArgument->setText( "" );
174   QString aName;
175
176   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
177     int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
178     if ( aNbSel < 1 ) {
179       myObjects.length( 0 );
180       return;
181     }
182     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
183     if ( !myObjects.length() )
184       return;
185   }
186   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
187     if ( IObjectCount() != 1 ) {
188       myPoint = GEOM::GEOM_Object::_nil();
189       return;
190     }
191     Standard_Boolean testResult = Standard_False;
192     myPoint = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
193     if ( !testResult || CORBA::is_nil( myPoint ) )
194       return;
195     aName = GEOMBase::GetName( myPoint );
196   }
197   myEditCurrentArgument->setText( aName );
198   
199   displayPreview();
200 }
201
202
203 //=================================================================================
204 // function : LineEditReturnPressed()
205 // purpose  :
206 //=================================================================================
207 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
208 {
209   QLineEdit* send = (QLineEdit*)sender();
210   if ( send == GroupPoints->LineEdit1 ||
211        send == GroupPoints->LineEdit2 ) {
212     myEditCurrentArgument = send;
213     GEOMBase_Skeleton::LineEditReturnPressed();
214   }
215 }
216
217
218 //=================================================================================
219 // function : SetEditCurrentArgument()
220 // purpose  :
221 //=================================================================================
222 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
223 {
224   QPushButton* send = (QPushButton*)sender();
225   
226   if ( send == GroupPoints->PushButton1 ) {
227     myEditCurrentArgument = GroupPoints->LineEdit1;
228     globalSelection();
229   }
230   else if ( send == GroupPoints->PushButton2 ) {
231     myEditCurrentArgument = GroupPoints->LineEdit2;
232     globalSelection( GEOM_POINT );
233   }
234   
235   myEditCurrentArgument->setFocus();
236   SelectionIntoArgument();
237 }
238
239
240 //=================================================================================
241 // function : ActivateThisDialog()
242 // purpose  :
243 //=================================================================================
244 void TransformationGUI_ScaleDlg::ActivateThisDialog()
245 {
246   GEOMBase_Skeleton::ActivateThisDialog();
247   connect( myGeomGUI->getApp()->selectionMgr(), 
248            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
249   globalSelection();
250   GroupPoints->LineEdit1->setFocus();
251   myEditCurrentArgument = GroupPoints->LineEdit1;
252 }
253
254
255 //=================================================================================
256 // function : enterEvent()
257 // purpose  :
258 //=================================================================================
259 void TransformationGUI_ScaleDlg::enterEvent( QEvent* )
260 {
261   if( !mainFrame()->GroupConstructors->isEnabled() )
262     ActivateThisDialog();
263 }
264
265
266 //=================================================================================
267 // function : ValueChangedInSpinBox()
268 // purpose  :
269 //=================================================================================
270 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
271 {
272   displayPreview();
273 }
274
275
276 //=================================================================================
277 // function : createOperation
278 // purpose  :
279 //=================================================================================
280 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
281 {
282   return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
283 }
284
285 //=================================================================================
286 // function : isValid
287 // purpose  :
288 //=================================================================================
289 bool TransformationGUI_ScaleDlg::isValid( QString& /*msg*/)
290 {
291   return !( myObjects.length() == 0 || myPoint->_is_nil() || fabs( GetFactor()) <= 0.00001 );
292 }
293
294
295 //=================================================================================
296 // function : execute
297 // purpose  :
298 //=================================================================================
299 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
300 {
301   GEOM::GEOM_Object_var anObj;
302
303   if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
304     for ( int i = 0; i < myObjects.length(); i++ ) {
305       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
306       if ( !anObj->_is_nil() )
307         objects.push_back( anObj._retn() );
308     }
309   }
310   else {
311     for ( int i = 0; i < myObjects.length(); i++ ) {
312       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
313       if ( !anObj->_is_nil() )
314         objects.push_back( anObj._retn() );
315     }
316   }
317   return true;
318 }
319
320
321 //=================================================================================
322 // function : closeEvent
323 // purpose  :
324 //=================================================================================
325 void  TransformationGUI_ScaleDlg::closeEvent( QCloseEvent* e )
326 {
327   GEOMBase_Skeleton::closeEvent( e );
328 }
329
330
331 //=================================================================================
332 // function : GetFactor()
333 // purpose  :
334 //=================================================================================
335 double TransformationGUI_ScaleDlg::GetFactor() const
336 {
337   return GroupPoints->SpinBox_DX->value();
338 }
339
340
341 //=================================================================================
342 // function :  CreateCopyModeChanged()
343 // purpose  :
344 //=================================================================================
345 void TransformationGUI_ScaleDlg::CreateCopyModeChanged( bool isCreateCopy )
346 {
347   mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
348 }