]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_ScaleDlg.cxx
Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 <BRepBuilderAPI_Transform.hxx>
32
33 #include "utilities.h"
34
35 using namespace std;
36
37 //=================================================================================
38 // class    : TransformationGUI_ScaleDlg()
39 // purpose  : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the 
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            TRUE to construct a modal dialog.
43 //=================================================================================
44 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
45   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 {
47   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
48   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49
50   setCaption(tr("GEOM_SCALE_TITLE"));
51
52   /***************************************************************/
53   GroupConstructors->setTitle(tr("GEOM_SCALE"));
54   RadioButton1->setPixmap(image0);
55   RadioButton2->close(TRUE);
56   RadioButton3->close(TRUE);
57
58   GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
59   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
60   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
61   GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
62   GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
63   GroupPoints->PushButton1->setPixmap(image1);
64   GroupPoints->PushButton2->setPixmap(image1);
65
66   Layout1->addWidget(GroupPoints, 1, 0);
67   /***************************************************************/
68
69   /* Initialisations */
70   myTransformationGUI = theTransformationGUI;
71   Init();
72 }
73
74
75 //=================================================================================
76 // function : ~TransformationGUI_ScaleDlg()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
80 {  
81   /* no need to delete child widgets, Qt does it all for us */
82 }
83
84
85 //=================================================================================
86 // function : Init()
87 // purpose  :
88 //=================================================================================
89 void TransformationGUI_ScaleDlg::Init()
90 {
91   /* init variables */
92   myEditCurrentArgument = GroupPoints->LineEdit1;
93
94   myPoint1.SetCoord(0.0, 0.0, 0.0);
95   myOkPoint1 = myOkBaseTopo = false;
96   myFactor = 2.0;
97
98   myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
99
100   double SpecificStep = 0.5;
101   /* min, max, step and decimals for spin boxes & initial values */
102   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
103   GroupPoints->SpinBox_DX->SetValue(myFactor);
104
105   /* signals and slots connections */
106   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108
109   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111
112   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114
115   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
116   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
117   
118   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
119
120   /* displays Dialog */
121   GroupPoints->show();
122   this->show();
123
124   return;
125 }
126
127
128 //=================================================================================
129 // function : ClickOnOk()
130 // purpose  :
131 //=================================================================================
132 void TransformationGUI_ScaleDlg::ClickOnOk()
133 {
134   this->ClickOnApply();
135   ClickOnCancel();
136   return;
137 }
138
139
140 //=================================================================================
141 // function : ClickOnApply()
142 // purpose  :
143 //=================================================================================
144 void TransformationGUI_ScaleDlg::ClickOnApply()
145 {
146   buttonApply->setFocus();
147   QAD_Application::getDesktop()->putInfo(tr(""));
148   if (mySimulationTopoDs.IsNull())
149     return;
150   myGeomBase->EraseSimulationShape();
151   mySimulationTopoDs.Nullify();
152
153   if(myOkBaseTopo && myOkPoint1)
154     myTransformationGUI->MakeScaleAndDisplay(myGeomShape, myPoint1, myFactor);
155   return;
156 }
157
158
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose  : Called when selection as changed or other case
162 //=================================================================================
163 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
164 {
165   myGeomBase->EraseSimulationShape();
166   mySimulationTopoDs.Nullify();
167   myEditCurrentArgument->setText("");
168   QString aString = ""; /* name of selection */
169   
170   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
171   if (nbSel != 1) {
172     if(myEditCurrentArgument == GroupPoints->LineEdit1)
173       myOkBaseTopo = false;
174     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
175       myOkPoint1 = false;
176     return;
177   }
178
179   /* nbSel == 1 */
180   TopoDS_Shape S;
181   Standard_Boolean testResult;
182   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
183   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
184     return;  
185  
186   /*  gp_Pnt : not used */
187   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
188     myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
189     if(!testResult)
190       return ;
191     GroupPoints->LineEdit1->setText(aString);
192     myBaseTopo = S; 
193     myOkBaseTopo = true;
194   }    
195   else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint1)) {
196     GroupPoints->LineEdit2->setText(aString);
197     myOkPoint1 = true;
198   }
199
200   if(myOkPoint1 && myOkBaseTopo)
201     this->MakeScaleSimulationAndDisplay();
202   return;
203 }
204
205
206 //=================================================================================
207 // function : LineEditReturnPressed()
208 // purpose  :
209 //=================================================================================
210 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
211 {
212   QLineEdit* send = (QLineEdit*)sender();
213   if(send == GroupPoints->LineEdit1)
214     myEditCurrentArgument = GroupPoints->LineEdit1;
215   else if (send == GroupPoints->LineEdit2)
216     myEditCurrentArgument = GroupPoints->LineEdit2;
217   else
218     return;
219
220   GEOMBase_Skeleton::LineEditReturnPressed();
221   return;
222 }
223
224
225 //=================================================================================
226 // function : SetEditCurrentArgument()
227 // purpose  :
228 //=================================================================================
229 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
230 {
231   QPushButton* send = (QPushButton*)sender();
232   mySelection->ClearFilters();
233
234   if(send == GroupPoints->PushButton1) {
235     GroupPoints->LineEdit1->setFocus();
236     myEditCurrentArgument = GroupPoints->LineEdit1;
237   }
238   else if(send == GroupPoints->PushButton2) {
239     GroupPoints->LineEdit2->setFocus();
240     myEditCurrentArgument = GroupPoints->LineEdit2;
241     mySelection->AddFilter(myVertexFilter);
242   }
243   this->SelectionIntoArgument();
244
245   return;
246 }
247
248
249 //=================================================================================
250 // function : ActivateThisDialog()
251 // purpose  :
252 //=================================================================================
253 void TransformationGUI_ScaleDlg::ActivateThisDialog()
254 {
255   GEOMBase_Skeleton::ActivateThisDialog();
256   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257   GroupPoints->LineEdit1->setFocus();
258   myEditCurrentArgument = GroupPoints->LineEdit1;
259   if(!mySimulationTopoDs.IsNull())
260     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
261   return;
262 }
263
264
265 //=================================================================================
266 // function : enterEvent()
267 // purpose  :
268 //=================================================================================
269 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
270 {
271   if(GroupConstructors->isEnabled())
272     return;
273   this->ActivateThisDialog();
274   return;
275 }
276
277
278 //=================================================================================
279 // function : ValueChangedInSpinBox()
280 // purpose  :
281 //=================================================================================
282 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox(double newValue)
283 {
284   myFactor = newValue;
285   if(fabs(myFactor) > 0.00001 && myOkPoint1 && myOkBaseTopo)
286     MakeScaleSimulationAndDisplay();
287   return;
288 }
289
290
291 //=================================================================================
292 // function : MakeScaleSimulationAndDisplay()
293 // purpose  :
294 //=================================================================================
295 void TransformationGUI_ScaleDlg::MakeScaleSimulationAndDisplay()
296 {
297   myGeomBase->EraseSimulationShape();
298   mySimulationTopoDs.Nullify();
299   
300   try {
301     gp_Trsf theTransformation;
302     theTransformation.SetScale(myPoint1, myFactor);
303     BRepBuilderAPI_Transform myBRepTransformation(myBaseTopo, theTransformation, Standard_False);
304     mySimulationTopoDs = myBRepTransformation.Shape();
305     if(mySimulationTopoDs.IsNull())
306       return;
307     else
308       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
309   }
310   catch(Standard_Failure) {
311     MESSAGE("Exception catched in MakeScaleSimulationAndDisplay");
312     return;
313   }
314   return;
315 }