]> Shamusworld >> Repos - architektonas/blob - src/structs.h
20a03d264ba0016e3a03835bacf6f7d209750540
[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, OTPolyline, 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, TTParallel };
16
17 enum ToolState { TSNone, TSPoint1, TSPoint2, TSPoint3, TSPoint4, TSDone };
18
19 enum BasicUnit { BUInch = 0, BUFoot, BUYard, BUMile, BUMM, BUCM, BUM, BUKM, BUCount };
20
21 const char objName[OTCount][16] = {
22         "None", "Line", "Circle", "Ellipse", "Arc", "Polygon", "Dimension",
23         "Spline", "Text", "Container"
24 };
25 const char dimName[DTCount][32] = {
26         "Linear", "Vertical", "Horizontal", "Radial", "Diametric",
27         "Circumferential", "Angular", "Leader"
28 };
29
30 const char buShortName[BUCount][8] = {
31         "in", "ft", "yd", "mi", "mm", "cm", "m", "km"
32 };
33
34 const double buInInches[BUCount] = { 1.0, 12.0, 36.0, 1.0/25.4, 1.0/2.54, 1.0/0.0254, 1.0/0.0000254 };
35
36 #define OBJECT_COMMON \
37         int type;         \
38         uint32_t id;      \
39         int layer;        \
40         uint32_t color;   \
41         float thickness;  \
42         int style;        \
43         bool selected;    \
44         bool hovered;     \
45         bool hitPoint[5]; \
46         bool hitObject;   \
47         Point p[5];       \
48         double angle[3];  \
49         double radius[2]; \
50         double length;
51
52 struct Object {
53         OBJECT_COMMON;
54 };
55
56 struct Line {
57         OBJECT_COMMON;
58
59         Line(): type(OTLine), id(Global::objectID++), selected(false), hovered(false), hitObject(false) { hitPoint[0] = hitPoint[1] = false; }
60         Line(Vector pt1, Vector pt2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
61                 type(OTLine), id(Global::objectID++), layer(0), color(c), thickness(th),
62                 style(l), selected(false), hovered(false), hitObject(false) { p[0] = pt1; p[1] = pt2; hitPoint[0] = hitPoint[1] = false; }
63         Vector Vect(void) { return Vector(p[0], p[1]); }
64         Vector Unit(void) { return Vector(p[0], p[1]).Unit(); }
65         double Length(void) { return Vector(p[0], p[1]).Magnitude(); }
66 };
67
68 struct Circle {
69         OBJECT_COMMON;
70
71         Circle(): type(OTCircle), id(Global::objectID++) {}
72         Circle(Vector pt1, double r, float th = 1.0, uint32_t c = 0, int l = LSSolid):
73                 type(OTCircle), id(Global::objectID++), layer(0), color(c), thickness(th),
74                 style(l), selected(false), hovered(false), hitObject(false)
75                 { p[0] = pt1; radius[0] = r; hitPoint[0] = hitPoint[1] = false; }
76 };
77
78 struct Ellipse {
79         OBJECT_COMMON;
80
81         Ellipse(): type(OTEllipse), id(Global::objectID++) {}
82         Ellipse(Vector pt1, Vector pt2, double r1, double r2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
83                 type(OTEllipse), id(Global::objectID++), layer(0), color(c), thickness(th),
84                 style(l), selected(false), hovered(false), hitObject(false)
85                 { p[0] = pt1; p[1] = pt2; radius[0] = r1; radius[1] = r2; hitPoint[0] = hitPoint[1] = false; }
86 };
87
88 struct Arc {
89         OBJECT_COMMON;
90
91         Arc(): type(OTArc), id(Global::objectID++) {}
92         Arc(Vector pt1, double r, double a1, double a2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
93                 type(OTArc), id(Global::objectID++), layer(0), color(c), thickness(th),
94                 style(l), selected(false), hovered(false), hitObject(false)
95                 { p[0] = pt1; radius[0] = r; angle[0] = a1, angle[1] = a2; hitPoint[0] = hitPoint[1] = hitPoint[2] = false; }
96 };
97
98 struct Dimension {
99         OBJECT_COMMON;
100         int subtype;
101         double offset;
102         Point lp[2];            // Line point, the actual dimension line
103         Object * obj[2];        // Pointer to attached objects (circle, lines for angle)
104
105         Dimension(): type(OTDimension), id(Global::objectID++), selected(false),
106                 hovered(false), hitObject(false)
107                 { hitPoint[0] = hitPoint[1] = hitPoint[2] = hitPoint[3] = hitPoint[4] = false; }
108         Dimension(Vector pt1, Vector pt2, DimensionType dt = DTLinear, double offs = 0, float th = 1.0, uint32_t c = 0x0000FF, int l = LSSolid):
109                 type(OTDimension), id(Global::objectID++), layer(0), color(c),
110                 thickness(th), style(l), selected(false), hovered(false),
111                 hitObject(false), subtype(dt), offset(offs)
112                 { p[0] = pt1; p[1] = pt2; hitPoint[0] = hitPoint[1] = hitPoint[2] = hitPoint[3] = hitPoint[4] = false; }
113 };
114
115 struct Text {
116         OBJECT_COMMON;
117         Rect extents;
118         bool measured;
119         std::string s;
120
121         Text(): type(OTText), id(Global::objectID++) {}
122         Text(Vector pt1, char * str, float th = 10.0, uint32_t c = 0):
123                 type(OTText), id(Global::objectID++), layer(0), color(c), thickness(th),
124                 style(LSSolid), selected(false), hovered(false), hitObject(false),
125                 measured(false), s(str) { p[0] = pt1; angle[0] = 0; }
126 };
127
128 struct Polygon {
129         OBJECT_COMMON;
130         int sides;
131
132         Polygon(): type(OTPolygon), id(Global::objectID++) {}
133 };
134
135 struct Polyline {
136         OBJECT_COMMON;
137         VPVector objects;
138         bool closed;
139         Object * clicked;
140
141         Polyline(): type(OTPolyline), id(Global::objectID++), selected(false), hovered(false), hitObject(false), clicked(NULL) {}
142         void Add(void * obj) { objects.push_back(obj); }
143         void Add(VPVector objs) { objects.insert(objects.end(), objs.begin(), objs.end()); }
144 };
145
146 struct Spline {
147         OBJECT_COMMON;
148
149         Spline(): type(OTSpline), id(Global::objectID++) {}
150 };
151
152 struct Container {
153         OBJECT_COMMON;
154         VPVector objects;
155         double scale;
156         bool topLevel;
157         Object * clicked;
158
159         Container(bool tl = false): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false), topLevel(tl), clicked(NULL) {}
160         void Add(void * obj) { objects.push_back(obj); }
161         void Add(VPVector objs) { objects.insert(objects.end(), objs.begin(), objs.end()); }
162 //      void DeleteContents(void) {}
163 /*      void DeleteContents(Container * c)
164         {
165                 std::vector<void *>::iterator i;
166
167                 for(i=c->objects.begin(); i!=c->objects.end(); i++)
168                 {
169                         Object * obj = (Object *)(*i);
170
171                         if (obj->type == OTContainer)
172                                 DeleteContainer((Container *)obj);
173
174                         delete *i;
175                 }
176         }*/
177 };
178
179 #endif  // __STRUCTS_H__