1 /****************************************************************************
2 ** $Id: rs_actiondimdiametric.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_actiondimdiametric.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
31 #include "rs_dialogfactory.h"
35 RS_ActionDimDiametric::RS_ActionDimDiametric(
36 RS_EntityContainer& container,
37 RS_GraphicView& graphicView)
38 :RS_ActionDimension("Draw Diametric Dimensions",
39 container, graphicView)
45 QAction * RS_ActionDimDiametric::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
47 QAction * action = new QAction(tr("&Diametric"), 0);
48 // QAction* action = new QAction(tr("Diametric"), tr("&Diametric"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Diametric Dimension"));
55 void RS_ActionDimDiametric::reset()
57 RS_ActionDimension::reset();
59 edata = RS_DimDiametricData(Vector(false),
63 RS_DIALOGFACTORY->requestOptions(this, true, true);
68 void RS_ActionDimDiametric::trigger()
70 RS_PreviewActionInterface::trigger();
74 RS_DimDiametric* newEntity = NULL;
76 newEntity = new RS_DimDiametric(container,
80 newEntity->setLayerToActive();
81 newEntity->setPenToActive();
83 container->addEntity(newEntity);
87 document->startUndoCycle();
88 document->addUndoable(newEntity);
89 document->endUndoCycle();
92 Vector rz = graphicView->getRelativeZero();
93 graphicView->moveRelativeZero(Vector(0.0,0.0));
94 graphicView->drawEntity(newEntity);
95 graphicView->moveRelativeZero(rz);
98 RS_DEBUG->print("RS_ActionDimDiametric::trigger:"
105 void RS_ActionDimDiametric::preparePreview()
109 Vector center = Vector(false);
110 if (entity->rtti()==RS2::EntityArc) {
111 radius = ((RS_Arc*)entity)->getRadius();
112 center = ((RS_Arc*)entity)->getCenter();
113 } else if (entity->rtti()==RS2::EntityCircle) {
114 radius = ((RS_Circle*)entity)->getRadius();
115 center = ((RS_Circle*)entity)->getCenter();
117 double angle = center.angleTo(pos);
119 data.definitionPoint.setPolar(radius, angle+M_PI);
120 data.definitionPoint += center;
122 edata.definitionPoint.setPolar(radius, angle);
123 edata.definitionPoint += center;
129 void RS_ActionDimDiametric::mouseMoveEvent(QMouseEvent* e)
131 RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent begin");
133 Vector mouse(graphicView->toGraphX(e->x()),
134 graphicView->toGraphY(e->y()));
136 switch (getStatus()) {
138 entity = catchEntity(e, RS2::ResolveAll);
146 RS_DimDiametric* d = new RS_DimDiametric(preview, data, edata);
151 preview->addEntity(d);
160 RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent end");
165 void RS_ActionDimDiametric::mouseReleaseEvent(QMouseEvent* e)
168 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
169 switch (getStatus()) {
171 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
173 if (en->rtti()==RS2::EntityArc ||
174 en->rtti()==RS2::EntityCircle) {
178 if (entity->rtti()==RS2::EntityArc) {
180 ((RS_Arc*)entity)->getCenter();
181 } else if (entity->rtti()==RS2::EntityCircle) {
183 ((RS_Circle*)entity)->getCenter();
185 graphicView->moveRelativeZero(center);
188 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
196 RS_CoordinateEvent ce(snapPoint(e));
197 coordinateEvent(&ce);
204 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
214 void RS_ActionDimDiametric::coordinateEvent(RS_CoordinateEvent* e)
220 switch (getStatus()) {
222 pos = e->getCoordinate();
225 setStatus(SetEntity);
234 void RS_ActionDimDiametric::commandEvent(RS_CommandEvent* e)
236 QString c = e->getCommand().toLower();
238 if (checkCommand("help", c)) {
239 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
240 + getAvailableCommands().join(", "));
244 // setting new text label:
245 if (getStatus()==SetText) {
247 RS_DIALOGFACTORY->requestOptions(this, true, true);
248 graphicView->enableCoordinateInput();
249 setStatus(lastStatus);
254 if (checkCommand("text", c)) {
255 lastStatus = (Status)getStatus();
256 graphicView->disableCoordinateInput();
261 if (getStatus()==SetPos) {
263 double a = RS_Math::eval(c, &ok);
265 pos.setPolar(1.0, RS_Math::deg2rad(a));
266 pos += data.definitionPoint;
269 setStatus(SetEntity);
271 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
279 QStringList RS_ActionDimDiametric::getAvailableCommands() {
282 switch (getStatus()) {
285 cmd += command("text");
296 void RS_ActionDimDiametric::updateMouseButtonHints() {
297 switch (getStatus()) {
299 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
303 RS_DIALOGFACTORY->updateMouseWidget(
304 tr("Specify dimension line location"), tr("Cancel"));
307 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
310 RS_DIALOGFACTORY->updateMouseWidget("", "");
317 void RS_ActionDimDiametric::showOptions() {
318 RS_ActionInterface::showOptions();
320 RS_DIALOGFACTORY->requestOptions(this, true);
325 void RS_ActionDimDiametric::hideOptions() {
326 RS_ActionInterface::hideOptions();
328 //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false);
329 RS_DIALOGFACTORY->requestOptions(this, false);