X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintAngle.cpp;h=8fb29c48c33e5866c795c9acc2c01e5798af491e;hb=3f1a42a51c7de1911c75453ff7134593d7d2c6b1;hp=712d436af2aefdf0ad2f536693d4749a8b0ea45e;hpb=091f03f2d26b8532c7e8038471cc0f8684b9a770;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 712d436af..8fb29c48c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -43,6 +44,9 @@ void SketchPlugin_ConstraintAngle::initAttributes() data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(), ModelAPI_AttributeInteger::typeId()); + + data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID(), ModelAPI_AttributeBoolean::typeId()); } void SketchPlugin_ConstraintAngle::colorConfigInfo(std::string& theSection, std::string& theName, @@ -68,7 +72,7 @@ void SketchPlugin_ConstraintAngle::execute() if (!anAttrValue->isInitialized()) { double anAngle = calculateAngle(); anAttrValue->setValue(anAngle); - updateAngleValue(); + updateConstraintValueByAngleValue(); } // the value should to be computed here, not in the getAISObject in order to change the model value // inside the object transaction. This is important for creating a constraint by preselection. @@ -106,7 +110,7 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value double anAngle = calculateAngle(); aValueAttr->setValue(anAngle); - updateAngleValue(); + updateConstraintValueByAngleValue(); } } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { // Recalculate flyout point in local coordinates @@ -135,67 +139,53 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); double anAngle = calculateAngle(); aValueAttr->setValue(anAngle); - updateAngleValue(); } else if (theID == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) { - updateAngleValue(); + updateConstraintValueByAngleValue(); } } double SketchPlugin_ConstraintAngle::calculateAngle() { - double anAngle = 0.0; - std::shared_ptr aData = data(); std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); - // Intersection of lines - std::shared_ptr anInter = intersect(aLineA, aLineB); - if (!anInter) - return anAngle; - - // Start and end points of lines - std::shared_ptr aPointA1 = std::dynamic_pointer_cast( + std::shared_ptr aStartA = std::dynamic_pointer_cast( aLineA->attribute(SketchPlugin_Line::START_ID())); - std::shared_ptr aPointA2 = std::dynamic_pointer_cast( + std::shared_ptr aEndA = std::dynamic_pointer_cast( aLineA->attribute(SketchPlugin_Line::END_ID())); - - std::shared_ptr aPointB1 = std::dynamic_pointer_cast( + std::shared_ptr aStartB = std::dynamic_pointer_cast( aLineB->attribute(SketchPlugin_Line::START_ID())); - std::shared_ptr aPointB2 = std::dynamic_pointer_cast( + std::shared_ptr aEndB = std::dynamic_pointer_cast( aLineB->attribute(SketchPlugin_Line::END_ID())); - std::shared_ptr aStartA = aPointA1->pnt(); - std::shared_ptr aEndA = aPointA2->pnt(); - std::shared_ptr aStartB = aPointB1->pnt(); - std::shared_ptr aEndB = aPointB2->pnt(); - - double aDist[2][2] = { - { anInter->distance(aStartA), anInter->distance(aEndA) }, - { anInter->distance(aStartB), anInter->distance(aEndB) } - }; - - // Directions of lines - if (aDist[0][0] > aDist[0][1]) - aEndA = aStartA; - if (aDist[1][0] > aDist[1][1]) - aEndB = aStartB; - - std::shared_ptr aDirA(new GeomAPI_Dir2d(aEndA->xy()->decreased(anInter->xy()))); - std::shared_ptr aDirB(new GeomAPI_Dir2d(aEndB->xy()->decreased(anInter->xy()))); - - double aDirAngle = aDirA->angle(aDirB); - if (aDirAngle < 0) - aDirAngle += 2.0 * PI; - anAngle = fabs(aDirAngle) * 180.0 / PI; + std::shared_ptr anAng; + if (!attribute(ANGLE_REVERSED_FIRST_LINE_ID())->isInitialized() || + !attribute(ANGLE_REVERSED_SECOND_LINE_ID())->isInitialized()) + anAng = std::shared_ptr(new GeomAPI_Angle2d( + aStartA->pnt(), aEndA->pnt(), aStartB->pnt(), aEndB->pnt())); + else { + std::shared_ptr aLine1(new GeomAPI_Lin2d(aStartA->pnt(), aEndA->pnt())); + bool isReversed1 = boolean(ANGLE_REVERSED_FIRST_LINE_ID())->value(); + std::shared_ptr aLine2(new GeomAPI_Lin2d(aStartB->pnt(), aEndB->pnt())); + bool isReversed2 = boolean(ANGLE_REVERSED_SECOND_LINE_ID())->value(); + anAng = std::shared_ptr(new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2)); + } + double anAngle = anAng->angleDegree(); + std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::VALUE())); + if (!aValueAttr->isInitialized()) + aValueAttr->setValue(anAngle); /// an angle value should be corrected by the current angle type anAngle = getAngleForType(anAngle); + boolean(ANGLE_REVERSED_FIRST_LINE_ID())->setValue(anAng->isReversed(0)); + boolean(ANGLE_REVERSED_SECOND_LINE_ID())->setValue(anAng->isReversed(1)); return anAngle; } -double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle) +double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle, bool isPreviousValueObtuse) { double anAngle = theAngle; @@ -207,8 +197,15 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle) case SketcherPrs_Tools::ANGLE_DIRECT: anAngle = theAngle; break; - case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: - anAngle = fabs(180.0 - theAngle); + case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: { + if (theAngle > 180 || isPreviousValueObtuse) + anAngle = theAngle - 180.0; + else + anAngle = 180.0 - theAngle; + + if (anAngle < 0.0) + anAngle += 360.0; + } break; case SketcherPrs_Tools::ANGLE_BACKWARD: anAngle = 360.0 - theAngle; @@ -219,16 +216,16 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle) return anAngle; } -void SketchPlugin_ConstraintAngle::updateAngleValue() +void SketchPlugin_ConstraintAngle::updateConstraintValueByAngleValue() { std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); double anAngle = aValueAttr->value(); /// an angle value should be corrected by the current angle type - anAngle = getAngleForType(anAngle); aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); + anAngle = getAngleForType(anAngle, aValueAttr->value() > 180.0); aValueAttr->setValue(anAngle); }