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 "commandevent.h"
21 #include "dialogfactory.h"
22 #include "modification.h"
24 ActionModifyTrimAmount::ActionModifyTrimAmount(
25 EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Trim Entity by a given amount",
27 container, graphicView)
30 trimCoord = Vector(false);
34 ActionModifyTrimAmount::~ActionModifyTrimAmount()
38 /*virtual*/ RS2::ActionType ActionModifyTrimAmount::rtti()
40 return RS2::ActionModifyTrimAmount;
43 void ActionModifyTrimAmount::init(int status)
45 ActionInterface::init(status);
47 /* snapMode = RS2::SnapFree;
48 snapRes = RS2::RestrictNothing;*/
51 void ActionModifyTrimAmount::trigger()
53 DEBUG->print("ActionModifyTrimAmount::trigger()");
55 if (trimEntity != NULL && trimEntity->isAtomic())
57 Modification m(*container, graphicView);
58 m.trimAmount(trimCoord, (AtomicEntity *)trimEntity, distance);
61 setStatus(ChooseTrimEntity);
63 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
67 void ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e)
69 trimCoord = graphicView->toGraph(e->x(), e->y());
70 trimEntity = catchEntity(e);
72 if (e->button() == Qt::LeftButton)
76 case ChooseTrimEntity:
78 if (trimEntity != NULL && trimEntity->isAtomic())
82 if (trimEntity == NULL)
83 DIALOGFACTORY->commandMessage(
84 tr("No entity found. "));
85 else if (trimEntity->rtti() == RS2::EntityInsert)
86 DIALOGFACTORY->commandMessage(
87 tr("The chosen Entity is in a block. "
88 "Please edit the block."));
90 DIALOGFACTORY->commandMessage(
91 tr("The chosen Entity is not an atomic entity "
92 "or cannot be trimmed."));
100 else if (e->button() == Qt::RightButton)
103 init(getStatus() - 1);
107 void ActionModifyTrimAmount::commandEvent(CommandEvent * e)
109 QString c = e->getCommand().toLower();
111 if (checkCommand("help", c))
113 DIALOGFACTORY->commandMessage(msgAvailableCommands()
114 + getAvailableCommands().join(", "));
120 case ChooseTrimEntity: {
122 double d = Math::eval(c, &ok);
127 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
128 DIALOGFACTORY->requestOptions(this, true, true);
129 setStatus(ChooseTrimEntity);
138 QStringList ActionModifyTrimAmount::getAvailableCommands()
144 case ChooseTrimEntity:
154 void ActionModifyTrimAmount::showOptions()
156 ActionInterface::showOptions();
158 DIALOGFACTORY->requestOptions(this, true);
161 void ActionModifyTrimAmount::hideOptions()
163 ActionInterface::hideOptions();
165 DIALOGFACTORY->requestOptions(this, false);
168 void ActionModifyTrimAmount::updateMouseButtonHints()
172 case ChooseTrimEntity:
173 DIALOGFACTORY->updateMouseWidget(
174 tr("Select entity to trim or enter distance:"), tr("Back"));
178 DIALOGFACTORY->updateMouseWidget("", "");
183 void ActionModifyTrimAmount::updateMouseCursor()
185 graphicView->setMouseCursor(RS2::CadCursor);
188 void ActionModifyTrimAmount::updateToolBar()
190 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
193 double ActionModifyTrimAmount::getDistance()
198 void ActionModifyTrimAmount::setDistance(double d)