1 // 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 "actionmodifytrimamount.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_modification.h"
21 ActionModifyTrimAmount::ActionModifyTrimAmount(
22 RS_EntityContainer & container, GraphicView & graphicView):
23 ActionInterface("Trim Entity by a given amount",
24 container, graphicView)
27 trimCoord = Vector(false);
31 ActionModifyTrimAmount::~ActionModifyTrimAmount()
35 /*virtual*/ RS2::ActionType ActionModifyTrimAmount::rtti()
37 return RS2::ActionModifyTrimAmount;
40 void ActionModifyTrimAmount::init(int status)
42 ActionInterface::init(status);
44 /* snapMode = RS2::SnapFree;
45 snapRes = RS2::RestrictNothing;*/
48 void ActionModifyTrimAmount::trigger()
50 RS_DEBUG->print("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 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 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 ActionModifyTrimAmount::getAvailableCommands()
141 case ChooseTrimEntity:
151 void ActionModifyTrimAmount::showOptions()
153 ActionInterface::showOptions();
155 RS_DIALOGFACTORY->requestOptions(this, true);
158 void ActionModifyTrimAmount::hideOptions()
160 ActionInterface::hideOptions();
162 RS_DIALOGFACTORY->requestOptions(this, false);
165 void ActionModifyTrimAmount::updateMouseButtonHints()
169 case ChooseTrimEntity:
170 RS_DIALOGFACTORY->updateMouseWidget(
171 tr("Select entity to trim or enter distance:"), tr("Back"));
175 RS_DIALOGFACTORY->updateMouseWidget("", "");
180 void ActionModifyTrimAmount::updateMouseCursor()
182 graphicView->setMouseCursor(RS2::CadCursor);
185 void ActionModifyTrimAmount::updateToolBar()
187 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
190 double ActionModifyTrimAmount::getDistance()
195 void ActionModifyTrimAmount::setDistance(double d)