1 /****************************************************************************
2 ** $Id: rs_actiondimaligned.cpp 1134 2004-07-13 23:26:13Z 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_actiondimaligned.h"
29 #include "rs_snapper.h"
30 #include "rs_constructionline.h"
31 #include "rs_dialogfactory.h"
35 RS_ActionDimAligned::RS_ActionDimAligned(RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_ActionDimension("Draw aligned dimensions",
38 container, graphicView)
43 RS_ActionDimAligned::~RS_ActionDimAligned()
47 QAction * RS_ActionDimAligned::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
49 QAction * action = new QAction(tr("&Aligned"), 0);
50 // QAction* action = new QAction(tr("Aligned"), tr("&Aligned"),
51 // QKeySequence(), NULL);
52 action->setStatusTip(tr("Aligned Dimension"));
58 void RS_ActionDimAligned::reset()
60 RS_ActionDimension::reset();
61 edata = RS_DimAlignedData(Vector(false), Vector(false));
62 lastStatus = SetExtPoint1;
64 if (RS_DIALOGFACTORY != NULL)
65 RS_DIALOGFACTORY->requestOptions(this, true, true);
70 void RS_ActionDimAligned::trigger()
72 RS_ActionDimension::trigger();
75 graphicView->moveRelativeZero(data.definitionPoint);
77 //data.text = getText();
79 new RS_DimAligned(container, data, edata);
80 dim->setLayerToActive();
81 dim->setPenToActive();
83 container->addEntity(dim);
87 document->startUndoCycle();
88 document->addUndoable(dim);
89 document->endUndoCycle();
93 Vector rz = graphicView->getRelativeZero();
94 graphicView->moveRelativeZero(Vector(0.0,0.0));
95 graphicView->drawEntity(dim);
96 graphicView->moveRelativeZero(rz);
99 RS_DEBUG->print("RS_ActionDimAligned::trigger():"
100 " dim added: %d", dim->getId());
105 void RS_ActionDimAligned::preparePreview() {
108 edata.extensionPoint1.angleTo(
109 edata.extensionPoint2)
111 RS_ConstructionLine cl(NULL,
112 RS_ConstructionLineData(
113 edata.extensionPoint2,
114 edata.extensionPoint2+dirV));
116 data.definitionPoint =
117 cl.getNearestPointOnEntity(data.definitionPoint);
122 void RS_ActionDimAligned::mouseMoveEvent(QMouseEvent* e) {
123 RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent begin");
125 Vector mouse = snapPoint(e);
127 switch (getStatus()) {
132 if (edata.extensionPoint1.valid) {
137 RS_LineData(edata.extensionPoint1, mouse))
144 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid) {
147 data.definitionPoint = mouse;
151 //data.text = getText();
152 RS_DimAligned* dim = new RS_DimAligned(preview, data, edata);
154 preview->addEntity(dim);
163 RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent end");
168 void RS_ActionDimAligned::mouseReleaseEvent(QMouseEvent* e) {
169 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
170 RS_CoordinateEvent ce(snapPoint(e));
171 coordinateEvent(&ce);
172 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
181 void RS_ActionDimAligned::coordinateEvent(RS_CoordinateEvent* e) {
186 Vector pos = e->getCoordinate();
188 switch (getStatus()) {
190 edata.extensionPoint1 = pos;
191 graphicView->moveRelativeZero(pos);
192 setStatus(SetExtPoint2);
196 edata.extensionPoint2 = pos;
197 graphicView->moveRelativeZero(pos);
198 setStatus(SetDefPoint);
202 data.definitionPoint = pos;
205 setStatus(SetExtPoint1);
215 void RS_ActionDimAligned::commandEvent(RS_CommandEvent* e) {
216 QString c = e->getCommand().toLower();
218 if (checkCommand("help", c)) {
219 if (RS_DIALOGFACTORY!=NULL) {
220 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
221 + getAvailableCommands().join(", "));
226 switch (getStatus()) {
229 if (RS_DIALOGFACTORY!=NULL) {
230 RS_DIALOGFACTORY->requestOptions(this, true, true);
232 setStatus(lastStatus);
233 graphicView->enableCoordinateInput();
238 if (checkCommand("text", c)) {
239 lastStatus = (Status)getStatus();
240 graphicView->disableCoordinateInput();
249 QStringList RS_ActionDimAligned::getAvailableCommands() {
252 switch (getStatus()) {
256 cmd += command("text");
268 void RS_ActionDimAligned::updateMouseButtonHints() {
269 if (RS_DIALOGFACTORY!=NULL) {
270 switch (getStatus()) {
272 RS_DIALOGFACTORY->updateMouseWidget(
273 tr("Specify first extension line origin"),
277 RS_DIALOGFACTORY->updateMouseWidget(
278 tr("Specify second extension line origin"),
282 RS_DIALOGFACTORY->updateMouseWidget(
283 tr("Specify dimension line location"),
287 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
290 RS_DIALOGFACTORY->updateMouseWidget("", "");
298 void RS_ActionDimAligned::hideOptions() {
299 if (RS_DIALOGFACTORY!=NULL) {
300 RS_DIALOGFACTORY->requestOptions(this, false);
303 RS_ActionDimension::hideOptions();
308 void RS_ActionDimAligned::showOptions() {
309 RS_ActionDimension::showOptions();
311 if (RS_DIALOGFACTORY!=NULL) {
312 RS_DIALOGFACTORY->requestOptions(this, true);