]> Shamusworld >> Repos - architektonas/blob - src/actions/actioninfoangle.cpp
Removed unnecessary RS_ prefix from classes and whatnot.
[architektonas] / src / actions / actioninfoangle.cpp
1 // actioninfoangle.cpp
2 //
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
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/04/2010  Added this text. :-)
15 //
16
17 #include "actioninfoangle.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "information.h"
23
24 ActionInfoAngle::ActionInfoAngle(EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Angle",
25                 container, graphicView)
26 {
27 }
28
29 ActionInfoAngle::~ActionInfoAngle()
30 {
31 }
32
33 void ActionInfoAngle::init(int status)
34 {
35         ActionInterface::init(status);
36 }
37
38 void ActionInfoAngle::trigger()
39 {
40         DEBUG->print("ActionInfoAngle::trigger()");
41         deleteSnapper();
42
43         if (entity1 != NULL && entity2 != NULL)
44         {
45                 VectorSolutions sol = Information::getIntersection(entity1, entity2, false);
46
47                 if (sol.hasValid())
48                 {
49                         intersection = sol.get(0);
50
51                         if (intersection.valid && point1.valid && point2.valid)
52                         {
53                                 double angle1 = intersection.angleTo(point1);
54                                 double angle2 = intersection.angleTo(point2);
55                                 double angle = fabs(angle2 - angle1);
56
57                                 QString str;
58                                 str.sprintf("%.6f", Math::rad2deg(angle));
59                                 DIALOGFACTORY->commandMessage(tr("Angle: %1%2").arg(str).arg(QChar(0xB0)));
60                         }
61                 }
62                 else
63                         DIALOGFACTORY->commandMessage(tr("Lines are parallel"));
64         }
65 }
66
67 void ActionInfoAngle::mouseMoveEvent(QMouseEvent * /*e*/)
68 {
69         DEBUG->print("ActionInfoAngle::mouseMoveEvent begin");
70
71         switch (getStatus())
72         {
73         case SetEntity1:
74                 break;
75
76         case SetEntity2:
77                 break;
78
79         default:
80                 break;
81         }
82
83         DEBUG->print("ActionInfoAngle::mouseMoveEvent end");
84 }
85
86 void ActionInfoAngle::mouseReleaseEvent(QMouseEvent * e)
87 {
88         if (e->button() == Qt::LeftButton)
89         {
90                 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
91
92                 switch (getStatus())
93                 {
94                 case SetEntity1:
95                         entity1 = catchEntity(e);
96
97                         if (entity1 != NULL && entity1->rtti() == RS2::EntityLine)
98                         {
99                                 point1 = entity1->getNearestPointOnEntity(mouse);
100                                 setStatus(SetEntity2);
101                         }
102
103                         break;
104
105                 case SetEntity2:
106                         entity2 = catchEntity(e);
107
108                         if (entity2 != NULL && entity2->rtti() == RS2::EntityLine)
109                         {
110                                 point2 = entity2->getNearestPointOnEntity(mouse);
111                                 trigger();
112                                 setStatus(SetEntity1);
113                         }
114
115                         break;
116
117                 default:
118                         break;
119                 }
120         }
121         else if (e->button() == Qt::RightButton)
122         {
123                 deletePreview();
124                 deleteSnapper();
125                 init(getStatus() - 1);
126         }
127 }
128
129 void ActionInfoAngle::updateMouseButtonHints()
130 {
131         switch (getStatus())
132         {
133         case SetEntity1:
134                 DIALOGFACTORY->updateMouseWidget(
135                         tr("Specify first line"), tr("Cancel"));
136                 break;
137
138         case SetEntity2:
139                 DIALOGFACTORY->updateMouseWidget(
140                         tr("Specify second line"), tr("Back"));
141                 break;
142
143         default:
144                 DIALOGFACTORY->updateMouseWidget("", "");
145                 break;
146         }
147 }
148
149 void ActionInfoAngle::updateMouseCursor()
150 {
151         graphicView->setMouseCursor(RS2::CadCursor);
152 }
153
154 void ActionInfoAngle::updateToolBar()
155 {
156         switch (getStatus())
157         {
158         case SetEntity1:
159         case SetEntity2:
160                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
161                 break;
162
163         default:
164                 DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
165                 break;
166         }
167 }