void SketchPlugin_ConstraintDistance::execute()
{
boost::shared_ptr<ModelAPI_Data> aData = data();
- AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ AttributeDoublePtr anAttrValue = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
aData->attribute(SketchPlugin_Constraint::VALUE()));
- if (!anAttr_Value->isInitialized()) {
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A());
- boost::shared_ptr<GeomDataAPI_Point2D> 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<SketchPlugin_Line> 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<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_B());
- if (aLine)
- anAttr_Value->setValue(aLine->distanceToPoint(aPoint_A->pnt()));
+ if(anAttrValue->isInitialized())
+ return;
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointA =
+ getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+ boost::shared_ptr<GeomDataAPI_Point2D> 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<SketchPlugin_Line> aLine =
+ getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+ if (aLine) {
+ aDistance = aLine->distanceToPoint(aPointB->pnt());
+ }
+ } else if (aPointA && !aPointB) { // Point and line
+ boost::shared_ptr<SketchPlugin_Line> aLine =
+ getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+ if (aLine) {
+ aDistance = aLine->distanceToPoint(aPointA->pnt());
}
}
}
+ if(aDistance >= 0) {
+ anAttrValue->setValue(aDistance);
+ }
}
//*************************************************************************************
boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y());
boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y());
- boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt =
- aFlyOutAttr->isInitialized() ?
- sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()) : boost::shared_ptr<GeomAPI_Pnt>();
-
+ boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = boost::shared_ptr<GeomAPI_Pnt>();
+ if(aFlyOutAttr->isInitialized()) {
+ aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
+ } else {
+ boost::shared_ptr<GeomAPI_Lin2d> aLine = boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aPnt_A, aPnt_B));
+ double aDist = aPoint1->distance(aPoint2)/5.;
+ boost::shared_ptr<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
+ aFlyOutAttr->setValue(aFPnt);
+ aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
+ }
// value calculation
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
if (!aData->isValid())
return;
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
- aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+ aPoint->setValue(theDeltaX, theDeltaY);
}
//*************************************************************************************