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