1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : BasicGUI_EllipseDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "BasicGUI_EllipseDlg.h"
31 #include <gp_Elips.hxx>
32 #include <BRepBuilderAPI_MakeEdge.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include "QAD_Config.h"
36 #include "utilities.h"
40 //=================================================================================
41 // class : BasicGUI_EllipseDlg()
42 // purpose : Constructs a BasicGUI_EllipseDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ELLIPSE_PV")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_ELLIPSE_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->close(TRUE);
59 RadioButton3->close(TRUE);
61 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
65 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MINOR"));
66 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MAJOR"));
67 GroupPoints->PushButton1->setPixmap(image1);
68 GroupPoints->PushButton2->setPixmap(image1);
70 Layout1->addWidget(GroupPoints, 1, 0);
71 /***************************************************************/
74 myBasicGUI = theBasicGUI;
79 //=================================================================================
80 // function : ~BasicGUI_EllipseDlg()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
85 // no need to delete child widgets, Qt does it all for us
89 //=================================================================================
92 //=================================================================================
93 void BasicGUI_EllipseDlg::Init()
96 myEditCurrentArgument = GroupPoints->LineEdit1;
98 myMajorRadius = 200.0;
99 myMinorRadius = 100.0;
100 myOkPoint = myOkDir = false;
102 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
103 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
104 mySelection->AddFilter(myVertexFilter);
106 /* Get setting of step value from file configuration */
107 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
108 step = St.toDouble();
110 /* min, max, step and decimals for spin boxes & initial values */
111 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
112 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
113 GroupPoints->SpinBox_DX->SetValue(myMajorRadius);
114 GroupPoints->SpinBox_DY->SetValue(myMinorRadius);
116 /* signals and slots connections */
117 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
127 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
129 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
130 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
132 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
134 /* displays Dialog */
142 //=================================================================================
143 // function : ClickOnOk()
145 //=================================================================================
146 void BasicGUI_EllipseDlg::ClickOnOk()
148 this->ClickOnApply();
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 void BasicGUI_EllipseDlg::ClickOnApply()
159 buttonApply->setFocus();
160 QAD_Application::getDesktop()->putInfo(tr(""));
161 if (mySimulationTopoDs.IsNull())
163 myGeomBase->EraseSimulationShape();
164 mySimulationTopoDs.Nullify();
166 if(myOkPoint && myOkDir)
167 myBasicGUI->MakeEllipseAndDisplay(myPoint, myDir, myMajorRadius, myMinorRadius);
171 //=================================================================================
172 // function : SelectionIntoArgument()
173 // purpose : Called when selection as changed or other case
174 //=================================================================================
175 void BasicGUI_EllipseDlg::SelectionIntoArgument()
177 myGeomBase->EraseSimulationShape();
178 mySimulationTopoDs.Nullify();
179 myEditCurrentArgument->setText("");
180 QString aString = ""; /* name of selection */
182 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
184 if(myEditCurrentArgument == GroupPoints->LineEdit1)
186 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
193 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
196 /* gp_Pnt : not used */
197 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint)) {
198 GroupPoints->LineEdit1->setText(aString);
201 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
202 BRepAdaptor_Curve curv(TopoDS::Edge(S));
203 myDir = curv.Line().Direction();
204 GroupPoints->LineEdit2->setText(aString);
208 if(myOkPoint && myOkDir)
209 this->MakeEllipseSimulationAndDisplay();
214 //=================================================================================
215 // function : SetEditCurrentArgument()
217 //=================================================================================
218 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
220 QPushButton* send = (QPushButton*)sender();
221 mySelection->ClearFilters();
223 if(send == GroupPoints->PushButton1) {
224 GroupPoints->LineEdit1->setFocus();
225 myEditCurrentArgument = GroupPoints->LineEdit1;
226 mySelection->AddFilter(myVertexFilter);
228 else if(send == GroupPoints->PushButton2) {
229 GroupPoints->LineEdit2->setFocus();
230 myEditCurrentArgument = GroupPoints->LineEdit2;
231 mySelection->AddFilter(myEdgeFilter);
233 this->SelectionIntoArgument();
238 //=================================================================================
239 // function : LineEditReturnPressed()
241 //=================================================================================
242 void BasicGUI_EllipseDlg::LineEditReturnPressed()
244 QLineEdit* send = (QLineEdit*)sender();
245 if(send == GroupPoints->LineEdit1)
246 myEditCurrentArgument = GroupPoints->LineEdit1;
247 else if (send == GroupPoints->LineEdit2)
248 myEditCurrentArgument = GroupPoints->LineEdit2;
252 GEOMBase_Skeleton::LineEditReturnPressed();
257 //=================================================================================
258 // function : ActivateThisDialog()
260 //=================================================================================
261 void BasicGUI_EllipseDlg::ActivateThisDialog()
263 GEOMBase_Skeleton::ActivateThisDialog();
264 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
265 GroupPoints->LineEdit1->setFocus();
266 myEditCurrentArgument = GroupPoints->LineEdit1;
267 mySelection->AddFilter(myVertexFilter);
268 if(!mySimulationTopoDs.IsNull())
269 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
274 //=================================================================================
275 // function : enterEvent()
277 //=================================================================================
278 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
280 if (GroupConstructors->isEnabled())
282 this->ActivateThisDialog();
287 //=================================================================================
288 // function : ValueChangedInSpinBox()
290 //=================================================================================
291 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
293 QObject* send = (QObject*)sender();
295 if(send == GroupPoints->SpinBox_DX )
296 myMajorRadius = newValue;
297 else if(send == GroupPoints->SpinBox_DY)
298 myMinorRadius = newValue;
300 if (myOkPoint && myOkDir)
301 MakeEllipseSimulationAndDisplay();
306 //=================================================================================
307 // function : MakeEllipseSimulationAndDisplay()
309 //=================================================================================
310 void BasicGUI_EllipseDlg::MakeEllipseSimulationAndDisplay()
312 myGeomBase->EraseSimulationShape();
313 mySimulationTopoDs.Nullify();
315 if(myMajorRadius < myMinorRadius)
319 gp_Ax2 anAxis(myPoint, myDir);
320 gp_Elips ellipse(anAxis, myMajorRadius, myMinorRadius);
321 BRepBuilderAPI_MakeEdge MakeEdge(ellipse);
322 mySimulationTopoDs = MakeEdge.Shape();
323 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
325 catch(Standard_Failure) {
326 MESSAGE("Exception catched in MakeEllipseSimulationAndDisplay");