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
29 #include "BasicGUI_ArcDlg.h"
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <GC_MakeArcOfCircle.hxx>
33 #include <Geom_TrimmedCurve.hxx>
34 #include <Precision.hxx>
36 #include "utilities.h"
40 //=================================================================================
41 // class : BasicGUI_ArcDlg()
42 // purpose : Constructs a BasicGUI_ArcDlg 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_ArcDlg::BasicGUI_ArcDlg(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_ARC")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_ARC_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_ARC"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->close(TRUE);
59 RadioButton3->close(TRUE);
61 GroupPoints = new DlgRef_3Sel_QTD(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
65 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
66 GroupPoints->PushButton1->setPixmap(image1);
67 GroupPoints->PushButton2->setPixmap(image1);
68 GroupPoints->PushButton3->setPixmap(image1);
70 Layout1->addWidget(GroupPoints, 1, 0);
71 /***************************************************************/
74 myBasicGUI = theBasicGUI;
79 //=================================================================================
80 // function : ~BasicGUI_ArcDlg()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
85 // no need to delete child widgets, Qt does it all for us
89 //=================================================================================
92 //=================================================================================
93 void BasicGUI_ArcDlg::Init()
96 myEditCurrentArgument = GroupPoints->LineEdit1;
97 myOkPoint1 = myOkPoint2 = myOkPoint3 = false;
99 /* Vertices Filter for all arguments */
100 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
101 mySelection->AddFilter(myVertexFilter);
103 /* signals and slots connections */
104 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
105 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
117 /* displays Dialog */
125 //=================================================================================
126 // function : ClickOnOk()
128 //=================================================================================
129 void BasicGUI_ArcDlg::ClickOnOk()
131 this->ClickOnApply();
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 void BasicGUI_ArcDlg::ClickOnApply()
143 buttonApply->setFocus();
144 QAD_Application::getDesktop()->putInfo(tr(""));
145 if (mySimulationTopoDs.IsNull())
147 myGeomBase->EraseSimulationShape();
148 mySimulationTopoDs.Nullify();
150 if(myOkPoint1 && myOkPoint2 && myOkPoint3)
151 myBasicGUI->MakeArcAndDisplay(myPoint1, myPoint2, myPoint3);
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void BasicGUI_ArcDlg::SelectionIntoArgument()
162 myGeomBase->EraseSimulationShape();
163 mySimulationTopoDs.Nullify();
164 myEditCurrentArgument->setText("");
165 QString aString = ""; /* name of selection */
167 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
169 if (myEditCurrentArgument == GroupPoints->LineEdit1)
171 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
173 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
180 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
183 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
184 myEditCurrentArgument->setText(aString);
187 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
188 myEditCurrentArgument->setText(aString);
191 else if(myEditCurrentArgument == GroupPoints->LineEdit3 && myGeomBase->VertexToPoint(S, myPoint3)) {
192 myEditCurrentArgument->setText(aString);
196 if(myOkPoint1 && myOkPoint2 && myOkPoint3)
197 this->MakeArcSimulationAndDisplay();
202 //=================================================================================
203 // function : SetEditCurrentArgument()
205 //=================================================================================
206 void BasicGUI_ArcDlg::SetEditCurrentArgument()
208 QPushButton* send = (QPushButton*)sender();
209 mySelection->ClearFilters();
211 if(send == GroupPoints->PushButton1) {
212 GroupPoints->LineEdit1->setFocus();
213 myEditCurrentArgument = GroupPoints->LineEdit1;
215 else if(send == GroupPoints->PushButton2) {
216 GroupPoints->LineEdit2->setFocus();
217 myEditCurrentArgument = GroupPoints->LineEdit2;
219 else if(send == GroupPoints->PushButton3) {
220 GroupPoints->LineEdit3->setFocus();
221 myEditCurrentArgument = GroupPoints->LineEdit3;
223 mySelection->AddFilter(myVertexFilter);
224 this->SelectionIntoArgument();
230 //=================================================================================
231 // function : LineEditReturnPressed()
233 //=================================================================================
234 void BasicGUI_ArcDlg::LineEditReturnPressed()
236 QLineEdit* send = (QLineEdit*)sender();
237 if(send == GroupPoints->LineEdit1)
238 myEditCurrentArgument = GroupPoints->LineEdit1;
239 else if(send == GroupPoints->LineEdit2)
240 myEditCurrentArgument = GroupPoints->LineEdit2;
241 else if(send == GroupPoints->LineEdit3)
242 myEditCurrentArgument = GroupPoints->LineEdit3;
246 GEOMBase_Skeleton::LineEditReturnPressed();
251 //=================================================================================
252 // function : ActivateThisDialog()
254 //=================================================================================
255 void BasicGUI_ArcDlg::ActivateThisDialog()
257 GEOMBase_Skeleton::ActivateThisDialog();
258 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
259 mySelection->AddFilter(myVertexFilter);
260 if(!mySimulationTopoDs.IsNull())
261 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
266 //=================================================================================
267 // function : enterEvent()
269 //=================================================================================
270 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
272 if(GroupConstructors->isEnabled())
274 this->ActivateThisDialog();
279 //=================================================================================
280 // function : MakeArcSimulationAndDisplay()
282 //=================================================================================
283 void BasicGUI_ArcDlg::MakeArcSimulationAndDisplay()
285 myGeomBase->EraseSimulationShape();
286 mySimulationTopoDs.Nullify();
289 if(myPoint2.IsEqual(myPoint1, Precision::Confusion()) ||
290 myPoint2.IsEqual(myPoint3, Precision::Confusion())) {
291 myEditCurrentArgument->setText("");
295 gp_Vec v1(myPoint2, myPoint1);
296 gp_Vec v2(myPoint2, myPoint3);
297 if(v1.IsParallel(v2, Precision::Angular())) {
298 myEditCurrentArgument->setText("");
302 GC_MakeArcOfCircle Arc(myPoint1, myPoint2, myPoint3);
304 Handle(Geom_TrimmedCurve) curve = Arc.Value();
305 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(curve).Shape();
306 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
309 catch(Standard_Failure) {
310 MESSAGE("Exception catched in MakeArcSimulationAndDisplay");