Salome HOME
770cc70b35a34a44c4eaa3bdfb2efcc563230497
[modules/geom.git] / src / BuildGUI / BuildGUI_EdgeDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BuildGUI_EdgeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_EdgeDlg.h"
30
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <Precision.hxx>
33
34 #include "utilities.h"
35
36 using namespace std;
37
38 //=================================================================================
39 // class    : BuildGUI_EdgeDlg()
40 // purpose  : Constructs a BuildGUI_EdgeDlg 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 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(QWidget* parent, const char* name, BuildGUI* theBuildGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
46   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 {
48   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
49   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50
51   setCaption(tr("GEOM_EDGE_TITLE"));
52
53   /***************************************************************/
54   GroupConstructors->setTitle(tr("GEOM_EDGE"));
55   RadioButton1->setPixmap(image0);
56   RadioButton2->close(TRUE);
57   RadioButton3->close(TRUE);
58
59   GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
60   GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
61   GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
62   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
63   GroupPoints->PushButton1->setPixmap(image1);
64   GroupPoints->PushButton2->setPixmap(image1);
65
66   Layout1->addWidget(GroupPoints, 1, 0);
67   /***************************************************************/
68
69   /* Initialisations */
70   myBuildGUI = theBuildGUI;
71   Init();
72 }
73
74
75 //=================================================================================
76 // function : ~BuildGUI_EdgeDlg()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
80 {
81     // no need to delete child widgets, Qt does it all for us
82 }
83
84
85 //=================================================================================
86 // function : Init()
87 // purpose  :
88 //=================================================================================
89 void BuildGUI_EdgeDlg::Init()
90 {
91   /* init variables */
92   myEditCurrentArgument = GroupPoints->LineEdit1;
93
94   myPoint1.SetCoord(0.0, 0.0, 0.0);
95   myPoint2.SetCoord(0.0, 0.0, 0.0);
96   myOkPoint1 = myOkPoint2 = false;
97
98   /* first filter used */
99   myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
100   mySelection->AddFilter(myVertexFilter);
101
102   /* signals and slots connections */
103   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
105
106   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108
109   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111   
112   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
113
114   /* displays Dialog */
115   GroupPoints->show();
116   this->show();
117
118   return;
119 }
120
121
122 //=================================================================================
123 // function : ClickOnOk()
124 // purpose  :
125 //=================================================================================
126 void BuildGUI_EdgeDlg::ClickOnOk()
127 {
128   this->ClickOnApply();
129   ClickOnCancel();
130   return;
131 }
132
133
134 //=================================================================================
135 // function : ClickOnApply()
136 // purpose  :
137 //=================================================================================
138 void BuildGUI_EdgeDlg::ClickOnApply()
139 {
140   QAD_Application::getDesktop()->putInfo(tr(""));
141   if (mySimulationTopoDs.IsNull())
142     return;
143   myGeomBase->EraseSimulationShape();
144   mySimulationTopoDs.Nullify();
145
146   if(myOkPoint1 && myOkPoint2) 
147     myBuildGUI->MakeLinearEdgeAndDisplay(myPoint1, myPoint2);
148   return;
149 }
150
151
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose  : Called when selection as changed or other case
155 //=================================================================================
156 void BuildGUI_EdgeDlg::SelectionIntoArgument()
157 {
158   myGeomBase->EraseSimulationShape();
159   mySimulationTopoDs.Nullify();
160   myEditCurrentArgument->setText("");
161   QString aString = ""; /* name of selection */
162   
163   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
164   if(nbSel != 1) {
165     if(myEditCurrentArgument == GroupPoints->LineEdit1)
166       myOkPoint1 = false;
167     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
168       myOkPoint2 = false;
169     return;
170   }
171   
172   // nbSel == 1
173   TopoDS_Shape S; 
174   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
175     return;
176   
177   if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
178     myEditCurrentArgument->setText(aString);
179     myOkPoint1 = true;
180   }
181   else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
182     myEditCurrentArgument->setText(aString);
183     myOkPoint2 = true;
184   }
185
186   if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion())
187     this->MakeEdgeSimulationAndDisplay();
188   return;
189 }
190
191
192 //=================================================================================
193 // function : LineEditReturnPressed()
194 // purpose  :
195 //=================================================================================
196 void BuildGUI_EdgeDlg::LineEditReturnPressed()
197 {
198   QLineEdit* send = (QLineEdit*)sender();
199   if(send == GroupPoints->LineEdit1)
200     myEditCurrentArgument = GroupPoints->LineEdit1;
201   else if (send == GroupPoints->LineEdit2)
202     myEditCurrentArgument = GroupPoints->LineEdit2;
203   else
204     return;
205
206   GEOMBase_Skeleton::LineEditReturnPressed();
207   return;
208 }
209
210
211 //=================================================================================
212 // function : SetEditCurrentArgument()
213 // purpose  :
214 //=================================================================================
215 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
216 {
217   QPushButton* send = (QPushButton*)sender();
218   mySelection->ClearFilters();
219
220   if(send == GroupPoints->PushButton1) {
221     GroupPoints->LineEdit1->setFocus();
222     myEditCurrentArgument = GroupPoints->LineEdit1;
223   }
224   else if(send == GroupPoints->PushButton2) {
225     GroupPoints->LineEdit2->setFocus();
226     myEditCurrentArgument = GroupPoints->LineEdit2;
227   }
228   mySelection->AddFilter(myVertexFilter);
229   this->SelectionIntoArgument();
230
231   return;
232 }
233
234
235 //=================================================================================
236 // function : ActivateThisDialog()
237 // purpose  :
238 //=================================================================================
239 void BuildGUI_EdgeDlg::ActivateThisDialog()
240 {
241   GEOMBase_Skeleton::ActivateThisDialog();
242   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243   mySelection->AddFilter(myVertexFilter);
244   if(!mySimulationTopoDs.IsNull())
245     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
246   return;
247 }
248
249
250 //=================================================================================
251 // function : enterEvent()
252 // purpose  :
253 //=================================================================================
254 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
255 {
256   if (GroupConstructors->isEnabled())
257     return;
258   this->ActivateThisDialog();
259   return;
260 }
261
262
263 //=================================================================================
264 // function : MakeMirrorSimulationAndDisplay()
265 // purpose  : S1 is a shape and S2 a mirror.
266 //=================================================================================
267 void BuildGUI_EdgeDlg::MakeEdgeSimulationAndDisplay()
268 {
269   myGeomBase->EraseSimulationShape();
270   mySimulationTopoDs.Nullify();
271   
272   try {
273     mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
274     myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
275   }
276   catch(Standard_Failure) {
277     MESSAGE("Exception catched in MakeEdgeSimulationAndDisplay");
278     return;
279   }
280   return;
281 }