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