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