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 "rs_insert.h"
21 #include "rs_modification.h"
26 RS_ActionBlocksCreate::RS_ActionBlocksCreate(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Blocks Create", container, graphicView)
28 referencePoint = Vector(false);
31 RS_ActionBlocksCreate::~RS_ActionBlocksCreate()
36 QAction * RS_ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
38 QAction * action = new QAction(tr("&Create Block"), 0);
39 // QAction* action = new QAction(tr("Create Block"),
40 // tr("&Create Block"),
41 // QKeySequence(), NULL);
42 action->setStatusTip(tr("Create Block"));
49 /*virtual*/ RS2::ActionType RS_ActionBlocksCreate::rtti()
51 return RS2::ActionBlocksCreate;
54 void RS_ActionBlocksCreate::init(int status)
56 RS_PreviewActionInterface::init(status);
59 void RS_ActionBlocksCreate::trigger()
65 //RS_Modification m(*container, graphicView);
66 //m.paste(data.insertionPoint);
67 //std::cout << *RS_Clipboard::instance();
71 RS_BlockList * blockList = graphic->getBlockList();
73 if (blockList != NULL)
75 RS_BlockData d = RS_DIALOGFACTORY->requestNewBlockDialog(blockList);
77 if (!d.name.isEmpty())
79 RS_Creation creation(container, graphicView);
80 creation.createBlock(d, referencePoint, true);
82 RS_InsertData id(d.name, referencePoint, Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0));
83 creation.createInsert(id);
88 graphicView->redraw();
90 graphicView->killSelectActions();
93 void RS_ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
99 case SetReferencePoint:
100 //data.insertionPoint = snapPoint(e);
105 //preview->addAllFrom(*block);
106 //preview->move(data.insertionPoint);
107 RS_Creation creation(preview, NULL, false);
108 creation.createInsert(data);
118 void RS_ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
120 // if (e->button() == Qt::LeftButton)
121 if (e->button() == Qt::LeftButton)
123 // Vector ce(snapPoint(e));
124 // coordinateEvent(&ce);
125 Vector ce(snapPoint(e));
126 coordinateEvent(&ce);
128 // else if (e->button() == Qt::RightButton)
129 else if (e->button() == Qt::RightButton)
132 init(getStatus() - 1);
136 //void RS_ActionBlocksCreate::coordinateEvent(Vector * e)
137 void RS_ActionBlocksCreate::coordinateEvent(Vector * e)
144 case SetReferencePoint:
145 // referencePoint = e->getCoordinate();
155 void RS_ActionBlocksCreate::updateMouseButtonHints()
159 case SetReferencePoint:
160 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
164 RS_DIALOGFACTORY->updateMouseWidget("", "");
169 void RS_ActionBlocksCreate::updateMouseCursor()
171 graphicView->setMouseCursor(RS2::CadCursor);
174 void RS_ActionBlocksCreate::updateToolBar()
177 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
179 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);