]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifytrimamount.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifytrimamount.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifytrimamount.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifytrimamount.h"
28
29 #include "rs_snapper.h"
30
31 RS_ActionModifyTrimAmount::RS_ActionModifyTrimAmount(
32     RS_EntityContainer& container,
33     RS_GraphicView& graphicView)
34         :RS_ActionInterface("Trim Entity by a given amount",
35                     container, graphicView) {
36
37     trimEntity = NULL;
38     trimCoord = Vector(false);
39     distance = 0.0;
40 }
41
42 QAction* RS_ActionModifyTrimAmount::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
43 {
44         QAction * action = new QAction(tr("&Lengthen"), 0);
45 //      QAction* action = new QAction(tr("Lengthen"), tr("&Lengthen"),
46 //                                                      QKeySequence(), NULL);
47         action->setStatusTip(tr("Lengthen by a given amount"));
48         return action;
49 }
50
51 void RS_ActionModifyTrimAmount::init(int status)
52 {
53     RS_ActionInterface::init(status);
54
55     snapMode = RS2::SnapFree;
56     snapRes = RS2::RestrictNothing;
57 }
58
59
60
61 void RS_ActionModifyTrimAmount::trigger() {
62
63     RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()");
64
65     if (trimEntity!=NULL && trimEntity->isAtomic()) {
66
67         RS_Modification m(*container, graphicView);
68         m.trimAmount(trimCoord, (RS_AtomicEntity*)trimEntity, distance);
69
70         trimEntity = NULL;
71         setStatus(ChooseTrimEntity);
72
73         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
74     }
75 }
76
77
78
79 void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent* e) {
80
81     trimCoord = graphicView->toGraph(e->x(), e->y());
82     trimEntity = catchEntity(e);
83
84     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
85         switch (getStatus()) {
86         case ChooseTrimEntity:
87             if (trimEntity!=NULL && trimEntity->isAtomic()) {
88                 trigger();
89             } else {
90                 if (trimEntity==NULL) {
91                     RS_DIALOGFACTORY->commandMessage(
92                         tr("No entity found. "));
93                 } else if (trimEntity->rtti()==RS2::EntityInsert) {
94                     RS_DIALOGFACTORY->commandMessage(
95                         tr("The chosen Entity is in a block. "
96                            "Please edit the block."));
97                 } else {
98                     RS_DIALOGFACTORY->commandMessage(
99                         tr("The chosen Entity is not an atomic entity "
100                            "or cannot be trimmed."));
101                 }
102             }
103             break;
104
105         default:
106             break;
107         }
108     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
109         deleteSnapper();
110         init(getStatus()-1);
111     }
112 }
113
114
115
116 void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent* e) {
117     QString c = e->getCommand().toLower();
118
119     if (checkCommand("help", c)) {
120         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
121                                          + getAvailableCommands().join(", "));
122         return;
123     }
124
125     switch (getStatus()) {
126     case ChooseTrimEntity: {
127             bool ok;
128             double d = RS_Math::eval(c, &ok);
129             if (ok==true) {
130                 distance = d;
131             } else {
132                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
133             }
134             RS_DIALOGFACTORY->requestOptions(this, true, true);
135             setStatus(ChooseTrimEntity);
136         }
137         break;
138
139     default:
140         break;
141     }
142 }
143
144
145
146 QStringList RS_ActionModifyTrimAmount::getAvailableCommands() {
147     QStringList cmd;
148
149     switch (getStatus()) {
150     case ChooseTrimEntity:
151         break;
152     default:
153         break;
154     }
155
156     return cmd;
157 }
158
159
160 void RS_ActionModifyTrimAmount::showOptions() {
161     RS_ActionInterface::showOptions();
162
163     RS_DIALOGFACTORY->requestOptions(this, true);
164 }
165
166
167
168 void RS_ActionModifyTrimAmount::hideOptions() {
169     RS_ActionInterface::hideOptions();
170
171     RS_DIALOGFACTORY->requestOptions(this, false);
172 }
173
174
175 void RS_ActionModifyTrimAmount::updateMouseButtonHints() {
176     switch (getStatus()) {
177     case ChooseTrimEntity:
178         RS_DIALOGFACTORY->updateMouseWidget(
179             tr("Select entity to trim or enter distance:"),
180             tr("Back"));
181         break;
182     default:
183         RS_DIALOGFACTORY->updateMouseWidget("", "");
184         break;
185     }
186 }
187
188
189
190 void RS_ActionModifyTrimAmount::updateMouseCursor() {
191     graphicView->setMouseCursor(RS2::CadCursor);
192 }
193
194
195
196 void RS_ActionModifyTrimAmount::updateToolBar() {
197     RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
198 }
199
200
201 // EOF