FreeCAD

Форк
0
/
HyperbolaPyImp.cpp 
181 строка · 7.4 Кб
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_MakeHyperbola.hxx>
26
# include <Geom_Hyperbola.hxx>
27
#endif
28

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

33
#include "HyperbolaPy.h"
34
#include "HyperbolaPy.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 HyperbolaPy::representation() const
44
{
45
    return "<Hyperbola object>";
46
}
47

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

54
// constructor method
55
int HyperbolaPy::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(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->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, &(HyperbolaPy::Type), &pHypr)) {
69
        HyperbolaPy* pHyperbola = static_cast<HyperbolaPy*>(pHypr);
70
        Handle(Geom_Hyperbola) Hypr1 = Handle(Geom_Hyperbola)::DownCast
71
            (pHyperbola->getGeomHyperbolaPtr()->handle());
72
        Handle(Geom_Hyperbola) Hypr2 = Handle(Geom_Hyperbola)::DownCast
73
            (this->getGeomHyperbolaPtr()->handle());
74
        Hypr2->SetHypr(Hypr1->Hypr());
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::VectorPy::Type), &pV1,
83
                                             &(Base::VectorPy::Type), &pV2,
84
                                            &(Base::VectorPy::Type), &pV3)) {
85
        Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
86
        Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
87
        Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
88
        GC_MakeHyperbola me(gp_Pnt(v1.x,v1.y,v1.z),
89
                          gp_Pnt(v2.x,v2.y,v2.z),
90
                          gp_Pnt(v3.x,v3.y,v3.z));
91
        if (!me.IsDone()) {
92
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
93
            return -1;
94
        }
95

96
        Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
97
        hyperbola->SetHypr(me.Value()->Hypr());
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::VectorPy::Type), &pV,
107
                                        &major, &minor)) {
108
        Base::Vector3d c = static_cast<Base::VectorPy*>(pV)->value();
109
        GC_MakeHyperbola me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,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(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
117
        hyperbola->SetHypr(me.Value()->Hypr());
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 HyperbolaPy::getMajorRadius() const
130
{
131
    Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
132
    return Py::Float(hyperbola->MajorRadius());
133
}
134

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

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

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

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

159
Py::Object HyperbolaPy::getFocus1() const
160
{
161
    Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
162
    gp_Pnt loc = hyperbola->Focus1();
163
    return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
164
}
165

166
Py::Object HyperbolaPy::getFocus2() const
167
{
168
    Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
169
    gp_Pnt loc = hyperbola->Focus2();
170
    return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
171
}
172

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

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

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

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

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

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