1 // rs_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 "rs_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 RS_ActionBlocksCreate::RS_ActionBlocksCreate(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Blocks Create", container, graphicView)
29 referencePoint = Vector(false);
32 RS_ActionBlocksCreate::~RS_ActionBlocksCreate()
37 QAction * RS_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 RS_ActionBlocksCreate::rtti()
52 return RS2::ActionBlocksCreate;
55 void RS_ActionBlocksCreate::init(int status)
57 RS_PreviewActionInterface::init(status);
60 void RS_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 RS_ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
100 case SetReferencePoint:
101 //data.insertionPoint = snapPoint(e);
106 //preview->addAllFrom(*block);
107 //preview->move(data.insertionPoint);
108 RS_Creation creation(preview, NULL, false);
109 creation.createInsert(data);
119 void RS_ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
121 // if (e->button() == Qt::LeftButton)
122 if (e->button() == Qt::LeftButton)
124 // Vector ce(snapPoint(e));
125 // coordinateEvent(&ce);
126 Vector ce(snapPoint(e));
127 coordinateEvent(&ce);
129 // else if (e->button() == Qt::RightButton)
130 else if (e->button() == Qt::RightButton)
133 init(getStatus() - 1);
137 //void RS_ActionBlocksCreate::coordinateEvent(Vector * e)
138 void RS_ActionBlocksCreate::coordinateEvent(Vector * e)
145 case SetReferencePoint:
146 // referencePoint = e->getCoordinate();
156 void RS_ActionBlocksCreate::updateMouseButtonHints()
160 case SetReferencePoint:
161 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
165 RS_DIALOGFACTORY->updateMouseWidget("", "");
170 void RS_ActionBlocksCreate::updateMouseCursor()
172 graphicView->setMouseCursor(RS2::CadCursor);
175 void RS_ActionBlocksCreate::updateToolBar()
178 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
180 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);