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