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_actiondimradial.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_commandevent.h"
35
RS_ActionDimRadial::RS_ActionDimRadial(
36
RS_EntityContainer& container,
37
RS_GraphicView& graphicView)
38
:RS_ActionDimension("Draw Radial Dimensions",
39
container, graphicView) {
44
QAction* RS_ActionDimRadial::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
46
QAction* action = new QAction(tr("&Radial"), NULL);
47
action->setIcon(QIcon(":/extui/dimradial.png"));
48
//action->zetStatusTip(tr("Radial Dimension"));
53
void RS_ActionDimRadial::reset() {
54
RS_ActionDimension::reset();
56
edata = RS_DimRadialData(RS_Vector(false),
59
pos = RS_Vector(false);
60
RS_DIALOGFACTORY->requestOptions(this, true, true);
65
void RS_ActionDimRadial::trigger() {
66
RS_ActionDimension::trigger();
70
RS_DimRadial* newEntity = NULL;
72
newEntity = new RS_DimRadial(container,
76
newEntity->setLayerToActive();
77
newEntity->setPenToActive();
79
container->addEntity(newEntity);
83
document->startUndoCycle();
84
document->addUndoable(newEntity);
85
document->endUndoCycle();
87
RS_Vector rz = graphicView->getRelativeZero();
88
graphicView->redraw(RS2::RedrawDrawing);
89
graphicView->moveRelativeZero(rz);
94
RS_DEBUG->print("RS_ActionDimRadial::trigger:"
100
void RS_ActionDimRadial::preparePreview() {
102
double angle = data.definitionPoint.angleTo(pos);
104
if (entity->rtti()==RS2::EntityArc) {
105
radius = ((RS_Arc*)entity)->getRadius();
106
} else if (entity->rtti()==RS2::EntityCircle) {
107
radius = ((RS_Circle*)entity)->getRadius();
110
edata.definitionPoint.setPolar(radius, angle);
111
edata.definitionPoint += data.definitionPoint;
117
void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent* e) {
118
RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin");
120
//RS_Vector mouse(graphicView->toGraphX(e->x()),
121
// graphicView->toGraphY(e->y()));
123
switch (getStatus()) {
125
entity = catchEntity(e, RS2::ResolveAll);
134
RS_DimRadial* d = new RS_DimRadial(preview, data, edata);
137
preview->addEntity(d);
147
RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end");
152
void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent* e) {
154
if (e->button()==Qt::LeftButton) {
155
switch (getStatus()) {
157
RS_Entity* en = catchEntity(e, RS2::ResolveAll);
159
if (en->rtti()==RS2::EntityArc ||
160
en->rtti()==RS2::EntityCircle) {
162
if (entity->rtti()==RS2::EntityArc) {
163
data.definitionPoint =
164
((RS_Arc*)entity)->getCenter();
165
} else if (entity->rtti()==RS2::EntityCircle) {
166
data.definitionPoint =
167
((RS_Circle*)entity)->getCenter();
169
graphicView->moveRelativeZero(data.definitionPoint);
172
RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
180
RS_CoordinateEvent ce(snapPoint(e));
181
coordinateEvent(&ce);
188
} else if (e->button()==Qt::RightButton) {
196
void RS_ActionDimRadial::coordinateEvent(RS_CoordinateEvent* e) {
201
switch (getStatus()) {
203
pos = e->getCoordinate();
206
setStatus(SetEntity);
216
void RS_ActionDimRadial::commandEvent(RS_CommandEvent* e) {
217
QString c = e->getCommand().toLower();
219
if (checkCommand("help", c)) {
220
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
221
+ getAvailableCommands().join(", "));
225
// setting new text label:
226
if (getStatus()==SetText) {
228
RS_DIALOGFACTORY->requestOptions(this, true, true);
229
graphicView->enableCoordinateInput();
230
setStatus(lastStatus);
235
if (checkCommand("text", c)) {
236
lastStatus = (Status)getStatus();
237
graphicView->disableCoordinateInput();
242
if (getStatus()==SetPos) {
244
double a = RS_Math::eval(c, &ok);
246
pos.setPolar(1.0, RS_Math::deg2rad(a));
247
pos += data.definitionPoint;
250
setStatus(SetEntity);
252
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
260
QStringList RS_ActionDimRadial::getAvailableCommands() {
263
switch (getStatus()) {
266
cmd += command("text");
277
void RS_ActionDimRadial::updateMouseButtonHints() {
278
switch (getStatus()) {
280
RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
284
RS_DIALOGFACTORY->updateMouseWidget(
285
tr("Specify dimension line position or enter angle:"),
289
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
292
RS_DIALOGFACTORY->updateMouseWidget("", "");
299
void RS_ActionDimRadial::showOptions() {
300
RS_ActionInterface::showOptions();
302
RS_DIALOGFACTORY->requestOptions(this, true);
303
//RS_DIALOGFACTORY->requestDimRadialOptions(edata, true);
308
void RS_ActionDimRadial::hideOptions() {
309
RS_ActionInterface::hideOptions();
311
//RS_DIALOGFACTORY->requestDimRadialOptions(edata, false);
312
RS_DIALOGFACTORY->requestOptions(this, false);