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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
13 // JLH 06/03/2010 Scrubbed out all occurances of RS_CoordinateEvent
16 #include "actionblockscreate.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_insert.h"
22 #include "rs_modification.h"
27 ActionBlocksCreate::ActionBlocksCreate(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Blocks Create", container, graphicView)
29 referencePoint = Vector(false);
32 ActionBlocksCreate::~ActionBlocksCreate()
37 QAction * ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
39 QAction * action = new QAction(tr("&Create Block"), 0);
40 // QAction* action = new QAction(tr("Create Block"),
41 // tr("&Create Block"),
42 // QKeySequence(), NULL);
43 action->setStatusTip(tr("Create Block"));
50 /*virtual*/ RS2::ActionType ActionBlocksCreate::rtti()
52 return RS2::ActionBlocksCreate;
55 void ActionBlocksCreate::init(int status)
57 ActionInterface::init(status);
60 void ActionBlocksCreate::trigger()
66 //RS_Modification m(*container, graphicView);
67 //m.paste(data.insertionPoint);
68 //std::cout << *RS_Clipboard::instance();
72 RS_BlockList * blockList = graphic->getBlockList();
74 if (blockList != NULL)
76 RS_BlockData d = RS_DIALOGFACTORY->requestNewBlockDialog(blockList);
78 if (!d.name.isEmpty())
80 RS_Creation creation(container, graphicView);
81 creation.createBlock(d, referencePoint, true);
83 RS_InsertData id(d.name, referencePoint, Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0));
84 creation.createInsert(id);
89 graphicView->redraw();
91 graphicView->killSelectActions();
94 void ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
97 graphicView->snapper.snapPoint(e);
101 case SetReferencePoint:
102 //data.insertionPoint = snapPoint(e);
107 //preview->addAllFrom(*block);
108 //preview->move(data.insertionPoint);
109 RS_Creation creation(preview, NULL, false);
110 creation.createInsert(data);
120 void ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
122 if (e->button() == Qt::LeftButton)
124 // Vector ce(snapPoint(e));
125 Vector ce(graphicView->snapper.snapPoint(e));
126 coordinateEvent(&ce);
128 else if (e->button() == Qt::RightButton)
131 init(getStatus() - 1);
135 void ActionBlocksCreate::coordinateEvent(Vector * e)
142 case SetReferencePoint:
152 void ActionBlocksCreate::updateMouseButtonHints()
156 case SetReferencePoint:
157 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
161 RS_DIALOGFACTORY->updateMouseWidget("", "");
166 void ActionBlocksCreate::updateMouseCursor()
168 graphicView->setMouseCursor(RS2::CadCursor);
171 void ActionBlocksCreate::updateToolBar()
174 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
176 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);