X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintDistance.cpp;h=90e1a2437e5fcf7733e46e0096e2189320a54ef7;hb=c090c28c1f1190a992e62baefeb01fd8873fb51c;hp=e8ea4bfbed0c10497c1a1b40e82b36023e3b74cf;hpb=cd9217d7e87997ec8bc150a6d8c389e742ca0f84;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index e8ea4bfbe..90e1a2437 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -33,31 +33,37 @@ void SketchPlugin_ConstraintDistance::initAttributes() void SketchPlugin_ConstraintDistance::execute() { boost::shared_ptr aData = data(); - AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast( + AttributeDoublePtr anAttrValue = boost::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::VALUE())); - if (!anAttr_Value->isInitialized()) { - boost::shared_ptr aPoint_A = getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_A()); - boost::shared_ptr aPoint_B = getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_B()); - - if (aPoint_A && aPoint_B) { // both points - anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt())); - } else { - if (!aPoint_A && aPoint_B) { //Line and point - boost::shared_ptr aLine = getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_A()); - if (aLine) - anAttr_Value->setValue(aLine->distanceToPoint(aPoint_B->pnt())); - } else if (aPoint_A && !aPoint_B) { // Point and line - boost::shared_ptr aLine = getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_B()); - if (aLine) - anAttr_Value->setValue(aLine->distanceToPoint(aPoint_A->pnt())); + if(anAttrValue->isInitialized()) + return; + boost::shared_ptr aPointA = + getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); + boost::shared_ptr aPointB = + getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B()); + + double aDistance = -1.; + if (aPointA && aPointB) { // both points + aDistance = aPointA->pnt()->distance(aPointB->pnt()); + } else { + if (!aPointA && aPointB) { //Line and point + boost::shared_ptr aLine = + getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + if (aLine) { + aDistance = aLine->distanceToPoint(aPointB->pnt()); + } + } else if (aPointA && !aPointB) { // Point and line + boost::shared_ptr aLine = + getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + if (aLine) { + aDistance = aLine->distanceToPoint(aPointA->pnt()); } } } + if(aDistance >= 0) { + anAttrValue->setValue(aDistance); + } } //************************************************************************************* @@ -103,10 +109,16 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi boost::shared_ptr aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y()); boost::shared_ptr aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y()); - boost::shared_ptr aFlyoutPnt = - aFlyOutAttr->isInitialized() ? - sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()) : boost::shared_ptr(); - + boost::shared_ptr aFlyoutPnt = boost::shared_ptr(); + if(aFlyOutAttr->isInitialized()) { + aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); + } else { + boost::shared_ptr aLine = boost::shared_ptr(new GeomAPI_Lin2d(aPnt_A, aPnt_B)); + double aDist = aPoint1->distance(aPoint2)/5.; + boost::shared_ptr aFPnt = aLine->shiftedLocation(aDist); + aFlyOutAttr->setValue(aFPnt); + aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y()); + } // value calculation boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast< ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE())); @@ -131,9 +143,9 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY) if (!aData->isValid()) return; - boost::shared_ptr aPoint1 = boost::dynamic_pointer_cast( + boost::shared_ptr aPoint = boost::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); + aPoint->setValue(theDeltaX, theDeltaY); } //*************************************************************************************