]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlinetangent2.cpp
f4bcf99db927b66280c49f5885c9924dbd60a9df
[architektonas] / src / actions / rs_actiondrawlinetangent2.cpp
1 // rs_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 "rs_actiondrawlinetangent2.h"
16
17 #include "rs_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
21
22 RS_ActionDrawLineTangent2::RS_ActionDrawLineTangent2(
23         RS_EntityContainer & container, GraphicView & graphicView):
24         RS_PreviewActionInterface("Draw Tangents 2", container, graphicView)
25 {
26         tangent = NULL;
27         circle1 = NULL;
28         circle2 = NULL;
29 }
30
31 RS_ActionDrawLineTangent2::~RS_ActionDrawLineTangent2()
32 {
33 }
34
35 void RS_ActionDrawLineTangent2::trigger()
36 {
37         RS_PreviewActionInterface::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("RS_ActionDrawLineTangent2::trigger:"
66                         " Entity is NULL\n");
67 }
68
69 void RS_ActionDrawLineTangent2::mouseMoveEvent(QMouseEvent * e)
70 {
71         RS_DEBUG->print("RS_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                 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
88
89                 if (en != NULL && (en->rtti() == RS2::EntityCircle
90                                    || en->rtti() == RS2::EntityArc))
91                 {
92                         circle2 = en;
93
94                         RS_Creation creation(NULL, NULL);
95                         RS_Line * t = creation.createTangent2(mouse,
96                                         circle1,
97                                         circle2);
98
99                         if (t != NULL)
100                         {
101                                 if (tangent != NULL)
102                                         delete tangent;
103                                 tangent = (RS_Line *)t->clone();
104
105                                 deletePreview();
106                                 clearPreview();
107                                 preview->addEntity(t);
108                                 drawPreview();
109                         }
110                 }
111         }
112         break;
113
114         default:
115                 break;
116         }
117
118         RS_DEBUG->print("RS_ActionDrawLineTangent2::mouseMoveEvent end");
119 }
120
121 void RS_ActionDrawLineTangent2::mouseReleaseEvent(QMouseEvent * e)
122 {
123         if (e->button() == Qt::RightButton)
124         {
125                 deletePreview();
126                 clearPreview();
127                 init(getStatus() - 1);
128         }
129         else
130         {
131                 switch (getStatus())
132                 {
133                 case SetCircle1:
134                         setStatus(SetCircle2);
135                         break;
136
137                 case SetCircle2:
138                         trigger();
139                         break;
140                 }
141         }
142 }
143
144 void RS_ActionDrawLineTangent2::updateMouseButtonHints()
145 {
146         if (RS_DIALOGFACTORY != NULL)
147         {
148                 switch (getStatus())
149                 {
150                 case SetCircle1:
151                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first circle or arc"),
152                                 tr("Cancel"));
153                         break;
154
155                 case SetCircle2:
156                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second circle or arc"),
157                                 tr("Back"));
158                         break;
159
160                 default:
161                         RS_DIALOGFACTORY->updateMouseWidget("", "");
162                         break;
163                 }
164         }
165 }
166
167 void RS_ActionDrawLineTangent2::updateMouseCursor()
168 {
169         graphicView->setMouseCursor(RS2::CadCursor);
170 }
171
172 void RS_ActionDrawLineTangent2::updateToolBar()
173 {
174         if (RS_DIALOGFACTORY != NULL)
175                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
176 }
177
178 // EOF