]> Shamusworld >> Repos - architektonas/blob - src/actions/actionblockscreate.cpp
Fixed problem with MDI activation.
[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 CoordinateEvent
16 //
17
18 #include "actionblockscreate.h"
19
20 #include "creation.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
23 #include "insert.h"
24 #include "modification.h"
25
26 /**
27  * Constructor.
28  */
29 ActionBlocksCreate::ActionBlocksCreate(EntityContainer & container, GraphicView & graphicView): ActionInterface("Blocks Create", container, graphicView)
30 {
31         referencePoint = Vector(false);
32 }
33
34 ActionBlocksCreate::~ActionBlocksCreate()
35 {
36 }
37
38 /*virtual*/ RS2::ActionType ActionBlocksCreate::rtti()
39 {
40         return RS2::ActionBlocksCreate;
41 }
42
43 void ActionBlocksCreate::init(int status)
44 {
45         ActionInterface::init(status);
46 }
47
48 void ActionBlocksCreate::trigger()
49 {
50         if (graphic)
51         {
52                 BlockList * blockList = graphic->getBlockList();
53
54                 if (blockList)
55                 {
56                         BlockData d = DIALOGFACTORY->requestNewBlockDialog(blockList);
57
58                         if (!d.name.isEmpty())
59                         {
60                                 Creation creation(container, graphicView);
61                                 creation.createBlock(d, referencePoint, true);
62                                 InsertData id(d.name, referencePoint, Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0));
63                                 creation.createInsert(id);
64                         }
65                 }
66         }
67
68         graphicView->redraw();
69         finish();
70         graphicView->killSelectActions();
71 }
72
73 void ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e)
74 {
75 //      graphicView->snapper.snapPoint(e);
76         graphicView->SnapPoint(e);
77
78         switch (getStatus())
79         {
80         case SetReferencePoint:
81                 //data.insertionPoint = snapPoint(e);
82
83                 /*if (block!=NULL) {
84                         deletePreview();
85                         clearPreview();
86                         //preview->addAllFrom(*block);
87                         //preview->move(data.insertionPoint);
88                         Creation creation(preview, NULL, false);
89                         creation.createInsert(data);
90                         drawPreview();
91                    }*/
92                 break;
93
94         default:
95                 break;
96         }
97 }
98
99 void ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e)
100 {
101         if (e->button() == Qt::LeftButton)
102         {
103 //              Vector ce(graphicView->snapper.snapPoint(e));
104                 Vector ce(graphicView->SnapPoint(e));
105                 coordinateEvent(&ce);
106         }
107         else if (e->button() == Qt::RightButton)
108         {
109 //              deleteSnapper();
110                 init(getStatus() - 1);
111         }
112 }
113
114 void ActionBlocksCreate::coordinateEvent(Vector * e)
115 {
116         if (!e)
117                 return;
118
119         switch (getStatus())
120         {
121         case SetReferencePoint:
122                 referencePoint = *e;
123                 trigger();
124                 break;
125
126         default:
127                 break;
128         }
129 }
130
131 void ActionBlocksCreate::updateMouseButtonHints()
132 {
133         switch (getStatus())
134         {
135         case SetReferencePoint:
136                 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
137                 break;
138
139         default:
140                 DIALOGFACTORY->updateMouseWidget("", "");
141                 break;
142         }
143 }
144
145 void ActionBlocksCreate::updateMouseCursor()
146 {
147         graphicView->setMouseCursor(RS2::CadCursor);
148 }
149
150 void ActionBlocksCreate::updateToolBar()
151 {
152         if (!isFinished())
153                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
154         else
155                 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
156 }
157