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

« back to all changes in this revision

Viewing changes to src/actions/rs_actionmodifymoverotate.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_actionmodifymoverotate.h"
28
 
 
29
 
#include <QAction>
30
 
#include "rs_dialogfactory.h"
31
 
#include "rs_graphicview.h"
32
 
#include "rs_commandevent.h"
33
 
 
34
 
 
35
 
 
36
 
RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate(
37
 
    RS_EntityContainer& container,
38
 
    RS_GraphicView& graphicView)
39
 
        :RS_PreviewActionInterface("Move and Rotate Entities",
40
 
                           container, graphicView) {
41
 
}
42
 
 
43
 
QAction* RS_ActionModifyMoveRotate::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
44
 
        // tr("Move and Rotate")
45
 
    QAction* action = new QAction(tr("M&ove and Rotate"), NULL);
46
 
        action->setIcon(QIcon(":/extui/modifymoverotate.png"));
47
 
        //action->zetStatusTip(tr("Move and Rotate Entities"));
48
 
    return action;
49
 
}
50
 
 
51
 
void RS_ActionModifyMoveRotate::init(int status) {
52
 
    RS_ActionInterface::init(status);
53
 
}
54
 
 
55
 
 
56
 
 
57
 
void RS_ActionModifyMoveRotate::trigger() {
58
 
 
59
 
    RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()");
60
 
 
61
 
    RS_Modification m(*container, graphicView);
62
 
    m.moveRotate(data);
63
 
 
64
 
    finish();
65
 
 
66
 
    RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
67
 
}
68
 
 
69
 
 
70
 
 
71
 
void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent* e) {
72
 
    RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin");
73
 
 
74
 
    if (getStatus()==SetReferencePoint ||
75
 
            getStatus()==SetTargetPoint) {
76
 
 
77
 
        RS_Vector mouse = snapPoint(e);
78
 
        if(mouse.valid==false) return;
79
 
        switch (getStatus()) {
80
 
        case SetReferencePoint:
81
 
            data.referencePoint = mouse;
82
 
            break;
83
 
 
84
 
        case SetTargetPoint:
85
 
            if (data.referencePoint.valid) {
86
 
                targetPoint = mouse;
87
 
                data.offset = targetPoint-data.referencePoint;
88
 
 
89
 
                deletePreview();
90
 
                preview->addSelectionFrom(*container);
91
 
                preview->rotate(data.referencePoint, data.angle);
92
 
                preview->move(data.offset);
93
 
                drawPreview();
94
 
            }
95
 
            break;
96
 
 
97
 
        default:
98
 
            break;
99
 
        }
100
 
    }
101
 
 
102
 
    RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end");
103
 
}
104
 
 
105
 
 
106
 
 
107
 
void RS_ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent* e) {
108
 
    if (e->button()==Qt::LeftButton) {
109
 
        RS_Vector vp=snapPoint(e);
110
 
        if(vp.valid==false) return;
111
 
        RS_CoordinateEvent ce(vp);
112
 
        coordinateEvent(&ce);
113
 
    } else if (e->button()==Qt::RightButton) {
114
 
        deletePreview();
115
 
        init(getStatus()-1);
116
 
    }
117
 
}
118
 
 
119
 
 
120
 
 
121
 
void RS_ActionModifyMoveRotate::coordinateEvent(RS_CoordinateEvent* e) {
122
 
    if (e==NULL) {
123
 
        return;
124
 
    }
125
 
 
126
 
    RS_Vector pos = e->getCoordinate();
127
 
 
128
 
    switch (getStatus()) {
129
 
    case SetReferencePoint:
130
 
        data.referencePoint = pos;
131
 
        setStatus(SetTargetPoint);
132
 
        break;
133
 
 
134
 
    case SetTargetPoint:
135
 
        targetPoint = pos;
136
 
 
137
 
        setStatus(ShowDialog);
138
 
        data.offset = targetPoint - data.referencePoint;
139
 
        if (RS_DIALOGFACTORY->requestMoveRotateDialog(data)) {
140
 
            trigger();
141
 
            //finish();
142
 
        }
143
 
        break;
144
 
 
145
 
    default:
146
 
        break;
147
 
    }
148
 
}
149
 
 
150
 
 
151
 
