}
}
-void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute,
+void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute,
const AttributePtr& theSecondAngleAttribute,
- const int& theNumberOfCopies,
- const bool toFullAngle)
+ const int& theValue,
+ const bool toMultiply)
{
- if (theNumberOfCopies == 0)
+ if (theValue == 0 || !theFirstAngleAttribute->isInitialized())
return;
AttributeDoublePtr aDoubleFirstAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
AttributeDoublePtr aDoubleSecondAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
theSecondAngleAttribute);
- if (toFullAngle)
- aDoubleSecondAttr->setValue(aValue*theNumberOfCopies);
+ if (toMultiply)
+ aDoubleSecondAttr->setValue(aValue*theValue);
else
- aDoubleSecondAttr->setValue(aValue/theNumberOfCopies);
+ aDoubleSecondAttr->setValue(aValue/theValue);
+}
+
+void updateMultiAttribute(const AttributePtr& theFirstAttribute,
+ const AttributePtr& theSecondAttribute,
+ const AttributePtr& theModifiedAttribute,
+ const int& theValue,
+ const bool toMultiply)
+{
+ if (theValue == 0 || !theFirstAttribute->isInitialized()
+ || !theSecondAttribute->isInitialized())
+ return;
+
+ std::shared_ptr<GeomDataAPI_Point2D> aFirstPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFirstAttribute);
+ std::shared_ptr<GeomDataAPI_Point2D> aSecondPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theSecondAttribute);
+ std::shared_ptr<GeomDataAPI_Point2D> aModifiedPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theModifiedAttribute);
+
+ if (!aFirstPoint.get() || !aSecondPoint.get() || !aModifiedPoint.get())
+ return;
+
+ if (aFirstPoint->pnt()->isEqual(aSecondPoint->pnt()))
+ aModifiedPoint->setValue(aFirstPoint->pnt());
+ else {
+ double aDx = aSecondPoint->x() - aFirstPoint->x();
+ double aDy = aSecondPoint->y() - aFirstPoint->y();
+
+ double aX = toMultiply ? aDx * theValue : aDx / theValue;
+ double anY = toMultiply ? aDy * theValue : aDy / theValue;
+
+ aModifiedPoint->setValue(aFirstPoint->x() + aX, aFirstPoint->y() + anY);
+ }
}
} // namespace SketchPlugin_Tools