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