1 /****************************************************************************
2 ** $Id: rs_actiondrawlinepolygon.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_actiondrawlinepolygon.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
34 RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon(
35 RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_PreviewActionInterface("Draw Polygons", container, graphicView) {
39 center = Vector(false);
40 corner = Vector(false);
45 QAction* RS_ActionDrawLinePolygon::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
47 QAction * action = new QAction(tr("Pol&ygon (Cen,Cor)"), 0);
48 // QAction* action = new QAction(tr("Polygon"), tr("Pol&ygon (Cen,Cor)"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Draw polygon with center and corner"));
55 void RS_ActionDrawLinePolygon::trigger() {
56 RS_PreviewActionInterface::trigger();
62 RS_Creation creation(container, graphicView);
63 bool ok = creation.createPolygon(center, corner, number);
66 RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger:"
67 " No polygon added\n");
73 void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent* e) {
74 RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin");
76 Vector mouse = snapPoint(e);
78 switch (getStatus()) {
88 RS_Creation creation(preview, NULL, false);
89 creation.createPolygon(center, corner, number);
102 void RS_ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent* e) {
103 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
104 RS_CoordinateEvent ce(snapPoint(e));
105 coordinateEvent(&ce);
106 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
116 void RS_ActionDrawLinePolygon::coordinateEvent(RS_CoordinateEvent* e) {
121 Vector mouse = e->getCoordinate();
123 switch (getStatus()) {
126 setStatus(SetCorner);
127 graphicView->moveRelativeZero(mouse);
142 void RS_ActionDrawLinePolygon::updateMouseButtonHints() {
143 if (RS_DIALOGFACTORY!=NULL) {
144 switch (getStatus()) {
146 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"),
151 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), "");
155 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
159 RS_DIALOGFACTORY->updateMouseWidget("", "");
167 void RS_ActionDrawLinePolygon::showOptions() {
168 RS_ActionInterface::showOptions();
170 if (RS_DIALOGFACTORY!=NULL) {
171 RS_DIALOGFACTORY->requestOptions(this, true);
177 void RS_ActionDrawLinePolygon::hideOptions() {
178 RS_ActionInterface::hideOptions();
180 if (RS_DIALOGFACTORY!=NULL) {
181 RS_DIALOGFACTORY->requestOptions(this, false);
187 void RS_ActionDrawLinePolygon::commandEvent(RS_CommandEvent* e) {
188 QString c = e->getCommand().toLower();
190 if (checkCommand("help", c)) {
191 if (RS_DIALOGFACTORY!=NULL) {
192 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
193 + getAvailableCommands().join(", "));
198 switch (getStatus()) {
201 if (checkCommand("number", c)) {
205 lastStatus = (Status)getStatus();
206 setStatus(SetNumber);
212 int n = c.toInt(&ok);
214 if (n>0 && n<10000) {
217 if (RS_DIALOGFACTORY!=NULL) {
218 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
223 if (RS_DIALOGFACTORY!=NULL) {
224 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
227 if (RS_DIALOGFACTORY!=NULL) {
228 RS_DIALOGFACTORY->requestOptions(this, true, true);
230 setStatus(lastStatus);
241 QStringList RS_ActionDrawLinePolygon::getAvailableCommands() {
244 switch (getStatus()) {
247 cmd += command("number");
258 void RS_ActionDrawLinePolygon::updateMouseCursor() {
259 graphicView->setMouseCursor(RS2::CadCursor);
264 void RS_ActionDrawLinePolygon::updateToolBar() {
265 if (RS_DIALOGFACTORY!=NULL) {
267 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
269 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);