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_actionblocksinsert.h"
30
#include "rs_graphic.h"
31
#include "rs_graphicview.h"
32
#include "rs_dialogfactory.h"
33
#include "rs_commandevent.h"
34
#include "rs_creation.h"
39
RS_ActionBlocksInsert::RS_ActionBlocksInsert(RS_EntityContainer& container,
40
RS_GraphicView& graphicView)
41
:RS_PreviewActionInterface("Blocks Insert",
42
container, graphicView) {
44
reset(); // init data Member
45
lastStatus = SetUndefined;
50
RS_ActionBlocksInsert::~RS_ActionBlocksInsert() {}
52
QAction* RS_ActionBlocksInsert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
54
QAction* action = new QAction(tr("&Insert Block"), NULL);
55
//action->zetStatusTip(tr("Insert Block"));
56
action->setIcon(QIcon(":/ui/blockinsert.png"));
60
void RS_ActionBlocksInsert::init(int status) {
61
RS_PreviewActionInterface::init(status);
66
block = graphic->getActiveBlock();
68
data.name = block->getName();
77
void RS_ActionBlocksInsert::reset() {
78
data = RS_InsertData("",
90
void RS_ActionBlocksInsert::trigger() {
93
//RS_Modification m(*container, graphicView);
94
//m.paste(data.insertionPoint);
95
//std::cout << *RS_Clipboard::instance();
98
RS_Creation creation(container, graphicView);
99
data.updateMode = RS2::Update;
100
creation.createInsert(data);
103
graphicView->redraw(RS2::RedrawDrawing);
109
void RS_ActionBlocksInsert::mouseMoveEvent(QMouseEvent* e) {
110
switch (getStatus()) {
112
data.insertionPoint = snapPoint(e);
116
//preview->addAllFrom(*block);
117
//preview->move(data.insertionPoint);
118
RS_Creation creation(preview, NULL, false);
119
// Create insert as preview only
120
data.updateMode = RS2::PreviewUpdate;
121
creation.createInsert(data);
133
void RS_ActionBlocksInsert::mouseReleaseEvent(QMouseEvent* e) {
134
if (e->button()==Qt::LeftButton) {
135
RS_CoordinateEvent ce(snapPoint(e));
136
coordinateEvent(&ce);
137
} else if (e->button()==Qt::RightButton) {
144
void RS_ActionBlocksInsert::coordinateEvent(RS_CoordinateEvent* e) {
149
data.insertionPoint = e->getCoordinate();
155
void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent* e) {
156
QString c = e->getCommand().toLower();
158
if (checkCommand("help", c)) {
159
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
160
+ getAvailableCommands().join(", "));
164
switch (getStatus()) {
166
if (checkCommand("angle", c)) {
168
lastStatus = (Status)getStatus();
170
} else if (checkCommand("factor", c)) {
172
lastStatus = (Status)getStatus();
173
setStatus(SetFactor);
174
} else if (checkCommand("columns", c)) {
176
lastStatus = (Status)getStatus();
177
setStatus(SetColumns);
178
} else if (checkCommand("rows", c)) {
180
lastStatus = (Status)getStatus();
182
} else if (checkCommand("columnspacing", c)) {
184
lastStatus = (Status)getStatus();
185
setStatus(SetColumnSpacing);
186
} else if (checkCommand("rowspacing", c)) {
188
lastStatus = (Status)getStatus();
189
setStatus(SetRowSpacing);
195
double a = RS_Math::eval(c, &ok);
197
data.angle = RS_Math::deg2rad(a);
199
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
201
RS_DIALOGFACTORY->requestOptions(this, true, true);
202
setStatus(lastStatus);
208
double f = RS_Math::eval(c, &ok);
212
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
214
RS_DIALOGFACTORY->requestOptions(this, true, true);
215
setStatus(lastStatus);
221
int cols = (int)RS_Math::eval(c, &ok);
225
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
227
RS_DIALOGFACTORY->requestOptions(this, true, true);
228
setStatus(lastStatus);
234
int rows = (int)RS_Math::eval(c, &ok);
238
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
240
RS_DIALOGFACTORY->requestOptions(this, true, true);
241
setStatus(lastStatus);
245
case SetColumnSpacing: {
247
double cs = (int)RS_Math::eval(c, &ok);
251
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
253
RS_DIALOGFACTORY->requestOptions(this, true, true);
254
setStatus(lastStatus);
258
case SetRowSpacing: {
260
int rs = (int)RS_Math::eval(c, &ok);
264
RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
266
RS_DIALOGFACTORY->requestOptions(this, true, true);
267
setStatus(lastStatus);
278
QStringList RS_ActionBlocksInsert::getAvailableCommands() {
281
switch (getStatus()) {
283
cmd += command("angle");
284
cmd += command("factor");
286
cmd += command("columns");
287
cmd += command("rows");
288
cmd += command("columnspacing");
289
cmd += command("rowspacing");
299
void RS_ActionBlocksInsert::showOptions() {
300
RS_ActionInterface::showOptions();
302
RS_DIALOGFACTORY->requestOptions(this, true);
307
void RS_ActionBlocksInsert::hideOptions() {
308
RS_ActionInterface::hideOptions();
310
RS_DIALOGFACTORY->requestOptions(this, false);
314
void RS_ActionBlocksInsert::updateMouseButtonHints() {
315
switch (getStatus()) {
317
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
321
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"),
325
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"),
329
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"),
333
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"),
336
case SetColumnSpacing:
337
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"),
341
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"),
345
RS_DIALOGFACTORY->updateMouseWidget("", "");
352
void RS_ActionBlocksInsert::updateMouseCursor() {
353
graphicView->setMouseCursor(RS2::CadCursor);
358
void RS_ActionBlocksInsert::updateToolBar() {
359
//not needed any more
362
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
364
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);