1 // rs_actioninfoangle.cpp
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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "rs_actioninfoangle.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_information.h"
21 RS_ActionInfoAngle::RS_ActionInfoAngle(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Info Angle",
22 container, graphicView)
26 RS_ActionInfoAngle::~RS_ActionInfoAngle()
30 void RS_ActionInfoAngle::init(int status)
32 RS_ActionInterface::init(status);
35 void RS_ActionInfoAngle::trigger()
37 RS_DEBUG->print("RS_ActionInfoAngle::trigger()");
40 if (entity1 != NULL && entity2 != NULL)
42 VectorSolutions sol = RS_Information::getIntersection(entity1, entity2, false);
46 intersection = sol.get(0);
48 if (intersection.valid && point1.valid && point2.valid)
50 double angle1 = intersection.angleTo(point1);
51 double angle2 = intersection.angleTo(point2);
52 double angle = fabs(angle2 - angle1);
55 str.sprintf("%.6f", RS_Math::rad2deg(angle));
56 RS_DIALOGFACTORY->commandMessage(tr("Angle: %1%2").arg(str).arg(QChar(0xB0)));
60 RS_DIALOGFACTORY->commandMessage(tr("Lines are parallel"));
64 void RS_ActionInfoAngle::mouseMoveEvent(QMouseEvent * /*e*/)
66 RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent begin");
80 RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent end");
83 void RS_ActionInfoAngle::mouseReleaseEvent(QMouseEvent * e)
85 if (e->button() == Qt::LeftButton)
87 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
92 entity1 = catchEntity(e);
94 if (entity1 != NULL && entity1->rtti() == RS2::EntityLine)
96 point1 = entity1->getNearestPointOnEntity(mouse);
97 setStatus(SetEntity2);
103 entity2 = catchEntity(e);
105 if (entity2 != NULL && entity2->rtti() == RS2::EntityLine)
107 point2 = entity2->getNearestPointOnEntity(mouse);
109 setStatus(SetEntity1);
118 else if (e->button() == Qt::RightButton)
122 init(getStatus() - 1);
126 void RS_ActionInfoAngle::updateMouseButtonHints()
131 RS_DIALOGFACTORY->updateMouseWidget(
132 tr("Specify first line"), tr("Cancel"));
136 RS_DIALOGFACTORY->updateMouseWidget(
137 tr("Specify second line"), tr("Back"));
141 RS_DIALOGFACTORY->updateMouseWidget("", "");
146 void RS_ActionInfoAngle::updateMouseCursor()
148 graphicView->setMouseCursor(RS2::CadCursor);
151 void RS_ActionInfoAngle::updateToolBar()
157 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
161 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);