1 // rs_actionblocksinsert.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
13 // JLH 06/03/2010 Scrubbed out all occurances of RS_CoordinateEvent
16 #include "rs_actionblocksinsert.h"
19 #include "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "rs_modification.h"
23 #include "rs_preview.h"
28 RS_ActionBlocksInsert::RS_ActionBlocksInsert(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Blocks Insert",
29 container, graphicView)
33 RS_ActionBlocksInsert::~RS_ActionBlocksInsert()
38 QAction * RS_ActionBlocksInsert::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
40 QAction * action = new QAction(tr("&Insert Block"), 0);
41 // QAction* action = new QAction(tr("Insert Block"), tr("&Insert Block"),
42 // QKeySequence(), NULL);
43 action->setStatusTip(tr("Insert Block"));
50 /*virtual*/ RS2::ActionType RS_ActionBlocksInsert::rtti()
52 return RS2::ActionBlocksInsert;
55 void RS_ActionBlocksInsert::init(int status /*= 0*/)
57 RS_PreviewActionInterface::init(status);
63 block = graphic->getActiveBlock();
66 data.name = block->getName();
72 void RS_ActionBlocksInsert::reset()
74 data = RS_InsertData("", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0,
75 1, 1, Vector(1.0, 1.0), NULL, RS2::Update);
78 void RS_ActionBlocksInsert::trigger()
84 //RS_Modification m(*container, graphicView);
85 //m.paste(data.insertionPoint);
86 //std::cout << *RS_Clipboard::instance();
90 RS_Creation creation(container, graphicView);
91 data.updateMode = RS2::Update;
92 creation.createInsert(data);
95 graphicView->redraw();
99 void RS_ActionBlocksInsert::mouseMoveEvent(QMouseEvent * e)
104 data.insertionPoint = snapPoint(e);
110 //preview->addAllFrom(*block);
111 //preview->move(data.insertionPoint);
112 RS_Creation creation(preview, NULL, false);
113 // Create insert as preview only
114 data.updateMode = RS2::PreviewUpdate;
115 creation.createInsert(data);
125 void RS_ActionBlocksInsert::mouseReleaseEvent(QMouseEvent * e)
127 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
128 if (e->button() == Qt::LeftButton)
130 Vector ce(snapPoint(e));
131 coordinateEvent(&ce);
133 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
134 else if (e->button() == Qt::RightButton)
137 init(getStatus() - 1);
141 void RS_ActionBlocksInsert::coordinateEvent(Vector * e)
146 // data.insertionPoint = e->getCoordinate();
147 data.insertionPoint = *e;
151 void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent * e)
153 QString c = e->getCommand().toLower();
155 if (checkCommand("help", c))
157 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
158 + getAvailableCommands().join(", "));
166 if (checkCommand("angle", c))
171 lastStatus = (Status)getStatus();
174 else if (checkCommand("factor", c))
179 lastStatus = (Status)getStatus();
180 setStatus(SetFactor);
182 else if (checkCommand("columns", c))
187 lastStatus = (Status)getStatus();
188 setStatus(SetColumns);
190 else if (checkCommand("rows", c))
195 lastStatus = (Status)getStatus();
198 else if (checkCommand("columnspacing", c))
203 lastStatus = (Status)getStatus();
204 setStatus(SetColumnSpacing);
206 else if (checkCommand("rowspacing", c))
211 lastStatus = (Status)getStatus();
212 setStatus(SetRowSpacing);
219 double a = RS_Math::eval(c, &ok);
222 data.angle = RS_Math::deg2rad(a);
224 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
225 RS_DIALOGFACTORY->requestOptions(this, true, true);
226 setStatus(lastStatus);
233 double f = RS_Math::eval(c, &ok);
238 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
239 RS_DIALOGFACTORY->requestOptions(this, true, true);
240 setStatus(lastStatus);
247 int cols = (int)RS_Math::eval(c, &ok);
252 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
253 RS_DIALOGFACTORY->requestOptions(this, true, true);
254 setStatus(lastStatus);
261 int rows = (int)RS_Math::eval(c, &ok);
266 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
267 RS_DIALOGFACTORY->requestOptions(this, true, true);
268 setStatus(lastStatus);
272 case SetColumnSpacing:
275 double cs = (int)RS_Math::eval(c, &ok);
280 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
281 RS_DIALOGFACTORY->requestOptions(this, true, true);
282 setStatus(lastStatus);
289 int rs = (int)RS_Math::eval(c, &ok);
294 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
295 RS_DIALOGFACTORY->requestOptions(this, true, true);
296 setStatus(lastStatus);
305 QStringList RS_ActionBlocksInsert::getAvailableCommands()
312 cmd += command("angle");
313 cmd += command("factor");
314 cmd += command("columns");
315 cmd += command("rows");
316 cmd += command("columnspacing");
317 cmd += command("rowspacing");
327 void RS_ActionBlocksInsert::showOptions()
329 RS_ActionInterface::showOptions();
330 RS_DIALOGFACTORY->requestOptions(this, true);
333 void RS_ActionBlocksInsert::hideOptions()
335 RS_ActionInterface::hideOptions();
336 RS_DIALOGFACTORY->requestOptions(this, false);
339 void RS_ActionBlocksInsert::updateMouseButtonHints()
344 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
348 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
352 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
356 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"), "");
360 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"), "");
363 case SetColumnSpacing:
364 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"), "");
368 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"), "");
372 RS_DIALOGFACTORY->updateMouseWidget("", "");
377 void RS_ActionBlocksInsert::updateMouseCursor()
379 graphicView->setMouseCursor(RS2::CadCursor);
382 void RS_ActionBlocksInsert::updateToolBar()
385 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
387 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
390 double RS_ActionBlocksInsert::getAngle()
395 void RS_ActionBlocksInsert::setAngle(double a)
400 double RS_ActionBlocksInsert::getFactor()
402 return data.scaleFactor.x;
405 void RS_ActionBlocksInsert::setFactor(double f)
407 data.scaleFactor = Vector(f, f);
410 int RS_ActionBlocksInsert::getColumns()
415 void RS_ActionBlocksInsert::setColumns(int c)
420 int RS_ActionBlocksInsert::getRows()
425 void RS_ActionBlocksInsert::setRows(int r)
430 double RS_ActionBlocksInsert::getColumnSpacing()
432 return data.spacing.x;
435 void RS_ActionBlocksInsert::setColumnSpacing(double cs)
440 double RS_ActionBlocksInsert::getRowSpacing()
442 return data.spacing.y;
445 void RS_ActionBlocksInsert::setRowSpacing(double rs)