X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Angle.cpp;h=f5bcf8e3de258adabb2791c2ae02b9090f5b3ed4;hb=ea593bc59e7e9461f6c4e2afd3f24d621edb1011;hp=0427ff1f46651d05764e97a8b3a0e7f9824ab54e;hpb=63f80d9837b4dcb16e9fafc3b07fac36f6f7b00d;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index 0427ff1f4..f5bcf8e3d 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -1,12 +1,25 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: SketcherPrs_Angle.cpp -// Created: 20 August 2015 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "SketcherPrs_Angle.h" -#include "SketcherPrs_Tools.h" #include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_Tools.h" #include #include @@ -25,19 +38,25 @@ #include #include +/// 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, + double theDimValue, double theTextSize, SketcherPrs_Tools::LocationType theLocationType); + #define PI 3.1415926535897932 //#ifndef WNT // #define COMPILATION_CORRECTION //#endif -IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension); IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension); -SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) +SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, + SketchPlugin_Sketch* theSketcher) : AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), - mySketcherPlane(thePlane), + mySketcher(theSketcher), 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) { @@ -46,9 +65,9 @@ SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, 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(); @@ -76,7 +95,7 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, DataPtr aData = theConstraint->data(); // Flyout point - std::shared_ptr aFlyoutAttr = + std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); if (!aFlyoutAttr->isInitialized()) @@ -90,9 +109,9 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, if (!anAttr2->isInitialized()) return aReadyToDisplay; - FeaturePtr aLineA = + FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); - FeaturePtr aLineB = + FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); if (!aLineA.get() || !aLineB.get()) @@ -117,10 +136,10 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, aStartA->pnt(), aEndA->pnt(), aStartB->pnt(), aEndB->pnt())); else { std::shared_ptr aLine1(new GeomAPI_Lin2d(aStartA->pnt(), aEndA->pnt())); - bool isReversed1 = + bool isReversed1 = aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->value(); std::shared_ptr aLine2(new GeomAPI_Lin2d(aStartB->pnt(), aEndB->pnt())); - bool isReversed2 = + bool isReversed2 = aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value(); anAng = std::shared_ptr( new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2)); @@ -143,11 +162,13 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { + if (!plane().get()) + return; gp_Pnt aFirstPoint, aSecondPoint, aCenterPoint; - bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, + bool aReadyToDisplay = readyToDisplay(myConstraint, plane(), aFirstPoint, aSecondPoint, aCenterPoint); if (aReadyToDisplay) { myFirstPoint = aFirstPoint; @@ -155,15 +176,15 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP myCenterPoint = aCenterPoint; DataPtr aData = myConstraint->data(); - AttributeDoublePtr anAttributeValue = + AttributeDoublePtr anAttributeValue = aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); myValue.init(anAttributeValue); - std::shared_ptr aFlyoutAttr = + std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = - mySketcherPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + std::shared_ptr aFlyoutPnt = + plane()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); myFlyOutPoint = aFlyoutPnt->impl(); } @@ -176,12 +197,12 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP switch (anAngleType) { case SketcherPrs_Tools::ANGLE_DIRECT: { #ifndef COMPILATION_CORRECTION - SetArrowVisible(Standard_False/*first*/, Standard_True/*second*/); + SetArrowsVisibility(AIS_TOAV_Second); #endif SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint); #ifndef COMPILATION_CORRECTION bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); - SetAngleReversed(!isReversedPlanes); + SetType(!isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior); #endif } break; @@ -192,18 +213,18 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP gp_Vec(myCenterPoint, myFirstPoint).Normalized() * (-anEdge1Length)); SetMeasuredGeometry(aFirstPoint, myCenterPoint, mySecondPoint); #ifndef COMPILATION_CORRECTION - SetAngleReversed(false); + SetType(AIS_TOA_Interior); #endif } break; case SketcherPrs_Tools::ANGLE_BACKWARD: { #ifndef COMPILATION_CORRECTION - SetArrowVisible(Standard_False/*first*/, Standard_True/*second*/); + SetArrowsVisibility(AIS_TOAV_Second); #endif SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint); bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); #ifndef COMPILATION_CORRECTION - SetAngleReversed(isReversedPlanes); + SetType(isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior); #endif } break; @@ -217,8 +238,19 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP // Update text visualization: parameter value or parameter text myStyleListener->updateDimensions(this, myValue); - myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length()); - myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length()); + double aTextSize = 0.0; + GetValueString(aTextSize); + AttributeIntegerPtr aLocAttr = std::dynamic_pointer_cast + (myConstraint->data()->attribute(SketchPlugin_ConstraintAngle::LOCATION_TYPE_ID())); + 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); @@ -247,22 +279,22 @@ void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSel default: { // there are own selection modes, so the others should be ignored // otherwise, the text selection appears in the viewer - return; + return; } } - SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight()); + SetSelToleranceForText2d(SketcherPrs_Tools::getArrowSize()/5.); AIS_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; }