]> Shamusworld >> Repos - architektonas/commitdiff
Various fixes to Container/Group handling, added DrawArcAction.
authorShamus Hammons <jlhamm@acm.org>
Wed, 14 Aug 2013 01:15:59 +0000 (20:15 -0500)
committerShamus Hammons <jlhamm@acm.org>
Wed, 14 Aug 2013 01:15:59 +0000 (20:15 -0500)
Also, fixed snap to grid to work as it should. If it's on, it's on; if
it's off it's off. Seems simple in concept and, as it turns out, it was
simple in implementation. Dunno why it took so long to finally fix it.
:-P

12 files changed:
TODO
architektonas.pro
src/applicationwindow.cpp
src/container.cpp
src/drawarcaction.cpp [new file with mode: 0644]
src/drawarcaction.h [new file with mode: 0644]
src/drawingview.cpp
src/drawingview.h
src/object.cpp
src/object.h
src/painter.cpp
src/painter.h

diff --git a/TODO b/TODO
index 540d541ecbba779e6abc48fc439b9af392587cd7..9bbbe206b18db3d8d5c95ff1dc7b9b3139ae923f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,11 +3,13 @@ Stuff To Be Implemented/Fixed
 
  - Add Arc
  - Add Polygon
+ - Add Ellipse
+ - Add Spline
+ - Add Text
  - Manipulate Dimension
  - Object connections
  - Group selection (kind done, needs more work though)
  - Take movement code out of Objects and put it into top level Container
- - Fix snap to grid to honor both states (right now, it's a weird mix of states)
  - Add OSD routines so they don't have to be implemented in Objects
  - Add OSD to Object creation
  - Add layers
@@ -17,7 +19,12 @@ Stuff To Be Implemented/Fixed
  - Add fill/hatch to Objects
  - Fix zooming to be more intuitive
  - Add other Dimension types, like radial, diametric, leader
- - Add Ellipse
- - Add Spline
- - Add Text
+ - Mirror tool
+ - Restrict movement horizontal/vertical tool
+ - Trim tool
+
 
+Stuff That's Done
+-----------------
+
+ - Fix snap to grid to honor both states (right now, it's a weird mix of states)
index 108fba74736dd8bff77163fc9c75c3fe651ff93f..668392e9a4778f146d02bb78a32228dd7e8b05cb 100644 (file)
@@ -52,6 +52,7 @@ HEADERS = \
        src/container.h \
        src/dimension.h \
        src/drawingview.h \
+       src/drawarcaction.h \
        src/drawcircleaction.h \
        src/drawdimensionaction.h \
        src/drawlineaction.h \
@@ -82,6 +83,7 @@ SOURCES = \
        src/container.cpp \
        src/dimension.cpp \
        src/drawingview.cpp \
+       src/drawarcaction.cpp \
        src/drawcircleaction.cpp \
        src/drawdimensionaction.cpp \
        src/drawlineaction.cpp \
index daae37cf0e4fd61898f1eac1998d1184e7c91922..b812e4d8a05e70897b830587af40a456d826df10 100644 (file)
@@ -386,6 +386,7 @@ void ApplicationWindow::SetInternalToolStates(void)
 
        drawing->SetAddLineToolActive(addLineAct->isChecked());
        drawing->SetAddCircleToolActive(addCircleAct->isChecked());
+       drawing->SetAddArcToolActive(addArcAct->isChecked());
        drawing->SetAddDimensionToolActive(addDimensionAct->isChecked());
 }
 
index 757828aad73e064af821d04816807a82fa93702a..da491f617b8366ff71bacf1bba6b0ebda26a3bef 100644 (file)
@@ -25,6 +25,7 @@ Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p),
        dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false)
 {
        type = OTContainer;
+       state = OSInactive;
 }
 
 
@@ -34,6 +35,7 @@ Container::Container(const Container & copy): Object(copy.position, copy.parent)
        // Use overloaded assignment operator
        *this = copy;
        type = OTContainer;
+       state = OSInactive;
 }
 
 
@@ -85,7 +87,7 @@ Container & Container::operator=(const Container & from)
                        painter->SetPen(QPen(Qt::blue, 2.0, Qt::DashLine));
 
                painter->SetBrush(QBrush(Qt::NoBrush));
-               painter->DrawRect(boundary);
+               painter->DrawPaddedRect(boundary);
        }
 }
 
