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