1 /****************************************************************************
2 ** $Id: rs_actiondimleader.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_actiondimleader.h"
29 #include "rs_snapper.h"
31 RS_ActionDimLeader::RS_ActionDimLeader(RS_EntityContainer & container,
32 RS_GraphicView & graphicView):
33 RS_PreviewActionInterface("Draw leaders", container, graphicView)
38 RS_ActionDimLeader::~RS_ActionDimLeader()
42 /*virtual*/ RS2::ActionType RS_ActionDimLeader::rtti()
44 return RS2::ActionDimLeader;
47 QAction * RS_ActionDimLeader::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
49 QAction * action = new QAction(tr("&Leader"), 0);
50 // QAction* action = new QAction(tr("Leader"), tr("&Leader"),
51 // QKeySequence(), NULL);
52 action->setStatusTip(tr("Leader Dimension"));
57 void RS_ActionDimLeader::reset()
59 //data = RS_LineData(Vector(false), Vector(false));
60 //start = Vector(false);
65 void RS_ActionDimLeader::init(int status)
67 RS_PreviewActionInterface::init(status);
72 void RS_ActionDimLeader::trigger()
74 RS_PreviewActionInterface::trigger();
76 if (points.count() > 0)
78 RS_Leader * leader = new RS_Leader(container, RS_LeaderData(true));
79 leader->setLayerToActive();
80 leader->setPenToActive();
82 // for(Vector * v=points.first(); v!=NULL; v=points.next())
83 // leader->addVertex(*v);
84 for(int i=0; i<points.size(); i++)
85 leader->addVertex(*(points[i]));
87 container->addEntity(leader);
92 document->startUndoCycle();
93 document->addUndoable(leader);
94 document->endUndoCycle();
100 Vector rz = graphicView->getRelativeZero();
101 graphicView->moveRelativeZero(Vector(0.0, 0.0));
102 graphicView->drawEntity(leader);
103 graphicView->moveRelativeZero(rz);
106 RS_DEBUG->print("RS_ActionDimLeader::trigger(): leader added: %d", leader->getId());
110 void RS_ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
112 RS_DEBUG->print("RS_ActionDimLeader::mouseMoveEvent begin");
114 Vector mouse = snapPoint(e);
116 if (getStatus()==SetEndpoint && points.last()!=NULL)
121 // fill in lines that were already set:
124 // for(Vector * v=points.first(); v!=NULL; v=points.next())
125 for(int i=0; i<points.size(); i++)
127 Vector * v = points[i];
130 preview->addEntity(new RS_Line(preview, RS_LineData(last, *v)));
135 Vector p = *points.last();
136 preview->addEntity(new RS_Line(preview, RS_LineData(p, mouse)));
140 RS_DEBUG->print("RS_ActionDimLeader::mouseMoveEvent end");
143 void RS_ActionDimLeader::mouseReleaseEvent(QMouseEvent * e)
145 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
147 RS_CoordinateEvent ce(snapPoint(e));
148 coordinateEvent(&ce);
150 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
152 if (getStatus() == SetEndpoint)
156 setStatus(SetStartpoint);
162 init(getStatus() - 1);
167 void RS_ActionDimLeader::keyPressEvent(QKeyEvent * e)
169 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
173 setStatus(SetStartpoint);
177 void RS_ActionDimLeader::coordinateEvent(RS_CoordinateEvent * e)
182 Vector mouse = e->getCoordinate();
187 //data.startpoint = mouse;
189 points.append(new Vector(mouse));
190 //start = data.startpoint;
191 setStatus(SetEndpoint);
192 graphicView->moveRelativeZero(mouse);
196 //data.endpoint = mouse;
197 points.append(new Vector(mouse));
199 //data.startpoint = data.endpoint;
200 graphicView->moveRelativeZero(mouse);
208 void RS_ActionDimLeader::commandEvent(RS_CommandEvent * e)
210 QString c = e->getCommand().toLower();
212 if (checkCommand("help", c))
214 if (RS_DIALOGFACTORY != NULL)
216 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
217 + getAvailableCommands().join(", "));
228 setStatus(SetStartpoint);
233 QStringList RS_ActionDimLeader::getAvailableCommands()
240 void RS_ActionDimLeader::updateMouseButtonHints()
242 if (RS_DIALOGFACTORY != NULL)
247 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel"));
250 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish"));
253 RS_DIALOGFACTORY->updateMouseWidget("", "");
259 void RS_ActionDimLeader::showOptions()
261 RS_ActionInterface::showOptions();
263 //RS_DIALOGFACTORY->requestOptions(this, true);
266 void RS_ActionDimLeader::hideOptions()
268 RS_ActionInterface::hideOptions();
270 //RS_DIALOGFACTORY->requestOptions(this, false);
273 void RS_ActionDimLeader::updateMouseCursor()
275 graphicView->setMouseCursor(RS2::CadCursor);
278 void RS_ActionDimLeader::updateToolBar()
280 if (RS_DIALOGFACTORY != NULL)
283 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
285 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);