]> Shamusworld >> Repos - architektonas/commitdiff
Fixed loading code, added "Base Unit" dialog.
authorShamus Hammons <jlhamm@acm.org>
Thu, 15 Aug 2013 23:42:16 +0000 (18:42 -0500)
committerShamus Hammons <jlhamm@acm.org>
Thu, 15 Aug 2013 23:42:16 +0000 (18:42 -0500)
Loading code (and the underlying copy code) still needs some way to deal
to deal with Connections. Right now, the load code just creates the
objects and stuffs them into a Container. Also, the "Base Unit" needs to
be a property that gets saved with the drawing, so it will eventually
need its own settings dialog.

17 files changed:
TODO
architektonas.pro
src/arc.cpp
src/arc.h
src/baseunittab.cpp [new file with mode: 0644]
src/baseunittab.h [new file with mode: 0644]
src/circle.cpp
src/circle.h
src/container.cpp
src/dimension.cpp
src/dimension.h
src/drawingview.cpp
src/generaltab.cpp
src/line.cpp
src/object.cpp
src/settingsdialog.cpp
src/settingsdialog.h

diff --git a/TODO b/TODO
index 9bbbe206b18db3d8d5c95ff1dc7b9b3139ae923f..92517e09079fd88bb9b018d06bfbede067cb02a7 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
 Stuff To Be Implemented/Fixed
 -----------------------------
 
- - Add Arc
  - Add Polygon
  - Add Ellipse
  - Add Spline
@@ -22,9 +21,20 @@ Stuff To Be Implemented/Fixed
  - Mirror tool
  - Restrict movement horizontal/vertical tool
  - Trim tool
+ - Fix Arc manipulator. Idea: split edge handles so that the inner half controls
+   arc sizing, outer half controls rotation. That way you can grab either handle
+   and know what it's supposed to do.
+ - Fix loading and saving code
+ - Fix snap to grid to allow picking up of handles when they are not on a grid
+   point.
+ - Add Drawing Properties dialog (separate from Application Settings)
 
 
 Stuff That's Done
 -----------------
 
  - Fix snap to grid to honor both states (right now, it's a weird mix of states)
+   [Shamus 2013-08-11]
+ - Add Arc [Shamus 2013-08-14]
+
+
index 668392e9a4778f146d02bb78a32228dd7e8b05cb..f0ed68254684877f6af7fb5d7686e5bfeedff562 100644 (file)
@@ -45,6 +45,7 @@ HEADERS = \
        src/action.h \
        src/applicationwindow.h \
        src/arc.h \
+       src/baseunittab.h \
        src/blockitemwidget.h \
        src/blockwidget.h \
        src/circle.h \
@@ -76,6 +77,7 @@ SOURCES = \
        src/action.cpp \
        src/applicationwindow.cpp \
        src/arc.cpp \
+       src/baseunittab.cpp \
        src/blockitemwidget.cpp \
        src/blockwidget.cpp \
        src/circle.cpp \
index 355d7a76f2b5b425ddc5b882f7e21e86a22d8dc4..89a46f3dab1e0ca12cd6e65acb4abeed92ef3250 100644 (file)
@@ -400,3 +400,19 @@ bool Arc::AngleInArcSpan(double angle)
        fprintf(file, "ARC (%lf,%lf) %lf, %lf, %lf\n", position.x, position.y, radius, startAngle, angleSpan);
 }
 
+
+/*virtual*/ Object * Arc::Copy(void)
+{
+#warning "!!! This doesn't take care of attached Dimensions !!!"
+/*
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
+
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
+*/
+       return new Arc(position, radius, startAngle, angleSpan, parent);
+}
+
index 587d0eb5cbf3be72eaf61901890e9876be1df8ad..6419750e2afe7debde0af17b59096ff497faf44b 100644 (file)
--- a/src/arc.h
+++ b/src/arc.h
@@ -15,8 +15,8 @@ class Arc: public Object
                virtual void PointerMoved(Vector);
                virtual void PointerReleased(void);
                virtual void Enumerate(FILE *);
+               virtual Object * Copy(void);
                virtual QRectF Extents(void);
-//             virtual Object * Copy(void);
 //             virtual ObjectType Type(void);
 
        private:
