]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifydeletefree.cpp
8d2275c79dc85738c013746d8290655f1b398303
[architektonas] / src / actions / rs_actionmodifydeletefree.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifydeletefree.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
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.
12 **
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.
16 **
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.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifydeletefree.h"
28
29 #include "rs_point.h"
30 #include "rs_polyline.h"
31 #include "rs_modification.h"
32
33
34
35 RS_ActionModifyDeleteFree::RS_ActionModifyDeleteFree(
36     RS_EntityContainer& container,
37     RS_GraphicView& graphicView)
38         :RS_ActionInterface("Delete Entities Freehand",
39                     container, graphicView) {}
40
41 QAction* RS_ActionModifyDeleteFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
42 {
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"));
47         return action;
48 }
49
50
51 void RS_ActionModifyDeleteFree::init(int status) {
52     RS_ActionInterface::init(status);
53     polyline = NULL;
54     e1 = e2 = NULL;
55     v1 = v2 = Vector(false);
56     setSnapMode(RS2::SnapOnEntity);
57 }
58
59
60
61 void RS_ActionModifyDeleteFree::trigger() {
62     if (e1!=NULL && e2!=NULL) {
63         RS_EntityContainer* parent = e2->getParent();
64         if (parent!=NULL) {
65             if (parent->rtti()==RS2::EntityPolyline) {
66                 if(parent->getId() == polyline->getId()) {
67
68                     // deletes whole polyline on screen:
69                     graphicView->deleteEntity((RS_Entity*)polyline);
70
71                     // splits up the polyline in the container:
72                     RS_Polyline* pl1;
73                     RS_Polyline* pl2;
74                     RS_Modification m(*container);
75                     m.splitPolyline(*polyline,
76                                     *e1, v1,
77                                     *e2, v2,
78                                     &pl1, &pl2);
79
80                     if (document) {
81                         document->startUndoCycle();
82                         document->addUndoable(polyline);
83                         document->addUndoable(pl1);
84                         document->addUndoable(pl2);
85                         document->endUndoCycle();
86                     }
87
88                     // draws the new polylines on the screen:
89                     graphicView->drawEntity((RS_Entity*)pl1);
90                     graphicView->drawEntity((RS_Entity*)pl2);
91
92                     init();
93
94                     RS_DIALOGFACTORY->updateSelectionWidget(
95                         container->countSelected());
96                 } else {
97                                 RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
98                 }
99             } else {
100                         RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
101             }
102         } else {
103                 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL"));
104         }
105     } else {
106         RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL"));
107     }
108 }
109
110
111
112 void RS_ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent* e) {
113     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
114         init(getStatus()-1);
115     } else {
116
117         switch (getStatus()) {
118         case 0: {
119                 v1 = snapPoint(e);
120                 e1 = getKeyEntity();
121                 if (e1!=NULL) {
122                     RS_EntityContainer* parent = e1->getParent();
123                     if (parent!=NULL) {
124                         if (parent->rtti()==RS2::EntityPolyline) {
125                             polyline = (RS_Polyline*)parent;
126                             setStatus(1);
127                         } else {
128                                                 RS_DIALOGFACTORY->commandMessage(
129                                                                 tr("Parent of first entity is not a polyline"));
130                         }
131                     } else {
132                                         RS_DIALOGFACTORY->commandMessage(
133                                                         tr("Parent of first entity is NULL"));
134                     }
135                 } else {
136                                 RS_DIALOGFACTORY->commandMessage(
137                                                 tr("First entity is NULL"));
138                 }
139             }
140             break;
141
142         case 1: {
143                 v2 = snapPoint(e);
144                 e2 = getKeyEntity();
145
146                 if (e2!=NULL) {
147                     trigger();
148                 } else {
149                                 RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL"));
150                 }
151             }
152             break;
153         }
154     }
155 }
156
157
158
159 void RS_ActionModifyDeleteFree::updateMouseButtonHints() {
160     switch (getStatus()) {
161     case 0:
162         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point "
163                                                "on a polyline"), tr("Cancel"));
164         break;
165     case 1:
166         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point "
167                                                "on the same polyline"),
168                                             tr("Back"));
169         break;
170     default:
171         RS_DIALOGFACTORY->updateMouseWidget("", "");
172         break;
173     }
174 }
175
176 // EOF