FreeCAD

Форк
0
/
ArcOfConic2dPyImp.cpp 
121 строка · 4.7 Кб
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 <Geom2d_Conic.hxx>
26
# include <Geom2d_TrimmedCurve.hxx>
27
#endif
28

29
#include <Base/GeometryPyCXX.h>
30

31
#include "Geom2d/ArcOfConic2dPy.h"
32
#include "Geom2d/ArcOfConic2dPy.cpp"
33
#include "OCCError.h"
34

35

36
using namespace Part;
37

38
// returns a string which represents the object e.g. when printed in python
39
std::string ArcOfConic2dPy::representation() const
40
{
41
    return "<Arc of conic2d object>";
42
}
43

44
PyObject *ArcOfConic2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
45
{
46
    // never create such objects with the constructor
47
    PyErr_SetString(PyExc_RuntimeError,
48
        "You cannot create an instance of the abstract class 'ArcOfConic2d'.");
49
    return nullptr;
50
}
51

52
// constructor method
53
int ArcOfConic2dPy::PyInit(PyObject* /*args*/, PyObject* /*kwds*/)
54
{
55
    return -1;
56
}
57

58
Py::Object ArcOfConic2dPy::getLocation() const
59
{
60
    Base::Vector2d loc = getGeom2dArcOfConicPtr()->getLocation();
61
    return Base::Vector2dPy::create(loc);
62
}
63

64
void  ArcOfConic2dPy::setLocation(Py::Object arg)
65
{
66
    Base::Vector2d loc = Py::toVector2d(arg.ptr());
67
    getGeom2dArcOfConicPtr()->setLocation(loc);
68
}
69

70
Py::Float ArcOfConic2dPy::getEccentricity() const
71
{
72
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
73
    Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
74
    return Py::Float(conic->Eccentricity());
75
}
76

77
Py::Object ArcOfConic2dPy::getXAxis() const
78
{
79
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
80
    Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
81
    gp_Dir2d xdir = conic->XAxis().Direction();
82
    return Base::Vector2dPy::create(xdir.X(), xdir.Y());
83
}
84

85
void  ArcOfConic2dPy::setXAxis(Py::Object arg)
86
{
87
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
88
    Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
89
    Base::Vector2d dir = Py::toVector2d(arg.ptr());
90
    gp_Ax2d xaxis = conic->XAxis();
91
    xaxis.SetDirection(gp_Dir2d(dir.x, dir.y));
92
    conic->SetXAxis(xaxis);
93
}
94

95
Py::Object ArcOfConic2dPy::getYAxis() const
96
{
97
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
98
    Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
99
    gp_Dir2d ydir = conic->YAxis().Direction();
100
    return Base::Vector2dPy::create(ydir.X(), ydir.Y());
101
}
102

103
void  ArcOfConic2dPy::setYAxis(Py::Object arg)
104
{
105
    Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
106
    Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
107
    Base::Vector2d dir = Py::toVector2d(arg.ptr());
108
    gp_Ax2d yaxis = conic->YAxis();
109
    yaxis.SetDirection(gp_Dir2d(dir.x, dir.y));
110
    conic->SetYAxis(yaxis);
111
}
112

113
PyObject *ArcOfConic2dPy::getCustomAttributes(const char* ) const
114
{
115
    return nullptr;
116
}
117

118
int ArcOfConic2dPy::setCustomAttributes(const char* , PyObject *)
119
{
120
    return 0;
121
}
122

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

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

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

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