]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlinetangent1.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actiondrawlinetangent1.cpp
1 // rs_actiondrawlinetangent1.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/04/2010  Added this text. :-)
13 //
14
15 #include "rs_actiondrawlinetangent1.h"
16
17 #include "rs_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
21
22 RS_ActionDrawLineTangent1::RS_ActionDrawLineTangent1(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Tangents 1",
23                 container, graphicView)
24 {
25         tangent = NULL;
26         point = Vector(false);
27         circle = NULL;
28 }
29
30 RS_ActionDrawLineTangent1::~RS_ActionDrawLineTangent1()
31 {
32 }
33
34 void RS_ActionDrawLineTangent1::trigger()
35 {
36         RS_PreviewActionInterface::trigger();
37
38         if (tangent != NULL)
39         {
40                 RS_Entity * newEntity = NULL;
41                 newEntity = new RS_Line(container, tangent->getData());
42
43                 if (newEntity != NULL)
44                 {
45                         newEntity->setLayerToActive();
46                         newEntity->setPenToActive();
47                         container->addEntity(newEntity);
48
49                         // upd. undo list:
50                         if (document != NULL)
51                         {
52                                 document->startUndoCycle();
53                                 document->addUndoable(newEntity);
54                                 document->endUndoCycle();
55                         }
56
57                         deleteSnapper();
58                         graphicView->drawEntity(newEntity);
59
60                         setStatus(SetPoint);
61                 }
62
63                 delete tangent;
64                 tangent = NULL;
65         }
66         else
67                 RS_DEBUG->print("RS_ActionDrawLineTangent1::trigger:"
68                         " Entity is NULL\n");
69 }
70
71 void RS_ActionDrawLineTangent1::mouseMoveEvent(QMouseEvent * e)
72 {
73         RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent begin");
74
75         Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
76
77         switch (getStatus())
78         {
79         case SetPoint:
80                 point = snapPoint(e);
81                 break;
82
83         case SetCircle: {
84                 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
85
86                 if (en != NULL && (en->rtti() == RS2::EntityCircle
87                                    || en->rtti() == RS2::EntityArc
88                                    || en->rtti() == RS2::EntityEllipse))
89                 {
90                         circle = en;
91
92                         RS_Creation creation(NULL, NULL);
93                         RS_Line * t = creation.createTangent1(mouse,
94                                         point,
95                                         circle);
96
97                         if (t != NULL)
98                         {
99                                 if (tangent != NULL)
100                                         delete tangent;
101                                 tangent = (RS_Line *)t->clone();
102
103                                 deletePreview();
104                                 clearPreview();
105                                 preview->addEntity(t);
106                                 drawPreview();
107                         }
108                 }
109         }
110         break;
111
112         default:
113                 break;
114         }
115
116         RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent end");
117 }
118
119 void RS_ActionDrawLineTangent1::mouseReleaseEvent(QMouseEvent * e)
120 {
121         if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
122         {
123                 deletePreview();
124                 clearPreview();
125                 deleteSnapper();
126                 init(getStatus() - 1);
127         }
128         else
129         {
130                 switch (getStatus())
131                 {
132                 case SetPoint: {
133                         Vector ce(snapPoint(e));
134                         coordinateEvent(&ce);
135                 }
136                 break;
137
138                 case SetCircle:
139                         trigger();
140                         break;
141                 }
142         }
143 }
144
145 void RS_ActionDrawLineTangent1::coordinateEvent(Vector * e)
146 {
147         if (e == NULL)
148                 return;
149
150         switch (getStatus())
151         {
152         case SetPoint:
153                 point = *e;
154                 deleteSnapper();
155                 graphicView->moveRelativeZero(point);
156                 setStatus(SetCircle);
157                 break;
158
159         default:
160                 break;
161         }
162 }
163
164 void RS_ActionDrawLineTangent1::updateMouseButtonHints()
165 {
166         if (RS_DIALOGFACTORY != NULL)
167         {
168                 switch (getStatus())
169                 {
170                 case SetPoint:
171                         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"),
172                                 tr("Cancel"));
173                         break;
174
175                 case SetCircle:
176                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select circle, arc or ellipse"),
177                                 tr("Back"));
178                         break;
179
180                 default:
181                         RS_DIALOGFACTORY->updateMouseWidget("", "");
182                         break;
183                 }
184         }
185 }
186
187 void RS_ActionDrawLineTangent1::updateMouseCursor()
188 {
189         graphicView->setMouseCursor(RS2::CadCursor);
190 }
191
192 void RS_ActionDrawLineTangent1::updateToolBar()
193 {
194         if (RS_DIALOGFACTORY != NULL)
195         {
196                 if (!isFinished())
197                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
198                 else
199                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
200         }
201 }
202
203 // EOF