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