FreeCAD

Форк
0
/
ArcPyImp.cpp 
199 строк · 7.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 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 <GC_MakeArcOfCircle.hxx>
26
# include <GC_MakeArcOfEllipse.hxx>
27
# include <GC_MakeArcOfHyperbola.hxx>
28
# include <GC_MakeArcOfParabola.hxx>
29
# include <Geom_Circle.hxx>
30
# include <Geom_Ellipse.hxx>
31
# include <Geom_Hyperbola.hxx>
32
# include <Geom_Parabola.hxx>
33
#endif
34

35
#include <Base/VectorPy.h>
36

37
#include "ArcPy.h"
38
#include "ArcPy.cpp"
39
#include "CirclePy.h"
40
#include "EllipsePy.h"
41
#include "HyperbolaPy.h"
42
#include "OCCError.h"
43
#include "ParabolaPy.h"
44

45

46
using namespace Part;
47

48
extern const char* gce_ErrorStatusText(gce_ErrorType et);
49

50
// returns a string which represents the object e.g. when printed in python
51
std::string ArcPy::representation() const
52
{
53
    return "<Arc object>";
54
}
55

56
PyObject *ArcPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
57
{
58
    // never create such objects with the constructor
59
    return new ArcPy(new GeomTrimmedCurve());
60
}
61

62
// constructor method
63
int ArcPy::PyInit(PyObject* args, PyObject* /*kwd*/)
64
{
65
    PyObject* o;
66
    double u1, u2;
67
    PyObject *sense=Py_True;
68
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::CirclePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
69
        try {
70
            Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast
71
                (static_cast<CirclePy*>(o)->getGeomCirclePtr()->handle());
72
            GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, Base::asBoolean(sense));
73
            if (!arc.IsDone()) {
74
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
75
                return -1;
76
            }
77

78
            getGeomTrimmedCurvePtr()->setHandle(arc.Value());
79
            return 0;
80
        }
81
        catch (Standard_Failure& e) {
82
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
83
            return -1;
84
        }
85
        catch (...) {
86
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
87
            return -1;
88
        }
89
    }
90

91
    PyErr_Clear();
92
    PyObject *pV1, *pV2, *pV3;
93
    if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1,
94
                                         &(Base::VectorPy::Type), &pV2,
95
                                         &(Base::VectorPy::Type), &pV3)) {
96
        Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
97
        Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
98
        Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
99

100
        GC_MakeArcOfCircle arc(gp_Pnt(v1.x,v1.y,v1.z),
101
                               gp_Pnt(v2.x,v2.y,v2.z),
102
                               gp_Pnt(v3.x,v3.y,v3.z));
103
        if (!arc.IsDone()) {
104
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
105
            return -1;
106
        }
107

108
        getGeomTrimmedCurvePtr()->setHandle(arc.Value());
109
        return 0;
110
    }
111

112
    PyErr_Clear();
113
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::EllipsePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
114
        try {
115
            Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast
116
                (static_cast<EllipsePy*>(o)->getGeomEllipsePtr()->handle());
117
            GC_MakeArcOfEllipse arc(ellipse->Elips(), u1, u2, Base::asBoolean(sense));
118
            if (!arc.IsDone()) {
119
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
120
                return -1;
121
            }
122

123
            getGeomTrimmedCurvePtr()->setHandle(arc.Value());
124
            return 0;
125
        }
126
        catch (Standard_Failure& e) {
127
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
128
            return -1;
129
        }
130
        catch (...) {
131
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
132
            return -1;
133
        }
134
    }
135

136

137
    PyErr_Clear();
138
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::ParabolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
139
        try {
140
            Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast
141
                (static_cast<ParabolaPy*>(o)->getGeomParabolaPtr()->handle());
142
            GC_MakeArcOfParabola arc(parabola->Parab(), u1, u2, Base::asBoolean(sense));
143
            if (!arc.IsDone()) {
144
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
145
                return -1;
146
            }
147

148
            getGeomTrimmedCurvePtr()->setHandle(arc.Value());
149
            return 0;
150
        }
151
        catch (Standard_Failure& e) {
152
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
153
            return -1;
154
        }
155
        catch (...) {
156
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
157
            return -1;
158
        }
159
    }
160

161
    PyErr_Clear();
162

163
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
164
        try {
165
            Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast
166
                (static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
167
            GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, Base::asBoolean(sense));
168
            if (!arc.IsDone()) {
169
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
170
                return -1;
171
            }
172

173
            getGeomTrimmedCurvePtr()->setHandle(arc.Value());
174
            return 0;
175
        }
176
        catch (Standard_Failure& e) {
177
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
178
            return -1;
179
        }
180
        catch (...) {
181
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
182
            return -1;
183
        }
184
    }
185

186
    // All checks failed
187
    PyErr_SetString(PyExc_TypeError, "Arc constructor expects a conic curve and a parameter range");
188
    return -1;
189
}
190

191
PyObject *ArcPy::getCustomAttributes(const char* /*attr*/) const
192
{
193
    return nullptr;
194
}
195

196
int ArcPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
197
{
198
    return 0;
199
}
200

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

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

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

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