1 // actionmodifydeletefree.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 "actionmodifydeletefree.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_modification.h"
22 #include "rs_polyline.h"
25 ActionModifyDeleteFree::ActionModifyDeleteFree(RS_EntityContainer & container,
26 GraphicView & graphicView):
27 ActionInterface("Delete Entities Freehand", container, graphicView)
31 ActionModifyDeleteFree::~ActionModifyDeleteFree()
35 void ActionModifyDeleteFree::init(int status)
37 ActionInterface::init(status);
40 v1 = v2 = Vector(false);
41 // setSnapMode(RS2::SnapOnEntity);
44 void ActionModifyDeleteFree::trigger()
48 RS_EntityContainer * parent = e2->getParent();
52 if (parent->rtti() == RS2::EntityPolyline)
54 if (parent->getId() == polyline->getId())
56 // deletes whole polyline on screen:
57 graphicView->deleteEntity((RS_Entity *)polyline);
59 // splits up the polyline in the container:
62 RS_Modification m(*container);
63 m.splitPolyline(*polyline, *e1, v1, *e2, v2, &pl1, &pl2);
67 document->startUndoCycle();
68 document->addUndoable(polyline);
69 document->addUndoable(pl1);
70 document->addUndoable(pl2);
71 document->endUndoCycle();
74 // draws the new polylines on the screen:
75 graphicView->drawEntity((RS_Entity *)pl1);
76 graphicView->drawEntity((RS_Entity *)pl2);
80 RS_DIALOGFACTORY->updateSelectionWidget(
81 container->countSelected());
84 RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
87 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
90 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL"));
93 RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL"));
96 void ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e)
98 if (e->button() == Qt::RightButton)
99 init(getStatus() - 1);
106 // e1 = getKeyEntity();
107 e1 = graphicView->snapper.getKeyEntity();
111 RS_EntityContainer * parent = e1->getParent();
115 if (parent->rtti() == RS2::EntityPolyline)
117 polyline = (RS_Polyline *)parent;
121 RS_DIALOGFACTORY->commandMessage(
122 tr("Parent of first entity is not a polyline"));
125 RS_DIALOGFACTORY->commandMessage(
126 tr("Parent of first entity is NULL"));
129 RS_DIALOGFACTORY->commandMessage(
130 tr("First entity is NULL"));
136 // e2 = getKeyEntity();
137 e2 = graphicView->snapper.getKeyEntity();
142 RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL"));
149 void ActionModifyDeleteFree::updateMouseButtonHints()
154 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point "
155 "on a polyline"), tr("Cancel"));
159 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point "
160 "on the same polyline"), tr("Back"));
164 RS_DIALOGFACTORY->updateMouseWidget("", "");