X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchAPI%2FSketchAPI_ConstraintAngle.cpp;h=4f5eedf235d63b2a44b9977a4256a1ce68f90d09;hb=d5c7ad3c50f89a2ddc2de1866ffb7f09397f3be2;hp=fa12b859241ab15978504fc442c66ff53cf46cca;hpb=6e421e939851e0de46554ae45a3ca0e1f67cd91d;p=modules%2Fshaper.git diff --git a/src/SketchAPI/SketchAPI_ConstraintAngle.cpp b/src/SketchAPI/SketchAPI_ConstraintAngle.cpp index fa12b8592..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,32 +76,46 @@ 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 (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 if (fabs(aValueAttr->value() - anAngleComplmentary) < TOLERANCE) - aType = "Complementary"; - else if (fabs(aValueAttr->value() - anAngleBackward) < TOLERANCE) - aType = "Backward"; return aType; } @@ -111,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) { @@ -129,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; }