+ fixes #0001703: Spreadsheet PropertyController
This commit is contained in:
parent
0eec1d8e49
commit
3c8a00dfec
|
@ -292,20 +292,91 @@ PyObject* SketchObjectPy::setDatum(PyObject *args)
|
||||||
int Index;
|
int Index;
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
Base::Quantity Quantity;
|
Base::Quantity Quantity;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// handle (int,Quantity)
|
||||||
if (PyArg_ParseTuple(args,"iO!", &Index, &(Base::QuantityPy::Type), &object)) {
|
if (PyArg_ParseTuple(args,"iO!", &Index, &(Base::QuantityPy::Type), &object)) {
|
||||||
Quantity = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
|
Quantity = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
|
||||||
if (Quantity.getUnit() == Base::Unit::Angle)
|
if (Quantity.getUnit() == Base::Unit::Angle) {
|
||||||
//Datum = Quantity.getValueAs(Base::Quantity::Radian);
|
|
||||||
Datum = Base::toRadians<double>(Quantity.getValue());
|
Datum = Base::toRadians<double>(Quantity.getValue());
|
||||||
else
|
break;
|
||||||
Datum = Quantity.getValue();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_Clear();
|
Datum = Quantity.getValue();
|
||||||
if (!PyArg_ParseTuple(args, "id", &Index, &Datum))
|
break;
|
||||||
return 0;
|
|
||||||
Quantity.setValue(Datum);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle (int,double)
|
||||||
|
PyErr_Clear();
|
||||||
|
if (PyArg_ParseTuple(args, "id", &Index, &Datum)) {
|
||||||
|
Quantity.setValue(Datum);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle (string,Quantity)
|
||||||
|
char* constrName;
|
||||||
|
PyErr_Clear();
|
||||||
|
if (PyArg_ParseTuple(args,"sO!", &constrName, &(Base::QuantityPy::Type), &object)) {
|
||||||
|
Quantity = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
|
||||||
|
if (Quantity.getUnit() == Base::Unit::Angle) {
|
||||||
|
Datum = Base::toRadians<double>(Quantity.getValue());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Datum = Quantity.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
Index = -1;
|
||||||
|
const std::vector<Constraint*>& vals = this->getSketchObjectPtr()->Constraints.getValues();
|
||||||
|
for (std::vector<Constraint*>::const_iterator it = vals.begin(); it != vals.end(); ++it, ++i) {
|
||||||
|
if ((*it)->Name == constrName) {
|
||||||
|
Index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Index >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::stringstream str;
|
||||||
|
str << "Invalid constraint name: '" << constrName << "'";
|
||||||
|
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle (string,double)
|
||||||
|
PyErr_Clear();
|
||||||
|
if (PyArg_ParseTuple(args, "sd", &constrName, &Datum)) {
|
||||||
|
Quantity.setValue(Datum);
|
||||||
|
int i = 0;
|
||||||
|
Index = -1;
|
||||||
|
const std::vector<Constraint*>& vals = this->getSketchObjectPtr()->Constraints.getValues();
|
||||||
|
for (std::vector<Constraint*>::const_iterator it = vals.begin(); it != vals.end(); ++it, ++i) {
|
||||||
|
if ((*it)->Name == constrName) {
|
||||||
|
Index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Index >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::stringstream str;
|
||||||
|
str << "Invalid constraint name: '" << constrName << "'";
|
||||||
|
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// error handling
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Wrong arguments");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (false);
|
||||||
|
|
||||||
int err=this->getSketchObjectPtr()->setDatum(Index, Datum);
|
int err=this->getSketchObjectPtr()->setDatum(Index, Datum);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -685,6 +685,7 @@ class SpreadsheetPropertyController:
|
||||||
else:
|
else:
|
||||||
if Draft.getType(obj.TargetObject) == "Sketch":
|
if Draft.getType(obj.TargetObject) == "Sketch":
|
||||||
if obj.TargetProperty.isdigit():
|
if obj.TargetProperty.isdigit():
|
||||||
|
# try setting by constraint id
|
||||||
try:
|
try:
|
||||||
c = int(obj.TargetProperty)
|
c = int(obj.TargetProperty)
|
||||||
obj.TargetObject.setDatum(c,float(value))
|
obj.TargetObject.setDatum(c,float(value))
|
||||||
|
@ -692,6 +693,14 @@ class SpreadsheetPropertyController:
|
||||||
if DEBUG: print "setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
|
if DEBUG: print "setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
|
||||||
except:
|
except:
|
||||||
if DEBUG: print "unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
|
if DEBUG: print "unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
|
||||||
|
else:
|
||||||
|
# try setting by constraint name
|
||||||
|
try:
|
||||||
|
obj.TargetObject.setDatum(obj.TargetProperty,float(value))
|
||||||
|
FreeCAD.ActiveDocument.recompute()
|
||||||
|
if DEBUG: print "setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
|
||||||
|
except:
|
||||||
|
if DEBUG: print "unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
|
||||||
|
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user