diff --git a/src/drawarcaction.cpp b/src/drawarcaction.cpp
new file mode 100644 (file)
index 0000000..96db309
--- /dev/null
@@ -0,0 +1,88 @@
+// drawarcaction.cpp: Draw arc object
+//
+// Part of the Architektonas Project
+// (C) 2011 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// WHO  WHEN        WHAT
+// ---  ----------  ------------------------------------------------------------
+// JLH  08/13/2013  Created this file
+//
+
+#include "drawarcaction.h"
+#include "painter.h"
+#include "arc.h"
+//#include "vector.h"
+
+
+enum { FIRST_POINT, SECOND_POINT, THIRD_POINT };
+//#define FIRST_POINT 0
+//#define SECOND_POINT 1
+#define NEXT_POINT 2
+
+
+DrawArcAction::DrawArcAction(): state(FIRST_POINT), arc(NULL)
+{
+}
+
+
+DrawArcAction::~DrawArcAction()
+{
+}
+
+
+/*virtual*/ void DrawArcAction::Draw(Painter * painter)
+{
+       painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
+
+       // I think stuff like crosshairs should be done in the DrawingView, tho
+       if (state == FIRST_POINT)
+       {
+               painter->DrawHandle(p1);
+       }
+       else
+       {
+//             painter->DrawLine(p1, p2);
+//             painter->DrawHandle(p2);
+       }
+}
+
+
+/*virtual*/ void DrawArcAction::MouseDown(Vector point)
+{
+       if (state == FIRST_POINT)
+               p1 = point;
+//     else
+//             p2 = point;
+}
+
+
+/*virtual*/ void DrawArcAction::MouseMoved(Vector point)
+{
+       if (state == FIRST_POINT)
+               p1 = point;
+//     else
+//             p2 = point;
+}
+
+
+/*virtual*/ void DrawArcAction::MouseReleased(void)
+{
+       if (state == FIRST_POINT)
+       {
+//             p2 = p1;
+               state = NEXT_POINT;
+       }
+       else if (state == NEXT_POINT)
+       {
+               // We create the new object here, and then pass it off to the
+               // DrawingView which stuffs it into the document.
+//             text = new Text(p1, p2);
+//             arc = new Arc(...);
+               // We don't need no stinkin' sentinels, when we have signals & slots!
+               emit ObjectReady(arc);
+       }
+}
+
diff --git a/src/drawarcaction.h b/src/drawarcaction.h
new file mode 100644 (file)
index 0000000..afb9f91
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __DRAWARCACTION_H__
+#define __DRAWARCACTION_H__
+
+#include "action.h"
+
+class Arc;
+
+class DrawArcAction: public Action
+{
+       public:
+               DrawArcAction();
+               ~DrawArcAction();
+
+               virtual void Draw(Painter *);
+               virtual void MouseDown(Vector);
+               virtual void MouseMoved(Vector);
+               virtual void MouseReleased(void);
+
+       private:
+               int state;
+               Arc * arc;
+               Vector p1, p2;
+};
+
+#endif // __DRAWARCACTION_H__
index 8f689a80bd0e33cd2ef3000ba7bff14fea6d5c59..31aeaf028193e6fe9c43cb530a9a166d7c6befce 100644 (file)
@@ -34,6 +34,7 @@
 #include "arc.h"
 #include "circle.h"
 #include "dimension.h"
+#include "drawarcaction.h"
 #include "drawcircleaction.h"
 #include "drawdimensionaction.h"
 #include "drawlineaction.h"
@@ -124,7 +125,8 @@ Painter::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
-need a thickness parameter similar to the "size" param for dimensions.
+need a thickness parameter similar to the "size" param for dimensions. (And now
+we do! :-)
 
 */
 #if 0
@@ -180,6 +182,19 @@ void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
 }
 
 
+void DrawingView::SetAddArcToolActive(bool state/*= true*/)
+{
+       if (state)
+       {
+               toolAction = new DrawArcAction();
+               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+                       SLOT(AddNewObjectToDocument(Object *)));
+       }
+
+       update();
+}
+
+
 void DrawingView::SetAddDimensionToolActive(bool state/*= true*/)
 {
        if (state)
@@ -328,6 +343,26 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
 }
 
 