void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent* e) {
152
 
    QString c = e->getCommand().toLower();
153
 
 
154
 
    if (checkCommand("help", c)) {
155
 
        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
156
 
                                         + getAvailableCommands().join(", "));
157
 
        return;
158
 
    }
159
 
 
160
 
    switch (getStatus()) {
161
 
    case SetReferencePoint:
162
 
    case SetTargetPoint:
163
 
                // RVT_PORT changed from if (c==checkCommand("angle", c)) {
164
 
        if (checkCommand("angle", c)) {
165
 
            deletePreview();
166
 
            lastStatus = (Status)getStatus();
167
 
            setStatus(SetAngle);
168
 
        }
169
 
        break;
170
 
 
171
 
    case SetAngle: {
172
 
            bool ok;
173
 
            double a = RS_Math::eval(c, &ok);
174
 
            if (ok==true) {
175
 
                data.angle = RS_Math::deg2rad(a);
176
 
            } else {
177
 
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
178
 
            }
179
 
            RS_DIALOGFACTORY->requestOptions(this, true, true);
180
 
            setStatus(lastStatus);
181
 
        }
182
 
        break;
183
 
    }
184
 
}
185
 
 
186
 
 
187
 
 
188
 
QStringList RS_ActionModifyMoveRotate::getAvailableCommands() {
189
 
    QStringList cmd;
190
 
 
191
 
    switch (getStatus()) {
192
 
    case SetReferencePoint:
193
 
    case SetTargetPoint:
194
 
        cmd += command("angle");
195
 
        break;
196
 
 
197
 
    default:
198
 
        break;
199
 
    }
200
 
 
201
 
    return cmd;
202
 
}
203
 
 
204
 
 
205
 
 
206
 
void RS_ActionModifyMoveRotate::showOptions() {
207
 
    //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n";
208
 
 
209
 
    RS_ActionInterface::showOptions();
210
 
 
211
 
    RS_DIALOGFACTORY->requestOptions(this, true);
212
 
}
213
 
 
214
 
 
215
 
 
216
 
void RS_ActionModifyMoveRotate::hideOptions() {
217
 
    //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n";
218
 
 
219
 
    RS_ActionInterface::hideOptions();
220
 
 
221
 
    RS_DIALOGFACTORY->requestOptions(this, false);
222
 
}
223
 
 
224
 
 
225
 
void RS_ActionModifyMoveRotate::updateMouseButtonHints() {
226
 
    switch (getStatus()) {
227
 
    case SetReferencePoint:
228
 
        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
229
 
                                            tr("Cancel"));
230
 
        break;
231
 
    case SetTargetPoint:
232
 
        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
233
 
                                            tr("Back"));
234
 
        break;
235
 
    case SetAngle:
236
 
        RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"),
237
 
                                            tr("Back"));
238
 
        break;
239
 
    default:
240
 
        RS_DIALOGFACTORY->updateMouseWidget("", "");
241
 
        break;
242
 
    }
243
 
}
244
 
 
245
 
 
246
 
 
247
 
void RS_ActionModifyMoveRotate::updateMouseCursor() {
248
 
    graphicView->setMouseCursor(RS2::CadCursor);
249
 
}
250
 
 
251
 
 
252
 
 
253
 
void RS_ActionModifyMoveRotate::updateToolBar() {
254
 
    switch (getStatus()) {
255
 
    case SetReferencePoint:
256
 
    case SetTargetPoint:
257
 
        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
258
 
        break;
259
 
    default:
260
 
        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
261
 
        break;
262
 
    }
263
 
}
264
 
 
265
 
 
266
 
// EOF