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

« back to all changes in this revision

Viewing changes to src/Mod/Part/App/SurfaceOfExtrusionPyImp.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_SurfaceOfLinearExtrusion.hxx>
 
27
#endif
 
28
 
 
29
#include "Geometry.h"
 
30
#include "SurfaceOfExtrusionPy.h"
 
31
#include "SurfaceOfExtrusionPy.cpp"
 
32
 
 
33
#include <Base/GeometryPyCXX.h>
 
34
#include <Base/VectorPy.h>
 
35
 
 
36
using namespace Part;
 
37
 
 
38
// returns a string which represents the object e.g. when printed in python
 
39
const char *SurfaceOfExtrusionPy::representation(void) const
 
40
{
 
41
    return "<SurfaceOfExtrusion object>";
 
42
}
 
43
 
 
44
PyObject *SurfaceOfExtrusionPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
 
45
{
 
46
    // create a new instance of SurfaceOfExtrusionPy and the Twin object 
 
47
    return new SurfaceOfExtrusionPy(new GeomSurfaceOfExtrusion);
 
48
}
 
49
 
 
50
// constructor method
 
51
int SurfaceOfExtrusionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
 
52
{
 
53
    PyObject* pGeom;
 
54
    PyObject* pDir;
 
55
    if (!PyArg_ParseTuple(args, "O!O!", 
 
56
                            &(GeometryPy::Type), &pGeom, 
 
57
                            &(Base::VectorPy::Type),&pDir))
 
58
        return -1;
 
59
 
 
60
    GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
 
61
    Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
 
62
        (pcGeo->getGeometryPtr()->handle());
 
63
    if (curve.IsNull()) {
 
64
        PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
 
65
        return -1;
 
66
    }
 
67
 
 
68
    try {
 
69
        Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
 
70
        Handle_Geom_SurfaceOfLinearExtrusion curve2 = new Geom_SurfaceOfLinearExtrusion(curve,
 
71
            gp_Dir(dir.x,dir.y,dir.z));
 
72
        getGeomSurfaceOfExtrusionPtr()->setHandle(curve2);
 
73
        return 0;
 
74
    }
 
75
    catch (Standard_Failure) {
 
76
        Handle_Standard_Failure e = Standard_Failure::Caught();
 
77
        PyErr_SetString(PyExc_Exception, e->GetMessageString());
 
78
        return -1;
 
79
    }
 
80
}
 
81
 
 
82
Py::Object SurfaceOfExtrusionPy::getDirection(void) const
 
83
{
 
84
    Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
 
85
        (getGeometryPtr()->handle());
 
86
    const gp_Dir& dir = curve->Direction();
 
87
    return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
 
88
}
 
89
 
 
90
void  SurfaceOfExtrusionPy::setDirection(Py::Object arg)
 
91
{
 
92
    PyObject* p = arg.ptr();
 
93
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
 
94
        Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
 
95
        Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
 
96
            (getGeometryPtr()->handle());
 
97
        curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
 
98
    }
 
99
    else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
 
100
        Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
 
101
        Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
 
102
            (getGeometryPtr()->handle());
 
103
        curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
 
104
    }
 
105
    else {
 
106
        std::string error = std::string("type must be 'Vector', not ");
 
107
        error += p->ob_type->tp_name;
 
108
        throw Py::TypeError(error);
 
109
    }
 
110
}
 
111
 
 
112
Py::Object SurfaceOfExtrusionPy::getBasisCurve(void) const
 
113
{
 
114
    throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
 
115
}
 
116
 
 
117
void  SurfaceOfExtrusionPy::setBasisCurve(Py::Object arg)
 
118
{
 
119
    PyObject* p = arg.ptr();
 
120
    if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
 
121
        GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
 
122
        Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
 
123
            (pcGeo->getGeometryPtr()->handle());
 
124
        if (curve.IsNull()) {
 
125
            throw Py::TypeError("geometry is not a curve");
 
126
        }
 
127
 
 
128
        try {
 
129
            Handle_Geom_SurfaceOfLinearExtrusion curve2 = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
 
130
                (getGeometryPtr()->handle());
 
131
            curve2->SetBasisCurve(curve);
 
132
        }
 
133
        catch (Standard_Failure) {
 
134
            Handle_Standard_Failure e = Standard_Failure::Caught();
 
135
            throw Py::Exception(e->GetMessageString());
 
136
        }
 
137
    }
 
138
}
 
139
 
 
140
PyObject *SurfaceOfExtrusionPy::getCustomAttributes(const char* /*attr*/) const
 
141
{
 
142
    return 0;
 
143
}
 
144
 
 
145
int SurfaceOfExtrusionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
 
146
{
 
147
    return 0; 
 
148
}