]> Shamusworld >> Repos - architektonas/commitdiff
Preliminary Delete Object tool implementation.
authorShamus Hammons <jlhamm@acm.org>
Thu, 19 May 2011 18:51:18 +0000 (18:51 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 19 May 2011 18:51:18 +0000 (18:51 +0000)
res/architektonas.qrc
src/applicationwindow.cpp
src/applicationwindow.h
src/container.cpp
src/line.cpp
src/object.cpp
src/object.h
src/vector.cpp
src/vector.h

index 60d9147c6d6b032f2b233303e8022c9e6c0263cc..b0b136053723e9b6413a5452fe8b09618f5d3491 100644 (file)
@@ -3,6 +3,7 @@
                <file>atns-icon.png</file>
                <file>fix-angle.png</file>
                <file>fix-length.png</file>
+               <file>generic-tool.png</file>
                <file>splash.png</file>
                <file>quit.png</file>
        </qresource>
index 99092d1abd8664db7f374b44de961eca72741f99..b156d15fa90ab926f2ea92098b380b9beef57fa1 100644 (file)
@@ -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)
index c6b8aa24d893173d71ab3ca8c6d957a476373dff..bbe01a4b29fb4d63b669718ac538661d0eaf3fe1 100644 (file)
@@ -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__
index 727c14360450cc498cf809b119bb08f3967021fb..4fceefdac106829e6d0a939f5e89fc27b66f437e 100644 (file)
@@ -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;
index c2831fcf91368c3b56b8d46fbe86f4dfefc0a29a..3f4b8d4aebae8a60557a5d1660fd0c5e748b4081 100644 (file)
@@ -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.
 
index eaef4d4484eb9d002d34777354554704cac985b7..4be11f55fa0961ceb78202881bcc3b2bc0ce577c 100644 (file)
@@ -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;
+}
index deaa91f3604f923b16a805fd57ccc55e241ca749..e4bbe781c7c2a0bcb86ee8179d03f100faf0cd48 100644 (file)
@@ -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__
index da0d4c557aae2fe4e68b5df17d8cf0d4ce5f0ccf..e9ad51f3427fa06ad918dd7793986369cacdef87 100644 (file)
@@ -25,6 +25,10 @@ Vector::Vector(double xx/*= 0*/, double yy/*= 0*/, double zz/*= 0*/): x(xx), y(y
 {\r
 }\r
 \r
+Vector::Vector(Vector head, Vector tail): x(head.x - tail.x), y(head.y - tail.y), z(head.z - tail.z)\r
+{\r
+}\r
+\r
 Vector Vector::operator=(Vector const v)\r
 {\r
        x = v.x, y = v.y, z = v.z;\r
@@ -169,3 +173,11 @@ double Vector::Dot(Vector v1, Vector v2)
 {\r
        return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);\r
 }\r
+\r
+double Vector::Magnitude(Vector v1, Vector v2)\r
+{\r
+       double xx = v1.x - v2.x;\r
+       double yy = v1.y - v2.y;\r
+       double zz = v1.z - v2.z;\r
+       return sqrt(xx * xx + yy * yy + zz * zz);\r
+}\r
index c1cee7dea145eade87160833abd5404f7a22f3a7..81a715f33e54ab533c3c022477b6074d9edf588f 100644 (file)
@@ -16,6 +16,7 @@ class Vector
 {\r
        public:\r
                Vector(double xx = 0, double yy = 0, double zz = 0);\r
+               Vector(Vector head, Vector tail);               // Create vector from two points\r
                Vector operator=(Vector const v);\r
                Vector operator+(Vector const v);\r
                Vector operator-(Vector const v);\r
@@ -40,6 +41,7 @@ class Vector
                // Class methods\r
 \r
                static double Dot(Vector v1, Vector v2);\r
+               static double Magnitude(Vector v1, Vector v2);\r
 \r
        public:\r
                double x, y, z;\r