File size: 8,544 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// SPDX-License-Identifier: LGPL-2.1-or-later

/***************************************************************************

 *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net>     *

 *                                                                         *

 *   This file is part of the FreeCAD CAx development system.              *

 *                                                                         *

 *   This library is free software; you can redistribute it and/or         *

 *   modify it under the terms of the GNU Library General Public           *

 *   License as published by the Free Software Foundation; either          *

 *   version 2 of the License, or (at your option) any later version.      *

 *                                                                         *

 *   This library  is distributed in the hope that it will be useful,      *

 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *

 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *

 *   GNU Library General Public License for more details.                  *

 *                                                                         *

 *   You should have received a copy of the GNU Library General Public     *

 *   License along with this library; see the file COPYING.LIB. If not,    *

 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *

 *   Suite 330, Boston, MA  02111-1307, USA                                *

 *                                                                         *

 ***************************************************************************/

#ifndef INSPECTION_FEATURE_H
#define INSPECTION_FEATURE_H

#include <App/DocumentObject.h>
#include <App/DocumentObjectGroup.h>

#include <Mod/Inspection/InspectionGlobal.h>
#include <Mod/Points/App/Points.h>


class TopoDS_Shape;
class BRepExtrema_DistShapeShape;
class gp_Pnt;

namespace MeshCore
{
class MeshKernel;
class MeshGrid;
}  // namespace MeshCore

namespace Mesh
{
class MeshObject;
}
namespace Points
{
class PointsGrid;
}
namespace Part
{
class TopoShape;
}

namespace Inspection
{

/** Delivers the number of points to be checked and returns the appropriate point to an index. */
class InspectionExport InspectActualGeometry

{
public:
    InspectActualGeometry() = default;
    virtual ~InspectActualGeometry() = default;
    /// Number of points to be checked
    virtual unsigned long countPoints() const = 0;
    virtual Base::Vector3f getPoint(unsigned long) const = 0;
};

class InspectionExport InspectActualMesh: public InspectActualGeometry
{
public:
    explicit InspectActualMesh(const Mesh::MeshObject& rMesh);
    ~InspectActualMesh() override;
    unsigned long countPoints() const override;
    Base::Vector3f getPoint(unsigned long) const override;

private:
    const MeshCore::MeshKernel& _mesh;
    bool _bApply;
    Base::Matrix4D _clTrf;
};

class InspectionExport InspectActualPoints: public InspectActualGeometry
{
public:
    explicit InspectActualPoints(const Points::PointKernel&);
    unsigned long countPoints() const override;
    Base::Vector3f getPoint(unsigned long) const override;

private:
    const Points::PointKernel& _rKernel;
};

class InspectionExport InspectActualShape: public InspectActualGeometry
{
public:
    explicit InspectActualShape(const Part::TopoShape&);
    unsigned long countPoints() const override;
    Base::Vector3f getPoint(unsigned long) const override;

private:
    void fetchPoints(double deflection);

private:
    const Part::TopoShape& _rShape;
    std::vector<Base::Vector3d> points;
};

/** Calculates the shortest distance of the underlying geometry to a given point. */
class InspectionExport InspectNominalGeometry

{
public:
    InspectNominalGeometry() = default;
    virtual ~InspectNominalGeometry() = default;
    virtual float getDistance(const Base::Vector3f&) const = 0;
};

class InspectionExport InspectNominalMesh: public InspectNominalGeometry
{
public:
    InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset);
    ~InspectNominalMesh() override;
    float getDistance(const Base::Vector3f&) const override;

private:
    const MeshCore::MeshKernel& _mesh;
    MeshCore::MeshGrid* _pGrid;
    Base::BoundBox3f _box;
    bool _bApply;
    Base::Matrix4D _clTrf;
};

class InspectionExport InspectNominalFastMesh: public InspectNominalGeometry
{
public:
    InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset);
    ~InspectNominalFastMesh() override;
    float getDistance(const Base::Vector3f&) const override;

protected:
    const MeshCore::MeshKernel& _mesh;
    MeshCore::MeshGrid* _pGrid;
    Base::BoundBox3f _box;
    unsigned long max_level;
    bool _bApply;
    Base::Matrix4D _clTrf;
};

class InspectionExport InspectNominalPoints: public InspectNominalGeometry
{
public:
    InspectNominalPoints(const Points::PointKernel&, float offset);
    ~InspectNominalPoints() override;
    float getDistance(const Base::Vector3f&) const override;

private:
    const Points::PointKernel& _rKernel;
    Points::PointsGrid* _pGrid;
};

class InspectionExport InspectNominalShape: public InspectNominalGeometry
{
public:
    InspectNominalShape(const TopoDS_Shape&, float offset);
    ~InspectNominalShape() override;
    float getDistance(const Base::Vector3f&) const override;

private:
    bool isInsideSolid(const gp_Pnt&) const;
    bool isBelowFace(const gp_Pnt&) const;

private:
    BRepExtrema_DistShapeShape* distss;
    const TopoDS_Shape& _rShape;
    bool isSolid {false};
};

class InspectionExport PropertyDistanceList: public App::PropertyLists
{
    TYPESYSTEM_HEADER_WITH_OVERRIDE();

public:
    /**

     * A constructor.

     * A more elaborate description of the constructor.

     */
    PropertyDistanceList();

    /**

     * A destructor.

     * A more elaborate description of the destructor.

     */
    ~PropertyDistanceList() override;

    void setSize(int newSize) override;
    int getSize() const override;

    /** Sets the property

     */
    void setValue(float);

    /// index operator
    float operator[](const int idx) const
    {
        return _lValueList.operator[](idx);
    }

    void set1Value(const int idx, float value)
    {
        _lValueList.operator[](idx) = value;
    }
    void setValues(const std::vector<float>& values);

    const std::vector<float>& getValues() const
    {
        return _lValueList;
    }

    PyObject* getPyObject() override;
    void setPyObject(PyObject*) override;

    void Save(Base::Writer& writer) const override;
    void Restore(Base::XMLReader& reader) override;

    void SaveDocFile(Base::Writer& writer) const override;
    void RestoreDocFile(Base::Reader& reader) override;

    Property* Copy() const override;
    void Paste(const Property& from) override;
    unsigned int getMemSize() const override;

private:
    std::vector<float> _lValueList;
};

// ----------------------------------------------------------------

/** The inspection feature.

 * \author Werner Mayer

 */
class InspectionExport Feature: public App::DocumentObject
{
    PROPERTY_HEADER_WITH_OVERRIDE(Inspection::Feature);

public:
    /// Constructor
    Feature();
    ~Feature() override;

    /** @name Properties */
    //@{
    App::PropertyFloat SearchRadius;
    App::PropertyFloat Thickness;
    App::PropertyLink Actual;
    App::PropertyLinkList Nominals;
    PropertyDistanceList Distances;
    //@}

    /** @name Actions */
    //@{
    short mustExecute() const override;
    /// recalculate the Feature
    App::DocumentObjectExecReturn* execute() override;
    //@}

    /// returns the type name of the ViewProvider
    const char* getViewProviderName() const override
    {
        return "InspectionGui::ViewProviderInspection";
    }
};

class InspectionExport Group: public App::DocumentObjectGroup
{
    PROPERTY_HEADER_WITH_OVERRIDE(Inspection::Group);

public:
    /// Constructor
    Group();
    ~Group() override;

    /// returns the type name of the ViewProvider
    const char* getViewProviderName() const override
    {
        return "InspectionGui::ViewProviderInspectionGroup";
    }
};

}  // namespace Inspection


#endif  // INSPECTION_FEATURE_H