X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawlineparallel.cpp;h=a9e687ce2441f7692564a337b652313e93dd94b6;hb=27d4a138d23453e93a833e9347444b828a971cb4;hp=769f73a9c58562aefad606e8853b4b01bc7db47d;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawlineparallel.cpp b/src/actions/rs_actiondrawlineparallel.cpp index 769f73a..a9e687c 100644 --- a/src/actions/rs_actiondrawlineparallel.cpp +++ b/src/actions/rs_actiondrawlineparallel.cpp @@ -14,252 +14,243 @@ #include "rs_actiondrawlineparallel.h" -#include "rs_creation.h" -#include "rs_snapper.h" #include "rs_actiondrawlineparallelthrough.h" +#include "rs_commandevent.h" +#include "commands.h" +#include "rs_creation.h" +#include "rs_dialogfactory.h" +#include "graphicview.h" +#include "rs_preview.h" -RS_ActionDrawLineParallel::RS_ActionDrawLineParallel( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Parallels", container, graphicView) +RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw Parallels", + container, graphicView) { - parallel = NULL; - entity = NULL; - distance = 1.0; - number = 1; - coord = Vector(false); + parallel = NULL; + entity = NULL; + distance = 1.0; + number = 1; + coord = Vector(false); } -QAction * RS_ActionDrawLineParallel::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionDrawLineParallel::~RS_ActionDrawLineParallel() { - QAction * action = NULL; - - if (type == RS2::ActionDrawLineParallel) - { - action = new QAction(tr("Para&llel"), 0); -// action = new QAction(tr("Parallel"), tr("Para&llel"), -// QKeySequence(), NULL); - } - else if (type == RS2::ActionDrawArcParallel) - { - action = new QAction(tr("&Concentric"), 0); -// action = new QAction(tr("Concentric"), tr("&Concentric"), -// QKeySequence(), NULL); - } - else if (type == RS2::ActionDrawCircleParallel) - { - action = new QAction(tr("&Concentric"), 0); -// action = new QAction(tr("Concentric"), tr("&Concentric"), -// QKeySequence(), NULL); - } +} - action->setStatusTip(tr("Draw parallels to existing lines, arcs, circles")); - return action; +/*virtual*/ RS2::ActionType RS_ActionDrawLineParallel::rtti() +{ + return RS2::ActionDrawLineParallel; } void RS_ActionDrawLineParallel::trigger() { - RS_PreviewActionInterface::trigger(); + RS_PreviewActionInterface::trigger(); - RS_Creation creation(container, graphicView); - RS_Entity* e = creation.createParallel(coord, - distance, number, - entity); + RS_Creation creation(container, graphicView); + RS_Entity * e = creation.createParallel(coord, distance, number, entity); - if (e==NULL) { - RS_DEBUG->print("RS_ActionDrawLineParallel::trigger:" - " No parallels added\n"); - } + if (e == NULL) + RS_DEBUG->print("RS_ActionDrawLineParallel::trigger: No parallels added\n"); } +void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin"); + coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); + entity = catchEntity(e, RS2::ResolveAll); + switch (getStatus()) + { + case SetEntity: + { + deletePreview(); + clearPreview(); + RS_Creation creation(preview, NULL, false); + creation.createParallel(coord, distance, number, entity); + drawPreview(); + } + break; -void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin"); - - coord = Vector(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - entity = catchEntity(e, RS2::ResolveAll); - - switch (getStatus()) { - case SetEntity: { - deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createParallel(coord, - distance, number, - entity); - - drawPreview(); - } - break; - - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end"); } +void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + if (e->button() == Qt::RightButton) + init(getStatus() - 1); + else + trigger(); +} - -void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - trigger(); - } +void RS_ActionDrawLineParallel::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify Distance <%1> or select entity or [%2]") + .arg(distance).arg(RS_COMMANDS->command("through")), + tr("Cancel")); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLineParallel::showOptions() +{ + RS_ActionInterface::showOptions(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); -void RS_ActionDrawLineParallel::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify Distance <%1> or select entity or [%2]") - .arg(distance).arg(RS_COMMANDS->command("through")), - tr("Cancel")); - break; + updateMouseButtonHints(); +} - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); - break; +void RS_ActionDrawLineParallel::hideOptions() +{ + RS_ActionInterface::hideOptions(); - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } +void RS_ActionDrawLineParallel::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); -void RS_ActionDrawLineParallel::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } - updateMouseButtonHints(); -} + return; + } + switch (getStatus()) + { + case SetEntity: + if (checkCommand("through", c)) + { + finish(); + graphicView->setCurrentAction(new RS_ActionDrawLineParallelThrough(*container, + *graphicView)); + } + else if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetNumber); + } + else + { + bool ok; + double d = RS_Math::eval(c, &ok); + + if (ok && d > 1.0e-10) + distance = d; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + + updateMouseButtonHints(); + //setStatus(SetEntity); + } + break; + + case SetNumber: + { + bool ok; + int n = c.toInt(&ok); + if (ok) + { + if (n > 0 && n < 100) + number = n; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99")); -void RS_ActionDrawLineParallel::hideOptions() { - RS_ActionInterface::hideOptions(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } -} + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetEntity); + } + break; -void RS_ActionDrawLineParallel::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: { - if (checkCommand("through", c)) { - finish(); - graphicView->setCurrentAction( - new RS_ActionDrawLineParallelThrough(*container, - *graphicView)); - } else if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetNumber); - } else { - bool ok; - double d = RS_Math::eval(c, &ok); - if (ok==true && d>1.0e-10) { - distance = d; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - updateMouseButtonHints(); - //setStatus(SetEntity); - } - } - break; - - case SetNumber: { - bool ok; - int n = c.toInt(&ok); - if (ok==true) { - if (n>0 && n<100) { - number = n; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " - "Try 1..99")); - } - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(SetEntity); - } - break; - - default: - break; - } + default: + break; + } } +QStringList RS_ActionDrawLineParallel::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetEntity: + cmd += command("number"); + cmd += command("through"); + break; -QStringList RS_ActionDrawLineParallel::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetEntity: - cmd += command("number"); - cmd += command("through"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } +void RS_ActionDrawLineParallel::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} - -void RS_ActionDrawLineParallel::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineParallel::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); } +double RS_ActionDrawLineParallel::getDistance() +{ + return distance; +} +void RS_ActionDrawLineParallel::setDistance(double d) +{ + distance = d; +} -void RS_ActionDrawLineParallel::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +int RS_ActionDrawLineParallel::getNumber() +{ + return number; } +void RS_ActionDrawLineParallel::setNumber(int n) +{ + number = n; +} -// EOF