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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "actionmodifyround.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_information.h"
20 #include "rs_preview.h"
22 ActionModifyRound::ActionModifyRound(RS_EntityContainer & container, GraphicView & graphicView):
23 ActionInterface("Round Entities", container, graphicView)
27 coord1 = Vector(false);
28 coord2 = Vector(false);
31 ActionModifyRound::~ActionModifyRound()
35 /*virtual*/ RS2::ActionType ActionModifyRound::rtti()
37 return RS2::ActionModifyRound;
40 void ActionModifyRound::init(int status)
42 ActionInterface::init(status);
44 /* snapMode = RS2::SnapFree;
45 snapRes = RS2::RestrictNothing;*/
48 void ActionModifyRound::trigger()
50 RS_DEBUG->print("ActionModifyRound::trigger()");
52 if (entity1 != NULL && entity1->isAtomic()
53 && entity2 != NULL && entity2->isAtomic())
57 RS_Modification m(*container, graphicView);
58 m.round(coord2, coord1, (RS_AtomicEntity *)entity1, coord2,
59 (RS_AtomicEntity *)entity2, data);
61 coord1 = Vector(false);
63 coord2 = Vector(false);
65 setStatus(SetEntity1);
69 if (RS_DIALOGFACTORY != NULL)
70 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
74 void ActionModifyRound::mouseMoveEvent(QMouseEvent * e)
76 RS_DEBUG->print("ActionModifyRound::mouseMoveEvent begin");
78 Vector mouse = graphicView->toGraph(e->x(), e->y());
79 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
92 if (entity1 != NULL && entity2 != NULL && entity2->isAtomic()
93 && RS_Information::isTrimmable(entity1, entity2))
97 /* RS_Entity * tmp1 = entity1->clone();
98 RS_Entity * tmp2 = entity2->clone();*/
99 // tmp1->reparent(preview);
100 // tmp2->reparent(preview);
101 // preview->addEntity(tmp1);
102 // preview->addEntity(tmp2);
104 /* bool trim = data.trim;
106 RS_Modification m(*preview, NULL, false);
107 m.round(coord2, coord1, (RS_AtomicEntity *)tmp1, coord2,
108 (RS_AtomicEntity *)tmp2, data);
111 preview->removeEntity(tmp1);
112 preview->removeEntity(tmp2);*/
121 RS_DEBUG->print("ActionModifyRound::mouseMoveEvent end");
124 void ActionModifyRound::mouseReleaseEvent(QMouseEvent * e)
126 Vector mouse = graphicView->toGraph(e->x(), e->y());
127 RS_Entity * se = catchEntity(e, RS2::ResolveAll);
129 if (e->button() == Qt::LeftButton)
137 if (entity1 != NULL && entity1->isAtomic()
138 && RS_Information::isTrimmable(entity1))
139 setStatus(SetEntity2);
146 if (entity2 != NULL && entity2->isAtomic()
147 && RS_Information::isTrimmable(entity1, entity2))
148 //setStatus(ChooseRounding);
156 else if (e->button() == Qt::RightButton)
160 init(getStatus() - 1);
164 void ActionModifyRound::commandEvent(RS_CommandEvent * e)
166 QString c = e->getCommand().toLower();
168 if (checkCommand("help", c))
170 if (RS_DIALOGFACTORY != NULL)
171 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
172 + getAvailableCommands().join(", "));
181 if (checkCommand("radius", c))
186 lastStatus = (Status)getStatus();
187 setStatus(SetRadius);
189 else if (checkCommand("trim", c))
194 lastStatus = (Status)getStatus();
197 data.trim = !data.trim;
199 if (RS_DIALOGFACTORY != NULL)
200 RS_DIALOGFACTORY->requestOptions(this, true, true);
206 double r = RS_Math::eval(c, &ok);
210 else if (RS_DIALOGFACTORY != NULL)
211 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
213 if (RS_DIALOGFACTORY != NULL)
214 RS_DIALOGFACTORY->requestOptions(this, true, true);
215 setStatus(lastStatus);
220 if (c==cmdYes.toLower() || c==cmdYes2) {
222 } else if (c==cmdNo.toLower() || c==cmdNo2) {
225 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
228 RS_DIALOGFACTORY->requestOptions(this, true, true);
229 setStatus(lastStatus);
238 QStringList ActionModifyRound::getAvailableCommands()
246 cmd += command("radius");
247 cmd += command("trim");
256 void ActionModifyRound::showOptions()
258 ActionInterface::showOptions();
260 if (RS_DIALOGFACTORY != NULL)
261 RS_DIALOGFACTORY->requestOptions(this, true);
264 void ActionModifyRound::hideOptions()
266 ActionInterface::hideOptions();
268 if (RS_DIALOGFACTORY != NULL)
269 RS_DIALOGFACTORY->requestOptions(this, false);
272 void ActionModifyRound::updateMouseButtonHints()
274 if (RS_DIALOGFACTORY != NULL)
279 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
284 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
289 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
294 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
298 RS_DIALOGFACTORY->updateMouseWidget("", "");
304 void ActionModifyRound::updateMouseCursor()
306 graphicView->setMouseCursor(RS2::CadCursor);
309 void ActionModifyRound::updateToolBar()
311 if (RS_DIALOGFACTORY != NULL)
312 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
315 void ActionModifyRound::setRadius(double r)
320 double ActionModifyRound::getRadius()
325 void ActionModifyRound::setTrim(bool t)
330 bool ActionModifyRound::isTrimOn()