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
29 #include "BasicGUI_EllipseDlg.h"
32 #include <gp_Elips.hxx>
33 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include "QAD_Config.h"
37 //=================================================================================
38 // class : BasicGUI_EllipseDlg()
39 // purpose : Constructs a BasicGUI_EllipseDlg 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 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, 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_ELLIPSE_PV")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_ELLIPSE_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->close(TRUE);
56 RadioButton3->close(TRUE);
58 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
59 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
60 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
61 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
62 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MINOR"));
63 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MAJOR"));
64 GroupPoints->PushButton1->setPixmap(image1);
65 GroupPoints->PushButton2->setPixmap(image1);
67 Layout1->addWidget(GroupPoints, 1, 0);
68 /***************************************************************/
71 myBasicGUI = theBasicGUI;
76 //=================================================================================
77 // function : ~BasicGUI_EllipseDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
82 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void BasicGUI_EllipseDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
95 myMajorRadius = 200.0;
96 myMinorRadius = 100.0;
97 myOkPoint = myOkDir = false;
99 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
100 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
101 mySelection->AddFilter(myVertexFilter);
103 /* Get setting of step value from file configuration */
104 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
105 step = St.toDouble();
107 /* min, max, step and decimals for spin boxes & initial values */
108 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
109 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
110 GroupPoints->SpinBox_DX->SetValue(myMajorRadius);
111 GroupPoints->SpinBox_DY->SetValue(myMinorRadius);
113 /* signals and slots connections */
114 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
117 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
124 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
126 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
127 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
129 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
131 /* displays Dialog */
139 //=================================================================================
140 // function : ClickOnOk()
142 //=================================================================================
143 void BasicGUI_EllipseDlg::ClickOnOk()
145 this->ClickOnApply();
150 //=================================================================================
151 // function : ClickOnApply()
153 //=================================================================================
154 void BasicGUI_EllipseDlg::ClickOnApply()
156 QAD_Application::getDesktop()->putInfo(tr(""));
157 if (mySimulationTopoDs.IsNull())
159 myGeomBase->EraseSimulationShape();
160 mySimulationTopoDs.Nullify();
162 if(myOkPoint && myOkDir)
163 myBasicGUI->MakeEllipseAndDisplay(myPoint, myDir, myMajorRadius, myMinorRadius);
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose : Called when selection as changed or other case
170 //=================================================================================
171 void BasicGUI_EllipseDlg::SelectionIntoArgument()
173 myGeomBase->EraseSimulationShape();
174 mySimulationTopoDs.Nullify();
175 myEditCurrentArgument->setText("");
176 QString aString = ""; /* name of selection */
178 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
180 if(myEditCurrentArgument == GroupPoints->LineEdit1)
182 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
189 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
192 /* gp_Pnt : not used */
193 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint)) {
194 GroupPoints->LineEdit1->setText(aString);
197 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
198 BRepAdaptor_Curve curv(TopoDS::Edge(S));
199 myDir = curv.Line().Direction();
200 GroupPoints->LineEdit2->setText(aString);
204 if(myOkPoint && myOkDir)
205 this->MakeEllipseSimulationAndDisplay();
210 //=================================================================================
211 // function : SetEditCurrentArgument()
213 //=================================================================================
214 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
216 QPushButton* send = (QPushButton*)sender();
217 mySelection->ClearFilters();
219 if(send == GroupPoints->PushButton1) {
220 GroupPoints->LineEdit1->setFocus();
221 myEditCurrentArgument = GroupPoints->LineEdit1;
222 mySelection->AddFilter(myVertexFilter);
224 else if(send == GroupPoints->PushButton2) {
225 GroupPoints->LineEdit2->setFocus();
226 myEditCurrentArgument = GroupPoints->LineEdit2;
227 mySelection->AddFilter(myEdgeFilter);
229 this->SelectionIntoArgument();
234 //=================================================================================
235 // function : LineEditReturnPressed()
237 //=================================================================================
238 void BasicGUI_EllipseDlg::LineEditReturnPressed()
240 QLineEdit* send = (QLineEdit*)sender();
241 if(send == GroupPoints->LineEdit1)
242 myEditCurrentArgument = GroupPoints->LineEdit1;
243 else if (send == GroupPoints->LineEdit2)
244 myEditCurrentArgument = GroupPoints->LineEdit2;
248 GEOMBase_Skeleton::LineEditReturnPressed();
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void BasicGUI_EllipseDlg::ActivateThisDialog()
259 GEOMBase_Skeleton::ActivateThisDialog();
260 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261 GroupPoints->LineEdit1->setFocus();
262 myEditCurrentArgument = GroupPoints->LineEdit1;
263 mySelection->AddFilter(myVertexFilter);
264 if(!mySimulationTopoDs.IsNull())
265 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
270 //=================================================================================
271 // function : enterEvent()
273 //=================================================================================
274 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
276 if (GroupConstructors->isEnabled())
278 this->ActivateThisDialog();
283 //=================================================================================
284 // function : ValueChangedInSpinBox()
286 //=================================================================================
287 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
289 QObject* send = (QObject*)sender();
291 if(send == GroupPoints->SpinBox_DX )
292 myMajorRadius = newValue;
293 else if(send == GroupPoints->SpinBox_DY)
294 myMinorRadius = newValue;
296 if (myOkPoint && myOkDir)
297 MakeEllipseSimulationAndDisplay();
302 //=================================================================================
303 // function : MakeEllipseSimulationAndDisplay()
305 //=================================================================================
306 void BasicGUI_EllipseDlg::MakeEllipseSimulationAndDisplay()
308 myGeomBase->EraseSimulationShape();
309 mySimulationTopoDs.Nullify();
311 if(myMajorRadius < myMinorRadius)
315 gp_Ax2 anAxis(myPoint, myDir);
316 gp_Elips ellipse(anAxis, myMajorRadius, myMinorRadius);
317 BRepBuilderAPI_MakeEdge MakeEdge(ellipse);
318 mySimulationTopoDs = MakeEdge.Shape();
319 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
321 catch(Standard_Failure) {
322 MESSAGE("Exception catched in MakeEllipseSimulationAndDisplay");