FreeCAD

Форк
0
/
PlateSurfacePyImp.cpp 
198 строк · 7.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2015 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 <GeomPlate_BuildPlateSurface.hxx>
26
# include <GeomPlate_MakeApprox.hxx>
27
# include <GeomPlate_PointConstraint.hxx>
28
# include <GeomPlate_Surface.hxx>
29
#endif
30

31
#include <Base/GeometryPyCXX.h>
32
#include <Base/PyWrapParseTupleAndKeywords.h>
33
#include <Base/VectorPy.h>
34
#include <Base/Vector3D.h>
35

36
#include "PlateSurfacePy.h"
37
#include "PlateSurfacePy.cpp"
38
#include "BSplineSurfacePy.h"
39
#include "OCCError.h"
40

41

42
using namespace Part;
43

44
// returns a string which represents the object e.g. when printed in python
45
std::string PlateSurfacePy::representation() const
46
{
47
    return "<PlateSurface object>";
48
}
49

50
PyObject *PlateSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
51
{
52
    // create a new instance of PlateSurfacePy and the Twin object
53
    return new PlateSurfacePy(new GeomPlateSurface);
54
}
55

56
// constructor method
57
int PlateSurfacePy::PyInit(PyObject* args, PyObject* kwds)
58
{
59
    static const std::array<const char *, 12> kwds_Parameter{"Surface", "Points", "Curves", "Degree",
60
                                                             "NbPtsOnCur", "NbIter", "Tol2d", "Tol3d", "TolAng",
61
                                                             "TolCurv", "Anisotropie", nullptr};
62

63
    PyObject* surface = nullptr;
64
    PyObject* points = nullptr;
65
    PyObject* curves = nullptr;
66
    int Degree = 3;
67
    int NbPtsOnCur = 10;
68
    int NbIter = 3;
69
    double Tol2d = 0.00001;
70
    double Tol3d = 0.0001;
71
    double TolAng = 0.01;
72
    double TolCurv = 0.1;
73
    PyObject* Anisotropie = Py_False; // NOLINT
74

75
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|O!OOiiiddddO!", kwds_Parameter,
76
                                             &(GeometryPy::Type), &surface, &points, &curves,
77
                                             &Degree, &NbPtsOnCur, &NbIter, &Tol2d, &Tol3d, &TolAng, &TolCurv,
78
                                             &PyBool_Type, &Anisotropie)) {
79
        return -1;
80
    }
81

82
    if (!surface && !points && !curves) {
83
        PyErr_SetString(PyExc_ValueError, "set points or curves as constraints");
84
        return -1;
85
    }
86

87
    Handle(Geom_Surface) surf;
88
    if (surface) {
89
        GeometryPy* pcGeo = static_cast<GeometryPy*>(surface);
90
        surf = Handle(Geom_Surface)::DownCast
91
            (pcGeo->getGeometryPtr()->handle());
92
        if (surf.IsNull()) {
93
            PyErr_SetString(PyExc_TypeError, "geometry is not a surface");
94
            return -1;
95
        }
96
    }
97

98
    try {
99
        GeomPlate_BuildPlateSurface buildPlate(Degree, NbPtsOnCur, NbIter, Tol2d, Tol3d, TolAng, TolCurv,
100
            Base::asBoolean(Anisotropie));
101
        if (!surf.IsNull()) {
102
            buildPlate.LoadInitSurface(surf);
103

104
            if (!points && !curves) {
105
                Standard_Real U1,U2,V1,V2;
106
                surf->Bounds(U1,U2,V1,V2);
107
                buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U1,V1),0));
108
                buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U1,V2),0));
109
                buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U2,V1),0));
110
                buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U2,V2),0));
111
            }
112
        }
113

114
        if (points) {
115
            Py::Sequence list(points);
116
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
117
                Base::Vector3d vec = Py::Vector(*it).toVector();
118
                Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(gp_Pnt(vec.x,vec.y,vec.z),0);
119
                buildPlate.Add(PCont);
120
            }
121
        }
122

123
        if (curves) {
124
            Py::Sequence list(curves);
125
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
126
                //TODO
127
            }
128
        }
129

130
        buildPlate.Perform();
131
        getGeomPlateSurfacePtr()->setHandle(buildPlate.Surface());
132
        return 0;
133
    }
134
    catch (Standard_Failure& e) {
135

136
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
137
        return -1;
138
    }
139
}
140

141
PyObject* PlateSurfacePy::makeApprox(PyObject *args, PyObject* kwds)
142
{
143
    static const std::array<const char *, 8> kwds_Parameter{"Tol3d", "MaxSegments", "MaxDegree", "MaxDistance",
144
                                                            "CritOrder", "Continuity", "EnlargeCoeff", nullptr};
145

146
    double tol3d=0.01;
147
    int maxSeg=9;
148
    int maxDegree=3;
149
    double dmax = 0.0001;
150
    int critOrder=0;
151
    const char* cont = "C1";
152
    double enlargeCoeff = 1.1;
153

154
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|diidisd", kwds_Parameter,
155
                                             &tol3d, &maxSeg, &maxDegree, &dmax, &critOrder, &cont, &enlargeCoeff)) {
156
        return nullptr;
157
    }
158

159
    GeomAbs_Shape continuity;
160
    std::string uc = cont;
161
    if (uc == "C0")
162
        continuity = GeomAbs_C0;
163
    else if (uc == "C1")
164
        continuity = GeomAbs_C1;
165
    else if (uc == "C2")
166
        continuity = GeomAbs_C2;
167
    else if (uc == "C3")
168
        continuity = GeomAbs_C3;
169
    else if (uc == "CN")
170
        continuity = GeomAbs_CN;
171
    else if (uc == "G1")
172
        continuity = GeomAbs_G1;
173
    else
174
        continuity = GeomAbs_C1;
175

176
    PY_TRY {
177
        GeomPlate_MakeApprox approx(Handle(GeomPlate_Surface)::DownCast(getGeomPlateSurfacePtr()->handle()),
178
            tol3d, maxSeg, maxDegree, dmax, critOrder, continuity, enlargeCoeff);
179
        Handle(Geom_BSplineSurface) hSurf = approx.Surface();
180

181
        if (!hSurf.IsNull()) {
182
            return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf));
183
        }
184

185
        PyErr_SetString(PyExc_RuntimeError, "Approximation of B-spline surface failed");
186
        return nullptr;
187
    } PY_CATCH_OCC;
188
}
189

190
PyObject *PlateSurfacePy::getCustomAttributes(const char* /*attr*/) const
191
{
192
    return nullptr;
193
}
194

195
int PlateSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
196
{
197
    return 0;
198
}
199

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

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

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

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