From 89b8b0c60579d8ef0cf9a13521e7bf7c7864883f Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 15 Aug 2013 18:42:16 -0500 Subject: [PATCH] Fixed loading code, added "Base Unit" dialog. 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. --- TODO | 12 +++++++++++- architektonas.pro | 2 ++ src/arc.cpp | 16 ++++++++++++++++ src/arc.h | 2 +- src/baseunittab.cpp | 30 ++++++++++++++++++++++++++++++ src/baseunittab.h | 18 ++++++++++++++++++ src/circle.cpp | 16 ++++++++++++++++ src/circle.h | 2 +- src/container.cpp | 15 ++++++++++++--- src/dimension.cpp | 19 +++++++++++++++++++ src/dimension.h | 2 +- src/drawingview.cpp | 8 +++++++- src/generaltab.cpp | 1 + src/line.cpp | 11 ++++++----- src/object.cpp | 30 ++++++++++++++++++++++++++++-- src/settingsdialog.cpp | 5 +++++ src/settingsdialog.h | 2 ++ 17 files changed, 176 insertions(+), 15 deletions(-) create mode 100644 src/baseunittab.cpp create mode 100644 src/baseunittab.h diff --git a/TODO b/TODO index 9bbbe20..92517e0 100644 --- 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] + + diff --git a/architektonas.pro b/architektonas.pro index 668392e..f0ed682 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -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 \ diff --git a/src/arc.cpp b/src/arc.cpp index 355d7a7..89a46f3 100644 --- a/src/arc.cpp +++ b/src/arc.cpp @@ -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); +} + diff --git a/src/arc.h b/src/arc.h index 587d0eb..6419750 100644 --- 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 index 0000000..f9ea41f --- /dev/null +++ b/src/baseunittab.cpp @@ -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 +// +// 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 index 0000000..022317c --- /dev/null +++ b/src/baseunittab.h @@ -0,0 +1,18 @@ +#ifndef __BASEUNITTAB_H__ +#define __BASEUNITTAB_H__ + +#include + +class BaseUnitTab: public QWidget +{ + Q_OBJECT + + public: + BaseUnitTab(QWidget * parent = 0); + ~BaseUnitTab(); + + public: + QCheckBox * antialiasChk; +}; + +#endif // __BASEUNITTAB_H__ diff --git a/src/circle.cpp b/src/circle.cpp index 1f350b0..77ea95a 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -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); +} + diff --git a/src/circle.h b/src/circle.h index 1f0d387..eb86957 100644 --- a/src/circle.h +++ b/src/circle.h @@ -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: diff --git a/src/container.cpp b/src/container.cpp index da491f6..ced7326 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -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::const_iterator i; + +// for(uint i=0; iCopy(); - // 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::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()); } diff --git a/src/dimension.cpp b/src/dimension.cpp index 6f561be..2a989dc 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -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) diff --git a/src/dimension.h b/src/dimension.h index 252c933..d4c4c31 100644 --- a/src/dimension.h +++ b/src/dimension.h @@ -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); diff --git a/src/drawingview.cpp b/src/drawingview.cpp index ab9f565..5bbcddf 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -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); diff --git a/src/generaltab.cpp b/src/generaltab.cpp index 7b18549..358c2a1 100644 --- a/src/generaltab.cpp +++ b/src/generaltab.cpp @@ -23,6 +23,7 @@ GeneralTab::GeneralTab(QWidget * parent/*= 0*/): QWidget(parent) setLayout(layout); } + GeneralTab::~GeneralTab() { } diff --git a/src/line.cpp b/src/line.cpp index 9054bbc..a3d745a 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -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); } diff --git a/src/object.cpp b/src/object.cpp index fc8d834..404d305 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -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::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::iterator i; + + for(i=connected.begin(); i!=connected.end(); ) + { + if ((*i).object == obj) + connected.erase(i); + else + i++; + } +#endif } diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 871f1f3..7b528c7 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -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() { } + diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 2298a6e..941f21d 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -4,6 +4,7 @@ #include class GeneralTab; +class BaseUnitTab; class SettingsDialog: public QDialog { @@ -19,6 +20,7 @@ class SettingsDialog: public QDialog public: GeneralTab * generalTab; + BaseUnitTab * baseunitTab; }; #endif // __SETTINGSDIALOG_H__ -- 2.37.2