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