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) {
188 myFace = aSelectedObject;
190 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
192 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
194 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
195 TColStd_IndexedMapOfInteger aMap;
196 aSelMgr->GetIndexes(firstIObject(), aMap);
197 if (aMap.Extent() == 1) // Local Selection
199 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
200 int anIndex = aMap( 1 );
201 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
202 aName += QString(":vertex_%1").arg(anIndex);
204 else // Global Selection
206 if (aShape.ShapeType() != TopAbs_VERTEX) {
207 aSelectedObject = GEOM::GEOM_Object::_nil();
212 myPoint = aSelectedObject;
215 myEditCurrentArgument->setText( aName );
220 //=================================================================================
221 // function : LineEditReturnPressed()
223 //=================================================================================
224 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
226 QLineEdit* send = (QLineEdit*)sender();
227 if (send == GroupArgs->LineEdit1 ||
228 send == GroupArgs->LineEdit2)
230 myEditCurrentArgument = send;
231 GEOMBase_Skeleton::LineEditReturnPressed();
235 //=================================================================================
236 // function : SetEditCurrentArgument()
238 //=================================================================================
239 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
241 QPushButton* send = (QPushButton*)sender();
242 globalSelection(GEOM_FACE);
244 if (send == GroupArgs->PushButton1) {
245 myEditCurrentArgument = GroupArgs->LineEdit1;
247 else if (send == GroupArgs->PushButton2) {
248 myEditCurrentArgument = GroupArgs->LineEdit2;
249 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
252 myEditCurrentArgument->setFocus();
253 SelectionIntoArgument();
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void MeasureGUI_NormaleDlg::ActivateThisDialog()
262 GEOMBase_Skeleton::ActivateThisDialog();
264 SelectionIntoArgument();
267 //=================================================================================
268 // function : enterEvent()
270 //=================================================================================
271 void MeasureGUI_NormaleDlg::enterEvent (QEvent* e)
273 if (!GroupConstructors->isEnabled())
274 ActivateThisDialog();
277 //=================================================================================
278 // function : createOperation
280 //=================================================================================
281 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
283 return getGeomEngine()->GetIMeasureOperations(getStudyId());
286 //=================================================================================
287 // function : isValid
289 //=================================================================================
290 bool MeasureGUI_NormaleDlg::isValid (QString&)
292 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
293 return !CORBA::is_nil(myFace);
296 //=================================================================================
297 // function : execute
299 //=================================================================================
300 bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
302 GEOM::GEOM_Object_var anObj =
303 GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint);
305 if (!anObj->_is_nil())
306 objects.push_back(anObj._retn());