1 // rs_actionmodifytrimamount.cpp
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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "rs_actionmodifytrimamount.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_modification.h"
21 RS_ActionModifyTrimAmount::RS_ActionModifyTrimAmount(
22 RS_EntityContainer & container, GraphicView & graphicView):
23 RS_ActionInterface("Trim Entity by a given amount",
24 container, graphicView)
27 trimCoord = Vector(false);
31 RS_ActionModifyTrimAmount::~RS_ActionModifyTrimAmount()
35 /*virtual*/ RS2::ActionType RS_ActionModifyTrimAmount::rtti()
37 return RS2::ActionModifyTrimAmount;
40 void RS_ActionModifyTrimAmount::init(int status)
42 RS_ActionInterface::init(status);
44 snapMode = RS2::SnapFree;
45 snapRes = RS2::RestrictNothing;
48 void RS_ActionModifyTrimAmount::trigger()
50 RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()");
52 if (trimEntity != NULL && trimEntity->isAtomic())
54 RS_Modification m(*container, graphicView);
55 m.trimAmount(trimCoord, (RS_AtomicEntity *)trimEntity, distance);
58 setStatus(ChooseTrimEntity);
60 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
64 void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e)
66 trimCoord = graphicView->toGraph(e->x(), e->y());
67 trimEntity = catchEntity(e);
69 if (e->button() == Qt::LeftButton)
73 case ChooseTrimEntity:
75 if (trimEntity != NULL && trimEntity->isAtomic())
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."));
87 RS_DIALOGFACTORY->commandMessage(
88 tr("The chosen Entity is not an atomic entity "
89 "or cannot be trimmed."));
97 else if (e->button() == Qt::RightButton)
100 init(getStatus() - 1);
104 void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent * e)
106 QString c = e->getCommand().toLower();
108 if (checkCommand("help", c))
110 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
111 + getAvailableCommands().join(", "));
117 case ChooseTrimEntity: {
119 double d = RS_Math::eval(c, &ok);
124 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
125 RS_DIALOGFACTORY->requestOptions(this, true, true);
126 setStatus(ChooseTrimEntity);
135 QStringList RS_ActionModifyTrimAmount::getAvailableCommands()
141 case ChooseTrimEntity:
151 void RS_ActionModifyTrimAmount::showOptions()
153 RS_ActionInterface::showOptions();
155 RS_DIALOGFACTORY->requestOptions(this, true);
158 void RS_ActionModifyTrimAmount::hideOptions()
160 RS_ActionInterface::hideOptions();
162 RS_DIALOGFACTORY->requestOptions(this, false);
165 void RS_ActionModifyTrimAmount::updateMouseButtonHints()
169 case ChooseTrimEntity:
170 RS_DIALOGFACTORY->updateMouseWidget(
171 tr("Select entity to trim or enter distance:"),
176 RS_DIALOGFACTORY->updateMouseWidget("", "");
181 void RS_ActionModifyTrimAmount::updateMouseCursor()
183 graphicView->setMouseCursor(RS2::CadCursor);
186 void RS_ActionModifyTrimAmount::updateToolBar()
188 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
191 double RS_ActionModifyTrimAmount::getDistance()
196 void RS_ActionModifyTrimAmount::setDistance(double d)