//printf("Zoom in... Center=%.2f,%.2f; ", center.x, center.y);
center = Painter::QtToCartesianCoords(center);
//printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
- Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
+ Vector newOrigin = center - ((center - Global::origin) / zoomFactor);
//printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
- Painter::origin = newOrigin;
+ Global::origin = newOrigin;
//printf("Zoom in... level going from %02f to ", Painter::zoom);
// This just zooms leaving origin intact... should zoom in at the current
// center! [DONE]
- Painter::zoom *= zoomFactor;
- Global::gridSpacing = drawing->gridPixels / Painter::zoom;
+ Global::zoom *= zoomFactor;
+ Global::gridSpacing = drawing->gridPixels / Global::zoom;
drawing->UpdateGridBackground();
drawing->update();
//printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
// Vector newOrigin = (center - Painter::origin) * zoomFactor;
// Vector newOrigin = center - (Painter::origin * zoomFactor);
- Vector newOrigin = center + ((Painter::origin - center) * zoomFactor);
+ Vector newOrigin = center + ((Global::origin - center) * zoomFactor);
//printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
- Painter::origin = newOrigin;
+ Global::origin = newOrigin;
//printf("Zoom out...\n");
// This just zooms leaving origin intact... should zoom out at the current
// center! [DONE]
- Painter::zoom /= zoomFactor;
- Global::gridSpacing = drawing->gridPixels / Painter::zoom;
+ Global::zoom /= zoomFactor;
+ Global::gridSpacing = drawing->gridPixels / Global::zoom;
drawing->UpdateGridBackground();
drawing->update();
// drawing->gridSpacing = value;
// Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
Global::gridSpacing = value;
- Painter::zoom = drawing->gridPixels / Global::gridSpacing;
+ Global::zoom = drawing->gridPixels / Global::gridSpacing;
drawing->UpdateGridBackground();
drawing->update();
}
#include "drawingview.h"
#include <stdint.h>
-#include "mathconstants.h"
-
-//#include "arc.h"
-//#include "circle.h"
-//#include "dimension.h"
-//#include "geometry.h"
-//#include "line.h"
#include "global.h"
+#include "mathconstants.h"
#include "painter.h"
+#include "structs.h"
#define BACKGROUND_MAX_SIZE 512
// Alternate way to do the above...
line->SetDimensionOnLine();
#endif
+#else
+ Line * line = new Line;//(Vector(5, 5), Vector(50, 40), &document);
+ line->p1 = Vector(5, 5);
+ line->p2 = Vector(50, 40);
+ line->type = OTLine;
+ line->thickness = 1.0;
+ document.objects.push_back(line);
+ document.objects.push_back(new Line(Vector(50, 40), Vector(10, 83)));
+ document.objects.push_back(new Line(Vector(10, 83), Vector(17, 2)));
+ document.objects.push_back(new Circle(Vector(100, 100), 36));
+ document.objects.push_back(new Circle(Vector(50, 150), 49));
+ document.objects.push_back(new Arc(Vector(300, 300), 32, PI / 4.0, PI * 1.3)),
+ document.objects.push_back(new Arc(Vector(200, 200), 60, PI / 2.0, PI * 1.5));
#endif
/*
The drawing enforces the grid spacing through the drawing->gridSpacing variable.
- drawing->gridSpacing = 12.0 / Painter::zoom;
+ drawing->gridSpacing = 12.0 / Global::zoom;
-Painter::zoom is the zoom factor for the drawing, and all mouse clicks are
-translated to Cartesian coordinates through this. (Initially, Painter::zoom is
+Global::zoom is the zoom factor for the drawing, and all mouse clicks are
+translated to Cartesian coordinates through this. (Initially, Global::zoom is
set to 1.0. SCREEN_ZOOM is set to 1.0/4.0.)
Really, the 100% zoom level can be set at *any* zoom level, it's more of a
this. Maybe this is the case for having a base unit and basing point sizes off
of that.
-Here's what's been figured out. Painter::zoom is simply the ratio of pixels to
+Here's what's been figured out. Global::zoom is simply the ratio of pixels to
base units. What that means is that if you have a 12px grid with a 6" grid size
-(& base unit of "inches"), Painter::zoom becomes 12px / 6" = 2.0 px/in.
+(& base unit of "inches"), Global::zoom becomes 12px / 6" = 2.0 px/in.
Dimensions now have a "size" parameter to set their absolute size in relation
to the base unit. ATM, the arrows are drawn in pixels, but also scaled by
-Painter::zoom *and* size. Same with the dimension text; it's drawn at 10pt and
+Global::zoom *and* size. Same with the dimension text; it's drawn at 10pt and
scaled the same way as the arrowheads.
Need a way to scale line widths as well. :-/ Shouldn't be too difficult, just
// Set up new BG brush & zoom level (pixels per base unit)
// Painter::zoom = gridPixels / gridSpacing;
- Painter::zoom = gridPixels / Global::gridSpacing;
+ Global::zoom = gridPixels / Global::gridSpacing;
UpdateGridBackground();
}
// The top level document takes care of rendering for us...
// document.Draw(&painter);
+ // Not any more it doesn't...
+ RenderObjects(&painter, &document);
#if 0
if (toolAction)
}
+void DrawingView::RenderObjects(Painter * p, Container * c)
+{
+ std::vector<void *>::iterator i;
+
+ for(i=c->objects.begin(); i!=c->objects.end(); i++)
+ {
+ Object * obj = (Object *)(*i);
+ p->SetPen(QPen(Qt::black, 1.0 * Global::zoom * obj->thickness, Qt::SolidLine));
+
+ switch (obj->type)
+ {
+ case OTLine:
+ {
+ Line * l = (Line *)obj;
+ p->DrawLine(l->p1, l->p2);
+ break;
+ }
+ case OTCircle:
+ {
+ Circle * ci = (Circle *)obj;
+ p->DrawEllipse(ci->p1, ci->radius, ci->radius);
+ break;
+ }
+ case OTArc:
+ {
+ Arc * a = (Arc *)obj;
+ p->DrawArc(a->p1, a->radius, a->angle1, a->angle2);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+
+
void DrawingView::resizeEvent(QResizeEvent * /*event*/)
{
- Painter::screenSize = Vector(size().width(), size().height());
+ Global::screenSize = Vector(size().width(), size().height());
UpdateGridBackground();
}
// Since we're using Qt coords for scrolling, we have to adjust them here to
// conform to Cartesian coords, since the origin is using Cartesian. :-)
Vector delta(oldPoint, point);
- delta /= Painter::zoom;
+ delta /= Global::zoom;
delta.y = -delta.y;
- Painter::origin -= delta;
+ Global::origin -= delta;
UpdateGridBackground();
update();
// This is not centering for some reason. Need to figure out why. :-/
if (event->delta() > 0)
{
- Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
- Painter::origin = newOrigin;
- Painter::zoom *= zoomFactor;
+ Vector newOrigin = center - ((center - Global::origin) / zoomFactor);
+ Global::origin = newOrigin;
+ Global::zoom *= zoomFactor;
}
else
{
- Vector newOrigin = center + ((-center + Painter::origin) * zoomFactor);
- Painter::origin = newOrigin;
- Painter::zoom /= zoomFactor;
+ Vector newOrigin = center + ((-center + Global::origin) * zoomFactor);
+ Global::origin = newOrigin;
+ Global::zoom /= zoomFactor;
}
#if 1
// Global::gridSpacing = gridPixels / Painter::zoom;
// UpdateGridBackground();
- SetGridSize(Global::gridSpacing * Painter::zoom);
+ SetGridSize(Global::gridSpacing * Global::zoom);
update();
// zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Global::gridSpacing));
#endif
//#include "container.h"
#include "structs.h"
+class Painter;
+
class DrawingView: public QWidget
{
Q_OBJECT
void SetGridSize(uint32_t);
void UpdateGridBackground(void);
Point SnapPointToGrid(Point);
+ void RenderObjects(Painter *, Container *);
public slots:
void AddNewObjectToDocument(Object *);
int Global::currentLayer = 0;
Point Global::snapPoint;
bool Global::snapPointIsValid = false;
+uint32_t Global::objectID = 1;
+
+Vector Global::origin(-10.0, -10.0);
+double Global::zoom = 1.0;
+Vector Global::screenSize(200.0, 200.0);
+
// Global variable class. Note that all vars are class vars, so we don't have
// to do any instantiation shite.
+#include <stdint.h>
#include <QRectF>
#include "vector.h"
static bool snapToGrid;
static bool ignoreClicks;
static bool dontMove;
+ static uint32_t objectID;
// Coming soon...
static Point origin;
//
#include "painter.h"
-
-#include "mathconstants.h"
-//#include "object.h"
#include "global.h"
+#include "mathconstants.h"
// Set class variable defaults
-Vector Painter::origin(-10.0, -10.0);
-double Painter::zoom = 1.0;
-Vector Painter::screenSize(200.0, 200.0);
+//Vector Painter::origin(-10.0, -10.0);
+//double Painter::zoom = 1.0;
+//Vector Painter::screenSize(200.0, 200.0);
Painter::Painter(QPainter * p/*= NULL*/): painter(p)
{
// Convert regular Cartesian coordinates to the inverted Y-axis Qt coordinates
// at the current origin and zoom level.
- return Vector((v.x - origin.x) * zoom, screenSize.y - ((v.y - origin.y) * zoom));
+ return Vector((v.x - Global::origin.x) * Global::zoom, Global::screenSize.y - ((v.y - Global::origin.y) * Global::zoom));
}
{
// Convert screen location, with inverted Y-axis coordinates, to regular
// Cartesian coordinates at the current zoom level.
- return Vector((v.x / zoom) + origin.x, ((screenSize.y - v.y) / zoom) + origin.y);
+ return Vector((v.x / Global::zoom) + Global::origin.x, ((Global::screenSize.y - v.y) / Global::zoom) + Global::origin.y);
/*
How to do it:
// We may need this stuff... If dimension text is large enough.
// int textWidth = QFontMetrics(painter->font()).width(text);
// int textHeight = QFontMetrics(painter->font()).height();
- QRectF textBox(-100.0 * zoom * size, -100.0 * zoom * size, 200.0 * zoom * size, 200.0 * zoom * size); // x, y, w, h; x/y = upper left corner
+ QRectF textBox(-100.0 * Global::zoom * size, -100.0 * Global::zoom * size, 200.0 * Global::zoom * size, 200.0 * Global::zoom * size); // x, y, w, h; x/y = upper left corner
// This is in pixels. Might not render correctly at all zoom levels.
// Need to figure out if dimensions are always rendered at one size
// regardless of zoom, or if they have a definite size, and are thus
// zoomable.
- float yOffset = -12.0 * zoom * size;
+ float yOffset = -12.0 * Global::zoom * size;
// Fix text so it isn't upside down...
if ((angle > PI * 0.5) && (angle < PI * 1.5))
{
angle += PI;
- yOffset = 12.0 * zoom * size;
+ yOffset = 12.0 * Global::zoom * size;
}
textBox.translate(0, yOffset);
{
center = CartesianToQtCoords(center);
// Need to multiply scalar quantities by the zoom factor as well...
- radius *= zoom;
+ radius *= Global::zoom;
QRectF rectangle(QPointF(center.x - radius, center.y - radius),
QPointF(center.x + radius, center.y + radius));
int angle1 = (int)(startAngle * RADIANS_TO_DEGREES * 16.0);
{
// Need to multiply scalar quantities by the zoom factor as well...
center = CartesianToQtCoords(center);
- painter->drawEllipse(QPointF(center.x, center.y), axis1 * zoom, axis2 * zoom);
+ painter->drawEllipse(QPointF(center.x, center.y), axis1 * Global::zoom, axis2 * Global::zoom);
}
return;
Vector screenPoint = CartesianToQtCoords(point);
- painter->drawLine(0, screenPoint.y, screenSize.x, screenPoint.y);
- painter->drawLine(screenPoint.x, 0, screenPoint.x, screenSize.y);
+ painter->drawLine(0, screenPoint.y, Global::screenSize.x, screenPoint.y);
+ painter->drawLine(screenPoint.x, 0, screenPoint.x, Global::screenSize.y);
}
public:
// Class variables
- static Vector origin; // The window origin, not location of the origin
- static double zoom; // Window zoom factor
- static Vector screenSize; // Width & height of the window we're drawing on
+// static Vector origin; // The window origin, not location of the origin
+// static double zoom; // Window zoom factor
+// static Vector screenSize; // Width & height of the window we're drawing on
private:
QPainter * painter;
#include <stdint.h>
#include <vector>
#include <string>
+#include "global.h"
#include "vector.h"
+enum ObjectType { OTNone, OTObject, OTLine, OTCircle, OTArc, OTDimension, OTEllipse, OTContainer, OTSpline };
+
#define OBJECT_COMMON \
- int type; \
- uint32_t id; \
- int layer; \
- uint32_t color; \
- float thickness;
+ int type; \
+ uint32_t id; \
+ int layer; \
+ uint32_t color; \
+ float thickness; \
+ int style; \
+ bool selected;
struct Line {
OBJECT_COMMON;
Point p1;
Point p2;
+
+ Line(): type(OTLine), id(Global::objectID++) {}
+ Line(Vector pt1, Vector pt2, float th = 1.0, uint32_t c = 0, int l = 0):
+ type(OTLine), id(Global::objectID++), layer(l), color(c), thickness(th),
+ style(0), selected(false), p1(pt1), p2(pt2) {}
};
struct Circle {
OBJECT_COMMON;
Point p1;
double radius;
+
+ Circle(Vector pt1, double r, float th = 1.0, uint32_t c = 0, int l = 0):
+ type(OTCircle), id(Global::objectID++), layer(l), color(c), thickness(th),
+ style(0), selected(false), p1(pt1), radius(r) {}
};
struct Arc {
double radius;
double angle1;
double angle2;
+
+ Arc(Vector pt1, double r, double a1, double a2, float th = 1.0, uint32_t c = 0, int l = 0):
+ type(OTArc), id(Global::objectID++), layer(l), color(c), thickness(th),
+ style(0), selected(false), p1(pt1), radius(r), angle1(a1), angle2(a2) {}
};
struct Text {