1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "rs_actiondrawcirclecr.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_commandevent.h"
37
RS_ActionDrawCircleCR::RS_ActionDrawCircleCR(RS_EntityContainer& container,
38
RS_GraphicView& graphicView)
39
:RS_PreviewActionInterface("Draw circles CR",
40
container, graphicView) {
47
RS_ActionDrawCircleCR::~RS_ActionDrawCircleCR() {}
50
QAction* RS_ActionDrawCircleCR::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
51
// "Circle: Center, Radius"
52
QAction* action = new QAction(tr("Center, &Radius"), NULL);
53
action->setIcon(QIcon(":/extui/circlescr.png"));
54
//action->zetStatusTip(tr("Draw circles with center and radius"));
59
void RS_ActionDrawCircleCR::reset() {
60
data = RS_CircleData(RS_Vector(false), 0.0);
65
void RS_ActionDrawCircleCR::init(int status) {
66
RS_PreviewActionInterface::init(status);
71
void RS_ActionDrawCircleCR::trigger() {
72
RS_PreviewActionInterface::trigger();
74
RS_Circle* circle = new RS_Circle(container,
76
circle->setLayerToActive();
77
circle->setPenToActive();
78
container->addEntity(circle);
82
document->startUndoCycle();
83
document->addUndoable(circle);
84
document->endUndoCycle();
86
graphicView->redraw(RS2::RedrawDrawing);
87
graphicView->moveRelativeZero(circle->getCenter());
91
RS_DEBUG->print("RS_ActionDrawCircleCR::trigger(): circle added: %d",
97
void RS_ActionDrawCircleCR::mouseMoveEvent(QMouseEvent* e) {
98
RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent begin");
100
RS_Vector mouse = snapPoint(e);
101
switch (getStatus()) {
105
preview->addEntity(new RS_Circle(preview,
111
RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent end");
116
void RS_ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent* e) {
117
if (e->button()==Qt::LeftButton) {
118
RS_CoordinateEvent ce(snapPoint(e));
119
coordinateEvent(&ce);
120
} else if (e->button()==Qt::RightButton) {
128
void RS_ActionDrawCircleCR::coordinateEvent(RS_CoordinateEvent* e) {
133
RS_Vector mouse = e->getCoordinate();
135
switch (getStatus()) {
148
void RS_ActionDrawCircleCR::commandEvent(RS_CommandEvent* e) {
149
QString c = e->getCommand().toLower();
151
if (checkCommand("help", c)) {
152
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
153
+ getAvailableCommands().join(", "));
157
switch (getStatus()) {
159
if (checkCommand("radius", c)) {
161
setStatus(SetRadius);
167
double r = RS_Math::eval(c, &ok);
171
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
173
RS_DIALOGFACTORY->requestOptions(this, true, true);
174
setStatus(SetCenter);
185
QStringList RS_ActionDrawCircleCR::getAvailableCommands() {
188
switch (getStatus()) {
190
cmd += command("radius");
199
void RS_ActionDrawCircleCR::updateMouseButtonHints() {
200
switch (getStatus()) {
202
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle center"),
206
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle radius"),
210
RS_DIALOGFACTORY->updateMouseWidget("", "");
217
void RS_ActionDrawCircleCR::showOptions() {
218
RS_ActionInterface::showOptions();
220
RS_DIALOGFACTORY->requestOptions(this, true);
225
void RS_ActionDrawCircleCR::hideOptions() {
226
RS_ActionInterface::hideOptions();
228
RS_DIALOGFACTORY->requestOptions(this, false);
233
void RS_ActionDrawCircleCR::updateMouseCursor() {
234
graphicView->setMouseCursor(RS2::CadCursor);
239
//void RS_ActionDrawCircleCR::updateToolBar() {
240
// if (RS_DIALOGFACTORY!=NULL) {
241
// if (isFinished()) {
242
// RS_DIALOGFACTORY->resetToolBar();