FreeCAD

Форк
0
/
ArcOfCirclePyImp.cpp 
155 строк · 5.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 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_MakeArcOfCircle.hxx>
26
# include <Geom_Circle.hxx>
27
# include <Geom_TrimmedCurve.hxx>
28
#endif
29

30
#include <Base/VectorPy.h>
31

32
#include "ArcOfCirclePy.h"
33
#include "ArcOfCirclePy.cpp"
34
#include "CirclePy.h"
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 ArcOfCirclePy::representation() const
44
{
45
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
46
        (getGeomArcOfCirclePtr()->handle());
47
    Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(trim->BasisCurve());
48

49
    gp_Ax1 axis = circle->Axis();
50
    gp_Dir dir = axis.Direction();
51
    gp_Pnt loc = axis.Location();
52
    Standard_Real fRad = circle->Radius();
53
    Standard_Real u1 = trim->FirstParameter();
54
    Standard_Real u2 = trim->LastParameter();
55

56
    std::stringstream str;
57
    str << "ArcOfCircle (";
58
    str << "Radius : " << fRad << ", ";
59
    str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
60
    str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
61
    str << "Parameter : (" << u1 << ", " << u2 << ")";
62
    str << ")";
63

64
    return str.str();
65
}
66

67
PyObject *ArcOfCirclePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
68
{
69
    // create a new instance of ArcOfCirclePy and the Twin object
70
    return new ArcOfCirclePy(new GeomArcOfCircle);
71
}
72

73
// constructor method
74
int ArcOfCirclePy::PyInit(PyObject* args, PyObject* /*kwds*/)
75
{
76
    PyObject* o;
77
    double u1, u2;
78
    PyObject *sense=Py_True;
79
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::CirclePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
80
        try {
81
            Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast
82
                (static_cast<CirclePy*>(o)->getGeomCirclePtr()->handle());
83
            GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, Base::asBoolean(sense));
84
            if (!arc.IsDone()) {
85
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
86
                return -1;
87
            }
88

89
            getGeomArcOfCirclePtr()->setHandle(arc.Value());
90
            return 0;
91
        }
92
        catch (Standard_Failure& e) {
93
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
94
            return -1;
95
        }
96
        catch (...) {
97
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
98
            return -1;
99
        }
100
    }
101

102
    PyErr_Clear();
103
    PyObject *pV1, *pV2, *pV3;
104
    if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1,
105
                                         &(Base::VectorPy::Type), &pV2,
106
                                         &(Base::VectorPy::Type), &pV3)) {
107
        Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
108
        Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
109
        Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
110

111
        GC_MakeArcOfCircle arc(gp_Pnt(v1.x,v1.y,v1.z),
112
                               gp_Pnt(v2.x,v2.y,v2.z),
113
                               gp_Pnt(v3.x,v3.y,v3.z));
114
        if (!arc.IsDone()) {
115
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
116
            return -1;
117
        }
118

119
        getGeomArcOfCirclePtr()->setHandle(arc.Value());
120
        return 0;
121
    }
122

123
    // All checks failed
124
    PyErr_SetString(PyExc_TypeError,
125
        "ArcOfCircle constructor expects a circle curve and a parameter range or three points");
126
    return -1;
127
}
128

129
Py::Float ArcOfCirclePy::getRadius() const
130
{
131
    return Py::Float(getGeomArcOfCirclePtr()->getRadius());
132
}
133

134
void  ArcOfCirclePy::setRadius(Py::Float arg)
135
{
136
    getGeomArcOfCirclePtr()->setRadius((double)arg);
137
}
138

139
Py::Object ArcOfCirclePy::getCircle() const
140
{
141
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
142
        (getGeomArcOfCirclePtr()->handle());
143
    Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(trim->BasisCurve());
144
    return Py::Object(new CirclePy(new GeomCircle(circle)), true);
145
}
146

147
PyObject *ArcOfCirclePy::getCustomAttributes(const char* ) const
148
{
149
    return nullptr;
150
}
151

152
int ArcOfCirclePy::setCustomAttributes(const char* , PyObject *)
153
{
154
    return 0;
155
}
156

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

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

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

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