From 11c8951be50e0b4bd8e614a61f38ddc04265c0c9 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 26 Jun 2014 18:10:13 +0400 Subject: [PATCH] Flyout implemented for parallel and perpendicular constraints --- .../SketchPlugin_ConstraintParallel.cpp | 23 ++++++++- .../SketchPlugin_ConstraintParallel.h | 5 ++ .../SketchPlugin_ConstraintPerpendicular.cpp | 27 ++++++++-- .../SketchPlugin_ConstraintPerpendicular.h | 5 ++ .../SketchPlugin_ConstraintRadius.cpp | 51 +++++++++++++++---- 5 files changed, 96 insertions(+), 15 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index 92e23ead4..f77c95d27 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -6,13 +6,17 @@ #include #include + #include +#include #include #include #include #include +#include +#include SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel() { @@ -61,11 +65,16 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle boost::shared_ptr aLine2 = aLine2Feature->preview(); Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); + boost::shared_ptr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFOPnt2d = aFlyoutAttr->pnt(); + boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y()); + if (anAIS.IsNull()) { Handle(AIS_ParallelRelation) aParallel = new AIS_ParallelRelation(aLine1->impl(), aLine2->impl(), aPlane); - + aParallel->SetPosition(aFlyoutPnt->impl()); anAIS = aParallel; } else @@ -76,9 +85,21 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle aParallel->SetFirstShape(aLine1->impl()); aParallel->SetSecondShape(aLine2->impl()); aParallel->SetPlane(aPlane); + aParallel->SetPosition(aFlyoutPnt->impl()); aParallel->Redisplay(Standard_True); } } return anAIS; } +void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index eae4fcfbb..9496f0722 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -42,6 +42,11 @@ public: /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + /// Moves the feature + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); + /// \brief Use plugin manager for features creation SketchPlugin_ConstraintParallel(); }; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index d3646af7e..1b6cc4d09 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -4,16 +4,20 @@ #include "SketchPlugin_ConstraintPerpendicular.h" -#include - #include #include + #include +#include #include #include #include +#include +#include +#include + SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular() { } @@ -60,11 +64,16 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(H boost::shared_ptr aLine2 = aLine2Feature->preview(); Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); + boost::shared_ptr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFOPnt2d = aFlyoutAttr->pnt(); + boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y()); + if (anAIS.IsNull()) { Handle(AIS_PerpendicularRelation) aPerpendicular = new AIS_PerpendicularRelation(aLine1->impl(), aLine2->impl(), aPlane); - + aPerpendicular->SetPosition(aFlyoutPnt->impl()); anAIS = aPerpendicular; } else @@ -75,9 +84,21 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(H aPerpendicular->SetFirstShape(aLine1->impl()); aPerpendicular->SetSecondShape(aLine2->impl()); aPerpendicular->SetPlane(aPlane); + aPerpendicular->SetPosition(aFlyoutPnt->impl()); aPerpendicular->Redisplay(Standard_True); } } return anAIS; } +void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index 68b733e8c..c960f50e8 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -42,6 +42,11 @@ public: /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + /// Moves the feature + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); + /// \brief Use plugin manager for features creation SketchPlugin_ConstraintPerpendicular(); }; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 6f4d17670..391dbd451 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include +#include #include #include @@ -123,14 +126,13 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( // We want to show a radius dimension starting from the circle centre and // ending at the user-defined point. // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all. - gp_Pnt anAPnt = anAnchor->impl(); - double aDelta = 1/1000.0; - if (anAnchor->x() != 0) - anAnchor->setX(anAnchor->x() + aDelta); - if (anAnchor->y() != 0) - anAnchor->setY(anAnchor->y() + aDelta); - if (anAnchor->z() != 0) - anAnchor->setZ(anAnchor->z() + aDelta); + boost::shared_ptr anAnchorXYZ = anAnchor->xyz(); + anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz()); + boost::shared_ptr aDeltaDir(new GeomAPI_Dir(anAnchorXYZ)); + const double aDelta = 1e-3; + anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x()); + anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y()); + anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z()); if (anAIS.IsNull()) { @@ -169,7 +171,34 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY) if (!aData->isValid()) return; - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + FeaturePtr aFeature = aRef->feature(); + if (!aFeature) + return; + std::string aCenterAttrName; + if (aFeature->getKind() == SKETCH_CIRCLE_KIND) + aCenterAttrName = CIRCLE_ATTR_CENTER; + else if (aFeature->getKind() == SKETCH_ARC_KIND) + aCenterAttrName = ARC_ATTR_CENTER; + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(aFeature->data()->attribute(aCenterAttrName)); + boost::shared_ptr aCenter = aCenterAttr->pnt(); + + // The specified delta applied on the circle curve, + // so it will be scaled due to distance between flyout and center points + boost::shared_ptr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFlyout = aFlyoutAttr->pnt(); + + boost::shared_ptr aRadius = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aScale = aFlyout->distance(aCenter) / aRadius->value(); + + boost::shared_ptr aCircle(new GeomAPI_Circ2d(aCenter, aFlyout)); + aFlyout->setX(aFlyout->x() + aScale * theDeltaX); + aFlyout->setY(aFlyout->y() + aScale * theDeltaY); + aFlyout = aCircle->project(aFlyout); + + aFlyoutAttr->setValue(aFlyout->x(), aFlyout->y()); } -- 2.39.2