1 // 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 // 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 05/22/2010 Added this text. :-)
17 #include "actionmodifytrim.h"
19 #include "rs_dialogfactory.h"
20 #include "rs_modification.h"
23 * @param both Trim both entities.
25 ActionModifyTrim::ActionModifyTrim(RS_EntityContainer & container,
26 GraphicView & graphicView, bool both): ActionInterface("Trim Entity",
27 container, graphicView)
30 trimCoord = Vector(false);
32 limitCoord = Vector(false);
36 ActionModifyTrim::~ActionModifyTrim()
40 void ActionModifyTrim::init(int status)
42 ActionInterface::init(status);
44 /* snapMode = RS2::SnapFree;
45 snapRes = RS2::RestrictNothing;*/
48 void ActionModifyTrim::trigger()
50 RS_DEBUG->print("ActionModifyTrim::trigger()");
52 if (trimEntity && trimEntity->isAtomic() && limitEntity)
54 RS_Modification m(*container, graphicView);
55 m.trim(trimCoord, (RS_AtomicEntity *)trimEntity,
56 limitCoord, limitEntity, both);
62 limitEntity->setHighlighted(false);
63 graphicView->drawEntity(limitEntity);
64 setStatus(ChooseLimitEntity);
67 setStatus(ChooseTrimEntity);
69 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
73 void ActionModifyTrim::mouseMoveEvent(QMouseEvent * e)
75 RS_DEBUG->print("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("ActionModifyTrim::mouseMoveEvent end");
99 void 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:
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 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 ActionModifyTrim::updateMouseCursor()
178 graphicView->setMouseCursor(RS2::CadCursor);
181 void ActionModifyTrim::updateToolBar()
183 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);