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 QAD_Application::getDesktop()->putInfo(tr(""));
152 if (mySimulationTopoDs.IsNull())
154 myGeomBase->EraseSimulationShape();
155 mySimulationTopoDs.Nullify();
158 myTransformationGUI->MakeTranslationAndDisplay(myGeomShape, myVec);
163 //=================================================================================
164 // function : SelectionIntoArgument()
165 // purpose : Called when selection as changed or other case
166 //=================================================================================
167 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
169 myGeomBase->EraseSimulationShape();
170 mySimulationTopoDs.Nullify();
171 myEditCurrentArgument->setText("");
172 QString aString = ""; /* name of selection */
174 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
176 if(myEditCurrentArgument == GroupPoints->LineEdit1)
183 Standard_Boolean testResult;
184 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
185 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
188 /* gp_Pnt : not used */
189 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
190 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
193 GroupPoints->LineEdit1->setText(aString);
199 this->MakeTranslationSimulationAndDisplay();
204 //=================================================================================
205 // function : SetEditCurrentArgument()
207 //=================================================================================
208 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
210 QLineEdit* send = (QLineEdit*)sender();
211 if(send == GroupPoints->LineEdit1)
212 myEditCurrentArgument = GroupPoints->LineEdit1;
216 GEOMBase_Skeleton::LineEditReturnPressed();
221 //=================================================================================
222 // function : LineEditReturnPressed()
224 //=================================================================================
225 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
227 QPushButton* send = (QPushButton*)sender();
229 if(send == GroupPoints->PushButton1) {
230 GroupPoints->LineEdit1->setFocus();
231 myEditCurrentArgument = GroupPoints->LineEdit1;
232 this->SelectionIntoArgument();
239 //=================================================================================
240 // function : ActivateThisDialog()
242 //=================================================================================
243 void TransformationGUI_TranslationDlg::ActivateThisDialog()
245 GEOMBase_Skeleton::ActivateThisDialog();
246 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
247 if(!mySimulationTopoDs.IsNull())
248 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
253 //=================================================================================
254 // function : enterEvent()
256 //=================================================================================
257 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
259 if(GroupConstructors->isEnabled())
261 this->ActivateThisDialog();
266 //=================================================================================
267 // function : ValueChangedInSpinBox()
269 //=================================================================================
270 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox(double newValue)
272 QObject* send = (QObject*)sender();
273 Standard_Real Dx, Dy, Dz;
275 if(send == GroupPoints->SpinBox_DX) {
277 Dy = GroupPoints->SpinBox_DY->GetValue();
278 Dz = GroupPoints->SpinBox_DZ->GetValue();
280 else if(send == GroupPoints->SpinBox_DY) {
281 Dx = GroupPoints->SpinBox_DX->GetValue();
283 Dz = GroupPoints->SpinBox_DZ->GetValue();
285 else if(send == GroupPoints->SpinBox_DZ) {
286 Dx = GroupPoints->SpinBox_DX->GetValue();
287 Dy = GroupPoints->SpinBox_DY->GetValue();
291 myVec.SetCoord(Dx, Dy, Dz);
293 MakeTranslationSimulationAndDisplay();
298 //=================================================================================
299 // function : MakeTranslationSimulationAndDisplay()
301 //=================================================================================
302 void TransformationGUI_TranslationDlg::MakeTranslationSimulationAndDisplay()
304 myGeomBase->EraseSimulationShape();
305 mySimulationTopoDs.Nullify();
308 gp_Trsf theTransformation;
309 theTransformation.SetTranslation(myVec);
310 BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
311 mySimulationTopoDs = myBRepTransformation.Shape();
312 if(mySimulationTopoDs.IsNull())
315 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
317 catch(Standard_Failure) {
318 MESSAGE("Exception catched in MakeTranslationSimulationAndDisplay");