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