Sketcher: Fix Sketch Mirror functionality

=========================================

The problem:
Mirror stopped working.

How to reproduce:
Select a sketch, and apply "Mirror Sketch" from the menu.

Why?
With the introduction of expressions, mirror sketch stopped working. The reason is that mirror functionality did use the "clone" function to make copies of constraints
and then modify their values. After expessions introduction, which introduces a unique tag per constraint, this copy was regarded as a "rename" of the original constraint
as they shared the unique tag.

Fix?
New function "copy()" for a constraint, that copies all the content but the tag.
This commit is contained in:
Abdullah Tahiri 2015-12-04 14:49:40 +01:00 committed by wmayer
parent 118d2eb531
commit 501fa80e4d
3 changed files with 32 additions and 11 deletions

View File

@ -97,6 +97,26 @@ Constraint *Constraint::clone(void) const
return new Constraint(*this);
}
Constraint *Constraint::copy(void) const
{
Constraint *temp = new Constraint();
temp->Value = this->Value;
temp->Type = this->Type;
temp->AlignmentType = this->AlignmentType;
temp->Name = this->Name;
temp->First = this->First;
temp->FirstPos = this->FirstPos;
temp->Second = this->Second;
temp->SecondPos = this->SecondPos;
temp->Third = this->Third;
temp->ThirdPos = this->ThirdPos;
temp->LabelDistance = this->LabelDistance;
temp->LabelPosition = this->LabelPosition;
temp->isDriving = this->isDriving;
// Do not copy tag, otherwise it is considered a clone, and a "rename" by the expression engine.
return temp;
}
PyObject *Constraint::getPyObject(void)
{
return new ConstraintPy(new Constraint(*this));

View File

@ -71,7 +71,8 @@ public:
Constraint();
Constraint(const Constraint&);
virtual ~Constraint();
virtual Constraint *clone(void) const;
virtual Constraint *clone(void) const; // does copy the tag, it will be treated as a rename by the expression engine.
virtual Constraint *copy(void) const; // does not copy the tag, but generates a new one
static const int GeoUndef;

View File

@ -49,7 +49,7 @@
#include <boost/bind.hpp>
#include <App/Document.h>
#include <App/FeaturePythonPyImp.h>
#include <App/FeaturePythonPyImp.h>
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Tools.h>
@ -1951,7 +1951,7 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
if( (*it)->Type != Sketcher::DistanceX &&
(*it)->Type != Sketcher::DistanceY) {
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->First = geoIdMap[(*it)->First];
newconstrVals.push_back(constNew);
@ -1972,7 +1972,7 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
(*it)->Type == Sketcher::Equal ||
(*it)->Type == Sketcher::Radius ||
(*it)->Type == Sketcher::PointOnObject ){
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->First = geoIdMap[(*it)->First];
constNew->Second = geoIdMap[(*it)->Second];
@ -1999,7 +1999,7 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
std::vector<int>::const_iterator tit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Third);
if(tit != geoIdList.end()) { // Third is also in the list
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->First = geoIdMap[(*it)->First];
constNew->Second = geoIdMap[(*it)->Second];
constNew->Third = geoIdMap[(*it)->Third];
@ -2182,20 +2182,20 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
(*it)->Type == Sketcher::Distance ||
(*it)->Type == Sketcher::Radius ) && clone ) {
// Distances on a single Element are mapped to equality constraints in clone mode
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->Type = Sketcher::Equal;
constNew->Second = geoIdMap[(*it)->First]; // first is already (*it->First)
newconstrVals.push_back(constNew);
}
else if ((*it)->Type == Sketcher::Angle && clone){
// Angles on a single Element are mapped to parallel constraints in clone mode
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->Type = Sketcher::Parallel;
constNew->Second = geoIdMap[(*it)->First]; // first is already (*it->First)
newconstrVals.push_back(constNew);
}
else {
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->First = geoIdMap[(*it)->First];
newconstrVals.push_back(constNew);
}
@ -2211,7 +2211,7 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Distance) && ((*it)->First == (*it)->Second) && clone ) {
// Distances on a two Elements, which must be points of the same line are mapped to equality constraints in clone mode
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->Type = Sketcher::Equal;
constNew->FirstPos = Sketcher::none;
constNew->Second = geoIdMap[(*it)->First]; // first is already (*it->First)
@ -2219,7 +2219,7 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
newconstrVals.push_back(constNew);
}
else {
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->First = geoIdMap[(*it)->First];
constNew->Second = geoIdMap[(*it)->Second];
newconstrVals.push_back(constNew);
@ -2229,7 +2229,7 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
std::vector<int>::const_iterator tit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Third);
if(tit != geoIdList.end()) { // Third is also in the list
Constraint *constNew = (*it)->clone();
Constraint *constNew = (*it)->copy();
constNew->First = geoIdMap[(*it)->First];
constNew->Second = geoIdMap[(*it)->Second];
constNew->Third = geoIdMap[(*it)->Third];