1 /****************************************************************************
2 ** $Id: rs_actiondrawcircle3p.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_actiondrawcircle3p.h"
29 #include "rs_snapper.h"
33 RS_ActionDrawCircle3P::RS_ActionDrawCircle3P(RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Draw circles",
36 container, graphicView) {
42 RS_ActionDrawCircle3P::~RS_ActionDrawCircle3P() {}
45 QAction* RS_ActionDrawCircle3P::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
47 QAction * action = new QAction(tr("3 Points"), 0);
48 // QAction* action = new QAction(tr("Circle: 3 Points"), tr("3 Points"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Draw circles with 3 points"));
57 void RS_ActionDrawCircle3P::reset() {
59 point1 = Vector(false);
60 point2 = Vector(false);
61 point3 = Vector(false);
66 void RS_ActionDrawCircle3P::init(int status) {
67 RS_PreviewActionInterface::init(status);
74 void RS_ActionDrawCircle3P::trigger() {
75 RS_PreviewActionInterface::trigger();
79 RS_Circle* circle = new RS_Circle(container,
81 circle->setLayerToActive();
82 circle->setPenToActive();
83 container->addEntity(circle);
87 document->startUndoCycle();
88 document->addUndoable(circle);
89 document->endUndoCycle();
92 Vector rz = graphicView->getRelativeZero();
93 graphicView->moveRelativeZero(Vector(0.0,0.0));
94 graphicView->drawEntity(circle);
95 graphicView->moveRelativeZero(rz);
101 RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid circle data."));
106 void RS_ActionDrawCircle3P::preparePreview() {
108 if (point1.valid && point2.valid && point3.valid) {
109 RS_Circle circle(NULL, data);
110 bool suc = circle.createFrom3P(point1, point2, point3);
112 data = circle.getData();
119 void RS_ActionDrawCircle3P::mouseMoveEvent(QMouseEvent* e) {
120 Vector mouse = snapPoint(e);
122 switch (getStatus()) {
134 if (data.isValid()) {
135 RS_Circle* circle = new RS_Circle(preview, data);
139 preview->addEntity(circle);
148 void RS_ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent* e) {
149 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
150 RS_CoordinateEvent ce(snapPoint(e));
151 coordinateEvent(&ce);
152 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
161 void RS_ActionDrawCircle3P::coordinateEvent(RS_CoordinateEvent* e) {
165 Vector mouse = e->getCoordinate();
167 switch (getStatus()) {
170 graphicView->moveRelativeZero(mouse);
171 setStatus(SetPoint2);
176 graphicView->moveRelativeZero(mouse);
177 setStatus(SetPoint3);
192 void RS_ActionDrawCircle3P::commandEvent(RS_CommandEvent* e) {
193 QString c = e->getCommand().toLower();
195 if (checkCommand("help", c)) {
196 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
197 + getAvailableCommands().join(", "));
204 QStringList RS_ActionDrawCircle3P::getAvailableCommands() {
210 void RS_ActionDrawCircle3P::updateMouseButtonHints() {
211 switch (getStatus()) {
213 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"),
217 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
221 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify third point"),
225 RS_DIALOGFACTORY->updateMouseWidget("", "");
232 void RS_ActionDrawCircle3P::updateMouseCursor() {
233 graphicView->setMouseCursor(RS2::CadCursor);
238 void RS_ActionDrawCircle3P::updateToolBar() {
240 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
242 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);