1 // actionlibraryinsert.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/04/2010 Added this text. :-)
15 #include "actionlibraryinsert.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
26 ActionLibraryInsert::ActionLibraryInsert(RS_EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Library Insert", container, graphicView)
31 ActionLibraryInsert::~ActionLibraryInsert()
35 /*virtual*/ RS2::ActionType ActionLibraryInsert::rtti()
37 return RS2::ActionLibraryInsert;
40 void ActionLibraryInsert::init(int status)
42 ActionInterface::init(status);
46 /*if (graphic!=NULL) {
47 block = graphic->getActiveBlock();
49 data.name = block->getName();
55 void ActionLibraryInsert::setFile(const QString & file)
59 if (!prev.open(file, RS2::FormatUnknown))
60 RS_DIALOGFACTORY->commandMessage(tr("Cannot open file '%1'").arg(file));
63 void ActionLibraryInsert::reset()
65 /*data = RS_InsertData("",
74 data.insertionPoint = Vector(false);
79 void ActionLibraryInsert::trigger()
85 RS_Creation creation(container, graphicView);
86 creation.createLibraryInsert(data);
88 graphicView->redraw();
91 void ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e)
96 data.insertionPoint = snapPoint(e);
100 // preview->addAllFrom(prev);
101 // preview->move(data.insertionPoint);
102 // preview->scale(data.insertionPoint, Vector(data.factor, data.factor));
107 double uf = RS_Units::convert(1.0, prev.getUnit(), graphic->getUnit());
108 // preview->scale(data.insertionPoint, Vector(uf, uf));
111 // preview->rotate(data.insertionPoint, data.angle);
120 void ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
122 if (e->button() == Qt::LeftButton)
124 Vector ce(snapPoint(e));
125 coordinateEvent(&ce);
127 else if (e->button() == Qt::RightButton)
130 init(getStatus() - 1);
134 void ActionLibraryInsert::coordinateEvent(Vector * e)
139 data.insertionPoint = *e;
143 void ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
145 QString c = e->getCommand().toLower();
147 if (checkCommand("help", c))
149 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
157 if (checkCommand("angle", c))
162 lastStatus = (Status)getStatus();
165 else if (checkCommand("factor", c))
170 lastStatus = (Status)getStatus();
171 setStatus(SetFactor);
178 double a = RS_Math::eval(c, &ok);
181 data.angle = RS_Math::deg2rad(a);
183 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
185 RS_DIALOGFACTORY->requestOptions(this, true, true);
186 setStatus(lastStatus);
193 double f = RS_Math::eval(c, &ok);
198 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
200 RS_DIALOGFACTORY->requestOptions(this, true, true);
201 setStatus(lastStatus);
210 QStringList ActionLibraryInsert::getAvailableCommands()
217 cmd += command("angle");
218 cmd += command("factor");
228 void ActionLibraryInsert::showOptions()
230 ActionInterface::showOptions();
232 RS_DIALOGFACTORY->requestOptions(this, true);
235 void ActionLibraryInsert::hideOptions()
237 ActionInterface::hideOptions();
239 RS_DIALOGFACTORY->requestOptions(this, false);
242 void ActionLibraryInsert::updateMouseButtonHints()
247 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
251 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
255 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
259 RS_DIALOGFACTORY->updateMouseWidget("", "");
264 void ActionLibraryInsert::updateMouseCursor()
266 graphicView->setMouseCursor(RS2::CadCursor);
269 void ActionLibraryInsert::updateToolBar()
272 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
274 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
277 double ActionLibraryInsert::getAngle()
282 void ActionLibraryInsert::setAngle(double a)
287 double ActionLibraryInsert::getFactor()
292 void ActionLibraryInsert::setFactor(double f)