FreeCAD

Форк
0
/
RectangularTrimmedSurfacePyImp.cpp 
130 строк · 5.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2010 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_RectangularTrimmedSurface.hxx>
26
#endif
27

28
#include "OCCError.h"
29

30
// inclusion of the generated files (generated out of RectangularTrimmedSurfacePy.xml)
31
#include "GeometryCurvePy.h"
32
#include "RectangularTrimmedSurfacePy.h"
33
#include "RectangularTrimmedSurfacePy.cpp"
34

35

36
using namespace Part;
37

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

44
PyObject *RectangularTrimmedSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
45
{
46
    // create a new instance of RectangularTrimmedSurfacePy and the Twin object
47
    return new RectangularTrimmedSurfacePy(new GeomTrimmedSurface);
48
}
49

50
// constructor method
51
int RectangularTrimmedSurfacePy::PyInit(PyObject* args, PyObject* /*kwd*/)
52
{
53
    PyObject* surf;
54
    double u1,u2,v1,v2;
55
    PyObject *usense=Py_True, *vsense=Py_True;
56
    if (PyArg_ParseTuple(args, "O!dddd|O!O!",&(Part::GeometrySurfacePy::Type),&surf,
57
                         &u1,&u2,&v1,&v2,&PyBool_Type,&usense,&PyBool_Type,&vsense)) {
58
        getGeomTrimmedSurfacePtr()->setHandle(new Geom_RectangularTrimmedSurface(
59
            Handle(Geom_Surface)::DownCast(static_cast<GeometrySurfacePy*>(surf)->
60
                getGeomSurfacePtr()->handle()),
61
            u1, u2, v1, v2,
62
            Base::asBoolean(usense),
63
            Base::asBoolean(vsense)
64
        ));
65
        return 0;
66
    }
67

68
    PyErr_Clear();
69
    double param1,param2;
70
    PyObject *utrim=Py_False, *sense=Py_True;
71
    if (PyArg_ParseTuple(args, "O!ddO!|O!",&(Part::GeometrySurfacePy::Type),&surf,
72
                         &param1,&param2,&PyBool_Type,&utrim,&PyBool_Type,&sense)) {
73
        Standard_Boolean UTrim = Base::asBoolean(utrim);
74
        Standard_Boolean Sense = Base::asBoolean(sense);
75
        getGeomTrimmedSurfacePtr()->setHandle(new Geom_RectangularTrimmedSurface(
76
            Handle(Geom_Surface)::DownCast(static_cast<GeometrySurfacePy*>(surf)->
77
                getGeomSurfacePtr()->handle()),
78
            param1, param2, UTrim, Sense
79
        ));
80
        return 0;
81
    }
82

83
    PyErr_SetString(PartExceptionOCCError, "A surface and the trim parameters must be given");
84
    return -1;
85
}
86

87
PyObject* RectangularTrimmedSurfacePy::setTrim(PyObject *args)
88
{
89
    double u1, u2, v1, v2;
90
    if (!PyArg_ParseTuple(args, "dddd", &u1, &u2, &v1, &v2))
91
        return nullptr;
92

93
    try {
94
        Handle(Geom_RectangularTrimmedSurface) surf = Handle(Geom_RectangularTrimmedSurface)::DownCast
95
            (getGeometryPtr()->handle());
96
        if (surf.IsNull()) {
97
            PyErr_SetString(PyExc_TypeError, "geometry is not a surface");
98
            return nullptr;
99
        }
100

101
        surf->SetTrim(u1, u2, v1, v2);
102
        Py_Return;
103
    }
104
    catch (const Standard_Failure& e) {
105
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
106
        return nullptr;
107
    }
108
}
109

110
Py::Object RectangularTrimmedSurfacePy::getBasisSurface() const
111
{
112
    Handle(Geom_RectangularTrimmedSurface) surf = Handle(Geom_RectangularTrimmedSurface)::DownCast
113
        (getGeometryPtr()->handle());
114
    if (surf.IsNull()) {
115
        throw Py::TypeError("geometry is not a surface");
116
    }
117

118
    std::unique_ptr<GeomSurface> geo(makeFromSurface(surf->BasisSurface()));
119
    return Py::asObject(geo->getPyObject());
120
}
121

122
PyObject *RectangularTrimmedSurfacePy::getCustomAttributes(const char* /*attr*/) const
123
{
124
    return nullptr;
125
}
126

127
int RectangularTrimmedSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
128
{
129
    return 0;
130
}
131

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

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

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

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