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
30 #include "TransformationGUI_TranslationDlg.h"
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include "QAD_Config.h"
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)
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48 setCaption(tr("GEOM_TRANSLATION_TITLE"));
50 /***************************************************************/
51 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
52 RadioButton1->setPixmap(image0);
53 RadioButton2->close(TRUE);
54 RadioButton3->close(TRUE);
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);
64 Layout1->addWidget(GroupPoints, 1, 0);
65 /***************************************************************/
68 myTransformationGUI = theTransformationGUI;
73 //=================================================================================
74 // function : ~TransformationGUI_TranslationDlg()
75 // purpose : Destroys the object and frees any allocated resources
76 //=================================================================================
77 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
79 // no need to delete child widgets, Qt does it all for us
83 //=================================================================================
86 //=================================================================================
87 void TransformationGUI_TranslationDlg::Init()
90 myEditCurrentArgument = GroupPoints->LineEdit1;
92 myVec.SetCoord(0.0, 0.0, 0.0);
95 /* Get setting of step value from file configuration */
96 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
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);
104 GroupPoints->SpinBox_DX->SetValue(0.0);
105 GroupPoints->SpinBox_DY->SetValue(0.0);
106 GroupPoints->SpinBox_DZ->SetValue(0.0);
108 /* signals and slots connections */
109 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
110 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
112 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
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)));
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)));
123 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
125 /* displays Dialog */
133 //=================================================================================
134 // function : ClickOnOk()
136 //=================================================================================
137 void TransformationGUI_TranslationDlg::ClickOnOk()
139 this->ClickOnApply();
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 void TransformationGUI_TranslationDlg::ClickOnApply()
151 buttonApply->setFocus();
152 QAD_Application::getDesktop()->putInfo(tr(""));
153 if (mySimulationTopoDs.IsNull())
155 myGeomBase->EraseSimulationShape();
156 mySimulationTopoDs.Nullify();
159 myTransformationGUI->MakeTranslationAndDisplay(myGeomShape, myVec);
164 //=================================================================================
165 // function : SelectionIntoArgument()
166 // purpose : Called when selection as changed or other case
167 //=================================================================================
168 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
170 myGeomBase->EraseSimulationShape();
171 mySimulationTopoDs.Nullify();
172 myEditCurrentArgument->setText("");
173 QString aString = ""; /* name of selection */
175 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
177 if(myEditCurrentArgument == GroupPoints->LineEdit1)
184 Standard_Boolean testResult;
185 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
186 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
189 /* gp_Pnt : not used */
190 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
191 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
194 GroupPoints->LineEdit1->setText(aString);
200 this->MakeTranslationSimulationAndDisplay();
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
211 QLineEdit* send = (QLineEdit*)sender();
212 if(send == GroupPoints->LineEdit1)
213 myEditCurrentArgument = GroupPoints->LineEdit1;
217 GEOMBase_Skeleton::LineEditReturnPressed();
222 //=================================================================================
223 // function : LineEditReturnPressed()
225 //=================================================================================
226 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
228 QPushButton* send = (QPushButton*)sender();
230 if(send == GroupPoints->PushButton1) {
231 GroupPoints->LineEdit1->setFocus();
232 myEditCurrentArgument = GroupPoints->LineEdit1;
233 this->SelectionIntoArgument();
240 //=================================================================================
241 // function : ActivateThisDialog()
243 //=================================================================================
244 void TransformationGUI_TranslationDlg::ActivateThisDialog()
246 GEOMBase_Skeleton::ActivateThisDialog();
247 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
248 if(!mySimulationTopoDs.IsNull())
249 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
254 //=================================================================================
255 // function : enterEvent()
257 //=================================================================================
258 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
260 if(GroupConstructors->isEnabled())
262 this->ActivateThisDialog();
267 //=================================================================================
268 // function : ValueChangedInSpinBox()
270 //=================================================================================
271 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox(double newValue)
273 QObject* send = (QObject*)sender();
274 Standard_Real Dx, Dy, Dz;
276 if(send == GroupPoints->SpinBox_DX) {
278 Dy = GroupPoints->SpinBox_DY->GetValue();
279 Dz = GroupPoints->SpinBox_DZ->GetValue();
281 else if(send == GroupPoints->SpinBox_DY) {
282 Dx = GroupPoints->SpinBox_DX->GetValue();
284 Dz = GroupPoints->SpinBox_DZ->GetValue();
286 else if(send == GroupPoints->SpinBox_DZ) {
287 Dx = GroupPoints->SpinBox_DX->GetValue();
288 Dy = GroupPoints->SpinBox_DY->GetValue();
292 myVec.SetCoord(Dx, Dy, Dz);
294 MakeTranslationSimulationAndDisplay();
299 //=================================================================================
300 // function : MakeTranslationSimulationAndDisplay()
302 //=================================================================================
303 void TransformationGUI_TranslationDlg::MakeTranslationSimulationAndDisplay()
305 myGeomBase->EraseSimulationShape();
306 mySimulationTopoDs.Nullify();
309 gp_Trsf theTransformation;
310 theTransformation.SetTranslation(myVec);
311 BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
312 mySimulationTopoDs = myBRepTransformation.Shape();
313 if(mySimulationTopoDs.IsNull())
316 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
318 catch(Standard_Failure) {
319 MESSAGE("Exception catched in MakeTranslationSimulationAndDisplay");