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 QAD_Application::getDesktop()->putInfo(tr(""));
144 if (mySimulationTopoDs.IsNull())
146 myGeomBase->EraseSimulationShape();
147 mySimulationTopoDs.Nullify();
149 if(myOkBaseTopo && myOkPoint1)
150 myTransformationGUI->MakeScaleAndDisplay(myGeomShape, myPoint1, myFactor);
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection as changed or other case
158 //=================================================================================
159 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
161 myGeomBase->EraseSimulationShape();
162 mySimulationTopoDs.Nullify();
163 myEditCurrentArgument->setText("");
164 QString aString = ""; /* name of selection */
166 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
168 if(myEditCurrentArgument == GroupPoints->LineEdit1)
169 myOkBaseTopo = false;
170 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
177 Standard_Boolean testResult;
178 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
179 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
182 /* gp_Pnt : not used */
183 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
184 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
187 GroupPoints->LineEdit1->setText(aString);
191 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint1)) {
192 GroupPoints->LineEdit2->setText(aString);
196 if(myOkPoint1 && myOkBaseTopo)
197 this->MakeScaleSimulationAndDisplay();
202 //=================================================================================
203 // function : LineEditReturnPressed()
205 //=================================================================================
206 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
208 QLineEdit* send = (QLineEdit*)sender();
209 if(send == GroupPoints->LineEdit1)
210 myEditCurrentArgument = GroupPoints->LineEdit1;
211 else if (send == GroupPoints->LineEdit2)
212 myEditCurrentArgument = GroupPoints->LineEdit2;
216 GEOMBase_Skeleton::LineEditReturnPressed();
221 //=================================================================================
222 // function : SetEditCurrentArgument()
224 //=================================================================================
225 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
227 QPushButton* send = (QPushButton*)sender();
228 mySelection->ClearFilters();
230 if(send == GroupPoints->PushButton1) {
231 GroupPoints->LineEdit1->setFocus();
232 myEditCurrentArgument = GroupPoints->LineEdit1;
234 else if(send == GroupPoints->PushButton2) {
235 GroupPoints->LineEdit2->setFocus();
236 myEditCurrentArgument = GroupPoints->LineEdit2;
237 mySelection->AddFilter(myVertexFilter);
239 this->SelectionIntoArgument();
245 //=================================================================================
246 // function : ActivateThisDialog()
248 //=================================================================================
249 void TransformationGUI_ScaleDlg::ActivateThisDialog()
251 GEOMBase_Skeleton::ActivateThisDialog();
252 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
253 GroupPoints->LineEdit1->setFocus();
254 myEditCurrentArgument = GroupPoints->LineEdit1;
255 if(!mySimulationTopoDs.IsNull())
256 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
261 //=================================================================================
262 // function : enterEvent()
264 //=================================================================================
265 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
267 if(GroupConstructors->isEnabled())
269 this->ActivateThisDialog();
274 //=================================================================================
275 // function : ValueChangedInSpinBox()
277 //=================================================================================
278 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox(double newValue)
281 if(fabs(myFactor) > 0.00001 && myOkPoint1 && myOkBaseTopo)
282 MakeScaleSimulationAndDisplay();
287 //=================================================================================
288 // function : MakeScaleSimulationAndDisplay()
290 //=================================================================================
291 void TransformationGUI_ScaleDlg::MakeScaleSimulationAndDisplay()
293 myGeomBase->EraseSimulationShape();
294 mySimulationTopoDs.Nullify();
297 gp_Trsf theTransformation;
298 theTransformation.SetScale(myPoint1, myFactor);
299 BRepBuilderAPI_Transform myBRepTransformation(myBaseTopo, theTransformation, Standard_False);
300 mySimulationTopoDs = myBRepTransformation.Shape();
301 if(mySimulationTopoDs.IsNull())
304 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
306 catch(Standard_Failure) {
307 MESSAGE("Exception catched in MakeScaleSimulationAndDisplay");