1 /****************************************************************************
2 ** $Id: rs_actiondrawarc3p.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_actiondrawarc3p.h"
29 #include "rs_actiondrawarc.h"
31 #include "rs_snapper.h"
32 #include "rs_dialogfactory.h"
34 RS_ActionDrawArc3P::RS_ActionDrawArc3P(RS_EntityContainer & container,
35 RS_GraphicView & graphicView):
36 RS_PreviewActionInterface("Draw arcs 3P", container, graphicView)
41 RS_ActionDrawArc3P::~RS_ActionDrawArc3P()
45 QAction * RS_ActionDrawArc3P::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
47 QAction * action = new QAction(tr("&3 Points"), 0);
48 // QAction* action = new QAction(tr("Arc: 3 Points"), tr("&3 Points"), QKeySequence(), NULL);
49 action->setStatusTip(tr("Draw arcs with 3 points"));
53 void RS_ActionDrawArc3P::reset()
56 point1 = Vector(false);
57 point2 = Vector(false);
58 point3 = Vector(false);
61 void RS_ActionDrawArc3P::init(int status)
63 RS_PreviewActionInterface::init(status);
68 void RS_ActionDrawArc3P::trigger()
70 RS_PreviewActionInterface::trigger();
75 RS_Arc * arc = new RS_Arc(container, data);
76 arc->setLayerToActive();
77 arc->setPenToActive();
78 container->addEntity(arc);
83 document->startUndoCycle();
84 document->addUndoable(arc);
85 document->endUndoCycle();
89 graphicView->moveRelativeZero(Vector(0.0, 0.0));
90 graphicView->drawEntity(arc);
91 graphicView->moveRelativeZero(arc->getEndpoint());
99 RS_DIALOGFACTORY->commandMessage(tr("Invalid arc data."));
103 void RS_ActionDrawArc3P::preparePreview()
107 if (point1.valid && point2.valid && point3.valid)
109 RS_Arc arc(NULL, data);
110 bool suc = arc.createFrom3P(point1, point2, point3);
113 data = arc.getData();
117 void RS_ActionDrawArc3P::mouseMoveEvent(QMouseEvent * e)
119 Vector mouse = snapPoint(e);
132 RS_Line * line = new RS_Line(preview, RS_LineData(point1, point2));
136 preview->addEntity(line);
147 RS_Arc * arc = new RS_Arc(preview, data);
151 preview->addEntity(arc);
161 void RS_ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e)
163 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
165 RS_CoordinateEvent ce(snapPoint(e));
166 coordinateEvent(&ce);
168 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
172 init(getStatus() - 1);
176 void RS_ActionDrawArc3P::coordinateEvent(RS_CoordinateEvent * e)
181 Vector mouse = e->getCoordinate();
187 graphicView->moveRelativeZero(mouse);
188 setStatus(SetPoint2);
193 graphicView->moveRelativeZero(mouse);
194 setStatus(SetPoint3);
207 void RS_ActionDrawArc3P::commandEvent(RS_CommandEvent * e)
209 QString c = e->getCommand().toLower();
211 if (checkCommand("help", c))
213 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
214 + getAvailableCommands().join(", "));
218 if (RS_COMMANDS->checkCommand("center", c, rtti()))
221 graphicView->setCurrentAction(new RS_ActionDrawArc(*container, *graphicView));
225 QStringList RS_ActionDrawArc3P::getAvailableCommands()
231 void RS_ActionDrawArc3P::updateMouseButtonHints()
236 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify startpoint or [Center]"), tr("Cancel"));
239 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back"));
242 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify endpoint"), tr("Back"));
245 RS_DIALOGFACTORY->updateMouseWidget("", "");
250 void RS_ActionDrawArc3P::updateMouseCursor()
252 graphicView->setMouseCursor(RS2::CadCursor);
255 void RS_ActionDrawArc3P::updateToolBar()
258 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
260 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);