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