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