Skip to content

Commit

Permalink
Sketcher: BSpline deletion/special hideunused internal geometry
Browse files Browse the repository at this point in the history
===============================================================

The implementation of BSpline differs from previous complex forms.

The BSpline is created constraint to be polynomic (non-rational), with radius of first circle and equality constraints.

Hide unused internal geometry considers as unused the following constraints:
- A pole which has equality constraints with another pole of the same bspline
- Any radius constraint on a pole

Deletion of a BSpline will delete the internal geometry that is unused as per the definition above.

If there is another constraint (other than the Internal alignment constraint) it will leave the internal geometry having such constraint undeleted.
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Feb 2, 2017
1 parent 4750bd4 commit b708957
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
75 changes: 40 additions & 35 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -3491,7 +3491,7 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid)
if (GeoId < 0 || GeoId > getHighestCurveIndex())
return -1;

const Part::Geometry *geo = getGeometry(GeoId);
const Part::Geometry *geo = getGeometry(GeoId);
// Only for supported types
if (geo->getTypeId() == Part::GeomEllipse::getClassTypeId() ||
geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() ||
Expand Down Expand Up @@ -3574,8 +3574,12 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid)
delGeometry(*it,false);
}
}

return delgeometries.size(); //number of deleted elements

int ndeleted = delgeometries.size();

delgeometries.clear();

return ndeleted; //number of deleted elements
}
else if( geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) {
// if the focus-to-vertex line is constrained, then never delete the focus
Expand Down Expand Up @@ -3663,7 +3667,11 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid)
}
}

return delgeometries.size(); //number of deleted elements
int ndeleted = delgeometries.size();

delgeometries.clear();

return ndeleted; //number of deleted elements
}
else if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) {

Expand Down Expand Up @@ -3697,30 +3705,47 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid)
}

std::vector<int> delgeometries;
bool firstpoledeleted = false;

for (it=controlpointgeoids.begin(), ita=associatedcontraints.begin(); it!=controlpointgeoids.end() && ita!=associatedcontraints.end(); ++it, ++ita) {
if ((*it) != -1) {
// look for a circle at geoid index
for (std::vector< Sketcher::Constraint * >::const_iterator itc= vals.begin();
itc != vals.end(); ++itc) {
for (std::vector< Sketcher::Constraint * >::const_iterator itc= vals.begin(); itc != vals.end(); ++itc) {

if ( (*itc)->Type==Sketcher::Equal ) {
bool f=false,s=false;
for ( std::vector<int>::iterator its=controlpointgeoids.begin(); its!=controlpointgeoids.end(); ++its) {
if( (*itc)->First == *its ) {
f=true;
}
else if ( (*itc)->Second == *its ) {
s=true;
}

if ((*itc)->Second == (*it) || (*itc)->First == (*it) || (*itc)->Third == (*it))
if (f && s) { // the equality constraint is not interpole
break;
}
}

if ( (f && !s) || (!f && s) ) { // the equality constraint constraints a pole but it is not interpole
(*ita)++;
}

}
// ignore radiuses
else if ((*itc)->Type!=Sketcher::Radius && ( (*itc)->Second == (*it) || (*itc)->First == (*it) || (*itc)->Third == (*it)) )
(*ita)++;

}

if ((*ita)<3 ) { // IA + Weight
if ( (*ita) < 2 ) { // IA
delgeometries.push_back((*it));

if (it == controlpointgeoids.begin())
firstpoledeleted = true;
}
}
}

if(delgeoid)
delgeometries.push_back(GeoId);

std::sort(delgeometries.begin(), delgeometries.end()); // indices over an erased element get automatically updated!!

if (delgeometries.size()>0) {
Expand All @@ -3729,30 +3754,10 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid)
}
}

// retest the first pole after removal of equality constraints from other poles
associatedcontraints[0] = 0;
int ndeleted = delgeometries.size();
delgeometries.clear();

if (controlpointgeoids[0] != -1 && !firstpoledeleted) {
// look for a circle at geoid index
for (std::vector< Sketcher::Constraint * >::const_iterator itc= vals.begin(); itc != vals.end(); ++itc) {
if ((*itc)->Second == controlpointgeoids[0] ||
(*itc)->First == controlpointgeoids[0] ||
(*itc)->Third == controlpointgeoids[0])
associatedcontraints[0]++;
}

if (associatedcontraints[0]<4 ) // IA + Weight + Radius
delgeometries.push_back(controlpointgeoids[0]);
}

if (delgeometries.size()>0) {
for (std::vector<int>::reverse_iterator it=delgeometries.rbegin(); it!=delgeometries.rend(); ++it) {
delGeometry(*it,false);
}
}

return delgeometries.size(); //number of deleted elements
return ndeleted; //number of deleted elements
}
else {
return -1; // not supported type
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -193,7 +193,7 @@ class SketcherExport SketchObject : public Part::Part2DObject
\brief Deletes all unused (not further constrained) internal geometry
\param GeoId - the geometry having the internal geometry to delete
\param delgeoid - if true in addition to the unused internal geometry also deletes the GeoId geometry
\retval int - returns -1 on error
\retval int - returns -1 on error, otherwise the number of deleted elements
*/
int DeleteUnusedInternalGeometry(int GeoId, bool delgeoid=false);

Expand Down

0 comments on commit b708957

Please sign in to comment.