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