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