From f04d5171da99edd970a96b2a38c095d3c275249a Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 21 Dec 2021 20:29:06 +0100 Subject: [PATCH] EditCoinManager: Additional refactoring --- src/Mod/Sketcher/App/SketchObject.cpp | 6 +- src/Mod/Sketcher/App/SketchObject.h | 4 +- src/Mod/Sketcher/Gui/EditModeCoinManager.cpp | 4 +- src/Mod/Sketcher/Gui/EditModeCoinManager.h | 2 +- .../Gui/EditModeConstraintCoinManager.cpp | 14 ++-- .../Gui/EditModeConstraintCoinManager.h | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 64 ++++++------------- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 5 +- 8 files changed, 39 insertions(+), 62 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 18b647172c..40b277dbbb 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -7040,9 +7040,9 @@ std::vector SketchObject::getCompleteGeometry(void) const return vals; } -std::vector> SketchObject::getCompleteGeometryFacade(void) const +GeoListFacade SketchObject::getGeoListFacade(void) const { - std::vector> facade; + std::vector facade; facade.reserve( Geometry.getSize() + ExternalGeo.size() ); for(auto geo : Geometry.getValues()) @@ -7051,7 +7051,7 @@ std::vector> SketchObject::getCompleteGeom for(auto rit = ExternalGeo.rbegin(); rit != ExternalGeo.rend(); rit++) facade.push_back(GeometryFacade::getFacade(*rit)); - return facade; + return GeoListFacade::getGeoListModel(std::move(facade), Geometry.getSize()); } void SketchObject::rebuildVertexIndex(void) diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 6610577724..85fa186607 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -44,6 +44,8 @@ #include "GeoEnum.h" +#include "GeoList.h" + namespace Sketcher { @@ -194,7 +196,7 @@ public: /// retrieves a vector containing both normal and external Geometry (including the sketch axes) std::vector getCompleteGeometry(void) const; - std::vector> getCompleteGeometryFacade(void) const; + GeoListFacade getGeoListFacade(void) const; /// converts a GeoId index into an index of the CompleteGeometry vector int getCompleteGeometryIndex(int GeoId) const; diff --git a/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp index 5d14344187..2c4316b982 100644 --- a/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp @@ -783,9 +783,9 @@ void EditModeCoinManager::drawConstraintIcons() pEditModeConstraintCoinManager->drawConstraintIcons(); } -void EditModeCoinManager::drawConstraintIcons(const GeoList & geolist) +void EditModeCoinManager::drawConstraintIcons(const GeoListFacade & geolistfacade) { - pEditModeConstraintCoinManager->drawConstraintIcons(geolist); + pEditModeConstraintCoinManager->drawConstraintIcons(geolistfacade); } void EditModeCoinManager::updateVirtualSpace() diff --git a/src/Mod/Sketcher/Gui/EditModeCoinManager.h b/src/Mod/Sketcher/Gui/EditModeCoinManager.h index c58869f447..1ca50989bc 100644 --- a/src/Mod/Sketcher/Gui/EditModeCoinManager.h +++ b/src/Mod/Sketcher/Gui/EditModeCoinManager.h @@ -214,7 +214,7 @@ public: void drawConstraintIcons(); // This specific overload is to use a specific geometry list, which may be a temporal one - void drawConstraintIcons(const GeoList & geolist); + void drawConstraintIcons(const GeoListFacade & geolistfacade); //@} /** @name coin node access*/ diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index 6f0ece3642..61be445d6a 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -1825,12 +1825,12 @@ SbVec3s EditModeConstraintCoinManager::getDisplayedSize(const SoImage *iconPtr) // public function that triggers drawing of most constraint icons void EditModeConstraintCoinManager::drawConstraintIcons() { - auto geolist = ViewProviderSketchCoinAttorney::getGeoList(viewProvider); + auto geolistfacade = ViewProviderSketchCoinAttorney::getGeoListFacade(viewProvider); - drawConstraintIcons(geolist); + drawConstraintIcons(geolistfacade); } -void EditModeConstraintCoinManager::drawConstraintIcons(const GeoList & geolist) +void EditModeConstraintCoinManager::drawConstraintIcons(const GeoListFacade & geolistfacade) { const std::vector &constraints = ViewProviderSketchCoinAttorney::getConstraints(viewProvider); @@ -1852,8 +1852,8 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoList & geolist) case Tangent: { // second icon is available only for colinear line segments - const Part::Geometry *geo1 = geolist.getGeometryFromGeoId((*it)->First); - const Part::Geometry *geo2 = geolist.getGeometryFromGeoId((*it)->Second); + const Part::Geometry *geo1 = geolistfacade.getGeometryFromGeoId((*it)->First); + const Part::Geometry *geo2 = geolistfacade.getGeometryFromGeoId((*it)->Second); if (geo1 && geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && geo2 && geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { multipleIcons = true; @@ -1917,8 +1917,8 @@ void EditModeConstraintCoinManager::drawConstraintIcons(const GeoList & geolist) thisIcon.visible = (*it)->isInVirtualSpace == ViewProviderSketchCoinAttorney::isShownVirtualSpace(viewProvider); if ((*it)->Type==Symmetric) { - Base::Vector3d startingpoint = geolist.getPoint((*it)->First, (*it)->FirstPos); - Base::Vector3d endpoint = geolist.getPoint((*it)->Second,(*it)->SecondPos); + Base::Vector3d startingpoint = geolistfacade.getPoint((*it)->First, (*it)->FirstPos); + Base::Vector3d endpoint = geolistfacade.getPoint((*it)->Second,(*it)->SecondPos); SbVec3f pos0(startingpoint.x,startingpoint.y,startingpoint.z); SbVec3f pos1(endpoint.x,endpoint.y,endpoint.z); diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h index ac17243330..e638aa70af 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h @@ -103,7 +103,7 @@ public: void drawConstraintIcons(); // This specific overload is to use a specific geometry list, which may be a temporal one - void drawConstraintIcons(const GeoList & geolist); + void drawConstraintIcons(const GeoListFacade & geolistfacade); //@} /** @name update coin colors*/ diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 323cb80347..ed295e458e 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2398,9 +2398,8 @@ float ViewProviderSketch::getScaleFactor() const // // This function takes a reference to a vector of deep copies to delete. These deep copies are necessary to transparently perform (1) while doing (2). void ViewProviderSketch::scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGeometry( - GeoList & geolist, - bool geometrywithmemoryallocation, - std::vector> &deepCopiesToDelete ) + GeoListFacade & geolistfacade, + bool geometrywithmemoryallocation) { // In order to allow to tweak geometry and insert scaling factors, this function needs to // change the geometry vector. This is highly exceptional for a drawing function and special @@ -2408,16 +2407,16 @@ void ViewProviderSketch::scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGe // 1. The treatment is exceptional and no other appropriate place is available to perform this tweak // 2. The original object needs to remain const for the benefit of all other class hierarchy of drawing functions // 3. When referring to actual geometry, the modified pointers are short lived, as they are destroyed after drawing - auto tempGeo = const_cast< std::vector< Part::Geometry *> &>(geolist.geomlist); + auto & tempGeo = geolistfacade.geomlist; int GeoId = 0; - for (std::vector::const_iterator it = tempGeo.begin(); it != tempGeo.end()-2; ++it, GeoId++) { - if (GeoId >= geolist.getInternalCount()) - GeoId = -geolist.getExternalCount(); + for (auto it = tempGeo.begin(); it != tempGeo.end()-2; ++it, GeoId++) { + if (GeoId >= geolistfacade.getInternalCount()) + GeoId = -geolistfacade.getExternalCount(); - if ((*it)->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle - const Part::GeomCircle *circle = static_cast(*it); - auto gf = GeometryFacade::getFacade(circle); + if ((*it)->getGeometry()->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle + const Part::GeomCircle *circle = static_cast((*it)->getGeometry()); + auto & gf = (*it); // BSpline weights have a radius corresponding to the weight value // However, in order for them proportional to the B-Spline size, @@ -2427,7 +2426,7 @@ void ViewProviderSketch::scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGe if(gf->getInternalType() == InternalType::BSplineControlPoint) { for( auto c : getSketchObject()->Constraints.getValues()) { if( c->Type == InternalAlignment && c->AlignmentType == BSplineControlPoint && c->First == GeoId) { - auto bspline = dynamic_cast(tempGeo[c->Second]); + auto bspline = dynamic_cast(tempGeo[c->Second]->getGeometry()); if(bspline){ auto weights = bspline->getWeights(); @@ -2470,14 +2469,13 @@ void ViewProviderSketch::scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGe Part::GeomCircle * tmpcircle; if(geometrywithmemoryallocation) { // with memory allocation - tmpcircle = static_cast(*it); + tmpcircle = const_cast(circle); tmpcircle->setRadius(vradius); } else { // without memory allocation - tmpcircle = static_cast((*it)->clone()); + tmpcircle = static_cast(circle->clone()); tmpcircle->setRadius(vradius); - deepCopiesToDelete.push_back(std::unique_ptr(tmpcircle)); - tempGeo[GeoId] = tmpcircle; // this is the circle that will be drawn, with the updated vradius. + tempGeo[GeoId] = GeometryFacade::getFacade(tmpcircle, true); // this is the circle that will be drawn, with the updated vradius, the facade takes ownership and will deallocate. } // save scale factor for any prospective dragging operation @@ -2519,27 +2517,16 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationoverl // ============== Retrieve geometry to be represented ================================= - std::vector tempGeo; + auto geolistfacade = temp ? + getSolvedSketch().extractGeoListFacade(): // with memory allocation + getSketchObject()->getGeoListFacade(); // without memory allocation - if (temp) - tempGeo = getSolvedSketch().extractGeometry(true, true); // with memory allocation - else - tempGeo = getSketchObject()->getCompleteGeometry(); // without memory allocation - - int intGeoCount = getSketchObject()->getHighestCurveIndex() + 1; - - auto geolist = GeoList::getGeoListModel(tempGeo, intGeoCount); - - assert(int(tempGeo.size()) == geolist.getExternalCount() + intGeoCount); - assert(int(tempGeo.size()) >= 2); + assert(int( geolistfacade.geomlist.size()) >= 2); // ============== Prepare geometry for representation ================================== // ************ Manage BSpline pole circle scaling **************************** - // memory management of deep copies necessary for drawing which are destroyed when the vector gets out of scope (i.e. at the end of this function). - std::vector> deepCopiesToDelete; - // This function ensures that the geometry used for drawing takes into account: // 1. the OCC mandated weight, which is normalised for non-rational BSplines, but not normalised for rational BSplines. // That includes properly sizing for drawing any weight constraint. @@ -2549,20 +2536,15 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationoverl // // This function takes a reference to a vector of deep copies to delete. These deep copies are necessary to transparently perform (1) while doing (2). - scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGeometry( - geolist, - temp, - deepCopiesToDelete); + scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGeometry(geolistfacade, temp); // ============== Render geometry, constraints and geometry information overlays ================================== - auto geolistfacade = Sketcher::getGeoListFacade(geolist); - editCoinManager->processGeometryConstraintsInformationOverlay(geolistfacade, rebuildinformationoverlay); // Avoids unneeded calls to pixmapFromSvg if(Mode==STATUS_NONE || Mode==STATUS_SKETCH_UseHandler) { - editCoinManager->drawConstraintIcons(geolist); + editCoinManager->drawConstraintIcons(geolistfacade); editCoinManager->updateColor(geolistfacade); } @@ -3517,13 +3499,7 @@ double ViewProviderSketch::getRotation(SbVec3f pos0, SbVec3f pos1) const GeoListFacade ViewProviderSketch::getGeoListFacade() const { - auto tempGeoFacade = getSketchObject()->getCompleteGeometryFacade(); - - int intGeoCount = getSketchObject()->getHighestCurveIndex() + 1; - - auto geolistfacade = GeoListFacade::getGeoListModel(std::move(tempGeoFacade), intGeoCount); - - return geolistfacade; + return getSketchObject()->getGeoListFacade(); } bool ViewProviderSketch::isSketchInvalid() const diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index bf3f10b41d..ee903b71c1 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -586,9 +586,8 @@ protected: private: /// function to handle OCCT BSpline weight calculation singularities and representation void scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGeometry( - GeoList & geolist, - bool geometrywithmemoryallocation, - std::vector> &deepCopiesToDelete); + GeoListFacade & geolist, + bool geometrywithmemoryallocation); /** @name geometry and coordinates auxiliary functions */ //@{