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
30 #include "BasicGUI_CircleDlg.h"
33 #include <gp_Circ.hxx>
34 #include <BRepBuilderAPI_MakeEdge.hxx>
35 #include <BRepAdaptor_Curve.hxx>
36 #include "QAD_Config.h"
38 //=================================================================================
39 // class : BasicGUI_CircleDlg()
40 // purpose : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 BasicGUI_CircleDlg::BasicGUI_CircleDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_CIRCLE_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->close(TRUE);
57 RadioButton3->close(TRUE);
59 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
60 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
61 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
62 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
63 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
64 GroupPoints->PushButton1->setPixmap(image1);
65 GroupPoints->PushButton2->setPixmap(image1);
67 Layout1->addWidget(GroupPoints, 1, 0);
68 /***************************************************************/
71 myBasicGUI = theBasicGUI;
76 //=================================================================================
77 // function : ~BasicGUI_CircleDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
82 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void BasicGUI_CircleDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
96 myOkPoint1 = myOkDir = false;
98 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
99 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
100 mySelection->AddFilter(myVertexFilter);
102 /* Get setting of step value from file configuration */
103 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
104 step = St.toDouble();
106 /* min, max, step and decimals for spin boxes & initial values */
107 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
108 GroupPoints->SpinBox_DX->SetValue(myRadius);
110 /* signals and slots connections */
111 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
121 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
123 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
125 /* displays Dialog */
133 //=================================================================================
134 // function : ClickOnOk()
136 //=================================================================================
137 void BasicGUI_CircleDlg::ClickOnOk()
139 this->ClickOnApply();
144 //=================================================================================
145 // function : ClickOnApply()
147 //=================================================================================
148 void BasicGUI_CircleDlg::ClickOnApply()
150 QAD_Application::getDesktop()->putInfo(tr(""));
151 if (mySimulationTopoDs.IsNull())
153 myGeomBase->EraseSimulationShape();
154 mySimulationTopoDs.Nullify();
156 if(myOkPoint1 && myOkDir)
157 myBasicGUI->MakeCircleAndDisplay(myPoint1, myDir, myRadius);
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose : Called when selection as changed or other case
165 //=================================================================================
166 void BasicGUI_CircleDlg::SelectionIntoArgument()
168 myGeomBase->EraseSimulationShape();
169 mySimulationTopoDs.Nullify();
170 myEditCurrentArgument->setText("");
171 QString aString = ""; /* name of selection */
173 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
175 if(myEditCurrentArgument == GroupPoints->LineEdit1)
177 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
184 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
187 /* gp_Pnt : not used */
188 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
189 GroupPoints->LineEdit1->setText(aString);
192 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
193 BRepAdaptor_Curve curv(TopoDS::Edge(S));
194 myDir = curv.Line().Direction();
195 GroupPoints->LineEdit2->setText(aString);
199 if(myOkPoint1 && myOkDir)
200 this->MakeCircleSimulationAndDisplay();
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void BasicGUI_CircleDlg::SetEditCurrentArgument()
211 QPushButton* send = (QPushButton*)sender();
212 mySelection->ClearFilters();
214 if(send == GroupPoints->PushButton1) {
215 GroupPoints->LineEdit1->setFocus();
216 myEditCurrentArgument = GroupPoints->LineEdit1;
217 mySelection->AddFilter(myVertexFilter);
219 else if(send == GroupPoints->PushButton2) {
220 GroupPoints->LineEdit2->setFocus();
221 myEditCurrentArgument = GroupPoints->LineEdit2;
222 mySelection->AddFilter(myEdgeFilter);
224 this->SelectionIntoArgument();
229 //=================================================================================
230 // function : LineEditReturnPressed()
232 //=================================================================================
233 void BasicGUI_CircleDlg::LineEditReturnPressed()
235 QLineEdit* send = (QLineEdit*)sender();
236 if(send == GroupPoints->LineEdit1)
237 myEditCurrentArgument = GroupPoints->LineEdit1;
238 else if (send == GroupPoints->LineEdit2)
239 myEditCurrentArgument = GroupPoints->LineEdit2;
243 GEOMBase_Skeleton::LineEditReturnPressed();
248 //=================================================================================
249 // function : ActivateThisDialog()
251 //=================================================================================
252 void BasicGUI_CircleDlg::ActivateThisDialog()
254 GEOMBase_Skeleton::ActivateThisDialog();
255 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
256 GroupPoints->LineEdit1->setFocus();
257 myEditCurrentArgument = GroupPoints->LineEdit1;
258 mySelection->AddFilter(myVertexFilter);
259 if(!mySimulationTopoDs.IsNull())
260 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
265 //=================================================================================
266 // function : enterEvent()
268 //=================================================================================
269 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
271 if(GroupConstructors->isEnabled())
273 this->ActivateThisDialog();
278 //=================================================================================
279 // function : ValueChangedInSpinBox()
281 //=================================================================================
282 void BasicGUI_CircleDlg::ValueChangedInSpinBox(double newValue)
285 if(myOkPoint1 && myOkDir)
286 MakeCircleSimulationAndDisplay();
291 //=================================================================================
292 // function : MakeCircleSimulationAndDisplay()
294 //=================================================================================
295 void BasicGUI_CircleDlg::MakeCircleSimulationAndDisplay()
297 myGeomBase->EraseSimulationShape();
298 mySimulationTopoDs.Nullify();
301 gp_Ax2 anAxis(myPoint1, myDir);
302 gp_Circ circ(anAxis, myRadius);
303 BRepBuilderAPI_MakeEdge MakeEdge(circ);
304 mySimulationTopoDs = MakeEdge.Shape();
305 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
307 catch(Standard_Failure) {
308 MESSAGE("Exception catched in MakeCircleSimulationAndDisplay");