Sketcher: Responsivity tweaks and AngleViaPoint Constraint

Solver iteration limit independent of system size (reduces hangs when
solver fails to converge).
Repaint() instead of update() to force render for every movePoint.

Sketcher: New Constraint AngleViaPoint

* Adding generic CalculateNormal() method
* Reconfiguration of GCS geometry classes: adding a base class "Curve",
that has a pure virtual function CalculateNormal().
* Initial inplementation of the new function.
* adding Vector2D class (I wanted to reuse the existing, but got wierd
compile errors, so implemented a new one... TODO.)
* Adding redirection support into GCS shapes. Adding a Copy method to
GCS::Curve.
* Automatic point-on-object
* Angle precalculation: when AngleViaPoint is added, angle is properly calculated based on
existing geometry.
* Added tangency-via-point using one.
* Implemented placement of tangency-via-point icon in 3d view. Also
affected is the placement of point-on-object icon (since it is very
similar code, it is now shared with tangency-via-point)
* Placement and moving of angle datum
Functions: calculateAngleViaPoint, isPointOnCurve,
calculateConstraintError exposed to python
* Endpoint tangency: All endpoint-to-endpoint and endpoint-to-curve tangency now works
through AngleViaPoint constraint and obsolete code clean up (most procedures
addConstraintTangentXXX2YYY)
This commit is contained in:
DeepSOIC
2014-11-01 22:17:46 +04:00
committed by wmayer
parent 948eb8e636
commit 865ecca262
17 changed files with 1497 additions and 692 deletions

View File

