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_ScaleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_ScaleDlg.h"
31 #include <BRepBuilderAPI_Transform.hxx>
33 #include "utilities.h"
37 //=================================================================================
38 // class : TransformationGUI_ScaleDlg()
39 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
45 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_SCALE_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_SCALE"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->close(TRUE);
56 RadioButton3->close(TRUE);
58 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
59 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
60 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
61 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
62 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
63 GroupPoints->PushButton1->setPixmap(image1);
64 GroupPoints->PushButton2->setPixmap(image1);
66 Layout1->addWidget(GroupPoints, 1, 0);
67 /***************************************************************/
70 myTransformationGUI = theTransformationGUI;
75 //=================================================================================
76 // function : ~TransformationGUI_ScaleDlg()
77 // purpose : Destroys the object and frees any allocated resources
78 //=================================================================================
79 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
81 /* no need to delete child widgets, Qt does it all for us */
85 //=================================================================================
88 //=================================================================================
89 void TransformationGUI_ScaleDlg::Init()
92 myEditCurrentArgument = GroupPoints->LineEdit1;
94 myPoint1.SetCoord(0.0, 0.0, 0.0);
95 myOkPoint1 = myOkBaseTopo = false;
98 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
100 double SpecificStep = 0.5;
101 /* min, max, step and decimals for spin boxes & initial values */
102 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
103 GroupPoints->SpinBox_DX->SetValue(myFactor);
105 /* signals and slots connections */
106 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
116 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
118 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
120 /* displays Dialog */
128 //=================================================================================
129 // function : ClickOnOk()
131 //=================================================================================
132 void TransformationGUI_ScaleDlg::ClickOnOk()
134 this->ClickOnApply();
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 void TransformationGUI_ScaleDlg::ClickOnApply()
146 buttonApply->setFocus();
147 QAD_Application::getDesktop()->putInfo(tr(""));
148 if (mySimulationTopoDs.IsNull())
150 myGeomBase->EraseSimulationShape();
151 mySimulationTopoDs.Nullify();
153 if(myOkBaseTopo && myOkPoint1)
154 myTransformationGUI->MakeScaleAndDisplay(myGeomShape, myPoint1, myFactor);
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose : Called when selection as changed or other case
162 //=================================================================================
163 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
165 myGeomBase->EraseSimulationShape();
166 mySimulationTopoDs.Nullify();
167 myEditCurrentArgument->setText("");
168 QString aString = ""; /* name of selection */
170 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
172 if(myEditCurrentArgument == GroupPoints->LineEdit1)
173 myOkBaseTopo = false;
174 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
181 Standard_Boolean testResult;
182 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
183 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
186 /* gp_Pnt : not used */
187 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
188 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
191 GroupPoints->LineEdit1->setText(aString);
195 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint1)) {
196 GroupPoints->LineEdit2->setText(aString);
200 if(myOkPoint1 && myOkBaseTopo)
201 this->MakeScaleSimulationAndDisplay();
206 //=================================================================================
207 // function : LineEditReturnPressed()
209 //=================================================================================
210 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
212 QLineEdit* send = (QLineEdit*)sender();
213 if(send == GroupPoints->LineEdit1)
214 myEditCurrentArgument = GroupPoints->LineEdit1;
215 else if (send == GroupPoints->LineEdit2)
216 myEditCurrentArgument = GroupPoints->LineEdit2;
220 GEOMBase_Skeleton::LineEditReturnPressed();
225 //=================================================================================
226 // function : SetEditCurrentArgument()
228 //=================================================================================
229 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
231 QPushButton* send = (QPushButton*)sender();
232 mySelection->ClearFilters();
234 if(send == GroupPoints->PushButton1) {
235 GroupPoints->LineEdit1->setFocus();
236 myEditCurrentArgument = GroupPoints->LineEdit1;
238 else if(send == GroupPoints->PushButton2) {
239 GroupPoints->LineEdit2->setFocus();
240 myEditCurrentArgument = GroupPoints->LineEdit2;
241 mySelection->AddFilter(myVertexFilter);
243 this->SelectionIntoArgument();
249 //=================================================================================
250 // function : ActivateThisDialog()
252 //=================================================================================
253 void TransformationGUI_ScaleDlg::ActivateThisDialog()
255 GEOMBase_Skeleton::ActivateThisDialog();
256 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 GroupPoints->LineEdit1->setFocus();
258 myEditCurrentArgument = GroupPoints->LineEdit1;
259 if(!mySimulationTopoDs.IsNull())
260 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
265 //=================================================================================
266 // function : enterEvent()
268 //=================================================================================
269 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
271 if(GroupConstructors->isEnabled())
273 this->ActivateThisDialog();
278 //=================================================================================
279 // function : ValueChangedInSpinBox()
281 //=================================================================================
282 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox(double newValue)
285 if(fabs(myFactor) > 0.00001 && myOkPoint1 && myOkBaseTopo)
286 MakeScaleSimulationAndDisplay();
291 //=================================================================================
292 // function : MakeScaleSimulationAndDisplay()
294 //=================================================================================
295 void TransformationGUI_ScaleDlg::MakeScaleSimulationAndDisplay()
297 myGeomBase->EraseSimulationShape();
298 mySimulationTopoDs.Nullify();
301 gp_Trsf theTransformation;
302 theTransformation.SetScale(myPoint1, myFactor);
303 BRepBuilderAPI_Transform myBRepTransformation(myBaseTopo, theTransformation, Standard_False);
304 mySimulationTopoDs = myBRepTransformation.Shape();
305 if(mySimulationTopoDs.IsNull())
308 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
310 catch(Standard_Failure) {
311 MESSAGE("Exception catched in MakeScaleSimulationAndDisplay");