]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionblockscreate.cpp
Scrubbed out all references to RS2::qtToRsButton(). Gone!
[architektonas] / src / actions / rs_actionblockscreate.cpp
1 // rs_actionblockscreate.cpp
2 //
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
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/03/2010  Added this text. :-)
13 // JLH  06/03/2010  Scrubbed out all occurances of RS_CoordinateEvent
14 //
15
16 #include "rs_actionblockscreate.h"
17
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "rs_insert.h"
21 #include "rs_modification.h"
22
23 /**
24  * Constructor.
25  */
26 RS_ActionBlocksCreate::RS_ActionBlocksCreate(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Blocks Create", container, graphicView)
27 {
28         referencePoint = Vector(false);
29 }
30
31 RS_ActionBlocksCreate::~RS_ActionBlocksCreate()
32 {
33 }
34
35 #if 0
36 QAction * RS_ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
37 {
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"));
43
44         return action;
45 }
46
47 #endif
48
49 /*virtual*/ RS2::ActionType RS_ActionBlocksCreate::rtti()
50 {
51         return RS2::ActionBlocksCreate;
52 }
53
54 void RS_ActionBlocksCreate::init(int status)
55 {
56         RS_PreviewActionInterface::init(status);
57 }
58
59 void RS_ActionBlocksCreate::trigger()
60 {
61         deleteSnapper();
62         //deletePreview();
63         //clearPreview();
64
65         //RS_Modification m(*container, graphicView);
66         //m.paste(data.insertionPoint);
67         //std::cout << *RS_Clipboard::instance();
68
69         if (graphic != NULL)
70         {
71                 RS_BlockList * blockList = graphic->getBlockList();
72
73                 if (blockList != NULL)
74                 {
75                         RS_BlockData d = RS_DIALOGFACTORY->requestNewBlockDialog(blockList);
76
77                         if (!d.name.isEmpty())
78                         {
79                                 RS_Creation creation(container, graphicView);
80                                 creation.createBlock(d, referencePoint, true);
81
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);
84                         }
85                 }
86         }
87
88         graphicView->redraw();
89         finish();
90         graphicView->killSelectActions();
91 }
92
93 void RS_ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
94 {
95         snapPoint(e);
96
97         switch (getStatus())
98         {
99         case SetReferencePoint:
100                 //data.insertionPoint = snapPoint(e);
101
102                 /*if (block!=NULL) {
103                         deletePreview();
104                         clearPreview();
105                         //preview->addAllFrom(*block);
106                         //preview->move(data.insertionPoint);
107                         RS_Creation creation(preview, NULL, false);
108                         creation.createInsert(data);
109                         drawPreview();
110                    }*/
111                 break;
112
113         default:
114                 break;
115         }
116 }
117
118 void RS_ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
119 {
120 //      if (e->button() == Qt::LeftButton)
121         if (e->button() == Qt::LeftButton)
122         {
123 //              Vector ce(snapPoint(e));
124 //              coordinateEvent(&ce);
125                 Vector ce(snapPoint(e));
126                 coordinateEvent(&ce);
127         }
128 //      else if (e->button() == Qt::RightButton)
129         else if (e->button() == Qt::RightButton)
130         {
131                 deleteSnapper();
132                 init(getStatus() - 1);
133         }
134 }
135
136 //void RS_ActionBlocksCreate::coordinateEvent(Vector * e)
137 void RS_ActionBlocksCreate::coordinateEvent(Vector * e)
138 {
139         if (e == NULL)
140                 return;
141
142         switch (getStatus())
143         {
144         case SetReferencePoint:
145 //              referencePoint = e->getCoordinate();
146                 referencePoint = *e;
147                 trigger();
148                 break;
149
150         default:
151                 break;
152         }
153 }
154
155 void RS_ActionBlocksCreate::updateMouseButtonHints()
156 {
157         switch (getStatus())
158         {
159         case SetReferencePoint:
160                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
161                 break;
162
163         default:
164                 RS_DIALOGFACTORY->updateMouseWidget("", "");
165                 break;
166         }
167 }
168
169 void RS_ActionBlocksCreate::updateMouseCursor()
170 {
171         graphicView->setMouseCursor(RS2::CadCursor);
172 }
173
174 void RS_ActionBlocksCreate::updateToolBar()
175 {
176         if (!isFinished())
177                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
178         else
179                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
180 }
181