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