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 // 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/04/2010 Added this text. :-)
17 #include "actionlibraryinsert.h"
19 #include "commandevent.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
28 ActionLibraryInsert::ActionLibraryInsert(EntityContainer & container, GraphicView & graphicView):
29 ActionInterface("Library Insert", container, graphicView)
33 ActionLibraryInsert::~ActionLibraryInsert()
37 /*virtual*/ RS2::ActionType ActionLibraryInsert::rtti()
39 return RS2::ActionLibraryInsert;
42 void ActionLibraryInsert::init(int status)
44 ActionInterface::init(status);
48 /*if (graphic!=NULL) {
49 block = graphic->getActiveBlock();
51 data.name = block->getName();
57 void ActionLibraryInsert::setFile(const QString & file)
61 if (!prev.open(file, RS2::FormatUnknown))
62 DIALOGFACTORY->commandMessage(tr("Cannot open file '%1'").arg(file));
65 void ActionLibraryInsert::reset()
67 /*data = InsertData("",
76 data.insertionPoint = Vector(false);
81 void ActionLibraryInsert::trigger()
87 Creation creation(container, graphicView);
88 creation.createLibraryInsert(data);
90 graphicView->redraw();
93 void ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e)
98 data.insertionPoint = snapPoint(e);
102 // preview->addAllFrom(prev);
103 // preview->move(data.insertionPoint);
104 // preview->scale(data.insertionPoint, Vector(data.factor, data.factor));
109 double uf = Units::convert(1.0, prev.getUnit(), graphic->getUnit());
110 // preview->scale(data.insertionPoint, Vector(uf, uf));
113 // preview->rotate(data.insertionPoint, data.angle);
122 void ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
124 if (e->button() == Qt::LeftButton)
126 Vector ce(snapPoint(e));
127 coordinateEvent(&ce);
129 else if (e->button() == Qt::RightButton)
132 init(getStatus() - 1);
136 void ActionLibraryInsert::coordinateEvent(Vector * e)
141 data.insertionPoint = *e;
145 void ActionLibraryInsert::commandEvent(CommandEvent * e)
147 QString c = e->getCommand().toLower();
149 if (checkCommand("help", c))
151 DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
159 if (checkCommand("angle", c))
164 lastStatus = (Status)getStatus();
167 else if (checkCommand("factor", c))
172 lastStatus = (Status)getStatus();
173 setStatus(SetFactor);
180 double a = Math::eval(c, &ok);
183 data.angle = Math::deg2rad(a);
185 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
187 DIALOGFACTORY->requestOptions(this, true, true);
188 setStatus(lastStatus);
195 double f = Math::eval(c, &ok);
200 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
202 DIALOGFACTORY->requestOptions(this, true, true);
203 setStatus(lastStatus);
212 QStringList ActionLibraryInsert::getAvailableCommands()
219 cmd += command("angle");
220 cmd += command("factor");
230 void ActionLibraryInsert::showOptions()
232 ActionInterface::showOptions();
234 DIALOGFACTORY->requestOptions(this, true);
237 void ActionLibraryInsert::hideOptions()
239 ActionInterface::hideOptions();
241 DIALOGFACTORY->requestOptions(this, false);
244 void ActionLibraryInsert::updateMouseButtonHints()
249 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
253 DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
257 DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
261 DIALOGFACTORY->updateMouseWidget("", "");
266 void ActionLibraryInsert::updateMouseCursor()
268 graphicView->setMouseCursor(RS2::CadCursor);
271 void ActionLibraryInsert::updateToolBar()
274 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
276 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
279 double ActionLibraryInsert::getAngle()
284 void ActionLibraryInsert::setAngle(double a)
289 double ActionLibraryInsert::getFactor()
294 void ActionLibraryInsert::setFactor(double f)