1 // rs_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 "rs_actionmodifybevel.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_information.h"
21 RS_ActionModifyBevel::RS_ActionModifyBevel(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Bevel Entities",
22 container, graphicView)
25 coord1 = Vector(false);
27 coord2 = Vector(false);
30 RS_ActionModifyBevel::~RS_ActionModifyBevel()
34 /*virtual*/ RS2::ActionType RS_ActionModifyBevel::rtti()
36 return RS2::ActionModifyBevel;
39 void RS_ActionModifyBevel::init(int status)
41 RS_ActionInterface::init(status);
43 snapMode = RS2::SnapFree;
44 snapRes = RS2::RestrictNothing;
47 void RS_ActionModifyBevel::trigger()
49 RS_DEBUG->print("RS_ActionModifyBevel::trigger()");
51 if (entity1 != NULL && entity1->isAtomic()
52 && entity2 != NULL && entity2->isAtomic())
54 RS_Modification m(*container, graphicView);
55 m.bevel(coord1, (RS_AtomicEntity *)entity1,
56 coord2, (RS_AtomicEntity *)entity2,
61 setStatus(SetEntity1);
63 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
67 void RS_ActionModifyBevel::mouseMoveEvent(QMouseEvent * e)
69 RS_DEBUG->print("RS_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("RS_ActionModifyBevel::mouseMoveEvent end");
97 void RS_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 RS_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 RS_ActionModifyBevel::getAvailableCommands()
225 cmd += command("length1");
226 cmd += command("length2");
227 cmd += command("trim");
236 void RS_ActionModifyBevel::showOptions()
238 RS_ActionInterface::showOptions();
240 RS_DIALOGFACTORY->requestOptions(this, true);
243 void RS_ActionModifyBevel::hideOptions()
245 RS_ActionInterface::hideOptions();
247 RS_DIALOGFACTORY->requestOptions(this, false);
250 void RS_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 RS_ActionModifyBevel::updateMouseCursor()
286 graphicView->setMouseCursor(RS2::CadCursor);
289 void RS_ActionModifyBevel::updateToolBar()
291 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
294 void RS_ActionModifyBevel::setLength1(double l1)
299 double RS_ActionModifyBevel::getLength1()
304 void RS_ActionModifyBevel::setLength2(double l2)
309 double RS_ActionModifyBevel::getLength2()
314 void RS_ActionModifyBevel::setTrim(bool t)
319 bool RS_ActionModifyBevel::isTrimOn()