1 // actionblockscreate.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/03/2010 Added this text. :-)
15 // JLH 06/03/2010 Scrubbed out all occurances of RS_CoordinateEvent
18 #include "actionblockscreate.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_insert.h"
24 #include "rs_modification.h"
29 ActionBlocksCreate::ActionBlocksCreate(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Blocks Create", container, graphicView)
31 referencePoint = Vector(false);
34 ActionBlocksCreate::~ActionBlocksCreate()
39 QAction * ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
41 QAction * action = new QAction(tr("&Create Block"), 0);
42 // QAction* action = new QAction(tr("Create Block"),
43 // tr("&Create Block"),
44 // QKeySequence(), NULL);
45 action->setStatusTip(tr("Create Block"));
52 /*virtual*/ RS2::ActionType ActionBlocksCreate::rtti()
54 return RS2::ActionBlocksCreate;
57 void ActionBlocksCreate::init(int status)
59 ActionInterface::init(status);
62 void ActionBlocksCreate::trigger()
68 //RS_Modification m(*container, graphicView);
69 //m.paste(data.insertionPoint);
70 //std::cout << *RS_Clipboard::instance();
74 RS_BlockList * blockList = graphic->getBlockList();
76 if (blockList != NULL)
78 RS_BlockData d = RS_DIALOGFACTORY->requestNewBlockDialog(blockList);
80 if (!d.name.isEmpty())
82 RS_Creation creation(container, graphicView);
83 creation.createBlock(d, referencePoint, true);
85 RS_InsertData id(d.name, referencePoint, Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0));
86 creation.createInsert(id);
91 graphicView->redraw();
93 graphicView->killSelectActions();
96 void ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
99 graphicView->snapper.snapPoint(e);
103 case SetReferencePoint:
104 //data.insertionPoint = snapPoint(e);
109 //preview->addAllFrom(*block);
110 //preview->move(data.insertionPoint);
111 RS_Creation creation(preview, NULL, false);
112 creation.createInsert(data);
122 void ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
124 if (e->button() == Qt::LeftButton)
126 // Vector ce(snapPoint(e));
127 Vector ce(graphicView->snapper.snapPoint(e));
128 coordinateEvent(&ce);
130 else if (e->button() == Qt::RightButton)
133 init(getStatus() - 1);
137 void ActionBlocksCreate::coordinateEvent(Vector * e)
144 case SetReferencePoint:
154 void ActionBlocksCreate::updateMouseButtonHints()
158 case SetReferencePoint:
159 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
163 RS_DIALOGFACTORY->updateMouseWidget("", "");
168 void ActionBlocksCreate::updateMouseCursor()
170 graphicView->setMouseCursor(RS2::CadCursor);
173 void ActionBlocksCreate::updateToolBar()
176 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
178 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);