FreeCAD

Форк
0
/
ArcOfParabola2dPyImp.cpp 
115 строк · 4.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_MakeArcOfParabola.hxx>
26
# include <Geom2d_Parabola.hxx>
27
# include <Geom2d_TrimmedCurve.hxx>
28
# include <gp_Parab2d.hxx>
29
#endif
30

31
#include "Geom2d/ArcOfParabola2dPy.h"
32
#include "Geom2d/ArcOfParabola2dPy.cpp"
33
#include "Geom2d/Parabola2dPy.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 ArcOfParabola2dPy::representation() const
43
{
44
    return "<ArcOfParabola2d object>";
45
}
46

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

53
// constructor method
54
int ArcOfParabola2dPy::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::Parabola2dPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
60
        try {
61
            Handle(Geom2d_Parabola) parabola = Handle(Geom2d_Parabola)::DownCast
62
                (static_cast<Parabola2dPy*>(o)->getGeom2dParabolaPtr()->handle());
63
            GCE2d_MakeArcOfParabola arc(parabola->Parab2d(), u1, u2, Base::asBoolean(sense));
64
            if (!arc.IsDone()) {
65
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
66
                return -1;
67
            }
68

69
            getGeom2dArcOfParabolaPtr()->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
        "ArcOfParabola2d constructor expects an parabola curve and a parameter range");
86
    return -1;
87
}
88

89
Py::Float ArcOfParabola2dPy::getFocal() const
90
{
91
    return Py::Float(getGeom2dArcOfParabolaPtr()->getFocal());
92
}
93

94
void  ArcOfParabola2dPy::setFocal(Py::Float arg)
95
{
96
    getGeom2dArcOfParabolaPtr()->setFocal((double)arg);
97
}
98

99
Py::Object ArcOfParabola2dPy::getParabola() const
100
{
101
    Handle(Geom2d_TrimmedCurve) trim = Handle(Geom2d_TrimmedCurve)::DownCast
102
        (getGeom2dArcOfParabolaPtr()->handle());
103
    Handle(Geom2d_Parabola) parabola = Handle(Geom2d_Parabola)::DownCast(trim->BasisCurve());
104
    return Py::asObject(new Parabola2dPy(new Geom2dParabola(parabola)));
105
}
106

107
PyObject *ArcOfParabola2dPy::getCustomAttributes(const char* ) const
108
{
109
    return nullptr;
110
}
111

112
int ArcOfParabola2dPy::setCustomAttributes(const char* , PyObject *)
113
{
114
    return 0;
115
}
116

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

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

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

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