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_dialogfactory.h"
18 #include "rs_information.h"
20 RS_ActionModifyBevel::RS_ActionModifyBevel(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Bevel Entities",
21 container, graphicView)
24 coord1 = Vector(false);
26 coord2 = Vector(false);
29 RS_ActionModifyBevel::~RS_ActionModifyBevel()
33 /*virtual*/ RS2::ActionType RS_ActionModifyBevel::rtti()
35 return RS2::ActionModifyBevel;
38 void RS_ActionModifyBevel::init(int status)
40 RS_ActionInterface::init(status);
42 snapMode = RS2::SnapFree;
43 snapRes = RS2::RestrictNothing;
46 void RS_ActionModifyBevel::trigger()
48 RS_DEBUG->print("RS_ActionModifyBevel::trigger()");
50 if (entity1 != NULL && entity1->isAtomic()
51 && entity2 != NULL && entity2->isAtomic())
53 RS_Modification m(*container, graphicView);
54 m.bevel(coord1, (RS_AtomicEntity *)entity1,
55 coord2, (RS_AtomicEntity *)entity2,
60 setStatus(SetEntity1);
62 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
66 void RS_ActionModifyBevel::mouseMoveEvent(QMouseEvent * e)
68 RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent begin");
70 Vector mouse = graphicView->toGraph(e->x(), e->y());
71 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
82 if (entity1 != NULL && RS_Information::isTrimmable(entity1))
93 RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent end");
96 void RS_ActionModifyBevel::mouseReleaseEvent(QMouseEvent * e)
98 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
104 if (entity1 != NULL && entity1->isAtomic())
105 setStatus(SetEntity2);
110 if (entity2 != NULL && entity2->isAtomic()
111 && RS_Information::isTrimmable(entity1, entity2))
119 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
123 init(getStatus() - 1);
127 void RS_ActionModifyBevel::commandEvent(RS_CommandEvent * e)
129 QString c = e->getCommand().toLower();
131 if (checkCommand("help", c))
133 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
134 + getAvailableCommands().join(", "));
143 if (checkCommand("length1", c))
148 lastStatus = (Status)getStatus();
149 setStatus(SetLength1);
151 else if (checkCommand("length2", c))
156 lastStatus = (Status)getStatus();
157 setStatus(SetLength2);
159 else if (checkCommand("trim", c))
164 //lastStatus = (Status)getStatus();
165 //setStatus(SetTrim);
166 data.trim = !data.trim;
167 RS_DIALOGFACTORY->requestOptions(this, true, true);
173 double l = RS_Math::eval(c, &ok);
178 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
179 RS_DIALOGFACTORY->requestOptions(this, true, true);
180 setStatus(lastStatus);
186 double l = RS_Math::eval(c, &ok);
191 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
192 RS_DIALOGFACTORY->requestOptions(this, true, true);
193 setStatus(lastStatus);
198 if (checkCommand()) {
200 } else if (c==cmdNo.toLower() || c==cmdNo2) {
203 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
206 RS_DIALOGFACTORY->requestOptions(this, true, true);
207 setStatus(lastStatus);
216 QStringList RS_ActionModifyBevel::getAvailableCommands()
224 cmd += command("length1");
225 cmd += command("length2");
226 cmd += command("trim");
235 void RS_ActionModifyBevel::showOptions()
237 RS_ActionInterface::showOptions();
239 RS_DIALOGFACTORY->requestOptions(this, true);
242 void RS_ActionModifyBevel::hideOptions()
244 RS_ActionInterface::hideOptions();
246 RS_DIALOGFACTORY->requestOptions(this, false);
249 void RS_ActionModifyBevel::updateMouseButtonHints()
254 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
259 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
264 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
269 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
274 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
278 RS_DIALOGFACTORY->updateMouseWidget("", "");
283 void RS_ActionModifyBevel::updateMouseCursor()
285 graphicView->setMouseCursor(RS2::CadCursor);
288 void RS_ActionModifyBevel::updateToolBar()
290 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
293 void RS_ActionModifyBevel::setLength1(double l1)
298 double RS_ActionModifyBevel::getLength1()
303 void RS_ActionModifyBevel::setLength2(double l2)
308 double RS_ActionModifyBevel::getLength2()
313 void RS_ActionModifyBevel::setTrim(bool t)
318 bool RS_ActionModifyBevel::isTrimOn()