]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifytrim.cpp
4cb23892963efafe4f12e88b478c13228bead8e4
[architektonas] / src / actions / actionmodifytrim.cpp
1 // actionmodifytrim.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  05/22/2010  Added this text. :-)
13 //
14
15 #include "actionmodifytrim.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_modification.h"
19
20 /**
21  * @param both Trim both entities.
22  */
23 ActionModifyTrim::ActionModifyTrim(RS_EntityContainer & container,
24         GraphicView & graphicView, bool both): ActionInterface("Trim Entity",
25                 container, graphicView)
26 {
27         trimEntity = NULL;
28         trimCoord = Vector(false);
29         limitEntity = NULL;
30         limitCoord = Vector(false);
31         this->both = both;
32 }
33
34 ActionModifyTrim::~ActionModifyTrim()
35 {
36 }
37
38 void ActionModifyTrim::init(int status)
39 {
40         ActionInterface::init(status);
41
42 /*      snapMode = RS2::SnapFree;
43         snapRes = RS2::RestrictNothing;*/
44 }
45
46 void ActionModifyTrim::trigger()
47 {
48         RS_DEBUG->print("ActionModifyTrim::trigger()");
49
50         if (trimEntity && trimEntity->isAtomic() && limitEntity)
51         {
52                 RS_Modification m(*container, graphicView);
53                 m.trim(trimCoord, (RS_AtomicEntity *)trimEntity,
54                         limitCoord, limitEntity, both);
55
56                 trimEntity = NULL;
57
58                 if (both)
59                 {
60                         limitEntity->setHighlighted(false);
61                         graphicView->drawEntity(limitEntity);
62                         setStatus(ChooseLimitEntity);
63                 }
64                 else
65                         setStatus(ChooseTrimEntity);
66
67                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
68         }
69 }
70
71 void ActionModifyTrim::mouseMoveEvent(QMouseEvent * e)
72 {
73         RS_DEBUG->print("ActionModifyTrim::mouseMoveEvent begin");
74
75         Vector mouse = graphicView->toGraph(e->x(), e->y());
76         RS_Entity * se = catchEntity(e);
77
78         switch (getStatus())
79         {
80         case ChooseLimitEntity:
81                 limitCoord = mouse;
82                 limitEntity = se;
83                 break;
84
85         case ChooseTrimEntity:
86                 trimCoord = mouse;
87                 trimEntity = se;
88                 break;
89
90         default:
91                 break;
92         }
93
94         RS_DEBUG->print("ActionModifyTrim::mouseMoveEvent end");
95 }
96
97 void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
98 {
99         if (e->button() == Qt::LeftButton)
100         {
101                 Vector mouse = graphicView->toGraph(e->x(), e->y());
102                 RS_Entity * se = catchEntity(e);
103
104                 switch (getStatus())
105                 {
106                 case ChooseLimitEntity:
107                         limitCoord = mouse;
108                         limitEntity = se;
109
110                         if (limitEntity)
111                         {
112                                 limitEntity->setHighlighted(true);
113                                 graphicView->drawEntity(limitEntity);
114                                 setStatus(ChooseTrimEntity);
115                         }
116                         break;
117
118                 case ChooseTrimEntity:
119                         trimCoord = mouse;
120                         trimEntity = se;
121
122                         if (trimEntity != NULL && trimEntity->isAtomic())
123                                 trigger();
124                         break;
125
126                 default:
127                         break;
128                 }
129         }
130         else if (e->button() == Qt::RightButton)
131         {
132                 deletePreview();
133                 deleteSnapper();
134
135                 if (limitEntity != NULL)
136                 {
137                         limitEntity->setHighlighted(false);
138                         graphicView->drawEntity(limitEntity);
139                 }
140                 init(getStatus() - 1);
141         }
142 }
143
144 void ActionModifyTrim::updateMouseButtonHints()
145 {
146         switch (getStatus())
147         {
148         case ChooseLimitEntity:
149
150                 if (both)
151                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"),
152                                 tr("Cancel"));
153                 else
154                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"),
155                                 tr("Back"));
156                 break;
157
158         case ChooseTrimEntity:
159
160                 if (both)
161                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"),
162                                 tr("Cancel"));
163                 else
164                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"),
165                                 tr("Back"));
166                 break;
167
168         default:
169                 RS_DIALOGFACTORY->updateMouseWidget("", "");
170                 break;
171         }
172 }
173
174 void ActionModifyTrim::updateMouseCursor()
175 {
176         graphicView->setMouseCursor(RS2::CadCursor);
177 }
178
179 void ActionModifyTrim::updateToolBar()
180 {
181         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
182 }
183