| 1812 | // clang-format off |
| 1813 | |
| 1814 | int SketchObject::removeAxesAlignment(const std::vector<int>& geoIdList) |
| 1815 | { |
| 1816 | if (geoIdList.empty()) { |
| 1817 | return 0; |
| 1818 | } |
| 1819 | |
| 1820 | Base::StateLocker lock(managedoperation, true); |
| 1821 | |
| 1822 | const std::vector<Constraint*>& currentConstraints = this->Constraints.getValues(); |
| 1823 | std::vector<Constraint*> newConstraints; |
| 1824 | newConstraints.reserve(currentConstraints.size()); |
| 1825 | |
| 1826 | bool changed = false; |
| 1827 | |
| 1828 | // Track reference geometry for converting multiple H/V constraints into Parallel constraints. |
| 1829 | // Maps ConstraintType (H or V) -> Geometry ID. |
| 1830 | std::map<Sketcher::ConstraintType, int> referenceGeoIds = { |
| 1831 | {Sketcher::Horizontal, GeoEnum::GeoUndef}, |
| 1832 | {Sketcher::Vertical, GeoEnum::GeoUndef} |
| 1833 | }; |
| 1834 | |
| 1835 | for (Constraint* constr : currentConstraints) { |
| 1836 | bool involvesSelection = false; |
| 1837 | for (const auto& geoid : geoIdList) { |
| 1838 | if (constr->involvesGeoId(geoid)) { |
| 1839 | involvesSelection = true; |
| 1840 | break; // Found a match, no need to check other IDs for this constraint |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | // If the constraint is not touched by our selection, keep it as is. |
| 1845 | if (!involvesSelection) { |
| 1846 | newConstraints.push_back(constr); |
| 1847 | continue; |
| 1848 | } |
| 1849 | |
| 1850 | // Processing the constraint based on type |
| 1851 | switch (constr->Type) { |
| 1852 | case Sketcher::Horizontal: |
| 1853 | case Sketcher::Vertical: { |
| 1854 | // Only remove alignment for Lines (PointPos::none), not individual points |
| 1855 | if (constr->FirstPos == Sketcher::PointPos::none && |
| 1856 | constr->SecondPos == Sketcher::PointPos::none) { |
| 1857 | |
| 1858 | changed = true; |
| 1859 | |
| 1860 | // The first H/V constraint found acts as the "reference" and is effectively removed. |
| 1861 | // Subsequent H/V constraints are converted to be 'Parallel' to that first reference. |
| 1862 | if (referenceGeoIds[constr->Type] == GeoEnum::GeoUndef) { |
| 1863 | referenceGeoIds[constr->Type] = constr->First; |
| 1864 | // We do NOT add the constraint to newConstraints, effectively deleting it. |
| 1865 | } |
| 1866 | else { |
| 1867 | // Convert to Parallel |
| 1868 | Constraint* newConstr = new Constraint(); |
| 1869 | newConstr->Type = Sketcher::Parallel; |
| 1870 | newConstr->First = referenceGeoIds[constr->Type]; |
| 1871 | newConstr->Second = constr->First; |