Sketcher: Contraint class extension

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

An additional index for internal geometry elements is introduced, to be stored only Internal Aligment constraint and backwards compatible.
This commit is contained in:
Abdullah Tahiri 2017-01-11 23:00:43 +01:00
parent 1155022a82
commit d66242bd08
4 changed files with 33 additions and 22 deletions

View File

@ -56,7 +56,8 @@ Constraint::Constraint()
ThirdPos(none),
LabelDistance(10.f),
LabelPosition(0.f),
isDriving(true)
isDriving(true),
InternalAlignmentIndex(-1)
{
// Initialize a random number generator, to avoid Valgrind false positives.
static boost::mt19937 ran;
@ -85,7 +86,8 @@ Constraint::Constraint(const Constraint& from)
LabelDistance(from.LabelDistance),
LabelPosition(from.LabelPosition),
isDriving(from.isDriving),
tag(from.tag)
tag(from.tag),
InternalAlignmentIndex(from.InternalAlignmentIndex)
{
}
@ -114,6 +116,7 @@ Constraint *Constraint::copy(void) const
temp->LabelDistance = this->LabelDistance;
temp->LabelPosition = this->LabelPosition;
temp->isDriving = this->isDriving;
temp->InternalAlignmentIndex = this->InternalAlignmentIndex;
// Do not copy tag, otherwise it is considered a clone, and a "rename" by the expression engine.
return temp;
}
@ -172,22 +175,24 @@ unsigned int Constraint::getMemSize (void) const
void Constraint::Save (Writer &writer) const
{
writer.Stream() << writer.ind() << "<Constrain "
<< "Name=\"" << Name << "\" "
<< "Type=\"" << (int)Type << "\" ";
<< "Name=\"" << Name << "\" "
<< "Type=\"" << (int)Type << "\" ";
if(this->Type==InternalAlignment)
writer.Stream()
<< "InternalAlignmentType=\"" << (int)AlignmentType << "\" ";
<< "InternalAlignmentType=\"" << (int)AlignmentType << "\" "
<< "InternalAlignmentIndex=\"" << InternalAlignmentIndex << "\" ";
writer.Stream()
<< "Value=\"" << Value << "\" "
<< "First=\"" << First << "\" "
<< "FirstPos=\"" << (int) FirstPos << "\" "
<< "Second=\"" << Second << "\" "
<< "SecondPos=\"" << (int) SecondPos << "\" "
<< "Third=\"" << Third << "\" "
<< "ThirdPos=\"" << (int) ThirdPos << "\" "
<< "LabelDistance=\"" << LabelDistance << "\" "
<< "LabelPosition=\"" << LabelPosition << "\" "
<< "IsDriving=\"" << (int)isDriving << "\" />"
<< "Value=\"" << Value << "\" "
<< "First=\"" << First << "\" "
<< "FirstPos=\"" << (int) FirstPos << "\" "
<< "Second=\"" << Second << "\" "
<< "SecondPos=\"" << (int) SecondPos << "\" "
<< "Third=\"" << Third << "\" "
<< "ThirdPos=\"" << (int) ThirdPos << "\" "
<< "LabelDistance=\"" << LabelDistance << "\" "
<< "LabelPosition=\"" << LabelPosition << "\" "
<< "IsDriving=\"" << (int)isDriving << "\" />"
<< std::endl;
}
@ -202,10 +207,15 @@ void Constraint::Restore(XMLReader &reader)
Second = reader.getAttributeAsInteger("Second");
SecondPos = (PointPos) reader.getAttributeAsInteger("SecondPos");
if(this->Type==InternalAlignment)
if(this->Type==InternalAlignment) {
AlignmentType = (InternalAlignmentType) reader.getAttributeAsInteger("InternalAlignmentType");
else
if (reader.hasAttribute("InternalAlignmentIndex"))
InternalAlignmentIndex = reader.getAttributeAsInteger("InternalAlignmentIndex");
}
else {
AlignmentType = Undef;
}
// read the third geo group if present
if (reader.hasAttribute("Third")) {

View File

@ -111,11 +111,12 @@ public:
PointPos FirstPos;
int Second;
PointPos SecondPos;
int Third; // Note: for InternalAlignment Type this index indexes equal internal geometry elements (e.g. index of pole in a bspline), thirdpos remains unused. It is not a GeoId.
int Third;
PointPos ThirdPos;
float LabelDistance;
float LabelPosition;
bool isDriving;
int InternalAlignmentIndex; // Note: for InternalAlignment Type this index indexes equal internal geometry elements (e.g. index of pole in a bspline). It is not a GeoId!!
protected:
boost::uuids::uuid tag;

View File

@ -1198,7 +1198,7 @@ int Sketch::addConstraint(const Constraint *constraint)
rtn = addInternalAlignmentParabolaFocus(constraint->First,constraint->Second);
break;
case BSplineControlPoint:
rtn = addInternalAlignmentBSplineControlPoint(constraint->First,constraint->Second, constraint->Third);
rtn = addInternalAlignmentBSplineControlPoint(constraint->First,constraint->Second, constraint->InternalAlignmentIndex);
default:
break;
}

View File

@ -3326,8 +3326,8 @@ int SketchObject::ExposeInternalGeometry(int GeoId)
{
switch((*it)->AlignmentType){
case Sketcher::BSplineControlPoint:
controlpoints[(*it)->Third] = true;
controlpointgeoids[(*it)->Third] = (*it)->First;
controlpoints[(*it)->InternalAlignmentIndex] = true;
controlpointgeoids[(*it)->InternalAlignmentIndex] = (*it)->First;
break;
default:
return -1;
@ -3373,7 +3373,7 @@ int SketchObject::ExposeInternalGeometry(int GeoId)
newConstr->First = currentgeoid+incrgeo+1;
newConstr->FirstPos = Sketcher::mid;
newConstr->Second = GeoId;
newConstr->Third = index;
newConstr->InternalAlignmentIndex = index;
icon.push_back(newConstr);