~ubuntu-branches/debian/sid/librecad/sid

« back to all changes in this revision

Viewing changes to librecad/src/actions/rs_actiondimradial.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2013-12-09 23:29:24 UTC
  • mfrom: (0.2.9) (11.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20131209232924-3w7aau9lo2bdv32c
Tags: 2.0.0~rc3+nolibs-1
* Merge from experimental to unstable.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
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.
 
13
**
 
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.
 
18
** 
 
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
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!  
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
#include "rs_actiondimradial.h"
 
28
 
 
29
#include <QAction>
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
#include "rs_commandevent.h"
 
33
 
 
34
 
 
35
RS_ActionDimRadial::RS_ActionDimRadial(
 
36
    RS_EntityContainer& container,
 
37
    RS_GraphicView& graphicView)
 
38
        :RS_ActionDimension("Draw Radial Dimensions",
 
39
                    container, graphicView) {
 
40
    reset();
 
41
}
 
42
 
 
43
 
 
44
QAction* RS_ActionDimRadial::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
 
45
        // tr("Radial")
 
46
    QAction* action = new QAction(tr("&Radial"),  NULL);
 
47
        action->setIcon(QIcon(":/extui/dimradial.png"));
 
48
    //action->zetStatusTip(tr("Radial Dimension"));
 
49
 
 
50
    return action;
 
51
}
 
52
 
 
53
void RS_ActionDimRadial::reset() {
 
54
    RS_ActionDimension::reset();
 
55
 
 
56
    edata = RS_DimRadialData(RS_Vector(false),
 
57
                             0.0);
 
58
    entity = NULL;
 
59
    pos = RS_Vector(false);
 
60
    RS_DIALOGFACTORY->requestOptions(this, true, true);
 
61
}
 
62
 
 
63
 
 
64
 
 
65
void RS_ActionDimRadial::trigger() {
 
66
    RS_ActionDimension::trigger();
 
67
 
 
68
    preparePreview();
 
69
    if (entity!=NULL) {
 
70
        RS_DimRadial* newEntity = NULL;
 
71
 
 
72
        newEntity = new RS_DimRadial(container,
 
73
                                     data,
 
74
                                     edata);
 
75
 
 
76
        newEntity->setLayerToActive();
 
77
        newEntity->setPenToActive();
 
78
        newEntity->update();
 
79
        container->addEntity(newEntity);
 
80
 
 
81
        // upd. undo list:
 
82
        if (document!=NULL) {
 
83
            document->startUndoCycle();
 
84
            document->addUndoable(newEntity);
 
85
            document->endUndoCycle();
 
86
        }
 
87
        RS_Vector rz = graphicView->getRelativeZero();
 
88
                graphicView->redraw(RS2::RedrawDrawing);
 
89
        graphicView->moveRelativeZero(rz);
 
90
        //drawSnapper();
 
91
 
 
92
    }
 
93
    else {
 
94
        RS_DEBUG->print("RS_ActionDimRadial::trigger:"
 
95
                        " Entity is NULL\n");
 
96
    }
 
97
}
 
98
 
 
99
 
 
100
void RS_ActionDimRadial::preparePreview() {
 
101
    if (entity!=NULL) {
 
102
        double angle = data.definitionPoint.angleTo(pos);
 
103
        double radius=0.0;
 
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();
 
108
        }
 
109
 
 
110
        edata.definitionPoint.setPolar(radius, angle);
 
111
        edata.definitionPoint += data.definitionPoint;
 
112
    }
 
113
}
 
114
 
 
115
 
 
116
 
 
117
void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent* e) {
 
118
    RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin");
 
119
 
 
120
    //RS_Vector mouse(graphicView->toGraphX(e->x()),
 
121
    //                graphicView->toGraphY(e->y()));
 
122
 
 
123
    switch (getStatus()) {
 
124
    case SetEntity:
 
125
        entity = catchEntity(e, RS2::ResolveAll);
 
126
        break;
 
127
 
 
128
    case SetPos:
 
129
        if (entity!=NULL) {
 
130
            pos = snapPoint(e);
 
131
 
 
132
            preparePreview();
 
133
 
 
134
            RS_DimRadial* d = new RS_DimRadial(preview, data, edata);
 
135
 
 
136
            deletePreview();
 
137
            preview->addEntity(d);
 
138
            d->update();
 
139
            drawPreview();
 
140
        }
 
141
        break;
 
142
 
 
143
    default:
 
144
        break;
 
145
    }
 
146
 
 
147
    RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end");
 
148
}
 
