Sketcher new Feature: Non-driving constraints (aka Driven constraints or dimensions)
==================================================================================== It allows to enable and disable a constraint in the constraint list. When disabled, the constraints current value is shown, but its value is not enforced (it is driven by the other constraints and user interaction). A disabled constraint can be enabled (as far as it is enforceable, see non-driving constraints to external geometry below). The sketcher functionality has been extended to support non-driving constraints to external geometry elements. This were previously excluded from the possibility of creating a constraint on them (as their values depend on other sketches and would be redundant with the unchanged value or conflicting when value is changed). Now these constraints are created as non-driving, but as they are not enforceable, the UI does not allow you to make them driving. The constraint filter has been extended to include a Non-Driving constraints category. Thanks again to Werner for his continuous support, and specially in this case to DeepSOIC, as he pointed towards a much better implementation solution than my original idea.
This commit is contained in:
@@ -53,7 +53,8 @@ Constraint::Constraint()
|
||||
Third(GeoUndef),
|
||||
ThirdPos(none),
|
||||
LabelDistance(10.f),
|
||||
LabelPosition(0.f)
|
||||
LabelPosition(0.f),
|
||||
isDriving(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -69,7 +70,8 @@ Constraint::Constraint(const Constraint& from)
|
||||
Third(from.Third),
|
||||
ThirdPos(from.ThirdPos),
|
||||
LabelDistance(from.LabelDistance),
|
||||
LabelPosition(from.LabelPosition)
|
||||
LabelPosition(from.LabelPosition),
|
||||
isDriving(from.isDriving)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -109,7 +111,8 @@ void Constraint::Save (Writer &writer) const
|
||||
<< "Third=\"" << Third << "\" "
|
||||
<< "ThirdPos=\"" << (int) ThirdPos << "\" "
|
||||
<< "LabelDistance=\"" << LabelDistance << "\" "
|
||||
<< "LabelPosition=\"" << LabelPosition << "\" />"
|
||||
<< "LabelPosition=\"" << LabelPosition << "\" "
|
||||
<< "IsDriving=\"" << (int)isDriving << "\" />"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -140,4 +143,7 @@ void Constraint::Restore(XMLReader &reader)
|
||||
|
||||
if (reader.hasAttribute("LabelPosition"))
|
||||
LabelPosition = (float)reader.getAttributeAsFloat("LabelPosition");
|
||||
|
||||
if (reader.hasAttribute("IsDriving"))
|
||||
isDriving = (bool)reader.getAttributeAsInteger("IsDriving");
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ public:
|
||||
PointPos ThirdPos;
|
||||
float LabelDistance;
|
||||
float LabelPosition;
|
||||
bool isDriving;
|
||||
};
|
||||
|
||||
} //namespace Sketcher
|
||||
|
||||
@@ -94,6 +94,11 @@ void Sketch::clear(void)
|
||||
for (std::vector<GeoDef>::iterator it = Geoms.begin(); it != Geoms.end(); ++it)
|
||||
if (it->geo) delete it->geo;
|
||||
Geoms.clear();
|
||||
|
||||
// deleting the non-Driving constraints copied into this sketch
|
||||
//for (std::vector<Constraint *>::iterator it = NonDrivingConstraints.begin(); it != NonDrivingConstraints.end(); ++it)
|
||||
// if (*it) delete *it;
|
||||
Constrs.clear();
|
||||
|
||||
GCSsys.clear();
|
||||
isInitMove = false;
|
||||
@@ -121,9 +126,9 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList,
|
||||
Geoms[i].external = true;
|
||||
|
||||
// The Geoms list might be empty after an undo/redo
|
||||
if (!Geoms.empty())
|
||||
if (!Geoms.empty()) {
|
||||
addConstraints(ConstraintList);
|
||||
|
||||
}
|
||||
GCSsys.clearByTag(-1);
|
||||
GCSsys.declareUnknowns(Parameters);
|
||||
GCSsys.initSolution();
|
||||
@@ -630,24 +635,69 @@ int Sketch::addConstraint(const Constraint *constraint)
|
||||
if(int(Geoms.size()) <= 0)
|
||||
throw Base::Exception("Sketch::addConstraint. Can't add constraint to a sketch with no geometry!");
|
||||
int rtn = -1;
|
||||
|
||||
ConstrDef c;
|
||||
c.constr=const_cast<Constraint *>(constraint);
|
||||
c.driving=constraint->isDriving;
|
||||
|
||||
switch (constraint->Type) {
|
||||
case DistanceX:
|
||||
if (constraint->FirstPos == none) // horizontal length of a line
|
||||
rtn = addDistanceXConstraint(constraint->First,constraint->Value);
|
||||
else if (constraint->Second == Constraint::GeoUndef) // point on fixed x-coordinate
|
||||
rtn = addCoordinateXConstraint(constraint->First,constraint->FirstPos,constraint->Value);
|
||||
else if (constraint->SecondPos != none) // point to point horizontal distance
|
||||
if (constraint->FirstPos == none){ // horizontal length of a line
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addDistanceXConstraint(constraint->First,c.value);
|
||||
}
|
||||
else if (constraint->Second == Constraint::GeoUndef) {// point on fixed x-coordinate
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addCoordinateXConstraint(constraint->First,constraint->FirstPos,c.value);
|
||||
}
|
||||
else if (constraint->SecondPos != none) {// point to point horizontal distance
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addDistanceXConstraint(constraint->First,constraint->FirstPos,
|
||||
constraint->Second,constraint->SecondPos,constraint->Value);
|
||||
constraint->Second,constraint->SecondPos,c.value);
|
||||
}
|
||||
break;
|
||||
case DistanceY:
|
||||
if (constraint->FirstPos == none) // vertical length of a line
|
||||
rtn = addDistanceYConstraint(constraint->First,constraint->Value);
|
||||
else if (constraint->Second == Constraint::GeoUndef) // point on fixed y-coordinate
|
||||
rtn = addCoordinateYConstraint(constraint->First,constraint->FirstPos,constraint->Value);
|
||||
else if (constraint->SecondPos != none) // point to point vertical distance
|
||||
if (constraint->FirstPos == none){ // vertical length of a line
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addDistanceYConstraint(constraint->First,c.value);
|
||||
}
|
||||
else if (constraint->Second == Constraint::GeoUndef){ // point on fixed y-coordinate
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addCoordinateYConstraint(constraint->First,constraint->FirstPos,c.value);
|
||||
}
|
||||
else if (constraint->SecondPos != none){ // point to point vertical distance
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addDistanceYConstraint(constraint->First,constraint->FirstPos,
|
||||
constraint->Second,constraint->SecondPos,constraint->Value);
|
||||
constraint->Second,constraint->SecondPos,c.value);
|
||||
}
|
||||
break;
|
||||
case Horizontal:
|
||||
if (constraint->Second == Constraint::GeoUndef) // horizontal line
|
||||
@@ -680,11 +730,17 @@ int Sketch::addConstraint(const Constraint *constraint)
|
||||
rtn = addPerpendicularConstraint(constraint->First,constraint->Second);
|
||||
} else {
|
||||
//any other point-wise perpendicularity
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addAngleAtPointConstraint(
|
||||
constraint->First, constraint->FirstPos,
|
||||
constraint->Second, constraint->SecondPos,
|
||||
constraint->Third, constraint->ThirdPos,
|
||||
constraint->Value, constraint->Type);
|
||||
c.value, constraint->Type);
|
||||
}
|
||||
|
||||
|
||||
@@ -697,46 +753,101 @@ int Sketch::addConstraint(const Constraint *constraint)
|
||||
rtn = addTangentConstraint(constraint->First,constraint->Second);
|
||||
} else {
|
||||
//any other point-wise tangency (endpoint-to-curve, endpoint-to-endpoint, tangent-via-point)
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addAngleAtPointConstraint(
|
||||
constraint->First, constraint->FirstPos,
|
||||
constraint->Second, constraint->SecondPos,
|
||||
constraint->Third, constraint->ThirdPos,
|
||||
constraint->Value, constraint->Type);
|
||||
c.value, constraint->Type);
|
||||
}
|
||||
break;
|
||||
case Distance:
|
||||
if (constraint->SecondPos != none) // point to point distance
|
||||
if (constraint->SecondPos != none){ // point to point distance
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addDistanceConstraint(constraint->First,constraint->FirstPos,
|
||||
constraint->Second,constraint->SecondPos,
|
||||
constraint->Value);
|
||||
else if (constraint->Second != Constraint::GeoUndef) {
|
||||
if (constraint->FirstPos != none) // point to line distance
|
||||
rtn = addDistanceConstraint(constraint->First,constraint->FirstPos,
|
||||
constraint->Second,constraint->Value);
|
||||
else // line to line distance (not implemented yet)
|
||||
rtn = addDistanceConstraint(constraint->First,constraint->Second,constraint->Value);
|
||||
c.value);
|
||||
}
|
||||
else if (constraint->Second != Constraint::GeoUndef) {
|
||||
if (constraint->FirstPos != none) { // point to line distance
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addDistanceConstraint(constraint->First,constraint->FirstPos,
|
||||
constraint->Second,c.value);
|
||||
}
|
||||
}
|
||||
else {// line length
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addDistanceConstraint(constraint->First,c.value);
|
||||
}
|
||||
else // line length
|
||||
rtn = addDistanceConstraint(constraint->First,constraint->Value);
|
||||
break;
|
||||
case Angle:
|
||||
if (constraint->Third != Constraint::GeoUndef){
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addAngleAtPointConstraint (
|
||||
constraint->First, constraint->FirstPos,
|
||||
constraint->Second, constraint->SecondPos,
|
||||
constraint->Third, constraint->ThirdPos,
|
||||
constraint->Value, constraint->Type);
|
||||
} else if (constraint->SecondPos != none) // angle between two lines (with explicit start points)
|
||||
c.value, constraint->Type);
|
||||
} else if (constraint->SecondPos != none){ // angle between two lines (with explicit start points)
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
|
||||
rtn = addAngleConstraint(constraint->First,constraint->FirstPos,
|
||||
constraint->Second,constraint->SecondPos,constraint->Value);
|
||||
else if (constraint->Second != Constraint::GeoUndef) // angle between two lines
|
||||
rtn = addAngleConstraint(constraint->First,constraint->Second,constraint->Value);
|
||||
else if (constraint->First != Constraint::GeoUndef) // orientation angle of a line
|
||||
rtn = addAngleConstraint(constraint->First,constraint->Value);
|
||||
constraint->Second,constraint->SecondPos,c.value);
|
||||
}
|
||||
else if (constraint->Second != Constraint::GeoUndef){ // angle between two lines
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addAngleConstraint(constraint->First,constraint->Second,c.value);
|
||||
}
|
||||
else if (constraint->First != Constraint::GeoUndef) {// orientation angle of a line
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addAngleConstraint(constraint->First,c.value);
|
||||
}
|
||||
break;
|
||||
case Radius:
|
||||
rtn = addRadiusConstraint(constraint->First, constraint->Value);
|
||||
{
|
||||
c.value = new double(constraint->Value);
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else
|
||||
Parameters.push_back(c.value);
|
||||
rtn = addRadiusConstraint(constraint->First, c.value);
|
||||
break;
|
||||
}
|
||||
case Equal:
|
||||
rtn = addEqualConstraint(constraint->First,constraint->Second);
|
||||
break;
|
||||
@@ -766,62 +877,76 @@ int Sketch::addConstraint(const Constraint *constraint)
|
||||
}
|
||||
break;
|
||||
case SnellsLaw:
|
||||
{
|
||||
c.value = new double(constraint->Value);
|
||||
c.secondvalue = new double(constraint->Value);
|
||||
|
||||
if(c.driving) {
|
||||
FixParameters.push_back(c.value);
|
||||
FixParameters.push_back(c.secondvalue);
|
||||
}
|
||||
else {
|
||||
Parameters.push_back(c.value);
|
||||
Parameters.push_back(c.secondvalue);
|
||||
}
|
||||
|
||||
//assert(constraint->ThirdPos==none); //will work anyway...
|
||||
rtn = addSnellsLawConstraint(constraint->First, constraint->FirstPos,
|
||||
constraint->Second, constraint->SecondPos,
|
||||
constraint->Third,
|
||||
constraint->Value);
|
||||
c.value, c.secondvalue);
|
||||
}
|
||||
break;
|
||||
case None:
|
||||
break;
|
||||
}
|
||||
|
||||
Constrs.push_back(c);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
int Sketch::addConstraints(const std::vector<Constraint *> &ConstraintList)
|
||||
{
|
||||
int rtn = -1;
|
||||
|
||||
for (std::vector<Constraint *>::const_iterator it = ConstraintList.begin();it!=ConstraintList.end();++it)
|
||||
rtn = addConstraint (*it);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
int Sketch::addCoordinateXConstraint(int geoId, PointPos pos, double value)
|
||||
int Sketch::addCoordinateXConstraint(int geoId, PointPos pos, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
int pointId = getPointId(geoId, pos);
|
||||
|
||||
if (pointId >= 0 && pointId < int(Points.size())) {
|
||||
double *val = new double(value);
|
||||
FixParameters.push_back(val);
|
||||
|
||||
GCS::Point &p = Points[pointId];
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintCoordinateX(p, val, tag);
|
||||
GCSsys.addConstraintCoordinateX(p, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Sketch::addCoordinateYConstraint(int geoId, PointPos pos, double value)
|
||||
int Sketch::addCoordinateYConstraint(int geoId, PointPos pos, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
int pointId = getPointId(geoId, pos);
|
||||
|
||||
if (pointId >= 0 && pointId < int(Points.size())) {
|
||||
double *val = new double(value);
|
||||
FixParameters.push_back(val);
|
||||
GCS::Point &p = Points[pointId];
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintCoordinateY(p, val, tag);
|
||||
GCSsys.addConstraintCoordinateY(p, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Sketch::addDistanceXConstraint(int geoId, double value)
|
||||
int Sketch::addDistanceXConstraint(int geoId, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
@@ -830,15 +955,12 @@ int Sketch::addDistanceXConstraint(int geoId, double value)
|
||||
|
||||
GCS::Line &l = Lines[Geoms[geoId].index];
|
||||
|
||||
FixParameters.push_back(new double(value));
|
||||
double *diff = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintDifference(l.p1.x, l.p2.x, diff, tag);
|
||||
GCSsys.addConstraintDifference(l.p1.x, l.p2.x, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
|
||||
int Sketch::addDistanceYConstraint(int geoId, double value)
|
||||
int Sketch::addDistanceYConstraint(int geoId, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
@@ -847,15 +969,12 @@ int Sketch::addDistanceYConstraint(int geoId, double value)
|
||||
|
||||
GCS::Line &l = Lines[Geoms[geoId].index];
|
||||
|
||||
FixParameters.push_back(new double(value));
|
||||
double *diff = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintDifference(l.p1.y, l.p2.y, diff, tag);
|
||||
GCSsys.addConstraintDifference(l.p1.y, l.p2.y, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
|
||||
int Sketch::addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
|
||||
int Sketch::addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value)
|
||||
{
|
||||
geoId1 = checkGeoId(geoId1);
|
||||
geoId2 = checkGeoId(geoId2);
|
||||
@@ -868,17 +987,14 @@ int Sketch::addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointP
|
||||
GCS::Point &p1 = Points[pointId1];
|
||||
GCS::Point &p2 = Points[pointId2];
|
||||
|
||||
FixParameters.push_back(new double(value));
|
||||
double *difference = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintDifference(p1.x, p2.x, difference, tag);
|
||||
GCSsys.addConstraintDifference(p1.x, p2.x, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Sketch::addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
|
||||
int Sketch::addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value)
|
||||
{
|
||||
geoId1 = checkGeoId(geoId1);
|
||||
geoId2 = checkGeoId(geoId2);
|
||||
@@ -891,11 +1007,8 @@ int Sketch::addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointP
|
||||
GCS::Point &p1 = Points[pointId1];
|
||||
GCS::Point &p2 = Points[pointId2];
|
||||
|
||||
FixParameters.push_back(new double(value));
|
||||
double *difference = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintDifference(p1.y, p2.y, difference, tag);
|
||||
GCSsys.addConstraintDifference(p1.y, p2.y, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
@@ -1148,7 +1261,7 @@ int Sketch::addAngleAtPointConstraint(
|
||||
int geoId1, PointPos pos1,
|
||||
int geoId2, PointPos pos2,
|
||||
int geoId3, PointPos pos3,
|
||||
double value,
|
||||
double * value,
|
||||
ConstraintType cTyp)
|
||||
{
|
||||
|
||||
@@ -1205,9 +1318,7 @@ int Sketch::addAngleAtPointConstraint(
|
||||
p2 = &(Points[pointId]);
|
||||
}
|
||||
|
||||
// add the parameter for the angle
|
||||
FixParameters.push_back(new double(0.0));
|
||||
double *angle = FixParameters[FixParameters.size()-1];
|
||||
double *angle = value;
|
||||
|
||||
//For tangency/perpendicularity, we don't just copy the angle.
|
||||
//The angle stored for tangency/perpendicularity is offset, so that the options
|
||||
@@ -1215,9 +1326,8 @@ int Sketch::addAngleAtPointConstraint(
|
||||
// Use autodetect then.
|
||||
//The same functionality is implemented in SketchObject.cpp, where
|
||||
// it is used to permanently lock down the autodecision.
|
||||
if (cTyp == Angle)
|
||||
*angle = value;
|
||||
else {
|
||||
if (cTyp != Angle)
|
||||
{
|
||||
//The same functionality is implemented in SketchObject.cpp, where
|
||||
// it is used to permanently lock down the autodecision.
|
||||
double angleOffset = 0.0;//the difference between the datum value and the actual angle to apply. (datum=angle+offset)
|
||||
@@ -1225,7 +1335,7 @@ int Sketch::addAngleAtPointConstraint(
|
||||
if (cTyp == Tangent) {angleOffset = -M_PI/2; angleDesire = 0.0;}
|
||||
if (cTyp == Perpendicular) {angleOffset = 0; angleDesire = M_PI/2;}
|
||||
|
||||
if (value==0.0) {//autodetect tangency internal/external (and same for perpendicularity)
|
||||
if (*value==0.0) {//autodetect tangency internal/external (and same for perpendicularity)
|
||||
double angleErr = GCSsys.calculateAngleViaPoint(*crv1, *crv2, p) - angleDesire;
|
||||
//bring angleErr to -pi..pi
|
||||
if (angleErr > M_PI) angleErr -= M_PI*2;
|
||||
@@ -1237,10 +1347,9 @@ int Sketch::addAngleAtPointConstraint(
|
||||
|
||||
*angle = angleDesire;
|
||||
} else
|
||||
*angle = value-angleOffset;
|
||||
*angle = *value-angleOffset;
|
||||
}
|
||||
|
||||
|
||||
int tag = -1;
|
||||
if(e2c)
|
||||
tag = Sketch::addPointOnObjectConstraint(geoId1, pos1, geoId2);//increases ConstraintsCounter
|
||||
@@ -1256,7 +1365,7 @@ int Sketch::addAngleAtPointConstraint(
|
||||
}
|
||||
|
||||
// line length constraint
|
||||
int Sketch::addDistanceConstraint(int geoId, double value)
|
||||
int Sketch::addDistanceConstraint(int geoId, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
@@ -1265,31 +1374,13 @@ int Sketch::addDistanceConstraint(int geoId, double value)
|
||||
|
||||
GCS::Line &l = Lines[Geoms[geoId].index];
|
||||
|
||||
// add the parameter for the length
|
||||
FixParameters.push_back(new double(value));
|
||||
double *distance = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintP2PDistance(l.p1, l.p2, distance, tag);
|
||||
GCSsys.addConstraintP2PDistance(l.p1, l.p2, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
|
||||
// line to line distance constraint
|
||||
int Sketch::addDistanceConstraint(int geoId1, int geoId2, double value)
|
||||
{
|
||||
//geoId1 = checkGeoId(geoId1);
|
||||
//geoId2 = checkGeoId(geoId2);
|
||||
|
||||
//assert(Geoms[geoId1].type == Line);
|
||||
//assert(Geoms[geoId2].type == Line);
|
||||
|
||||
Base::Console().Warning("Line to line distance constraints are not implemented yet.\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// point to line distance constraint
|
||||
int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double value)
|
||||
int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double * value)
|
||||
{
|
||||
geoId1 = checkGeoId(geoId1);
|
||||
geoId2 = checkGeoId(geoId2);
|
||||
@@ -1303,19 +1394,15 @@ int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double
|
||||
GCS::Point &p1 = Points[pointId1];
|
||||
GCS::Line &l2 = Lines[Geoms[geoId2].index];
|
||||
|
||||
// add the parameter for the distance
|
||||
FixParameters.push_back(new double(value));
|
||||
double *distance = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintP2LDistance(p1, l2, distance, tag);
|
||||
GCSsys.addConstraintP2LDistance(p1, l2, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// point to point distance constraint
|
||||
int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
|
||||
int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value)
|
||||
{
|
||||
geoId1 = checkGeoId(geoId1);
|
||||
geoId2 = checkGeoId(geoId2);
|
||||
@@ -1328,74 +1415,56 @@ int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPo
|
||||
GCS::Point &p1 = Points[pointId1];
|
||||
GCS::Point &p2 = Points[pointId2];
|
||||
|
||||
// add the parameter for the distance
|
||||
FixParameters.push_back(new double(value));
|
||||
double *distance = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintP2PDistance(p1, p2, distance, tag);
|
||||
GCSsys.addConstraintP2PDistance(p1, p2, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Sketch::addRadiusConstraint(int geoId, double value)
|
||||
int Sketch::addRadiusConstraint(int geoId, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
if (Geoms[geoId].type == Circle) {
|
||||
GCS::Circle &c = Circles[Geoms[geoId].index];
|
||||
// add the parameter for the radius
|
||||
FixParameters.push_back(new double(value));
|
||||
double *radius = FixParameters[FixParameters.size()-1];
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintCircleRadius(c, radius, tag);
|
||||
GCSsys.addConstraintCircleRadius(c, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
else if (Geoms[geoId].type == Arc) {
|
||||
GCS::Arc &a = Arcs[Geoms[geoId].index];
|
||||
// add the parameter for the radius
|
||||
FixParameters.push_back(new double(value));
|
||||
double *radius = FixParameters[FixParameters.size()-1];
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintArcRadius(a, radius, tag);
|
||||
GCSsys.addConstraintArcRadius(a, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// line orientation angle constraint
|
||||
int Sketch::addAngleConstraint(int geoId, double value)
|
||||
int Sketch::addAngleConstraint(int geoId, double * value)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
if (Geoms[geoId].type == Line) {
|
||||
GCS::Line &l = Lines[Geoms[geoId].index];
|
||||
|
||||
// add the parameter for the angle
|
||||
FixParameters.push_back(new double(value));
|
||||
double *angle = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintP2PAngle(l.p1, l.p2, angle, tag);
|
||||
GCSsys.addConstraintP2PAngle(l.p1, l.p2, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
else if (Geoms[geoId].type == Arc) {
|
||||
GCS::Arc &a = Arcs[Geoms[geoId].index];
|
||||
|
||||
// add the parameter for the angle
|
||||
FixParameters.push_back(new double(value));
|
||||
double *angle = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintL2LAngle(a.center, a.start, a.center, a.end, angle, tag);
|
||||
GCSsys.addConstraintL2LAngle(a.center, a.start, a.center, a.end, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// line to line angle constraint
|
||||
int Sketch::addAngleConstraint(int geoId1, int geoId2, double value)
|
||||
int Sketch::addAngleConstraint(int geoId1, int geoId2, double * value)
|
||||
{
|
||||
geoId1 = checkGeoId(geoId1);
|
||||
geoId2 = checkGeoId(geoId2);
|
||||
@@ -1407,17 +1476,13 @@ int Sketch::addAngleConstraint(int geoId1, int geoId2, double value)
|
||||
GCS::Line &l1 = Lines[Geoms[geoId1].index];
|
||||
GCS::Line &l2 = Lines[Geoms[geoId2].index];
|
||||
|
||||
// add the parameter for the angle
|
||||
FixParameters.push_back(new double(value));
|
||||
double *angle = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintL2LAngle(l1, l2, angle, tag);
|
||||
GCSsys.addConstraintL2LAngle(l1, l2, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
|
||||
// line to line angle constraint (with explicitly given start points)
|
||||
int Sketch::addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
|
||||
int Sketch::addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value)
|
||||
{
|
||||
geoId1 = checkGeoId(geoId1);
|
||||
geoId2 = checkGeoId(geoId2);
|
||||
@@ -1447,12 +1512,8 @@ int Sketch::addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos p
|
||||
if (l1p1 == 0 || l2p1 == 0)
|
||||
return -1;
|
||||
|
||||
// add the parameter for the angle
|
||||
FixParameters.push_back(new double(value));
|
||||
double *angle = FixParameters[FixParameters.size()-1];
|
||||
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintL2LAngle(*l1p1, *l1p2, *l2p1, *l2p2, angle, tag);
|
||||
GCSsys.addConstraintL2LAngle(*l1p1, *l1p2, *l2p1, *l2p2, value, tag);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
|
||||
@@ -1644,7 +1705,9 @@ int Sketch::addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointP
|
||||
int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1,
|
||||
int geoIdRay2, PointPos posRay2,
|
||||
int geoIdBnd,
|
||||
double n2divn1)
|
||||
double * value,
|
||||
double * secondvalue
|
||||
)
|
||||
{
|
||||
|
||||
geoIdRay1 = checkGeoId(geoIdRay1);
|
||||
@@ -1675,12 +1738,13 @@ int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1,
|
||||
GCS::Point &p1 = Points[pointId1];
|
||||
GCS::Point &p2 = Points[pointId2];
|
||||
|
||||
// add the parameters (refractive indexes)
|
||||
FixParameters.push_back(new double(0.0));
|
||||
double *n1 = FixParameters[FixParameters.size()-1];
|
||||
FixParameters.push_back(new double(0.0));
|
||||
double *n2 = FixParameters[FixParameters.size()-1];
|
||||
|
||||
// add the parameters (refractive indexes)
|
||||
// n1 uses the place hold by n2divn1, so that is retrivable in updateNonDrivingConstraints
|
||||
double *n1 = value;
|
||||
double *n2 = secondvalue;
|
||||
|
||||
double n2divn1=*value;
|
||||
|
||||
if ( abs(n2divn1) >= 1.0 ){
|
||||
*n2 = n2divn1;
|
||||
*n1 = 1.0;
|
||||
@@ -1993,6 +2057,23 @@ bool Sketch::updateGeometry()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Sketch::updateNonDrivingConstraints()
|
||||
{
|
||||
for (std::vector<ConstrDef>::iterator it = Constrs.begin();it!=Constrs.end();++it){
|
||||
if(!(*it).driving) {
|
||||
if((*it).constr->Type==SnellsLaw) {
|
||||
double n1 = *((*it).value);
|
||||
double n2 = *((*it).secondvalue);
|
||||
|
||||
(*it).constr->Value = n2/n1;
|
||||
}
|
||||
else
|
||||
(*it).constr->Value=*((*it).value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// solving ==========================================================
|
||||
|
||||
int Sketch::solve(void)
|
||||
@@ -2043,6 +2124,9 @@ int Sketch::solve(void)
|
||||
GCSsys.undoSolution();
|
||||
updateGeometry();
|
||||
Base::Console().Warning("Invalid solution from %s solver.\n", solvername.c_str());
|
||||
}else
|
||||
{
|
||||
updateNonDrivingConstraints();
|
||||
}
|
||||
} else {
|
||||
valid_solution = false;
|
||||
|
||||
@@ -135,14 +135,14 @@ public:
|
||||
/// add one constraint to the sketch
|
||||
int addConstraint(const Constraint *constraint);
|
||||
/// add a fixed coordinate constraint to a point
|
||||
int addCoordinateXConstraint(int geoId, PointPos pos, double value);
|
||||
int addCoordinateYConstraint(int geoId, PointPos pos, double value);
|
||||
int addCoordinateXConstraint(int geoId, PointPos pos, double * value);
|
||||
int addCoordinateYConstraint(int geoId, PointPos pos, double * value);
|
||||
/// add a horizontal distance constraint to two points or line ends
|
||||
int addDistanceXConstraint(int geoId, double value);
|
||||
int addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
|
||||
int addDistanceXConstraint(int geoId, double * value);
|
||||
int addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value);
|
||||
/// add a vertical distance constraint to two points or line ends
|
||||
int addDistanceYConstraint(int geoId, double value);
|
||||
int addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
|
||||
int addDistanceYConstraint(int geoId, double * value);
|
||||
int addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value);
|
||||
/// add a horizontal constraint to a geometry
|
||||
int addHorizontalConstraint(int geoId);
|
||||
int addHorizontalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
|
||||
@@ -152,10 +152,9 @@ public:
|
||||
/// add a coincident constraint to two points of two geometries
|
||||
int addPointCoincidentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
|
||||
/// add a length or distance constraint
|
||||
int addDistanceConstraint(int geoId1, double value);
|
||||
int addDistanceConstraint(int geoId1, int geoId2, double value);
|
||||
int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double value);
|
||||
int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
|
||||
int addDistanceConstraint(int geoId1, double * value);
|
||||
int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double * value);
|
||||
int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value);
|
||||
/// add a parallel constraint between two lines
|
||||
int addParallelConstraint(int geoId1, int geoId2);
|
||||
/// add a perpendicular constraint between two lines
|
||||
@@ -166,14 +165,14 @@ public:
|
||||
int geoId1, PointPos pos1,
|
||||
int geoId2, PointPos pos2,
|
||||
int geoId3, PointPos pos3,
|
||||
double value,
|
||||
double * value,
|
||||
ConstraintType cTyp);
|
||||
/// add a radius constraint on a circle or an arc
|
||||
int addRadiusConstraint(int geoId, double value);
|
||||
int addRadiusConstraint(int geoId, double * value);
|
||||
/// add an angle constraint on a line or between two lines
|
||||
int addAngleConstraint(int geoId, double value);
|
||||
int addAngleConstraint(int geoId1, int geoId2, double value);
|
||||
int addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
|
||||
int addAngleConstraint(int geoId, double * value);
|
||||
int addAngleConstraint(int geoId1, int geoId2, double * value);
|
||||
int addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value);
|
||||
/// add angle-via-point constraint between any two curves
|
||||
int addAngleViaPointConstraint(int geoId1, int geoId2, int geoId3, PointPos pos3, double value);
|
||||
/// add an equal length or radius constraints between two lines or between circles and arcs
|
||||
@@ -188,7 +187,8 @@ public:
|
||||
int addSnellsLawConstraint(int geoIdRay1, PointPos posRay1,
|
||||
int geoIdRay2, PointPos posRay2,
|
||||
int geoIdBnd,
|
||||
double n2divn1);
|
||||
double * value,
|
||||
double * second);
|
||||
//@}
|
||||
|
||||
/// Internal Alignment constraints
|
||||
@@ -238,8 +238,17 @@ protected:
|
||||
int midPointId; // index in Points of the start point of this geometry
|
||||
int endPointId; // index in Points of the end point of this geometry
|
||||
};
|
||||
|
||||
struct ConstrDef {
|
||||
ConstrDef() : driving(true) {}
|
||||
Constraint * constr; // pointer to the constraint
|
||||
bool driving;
|
||||
double * value;
|
||||
double * secondvalue; // this is needed for SnellsLaw
|
||||
};
|
||||
|
||||
std::vector<GeoDef> Geoms;
|
||||
std::vector<ConstrDef> Constrs;
|
||||
GCS::System GCSsys;
|
||||
int ConstraintsCounter;
|
||||
std::vector<int> Conflicting;
|
||||
@@ -264,6 +273,7 @@ protected:
|
||||
private:
|
||||
|
||||
bool updateGeometry(void);
|
||||
bool updateNonDrivingConstraints(void);
|
||||
|
||||
/// checks if the index bounds and converts negative indices to positive
|
||||
int checkGeoId(int geoId);
|
||||
|
||||
@@ -219,6 +219,60 @@ int SketchObject::setDatum(int ConstrId, double Datum)
|
||||
return err;
|
||||
}
|
||||
|
||||
int SketchObject::setDriving(int ConstrId, bool isdriving)
|
||||
{
|
||||
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size()))
|
||||
return -1;
|
||||
|
||||
ConstraintType type = vals[ConstrId]->Type;
|
||||
|
||||
if (type != Distance &&
|
||||
type != DistanceX &&
|
||||
type != DistanceY &&
|
||||
type != Radius &&
|
||||
type != Angle &&
|
||||
type != SnellsLaw)
|
||||
return -1;
|
||||
|
||||
// copy the list
|
||||
std::vector<Constraint *> newVals(vals);
|
||||
// clone the changed Constraint
|
||||
Constraint *constNew = vals[ConstrId]->clone();
|
||||
constNew->isDriving = isdriving;
|
||||
newVals[ConstrId] = constNew;
|
||||
this->Constraints.setValues(newVals);
|
||||
delete constNew;
|
||||
|
||||
int err = solve();
|
||||
if (err)
|
||||
this->Constraints.setValues(vals);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int SketchObject::getDriving(int ConstrId, bool &isdriving)
|
||||
{
|
||||
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size()))
|
||||
return -1;
|
||||
|
||||
ConstraintType type = vals[ConstrId]->Type;
|
||||
|
||||
if (type != Distance &&
|
||||
type != DistanceX &&
|
||||
type != DistanceY &&
|
||||
type != Radius &&
|
||||
type != Angle &&
|
||||
type != SnellsLaw)
|
||||
return -1;
|
||||
|
||||
isdriving=vals[ConstrId]->isDriving;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative)
|
||||
{
|
||||
Sketch sketch;
|
||||
|
||||
@@ -110,6 +110,10 @@ public:
|
||||
int solve();
|
||||
/// set the datum of a Distance or Angle constraint and solve
|
||||
int setDatum(int ConstrId, double Datum);
|
||||
/// set the driving status of this constraint and solve
|
||||
int setDriving(int ConstrId, bool isdriving);
|
||||
/// get the driving status of this constraint
|
||||
int getDriving(int ConstrId, bool &isdriving);
|
||||
/// move this point to a new location and solve
|
||||
int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative=false);
|
||||
/// retrieves the coordinates of a point
|
||||
|
||||
@@ -78,6 +78,16 @@
|
||||
<UserDocu>Get the value of a datum constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setDriving">
|
||||
<Documentation>
|
||||
<UserDocu>set the Driving status of a datum constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getDriving">
|
||||
<Documentation>
|
||||
<UserDocu>Get the Driving status of a datum constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="movePoint">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
||||
@@ -568,6 +568,42 @@ PyObject* SketchObjectPy::getDatum(PyObject *args)
|
||||
return new Base::QuantityPy(new Base::Quantity(datum));
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::setDriving(PyObject *args)
|
||||
{
|
||||
PyObject* driving;
|
||||
int constrid;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iO!", &constrid, &PyBool_Type, &driving))
|
||||
return 0;
|
||||
|
||||
if (this->getSketchObjectPtr()->setDriving(constrid, PyObject_IsTrue(driving) ? true : false)) {
|
||||
std::stringstream str;
|
||||
str << "Not able set Driving for constraint with the given index: " << constrid;
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::getDriving(PyObject *args)
|
||||
{
|
||||
int constrid;
|
||||
bool driving;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &constrid))
|
||||
return 0;
|
||||
|
||||
SketchObject* obj = this->getSketchObjectPtr();
|
||||
if (this->getSketchObjectPtr()->getDriving(constrid, driving)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Py::new_reference_to(Py::Boolean(driving));
|
||||
}
|
||||
|
||||
|
||||
PyObject* SketchObjectPy::movePoint(PyObject *args)
|
||||
{
|
||||
PyObject *pcObj;
|
||||
|
||||
Reference in New Issue
Block a user