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 "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "rs_information.h"
22 #include "rs_preview.h"
24 ActionModifyRound::ActionModifyRound(RS_EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Round Entities", container, graphicView)
29 coord1 = Vector(false);
30 coord2 = Vector(false);
33 ActionModifyRound::~ActionModifyRound()
37 /*virtual*/ RS2::ActionType ActionModifyRound::rtti()
39 return RS2::ActionModifyRound;
42 void ActionModifyRound::init(int status)
44 ActionInterface::init(status);
46 /* snapMode = RS2::SnapFree;
47 snapRes = RS2::RestrictNothing;*/
50 void ActionModifyRound::trigger()
52 RS_DEBUG->print("ActionModifyRound::trigger()");
54 if (entity1 != NULL && entity1->isAtomic()
55 && entity2 != NULL && entity2->isAtomic())
59 RS_Modification m(*container, graphicView);
60 m.round(coord2, coord1, (RS_AtomicEntity *)entity1, coord2,
61 (RS_AtomicEntity *)entity2, data);
63 coord1 = Vector(false);
65 coord2 = Vector(false);
67 setStatus(SetEntity1);
71 if (RS_DIALOGFACTORY != NULL)
72 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
76 void ActionModifyRound::mouseMoveEvent(QMouseEvent * e)
78 RS_DEBUG->print("ActionModifyRound::mouseMoveEvent begin");
80 Vector mouse = graphicView->toGraph(e->x(), e->y());
81 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
94 if (entity1 != NULL && entity2 != NULL && entity2->isAtomic()
95 && RS_Information::isTrimmable(entity1, entity2))
99 /* RS_Entity * tmp1 = entity1->clone();
100 RS_Entity * tmp2 = entity2->clone();*/
101 // tmp1->reparent(preview);
102 // tmp2->reparent(preview);
103 // preview->addEntity(tmp1);
104 // preview->addEntity(tmp2);
106 /* bool trim = data.trim;
108 RS_Modification m(*preview, NULL, false);
109 m.round(coord2, coord1, (RS_AtomicEntity *)tmp1, coord2,
110 (RS_AtomicEntity *)tmp2, data);
113 preview->removeEntity(tmp1);
114 preview->removeEntity(tmp2);*/
123 RS_DEBUG->print("ActionModifyRound::mouseMoveEvent end");
126 void ActionModifyRound::mouseReleaseEvent(QMouseEvent * e)
128 Vector mouse = graphicView->toGraph(e->x(), e->y());
129 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
131 if (e->button() == Qt::LeftButton)
139 if (entity1 != NULL && entity1->isAtomic()
140 && RS_Information::isTrimmable(entity1))
141 setStatus(SetEntity2);
148 if (entity2 != NULL && entity2->isAtomic()
149 && RS_Information::isTrimmable(entity1, entity2))
150 //setStatus(ChooseRounding);
158 else if (e->button() == Qt::RightButton)
162 init(getStatus() - 1);
166 void ActionModifyRound::commandEvent(RS_CommandEvent * e)
168 QString c = e->getCommand().toLower();
170 if (checkCommand("help", c))
172 if (RS_DIALOGFACTORY != NULL)
173 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
174 + getAvailableCommands().join(", "));
183 if (checkCommand("radius", c))
188 lastStatus = (Status)getStatus();
189 setStatus(SetRadius);
191 else if (checkCommand("trim", c))
196 lastStatus = (Status)getStatus();
199 data.trim = !data.trim;
201 if (RS_DIALOGFACTORY != NULL)
202 RS_DIALOGFACTORY->requestOptions(this, true, true);
208 double r = RS_Math::eval(c, &ok);
212 else if (RS_DIALOGFACTORY != NULL)
213 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
215 if (RS_DIALOGFACTORY != NULL)
216 RS_DIALOGFACTORY->requestOptions(this, true, true);
217 setStatus(lastStatus);
222 if (c==cmdYes.toLower() || c==cmdYes2) {
224 } else if (c==cmdNo.toLower() || c==cmdNo2) {
227 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
230 RS_DIALOGFACTORY->requestOptions(this, true, true);
231 setStatus(lastStatus);
240 QStringList ActionModifyRound::getAvailableCommands()
248 cmd += command("radius");
249 cmd += command("trim");
258 void ActionModifyRound::showOptions()
260 ActionInterface::showOptions();
262 if (RS_DIALOGFACTORY != NULL)
263 RS_DIALOGFACTORY->requestOptions(this, true);
266 void ActionModifyRound::hideOptions()
268 ActionInterface::hideOptions();
270 if (RS_DIALOGFACTORY != NULL)
271 RS_DIALOGFACTORY->requestOptions(this, false);
274 void ActionModifyRound::updateMouseButtonHints()
276 if (RS_DIALOGFACTORY != NULL)
281 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
286 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
291 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
296 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
300 RS_DIALOGFACTORY->updateMouseWidget("", "");
306 void ActionModifyRound::updateMouseCursor()
308 graphicView->setMouseCursor(RS2::CadCursor);
311 void ActionModifyRound::updateToolBar()
313 if (RS_DIALOGFACTORY != NULL)
314 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
317 void ActionModifyRound::setRadius(double r)
322 double ActionModifyRound::getRadius()
327 void ActionModifyRound::setTrim(bool t)
332 bool ActionModifyRound::isTrimOn()