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