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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "actionmodifybevel.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_information.h"
21 ActionModifyBevel::ActionModifyBevel(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Bevel Entities",
22 container, graphicView)
25 coord1 = Vector(false);
27 coord2 = Vector(false);
30 ActionModifyBevel::~ActionModifyBevel()
34 /*virtual*/ RS2::ActionType ActionModifyBevel::rtti()
36 return RS2::ActionModifyBevel;
39 void ActionModifyBevel::init(int status)
41 ActionInterface::init(status);
43 /* snapMode = RS2::SnapFree;
44 snapRes = RS2::RestrictNothing;*/
47 void ActionModifyBevel::trigger()
49 RS_DEBUG->print("ActionModifyBevel::trigger()");
51 if (entity1 && entity1->isAtomic()
52 && entity2 && entity2->isAtomic())
54 RS_Modification m(*container, graphicView);
55 m.bevel(coord1, (RS_AtomicEntity *)entity1, coord2, (RS_AtomicEntity *)entity2, data);
59 setStatus(SetEntity1);
61 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
65 void ActionModifyBevel::mouseMoveEvent(QMouseEvent * e)
67 RS_DEBUG->print("ActionModifyBevel::mouseMoveEvent begin");
69 Vector mouse = graphicView->toGraph(e->x(), e->y());
70 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
81 if (entity1 != NULL && RS_Information::isTrimmable(entity1))
92 RS_DEBUG->print("ActionModifyBevel::mouseMoveEvent end");
95 void ActionModifyBevel::mouseReleaseEvent(QMouseEvent * e)
97 if (e->button() == Qt::LeftButton)
103 if (entity1 != NULL && entity1->isAtomic())
104 setStatus(SetEntity2);
109 if (entity2 != NULL && entity2->isAtomic()
110 && RS_Information::isTrimmable(entity1, entity2))
118 else if (e->button() == Qt::RightButton)
122 init(getStatus() - 1);
126 void ActionModifyBevel::commandEvent(RS_CommandEvent * e)
128 QString c = e->getCommand().toLower();
130 if (checkCommand("help", c))
132 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
133 + getAvailableCommands().join(", "));
142 if (checkCommand("length1", c))
147 lastStatus = (Status)getStatus();
148 setStatus(SetLength1);
150 else if (checkCommand("length2", c))
155 lastStatus = (Status)getStatus();
156 setStatus(SetLength2);
158 else if (checkCommand("trim", c))
163 //lastStatus = (Status)getStatus();
164 //setStatus(SetTrim);
165 data.trim = !data.trim;
166 RS_DIALOGFACTORY->requestOptions(this, true, true);
172 double l = RS_Math::eval(c, &ok);
177 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
178 RS_DIALOGFACTORY->requestOptions(this, true, true);
179 setStatus(lastStatus);
185 double l = RS_Math::eval(c, &ok);
190 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
191 RS_DIALOGFACTORY->requestOptions(this, true, true);
192 setStatus(lastStatus);
197 if (checkCommand()) {
199 } else if (c==cmdNo.toLower() || c==cmdNo2) {
202 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
205 RS_DIALOGFACTORY->requestOptions(this, true, true);
206 setStatus(lastStatus);
215 QStringList ActionModifyBevel::getAvailableCommands()
223 cmd += command("length1");
224 cmd += command("length2");
225 cmd += command("trim");
234 void ActionModifyBevel::showOptions()
236 ActionInterface::showOptions();
238 RS_DIALOGFACTORY->requestOptions(this, true);
241 void ActionModifyBevel::hideOptions()
243 ActionInterface::hideOptions();
245 RS_DIALOGFACTORY->requestOptions(this, false);
248 void ActionModifyBevel::updateMouseButtonHints()
253 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
258 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
263 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
268 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
273 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
277 RS_DIALOGFACTORY->updateMouseWidget("", "");
282 void ActionModifyBevel::updateMouseCursor()
284 graphicView->setMouseCursor(RS2::CadCursor);
287 void ActionModifyBevel::updateToolBar()
289 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
292 void ActionModifyBevel::setLength1(double l1)
297 double ActionModifyBevel::getLength1()
302 void ActionModifyBevel::setLength2(double l2)
307 double ActionModifyBevel::getLength2()
312 void ActionModifyBevel::setTrim(bool t)
317 bool ActionModifyBevel::isTrimOn()