]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifycut.cpp
000c75a675cce393242544569d0726e649b9f085
[architektonas] / src / actions / actionmodifycut.cpp
1 // actionmodifycut.cpp
2 //
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
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/04/2010  Added this text. :-)
15 //
16
17 #include "actionmodifycut.h"
18
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_modification.h"
22
23 ActionModifyCut::ActionModifyCut(RS_EntityContainer & container,
24         GraphicView & graphicView): ActionInterface("Cut Entity",
25                 container, graphicView)
26 {
27         cutEntity = NULL;
28         cutCoord = Vector(false);
29 }
30
31 ActionModifyCut::~ActionModifyCut()
32 {
33 }
34
35 void ActionModifyCut::init(int status)
36 {
37         ActionInterface::init(status);
38 }
39
40 void ActionModifyCut::trigger()
41 {
42         RS_DEBUG->print("ActionModifyCut::trigger()");
43
44         if (cutEntity != NULL && cutEntity->isAtomic() && cutCoord.valid
45             && cutEntity->isPointOnEntity(cutCoord))
46         {
47                 cutEntity->setHighlighted(false);
48                 graphicView->drawEntity(cutEntity);
49
50                 RS_Modification m(*container, graphicView);
51                 m.cut(cutCoord, (RS_AtomicEntity *)cutEntity);
52
53                 cutEntity = NULL;
54                 cutCoord = Vector(false);
55                 setStatus(ChooseCutEntity);
56
57                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
58         }
59 }
60
61 void ActionModifyCut::mouseMoveEvent(QMouseEvent * e)
62 {
63         RS_DEBUG->print("ActionModifyCut::mouseMoveEvent begin");
64
65         switch (getStatus())
66         {
67         case ChooseCutEntity:
68                 break;
69
70         case SetCutCoord:
71                 snapPoint(e);
72                 break;
73
74         default:
75                 break;
76         }
77
78         RS_DEBUG->print("ActionModifyTrim::mouseMoveEvent end");
79 }
80
81 void ActionModifyCut::mouseReleaseEvent(QMouseEvent * e)
82 {
83         if (e->button() == Qt::LeftButton)
84         {
85                 switch (getStatus())
86                 {
87                 case ChooseCutEntity:
88                         cutEntity = catchEntity(e);
89
90                         if (cutEntity == NULL)
91                                 RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
92                         else if (cutEntity->rtti() != RS2::EntityLine
93                                 && cutEntity->rtti() != RS2::EntityArc
94                                 && cutEntity->rtti() != RS2::EntityCircle
95                                 && cutEntity->rtti() != RS2::EntityEllipse)
96
97                                 RS_DIALOGFACTORY->commandMessage(
98                                         tr("Entity must be a line, arc, circle or ellipse."));
99                         else
100                         {
101                                 cutEntity->setHighlighted(true);
102                                 graphicView->drawEntity(cutEntity);
103                                 setStatus(SetCutCoord);
104                         }
105                         break;
106
107                 case SetCutCoord:
108                         cutCoord = snapPoint(e);
109
110                         if (cutEntity == NULL)
111                                 RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
112                         else if (!cutCoord.valid)
113                                 RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid."));
114                         else if (!cutEntity->isPointOnEntity(cutCoord))
115                                 RS_DIALOGFACTORY->commandMessage(
116                                         tr("Cutting point is not on entity."));
117                         else
118                         {
119                                 deleteSnapper();
120                                 trigger();
121                         }
122                         break;
123
124                 default:
125                         break;
126                 }
127         }
128         else if (e->button() == Qt::RightButton)
129         {
130                 deleteSnapper();
131
132                 if (cutEntity != NULL)
133                 {
134                         cutEntity->setHighlighted(false);
135                         graphicView->drawEntity(cutEntity);
136                 }
137                 init(getStatus() - 1);
138         }
139 }
140
141 void ActionModifyCut::updateMouseButtonHints()
142 {
143         switch (getStatus())
144         {
145         case ChooseCutEntity:
146                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"),
147                         tr("Cancel"));
148                 break;
149
150         case SetCutCoord:
151                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"),
152                         tr("Back"));
153                 break;
154
155         default:
156                 RS_DIALOGFACTORY->updateMouseWidget("", "");
157                 break;
158         }
159 }
160
161 void ActionModifyCut::updateMouseCursor()
162 {
163         graphicView->setMouseCursor(RS2::CadCursor);
164 }
165
166 void ActionModifyCut::updateToolBar()
167 {
168         switch (getStatus())
169         {
170         case SetCutCoord:
171                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
172                 break;
173
174         case ChooseCutEntity:
175         default:
176                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
177                 break;
178         }
179 }