]> Shamusworld >> Repos - architektonas/blobdiff - src/structs.h
Added base units & display style to drawing.
[architektonas] / src / structs.h
index f1b5ce1cf722dc06b6fd4b4050173f75f3834e17..47d8d85a50795519943efebfea49879502c303e2 100644 (file)
@@ -5,12 +5,33 @@
 #include <vector>
 #include <string>
 #include "global.h"
+#include "rect.h"
 #include "vector.h"
 
-enum ObjectType { OTNone, OTLine, OTCircle, OTEllipse, OTArc, OTDimension, OTSpline, OTText, OTContainer };
+enum ObjectType { OTNone = 0, OTLine, OTCircle, OTEllipse, OTArc, OTPolygon, OTDimension, OTSpline, OTText, OTContainer, OTPolyline, OTCount };
 
-enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader };
+enum DimensionType { DTLinear = 0, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader, DTCount };
 
+enum ToolType { TTNone, TTLine, TTCircle, TTEllipse, TTArc, TTDimension, TTText, TTPolygon, TTSpline, TTRotate, TTMirror, TTTrim, TTTriangulate, TTDelete, TTParallel };
+
+enum ToolState { TSNone, TSPoint1, TSPoint2, TSPoint3, TSPoint4, TSDone };
+
+enum BasicUnit { BUInch = 0, BUFoot, BUYard, BUMile, BUMM, BUCM, BUM, BUKM, BUCount };
+
+const char objName[OTCount][16] = {
+       "None", "Line", "Circle", "Ellipse", "Arc", "Polygon", "Dimension",
+       "Spline", "Text", "Container"
+};
+const char dimName[DTCount][32] = {
+       "Linear", "Vertical", "Horizontal", "Radial", "Diametric",
+       "Circumferential", "Angular", "Leader"
+};
+
+const char buShortName[BUCount][8] = {
+       "in", "ft", "yd", "mi", "mm", "cm", "m", "km"
+};
+
+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 };
 
 #define OBJECT_COMMON \
        int type;         \
@@ -21,90 +42,143 @@ enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric
        int style;        \
        bool selected;    \
        bool hovered;     \
-       bool hitPoint[4]; \
-       bool hitObject;
+       bool hitPoint[5]; \
+       bool hitObject;   \
+       Point p[5];       \
+       double angle[3];  \
+       double radius[2]; \
+       double length;
+
+struct Object {
+       OBJECT_COMMON;
+};
 
 struct Line {
        OBJECT_COMMON;
-       Point p1;
-       Point p2;
 
-       Line(): type(OTLine), id(Global::objectID++) {}
+       Line(): type(OTLine), id(Global::objectID++), selected(false), hovered(false), hitObject(false) { hitPoint[0] = hitPoint[1] = false; }
        Line(Vector pt1, Vector pt2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTLine), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), p1(pt1), p2(pt2) {}
+               style(l), selected(false), hovered(false), hitObject(false) { p[0] = pt1; p[1] = pt2; hitPoint[0] = hitPoint[1] = false; }
+       Vector Vect(void) { return Vector(p[0], p[1]); }
+       Vector Unit(void) { return Vector(p[0], p[1]).Unit(); }
+       double Length(void) { return Vector(p[0], p[1]).Magnitude(); }
 };
 
 struct Circle {
        OBJECT_COMMON;
-       Point p1;
-       double radius;
 
+       Circle(): type(OTCircle), id(Global::objectID++) {}
        Circle(Vector pt1, double r, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTCircle), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), p1(pt1), radius(r) {}
+               style(l), selected(false), hovered(false), hitObject(false)
+               { p[0] = pt1; radius[0] = r; hitPoint[0] = hitPoint[1] = false; }
 };
 
 struct Ellipse {
        OBJECT_COMMON;
-       Point p1;
-       Point p2;
-       double radius1;
-       double radius2;
 
+       Ellipse(): type(OTEllipse), id(Global::objectID++) {}
        Ellipse(Vector pt1, Vector pt2, double r1, double r2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTEllipse), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), p1(pt1), p2(pt2), radius1(r1), radius2(r2) {}
+               style(l), selected(false), hovered(false), hitObject(false)
+               { p[0] = pt1; p[1] = pt2; radius[0] = r1; radius[1] = r2; hitPoint[0] = hitPoint[1] = false; }
 };
 
 struct Arc {
        OBJECT_COMMON;
-       Point p1;
-       double radius;
-       double angle1;
-       double angle2;
 
+       Arc(): type(OTArc), id(Global::objectID++) {}
        Arc(Vector pt1, double r, double a1, double a2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTArc), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), p1(pt1), radius(r), angle1(a1), angle2(a2) {}
