X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdimension.cpp;h=3060ff1b930c8682409f10993b73622562fbb098;hb=baf67656b97e3d61e9223e66ebe4f554e364cd4a;hp=381196b00e37993ec204b277afa31ad2e03a36ce;hpb=c51c02d23ddd4423882da2c54b76f8f2c90c1c99;p=architektonas diff --git a/src/dimension.cpp b/src/dimension.cpp index 381196b..3060ff1 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ @@ -15,11 +15,21 @@ #include #include "mathconstants.h" +#include "painter.h" -Dimension::Dimension(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2), +Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Object * p/*= NULL*/): + Object(p1, p), endpoint(p2), dragging(false), draggingHandle1(false), draggingHandle2(false), - length(p2.Magnitude()) + length(p2.Magnitude()), type(dt), point1(NULL), point2(NULL) +{ +} + +// This is bad, p1 & p2 could be NULL, causing much consternation... +Dimension::Dimension(Vector * p1, Vector * p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/): + Object(*p1, p), endpoint(*p2), + dragging(false), draggingHandle1(false), draggingHandle2(false), + length(p2->Magnitude()), type(dt), point1(p1), point2(p2) { } @@ -27,12 +37,20 @@ Dimension::~Dimension() { } -/*virtual*/ void Dimension::Draw(QPainter * painter) +/*virtual*/ void Dimension::Draw(Painter * painter) { + // If there are valid Vector pointers in here, use them to update the internal + // positions. Otherwise, we just use the internal positions by default. + if (point1) + position = *point1; + + if (point2) + endpoint = *point2; + if (state == OSSelected) - painter->setPen(QPen(Qt::red, 2.0, Qt::DotLine)); + painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine)); else - painter->setPen(QPen(Qt::blue, 1.0, Qt::SolidLine)); + painter->SetPen(QPen(Qt::blue, 1.0, Qt::SolidLine)); // Draw an aligned dimension line double angle = Vector(endpoint - position).Angle(); @@ -40,29 +58,37 @@ Dimension::~Dimension() Vector orthogonal = Vector(cos(orthoAngle), sin(orthoAngle)); Vector unit = Vector(endpoint - position).Unit(); +//NOTE: SCREEN_ZOOM is our kludge factor... We need to figure out a better +// way of doing this... // Get our line parallel to our points - Point p1 = position + (orthogonal * 10.0); - Point p2 = endpoint + (orthogonal * 10.0); + Point p1 = position + (orthogonal * 10.0 * SCREEN_ZOOM); + Point p2 = endpoint + (orthogonal * 10.0 * SCREEN_ZOOM); // Draw main dimension line - painter->drawLine(QPointF(p1.x, p1.y), QPointF(p2.x, p2.y)); + painter->DrawLine(p1, p2); - Point p3 = position + (orthogonal * 16.0); - Point p4 = endpoint + (orthogonal * 16.0); - Point p5 = position + (orthogonal * 4.0); - Point p6 = endpoint + (orthogonal * 4.0); + Point p3 = position + (orthogonal * 16.0 * SCREEN_ZOOM); + Point p4 = endpoint + (orthogonal * 16.0 * SCREEN_ZOOM); + Point p5 = position + (orthogonal * 4.0 * SCREEN_ZOOM); + Point p6 = endpoint + (orthogonal * 4.0 * SCREEN_ZOOM); // Draw extension lines - painter->drawLine(QPointF(p3.x, p3.y), QPointF(p5.x, p5.y)); - painter->drawLine(QPointF(p4.x, p4.y), QPointF(p6.x, p6.y)); + painter->DrawLine(p3, p5); + painter->DrawLine(p4, p6); + + painter->SetBrush(QBrush(QColor(Qt::blue))); + painter->DrawArrowhead(p1, p2); + painter->DrawArrowhead(p2, p1); // Draw length of dimension line... - painter->setFont(QFont("Arial", 10)); + painter->SetFont(QFont("Arial", 10.0 * Painter::zoom * SCREEN_ZOOM)); Vector v1((p1.x - p2.x) / 2.0, (p1.y - p2.y) / 2.0); Point ctr = p2 + v1; + // This is in pixels, which isn't even remotely correct... !!! FIX !!! QString dimText = QString("%1\"").arg(Vector(endpoint - position).Magnitude()); - int textWidth = QFontMetrics(painter->font()).width(dimText); - int textHeight = QFontMetrics(painter->font()).height(); +// int textWidth = QFontMetrics(painter->font()).width(dimText); +// int textHeight = QFontMetrics(painter->font()).height(); +#if 0 //We have to do transformation voodoo to make the text come out readable and in correct orientation... //Some things to note here: if angle > 90 degrees, then we need to take the negative of the angle //for our text. @@ -83,11 +109,25 @@ painter->scale(1.0, -1.0); //painter->translate(-textWidth / 2, -24); // painter->drawText(0, 0, textWidth, 20, Qt::AlignCenter, dimText); // This version draws the y-coord from the baseline of the font - painter->drawText(-textWidth / 2, yOffset, dimText); + painter->DrawText(-textWidth / 2, yOffset, dimText); //painter->setPen(QPen(QColor(0xFF, 0x20, 0x20), 1.0, Qt::SolidLine)); //painter->drawLine(20, 0, -20, 0); //painter->drawLine(0, 20, 0, -20); painter->restore(); +#else +// painter->DrawText(QRectF(QPointF(ctr.x, ctr.y), QPointF(ctr.x + textWidth, ctr.y + textHeight)), Qt::AlignVCenter, dimText); +// Now that we've taken our own good advice, maybe we should have the painter class +// do a nice abstracted text draw routine? :-) + painter->DrawAngledText(ctr, angle, dimText); +#endif + +/* +All of the preceeding makes me think that rather than try to compensate for Qt's unbelieveably +AWFUL decision to go with a wrong-handed graphics subsystem, it may be better to just stuff +all of that crap into some kind of subclass that handles all the nastiness behind the scenes. +I mean, really, all this crap just to get some proplerly rendered text on the screen? How +retarded is that? :-/ +*/ } /*virtual*/ Vector Dimension::Center(void) @@ -279,14 +319,39 @@ about keeping track of old states... state = oldState; } -void Dimension::SetPoint1(Vector v) +void Dimension::SetPoint1(Vector * v) { - position = v; + point1 = v; needUpdate = true; } -void Dimension::SetPoint2(Vector v) +void Dimension::SetPoint2(Vector * v) { - endpoint = v; + point2 = v; needUpdate = true; } + +Vector Dimension::GetPoint1(void) +{ + return position; +} + +Vector Dimension::GetPoint2(void) +{ + return endpoint; +} + +void Dimension::FlipSides(void) +{ +#if 0 + Vector tmp = position; + position = endpoint; + endpoint = tmp; +#else + Vector * tmp = point1; + point1 = point2; + point2 = tmp; +#endif + needUpdate = true; +} +