OpticConstraints: Adding Snell's law

Fix AngleViaPoint to support new derivative calculation technique.

OpticConstraints: Adding Snell's law. Fix AngleViaPoint to support new derivative calculation technique.

Snell's law constraint added to GCS, but not yet exposed and cannot be
tested.
Since the way CalculateNormal() returns derivatives had changed,
AngleViaPoint constraint needed modifications. Nothing serious.

OpticConstraints: SnellsLaw progress

Addable through python. Fix math. Some quick-and-dirty visual stuff to
get rid of hangs and to see the constraint in action.

OpticConstraints: SnellsLaw: flipping logic fix

OpticConstraints: SnellsLaw progress

Added toolbar button. Allowed editing a datum by doubleclick. New error
message approach during constraint creation.

OpticConstraints: SnellsLaw

OpticConstraints: SnellsLaw: list label improvement

OpticConstraints: SnellsLaw: fix after rebase

OpticConstraints: SnellsLaw: expose helper constraints

Snell's law internally is made of three constraints: point-on-object,
coincident and the Snell's sin/sin. They were all buried under one UI
constraint. Exposing them allows to construct reflection and
birefringence on the point (attempting to do so used to result in
redundant constraints and was often not functional at all).
This commit breaks compatibility with older files.

OpticConstraints: SnellsLaw: small refactor of math

Placing the duplicated code of error and gradient calculation into a
private method.

OpticConstraints: SnellsLaw: fix datum edit unit

OpticConstraints: SnellsLaw: fix datum edit bug

After previous fix, the dimensionless value was not accepted (the
constraint's value did not change, the changes were ignored).
This commit is contained in:
DeepSOIC
2014-12-11 23:30:58 +03:00
committed by wmayer
parent 88578489fb
commit cf4e9df78d
16 changed files with 510 additions and 57 deletions

View File

@@ -378,17 +378,34 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "siiiiii", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &SecondPos, &ThirdIndex, &ThirdPos)) {
// ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3, PosIndex3
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()->ThirdPos = (Sketcher::PointPos) ThirdPos;
return 0;
if (PyArg_ParseTuple(args, "siiiiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &SecondPos, &ThirdIndex, &index_or_value)) {
if (PyInt_Check(index_or_value)) {
ThirdPos = PyInt_AsLong(index_or_value);
// ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3, PosIndex3
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()->ThirdPos = (Sketcher::PointPos) ThirdPos;
return 0;
}
}
if (PyNumber_Check(index_or_value)) { // can be float or int
Value = PyFloat_AsDouble(index_or_value);
if (strcmp("SnellsLaw",ConstraintType) == 0 ) {
this->getConstraintPtr()->Type = SnellsLaw;
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()->ThirdPos = none;
this->getConstraintPtr()->Value = Value;
return 0;
}
}
}
@@ -436,6 +453,7 @@ std::string ConstraintPy::representation(void) const
else
result << "'AngleViaPoint'>";
break;
case SnellsLaw : result << "'SnellsLaw'>"; break;
case InternalAlignment :
switch(this->getConstraintPtr()->AlignmentType) {
case Undef : result << "'InternalAlignment:Undef'>";break;