1 /****************************************************************************
2 ** $Id: rs_actionmodifystretch.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_actionmodifystretch.h"
29 #include "rs_snapper.h"
33 RS_ActionModifyStretch::RS_ActionModifyStretch(RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Stretch Entities",
36 container, graphicView) {
38 firstCorner = Vector(false);
39 secondCorner = Vector(false);
40 referencePoint = Vector(false);
41 targetPoint = Vector(false);
44 QAction* RS_ActionModifyStretch::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 QAction * action = new QAction(tr("&Stretch"), 0);
47 // QAction* action = new QAction(tr("Stretch"), tr("&Stretch"),
48 // QKeySequence(), NULL);
49 action->setStatusTip(tr("Stretch Entities"));
54 void RS_ActionModifyStretch::init(int status) {
55 RS_ActionInterface::init(status);
61 void RS_ActionModifyStretch::trigger() {
63 RS_DEBUG->print("RS_ActionModifyStretch::trigger()");
70 RS_Modification m(*container, graphicView);
71 m.stretch(firstCorner, secondCorner, targetPoint-referencePoint);
75 setStatus(SetFirstCorner);
77 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
82 void RS_ActionModifyStretch::mouseMoveEvent(QMouseEvent* e) {
83 RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent begin");
85 Vector mouse = snapPoint(e);
86 switch (getStatus()) {
91 if (firstCorner.valid) {
92 secondCorner = snapPoint(e);
97 RS_LineData(Vector(firstCorner.x,
99 Vector(secondCorner.x,
103 RS_LineData(Vector(secondCorner.x,
105 Vector(secondCorner.x,
109 RS_LineData(Vector(secondCorner.x,
111 Vector(firstCorner.x,
115 RS_LineData(Vector(firstCorner.x,
117 Vector(firstCorner.x,
123 case SetReferencePoint:
127 if (referencePoint.valid) {
132 preview->addStretchablesFrom(*container, firstCorner, secondCorner);
133 //preview->move(targetPoint-referencePoint);
134 preview->stretch(firstCorner, secondCorner,
135 targetPoint-referencePoint);
144 RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent end");
149 void RS_ActionModifyStretch::mouseReleaseEvent(QMouseEvent* e) {
150 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
151 RS_CoordinateEvent ce(snapPoint(e));
152 coordinateEvent(&ce);
153 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
162 void RS_ActionModifyStretch::coordinateEvent(RS_CoordinateEvent* e) {
167 Vector mouse = e->getCoordinate();
169 switch (getStatus()) {
172 setStatus(SetSecondCorner);
175 case SetSecondCorner:
176 secondCorner = mouse;
179 setStatus(SetReferencePoint);
182 case SetReferencePoint:
183 referencePoint = mouse;
184 graphicView->moveRelativeZero(referencePoint);
185 setStatus(SetTargetPoint);
190 graphicView->moveRelativeZero(targetPoint);
202 void RS_ActionModifyStretch::updateMouseButtonHints() {
203 switch (getStatus()) {
205 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
208 case SetSecondCorner:
209 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
212 case SetReferencePoint:
213 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
217 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
221 RS_DIALOGFACTORY->updateMouseWidget("", "");
228 void RS_ActionModifyStretch::updateMouseCursor() {
229 graphicView->setMouseCursor(RS2::CadCursor);
234 void RS_ActionModifyStretch::updateToolBar() {
236 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
238 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);