FreeCAD

Форк
0
/
ArcOfEllipse2dPyImp.cpp 
124 строки · 4.6 Кб
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_MakeArcOfEllipse.hxx>
26
# include <Geom2d_Ellipse.hxx>
27
# include <Geom2d_TrimmedCurve.hxx>
28
# include <gp_Elips2d.hxx>
29
#endif
30

31
#include "Geom2d/ArcOfEllipse2dPy.h"
32
#include "Geom2d/ArcOfEllipse2dPy.cpp"
33
#include "Geom2d/Ellipse2dPy.h"
34
#include "OCCError.h"
35

36

37
using namespace Part;
38

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

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

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

53
// constructor method
54
int ArcOfEllipse2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
55
{
56
    PyObject* o;
57
    double u1, u2;
58
    PyObject *sense=Py_True;
59
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::Ellipse2dPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
60
        try {
61
            Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast
62
                (static_cast<Ellipse2dPy*>(o)->getGeom2dEllipsePtr()->handle());
63
            GCE2d_MakeArcOfEllipse arc(ellipse->Elips2d(), u1, u2, Base::asBoolean(sense));
64
            if (!arc.IsDone()) {
65
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
66
                return -1;
67
            }
68

69
            getGeom2dArcOfEllipsePtr()->setHandle(arc.Value());
70
            return 0;
71
        }
72
        catch (Standard_Failure& e) {
73

74
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
75
            return -1;
76
        }
77
        catch (...) {
78
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
79
            return -1;
80
        }
81
    }
82

83
    // All checks failed
84
    PyErr_SetString(PyExc_TypeError,
85
        "ArcOfEllipse2d constructor expects an ellipse curve and a parameter range");
86
    return -1;
87
}
88

89
Py::Float ArcOfEllipse2dPy::getMajorRadius() const
90
{
91
    return Py::Float(getGeom2dArcOfEllipsePtr()->getMajorRadius());
92
}
93

94
void  ArcOfEllipse2dPy::setMajorRadius(Py::Float arg)
95
{
96
    getGeom2dArcOfEllipsePtr()->setMajorRadius((double)arg);
97
}
98

99
Py::Float ArcOfEllipse2dPy::getMinorRadius() const
100
{
101
    return Py::Float(getGeom2dArcOfEllipsePtr()->getMinorRadius());
102
}
103

104
void  ArcOfEllipse2dPy::setMinorRadius(Py::Float arg)
105
{
106
    getGeom2dArcOfEllipsePtr()->setMinorRadius((double)arg);
107
}
108

109
Py::Object ArcOfEllipse2dPy::getEllipse() const
110
{
111
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
112
    Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(curve->BasisCurve());
113
    return Py::asObject(new Ellipse2dPy(new Geom2dEllipse(ellipse)));
114
}
115

116
PyObject *ArcOfEllipse2dPy::getCustomAttributes(const char* ) const
117
{
118
    return nullptr;
119
}
120

121
int ArcOfEllipse2dPy::setCustomAttributes(const char* , PyObject *)
122
{
123
    return 0;
124
}
125

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

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

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

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