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