1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : MeasureGUI_NormaleDlg.cxx
25 // Author : Julia DOROVSKIKH
29 #include "MeasureGUI_NormaleDlg.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
42 #include "GEOMImpl_Types.hxx"
44 #include "utilities.h"
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)
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")));
62 setCaption(tr("GEOM_NORMALE_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_NORMALE"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->close(TRUE);
68 RadioButton3->close(TRUE);
70 GroupArgs = new DlgRef_2Sel_QTD (this, "GroupArgs");
71 GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
74 GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
76 GroupArgs->PushButton1->setPixmap(image1);
77 GroupArgs->PushButton2->setPixmap(image1);
79 Layout1->addWidget(GroupArgs, 2, 0);
80 /***************************************************************/
82 setHelpFileName("using_measurement_tools_page.html#normale_anchor");
87 //=================================================================================
88 // function : ~MeasureGUI_NormaleDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
93 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void MeasureGUI_NormaleDlg::Init()
103 GroupArgs->LineEdit1->setReadOnly(true);
104 GroupArgs->LineEdit2->setReadOnly(true);
106 myFace = GEOM::GEOM_Object::_nil();
107 myPoint = GEOM::GEOM_Object::_nil();
109 myEditCurrentArgument = GroupArgs->LineEdit1;
110 globalSelection(GEOM_FACE);
112 /* signals and slots connections */
113 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
114 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116 connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(myGeomGUI->getApp()->selectionMgr(),
123 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
125 initName(tr("GEOM_VECTOR_NORMALE"));
127 //ConstructorsClicked(0);
128 SelectionIntoArgument();
130 /* displays Dialog */
135 //=================================================================================
136 // function : ClickOnOk()
138 //=================================================================================
139 void MeasureGUI_NormaleDlg::ClickOnOk()
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool MeasureGUI_NormaleDlg::ClickOnApply()
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose : Called when selection as changed or other case
161 //=================================================================================
162 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
165 myEditCurrentArgument->setText("");
167 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
168 myFace = GEOM::GEOM_Object::_nil();
170 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
171 myPoint = GEOM::GEOM_Object::_nil();
174 if (IObjectCount() != 1)
178 Standard_Boolean testResult = Standard_False;
179 GEOM::GEOM_Object_var aSelectedObject =
180 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
185 QString aName = GEOMBase::GetName(aSelectedObject);
187 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
189 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
191 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
192 TColStd_IndexedMapOfInteger aMap;
193 aSelMgr->GetIndexes(firstIObject(), aMap);
194 if (aMap.Extent() == 1) // Local Selection
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);
201 else // Global Selection
203 if (aShape.ShapeType() != TopAbs_FACE) {
204 aSelectedObject = GEOM::GEOM_Object::_nil();
209 myFace = aSelectedObject;
211 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
213 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
215 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
216 TColStd_IndexedMapOfInteger aMap;
217 aSelMgr->GetIndexes(firstIObject(), aMap);
218 if (aMap.Extent() == 1) // Local Selection
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);
225 else // Global Selection
227 if (aShape.ShapeType() != TopAbs_VERTEX) {
228 aSelectedObject = GEOM::GEOM_Object::_nil();
233 myPoint = aSelectedObject;
236 myEditCurrentArgument->setText( aName );
241 //=================================================================================
242 // function : LineEditReturnPressed()
244 //=================================================================================
245 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
247 QLineEdit* send = (QLineEdit*)sender();
248 if (send == GroupArgs->LineEdit1 ||
249 send == GroupArgs->LineEdit2)
251 myEditCurrentArgument = send;
252 GEOMBase_Skeleton::LineEditReturnPressed();
256 //=================================================================================
257 // function : SetEditCurrentArgument()
259 //=================================================================================
260 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
262 QPushButton* send = (QPushButton*)sender();
263 globalSelection(GEOM_FACE);
265 if (send == GroupArgs->PushButton1) {
266 myEditCurrentArgument = GroupArgs->LineEdit1;
267 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
269 else if (send == GroupArgs->PushButton2) {
270 myEditCurrentArgument = GroupArgs->LineEdit2;
271 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
274 myEditCurrentArgument->setFocus();
275 SelectionIntoArgument();
278 //=================================================================================
279 // function : ActivateThisDialog()
281 //=================================================================================
282 void MeasureGUI_NormaleDlg::ActivateThisDialog()
284 GEOMBase_Skeleton::ActivateThisDialog();
286 SelectionIntoArgument();
289 //=================================================================================
290 // function : enterEvent()
292 //=================================================================================
293 void MeasureGUI_NormaleDlg::enterEvent (QEvent* e)
295 if (!GroupConstructors->isEnabled())
296 ActivateThisDialog();
299 //=================================================================================
300 // function : createOperation
302 //=================================================================================
303 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
305 return getGeomEngine()->GetIMeasureOperations(getStudyId());
308 //=================================================================================
309 // function : isValid
311 //=================================================================================
312 bool MeasureGUI_NormaleDlg::isValid (QString&)
314 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
315 return !CORBA::is_nil(myFace);
318 //=================================================================================
319 // function : execute
321 //=================================================================================
322 bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
324 GEOM::GEOM_Object_var anObj =
325 GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint);
327 if (!anObj->_is_nil())
328 objects.push_back(anObj._retn());