]> Shamusworld >> Repos - architektonas/blob - src/structs.h
Make selections encompass Dimension objects.
[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         Object * obj[2];        // Pointer to attached objects (circle, lines for angle)
78
79         Dimension(): type(OTDimension), id(Global::objectID++) {}
80         Dimension(Vector pt1, Vector pt2, DimensionType dt = DTLinear, float th = 1.0, uint32_t c = 0x0000FF, int l = LSSolid):
81                 type(OTDimension), id(Global::objectID++), layer(0), color(c),
82                 thickness(th), style(l), selected(false), hovered(false),
83                 hitObject(false), subtype(dt), offset(0) { p[0] = pt1; p[1] = pt2; }
84 };
85
86 struct Text {
87         OBJECT_COMMON;
88         std::string s;
89
90         Text(): type(OTText), id(Global::objectID++) {}
91         Text(Vector pt1, char * str, float th = 10.0, uint32_t c = 0):
92                 type(OTText), id(Global::objectID++), layer(0), color(c), thickness(th),
93                 style(LSSolid), selected(false), hovered(false), hitObject(false), s(str) { p[0] = pt1; }
94 };
95
96 struct Polygon {
97         OBJECT_COMMON;
98
99         Polygon(): type(OTPolygon), id(Global::objectID++) {}
100 };
101
102 struct Spline {
103         OBJECT_COMMON;
104
105         Spline(): type(OTSpline), id(Global::objectID++) {}
106 };
107
108 struct Container {
109         OBJECT_COMMON;
110         std::vector<void *> objects;
111         double scale;
112         bool topLevel;
113
114         Container(bool tl = false): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false), topLevel(tl) {}
115 //      void DeleteContents(void) {}
116 /*      void DeleteContents(Container * c)
117         {
118                 std::vector<void *>::iterator i;
119
120                 for(i=c->objects.begin(); i!=c->objects.end(); i++)
121                 {
122                         Object * obj = (Object *)(*i);
123
124                         if (obj->type == OTContainer)
125                                 DeleteContainer((Container *)obj);
126
127                         delete *i;
128                 }
129         }*/
130 };
131
132 struct Object {
133         OBJECT_COMMON;
134 };
135
136 #endif  // __STRUCTS_H__
137