+               style(l), selected(false), hovered(false), hitObject(false)
+               { p[0] = pt1; radius[0] = r; angle[0] = a1, angle[1] = a2; hitPoint[0] = hitPoint[1] = hitPoint[2] = false; }
 };
 
 struct Dimension {
        OBJECT_COMMON;
        int subtype;
-       Point p1;
-       Point p2;
        double offset;
-
-       Dimension(Vector pt1, Vector pt2, DimensionType dt = DTLinear, float th = 1.0, uint32_t c = 0x0000FF, int l = LSSolid):
-               type(OTDimension), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), subtype(dt), p1(pt1), p2(pt2) {}
+       Point lp[2];            // Line point, the actual dimension line
+       Object * obj[2];        // Pointer to attached objects (circle, lines for angle)
+
+       Dimension(): type(OTDimension), id(Global::objectID++), selected(false),
+               hovered(false), hitObject(false)
+               { hitPoint[0] = hitPoint[1] = hitPoint[2] = hitPoint[3] = hitPoint[4] = false; }
+       Dimension(Vector pt1, Vector pt2, DimensionType dt = DTLinear, double offs = 0, float th = 1.0, uint32_t c = 0x0000FF, int l = LSSolid):
+               type(OTDimension), id(Global::objectID++), layer(0), color(c),
+               thickness(th), style(l), selected(false), hovered(false),
+               hitObject(false), subtype(dt), offset(offs)
+               { p[0] = pt1; p[1] = pt2; hitPoint[0] = hitPoint[1] = hitPoint[2] = hitPoint[3] = hitPoint[4] = false; }
 };
 
 struct Text {
        OBJECT_COMMON;
-       Point p1;
+       Rect extents;
+       bool measured;
        std::string s;
 
-       Text(Vector pt, char * str, float th = 10.0, uint32_t c = 0):
+       Text(): type(OTText), id(Global::objectID++) {}
+       Text(Vector pt1, const char * str, float th = 10.0, uint32_t c = 0):
                type(OTText), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(LSSolid), selected(false), hovered(false), p1(pt), s(str) {}
+               style(LSSolid), selected(false), hovered(false), hitObject(false),
+               measured(false), s(str) { p[0] = pt1; angle[0] = 0; }
 };
 
-struct Container {
+struct Polygon {
        OBJECT_COMMON;
-       Point p1;
-       std::vector<void *> objects;
-       double angle;
-       double scale;
+       int sides;
 
-       Container(): type(OTContainer), id(Global::objectID++), selected(false), hovered(false) {}
+       Polygon(): type(OTPolygon), id(Global::objectID++) {}
 };
 
-struct Object {
+struct Polyline {
        OBJECT_COMMON;
+       VPVector objects;
+       bool closed;
+       Object * clicked;
+
+       Polyline(): type(OTPolyline), id(Global::objectID++), selected(false), hovered(false), hitObject(false), clicked(NULL) {}
+       void Add(void * obj) { objects.push_back(obj); }
+       void Add(VPVector objs) { objects.insert(objects.end(), objs.begin(), objs.end()); }
 };
 
+struct Spline {
+       OBJECT_COMMON;
 
-#endif // __STRUCTS_H__
+       Spline(): type(OTSpline), id(Global::objectID++) {}
+};
 
+struct Container {
+       OBJECT_COMMON;
+       VPVector objects;
+       double scale;
+       bool topLevel;
+       Object * clicked;
+
+       int baseUnit;            // Type of BasicUnit as seen above
+       int unitStyle;           // 0 = decimal, 1 = fractional
+       int decimalPrecision;    // 0-5, which, +1, is # of decimal places
+       int fractionalPrecision; // 0-5, which, +1, is 1/(2^n)
+
+       Container(bool tl = false): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false), topLevel(tl), clicked(NULL), baseUnit(0), unitStyle(0), decimalPrecision(3), fractionalPrecision(4) {}
+       void Add(void * obj) { objects.push_back(obj); }
+       void Add(VPVector objs) { objects.insert(objects.end(), objs.begin(), objs.end()); }
+//     void DeleteContents(void) {}
+/*     void DeleteContents(Container * c)
+       {
+               std::vector<void *>::iterator i;
+
+               for(i=c->objects.begin(); i!=c->objects.end(); i++)
+               {
+                       Object * obj = (Object *)(*i);
+
+                       if (obj->type == OTContainer)
+                               DeleteContainer((Container *)obj);
+
+                       delete *i;
+               }
+       }*/
+};
+
+#endif // __STRUCTS_H__