1
/***************************************************************************
2
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
4
* This file is part of FreeCAD. *
6
* FreeCAD is free software: you can redistribute it and/or modify it *
7
* under the terms of the GNU Lesser General Public License as *
8
* published by the Free Software Foundation, either version 2.1 of the *
9
* License, or (at your option) any later version. *
11
* FreeCAD is distributed in the hope that it will be useful, but *
12
* WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
* Lesser General Public License for more details. *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with FreeCAD. If not, see *
18
* <https://www.gnu.org/licenses/>. *
20
**************************************************************************/
22
#include "PreCompiled.h"
27
#include <Base/Quantity.h>
28
#include <Base/QuantityPy.h>
29
#include <CXX/Objects.hxx>
30
#include <Gui/MetaTypes.h>
33
#include "Exceptions.h"
35
#include "ModelLibrary.h"
36
#include "ModelPropertyPy.h"
37
#include "ModelUuids.h"
39
#include "Array3DPy.cpp"
41
using namespace Materials;
43
// returns a string which represents the object e.g. when printed in python
44
std::string Array3DPy::representation() const
46
std::stringstream str;
47
str << "<Array3D object at " << getMaterial3DArrayPtr() << ">";
52
PyObject* Array3DPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
54
// never create such objects with the constructor
55
return new Array3DPy(new Material3DArray());
59
int Array3DPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
64
Py::List Array3DPy::getArray() const
67
auto array = getMaterial3DArrayPtr()->getArray();
69
for (auto& depth : array) {
71
for (auto& row : *std::get<1>(depth)) {
73
for (auto& column : *row) {
74
auto quantity = new Base::QuantityPy(new Base::Quantity(column));
75
rowList.append(Py::asObject(quantity));
78
depthList.append(rowList);
80
list.append(depthList);
86
Py::Int Array3DPy::getColumns() const
88
return Py::Int(getMaterial3DArrayPtr()->columns());
91
Py::Int Array3DPy::getDepth() const
93
return Py::Int(getMaterial3DArrayPtr()->depth());
96
PyObject* Array3DPy::getRows(PyObject* args)
98
int depth = getMaterial3DArrayPtr()->currentDepth();
99
if (!PyArg_ParseTuple(args, "|i", &depth)) {
103
return PyLong_FromLong(getMaterial3DArrayPtr()->rows(depth));
106
PyObject* Array3DPy::getValue(PyObject* args)
111
if (!PyArg_ParseTuple(args, "iii", &depth, &row, &column)) {
116
auto value = getMaterial3DArrayPtr()->getValue(depth, row, column);
117
return new Base::QuantityPy(new Base::Quantity(value));
119
catch (const InvalidIndex&) {
122
PyErr_SetString(PyExc_IndexError, "Invalid array index");
126
PyObject* Array3DPy::getDepthValue(PyObject* args)
129
if (!PyArg_ParseTuple(args, "i", &depth)) {
134
auto value = getMaterial3DArrayPtr()->getDepthValue(depth);
135
return new Base::QuantityPy(new Base::Quantity(value));
137
catch (const InvalidIndex&) {
140
PyErr_SetString(PyExc_IndexError, "Invalid array index");
144
PyObject* Array3DPy::getCustomAttributes(const char* /*attr*/) const
149
int Array3DPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)