FreeCAD

Форк
0
/
MeasurementPyImp.cpp 
225 строк · 6.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk>                 *
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
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <sstream>
26
#endif
27

28
#include <App/Application.h>
29
#include <App/Document.h>
30
#include <Base/GeometryPyCXX.h>
31

32
// inclusion of the generated files (generated out of SketchObjectSFPy.xml)
33
#include "MeasurementPy.h"
34
#include "MeasurementPy.cpp"
35

36

37
using namespace Measure;
38

39
// returns a string which represents the object e.g. when printed in python
40
std::string MeasurementPy::representation() const
41
{
42
    return "<Measure::Measurement>";
43
}
44

45
PyObject* MeasurementPy::PyMake(struct _typeobject*, PyObject*, PyObject*)  // Python wrapper
46
{
47
    // create a new instance of BoundBoxPy and the Twin object
48
    return new MeasurementPy(new Measurement);
49
}
50

51
// constructor method
52
int MeasurementPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
53
{
54
    return 0;
55
}
56

57
PyObject* MeasurementPy::addReference3D(PyObject* args)
58
{
59
    char* ObjectName;
60
    char* SubName;
61
    if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName, &SubName)) {
62
        return nullptr;
63
    }
64

65
    // get the target object for the external link
66
    App::DocumentObject* Obj = App::GetApplication().getActiveDocument()->getObject(ObjectName);
67
    if (!Obj) {
68
        std::stringstream str;
69
        str << ObjectName << "does not exist in the document";
70
        PyErr_SetString(PyExc_ValueError, str.str().c_str());
71
        return nullptr;
72
    }
73

74
    // add the external
75
    if (this->getMeasurementPtr()->addReference3D(Obj, SubName) < 0) {
76
        std::stringstream str;
77
        str << "Not able to add reference";
78
        PyErr_SetString(PyExc_ValueError, str.str().c_str());
79
        return nullptr;
80
    }
81

82
    Py_Return;
83
}
84

85
PyObject* MeasurementPy::has3DReferences(PyObject* args)
86
{
87
    PyObject* result = Py_False;
88
    if (!PyArg_ParseTuple(args, "")) {
89
        return nullptr;
90
    }
91

92
    if (getMeasurementPtr()->has3DReferences()) {
93
        result = Py_True;
94
    }
95

96
    Py_IncRef(result);
97
    return result;
98
}
99

100
PyObject* MeasurementPy::clear(PyObject* args)
101
{
102
    if (!PyArg_ParseTuple(args, "")) {
103
        return nullptr;
104
    }
105

106
    this->getMeasurementPtr()->clear();
107

108
    Py_Return;
109
}
110

111
PyObject* MeasurementPy::delta(PyObject* args)
112
{
113
    if (!PyArg_ParseTuple(args, "")) {
114
        return nullptr;
115
    }
116

117
    Py::Vector delta(this->getMeasurementPtr()->delta());
118

119
    return Py::new_reference_to(delta);
120
}
121

122
PyObject* MeasurementPy::length(PyObject* args)
123
{
124
    if (!PyArg_ParseTuple(args, "")) {
125
        return nullptr;
126
    }
127

128
    Py::Float length;
129
    length = this->getMeasurementPtr()->length();
130

131
    return Py::new_reference_to(length);
132
}
133

134
PyObject* MeasurementPy::lineLineDistance(PyObject* args)
135
{
136
    if (!PyArg_ParseTuple(args, "")) {
137
        return nullptr;
138
    }
139

140
    Py::Float length;
141
    length = this->getMeasurementPtr()->lineLineDistance();
142

143
    return Py::new_reference_to(length);
144
}
145

146
PyObject* MeasurementPy::planePlaneDistance(PyObject* args)
147
{
148
    if (!PyArg_ParseTuple(args, "")) {
149
        return nullptr;
150
    }
151

152
    Py::Float length;
153
    length = this->getMeasurementPtr()->planePlaneDistance();
154

155
    return Py::new_reference_to(length);
156
}
157

158
PyObject* MeasurementPy::volume(PyObject* args)
159
{
160
    if (!PyArg_ParseTuple(args, "")) {
161
        return nullptr;
162
    }
163

164
    Py::Float length;
165
    length = this->getMeasurementPtr()->volume();
166

167
    return Py::new_reference_to(length);
168
}
169

170
PyObject* MeasurementPy::area(PyObject* args)
171
{
172
    if (!PyArg_ParseTuple(args, "")) {
173
        return nullptr;
174
    }
175

176
    Py::Float length;
177
    length = this->getMeasurementPtr()->area();
178

179
    return Py::new_reference_to(length);
180
}
181

182
PyObject* MeasurementPy::radius(PyObject* args)
183
{
184
    if (!PyArg_ParseTuple(args, "")) {
185
        return nullptr;
186
    }
187

188
    Py::Float radius;
189
    radius = this->getMeasurementPtr()->radius();
190

191
    return Py::new_reference_to(radius);
192
}
193

194
PyObject* MeasurementPy::angle(PyObject* args)
195
{
196
    if (!PyArg_ParseTuple(args, "")) {
197
        return nullptr;
198
    }
199

200
    Py::Float angle;
201
    angle = this->getMeasurementPtr()->angle();
202

203
    return Py::new_reference_to(angle);
204
}
205

206
PyObject* MeasurementPy::com(PyObject* args)
207
{
208
    if (!PyArg_ParseTuple(args, "")) {
209
        return nullptr;
210
    }
211

212
    Py::Vector com(this->getMeasurementPtr()->massCenter());
213

214
    return Py::new_reference_to(com);
215
}
216

217
PyObject* MeasurementPy::getCustomAttributes(const char* /*attr*/) const
218
{
219
    return nullptr;
220
}
221

222
int MeasurementPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
223
{
224
    return 0;
225
}
226

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.