Debian Codegraph @

src/App/GeoFeaturePyImp.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2016 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 // inclusion of the generated files (generated out of GeoFeaturePy.xml)
24 #include "GeoFeaturePy.h"
25 #include "GeoFeaturePy.cpp"
26 #include <Base/PlacementPy.h>
27 #include <CXX/Objects.hxx>
28
29 using namespace App;
30
31 // returns a string which represents the object e.g. when printed in python
32 std::string GeoFeaturePy::representation() const
33 {
34 return {"<GeoFeature object>"};
35 }
36
37 PyObject* GeoFeaturePy::getPaths(PyObject* /*args*/)
38 {
39 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
40 return nullptr;
41 }
42
43 PyObject* GeoFeaturePy::getGlobalPlacement(PyObject* args)
44 {
45
46 if (!PyArg_ParseTuple(args, "")) {
47 return nullptr;
48 }
49
50 try {
51 Base::Placement p = static_cast<GeoFeature*>(getDocumentObjectPtr())->globalPlacement();
52 return new Base::PlacementPy(new Base::Placement(p));
53 }
54 catch (const Base::Exception& e) {
55 throw Py::RuntimeError(e.what());
56 }
57 }
58
59 PyObject* GeoFeaturePy::getGlobalPlacementOf(PyObject* args)
60 {
61
62 PyObject* pyTargetObj {nullptr};
63 PyObject* pyRootObj {nullptr};
64 char* pname {nullptr};
65
66 if (!PyArg_ParseTuple(args, "O!O!s",
67 &DocumentObjectPy::Type,
68 &pyTargetObj,
69 &DocumentObjectPy::Type,
70 &pyRootObj,
71 &pname)) {
72 return nullptr;
73 }
74 auto* targetObj = static_cast<App::DocumentObjectPy*>(pyTargetObj)->getDocumentObjectPtr();
75 auto* rootObj = static_cast<App::DocumentObjectPy*>(pyRootObj)->getDocumentObjectPtr();
76
77 try {
78 Base::Placement p = GeoFeature::getGlobalPlacement(targetObj, rootObj, pname);
79 return new Base::PlacementPy(new Base::Placement(p));
80 }
81 catch (const Base::Exception& e) {
82 throw Py::RuntimeError(e.what());
83 }
84 }
85
86 PyObject* GeoFeaturePy::getPropertyNameOfGeometry(PyObject* args)
87 {
88 if (!PyArg_ParseTuple(args, "")) {
89 return nullptr;
90 }
91
92 GeoFeature* object = this->getGeoFeaturePtr();
93 const PropertyComplexGeoData* prop = object->getPropertyOfGeometry();
94 const char* name = prop ? prop->getName() : nullptr;
95 if (Property::isValidName(name)) {
96 return Py::new_reference_to(Py::String(std::string(name)));
97 }
98 return Py::new_reference_to(Py::None());
99 }
100
101 PyObject* GeoFeaturePy::getPropertyOfGeometry(PyObject* args)
102 {
103 if (!PyArg_ParseTuple(args, "")) {
104 return nullptr;
105 }
106
107 GeoFeature* object = this->getGeoFeaturePtr();
108 const PropertyComplexGeoData* prop = object->getPropertyOfGeometry();
109 if (prop) {
110 return const_cast<PropertyComplexGeoData*>(prop)->getPyObject();
111 }
112 return Py::new_reference_to(Py::None());
113 }
114
115 PyObject* GeoFeaturePy::getCustomAttributes(const char* /*attr*/) const
116 {
117 return nullptr;
118 }
119
120 int GeoFeaturePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
121 {
122 return 0;
123 }
124
125 Py::String GeoFeaturePy::getElementMapVersion() const
126 {
127 return Py::String(
128 getGeoFeaturePtr()->getElementMapVersion(getGeoFeaturePtr()->getPropertyOfGeometry()));
129 }