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_RotationDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "TransformationGUI_RotationDlg.h"
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <BRepAdaptor_Curve.hxx>
36 //=================================================================================
37 // class : TransformationGUI_RotationDlg()
38 // purpose : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // TRUE to construct a modal dialog.
42 //=================================================================================
43 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
44 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49 setCaption(tr("GEOM_ROTATION_TITLE"));
51 /***************************************************************/
52 GroupConstructors->setTitle(tr("GEOM_ROTATION"));
53 RadioButton1->setPixmap(image0);
54 RadioButton2->close(TRUE);
55 RadioButton3->close(TRUE);
57 GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
58 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
59 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
60 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
61 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
62 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
63 GroupPoints->PushButton1->setPixmap(image1);
64 GroupPoints->PushButton2->setPixmap(image1);
66 Layout1->addWidget(GroupPoints, 1, 0);
67 /***************************************************************/
70 myTransformationGUI = theTransformationGUI;
75 //=================================================================================
76 // function : ~TransformationGUI_RotationDlg()
77 // purpose : Destroys the object and frees any allocated resources
78 //=================================================================================
79 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
81 // no need to delete child widgets, Qt does it all for us
85 //=================================================================================
88 //=================================================================================
89 void TransformationGUI_RotationDlg::Init()
92 myEditCurrentArgument = GroupPoints->LineEdit1;
95 myOkBase = myOkAxis = false;
97 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
99 double SpecificStep = 5;
100 /* min, max, step and decimals for spin boxes & initial values */
101 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
102 GroupPoints->SpinBox_DX->SetValue(myAngle);
104 /* signals and slots connections */
105 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
115 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
117 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
119 /* displays Dialog */
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void TransformationGUI_RotationDlg::ClickOnOk()
133 this->ClickOnApply();
139 //=================================================================================
140 // function : ClickOnApply()
142 //=================================================================================
143 void TransformationGUI_RotationDlg::ClickOnApply()
145 buttonApply->setFocus();
146 QAD_Application::getDesktop()->putInfo(tr(""));
147 if (mySimulationTopoDs.IsNull())
149 myGeomBase->EraseSimulationShape();
150 mySimulationTopoDs.Nullify();
152 if(myOkBase && myOkAxis)
153 myTransformationGUI->MakeRotationAndDisplay(myGeomShape, myLoc, myDir, myAngle*PI180);
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose : Called when selection as changed or other case
161 //=================================================================================
162 void TransformationGUI_RotationDlg::SelectionIntoArgument()
164 myGeomBase->EraseSimulationShape();
165 mySimulationTopoDs.Nullify();
166 myEditCurrentArgument->setText("");
167 QString aString = ""; /* name of selection */
169 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
171 if(myEditCurrentArgument == GroupPoints->LineEdit1)
173 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
180 Standard_Boolean testResult;
181 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
182 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
185 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
186 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
189 myEditCurrentArgument->setText(aString);
193 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
194 BRepAdaptor_Curve curv(TopoDS::Edge(S));
195 myDir = curv.Line().Direction();
196 myLoc = curv.Line().Location();
197 myEditCurrentArgument->setText(aString);
201 if(myOkBase && myOkAxis)
202 this->MakeRotationSimulationAndDisplay();
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
213 QPushButton* send = (QPushButton*)sender();
214 mySelection->ClearFilters();
216 if(send == GroupPoints->PushButton1) {
217 GroupPoints->LineEdit1->setFocus();
218 myEditCurrentArgument = GroupPoints->LineEdit1;
220 else if(send == GroupPoints->PushButton2) {
221 GroupPoints->LineEdit2->setFocus();
222 myEditCurrentArgument = GroupPoints->LineEdit2;
223 mySelection->AddFilter(myEdgeFilter);
225 this->SelectionIntoArgument();
231 //=================================================================================
232 // function : LineEditReturnPressed()
234 //=================================================================================
235 void TransformationGUI_RotationDlg::LineEditReturnPressed()
237 QLineEdit* send = (QLineEdit*)sender();
238 if(send == GroupPoints->LineEdit1)
239 myEditCurrentArgument = GroupPoints->LineEdit1;
240 else if (send == GroupPoints->LineEdit2)
241 myEditCurrentArgument = GroupPoints->LineEdit2;
245 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : ActivateThisDialog()
253 //=================================================================================
254 void TransformationGUI_RotationDlg::ActivateThisDialog()
256 GEOMBase_Skeleton::ActivateThisDialog();
257 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
258 GroupPoints->LineEdit1->setFocus();
259 myEditCurrentArgument = GroupPoints->LineEdit1;
260 if(!mySimulationTopoDs.IsNull())
261 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
266 //=================================================================================
267 // function : enterEvent()
269 //=================================================================================
270 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
272 if (GroupConstructors->isEnabled())
274 this->ActivateThisDialog();
279 //=================================================================================
280 // function : ValueChangedInSpinBox()
282 //=================================================================================
283 void TransformationGUI_RotationDlg::ValueChangedInSpinBox(double newValue)
286 if(myOkBase && myOkAxis)
287 MakeRotationSimulationAndDisplay();
292 //=================================================================================
293 // function : MakeRotationSimulationAndDisplay()
295 //=================================================================================
296 void TransformationGUI_RotationDlg::MakeRotationSimulationAndDisplay()
298 myGeomBase->EraseSimulationShape();
299 mySimulationTopoDs.Nullify();
302 gp_Ax1 AX(myLoc, myDir);
303 gp_Trsf theTransformation;
304 theTransformation.SetRotation(AX, myAngle*PI180);
305 BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
306 this->mySimulationTopoDs = myBRepTransformation.Shape();
307 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
309 catch(Standard_Failure) {
310 MESSAGE("Exception catched in MakeRotationSimulationAndDisplay");
317 //=================================================================================
318 // function : ReverseAngle()
319 // purpose : 'state' not used here
320 //=================================================================================
321 void TransformationGUI_RotationDlg::ReverseAngle(int state)
324 GroupPoints->SpinBox_DX->SetValue(myAngle);
325 if(myOkBase && myOkAxis)
326 MakeRotationSimulationAndDisplay();