FreeCAD

Форк
0
/
ArcOfCircle2dPyImp.cpp 
136 строк · 5.1 Кб
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_MakeArcOfCircle.hxx>
26
# include <Geom2d_Circle.hxx>
27
# include <Geom2d_TrimmedCurve.hxx>
28
# include <gp_Circ2d.hxx>
29
#endif
30

31
#include <Base/GeometryPyCXX.h>
32

33
#include "Geom2d/ArcOfCircle2dPy.h"
34
#include "Geom2d/ArcOfCircle2dPy.cpp"
35
#include "Geom2d/Circle2dPy.h"
36
#include "OCCError.h"
37

38

39
using namespace Part;
40

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

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

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

55
// constructor method
56
int ArcOfCircle2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
57
{
58
    PyObject* o;
59
    double u1, u2;
60
    PyObject *sense=Py_True;
61
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::Circle2dPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
62
        try {
63
            Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast
64
                (static_cast<Circle2dPy*>(o)->getGeom2dCirclePtr()->handle());
65
            GCE2d_MakeArcOfCircle arc(circle->Circ2d(), u1, u2, Base::asBoolean(sense));
66
            if (!arc.IsDone()) {
67
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
68
                return -1;
69
            }
70

71
            getGeom2dArcOfCirclePtr()->setHandle(arc.Value());
72
            return 0;
73
        }
74
        catch (Standard_Failure& e) {
75
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
76
            return -1;
77
        }
78
        catch (...) {
79
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
80
            return -1;
81
        }
82
    }
83

84
    PyErr_Clear();
85
    PyObject *pV1, *pV2, *pV3;
86
    if (PyArg_ParseTuple(args, "O!O!O!", Base::Vector2dPy::type_object(), &pV1,
87
                                         Base::Vector2dPy::type_object(), &pV2,
88
                                         Base::Vector2dPy::type_object(), &pV3)) {
89
        Base::Vector2d v1 = Py::toVector2d(pV1);
90
        Base::Vector2d v2 = Py::toVector2d(pV2);
91
        Base::Vector2d v3 = Py::toVector2d(pV3);
92

93
        GCE2d_MakeArcOfCircle arc(gp_Pnt2d(v1.x,v1.y),
94
                                  gp_Pnt2d(v2.x,v2.y),
95
                                  gp_Pnt2d(v3.x,v3.y));
96
        if (!arc.IsDone()) {
97
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
98
            return -1;
99
        }
100

101
        getGeom2dArcOfCirclePtr()->setHandle(arc.Value());
102
        return 0;
103
    }
104

105
    // All checks failed
106
    PyErr_SetString(PyExc_TypeError,
107
        "ArcOfCircle2d constructor expects a circle curve and a parameter range or three points");
108
    return -1;
109
}
110

111
Py::Float ArcOfCircle2dPy::getRadius() const
112
{
113
    return Py::Float(getGeom2dArcOfCirclePtr()->getRadius());
114
}
115

116
void  ArcOfCircle2dPy::setRadius(Py::Float arg)
117
{
118
    getGeom2dArcOfCirclePtr()->setRadius((double)arg);
119
}
120

121
Py::Object ArcOfCircle2dPy::getCircle() const
122
{
123
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
124
    Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(curve->BasisCurve());
125
    return Py::asObject(new Circle2dPy(new Geom2dCircle(circle)));
126
}
127

128
PyObject *ArcOfCircle2dPy::getCustomAttributes(const char* ) const
129
{
130
    return nullptr;
131
}
132

133
int ArcOfCircle2dPy::setCustomAttributes(const char* , PyObject *)
134
{
135
    return 0;
136
}
137

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

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

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

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