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_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
25 RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container, RS_GraphicView & graphicView):
26 RS_PreviewActionInterface("Library Insert", container, graphicView)
30 RS_ActionLibraryInsert::~RS_ActionLibraryInsert()
34 /*virtual*/ RS2::ActionType RS_ActionLibraryInsert::rtti()
36 return RS2::ActionLibraryInsert;
39 void RS_ActionLibraryInsert::init(int status)
41 RS_PreviewActionInterface::init(status);
45 /*if (graphic!=NULL) {
46 block = graphic->getActiveBlock();
48 data.name = block->getName();
54 void RS_ActionLibraryInsert::setFile(const QString & file)
58 if (!prev.open(file, RS2::FormatUnknown))
59 RS_DIALOGFACTORY->commandMessage(tr("Cannot open file '%1'").arg(file));
62 void RS_ActionLibraryInsert::reset()
64 /*data = RS_InsertData("",
73 data.insertionPoint = Vector(false);
78 void RS_ActionLibraryInsert::trigger()
84 RS_Creation creation(container, graphicView);
85 creation.createLibraryInsert(data);
87 graphicView->redraw();
90 void RS_ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e)
95 data.insertionPoint = snapPoint(e);
100 preview->addAllFrom(prev);
101 preview->move(data.insertionPoint);
102 preview->scale(data.insertionPoint,
103 Vector(data.factor, data.factor));
108 double uf = RS_Units::convert(1.0, prev.getUnit(), graphic->getUnit());
109 preview->scale(data.insertionPoint, Vector(uf, uf));
112 preview->rotate(data.insertionPoint, data.angle);
114 //RS_Creation creation(preview, NULL, false);
115 //creation.createInsert(data);
125 void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
127 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
129 Vector ce(snapPoint(e));
130 coordinateEvent(&ce);
132 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
135 init(getStatus() - 1);
139 void RS_ActionLibraryInsert::coordinateEvent(Vector * e)
144 data.insertionPoint = *e;
148 void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
150 QString c = e->getCommand().toLower();
152 if (checkCommand("help", c))
154 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
162 if (checkCommand("angle", c))
167 lastStatus = (Status)getStatus();
170 else if (checkCommand("factor", c))
175 lastStatus = (Status)getStatus();
176 setStatus(SetFactor);
183 double a = RS_Math::eval(c, &ok);
186 data.angle = RS_Math::deg2rad(a);
188 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
190 RS_DIALOGFACTORY->requestOptions(this, true, true);
191 setStatus(lastStatus);
198 double f = RS_Math::eval(c, &ok);
203 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
205 RS_DIALOGFACTORY->requestOptions(this, true, true);
206 setStatus(lastStatus);
215 QStringList RS_ActionLibraryInsert::getAvailableCommands()
222 cmd += command("angle");
223 cmd += command("factor");
233 void RS_ActionLibraryInsert::showOptions()
235 RS_ActionInterface::showOptions();
237 RS_DIALOGFACTORY->requestOptions(this, true);
240 void RS_ActionLibraryInsert::hideOptions()
242 RS_ActionInterface::hideOptions();
244 RS_DIALOGFACTORY->requestOptions(this, false);
247 void RS_ActionLibraryInsert::updateMouseButtonHints()
252 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
256 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
260 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
264 RS_DIALOGFACTORY->updateMouseWidget("", "");
269 void RS_ActionLibraryInsert::updateMouseCursor()
271 graphicView->setMouseCursor(RS2::CadCursor);
274 void RS_ActionLibraryInsert::updateToolBar()
277 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
279 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
282 double RS_ActionLibraryInsert::getAngle()
287 void RS_ActionLibraryInsert::setAngle(double a)
292 double RS_ActionLibraryInsert::getFactor()
297 void RS_ActionLibraryInsert::setFactor(double f)