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