]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawpoint.cpp
8ec3a810a5f2f29e8a8fe295564a7671e739581e
[architektonas] / src / actions / rs_actiondrawpoint.cpp
1 // rs_actiondrawpoint.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  05/22/2010  Added this text. :-)
13 //
14
15 #include "rs_actiondrawpoint.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
20
21 RS_ActionDrawPoint::RS_ActionDrawPoint(RS_EntityContainer & container, RS_GraphicView & graphicView):
22         RS_PreviewActionInterface("Draw Points", container, graphicView)
23 {
24 }
25
26 RS_ActionDrawPoint::~RS_ActionDrawPoint()
27 {
28 }
29
30 void RS_ActionDrawPoint::trigger()
31 {
32         if (pt.valid)
33         {
34                 RS_Point * point = new RS_Point(container, RS_PointData(pt));
35                 container->addEntity(point);
36
37                 if (document)
38                 {
39                         document->startUndoCycle();
40                         document->addUndoable(point);
41                         document->endUndoCycle();
42                 }
43
44                 deleteSnapper();
45                 graphicView->moveRelativeZero(Vector(0.0, 0.0));
46                 graphicView->drawEntity(point);
47                 graphicView->moveRelativeZero(pt);
48                 drawSnapper();
49         }
50 }
51
52 void RS_ActionDrawPoint::mouseMoveEvent(QMouseEvent * e)
53 {
54         snapPoint(e);
55 }
56
57 void RS_ActionDrawPoint::mouseReleaseEvent(QMouseEvent * e)
58 {
59         if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
60         {
61                 Vector ce(snapPoint(e));
62                 coordinateEvent(&ce);
63         }
64         else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
65         {
66                 deleteSnapper();
67                 init(getStatus() - 1);
68         }
69 }
70
71 void RS_ActionDrawPoint::coordinateEvent(Vector * e)
72 {
73         if (e == NULL)
74                 return;
75
76         Vector mouse = *e;
77
78         pt = mouse;
79         trigger();
80 }
81
82 void RS_ActionDrawPoint::commandEvent(RS_CommandEvent * e)
83 {
84         QString c = e->getCommand().toLower();
85
86         if (checkCommand("help", c))
87         {
88                 if (RS_DIALOGFACTORY != NULL)
89                         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
90                                 + getAvailableCommands().join(", "));
91
92                 return;
93         }
94 }
95
96 QStringList RS_ActionDrawPoint::getAvailableCommands()
97 {
98         QStringList cmd;
99         return cmd;
100 }
101
102 void RS_ActionDrawPoint::updateMouseButtonHints()
103 {
104         if (RS_DIALOGFACTORY != NULL)
105         {
106                 switch (getStatus())
107                 {
108                 case 0:
109                         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify location"), tr("Cancel"));
110                         break;
111
112                 default:
113                         RS_DIALOGFACTORY->updateMouseWidget("", "");
114                         break;
115                 }
116         }
117 }
118
119 void RS_ActionDrawPoint::updateMouseCursor()
120 {
121         graphicView->setMouseCursor(RS2::CadCursor);
122 }
123
124 void RS_ActionDrawPoint::updateToolBar()
125 {
126         if (RS_DIALOGFACTORY != NULL)
127         {
128                 if (!isFinished())
129                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
130                 else
131                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarPoints);
132         }
133 }
134