FreeCAD

Форк
0
/
OffsetSurfacePyImp.cpp 
132 строки · 4.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 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 <Geom_OffsetSurface.hxx>
26
# include <memory>
27
#endif
28

29
#include "OCCError.h"
30
#include "OffsetSurfacePy.h"
31
#include "OffsetSurfacePy.cpp"
32

33

34
using namespace Part;
35

36
// returns a string which represents the object e.g. when printed in python
37
std::string OffsetSurfacePy::representation() const
38
{
39
    return "<OffsetSurface object>";
40
}
41

42
PyObject *OffsetSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
43
{
44
    // create a new instance of OffsetSurfacePy and the Twin object
45
    return new OffsetSurfacePy(new GeomOffsetSurface);
46
}
47

48
// constructor method
49
int OffsetSurfacePy::PyInit(PyObject* args, PyObject* /*kwd*/)
50
{
51
    PyObject* pGeom;
52
    double offset;
53
    if (!PyArg_ParseTuple(args, "O!d",
54
                            &(GeometryPy::Type), &pGeom,
55
                            &offset))
56
        return -1;
57

58
    GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
59
    Handle(Geom_Surface) surf = Handle(Geom_Surface)::DownCast
60
        (pcGeo->getGeometryPtr()->handle());
61
    if (surf.IsNull()) {
62
        PyErr_SetString(PyExc_TypeError, "geometry is not a surface");
63
        return -1;
64
    }
65

66
    try {
67
        Handle(Geom_OffsetSurface) surf2 = new Geom_OffsetSurface(surf, offset);
68
        getGeomOffsetSurfacePtr()->setHandle(surf2);
69
        return 0;
70
    }
71
    catch (Standard_Failure& e) {
72

73
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
74
        return -1;
75
    }
76
}
77

78
Py::Float OffsetSurfacePy::getOffsetValue() const
79
{
80
    Handle(Geom_OffsetSurface) surf = Handle(Geom_OffsetSurface)::DownCast(getGeometryPtr()->handle());
81
    return Py::Float(surf->Offset());
82
}
83

84
void  OffsetSurfacePy::setOffsetValue(Py::Float arg)
85
{
86
    Handle(Geom_OffsetSurface) surf = Handle(Geom_OffsetSurface)::DownCast(getGeometryPtr()->handle());
87
    surf->SetOffsetValue((double)arg);
88
}
89

90
Py::Object OffsetSurfacePy::getBasisSurface() const
91
{
92
    Handle(Geom_OffsetSurface) surf = Handle(Geom_OffsetSurface)::DownCast
93
        (getGeometryPtr()->handle());
94
    if (surf.IsNull()) {
95
        throw Py::TypeError("geometry is not a surface");
96
    }
97

98
    std::unique_ptr<GeomSurface> geo(makeFromSurface(surf->BasisSurface()));
99
    return Py::asObject(geo->getPyObject());
100
}
101

102
void  OffsetSurfacePy::setBasisSurface(Py::Object arg)
103
{
104
    PyObject* p = arg.ptr();
105
    if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
106
        GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
107
        Handle(Geom_Surface) surf = Handle(Geom_Surface)::DownCast
108
            (pcGeo->getGeometryPtr()->handle());
109
        if (surf.IsNull()) {
110
            throw Py::TypeError("geometry is not a surface");
111
        }
112

113
        try {
114
            Handle(Geom_OffsetSurface) surf2 = Handle(Geom_OffsetSurface)::DownCast
115
                (getGeometryPtr()->handle());
116
            surf2->SetBasisSurface(surf);
117
        }
118
        catch (Standard_Failure& e) {
119
            throw Py::RuntimeError(e.GetMessageString());
120
        }
121
    }
122
}
123

124
PyObject *OffsetSurfacePy::getCustomAttributes(const char* /*attr*/) const
125
{
126
    return nullptr;
127
}
128

129
int OffsetSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
130
{
131
    return 0;
132
}
133

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

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

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

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