EditCoinManager: Additional refactoring

This commit is contained in:
Abdullah Tahiri
2021-12-21 20:29:06 +01:00
committed by abdullahtahiriyo
parent dfd726ec35
commit f04d5171da
8 changed files with 39 additions and 62 deletions

View File

@@ -7040,9 +7040,9 @@ std::vector<Part::Geometry*> SketchObject::getCompleteGeometry(void) const
return vals;
}
std::vector<std::unique_ptr<const GeometryFacade>> SketchObject::getCompleteGeometryFacade(void) const
GeoListFacade SketchObject::getGeoListFacade(void) const
{
std::vector<std::unique_ptr<const GeometryFacade>> facade;
std::vector<GeometryFacadeUniquePtr> facade;
facade.reserve( Geometry.getSize() + ExternalGeo.size() );
for(auto geo : Geometry.getValues())
@@ -7051,7 +7051,7 @@ std::vector<std::unique_ptr<const GeometryFacade>> 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)

View File

@@ -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<Part::Geometry*> getCompleteGeometry(void) const;
std::vector<std::unique_ptr<const GeometryFacade>> getCompleteGeometryFacade(void) const;
GeoListFacade getGeoListFacade(void) const;
/// converts a GeoId index into an index of the CompleteGeometry vector
int getCompleteGeometryIndex(int GeoId) const;

View File

@@ -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()

View File

@@ -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*/

View File

@@ -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<Sketcher::Constraint *> &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);

View File

@@ -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*/

View File

@@ -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<std::unique_ptr<Part::Geometry>> &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<Part::Geometry *>::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<const Part::GeomCircle *>(*it);
auto gf = GeometryFacade::getFacade(circle);
if ((*it)->getGeometry()->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle
const Part::GeomCircle *circle = static_cast<const Part::GeomCircle *>((*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<const Part::GeomBSplineCurve *>(tempGeo[c->Second]);
auto bspline = dynamic_cast<const Part::GeomBSplineCurve *>(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<Part::GeomCircle *>(*it);
tmpcircle = const_cast<Part::GeomCircle *>(circle);
tmpcircle->setRadius(vradius);
}
else { // without memory allocation
tmpcircle = static_cast<Part::GeomCircle *>((*it)->clone());
tmpcircle = static_cast<Part::GeomCircle *>(circle->clone());
tmpcircle->setRadius(vradius);
deepCopiesToDelete.push_back(std::unique_ptr<Part::GeomCircle>(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<Part::Geometry *> 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<std::unique_ptr<Part::Geometry>> 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

View File

@@ -586,9 +586,8 @@ protected:
private:
/// function to handle OCCT BSpline weight calculation singularities and representation
void scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGeometry(
GeoList & geolist,
bool geometrywithmemoryallocation,
std::vector<std::unique_ptr<Part::Geometry>> &deepCopiesToDelete);
GeoListFacade & geolist,
bool geometrywithmemoryallocation);
/** @name geometry and coordinates auxiliary functions */
//@{