From 6114b754fcd6e7d83c71dc2fa0ef2ec185387e12 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 23 Apr 2020 12:19:42 -0500 Subject: [PATCH] Minor updates to various files, removal of old cruft. Also, add new icons for cut, copy & paste actions. --- TODO | 3 +- architektonas.pro | 2 +- res/architektonas.qrc | 3 + res/editcopy2.png | Bin 0 -> 692 bytes res/editcut2.png | Bin 0 -> 981 bytes res/editpaste2.png | Bin 0 -> 818 bytes src/geometry.cpp | 7 + src/geometry.h | 1 + src/mathconstants.h | 2 +- src/objectwidget.cpp | 33 +--- src/triangulateaction.cpp | 335 -------------------------------------- src/triangulateaction.h | 34 ---- src/trimaction.cpp | 258 ----------------------------- src/trimaction.h | 30 ---- src/vector.cpp | 17 +- src/vector.h | 2 +- 16 files changed, 30 insertions(+), 697 deletions(-) create mode 100644 res/editcopy2.png create mode 100644 res/editcut2.png create mode 100644 res/editpaste2.png delete mode 100644 src/triangulateaction.cpp delete mode 100644 src/triangulateaction.h delete mode 100644 src/trimaction.cpp delete mode 100644 src/trimaction.h diff --git a/TODO b/TODO index b783d7e..d5ea1c7 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ Stuff To Be Implemented/Fixed (actually I think this should be more of the state code handling. Have to see.) - Add OSD to Object creation - - Add layers - Add blocks - Add page layout - Add fill/hatch to Objects @@ -26,11 +25,13 @@ Stuff To Be Implemented/Fixed - Trim/Slice tool (to be able to click on a line segment crossing another, and remove it and it only, or to cut the entity at other entities crossing) - Make Architektonas an MDI application + - Parallel tool (be able to make copy of object that's parallel to original) Stuff That's Done ----------------- + - Add layers [Shamus 2015ish] - Add pen color/style/width to Objects [Shamus 2017ish] - Fix loading and saving code [Shamus 2016ish] - Manipulate Dimension [Shamus 2014-03-20] diff --git a/architektonas.pro b/architektonas.pro index d79275e..4375488 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -2,7 +2,7 @@ # Architektonas Qt project file # # by James Hammons -# Copyright (C) 2015 Underground Software +# Copyright (C) 2020 Underground Software # # See the README and GPLv3 files for licensing and warranty information # diff --git a/res/architektonas.qrc b/res/architektonas.qrc index afe168c..16283e4 100644 --- a/res/architektonas.qrc +++ b/res/architektonas.qrc @@ -40,5 +40,8 @@ layer-up.png layer-down.png block-import.png + editcut2.png + editcopy2.png + editpaste2.png diff --git a/res/editcopy2.png b/res/editcopy2.png new file mode 100644 index 0000000000000000000000000000000000000000..051b84379a6894d63baa49403e80ea640f048711 GIT binary patch literal 692 zcmV;l0!#ggP)a0Mprzy-JgaRr*-%q^In zG3hXHU`U!oATdrHL4x7l+mCzC!vXJyv1V13`p;iq9cj1sjz&j^O$Z)qJ>CbD((LT~ z9Nymk@g|DQXMm!xtgSrUu$Ih~t?3{ofoO9#Jlr-dpS58KY53{x2W`&RG@~W>{Hy%G}&EBJ!x&e8$MgFxQ=! z+XS@M93OY-^>XgqsnTpNyqK7{_pvB!1*nD)zIyLJDWz@-WEmVCrKD-f($X{|BQZcD z%V;D?Mo~DjtpBRh*}Gd5_QMr{ejmEsK1yk{)|5&Y?P?XguW)eiha^cTm&@yeL300` zK?soN1;!}KWrK)t9lS9@97oja6U@v!WN4`T_FN#(K|~`rL0=G8La7unIXTAE)HudO z7^N-_VT_=Z!8y2GKZ|ZRCr!I}AE;DHhzKT0dL&6flJxOD;JwGWK%QIVlAR>+WZ8fa zgle^d)*55Lv|3wVTCJ@s&-HqP-u(RIm#eGOjWf8`7R0eZDTPvU>QFGi>&wG=ZmHGA zsMW?cyr-cQIOow?VQoNbh1LoYeX{oD;i9nA>k}+5&*B_77qC`%?{(Cp9GGA(KTNs8UfSfC?>L0BVAS)D~3O01HGn z?2y6+5G+uo2*Dx(RD=|vqNpJaZ7PLEu9^oWq@fShRUXAoD?jST*yC{~W6xX`5pD(l z`smYtbPi#R;mpLJu&O$kp#hZQ-&hvlblL}7TAI!(O6e6!$*-H685o9vK){E=!2wVJ zP-Z^{OYdjqew~f>RPIAIDbQqZp)TZA- zX?+H1g&><%kk6}7RUNU|UH0HXp`okmvGF5E23{@{)Lb0^7zm{xHalSI@GgA_B`8V}w{ER=_x1JseDvty1J|ytnX|K3PXYjs|Az1otO}gz3%KL#hDZ(Mas~AF z@BMse=y`E!>Pls1X7Sx%&_DJ+z%v(}XRJA-W?oZ5<`Exg5#nYb+_r{{K zXu>cFXpR8*0E97y$+v`LPsnmdV~*E*9>;l!$Faz9ZVbBxXe(8Sf(0XE#ncK-CT^NP z>18%bC@}C&T8{|ocn8O1Is0ic?NpfapW0R&Y3GsoiyTni6@ebuw+A6^pXP$ z6E(%C;Y@vnM3(5!wwsZnQTZj{BMl)x?YeZ5~l8RW;s`}V1AX2^-Mpn<13pUjXeT9D#quGwSmjo#+>IqbmxCkd3mo!x0nkk#Spdpg6q{-C&D(v(@EcE;$2p2dPnBWfj&rKUnEJ>oKMW0>4Q_ zK~#90O_MusTxAf3pZU(Wdv+}+YiHN7gIxqAM2SG$gRp`O5-!|CqCrql#4QE%AOt^v z0;NJJ)6hUg53=ILtB_j^zB zOZD2~!ou7q^N$Ut0d{vEn!B4jpPkn~f4MUABUK|*7DPBMO^j3C_!V#M+{{e>-PP4M zo>-Xga|qby^BZ4Z^qG4qTE7uuvIdf==*NK2o%~{9`GuA6ZJ(DeKEp(}LzexA2&8Gs zt4lBTfB0to0qT8TUv&I_=R2H@B+Ap+ll;AV1!Cm<-<)k4_o2>*hEV4?6Cf85P+};{0^hL!v|FHi&?+5!wI$Ch(lq^`s?3BQmJVN) zcpHcjh!KUsnG?_%pDV_Z>sm7y^k}zRIOnhFU_G%eaD{{1Lgm2KL}|g)7?328Bnet8 zrl)&!I&HSM@1vu4xCc4@p9-1)0x>jrUGZpn4^3k!iiQv(Y1&3a(9sy&y$8759Y;(; zgKsq;V{us;%CaKHK)0I$pj3j6g~9FB_;I*U!4Q1S5y6;%F_t7rNK+6w92NnMwItT! z?HC~5AW|{%4d)yp3XzD2LhF&?2>RY0TbqBm=ak}DfOXiDj?)4@fcFs*K_300qhHwB zPu{%w)5LqdG@39Xcq3+VpwGOMs8yvPO>ng9R*07*qoM6N<$f?ME!!vFvP literal 0 HcmV?d00001 diff --git a/src/geometry.cpp b/src/geometry.cpp index b52ff7e..4cd229f 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -341,6 +341,13 @@ Point Geometry::GetPointForParameter(Object * obj, double t) } +Point Geometry::Midpoint(Line * line) +{ + return Point((line->p[0].x + line->p[1].x) / 2.0, + (line->p[0].y + line->p[1].y) / 2.0); +} + + /* How to find the tangent of a point off a circle: diff --git a/src/geometry.h b/src/geometry.h index f1371e3..41cd472 100644 --- a/src/geometry.h +++ b/src/geometry.h @@ -18,6 +18,7 @@ class Geometry static void CheckLineToCircleIntersection(Object *, Object *); static void FindAnglesForSides(double s1, double s2, double s3, double * a1, double * a2, double * a3); static Point GetPointForParameter(Object *, double); + static Point Midpoint(Line *); }; #endif // __GEOMETRY_H__ diff --git a/src/mathconstants.h b/src/mathconstants.h index b0e516e..010dd18 100644 --- a/src/mathconstants.h +++ b/src/mathconstants.h @@ -12,7 +12,7 @@ // WHO WHEN WHAT // --- ---------- ----------------------------------------------------------- // JLH 04/01/2011 Created this file -// JLH 03/15/2016 Added Tau constants, removed Pi constants +// JLH 03/15/2016 Added Tau constants, removed Pi constants (Pi is wrong) // #define TAU 6.28318530717958647692528676655 diff --git a/src/objectwidget.cpp b/src/objectwidget.cpp index b4f2cda..915e103 100644 --- a/src/objectwidget.cpp +++ b/src/objectwidget.cpp @@ -1,7 +1,7 @@ // objectwidget.cpp: Object tweaking widget // // Part of the Architektonas Project -// (C) 2016 Underground Software +// (C) 2020 Underground Software // See the README and GPLv3 files for licensing and warranty information // // JLH = James Hammons @@ -17,22 +17,8 @@ ObjectWidget::ObjectWidget(void): QWidget() { -#if 0 - QListWidget * qlw = new QListWidget; - QListWidgetItem * qli1 = new QListWidgetItem(qlw); - QListWidgetItem * qli2 = new QListWidgetItem(qlw); - QListWidgetItem * qli3 = new QListWidgetItem(qlw); - QListWidgetItem * qli4 = new QListWidgetItem(qlw); - QListWidgetItem * qli5 = new QListWidgetItem(qlw); -#endif label = new QLabel; -#if 0 - QPushButton * pb1 = new QPushButton("+"); - QPushButton * pb2 = new QPushButton("-"); - QPushButton * pb3 = new QPushButton("Edit"); - QPushButton * pb4 = new QPushButton("Import"); -#else QToolButton * pb1 = new QToolButton; QToolButton * pb2 = new QToolButton; QToolButton * pb3 = new QToolButton; @@ -47,7 +33,6 @@ ObjectWidget::ObjectWidget(void): QWidget() pb2->setToolTip(tr("Remove block")); pb3->setToolTip(tr("Edit block")); pb4->setToolTip(tr("Import block")); -#endif QHBoxLayout * hbox1 = new QHBoxLayout; hbox1->addWidget(pb1); @@ -58,6 +43,7 @@ ObjectWidget::ObjectWidget(void): QWidget() QVBoxLayout * mainLayout = new QVBoxLayout; mainLayout->addWidget(label); + mainLayout->addStretch(); mainLayout->addLayout(hbox1); setLayout(mainLayout); @@ -71,19 +57,11 @@ ObjectWidget::~ObjectWidget() void ObjectWidget::ShowInfo(Object * obj) { - const char objName[OTCount][16] = { - "None", "Line", "Circle", "Ellipse", "Arc", "Polygon", "Dimension", "Spline", "Text", "Container" - }; - const char dimName[DTCount][32] = { - "Linear", "Vertical", "Horizontal", "Radial", "Diametric", - "Circumferential", "Angular", "Leader" - }; - // Sanity check if (obj == NULL) return; - QString s = QString("%1

").arg(QString(objName[obj->type])); + QString s = QString("%1

").arg(QString(objName[obj->type])); switch (obj->type) { @@ -104,13 +82,16 @@ void ObjectWidget::ShowInfo(Object * obj) case OTArc: s += QString("Center: <%1, %2>
Radius: %3
Start: %4°
Span: %5°
").arg(obj->p[0].x).arg(obj->p[0].y).arg(obj->radius[0]).arg(obj->angle[0] * RADIANS_TO_DEGREES).arg(obj->angle[1] * RADIANS_TO_DEGREES); break; - break; case OTPolygon: break; case OTDimension: + { + Dimension * d = (Dimension *)obj; + s += QString("Type: %1
").arg(dimName[d->subtype]); break; + } case OTSpline: break; diff --git a/src/triangulateaction.cpp b/src/triangulateaction.cpp deleted file mode 100644 index 1f6a949..0000000 --- a/src/triangulateaction.cpp +++ /dev/null @@ -1,335 +0,0 @@ -// triangulateaction.cpp: Action class for creating triangles from lines -// -// Part of the Architektonas Project -// (C) 2014 Underground Software -// See the README and GPLv3 files for licensing and warranty information -// -// JLH = James Hammons -// -// WHO WHEN WHAT -// --- ---------- ------------------------------------------------------------ -// JLH 05/07/2014 Created this file -// - -#include "triangulateaction.h" -#include "applicationwindow.h" -#include "circle.h" -#include "container.h" -#include "drawingview.h" -#include "geometry.h" -#include "line.h" -#include "mathconstants.h" -#include "painter.h" - - -enum { FIRST_LINE, SECOND_LINE, THIRD_LINE }; - - -TriangulateAction::TriangulateAction(): state(FIRST_LINE),// t(0), u(1.0), - line1(NULL), line2(NULL), line3(NULL), - doc(&(ApplicationWindow::drawing->document)) -//, line(NULL), -// shiftWasPressedOnNextPoint(false), ctrlWasPressed(false), -// mirror(new Container(Vector())) -{ -// ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror); -// mirror->Save(); -} - - -TriangulateAction::~TriangulateAction() -{ -} - - -/*virtual*/ void TriangulateAction::Draw(Painter * painter) -{ - Object * obj = doc->lastObjectHovered; - - if (obj == NULL) - return; - - // This assumes a Line, but it might not be! - painter->SetPen(QPen(Qt::blue, 2.0, Qt::DotLine)); -// Vector v(((Line *)obj)->position, ((Line *)obj)->endpoint); - Point p1 = ((Line *)obj)->position; - Point p2 = ((Line *)obj)->endpoint; - painter->DrawLine(p1, p2); -#if 0 - if (state == FIRST_POINT) - { - painter->DrawHandle(p1); - } - else - { - Vector reflectedP2 = -(p2 - p1); - Point newP2 = p1 + reflectedP2; - painter->DrawLine(newP2, p2); - painter->DrawHandle(p1); - - double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES; - - // Keep the angle between 0 and 180 degrees - if (absAngle > 180.0) - absAngle -= 180.0; - - QString text = QChar(0x2221) + QObject::tr(": %1"); - text = text.arg(absAngle); - - if (ctrlWasPressed) - text += " (Copy)"; - - painter->DrawInformativeText(text); - - // Draw the mirror only if there's been a line to mirror around - if (p1 != p2) - mirror->Draw(painter); - } -#endif -} - - -/*virtual*/ void TriangulateAction::MouseDown(Vector /*point*/) -{ -#if 0 -// this is not accurate enough. need to use the actual intersection point, not -// just the parameter(s). - Object * toTrim = doc->lastObjectHovered; - - if (toTrim == NULL) - return; - -//it would be nice to do it like this, but if we bisect the object, we have to -//create an extra one... -// toTrim->Trim(t, u); - - Vector v(((Line *)toTrim)->position, ((Line *)toTrim)->endpoint); - - // Check to see which case we have... - // We're trimming point #1... - if (t == 0) - { - ((Line *)toTrim)->position = ((Line *)toTrim)->position + (v * u); -// u = 1.0; - } - else if (u == 1.0) - { - ((Line *)toTrim)->endpoint = ((Line *)toTrim)->position + (v * t); -// t = 0; - } - else - { - Point p1 = ((Line *)toTrim)->position + (v * t); - Point p2 = ((Line *)toTrim)->position + (v * u); - Point p3 = ((Line *)toTrim)->endpoint; - ((Line *)toTrim)->endpoint = p1; - Line * line = new Line(p2, p3); - emit ObjectReady(line); -// t = 0, u = 1.0; - } - - doc->lastObjectHovered = NULL; -#endif -} - - -/*virtual*/ void TriangulateAction::MouseMoved(Vector point) -{ -#if 0 - if (state == FIRST_POINT) - p1 = point; -// else -// { -// p2 = point; -// mirror->Restore(); -// mirror->Mirror(p1, p2); -// } -#endif - -#if 0 -// Container & doc = ApplicationWindow::drawing->document; -// int items = doc.ItemsSelected(); - Object * toTrim = doc->lastObjectHovered; -// double closestPt1 = 0, closestPt2 = 1.0; - t = 0, u = 1.0; - - if (toTrim == NULL) - return; - - if (toTrim->type != OTLine) - return; - - double pointHoveredT = Geometry::ParameterOfLineAndPoint(((Line *)toTrim)->position, ((Line *)toTrim)->endpoint, point); - - std::vector::iterator i; - - for(i=doc->objects.begin(); i!=doc->objects.end(); i++) - { - // Can't trim against yourself... :-P - if (*i == toTrim) - continue; - - Object * trimAgainst = *i; - double t1;//, u1; - - if ((toTrim->type != OTLine) || (trimAgainst->type != OTLine)) - continue; - - int intersects = Geometry::Intersects((Line *)toTrim, (Line *)trimAgainst, &t1);//, &u1); - - if (intersects) - { - // Now what? We don't know which side to trim! - // ... now we do, we know which side of the Line we're on! - if ((t1 > t) && (t1 < pointHoveredT)) - t = t1; - - if ((t1 < u) && (t1 > pointHoveredT)) - u = t1; - } - } -#endif -} - - -/*virtual*/ void TriangulateAction::MouseReleased(void) -{ -#if 0 - if (state == FIRST_POINT) - { - p2 = p1; - state = NEXT_POINT; - } - else if (state == NEXT_POINT) - { - if (!ctrlWasPressed) - { - state = FIRST_POINT; - ApplicationWindow::drawing->document.MirrorSelected(p1, p2); - - mirror->Clear(); - ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror); - mirror->Save(); - } - else - { - mirror->CopyContentsTo(&(ApplicationWindow::drawing->document)); - } - } -#endif - Object * obj = doc->lastObjectHovered; - - if (obj == NULL) - return; - - if (obj->type != OTLine) - return; - - if (state == FIRST_LINE) - { - line1 = (Line *)obj; - line1->state = OSSelected; - state = SECOND_LINE; - } - else if (state == SECOND_LINE) - { - line2 = (Line *)obj; - line2->state = OSSelected; - state = THIRD_LINE; - } - else if (state == THIRD_LINE) - { - line3 = (Line *)obj; - state = FIRST_LINE; - Triangulate(); - } -} - - -/*virtual*/ void TriangulateAction::KeyDown(int /*key*/) -{ -#if 0 - if ((key == Qt::Key_Shift) && (state == NEXT_POINT)) - { - shiftWasPressedOnNextPoint = true; - p1Save = p1; - p1 = p2; - state = FIRST_POINT; - emit NeedRefresh(); - } - else if (key == Qt::Key_Control) - { - ctrlWasPressed = true; - emit NeedRefresh(); - } -#endif -#if 0 - if ((t == 0) && (u == 1.0)) - return; - - t = 0, u = 1.0; -#endif -} - - -/*virtual*/ void TriangulateAction::KeyReleased(int /*key*/) -{ -#if 0 - if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint) - { - shiftWasPressedOnNextPoint = false; - p2 = p1; - p1 = p1Save; - state = NEXT_POINT; - emit NeedRefresh(); - } - else if (key == Qt::Key_Control) - { - ctrlWasPressed = false; - emit NeedRefresh(); - } -#endif -} - - -void TriangulateAction::Triangulate(void) -{ -// N.B.: Should connect the line segments together, once made into a triangle... - double length2 = Vector(line2->position, line2->endpoint).Magnitude(); - double length3 = Vector(line3->position, line3->endpoint).Magnitude(); -#if 0 - double angle1, angle2, angle3; - double length1 = Vector(line1->position, line1->endpoint).Magnitude(); - Geometry::FindAnglesForSides(length1, length2, length3, &angle1, &angle2, &angle3); -printf("Triangulate: l1=%lf, l2=%lf, l3=%lf, a1=%lf, a2=%lf, a3=%lf\n", length1, length2, length3, angle1, angle2, angle3); - - // We use line1 as the base. Move the other lines to it. - double line1Angle = Vector(line1->position, line1->endpoint).Angle(); - double newLine2Angle = line1Angle + angle3; - Vector v; - v.SetAngleAndLength(newLine2Angle, length2); -printf(" line1Angle=%lf, newLine2Angle=%lf\n", line1Angle, newLine2Angle); - - line2->position = line1->endpoint; - line2->endpoint = line1->endpoint - v; - -// double line2Angle = Vector(line2->position, line2->endpoint).Angle(); -// double newLine3Angle = line2Angle + angle1; -// Vector v2; -// v2.SetAngleAndLength(newLine3Angle, length3); -#else - Circle c1(line1->position, length2), c2(line1->endpoint, length3); - Point p1, p2; - int n = Geometry::Intersects(&c1, &c2, 0, 0, 0, 0, &p1, &p2); -//printf("Circle-circle intersections: n=%i, <%lf, %lf, %lf>, <%lf, %lf, %lf>\n", n, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); -#endif - line2->position = line1->endpoint; - line2->endpoint = p1; - - line3->position = line2->endpoint; - line3->endpoint = line1->position; - - line1->state = OSInactive; - line2->state = OSInactive; -} - diff --git a/src/triangulateaction.h b/src/triangulateaction.h deleted file mode 100644 index 754954a..0000000 --- a/src/triangulateaction.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __TRIANGULATEACTION_H__ -#define __TRIANGULATEACTION_H__ - -#include "action.h" - -class Container; -class Line; - -class TriangulateAction: public Action -{ - public: - TriangulateAction(); - ~TriangulateAction(); - - virtual void Draw(Painter *); - virtual void MouseDown(Vector); - virtual void MouseMoved(Vector); - virtual void MouseReleased(void); - virtual void KeyDown(int); - virtual void KeyReleased(int); - - private: - void Triangulate(void); - - private: - int state; - Line * line1, * line2, * line3; -// Vector p1, p2, p1Save; -// double t, u; - Container * doc; -}; - -#endif // __TRIANGULATEACTION_H__ - diff --git a/src/trimaction.cpp b/src/trimaction.cpp deleted file mode 100644 index a72594a..0000000 --- a/src/trimaction.cpp +++ /dev/null @@ -1,258 +0,0 @@ -// trimaction.cpp: Action class for mirroring selected objects -// -// 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/27/2011 Created this file -// - -#include "trimaction.h" -#include "applicationwindow.h" -#include "container.h" -#include "drawingview.h" -#include "geometry.h" -#include "line.h" -#include "mathconstants.h" -#include "painter.h" - - -enum { FIRST_POINT, NEXT_POINT }; - - -TrimAction::TrimAction(): state(FIRST_POINT), t(0), u(1.0), - doc(&(ApplicationWindow::drawing->document)) -//, line(NULL), -// shiftWasPressedOnNextPoint(false), ctrlWasPressed(false), -// mirror(new Container(Vector())) -{ -// ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror); -// mirror->Save(); -} - - -TrimAction::~TrimAction() -{ -} - - -/*virtual*/ void TrimAction::Draw(Painter * painter) -{ - Object * obj = doc->lastObjectHovered; - - if (obj == NULL) - return; - - // This assumes a Line, but it might not be! - painter->SetPen(QPen(Qt::black, 2.0, Qt::DotLine)); - Vector v(((Line *)obj)->position, ((Line *)obj)->endpoint); - Point p1 = ((Line *)obj)->position + (v * t); - Point p2 = ((Line *)obj)->position + (v * u); - painter->DrawLine(p1, p2); -#if 0 - if (state == FIRST_POINT) - { - painter->DrawHandle(p1); - } - else - { - Vector reflectedP2 = -(p2 - p1); - Point newP2 = p1 + reflectedP2; - painter->DrawLine(newP2, p2); - painter->DrawHandle(p1); - - double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES; - - // Keep the angle between 0 and 180 degrees - if (absAngle > 180.0) - absAngle -= 180.0; - - QString text = QChar(0x2221) + QObject::tr(": %1"); - text = text.arg(absAngle); - - if (ctrlWasPressed) - text += " (Copy)"; - - painter->DrawInformativeText(text); - - // Draw the mirror only if there's been a line to mirror around - if (p1 != p2) - mirror->Draw(painter); - } -#endif -} - - -/*virtual*/ void TrimAction::MouseDown(Vector /*point*/) -{ -// this is not accurate enough. need to use the actual intersection point, not -// just the parameter(s). - Object * toTrim = doc->lastObjectHovered; - - if (toTrim == NULL) - return; - -//it would be nice to do it like this, but if we bisect the object, we have to -//create an extra one... -// toTrim->Trim(t, u); - - Vector v(((Line *)toTrim)->position, ((Line *)toTrim)->endpoint); - - // Check to see which case we have... - // We're trimming point #1... - if (t == 0) - { - ((Line *)toTrim)->position = ((Line *)toTrim)->position + (v * u); -// u = 1.0; - } - else if (u == 1.0) - { - ((Line *)toTrim)->endpoint = ((Line *)toTrim)->position + (v * t); -// t = 0; - } - else - { - Point p1 = ((Line *)toTrim)->position + (v * t); - Point p2 = ((Line *)toTrim)->position + (v * u); - Point p3 = ((Line *)toTrim)->endpoint; - ((Line *)toTrim)->endpoint = p1; - Line * line = new Line(p2, p3); - emit ObjectReady(line); -// t = 0, u = 1.0; - } - - doc->lastObjectHovered = NULL; -} - - -/*virtual*/ void TrimAction::MouseMoved(Vector point) -{ -#if 0 - if (state == FIRST_POINT) - p1 = point; -// else -// { -// p2 = point; -// mirror->Restore(); -// mirror->Mirror(p1, p2); -// } -#endif -// Container & doc = ApplicationWindow::drawing->document; -// int items = doc.ItemsSelected(); - Object * toTrim = doc->lastObjectHovered; -// double closestPt1 = 0, closestPt2 = 1.0; - t = 0, u = 1.0; - - if (toTrim == NULL) - return; - - if (toTrim->type != OTLine) - return; - - double pointHoveredT = Geometry::ParameterOfLineAndPoint(((Line *)toTrim)->position, ((Line *)toTrim)->endpoint, point); - - std::vector::iterator i; - - for(i=doc->objects.begin(); i!=doc->objects.end(); i++) - { - // Can't trim against yourself... :-P - if (*i == toTrim) - continue; - - Object * trimAgainst = *i; - double t1;//, u1; - - if ((toTrim->type != OTLine) || (trimAgainst->type != OTLine)) - continue; - - int intersects = Geometry::Intersects((Line *)toTrim, (Line *)trimAgainst, &t1);//, &u1); - - if (intersects) - { - // Now what? We don't know which side to trim! - // ... now we do, we know which side of the Line we're on! - if ((t1 > t) && (t1 < pointHoveredT)) - t = t1; - - if ((t1 < u) && (t1 > pointHoveredT)) - u = t1; - } - } -} - - -/*virtual*/ void TrimAction::MouseReleased(void) -{ -#if 0 - if (state == FIRST_POINT) - { - p2 = p1; - state = NEXT_POINT; - } - else if (state == NEXT_POINT) - { - if (!ctrlWasPressed) - { - state = FIRST_POINT; - ApplicationWindow::drawing->document.MirrorSelected(p1, p2); - - mirror->Clear(); - ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror); - mirror->Save(); - } - else - { - mirror->CopyContentsTo(&(ApplicationWindow::drawing->document)); - } - } -#endif -} - - -/*virtual*/ void TrimAction::KeyDown(int /*key*/) -{ -#if 0 - if ((key == Qt::Key_Shift) && (state == NEXT_POINT)) - { - shiftWasPressedOnNextPoint = true; - p1Save = p1; - p1 = p2; - state = FIRST_POINT; - emit NeedRefresh(); - } - else if (key == Qt::Key_Control) - { - ctrlWasPressed = true; - emit NeedRefresh(); - } -#endif - if ((t == 0) && (u == 1.0)) - return; - - t = 0, u = 1.0; -} - - -/*virtual*/ void TrimAction::KeyReleased(int /*key*/) -{ -#if 0 - if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint) - { - shiftWasPressedOnNextPoint = false; - p2 = p1; - p1 = p1Save; - state = NEXT_POINT; - emit NeedRefresh(); - } - else if (key == Qt::Key_Control) - { - ctrlWasPressed = false; - emit NeedRefresh(); - } -#endif -} - diff --git a/src/trimaction.h b/src/trimaction.h deleted file mode 100644 index 67e7c85..0000000 --- a/src/trimaction.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __TRIMACTION_H__ -#define __TRIMACTION_H__ - -#include "action.h" - -class Container; -class Line; - -class TrimAction: public Action -{ - public: - TrimAction(); - ~TrimAction(); - - virtual void Draw(Painter *); - virtual void MouseDown(Vector); - virtual void MouseMoved(Vector); - virtual void MouseReleased(void); - virtual void KeyDown(int); - virtual void KeyReleased(int); - - private: - int state; - Vector p1, p2, p1Save; - double t, u; - Container * doc; -}; - -#endif // __TRIMACTION_H__ - diff --git a/src/vector.cpp b/src/vector.cpp index 53c6bfe..20b8ef5 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -194,7 +194,8 @@ Vector Vector::Unit(void) { double mag = Magnitude(); - // If the magnitude of the vector is zero, then the Unit vector is undefined... + // If the magnitude of the vector is zero, then the Unit vector is + // undefined... if (mag == 0) return Vector(0, 0, 0); @@ -210,15 +211,11 @@ double Vector::Magnitude(void) double Vector::Angle(void) { - // acos returns a value between zero and PI, which means we don't know which - // quadrant the angle is in... Though, if the y-coordinate of the vector is - // negative, that means that the angle is in quadrants III - IV. + // acos returns a value between zero and TAU/2, which means we don't know + // which quadrant the angle is in... However, if the y-coordinate of the + // vector is negative, that means that the angle is in quadrants III - IV. double rawAngle = acos(Unit().x); -#if 0 - double correctedAngle = (y < 0 ? (2.0 * PI) - rawAngle : rawAngle); -#else double correctedAngle = (y < 0 ? TAU - rawAngle : rawAngle); -#endif return correctedAngle; } @@ -289,10 +286,10 @@ bool Vector::isZero(double epsilon/*= 1e-6*/) // This is done using the following formula: // (a . b) = ||a|| ||b|| cos(theta) // However, have to check for two degenerate cases, where a = cb: - // 1, if c > 0, theta = 0; 2, if c < 0, theta = 180°. + // 1) if c > 0, theta = 0; 2) if c < 0, theta = 180°. // Also, the vectors a & b have to be non-zero. // Also, have to check using an epsilon because acos will not return an - // exact value if the vectors are orthogonal + // exact value if the vectors are orthogonal. if (a.isZero() || b.isZero()) return 0; diff --git a/src/vector.h b/src/vector.h index e59b0e8..5ef0a92 100644 --- a/src/vector.h +++ b/src/vector.h @@ -4,7 +4,7 @@ // Various structures used for 3 dimensional imaging // // by James Hammons -// (C) 2001, 2014 Underground Software +// (C) 2001, 2018 Underground Software // #ifndef __VECTOR_H__ -- 2.37.2