1 // actionmodifybevel.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 "actionmodifybevel.h"
19 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "information.h"
24 ActionModifyBevel::ActionModifyBevel(EntityContainer & container, GraphicView & graphicView): ActionInterface("Bevel Entities",
25 container, graphicView)
28 coord1 = Vector(false);
30 coord2 = Vector(false);
33 ActionModifyBevel::~ActionModifyBevel()
37 /*virtual*/ RS2::ActionType ActionModifyBevel::rtti()
39 return RS2::ActionModifyBevel;
42 void ActionModifyBevel::init(int status)
44 ActionInterface::init(status);
46 /* snapMode = RS2::SnapFree;
47 snapRes = RS2::RestrictNothing;*/
50 void ActionModifyBevel::trigger()
52 DEBUG->print("ActionModifyBevel::trigger()");
54 if (entity1 && entity1->isAtomic()
55 && entity2 && entity2->isAtomic())
57 Modification m(*container, graphicView);
58 m.bevel(coord1, (AtomicEntity *)entity1, coord2, (AtomicEntity *)entity2, data);
62 setStatus(SetEntity1);
64 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
68 void ActionModifyBevel::mouseMoveEvent(QMouseEvent * e)
70 DEBUG->print("ActionModifyBevel::mouseMoveEvent begin");
72 Vector mouse = graphicView->toGraph(e->x(), e->y());
73 Entity * se = catchEntity(e, RS2::ResolveAll);
84 if (entity1 != NULL && Information::isTrimmable(entity1))
95 DEBUG->print("ActionModifyBevel::mouseMoveEvent end");
98 void ActionModifyBevel::mouseReleaseEvent(QMouseEvent * e)
100 if (e->button() == Qt::LeftButton)
106 if (entity1 != NULL && entity1->isAtomic())
107 setStatus(SetEntity2);
112 if (entity2 != NULL && entity2->isAtomic()
113 && Information::isTrimmable(entity1, entity2))
121 else if (e->button() == Qt::RightButton)
125 init(getStatus() - 1);
129 void ActionModifyBevel::commandEvent(CommandEvent * e)
131 QString c = e->getCommand().toLower();
133 if (checkCommand("help", c))
135 DIALOGFACTORY->commandMessage(msgAvailableCommands()
136 + getAvailableCommands().join(", "));
145 if (checkCommand("length1", c))
150 lastStatus = (Status)getStatus();
151 setStatus(SetLength1);
153 else if (checkCommand("length2", c))
158 lastStatus = (Status)getStatus();
159 setStatus(SetLength2);
161 else if (checkCommand("trim", c))
166 //lastStatus = (Status)getStatus();
167 //setStatus(SetTrim);
168 data.trim = !data.trim;
169 DIALOGFACTORY->requestOptions(this, true, true);
175 double l = Math::eval(c, &ok);
180 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
181 DIALOGFACTORY->requestOptions(this, true, true);
182 setStatus(lastStatus);
188 double l = Math::eval(c, &ok);
193 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
194 DIALOGFACTORY->requestOptions(this, true, true);
195 setStatus(lastStatus);
200 if (checkCommand()) {
202 } else if (c==cmdNo.toLower() || c==cmdNo2) {
205 DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
208 DIALOGFACTORY->requestOptions(this, true, true);
209 setStatus(lastStatus);
218 QStringList ActionModifyBevel::getAvailableCommands()
226 cmd += command("length1");
227 cmd += command("length2");
228 cmd += command("trim");
237 void ActionModifyBevel::showOptions()
239 ActionInterface::showOptions();
241 DIALOGFACTORY->requestOptions(this, true);
244 void ActionModifyBevel::hideOptions()
246 ActionInterface::hideOptions();
248 DIALOGFACTORY->requestOptions(this, false);
251 void ActionModifyBevel::updateMouseButtonHints()
256 DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
261 DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
266 DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
271 DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
276 DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
280 DIALOGFACTORY->updateMouseWidget("", "");
285 void ActionModifyBevel::updateMouseCursor()
287 graphicView->setMouseCursor(RS2::CadCursor);
290 void ActionModifyBevel::updateToolBar()
292 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
295 void ActionModifyBevel::setLength1(double l1)
300 double ActionModifyBevel::getLength1()
305 void ActionModifyBevel::setLength2(double l2)
310 double ActionModifyBevel::getLength2()
315 void ActionModifyBevel::setTrim(bool t)
320 bool ActionModifyBevel::isTrimOn()