Materials: Set array quantity format (#21647)
* Materials: Set array quantity format When setting quantity formats, the default format is not actually the default. Instead fixed format is, which causes issues for very small and very large values. This was fixed for C++ but arrays created in Python were not setting the format correctly. * Apply suggestions from code review Co-authored-by: Benjamin Nauck <benjamin@nauck.se>
This commit is contained in:
@@ -159,7 +159,9 @@ PyObject* Array2DPy::setValue(PyObject* args)
|
||||
if (PyArg_ParseTuple(args, "iiO!", &row, &column, &PyUnicode_Type, &valueObj)) {
|
||||
Py::String item(valueObj);
|
||||
try {
|
||||
QVariant variant = QVariant::fromValue(Base::Quantity::parse(item.as_string()));
|
||||
auto quantity = Base::Quantity::parse(item.as_string());
|
||||
quantity.setFormat(MaterialValue::getQuantityFormat());
|
||||
QVariant variant = QVariant::fromValue(quantity);
|
||||
getArray2DPtr()->setValue(row, column, variant);
|
||||
}
|
||||
catch (const InvalidIndex&) {
|
||||
|
||||
@@ -163,10 +163,16 @@ PyObject* Array3DPy::setDepthValue(PyObject* args)
|
||||
if (PyArg_ParseTuple(args, "iO!", &depth, &PyUnicode_Type, &valueObj)) {
|
||||
Py::String item(valueObj);
|
||||
try {
|
||||
getArray3DPtr()->setDepthValue(depth, Base::Quantity::parse(item.as_string()));
|
||||
auto quantity = Base::Quantity::parse(item.as_string());
|
||||
quantity.setFormat(MaterialValue::getQuantityFormat());
|
||||
getArray3DPtr()->setDepthValue(depth, quantity);
|
||||
}
|
||||
catch (const InvalidIndex&) {
|
||||
PyErr_SetString(PyExc_IndexError, "Invalid array index");
|
||||
catch (const Base::ParserError& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
catch (const InvalidIndex& e) {
|
||||
PyErr_SetString(PyExc_IndexError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
Py_Return;
|
||||
@@ -185,10 +191,16 @@ PyObject* Array3DPy::setValue(PyObject* args)
|
||||
if (PyArg_ParseTuple(args, "iiiO!", &depth, &row, &column, &PyUnicode_Type, &valueObj)) {
|
||||
Py::String item(valueObj);
|
||||
try {
|
||||
getArray3DPtr()->setValue(depth, row, column, Base::Quantity::parse(item.as_string()));
|
||||
auto quantity = Base::Quantity::parse(item.as_string());
|
||||
quantity.setFormat(MaterialValue::getQuantityFormat());
|
||||
getArray3DPtr()->setValue(depth, row, column, quantity);
|
||||
}
|
||||
catch (const InvalidIndex&) {
|
||||
PyErr_SetString(PyExc_IndexError, "Invalid array index");
|
||||
catch (const Base::ParserError& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
catch (const InvalidIndex& e) {
|
||||
PyErr_SetString(PyExc_IndexError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
Py_Return;
|
||||
|
||||
Reference in New Issue
Block a user