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_AngleDlg.cxx
25 // Author : Julia DOROVSKIKH
29 #include "MeasureGUI_AngleDlg.h"
31 #include "MeasureGUI_2Sel1LineEdit_QTD.h"
34 #include "GEOM_Displayer.h"
35 #include "DlgRef_SpinBox.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_ViewWindow.h"
40 #include "SOCC_ViewModel.h"
41 #include "SalomeApp_Tools.h"
44 #include <AIS_AngleDimension.hxx>
45 #include <AIS_ListIteratorOfListOfInteractive.hxx>
46 #include <BRep_Tool.hxx>
47 #include <BRepBuilderAPI_MakeEdge.hxx>
48 #include <BRepBuilderAPI_MakeVertex.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <Geom_Plane.hxx>
53 #include <gce_MakePln.hxx>
54 #include <Precision.hxx>
57 #include <qlineedit.h>
60 #include <qpushbutton.h>
61 #include <qradiobutton.h>
62 #include <qbuttongroup.h>
64 #include "GEOMImpl_Types.hxx"
66 #include "utilities.h"
68 #include <Standard_Failure.hxx>
69 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
71 //=================================================================================
72 // class : MeasureGUI_AngleDlg()
73 // purpose : Constructs a MeasureGUI_AngleDlg which is a child of 'parent', with the
74 // name 'name' and widget flags set to 'f'.
75 // The dialog will by default be modeless, unless you set 'modal' to
76 // TRUE to construct a modal dialog.
77 //=================================================================================
78 MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
79 : MeasureGUI_Skeleton(GUI, parent, "MeasureGUI_AngleDlg")
81 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_ANGLE")));
82 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
84 setCaption(tr("GEOM_MEASURE_ANGLE_TITLE"));
88 GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE"));
89 RadioButton1->setPixmap(image0);
91 myGrp = new MeasureGUI_2Sel1LineEdit_QTD(this, "myGrp");
92 myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ"));
93 myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
94 myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
95 myGrp->TextLabel3->setText(tr("GEOM_MEASURE_ANGLE_IS"));
96 myGrp->LineEdit3->setReadOnly(TRUE);
97 myGrp->PushButton1->setPixmap(image1);
98 myGrp->PushButton2->setPixmap(image1);
99 myGrp->LineEdit1->setReadOnly(true);
100 myGrp->LineEdit2->setReadOnly(true);
102 Layout1->addWidget(myGrp, 1, 0);
104 // Help page reference
105 myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#Angle";
111 //=================================================================================
112 // function : ~MeasureGUI_AngleDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg()
119 //=================================================================================
122 //=================================================================================
123 void MeasureGUI_AngleDlg::Init()
125 mySelBtn = myGrp->PushButton1;
126 mySelEdit = myGrp->LineEdit1;
127 mySelBtn2 = myGrp->PushButton2;
128 mySelEdit2 = myGrp->LineEdit2;
130 myEditCurrentArgument = mySelEdit;
132 connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 globalSelection(GEOM_LINE);
136 MeasureGUI_Skeleton::Init();
140 //=================================================================================
141 // function : SelectionIntoArgument()
142 // purpose : Called when selection has changed
143 //=================================================================================
144 void MeasureGUI_AngleDlg::SelectionIntoArgument()
146 Standard_Boolean testResult = Standard_False;
147 GEOM::GEOM_Object_var aSelectedObject =
148 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
151 aSelectedObject = GEOM::GEOM_Object::_nil();
153 if (myEditCurrentArgument == mySelEdit)
154 myObj = aSelectedObject;
156 myObj2 = aSelectedObject;
161 //=================================================================================
162 // function : processObject()
163 // purpose : Fill dialogs fields in accordance with myObj and myObj2
164 //=================================================================================
165 void MeasureGUI_AngleDlg::processObject()
167 myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : "");
168 myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
171 if (getParameters(anAngle))
173 myGrp->LineEdit3->setText(DlgRef_SpinBox::PrintDoubleValue(anAngle));
178 myGrp->LineEdit3->setText("");
183 //=================================================================================
184 // function : getParameters()
185 // purpose : Get angle between objects
186 //=================================================================================
187 bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
192 theAngle = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetAngle(myObj, myObj2);
194 catch(const SALOME::SALOME_Exception& e) {
195 SalomeApp_Tools::QtCatchCorbaException(e);
199 return getOperation()->IsDone();
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void MeasureGUI_AngleDlg::SetEditCurrentArgument()
211 QPushButton* send = (QPushButton*)sender();
213 if (send == mySelBtn) {
214 mySelEdit->setFocus();
215 myEditCurrentArgument = mySelEdit;
218 mySelEdit2->setFocus();
219 myEditCurrentArgument = mySelEdit2;
222 globalSelection(GEOM_LINE);
223 SelectionIntoArgument();
226 //=================================================================================
227 // function : LineEditReturnPressed()
229 //=================================================================================
230 void MeasureGUI_AngleDlg::LineEditReturnPressed()
232 QLineEdit* send = (QLineEdit*)sender();
234 if (send == mySelEdit)
235 myEditCurrentArgument = mySelEdit;
237 myEditCurrentArgument = mySelEdit2;
239 if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), selectedIO()))
240 mySelEdit->setText(mySelEdit->text());
243 //=================================================================================
244 // function : buildPrs()
246 //=================================================================================
247 SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
251 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
253 if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) ||
254 vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
257 if (anAngle > Precision::Angular())
261 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
265 if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) &&
266 GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE))
268 TopoDS_Edge anEdge1 = TopoDS::Edge(S1);
269 TopoDS_Edge anEdge2 = TopoDS::Edge(S2);
271 // Build a plane for angle dimension presentation {P11, P12, P3}
272 TopoDS_Vertex V11, V12, V21, V22;
273 TopExp::Vertices(anEdge1, V11, V12);
274 TopExp::Vertices(anEdge2, V21, V22);
276 gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
277 gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge1));
279 gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
280 gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge2));
289 // *-----/----------*
293 gp_Pnt aP3 (aP22.XYZ() + aP11.XYZ() - aP21.XYZ());
295 gce_MakePln gce_MP (aP11, aP12, aP3);
296 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
298 // Build the angle dimension presentation
300 aLabel.sprintf("%.1f", anAngle);
302 Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension
303 (anEdge1, anEdge2, aPlane, anAngle * PI180,
304 TCollection_ExtendedString((Standard_CString)aLabel.latin1()));
307 dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
310 aPrs->AddObject(anIO);
315 catch(Standard_Failure)
323 //=================================================================================
324 // function : isValid()
326 //=================================================================================
327 bool MeasureGUI_AngleDlg::isValid(QString& msg)
329 return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil();