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_actionmodifymoverotate.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_commandevent.h"
36
RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate(
37
RS_EntityContainer& container,
38
RS_GraphicView& graphicView)
39
:RS_PreviewActionInterface("Move and Rotate Entities",
40
container, graphicView) {
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"));
51
void RS_ActionModifyMoveRotate::init(int status) {
52
RS_ActionInterface::init(status);
57
void RS_ActionModifyMoveRotate::trigger() {
59
RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()");
61
RS_Modification m(*container, graphicView);
66
RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
71
void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent* e) {
72
RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin");
74
if (getStatus()==SetReferencePoint ||
75
getStatus()==SetTargetPoint) {
77
RS_Vector mouse = snapPoint(e);
78
if(mouse.valid==false) return;
79
switch (getStatus()) {
80
case SetReferencePoint:
81
data.referencePoint = mouse;
85
if (data.referencePoint.valid) {
87
data.offset = targetPoint-data.referencePoint;
90
preview->addSelectionFrom(*container);
91
preview->rotate(data.referencePoint, data.angle);
92
preview->move(data.offset);
102
RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end");
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) {
121
void RS_ActionModifyMoveRotate::coordinateEvent(RS_CoordinateEvent* e) {
126
RS_Vector pos = e->getCoordinate();
128
switch (getStatus()) {
129
case SetReferencePoint:
130
data.referencePoint = pos;
131
setStatus(SetTargetPoint);
137
setStatus(ShowDialog);
138
data.offset = targetPoint - data.referencePoint;
139
if (RS_DIALOGFACTORY->requestMoveRotateDialog(data)) {
151
void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent* e) {
152
QString c = e->getCommand().toLower();
154
if (checkCommand("help", c)) {
155
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
156
+ getAvailableCommands().join(", "));
160
switch (getStatus()) {
161
case SetReferencePoint:
163
// RVT_PORT changed from if (c==checkCommand("angle", c)) {
164
if (checkCommand("angle", c)) {
166
lastStatus = (Status)getStatus();
173
double a = RS_Math::eval(c, &ok);
175
data.angle = RS_Math::deg2rad(a);
177
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
179
RS_DIALOGFACTORY->requestOptions(this, true, true);
180
setStatus(lastStatus);
188
QStringList RS_ActionModifyMoveRotate::getAvailableCommands() {
191
switch (getStatus()) {
192
case SetReferencePoint:
194
cmd += command("angle");
206
void RS_ActionModifyMoveRotate::showOptions() {
207
//std::cout << "RS_ActionModifyMoveRotate::showOptions()\n";
209
RS_ActionInterface::showOptions();
211
RS_DIALOGFACTORY->requestOptions(this, true);
216
void RS_ActionModifyMoveRotate::hideOptions() {
217
//std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n";
219
RS_ActionInterface::hideOptions();
221
RS_DIALOGFACTORY->requestOptions(this, false);
225
void RS_ActionModifyMoveRotate::updateMouseButtonHints() {
226
switch (getStatus()) {
227
case SetReferencePoint:
228
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
232
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
236
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"),
240
RS_DIALOGFACTORY->updateMouseWidget("", "");
247
void RS_ActionModifyMoveRotate::updateMouseCursor() {
248
graphicView->setMouseCursor(RS2::CadCursor);
253
void RS_ActionModifyMoveRotate::updateToolBar() {
254
switch (getStatus()) {
255
case SetReferencePoint:
257
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
260
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);