]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifycut.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifycut.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifycut.cpp 2420 2005-07-01 16:47:35Z 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_actionmodifycut.h"
28
29 #include "rs_snapper.h"
30
31
32 RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer& container,
33                                        RS_GraphicView& graphicView)
34         :RS_ActionInterface("Cut Entity",
35                     container, graphicView) {
36
37     cutEntity = NULL;
38     cutCoord = Vector(false);
39 }
40
41 QAction* RS_ActionModifyCut::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
42 {
43         QAction * action = new QAction(tr("&Divide"), 0);
44 //      QAction* action = new QAction(tr("Divide"), tr("&Divide"),
45 //                                                                      QKeySequence(), NULL);
46         action->setStatusTip(tr("Cut Entities"));
47         return action;
48 }
49
50
51 void RS_ActionModifyCut::init(int status)
52 {
53     RS_ActionInterface::init(status);
54 }
55
56
57
58 void RS_ActionModifyCut::trigger() {
59
60     RS_DEBUG->print("RS_ActionModifyCut::trigger()");
61
62     if (cutEntity!=NULL && cutEntity->isAtomic() && cutCoord.valid &&
63             cutEntity->isPointOnEntity(cutCoord)) {
64
65         cutEntity->setHighlighted(false);
66         graphicView->drawEntity(cutEntity);
67
68         RS_Modification m(*container, graphicView);
69         m.cut(cutCoord, (RS_AtomicEntity*)cutEntity);
70
71         cutEntity = NULL;
72         cutCoord = Vector(false);
73         setStatus(ChooseCutEntity);
74
75         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
76     }
77 }
78
79
80
81 void RS_ActionModifyCut::mouseMoveEvent(QMouseEvent* e) {
82     RS_DEBUG->print("RS_ActionModifyCut::mouseMoveEvent begin");
83
84     switch (getStatus()) {
85     case ChooseCutEntity:
86         break;
87
88     case SetCutCoord:
89         snapPoint(e);
90         break;
91
92     default:
93         break;
94     }
95
96     RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
97 }
98
99
100 void RS_ActionModifyCut::mouseReleaseEvent(QMouseEvent* e) {
101     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
102         switch (getStatus()) {
103         case ChooseCutEntity:
104             cutEntity = catchEntity(e);
105             if (cutEntity==NULL) {
106                 RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
107             } else if (cutEntity->rtti()!=RS2::EntityLine &&
108                        cutEntity->rtti()!=RS2::EntityArc &&
109                        cutEntity->rtti()!=RS2::EntityCircle &&
110                        cutEntity->rtti()!=RS2::EntityEllipse) {
111
112                 RS_DIALOGFACTORY->commandMessage(
113                     tr("Entity must be a line, arc, circle or ellipse."));
114             } else {
115                 cutEntity->setHighlighted(true);
116                 graphicView->drawEntity(cutEntity);
117                 setStatus(SetCutCoord);
118             }
119             break;
120
121         case SetCutCoord:
122             cutCoord = snapPoint(e);
123             if (cutEntity==NULL) {
124                 RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
125             } else if (!cutCoord.valid) {
126                 RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid."));
127             } else if (!cutEntity->isPointOnEntity(cutCoord)) {
128                 RS_DIALOGFACTORY->commandMessage(
129                     tr("Cutting point is not on entity."));
130             } else {
131                 deleteSnapper();
132                 trigger();
133             }
134             break;
135
136         default:
137             break;
138         }
139     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
140         deleteSnapper();
141         if (cutEntity!=NULL) {
142             cutEntity->setHighlighted(false);
143             graphicView->drawEntity(cutEntity);
144         }
145         init(getStatus()-1);
146     }
147 }
148
149
150
151 void RS_ActionModifyCut::updateMouseButtonHints() {
152     switch (getStatus()) {
153     case ChooseCutEntity:
154         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"),
155                                             tr("Cancel"));
156         break;
157     case SetCutCoord:
158         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"),
159                                             tr("Back"));
160         break;
161     default:
162         RS_DIALOGFACTORY->updateMouseWidget("", "");
163         break;
164     }
165 }
166
167
168
169 void RS_ActionModifyCut::updateMouseCursor() {
170     graphicView->setMouseCursor(RS2::CadCursor);
171 }
172
173
174
175 void RS_ActionModifyCut::updateToolBar() {
176
177     switch (getStatus()) {
178     case SetCutCoord:
179         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
180         break;
181     case ChooseCutEntity:
182     default:
183         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
184         break;
185     }
186 }
187
188
189 // EOF