1 // rs_actionmodifystretch.cpp
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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "rs_actionmodifystretch.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_modification.h"
19 #include "rs_preview.h"
21 RS_ActionModifyStretch::RS_ActionModifyStretch(RS_EntityContainer & container,
22 GraphicView & graphicView): RS_PreviewActionInterface("Stretch Entities",
23 container, graphicView)
25 firstCorner = Vector(false);
26 secondCorner = Vector(false);
27 referencePoint = Vector(false);
28 targetPoint = Vector(false);
31 RS_ActionModifyStretch::~RS_ActionModifyStretch()
35 void RS_ActionModifyStretch::init(int status)
37 RS_ActionInterface::init(status);
40 void RS_ActionModifyStretch::trigger()
42 RS_DEBUG->print("RS_ActionModifyStretch::trigger()");
49 RS_Modification m(*container, graphicView);
50 m.stretch(firstCorner, secondCorner, targetPoint - referencePoint);
54 setStatus(SetFirstCorner);
56 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
59 void RS_ActionModifyStretch::mouseMoveEvent(QMouseEvent * e)
61 RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent begin");
63 Vector mouse = snapPoint(e);
72 if (firstCorner.valid)
74 secondCorner = snapPoint(e);
79 RS_LineData(Vector(firstCorner.x,
81 Vector(secondCorner.x,
85 RS_LineData(Vector(secondCorner.x,
87 Vector(secondCorner.x,
91 RS_LineData(Vector(secondCorner.x,
97 RS_LineData(Vector(firstCorner.x,
105 case SetReferencePoint:
110 if (referencePoint.valid)
116 preview->addStretchablesFrom(*container, firstCorner, secondCorner);
117 //preview->move(targetPoint-referencePoint);
118 preview->stretch(firstCorner, secondCorner,
119 targetPoint - referencePoint);
128 RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent end");
131 void RS_ActionModifyStretch::mouseReleaseEvent(QMouseEvent * e)
133 if (e->button() == Qt::LeftButton)
135 Vector ce(snapPoint(e));
136 coordinateEvent(&ce);
138 else if (e->button() == Qt::RightButton)
142 init(getStatus() - 1);
146 void RS_ActionModifyStretch::coordinateEvent(Vector * e)
157 setStatus(SetSecondCorner);
160 case SetSecondCorner:
161 secondCorner = mouse;
164 setStatus(SetReferencePoint);
167 case SetReferencePoint:
168 referencePoint = mouse;
169 graphicView->moveRelativeZero(referencePoint);
170 setStatus(SetTargetPoint);
175 graphicView->moveRelativeZero(targetPoint);
185 void RS_ActionModifyStretch::updateMouseButtonHints()
190 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
194 case SetSecondCorner:
195 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
199 case SetReferencePoint:
200 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
205 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
210 RS_DIALOGFACTORY->updateMouseWidget("", "");
215 void RS_ActionModifyStretch::updateMouseCursor()
217 graphicView->setMouseCursor(RS2::CadCursor);
220 void RS_ActionModifyStretch::updateToolBar()
223 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
225 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);