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