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