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