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 : BasicGUI_CircleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_CircleDlg.h"
32 #include <gp_Circ.hxx>
33 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include "QAD_Config.h"
37 #include "utilities.h"
41 //=================================================================================
42 // class : BasicGUI_CircleDlg()
43 // purpose : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 BasicGUI_CircleDlg::BasicGUI_CircleDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_CIRCLE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->close(TRUE);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
63 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
65 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
66 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
67 GroupPoints->PushButton1->setPixmap(image1);
68 GroupPoints->PushButton2->setPixmap(image1);
70 Layout1->addWidget(GroupPoints, 1, 0);
71 /***************************************************************/
74 myBasicGUI = theBasicGUI;
79 //=================================================================================
80 // function : ~BasicGUI_CircleDlg()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
85 // no need to delete child widgets, Qt does it all for us
89 //=================================================================================
92 //=================================================================================
93 void BasicGUI_CircleDlg::Init()
96 myEditCurrentArgument = GroupPoints->LineEdit1;
99 myOkPoint1 = myOkDir = false;
101 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
102 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
103 mySelection->AddFilter(myVertexFilter);
105 /* Get setting of step value from file configuration */
106 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
107 step = St.toDouble();
109 /* min, max, step and decimals for spin boxes & initial values */
110 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
111 GroupPoints->SpinBox_DX->SetValue(myRadius);
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(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
126 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
128 /* displays Dialog */
136 //=================================================================================
137 // function : ClickOnOk()
139 //=================================================================================
140 void BasicGUI_CircleDlg::ClickOnOk()
142 this->ClickOnApply();
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 void BasicGUI_CircleDlg::ClickOnApply()
153 buttonApply->setFocus();
154 QAD_Application::getDesktop()->putInfo(tr(""));
155 if (mySimulationTopoDs.IsNull())
157 myGeomBase->EraseSimulationShape();
158 mySimulationTopoDs.Nullify();
160 if(myOkPoint1 && myOkDir)
161 myBasicGUI->MakeCircleAndDisplay(myPoint1, myDir, myRadius);
166 //=================================================================================
167 // function : SelectionIntoArgument()
168 // purpose : Called when selection as changed or other case
169 //=================================================================================
170 void BasicGUI_CircleDlg::SelectionIntoArgument()
172 myGeomBase->EraseSimulationShape();
173 mySimulationTopoDs.Nullify();
174 myEditCurrentArgument->setText("");
175 QString aString = ""; /* name of selection */
177 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
179 if(myEditCurrentArgument == GroupPoints->LineEdit1)
181 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
188 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
191 /* gp_Pnt : not used */
192 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
193 GroupPoints->LineEdit1->setText(aString);
196 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
197 BRepAdaptor_Curve curv(TopoDS::Edge(S));
198 myDir = curv.Line().Direction();
199 GroupPoints->LineEdit2->setText(aString);
203 if(myOkPoint1 && myOkDir)
204 this->MakeCircleSimulationAndDisplay();
209 //=================================================================================
210 // function : SetEditCurrentArgument()
212 //=================================================================================
213 void BasicGUI_CircleDlg::SetEditCurrentArgument()
215 QPushButton* send = (QPushButton*)sender();
216 mySelection->ClearFilters();
218 if(send == GroupPoints->PushButton1) {
219 GroupPoints->LineEdit1->setFocus();
220 myEditCurrentArgument = GroupPoints->LineEdit1;
221 mySelection->AddFilter(myVertexFilter);
223 else if(send == GroupPoints->PushButton2) {
224 GroupPoints->LineEdit2->setFocus();
225 myEditCurrentArgument = GroupPoints->LineEdit2;
226 mySelection->AddFilter(myEdgeFilter);
228 this->SelectionIntoArgument();
233 //=================================================================================
234 // function : LineEditReturnPressed()
236 //=================================================================================
237 void BasicGUI_CircleDlg::LineEditReturnPressed()
239 QLineEdit* send = (QLineEdit*)sender();
240 if(send == GroupPoints->LineEdit1)
241 myEditCurrentArgument = GroupPoints->LineEdit1;
242 else if (send == GroupPoints->LineEdit2)
243 myEditCurrentArgument = GroupPoints->LineEdit2;
247 GEOMBase_Skeleton::LineEditReturnPressed();
252 //=================================================================================
253 // function : ActivateThisDialog()
255 //=================================================================================
256 void BasicGUI_CircleDlg::ActivateThisDialog()
258 GEOMBase_Skeleton::ActivateThisDialog();
259 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260 GroupPoints->LineEdit1->setFocus();
261 myEditCurrentArgument = GroupPoints->LineEdit1;
262 mySelection->AddFilter(myVertexFilter);
263 if(!mySimulationTopoDs.IsNull())
264 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
269 //=================================================================================
270 // function : enterEvent()
272 //=================================================================================
273 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
275 if(GroupConstructors->isEnabled())
277 this->ActivateThisDialog();
282 //=================================================================================
283 // function : ValueChangedInSpinBox()
285 //=================================================================================
286 void BasicGUI_CircleDlg::ValueChangedInSpinBox(double newValue)
289 if(myOkPoint1 && myOkDir)
290 MakeCircleSimulationAndDisplay();
295 //=================================================================================
296 // function : MakeCircleSimulationAndDisplay()
298 //=================================================================================
299 void BasicGUI_CircleDlg::MakeCircleSimulationAndDisplay()
301 myGeomBase->EraseSimulationShape();
302 mySimulationTopoDs.Nullify();
305 gp_Ax2 anAxis(myPoint1, myDir);
306 gp_Circ circ(anAxis, myRadius);
307 BRepBuilderAPI_MakeEdge MakeEdge(circ);
308 mySimulationTopoDs = MakeEdge.Shape();
309 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
311 catch(Standard_Failure) {
312 MESSAGE("Exception catched in MakeCircleSimulationAndDisplay");