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_creation.h"
20 #include "rs_dialogfactory.h"
21 #include "rs_modification.h"
22 #include "rs_preview.h"
27 RS_ActionBlocksInsert::RS_ActionBlocksInsert(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Blocks Insert",
28 container, graphicView)
32 RS_ActionBlocksInsert::~RS_ActionBlocksInsert()
37 QAction * RS_ActionBlocksInsert::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
39 QAction * action = new QAction(tr("&Insert Block"), 0);
40 // QAction* action = new QAction(tr("Insert Block"), tr("&Insert Block"),
41 // QKeySequence(), NULL);
42 action->setStatusTip(tr("Insert Block"));
49 /*virtual*/ RS2::ActionType RS_ActionBlocksInsert::rtti()
51 return RS2::ActionBlocksInsert;
54 void RS_ActionBlocksInsert::init(int status /*= 0*/)
56 RS_PreviewActionInterface::init(status);
62 block = graphic->getActiveBlock();
65 data.name = block->getName();
71 void RS_ActionBlocksInsert::reset()
73 data = RS_InsertData("", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0,
74 1, 1, Vector(1.0, 1.0), NULL, RS2::Update);
77 void RS_ActionBlocksInsert::trigger()
83 //RS_Modification m(*container, graphicView);
84 //m.paste(data.insertionPoint);
85 //std::cout << *RS_Clipboard::instance();
89 RS_Creation creation(container, graphicView);
90 data.updateMode = RS2::Update;
91 creation.createInsert(data);
94 graphicView->redraw();
98 void RS_ActionBlocksInsert::mouseMoveEvent(QMouseEvent * e)
103 data.insertionPoint = snapPoint(e);
109 //preview->addAllFrom(*block);
110 //preview->move(data.insertionPoint);
111 RS_Creation creation(preview, NULL, false);
112 // Create insert as preview only
113 data.updateMode = RS2::PreviewUpdate;
114 creation.createInsert(data);
124 void RS_ActionBlocksInsert::mouseReleaseEvent(QMouseEvent * e)
126 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
127 if (e->button() == Qt::LeftButton)
129 Vector ce(snapPoint(e));
130 coordinateEvent(&ce);
132 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
133 else if (e->button() == Qt::RightButton)
136 init(getStatus() - 1);
140 void RS_ActionBlocksInsert::coordinateEvent(Vector * e)
145 // data.insertionPoint = e->getCoordinate();
146 data.insertionPoint = *e;
150 void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent * e)
152 QString c = e->getCommand().toLower();
154 if (checkCommand("help", c))
156 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
157 + getAvailableCommands().join(", "));
165 if (checkCommand("angle", c))
170 lastStatus = (Status)getStatus();
173 else if (checkCommand("factor", c))
178 lastStatus = (Status)getStatus();
179 setStatus(SetFactor);
181 else if (checkCommand("columns", c))
186 lastStatus = (Status)getStatus();
187 setStatus(SetColumns);
189 else if (checkCommand("rows", c))
194 lastStatus = (Status)getStatus();
197 else if (checkCommand("columnspacing", c))
202 lastStatus = (Status)getStatus();
203 setStatus(SetColumnSpacing);
205 else if (checkCommand("rowspacing", c))
210 lastStatus = (Status)getStatus();
211 setStatus(SetRowSpacing);
218 double a = RS_Math::eval(c, &ok);
221 data.angle = RS_Math::deg2rad(a);
223 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
224 RS_DIALOGFACTORY->requestOptions(this, true, true);
225 setStatus(lastStatus);
232 double f = RS_Math::eval(c, &ok);
237 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
238 RS_DIALOGFACTORY->requestOptions(this, true, true);
239 setStatus(lastStatus);
246 int cols = (int)RS_Math::eval(c, &ok);
251 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
252 RS_DIALOGFACTORY->requestOptions(this, true, true);
253 setStatus(lastStatus);
260 int rows = (int)RS_Math::eval(c, &ok);
265 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
266 RS_DIALOGFACTORY->requestOptions(this, true, true);
267 setStatus(lastStatus);
271 case SetColumnSpacing:
274 double cs = (int)RS_Math::eval(c, &ok);
279 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
280 RS_DIALOGFACTORY->requestOptions(this, true, true);
281 setStatus(lastStatus);
288 int rs = (int)RS_Math::eval(c, &ok);
293 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
294 RS_DIALOGFACTORY->requestOptions(this, true, true);
295 setStatus(lastStatus);
304 QStringList RS_ActionBlocksInsert::getAvailableCommands()
311 cmd += command("angle");
312 cmd += command("factor");
313 cmd += command("columns");
314 cmd += command("rows");
315 cmd += command("columnspacing");
316 cmd += command("rowspacing");
326 void RS_ActionBlocksInsert::showOptions()
328 RS_ActionInterface::showOptions();
329 RS_DIALOGFACTORY->requestOptions(this, true);
332 void RS_ActionBlocksInsert::hideOptions()
334 RS_ActionInterface::hideOptions();
335 RS_DIALOGFACTORY->requestOptions(this, false);
338 void RS_ActionBlocksInsert::updateMouseButtonHints()
343 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
347 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
351 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
355 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"), "");
359 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"), "");
362 case SetColumnSpacing:
363 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"), "");
367 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"), "");
371 RS_DIALOGFACTORY->updateMouseWidget("", "");
376 void RS_ActionBlocksInsert::updateMouseCursor()
378 graphicView->setMouseCursor(RS2::CadCursor);
381 void RS_ActionBlocksInsert::updateToolBar()
384 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
386 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
389 double RS_ActionBlocksInsert::getAngle()
394 void RS_ActionBlocksInsert::setAngle(double a)
399 double RS_ActionBlocksInsert::getFactor()
401 return data.scaleFactor.x;
404 void RS_ActionBlocksInsert::setFactor(double f)
406 data.scaleFactor = Vector(f, f);
409 int RS_ActionBlocksInsert::getColumns()
414 void RS_ActionBlocksInsert::setColumns(int c)
419 int RS_ActionBlocksInsert::getRows()
424 void RS_ActionBlocksInsert::setRows(int r)
429 double RS_ActionBlocksInsert::getColumnSpacing()
431 return data.spacing.x;
434 void RS_ActionBlocksInsert::setColumnSpacing(double cs)
439 double RS_ActionBlocksInsert::getRowSpacing()
441 return data.spacing.y;
444 void RS_ActionBlocksInsert::setRowSpacing(double rs)