X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchAPI%2FSketchAPI_ConstraintAngle.cpp;h=4f5eedf235d63b2a44b9977a4256a1ce68f90d09;hb=d5c7ad3c50f89a2ddc2de1866ffb7f09397f3be2;hp=50bbbb946ef93b285bea8e85887568b142c9b971;hpb=7be9fb87d5945e2d9b22af8421e63ec5b404bad1;p=modules%2Fshaper.git diff --git a/src/SketchAPI/SketchAPI_ConstraintAngle.cpp b/src/SketchAPI/SketchAPI_ConstraintAngle.cpp index 50bbbb946..4f5eedf23 100644 --- a/src/SketchAPI/SketchAPI_ConstraintAngle.cpp +++ b/src/SketchAPI/SketchAPI_ConstraintAngle.cpp @@ -28,6 +28,8 @@ #include #include +#include + #include SketchAPI_ConstraintAngle::SketchAPI_ConstraintAngle( @@ -74,34 +76,45 @@ static void calculatePossibleValuesOfAngle(FeaturePtr theFeature, std::shared_ptr 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 (aDirectDiff > TOLERANCE) { + 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 = "Complementary"; + aType = THE_ANGLE_SUPPLEMENTARY; else if (aBackwardDiff < aDirectDiff && aBackwardDiff < aComplementaryDiff) - aType = "Backward"; + aType = THE_ANGLE_BACKWARD; } return aType; } @@ -114,10 +127,9 @@ void SketchAPI_ConstraintAngle::dump(ModelHighAPI_Dumper& theDumper) const // 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 << aBase << " = " << aSketchName << "." << "setAngle("; bool isFirstAttr = true; for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { @@ -132,5 +144,6 @@ void SketchAPI_ConstraintAngle::dump(ModelHighAPI_Dumper& theDumper) const if (aValueAttr && aValueAttr->isInitialized()) theDumper << ", " << aValueAttr; - theDumper << ")" << std::endl; + std::string aType = angleTypeToString(aBase); + theDumper << ", type = \"" << aType << "\")" << std::endl; }