]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawlinetangent2.cpp
Last checkin before major refactor...
[architektonas] / src / actions / actiondrawlinetangent2.cpp
1 // actiondrawlinetangent2.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 "actiondrawlinetangent2.h"
16
17 #include "rs_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
21
22 ActionDrawLineTangent2::ActionDrawLineTangent2(
23         RS_EntityContainer & container, GraphicView & graphicView):
24         ActionInterface("Draw Tangents 2", container, graphicView)
25 {
26         tangent = NULL;
27         circle1 = NULL;
28         circle2 = NULL;
29 }
30
31 ActionDrawLineTangent2::~ActionDrawLineTangent2()
32 {
33 }
34
35 void ActionDrawLineTangent2::trigger()
36 {
37         ActionInterface::trigger();
38
39         if (tangent != NULL)
40         {
41                 RS_Entity * newEntity = NULL;
42                 newEntity = new RS_Line(container, tangent->getData());
43
44                 if (newEntity != NULL)
45                 {
46                         newEntity->setLayerToActive();
47                         newEntity->setPenToActive();
48                         container->addEntity(newEntity);
49
50                         // upd. undo list:
51                         if (document != NULL)
52                         {
53                                 document->startUndoCycle();
54                                 document->addUndoable(newEntity);
55                                 document->endUndoCycle();
56                         }
57                         graphicView->drawEntity(newEntity);
58                         setStatus(SetCircle1);
59                 }
60
61                 delete tangent;
62                 tangent = NULL;
63         }
64         else
65                 RS_DEBUG->print("ActionDrawLineTangent2::trigger:"
66                         " Entity is NULL\n");
67 }
68
69 void ActionDrawLineTangent2::mouseMoveEvent(QMouseEvent * e)
70 {
71         RS_DEBUG->print("ActionDrawLineTangent2::mouseMoveEvent begin");
72
73         Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
74
75         switch (getStatus())
76         {
77         case SetCircle1: {
78                 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
79
80                 if (en != NULL && (en->rtti() == RS2::EntityCircle
81                                    || en->rtti() == RS2::EntityArc))
82                         circle1 = en;
83         }
84         break;
85
86         case SetCircle2:
87         {
88                 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
89
90                 if (en && (en->rtti() == RS2::EntityCircle
91                         || en->rtti() == RS2::EntityArc))
92                 {
93                         circle2 = en;
94                         RS_Creation creation(NULL, NULL);
95                         RS_Line * t = creation.createTangent2(mouse, circle1, circle2);
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("ActionDrawLineTangent2::mouseMoveEvent end");
118 }
119
120 void ActionDrawLineTangent2::mouseReleaseEvent(QMouseEvent * e)
121 {
122         if (e->button() == Qt::RightButton)
123         {
124                 deletePreview();
125                 clearPreview();
126                 init(getStatus() - 1);
127         }
128         else
129         {
130                 switch (getStatus())
131                 {
132                 case SetCircle1:
133                         setStatus(SetCircle2);
134                         break;
135
136                 case SetCircle2:
137                         trigger();
138                         break;
139                 }
140         }
141 }
142
143 void ActionDrawLineTangent2::updateMouseButtonHints()
144 {
145         if (RS_DIALOGFACTORY != NULL)
146         {
147                 switch (getStatus())
148                 {
149                 case SetCircle1:
150                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first circle or arc"),
151                                 tr("Cancel"));
152                         break;
153
154                 case SetCircle2:
155                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second circle or arc"),
156                                 tr("Back"));
157                         break;
158
159                 default:
160                         RS_DIALOGFACTORY->updateMouseWidget("", "");
161                         break;
162                 }
163         }
164 }
165
166 void ActionDrawLineTangent2::updateMouseCursor()
167 {
168         graphicView->setMouseCursor(RS2::CadCursor);
169 }
170
171 void ActionDrawLineTangent2::updateToolBar()
172 {
173         if (RS_DIALOGFACTORY != NULL)
174                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
175 }