FreeCAD

Форк
0
/
ArcOfConicPyImp.cpp 
242 строки · 8.0 Кб
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 <Geom_TrimmedCurve.hxx>
26
#endif
27

28
#include <Base/GeometryPyCXX.h>
29
#include <Base/VectorPy.h>
30

31
#include "ArcOfConicPy.h"
32
#include "ArcOfConicPy.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 ArcOfConicPy::representation() const
40
{
41
    return "<ArcOfConic object>";
42
}
43

44
PyObject *ArcOfConicPy::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 'ArcOfConic'.");
49
    return nullptr;
50
}
51

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

58
Py::Object ArcOfConicPy::getLocation() const
59
{
60
    return Py::Vector(getGeomArcOfConicPtr()->getLocation());
61
}
62

63
Py::Object ArcOfConicPy::getCenter() const
64
{
65
    return Py::Vector(getGeomArcOfConicPtr()->getCenter());
66
}
67

68
void  ArcOfConicPy::setLocation(Py::Object arg)
69
{
70
    PyObject* p = arg.ptr();
71
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
72
        Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
73
        getGeomArcOfConicPtr()->setLocation(loc);
74
    }
75
    else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
76
        Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
77
        getGeomArcOfConicPtr()->setLocation(loc);
78
    }
79
    else {
80
        std::string error = std::string("type must be 'Vector', not ");
81
        error += p->ob_type->tp_name;
82
        throw Py::TypeError(error);
83
    }
84
}
85

86
void  ArcOfConicPy::setCenter(Py::Object arg)
87
{
88
    PyObject* p = arg.ptr();
89
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
90
        Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
91
        getGeomArcOfConicPtr()->setCenter(loc);
92
    }
93
    else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
94
        Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
95
        getGeomArcOfConicPtr()->setCenter(loc);
96
    }
97
    else {
98
        std::string error = std::string("type must be 'Vector', not ");
99
        error += p->ob_type->tp_name;
100
        throw Py::TypeError(error);
101
    }
102
}
103

104
Py::Float ArcOfConicPy::getAngleXU() const
105
{
106
    return Py::Float(getGeomArcOfConicPtr()->getAngleXU());
107
}
108

109
void ArcOfConicPy::setAngleXU(Py::Float arg)
110
{
111
    getGeomArcOfConicPtr()->setAngleXU((double)arg);
112
}
113

114
Py::Object ArcOfConicPy::getAxis() const
115
{
116
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
117
        (getGeomArcOfConicPtr()->handle());
118
    Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
119
    gp_Ax1 axis = conic->Axis();
120
    gp_Dir dir = axis.Direction();
121
    return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
122
}
123

124
void  ArcOfConicPy::setAxis(Py::Object arg)
125
{
126
    PyObject* p = arg.ptr();
127
    Base::Vector3d val;
128
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
129
        val = static_cast<Base::VectorPy*>(p)->value();
130
    }
131
    else if (PyTuple_Check(p)) {
132
        val = Base::getVectorFromTuple<double>(p);
133
    }
134
    else {
135
        std::string error = std::string("type must be 'Vector', not ");
136
        error += p->ob_type->tp_name;
137
        throw Py::TypeError(error);
138
    }
139

140
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
141
        (getGeomArcOfConicPtr()->handle());
142
    Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
143
    try {
144
        gp_Ax1 axis;
145
        axis.SetLocation(conic->Location());
146
        axis.SetDirection(gp_Dir(val.x, val.y, val.z));
147
        conic->SetAxis(axis);
148
    }
149
    catch (Standard_Failure&) {
150
        throw Py::RuntimeError("cannot set axis");
151
    }
152
}
153

154
Py::Object ArcOfConicPy::getXAxis() const
155
{
156
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
157
        (getGeomArcOfConicPtr()->handle());
158
    Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
159
    gp_Ax1 axis = conic->XAxis();
160
    gp_Dir dir = axis.Direction();
161
    return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
162
}
163

164
void  ArcOfConicPy::setXAxis(Py::Object arg)
165
{
166
    PyObject* p = arg.ptr();
167
    Base::Vector3d val;
168
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
169
        val = static_cast<Base::VectorPy*>(p)->value();
170
    }
171
    else if (PyTuple_Check(p)) {
172
        val = Base::getVectorFromTuple<double>(p);
173
    }
174
    else {
175
        std::string error = std::string("type must be 'Vector', not ");
176
        error += p->ob_type->tp_name;
177
        throw Py::TypeError(error);
178
    }
179

180
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
181
        (getGeomArcOfConicPtr()->handle());
182
    Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
183
    try {
184
        gp_Ax2 pos;
185
        pos = conic->Position();
186
        pos.SetXDirection(gp_Dir(val.x, val.y, val.z));
187
        conic->SetPosition(pos);
188
    }
189
    catch (Standard_Failure&) {
190
        throw Py::RuntimeError("cannot set X axis");
191
    }
192
}
193

194
Py::Object ArcOfConicPy::getYAxis() const
195
{
196
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
197
        (getGeomArcOfConicPtr()->handle());
198
    Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
199
    gp_Ax1 axis = conic->YAxis();
200
    gp_Dir dir = axis.Direction();
201
    return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
202
}
203

204
void  ArcOfConicPy::setYAxis(Py::Object arg)
205
{
206
    PyObject* p = arg.ptr();
207
    Base::Vector3d val;
208
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
209
        val = static_cast<Base::VectorPy*>(p)->value();
210
    }
211
    else if (PyTuple_Check(p)) {
212
        val = Base::getVectorFromTuple<double>(p);
213
    }
214
    else {
215
        std::string error = std::string("type must be 'Vector', not ");
216
        error += p->ob_type->tp_name;
217
        throw Py::TypeError(error);
218
    }
219

220
    Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
221
        (getGeomArcOfConicPtr()->handle());
222
    Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(trim->BasisCurve());
223
    try {
224
        gp_Ax2 pos;
225
        pos = conic->Position();
226
        pos.SetYDirection(gp_Dir(val.x, val.y, val.z));
227
        conic->SetPosition(pos);
228
    }
229
    catch (Standard_Failure&) {
230
        throw Py::RuntimeError("cannot set Y axis");
231
    }
232
}
233

234
PyObject *ArcOfConicPy::getCustomAttributes(const char* ) const
235
{
236
    return nullptr;
237
}
238

239
int ArcOfConicPy::setCustomAttributes(const char* , PyObject *)
240
{
241
    return 0;
242
}
243

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

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

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

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