X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondimangular.cpp;h=9ebb5681c7c64184ce67833838f25fc66674751f;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=57c16b44d0e9c918882f1c6cae15df53bde47228;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondimangular.cpp b/src/actions/rs_actiondimangular.cpp index 57c16b4..9ebb568 100644 --- a/src/actions/rs_actiondimangular.cpp +++ b/src/actions/rs_actiondimangular.cpp @@ -1,316 +1,310 @@ -/**************************************************************************** -** $Id: rs_actiondimangular.cpp 1134 2004-07-13 23:26:13Z andrew $ -** -** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. -** -** This file is part of the qcadlib Library project. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid qcadlib Professional Edition licenses may use -** this file in accordance with the qcadlib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ +// rs_actiondimangular.cpp +// +// Part of the Architektonas Project +// Originally part of QCad Community Edition by Andrew Mustun +// Extensively rewritten and refactored by James L. Hammons +// (C) 2010 Underground Software +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 06/03/2010 Added this text. :-) +// #include "rs_actiondimangular.h" -#include "rs_creation.h" -#include "rs_information.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_information.h" +#include "rs_preview.h" - - -RS_ActionDimAngular::RS_ActionDimAngular( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionDimension("Draw Angular Dimensions", - container, graphicView) { - reset(); +RS_ActionDimAngular::RS_ActionDimAngular(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Angular Dimensions", + container, graphicView) +{ + reset(); } -QAction * RS_ActionDimAngular::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDimAngular::~RS_ActionDimAngular() { - QAction * action = new QAction(tr("&Angular"), 0); -// QAction* action = new QAction(tr("Angular"), tr("&Angular"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Angular Dimension")); - - return action; } - -void RS_ActionDimAngular::reset() { - RS_ActionDimension::reset(); - - edata = RS_DimAngularData(Vector(false), - Vector(false), - Vector(false), - Vector(false)); - line1 = NULL; - line2 = NULL; - center = Vector(false); - RS_DIALOGFACTORY->requestOptions(this, true, true); +/*virtual*/ RS2::ActionType RS_ActionDimAngular::rtti() +{ + return RS2::ActionDimAngular; } - - -void RS_ActionDimAngular::trigger() { - RS_PreviewActionInterface::trigger(); - - if (line1!=NULL && line2!=NULL) { - RS_DimAngular* newEntity = NULL; - - newEntity = new RS_DimAngular(container, - data, - edata); - - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - newEntity->update(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(newEntity); - graphicView->moveRelativeZero(rz); - - } else { - RS_DEBUG->print("RS_ActionDimAngular::trigger:" - " Entity is NULL\n"); - } +void RS_ActionDimAngular::reset() +{ + RS_ActionDimension::reset(); + edata = RS_DimAngularData(Vector(false), Vector(false), Vector(false), Vector(false)); + line1 = NULL; + line2 = NULL; + center = Vector(false); + RS_DIALOGFACTORY->requestOptions(this, true, true); } +void RS_ActionDimAngular::trigger() +{ + RS_PreviewActionInterface::trigger(); + + if (line1 != NULL && line2 != NULL) + { + RS_DimAngular * newEntity = NULL; + + newEntity = new RS_DimAngular(container, + data, + edata); + + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + newEntity->update(); + container->addEntity(newEntity); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(newEntity); + graphicView->moveRelativeZero(rz); + } + else + RS_DEBUG->print("RS_ActionDimAngular::trigger:" + " Entity is NULL\n"); +} +void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin"); -void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin"); + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); + switch (getStatus()) + { + case SetLine1: + break; - switch (getStatus()) { - case SetLine1: - break; + case SetLine2: + break; - case SetLine2: - break; + case SetPos: - case SetPos: - if (line1!=NULL && line2!=NULL && center.valid) { - Vector mouse = snapPoint(e); - edata.definitionPoint4 = mouse; + if (line1 != NULL && line2 != NULL && center.valid) + { + Vector mouse = snapPoint(e); + edata.definitionPoint4 = mouse; - RS_DimAngular* d = new RS_DimAngular(preview, data, edata); - d->update(); + RS_DimAngular * d = new RS_DimAngular(preview, data, edata); + d->update(); - deletePreview(); - clearPreview(); - preview->addEntity(d); - drawPreview(); - } - break; + deletePreview(); + clearPreview(); + preview->addEntity(d); + drawPreview(); + } + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end"); } - - -void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetLine1: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && - en->rtti()==RS2::EntityLine) { - line1 = (RS_Line*)en; - setStatus(SetLine2); - } - } - break; - - case SetLine2: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && - en->rtti()==RS2::EntityLine) { - line2 = (RS_Line*)en; - - VectorSolutions sol = - RS_Information::getIntersectionLineLine(line1, line2); - - if (sol.get(0).valid) { - center = sol.get(0); - - if (center.distanceTo(line1->getStartpoint()) < - center.distanceTo(line1->getEndpoint())) { - edata.definitionPoint1 = line1->getStartpoint(); - edata.definitionPoint2 = line1->getEndpoint(); - } else { - edata.definitionPoint1 = line1->getEndpoint(); - edata.definitionPoint2 = line1->getStartpoint(); - } - - if (center.distanceTo(line2->getStartpoint()) < - center.distanceTo(line2->getEndpoint())) { - edata.definitionPoint3 = line2->getStartpoint(); - data.definitionPoint = line2->getEndpoint(); - } else { - edata.definitionPoint3 = line2->getEndpoint(); - data.definitionPoint = line2->getStartpoint(); - } - graphicView->moveRelativeZero(center); - setStatus(SetPos); - } - } - } - break; - - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - clearPreview(); - init(getStatus()-1); - } - +void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::LeftButton) + { + switch (getStatus()) + { + case SetLine1: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL + && en->rtti() == RS2::EntityLine) + { + line1 = (RS_Line *)en; + setStatus(SetLine2); + } + } + break; + + case SetLine2: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL + && en->rtti() == RS2::EntityLine) + { + line2 = (RS_Line *)en; + + VectorSolutions sol = + RS_Information::getIntersectionLineLine(line1, line2); + + if (sol.get(0).valid) + { + center = sol.get(0); + + if (center.distanceTo(line1->getStartpoint()) + < center.distanceTo(line1->getEndpoint())) + { + edata.definitionPoint1 = line1->getStartpoint(); + edata.definitionPoint2 = line1->getEndpoint(); + } + else + { + edata.definitionPoint1 = line1->getEndpoint(); + edata.definitionPoint2 = line1->getStartpoint(); + } + + if (center.distanceTo(line2->getStartpoint()) + < center.distanceTo(line2->getEndpoint())) + { + edata.definitionPoint3 = line2->getStartpoint(); + data.definitionPoint = line2->getEndpoint(); + } + else + { + edata.definitionPoint3 = line2->getEndpoint(); + data.definitionPoint = line2->getStartpoint(); + } + graphicView->moveRelativeZero(center); + setStatus(SetPos); + } + } + } + break; + + case SetPos: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + } + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + clearPreview(); + init(getStatus() - 1); + } } - - -void RS_ActionDimAngular::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - edata.definitionPoint4 = e->getCoordinate(); - trigger(); - reset(); - setStatus(SetLine1); - break; - - default: - break; - } +void RS_ActionDimAngular::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + switch (getStatus()) + { + case SetPos: + edata.definitionPoint4 = *e; + trigger(); + reset(); + setStatus(SetLine1); + break; + + default: + break; + } } - -void RS_ActionDimAngular::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - // setting new text label: - if (getStatus()==SetText) { - setText(c); - RS_DIALOGFACTORY->requestOptions(this, true, true); - graphicView->enableCoordinateInput(); - setStatus(lastStatus); - return; - } - - // command: text - if (checkCommand("text", c)) { - lastStatus = (Status)getStatus(); - graphicView->disableCoordinateInput(); - setStatus(SetText); - } +void RS_ActionDimAngular::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + // setting new text label: + if (getStatus() == SetText) + { + setText(c); + RS_DIALOGFACTORY->requestOptions(this, true, true); + graphicView->enableCoordinateInput(); + setStatus(lastStatus); + return; + } + + // command: text + if (checkCommand("text", c)) + { + lastStatus = (Status)getStatus(); + graphicView->disableCoordinateInput(); + setStatus(SetText); + } } +QStringList RS_ActionDimAngular::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetLine1: + case SetLine2: + case SetPos: + cmd += command("text"); + break; -QStringList RS_ActionDimAngular::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetLine1: - case SetLine2: - case SetPos: - cmd += command("text"); - break; - - default: - break; - } + default: + break; + } - return cmd; + return cmd; } +void RS_ActionDimAngular::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDimAngular::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDimAngular::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDimAngular::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDimAngular::updateMouseButtonHints() { - switch (getStatus()) { - case SetLine1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"), - tr("Cancel")); - break; - case SetLine2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"), - tr("Cancel")); - break; - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify dimension arc line location"), tr("Cancel")); - break; - case SetText: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDimAngular::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetLine1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"), + tr("Cancel")); + break; + + case SetLine2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"), + tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify dimension arc line location"), tr("Cancel")); + break; + + case SetText: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - // EOF