File size: 8,006 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
/***************************************************************************
 *   Copyright (c) 2019 WandererFan <wandererfan@gmail.com>                *
 *                                                                         *
 *   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 TECHDRAW_CENTERLINE_H
#define TECHDRAW_CENTERLINE_H

#include <App/FeaturePython.h>
#include <Base/Persistence.h>
#include <Base/Vector3D.h>
#include <Mod/TechDraw/TechDrawGlobal.h>

#include "Tag.h"
#include "Cosmetic.h"
#include "Geometry.h"


namespace TechDraw {
class DrawViewPart;

class TechDrawExport CenterLine: public Base::Persistence, public TechDraw::Tag
{
    TYPESYSTEM_HEADER_WITH_OVERRIDE();

public:
    enum class Mode
    {
        VERTICAL,
        HORIZONTAL,
        ALIGNED
    };
    // TODO: when C++ 20
    // using Mode;
    enum class Type
    {
        FACE,
        EDGE,
        VERTEX
    };  // TODO: Make this global
    // TODO: when C++ 20
    // using Mode;

    template <typename U, std::enable_if_t<
        std::is_same_v<CenterLine::Type, U> ||
        std::is_same_v<CenterLine::Mode, U>,
        bool
    > =true>
    friend std::ostream& operator<<(std::ostream& out, const U& type) {
        out << static_cast<int>(type);
        return out;
    }

    CenterLine();
    CenterLine(const CenterLine* cl);
    //set m_faces after using next 3 ctors
    CenterLine(const TechDraw::BaseGeomPtr& bg,
               const Mode m = Mode::VERTICAL,
               const double h = 0.0,
               const double v = 0.0,
               const double r = 0.0,
               const double x = 0.0);
    CenterLine(const Base::Vector3d& p1, const Base::Vector3d& p2,
               const Mode m = Mode::VERTICAL,
               const double h = 0.0,
               const double v = 0.0,
               const double r = 0.0,
               const double x = 0.0);
    ~CenterLine() override;

    TechDraw::BaseGeomPtr BaseGeomPtrFromVectors(Base::Vector3d pt1, Base::Vector3d pt2);

    // Persistence implementer ---------------------
    unsigned int getMemSize() const override;
    void Save(Base::Writer &/*writer*/) const override;
    void Restore(Base::XMLReader &/*reader*/) override;

    PyObject *getPyObject() override;
    CenterLine* copy() const;
    CenterLine* clone() const;

    std::string toString() const;

    static CenterLine* CenterLineBuilder(const TechDraw::DrawViewPart* partFeat,
                                         const std::vector<std::string>& subs,
                                         const Mode mode = Mode::VERTICAL,
                                         const bool flip = false);
    TechDraw::BaseGeomPtr scaledGeometry(const TechDraw::DrawViewPart* partFeat);
    TechDraw::BaseGeomPtr scaledAndRotatedGeometry(TechDraw::DrawViewPart* partFeat);

    static std::pair<Base::Vector3d, Base::Vector3d> rotatePointsAroundMid(
                                          const Base::Vector3d& p1,
                                          const Base::Vector3d& p2,
                                          const Base::Vector3d& mid,
                                          const double rotate);
    static std::pair<Base::Vector3d, Base::Vector3d> calcEndPointsNoRef(
                                                          const Base::Vector3d& start,
                                                          const Base::Vector3d& end,
                                                          const double scale,
                                                          const double ext,
                                                          const double hShift,
                                                          const double vShift,
                                                          const double rotate,
                                                          const double viewAngleDeg);
    static std::pair<Base::Vector3d, Base::Vector3d> calcEndPoints(
                                          const TechDraw::DrawViewPart* partFeat,
                                          const std::vector<std::string>& faceNames,
                                          const Mode mode,
                                          const double ext,
                                          const double m_hShift,
                                          const double m_vShift,
                                          const double rotate);
    static std::pair<Base::Vector3d, Base::Vector3d> calcEndPoints2Lines(
                                          const TechDraw::DrawViewPart* partFeat,
                                          const std::vector<std::string>& faceNames,
                                          const Mode mode,
                                          const double ext,
                                          const double m_hShift,
                                          const double m_vShift,
                                          const double rotate,
                                          const bool flip);
    static std::pair<Base::Vector3d, Base::Vector3d> calcEndPoints2Points(
                                          const TechDraw::DrawViewPart* partFeat,
                                          const std::vector<std::string>& faceNames,
                                          const Mode mode,
                                          const double ext,
                                          const double m_hShift,
                                          const double m_vShift,
                                          const double rotate,
                                          const bool flip);
    void dump(const char* title);
    void setShifts(const double h, const double v);
    double getHShift() const;
    double getVShift() const;
    void setRotate(const double r);
    double getRotate() const;
    void setExtend(const double e);
    double getExtend() const;
    void setFlip(const bool f);
    bool getFlip() const;
    void setType(const Type type) { m_type = type; };
    Type getType() const { return m_type; }

    Base::Vector3d m_start;
    Base::Vector3d m_end;

    //required to recalculate CL after source geom changes.
    std::vector<std::string> m_faces;
    std::vector<std::string> m_edges;
    std::vector<std::string> m_verts;
    Type m_type;
    Mode m_mode;
    double m_hShift;
    double m_vShift;
    double m_rotate;
    double m_extendBy;
    LineFormat m_format;
    bool m_flip2Line;

    TechDraw::BaseGeomPtr m_geometry;

protected:
    void initialize();

    Py::Object PythonObject;
};

}  // namespace TechDraw

#endif  // TECHDRAW_CENTERLINE_H