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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actionmodifytrimamount.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "rs_modification.h"
23 ActionModifyTrimAmount::ActionModifyTrimAmount(
24 RS_EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Trim Entity by a given amount",
26 container, graphicView)
29 trimCoord = Vector(false);
33 ActionModifyTrimAmount::~ActionModifyTrimAmount()
37 /*virtual*/ RS2::ActionType ActionModifyTrimAmount::rtti()
39 return RS2::ActionModifyTrimAmount;
42 void ActionModifyTrimAmount::init(int status)
44 ActionInterface::init(status);
46 /* snapMode = RS2::SnapFree;
47 snapRes = RS2::RestrictNothing;*/
50 void ActionModifyTrimAmount::trigger()
52 RS_DEBUG->print("ActionModifyTrimAmount::trigger()");
54 if (trimEntity != NULL && trimEntity->isAtomic())
56 RS_Modification m(*container, graphicView);
57 m.trimAmount(trimCoord, (RS_AtomicEntity *)trimEntity, distance);
60 setStatus(ChooseTrimEntity);
62 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
66 void ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e)
68 trimCoord = graphicView->toGraph(e->x(), e->y());
69 trimEntity = catchEntity(e);
71 if (e->button() == Qt::LeftButton)
75 case ChooseTrimEntity:
77 if (trimEntity != NULL && trimEntity->isAtomic())
81 if (trimEntity == NULL)
82 RS_DIALOGFACTORY->commandMessage(
83 tr("No entity found. "));
84 else if (trimEntity->rtti() == RS2::EntityInsert)
85 RS_DIALOGFACTORY->commandMessage(
86 tr("The chosen Entity is in a block. "
87 "Please edit the block."));
89 RS_DIALOGFACTORY->commandMessage(
90 tr("The chosen Entity is not an atomic entity "
91 "or cannot be trimmed."));
99 else if (e->button() == Qt::RightButton)
102 init(getStatus() - 1);
106 void ActionModifyTrimAmount::commandEvent(RS_CommandEvent * e)
108 QString c = e->getCommand().toLower();
110 if (checkCommand("help", c))
112 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
113 + getAvailableCommands().join(", "));
119 case ChooseTrimEntity: {
121 double d = RS_Math::eval(c, &ok);
126 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
127 RS_DIALOGFACTORY->requestOptions(this, true, true);
128 setStatus(ChooseTrimEntity);
137 QStringList ActionModifyTrimAmount::getAvailableCommands()
143 case ChooseTrimEntity:
153 void ActionModifyTrimAmount::showOptions()
155 ActionInterface::showOptions();
157 RS_DIALOGFACTORY->requestOptions(this, true);
160 void ActionModifyTrimAmount::hideOptions()
162 ActionInterface::hideOptions();
164 RS_DIALOGFACTORY->requestOptions(this, false);
167 void ActionModifyTrimAmount::updateMouseButtonHints()
171 case ChooseTrimEntity:
172 RS_DIALOGFACTORY->updateMouseWidget(
173 tr("Select entity to trim or enter distance:"), tr("Back"));
177 RS_DIALOGFACTORY->updateMouseWidget("", "");
182 void ActionModifyTrimAmount::updateMouseCursor()
184 graphicView->setMouseCursor(RS2::CadCursor);
187 void ActionModifyTrimAmount::updateToolBar()
189 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
192 double ActionModifyTrimAmount::getDistance()
197 void ActionModifyTrimAmount::setDistance(double d)