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