aCirc->parameter(anEdge->lastPoint(), paramTolerance, anEndParam);
aWasBlocked = data()->blockSendAttributeUpdated(true);
if(aStartParam < aMidParam && aMidParam < anEndParam) {
- setReversed(true);
- } else {
setReversed(false);
+ } else {
+ setReversed(true);
}
data()->blockSendAttributeUpdated(aWasBlocked, false);
}
}
+ } else if(theID == CENTER_ID() || theID == START_ID() || theID == END_ID()) {
+ if(!aCenterAttr->isInitialized()
+ || !aStartAttr->isInitialized()
+ || !anEndAttr->isInitialized()) {
+ return;
+ }
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+ std::shared_ptr<GeomAPI_Pnt2d> aStart = aStartAttr->pnt();
+ std::shared_ptr<GeomAPI_Pnt2d> anEnd = anEndAttr->pnt();
+ double aRadius = aCenter->distance(aStart);
+ if (aRadius < tolerance)
+ return;
+ std::shared_ptr<GeomAPI_Circ2d> aCircleForArc(new GeomAPI_Circ2d(aCenter, aStart));
+
+ bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ // The Arc end point is projected
+ // on the circle formed by center and start points
+ std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEnd);
+ if (aProjection && anEnd->distance(aProjection) > tolerance) {
+ anEndAttr->setValue(aProjection);
+ anEnd = aProjection;
+ }
+ data()->blockSendAttributeUpdated(aWasBlocked, false);
+
+ double aParameterNew = 0.0;
+ if(aCircleForArc->parameter(anEnd, paramTolerance, aParameterNew)) {
+ bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
+ if(!boolean(REVERSED_ID())->value()) {
+ boolean(REVERSED_ID())->setValue(true);
+ }
+ } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
+ if(boolean(REVERSED_ID())->value()) {
+ boolean(REVERSED_ID())->setValue(false);
+ }
+ }
+ data()->blockSendAttributeUpdated(aWasBlocked, false);
+ }
+ myParamBefore = aParameterNew;
}
double aRadius = 0;
#include "SketchPlugin_MacroArc.h"
+#include "SketchPlugin_Arc.h"
#include "SketchPlugin_Sketch.h"
#include "SketchPlugin_Tools.h"
void SketchPlugin_MacroArc::execute()
{
+ // Create arc feature.
+ FeaturePtr anArcFeature = sketch()->addFeature(SketchPlugin_Arc::ID());
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenter);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ anArcFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(myStart);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ anArcFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(myEnd);
+ anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())
+ ->setValue(boolean(REVERSED_ID())->value());
+ anArcFeature->execute();
+
+ myCenter.reset();
+ myStart.reset();
+ myEnd.reset();
+
+ // Create constraints.
+ std::string anArcType = string(ARC_TYPE())->value();
+ if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
+ SketchPlugin_Tools::createConstraint(this,
+ CENTER_POINT_REF_ID(),
+ anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
+ ObjectPtr(),
+ false);
+ SketchPlugin_Tools::createConstraint(this,
+ START_POINT_REF_ID(),
+ anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
+ ObjectPtr(),
+ false);
+ SketchPlugin_Tools::createConstraint(this,
+ END_POINT_REF_ID(),
+ anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
+ ObjectPtr(),
+ false);
+ } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
+ SketchPlugin_Tools::createConstraint(this,
+ START_POINT_REF_ID(),
+ anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
+ ObjectPtr(),
+ false);
+ SketchPlugin_Tools::createConstraint(this,
+ END_POINT_REF_ID(),
+ anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
+ ObjectPtr(),
+ false);
+ SketchPlugin_Tools::createConstraint(this,
+ PASSED_POINT_REF_ID(),
+ AttributePtr(),
+ anArcFeature->lastResult(),
+ true);
+ } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
+ SketchPlugin_Tools::createConstraint(this,
+ END_POINT_REF_ID(),
+ anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
+ ObjectPtr(),
+ false);
+ }
}