]> Shamusworld >> Repos - architektonas/blob - src/structs.h
Added Parallel tool + command processing.
[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 };
64
65 struct Circle {
66         OBJECT_COMMON;
67
68         Circle(): type(OTCircle), id(Global::objectID++) {}
69         Circle(Vector pt1, double r, float th = 1.0, uint32_t c = 0, int l = LSSolid):
70                 type(OTCircle), id(Global::objectID++), layer(0), color(c), thickness(th),
71                 style(l), selected(false), hovered(false), hitObject(false)
72                 { p[0] = pt1; radius[0] = r; hitPoint[0] = hitPoint[1] = false; }
73 };
74
75 struct Ellipse {
76         OBJECT_COMMON;
77
78         Ellipse(): type(OTEllipse), id(Global::objectID++) {}
79         Ellipse(Vector pt1, Vector pt2, double r1, double r2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
80                 type(OTEllipse), id(Global::objectID++), layer(0), color(c), thickness(th),
81                 style(l), selected(false), hovered(false), hitObject(false)
82                 { p[0] = pt1; p[1] = pt2; radius[0] = r1; radius[1] = r2; hitPoint[0] = hitPoint[1] = false; }
83 };
84
85 struct Arc {
86         OBJECT_COMMON;
87
88         Arc(): type(OTArc), id(Global::objectID++) {}
89         Arc(Vector pt1, double r, double a1, double a2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
90                 type(OTArc), id(Global::objectID++), layer(0), color(c), thickness(th),
91                 style(l), selected(false), hovered(false), hitObject(false)
92                 { p[0] = pt1; radius[0] = r; angle[0] = a1, angle[1] = a2; hitPoint[0] = hitPoint[1] = hitPoint[2] = false; }
93 };
94
95 struct Dimension {
96         OBJECT_COMMON;
97         int subtype;
98         double offset;
99         Point lp[2];            // Line point, the actual dimension line
100         Object * obj[2];        // Pointer to attached objects (circle, lines for angle)
101
102         Dimension(): type(OTDimension), id(Global::objectID++), selected(false),
103                 hovered(false), hitObject(false)
104                 { hitPoint[0] = hitPoint[1] = hitPoint[2] = hitPoint[3] = hitPoint[4] = false; }
105         Dimension(Vector pt1, Vector pt2, DimensionType dt = DTLinear, double offs = 0, float th = 1.0, uint32_t c = 0x0000FF, int l = LSSolid):
106                 type(OTDimension), id(Global::objectID++), layer(0), color(c),
107                 thickness(th), style(l), selected(false), hovered(false),
108                 hitObject(false), subtype(dt), offset(offs)
109                 { p[0] = pt1; p[1] = pt2; hitPoint[0] = hitPoint[1] = hitPoint[2] = hitPoint[3] = hitPoint[4] = false; }
110 };
111
112 struct Text {
113         OBJECT_COMMON;
114         Rect extents;
115         bool measured;
116         std::string s;
117
118         Text(): type(OTText), id(Global::objectID++) {}
119         Text(Vector pt1, char * str, float th = 10.0, uint32_t c = 0):
120                 type(OTText), id(Global::objectID++), layer(0), color(c), thickness(th),
121                 style(LSSolid), selected(false), hovered(false), hitObject(false),
122                 measured(false), s(str) { p[0] = pt1; angle[0] = 0; }
123 };
124
125 struct Polygon {
126         OBJECT_COMMON;
127         int sides;
128
129         Polygon(): type(OTPolygon), id(Global::objectID++) {}
130 };
131
132 struct Polyline {
133         OBJECT_COMMON;
134         VPVector objects;
135         bool closed;
136         Object * clicked;
137
138         Polyline(): type(OTPolyline), id(Global::objectID++), selected(false), hovered(false), hitObject(false), clicked(NULL) {}
139         void Add(void * obj) { objects.push_back(obj); }
140         void Add(VPVector objs) { objects.insert(objects.end(), objs.begin(), objs.end()); }
141 };
142
143 struct Spline {
144         OBJECT_COMMON;
145
146         Spline(): type(OTSpline), id(Global::objectID++) {}
147 };
148
149 struct Container {
150         OBJECT_COMMON;
151         VPVector objects;
152         double scale;
153         bool topLevel;
154         Object * clicked;
155
156         Container(bool tl = false): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false), topLevel(tl), clicked(NULL) {}
157         void Add(void * obj) { objects.push_back(obj); }
158         void Add(VPVector objs) { objects.insert(objects.end(), objs.begin(), objs.end()); }
159 //      void DeleteContents(void) {}
160 /*      void DeleteContents(Container * c)
161         {
162                 std::vector<void *>::iterator i;
163
164                 for(i=c->objects.begin(); i!=c->objects.end(); i++)
165                 {
166                         Object * obj = (Object *)(*i);
167
168                         if (obj->type == OTContainer)
169                                 DeleteContainer((Container *)obj);
170
171                         delete *i;
172                 }
173         }*/
174 };
175
176 #endif  // __STRUCTS_H__