1 /****************************************************************************
2 ** $Id: rs_actionmodifytrimamount.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_actionmodifytrimamount.h"
29 #include "rs_snapper.h"
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) {
38 trimCoord = Vector(false);
42 QAction* RS_ActionModifyTrimAmount::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
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"));
51 void RS_ActionModifyTrimAmount::init(int status)
53 RS_ActionInterface::init(status);
55 snapMode = RS2::SnapFree;
56 snapRes = RS2::RestrictNothing;
61 void RS_ActionModifyTrimAmount::trigger() {
63 RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()");
65 if (trimEntity!=NULL && trimEntity->isAtomic()) {
67 RS_Modification m(*container, graphicView);
68 m.trimAmount(trimCoord, (RS_AtomicEntity*)trimEntity, distance);
71 setStatus(ChooseTrimEntity);
73 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
79 void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent* e) {
81 trimCoord = graphicView->toGraph(e->x(), e->y());
82 trimEntity = catchEntity(e);
84 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
85 switch (getStatus()) {
86 case ChooseTrimEntity:
87 if (trimEntity!=NULL && trimEntity->isAtomic()) {
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."));
98 RS_DIALOGFACTORY->commandMessage(
99 tr("The chosen Entity is not an atomic entity "
100 "or cannot be trimmed."));
108 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
116 void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent* e) {
117 QString c = e->getCommand().toLower();
119 if (checkCommand("help", c)) {
120 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
121 + getAvailableCommands().join(", "));
125 switch (getStatus()) {
126 case ChooseTrimEntity: {
128 double d = RS_Math::eval(c, &ok);
132 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
134 RS_DIALOGFACTORY->requestOptions(this, true, true);
135 setStatus(ChooseTrimEntity);
146 QStringList RS_ActionModifyTrimAmount::getAvailableCommands() {
149 switch (getStatus()) {
150 case ChooseTrimEntity:
160 void RS_ActionModifyTrimAmount::showOptions() {
161 RS_ActionInterface::showOptions();
163 RS_DIALOGFACTORY->requestOptions(this, true);
168 void RS_ActionModifyTrimAmount::hideOptions() {
169 RS_ActionInterface::hideOptions();
171 RS_DIALOGFACTORY->requestOptions(this, false);
175 void RS_ActionModifyTrimAmount::updateMouseButtonHints() {
176 switch (getStatus()) {
177 case ChooseTrimEntity:
178 RS_DIALOGFACTORY->updateMouseWidget(
179 tr("Select entity to trim or enter distance:"),
183 RS_DIALOGFACTORY->updateMouseWidget("", "");
190 void RS_ActionModifyTrimAmount::updateMouseCursor() {
191 graphicView->setMouseCursor(RS2::CadCursor);
196 void RS_ActionModifyTrimAmount::updateToolBar() {
197 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);