Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Sketcher: Fix issue #4513 - SketchObject::addSymmetric
This fixes issue
https://tracker.freecadweb.org/view.php?id=4513

addSymmetric will now only transfer Vertical and Horizontal constraints if the reference axis is either
 - the HAxis
 - the VAxis
 - a Vertical line
 - a Horizontal line
  • Loading branch information
davidosterberg authored and abdullahtahiriyo committed Dec 23, 2020
1 parent 07211b0 commit 73fa304
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -3415,6 +3415,19 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
std::map<int, int> geoIdMap;
std::map<int, bool> isStartEndInverted;

// Find out if reference is aligned with V or H axis,
// if so we can keep Vertical and Horizontal constrants in the mirrored geometry.
bool refIsAxisAligned = false;
if (refGeoId == Sketcher::GeoEnum::VAxis || refGeoId == Sketcher::GeoEnum::HAxis)
refIsAxisAligned = true;
for (std::vector<Constraint *>::const_iterator it = constrvals.begin(); it != constrvals.end(); ++it) {
Constraint *constr = *(it);
if (constr->First != refGeoId)
continue;
if (constr->Type == Sketcher::Vertical || constr->Type == Sketcher::Horizontal)
refIsAxisAligned = true;
}

// reference is a line
if(refPosId == Sketcher::none) {
const Part::Geometry *georef = getGeometry(refGeoId);
Expand Down Expand Up @@ -3617,6 +3630,7 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
}
}
else { //reference is a point
refIsAxisAligned = true;
Vector3d refpoint;
const Part::Geometry *georef = getGeometry(refGeoId);

Expand Down Expand Up @@ -3888,14 +3902,27 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
if(fit != geoIdMap.end()) { // if First of constraint is in geoIdList

if( (*it)->Second == Constraint::GeoUndef /*&& (*it)->Third == Constraint::GeoUndef*/) {
if( (*it)->Type != Sketcher::DistanceX &&
(*it)->Type != Sketcher::DistanceY) { // this includes all non-directional single GeoId constraints, as radius, diameter, weight,...
if (refIsAxisAligned) {
// in this case we want to keep the Vertical, Horizontal constraints
// DistanceX ,and DistanceY constraints should also be possible to keep in this case,
// but keeping them causes segfault, not sure why.

if( (*it)->Type != Sketcher::DistanceX && (*it)->Type != Sketcher::DistanceY ) {
Constraint *constNew = (*it)->copy();
constNew->First = fit->second;
newconstrVals.push_back(constNew);
}

Constraint *constNew = (*it)->copy();
} else if( (*it)->Type != Sketcher::DistanceX &&
(*it)->Type != Sketcher::DistanceY &&
(*it)->Type != Sketcher::Vertical &&
(*it)->Type != Sketcher::Horizontal ) { // this includes all non-directional single GeoId constraints, as radius, diameter, weight,...

constNew->First = fit->second;
newconstrVals.push_back(constNew);
Constraint *constNew = (*it)->copy();
constNew->First = fit->second;
newconstrVals.push_back(constNew);
}

}
else { // other geoids intervene in this constraint

Expand Down

0 comments on commit 73fa304

Please sign in to comment.