]> Shamusworld >> Repos - architektonas/blob - src/actions/actionblockscreate.cpp
In the middle of major refactoring...
[architektonas] / src / actions / actionblockscreate.cpp
1 // 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 "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 ActionBlocksCreate::ActionBlocksCreate(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Blocks Create", container, graphicView)
28 {
29         referencePoint = Vector(false);
30 }
31
32 ActionBlocksCreate::~ActionBlocksCreate()
33 {
34 }
35
36 #if 0
37 QAction * 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 ActionBlocksCreate::rtti()
51 {
52         return RS2::ActionBlocksCreate;
53 }
54
55 void ActionBlocksCreate::init(int status)
56 {
57         ActionInterface::init(status);
58 }
59
60 void 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 ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
95 {
96 //      snapPoint(e);
97         graphicView->snapper.snapPoint(e);
98
99         switch (getStatus())
100         {
101         case SetReferencePoint:
102                 //data.insertionPoint = snapPoint(e);
103
104                 /*if (block!=NULL) {
105                         deletePreview();
106                         clearPreview();
107                         //preview->addAllFrom(*block);
108                         //preview->move(data.insertionPoint);
109                         RS_Creation creation(preview, NULL, false);
110                         creation.createInsert(data);
111                         drawPreview();
112                    }*/
113                 break;
114
115         default:
116                 break;
117         }
118 }
119
120 void ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
121 {
122         if (e->button() == Qt::LeftButton)
123         {
124 //              Vector ce(snapPoint(e));
125                 Vector ce(graphicView->snapper.snapPoint(e));
126                 coordinateEvent(&ce);
127         }
128         else if (e->button() == Qt::RightButton)
129         {
130 //              deleteSnapper();
131                 init(getStatus() - 1);
132         }
133 }
134
135 void ActionBlocksCreate::coordinateEvent(Vector * e)
136 {
137         if (!e)
138                 return;
139
140         switch (getStatus())
141         {
142         case SetReferencePoint:
143                 referencePoint = *e;
144                 trigger();
145                 break;
146
147         default:
148                 break;
149         }
150 }
151
152 void ActionBlocksCreate::updateMouseButtonHints()
153 {
154         switch (getStatus())
155         {
156         case SetReferencePoint:
157                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
158                 break;
159
160         default:
161                 RS_DIALOGFACTORY->updateMouseWidget("", "");
162                 break;
163         }
164 }
165
166 void ActionBlocksCreate::updateMouseCursor()
167 {
168         graphicView->setMouseCursor(RS2::CadCursor);
169 }
170
171 void ActionBlocksCreate::updateToolBar()
172 {
173         if (!isFinished())
174                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
175         else
176                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
177 }
178