X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Angle.cpp;h=88d57dd1ad221a45737fbe9d091e878a1cb7e8bd;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=400f0709994b360c20190fd6afd9d5c8671d78db;hpb=08f1aef6629e6a63cc4671d271ded4de6e826948;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index 400f07099..88d57dd1a 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,14 +12,13 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SketcherPrs_Angle.h" -#include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_DimensionStyle.h" #include "SketcherPrs_Tools.h" #include @@ -39,11 +38,17 @@ #include #include +#include + +#if OCC_VERSION_HEX > 0x070400 +#include +#endif + /// Update variable aspect parameters (depending on viewer scale) /// \param theDimAspect an aspect to be changed /// \param theDimValue an arrow value /// \param theTextSize an arrow value -extern void updateArrows(Handle_Prs3d_DimensionAspect theDimAspect, +extern void updateArrows(Handle(Prs3d_DimensionAspect) theDimAspect, double theDimValue, double theTextSize, SketcherPrs_Tools::LocationType theLocationType); #define PI 3.1415926535897932 @@ -52,26 +57,30 @@ extern void updateArrows(Handle_Prs3d_DimensionAspect theDimAspect, // #define COMPILATION_CORRECTION //#endif -IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, PrsDim_AngleDimension); SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) -: AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), - mySketcherPlane(thePlane), - myFirstPoint(gp_Pnt(0,0,0)), myCenterPoint(gp_Pnt(1,0,0)), mySecondPoint(gp_Pnt(0,1,0)), - myValue(90., false, ""), myFlyOutPoint(0, 0.5, 0) + SketchPlugin_Sketch* theSketcher) +: PrsDim_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), + myConstraint(theConstraint), + mySketcher(theSketcher), + myFirstPoint(gp_Pnt(0,0,0)), + mySecondPoint(gp_Pnt(0,1,0)), + myCenterPoint(gp_Pnt(1, 0, 0)), + myFlyOutPoint(0, 0.5, 0), + myValue(90., false, "") { myAspect = new Prs3d_DimensionAspect(); myAspect->MakeArrows3d(false); myAspect->MakeText3d(false); myAspect->MakeTextShaded(false); myAspect->MakeUnitsDisplayed(false); - myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight()); + myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getConfigTextHeight()); myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize()); SetDimensionAspect(myAspect); - myStyleListener = new SketcherPrs_DimensionStyleListener(); + myStyleListener = new SketcherPrs_DimensionStyle(); } SketcherPrs_Angle::~SketcherPrs_Angle() @@ -92,6 +101,8 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, gp_Pnt& theCenterPoint) { bool aReadyToDisplay = false; + if (!thePlane) + return aReadyToDisplay; DataPtr aData = theConstraint->data(); @@ -142,19 +153,42 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, std::shared_ptr aLine2(new GeomAPI_Lin2d(aStartB->pnt(), aEndB->pnt())); bool isReversed2 = aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value(); + + if (aData->integer(SketchPlugin_ConstraintAngle::TYPE_ID())->value() == + (int)SketcherPrs_Tools::ANGLE_COMPLEMENTARY) + isReversed1 = !isReversed1; + anAng = std::shared_ptr( new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2)); } - gp_Pnt2d aFirstPoint = anAng->firstPoint()->impl(); + gp_Pnt2d aCenterPoint = anAng->center()->impl(); + gp_Pnt2d aFirstPoint, aSecondPoint; + try { + if (anAng->angleRadian() > 0.0) { + aFirstPoint = anAng->firstPoint()->impl(); + aSecondPoint = anAng->secondPoint()->impl(); + } + else { + aFirstPoint = anAng->secondPoint()->impl(); + aSecondPoint = anAng->firstPoint()->impl(); + } + } + catch (...) { + // one of angle lines is degenerated, the presentation cannot be shown + return false; + } + + if (aData->integer(SketchPlugin_ConstraintAngle::TYPE_ID())->value() == + (int)SketcherPrs_Tools::ANGLE_BACKWARD) + std::swap(aFirstPoint, aSecondPoint); + std::shared_ptr aPoint = thePlane->to3D(aFirstPoint.X(), aFirstPoint.Y()); theFirstPoint = aPoint->impl(); - gp_Pnt2d aCenterPoint = anAng->center()->impl(); aPoint = thePlane->to3D(aCenterPoint.X(), aCenterPoint.Y()); theCenterPoint = aPoint->impl(); - gp_Pnt2d aSecondPoint = anAng->secondPoint()->impl(); aPoint = thePlane->to3D(aSecondPoint.X(), aSecondPoint.Y()); theSecondPoint = aPoint->impl(); @@ -166,15 +200,19 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { + if (!plane().get()) + return; + + DataPtr aData = myConstraint->data(); + gp_Pnt aFirstPoint, aSecondPoint, aCenterPoint; - bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, + bool aReadyToDisplay = readyToDisplay(myConstraint, plane(), aFirstPoint, aSecondPoint, aCenterPoint); if (aReadyToDisplay) { myFirstPoint = aFirstPoint; mySecondPoint = aSecondPoint; myCenterPoint = aCenterPoint; - DataPtr aData = myConstraint->data(); AttributeDoublePtr anAttributeValue = aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); myValue.init(anAttributeValue); @@ -183,53 +221,27 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); std::shared_ptr aFlyoutPnt = - mySketcherPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + plane()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); myFlyOutPoint = aFlyoutPnt->impl(); } - DataPtr aData = myConstraint->data(); - std::shared_ptr aTypeAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID())); - SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value()); - double aDist = -1; - switch (anAngleType) { - case SketcherPrs_Tools::ANGLE_DIRECT: { -#ifndef COMPILATION_CORRECTION - SetArrowsVisibility(AIS_TOAV_Second); -#endif - SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint); #ifndef COMPILATION_CORRECTION - bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); - SetType(!isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior); +#if OCC_VERSION_HEX > 0x070400 + SetArrowsVisibility(PrsDim_TypeOfAngleArrowVisibility_Both); +#else + SetArrowsVisibility(AIS_TOAV_Both); #endif - } - break; - case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: { - double anEdge1Length = aCenterPoint.Distance(myFirstPoint); - //aDist = calculateDistanceToFlyoutPoint(); - gp_Pnt aFirstPoint = aCenterPoint.Translated( - gp_Vec(myCenterPoint, myFirstPoint).Normalized() * (-anEdge1Length)); - SetMeasuredGeometry(aFirstPoint, myCenterPoint, mySecondPoint); -#ifndef COMPILATION_CORRECTION - SetType(AIS_TOA_Interior); #endif - } - break; - case SketcherPrs_Tools::ANGLE_BACKWARD: { + SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint); #ifndef COMPILATION_CORRECTION - SetArrowsVisibility(AIS_TOAV_Second); + bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); +#if OCC_VERSION_HEX > 0x070400 + SetType(!isReversedPlanes ? PrsDim_TypeOfAngle_Exterior : PrsDim_TypeOfAngle_Interior); +#else + SetType(!isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior); #endif - SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint); - bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); -#ifndef COMPILATION_CORRECTION - SetType(isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior); #endif - } - break; - default: - break; - } if (aDist < 0) /// it was not calculated yet aDist = calculateDistanceToFlyoutPoint(); SetFlyout(aDist); @@ -239,12 +251,19 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP double aTextSize = 0.0; GetValueString(aTextSize); - AttributeIntegerPtr aLocationTypeAttr = std::dynamic_pointer_cast + AttributeIntegerPtr aLocAttr = std::dynamic_pointer_cast (myConstraint->data()->attribute(SketchPlugin_ConstraintAngle::LOCATION_TYPE_ID())); - updateArrows(myAspect, GetValue(), aTextSize, - (SketcherPrs_Tools::LocationType)(aLocationTypeAttr->value())); + SketcherPrs_Tools::LocationType aLocationType = aLocAttr->isInitialized() ? + (SketcherPrs_Tools::LocationType)(aLocAttr->value()) : SketcherPrs_Tools::LOCATION_AUTOMATIC; + + double aRadius = myCenterPoint.Translated( + gp_Vec(myCenterPoint, myFirstPoint).Normalized()*aDist).Distance(myCenterPoint); + double anAngleValue = myValue.myDoubleValue; + double anAngleCircleLength = aRadius * anAngleValue * PI / 180.; + + updateArrows(myAspect, anAngleCircleLength, aTextSize, aLocationType); - AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode); + PrsDim_AngleDimension::Compute(thePresentationManager, thePresentation, theMode); if (!aReadyToDisplay) SketcherPrs_Tools::sendEmptyPresentationError(myConstraint, @@ -274,19 +293,19 @@ void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSel return; } } - SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight()); - AIS_AngleDimension::ComputeSelection(aSelection, aMode); + SetSelToleranceForText2d(SketcherPrs_Tools::getArrowSize()/5.); + PrsDim_AngleDimension::ComputeSelection(aSelection, aMode); } bool SketcherPrs_Angle::isAnglePlaneReversedToSketchPlane() { bool aReversed = false; - if (!mySketcherPlane.get()) + if (!plane().get()) return aReversed; gp_Pln aPlane = GetPlane(); gp_Dir aDir = aPlane.Axis().Direction(); - double aDot = mySketcherPlane->normal()->dot( + double aDot = plane()->normal()->dot( std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()))); return aDot < 0; }