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_ArcDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "BasicGUI_ArcDlg.h"
32 #include <BRepBuilderAPI_MakeEdge.hxx>
33 #include <GC_MakeArcOfCircle.hxx>
34 #include <Geom_TrimmedCurve.hxx>
35 #include <Precision.hxx>
37 //=================================================================================
38 // class : BasicGUI_ArcDlg()
39 // purpose : Constructs a BasicGUI_ArcDlg 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_ArcDlg::BasicGUI_ArcDlg(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_ARC")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_ARC_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_ARC"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->close(TRUE);
56 RadioButton3->close(TRUE);
58 GroupPoints = new DlgRef_3Sel_QTD(this, "GroupPoints");
59 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
60 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
61 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
62 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
63 GroupPoints->PushButton1->setPixmap(image1);
64 GroupPoints->PushButton2->setPixmap(image1);
65 GroupPoints->PushButton3->setPixmap(image1);
67 Layout1->addWidget(GroupPoints, 1, 0);
68 /***************************************************************/
71 myBasicGUI = theBasicGUI;
76 //=================================================================================
77 // function : ~BasicGUI_ArcDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
82 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void BasicGUI_ArcDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
94 myOkPoint1 = myOkPoint2 = myOkPoint3 = false;
96 /* Vertices Filter for all arguments */
97 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
98 mySelection->AddFilter(myVertexFilter);
100 /* signals and slots connections */
101 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
102 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
104 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
105 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
109 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
114 /* displays Dialog */
122 //=================================================================================
123 // function : ClickOnOk()
125 //=================================================================================
126 void BasicGUI_ArcDlg::ClickOnOk()
128 this->ClickOnApply();
134 //=================================================================================
135 // function : ClickOnApply()
137 //=================================================================================
138 void BasicGUI_ArcDlg::ClickOnApply()
140 QAD_Application::getDesktop()->putInfo(tr(""));
141 if (mySimulationTopoDs.IsNull())
143 myGeomBase->EraseSimulationShape();
144 mySimulationTopoDs.Nullify();
146 if(myOkPoint1 && myOkPoint2 && myOkPoint3)
147 myBasicGUI->MakeArcAndDisplay(myPoint1, myPoint2, myPoint3);
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection as changed or other case
155 //=================================================================================
156 void BasicGUI_ArcDlg::SelectionIntoArgument()
158 myGeomBase->EraseSimulationShape();
159 mySimulationTopoDs.Nullify();
160 myEditCurrentArgument->setText("");
161 QString aString = ""; /* name of selection */
163 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
165 if (myEditCurrentArgument == GroupPoints->LineEdit1)
167 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
169 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
176 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
179 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
180 myEditCurrentArgument->setText(aString);
183 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
184 myEditCurrentArgument->setText(aString);
187 else if(myEditCurrentArgument == GroupPoints->LineEdit3 && myGeomBase->VertexToPoint(S, myPoint3)) {
188 myEditCurrentArgument->setText(aString);
192 if(myOkPoint1 && myOkPoint2 && myOkPoint3)
193 this->MakeArcSimulationAndDisplay();
198 //=================================================================================
199 // function : SetEditCurrentArgument()
201 //=================================================================================
202 void BasicGUI_ArcDlg::SetEditCurrentArgument()
204 QPushButton* send = (QPushButton*)sender();
205 mySelection->ClearFilters();
207 if(send == GroupPoints->PushButton1) {
208 GroupPoints->LineEdit1->setFocus();
209 myEditCurrentArgument = GroupPoints->LineEdit1;
211 else if(send == GroupPoints->PushButton2) {
212 GroupPoints->LineEdit2->setFocus();
213 myEditCurrentArgument = GroupPoints->LineEdit2;
215 else if(send == GroupPoints->PushButton3) {
216 GroupPoints->LineEdit3->setFocus();
217 myEditCurrentArgument = GroupPoints->LineEdit3;
219 mySelection->AddFilter(myVertexFilter);
220 this->SelectionIntoArgument();
226 //=================================================================================
227 // function : LineEditReturnPressed()
229 //=================================================================================
230 void BasicGUI_ArcDlg::LineEditReturnPressed()
232 QLineEdit* send = (QLineEdit*)sender();
233 if(send == GroupPoints->LineEdit1)
234 myEditCurrentArgument = GroupPoints->LineEdit1;
235 else if(send == GroupPoints->LineEdit2)
236 myEditCurrentArgument = GroupPoints->LineEdit2;
237 else if(send == GroupPoints->LineEdit3)
238 myEditCurrentArgument = GroupPoints->LineEdit3;
242 GEOMBase_Skeleton::LineEditReturnPressed();
247 //=================================================================================
248 // function : ActivateThisDialog()
250 //=================================================================================
251 void BasicGUI_ArcDlg::ActivateThisDialog()
253 GEOMBase_Skeleton::ActivateThisDialog();
254 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
255 mySelection->AddFilter(myVertexFilter);
256 if(!mySimulationTopoDs.IsNull())
257 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
268 if(GroupConstructors->isEnabled())
270 this->ActivateThisDialog();
275 //=================================================================================
276 // function : MakeArcSimulationAndDisplay()
278 //=================================================================================
279 void BasicGUI_ArcDlg::MakeArcSimulationAndDisplay()
281 myGeomBase->EraseSimulationShape();
282 mySimulationTopoDs.Nullify();
285 if(myPoint2.IsEqual(myPoint1, Precision::Confusion()) ||
286 myPoint2.IsEqual(myPoint3, Precision::Confusion())) {
287 myEditCurrentArgument->setText("");
291 gp_Vec v1(myPoint2, myPoint1);
292 gp_Vec v2(myPoint2, myPoint3);
293 if(v1.IsParallel(v2, Precision::Angular())) {
294 myEditCurrentArgument->setText("");
298 GC_MakeArcOfCircle Arc(myPoint1, myPoint2, myPoint3);
300 Handle(Geom_TrimmedCurve) curve = Arc.Value();
301 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(curve).Shape();
302 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
305 catch(Standard_Failure) {
306 MESSAGE("Exception catched in MakeArcSimulationAndDisplay");