1 // Copyright (C) 2007-2016 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 <SUIT_Session.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
38 #include <SOCC_ViewModel.h>
39 #include <SalomeApp_Tools.h>
40 #include <SalomeApp_Application.h>
41 #include <LightApp_SelectionMgr.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>
56 #include <Prs3d_LineAspect.hxx>
57 #include <IntTools_EdgeEdge.hxx>
58 #include <IntTools_SequenceOfCommonPrts.hxx>
59 #include <IntTools_CommonPrt.hxx>
62 #include <qlineedit.h>
65 #include <qpushbutton.h>
66 #include <qradiobutton.h>
67 #include <qbuttongroup.h>
69 #include "GEOMImpl_Types.hxx"
71 #include "utilities.h"
73 #include <Standard_Failure.hxx>
74 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
76 //=================================================================================
77 // class : MeasureGUI_AngleDlg()
78 // purpose : Constructs a MeasureGUI_AngleDlg which is a child of 'parent', with the
79 // name 'name' and widget flags set to 'f'.
80 // The dialog will by default be modeless, unless you set 'modal' to
81 // TRUE to construct a modal dialog.
82 //=================================================================================
83 MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
84 : MeasureGUI_Skeleton(GUI, parent)
86 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
87 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ANGLE")));
88 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
90 setWindowTitle(tr("GEOM_MEASURE_ANGLE_TITLE"));
92 /***************************************************************/
93 mainFrame()->GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE"));
94 mainFrame()->RadioButton1->setIcon(image0);
96 myGrp = new MeasureGUI_2Sel1LineEdit(centralWidget());
97 myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ"));
98 myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
99 myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
100 myGrp->TextLabel3->setText(tr(aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" ) == "deg" ? "GEOM_MEASURE_ANGLE_DEG" : "GEOM_MEASURE_ANGLE_RAD"));
101 myGrp->LineEdit3->setReadOnly(true);
102 myGrp->PushButton1->setIcon(image1);
103 myGrp->PushButton2->setIcon(image1);
104 myGrp->LineEdit1->setReadOnly(true);
105 myGrp->LineEdit2->setReadOnly(true);
107 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
108 layout->setMargin(0); layout->setSpacing(6);
109 layout->addWidget(myGrp);
110 /***************************************************************/
112 // Help page reference
113 myHelpFileName = "angle_page.html";
119 //=================================================================================
120 // function : ~MeasureGUI_AngleDlg()
121 // purpose : Destroys the object and frees any allocated resources
122 //=================================================================================
123 MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg()
127 //=================================================================================
130 //=================================================================================
131 void MeasureGUI_AngleDlg::Init()
134 myGrp->LineEdit1->setText("");
135 myGrp->LineEdit2->setText("");
136 myGrp->LineEdit1->setEnabled(true);
137 myGrp->LineEdit2->setEnabled(false);
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()));
153 MeasureGUI_Skeleton::Init();
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection has changed
159 //=================================================================================
160 void MeasureGUI_AngleDlg::SelectionIntoArgument()
162 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_EDGE );
165 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
166 myGeomGUI->getApp()->selectionMgr()->clearSelected();
167 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
168 this, SLOT(SelectionIntoArgument()));
170 if (myEditCurrentArgument == mySelEdit) {
171 myObj = aSelectedObject;
172 if (myObj && !myObj2)
173 myGrp->PushButton2->click();
176 myObj2 = aSelectedObject;
177 if (myObj2 && !myObj)
178 myGrp->PushButton1->click();
184 //=================================================================================
185 // function : processObject()
186 // purpose : Fill dialogs fields in accordance with myObj and myObj2
187 //=================================================================================
188 void MeasureGUI_AngleDlg::processObject()
190 myGrp->LineEdit1->setText(myObj ? GEOMBase::GetName(myObj.get()) : "");
191 myGrp->LineEdit2->setText(myObj2 ? GEOMBase::GetName(myObj2.get()) : "");
194 if (getParameters(anAngle)) {
195 // To avoid the using different angle values in viewer and dialog,
196 // the value from presentation is used in both cases (see buildPrs())
200 myGrp->LineEdit3->setText("");
205 //=================================================================================
206 // function : getParameters()
207 // purpose : Get angle between objects
208 //=================================================================================
209 bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
213 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
215 theAngle = anOper->GetAngle(myObj.get(), myObj2.get());
217 catch(const SALOME::SALOME_Exception& e) {
218 SalomeApp_Tools::QtCatchCorbaException(e);
222 bool isDone = anOper->IsDone();
224 CORBA::String_var aMsg = anOper->GetErrorCode();
225 SUIT_MessageBox::warning(this,
226 QObject::tr("WRN_WARNING"),
227 QObject::tr(aMsg.in()));
235 //=================================================================================
236 // function : SetEditCurrentArgument()
238 //=================================================================================
239 void MeasureGUI_AngleDlg::SetEditCurrentArgument()
241 QPushButton* send = (QPushButton*)sender();
243 if (send == myGrp->PushButton1) {
244 myEditCurrentArgument = myGrp->LineEdit1;
246 myGrp->PushButton2->setDown(false);
247 myGrp->LineEdit2->setEnabled(false);
250 myEditCurrentArgument = myGrp->LineEdit2;
252 myGrp->PushButton1->setDown(false);
253 myGrp->LineEdit1->setEnabled(false);
256 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
258 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
259 this, SLOT(SelectionIntoArgument()));
262 myEditCurrentArgument->setEnabled(true);
263 myEditCurrentArgument->setFocus();
264 // after setFocus(), because it will be setDown(false) when loses focus
267 // seems we need it only to avoid preview disappearing, caused by selection mode change
271 //=================================================================================
272 // function : LineEditReturnPressed()
274 //=================================================================================
275 void MeasureGUI_AngleDlg::LineEditReturnPressed()
277 QLineEdit* send = (QLineEdit*)sender();
279 if (send == mySelEdit)
280 myEditCurrentArgument = mySelEdit;
282 myEditCurrentArgument = mySelEdit2;
284 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
285 SALOME_ListIO aSelList;
286 aSelMgr->selectedObjects(aSelList);
288 if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), aSelList))
289 mySelEdit->setText(mySelEdit->text());
292 //=================================================================================
293 // function : buildPrs()
295 //=================================================================================
296 SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
299 myGrp->LineEdit3->setText("");
301 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
303 if (!myObj || !myObj2 || !getParameters(anAngle) ||
304 vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
307 if (anAngle > Precision::Angular()) {
311 if (GEOMBase::GetShape(myObj.get() , S1, TopAbs_EDGE) &&
312 GEOMBase::GetShape(myObj2.get(), S2, TopAbs_EDGE)) {
313 TopoDS_Edge anEdge1 = TopoDS::Edge(S1);
314 TopoDS_Edge anEdge2 = TopoDS::Edge(S2);
316 Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension( anEdge1, anEdge2 );
318 Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
320 Handle(Geom_Line) geom_lin1,geom_lin2;
321 gp_Pnt ptat11,ptat12,ptat21,ptat22;
322 Standard_Boolean isInfinite1,isInfinite2;
323 Handle(Geom_Curve) extCurv;
324 Standard_Integer extShape;
325 Handle(Geom_Plane) aPlane;
326 if (AIS::ComputeGeometry(anEdge1,
339 Standard_Real arrSize1 = aDimensionStyle->ArrowAspect()->Length();
340 Standard_Real arrSize2 = aDimensionStyle->ArrowAspect()->Length();
341 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.;
342 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.;
343 aDimensionStyle->ArrowAspect()->SetLength( Max(arrSize1, arrSize2) );
346 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
347 int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
348 QString aUnitsAngle = resMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
350 aDimensionStyle->LineAspect()->SetWidth( w );
351 aDimensionStyle->SetTextHorizontalPosition( Prs3d_DTHP_Center );
352 aDimensionStyle->SetTextVerticalPosition( Prs3d_DTVP_Center );
353 aDimensionStyle->MakeText3d( Standard_False );
354 aDimensionStyle->MakeArrows3d( Standard_True );
356 anIO->SetDimensionAspect( aDimensionStyle );
357 anIO->SetDisplayUnits( aUnitsAngle.toUtf8().data() );
358 if (aUnitsAngle == "rad")
359 anIO->SetDisplaySpecialSymbol(AIS_DSS_No);
362 dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
365 aPrs->AddObject(anIO);
367 // set angle value into dialog
368 double anAngle = anIO->GetValue();
369 QString anAngleLabel = "GEOM_MEASURE_ANGLE_RAD";
370 if (aUnitsAngle == "deg") {
371 // using degrees instead of radians
372 anAngle *= 180. / M_PI;
373 anAngleLabel = "GEOM_MEASURE_ANGLE_DEG";
375 myGrp->TextLabel3->setText(tr(anAngleLabel.toUtf8().data()));
376 int aPrecision = resMgr->integerValue( "Geometry", "angle_precision", 6 );
377 myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle, aPrecision));
382 catch(Standard_Failure) {
389 //=================================================================================
390 // function : isValid()
392 //=================================================================================
393 bool MeasureGUI_AngleDlg::isValid (QString& msg)
395 return MeasureGUI_Skeleton::isValid(msg) && myObj2;
398 //=================================================================================
399 // function : activateSelection()
401 //=================================================================================
402 void MeasureGUI_AngleDlg::activateSelection()
404 globalSelection(GEOM_LINE);
405 localSelection( TopAbs_EDGE );