1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TransformationGUI_TranslationDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_TranslationDlg.h"
31 #include <BRepBuilderAPI_Transform.hxx>
32 #include "QAD_Config.h"
34 #include "utilities.h"
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)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_TRANSLATION_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->close(TRUE);
57 RadioButton3->close(TRUE);
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);
67 Layout1->addWidget(GroupPoints, 1, 0);
68 /***************************************************************/
71 myTransformationGUI = theTransformationGUI;
76 //=================================================================================
77 // function : ~TransformationGUI_TranslationDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
82 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void TransformationGUI_TranslationDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
95 myVec.SetCoord(0.0, 0.0, 0.0);
98 /* Get setting of step value from file configuration */
99 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
100 step = St.toDouble();
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);
107 GroupPoints->SpinBox_DX->SetValue(0.0);
108 GroupPoints->SpinBox_DY->SetValue(0.0);
109 GroupPoints->SpinBox_DZ->SetValue(0.0);
111 /* signals and slots connections */
112 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
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)));
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)));
126 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
128 /* displays Dialog */
136 //=================================================================================
137 // function : ClickOnOk()
139 //=================================================================================
140 void TransformationGUI_TranslationDlg::ClickOnOk()
142 this->ClickOnApply();
148 //=================================================================================
149 // function : ClickOnApply()
151 //=================================================================================
152 void TransformationGUI_TranslationDlg::ClickOnApply()
154 buttonApply->setFocus();
155 QAD_Application::getDesktop()->putInfo(tr(""));
156 if (mySimulationTopoDs.IsNull())
158 myGeomBase->EraseSimulationShape();
159 mySimulationTopoDs.Nullify();
162 myTransformationGUI->MakeTranslationAndDisplay(myGeomShape, myVec);
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose : Called when selection as changed or other case
170 //=================================================================================
171 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
173 myGeomBase->EraseSimulationShape();
174 mySimulationTopoDs.Nullify();
175 myEditCurrentArgument->setText("");
176 QString aString = ""; /* name of selection */
178 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
180 if(myEditCurrentArgument == GroupPoints->LineEdit1)
187 Standard_Boolean testResult;
188 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
189 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
192 /* gp_Pnt : not used */
193 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
194 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
197 GroupPoints->LineEdit1->setText(aString);
203 this->MakeTranslationSimulationAndDisplay();
208 //=================================================================================
209 // function : SetEditCurrentArgument()
211 //=================================================================================
212 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
214 QLineEdit* send = (QLineEdit*)sender();
215 if(send == GroupPoints->LineEdit1)
216 myEditCurrentArgument = GroupPoints->LineEdit1;
220 GEOMBase_Skeleton::LineEditReturnPressed();
225 //=================================================================================
226 // function : LineEditReturnPressed()
228 //=================================================================================
229 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
231 QPushButton* send = (QPushButton*)sender();
233 if(send == GroupPoints->PushButton1) {
234 GroupPoints->LineEdit1->setFocus();
235 myEditCurrentArgument = GroupPoints->LineEdit1;
236 this->SelectionIntoArgument();
243 //=================================================================================
244 // function : ActivateThisDialog()
246 //=================================================================================
247 void TransformationGUI_TranslationDlg::ActivateThisDialog()
249 GEOMBase_Skeleton::ActivateThisDialog();
250 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
251 if(!mySimulationTopoDs.IsNull())
252 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
257 //=================================================================================
258 // function : enterEvent()
260 //=================================================================================
261 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
263 if(GroupConstructors->isEnabled())
265 this->ActivateThisDialog();
270 //=================================================================================
271 // function : ValueChangedInSpinBox()
273 //=================================================================================
274 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox(double newValue)
276 QObject* send = (QObject*)sender();
277 Standard_Real Dx, Dy, Dz;
279 if(send == GroupPoints->SpinBox_DX) {
281 Dy = GroupPoints->SpinBox_DY->GetValue();
282 Dz = GroupPoints->SpinBox_DZ->GetValue();
284 else if(send == GroupPoints->SpinBox_DY) {
285 Dx = GroupPoints->SpinBox_DX->GetValue();
287 Dz = GroupPoints->SpinBox_DZ->GetValue();
289 else if(send == GroupPoints->SpinBox_DZ) {
290 Dx = GroupPoints->SpinBox_DX->GetValue();
291 Dy = GroupPoints->SpinBox_DY->GetValue();
295 myVec.SetCoord(Dx, Dy, Dz);
297 MakeTranslationSimulationAndDisplay();
302 //=================================================================================
303 // function : MakeTranslationSimulationAndDisplay()
305 //=================================================================================
306 void TransformationGUI_TranslationDlg::MakeTranslationSimulationAndDisplay()
308 myGeomBase->EraseSimulationShape();
309 mySimulationTopoDs.Nullify();
312 gp_Trsf theTransformation;
313 theTransformation.SetTranslation(myVec);
314 BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
315 mySimulationTopoDs = myBRepTransformation.Shape();
316 if(mySimulationTopoDs.IsNull())
319 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
321 catch(Standard_Failure) {
322 MESSAGE("Exception catched in MakeTranslationSimulationAndDisplay");