X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawlinerelangle.cpp;h=1ecd4c0639078b27ec6884e4b899a7635919f42a;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=3ac5f82850dc7f6b210e32d16c7642c4c1aac9ab;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawlinerelangle.cpp b/src/actions/rs_actiondrawlinerelangle.cpp index 3ac5f82..1ecd4c0 100644 --- a/src/actions/rs_actiondrawlinerelangle.cpp +++ b/src/actions/rs_actiondrawlinerelangle.cpp @@ -15,353 +15,363 @@ #include "rs_actiondrawlinerelangle.h" #include "rs_creation.h" -#include "rs_snapper.h" - -RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle( - RS_EntityContainer& container, - RS_GraphicView& graphicView, - double angle, - bool fixedAngle) - :RS_PreviewActionInterface("Draw Lines with relative angles", - container, graphicView) { - - entity = NULL; - this->angle = angle; - this->fixedAngle = fixedAngle; - length = 10.0; - pos = Vector(false); -} +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -QAction * RS_ActionDrawLineRelAngle::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle): + RS_PreviewActionInterface("Draw Lines with relative angles", + container, graphicView) { - QAction * action = NULL; + entity = NULL; + this->angle = angle; + this->fixedAngle = fixedAngle; + length = 10.0; + pos = Vector(false); +} - if (type == RS2::ActionDrawLineRelAngle) - { - action = new QAction(tr("R&elative angle"), 0); -// action = new QAction(tr("Relative angle"), tr("R&elative angle"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw line with relative angle")); - } - else if (type == RS2::ActionDrawLineOrthogonal) - { - action = new QAction(tr("&Orthogonal"), 0); -// action = new QAction(tr("Orthogonal"), tr("&Orthogonal"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw orthogonal line")); - } +RS_ActionDrawLineRelAngle::~RS_ActionDrawLineRelAngle() +{ +} - return action; +/*virtual*/ RS2::ActionType RS_ActionDrawLineRelAngle::rtti() +{ + return RS2::ActionDrawLineRelAngle; } void RS_ActionDrawLineRelAngle::trigger() { - RS_PreviewActionInterface::trigger(); - - deleteSnapper(); - deletePreview(); - clearPreview(); - - RS_Creation creation(container, graphicView); - creation.createLineRelAngle(pos, - entity, - angle, - length); - - /* - if (line!=NULL) { - RS_Entity* newEntity = NULL; - - newEntity = new RS_Line(container, - line->getData()); - - if (newEntity!=NULL) { - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - deleteSnapper(); - graphicView->drawEntity(newEntity); - setStatus(SetEntity); - } - //reset(); - delete line; - line = NULL; - } else { - RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:" - " Line is NULL\n"); - } - */ + RS_PreviewActionInterface::trigger(); + + deleteSnapper(); + deletePreview(); + clearPreview(); + + RS_Creation creation(container, graphicView); + creation.createLineRelAngle(pos, + entity, + angle, + length); + + /* + if (line!=NULL) { + RS_Entity* newEntity = NULL; + + newEntity = new RS_Line(container, + line->getData()); + + if (newEntity!=NULL) { + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + container->addEntity(newEntity); + + // upd. undo list: + if (document!=NULL) { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + deleteSnapper(); + graphicView->drawEntity(newEntity); + setStatus(SetEntity); + } + //reset(); + delete line; + line = NULL; + } else { + RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:" + " Line is NULL\n"); + } + */ } +void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin"); + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); -void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin"); - - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetEntity: - entity = catchEntity(e, RS2::ResolveAll); - break; - - case SetPos: { - //length = graphicView->toGraphDX(graphicView->getWidth()); - //Vector mouse = snapPoint(e); - pos = snapPoint(e); - - /*RS_Creation creation(NULL, NULL); - RS_Line* l = creation.createLineRelAngle(mouse, - entity, - angle, - length);*/ - - deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createLineRelAngle(pos, - entity, - angle, - length); - - drawPreview(); - - /*if (l!=NULL) { - if (line!=NULL) { - delete line; - } - line = (RS_Line*)l->clone(); + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e, RS2::ResolveAll); + break; + + case SetPos: { + //length = graphicView->toGraphDX(graphicView->getWidth()); + //Vector mouse = snapPoint(e); + pos = snapPoint(e); + + /*RS_Creation creation(NULL, NULL); + RS_Line* l = creation.createLineRelAngle(mouse, + entity, + angle, + length);*/ + + deletePreview(); + clearPreview(); + + RS_Creation creation(preview, NULL, false); + creation.createLineRelAngle(pos, + entity, + angle, + length); + + drawPreview(); + + /*if (l!=NULL) { + if (line!=NULL) { + delete line; + } + line = (RS_Line*)l->clone(); + + deletePreview(); + clearPreview(); + preview->addEntity(l); + drawPreview(); + }*/ + } + break; - deletePreview(); - clearPreview(); - preview->addEntity(l); - drawPreview(); - }*/ - } - break; + default: + break; + } - default: - break; - } + RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end"); +} - RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end"); +void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::LeftButton) + { + switch (getStatus()) + { + case SetEntity: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL + && (en->rtti() == RS2::EntityLine + || en->rtti() == RS2::EntityArc + || en->rtti() == RS2::EntityCircle)) + { + entity = en; + + entity->setHighlighted(true); + graphicView->drawEntity(entity); + + setStatus(SetPos); + } + } + break; + + case SetPos: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + default: + break; + } + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + clearPreview(); + + if (entity != NULL) + { + entity->setHighlighted(false); + graphicView->drawEntity(entity); + } + init(getStatus() - 1); + } } +void RS_ActionDrawLineRelAngle::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + switch (getStatus()) + { + case SetPos: + pos = *e; + trigger(); + break; -void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && - (en->rtti()==RS2::EntityLine || - en->rtti()==RS2::EntityArc || - en->rtti()==RS2::EntityCircle)) { - entity = en; - - entity->setHighlighted(true); - graphicView->drawEntity(entity); - - setStatus(SetPos); - } - } - break; - - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - clearPreview(); - if (entity!=NULL) { - entity->setHighlighted(false); - graphicView->drawEntity(entity); - } - init(getStatus()-1); - } + default: + break; + } } +void RS_ActionDrawLineRelAngle::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } -void RS_ActionDrawLineRelAngle::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - pos = e->getCoordinate(); - trigger(); - break; + switch (getStatus()) + { + case SetEntity: + case SetPos: + + if (!fixedAngle && checkCommand("angle", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetAngle); + } + else if (checkCommand("length", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetLength); + } + break; + + case SetAngle: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + angle = RS_Math::deg2rad(a); + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetPos); + } + break; - default: - break; - } -} + case SetLength: { + bool ok; + double l = RS_Math::eval(c, &ok); + if (ok == true) + length = l; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetPos); + } + break; -void RS_ActionDrawLineRelAngle::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - } - return; - } - - switch (getStatus()) { - case SetEntity: - case SetPos: - if (!fixedAngle && checkCommand("angle", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetAngle); - } else if (checkCommand("length", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetLength); - } - break; - - case SetAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - angle = RS_Math::deg2rad(a); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(SetPos); - } - break; - - case SetLength: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - length = l; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(SetPos); - } - break; - - default: - break; - } + default: + break; + } } +QStringList RS_ActionDrawLineRelAngle::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetPos: + case SetLength: -QStringList RS_ActionDrawLineRelAngle::getAvailableCommands() { - QStringList cmd; + if (!fixedAngle) + cmd += command("angle"); + cmd += command("length"); + break; - switch (getStatus()) { - case SetPos: - case SetLength: - if (!fixedAngle) { - cmd += command("angle"); - } - cmd += command("length"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - -void RS_ActionDrawLineRelAngle::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"), - tr("Cancel")); - break; - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLineRelAngle::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"), + tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLineRelAngle::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLineRelAngle::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawLineRelAngle::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLineRelAngle::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } +void RS_ActionDrawLineRelAngle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} - -void RS_ActionDrawLineRelAngle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineRelAngle::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } } +void RS_ActionDrawLineRelAngle::setAngle(double a) +{ + angle = a; +} +double RS_ActionDrawLineRelAngle::getAngle() +{ + return angle; +} -void RS_ActionDrawLineRelAngle::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +void RS_ActionDrawLineRelAngle::setLength(double l) +{ + length = l; } +double RS_ActionDrawLineRelAngle::getLength() +{ + return length; +} +bool RS_ActionDrawLineRelAngle::hasFixedAngle() +{ + return fixedAngle; +} -// EOF