1 // 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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actionmodifyround.h"
19 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "information.h"
25 ActionModifyRound::ActionModifyRound(EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Round Entities", container, graphicView)
30 coord1 = Vector(false);
31 coord2 = Vector(false);
34 ActionModifyRound::~ActionModifyRound()
38 /*virtual*/ RS2::ActionType ActionModifyRound::rtti()
40 return RS2::ActionModifyRound;
43 void ActionModifyRound::init(int status)
45 ActionInterface::init(status);
47 /* snapMode = RS2::SnapFree;
48 snapRes = RS2::RestrictNothing;*/
51 void ActionModifyRound::trigger()
53 DEBUG->print("ActionModifyRound::trigger()");
55 if (entity1 != NULL && entity1->isAtomic()
56 && entity2 != NULL && entity2->isAtomic())
60 Modification m(*container, graphicView);
61 m.round(coord2, coord1, (AtomicEntity *)entity1, coord2,
62 (AtomicEntity *)entity2, data);
64 coord1 = Vector(false);
66 coord2 = Vector(false);
68 setStatus(SetEntity1);
72 if (DIALOGFACTORY != NULL)
73 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
77 void ActionModifyRound::mouseMoveEvent(QMouseEvent * e)
79 DEBUG->print("ActionModifyRound::mouseMoveEvent begin");
81 Vector mouse = graphicView->toGraph(e->x(), e->y());
82 Entity * se = catchEntity(e, RS2::ResolveAll);
95 if (entity1 != NULL && entity2 != NULL && entity2->isAtomic()
96 && Information::isTrimmable(entity1, entity2))
100 /* Entity * tmp1 = entity1->clone();
101 Entity * tmp2 = entity2->clone();*/
102 // tmp1->reparent(preview);
103 // tmp2->reparent(preview);
104 // preview->addEntity(tmp1);
105 // preview->addEntity(tmp2);
107 /* bool trim = data.trim;
109 Modification m(*preview, NULL, false);
110 m.round(coord2, coord1, (AtomicEntity *)tmp1, coord2,
111 (AtomicEntity *)tmp2, data);
114 preview->removeEntity(tmp1);
115 preview->removeEntity(tmp2);*/
124 DEBUG->print("ActionModifyRound::mouseMoveEvent end");
127 void ActionModifyRound::mouseReleaseEvent(QMouseEvent * e)
129 Vector mouse = graphicView->toGraph(e->x(), e->y());
130 Entity * se = catchEntity(e, RS2::ResolveAll);
132 if (e->button() == Qt::LeftButton)
140 if (entity1 != NULL && entity1->isAtomic()
141 && Information::isTrimmable(entity1))
142 setStatus(SetEntity2);
149 if (entity2 != NULL && entity2->isAtomic()
150 && Information::isTrimmable(entity1, entity2))
151 //setStatus(ChooseRounding);
159 else if (e->button() == Qt::RightButton)
163 init(getStatus() - 1);
167 void ActionModifyRound::commandEvent(CommandEvent * e)
169 QString c = e->getCommand().toLower();
171 if (checkCommand("help", c))
173 if (DIALOGFACTORY != NULL)
174 DIALOGFACTORY->commandMessage(msgAvailableCommands()
175 + getAvailableCommands().join(", "));
184 if (checkCommand("radius", c))
189 lastStatus = (Status)getStatus();
190 setStatus(SetRadius);
192 else if (checkCommand("trim", c))
197 lastStatus = (Status)getStatus();
200 data.trim = !data.trim;
202 if (DIALOGFACTORY != NULL)
203 DIALOGFACTORY->requestOptions(this, true, true);
209 double r = Math::eval(c, &ok);
213 else if (DIALOGFACTORY != NULL)
214 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
216 if (DIALOGFACTORY != NULL)
217 DIALOGFACTORY->requestOptions(this, true, true);
218 setStatus(lastStatus);
223 if (c==cmdYes.toLower() || c==cmdYes2) {
225 } else if (c==cmdNo.toLower() || c==cmdNo2) {
228 DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
231 DIALOGFACTORY->requestOptions(this, true, true);
232 setStatus(lastStatus);
241 QStringList ActionModifyRound::getAvailableCommands()
249 cmd += command("radius");
250 cmd += command("trim");
259 void ActionModifyRound::showOptions()
261 ActionInterface::showOptions();
263 if (DIALOGFACTORY != NULL)
264 DIALOGFACTORY->requestOptions(this, true);
267 void ActionModifyRound::hideOptions()
269 ActionInterface::hideOptions();
271 if (DIALOGFACTORY != NULL)
272 DIALOGFACTORY->requestOptions(this, false);
275 void ActionModifyRound::updateMouseButtonHints()
277 if (DIALOGFACTORY != NULL)
282 DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
287 DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
292 DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
297 DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
301 DIALOGFACTORY->updateMouseWidget("", "");
307 void ActionModifyRound::updateMouseCursor()
309 graphicView->setMouseCursor(RS2::CadCursor);
312 void ActionModifyRound::updateToolBar()
314 if (DIALOGFACTORY != NULL)
315 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
318 void ActionModifyRound::setRadius(double r)
323 double ActionModifyRound::getRadius()
328 void ActionModifyRound::setTrim(bool t)
333 bool ActionModifyRound::isTrimOn()