1 // rs_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 "rs_actionlibraryinsert.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
26 RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container, GraphicView & graphicView):
27 RS_PreviewActionInterface("Library Insert", container, graphicView)
31 RS_ActionLibraryInsert::~RS_ActionLibraryInsert()
35 /*virtual*/ RS2::ActionType RS_ActionLibraryInsert::rtti()
37 return RS2::ActionLibraryInsert;
40 void RS_ActionLibraryInsert::init(int status)
42 RS_PreviewActionInterface::init(status);
46 /*if (graphic!=NULL) {
47 block = graphic->getActiveBlock();
49 data.name = block->getName();
55 void RS_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 RS_ActionLibraryInsert::reset()
65 /*data = RS_InsertData("",
74 data.insertionPoint = Vector(false);
79 void RS_ActionLibraryInsert::trigger()
85 RS_Creation creation(container, graphicView);
86 creation.createLibraryInsert(data);
88 graphicView->redraw();
91 void RS_ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e)
96 data.insertionPoint = snapPoint(e);
101 preview->addAllFrom(prev);
102 preview->move(data.insertionPoint);
103 preview->scale(data.insertionPoint,
104 Vector(data.factor, data.factor));
109 double uf = RS_Units::convert(1.0, prev.getUnit(), graphic->getUnit());
110 preview->scale(data.insertionPoint, Vector(uf, uf));
113 preview->rotate(data.insertionPoint, data.angle);
115 //RS_Creation creation(preview, NULL, false);
116 //creation.createInsert(data);
126 void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
128 if (e->button() == Qt::LeftButton)
130 Vector ce(snapPoint(e));
131 coordinateEvent(&ce);
133 else if (e->button() == Qt::RightButton)
136 init(getStatus() - 1);
140 void RS_ActionLibraryInsert::coordinateEvent(Vector * e)
145 data.insertionPoint = *e;
149 void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
151 QString c = e->getCommand().toLower();
153 if (checkCommand("help", c))
155 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
163 if (checkCommand("angle", c))
168 lastStatus = (Status)getStatus();
171 else if (checkCommand("factor", c))
176 lastStatus = (Status)getStatus();
177 setStatus(SetFactor);
184 double a = RS_Math::eval(c, &ok);
187 data.angle = RS_Math::deg2rad(a);
189 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
191 RS_DIALOGFACTORY->requestOptions(this, true, true);
192 setStatus(lastStatus);
199 double f = RS_Math::eval(c, &ok);
204 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
206 RS_DIALOGFACTORY->requestOptions(this, true, true);
207 setStatus(lastStatus);
216 QStringList RS_ActionLibraryInsert::getAvailableCommands()
223 cmd += command("angle");
224 cmd += command("factor");
234 void RS_ActionLibraryInsert::showOptions()
236 RS_ActionInterface::showOptions();
238 RS_DIALOGFACTORY->requestOptions(this, true);
241 void RS_ActionLibraryInsert::hideOptions()
243 RS_ActionInterface::hideOptions();
245 RS_DIALOGFACTORY->requestOptions(this, false);
248 void RS_ActionLibraryInsert::updateMouseButtonHints()
253 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
257 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
261 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
265 RS_DIALOGFACTORY->updateMouseWidget("", "");
270 void RS_ActionLibraryInsert::updateMouseCursor()
272 graphicView->setMouseCursor(RS2::CadCursor);
275 void RS_ActionLibraryInsert::updateToolBar()
278 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
280 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
283 double RS_ActionLibraryInsert::getAngle()
288 void RS_ActionLibraryInsert::setAngle(double a)
293 double RS_ActionLibraryInsert::getFactor()
298 void RS_ActionLibraryInsert::setFactor(double f)