1 /****************************************************************************
2 ** $Id: rs_actioninfoarea.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actioninfoarea.h"
29 #include "rs_snapper.h"
33 RS_ActionInfoArea::RS_ActionInfoArea(RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Info Area",
36 container, graphicView) {}
39 QAction* RS_ActionInfoArea::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
41 QAction * action = new QAction(tr("&Polygonal Area"), 0);
42 // QAction* action = new QAction(tr("Polygonal Area"),
43 // tr("&Polygonal Area"),
44 // QKeySequence(), NULL);
45 action->setStatusTip(tr("Measures the area of a polygon"));
50 void RS_ActionInfoArea::init(int status) {
51 RS_ActionInterface::init(status);
56 //std::cout << "RS_ActionInfoArea::init: " << status << "\n";
61 void RS_ActionInfoArea::trigger() {
63 RS_DEBUG->print("RS_ActionInfoArea::trigger()");
67 double area = ia.getArea();
68 double circ = ia.getCircumference();
70 RS_DEBUG->print("RS_ActionInfoArea::trigger: area: %f", area);
71 RS_DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area));
72 RS_DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ));
78 if (point1.valid && point2.valid) {
79 double dist = point1.distanceTo(point2);
81 str.sprintf("%.6f", dist);
82 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
89 void RS_ActionInfoArea::mouseMoveEvent(QMouseEvent* e) {
90 //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent begin");
92 if (getStatus()==SetFirstPoint ||
93 getStatus()==SetNextPoint) {
95 Vector mouse = snapPoint(e);
97 switch (getStatus()) {
104 if (currentLine!=NULL) {
105 preview->removeEntity(currentLine);
108 if (closingLine!=NULL) {
109 preview->removeEntity(closingLine);
113 currentLine = new RS_Line(preview,
116 preview->addEntity(currentLine);
118 if (preview->count()>1) {
119 closingLine = new RS_Line(preview,
123 preview->addEntity(closingLine);
135 //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent end");
140 void RS_ActionInfoArea::mouseReleaseEvent(QMouseEvent* e) {
141 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
142 RS_CoordinateEvent ce(snapPoint(e));
143 coordinateEvent(&ce);
144 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
148 // close the polygon (preview)
149 if (getStatus()==SetNextPoint && prev.valid) {
152 if (currentLine!=NULL) {
153 preview->removeEntity(currentLine);
156 if (closingLine!=NULL) {
157 preview->removeEntity(closingLine);
161 currentLine = new RS_Line(preview,
165 preview->addEntity(currentLine);
178 void RS_ActionInfoArea::coordinateEvent(RS_CoordinateEvent* e) {
183 Vector mouse = e->getCoordinate();
185 switch (getStatus()) {
193 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2")
194 .arg(mouse.x).arg(mouse.y));
196 graphicView->moveRelativeZero(point1);
199 setStatus(SetNextPoint);
209 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2")
210 .arg(mouse.x).arg(mouse.y));
214 graphicView->moveRelativeZero(mouse);
217 // automatically detect that the polyline is now closed
220 setStatus(SetFirstPoint);
223 //setStatus(SetFirstPoint);
233 void RS_ActionInfoArea::updateMouseButtonHints() {
234 switch (getStatus()) {
236 RS_DIALOGFACTORY->updateMouseWidget(
237 tr("Specify first point of polygon"),
241 RS_DIALOGFACTORY->updateMouseWidget(
242 tr("Specify next point of polygon"),
246 RS_DIALOGFACTORY->updateMouseWidget("", "");
253 void RS_ActionInfoArea::updateMouseCursor() {
254 graphicView->setMouseCursor(RS2::CadCursor);
259 void RS_ActionInfoArea::updateToolBar() {
260 switch (getStatus()) {
263 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
266 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);