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