1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : MeasureGUI_AngleDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
24 #include "MeasureGUI_AngleDlg.h"
25 #include "MeasureGUI_Widgets.h"
29 #include <GeometryGUI.h>
31 #include <Basics_OCCTVersion.hxx>
33 #include <SUIT_Session.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ViewWindow.h>
38 #include <SUIT_ViewManager.h>
40 #include <SOCC_ViewModel.h>
41 #include <SalomeApp_Tools.h>
42 #include <SalomeApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
46 #include <AIS_AngleDimension.hxx>
47 #include <AIS_ListIteratorOfListOfInteractive.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRepBuilderAPI_MakeEdge.hxx>
50 #include <BRepBuilderAPI_MakeVertex.hxx>
53 #include <TopoDS_Edge.hxx>
54 #include <Geom_Plane.hxx>
55 #include <gce_MakePln.hxx>
56 #include <Precision.hxx>
58 #include <AIS_Drawer.hxx>
59 #include <Prs3d_LineAspect.hxx>
60 #include <IntTools_EdgeEdge.hxx>
61 #include <IntTools_SequenceOfCommonPrts.hxx>
62 #include <IntTools_CommonPrt.hxx>
65 #include <qlineedit.h>
68 #include <qpushbutton.h>
69 #include <qradiobutton.h>
70 #include <qbuttongroup.h>
72 #include "GEOMImpl_Types.hxx"
74 #include "utilities.h"
76 #include <Standard_Failure.hxx>
77 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
79 //=================================================================================
80 // class : MeasureGUI_AngleDlg()
81 // purpose : Constructs a MeasureGUI_AngleDlg which is a child of 'parent', with the
82 // name 'name' and widget flags set to 'f'.
83 // The dialog will by default be modeless, unless you set 'modal' to
84 // TRUE to construct a modal dialog.
85 //=================================================================================
86 MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
87 : MeasureGUI_Skeleton(GUI, parent)
89 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
90 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ANGLE")));
91 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
93 setWindowTitle(tr("GEOM_MEASURE_ANGLE_TITLE"));
95 /***************************************************************/
96 mainFrame()->GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE"));
97 mainFrame()->RadioButton1->setIcon(image0);
99 myGrp = new MeasureGUI_2Sel1LineEdit(centralWidget());
100 myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ"));
101 myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
102 myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
103 myGrp->TextLabel3->setText(tr(aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" ) == "deg" ? "GEOM_MEASURE_ANGLE_DEG" : "GEOM_MEASURE_ANGLE_RAD"));
104 myGrp->LineEdit3->setReadOnly(true);
105 myGrp->PushButton1->setIcon(image1);
106 myGrp->PushButton2->setIcon(image1);
107 myGrp->LineEdit1->setReadOnly(true);
108 myGrp->LineEdit2->setReadOnly(true);
110 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
111 layout->setMargin(0); layout->setSpacing(6);
112 layout->addWidget(myGrp);
113 /***************************************************************/
115 // Help page reference
116 myHelpFileName = "angle_page.html";
122 //=================================================================================
123 // function : ~MeasureGUI_AngleDlg()
124 // purpose : Destroys the object and frees any allocated resources
125 //=================================================================================
126 MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg()
130 //=================================================================================
133 //=================================================================================
134 void MeasureGUI_AngleDlg::Init()
137 myGrp->LineEdit1->setText("");
138 myGrp->LineEdit2->setText("");
139 myObj = myObj2 = GEOM::GEOM_Object::_nil();
141 mySelBtn = myGrp->PushButton1;
142 mySelEdit = myGrp->LineEdit1;
143 mySelBtn2 = myGrp->PushButton2;
144 mySelEdit2 = myGrp->LineEdit2;
146 myEditCurrentArgument = mySelEdit;
148 // signals and slots connections
149 connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 globalSelection(GEOM_LINE);
153 MeasureGUI_Skeleton::Init();
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection has changed
159 //=================================================================================
160 void MeasureGUI_AngleDlg::SelectionIntoArgument()
162 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
163 SALOME_ListIO aSelList;
164 aSelMgr->selectedObjects(aSelList);
166 GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
168 if (aSelList.Extent() > 0) {
169 aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
173 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
174 myGeomGUI->getApp()->selectionMgr()->clearSelected();
175 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
176 this, SLOT(SelectionIntoArgument()));
178 if (myEditCurrentArgument == mySelEdit) {
179 myObj = aSelectedObject;
180 if (!myObj->_is_nil() && myObj2->_is_nil())
181 myGrp->PushButton2->click();
184 myObj2 = aSelectedObject;
185 if (!myObj2->_is_nil() && myObj->_is_nil())
186 myGrp->PushButton1->click();
192 //=================================================================================
193 // function : processObject()
194 // purpose : Fill dialogs fields in accordance with myObj and myObj2
195 //=================================================================================
196 void MeasureGUI_AngleDlg::processObject()
198 myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : "");
199 myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
202 if (getParameters(anAngle)) {
203 // To avoid the using different angle values in viewer and dialog,
204 // the value from presentation is used in both cases (see buildPrs())
208 myGrp->LineEdit3->setText("");
213 //=================================================================================
214 // function : getParameters()
215 // purpose : Get angle between objects
216 //=================================================================================
217 bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
221 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
223 theAngle = anOper->GetAngle(myObj, myObj2);
225 catch(const SALOME::SALOME_Exception& e) {
226 SalomeApp_Tools::QtCatchCorbaException(e);
230 bool isDone = anOper->IsDone();
232 CORBA::String_var aMsg = anOper->GetErrorCode();
233 SUIT_MessageBox::warning(this,
234 QObject::tr("WRN_WARNING"),
235 QObject::tr(aMsg.in()));
243 //=================================================================================
244 // function : SetEditCurrentArgument()
246 //=================================================================================
247 void MeasureGUI_AngleDlg::SetEditCurrentArgument()
249 QPushButton* send = (QPushButton*)sender();
251 if (send == myGrp->PushButton1) {
252 myEditCurrentArgument = myGrp->LineEdit1;
254 myGrp->PushButton2->setDown(false);
255 myGrp->LineEdit2->setEnabled(false);
258 myEditCurrentArgument = myGrp->LineEdit2;
260 myGrp->PushButton1->setDown(false);
261 myGrp->LineEdit1->setEnabled(false);
264 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
265 globalSelection(GEOM_LINE);
266 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
267 this, SLOT(SelectionIntoArgument()));
270 myEditCurrentArgument->setEnabled(true);
271 myEditCurrentArgument->setFocus();
272 // after setFocus(), because it will be setDown(false) when loses focus
275 // seems we need it only to avoid preview disappearing, caused by selection mode change
279 //=================================================================================
280 // function : LineEditReturnPressed()
282 //=================================================================================
283 void MeasureGUI_AngleDlg::LineEditReturnPressed()
285 QLineEdit* send = (QLineEdit*)sender();
287 if (send == mySelEdit)
288 myEditCurrentArgument = mySelEdit;
290 myEditCurrentArgument = mySelEdit2;
292 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
293 SALOME_ListIO aSelList;
294 aSelMgr->selectedObjects(aSelList);
296 if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), aSelList))
297 mySelEdit->setText(mySelEdit->text());
300 //=================================================================================
301 // function : buildPrs()
303 //=================================================================================
304 SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
308 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
310 if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) ||
311 vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
314 if (anAngle > Precision::Angular()) {
318 if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) &&
319 GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE)) {
320 TopoDS_Edge anEdge1 = TopoDS::Edge(S1);
321 TopoDS_Edge anEdge2 = TopoDS::Edge(S2);
323 Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension( anEdge1, anEdge2 );
325 Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
327 Handle(Geom_Line) geom_lin1,geom_lin2;
328 gp_Pnt ptat11,ptat12,ptat21,ptat22;
329 Standard_Boolean isInfinite1,isInfinite2;
330 Handle(Geom_Curve) extCurv;
331 Standard_Integer extShape;
332 Handle(Geom_Plane) aPlane;
333 if (AIS::ComputeGeometry(anEdge1,
346 Standard_Real arrSize1 = aDimensionStyle->ArrowAspect()->Length();
347 Standard_Real arrSize2 = aDimensionStyle->ArrowAspect()->Length();
348 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.;
349 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.;
350 aDimensionStyle->ArrowAspect()->SetLength( Max(arrSize1, arrSize2) );
353 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
354 int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
355 QString aUnitsAngle = resMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
357 aDimensionStyle->LineAspect()->SetWidth( w );
358 aDimensionStyle->SetTextHorizontalPosition( Prs3d_DTHP_Center );
359 aDimensionStyle->SetTextVerticalPosition( Prs3d_DTVP_Center );
360 aDimensionStyle->MakeText3d( Standard_False );
361 aDimensionStyle->MakeArrows3d( Standard_True );
363 anIO->SetDimensionAspect( aDimensionStyle );
364 anIO->SetDisplayUnits( aUnitsAngle.toLatin1().data() );
365 if (aUnitsAngle == "rad")
366 anIO->SetDisplaySpecialSymbol(AIS_DSS_No);
369 dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
372 aPrs->AddObject(anIO);
374 // set angle value into dialog
375 double anAngle = anIO->GetValue();
376 QString anAngleLabel = "GEOM_MEASURE_ANGLE_RAD";
377 if (aUnitsAngle == "deg") {
378 // using degrees instead of radians
379 anAngle *= 180. / M_PI;
380 anAngleLabel = "GEOM_MEASURE_ANGLE_DEG";
382 myGrp->TextLabel3->setText(tr(anAngleLabel.toLatin1().data()));
383 int aPrecision = resMgr->integerValue( "Geometry", "angle_precision", 6 );
384 myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle, aPrecision));
389 catch(Standard_Failure) {
396 //=================================================================================
397 // function : isValid()
399 //=================================================================================
400 bool MeasureGUI_AngleDlg::isValid (QString& msg)
402 return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil();