From 5c817bf5e431933e7aec024301e4cc9fd40a94d3 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sat, 12 Feb 2022 16:09:30 -0500 Subject: [PATCH] [Sketcher] Check constraint type before drawing icons Change is in `EditModeConstraintCoinManager::drawConstraintIcon` on the lines of 16a28614c86d01e2d70eeaf376861e25af579304. --- .../Gui/EditModeConstraintCoinManager.cpp | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index 03e54f652b..2eb0ba4164 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -1851,26 +1851,29 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & ge { const std::vector &constraints = ViewProviderSketchCoinAttorney::getConstraints(viewProvider); - int constrId = 0; - std::vector iconQueue; - for (std::vector::const_iterator it=constraints.begin(); - it != constraints.end(); ++it, ++constrId) { + int maxNumberOfConstraints = std::min(editModeScenegraphNodes.constrGroup->getNumChildren(), static_cast(constraints.size())); + + for (int constrId = 0; constrId < maxNumberOfConstraints; ++constrId) { + Sketcher::Constraint* constraint = constraints[constrId]; // Check if Icon Should be created bool multipleIcons = false; - QString icoType = iconTypeFromConstraint(*it); + QString icoType = iconTypeFromConstraint(constraint); if (icoType.isEmpty()) continue; - switch((*it)->Type) { + if (constraint->Type != vConstrType[constrId]) + break; + + switch(constraint->Type) { case Tangent: { // second icon is available only for colinear line segments - const Part::Geometry *geo1 = geolistfacade.getGeometryFromGeoId((*it)->First); - const Part::Geometry *geo2 = geolistfacade.getGeometryFromGeoId((*it)->Second); + const Part::Geometry *geo1 = geolistfacade.getGeometryFromGeoId(constraint->First); + const Part::Geometry *geo2 = geolistfacade.getGeometryFromGeoId(constraint->Second); if (geo1 && geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && geo2 && geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { multipleIcons = true; @@ -1880,9 +1883,9 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & ge case Horizontal: case Vertical: { // second icon is available only for point alignment - if ((*it)->Second != GeoEnum::GeoUndef && - (*it)->FirstPos != Sketcher::PointPos::none && - (*it)->SecondPos != Sketcher::PointPos::none) { + if (constraint->Second != GeoEnum::GeoUndef && + constraint->FirstPos != Sketcher::PointPos::none && + constraint->SecondPos != Sketcher::PointPos::none) { multipleIcons = true; } } @@ -1892,7 +1895,7 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & ge break; case Perpendicular: // second icon is available only when there is no common point - if ((*it)->FirstPos == Sketcher::PointPos::none && (*it)->Third == GeoEnum::GeoUndef) + if (constraint->FirstPos == Sketcher::PointPos::none && constraint->Third == GeoEnum::GeoUndef) multipleIcons = true; break; case Equal: @@ -1931,11 +1934,11 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & ge thisIcon.position = absPos; thisIcon.destination = coinIconPtr; thisIcon.infoPtr = infoPtr; - thisIcon.visible = (*it)->isInVirtualSpace == ViewProviderSketchCoinAttorney::isShownVirtualSpace(viewProvider); + thisIcon.visible = constraint->isInVirtualSpace == ViewProviderSketchCoinAttorney::isShownVirtualSpace(viewProvider); - if ((*it)->Type==Symmetric) { - Base::Vector3d startingpoint = geolistfacade.getPoint((*it)->First, (*it)->FirstPos); - Base::Vector3d endpoint = geolistfacade.getPoint((*it)->Second,(*it)->SecondPos); + if (constraint->Type==Symmetric) { + Base::Vector3d startingpoint = geolistfacade.getPoint(constraint->First, constraint->FirstPos); + Base::Vector3d endpoint = geolistfacade.getPoint(constraint->Second, constraint->SecondPos); SbVec3f pos0(startingpoint.x,startingpoint.y,startingpoint.z); SbVec3f pos1(endpoint.x,endpoint.y,endpoint.z); @@ -1947,10 +1950,10 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & ge } if (multipleIcons) { - if ((*it)->Name.empty()) + if (constraint->Name.empty()) thisIcon.label = QString::number(constrId + 1); else - thisIcon.label = QString::fromUtf8((*it)->Name.c_str()); + thisIcon.label = QString::fromUtf8(constraint->Name.c_str()); iconQueue.push_back(thisIcon); // Note that the second translation is meant to be applied after the first. @@ -1969,10 +1972,10 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & ge } } else { - if ((*it)->Name.empty()) + if (constraint->Name.empty()) thisIcon.label = QString(); else - thisIcon.label = QString::fromUtf8((*it)->Name.c_str()); + thisIcon.label = QString::fromUtf8(constraint->Name.c_str()); } iconQueue.push_back(thisIcon);