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
30 #include "TransformationGUI_ScaleDlg.h"
32 #include <BRepBuilderAPI_Transform.hxx>
34 //=================================================================================
35 // class : TransformationGUI_ScaleDlg()
36 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
37 // name 'name' and widget flags set to 'f'.
38 // The dialog will by default be modeless, unless you set 'modal' to
39 // TRUE to construct a modal dialog.
40 //=================================================================================
41 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
42 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
44 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
45 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
47 setCaption(tr("GEOM_SCALE_TITLE"));
49 /***************************************************************/
50 GroupConstructors->setTitle(tr("GEOM_SCALE"));
51 RadioButton1->setPixmap(image0);
52 RadioButton2->close(TRUE);
53 RadioButton3->close(TRUE);
55 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
56 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
57 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
58 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
59 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
60 GroupPoints->PushButton1->setPixmap(image1);
61 GroupPoints->PushButton2->setPixmap(image1);
63 Layout1->addWidget(GroupPoints, 1, 0);
64 /***************************************************************/
67 myTransformationGUI = theTransformationGUI;
72 //=================================================================================
73 // function : ~TransformationGUI_ScaleDlg()
74 // purpose : Destroys the object and frees any allocated resources
75 //=================================================================================
76 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
78 /* no need to delete child widgets, Qt does it all for us */
82 //=================================================================================
85 //=================================================================================
86 void TransformationGUI_ScaleDlg::Init()
89 myEditCurrentArgument = GroupPoints->LineEdit1;
91 myPoint1.SetCoord(0.0, 0.0, 0.0);
92 myOkPoint1 = myOkBaseTopo = false;
95 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
97 double SpecificStep = 0.5;
98 /* min, max, step and decimals for spin boxes & initial values */
99 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
100 GroupPoints->SpinBox_DX->SetValue(myFactor);
102 /* signals and slots connections */
103 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
106 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
113 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
115 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
117 /* displays Dialog */
125 //=================================================================================
126 // function : ClickOnOk()
128 //=================================================================================
129 void TransformationGUI_ScaleDlg::ClickOnOk()
131 this->ClickOnApply();
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 void TransformationGUI_ScaleDlg::ClickOnApply()
143 buttonApply->setFocus();
144 QAD_Application::getDesktop()->putInfo(tr(""));
145 if (mySimulationTopoDs.IsNull())
147 myGeomBase->EraseSimulationShape();
148 mySimulationTopoDs.Nullify();
150 if(myOkBaseTopo && myOkPoint1)
151 myTransformationGUI->MakeScaleAndDisplay(myGeomShape, myPoint1, myFactor);
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
162 myGeomBase->EraseSimulationShape();
163 mySimulationTopoDs.Nullify();
164 myEditCurrentArgument->setText("");
165 QString aString = ""; /* name of selection */
167 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
169 if(myEditCurrentArgument == GroupPoints->LineEdit1)
170 myOkBaseTopo = false;
171 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
178 Standard_Boolean testResult;
179 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
180 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
183 /* gp_Pnt : not used */
184 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
185 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
188 GroupPoints->LineEdit1->setText(aString);
192 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint1)) {
193 GroupPoints->LineEdit2->setText(aString);
197 if(myOkPoint1 && myOkBaseTopo)
198 this->MakeScaleSimulationAndDisplay();
203 //=================================================================================
204 // function : LineEditReturnPressed()
206 //=================================================================================
207 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
209 QLineEdit* send = (QLineEdit*)sender();
210 if(send == GroupPoints->LineEdit1)
211 myEditCurrentArgument = GroupPoints->LineEdit1;
212 else if (send == GroupPoints->LineEdit2)
213 myEditCurrentArgument = GroupPoints->LineEdit2;
217 GEOMBase_Skeleton::LineEditReturnPressed();
222 //=================================================================================
223 // function : SetEditCurrentArgument()
225 //=================================================================================
226 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
228 QPushButton* send = (QPushButton*)sender();
229 mySelection->ClearFilters();
231 if(send == GroupPoints->PushButton1) {
232 GroupPoints->LineEdit1->setFocus();
233 myEditCurrentArgument = GroupPoints->LineEdit1;
235 else if(send == GroupPoints->PushButton2) {
236 GroupPoints->LineEdit2->setFocus();
237 myEditCurrentArgument = GroupPoints->LineEdit2;
238 mySelection->AddFilter(myVertexFilter);
240 this->SelectionIntoArgument();
246 //=================================================================================
247 // function : ActivateThisDialog()
249 //=================================================================================
250 void TransformationGUI_ScaleDlg::ActivateThisDialog()
252 GEOMBase_Skeleton::ActivateThisDialog();
253 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
254 GroupPoints->LineEdit1->setFocus();
255 myEditCurrentArgument = GroupPoints->LineEdit1;
256 if(!mySimulationTopoDs.IsNull())
257 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
268 if(GroupConstructors->isEnabled())
270 this->ActivateThisDialog();
275 //=================================================================================
276 // function : ValueChangedInSpinBox()
278 //=================================================================================
279 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox(double newValue)
282 if(fabs(myFactor) > 0.00001 && myOkPoint1 && myOkBaseTopo)
283 MakeScaleSimulationAndDisplay();
288 //=================================================================================
289 // function : MakeScaleSimulationAndDisplay()
291 //=================================================================================
292 void TransformationGUI_ScaleDlg::MakeScaleSimulationAndDisplay()
294 myGeomBase->EraseSimulationShape();
295 mySimulationTopoDs.Nullify();
298 gp_Trsf theTransformation;
299 theTransformation.SetScale(myPoint1, myFactor);
300 BRepBuilderAPI_Transform myBRepTransformation(myBaseTopo, theTransformation, Standard_False);
301 mySimulationTopoDs = myBRepTransformation.Shape();
302 if(mySimulationTopoDs.IsNull())
305 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
307 catch(Standard_Failure) {
308 MESSAGE("Exception catched in MakeScaleSimulationAndDisplay");