From a31d447668d2181be1a59b9870a1f3ceeb4ddf67 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 16 Mar 2016 11:19:15 +0300 Subject: [PATCH] Angle presentation: proving acute and obtuse angles. --- .../SketchPlugin_ConstraintAngle.cpp | 8 ++++++- src/SketcherPrs/AIS_AngleDimension.cxx | 24 ++++++++++++++++--- src/SketcherPrs/AIS_AngleDimension.hxx | 6 +++++ src/SketcherPrs/CMakeLists.txt | 2 ++ src/SketcherPrs/SketcherPrs_Angle.cpp | 20 ++++------------ 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 06ba78238..6f3f8b853 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -169,10 +169,16 @@ double SketchPlugin_ConstraintAngle::calculateAngle() aEndA = aStartA; if (aDist[1][0] > aDist[1][1]) aEndB = aStartB; + std::shared_ptr aDirA(new GeomAPI_Dir2d(aEndA->xy()->decreased(anInter->xy()))); std::shared_ptr aDirB(new GeomAPI_Dir2d(aEndB->xy()->decreased(anInter->xy()))); - anAngle = fabs(aDirA->angle(aDirB)) * 180.0 / PI; + double aDirAngle = aDirA->angle(aDirB); + if (aDirAngle < 0) + aDirAngle += 2.0 * PI; + anAngle = fabs(aDirAngle) * 180.0 / PI; + //anAngle = fabs(aDirA->angle(aDirB)) * 180.0 / PI; + return anAngle; } diff --git a/src/SketcherPrs/AIS_AngleDimension.cxx b/src/SketcherPrs/AIS_AngleDimension.cxx index 2767e0310..4e2673625 100755 --- a/src/SketcherPrs/AIS_AngleDimension.cxx +++ b/src/SketcherPrs/AIS_AngleDimension.cxx @@ -277,6 +277,7 @@ void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace, //======================================================================= void AIS_AngleDimension::Init() { + SetGeometryOrientedAngle (Standard_False); SetSpecialSymbol (THE_DEGREE_SYMBOL); SetDisplaySpecialSymbol (AIS_DSS_After); SetFlyout (15.0); @@ -337,7 +338,13 @@ void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentat } gp_Pln aPlane = aConstructPlane.Value(); - + if (myGeometryOrientedAngle) { + gp_Ax1 anAxis = aPlane.Axis(); + gp_Dir aDir = anAxis.Direction(); + aDir.Reverse(); + aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir)); + } + // construct circle forming the arc gce_MakeCirc aConstructCircle (theCenter, aPlane, theRadius); if (!aConstructCircle.IsDone()) @@ -348,7 +355,8 @@ void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentat gp_Circ aCircle = aConstructCircle.Value(); // construct the arc - GC_MakeArcOfCircle aConstructArc (aCircle, theFirstAttach, theSecondAttach, Standard_True); + Standard_Boolean isArcSense = !myGeometryOrientedAngle; + GC_MakeArcOfCircle aConstructArc(aCircle, theFirstAttach, theSecondAttach, isArcSense); if (!aConstructArc.IsDone()) { return; @@ -363,7 +371,8 @@ void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentat gp_Vec aCenterToFirstVec (theCenter, theFirstAttach); gp_Vec aCenterToSecondVec (theCenter, theSecondAttach); const Standard_Real anAngle = aCenterToFirstVec.Angle (aCenterToSecondVec); - const Standard_Integer aNbPoints = Max (4, Standard_Integer (50.0 * anAngle / M_PI)); + const Standard_Integer aNbPoints = myGeometryOrientedAngle ? 40 : + Max (4, Standard_Integer (50.0 * anAngle / M_PI)); GCPnts_UniformAbscissa aMakePnts (anArcAdaptor, aNbPoints); if (!aMakePnts.IsDone()) @@ -1229,6 +1238,15 @@ void AIS_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos) myFixedTextPosition = theTextPos; } +//======================================================================= +//function : SetGeometryOrientedAngle +//purpose : +//======================================================================= +void AIS_AngleDimension::SetGeometryOrientedAngle(const Standard_Boolean& theState) +{ + myGeometryOrientedAngle = theState; +} + //======================================================================= //function : AdjustParameters //purpose : diff --git a/src/SketcherPrs/AIS_AngleDimension.hxx b/src/SketcherPrs/AIS_AngleDimension.hxx index 3a4495666..5e2c13390 100755 --- a/src/SketcherPrs/AIS_AngleDimension.hxx +++ b/src/SketcherPrs/AIS_AngleDimension.hxx @@ -207,6 +207,11 @@ public: Standard_EXPORT virtual const gp_Pnt GetTextPosition () const; + //! Sets state if the create arc should be built depending on the input geometry orientation + //! or to be always oriented in [0,0,1]. The last case propose angles more than 180 degree. + //! @param theSecondAttach [in] the second attachment point. + void SetGeometryOrientedAngle(const Standard_Boolean& theState); + public: DEFINE_STANDARD_RTTI (AIS_AngleDimension) @@ -335,6 +340,7 @@ protected: const gp_Pnt& theSecondPoint) const; private: + Standard_Boolean myGeometryOrientedAngle; gp_Pnt myFirstPoint; gp_Pnt mySecondPoint; diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 55d73ee50..acdb1d7ee 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS SketcherPrs_Mirror.h SketcherPrs_Transformation.h SketcherPrs_Angle.h + AIS_AngleDimension.hxx ) SET(PROJECT_SOURCES @@ -48,6 +49,7 @@ SET(PROJECT_SOURCES SketcherPrs_Mirror.cpp SketcherPrs_Transformation.cpp SketcherPrs_Angle.cpp + AIS_AngleDimension.cxx ) SET(PROJECT_LIBRARIES diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index e1133f7f8..d5f3cff71 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -116,37 +116,25 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP switch (anAngleType) { case ANGLE_DIRECT: { - /*gp_Pnt aPnt1(200, 100, 0); - gp_Pnt aPnt2(100, 100, 0); - gp_Pnt aPnt3(200, 200, 0); - //SetMeasuredGeometry(aPnt1, aPnt2, aPnt3); - SetMeasuredGeometry(aPnt3, aPnt2, aPnt1); - gp_Pln aPlane(aPnt2, gp_Dir(0, 0, 1)); - SetCustomPlane(aPlane); - */ + SetGeometryOrientedAngle(false); SetMeasuredGeometry(aEdge1, aEdge2); } break; case ANGLE_SUPPLEMENTARY: { // to calculate center, first and end points + SetGeometryOrientedAngle(false); SetMeasuredGeometry(aEdge1, aEdge2); - /* gp_Pnt aCenterPnt = CenterPoint(); gp_Pnt aFirstPnt = FirstPoint(); gp_Pnt aSecondPnt = SecondPoint(); - - //gp_Pnt aFirstPnt(200, 100, 0); - //gp_Pnt aCenterPnt(100, 100, 0); - //gp_Pnt aSecondPnt(200, 200, 0); double anEdge2Length = aCenterPnt.Distance(aSecondPnt); - aSecondPnt = aCenterPnt.Translated (gp_Vec(aCenterPnt, aSecondPnt).Normalized() * (-anEdge2Length)); SetMeasuredGeometry(aFirstPnt, aCenterPnt, aSecondPnt); - */ } break; case ANGLE_BACKWARD: { - SetMeasuredGeometry(aEdge2, aEdge1); + SetGeometryOrientedAngle(true); + SetMeasuredGeometry(aEdge1, aEdge2); } break; default: -- 2.39.2