X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Angle.cpp;h=c8f79b464d7f1b696f4b4a56cf0b1e8fc69688cc;hb=db25cb9e9be0ce3e2332141f7f2f47f088956bea;hp=8603dd444b790c0801d15a8dcc34b0db2bd56a87;hpb=ec4c89c20d9e981b527288ef230f527e025f4627;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index 8603dd444..c8f79b464 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -1,115 +1,261 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: SketcherPrs_Angle.cpp -// Created: 20 August 2015 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-2017 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_DimensionStyleListener.h" #include "SketcherPrs_Tools.h" #include #include +#include #include #include #include +#include +#include #include #include +#include #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 -IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension); -IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension); +//#ifndef WNT +// #define COMPILATION_CORRECTION +//#endif +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension); -SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, +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), myPlane(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) { 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); - SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight()); + + myStyleListener = new SketcherPrs_DimensionStyleListener(); } -void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) +SketcherPrs_Angle::~SketcherPrs_Angle() { - DataPtr aData = myConstraint->data(); + delete myStyleListener; +} + +bool SketcherPrs_Angle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) +{ + gp_Pnt aFirstPoint, aSecondPoint, aCenterPoint; + return readyToDisplay(theConstraint, thePlane, aFirstPoint, aSecondPoint, aCenterPoint); +} + +bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane, + gp_Pnt& theFirstPoint, gp_Pnt& theSecondPoint, + gp_Pnt& theCenterPoint) +{ + bool aReadyToDisplay = false; + + 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()) - return; // can not create a good presentation - - std::shared_ptr aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + return aReadyToDisplay; // can not create a good presentation AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); if (!anAttr1->isInitialized()) - return; + return aReadyToDisplay; AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); if (!anAttr2->isInitialized()) - return; + return aReadyToDisplay; - // Get angle edges - ObjectPtr aObj1 = anAttr1->object(); - ObjectPtr aObj2 = anAttr2->object(); + FeaturePtr aLineA = + SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + FeaturePtr aLineB = + SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); - std::shared_ptr aShape1 = SketcherPrs_Tools::getShape(aObj1); - std::shared_ptr aShape2 = SketcherPrs_Tools::getShape(aObj2); + if (!aLineA.get() || !aLineB.get()) + return aReadyToDisplay; - if (!aShape1 && !aShape2) - return; + std::shared_ptr aStartA = std::dynamic_pointer_cast( + aLineA->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aEndA = std::dynamic_pointer_cast( + aLineA->attribute(SketchPlugin_Line::END_ID())); + std::shared_ptr aStartB = std::dynamic_pointer_cast( + aLineB->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aEndB = std::dynamic_pointer_cast( + aLineB->attribute(SketchPlugin_Line::END_ID())); + + std::shared_ptr anAng; + bool isFirstPnt = aData->attribute( + SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->isInitialized(); + bool isSecondPnt = aData->attribute( + SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->isInitialized(); + if (!isFirstPnt || !isSecondPnt) + anAng = std::shared_ptr(new GeomAPI_Angle2d( + aStartA->pnt(), aEndA->pnt(), aStartB->pnt(), aEndB->pnt())); + else { + std::shared_ptr aLine1(new GeomAPI_Lin2d(aStartA->pnt(), aEndA->pnt())); + 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 = + aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value(); + anAng = std::shared_ptr( + new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2)); + } + + gp_Pnt2d aFirstPoint = anAng->firstPoint()->impl(); + 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(); + + return true; +} + + +void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + gp_Pnt aFirstPoint, aSecondPoint, aCenterPoint; + bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, + 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); - TopoDS_Shape aTEdge1 = aShape1->impl(); - TopoDS_Shape aTEdge2 = aShape2->impl(); - - TopoDS_Edge aEdge1 = TopoDS::Edge(aTEdge1); - TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2); - SetMeasuredGeometry(aEdge1, aEdge2); - - // Compute intersection point - TopoDS_Vertex aV1, aV2; - TopExp::Vertices(aEdge1, aV1, aV2); - gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1); - gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2); - std::shared_ptr aL1(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(), - aPnt2.X(), aPnt2.Y(), aPnt2.Z())); - TopExp::Vertices(aEdge2, aV1, aV2); - aPnt1 = BRep_Tool::Pnt(aV1); - aPnt2 = BRep_Tool::Pnt(aV2); - std::shared_ptr aL2(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(), - aPnt2.X(), aPnt2.Y(), aPnt2.Z())); - - std::shared_ptr aInter = aL1->intersect(aL2); - gp_Pnt aCenter = aInter->impl(); - - gp_Pnt aFLyPnt(aFlyoutPnt->x(), aFlyoutPnt->y(), aFlyoutPnt->z()); - double aDist = aCenter.Distance(aFLyPnt); + 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()); + 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); +#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: { +#ifndef COMPILATION_CORRECTION + SetArrowsVisibility(AIS_TOAV_Second); +#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); - // Angle value is in degrees - AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE()); - SetCustomValue(aVal->value() * PI / 180.0); + // Update text visualization: parameter value or parameter text + myStyleListener->updateDimensions(this, myValue); + + 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.; - myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length()); - myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length()); + updateArrows(myAspect, anAngleCircleLength, aTextSize, aLocationType); AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode); + + if (!aReadyToDisplay) + SketcherPrs_Tools::sendEmptyPresentationError(myConstraint, + "An empty AIS presentation: SketcherPrs_Angle"); } void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, @@ -132,8 +278,27 @@ 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::getArrowSize()/5.); AIS_AngleDimension::ComputeSelection(aSelection, aMode); } + +bool SketcherPrs_Angle::isAnglePlaneReversedToSketchPlane() +{ + bool aReversed = false; + if (!mySketcherPlane.get()) + return aReversed; + + gp_Pln aPlane = GetPlane(); + gp_Dir aDir = aPlane.Axis().Direction(); + double aDot = mySketcherPlane->normal()->dot( + std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()))); + return aDot < 0; +} + +double SketcherPrs_Angle::calculateDistanceToFlyoutPoint() +{ + return myFlyOutPoint.Distance(myCenterPoint); +}