]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifytrimamount.cpp
Sanity check stage II: rename classes...
[architektonas] / src / actions / actionmodifytrimamount.cpp
1 // actionmodifytrimamount.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 "actionmodifytrimamount.h"
18
19 #include "rs_commandevent.h"
20 #include "rs_debug.h"
21 #include "rs_dialogfactory.h"
22 #include "rs_modification.h"
23
24 ActionModifyTrimAmount::ActionModifyTrimAmount(
25         RS_EntityContainer & container, GraphicView & graphicView):
26         ActionInterface("Trim Entity by a given amount",
27                 container, graphicView)
28 {
29         trimEntity = NULL;
30         trimCoord = Vector(false);
31         distance = 0.0;
32 }
33
34 ActionModifyTrimAmount::~ActionModifyTrimAmount()
35 {
36 }
37
38 /*virtual*/ RS2::ActionType ActionModifyTrimAmount::rtti()
39 {
40         return RS2::ActionModifyTrimAmount;
41 }
42
43 void ActionModifyTrimAmount::init(int status)
44 {
45         ActionInterface::init(status);
46
47 /*      snapMode = RS2::SnapFree;
48         snapRes = RS2::RestrictNothing;*/
49 }
50
51 void ActionModifyTrimAmount::trigger()
52 {
53         RS_DEBUG->print("ActionModifyTrimAmount::trigger()");
54
55         if (trimEntity != NULL && trimEntity->isAtomic())
56         {
57                 RS_Modification m(*container, graphicView);
58                 m.trimAmount(trimCoord, (RS_AtomicEntity *)trimEntity, distance);
59
60                 trimEntity = NULL;
61                 setStatus(ChooseTrimEntity);
62
63                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
64         }
65 }
66
67 void ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e)
68 {
69         trimCoord = graphicView->toGraph(e->x(), e->y());
70         trimEntity = catchEntity(e);
71
72         if (e->button() == Qt::LeftButton)
73         {
74                 switch (getStatus())
75                 {
76                 case ChooseTrimEntity:
77
78                         if (trimEntity != NULL && trimEntity->isAtomic())
79                                 trigger();
80                         else
81                         {
82                                 if (trimEntity == NULL)
83                                         RS_DIALOGFACTORY->commandMessage(
84                                                 tr("No entity found. "));
85                                 else if (trimEntity->rtti() == RS2::EntityInsert)
86                                         RS_DIALOGFACTORY->commandMessage(
87                                                 tr("The chosen Entity is in a block. "
88                                                         "Please edit the block."));
89                                 else
90                                         RS_DIALOGFACTORY->commandMessage(
91                                                 tr("The chosen Entity is not an atomic entity "
92                                                         "or cannot be trimmed."));
93                         }
94                         break;
95
96                 default:
97                         break;
98                 }
99         }
100         else if (e->button() == Qt::RightButton)
101         {
102                 deleteSnapper();
103                 init(getStatus() - 1);
104         }
105 }
106
107 void ActionModifyTrimAmount::commandEvent(RS_CommandEvent * e)
108 {
109         QString c = e->getCommand().toLower();
110
111         if (checkCommand("help", c))
112         {
113                 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
114                         + getAvailableCommands().join(", "));
115                 return;
116         }
117
118         switch (getStatus())
119         {
120         case ChooseTrimEntity: {
121                 bool ok;
122                 double d = RS_Math::eval(c, &ok);
123
124                 if (ok == true)
125                         distance = d;
126                 else
127                         RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
128                 RS_DIALOGFACTORY->requestOptions(this, true, true);
129                 setStatus(ChooseTrimEntity);
130         }
131         break;
132
133         default:
134                 break;
135         }
136 }
137
138 QStringList ActionModifyTrimAmount::getAvailableCommands()
139 {
140         QStringList cmd;
141
142         switch (getStatus())
143         {
144         case ChooseTrimEntity:
145                 break;
146
147         default:
148                 break;
149         }
150
151         return cmd;
152 }
153
154 void ActionModifyTrimAmount::showOptions()
155 {
156         ActionInterface::showOptions();
157
158         RS_DIALOGFACTORY->requestOptions(this, true);
159 }
160
161 void ActionModifyTrimAmount::hideOptions()
162 {
163         ActionInterface::hideOptions();
164
165         RS_DIALOGFACTORY->requestOptions(this, false);
166 }
167
168 void ActionModifyTrimAmount::updateMouseButtonHints()
169 {
170         switch (getStatus())
171         {
172         case ChooseTrimEntity:
173                 RS_DIALOGFACTORY->updateMouseWidget(
174                         tr("Select entity to trim or enter distance:"), tr("Back"));
175                 break;
176
177         default:
178                 RS_DIALOGFACTORY->updateMouseWidget("", "");
179                 break;
180         }
181 }
182
183 void ActionModifyTrimAmount::updateMouseCursor()
184 {
185         graphicView->setMouseCursor(RS2::CadCursor);
186 }
187
188 void ActionModifyTrimAmount::updateToolBar()
189 {
190         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
191 }
192
193 double ActionModifyTrimAmount::getDistance()
194 {
195         return distance;
196 }
197
198 void ActionModifyTrimAmount::setDistance(double d)
199 {
200         distance = d;
201 }