]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifytrim.cpp
Refactoring: Moved RS_GraphicView to GraphicView.
[architektonas] / src / actions / rs_actionmodifytrim.cpp
1 // rs_actionmodifytrim.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  05/22/2010  Added this text. :-)
13 //
14
15 #include "rs_actionmodifytrim.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_modification.h"
19
20 /**
21  * @param both Trim both entities.
22  */
23 RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer & container,
24         GraphicView & graphicView, bool both): RS_PreviewActionInterface("Trim Entity",
25                 container, graphicView)
26 {
27         trimEntity = NULL;
28         trimCoord = Vector(false);
29         limitEntity = NULL;
30         limitCoord = Vector(false);
31         this->both = both;
32 }
33
34 RS_ActionModifyTrim::~RS_ActionModifyTrim()
35 {
36 }
37
38 void RS_ActionModifyTrim::init(int status)
39 {
40         RS_ActionInterface::init(status);
41
42         snapMode = RS2::SnapFree;
43         snapRes = RS2::RestrictNothing;
44 }
45
46 void RS_ActionModifyTrim::trigger()
47 {
48         RS_DEBUG->print("RS_ActionModifyTrim::trigger()");
49
50         if (trimEntity != NULL && trimEntity->isAtomic()
51             && limitEntity != NULL /* && limitEntity->isAtomic()*/)
52         {
53                 RS_Modification m(*container, graphicView);
54                 m.trim(trimCoord, (RS_AtomicEntity *)trimEntity,
55                         limitCoord, /*(RS_AtomicEntity*)*/ limitEntity,
56                         both);
57
58                 trimEntity = NULL;
59
60                 if (both)
61                 {
62                         limitEntity->setHighlighted(false);
63                         graphicView->drawEntity(limitEntity);
64                         setStatus(ChooseLimitEntity);
65                 }
66                 else
67                         setStatus(ChooseTrimEntity);
68
69                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
70         }
71 }
72
73 void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent * e)
74 {
75         RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin");
76
77         Vector mouse = graphicView->toGraph(e->x(), e->y());
78         RS_Entity * se = catchEntity(e);
79
80         switch (getStatus())
81         {
82         case ChooseLimitEntity:
83                 limitCoord = mouse;
84                 limitEntity = se;
85                 break;
86
87         case ChooseTrimEntity:
88                 trimCoord = mouse;
89                 trimEntity = se;
90                 break;
91
92         default:
93                 break;
94         }
95
96         RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
97 }
98
99 void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
100 {
101         if (e->button() == Qt::LeftButton)
102         {
103                 Vector mouse = graphicView->toGraph(e->x(), e->y());
104                 RS_Entity * se = catchEntity(e);
105
106                 switch (getStatus())
107                 {
108                 case ChooseLimitEntity:
109                         limitCoord = mouse;
110                         limitEntity = se;
111
112                         if (limitEntity != NULL /*&& limitEntity->isAtomic()*/)
113                         {
114                                 limitEntity->setHighlighted(true);
115                                 graphicView->drawEntity(limitEntity);
116                                 setStatus(ChooseTrimEntity);
117                         }
118                         break;
119
120                 case ChooseTrimEntity:
121                         trimCoord = mouse;
122                         trimEntity = se;
123
124                         if (trimEntity != NULL && trimEntity->isAtomic())
125                                 trigger();
126                         break;
127
128                 default:
129                         break;
130                 }
131         }
132         else if (e->button() == Qt::RightButton)
133         {
134                 deletePreview();
135                 deleteSnapper();
136
137                 if (limitEntity != NULL)
138                 {
139                         limitEntity->setHighlighted(false);
140                         graphicView->drawEntity(limitEntity);
141                 }
142                 init(getStatus() - 1);
143         }
144 }
145
146 void RS_ActionModifyTrim::updateMouseButtonHints()
147 {
148         switch (getStatus())
149         {
150         case ChooseLimitEntity:
151
152                 if (both)
153                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"),
154                                 tr("Cancel"));
155                 else
156                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"),
157                                 tr("Back"));
158                 break;
159
160         case ChooseTrimEntity:
161
162                 if (both)
163                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"),
164                                 tr("Cancel"));
165                 else
166                         RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"),
167                                 tr("Back"));
168                 break;
169
170         default:
171                 RS_DIALOGFACTORY->updateMouseWidget("", "");
172                 break;
173         }
174 }
175
176 void RS_ActionModifyTrim::updateMouseCursor()
177 {
178         graphicView->setMouseCursor(RS2::CadCursor);
179 }
180
181 void RS_ActionModifyTrim::updateToolBar()
182 {
183         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
184 }
185