FreeCAD

Форк
0
/
ArcOfParabolaPyImp.cpp 
141 строка · 5.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com>     *
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_MakeArcOfParabola.hxx>
26
# include <Geom_Parabola.hxx>
27
# include <Geom_TrimmedCurve.hxx>
28
#endif
29

30
#include "ArcOfParabolaPy.h"
31
#include "ArcOfParabolaPy.cpp"
32
#include "ParabolaPy.h"
33
#include "OCCError.h"
34

35

36
using namespace Part;
37

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

40
// returns a string which represents the object e.g. when printed in python
41
std::string ArcOfParabolaPy::representation() const
42
{
43
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
44
        (getGeomArcOfParabolaPtr()->handle());
45
    Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast(trim->BasisCurve());
46

47
    gp_Ax1 axis = parabola->Axis();
48
    gp_Dir dir = axis.Direction();
49
    gp_Pnt loc = axis.Location();
50
    Standard_Real fFocal = parabola->Focal();
51
    Standard_Real u1 = trim->FirstParameter();
52
    Standard_Real u2 = trim->LastParameter();
53

54
    gp_Dir normal = parabola->Axis().Direction();
55
    gp_Dir xdir = parabola->XAxis().Direction();
56

57
    gp_Ax2 xdirref(loc, normal); // this is a reference XY for the parabola
58

59
    Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
60

61

62
    std::stringstream str;
63
    str << "ArcOfParabola (";
64
    str << "Focal : " << fFocal << ", ";
65
    str << "AngleXU : " << fAngleXU << ", ";
66
    str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
67
    str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
68
    str << "Parameter : (" << u1 << ", " << u2 << ")";
69
    str << ")";
70

71
    return str.str();
72
}
73

74
PyObject *ArcOfParabolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
75
{
76
    // create a new instance of ArcOfParabolaPy and the Twin object
77
    return new ArcOfParabolaPy(new GeomArcOfParabola);
78
}
79

80
// constructor method
81
int ArcOfParabolaPy::PyInit(PyObject* args, PyObject* /*kwds*/)
82
{
83
    PyObject* o;
84
    double u1, u2;
85
    PyObject *sense=Py_True;
86
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::ParabolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
87
        try {
88
            Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast
89
                (static_cast<ParabolaPy*>(o)->getGeomParabolaPtr()->handle());
90
            GC_MakeArcOfParabola arc(parabola->Parab(), u1, u2, Base::asBoolean(sense));
91
            if (!arc.IsDone()) {
92
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
93
                return -1;
94
            }
95

96
            getGeomArcOfParabolaPtr()->setHandle(arc.Value());
97
            return 0;
98
        }
99
        catch (Standard_Failure& e) {
100
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
101
            return -1;
102
        }
103
        catch (...) {
104
            PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
105
            return -1;
106
        }
107
    }
108

109
    // All checks failed
110
    PyErr_SetString(PyExc_TypeError,
111
        "ArcOfParabola constructor expects an parabola curve and a parameter range");
112
    return -1;
113
}
114

115
Py::Float ArcOfParabolaPy::getFocal() const
116
{
117
    return Py::Float(getGeomArcOfParabolaPtr()->getFocal());
118
}
119

120
void  ArcOfParabolaPy::setFocal(Py::Float arg)
121
{
122
    getGeomArcOfParabolaPtr()->setFocal((double)arg);
123
}
124

125
Py::Object ArcOfParabolaPy::getParabola() const
126
{
127
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
128
        (getGeomArcOfParabolaPtr()->handle());
129
    Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast(trim->BasisCurve());
130
    return Py::Object(new ParabolaPy(new GeomParabola(parabola)), true);
131
}
132

133
PyObject *ArcOfParabolaPy::getCustomAttributes(const char* ) const
134
{
135
    return nullptr;
136
}
137

138
int ArcOfParabolaPy::setCustomAttributes(const char* , PyObject *)
139
{
140
    return 0;
141
}
142

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

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

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

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