]> Shamusworld >> Repos - architektonas/blob - src/actions/actioninfoarea.cpp
GPL compliance check...
[architektonas] / src / actions / actioninfoarea.cpp
1 // actioninfoarea.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 "actioninfoarea.h"
18
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
22
23 ActionInfoArea::ActionInfoArea(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Area",
24                 container, graphicView)
25 {
26 }
27
28 ActionInfoArea::~ActionInfoArea()
29 {
30 }
31
32 void ActionInfoArea::init(int status)
33 {
34         ActionInterface::init(status);
35
36         currentLine = NULL;
37         closingLine = NULL;
38
39         //std::cout << "ActionInfoArea::init: " << status << "\n";
40 }
41
42 void ActionInfoArea::trigger()
43 {
44         RS_DEBUG->print("ActionInfoArea::trigger()");
45
46         if (ia.isValid())
47         {
48                 ia.close();
49                 ia.calculate();
50                 double area = ia.getArea();
51                 double circ = ia.getCircumference();
52
53                 RS_DEBUG->print("ActionInfoArea::trigger: area: %f", area);
54                 RS_DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area));
55                 RS_DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ));
56         }
57
58         ia.reset();
59
60         /*
61            if (point1.valid && point2.valid) {
62             double dist = point1.distanceTo(point2);
63             QString str;
64             str.sprintf("%.6f", dist);
65             RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
66            }
67          */
68 }
69
70 void ActionInfoArea::mouseMoveEvent(QMouseEvent * e)
71 {
72         //RS_DEBUG->print("ActionInfoArea::mouseMoveEvent begin");
73
74         if (getStatus() == SetFirstPoint
75             || getStatus() == SetNextPoint)
76         {
77                 Vector mouse = snapPoint(e);
78
79                 switch (getStatus())
80                 {
81                 case SetFirstPoint:
82                         break;
83
84                 case SetNextPoint:
85
86                         if (prev.valid)
87                         {
88                                 deletePreview();
89
90                                 if (currentLine)
91                                 {
92 //                                      preview->removeEntity(currentLine);
93                                         currentLine = NULL;
94                                 }
95
96                                 if (closingLine)
97                                 {
98 //                                      preview->removeEntity(closingLine);
99                                         closingLine = NULL;
100                                 }
101
102 //                              currentLine = new RS_Line(preview, RS_LineData(prev, mouse));
103 //                              preview->addEntity(currentLine);
104
105 //                              if (preview->count() > 1)
106 //                              {
107 //                                      closingLine = new RS_Line(preview, RS_LineData(mouse, point1));
108 //                                      preview->addEntity(closingLine);
109 //                              }
110
111                                 drawPreview();
112                         }
113                         break;
114
115                 default:
116                         break;
117                 }
118         }
119 }
120
121 void ActionInfoArea::mouseReleaseEvent(QMouseEvent * e)
122 {
123         if (e->button() == Qt::LeftButton)
124         {
125                 Vector ce(snapPoint(e));
126                 coordinateEvent(&ce);
127         }
128         else if (e->button() == Qt::RightButton)
129         {
130                 // close the polygon (preview)
131                 if (getStatus() == SetNextPoint && prev.valid)
132                 {
133                         deletePreview();
134
135                         if (currentLine != NULL)
136                         {
137 //                              preview->removeEntity(currentLine);
138                                 currentLine = NULL;
139                         }
140
141                         if (closingLine != NULL)
142                         {
143 //                              preview->removeEntity(closingLine);
144                                 closingLine = NULL;
145                         }
146
147 //                      currentLine = new RS_Line(preview, RS_LineData(prev, point1));
148 //                      preview->addEntity(currentLine);
149                         drawPreview();
150                 }
151
152                 deleteSnapper();
153                 trigger();
154                 init(getStatus() - 1);
155         }
156 }
157
158 void ActionInfoArea::coordinateEvent(Vector * e)
159 {
160         if (e == NULL)
161                 return;
162
163         Vector mouse = *e;
164
165         switch (getStatus())
166         {
167         case SetFirstPoint:
168                 point1 = mouse;
169
170                 deletePreview();
171                 clearPreview();
172
173                 ia.addPoint(mouse);
174                 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
175
176                 graphicView->moveRelativeZero(point1);
177                 prev = mouse;
178
179                 setStatus(SetNextPoint);
180                 break;
181
182         case SetNextPoint:
183
184                 if (point1.valid)
185                 {
186                         ia.addPoint(mouse);
187                         RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
188
189                         currentLine = NULL;
190
191                         graphicView->moveRelativeZero(mouse);
192                         prev = mouse;
193
194                         // automatically detect that the polyline is now closed
195                         if (ia.isClosed())
196                         {
197                                 trigger();
198                                 setStatus(SetFirstPoint);
199                         }
200                 }
201                 break;
202
203         default:
204                 break;
205         }
206 }
207
208 void ActionInfoArea::updateMouseButtonHints()
209 {
210         switch (getStatus())
211         {
212         case SetFirstPoint:
213                 RS_DIALOGFACTORY->updateMouseWidget(
214                         tr("Specify first point of polygon"),
215                         tr("Cancel"));
216                 break;
217
218         case SetNextPoint:
219                 RS_DIALOGFACTORY->updateMouseWidget(
220                         tr("Specify next point of polygon"),
221                         tr("Terminate"));
222                 break;
223
224         default:
225                 RS_DIALOGFACTORY->updateMouseWidget("", "");
226                 break;
227         }
228 }
229
230 void ActionInfoArea::updateMouseCursor()
231 {
232         graphicView->setMouseCursor(RS2::CadCursor);
233 }
234
235 void ActionInfoArea::updateToolBar()
236 {
237         switch (getStatus())
238         {
239         case SetFirstPoint:
240         case SetNextPoint:
241                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
242                 break;
243
244         default:
245                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
246                 break;
247         }
248 }