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