1 // rs_actioninfoarea.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_actioninfoarea.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionInfoArea::RS_ActionInfoArea(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Info Area",
22 container, graphicView)
26 RS_ActionInfoArea::~RS_ActionInfoArea()
30 void RS_ActionInfoArea::init(int status)
32 RS_ActionInterface::init(status);
37 //std::cout << "RS_ActionInfoArea::init: " << status << "\n";
40 void RS_ActionInfoArea::trigger()
42 RS_DEBUG->print("RS_ActionInfoArea::trigger()");
48 double area = ia.getArea();
49 double circ = ia.getCircumference();
51 RS_DEBUG->print("RS_ActionInfoArea::trigger: area: %f", area);
52 RS_DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area));
53 RS_DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ));
59 if (point1.valid && point2.valid) {
60 double dist = point1.distanceTo(point2);
62 str.sprintf("%.6f", dist);
63 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
68 void RS_ActionInfoArea::mouseMoveEvent(QMouseEvent * e)
70 //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent begin");
72 if (getStatus() == SetFirstPoint
73 || getStatus() == SetNextPoint)
75 Vector mouse = snapPoint(e);
88 if (currentLine != NULL)
90 preview->removeEntity(currentLine);
94 if (closingLine != NULL)
96 preview->removeEntity(closingLine);
100 currentLine = new RS_Line(preview,
103 preview->addEntity(currentLine);
105 if (preview->count() > 1)
107 closingLine = new RS_Line(preview,
111 preview->addEntity(closingLine);
123 //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent end");
126 void RS_ActionInfoArea::mouseReleaseEvent(QMouseEvent * e)
128 if (e->button() == Qt::LeftButton)
130 Vector ce(snapPoint(e));
131 coordinateEvent(&ce);
133 else if (e->button() == Qt::RightButton)
138 // close the polygon (preview)
139 if (getStatus() == SetNextPoint && prev.valid)
143 if (currentLine != NULL)
145 preview->removeEntity(currentLine);
149 if (closingLine != NULL)
151 preview->removeEntity(closingLine);
155 currentLine = new RS_Line(preview,
159 preview->addEntity(currentLine);
166 init(getStatus() - 1);
170 void RS_ActionInfoArea::coordinateEvent(Vector * e)
186 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
188 graphicView->moveRelativeZero(point1);
191 setStatus(SetNextPoint);
203 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
207 graphicView->moveRelativeZero(mouse);
210 // automatically detect that the polyline is now closed
214 setStatus(SetFirstPoint);
217 //setStatus(SetFirstPoint);
226 void RS_ActionInfoArea::updateMouseButtonHints()
231 RS_DIALOGFACTORY->updateMouseWidget(
232 tr("Specify first point of polygon"),
237 RS_DIALOGFACTORY->updateMouseWidget(
238 tr("Specify next point of polygon"),
243 RS_DIALOGFACTORY->updateMouseWidget("", "");
248 void RS_ActionInfoArea::updateMouseCursor()
250 graphicView->setMouseCursor(RS2::CadCursor);
253 void RS_ActionInfoArea::updateToolBar()
259 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
263 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);