FreeCAD

Форк
0
/
PointConstraintPyImp.cpp 
259 строк · 7.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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 <memory>
26
# include <Standard_Failure.hxx>
27
#endif
28

29
#include <Base/VectorPy.h>
30
#include <Base/PyWrapParseTupleAndKeywords.h>
31

32
#include "GeomPlate/PointConstraintPy.h"
33
#include "GeomPlate/PointConstraintPy.cpp"
34

35

36
using namespace Part;
37

38
PyObject *PointConstraintPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
39
{
40
    // create a new instance of PointConstraintPy
41
    return new PointConstraintPy(nullptr);
42
}
43

44
// constructor method
45
int PointConstraintPy::PyInit(PyObject* args, PyObject* kwds)
46
{
47
    PyObject *pt;
48
    int order = 0;
49
    double tolDist = 0.0001;
50

51
    static const std::array<const char *, 4> keywords {"Point", "Order", "TolDist", nullptr};
52
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!|id", keywords, &(Base::VectorPy::Type), &pt, &order,
53
                                             &tolDist)) {
54
        return -1;
55
    }
56

57
    try {
58
        std::unique_ptr<GeomPlate_PointConstraint> ptr;
59
        Base::Vector3d v = static_cast<Base::VectorPy*>(pt)->value();
60

61
        ptr = std::make_unique<GeomPlate_PointConstraint>(gp_Pnt(v.x, v.y, v.z), order, tolDist);
62
        setTwinPointer(ptr.release());
63

64
        return 0;
65
    }
66
    catch (const Standard_Failure& e) {
67
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
68
        return -1;
69
    }
70
}
71

72
// returns a string which represents the object e.g. when printed in python
73
std::string PointConstraintPy::representation() const
74
{
75
    return {"<GeomPlate_PointConstraint object>"};
76
}
77

78
PyObject* PointConstraintPy::setOrder(PyObject *args)
79
{
80
    int order;
81
    if (!PyArg_ParseTuple(args, "i", &order))
82
        return nullptr;
83

84
    try {
85
        getGeomPlate_PointConstraintPtr()->SetOrder(order);
86
        Py_Return;
87
    }
88
    catch (const Standard_Failure& e) {
89
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
90
        return nullptr;
91
    }
92
}
93

94
PyObject* PointConstraintPy::order(PyObject *args)
95
{
96
    if (!PyArg_ParseTuple(args, ""))
97
        return nullptr;
98

99
    try {
100
        Standard_Integer v = getGeomPlate_PointConstraintPtr()->Order();
101
        return PyLong_FromLong(v);
102
    }
103
    catch (const Standard_Failure& e) {
104
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
105
        return nullptr;
106
    }
107
}
108

109
PyObject* PointConstraintPy::G0Criterion(PyObject *args)
110
{
111
    if (!PyArg_ParseTuple(args, ""))
112
        return nullptr;
113

114
    try {
115
        Standard_Real v = getGeomPlate_PointConstraintPtr()->G0Criterion();
116
        return PyFloat_FromDouble(v);
117
    }
118
    catch (const Standard_Failure& e) {
119
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
120
        return nullptr;
121
    }
122
}
123

124
PyObject* PointConstraintPy::G1Criterion(PyObject *args)
125
{
126
    if (!PyArg_ParseTuple(args, ""))
127
        return nullptr;
128

129
    try {
130
        Standard_Real v = getGeomPlate_PointConstraintPtr()->G1Criterion();
131
        return PyFloat_FromDouble(v);
132
    }
133
    catch (const Standard_Failure& e) {
134
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
135
        return nullptr;
136
    }
137
}
138

139
PyObject* PointConstraintPy::G2Criterion(PyObject *args)
140
{
141
    if (!PyArg_ParseTuple(args, ""))
142
        return nullptr;
143

144
    try {
145
        Standard_Real v = getGeomPlate_PointConstraintPtr()->G2Criterion();
146
        return PyFloat_FromDouble(v);
147
    }
148
    catch (const Standard_Failure& e) {
149
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
150
        return nullptr;
151
    }
152
}
153

154
PyObject* PointConstraintPy::setG0Criterion(PyObject *args)
155
{
156
    double tolDist;
157
    if (!PyArg_ParseTuple(args, "d", &tolDist))
158
        return nullptr;
159

160
    try {
161
        getGeomPlate_PointConstraintPtr()->SetG0Criterion(tolDist);
162
        Py_Return;
163
    }
164
    catch (const Standard_Failure& e) {
165
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
166
        return nullptr;
167
    }
168
}
169

170
PyObject* PointConstraintPy::setG1Criterion(PyObject *args)
171
{
172
    double tolAng;
173
    if (!PyArg_ParseTuple(args, "d", &tolAng))
174
        return nullptr;
175

176
    try {
177
        getGeomPlate_PointConstraintPtr()->SetG1Criterion(tolAng);
178
        Py_Return;
179
    }
180
    catch (const Standard_Failure& e) {
181
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
182
        return nullptr;
183
    }
184
}
185

186
PyObject* PointConstraintPy::setG2Criterion(PyObject *args)
187
{
188
    double tolCurv;
189
    if (!PyArg_ParseTuple(args, "d", &tolCurv))
190
        return nullptr;
191

192
    try {
193
        getGeomPlate_PointConstraintPtr()->SetG2Criterion(tolCurv);
194
        Py_Return;
195
    }
196
    catch (const Standard_Failure& e) {
197
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
198
        return nullptr;
199
    }
200
}
201

202
PyObject* PointConstraintPy::hasPnt2dOnSurf(PyObject *args)
203
{
204
    if (!PyArg_ParseTuple(args, ""))
205
        return nullptr;
206

207
    try {
208
        Standard_Boolean ok = getGeomPlate_PointConstraintPtr()->HasPnt2dOnSurf();
209
        return Py_BuildValue("O", (ok ? Py_True : Py_False));
210
    }
211
    catch (const Standard_Failure& e) {
212
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
213
        return nullptr;
214
    }
215
}
216

217
PyObject* PointConstraintPy::setPnt2dOnSurf(PyObject *args)
218
{
219
    double x, y;
220
    if (!PyArg_ParseTuple(args, "dd", &x, &y))
221
        return nullptr;
222

223
    try {
224
        getGeomPlate_PointConstraintPtr()->SetPnt2dOnSurf(gp_Pnt2d(x, y));
225
        Py_Return;
226
    }
227
    catch (const Standard_Failure& e) {
228
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
229
        return nullptr;
230
    }
231
}
232

233
PyObject* PointConstraintPy::pnt2dOnSurf(PyObject *args)
234
{
235
    if (!PyArg_ParseTuple(args, ""))
236
        return nullptr;
237

238
    try {
239
        gp_Pnt2d pt = getGeomPlate_PointConstraintPtr()->Pnt2dOnSurf();
240
        Py::Tuple coord(2);
241
        coord.setItem(0, Py::Float(pt.X()));
242
        coord.setItem(1, Py::Float(pt.Y()));
243
        return Py::new_reference_to(coord);
244
    }
245
    catch (const Standard_Failure& e) {
246
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
247
        return nullptr;
248
    }
249
}
250

251
PyObject *PointConstraintPy::getCustomAttributes(const char* /*attr*/) const
252
{
253
    return nullptr;
254
}
255

256
int PointConstraintPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
257
{
258
    return 0;
259
}
260

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

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

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

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