1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : MeasureGUI_NormaleDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "MeasureGUI_NormaleDlg.h"
30 #include "SUIT_Session.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
34 #include <TopoDS_Shape.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
41 #include "GEOMImpl_Types.hxx"
43 #include "utilities.h"
45 //=================================================================================
46 // class : MeasureGUI_NormaleDlg()
47 // purpose : Constructs a MeasureGUI_NormaleDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
53 const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE")));
59 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setCaption(tr("GEOM_NORMALE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_NORMALE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupArgs = new DlgRef_2Sel_QTD (this, "GroupArgs");
70 GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
73 GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
75 GroupArgs->PushButton1->setPixmap(image1);
76 GroupArgs->PushButton2->setPixmap(image1);
78 Layout1->addWidget(GroupArgs, 2, 0);
79 /***************************************************************/
81 setHelpFileName("using_measurement_tools_page.html#normale_anchor");
86 //=================================================================================
87 // function : ~MeasureGUI_NormaleDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
92 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void MeasureGUI_NormaleDlg::Init()
102 GroupArgs->LineEdit1->setReadOnly(true);
103 GroupArgs->LineEdit2->setReadOnly(true);
105 myFace = GEOM::GEOM_Object::_nil();
106 myPoint = GEOM::GEOM_Object::_nil();
108 myEditCurrentArgument = GroupArgs->LineEdit1;
109 globalSelection(GEOM_FACE);
111 /* signals and slots connections */
112 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115 connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(myGeomGUI->getApp()->selectionMgr(),
122 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
124 initName(tr("GEOM_VECTOR_NORMALE"));
126 //ConstructorsClicked(0);
127 SelectionIntoArgument();
129 /* displays Dialog */
134 //=================================================================================
135 // function : ClickOnOk()
137 //=================================================================================
138 void MeasureGUI_NormaleDlg::ClickOnOk()
144 //=================================================================================
145 // function : ClickOnApply()
147 //=================================================================================
148 bool MeasureGUI_NormaleDlg::ClickOnApply()
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose : Called when selection as changed or other case
160 //=================================================================================
161 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
164 myEditCurrentArgument->setText("");
166 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
167 myFace = GEOM::GEOM_Object::_nil();
169 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
170 myPoint = GEOM::GEOM_Object::_nil();
173 if (IObjectCount() != 1)
177 Standard_Boolean testResult = Standard_False;
178 GEOM::GEOM_Object_var aSelectedObject =
179 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
184 QString aName = GEOMBase::GetName(aSelectedObject);
186 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
188 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
190 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
191 TColStd_IndexedMapOfInteger aMap;
192 aSelMgr->GetIndexes(firstIObject(), aMap);
193 if (aMap.Extent() == 1) // Local Selection
195 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
196 int anIndex = aMap( 1 );
197 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
198 aName += QString(":face_%1").arg(anIndex);
200 else // Global Selection
202 if (aShape.ShapeType() != TopAbs_FACE) {
203 aSelectedObject = GEOM::GEOM_Object::_nil();
208 myFace = aSelectedObject;
210 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
212 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
214 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
215 TColStd_IndexedMapOfInteger aMap;
216 aSelMgr->GetIndexes(firstIObject(), aMap);
217 if (aMap.Extent() == 1) // Local Selection
219 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
220 int anIndex = aMap( 1 );
221 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
222 aName += QString(":vertex_%1").arg(anIndex);
224 else // Global Selection
226 if (aShape.ShapeType() != TopAbs_VERTEX) {
227 aSelectedObject = GEOM::GEOM_Object::_nil();
232 myPoint = aSelectedObject;
235 myEditCurrentArgument->setText( aName );
240 //=================================================================================
241 // function : LineEditReturnPressed()
243 //=================================================================================
244 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
246 QLineEdit* send = (QLineEdit*)sender();
247 if (send == GroupArgs->LineEdit1 ||
248 send == GroupArgs->LineEdit2)
250 myEditCurrentArgument = send;
251 GEOMBase_Skeleton::LineEditReturnPressed();
255 //=================================================================================
256 // function : SetEditCurrentArgument()
258 //=================================================================================
259 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
261 QPushButton* send = (QPushButton*)sender();
262 globalSelection(GEOM_FACE);
264 if (send == GroupArgs->PushButton1) {
265 myEditCurrentArgument = GroupArgs->LineEdit1;
266 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
268 else if (send == GroupArgs->PushButton2) {
269 myEditCurrentArgument = GroupArgs->LineEdit2;
270 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
273 myEditCurrentArgument->setFocus();
274 SelectionIntoArgument();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void MeasureGUI_NormaleDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
285 SelectionIntoArgument();
288 //=================================================================================
289 // function : enterEvent()
291 //=================================================================================
292 void MeasureGUI_NormaleDlg::enterEvent (QEvent* e)
294 if (!GroupConstructors->isEnabled())
295 ActivateThisDialog();
298 //=================================================================================
299 // function : createOperation
301 //=================================================================================
302 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
304 return getGeomEngine()->GetIMeasureOperations(getStudyId());
307 //=================================================================================
308 // function : isValid
310 //=================================================================================
311 bool MeasureGUI_NormaleDlg::isValid (QString&)
313 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
314 return !CORBA::is_nil(myFace);
317 //=================================================================================
318 // function : execute
320 //=================================================================================
321 bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
323 GEOM::GEOM_Object_var anObj =
324 GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint);
326 if (!anObj->_is_nil())
327 objects.push_back(anObj._retn());