FreeCAD

Форк
0
/
Hyperbola2dPyImp.cpp 
181 строка · 7.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2016 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 <GCE2d_MakeHyperbola.hxx>
26
# include <Geom2d_Hyperbola.hxx>
27
# include <gp_Hypr2d.hxx>
28
#endif
29

30
#include <Base/GeometryPyCXX.h>
31
#include <Base/PyWrapParseTupleAndKeywords.h>
32

33
#include "Geom2d/Hyperbola2dPy.h"
34
#include "Geom2d/Hyperbola2dPy.cpp"
35
#include "OCCError.h"
36

37

38
using namespace Part;
39

40
extern const char* gce_ErrorStatusText(gce_ErrorType et);
41

42
// returns a string which represents the object e.g. when printed in python
43
std::string Hyperbola2dPy::representation() const
44
{
45
    return "<Hyperbola2d object>";
46
}
47

48
PyObject *Hyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
49
{
50
    // create a new instance of Hyperbola2dPy and the Twin object
51
    return new Hyperbola2dPy(new Geom2dHyperbola);
52
}
53

54
// constructor method
55
int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds)
56
{
57
    static const std::array<const char *, 1> keywords_n {nullptr};
58
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
59
        Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
60
        hyperbola->SetMajorRadius(2.0);
61
        hyperbola->SetMinorRadius(1.0);
62
        return 0;
63
    }
64

65
    static const std::array<const char *, 2> keywords_e = {"Hyperbola", nullptr};
66
    PyErr_Clear();
67
    PyObject *pHypr;
68
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(Hyperbola2dPy::Type), &pHypr)) {
69
        Hyperbola2dPy* pHyperbola = static_cast<Hyperbola2dPy*>(pHypr);
70
        Handle(Geom2d_Hyperbola) Hypr1 = Handle(Geom2d_Hyperbola)::DownCast
71
            (pHyperbola->getGeom2dHyperbolaPtr()->handle());
72
        Handle(Geom2d_Hyperbola) Hypr2 = Handle(Geom2d_Hyperbola)::DownCast
73
            (this->getGeom2dHyperbolaPtr()->handle());
74
        Hypr2->SetHypr2d(Hypr1->Hypr2d());
75
        return 0;
76
    }
77

78
    static const std::array<const char *, 4> keywords_ssc {"S1", "S2", "Center", nullptr};
79
    PyErr_Clear();
80
    PyObject *pV1, *pV2, *pV3;
81
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc,
82
                                            Base::Vector2dPy::type_object(), &pV1,
83
                                            Base::Vector2dPy::type_object(), &pV2,
84
                                            Base::Vector2dPy::type_object(), &pV3)) {
85
        Base::Vector2d v1 = Py::toVector2d(pV1);
86
        Base::Vector2d v2 = Py::toVector2d(pV2);
87
        Base::Vector2d v3 = Py::toVector2d(pV3);
88
        GCE2d_MakeHyperbola me(gp_Pnt2d(v1.x,v1.y),
89
                               gp_Pnt2d(v2.x,v2.y),
90
                               gp_Pnt2d(v3.x,v3.y));
91
        if (!me.IsDone()) {
92
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
93
            return -1;
94
        }
95

96
        Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
97
        hyperbola->SetHypr2d(me.Value()->Hypr2d());
98
        return 0;
99
    }
100

101
    static const std::array<const char *, 4> keywords_cmm {"Center", "MajorRadius", "MinorRadius", nullptr};
102
    PyErr_Clear();
103
    PyObject *pV;
104
    double major, minor;
105
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm,
106
                                            Base::Vector2dPy::type_object(), &pV,
107
                                            &major, &minor)) {
108
        Base::Vector2d c = Py::toVector2d(pV);
109
        GCE2d_MakeHyperbola me(gp_Ax2d(gp_Pnt2d(c.x,c.y), gp_Dir2d(0.0,1.0)),
110
                               major, minor);
111
        if (!me.IsDone()) {
112
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
113
            return -1;
114
        }
115

116
        Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
117
        hyperbola->SetHypr2d(me.Value()->Hypr2d());
118
        return 0;
119
    }
120

121
    PyErr_SetString(PyExc_TypeError, "Hyperbola constructor accepts:\n"
122
        "-- empty parameter list\n"
123
        "-- Hyperbola\n"
124
        "-- Point, double, double\n"
125
        "-- Point, Point, Point");
126
    return -1;
127
}
128

129
Py::Float Hyperbola2dPy::getMajorRadius() const
130
{
131
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
132
    return Py::Float(hyperbola->MajorRadius());
133
}
134

135
void Hyperbola2dPy::setMajorRadius(Py::Float arg)
136
{
137
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
138
    hyperbola->SetMajorRadius((double)arg);
139
}
140

141
Py::Float Hyperbola2dPy::getMinorRadius() const
142
{
143
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
144
    return Py::Float(hyperbola->MinorRadius());
145
}
146

147
void Hyperbola2dPy::setMinorRadius(Py::Float arg)
148
{
149
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
150
    hyperbola->SetMinorRadius((double)arg);
151
}
152

153
Py::Float Hyperbola2dPy::getFocal() const
154
{
155
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
156
    return Py::Float(hyperbola->Focal());
157
}
158

159
Py::Object Hyperbola2dPy::getFocus1() const
160
{
161
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
162
    gp_Pnt2d loc = hyperbola->Focus1();
163
    return Base::Vector2dPy::create(loc.X(), loc.Y());
164
}
165

166
Py::Object Hyperbola2dPy::getFocus2() const
167
{
168
    Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
169
    gp_Pnt2d loc = hyperbola->Focus2();
170
    return Base::Vector2dPy::create(loc.X(), loc.Y());
171
}
172

173
PyObject *Hyperbola2dPy::getCustomAttributes(const char* /*attr*/) const
174
{
175
    return nullptr;
176
}
177

178
int Hyperbola2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
179
{
180
    return 0;
181
}
182

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

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

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

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