]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_LineDlg.cxx
Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / BasicGUI / BasicGUI_LineDlg.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   : BasicGUI_LineDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI_LineDlg.h"
30
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <BRep_Builder.hxx>
34 #include <Precision.hxx>
35
36 #include "utilities.h"
37
38 using namespace std;
39
40 //=================================================================================
41 // class    : BasicGUI_LineDlg()
42 // purpose  : Constructs a BasicGUI_LineDlg 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_LineDlg::BasicGUI_LineDlg(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)
49 {
50   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
51   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
52
53   setCaption(tr("GEOM_LINE_TITLE"));
54
55   /***************************************************************/
56   GroupConstructors->setTitle(tr("GEOM_LINE"));
57   RadioButton1->setPixmap(image0);
58   RadioButton2->close(TRUE);
59   RadioButton3->close(TRUE);
60
61   GroupPoints = new DlgRef_2Sel_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->PushButton1->setPixmap(image1);
66   GroupPoints->PushButton2->setPixmap(image1);
67
68   Layout1->addWidget(GroupPoints, 1, 0);
69   /***************************************************************/
70
71   /* Initialisations */
72   myBasicGUI = theBasicGUI;
73   Init();
74 }
75
76
77 //=================================================================================
78 // function : ~BasicGUI_LineDlg()
79 // purpose  : Destroys the object and frees any allocated resources
80 //=================================================================================
81 BasicGUI_LineDlg::~BasicGUI_LineDlg()
82 {  
83   /* no need to delete child widgets, Qt does it all for us */
84 }
85
86
87 //=================================================================================
88 // function : Init()
89 // purpose  :
90 //=================================================================================
91 void BasicGUI_LineDlg::Init()
92 {
93   /* init variables */
94   myEditCurrentArgument = GroupPoints->LineEdit1;
95
96   myPoint1.SetCoord(0.0, 0.0, 0.0);
97   myPoint2.SetCoord(0.0, 0.0, 0.0);
98   myOkPoint1 = myOkPoint2 = false;
99
100   /*  Vertices Filter for all arguments */
101   myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
102   mySelection->AddFilter(myVertexFilter);
103
104   /* signals and slots connections */
105   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107
108   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110
111   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113
114   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
115
116   /* displays Dialog */
117   GroupPoints->show();
118   this->show();
119
120   return;
121 }
122
123
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose  :
127 //=================================================================================
128 void BasicGUI_LineDlg::ClickOnOk()
129 {
130   this->ClickOnApply();
131   ClickOnCancel();
132   return;
133 }
134
135 //=================================================================================
136 // function : ClickOnApply()
137 // purpose  :
138 //=================================================================================
139 void BasicGUI_LineDlg::ClickOnApply()
140 {
141   buttonApply->setFocus();
142   QAD_Application::getDesktop()->putInfo(tr(""));
143   if (mySimulationTopoDs.IsNull())
144     return;
145   myGeomBase->EraseSimulationShape();
146   mySimulationTopoDs.Nullify();
147
148   if(myOkPoint1 && myOkPoint2) 
149     myBasicGUI->MakeLineAndDisplay(myPoint1, myPoint2);
150   return;
151 }
152
153
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose  : Called when selection as changed or other case
157 //=================================================================================
158 void BasicGUI_LineDlg::SelectionIntoArgument()
159 {
160   myGeomBase->EraseSimulationShape();
161   mySimulationTopoDs.Nullify();
162   myEditCurrentArgument->setText("");
163   QString aString = ""; /* name of selection */
164
165   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
166   if(nbSel != 1) {
167     if(myEditCurrentArgument == GroupPoints->LineEdit1)
168       myOkPoint1 = false;
169     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
170       myOkPoint2 = false;
171     return;
172   }
173
174   // nbSel == 1
175   TopoDS_Shape S; 
176   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
177     return;
178   
179   if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
180     myEditCurrentArgument->setText(aString);
181     myOkPoint1 = true;
182   }
183   else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
184     myEditCurrentArgument->setText(aString);
185     myOkPoint2 = true;
186   }
187
188   if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion())
189     this->MakeLineSimulationAndDisplay();
190   return;
191 }
192
193
194 //=================================================================================
195 // function : SetEditCurrentArgument()
196 // purpose  :
197 //=================================================================================
198 void BasicGUI_LineDlg::SetEditCurrentArgument()
199 {
200   QPushButton* send = (QPushButton*)sender();
201   mySelection->ClearFilters();
202
203   if(send == GroupPoints->PushButton1) {
204     GroupPoints->LineEdit1->setFocus();
205     myEditCurrentArgument = GroupPoints->LineEdit1;
206   }
207   else if(send == GroupPoints->PushButton2) {
208     GroupPoints->LineEdit2->setFocus();
209     myEditCurrentArgument = GroupPoints->LineEdit2;
210   }
211   mySelection->AddFilter(myVertexFilter);
212   this->SelectionIntoArgument();
213
214   return;
215 }
216
217
218 //=================================================================================
219 // function : LineEditReturnPressed()
220 // purpose  :
221 //=================================================================================
222 void BasicGUI_LineDlg::LineEditReturnPressed()
223 {
224   QLineEdit* send = (QLineEdit*)sender();
225   if(send == GroupPoints->LineEdit1)
226     myEditCurrentArgument = GroupPoints->LineEdit1;
227   else if(send == GroupPoints->LineEdit2)
228     myEditCurrentArgument = GroupPoints->LineEdit2;
229   else
230     return;
231
232   GEOMBase_Skeleton::LineEditReturnPressed();
233   return;
234 }
235
236
237 //=================================================================================
238 // function : ActivateThisDialog()
239 // purpose  :
240 //=================================================================================
241 void BasicGUI_LineDlg::ActivateThisDialog()
242 {
243   GEOMBase_Skeleton::ActivateThisDialog();
244   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
245   mySelection->AddFilter(myVertexFilter);
246   if(!mySimulationTopoDs.IsNull())
247     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
248   return;
249 }
250
251
252 //=================================================================================
253 // function : enterEvent()
254 // purpose  :
255 //=================================================================================
256 void BasicGUI_LineDlg::enterEvent(QEvent* e)
257 {
258   if(GroupConstructors->isEnabled())
259     return;
260   this->ActivateThisDialog();
261   return;
262 }
263
264
265 //=================================================================================
266 // function : MakeLineSimulationAndDisplay()
267 // purpose  : An arrow (cone topology) is added to 'modifiedShape'
268 //          : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
269 //          : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
270 //=================================================================================
271 void BasicGUI_LineDlg::MakeLineSimulationAndDisplay()
272 {
273   myGeomBase->EraseSimulationShape();
274   mySimulationTopoDs.Nullify();
275   
276   try {
277     mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
278     TopoDS_Shape arrow;
279     if(myGeomBase->CreateArrowForLinearEdge(mySimulationTopoDs, arrow)) {
280       TopoDS_Compound Comp;
281       BRep_Builder B;
282       B.MakeCompound (Comp);
283       B.Add(Comp, mySimulationTopoDs);
284       B.Add(Comp, arrow);
285       mySimulationTopoDs = Comp;
286     }
287     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
288   }
289   catch(Standard_Failure) {
290     MESSAGE("Exception catched in MakeLineSimulationAndDisplay");
291     return;
292   }
293   return;
294 }