]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_NormaleDlg.cxx
Salome HOME
6714e4fb19f18696f67f95cc58a1ae1a0fbad428
[modules/geom.git] / src / MeasureGUI / MeasureGUI_NormaleDlg.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : MeasureGUI_NormaleDlg.cxx
25 //  Author : Julia DOROVSKIKH
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_NormaleDlg.h"
30
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <qlabel.h>
36
37 #include "GEOMImpl_Types.hxx"
38
39 #include "utilities.h"
40
41 //=================================================================================
42 // class    : MeasureGUI_NormaleDlg()
43 // purpose  : Constructs a MeasureGUI_NormaleDlg which is a child of 'parent', with the
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
49                                               const char* name, bool modal, WFlags fl)
50   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
51                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 {
53   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
54   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE")));
55   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
56
57   setCaption(tr("GEOM_NORMALE_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_NORMALE"));
61   RadioButton1->setPixmap(image0);
62   RadioButton2->close(TRUE);
63   RadioButton3->close(TRUE);
64
65   GroupArgs = new DlgRef_2Sel_QTD (this, "GroupArgs");
66   GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
67
68   GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
69   GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
70
71   GroupArgs->PushButton1->setPixmap(image1);
72   GroupArgs->PushButton2->setPixmap(image1);
73
74   Layout1->addWidget(GroupArgs, 2, 0);
75   /***************************************************************/
76
77   setHelpFileName("using_measurement_tools_page.html#normale_anchor");
78
79   Init();
80 }
81
82 //=================================================================================
83 // function : ~MeasureGUI_NormaleDlg()
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
87 {
88   // no need to delete child widgets, Qt does it all for us
89 }
90
91 //=================================================================================
92 // function : Init()
93 // purpose  :
94 //=================================================================================
95 void MeasureGUI_NormaleDlg::Init()
96 {
97   /* init variables */
98   GroupArgs->LineEdit1->setReadOnly(true);
99   GroupArgs->LineEdit2->setReadOnly(true);
100
101   myFace = GEOM::GEOM_Object::_nil();
102   myPoint = GEOM::GEOM_Object::_nil();
103
104   myEditCurrentArgument = GroupArgs->LineEdit1;
105   globalSelection(GEOM_FACE);
106
107   /* signals and slots connections */
108   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110
111   connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112   connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113
114   connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115   connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116
117   connect(myGeomGUI->getApp()->selectionMgr(),
118           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
119
120   initName(tr("GEOM_VECTOR_NORMALE"));
121
122   //ConstructorsClicked(0);
123   SelectionIntoArgument();
124
125   /* displays Dialog */
126   GroupArgs->show();
127   this->show();
128 }
129
130 //=================================================================================
131 // function : ClickOnOk()
132 // purpose  :
133 //=================================================================================
134 void MeasureGUI_NormaleDlg::ClickOnOk()
135 {
136   if (ClickOnApply())
137     ClickOnCancel();
138 }
139
140 //=================================================================================
141 // function : ClickOnApply()
142 // purpose  :
143 //=================================================================================
144 bool MeasureGUI_NormaleDlg::ClickOnApply()
145 {
146   if (!onAccept())
147     return false;
148
149   initName();
150   return true;
151 }
152
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose  : Called when selection as changed or other case
156 //=================================================================================
157 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
158 {
159   erasePreview();
160   myEditCurrentArgument->setText("");
161
162   if (myEditCurrentArgument == GroupArgs->LineEdit1) {
163     myFace = GEOM::GEOM_Object::_nil();
164   }
165   else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
166     myPoint = GEOM::GEOM_Object::_nil();
167   }
168
169   if (IObjectCount() != 1)
170     return;
171
172   // nbSel == 1
173   Standard_Boolean testResult = Standard_False;
174   GEOM::GEOM_Object_var aSelectedObject =
175     GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
176
177   if (!testResult)
178     return;
179
180   if (myEditCurrentArgument == GroupArgs->LineEdit1) {
181     myFace = aSelectedObject;
182   }
183   else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
184     myPoint = aSelectedObject;
185   }
186
187   myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
188
189   displayPreview();
190 }
191
192 //=================================================================================
193 // function : LineEditReturnPressed()
194 // purpose  :
195 //=================================================================================
196 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
197 {
198   QLineEdit* send = (QLineEdit*)sender();
199   if (send == GroupArgs->LineEdit1 ||
200       send == GroupArgs->LineEdit2)
201   {
202     myEditCurrentArgument = send;
203     GEOMBase_Skeleton::LineEditReturnPressed();
204   }
205 }
206
207 //=================================================================================
208 // function : SetEditCurrentArgument()
209 // purpose  :
210 //=================================================================================
211 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
212 {
213   QPushButton* send = (QPushButton*)sender();
214
215   if (send == GroupArgs->PushButton1) {
216     myEditCurrentArgument = GroupArgs->LineEdit1;
217     globalSelection(GEOM_FACE);
218   }
219   else if (send == GroupArgs->PushButton2) {
220     myEditCurrentArgument = GroupArgs->LineEdit2;
221     globalSelection(GEOM_POINT);
222   }
223
224   myEditCurrentArgument->setFocus();
225   SelectionIntoArgument();
226 }
227
228 //=================================================================================
229 // function : ActivateThisDialog()
230 // purpose  :
231 //=================================================================================
232 void MeasureGUI_NormaleDlg::ActivateThisDialog()
233 {
234   GEOMBase_Skeleton::ActivateThisDialog();
235
236   SelectionIntoArgument();
237 }
238
239 //=================================================================================
240 // function : enterEvent()
241 // purpose  :
242 //=================================================================================
243 void MeasureGUI_NormaleDlg::enterEvent (QEvent* e)
244 {
245   if (!GroupConstructors->isEnabled())
246     ActivateThisDialog();
247 }
248
249 //=================================================================================
250 // function : createOperation
251 // purpose  :
252 //=================================================================================
253 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
254 {
255   return getGeomEngine()->GetIMeasureOperations(getStudyId());
256 }
257
258 //=================================================================================
259 // function : isValid
260 // purpose  :
261 //=================================================================================
262 bool MeasureGUI_NormaleDlg::isValid (QString&)
263 {
264   //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
265   return !CORBA::is_nil(myFace);
266 }
267
268 //=================================================================================
269 // function : execute
270 // purpose  :
271 //=================================================================================
272 bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
273 {
274   GEOM::GEOM_Object_var anObj =
275     GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint);
276
277   if (!anObj->_is_nil())
278     objects.push_back(anObj._retn());
279
280   return true;
281 }