149
 
 
150
 
 
151
 
 
152
void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent* e) {
 
153
 
 
154
    if (e->button()==Qt::LeftButton) {
 
155
        switch (getStatus()) {
 
156
        case SetEntity: {
 
157
                RS_Entity* en = catchEntity(e, RS2::ResolveAll);
 
158
                if (en!=NULL) {
 
159
                    if (en->rtti()==RS2::EntityArc ||
 
160
                            en->rtti()==RS2::EntityCircle) {
 
161
                        entity = en;
 
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();
 
168
                        }
 
169
                        graphicView->moveRelativeZero(data.definitionPoint);
 
170
                        setStatus(SetPos);
 
171
                    } else {
 
172
                        RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
 
173
                                                            "or arc entity"));
 
174
                    }
 
175
                }
 
176
            }
 
177
            break;
 
178
 
 
179
        case SetPos: {
 
180
                RS_CoordinateEvent ce(snapPoint(e));
 
181
                coordinateEvent(&ce);
 
182
            }
 
183
            break;
 
184
 
 
185
        default:
 
186
            break;
 
187
        }
 
188
    } else if (e->button()==Qt::RightButton) {
 
189
        deletePreview();
 
190
        init(getStatus()-1);
 
191
    }
 
192
}
 
193
 
 
194
 
 
195
 
 
196
void RS_ActionDimRadial::coordinateEvent(RS_CoordinateEvent* e) {
 
197
    if (e==NULL) {
 
198
        return;
 
199
    }
 
200
 
 
201
    switch (getStatus()) {
 
202
    case SetPos:
 
203
        pos = e->getCoordinate();
 
204
        trigger();
 
205
        reset();
 
206
        setStatus(SetEntity);
 
207
        break;
 
208
 
 
209
    default:
 
210
        break;
 
211
    }
 
212
}
 
213
 
 
214
 
 
215
 
 
216
void RS_ActionDimRadial::commandEvent(RS_CommandEvent* e) {
 
217
    QString c = e->getCommand().toLower();
 
218
 
 
219
    if (checkCommand("help", c)) {
 
220
        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
 
221
                                         + getAvailableCommands().join(", "));
 
222
        return;
 
223
    }
 
224
 
 
225
    // setting new text label:
 
226
    if (getStatus()==SetText) {
 
227
        setText(c);
 
228
        RS_DIALOGFACTORY->requestOptions(this, true, true);
 
229
        graphicView->enableCoordinateInput();
 
230
        setStatus(lastStatus);
 
231
        return;
 
232
    }
 
233
 
 
234
    // command: text
 
235
    if (checkCommand("text", c)) {
 
236
        lastStatus = (Status)getStatus();
 
237
        graphicView->disableCoordinateInput();
 
238
        setStatus(SetText);
 
239
    }
 
240
 
 
241
    // setting angle
 
242
    if (getStatus()==SetPos) {
 
243
        bool ok;
 
244
        double a = RS_Math::eval(c, &ok);
 
245
        if (ok==true) {
 
246
            pos.setPolar(1.0, RS_Math::deg2rad(a));
 
247
            pos += data.definitionPoint;
 
248
            trigger();
 
249
            reset();
 
250
            setStatus(SetEntity);
 
251
        } else {
 
252
            RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
 
253
        }
 
254
        return;
 
255
    }
 
256
}
 
257
 
 
258
 
 
259
 
 
260
QStringList RS_ActionDimRadial::getAvailableCommands() {
 
261
    QStringList cmd;
 
262
 
 
263
    switch (getStatus()) {
 
264
    case SetEntity:
 
265
    case SetPos:
 
266
        cmd += command("text");
 
267
        break;
 
268
 
 
269
    default:
 
270
        break;
 
271
    }
 
272
 
 
273
    return cmd;
 
274
}
 
275
 
 
276
 
 
277
void RS_ActionDimRadial::updateMouseButtonHints() {
 
278
    switch (getStatus()) {
 
279
    case SetEntity:
 
280
        RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
 
281
                                            tr("Cancel"));
 
282
        break;
 
283
    case SetPos:
 
284
        RS_DIALOGFACTORY->updateMouseWidget(
 
285
            tr("Specify dimension line position or enter angle:"),
 
286
            tr("Cancel"));
 
287
        break;
 
288
    case SetText:
 
289
        RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
 
290
        break;
 
291
    default:
 
292
        RS_DIALOGFACTORY->updateMouseWidget("", "");
 
293
        break;
 
294
    }
 
295
}
 
296
 
 
297
 
 
298
 
 
299
void RS_ActionDimRadial::showOptions() {
 
300
    RS_ActionInterface::showOptions();
 
301
 
 
302
    RS_DIALOGFACTORY->requestOptions(this, true);
 
303
    //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true);
 
304
}
 
305
 
 
306
 
 
307
 
 
308
void RS_ActionDimRadial::hideOptions() {
 
309
    RS_ActionInterface::hideOptions();
 
310
 
 
311
    //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false);
 
312
    RS_DIALOGFACTORY->requestOptions(this, false);
 
313
}
 
314
 
 
315
 
 
316
 
 
317
// EOF