1 /****************************************************************************
2 ** $Id: rs_actionlibraryinsert.cpp 1161 2004-12-09 23:10:09Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionlibraryinsert.h"
30 #include "rs_creation.h"
31 #include "rs_modification.h"
37 RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container,
38 RS_GraphicView & graphicView):
39 RS_PreviewActionInterface("Library Insert", container, graphicView)
43 RS_ActionLibraryInsert::~RS_ActionLibraryInsert()
47 QAction * RS_ActionLibraryInsert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
49 QAction * action = new QAction(tr("&Insert Library Object"), 0);
50 // QAction* action = new QAction(tr("Insert Library Object"),
51 // tr("&Insert Library Object"),
52 // QKeySequence(), NULL);
53 action->setStatusTip(tr("Inserts an Object from the part library."));
57 void RS_ActionLibraryInsert::init(int status)
59 RS_PreviewActionInterface::init(status);
63 /*if (graphic!=NULL) {
64 block = graphic->getActiveBlock();
66 data.name = block->getName();
72 void RS_ActionLibraryInsert::setFile(const QString & file)
76 if (!prev.open(file, RS2::FormatUnknown))
77 RS_DIALOGFACTORY->commandMessage(tr("Cannot open file '%1'").arg(file));
80 void RS_ActionLibraryInsert::reset()
82 /*data = RS_InsertData("",
91 data.insertionPoint = Vector(false);
96 void RS_ActionLibraryInsert::trigger()
102 RS_Creation creation(container, graphicView);
103 creation.createLibraryInsert(data);
105 graphicView->redraw();
108 void RS_ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e)
113 data.insertionPoint = snapPoint(e);
118 preview->addAllFrom(prev);
119 preview->move(data.insertionPoint);
120 preview->scale(data.insertionPoint,
121 Vector(data.factor, data.factor));
125 double uf = RS_Units::convert(1.0, prev.getUnit(), graphic->getUnit());
126 preview->scale(data.insertionPoint, Vector(uf, uf));
129 preview->rotate(data.insertionPoint, data.angle);
131 //RS_Creation creation(preview, NULL, false);
132 //creation.createInsert(data);
142 void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
144 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
146 RS_CoordinateEvent ce(snapPoint(e));
147 coordinateEvent(&ce);
149 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
152 init(getStatus() - 1);
156 void RS_ActionLibraryInsert::coordinateEvent(RS_CoordinateEvent * e)
161 data.insertionPoint = e->getCoordinate();
165 void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
167 QString c = e->getCommand().toLower();
169 if (checkCommand("help", c))
171 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
178 if (checkCommand("angle", c))
183 lastStatus = (Status)getStatus();
186 else if (checkCommand("factor", c))
191 lastStatus = (Status)getStatus();
192 setStatus(SetFactor);
199 double a = RS_Math::eval(c, &ok);
203 data.angle = RS_Math::deg2rad(a);
207 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
210 RS_DIALOGFACTORY->requestOptions(this, true, true);
211 setStatus(lastStatus);
218 double f = RS_Math::eval(c, &ok);
226 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
229 RS_DIALOGFACTORY->requestOptions(this, true, true);
230 setStatus(lastStatus);
239 QStringList RS_ActionLibraryInsert::getAvailableCommands()
246 cmd += command("angle");
247 cmd += command("factor");
257 void RS_ActionLibraryInsert::showOptions()
259 RS_ActionInterface::showOptions();
261 RS_DIALOGFACTORY->requestOptions(this, true);
264 void RS_ActionLibraryInsert::hideOptions()
266 RS_ActionInterface::hideOptions();
268 RS_DIALOGFACTORY->requestOptions(this, false);
271 void RS_ActionLibraryInsert::updateMouseButtonHints()
276 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
279 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
282 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
285 RS_DIALOGFACTORY->updateMouseWidget("", "");
290 void RS_ActionLibraryInsert::updateMouseCursor()
292 graphicView->setMouseCursor(RS2::CadCursor);
295 void RS_ActionLibraryInsert::updateToolBar()
298 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
300 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);