]> Shamusworld >> Repos - architektonas/blob - src/structs.h
54e2f51bffb088afd2476e1e67a46363b8216c78
[architektonas] / src / structs.h
1 #ifndef __STRUCTS_H__
2 #define __STRUCTS_H__
3
4 #include <stdint.h>
5 #include <vector>
6 #include <string>
7 #include "global.h"
8 #include "vector.h"
9
10 enum ObjectType { OTNone = 0, OTLine, OTCircle, OTEllipse, OTArc, OTPolygon, OTDimension, OTSpline, OTText, OTContainer, OTCount };
11
12 enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader };
13
14 enum ToolType { TTNone, TTLine, TTCircle, TTEllipse, TTArc, TTDimension, TTText, TTPolygon, TTSpline, TTRotate, TTMirror, TTTrim, TTTriangulate, TTDelete };
15
16 enum ToolState { TSNone, TSPoint1, TSPoint2, TSPoint3, TSPoint4, TSDone };
17
18 #define OBJECT_COMMON \
19         int type;         \
20         uint32_t id;      \
21         int layer;        \
22         uint32_t color;   \
23         float thickness;  \
24         int style;        \
25         bool selected;    \
26         bool hovered;     \
27         bool hitPoint[5]; \
28         bool hitObject;   \
29         Point p[5];       \
30         double angle[2];  \
31         double radius[2];
32
33 struct Line {
34         OBJECT_COMMON;
35
36         Line(): type(OTLine), id(Global::objectID++) {}
37         Line(Vector pt1, Vector pt2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
38                 type(OTLine), id(Global::objectID++), layer(0), color(c), thickness(th),
39                 style(l), selected(false), hovered(false), hitObject(false) { p[0] = pt1; p[1] = pt2; }
40 };
41
42 struct Circle {
43         OBJECT_COMMON;
44
45         Circle(): type(OTCircle), id(Global::objectID++) {}
46         Circle(Vector pt1, double r, float th = 1.0, uint32_t c = 0, int l = LSSolid):
47                 type(OTCircle), id(Global::objectID++), layer(0), color(c), thickness(th),
48                 style(l), selected(false), hovered(false), hitObject(false)
49                 { p[0] = pt1; radius[0] = r; }
50 };
51
52 struct Ellipse {
53         OBJECT_COMMON;
54
55         Ellipse(): type(OTEllipse), id(Global::objectID++) {}
56         Ellipse(Vector pt1, Vector pt2, double r1, double r2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
57                 type(OTEllipse), id(Global::objectID++), layer(0), color(c), thickness(th),
58                 style(l), selected(false), hovered(false), hitObject(false)
59                 { p[0] = pt1; p[1] = pt2; radius[0] = r1; radius[1] = r2; }
60 };
61
62 struct Arc {
63         OBJECT_COMMON;
64
65         Arc(): type(OTArc), id(Global::objectID++) {}
66         Arc(Vector pt1, double r, double a1, double a2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
67                 type(OTArc), id(Global::objectID++), layer(0), color(c), thickness(th),
68                 style(l), selected(false), hovered(false), hitObject(false)
69                 { p[0] = pt1; radius[0] = r; angle[0] = a1, angle[1] = a2; }
70 };
71
72 struct Dimension {
73         OBJECT_COMMON;
74         int subtype;
75         double offset;
76         Point lp[2];    // Line point, the actual dimension line
77
78         Dimension(): type(OTDimension), id(Global::objectID++) {}
79         Dimension(Vector pt1, Vector pt2, DimensionType dt = DTLinear, float th = 1.0, uint32_t c = 0x0000FF, int l = LSSolid):
80                 type(OTDimension), id(Global::objectID++), layer(0), color(c),
81                 thickness(th), style(l), selected(false), hovered(false),
82                 hitObject(false), subtype(dt), offset(0) { p[0] = pt1; p[1] = pt2; }
83 };
84
85 struct Text {
86         OBJECT_COMMON;
87         std::string s;
88
89         Text(): type(OTText), id(Global::objectID++) {}
90         Text(Vector pt1, char * str, float th = 10.0, uint32_t c = 0):
91                 type(OTText), id(Global::objectID++), layer(0), color(c), thickness(th),
92                 style(LSSolid), selected(false), hovered(false), hitObject(false), s(str) { p[0] = pt1; }
93 };
94
95 struct Polygon {
96         OBJECT_COMMON;
97
98         Polygon(): type(OTPolygon), id(Global::objectID++) {}
99 };
100
101 struct Spline {
102         OBJECT_COMMON;
103
104         Spline(): type(OTSpline), id(Global::objectID++) {}
105 };
106
107 struct Container {
108         OBJECT_COMMON;
109         std::vector<void *> objects;
110         double scale;
111         bool topLevel;
112
113         Container(bool tl = false): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false), topLevel(tl) {}
114 //      void DeleteContents(void) {}
115 /*      void DeleteContents(Container * c)
116         {
117                 std::vector<void *>::iterator i;
118
119                 for(i=c->objects.begin(); i!=c->objects.end(); i++)
120                 {
121                         Object * obj = (Object *)(*i);
122
123                         if (obj->type == OTContainer)
124                                 DeleteContainer((Container *)obj);
125
126                         delete *i;
127                 }
128         }*/
129 };
130
131 struct Object {
132         OBJECT_COMMON;
133 };
134
135 #endif  // __STRUCTS_H__
136