From ed59a237780d6a00ef93ccefa6ffccb677ea4c0d Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Thu, 29 Aug 2024 09:48:46 +0530 Subject: [PATCH] [Sketcher] Add some utility functions to `Sketcher::Constraint` `involvesGeoId`, `invovesGeoIdAndPosId`, `substituteIndexAndPos` --- src/Mod/Sketcher/App/Constraint.cpp | 19 +++++++++++++++++++ src/Mod/Sketcher/App/Constraint.h | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Mod/Sketcher/App/Constraint.cpp b/src/Mod/Sketcher/App/Constraint.cpp index b802e36d58..ee9ff43409 100644 --- a/src/Mod/Sketcher/App/Constraint.cpp +++ b/src/Mod/Sketcher/App/Constraint.cpp @@ -239,6 +239,25 @@ void Constraint::substituteIndex(int fromGeoId, int toGeoId) } } +void Constraint::substituteIndexAndPos(int fromGeoId, + PointPos fromPosId, + int toGeoId, + PointPos toPosId) +{ + if (this->First == fromGeoId && this->FirstPos == fromPosId) { + this->First = toGeoId; + this->FirstPos = toPosId; + } + if (this->Second == fromGeoId && this->SecondPos == fromPosId) { + this->Second = toGeoId; + this->SecondPos = toPosId; + } + if (this->Third == fromGeoId && this->ThirdPos == fromPosId) { + this->Third = toGeoId; + this->ThirdPos = toPosId; + } +} + std::string Constraint::typeToString(ConstraintType type) { return type2str[type]; diff --git a/src/Mod/Sketcher/App/Constraint.h b/src/Mod/Sketcher/App/Constraint.h index 3b9a806ce6..fdece4dc50 100644 --- a/src/Mod/Sketcher/App/Constraint.h +++ b/src/Mod/Sketcher/App/Constraint.h @@ -132,6 +132,21 @@ public: /// utility function to swap the index in First/Second/Third of the provided constraint from the /// fromGeoId GeoId to toGeoId void substituteIndex(int fromGeoId, int toGeoId); + /// utility function to swap the index and position in First/Second/Third of the provided + /// constraint from {fromGeoId, fromPosId} to {toGeoId, toPosId}. + void substituteIndexAndPos(int fromGeoId, PointPos fromPosId, int toGeoId, PointPos toPosId); + + /// utility function to check if `geoId` is one of the geometries + bool involvesGeoId(int geoId) const + { + return First == geoId || Second == geoId || Third == geoId; + } + /// utility function to check if (`geoId`, `posId`) is one of the points/curves + bool involvesGeoIdAndPosId(int geoId, PointPos posId) const + { + return (First == geoId && FirstPos == posId) || (Second == geoId && SecondPos == posId) + || (Third == geoId && ThirdPos == posId); + } std::string typeToString() const {