-// Copyright (C) 2017-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2017-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <SketchPlugin_MacroEllipticArc.h>
-////#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchPlugin_EllipticArc.h>
-////#include <SketchPlugin_Line.h>
#include <SketchPlugin_MacroArcReentrantMessage.h>
-////#include <SketchPlugin_Point.h>
#include <SketchPlugin_Tools.h>
#include <SketchPlugin_Sketch.h>
#include <GeomAlgoAPI_PointBuilder.h>
+const double TOLERANCE = 1.e-7;
const double paramTolerance = 1.e-4;
const double PI = 3.141592653589793238463;
void SketchPlugin_MacroEllipticArc::execute()
{
FeaturePtr anEllipse = createEllipticArcFeature();
+ constraintsForEllipticArc(anEllipse);
// message to init reentrant operation
static Events_ID anId = SketchPlugin_MacroArcReentrantMessage::eventId();
Events_Loop::loop()->send(aMessage);
}
-void SketchPlugin_MacroEllipticArc::attributeChanged(const std::string& theID)
+void SketchPlugin_MacroEllipticArc::attributeChanged(const std::string& /*theID*/)
{
static const int NB_POINTS = 4;
std::string aPointAttrName[NB_POINTS] = { CENTER_ID(),
myStartPnt = anEllipsePoints[2];
myEndPnt = anEllipsePoints[3];
+ if (myCenter->distance(myMajorAxis) < TOLERANCE)
+ return; // ellipse is not valid
+
std::shared_ptr<GeomAPI_Ellipse2d> anEllipse;
if (aNbInitialized == 2) {
GeomDir2dPtr aXDir(new GeomAPI_Dir2d(anEllipsePoints[1]->x() - anEllipsePoints[0]->x(),
}
// LCOV_EXCL_STOP
-////void SketchPlugin_MacroEllipticArc::constraintsForEllipseByCenterAxisAndPassed(
-//// FeaturePtr theEllipseFeature)
-////{
-//// // tangency on-the-fly is not applicable for ellipses
-//// static const bool isTangencyApplicable = false;
-//// // Create constraints.
-//// SketchPlugin_Tools::createCoincidenceOrTangency(
-//// this, FIRST_POINT_REF_ID(),
-//// theEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()),
-//// ObjectPtr(), isTangencyApplicable);
-//// SketchPlugin_Tools::createCoincidenceOrTangency(
-//// this, SECOND_POINT_REF_ID(),
-//// theEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()),
-//// ObjectPtr(), isTangencyApplicable);
-//// // make coincidence only if PASSED_POINT_REF_ID() refers a point but not an object
-//// if (!refattr(PASSED_POINT_REF_ID())->isObject()) {
-//// SketchPlugin_Tools::createCoincidenceOrTangency(
-//// this, PASSED_POINT_REF_ID(), AttributePtr(),
-//// theEllipseFeature->lastResult(), isTangencyApplicable);
-//// }
-////}
-////
-////void SketchPlugin_MacroEllipticArc::constraintsForEllipseByMajoxAxisAndPassed(
-//// FeaturePtr theEllipseFeature)
-////{
-//// // tangency on-the-fly is not applicable for ellipses
-//// static const bool isTangencyApplicable = false;
-//// // Create constraints.
-//// SketchPlugin_Tools::createCoincidenceOrTangency(
-//// this, FIRST_POINT_REF_ID(),
-//// theEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()),
-//// ObjectPtr(), isTangencyApplicable);
-//// SketchPlugin_Tools::createCoincidenceOrTangency(
-//// this, SECOND_POINT_REF_ID(),
-//// theEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()),
-//// ObjectPtr(), isTangencyApplicable);
-//// // make coincidence only if PASSED_POINT_REF_ID() refers a point but not an object
-//// if (!refattr(PASSED_POINT_REF_ID())->isObject()) {
-//// SketchPlugin_Tools::createCoincidenceOrTangency(
-//// this, PASSED_POINT_REF_ID(), AttributePtr(),
-//// theEllipseFeature->lastResult(), isTangencyApplicable);
-//// }
-////}
-
FeaturePtr SketchPlugin_MacroEllipticArc::createEllipticArcFeature()
{
GeomShapePtr anArc = getArcShape();
GeomEdgePtr anArcEdge = anArc->edge();
aStartPoint = anArcEdge->firstPoint();
aEndPoint = anArcEdge->lastPoint();
+ if (boolean(REVERSED_ID())->value())
+ std::swap(aStartPoint, aEndPoint);
if (anArcEdge->isEllipse())
anEllipse = anArcEdge->ellipse();
return aEllipseFeature;
}
+void SketchPlugin_MacroEllipticArc::constraintsForEllipticArc(FeaturePtr theEllipticArc)
+{
+ // tangency on-the-fly is not applicable for elliptic arcs
+ static const bool isTangencyApplicable = false;
+ // Create constraints.
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, CENTER_REF_ID(),
+ theEllipticArc->attribute(SketchPlugin_EllipticArc::CENTER_ID()),
+ ObjectPtr(), isTangencyApplicable);
+ // make coincidence only if PASSED_POINT_REF_ID() refers a point but not an object
+ if (!refattr(MAJOR_AXIS_POINT_REF_ID())->isObject()) {
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, MAJOR_AXIS_POINT_REF_ID(),
+ AttributePtr(),
+ theEllipticArc->lastResult(), isTangencyApplicable);
+ }
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, START_POINT_REF_ID(),
+ theEllipticArc->attribute(SketchPlugin_EllipticArc::START_POINT_ID()),
+ ObjectPtr(), isTangencyApplicable);
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, END_POINT_REF_ID(),
+ theEllipticArc->attribute(SketchPlugin_EllipticArc::END_POINT_ID()),
+ ObjectPtr(), isTangencyApplicable);
+}
+
AISObjectPtr SketchPlugin_MacroEllipticArc::getAISObject(AISObjectPtr thePrevious)
{
SketchPlugin_Sketch* aSketch = sketch();
if (!anAIS)
anAIS.reset(new GeomAPI_AISObject());
anAIS->createShape(aCompound);
+ SketchPlugin_Tools::customizeFeaturePrs(anAIS, boolean(AUXILIARY_ID())->value());
return anAIS;
}
return GeomShapePtr();
SketchPlugin_Sketch* aSketch = sketch();
- if (!aSketch)
+ if (!aSketch || myCenter->distance(myMajorAxis) < 1.e-7)
return GeomShapePtr();
GeomPointPtr aCenter(aSketch->to3D(myCenter->x(), myCenter->y()));