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_dialogfactory.h"
18 #include "rs_modification.h"
20 RS_ActionModifyTrimAmount::RS_ActionModifyTrimAmount(
21 RS_EntityContainer & container, RS_GraphicView & graphicView):
22 RS_ActionInterface("Trim Entity by a given amount",
23 container, graphicView)
26 trimCoord = Vector(false);
30 RS_ActionModifyTrimAmount::~RS_ActionModifyTrimAmount()
34 /*virtual*/ RS2::ActionType RS_ActionModifyTrimAmount::rtti()
36 return RS2::ActionModifyTrimAmount;
39 void RS_ActionModifyTrimAmount::init(int status)
41 RS_ActionInterface::init(status);
43 snapMode = RS2::SnapFree;
44 snapRes = RS2::RestrictNothing;
47 void RS_ActionModifyTrimAmount::trigger()
49 RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()");
51 if (trimEntity != NULL && trimEntity->isAtomic())
53 RS_Modification m(*container, graphicView);
54 m.trimAmount(trimCoord, (RS_AtomicEntity *)trimEntity, distance);
57 setStatus(ChooseTrimEntity);
59 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
63 void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e)
65 trimCoord = graphicView->toGraph(e->x(), e->y());
66 trimEntity = catchEntity(e);
68 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
72 case ChooseTrimEntity:
74 if (trimEntity != NULL && trimEntity->isAtomic())
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."));
86 RS_DIALOGFACTORY->commandMessage(
87 tr("The chosen Entity is not an atomic entity "
88 "or cannot be trimmed."));
96 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
99 init(getStatus() - 1);
103 void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent * e)
105 QString c = e->getCommand().toLower();
107 if (checkCommand("help", c))
109 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
110 + getAvailableCommands().join(", "));
116 case ChooseTrimEntity: {
118 double d = RS_Math::eval(c, &ok);
123 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
124 RS_DIALOGFACTORY->requestOptions(this, true, true);
125 setStatus(ChooseTrimEntity);
134 QStringList RS_ActionModifyTrimAmount::getAvailableCommands()
140 case ChooseTrimEntity:
150 void RS_ActionModifyTrimAmount::showOptions()
152 RS_ActionInterface::showOptions();
154 RS_DIALOGFACTORY->requestOptions(this, true);
157 void RS_ActionModifyTrimAmount::hideOptions()
159 RS_ActionInterface::hideOptions();
161 RS_DIALOGFACTORY->requestOptions(this, false);
164 void RS_ActionModifyTrimAmount::updateMouseButtonHints()
168 case ChooseTrimEntity:
169 RS_DIALOGFACTORY->updateMouseWidget(
170 tr("Select entity to trim or enter distance:"),
175 RS_DIALOGFACTORY->updateMouseWidget("", "");
180 void RS_ActionModifyTrimAmount::updateMouseCursor()
182 graphicView->setMouseCursor(RS2::CadCursor);
185 void RS_ActionModifyTrimAmount::updateToolBar()
187 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
190 double RS_ActionModifyTrimAmount::getDistance()
195 void RS_ActionModifyTrimAmount::setDistance(double d)