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"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_information.h"
23 ActionInfoAngle::ActionInfoAngle(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Angle",
24 container, graphicView)
28 ActionInfoAngle::~ActionInfoAngle()
32 void ActionInfoAngle::init(int status)
34 ActionInterface::init(status);
37 void ActionInfoAngle::trigger()
39 RS_DEBUG->print("ActionInfoAngle::trigger()");
42 if (entity1 != NULL && entity2 != NULL)
44 VectorSolutions sol = RS_Information::getIntersection(entity1, entity2, false);
48 intersection = sol.get(0);
50 if (intersection.valid && point1.valid && point2.valid)
52 double angle1 = intersection.angleTo(point1);
53 double angle2 = intersection.angleTo(point2);
54 double angle = fabs(angle2 - angle1);
57 str.sprintf("%.6f", RS_Math::rad2deg(angle));
58 RS_DIALOGFACTORY->commandMessage(tr("Angle: %1%2").arg(str).arg(QChar(0xB0)));
62 RS_DIALOGFACTORY->commandMessage(tr("Lines are parallel"));
66 void ActionInfoAngle::mouseMoveEvent(QMouseEvent * /*e*/)
68 RS_DEBUG->print("ActionInfoAngle::mouseMoveEvent begin");
82 RS_DEBUG->print("ActionInfoAngle::mouseMoveEvent end");
85 void ActionInfoAngle::mouseReleaseEvent(QMouseEvent * e)
87 if (e->button() == Qt::LeftButton)
89 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
94 entity1 = catchEntity(e);
96 if (entity1 != NULL && entity1->rtti() == RS2::EntityLine)
98 point1 = entity1->getNearestPointOnEntity(mouse);
99 setStatus(SetEntity2);
105 entity2 = catchEntity(e);
107 if (entity2 != NULL && entity2->rtti() == RS2::EntityLine)
109 point2 = entity2->getNearestPointOnEntity(mouse);
111 setStatus(SetEntity1);
120 else if (e->button() == Qt::RightButton)
124 init(getStatus() - 1);
128 void ActionInfoAngle::updateMouseButtonHints()
133 RS_DIALOGFACTORY->updateMouseWidget(
134 tr("Specify first line"), tr("Cancel"));
138 RS_DIALOGFACTORY->updateMouseWidget(
139 tr("Specify second line"), tr("Back"));
143 RS_DIALOGFACTORY->updateMouseWidget("", "");
148 void ActionInfoAngle::updateMouseCursor()
150 graphicView->setMouseCursor(RS2::CadCursor);
153 void ActionInfoAngle::updateToolBar()
159 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
163 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);