1 /****************************************************************************
2 ** $Id: rs_actionmodifydeletefree.cpp 1161 2004-12-09 23:10:09Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionmodifydeletefree.h"
30 #include "rs_polyline.h"
31 #include "rs_modification.h"
35 RS_ActionModifyDeleteFree::RS_ActionModifyDeleteFree(
36 RS_EntityContainer& container,
37 RS_GraphicView& graphicView)
38 :RS_ActionInterface("Delete Entities Freehand",
39 container, graphicView) {}
41 QAction* RS_ActionModifyDeleteFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
43 QAction * action = new QAction(tr("&Delete Freehand"), 0);
44 // QAction* action = new QAction(tr("Delete Freehand"), tr("&Delete Freehand"),
45 // QKeySequence(), NULL);
46 action->setStatusTip(tr("Delete Freehand"));
51 void RS_ActionModifyDeleteFree::init(int status) {
52 RS_ActionInterface::init(status);
55 v1 = v2 = Vector(false);
56 setSnapMode(RS2::SnapOnEntity);
61 void RS_ActionModifyDeleteFree::trigger() {
62 if (e1!=NULL && e2!=NULL) {
63 RS_EntityContainer* parent = e2->getParent();
65 if (parent->rtti()==RS2::EntityPolyline) {
66 if(parent->getId() == polyline->getId()) {
68 // deletes whole polyline on screen:
69 graphicView->deleteEntity((RS_Entity*)polyline);
71 // splits up the polyline in the container:
74 RS_Modification m(*container);
75 m.splitPolyline(*polyline,
81 document->startUndoCycle();
82 document->addUndoable(polyline);
83 document->addUndoable(pl1);
84 document->addUndoable(pl2);
85 document->endUndoCycle();
88 // draws the new polylines on the screen:
89 graphicView->drawEntity((RS_Entity*)pl1);
90 graphicView->drawEntity((RS_Entity*)pl2);
94 RS_DIALOGFACTORY->updateSelectionWidget(
95 container->countSelected());
97 RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
100 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
103 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL"));
106 RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL"));
112 void RS_ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent* e) {
113 if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
117 switch (getStatus()) {
122 RS_EntityContainer* parent = e1->getParent();
124 if (parent->rtti()==RS2::EntityPolyline) {
125 polyline = (RS_Polyline*)parent;
128 RS_DIALOGFACTORY->commandMessage(
129 tr("Parent of first entity is not a polyline"));
132 RS_DIALOGFACTORY->commandMessage(
133 tr("Parent of first entity is NULL"));
136 RS_DIALOGFACTORY->commandMessage(
137 tr("First entity is NULL"));
149 RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL"));
159 void RS_ActionModifyDeleteFree::updateMouseButtonHints() {
160 switch (getStatus()) {
162 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point "
163 "on a polyline"), tr("Cancel"));
166 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point "
167 "on the same polyline"),
171 RS_DIALOGFACTORY->updateMouseWidget("", "");