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 "actionmodifycut.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "modification.h"
24 ActionModifyCut::ActionModifyCut(EntityContainer & container,
25 GraphicView & graphicView): ActionInterface("Cut Entity",
26 container, graphicView)
29 cutCoord = Vector(false);
32 ActionModifyCut::~ActionModifyCut()
36 void ActionModifyCut::init(int status)
38 ActionInterface::init(status);
41 void ActionModifyCut::trigger()
43 DEBUG->print("ActionModifyCut::trigger()");
45 if (cutEntity != NULL && cutEntity->isAtomic() && cutCoord.valid
46 && cutEntity->isPointOnEntity(cutCoord))
48 cutEntity->setHighlighted(false);
49 graphicView->drawEntity(cutEntity);
51 Modification m(*container, graphicView);
52 m.cut(cutCoord, (AtomicEntity *)cutEntity);
55 cutCoord = Vector(false);
56 setStatus(ChooseCutEntity);
58 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
62 void ActionModifyCut::mouseMoveEvent(QMouseEvent * e)
64 DEBUG->print("ActionModifyCut::mouseMoveEvent begin");
79 DEBUG->print("ActionModifyTrim::mouseMoveEvent end");
82 void ActionModifyCut::mouseReleaseEvent(QMouseEvent * e)
84 if (e->button() == Qt::LeftButton)
89 cutEntity = catchEntity(e);
91 if (cutEntity == NULL)
92 DIALOGFACTORY->commandMessage(tr("No Entity found."));
93 else if (cutEntity->rtti() != RS2::EntityLine
94 && cutEntity->rtti() != RS2::EntityArc
95 && cutEntity->rtti() != RS2::EntityCircle
96 && cutEntity->rtti() != RS2::EntityEllipse)
98 DIALOGFACTORY->commandMessage(
99 tr("Entity must be a line, arc, circle or ellipse."));
102 cutEntity->setHighlighted(true);
103 graphicView->drawEntity(cutEntity);
104 setStatus(SetCutCoord);
109 cutCoord = snapPoint(e);
111 if (cutEntity == NULL)
112 DIALOGFACTORY->commandMessage(tr("No Entity found."));
113 else if (!cutCoord.valid)
114 DIALOGFACTORY->commandMessage(tr("Cutting point is invalid."));
115 else if (!cutEntity->isPointOnEntity(cutCoord))
116 DIALOGFACTORY->commandMessage(
117 tr("Cutting point is not on entity."));
129 else if (e->button() == Qt::RightButton)
133 if (cutEntity != NULL)
135 cutEntity->setHighlighted(false);
136 graphicView->drawEntity(cutEntity);
138 init(getStatus() - 1);
142 void ActionModifyCut::updateMouseButtonHints()
146 case ChooseCutEntity:
147 DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"),
152 DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"),
157 DIALOGFACTORY->updateMouseWidget("", "");
162 void ActionModifyCut::updateMouseCursor()
164 graphicView->setMouseCursor(RS2::CadCursor);
167 void ActionModifyCut::updateToolBar()
172 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
175 case ChooseCutEntity:
177 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);