1 /****************************************************************************
2 ** $Id: rs_actionmodifybevel.cpp 1161 2004-12-09 23:10:09Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionmodifybevel.h"
29 #include "rs_snapper.h"
30 #include "rs_information.h"
33 RS_ActionModifyBevel::RS_ActionModifyBevel(RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Bevel Entities",
36 container, graphicView) {
39 coord1 = Vector(false);
41 coord2 = Vector(false);
45 QAction* RS_ActionModifyBevel::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
47 QAction * action = new QAction(tr("&Bevel"), 0);
48 // QAction* action = new QAction(tr("Bevel"), tr("&Bevel"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Bevel Entities"));
55 void RS_ActionModifyBevel::init(int status) {
56 RS_ActionInterface::init(status);
58 snapMode = RS2::SnapFree;
59 snapRes = RS2::RestrictNothing;
64 void RS_ActionModifyBevel::trigger() {
66 RS_DEBUG->print("RS_ActionModifyBevel::trigger()");
68 if (entity1!=NULL && entity1->isAtomic() &&
69 entity2!=NULL && entity2->isAtomic()) {
71 RS_Modification m(*container, graphicView);
72 m.bevel(coord1, (RS_AtomicEntity*)entity1,
73 coord2, (RS_AtomicEntity*)entity2,
78 setStatus(SetEntity1);
80 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
86 void RS_ActionModifyBevel::mouseMoveEvent(QMouseEvent* e) {
87 RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent begin");
89 Vector mouse = graphicView->toGraph(e->x(), e->y());
90 RS_Entity* se = catchEntity(e, RS2::ResolveAll);
92 switch (getStatus()) {
99 if (entity1!=NULL && RS_Information::isTrimmable(entity1)) {
109 RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent end");
114 void RS_ActionModifyBevel::mouseReleaseEvent(QMouseEvent* e) {
115 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
116 switch (getStatus()) {
118 if (entity1!=NULL && entity1->isAtomic()) {
119 setStatus(SetEntity2);
124 if (entity2!=NULL && entity2->isAtomic() &&
125 RS_Information::isTrimmable(entity1, entity2)) {
133 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
142 void RS_ActionModifyBevel::commandEvent(RS_CommandEvent* e) {
143 QString c = e->getCommand().toLower();
145 if (checkCommand("help", c)) {
146 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
147 + getAvailableCommands().join(", "));
151 switch (getStatus()) {
154 if (checkCommand("length1", c)) {
158 lastStatus = (Status)getStatus();
159 setStatus(SetLength1);
160 } else if (checkCommand("length2", c)) {
164 lastStatus = (Status)getStatus();
165 setStatus(SetLength2);
166 } else if (checkCommand("trim", c)) {
170 //lastStatus = (Status)getStatus();
171 //setStatus(SetTrim);
172 data.trim = !data.trim;
173 RS_DIALOGFACTORY->requestOptions(this, true, true);
179 double l = RS_Math::eval(c, &ok);
183 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
185 RS_DIALOGFACTORY->requestOptions(this, true, true);
186 setStatus(lastStatus);
192 double l = RS_Math::eval(c, &ok);
196 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
198 RS_DIALOGFACTORY->requestOptions(this, true, true);
199 setStatus(lastStatus);
204 if (checkCommand()) {
206 } else if (c==cmdNo.toLower() || c==cmdNo2) {
209 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
212 RS_DIALOGFACTORY->requestOptions(this, true, true);
213 setStatus(lastStatus);
224 QStringList RS_ActionModifyBevel::getAvailableCommands() {
226 switch (getStatus()) {
229 cmd += command("length1");
230 cmd += command("length2");
231 cmd += command("trim");
241 void RS_ActionModifyBevel::showOptions() {
242 RS_ActionInterface::showOptions();
244 RS_DIALOGFACTORY->requestOptions(this, true);
249 void RS_ActionModifyBevel::hideOptions() {
250 RS_ActionInterface::hideOptions();
252 RS_DIALOGFACTORY->requestOptions(this, false);
257 void RS_ActionModifyBevel::updateMouseButtonHints() {
258 switch (getStatus()) {
260 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
264 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
268 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
272 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
276 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
280 RS_DIALOGFACTORY->updateMouseWidget("", "");
287 void RS_ActionModifyBevel::updateMouseCursor() {
288 graphicView->setMouseCursor(RS2::CadCursor);
293 void RS_ActionModifyBevel::updateToolBar() {
294 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);