1 // 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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/03/2010 Added this text. :-)
15 // JLH 06/03/2010 Scrubbed out all occurances of CoordinateEvent
18 #include "actionblocksinsert.h"
21 #include "commandevent.h"
23 #include "dialogfactory.h"
24 #include "modification.h"
30 ActionBlocksInsert::ActionBlocksInsert(EntityContainer & container, GraphicView & graphicView):
31 ActionInterface("Blocks Insert", container, graphicView)
35 ActionBlocksInsert::~ActionBlocksInsert()
39 /*virtual*/ RS2::ActionType ActionBlocksInsert::rtti()
41 return RS2::ActionBlocksInsert;
44 void ActionBlocksInsert::init(int status /*= 0*/)
46 ActionInterface::init(status);
51 block = graphic->getActiveBlock();
54 data.name = block->getName();
60 void ActionBlocksInsert::reset()
62 data = InsertData("", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0, 1, 1,
63 Vector(1.0, 1.0), NULL, RS2::Update);
66 void ActionBlocksInsert::trigger()
72 //Modification m(*container, graphicView);
73 //m.paste(data.insertionPoint);
74 //std::cout << *Clipboard::instance();
78 Creation creation(container, graphicView);
79 data.updateMode = RS2::Update;
80 creation.createInsert(data);
83 graphicView->redraw();
86 void ActionBlocksInsert::mouseMoveEvent(QMouseEvent * e)
91 // data.insertionPoint = snapPoint(e);
92 data.insertionPoint = graphicView->SnapPoint(e);
98 //preview->addAllFrom(*block);
99 //preview->move(data.insertionPoint);
100 // Creation creation(preview, NULL, false);
101 Creation creation(&(graphicView->preview), NULL, false);
102 // Create insert as preview only
103 data.updateMode = RS2::PreviewUpdate;
104 creation.createInsert(data);
114 void ActionBlocksInsert::mouseReleaseEvent(QMouseEvent * e)
116 if (e->button() == Qt::LeftButton)
118 // Vector ce(snapPoint(e));
119 Vector ce(graphicView->SnapPoint(e));
120 coordinateEvent(&ce);
122 else if (e->button() == Qt::RightButton)
125 init(getStatus() - 1);
129 void ActionBlocksInsert::coordinateEvent(Vector * e)
134 data.insertionPoint = *e;
138 void ActionBlocksInsert::commandEvent(CommandEvent * e)
140 QString c = e->getCommand().toLower();
142 if (checkCommand("help", c))
144 DIALOGFACTORY->commandMessage(msgAvailableCommands()
145 + getAvailableCommands().join(", "));
153 if (checkCommand("angle", c))
158 lastStatus = (Status)getStatus();
161 else if (checkCommand("factor", c))
166 lastStatus = (Status)getStatus();
167 setStatus(SetFactor);
169 else if (checkCommand("columns", c))
174 lastStatus = (Status)getStatus();
175 setStatus(SetColumns);
177 else if (checkCommand("rows", c))
182 lastStatus = (Status)getStatus();
185 else if (checkCommand("columnspacing", c))
190 lastStatus = (Status)getStatus();
191 setStatus(SetColumnSpacing);
193 else if (checkCommand("rowspacing", c))
198 lastStatus = (Status)getStatus();
199 setStatus(SetRowSpacing);
206 double a = Math::eval(c, &ok);
209 data.angle = Math::deg2rad(a);
211 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
213 DIALOGFACTORY->requestOptions(this, true, true);
214 setStatus(lastStatus);
221 double f = Math::eval(c, &ok);
226 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
228 DIALOGFACTORY->requestOptions(this, true, true);
229 setStatus(lastStatus);
236 int cols = (int)Math::eval(c, &ok);
241 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
243 DIALOGFACTORY->requestOptions(this, true, true);
244 setStatus(lastStatus);
251 int rows = (int)Math::eval(c, &ok);
256 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
258 DIALOGFACTORY->requestOptions(this, true, true);
259 setStatus(lastStatus);
263 case SetColumnSpacing:
266 double cs = (int)Math::eval(c, &ok);
271 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
273 DIALOGFACTORY->requestOptions(this, true, true);
274 setStatus(lastStatus);
281 int rs = (int)Math::eval(c, &ok);
286 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
288 DIALOGFACTORY->requestOptions(this, true, true);
289 setStatus(lastStatus);
298 QStringList ActionBlocksInsert::getAvailableCommands()
305 cmd += command("angle");
306 cmd += command("factor");
307 cmd += command("columns");
308 cmd += command("rows");
309 cmd += command("columnspacing");
310 cmd += command("rowspacing");
320 void ActionBlocksInsert::showOptions()
322 ActionInterface::showOptions();
323 DIALOGFACTORY->requestOptions(this, true);
326 void ActionBlocksInsert::hideOptions()
328 ActionInterface::hideOptions();
329 DIALOGFACTORY->requestOptions(this, false);
332 void ActionBlocksInsert::updateMouseButtonHints()
337 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
341 DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
345 DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
349 DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"), "");
353 DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"), "");
356 case SetColumnSpacing:
357 DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"), "");
361 DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"), "");
365 DIALOGFACTORY->updateMouseWidget("", "");
370 void ActionBlocksInsert::updateMouseCursor()
372 graphicView->setMouseCursor(RS2::CadCursor);
375 void ActionBlocksInsert::updateToolBar()
378 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
380 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
383 double ActionBlocksInsert::getAngle()
388 void ActionBlocksInsert::setAngle(double a)
393 double ActionBlocksInsert::getFactor()
395 return data.scaleFactor.x;
398 void ActionBlocksInsert::setFactor(double f)
400 data.scaleFactor = Vector(f, f);
403 int ActionBlocksInsert::getColumns()
408 void ActionBlocksInsert::setColumns(int c)
413 int ActionBlocksInsert::getRows()
418 void ActionBlocksInsert::setRows(int r)
423 double ActionBlocksInsert::getColumnSpacing()
425 return data.spacing.x;
428 void ActionBlocksInsert::setColumnSpacing(double cs)
433 double ActionBlocksInsert::getRowSpacing()
435 return data.spacing.y;
438 void ActionBlocksInsert::setRowSpacing(double rs)