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"
36 #include "GeometryGUI.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_ViewWindow.h"
40 #include "SUIT_MessageBox.h"
42 #include "SOCC_ViewModel.h"
43 #include "SalomeApp_Tools.h"
44 #include "SalomeApp_Application.h"
47 #include <AIS_AngleDimension.hxx>
48 #include <AIS_ListIteratorOfListOfInteractive.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BRepBuilderAPI_MakeEdge.hxx>
51 #include <BRepBuilderAPI_MakeVertex.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <Geom_Plane.hxx>
56 #include <gce_MakePln.hxx>
57 #include <Precision.hxx>
61 #include <qlineedit.h>
64 #include <qpushbutton.h>
65 #include <qradiobutton.h>
66 #include <qbuttongroup.h>
68 #include "GEOMImpl_Types.hxx"
70 #include "utilities.h"
72 #include <Standard_Failure.hxx>
73 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
75 //=================================================================================
76 // class : MeasureGUI_AngleDlg()
77 // purpose : Constructs a MeasureGUI_AngleDlg which is a child of 'parent', with the
78 // name 'name' and widget flags set to 'f'.
79 // The dialog will by default be modeless, unless you set 'modal' to
80 // TRUE to construct a modal dialog.
81 //=================================================================================
82 MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
83 : MeasureGUI_Skeleton(GUI, parent, "MeasureGUI_AngleDlg")
85 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_ANGLE")));
86 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
88 setCaption(tr("GEOM_MEASURE_ANGLE_TITLE"));
92 GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE"));
93 RadioButton1->setPixmap(image0);
95 myGrp = new MeasureGUI_2Sel1LineEdit_QTD(this, "myGrp");
96 myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ"));
97 myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
98 myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
99 myGrp->TextLabel3->setText(tr("GEOM_MEASURE_ANGLE_IS"));
100 myGrp->LineEdit3->setReadOnly(TRUE);
101 myGrp->PushButton1->setPixmap(image1);
102 myGrp->PushButton2->setPixmap(image1);
103 myGrp->LineEdit1->setReadOnly(true);
104 myGrp->LineEdit2->setReadOnly(true);
106 Layout1->addWidget(myGrp, 1, 0);
108 // Help page reference
109 myHelpFileName = "using_measurement_tools_page.html#angle_anchor";
115 //=================================================================================
116 // function : ~MeasureGUI_AngleDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg()
123 //=================================================================================
126 //=================================================================================
127 void MeasureGUI_AngleDlg::Init()
129 mySelBtn = myGrp->PushButton1;
130 mySelEdit = myGrp->LineEdit1;
131 mySelBtn2 = myGrp->PushButton2;
132 mySelEdit2 = myGrp->LineEdit2;
134 myEditCurrentArgument = mySelEdit;
136 connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 globalSelection(GEOM_LINE);
140 MeasureGUI_Skeleton::Init();
144 //=================================================================================
145 // function : SelectionIntoArgument()
146 // purpose : Called when selection has changed
147 //=================================================================================
148 void MeasureGUI_AngleDlg::SelectionIntoArgument()
150 Standard_Boolean testResult = Standard_False;
151 GEOM::GEOM_Object_var aSelectedObject =
152 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
155 aSelectedObject = GEOM::GEOM_Object::_nil();
157 if (myEditCurrentArgument == mySelEdit)
158 myObj = aSelectedObject;
160 myObj2 = aSelectedObject;
165 //=================================================================================
166 // function : processObject()
167 // purpose : Fill dialogs fields in accordance with myObj and myObj2
168 //=================================================================================
169 void MeasureGUI_AngleDlg::processObject()
171 myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : "");
172 myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
175 if (getParameters(anAngle))
177 myGrp->LineEdit3->setText(DlgRef_SpinBox::PrintDoubleValue(anAngle));
182 myGrp->LineEdit3->setText("");
187 //=================================================================================
188 // function : getParameters()
189 // purpose : Get angle between objects
190 //=================================================================================
191 bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
196 theAngle = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetAngle(myObj, myObj2);
198 catch(const SALOME::SALOME_Exception& e) {
199 SalomeApp_Tools::QtCatchCorbaException(e);
203 bool isDone = getOperation()->IsDone();
205 CORBA::String_var aMsg = getOperation()->GetErrorCode();
206 SUIT_MessageBox::warn1((QWidget*)myGeomGUI->getApp()->desktop(),
207 QObject::tr("WRN_WARNING"),
208 QObject::tr(aMsg.in()),
209 QObject::tr("BUT_OK"));
217 //=================================================================================
218 // function : SetEditCurrentArgument()
220 //=================================================================================
221 void MeasureGUI_AngleDlg::SetEditCurrentArgument()
223 QPushButton* send = (QPushButton*)sender();
225 if (send == mySelBtn) {
226 mySelEdit->setFocus();
227 myEditCurrentArgument = mySelEdit;
230 mySelEdit2->setFocus();
231 myEditCurrentArgument = mySelEdit2;
234 globalSelection(GEOM_LINE);
235 SelectionIntoArgument();
238 //=================================================================================
239 // function : LineEditReturnPressed()
241 //=================================================================================
242 void MeasureGUI_AngleDlg::LineEditReturnPressed()
244 QLineEdit* send = (QLineEdit*)sender();
246 if (send == mySelEdit)
247 myEditCurrentArgument = mySelEdit;
249 myEditCurrentArgument = mySelEdit2;
251 if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), selectedIO()))
252 mySelEdit->setText(mySelEdit->text());
255 //=================================================================================
256 // function : buildPrs()
258 //=================================================================================
259 SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
263 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
265 if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) ||
266 vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
269 if (anAngle > Precision::Angular())
273 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
277 if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) &&
278 GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE))
280 TopoDS_Edge anEdge1 = TopoDS::Edge(S1);
281 TopoDS_Edge anEdge2 = TopoDS::Edge(S2);
283 // Build a plane for angle dimension presentation {P11, P12, P3}
284 TopoDS_Vertex V11, V12, V21, V22;
285 TopExp::Vertices(anEdge1, V11, V12);
286 TopExp::Vertices(anEdge2, V21, V22);
288 gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
289 gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge1));
291 gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
292 gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge2));
301 // *-----/----------*
305 gp_Pnt aP3 (aP22.XYZ() + aP11.XYZ() - aP21.XYZ());
307 gce_MakePln gce_MP (aP11, aP12, aP3);
308 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
310 // Build the angle dimension presentation
312 aLabel.sprintf("%.1f", anAngle);
314 Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension
315 (anEdge1, anEdge2, aPlane, anAngle * PI180,
316 TCollection_ExtendedString((Standard_CString)aLabel.latin1()));
317 Handle(Geom_Line) geom_lin1,geom_lin2;
318 gp_Pnt ptat11,ptat12,ptat21,ptat22;
319 Standard_Boolean isInfinite1,isInfinite2;
320 Handle(Geom_Curve) extCurv;
321 Standard_Integer extShape;
322 if ( AIS::ComputeGeometry(anEdge1,
335 Standard_Real arrSize1 = anIO->ArrowSize();
336 Standard_Real arrSize2 = anIO->ArrowSize();
337 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.;
338 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.;
339 Standard_Real arrowSize = Max(arrSize1,arrSize2);
340 anIO->SetArrowSize(arrowSize);
344 dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
347 aPrs->AddObject(anIO);
352 catch(Standard_Failure)
360 //=================================================================================
361 // function : isValid()
363 //=================================================================================
364 bool MeasureGUI_AngleDlg::isValid(QString& msg)
366 return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil();