From fa8da664bfb749497b1b2d2991077af0554cc369 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 19 May 2011 18:51:18 +0000 Subject: [PATCH] Preliminary Delete Object tool implementation. --- res/architektonas.qrc | 1 + src/applicationwindow.cpp | 79 +++++++++++++++------------------------ src/applicationwindow.h | 6 +++ src/container.cpp | 24 ++++++++++-- src/line.cpp | 10 +++-- src/object.cpp | 6 +++ src/object.h | 2 + src/vector.cpp | 12 ++++++ src/vector.h | 2 + 9 files changed, 85 insertions(+), 57 deletions(-) diff --git a/res/architektonas.qrc b/res/architektonas.qrc index 60d9147..b0b1360 100644 --- a/res/architektonas.qrc +++ b/res/architektonas.qrc @@ -3,6 +3,7 @@ atns-icon.png fix-angle.png fix-length.png + generic-tool.png splash.png quit.png diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 99092d1..b156d15 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -35,61 +35,13 @@ ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Archit setCentralWidget(drawing); // ((TTEdit *)qApp)->charWnd = new CharWindow(this); -// editWnd = new EditWindow(this); -// setCentralWidget(editWnd); + setWindowIcon(QIcon(":/res/atns-icon.png")); setWindowTitle("Architektonas"); CreateActions(); CreateMenus(); CreateToolbars(); -#if 0 -// createActions(); - newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); - newAct->setShortcuts(QKeySequence::New); - newAct->setStatusTip(tr("Create a new file")); - connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); - - openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); - openAct->setShortcuts(QKeySequence::Open); - openAct->setStatusTip(tr("Open an existing file")); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); - - aboutQtAct = new QAction(tr("About &Qt"), this); - aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - -// createMenus(); - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(newAct); - fileMenu->addAction(openAct); - fileMenu->addAction(saveAct); - fileMenu->addAction(saveAsAct); - fileMenu->addSeparator(); - fileMenu->addAction(exitAct); - - editMenu = menuBar()->addMenu(tr("&Edit")); - editMenu->addAction(cutAct); - editMenu->addAction(copyAct); - editMenu->addAction(pasteAct); - - menuBar()->addSeparator(); - - helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(aboutAct); - helpMenu->addAction(aboutQtAct); - -// createToolBars(); - fileToolBar = addToolBar(tr("File")); - fileToolBar->addAction(newAct); - fileToolBar->addAction(openAct); - fileToolBar->addAction(saveAct); - - editToolBar = addToolBar(tr("Edit")); - editToolBar->addAction(cutAct); - editToolBar->addAction(copyAct); - editToolBar->addAction(pasteAct); -#endif // Create status bar statusBar()->showMessage(tr("Ready")); @@ -127,6 +79,11 @@ void ApplicationWindow::FixLength(void) Object::SetFixedLength(fixLengthAct->isChecked()); } +void ApplicationWindow::DeleteTool(void) +{ + Object::SetDeleteActive(deleteAct->isChecked()); +} + void ApplicationWindow::CreateActions(void) { exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."), @@ -140,6 +97,17 @@ void ApplicationWindow::CreateActions(void) fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."), QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true); connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength())); + + deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence(), true); + connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool())); + + addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence()); + + addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence()); + + addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence()); + + addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence()); } // @@ -189,6 +157,14 @@ void ApplicationWindow::CreateMenus(void) menu = menuBar()->addMenu(tr("&Edit")); menu->addAction(fixAngleAct); menu->addAction(fixLengthAct); + menu->addSeparator(); + menu->addAction(deleteAct); + menu->addSeparator(); + menu->addAction(addLineAct); + menu->addAction(addCircleAct); + menu->addAction(addArcAct); + menu->addAction(addDimensionAct); + // editMenu = menuBar()->addMenu(tr("&Edit")); // editMenu->addAction(cutAct); // editMenu->addAction(copyAct); @@ -209,6 +185,11 @@ void ApplicationWindow::CreateToolbars(void) toolbar = addToolBar(tr("Edit")); toolbar->addAction(fixAngleAct); toolbar->addAction(fixLengthAct); + toolbar->addAction(deleteAct); + toolbar->addAction(addLineAct); + toolbar->addAction(addCircleAct); + toolbar->addAction(addArcAct); + toolbar->addAction(addDimensionAct); } void ApplicationWindow::ReadSettings(void) diff --git a/src/applicationwindow.h b/src/applicationwindow.h index c6b8aa2..bbe01a4 100644 --- a/src/applicationwindow.h +++ b/src/applicationwindow.h @@ -24,6 +24,7 @@ class ApplicationWindow: public QMainWindow // void FileOpen(); void FixAngle(void); void FixLength(void); + void DeleteTool(void); private: void CreateActions(void); @@ -45,6 +46,11 @@ class ApplicationWindow: public QMainWindow QAction * exitAct; QAction * fixAngleAct; QAction * fixLengthAct; + QAction * deleteAct; + QAction * addDimensionAct; + QAction * addLineAct; + QAction * addCircleAct; + QAction * addArcAct; }; #endif // __APPLICATIONWINDOW_H__ diff --git a/src/container.cpp b/src/container.cpp index 727c143..4fceefd 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -101,14 +101,30 @@ Like so: #else bool collision = false; - for(int i=0; i<(int)objects.size(); i++) + // NOTE that this deletes the object on mouse down instead of mouse up. Have to + // check to see how it feels to do it that way... + if (deleteActive) + { + for(int i=0; i<(int)objects.size(); i++) + { + if (objects[i]->Collided(point)) + { + objects.erase(objects.begin() + i); // Calls the destructor, (deletes the object, I presume... O_o) + break; + } + } + } + else { - if (objects[i]->Collided(point)) - collision = true; + for(int i=0; i<(int)objects.size(); i++) + { + if (objects[i]->Collided(point)) + collision = true; + } } #endif - // Do we decouple the state of the generic container from the objects inside??? + // Do we decouple the state of the generic container from the objects inside??? Mebbe. state = OSInactive; // return false; return collision; diff --git a/src/line.cpp b/src/line.cpp index c2831fc..3f4b8d4 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -11,6 +11,8 @@ // JLH 03/22/2011 Created this file // JLH 04/11/2011 Fixed attached dimensions to stay at correct length when // "Fixed Length" button is down +// JLH 04/27/2011 Fixed attached dimension to stay a correct length when +// "Fixed Length" button is *not* down ;-) // #include "line.h" @@ -20,7 +22,7 @@ Line::Line(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2), dragging(false), draggingHandle1(false), draggingHandle2(false), //needUpdate(false), - length(p2.Magnitude()) + length(Vector::Magnitude(p2, p1)) { } @@ -209,11 +211,11 @@ Like so: if (needUpdate) { -// should only do this if "Fixed Length" is set... !!! FIX !!! +// should only do this if "Fixed Length" is set... !!! FIX !!! [DONE] Vector point1 = (draggingHandle1 ? endpoint : position); Vector point2 = (draggingHandle1 ? position : endpoint); - Vector current(point2 - point1); + Vector current(point2, point1); Vector v = current.Unit() * length; Vector v2 = point1 + v; @@ -358,7 +360,7 @@ dp1 = n3 . v2 = -by3 * bx2 + bx3 * by2; dp2 = n1 . v2 = -by1 * bx2 + bx1 * by2; ratio = dp1 / dp2; -crossing vector = v1 * rat; +crossing vector = v1 * ratio; And that's it. diff --git a/src/object.cpp b/src/object.cpp index eaef4d4..4be11f5 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -21,6 +21,7 @@ bool Object::fixedAngle = false; bool Object::fixedLength = false; QFont * Object::font = 0; int Object::viewportHeight = 0; +bool Object::deleteActive = false; Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive), @@ -95,3 +96,8 @@ void Object::SetViewportHeight(int height) { viewportHeight = height; } + +void Object::SetDeleteActive(bool state/*= true*/) +{ + deleteActive = state; +} diff --git a/src/object.h b/src/object.h index deaa91f..e4bbe78 100644 --- a/src/object.h +++ b/src/object.h @@ -30,6 +30,7 @@ class Object static void SetFixedLength(bool state = true); static void SetFont(QFont *); static void SetViewportHeight(int); + static void SetDeleteActive(bool state = true); protected: Vector position; // All objects have a position (doubles as reference point) @@ -47,6 +48,7 @@ class Object static bool fixedAngle; static bool fixedLength; static int viewportHeight; + static bool deleteActive; }; #endif // __OBJECT_H__ diff --git a/src/vector.cpp b/src/vector.cpp index da0d4c5..e9ad51f 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -25,6 +25,10 @@ Vector::Vector(double xx/*= 0*/, double yy/*= 0*/, double zz/*= 0*/): x(xx), y(y { } +Vector::Vector(Vector head, Vector tail): x(head.x - tail.x), y(head.y - tail.y), z(head.z - tail.z) +{ +} + Vector Vector::operator=(Vector const v) { x = v.x, y = v.y, z = v.z; @@ -169,3 +173,11 @@ double Vector::Dot(Vector v1, Vector v2) { return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z); } + +double Vector::Magnitude(Vector v1, Vector v2) +{ + double xx = v1.x - v2.x; + double yy = v1.y - v2.y; + double zz = v1.z - v2.z; + return sqrt(xx * xx + yy * yy + zz * zz); +} diff --git a/src/vector.h b/src/vector.h index c1cee7d..81a715f 100644 --- a/src/vector.h +++ b/src/vector.h @@ -16,6 +16,7 @@ class Vector { public: Vector(double xx = 0, double yy = 0, double zz = 0); + Vector(Vector head, Vector tail); // Create vector from two points Vector operator=(Vector const v); Vector operator+(Vector const v); Vector operator-(Vector const v); @@ -40,6 +41,7 @@ class Vector // Class methods static double Dot(Vector v1, Vector v2); + static double Magnitude(Vector v1, Vector v2); public: double x, y, z; -- 2.37.2