~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Part/App/ParabolaPyImp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2008 Werner Mayer <wmayer@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
 
 
24
#include "PreCompiled.h"
 
25
#ifndef _PreComp_
 
26
# include <Geom_Parabola.hxx>
 
27
#endif
 
28
 
 
29
#include <Base/VectorPy.h>
 
30
#include <Base/GeometryPyCXX.h>
 
31
 
 
32
#include "Geometry.h"
 
33
#include "ParabolaPy.h"
 
34
#include "ParabolaPy.cpp"
 
35
 
 
36
using namespace Part;
 
37
 
 
38
// returns a string which represents the object e.g. when printed in python
 
39
const char *ParabolaPy::representation(void) const
 
40
{
 
41
    return "<Parabola object>";
 
42
}
 
43
 
 
44
PyObject *ParabolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
 
45
{
 
46
    // create a new instance of ParabolaPy and the Twin object 
 
47
    return new ParabolaPy(new GeomParabola);
 
48
}
 
49
 
 
50
// constructor method
 
51
int ParabolaPy::PyInit(PyObject* args, PyObject* /*kwd*/)
 
52
{
 
53
    if (PyArg_ParseTuple(args, "")) {
 
54
        Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
 
55
            (getGeometryPtr()->handle());
 
56
        c->SetFocal(1.0);
 
57
        return 0;
 
58
    }
 
59
 
 
60
    return -1;
 
61
}
 
62
 
 
63
Py::Float ParabolaPy::getEccentricity(void) const
 
64
{
 
65
    Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
 
66
    return Py::Float(curve->Eccentricity()); 
 
67
}
 
68
 
 
69
Py::Float ParabolaPy::getFocal(void) const
 
70
{
 
71
    Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
 
72
    return Py::Float(curve->Focal()); 
 
73
}
 
74
 
 
75
void ParabolaPy::setFocal(Py::Float arg)
 
76
{
 
77
    Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
 
78
    curve->SetFocal((double)arg); 
 
79
}
 
80
 
 
81
Py::Object ParabolaPy::getFocus(void) const
 
82
{
 
83
    Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
 
84
        (getGeometryPtr()->handle());
 
85
    gp_Pnt loc = c->Focus();
 
86
    return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
 
87
}
 
88
 
 
89
Py::Float ParabolaPy::getParameter(void) const
 
90
{
 
91
    Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
 
92
    return Py::Float(curve->Parameter()); 
 
93
}
 
94
 
 
95
Py::Object ParabolaPy::getLocation(void) const
 
96
{
 
97
    Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
 
98
        (getGeometryPtr()->handle());
 
99
    gp_Pnt loc = c->Location();
 
100
    return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
 
101
}
 
102
 
 
103
void ParabolaPy::setLocation(Py::Object arg)
 
104
{
 
105
    PyObject* p = arg.ptr();
 
106
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
 
107
        Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
 
108
        Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
 
109
            (getGeometryPtr()->handle());
 
110
        c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
 
111
    }
 
112
    else if (PyTuple_Check(p)) {
 
113
        Py::Tuple tuple(arg);
 
114
        gp_Pnt loc;
 
115
        loc.SetX((double)Py::Float(tuple.getItem(0)));
 
116
        loc.SetY((double)Py::Float(tuple.getItem(1)));
 
117
        loc.SetZ((double)Py::Float(tuple.getItem(2)));
 
118
        Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
 
119
            (getGeometryPtr()->handle());
 
120
        c->SetLocation(loc);
 
121
    }
 
122
    else {
 
123
        std::string error = std::string("type must be 'Vector', not ");
 
124
        error += p->ob_type->tp_name;
 
125
        throw Py::TypeError(error);
 
126
    }
 
127
}
 
128
 
 
129
Py::Object ParabolaPy::getAxis(void) const
 
130
{
 
131
    Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
 
132
        (getGeometryPtr()->handle());
 
133
    gp_Dir dir = c->Axis().Direction();
 
134
    return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
 
135
}
 
136
 
 
137
void ParabolaPy::setAxis(Py::Object arg)
 
138
{
 
139
    Standard_Real dir_x, dir_y, dir_z;
 
140
    PyObject *p = arg.ptr();
 
141
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
 
142
        Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
 
143
        dir_x = v.x;
 
144
        dir_y = v.y;
 
145
        dir_z = v.z;
 
146
    }
 
147
    else if (PyTuple_Check(p)) {
 
148
        Py::Tuple tuple(arg);
 
149
        dir_x = (double)Py::Float(tuple.getItem(0));
 
150
        dir_y = (double)Py::Float(tuple.getItem(1));
 
151
        dir_z = (double)Py::Float(tuple.getItem(2));
 
152
    }
 
153
    else {
 
154
        std::string error = std::string("type must be 'Vector' or tuple, not ");
 
155
        error += p->ob_type->tp_name;
 
156
        throw Py::TypeError(error);
 
157
    }
 
158
 
 
159
    try {
 
160
        Handle_Geom_Parabola this_curv = Handle_Geom_Parabola::DownCast
 
161
            (this->getGeometryPtr()->handle());
 
162
        gp_Ax1 axis;
 
163
        axis.SetLocation(this_curv->Location());
 
164
        axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
 
165
        gp_Dir dir = axis.Direction();
 
166
        this_curv->SetAxis(axis);
 
167
    }
 
168
    catch (Standard_Failure) {
 
169
        throw Py::Exception("cannot set axis");
 
170
    }
 
171
}
 
172
 
 
173
PyObject *ParabolaPy::getCustomAttributes(const char* /*attr*/) const
 
174
{
 
175
    return 0;
 
176
}
 
177
 
 
178
int ParabolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
 
179
{
 
180
    return 0; 
 
181
}
 
182
 
 
183