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, Open CASCADE S.A.S.
26 #include "MeasureGUI_NormaleDlg.h"
30 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
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 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
56 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
57 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE")));
58 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
60 setWindowTitle(tr("GEOM_NORMALE_TITLE"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_NORMALE"));
64 mainFrame()->RadioButton1->setIcon(image0);
65 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton2->close();
67 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton3->close();
70 GroupArgs = new DlgRef_2Sel (centralWidget());
71 GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
74 GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
76 GroupArgs->PushButton1->setIcon(image1);
77 GroupArgs->PushButton2->setIcon(image1);
79 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
80 layout->setMargin(0); layout->setSpacing(6);
81 layout->addWidget(GroupArgs);
82 /***************************************************************/
84 setHelpFileName("using_measurement_tools_page.html#normale_anchor");
89 //=================================================================================
90 // function : ~MeasureGUI_NormaleDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
97 //=================================================================================
100 //=================================================================================
101 void MeasureGUI_NormaleDlg::Init()
104 GroupArgs->LineEdit1->setReadOnly(true);
105 GroupArgs->LineEdit2->setReadOnly(true);
107 GroupArgs->LineEdit1->setText("");
108 GroupArgs->LineEdit2->setText("");
109 myFace = myPoint = GEOM::GEOM_Object::_nil();
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 initName(tr("GEOM_VECTOR_NORMALE"));
123 GroupArgs->PushButton1->click();
124 SelectionIntoArgument();
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void MeasureGUI_NormaleDlg::ClickOnOk()
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 bool MeasureGUI_NormaleDlg::ClickOnApply()
147 // activate first line edit
148 GroupArgs->PushButton1->click();
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection is changed or on dialog initialization or activation
155 //=================================================================================
156 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
159 myEditCurrentArgument->setText("");
161 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
162 myFace = GEOM::GEOM_Object::_nil();
164 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
165 myPoint = GEOM::GEOM_Object::_nil();
168 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
169 SALOME_ListIO aSelList;
170 aSelMgr->selectedObjects(aSelList);
172 if (aSelList.Extent() != 1)
176 Standard_Boolean testResult = Standard_False;
177 GEOM::GEOM_Object_var aSelectedObject =
178 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
180 if (!testResult || CORBA::is_nil(aSelectedObject))
183 QString aName = GEOMBase::GetName(aSelectedObject);
185 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
187 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
189 TColStd_IndexedMapOfInteger aMap;
190 aSelMgr->GetIndexes(aSelList.First(), aMap);
191 if (aMap.Extent() == 1) // Local Selection
193 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
194 int anIndex = aMap(1);
195 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
196 aName += QString(":face_%1").arg(anIndex);
198 else // Global Selection
200 if (aShape.ShapeType() != TopAbs_FACE) {
201 aSelectedObject = GEOM::GEOM_Object::_nil();
206 myFace = aSelectedObject;
207 myEditCurrentArgument->setText(aName);
210 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
211 myGeomGUI->getApp()->selectionMgr()->clearSelected();
212 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
213 this, SLOT(SelectionIntoArgument()));
215 if (!myFace->_is_nil() && myPoint->_is_nil())
216 GroupArgs->PushButton2->click();
218 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
220 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
222 TColStd_IndexedMapOfInteger aMap;
223 aSelMgr->GetIndexes(aSelList.First(), aMap);
224 if (aMap.Extent() == 1) // Local Selection
226 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
227 int anIndex = aMap(1);
228 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
229 aName += QString(":vertex_%1").arg(anIndex);
231 else // Global Selection
233 if (aShape.ShapeType() != TopAbs_VERTEX) {
234 aSelectedObject = GEOM::GEOM_Object::_nil();
239 myPoint = aSelectedObject;
240 myEditCurrentArgument->setText(aName);
243 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
244 myGeomGUI->getApp()->selectionMgr()->clearSelected();
245 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
246 this, SLOT(SelectionIntoArgument()));
248 if (!myPoint->_is_nil() && myFace->_is_nil())
249 GroupArgs->PushButton1->click();
255 //=================================================================================
256 // function : SetEditCurrentArgument()
258 //=================================================================================
259 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
261 QPushButton* send = (QPushButton*)sender();
263 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
264 globalSelection(GEOM_FACE);
266 if (send == GroupArgs->PushButton1) {
267 myEditCurrentArgument = GroupArgs->LineEdit1;
269 GroupArgs->PushButton2->setDown(false);
270 GroupArgs->LineEdit2->setEnabled(false);
272 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
274 else if (send == GroupArgs->PushButton2) {
275 myEditCurrentArgument = GroupArgs->LineEdit2;
277 GroupArgs->PushButton1->setDown(false);
278 GroupArgs->LineEdit1->setEnabled(false);
280 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
282 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
283 this, SLOT(SelectionIntoArgument()));
286 myEditCurrentArgument->setEnabled(true);
287 myEditCurrentArgument->setFocus();
288 // after setFocus(), because it will be setDown(false) when loses focus
291 // seems we need it only to avoid preview disappearing, caused by selection mode change
295 //=================================================================================
296 // function : LineEditReturnPressed()
298 //=================================================================================
299 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
301 QLineEdit* send = (QLineEdit*)sender();
302 if (send == GroupArgs->LineEdit1 ||
303 send == GroupArgs->LineEdit2) {
304 myEditCurrentArgument = send;
305 GEOMBase_Skeleton::LineEditReturnPressed();
309 //=================================================================================
310 // function : ActivateThisDialog()
312 //=================================================================================
313 void MeasureGUI_NormaleDlg::ActivateThisDialog()
315 GEOMBase_Skeleton::ActivateThisDialog();
316 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
317 this, SLOT( SelectionIntoArgument() ) );
322 //=================================================================================
323 // function : enterEvent()
325 //=================================================================================
326 void MeasureGUI_NormaleDlg::enterEvent (QEvent*)
328 if (!mainFrame()->GroupConstructors->isEnabled())
329 ActivateThisDialog();
332 //=================================================================================
333 // function : createOperation
335 //=================================================================================
336 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
338 return getGeomEngine()->GetIMeasureOperations(getStudyId());
341 //=================================================================================
342 // function : isValid
344 //=================================================================================
345 bool MeasureGUI_NormaleDlg::isValid (QString&)
347 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
348 return !CORBA::is_nil(myFace);
351 //=================================================================================
352 // function : execute
354 //=================================================================================
355 bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
357 GEOM::GEOM_Object_var anObj =
358 GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint);
360 if (!anObj->_is_nil())
361 objects.push_back(anObj._retn());