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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "actionmodifydeletefree.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_modification.h"
20 #include "rs_polyline.h"
23 ActionModifyDeleteFree::ActionModifyDeleteFree(RS_EntityContainer & container,
24 GraphicView & graphicView):
25 ActionInterface("Delete Entities Freehand", container, graphicView)
29 ActionModifyDeleteFree::~ActionModifyDeleteFree()
33 void ActionModifyDeleteFree::init(int status)
35 ActionInterface::init(status);
38 v1 = v2 = Vector(false);
39 // setSnapMode(RS2::SnapOnEntity);
42 void ActionModifyDeleteFree::trigger()
46 RS_EntityContainer * parent = e2->getParent();
50 if (parent->rtti() == RS2::EntityPolyline)
52 if (parent->getId() == polyline->getId())
54 // deletes whole polyline on screen:
55 graphicView->deleteEntity((RS_Entity *)polyline);
57 // splits up the polyline in the container:
60 RS_Modification m(*container);
61 m.splitPolyline(*polyline, *e1, v1, *e2, v2, &pl1, &pl2);
65 document->startUndoCycle();
66 document->addUndoable(polyline);
67 document->addUndoable(pl1);
68 document->addUndoable(pl2);
69 document->endUndoCycle();
72 // draws the new polylines on the screen:
73 graphicView->drawEntity((RS_Entity *)pl1);
74 graphicView->drawEntity((RS_Entity *)pl2);
78 RS_DIALOGFACTORY->updateSelectionWidget(
79 container->countSelected());
82 RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
85 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
88 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL"));
91 RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL"));
94 void ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e)
96 if (e->button() == Qt::RightButton)
97 init(getStatus() - 1);
104 // e1 = getKeyEntity();
105 e1 = graphicView->snapper.getKeyEntity();
109 RS_EntityContainer * parent = e1->getParent();
113 if (parent->rtti() == RS2::EntityPolyline)
115 polyline = (RS_Polyline *)parent;
119 RS_DIALOGFACTORY->commandMessage(
120 tr("Parent of first entity is not a polyline"));
123 RS_DIALOGFACTORY->commandMessage(
124 tr("Parent of first entity is NULL"));
127 RS_DIALOGFACTORY->commandMessage(
128 tr("First entity is NULL"));
134 // e2 = getKeyEntity();
135 e2 = graphicView->snapper.getKeyEntity();
140 RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL"));
147 void ActionModifyDeleteFree::updateMouseButtonHints()
152 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point "
153 "on a polyline"), tr("Cancel"));
157 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point "
158 "on the same polyline"), tr("Back"));
162 RS_DIALOGFACTORY->updateMouseWidget("", "");