1 /****************************************************************************
2 ** $Id: rs_actiondimradial.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_actiondimradial.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
31 #include "rs_dialogfactory.h"
35 RS_ActionDimRadial::RS_ActionDimRadial(
36 RS_EntityContainer& container,
37 RS_GraphicView& graphicView)
38 :RS_ActionDimension("Draw Radial Dimensions",
39 container, graphicView) {
44 QAction * RS_ActionDimRadial::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
46 QAction * action = new QAction(tr("&Radial"), 0);
47 // QAction * action = new QAction(tr("Radial"), tr("&Radial"),
48 // QKeySequence(), NULL);
49 action->setStatusTip(tr("Radial Dimension"));
54 void RS_ActionDimRadial::reset()
56 RS_ActionDimension::reset();
58 edata = RS_DimRadialData(Vector(false),
62 RS_DIALOGFACTORY->requestOptions(this, true, true);
67 void RS_ActionDimRadial::trigger() {
68 RS_ActionDimension::trigger();
72 RS_DimRadial* newEntity = NULL;
74 newEntity = new RS_DimRadial(container,
78 newEntity->setLayerToActive();
79 newEntity->setPenToActive();
81 container->addEntity(newEntity);
85 document->startUndoCycle();
86 document->addUndoable(newEntity);
87 document->endUndoCycle();
90 Vector rz = graphicView->getRelativeZero();
91 graphicView->moveRelativeZero(Vector(0.0,0.0));
92 graphicView->drawEntity(newEntity);
93 graphicView->moveRelativeZero(rz);
98 RS_DEBUG->print("RS_ActionDimRadial::trigger:"
104 void RS_ActionDimRadial::preparePreview() {
106 double angle = data.definitionPoint.angleTo(pos);
108 if (entity->rtti()==RS2::EntityArc) {
109 radius = ((RS_Arc*)entity)->getRadius();
110 } else if (entity->rtti()==RS2::EntityCircle) {
111 radius = ((RS_Circle*)entity)->getRadius();
114 edata.definitionPoint.setPolar(radius, angle);
115 edata.definitionPoint += data.definitionPoint;
121 void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent* e) {
122 RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin");
124 //Vector mouse(graphicView->toGraphX(e->x()),
125 // graphicView->toGraphY(e->y()));
127 switch (getStatus()) {
129 entity = catchEntity(e, RS2::ResolveAll);
138 RS_DimRadial* d = new RS_DimRadial(preview, data, edata);
143 preview->addEntity(d);
152 RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end");
157 void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent* e) {
159 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
160 switch (getStatus()) {
162 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
164 if (en->rtti()==RS2::EntityArc ||
165 en->rtti()==RS2::EntityCircle) {
167 if (entity->rtti()==RS2::EntityArc) {
168 data.definitionPoint =
169 ((RS_Arc*)entity)->getCenter();
170 } else if (entity->rtti()==RS2::EntityCircle) {
171 data.definitionPoint =
172 ((RS_Circle*)entity)->getCenter();
174 graphicView->moveRelativeZero(data.definitionPoint);
177 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
185 RS_CoordinateEvent ce(snapPoint(e));
186 coordinateEvent(&ce);
193 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
203 void RS_ActionDimRadial::coordinateEvent(RS_CoordinateEvent* e) {
208 switch (getStatus()) {
210 pos = e->getCoordinate();
213 setStatus(SetEntity);
223 void RS_ActionDimRadial::commandEvent(RS_CommandEvent* e) {
224 QString c = e->getCommand().toLower();
226 if (checkCommand("help", c)) {
227 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
228 + getAvailableCommands().join(", "));
232 // setting new text label:
233 if (getStatus()==SetText) {
235 RS_DIALOGFACTORY->requestOptions(this, true, true);
236 graphicView->enableCoordinateInput();
237 setStatus(lastStatus);
242 if (checkCommand("text", c)) {
243 lastStatus = (Status)getStatus();
244 graphicView->disableCoordinateInput();
249 if (getStatus()==SetPos) {
251 double a = RS_Math::eval(c, &ok);
253 pos.setPolar(1.0, RS_Math::deg2rad(a));
254 pos += data.definitionPoint;
257 setStatus(SetEntity);
259 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
267 QStringList RS_ActionDimRadial::getAvailableCommands() {
270 switch (getStatus()) {
273 cmd += command("text");
284 void RS_ActionDimRadial::updateMouseButtonHints() {
285 switch (getStatus()) {
287 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
291 RS_DIALOGFACTORY->updateMouseWidget(
292 tr("Specify dimension line position or enter angle:"),
296 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
299 RS_DIALOGFACTORY->updateMouseWidget("", "");
306 void RS_ActionDimRadial::showOptions() {
307 RS_ActionInterface::showOptions();
309 RS_DIALOGFACTORY->requestOptions(this, true);
310 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true);
315 void RS_ActionDimRadial::hideOptions() {
316 RS_ActionInterface::hideOptions();
318 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false);
319 RS_DIALOGFACTORY->requestOptions(this, false);