3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actioninfoangle.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "information.h"
24 ActionInfoAngle::ActionInfoAngle(EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Angle",
25 container, graphicView)
29 ActionInfoAngle::~ActionInfoAngle()
33 void ActionInfoAngle::init(int status)
35 ActionInterface::init(status);
38 void ActionInfoAngle::trigger()
40 DEBUG->print("ActionInfoAngle::trigger()");
43 if (entity1 != NULL && entity2 != NULL)
45 VectorSolutions sol = Information::getIntersection(entity1, entity2, false);
49 intersection = sol.get(0);
51 if (intersection.valid && point1.valid && point2.valid)
53 double angle1 = intersection.angleTo(point1);
54 double angle2 = intersection.angleTo(point2);
55 double angle = fabs(angle2 - angle1);
58 str.sprintf("%.6f", Math::rad2deg(angle));
59 DIALOGFACTORY->commandMessage(tr("Angle: %1%2").arg(str).arg(QChar(0xB0)));
63 DIALOGFACTORY->commandMessage(tr("Lines are parallel"));
67 void ActionInfoAngle::mouseMoveEvent(QMouseEvent * /*e*/)
69 DEBUG->print("ActionInfoAngle::mouseMoveEvent begin");
83 DEBUG->print("ActionInfoAngle::mouseMoveEvent end");
86 void ActionInfoAngle::mouseReleaseEvent(QMouseEvent * e)
88 if (e->button() == Qt::LeftButton)
90 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
95 entity1 = catchEntity(e);
97 if (entity1 != NULL && entity1->rtti() == RS2::EntityLine)
99 point1 = entity1->getNearestPointOnEntity(mouse);
100 setStatus(SetEntity2);
106 entity2 = catchEntity(e);
108 if (entity2 != NULL && entity2->rtti() == RS2::EntityLine)
110 point2 = entity2->getNearestPointOnEntity(mouse);
112 setStatus(SetEntity1);
121 else if (e->button() == Qt::RightButton)
125 init(getStatus() - 1);
129 void ActionInfoAngle::updateMouseButtonHints()
134 DIALOGFACTORY->updateMouseWidget(
135 tr("Specify first line"), tr("Cancel"));
139 DIALOGFACTORY->updateMouseWidget(
140 tr("Specify second line"), tr("Back"));
144 DIALOGFACTORY->updateMouseWidget("", "");
149 void ActionInfoAngle::updateMouseCursor()
151 graphicView->setMouseCursor(RS2::CadCursor);
154 void ActionInfoAngle::updateToolBar()
160 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
164 DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);