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_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_information.h"
20 #include "rs_preview.h"
22 RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer & container, GraphicView & graphicView):
23 RS_PreviewActionInterface("Round Entities", container, graphicView)
27 coord1 = Vector(false);
28 coord2 = Vector(false);
31 RS_ActionModifyRound::~RS_ActionModifyRound()
35 /*virtual*/ RS2::ActionType RS_ActionModifyRound::rtti()
37 return RS2::ActionModifyRound;
40 void RS_ActionModifyRound::init(int status)
42 RS_ActionInterface::init(status);
44 snapMode = RS2::SnapFree;
45 snapRes = RS2::RestrictNothing;
48 void RS_ActionModifyRound::trigger()
50 RS_DEBUG->print("RS_ActionModifyRound::trigger()");
52 if (entity1 != NULL && entity1->isAtomic()
53 && entity2 != NULL && entity2->isAtomic())
57 RS_Modification m(*container, graphicView);
60 (RS_AtomicEntity *)entity1,
62 (RS_AtomicEntity *)entity2,
65 //coord = Vector(false);
66 coord1 = Vector(false);
68 coord2 = Vector(false);
70 setStatus(SetEntity1);
74 if (RS_DIALOGFACTORY != NULL)
75 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
79 void RS_ActionModifyRound::mouseMoveEvent(QMouseEvent * e)
81 RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent begin");
83 Vector mouse = graphicView->toGraph(e->x(), e->y());
84 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
97 if (entity1 != NULL && entity2 != NULL && entity2->isAtomic()
98 && RS_Information::isTrimmable(entity1, entity2))
102 //preview->addSelectionFrom(*container);
103 //preview->move(targetPoint-referencePoint);
104 RS_Entity * tmp1 = entity1->clone();
105 RS_Entity * tmp2 = entity2->clone();
106 tmp1->reparent(preview);
107 tmp2->reparent(preview);
108 preview->addEntity(tmp1);
109 preview->addEntity(tmp2);
111 bool trim = data.trim;
113 RS_Modification m(*preview, NULL, false);
116 (RS_AtomicEntity *)tmp1,
118 (RS_AtomicEntity *)tmp2,
122 preview->removeEntity(tmp1);
123 preview->removeEntity(tmp2);
132 RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent end");
135 void RS_ActionModifyRound::mouseReleaseEvent(QMouseEvent * e)
137 Vector mouse = graphicView->toGraph(e->x(), e->y());
138 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
140 if (e->button() == Qt::LeftButton)
148 if (entity1 != NULL && entity1->isAtomic()
149 && RS_Information::isTrimmable(entity1))
150 setStatus(SetEntity2);
157 if (entity2 != NULL && entity2->isAtomic()
158 && RS_Information::isTrimmable(entity1, entity2))
159 //setStatus(ChooseRounding);
167 else if (e->button() == Qt::RightButton)
171 init(getStatus() - 1);
175 void RS_ActionModifyRound::commandEvent(RS_CommandEvent * e)
177 QString c = e->getCommand().toLower();
179 if (checkCommand("help", c))
181 if (RS_DIALOGFACTORY != NULL)
182 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
183 + getAvailableCommands().join(", "));
192 if (checkCommand("radius", c))
197 lastStatus = (Status)getStatus();
198 setStatus(SetRadius);
200 else if (checkCommand("trim", c))
205 lastStatus = (Status)getStatus();
208 data.trim = !data.trim;
210 if (RS_DIALOGFACTORY != NULL)
211 RS_DIALOGFACTORY->requestOptions(this, true, true);
217 double r = RS_Math::eval(c, &ok);
221 else if (RS_DIALOGFACTORY != NULL)
222 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
224 if (RS_DIALOGFACTORY != NULL)
225 RS_DIALOGFACTORY->requestOptions(this, true, true);
226 setStatus(lastStatus);
231 if (c==cmdYes.toLower() || c==cmdYes2) {
233 } else if (c==cmdNo.toLower() || c==cmdNo2) {
236 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
239 RS_DIALOGFACTORY->requestOptions(this, true, true);
240 setStatus(lastStatus);
249 QStringList RS_ActionModifyRound::getAvailableCommands()
257 cmd += command("radius");
258 cmd += command("trim");
267 void RS_ActionModifyRound::showOptions()
269 RS_ActionInterface::showOptions();
271 if (RS_DIALOGFACTORY != NULL)
272 RS_DIALOGFACTORY->requestOptions(this, true);
275 void RS_ActionModifyRound::hideOptions()
277 RS_ActionInterface::hideOptions();
279 if (RS_DIALOGFACTORY != NULL)
280 RS_DIALOGFACTORY->requestOptions(this, false);
283 void RS_ActionModifyRound::updateMouseButtonHints()
285 if (RS_DIALOGFACTORY != NULL)
290 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
295 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
300 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
305 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
309 RS_DIALOGFACTORY->updateMouseWidget("", "");
315 void RS_ActionModifyRound::updateMouseCursor()
317 graphicView->setMouseCursor(RS2::CadCursor);
320 void RS_ActionModifyRound::updateToolBar()
322 if (RS_DIALOGFACTORY != NULL)
323 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
326 void RS_ActionModifyRound::setRadius(double r)
331 double RS_ActionModifyRound::getRadius()
336 void RS_ActionModifyRound::setTrim(bool t)
341 bool RS_ActionModifyRound::isTrimOn()