FreeCAD

Форк
0
/
ArcOfHyperbolaPyImp.cpp 
153 строки · 5.8 Кб
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_MakeArcOfHyperbola.hxx>
26
# include <Geom_Hyperbola.hxx>
27
# include <Geom_TrimmedCurve.hxx>
28
#endif
29

30
#include "ArcOfHyperbolaPy.h"
31
#include "ArcOfHyperbolaPy.cpp"
32
#include "HyperbolaPy.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 ArcOfHyperbolaPy::representation() const
42
{
43
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
44
        (getGeomArcOfHyperbolaPtr()->handle());
45
    Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(trim->BasisCurve());
46

47
    gp_Ax1 axis = hyperbola->Axis();
48
    gp_Dir dir = axis.Direction();
49
    gp_Pnt loc = axis.Location();
50
    Standard_Real fMajRad = hyperbola->MajorRadius();
51
    Standard_Real fMinRad = hyperbola->MinorRadius();
52
    Standard_Real u1 = trim->FirstParameter();
53
    Standard_Real u2 = trim->LastParameter();
54

55
    gp_Dir normal = hyperbola->Axis().Direction();
56
    gp_Dir xdir = hyperbola->XAxis().Direction();
57

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

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

62

63
    std::stringstream str;
64
    str << "ArcOfHyperbola (";
65
    str << "MajorRadius : " << fMajRad << ", ";
66
    str << "MinorRadius : " << fMinRad << ", ";
67
    str << "AngleXU : " << fAngleXU << ", ";
68
    str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
69
    str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
70
    str << "Parameter : (" << u1 << ", " << u2 << ")";
71
    str << ")";
72

73
    return str.str();
74
}
75

76
PyObject *ArcOfHyperbolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
77
{
78
    // create a new instance of ArcOfHyperbolaPy and the Twin object
79
    return new ArcOfHyperbolaPy(new GeomArcOfHyperbola);
80
}
81

82
// constructor method
83
int ArcOfHyperbolaPy::PyInit(PyObject* args, PyObject* /*kwds*/)
84
{
85
    PyObject* o;
86
    double u1, u2;
87
    PyObject *sense=Py_True;
88
    if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
89
        try {
90
            Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast
91
                (static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
92
            GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, Base::asBoolean(sense));
93
            if (!arc.IsDone()) {
94
                PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
95
                return -1;
96
            }
97

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

111
    // All checks failed
112
    PyErr_SetString(PyExc_TypeError,
113
        "ArcOfHyperbola constructor expects an hyperbola curve and a parameter range");
114
    return -1;
115
}
116

117
Py::Float ArcOfHyperbolaPy::getMajorRadius() const
118
{
119
    return Py::Float(getGeomArcOfHyperbolaPtr()->getMajorRadius());
120
}
121

122
void  ArcOfHyperbolaPy::setMajorRadius(Py::Float arg)
123
{
124
    getGeomArcOfHyperbolaPtr()->setMajorRadius((double)arg);
125
}
126

127
Py::Float ArcOfHyperbolaPy::getMinorRadius() const
128
{
129
    return Py::Float(getGeomArcOfHyperbolaPtr()->getMinorRadius());
130
}
131

132
void  ArcOfHyperbolaPy::setMinorRadius(Py::Float arg)
133
{
134
    getGeomArcOfHyperbolaPtr()->setMinorRadius((double)arg);
135
}
136

137
Py::Object ArcOfHyperbolaPy::getHyperbola() const
138
{
139
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
140
        (getGeomArcOfHyperbolaPtr()->handle());
141
    Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(trim->BasisCurve());
142
    return Py::Object(new HyperbolaPy(new GeomHyperbola(hyperbola)), true);
143
}
144

145
PyObject *ArcOfHyperbolaPy::getCustomAttributes(const char* ) const
146
{
147
    return nullptr;
148
}
149

150
int ArcOfHyperbolaPy::setCustomAttributes(const char* , PyObject *)
151
{
152
    return 0;
153
}
154

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

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

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

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