+//
+// This looks strange, but it's really quite simple: We want a point that's
+// more than half-way to the next grid point to snap there while conversely we
+// want a point that's less than half-way to to the next grid point then snap
+// to the one before it. So we add half of the grid spacing to the point, then
+// divide by it so that we can remove the fractional part, then multiply it
+// back to get back to the correct answer.
+//
+Vector DrawingView::SnapPointToGrid(Vector point)
+{
+       point += gridSpacing / 2.0;             // *This* adds to Z!!!
+       point /= gridSpacing;
+       point.x = floor(point.x);//need to fix this for negative numbers...
+       point.y = floor(point.y);
+       point.z = 0;                                    // Make *sure* Z doesn't go anywhere!!!
+       point *= gridSpacing;
+       return point;
+}
+
+
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
 {
        QPainter qtPainter(this);
@@ -388,6 +423,10 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
        if (event->button() == Qt::LeftButton)
        {
                Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+
+               if (Object::snapToGrid)
+                       point = SnapPointToGrid(point);
+
                collided = document.Collided(point);
 
                if (collided)
@@ -437,14 +476,9 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
        // Grid processing...
 #if 1
-       // This looks strange, but it's really quite simple: We want a point that's
-       // more than half-way to the next grid point to snap there while conversely
-       // we want a point that's less than half-way to to the next grid point then
-       // snap to the one before it. So we add half of the grid spacing to the
-       // point, then divide by it so that we can remove the fractional part, then
-       // multiply it back to get back to the correct answer.
-       if (event->buttons() & Qt::LeftButton)
+       if ((event->buttons() & Qt::LeftButton) && Object::snapToGrid)
        {
+#if 0
                point += gridSpacing / 2.0;                                     // *This* adds to Z!!!
                point /= gridSpacing;
 //200% is ok, gridSpacing = 6 in this case...
@@ -455,6 +489,9 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
                point.y = floor(point.y);
                point.z = 0;                                                            // Make *sure* Z doesn't go anywhere!!!
                point *= gridSpacing;
+#else
+               point = SnapPointToGrid(point);
+#endif
        }
 #endif
 //we should keep track of the last point here and only pass this down *if* the point
index 888737eb82286b38d3b2fbfe75151828da08e1d3..b296f28e64c887f2a8276d5a775cd76f178fe5f6 100644 (file)
@@ -17,6 +17,7 @@ class DrawingView: public QWidget
                void SetRotateToolActive(bool state = true);
                void SetAddLineToolActive(bool state = true);
                void SetAddCircleToolActive(bool state = true);
+               void SetAddArcToolActive(bool state = true);
                void SetAddDimensionToolActive(bool state = true);
                void SetGridSize(uint32_t);
                void UpdateGridBackground(void);
@@ -34,6 +35,7 @@ class DrawingView: public QWidget
        private:
                QPoint GetAdjustedMousePosition(QMouseEvent * event);
                QPoint GetAdjustedClientPosition(int x, int y);
+               Vector SnapPointToGrid(Vector);
 
        public:
                bool useAntialiasing;
index 523601dd755b438f20e0857bad2a127b0aa33f2e..fc8d834cf08fddeac06add6323008458647f26c8 100644 (file)
@@ -189,8 +189,9 @@ printf("Object: Destroyed!\n");
 #endif
 
 
-/*virtual*/ void Object::Translate(Vector)
+/*virtual*/ void Object::Translate(Vector amount)
 {
+       position += amount;
 }
 
 
index 513b677fba566421b6999859b705a8d051e76fba..72aaad644f29a79d96dba2d08a59e83118529509 100644 (file)
@@ -79,6 +79,7 @@ class Object
                static int viewportHeight;
                static bool deleteActive;
                static bool dimensionActive;
+       public:
                static bool snapToGrid;
                static bool ignoreClicks;
                static bool dontMove;
index 6cfd91f8ef62641d6584158631c6a3834866532a..308cab6b7bd87ed587cb884ae52113f1173abaad 100644 (file)
@@ -208,6 +208,7 @@ void Painter::DrawPoint(int x, int y)
 }
 
 
+// This is drawn in Qt coordinates...
 void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
 {
        if (!painter)
@@ -217,6 +218,22 @@ void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
 }
 
 
+// This is drawn partially in Cartesian coordinates, and partially in Qt
+// coordinates. The rect itself is in Cartesian but we want to pad it by a set
+// number of pixels.
+void Painter::DrawPaddedRect(QRectF rect)
+{
+       if (!painter)
+               return;
+
+       Vector v1 = CartesianToQtCoords(Vector(rect.x(), rect.y()));
+       Vector v2 = CartesianToQtCoords(Vector(rect.right(), rect.bottom()));
+       QRectF screenRect(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
+       screenRect.adjust(-8, 8, 8, -8);        // Left/top, right/bottom
+       painter->drawRect(screenRect);
+}
+
+
 void Painter::DrawRect(QRectF rect)
 {
        if (!painter)
index 219547c7b2f47f38b47084923ff59714cf0e38a7..84e3e1477a5d90b98822f70dd6bff0173fc22fc9 100644 (file)
@@ -26,6 +26,7 @@ class Painter
                void DrawLine(Vector, Vector);
                void DrawPoint(int, int);
                void DrawRoundedRect(QRectF, double, double);
+               void DrawPaddedRect(QRectF);
                void DrawRect(QRectF);
                void DrawText(QRectF, int, QString);
                void DrawArrowhead(Vector, Vector, double);