1 // rs_actionmodifyround.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_actionmodifyround.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_information.h"
19 #include "rs_preview.h"
21 RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer & container, RS_GraphicView & graphicView):
22 RS_PreviewActionInterface("Round Entities", container, graphicView)
26 coord1 = Vector(false);
27 coord2 = Vector(false);
30 RS_ActionModifyRound::~RS_ActionModifyRound()
34 /*virtual*/ RS2::ActionType RS_ActionModifyRound::rtti()
36 return RS2::ActionModifyRound;
39 void RS_ActionModifyRound::init(int status)
41 RS_ActionInterface::init(status);
43 snapMode = RS2::SnapFree;
44 snapRes = RS2::RestrictNothing;
47 void RS_ActionModifyRound::trigger()
49 RS_DEBUG->print("RS_ActionModifyRound::trigger()");
51 if (entity1 != NULL && entity1->isAtomic()
52 && entity2 != NULL && entity2->isAtomic())
56 RS_Modification m(*container, graphicView);
59 (RS_AtomicEntity *)entity1,
61 (RS_AtomicEntity *)entity2,
64 //coord = Vector(false);
65 coord1 = Vector(false);
67 coord2 = Vector(false);
69 setStatus(SetEntity1);
73 if (RS_DIALOGFACTORY != NULL)
74 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
78 void RS_ActionModifyRound::mouseMoveEvent(QMouseEvent * e)
80 RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent begin");
82 Vector mouse = graphicView->toGraph(e->x(), e->y());
83 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
96 if (entity1 != NULL && entity2 != NULL && entity2->isAtomic()
97 && RS_Information::isTrimmable(entity1, entity2))
101 //preview->addSelectionFrom(*container);
102 //preview->move(targetPoint-referencePoint);
103 RS_Entity * tmp1 = entity1->clone();
104 RS_Entity * tmp2 = entity2->clone();
105 tmp1->reparent(preview);
106 tmp2->reparent(preview);
107 preview->addEntity(tmp1);
108 preview->addEntity(tmp2);
110 bool trim = data.trim;
112 RS_Modification m(*preview, NULL, false);
115 (RS_AtomicEntity *)tmp1,
117 (RS_AtomicEntity *)tmp2,
121 preview->removeEntity(tmp1);
122 preview->removeEntity(tmp2);
131 RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent end");
134 void RS_ActionModifyRound::mouseReleaseEvent(QMouseEvent * e)
136 Vector mouse = graphicView->toGraph(e->x(), e->y());
137 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
139 if (e->button() == Qt::LeftButton)
147 if (entity1 != NULL && entity1->isAtomic()
148 && RS_Information::isTrimmable(entity1))
149 setStatus(SetEntity2);
156 if (entity2 != NULL && entity2->isAtomic()
157 && RS_Information::isTrimmable(entity1, entity2))
158 //setStatus(ChooseRounding);
166 else if (e->button() == Qt::RightButton)
170 init(getStatus() - 1);
174 void RS_ActionModifyRound::commandEvent(RS_CommandEvent * e)
176 QString c = e->getCommand().toLower();
178 if (checkCommand("help", c))
180 if (RS_DIALOGFACTORY != NULL)
181 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
182 + getAvailableCommands().join(", "));
191 if (checkCommand("radius", c))
196 lastStatus = (Status)getStatus();
197 setStatus(SetRadius);
199 else if (checkCommand("trim", c))
204 lastStatus = (Status)getStatus();
207 data.trim = !data.trim;
209 if (RS_DIALOGFACTORY != NULL)
210 RS_DIALOGFACTORY->requestOptions(this, true, true);
216 double r = RS_Math::eval(c, &ok);
220 else if (RS_DIALOGFACTORY != NULL)
221 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
223 if (RS_DIALOGFACTORY != NULL)
224 RS_DIALOGFACTORY->requestOptions(this, true, true);
225 setStatus(lastStatus);
230 if (c==cmdYes.toLower() || c==cmdYes2) {
232 } else if (c==cmdNo.toLower() || c==cmdNo2) {
235 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
238 RS_DIALOGFACTORY->requestOptions(this, true, true);
239 setStatus(lastStatus);
248 QStringList RS_ActionModifyRound::getAvailableCommands()
256 cmd += command("radius");
257 cmd += command("trim");
266 void RS_ActionModifyRound::showOptions()
268 RS_ActionInterface::showOptions();
270 if (RS_DIALOGFACTORY != NULL)
271 RS_DIALOGFACTORY->requestOptions(this, true);
274 void RS_ActionModifyRound::hideOptions()
276 RS_ActionInterface::hideOptions();
278 if (RS_DIALOGFACTORY != NULL)
279 RS_DIALOGFACTORY->requestOptions(this, false);
282 void RS_ActionModifyRound::updateMouseButtonHints()
284 if (RS_DIALOGFACTORY != NULL)
289 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
294 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
299 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
304 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
308 RS_DIALOGFACTORY->updateMouseWidget("", "");
314 void RS_ActionModifyRound::updateMouseCursor()
316 graphicView->setMouseCursor(RS2::CadCursor);
319 void RS_ActionModifyRound::updateToolBar()
321 if (RS_DIALOGFACTORY != NULL)
322 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
325 void RS_ActionModifyRound::setRadius(double r)
330 double RS_ActionModifyRound::getRadius()
335 void RS_ActionModifyRound::setTrim(bool t)
340 bool RS_ActionModifyRound::isTrimOn()