-// Copyright (C) 2019 CEA/DEN, EDF R&D
+// Copyright (C) 2019-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_ConstraintAngle.h>
#include <SketchPlugin_Line.h>
+#include <SketcherPrs_Tools.h>
+
#include <cmath>
SketchAPI_ConstraintAngle::SketchAPI_ConstraintAngle(
std::shared_ptr<GeomAPI_Angle2d> anAng(new GeomAPI_Angle2d(
aStartA->pnt(), aEndA->pnt(), aStartB->pnt(), aEndB->pnt()));
- theAngleDirect = anAng->angleDegree();
+ theAngleDirect = fabs(anAng->angleDegree());
+ theAngleComplementary = 180.0 - theAngleDirect;
theAngleBackward = 360.0 - theAngleDirect;
-
- if (theAngleDirect > 180.0)
- theAngleComplementary = theAngleDirect - 180.0;
- else
- theAngleComplementary = 180.0 - theAngleDirect;
}
static std::string angleTypeToString(FeaturePtr theFeature)
{
static const double TOLERANCE = 1.e-7;
+ static const std::string THE_ANGLE_DIRECT("Direct");
+ static const std::string THE_ANGLE_SUPPLEMENTARY("Supplementary");
+ static const std::string THE_ANGLE_BACKWARD("Backward");
+
double anAngleDirect, anAngleComplmentary, anAngleBackward;
calculatePossibleValuesOfAngle(theFeature, anAngleDirect, anAngleComplmentary, anAngleBackward);
AttributeDoublePtr aValueAttr = theFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
+ double aDirectDiff = fabs(aValueAttr->value() - anAngleDirect);
+ double aComplementaryDiff = fabs(aValueAttr->value() - anAngleComplmentary);
+ double aBackwardDiff = fabs(aValueAttr->value() - anAngleBackward);
+ AttributeIntegerPtr aTypeAttr = theFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID());
+ bool isDirect = aTypeAttr->value() == SketcherPrs_Tools::ANGLE_DIRECT;
+ bool isComplementary = aTypeAttr->value() == SketcherPrs_Tools::ANGLE_COMPLEMENTARY;
+ bool isBackward = aTypeAttr->value() == SketcherPrs_Tools::ANGLE_BACKWARD;
+
+ // find the minimal difference
std::string aType;
- if (fabs(aValueAttr->value() - anAngleDirect) < TOLERANCE) {
- // Nothing to do.
- // This case is empty and going the first to check the direct angle before the others.
+ if (isDirect && aDirectDiff < TOLERANCE) {
+ aType = THE_ANGLE_DIRECT;
+ }
+ else if (isComplementary && aComplementaryDiff < TOLERANCE)
+ aType = THE_ANGLE_SUPPLEMENTARY;
+ else if (isBackward && aBackwardDiff < TOLERANCE)
+ aType = THE_ANGLE_BACKWARD;
+ else {
+ if (aComplementaryDiff < aDirectDiff && aComplementaryDiff < aBackwardDiff)
+ aType = THE_ANGLE_SUPPLEMENTARY;
+ else if (aBackwardDiff < aDirectDiff && aBackwardDiff < aComplementaryDiff)
+ aType = THE_ANGLE_BACKWARD;
+ else
+ aType = THE_ANGLE_DIRECT;
}
- else if (fabs(aValueAttr->value() - anAngleComplmentary) < TOLERANCE)
- aType = "Complementary";
- else if (fabs(aValueAttr->value() - anAngleBackward) < TOLERANCE)
- aType = "Backward";
return aType;
}
// calculate angle value as it was just applied to the attributes
FeaturePtr aBase = feature();
- std::string aSetterSuffix = angleTypeToString(aBase);
const std::string& aSketchName = theDumper.parentName(aBase);
- theDumper << aBase << " = " << aSketchName << "." << "setAngle" << aSetterSuffix << "(";
+ theDumper.name(aBase, false, true, true); // mark constraint as dumped
+ theDumper << aSketchName << "." << "setAngle(";
bool isFirstAttr = true;
for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
if (aValueAttr && aValueAttr->isInitialized())
theDumper << ", " << aValueAttr;
- theDumper << ")" << std::endl;
+ std::string aType = angleTypeToString(aBase);
+ theDumper << ", type = \"" << aType << "\")" << std::endl;
}