#include <GeomAPI_Circ.h>
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Dir.h>
+#include <GeomAPI_XY.h>
#include <GeomAPI_XYZ.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
#include <Config_PropManager.h>
+const double tolerance = 1.e-7;
+
SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
{
}
if (!aData->isValid())
return;
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
- FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
- if (!aFeature)
- return;
- std::string aCenterAttrName;
- if (aFeature->getKind() == SketchPlugin_Circle::ID())
- aCenterAttrName = SketchPlugin_Circle::CENTER_ID();
- else if (aFeature->getKind() == SketchPlugin_Arc::ID())
- aCenterAttrName = SketchPlugin_Arc::CENTER_ID();
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aFeature->data()->attribute(aCenterAttrName));
- std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+ // The flyout point is calculated in local coordinates of the shape,
+ // so the center should be coincident with origin
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter(new GeomAPI_Pnt2d(0.0, 0.0));
// The specified delta applied on the circle curve,
// so it will be scaled due to distance between flyout and center points
aFlyout->setY(aFlyout->y() + aScale * theDeltaY);
aFlyout = aCircle->project(aFlyout);
+ myFlyoutUpdate = true;
aFlyoutAttr->setValue(aFlyout->x(), aFlyout->y());
+ myFlyoutUpdate = false;
}
void SketchPlugin_ConstraintRadius::attributeChanged(const std::string& theID) {
aValueAttr->setValue(aRadius);
}
}
+ } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
+ // Recalculate flyout point in local coordinates of the circle (or arc):
+ // coordinates are calculated according to center of the shape
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!aRefAttr || !aRefAttr->isObject())
+ return;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ if (!aFeature || (aFeature->getKind() != SketchPlugin_Arc::ID() &&
+ aFeature->getKind() != SketchPlugin_Circle::ID()))
+ return;
+
+ std::string aCenterAttrName;
+ if (aFeature->getKind() == SketchPlugin_Circle::ID())
+ aCenterAttrName = SketchPlugin_Circle::CENTER_ID();
+ else if (aFeature->getKind() == SketchPlugin_Arc::ID())
+ aCenterAttrName = SketchPlugin_Arc::CENTER_ID();
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(aFeature->data()->attribute(aCenterAttrName));
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+ std::shared_ptr<ModelAPI_AttributeDouble> aRadius = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(attribute(SketchPlugin_Constraint::VALUE()));
+
+ std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
+ double aDist = aFlyoutPnt->distance(aCenter);
+ if (aDist < tolerance)
+ return;
+
+ myFlyoutUpdate = true;
+ std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aCenter->xy());
+ aFlyoutAttr->setValue(aFlyoutDir->x(), aFlyoutDir->y());
+ myFlyoutUpdate = false;
}
}
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Arc.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeDouble.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Lin2d.h>
MyArrowSize = theSize;
}
-double getFlyoutDistance(const ModelAPI_Feature* theConstraint,
- const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+double getFlyoutDistance(const ModelAPI_Feature* theConstraint)
{
std::shared_ptr<GeomDataAPI_Point2D> aFlyoutPoint =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
return aFlyoutPoint->y();
}
+std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(const ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ ModelAPI_Feature* aConstraint = const_cast<ModelAPI_Feature*>(theConstraint);
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!aRefAttr || !aRefAttr->isObject() || !aRefAttr->object())
+ return std::shared_ptr<GeomAPI_Pnt>();
+
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter;
+ if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
+ aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
+ } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
+ aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->pnt();
+ } else
+ return std::shared_ptr<GeomAPI_Pnt>();
+
+ std::shared_ptr<GeomAPI_Pnt2d> anOrigin(new GeomAPI_Pnt2d(0.0, 0.0));
+ std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aConstraint->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()))->pnt();
+ double aRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ aConstraint->attribute(SketchPlugin_Constraint::VALUE()))->value();
+ double aLen = aFlyoutPnt->distance(anOrigin);
+ aFlyoutPnt->setX(aCenter->x() + aFlyoutPnt->x() * aRadius / aLen);
+ aFlyoutPnt->setY(aCenter->y() + aFlyoutPnt->y() * aRadius / aLen);
+ return thePlane->to3D(aFlyoutPnt->x(), aFlyoutPnt->y());
+}
};