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 "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "rs_information.h"
23 ActionModifyBevel::ActionModifyBevel(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Bevel Entities",
24 container, graphicView)
27 coord1 = Vector(false);
29 coord2 = Vector(false);
32 ActionModifyBevel::~ActionModifyBevel()
36 /*virtual*/ RS2::ActionType ActionModifyBevel::rtti()
38 return RS2::ActionModifyBevel;
41 void ActionModifyBevel::init(int status)
43 ActionInterface::init(status);
45 /* snapMode = RS2::SnapFree;
46 snapRes = RS2::RestrictNothing;*/
49 void ActionModifyBevel::trigger()
51 RS_DEBUG->print("ActionModifyBevel::trigger()");
53 if (entity1 && entity1->isAtomic()
54 && entity2 && entity2->isAtomic())
56 RS_Modification m(*container, graphicView);
57 m.bevel(coord1, (RS_AtomicEntity *)entity1, coord2, (RS_AtomicEntity *)entity2, data);
61 setStatus(SetEntity1);
63 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
67 void ActionModifyBevel::mouseMoveEvent(QMouseEvent * e)
69 RS_DEBUG->print("ActionModifyBevel::mouseMoveEvent begin");
71 Vector mouse = graphicView->toGraph(e->x(), e->y());
72 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
83 if (entity1 != NULL && RS_Information::isTrimmable(entity1))
94 RS_DEBUG->print("ActionModifyBevel::mouseMoveEvent end");
97 void ActionModifyBevel::mouseReleaseEvent(QMouseEvent * e)
99 if (e->button() == Qt::LeftButton)
105 if (entity1 != NULL && entity1->isAtomic())
106 setStatus(SetEntity2);
111 if (entity2 != NULL && entity2->isAtomic()
112 && RS_Information::isTrimmable(entity1, entity2))
120 else if (e->button() == Qt::RightButton)
124 init(getStatus() - 1);
128 void ActionModifyBevel::commandEvent(RS_CommandEvent * e)
130 QString c = e->getCommand().toLower();
132 if (checkCommand("help", c))
134 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
135 + getAvailableCommands().join(", "));
144 if (checkCommand("length1", c))
149 lastStatus = (Status)getStatus();
150 setStatus(SetLength1);
152 else if (checkCommand("length2", c))
157 lastStatus = (Status)getStatus();
158 setStatus(SetLength2);
160 else if (checkCommand("trim", c))
165 //lastStatus = (Status)getStatus();
166 //setStatus(SetTrim);
167 data.trim = !data.trim;
168 RS_DIALOGFACTORY->requestOptions(this, true, true);
174 double l = RS_Math::eval(c, &ok);
179 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
180 RS_DIALOGFACTORY->requestOptions(this, true, true);
181 setStatus(lastStatus);
187 double l = RS_Math::eval(c, &ok);
192 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
193 RS_DIALOGFACTORY->requestOptions(this, true, true);
194 setStatus(lastStatus);
199 if (checkCommand()) {
201 } else if (c==cmdNo.toLower() || c==cmdNo2) {
204 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
207 RS_DIALOGFACTORY->requestOptions(this, true, true);
208 setStatus(lastStatus);
217 QStringList ActionModifyBevel::getAvailableCommands()
225 cmd += command("length1");
226 cmd += command("length2");
227 cmd += command("trim");
236 void ActionModifyBevel::showOptions()
238 ActionInterface::showOptions();
240 RS_DIALOGFACTORY->requestOptions(this, true);
243 void ActionModifyBevel::hideOptions()
245 ActionInterface::hideOptions();
247 RS_DIALOGFACTORY->requestOptions(this, false);
250 void ActionModifyBevel::updateMouseButtonHints()
255 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
260 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
265 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
270 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
275 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
279 RS_DIALOGFACTORY->updateMouseWidget("", "");
284 void ActionModifyBevel::updateMouseCursor()
286 graphicView->setMouseCursor(RS2::CadCursor);
289 void ActionModifyBevel::updateToolBar()
291 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
294 void ActionModifyBevel::setLength1(double l1)
299 double ActionModifyBevel::getLength1()
304 void ActionModifyBevel::setLength2(double l2)
309 double ActionModifyBevel::getLength2()
314 void ActionModifyBevel::setTrim(bool t)
319 bool ActionModifyBevel::isTrimOn()