Materials: External Modules Part 1
Refactored code to support local and external material sources This is the first PR in a series to support external modules. External modules allow materials to be stored in external data sources such as databases or web services. No new functionality is introduced in this PR, rather it is a refactoring of code that will allow for changes to be introduced in future PRs. Minor performance improvements have also been made in the model and material managers. The Python API has been enhanced for many data types to allow for modification within Python.
This commit is contained in:
committed by
Chris Hennes
parent
3c4977a2d4
commit
00c57a9d08
@@ -44,7 +44,7 @@ using namespace Materials;
|
||||
std::string Array2DPy::representation() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "<Array2D object at " << getMaterial2DArrayPtr() << ">";
|
||||
str << "<Array2D object at " << getArray2DPtr() << ">";
|
||||
|
||||
return str.str();
|
||||
}
|
||||
@@ -52,7 +52,7 @@ std::string Array2DPy::representation() const
|
||||
PyObject* Array2DPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// never create such objects with the constructor
|
||||
return new Array2DPy(new Material2DArray());
|
||||
return new Array2DPy(new Array2D());
|
||||
}
|
||||
|
||||
// constructor method
|
||||
@@ -65,7 +65,7 @@ Py::List Array2DPy::getArray() const
|
||||
{
|
||||
Py::List list;
|
||||
|
||||
auto array = getMaterial2DArrayPtr()->getArray();
|
||||
auto array = getArray2DPtr()->getArray();
|
||||
|
||||
for (auto& row : array) {
|
||||
Py::List rowList;
|
||||
@@ -81,14 +81,29 @@ Py::List Array2DPy::getArray() const
|
||||
return list;
|
||||
}
|
||||
|
||||
Py::Long Array2DPy::getDimensions() const
|
||||
{
|
||||
return Py::Long(2);
|
||||
}
|
||||
|
||||
Py::Long Array2DPy::getRows() const
|
||||
{
|
||||
return Py::Long(getMaterial2DArrayPtr()->rows());
|
||||
return Py::Long(getArray2DPtr()->rows());
|
||||
}
|
||||
|
||||
void Array2DPy::setRows(Py::Long arg)
|
||||
{
|
||||
getArray2DPtr()->setRows(arg);
|
||||
}
|
||||
|
||||
Py::Long Array2DPy::getColumns() const
|
||||
{
|
||||
return Py::Long(getMaterial2DArrayPtr()->columns());
|
||||
return Py::Long(getArray2DPtr()->columns());
|
||||
}
|
||||
|
||||
void Array2DPy::setColumns(Py::Long arg)
|
||||
{
|
||||
getArray2DPtr()->setColumns(arg);
|
||||
}
|
||||
|
||||
PyObject* Array2DPy::getRow(PyObject* args)
|
||||
@@ -101,7 +116,7 @@ PyObject* Array2DPy::getRow(PyObject* args)
|
||||
try {
|
||||
Py::List list;
|
||||
|
||||
auto arrayRow = getMaterial2DArrayPtr()->getRow(row);
|
||||
auto arrayRow = getArray2DPtr()->getRow(row);
|
||||
for (auto& column : *arrayRow) {
|
||||
auto quantity =
|
||||
new Base::QuantityPy(new Base::Quantity(column.value<Base::Quantity>()));
|
||||
@@ -126,7 +141,7 @@ PyObject* Array2DPy::getValue(PyObject* args)
|
||||
}
|
||||
|
||||
try {
|
||||
auto value = getMaterial2DArrayPtr()->getValue(row, column);
|
||||
auto value = getArray2DPtr()->getValue(row, column);
|
||||
return new Base::QuantityPy(new Base::Quantity(value.value<Base::Quantity>()));
|
||||
}
|
||||
catch (const InvalidIndex&) {
|
||||
@@ -136,6 +151,28 @@ PyObject* Array2DPy::getValue(PyObject* args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* Array2DPy::setValue(PyObject* args)
|
||||
{
|
||||
int row;
|
||||
int column;
|
||||
PyObject* valueObj;
|
||||
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()));
|
||||
getArray2DPtr()->setValue(row, column, variant);
|
||||
}
|
||||
catch (const InvalidIndex&) {
|
||||
PyErr_SetString(PyExc_IndexError, "Invalid array index");
|
||||
return nullptr;
|
||||
}
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Expected (integer, integer, string) arguments");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* Array2DPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user