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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2010-01-11 08:48:33 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100111084833-4g9vgdqbkw8u34zb
Tags: 0.9.2646.5-1
* New upstream version (closes: #561696).
* Added swig to Build-Depends (closes: #563523, #563772).
* Removed python-opencv from Build-Depends and Recommends (closes: #560768).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net>        *
 
2
 *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
3
 *                                                                         *
4
4
 *   This file is part of the FreeCAD CAx development system.              *
5
5
 *                                                                         *
23
23
 
24
24
#include "PreCompiled.h"
25
25
#ifndef _PreComp_
26
 
# include <BRepBuilderAPI_MakeEdge.hxx>
27
 
# include <BRepBuilderAPI_MakeFace.hxx>
28
26
# include <gp_Ax1.hxx>
29
27
# include <gp_Dir.hxx>
30
28
# include <gp_Pnt.hxx>
31
29
# include <gp_Vec.hxx>
32
 
# include <gp_Trsf.hxx>
 
30
# include <gp_Trsf.hxx>
33
31
# include <Geom_Geometry.hxx>
34
32
# include <Geom_Curve.hxx>
35
33
# include <Geom_Surface.hxx>
 
34
# include <Precision.hxx>
36
35
# include <Standard_Failure.hxx>
37
36
#endif
38
37
 
51
50
 
52
51
#include "TopoShape.h"
53
52
#include "TopoShapePy.h"
54
 
#include "TopoShapeEdgePy.h"
55
 
#include "TopoShapeFacePy.h"
56
53
 
57
54
using namespace Part;
58
55
 
59
56
// returns a string which represents the object e.g. when printed in python
60
 
const char *GeometryPy::representation(void) const
 
57
std::string GeometryPy::representation(void) const
61
58
{
62
59
    return "<Geometry object>";
63
60
}
108
105
        return 0;
109
106
 
110
107
    Base::Placement* plm = static_cast<Base::PlacementPy*>(o)->getPlacementPtr();
111
 
    Base::Rotation rot(plm->_rot);
 
108
    Base::Rotation rot(plm->getRotation());
112
109
    Base::Vector3d pnt, dir;
113
110
    double angle;
114
111
 
115
112
    rot.getValue(dir, angle);
116
 
    pnt = plm->_pos;
 
113
    pnt = plm->getPosition();
117
114
    
118
115
    gp_Ax1 ax1(gp_Pnt(pnt.x,pnt.y,pnt.z), gp_Dir(dir.x,dir.y,dir.z));
119
116
    getGeometryPtr()->handle()->Rotate(ax1, angle);
155
152
                  mat[1][0],mat[1][1],mat[1][2],mat[1][3],
156
153
                  mat[2][0],mat[2][1],mat[2][2],mat[2][3],
157
154
                  0.00001,0.00001);
158
 
    trf.SetScaleFactor(mat[3][3]);
159
155
    getGeometryPtr()->handle()->Transform(trf);
160
156
    Py_Return;
161
157
}
183
179
    return 0;
184
180
}
185
181
 
186
 
PyObject* GeometryPy::toShape(PyObject *args)
187
 
{
188
 
    Handle_Geom_Geometry g = getGeometryPtr()->handle();
189
 
    Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
190
 
    Handle_Geom_Surface s = Handle_Geom_Surface::DownCast(g);
191
 
    try {
192
 
        if (!c.IsNull()) {
193
 
            double u,v;
194
 
            u=c->FirstParameter();
195
 
            v=c->LastParameter();
196
 
            if (!PyArg_ParseTuple(args, "|dd", &u,&v))
197
 
                return 0;
198
 
            BRepBuilderAPI_MakeEdge mkBuilder(c, u, v);
199
 
            TopoDS_Shape sh = mkBuilder.Shape();
200
 
            return new TopoShapeEdgePy(new TopoShape(sh));
201
 
        }
202
 
        if (!s.IsNull()) {
203
 
            double u1,u2,v1,v2;
204
 
            s->Bounds(u1,u2,v1,v2);
205
 
            if (!PyArg_ParseTuple(args, "|dddd", &u1,&u2,&v1,&v2))
206
 
                return 0;
207
 
            BRepBuilderAPI_MakeFace mkBuilder(s, u1, u2, v1, v2);
208
 
            TopoDS_Shape sh = mkBuilder.Shape();
209
 
            return new TopoShapeFacePy(new TopoShape(sh));
210
 
        }
211
 
    }
212
 
    catch (Standard_Failure) {
213
 
        Handle_Standard_Failure e = Standard_Failure::Caught();
214
 
        PyErr_SetString(PyExc_Exception, e->GetMessageString());
215
 
        return 0;
216
 
    }
217
 
 
218
 
    PyErr_SetString(PyExc_Exception, "Geometry is neither curve nor surface");
219
 
    return 0;
220
 
}
221
 
 
222
 
PyObject* GeometryPy::value(PyObject *args)
223
 
{
224
 
    Handle_Geom_Geometry g = getGeometryPtr()->handle();
225
 
    Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
226
 
    Handle_Geom_Surface s = Handle_Geom_Surface::DownCast(g);
227
 
    try {
228
 
        if (!c.IsNull()) {
229
 
            double u;
230
 
            if (!PyArg_ParseTuple(args, "d", &u))
231
 
                return 0;
232
 
            gp_Pnt p = c->Value(u);
233
 
            return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z()));
234
 
        }
235
 
        if (!s.IsNull()) {
236
 
            double u,v;
237
 
            if (!PyArg_ParseTuple(args, "dd", &u,&v))
238
 
                return 0;
239
 
            gp_Pnt p = s->Value(u,v);
240
 
            return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z()));
241
 
        }
242
 
    }
243
 
    catch (Standard_Failure) {
244
 
        Handle_Standard_Failure e = Standard_Failure::Caught();
245
 
        PyErr_SetString(PyExc_Exception, e->GetMessageString());
246
 
        return 0;
247
 
    }
248
 
 
249
 
    PyErr_SetString(PyExc_Exception, "Geometry is neither curve nor surface");
250
 
    return 0;
251
 
}
252
 
 
253
182
PyObject *GeometryPy::getCustomAttributes(const char* /*attr*/) const
254
183
{
255
184
    return 0;