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