@@ -52,9 +52,12 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
int ThirdIndex = Constraint::GeoUndef;
int ThirdPos = none;
double Value = 0;
int intArg1, intArg2, intArg3, intArg4, intArg5;
// Note: In Python 2.x PyArg_ParseTuple prints a warning if a float is given but an integer is expected.
// This means we must use a PyObject and check afterwards if it's a float or integer.
PyObject* index_or_value;
PyObject* oNumArg4;
PyObject* oNumArg5;
int any_index;
// ConstraintType, GeoIndex
@@ -237,10 +240,10 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "siiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &index_or_value)) {
if (PyArg_ParseTuple(args, "siiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &oNumArg4)) {
// Value, ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2
if (PyInt_Check(index_or_value)) {
SecondPos = PyInt_AsLong(index_or_value);
if (PyInt_Check(oNumArg4)) {
intArg4 = PyInt_AsLong(oNumArg4);
bool valid = false;
if (strcmp("Coincident", ConstraintType) == 0) {
this->getConstraintPtr()->Type = Coincident;
@@ -262,22 +265,33 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
this->getConstraintPtr()->Type = Tangent;
valid = true;
}
else if (strcmp("TangentViaPoint", ConstraintType) == 0) {
this->getConstraintPtr()->Type = Tangent;
//valid = true;//non-standard assignment
this->getConstraintPtr()->First = intArg1;
this->getConstraintPtr()->FirstPos = Sketcher::none;
this->getConstraintPtr()->Second = intArg2;
this->getConstraintPtr()->SecondPos = Sketcher::none;
this->getConstraintPtr()->Third = intArg3;
this->getConstraintPtr()->ThirdPos = (Sketcher::PointPos) intArg4;
return 0;
}
if (valid) {
this->getConstraintPtr()->First = FirstIndex;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
this->getConstraintPtr()->Second = SecondIndex;
this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
this->getConstraintPtr()->First = intArg1;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2;
this->getConstraintPtr()->Second = intArg3;
this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) intArg4;
return 0;
}
}
// ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, Value
if (PyNumber_Check(index_or_value)) { // can be float or int
Value = PyFloat_AsDouble(index_or_value);
if (PyNumber_Check(oNumArg4)) { // can be float or int
Value = PyFloat_AsDouble(oNumArg4);
if (strcmp("Distance",ConstraintType) == 0 ) {
this->getConstraintPtr()->Type = Distance;
this->getConstraintPtr()->First = FirstIndex;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
this->getConstraintPtr()->Second = SecondIndex;
this->getConstraintPtr()->First = intArg1;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2;
this->getConstraintPtr()->Second = intArg3;
this->getConstraintPtr()->Value = Value;
return 0;
}
@@ -285,23 +299,23 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "siiiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &SecondPos, &index_or_value)) {
if (PyArg_ParseTuple(args, "siiiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &intArg4, &oNumArg5)) {
// ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3
if (PyInt_Check(index_or_value)) {
ThirdIndex = PyInt_AsLong(index_or_value);
if (PyInt_Check(oNumArg5)) {
intArg5 = PyInt_AsLong(oNumArg5);
if (strcmp("Symmetric",ConstraintType) == 0 ) {
this->getConstraintPtr()->Type = Symmetric;
this->getConstraintPtr()->First = FirstIndex;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
this->getConstraintPtr()->Second = SecondIndex;
this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
this->getConstraintPtr()->Third = ThirdIndex;
this->getConstraintPtr()->First = intArg1;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2;
this->getConstraintPtr()->Second = intArg3;
this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) intArg4;
this->getConstraintPtr()->Third = intArg5;
return 0;
}
}
// ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, Value
if (PyNumber_Check(index_or_value)) { // can be float or int
Value = PyFloat_AsDouble(index_or_value);
if (PyNumber_Check(oNumArg5)) { // can be float or int
Value = PyFloat_AsDouble(oNumArg5);
bool valid=false;
if (strcmp("Distance",ConstraintType) == 0 ) {
this->getConstraintPtr()->Type = Distance;
@@ -316,19 +330,36 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
valid = true;
}
else if (strcmp("Angle",ConstraintType) == 0 ) {
if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) {
Base::Quantity q = *(static_cast<Base::QuantityPy*>(index_or_value)->getQuantityPtr());
if (PyObject_TypeCheck(oNumArg5, &(Base::QuantityPy::Type))) {
Base::Quantity q = *(static_cast<Base::QuantityPy*>(oNumArg5)->getQuantityPtr());
if (q.getUnit() == Base::Unit::Angle)
Value = q.getValueAs(Base::Quantity::Radian);
}
this->getConstraintPtr()->Type = Angle;
valid = true;
}
else if (strcmp("AngleViaPoint",ConstraintType) == 0 ) {
if (PyObject_TypeCheck(oNumArg5, &(Base::QuantityPy::Type))) {
Base::Quantity q = *(static_cast<Base::QuantityPy*>(oNumArg5)->getQuantityPtr());
if (q.getUnit() == Base::Unit::Angle)
Value = q.getValueAs(Base::Quantity::Radian);
}
this->getConstraintPtr()->Type = Angle;
//valid = true;//non-standard assignment
this->getConstraintPtr()->First = intArg1;
this->getConstraintPtr()->FirstPos = Sketcher::none;
this->getConstraintPtr()->Second = intArg2; //let's goof up all the terminology =)
this->getConstraintPtr()->SecondPos = Sketcher::none;
this->getConstraintPtr()->Third = intArg3;
this->getConstraintPtr()->ThirdPos = (Sketcher::PointPos) intArg4;
this->getConstraintPtr()->Value = Value;
return 0;
}
if (valid) {
this->getConstraintPtr()->First = FirstIndex;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
this->getConstraintPtr()->Second = SecondIndex;
this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
this->getConstraintPtr()->First = intArg1;
this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2;
this->getConstraintPtr()->Second = intArg3;
this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) intArg4;
this->getConstraintPtr()->Value = Value;
return 0;
}
@@ -375,9 +406,19 @@ std::string ConstraintPy::representation(void) const
case Horizontal : result << "'Horizontal' (" << getConstraintPtr()->First << ")>";break;
case Vertical : result << "'Vertical' (" << getConstraintPtr()->First << ")>";break;
case Parallel : result << "'Parallel'>";break;
case Tangent : result << "'Tangent'>";break;
case Tangent :
if (this->getConstraintPtr()->Third == Constraint::GeoUndef)
result << "'Tangent'>";
else
result << "'TangentViaPoint'>";
break;
case Distance : result << "'Distance'>";break;
case Angle : result << "'Angle'>";break;
case Angle :
if (this->getConstraintPtr()->Third == Constraint::GeoUndef)
result << "'Angle'>";
else
result << "'AngleViaPoint'>";
break;
case InternalAlignment :
switch(this->getConstraintPtr()->AlignmentType) {
case Undef : result << "'InternalAlignment:Undef'>";break;