1 /****************************************************************************
2 ** $Id: rs_actiondrawcircle2p.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_actiondrawcircle2p.h"
28 #include "rs_snapper.h"
32 RS_ActionDrawCircle2P::RS_ActionDrawCircle2P(RS_EntityContainer& container,
33 RS_GraphicView& graphicView)
34 :RS_PreviewActionInterface("Draw circles",
35 container, graphicView) {
41 RS_ActionDrawCircle2P::~RS_ActionDrawCircle2P() {}
44 QAction* RS_ActionDrawCircle2P::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 QAction * action = new QAction(tr("2 Points"), 0);
47 // QAction* action = new QAction(tr("Circle: 2 Points"), tr("2 Points"),
48 // QKeySequence(), NULL);
49 action->setStatusTip(tr("Draw circles with 2 points"));
55 void RS_ActionDrawCircle2P::reset() {
57 point1 = Vector(false);
58 point2 = Vector(false);
63 void RS_ActionDrawCircle2P::init(int status) {
64 RS_PreviewActionInterface::init(status);
71 void RS_ActionDrawCircle2P::trigger() {
72 RS_PreviewActionInterface::trigger();
76 RS_Circle* circle = new RS_Circle(container,
78 circle->setLayerToActive();
79 circle->setPenToActive();
80 container->addEntity(circle);
84 document->startUndoCycle();
85 document->addUndoable(circle);
86 document->endUndoCycle();
90 Vector rz = graphicView->getRelativeZero();
91 graphicView->moveRelativeZero(Vector(0.0,0.0));
92 graphicView->drawEntity(circle);
93 graphicView->moveRelativeZero(rz);
99 if (RS_DIALOGFACTORY!=NULL) {
100 RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data."));
107 void RS_ActionDrawCircle2P::preparePreview() {
109 if (point1.valid && point2.valid) {
110 RS_Circle circle(NULL, data);
111 bool suc = circle.createFrom2P(point1, point2);
113 data = circle.getData();
119 void RS_ActionDrawCircle2P::mouseMoveEvent(QMouseEvent* e) {
120 Vector mouse = snapPoint(e);
121 switch (getStatus()) {
129 if (data.isValid()) {
130 RS_Circle* circle = new RS_Circle(preview, data);
133 preview->addEntity(circle);
145 void RS_ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent* e) {
146 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
147 RS_CoordinateEvent ce(snapPoint(e));
148 coordinateEvent(&ce);
149 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
158 void RS_ActionDrawCircle2P::coordinateEvent(RS_CoordinateEvent* e) {
163 Vector mouse = e->getCoordinate();
165 switch (getStatus()) {
168 graphicView->moveRelativeZero(mouse);
169 setStatus(SetPoint2);
174 graphicView->moveRelativeZero(mouse);
185 void RS_ActionDrawCircle2P::commandEvent(RS_CommandEvent* e) {
186 QString c = e->getCommand().toLower();
188 if (checkCommand("help", c)) {
189 if (RS_DIALOGFACTORY!=NULL) {
190 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
191 + getAvailableCommands().join(", "));
200 QStringList RS_ActionDrawCircle2P::getAvailableCommands() {
207 void RS_ActionDrawCircle2P::updateMouseButtonHints() {
208 if (RS_DIALOGFACTORY!=NULL) {
209 switch (getStatus()) {
211 RS_DIALOGFACTORY->updateMouseWidget(
212 tr("Specify first point"), tr("Cancel"));
215 RS_DIALOGFACTORY->updateMouseWidget(
216 tr("Specify second point"), tr("Back"));
219 RS_DIALOGFACTORY->updateMouseWidget("", "");
227 void RS_ActionDrawCircle2P::updateMouseCursor() {
228 graphicView->setMouseCursor(RS2::CadCursor);
233 void RS_ActionDrawCircle2P::updateToolBar() {
234 if (RS_DIALOGFACTORY!=NULL) {
236 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
238 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);