From 562fc1b0ccccdb32dad916108c2b2e214bab4e5d Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 24 Jun 2014 20:03:25 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Length and distance constraint initalization of constraint value. --- .../SketchPlugin_ConstraintDistance.cpp | 40 ++++++++++++------- .../SketchPlugin_ConstraintLength.cpp | 34 ++++++++-------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index ad8eda3a7..e5480db6c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -45,13 +45,22 @@ void SketchPlugin_ConstraintDistance::execute() AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); - if (anAttr_A && anAttr_B && !anAttr_Value->isInitialized()) + if (anAttr_A->isInitialized() && anAttr_B->isInitialized() && !anAttr_Value->isInitialized()) { FeaturePtr aFeature_A = anAttr_A->feature(); FeaturePtr aFeature_B = anAttr_B->feature(); - - double aValue = 40; // TODO - anAttr_Value->setValue(aValue); + if (aFeature_A && aFeature_A) { + // calculate the distance + boost::shared_ptr aPoint_A = + boost::dynamic_pointer_cast + (aFeature_A->data()->attribute(POINT_ATTR_COORD)); + boost::shared_ptr aPoint_B = + boost::dynamic_pointer_cast + (aFeature_B->data()->attribute(POINT_ATTR_COORD)); + if (aPoint_A && aPoint_B) { + anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt())); + } + } } } @@ -72,16 +81,19 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape( // fly out calculation boost::shared_ptr aFlyOutAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); - - boost::shared_ptr aFeatureLin = - boost::shared_ptr(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), - aPoint_B->x(), aPoint_B->y())); - boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); - double aDistance = aFlyOutPnt->distance(aProjectedPoint); - if (!aFeatureLin->isRight(aFlyOutPnt)) - aDistance = -aDistance; - double aFlyout = aDistance; + double aFlyout = 0; + if (aFlyOutAttr->isInitialized()) { + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); + + boost::shared_ptr aFeatureLin = + boost::shared_ptr(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), + aPoint_B->x(), aPoint_B->y())); + boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aProjectedPoint); + if (!aFeatureLin->isRight(aFlyOutPnt)) + aDistance = -aDistance; + aFlyout = aDistance; + } //Build dimension here boost::shared_ptr aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y()); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index b911ea9a4..dac5f926b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -73,22 +73,24 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape( // fly out calculation boost::shared_ptr aFlyOutAttr = boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); - - boost::shared_ptr aStartPoint = - boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_START)); - boost::shared_ptr anEndPoint = - boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_END)); - - boost::shared_ptr aFeatureLin = boost::shared_ptr - (new GeomAPI_Lin2d(aStartPoint->x(), aStartPoint->y(), - anEndPoint->x(), anEndPoint->y())); - boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); - double aDistance = aFlyOutPnt->distance(aProjectedPoint); - if (!aFeatureLin->isRight(aFlyOutPnt)) - aDistance = -aDistance; - double aFlyout = aDistance; - + double aFlyout = 0; + if (aFlyOutAttr->isInitialized()) { + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); + + boost::shared_ptr aStartPoint = + boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_START)); + boost::shared_ptr anEndPoint = + boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_END)); + + boost::shared_ptr aFeatureLin = boost::shared_ptr + (new GeomAPI_Lin2d(aStartPoint->x(), aStartPoint->y(), + anEndPoint->x(), anEndPoint->y())); + boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aProjectedPoint); + if (!aFeatureLin->isRight(aFlyOutPnt)) + aDistance = -aDistance; + aFlyout = aDistance; + } // value boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); -- 2.39.2