aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/modelinglib/qmt/stereotype/shapes.h
blob: 145fcb4bb6a35e12c19b7148a6ebca1042f45848 (plain)
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
/****************************************************************************
**
** Copyright (C) 2016 Jochen Becher
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#pragma once

#include "shape.h"
#include "qmt/infrastructure/qmt_global.h"

#include "shapevalue.h"
#include "shapevisitor.h"

#include <QList>

namespace qmt {

class QMT_EXPORT LineShape : public IShape
{
public:
    LineShape() = default;

    LineShape(const ShapePointF &pos1, const ShapePointF &pos2)
        : m_pos1(pos1),
          m_pos2(pos2)
    {
    }

    ShapePointF pos1() const { return m_pos1; }
    ShapePointF pos2() const { return m_pos2; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_pos1;
    ShapePointF m_pos2;
};

class QMT_EXPORT RectShape : public IShape
{
public:
    RectShape() = default;

    RectShape(const ShapePointF &pos, const ShapeSizeF &size)
        : m_pos(pos),
          m_size(size)
    {
    }

    ShapePointF pos() const { return m_pos; }
    ShapeSizeF size() const { return m_size; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_pos;
    ShapeSizeF m_size;
};

class QMT_EXPORT RoundedRectShape : public IShape
{
public:
    RoundedRectShape() = default;

    RoundedRectShape(const ShapePointF &pos, const ShapeSizeF &size, const ShapeValueF &radius)
        : m_pos(pos),
          m_size(size),
          m_radius(radius)
    {
    }

    ShapePointF pos() const { return m_pos; }
    ShapeSizeF size() const { return m_size; }
    ShapeValueF radius() const { return m_radius; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_pos;
    ShapeSizeF m_size;
    ShapeValueF m_radius;
};

class QMT_EXPORT CircleShape : public IShape
{
public:
    CircleShape() = default;

    CircleShape(const ShapePointF &center, const ShapeValueF &radius)
        : m_center(center),
          m_radius(radius)
    {
    }

    ShapePointF center() const { return m_center; }
    ShapeValueF radius() const { return m_radius; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_center;
    ShapeValueF m_radius;
};

class QMT_EXPORT EllipseShape : public IShape
{
public:
    EllipseShape() = default;

    EllipseShape(const ShapePointF &center, const ShapeSizeF &radius)
        : m_center(center),
          m_radius(radius)
    {
    }

    ShapePointF center() const { return m_center; }
    ShapeSizeF radius() const { return m_radius; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_center;
    ShapeSizeF m_radius;
};

class QMT_EXPORT DiamondShape : public IShape
{
public:
    DiamondShape() = default;

    DiamondShape(const ShapePointF &center, const ShapeSizeF &size, bool filled)
        : m_center(center),
          m_size(size),
          m_filled(filled)
    {
    }

    ShapePointF center() const { return m_center; }
    ShapeSizeF size() const { return m_size; }
    bool filled() const { return m_filled; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_center;
    ShapeSizeF m_size;
    bool m_filled = false;
};

class QMT_EXPORT TriangleShape : public IShape
{
public:
    TriangleShape() = default;

    TriangleShape(const ShapePointF &center, const ShapeSizeF &size, bool filled)
        : m_center(center),
          m_size(size),
          m_filled(filled)
    {
    }

    ShapePointF center() const { return m_center; }
    ShapeSizeF size() const { return m_size; }
    bool filled() const { return m_filled; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_center;
    ShapeSizeF m_size;
    bool m_filled = false;
};

class QMT_EXPORT ArcShape : public IShape
{
public:
    ArcShape() = default;

    ArcShape(const ShapePointF &center, const ShapeSizeF &radius, qreal startAngle, qreal spanAngle)
        : m_center(center),
          m_radius(radius),
          m_startAngle(startAngle),
          m_spanAngle(spanAngle)
    {
    }

    ShapePointF center() const { return m_center; }
    ShapeSizeF radius() const { return m_radius; }
    qreal startAngle() const { return m_startAngle; }
    qreal spanAngle() const { return m_spanAngle; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

private:
    ShapePointF m_center;
    ShapeSizeF m_radius;
    qreal m_startAngle = 0.0;
    qreal m_spanAngle = 0.0;
};

class QMT_EXPORT PathShape : public IShape
{
public:
    enum ElementType {
        TypeNone,
        TypeMoveto,
        TypeLineto,
        TypeArcmoveto,
        TypeArcto,
        TypeClose
    };

    class Element
    {
    public:
        explicit Element(ElementType element = TypeNone)
            : m_elementType(element)
        {
        }

        ElementType m_elementType = TypeNone;
        ShapePointF m_position;
        ShapeSizeF m_size;
        qreal m_angle1 = 0.0;
        qreal m_angle2 = 0.0;
    };

    PathShape();
    ~PathShape() override;

    QList<Element> elements() const { return m_elements; }

    IShape *clone() const override;
    void accept(ShapeVisitor *visitor) override;
    void accept(ShapeConstVisitor *visitor) const override;

    void moveTo(const ShapePointF &pos);
    void lineTo(const ShapePointF &pos);
    void arcMoveTo(const ShapePointF &center, const ShapeSizeF &radius, qreal angle);
    void arcTo(const ShapePointF &center, const ShapeSizeF &radius,
               qreal startAngle, qreal sweepLength);
    void close();

private:
    QList<Element> m_elements;
};

} // namespace qmt