diff --git a/src/baseunittab.cpp b/src/baseunittab.cpp
new file mode 100644 (file)
index 0000000..f9ea41f
--- /dev/null
@@ -0,0 +1,30 @@
+//
+// baseunittab.cpp: "Base Unit" tab on the settings dialog
+//
+// 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/15/2011  Created this file
+
+#include "baseunittab.h"
+
+
+BaseUnitTab::BaseUnitTab(QWidget * parent/*= 0*/): QWidget(parent)
+{
+       antialiasChk = new QCheckBox(tr("Use Qt's built-in antialiasing"));
+
+       QVBoxLayout * layout = new QVBoxLayout;
+       layout->addWidget(antialiasChk);
+       setLayout(layout);
+}
+
+
+BaseUnitTab::~BaseUnitTab()
+{
+}
+
diff --git a/src/baseunittab.h b/src/baseunittab.h
new file mode 100644 (file)
index 0000000..022317c
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __BASEUNITTAB_H__
+#define __BASEUNITTAB_H__
+
+#include <QtGui>
+
+class BaseUnitTab: public QWidget
+{
+       Q_OBJECT
+
+       public:
+               BaseUnitTab(QWidget * parent = 0);
+               ~BaseUnitTab();
+
+       public:
+               QCheckBox * antialiasChk;
+};
+
+#endif // __BASEUNITTAB_H__
index 1f350b0341615f7cc2abbde872c0448c13e68b66..77ea95a6290e5ca87dbe8ba9477bac561fce7bef 100644 (file)
@@ -186,3 +186,19 @@ bool Circle::StateChanged(void)
        fprintf(file, "CIRCLE (%lf,%lf) %lf\n", position.x, position.y, radius);
 }
 
+
+/*virtual*/ Object * Circle::Copy(void)
+{
+#warning "!!! This doesn't take care of attached Dimensions !!!"
+/*
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
+
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
+*/
+       return new Circle(position, radius, parent);
+}
+
index 1f0d38723836822e32ba82089f163dfde45ca9c2..eb86957df4a43bc1c9c05994fef1f728dda5bf55 100644 (file)
@@ -16,8 +16,8 @@ class Circle: public Object
                virtual void PointerReleased(void);
                virtual bool HitTest(Point);
                virtual void Enumerate(FILE *);
+               virtual Object * Copy(void);
                virtual QRectF Extents(void);
-//             virtual Object * Copy(void);
 //             virtual ObjectType Type(void);
 
        protected:
index da491f617b8366ff71bacf1bba6b0ebda26a3bef..ced7326de4979b91e67d4d16dfe97694101d4837 100644 (file)
@@ -56,11 +56,18 @@ Container & Container::operator=(const Container & from)
 
        // Small problem with this approach: if the copied object goes out of scope,
        // all of the objects we copied in here will be deleted. D'oh!
-       for(uint i=0; i<from.objects.size(); i++)
+       // For this COPY constructor to be meaningful, we have to actually COPY the
+       // objects in this Container, not just MOVE a copy of the POINTER! D-:
+       std::vector<Object *>::const_iterator i;
+
+//     for(uint i=0; i<from.objects.size(); i++)
+       for(i=from.objects.begin(); i!=from.objects.end(); i++)
        {
-               Object * object = from.objects[i];
+//             Object * object = from.objects[i];
+               Object * object = (*i)->Copy();
 
-               // Need to copy the object here...
+               // Need to actually COPY the object here, not copy the pointer only!!
+               // (which we do now, above :-P)
 
                objects.push_back(object);
        }
@@ -73,8 +80,10 @@ Container & Container::operator=(const Container & from)
 {
        QRectF boundary;
 
+//int a=1;
        for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)
        {
+//printf("Containter::Draw item #%i [%X]...\n", a++, *i);
                (*i)->Draw(painter);
                boundary = boundary.united((*i)->Extents());
        }
index 6f561be7da4896efd7b5226277bde827bd3c91f8..2a989dccec0de1b91fb3d68f8ab13e4d2ebbbcdf 100644 (file)
@@ -324,6 +324,25 @@ about keeping track of old states...
 }
 
 
+/*virtual*/ Object * Dimension::Copy(void)
+{
+#warning "!!! This doesn't take care of attached Dimensions !!!"
+/*
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
+
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
+*/
+
+       Dimension * d = new Dimension(position, endpoint, dimensionType, parent);
+       d->size = size;
+       return d;
+}
+
+
 // Dimensions are special: they contain exactly *two* points. Here, we check
 // only for zero/non-zero in returning the correct points.
 /*virtual*/ Vector Dimension::GetPointAtParameter(double parameter)
index 252c93375dfa3f2a0afe6ab66b8e98614d4046a0..d4c4c31bc7d9e052cdba199002e1ad344b1f2eea 100644 (file)
@@ -19,7 +19,7 @@ class Dimension: public Object
                virtual void PointerMoved(Vector);
                virtual void PointerReleased(void);
                virtual void Enumerate(FILE *);
-//             virtual Object * Copy(void);
+               virtual Object * Copy(void);
                virtual Vector GetPointAtParameter(double parameter);
                virtual void Connect(Object *, double);
                virtual void Disconnect(Object *, double);
index ab9f565fc2423bcb4f5a0c2b076eeaf63e64f500..5bbcddf62ffeb0396b5f5edc5924e46ceaea9a5e 100644 (file)
@@ -369,7 +369,13 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
                Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
 
 // Problem with this: Can't select stuff very well with the snap grid on.
-// Completely screws things up.
+// Completely screws things up, as sometimes things don't fall on the grid.
+/*
+So, how to fix this? Have the Object check itself?
+Maybe we can fix this by having the initial point not be snapped, but when there's
+a drag, we substitute the snapped point 'oldPoint' which the Object keeps track of
+internally to know how far it was dragged...
+*/
                if (Object::snapToGrid)
                        point = SnapPointToGrid(point);
 
