1 // rs_actionmodifytrim.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 05/22/2010 Added this text. :-)
15 #include "rs_actionmodifytrim.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_modification.h"
21 * @param both Trim both entities.
23 RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer & container,
24 GraphicView & graphicView, bool both): RS_PreviewActionInterface("Trim Entity",
25 container, graphicView)
28 trimCoord = Vector(false);
30 limitCoord = Vector(false);
34 RS_ActionModifyTrim::~RS_ActionModifyTrim()
38 void RS_ActionModifyTrim::init(int status)
40 RS_ActionInterface::init(status);
42 snapMode = RS2::SnapFree;
43 snapRes = RS2::RestrictNothing;
46 void RS_ActionModifyTrim::trigger()
48 RS_DEBUG->print("RS_ActionModifyTrim::trigger()");
50 if (trimEntity != NULL && trimEntity->isAtomic()
51 && limitEntity != NULL /* && limitEntity->isAtomic()*/)
53 RS_Modification m(*container, graphicView);
54 m.trim(trimCoord, (RS_AtomicEntity *)trimEntity,
55 limitCoord, /*(RS_AtomicEntity*)*/ limitEntity,
62 limitEntity->setHighlighted(false);
63 graphicView->drawEntity(limitEntity);
64 setStatus(ChooseLimitEntity);
67 setStatus(ChooseTrimEntity);
69 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
73 void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent * e)
75 RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin");
77 Vector mouse = graphicView->toGraph(e->x(), e->y());
78 RS_Entity * se = catchEntity(e);
82 case ChooseLimitEntity:
87 case ChooseTrimEntity:
96 RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
99 void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
101 if (e->button() == Qt::LeftButton)
103 Vector mouse = graphicView->toGraph(e->x(), e->y());
104 RS_Entity * se = catchEntity(e);
108 case ChooseLimitEntity:
112 if (limitEntity != NULL /*&& limitEntity->isAtomic()*/)
114 limitEntity->setHighlighted(true);
115 graphicView->drawEntity(limitEntity);
116 setStatus(ChooseTrimEntity);
120 case ChooseTrimEntity:
124 if (trimEntity != NULL && trimEntity->isAtomic())
132 else if (e->button() == Qt::RightButton)
137 if (limitEntity != NULL)
139 limitEntity->setHighlighted(false);
140 graphicView->drawEntity(limitEntity);
142 init(getStatus() - 1);
146 void RS_ActionModifyTrim::updateMouseButtonHints()
150 case ChooseLimitEntity:
153 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"),
156 RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"),
160 case ChooseTrimEntity:
163 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"),
166 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"),
171 RS_DIALOGFACTORY->updateMouseWidget("", "");
176 void RS_ActionModifyTrim::updateMouseCursor()
178 graphicView->setMouseCursor(RS2::CadCursor);
181 void RS_ActionModifyTrim::updateToolBar()
183 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);