Sketcher: Make it possible to specify if the constraint is active or driving during python creation.
This commit is contained in:
committed by
Yorik van Havre
parent
7c6dde17fb
commit
ff74dd5106
@@ -355,6 +355,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string geoId2 = (addLastIdVar2 ? "lastGeoId + " : "") + std::to_string(constraint->Second);
|
||||
std::string geoId3 = (addLastIdVar3 ? "lastGeoId + " : "") + std::to_string(constraint->Third);
|
||||
|
||||
|
||||
static std::map<
|
||||
const Sketcher::ConstraintType,
|
||||
std::function<
|
||||
@@ -365,10 +366,9 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Coincident', %s, %i, %s, %i)") % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos));
|
||||
return boost::str(boost::format("Sketcher.Constraint('Coincident', %s, %i, %s, %i")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos));
|
||||
}},
|
||||
{Sketcher::Horizontal,
|
||||
[](const Sketcher::Constraint* constr,
|
||||
@@ -376,12 +376,12 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->Second == GeoEnum::GeoUndef) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Horizontal', %s)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Horizontal', %s")
|
||||
% geoId1);
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Horizontal', %s, %i, %s, %i)") % geoId1
|
||||
boost::format("Sketcher.Constraint('Horizontal', %s, %i, %s, %i") % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos));
|
||||
}
|
||||
@@ -392,12 +392,12 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->Second == GeoEnum::GeoUndef) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Vertical', %s)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Vertical', %s")
|
||||
% geoId1);
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Vertical', %s, %i, %s, %i)") % geoId1
|
||||
boost::format("Sketcher.Constraint('Vertical', %s, %i, %s, %i") % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos));
|
||||
}
|
||||
@@ -407,7 +407,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
[[maybe_unused]] std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Block', %s)") % geoId1);
|
||||
return boost::str(boost::format("Sketcher.Constraint('Block', %s") % geoId1);
|
||||
}},
|
||||
{Sketcher::Tangent,
|
||||
[](const Sketcher::Constraint* constr,
|
||||
@@ -415,16 +415,16 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->FirstPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Tangent', %s, %s)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Tangent', %s, %s")
|
||||
% geoId1 % geoId2);
|
||||
}
|
||||
else if (constr->SecondPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Tangent', %s, %i, %s)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Tangent', %s, %i, %s")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2);
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Tangent', %s, %i, %s, %i)") % geoId1
|
||||
boost::format("Sketcher.Constraint('Tangent', %s, %i, %s, %i") % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos));
|
||||
}
|
||||
@@ -434,7 +434,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Parallel', %s, %s)") % geoId1
|
||||
return boost::str(boost::format("Sketcher.Constraint('Parallel', %s, %s") % geoId1
|
||||
% geoId2);
|
||||
}},
|
||||
{Sketcher::Perpendicular,
|
||||
@@ -443,17 +443,17 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->FirstPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Perpendicular', %s, %s)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Perpendicular', %s, %s")
|
||||
% geoId1 % geoId2);
|
||||
}
|
||||
else if (constr->SecondPos == Sketcher::PointPos::none) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Perpendicular', %s, %i, %s)") % geoId1
|
||||
boost::format("Sketcher.Constraint('Perpendicular', %s, %i, %s") % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2);
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Perpendicular', %s, %i, %s, %i)")
|
||||
boost::format("Sketcher.Constraint('Perpendicular', %s, %i, %s, %i")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos));
|
||||
}
|
||||
@@ -463,7 +463,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Equal', %s, %s)") % geoId1
|
||||
return boost::str(boost::format("Sketcher.Constraint('Equal', %s, %s") % geoId1
|
||||
% geoId2);
|
||||
}},
|
||||
{Sketcher::InternalAlignment,
|
||||
@@ -477,7 +477,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
|| constr->AlignmentType == HyperbolaMinor
|
||||
|| constr->AlignmentType == ParabolaFocalAxis) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, %s)")
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, %s")
|
||||
% constr->internalAlignmentTypeToString() % geoId1 % geoId2);
|
||||
}
|
||||
else if (constr->AlignmentType == EllipseFocus1
|
||||
@@ -485,21 +485,20 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
|| constr->AlignmentType == HyperbolaFocus
|
||||
|| constr->AlignmentType == ParabolaFocus) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, %i, %s)")
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, %i, %s")
|
||||
% constr->internalAlignmentTypeToString() % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2);
|
||||
}
|
||||
else if (constr->AlignmentType == BSplineControlPoint) {
|
||||
return boost::str(
|
||||
boost::format(
|
||||
"Sketcher.Constraint('InternalAlignment:%s', %s, %i, %s, %i)")
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, %i, %s, %i")
|
||||
% constr->internalAlignmentTypeToString() % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2
|
||||
% constr->InternalAlignmentIndex);
|
||||
}
|
||||
else if (constr->AlignmentType == BSplineKnotPoint) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, 1, %s, %i)")
|
||||
boost::format("Sketcher.Constraint('InternalAlignment:%s', %s, 1, %s, %i")
|
||||
% constr->internalAlignmentTypeToString() % geoId1 % geoId2
|
||||
% constr->InternalAlignmentIndex);
|
||||
}
|
||||
@@ -513,21 +512,21 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->Second == GeoEnum::GeoUndef) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Distance', %s, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Distance', %s, %f")
|
||||
% geoId1 % constr->getValue());
|
||||
}
|
||||
else if (constr->FirstPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Distance', %s, %s, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Distance', %s, %s, %f")
|
||||
% geoId1 % geoId2 % constr->getValue());
|
||||
}
|
||||
else if (constr->SecondPos == Sketcher::PointPos::none) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Distance', %s, %i, %s, %f)") % geoId1
|
||||
boost::format("Sketcher.Constraint('Distance', %s, %i, %s, %f") % geoId1
|
||||
% static_cast<int>(constr->FirstPos) % geoId2 % constr->getValue());
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Distance', %s, %i, %s, %i, %f)")
|
||||
boost::format("Sketcher.Constraint('Distance', %s, %i, %s, %i, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % constr->getValue());
|
||||
}
|
||||
@@ -538,24 +537,24 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
std::string& geoId3) {
|
||||
if (constr->Second == GeoEnum::GeoUndef) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Angle', %s, %f)")
|
||||
% geoId1 % constr->getValue());
|
||||
return boost::str(boost::format("Sketcher.Constraint('Angle', %s, %f") % geoId1
|
||||
% constr->getValue());
|
||||
}
|
||||
else if (constr->Third == GeoEnum::GeoUndef) {
|
||||
if (constr->SecondPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Angle', %s, %s, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('Angle', %s, %s, %f")
|
||||
% geoId1 % geoId2 % constr->getValue());
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Angle', %s, %i, %s, %i, %f)")
|
||||
boost::format("Sketcher.Constraint('Angle', %s, %i, %s, %i, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % constr->getValue());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('AngleViaPoint', %s, %s, %s, %i, %f)")
|
||||
boost::format("Sketcher.Constraint('AngleViaPoint', %s, %s, %s, %i, %f")
|
||||
% geoId1 % geoId2 % geoId3 % static_cast<int>(constr->ThirdPos)
|
||||
% constr->getValue());
|
||||
}
|
||||
@@ -566,17 +565,17 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->Second == GeoEnum::GeoUndef) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceX', %s, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceX', %s, %f")
|
||||
% geoId1 % constr->getValue());
|
||||
}
|
||||
else if (constr->SecondPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceX', %s, %i, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceX', %s, %i, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos)
|
||||
% constr->getValue());
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('DistanceX', %s, %i, %s, %i, %f)")
|
||||
boost::format("Sketcher.Constraint('DistanceX', %s, %i, %s, %i, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % constr->getValue());
|
||||
}
|
||||
@@ -587,17 +586,17 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
if (constr->Second == GeoEnum::GeoUndef) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceY', %s, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceY', %s, %f")
|
||||
% geoId1 % constr->getValue());
|
||||
}
|
||||
else if (constr->SecondPos == Sketcher::PointPos::none) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceY', %s, %i, %f)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('DistanceY', %s, %i, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos)
|
||||
% constr->getValue());
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('DistanceY', %s, %i, %s, %i, %f)")
|
||||
boost::format("Sketcher.Constraint('DistanceY', %s, %i, %s, %i, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % constr->getValue());
|
||||
}
|
||||
@@ -607,7 +606,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
[[maybe_unused]] std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Radius', %s, %f)") % geoId1
|
||||
return boost::str(boost::format("Sketcher.Constraint('Radius', %s, %f") % geoId1
|
||||
% constr->getValue());
|
||||
}},
|
||||
{Sketcher::Diameter,
|
||||
@@ -615,7 +614,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
[[maybe_unused]] std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Diameter', %s, %f)") % geoId1
|
||||
return boost::str(boost::format("Sketcher.Constraint('Diameter', %s, %f") % geoId1
|
||||
% constr->getValue());
|
||||
}},
|
||||
{Sketcher::Weight,
|
||||
@@ -623,7 +622,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
[[maybe_unused]] std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('Weight', %s, %f)") % geoId1
|
||||
return boost::str(boost::format("Sketcher.Constraint('Weight', %s, %f") % geoId1
|
||||
% constr->getValue());
|
||||
}},
|
||||
{Sketcher::PointOnObject,
|
||||
@@ -631,7 +630,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId1,
|
||||
std::string& geoId2,
|
||||
[[maybe_unused]] std::string& geoId3) {
|
||||
return boost::str(boost::format("Sketcher.Constraint('PointOnObject', %s, %i, %s)")
|
||||
return boost::str(boost::format("Sketcher.Constraint('PointOnObject', %s, %i, %s")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2);
|
||||
}},
|
||||
{Sketcher::Symmetric,
|
||||
@@ -641,13 +640,13 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId3) {
|
||||
if (constr->ThirdPos == Sketcher::PointPos::none) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Symmetric', %s, %i, %s, %i, %s)")
|
||||
boost::format("Sketcher.Constraint('Symmetric', %s, %i, %s, %i, %s")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % geoId3);
|
||||
}
|
||||
else {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('Symmetric', %s, %i, %s, %i, %s, %i)")
|
||||
boost::format("Sketcher.Constraint('Symmetric', %s, %i, %s, %i, %s, %i")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % geoId3
|
||||
% static_cast<int>(constr->ThirdPos));
|
||||
@@ -659,7 +658,7 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
std::string& geoId2,
|
||||
std::string& geoId3) {
|
||||
return boost::str(
|
||||
boost::format("Sketcher.Constraint('SnellsLaw', %s, %i, %s, %i, %s, %f)")
|
||||
boost::format("Sketcher.Constraint('SnellsLaw', %s, %i, %s, %i, %s, %f")
|
||||
% geoId1 % static_cast<int>(constr->FirstPos) % geoId2
|
||||
% static_cast<int>(constr->SecondPos) % geoId3 % constr->getValue());
|
||||
}},
|
||||
@@ -672,8 +671,19 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint, Geo
|
||||
}
|
||||
|
||||
auto creator = result->second;
|
||||
std::string resultStr = creator(constraint, geoId1, geoId2, geoId3);
|
||||
|
||||
return creator(constraint, geoId1, geoId2, geoId3);
|
||||
if (!constraint->isActive || !constraint->isDriving) {
|
||||
std::string active = constraint->isActive ? "True" : "False";
|
||||
std::string driving = constraint->isDriving ? "True" : "False";
|
||||
resultStr += ", " + active;
|
||||
if (constraint->isDimensional()) {
|
||||
resultStr += ", " + driving;
|
||||
}
|
||||
}
|
||||
resultStr += ")";
|
||||
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
std::vector<std::string> PythonConverter::multiLine(std::string&& singlestring)
|
||||
|
||||
Reference in New Issue
Block a user