index 7b18549619638885984e9e5fd77100ecce764c69..358c2a1136e2f63063317548b35d96c1c35c19e1 100644 (file)
@@ -23,6 +23,7 @@ GeneralTab::GeneralTab(QWidget * parent/*= 0*/): QWidget(parent)
        setLayout(layout);
 }
 
+
 GeneralTab::~GeneralTab()
 {
 }
index 9054bbc8c2bcda9be454356eb552a4e3ab76a423..a3d745aa3da32908a53b3f45c47d6076af07ef24 100644 (file)
@@ -529,12 +529,13 @@ the horizontal line or vertical line that intersects from the current mouse posi
 {
 #warning "!!! This doesn't take care of attached Dimensions !!!"
 /*
-This is a real problem. While having a pointer in the Dimension to this line's points is fast & easy,
-it creates a huge problem when trying to replicate an object like this.
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
 
-Maybe a way to fix that then, is to have reference numbers instead of pointers. That way, if you copy
-them, ... you might still have problems. Because you can't be sure if a copy will be persistant or not,
-you then *definitely* do not want them to have the same reference number.
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
 */
        return new Line(position, endpoint, parent);
 }
index fc8d834cf08fddeac06add6323008458647f26c8..404d30576113a97ad9516b04677d087f81ad4346 100644 (file)
@@ -40,8 +40,9 @@ Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject),
 }
 
 
-Object::Object(Vector v,  Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
-       state(OSInactive), oldState(OSInactive), needUpdate(false)//, attachedDimension(0)
+Object::Object(Vector v,  Object * passedInParent/*= 0*/): position(v),
+       parent(passedInParent), state(OSInactive), oldState(OSInactive),
+       needUpdate(false)//, attachedDimension(0)
 {
 }
 
@@ -147,6 +148,7 @@ printf("Object: Destroyed!\n");
 
 /*virtual*/ void Object::Disconnect(Object * obj, double parameter)
 {
+#if 0
        for(uint i=0; i<connected.size(); i++)
        {
                if (connected[i].object == obj && connected[i].t == parameter)
@@ -155,11 +157,24 @@ printf("Object: Destroyed!\n");
                        return;
                }
        }
+#else
+       std::vector<Connection>::iterator i;
+
+       for(i=connected.begin(); i!=connected.end(); i++)
+       {
+               if (((*i).object == obj) && ((*i).t == parameter))
+               {
+                       connected.erase(i);
+                       return;
+               }
+       }
+#endif
 }
 
 
 /*virtual*/ void Object::DisconnectAll(Object * obj)
 {
+#if 0
        // According the std::vector docs, only items at position i and beyond are
        // invalidated, everything before i is still valid. So we use that here.
        for(uint i=0; i<connected.size();)
@@ -171,6 +186,17 @@ printf("Object: Destroyed!\n");
                else
                        i++;
        }
+#else
+       std::vector<Connection>::iterator i;
+
+       for(i=connected.begin(); i!=connected.end(); )
+       {
+               if ((*i).object == obj)
+                       connected.erase(i);
+               else
+                       i++;
+       }
+#endif
 }
 
 
index 871f1f30dcc01b0d2ff9670dc51d17f44996a147..7b528c79308d1c79f7b7861a8a3454dc75d4b2a1 100644 (file)
@@ -12,6 +12,7 @@
 // JLH  06/04/2011  Created this file
 
 #include "settingsdialog.h"
+#include "baseunittab.h"
 #include "generaltab.h"
 
 
@@ -19,7 +20,9 @@ SettingsDialog::SettingsDialog(QWidget * parent/*= 0*/): QDialog(parent)
 {
        tabWidget = new QTabWidget;
        generalTab = new GeneralTab(this);
+       baseunitTab = new BaseUnitTab(this);
        tabWidget->addTab(generalTab, tr("General"));
+       tabWidget->addTab(baseunitTab, tr("Base Units"));
 //     tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions"));
 //     tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));
 
@@ -36,6 +39,8 @@ SettingsDialog::SettingsDialog(QWidget * parent/*= 0*/): QDialog(parent)
        setWindowTitle(tr("Architektonas Settings"));
 }
 
+
 SettingsDialog::~SettingsDialog()
 {
 }
+
index 2298a6e3135e404767c0fbf503ac50d574c9d2e2..941f21d6a3bd2659c38d7334fbd85f30ec63c9ce 100644 (file)
@@ -4,6 +4,7 @@
 #include <QtGui>
 
 class GeneralTab;
+class BaseUnitTab;
 
 class SettingsDialog: public QDialog
 {
@@ -19,6 +20,7 @@ class SettingsDialog: public QDialog
 
        public:
                GeneralTab * generalTab;
+               BaseUnitTab * baseunitTab;
 };
 
 #endif // __SETTINGSDIALOG_H__