From a2712247ec6b1ff00fb85ce07d0fe5094be58e36 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 22 Apr 2016 07:43:16 +0300 Subject: [PATCH] Issue #1299, Issue #1393 Angle constraint: support of additional and complementary angles: correction to use GeomAPI_Angly2d to build AIS presentation by 3 points --- src/SketchSolver/SketchSolver_Manager.cpp | 2 + src/SketcherPrs/SketcherPrs_Angle.cpp | 118 +++++++++++----------- src/SketcherPrs/SketcherPrs_Angle.h | 3 + 3 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index 82f0c826b..15b28b09b 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -523,6 +523,8 @@ void SketchSolver_Manager::degreesOfFreedom() else if (aFeature->getKind() == SketchPlugin_ConstraintRigid::ID()) { AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast( aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); + if (!aRefAttr->isInitialized()) + continue; assert(aRefAttr); if (!aRefAttr->isObject()) aDoF -= 2; // attribute is a point diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index d4264233e..7082faaab 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -10,10 +10,13 @@ #include #include +#include #include #include #include +#include +#include #include #include @@ -85,6 +88,54 @@ bool SketcherPrs_Angle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } +bool SketcherPrs_Angle::getPoints(gp_Pnt& theFirstPoint, gp_Pnt& theSecondPoint, + gp_Pnt& theCenterPoint, double& theAngle) const +{ + bool aReadyToDisplay = false; + + std::shared_ptr aData = myConstraint->data(); + std::shared_ptr aPlane = myPlane; + FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + + 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; + if (!aData->attribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->isInitialized() || + !aData->attribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->isInitialized()) + 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)); + } + theAngle = anAng->angleDegree(); + + gp_Pnt2d aFirstPoint = anAng->firstPoint()->impl(); + std::shared_ptr aPoint = myPlane->to3D(aFirstPoint.X(), aFirstPoint.Y()); + theFirstPoint = aPoint->impl(); + + gp_Pnt2d aCenterPoint = anAng->center()->impl(); + aPoint = myPlane->to3D(aCenterPoint.X(), aCenterPoint.Y()); + theCenterPoint = aPoint->impl(); + + gp_Pnt2d aSecondPoint = anAng->secondPoint()->impl(); + aPoint = myPlane->to3D(aSecondPoint.X(), aSecondPoint.Y()); + theSecondPoint = aPoint->impl(); + + return aReadyToDisplay; +} + void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) @@ -100,76 +151,29 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID())); SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value()); - AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); - AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); - - // Get angle edges - ObjectPtr aObj1 = anAttr1->object(); - ObjectPtr aObj2 = anAttr2->object(); - - std::shared_ptr aShape1 = SketcherPrs_Tools::getShape(aObj1); - std::shared_ptr aShape2 = SketcherPrs_Tools::getShape(aObj2); - - TopoDS_Shape aTEdge1 = aShape1->impl(); - TopoDS_Shape aTEdge2 = aShape2->impl(); - - TopoDS_Edge aEdge1 = TopoDS::Edge(aTEdge1); - TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2); + gp_Pnt aFirstPoint, aSecondPoint, aCenterPoint; + double aValue; + getPoints(aFirstPoint, aSecondPoint, aCenterPoint, aValue); double aDist = -1; - switch (anAngleType) { case SketcherPrs_Tools::ANGLE_DIRECT: { SetArrowVisible(Standard_False/*first*/, Standard_True/*second*/); - /* - std::shared_ptr anEdge1 = std::shared_ptr(new GeomAPI_Edge(aShape1)); - std::shared_ptr anEdge2 = std::shared_ptr(new GeomAPI_Edge(aShape2)); - - std::shared_ptr aLin1 = anEdge1->line(); - std::shared_ptr aLin2 = anEdge2->line(); - - std::shared_ptr aCenterPnt = aLin1->intersect(aLin2); - std::shared_ptr aDir1 = aLin1->direction(); - std::shared_ptr aDir2 = aLin2->direction(); - - const gp_Pnt& aCenterPoint = aCenterPnt->impl(); - - const gp_Dir& aDirection1 = aDir1->impl(); - const gp_Dir& aDirection2 = aDir2->impl(); - - gp_Pnt aFirstPoint = aCenterPoint.Translated (gp_Vec (aDirection1)); - gp_Pnt aSecondPoint = aCenterPoint.Translated (gp_Vec (aDirection2)); - - SetMeasuredGeometry(aFirstPoint, aCenterPoint, aSecondPoint);*/ - SetMeasuredGeometry(aEdge1, aEdge2, Standard_False); + SetMeasuredGeometry(aFirstPoint, aCenterPoint, aSecondPoint); bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); SetAngleReversed(!isReversedPlanes); } break; case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: { - SetArrowVisible(Standard_True/*first*/, Standard_False/*second*/); - // to calculate center, first and end points - SetAngleReversed(false); - SetMeasuredGeometry(aEdge1, aEdge2, Standard_False); - /// the first point will be moved, so it is necessary to find distance - /// after applying initial parameters of geometry but before correcting them - /// for the current type of angle(complementary) - aDist = calculateDistanceToFlyoutPoint(); - /// invert the first edge according to the angle center - gp_Pnt aCenter = CenterPoint(); - gp_Pnt aFirst = FirstPoint(); - gp_Pnt aSecond = SecondPoint(); - double anEdge1Length = aCenter.Distance(aFirst); - aFirst = aCenter.Translated (gp_Vec(aCenter, aFirst).Normalized() * (-anEdge1Length)); - anEdge1Length = aCenter.Distance(aFirst); - - SetMeasuredGeometry(aFirst, aCenter, aSecond); + double anEdge1Length = aCenterPoint.Distance(aFirstPoint); + aFirstPoint = aCenterPoint.Translated (gp_Vec(aCenterPoint, aFirstPoint).Normalized() * (-anEdge1Length)); + anEdge1Length = aCenterPoint.Distance(aFirstPoint); + SetMeasuredGeometry(aFirstPoint, aCenterPoint, aSecondPoint); } break; case SketcherPrs_Tools::ANGLE_BACKWARD: { SetArrowVisible(Standard_False/*first*/, Standard_True/*second*/); - - SetMeasuredGeometry(aEdge1, aEdge2, Standard_False); + SetMeasuredGeometry(aFirstPoint, aCenterPoint, aSecondPoint); bool isReversedPlanes = isAnglePlaneReversedToSketchPlane(); SetAngleReversed(isReversedPlanes); } @@ -183,7 +187,7 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP // Angle value is in degrees AttributeDoublePtr aVal = aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); - SetCustomValue(aVal->value()); + SetCustomValue(aValue); myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length()); myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length()); diff --git a/src/SketcherPrs/SketcherPrs_Angle.h b/src/SketcherPrs/SketcherPrs_Angle.h index d2f4c3c35..5e425d09e 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.h +++ b/src/SketcherPrs/SketcherPrs_Angle.h @@ -62,6 +62,9 @@ protected: /// \return real value double calculateDistanceToFlyoutPoint(); + bool getPoints(gp_Pnt& theFirstPoint, gp_Pnt& theSecondPoint, gp_Pnt& theCenterPoint, + double& theAngle) const; + private: /// Constraint feature ModelAPI_Feature* myConstraint; -- 2.39.2