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