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