]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_TranslationDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[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   buttonApply->setFocus();
152   QAD_Application::getDesktop()->putInfo(tr(""));
153   if (mySimulationTopoDs.IsNull())
154     return;
155   myGeomBase->EraseSimulationShape();
156   mySimulationTopoDs.Nullify();
157
158   if(myOkBase)
159     myTransformationGUI->MakeTranslationAndDisplay(myGeomShape, myVec);
160   return;
161 }
162
163
164 //=================================================================================
165 // function : SelectionIntoArgument()
166 // purpose  : Called when selection as changed or other case
167 //=================================================================================
168 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
169 {
170   myGeomBase->EraseSimulationShape();
171   mySimulationTopoDs.Nullify();
172   myEditCurrentArgument->setText("");
173   QString aString = ""; /* name of selection */
174   
175   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
176   if (nbSel != 1) {
177     if(myEditCurrentArgument == GroupPoints->LineEdit1)
178       myOkBase = false;
179     return;
180   }
181
182   /* nbSel == 1 */
183   TopoDS_Shape S;
184   Standard_Boolean testResult;
185   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
186   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
187     return;  
188  
189   /*  gp_Pnt : not used */
190   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
191     myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
192     if(!testResult)
193       return ;
194     GroupPoints->LineEdit1->setText(aString);
195     myBase = S; 
196     myOkBase = true;
197   }
198
199   if(myOkBase)
200     this->MakeTranslationSimulationAndDisplay();
201   return;
202 }
203
204
205 //=================================================================================
206 // function : SetEditCurrentArgument()
207 // purpose  :
208 //=================================================================================
209 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
210 {
211   QLineEdit* send = (QLineEdit*)sender();
212   if(send == GroupPoints->LineEdit1)
213     myEditCurrentArgument = GroupPoints->LineEdit1;
214   else
215     return;
216
217   GEOMBase_Skeleton::LineEditReturnPressed();
218   return;
219 }
220
221
222 //=================================================================================
223 // function : LineEditReturnPressed()
224 // purpose  :
225 //=================================================================================
226 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
227 {    
228   QPushButton* send = (QPushButton*)sender();
229
230   if(send == GroupPoints->PushButton1) {
231     GroupPoints->LineEdit1->setFocus();
232     myEditCurrentArgument = GroupPoints->LineEdit1;
233     this->SelectionIntoArgument();
234   }
235
236   return;
237 }
238
239
240 //=================================================================================
241 // function : ActivateThisDialog()
242 // purpose  :
243 //=================================================================================
244 void TransformationGUI_TranslationDlg::ActivateThisDialog()
245 {
246   GEOMBase_Skeleton::ActivateThisDialog();
247   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
248   if(!mySimulationTopoDs.IsNull())
249     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
250   return;
251 }
252
253
254 //=================================================================================
255 // function : enterEvent()
256 // purpose  :
257 //=================================================================================
258 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
259 {
260   if(GroupConstructors->isEnabled())
261     return;
262   this->ActivateThisDialog();
263   return;
264 }
265
266
267 //=================================================================================
268 // function : ValueChangedInSpinBox()
269 // purpose  :
270 //=================================================================================
271 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox(double newValue)
272 {
273   QObject* send = (QObject*)sender();
274   Standard_Real Dx, Dy, Dz;
275
276   if(send == GroupPoints->SpinBox_DX) {
277     Dx = newValue;
278     Dy = GroupPoints->SpinBox_DY->GetValue();
279     Dz = GroupPoints->SpinBox_DZ->GetValue();
280   }
281   else if(send == GroupPoints->SpinBox_DY) {
282     Dx = GroupPoints->SpinBox_DX->GetValue();
283     Dy = newValue;
284     Dz = GroupPoints->SpinBox_DZ->GetValue();
285   }
286   else if(send == GroupPoints->SpinBox_DZ) {
287     Dx = GroupPoints->SpinBox_DX->GetValue();
288     Dy = GroupPoints->SpinBox_DY->GetValue();
289     Dz = newValue;
290   }
291
292   myVec.SetCoord(Dx, Dy, Dz);
293   if(myOkBase)
294     MakeTranslationSimulationAndDisplay();
295   return;
296 }
297
298
299 //=================================================================================
300 // function : MakeTranslationSimulationAndDisplay()
301 // purpose  :
302 //=================================================================================
303 void TransformationGUI_TranslationDlg::MakeTranslationSimulationAndDisplay()
304 {
305   myGeomBase->EraseSimulationShape();
306   mySimulationTopoDs.Nullify();
307   
308   try {
309     gp_Trsf theTransformation;
310     theTransformation.SetTranslation(myVec);
311     BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
312     mySimulationTopoDs = myBRepTransformation.Shape();
313     if(mySimulationTopoDs.IsNull())
314       return;
315     else
316       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
317   }
318   catch(Standard_Failure) {
319     MESSAGE("Exception catched in MakeTranslationSimulationAndDisplay");
320     return;
321   }
322   return;
323 }