| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2023 David Friedli <[email protected]> * |
| 3 |
* Copyright (c) 2023 Wandererfan <[email protected]> * |
| 4 |
* * |
| 5 |
* This file is part of FreeCAD. * |
| 6 |
* * |
| 7 |
* FreeCAD is free software: you can redistribute it and/or modify it * |
| 8 |
* under the terms of the GNU Lesser General Public License as * |
| 9 |
* published by the Free Software Foundation, either version 2.1 of the * |
| 10 |
* License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* FreeCAD is distributed in the hope that it will be useful, but * |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 15 |
* Lesser General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Lesser General Public * |
| 18 |
* License along with FreeCAD. If not, see * |
| 19 |
* <https://www.gnu.org/licenses/>. * |
| 20 |
* * |
| 21 |
**************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
// inclusion of the generated files (generated out of MeasureManagerPy.xml) |
| 25 |
#include "MeasureManagerPy.h" |
| 26 |
#include "MeasureManagerPy.cpp" |
| 27 |
|
| 28 |
|
| 29 |
using namespace App; |
| 30 |
|
| 31 |
|
| 32 |
// returns a string which represents the object e.g. when printed in python |
| 33 |
std::string MeasureManagerPy::representation() const |
| 34 |
{ |
| 35 |
return "<App::MeasureManager>"; |
| 36 |
} |
| 37 |
|
| 38 |
PyObject* MeasureManagerPy::getCustomAttributes(const char* /*attr*/) const |
| 39 |
{ |
| 40 |
return nullptr; |
| 41 |
} |
| 42 |
|
| 43 |
int MeasureManagerPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) |
| 44 |
{ |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
PyObject* MeasureManagerPy::addMeasureType(PyObject* args) |
| 50 |
{ |
| 51 |
PyObject* pyobj = Py_None; |
| 52 |
char *id, *label; |
| 53 |
|
| 54 |
if (!PyArg_ParseTuple(args, "ssO", &id, &label, &pyobj)) { |
| 55 |
return nullptr; |
| 56 |
} |
| 57 |
|
| 58 |
MeasureManager::addMeasureType( |
| 59 |
new App::MeasureType {id, label, "", nullptr, nullptr, true, pyobj}); |
| 60 |
|
| 61 |
Py_Return; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
PyObject* MeasureManagerPy::getMeasureTypes() |
| 66 |
{ |
| 67 |
Py::List types; |
| 68 |
for (auto& it : MeasureManager::getMeasureTypes()) { |
| 69 |
Py::Tuple type(3); |
| 70 |
type.setItem(0, Py::String(it->identifier)); |
| 71 |
type.setItem(1, Py::String(it->label)); |
| 72 |
type.setItem(2, Py::Object(it->pythonClass)); |
| 73 |
|
| 74 |
types.append(type); |
| 75 |
} |
| 76 |
|
| 77 |
return Py::new_reference_to(types); |
| 78 |
} |