#include "rs_actiondimlinear.h"
-#include "rs_snapper.h"
+#include "rs_commandevent.h"
#include "rs_constructionline.h"
#include "rs_dialogfactory.h"
+#include "graphicview.h"
+#include "rs_preview.h"
/**
* Constructor.
* @param fixedAngle true: The user can't change the angle.
* false: The user can change the angle in a option widget.
*/
-RS_ActionDimLinear::RS_ActionDimLinear(RS_EntityContainer& container,
- RS_GraphicView& graphicView, double angle, bool fixedAngle):
+RS_ActionDimLinear::RS_ActionDimLinear(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
RS_ActionDimension("Draw linear dimensions", container, graphicView)
{
edata.angle = angle;
this->fixedAngle = fixedAngle;
-
lastStatus = SetExtPoint1;
-
reset();
}
{
}
-QAction * RS_ActionDimLinear::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
+/*virtual*/ RS2::ActionType RS_ActionDimLinear::rtti()
{
- QAction * action;
-
- switch (type)
- {
- default:
- case RS2::ActionDimLinear:
- action = new QAction(tr("&Linear"), 0);
-// action = new QAction(tr("Linear"), tr("&Linear"),
-// QKeySequence(), NULL);
- action->setStatusTip(tr("Linear Dimension"));
- break;
-
- case RS2::ActionDimLinearHor:
- action = new QAction(tr("&Horizontal"), 0);
-// action = new QAction(tr("Horizontal"), tr("&Horizontal"),
-// QKeySequence(), NULL);
- action->setStatusTip(tr("Horizontal Dimension"));
- break;
-
- case RS2::ActionDimLinearVer:
- action = new QAction(tr("&Vertical"), 0);
-// action = new QAction(tr("Vertical"), tr("&Vertical"),
-// QKeySequence(), NULL);
- action->setStatusTip(tr("Vertical Dimension"));
- break;
- }
-
- return action;
+ return RS2::ActionDimLinear;
}
+void RS_ActionDimLinear::reset()
+{
+ RS_ActionDimension::reset();
+ edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
-void RS_ActionDimLinear::reset() {
- RS_ActionDimension::reset();
-
- edata = RS_DimLinearData(Vector(false),
- Vector(false),
- (fixedAngle ? edata.angle : 0.0), 0.0);
-
- if (RS_DIALOGFACTORY!=NULL) {
- RS_DIALOGFACTORY->requestOptions(this, true, true);
- }
+ if (RS_DIALOGFACTORY != NULL)
+ RS_DIALOGFACTORY->requestOptions(this, true, true);
}
+void RS_ActionDimLinear::trigger()
+{
+ RS_ActionDimension::trigger();
+ preparePreview();
+ RS_DimLinear * dim = new RS_DimLinear(container, data, edata);
+ dim->setLayerToActive();
+ dim->setPenToActive();
+ dim->update();
+ container->addEntity(dim);
+
+ // upd. undo list:
+ if (document != NULL)
+ {
+ document->startUndoCycle();
+ document->addUndoable(dim);
+ document->endUndoCycle();
+ }
+ deleteSnapper();
+ Vector rz = graphicView->getRelativeZero();
+ graphicView->moveRelativeZero(Vector(0.0, 0.0));
+ graphicView->drawEntity(dim);
+ graphicView->moveRelativeZero(rz);
+ drawSnapper();
-void RS_ActionDimLinear::trigger() {
- RS_ActionDimension::trigger();
-
- preparePreview();
- RS_DimLinear* dim = new RS_DimLinear(container, data, edata);
- dim->setLayerToActive();
- dim->setPenToActive();
- dim->update();
- container->addEntity(dim);
-
- // upd. undo list:
- if (document!=NULL) {
- document->startUndoCycle();
- document->addUndoable(dim);
- document->endUndoCycle();
- }
-
- deleteSnapper();
- Vector rz = graphicView->getRelativeZero();
- graphicView->moveRelativeZero(Vector(0.0,0.0));
- graphicView->drawEntity(dim);
- graphicView->moveRelativeZero(rz);
- drawSnapper();
-
- RS_DEBUG->print("RS_ActionDimLinear::trigger():"
- " dim added: %d", dim->getId());
+ RS_DEBUG->print("RS_ActionDimLinear::trigger(): dim added: %d", dim->getId());
}
+void RS_ActionDimLinear::preparePreview()
+{
+ Vector dirV;
+ dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
-void RS_ActionDimLinear::preparePreview() {
- Vector dirV;
- dirV.setPolar(100.0, edata.angle+M_PI/2.0);
-
- RS_ConstructionLine cl(
- NULL,
- RS_ConstructionLineData(
- edata.extensionPoint2,
- edata.extensionPoint2+dirV));
-
- data.definitionPoint =
- cl.getNearestPointOnEntity(data.definitionPoint);
+ RS_ConstructionLine cl(
+ NULL, RS_ConstructionLineData(
+ edata.extensionPoint2,
+ edata.extensionPoint2 + dirV));
+ data.definitionPoint =
+ cl.getNearestPointOnEntity(data.definitionPoint);
}
+void RS_ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
+{
+ RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent begin");
+ Vector mouse = snapPoint(e);
-void RS_ActionDimLinear::mouseMoveEvent(QMouseEvent* e) {
- RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent begin");
+ switch (getStatus())
+ {
+ case SetExtPoint1:
+ break;
- Vector mouse = snapPoint(e);
+ case SetExtPoint2:
+
+ if (edata.extensionPoint1.valid)
+ {
+ deletePreview();
+ clearPreview();
+ preview->addEntity(new RS_Line(preview,
+ RS_LineData(edata.extensionPoint1,
+ mouse)));
+ drawPreview();
+ }
+ break;
- switch (getStatus()) {
- case SetExtPoint1:
- break;
+ case SetDefPoint:
- case SetExtPoint2:
- if (edata.extensionPoint1.valid) {
- deletePreview();
- clearPreview();
- preview->addEntity(new RS_Line(preview,
- RS_LineData(edata.extensionPoint1,
- mouse)));
- drawPreview();
- }
- break;
+ if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
+ {
+ deletePreview();
+ clearPreview();
+ data.definitionPoint = mouse;
- case SetDefPoint:
- if (edata.extensionPoint1.valid && edata.extensionPoint2.valid) {
- deletePreview();
- clearPreview();
- data.definitionPoint = mouse;
+ preparePreview();
- preparePreview();
+ RS_DimLinear * dim = new RS_DimLinear(preview, data, edata);
+ dim->update();
+ preview->addEntity(dim);
+ drawPreview();
+ }
+ break;
+ }
- RS_DimLinear* dim = new RS_DimLinear(preview, data, edata);
- dim->update();
- preview->addEntity(dim);
- drawPreview();
- }
- break;
- }
+ RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent end");
+}
- RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent end");
+void RS_ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
+{
+ if (e->button() == Qt::LeftButton)
+ {
+ Vector ce(snapPoint(e));
+ coordinateEvent(&ce);
+ }
+ else if (e->button() == Qt::RightButton)
+ {
+ deletePreview();
+ deleteSnapper();
+ init(getStatus() - 1);
+ }
}
+void RS_ActionDimLinear::coordinateEvent(Vector * e)
+{
+ if (e == NULL)
+ return;
+ Vector pos = *e;
-void RS_ActionDimLinear::mouseReleaseEvent(QMouseEvent* e) {
- if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
- RS_CoordinateEvent ce(snapPoint(e));
- coordinateEvent(&ce);
- } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
- deletePreview();
- deleteSnapper();
- init(getStatus()-1);
- }
-}
+ switch (getStatus())
+ {
+ case SetExtPoint1:
+ edata.extensionPoint1 = pos;
+ graphicView->moveRelativeZero(pos);
+ setStatus(SetExtPoint2);
+ break;
+ case SetExtPoint2:
+ edata.extensionPoint2 = pos;
+ graphicView->moveRelativeZero(pos);
+ setStatus(SetDefPoint);
+ break;
+ case SetDefPoint:
+ data.definitionPoint = pos;
+ trigger();
+ reset();
+ setStatus(SetExtPoint1);
+ break;
-void RS_ActionDimLinear::coordinateEvent(RS_CoordinateEvent* e) {
- if (e==NULL) {
- return;
- }
+ default:
+ break;
+ }
+}
- Vector pos = e->getCoordinate();
+void RS_ActionDimLinear::commandEvent(RS_CommandEvent * e)
+{
+ QString c = e->getCommand().toLower();
- switch (getStatus()) {
- case SetExtPoint1:
- edata.extensionPoint1 = pos;
- graphicView->moveRelativeZero(pos);
- setStatus(SetExtPoint2);
- break;
+ if (checkCommand("help", c))
+ {
+ if (RS_DIALOGFACTORY != NULL)
+ RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ + getAvailableCommands().join(", "));
+ return;
+ }
- case SetExtPoint2:
- edata.extensionPoint2 = pos;
- graphicView->moveRelativeZero(pos);
- setStatus(SetDefPoint);
- break;
+ switch (getStatus())
+ {
+ case SetText:
+ setText(c);
- case SetDefPoint:
- data.definitionPoint = pos;
- trigger();
- reset();
- setStatus(SetExtPoint1);
- break;
+ if (RS_DIALOGFACTORY != NULL)
+ RS_DIALOGFACTORY->requestOptions(this, true, true);
+ graphicView->enableCoordinateInput();
+ setStatus(lastStatus);
+ break;
- default:
- break;
- }
-}
+ case SetAngle: {
+ bool ok;
+ double a = RS_Math::eval(c, &ok);
+ if (ok == true)
+ setAngle(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(lastStatus);
+ }
+ break;
-void RS_ActionDimLinear::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 SetText:
- setText(c);
- if (RS_DIALOGFACTORY!=NULL) {
- RS_DIALOGFACTORY->requestOptions(this, true, true);
- }
- graphicView->enableCoordinateInput();
- setStatus(lastStatus);
- break;
-
- case SetAngle: {
- bool ok;
- double a = RS_Math::eval(c, &ok);
- if (ok==true) {
- setAngle(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(lastStatus);
- }
- break;
-
- default:
- lastStatus = (Status)getStatus();
- deleteSnapper();
- deletePreview();
- clearPreview();
- if (checkCommand("text", c)) {
- graphicView->disableCoordinateInput();
- setStatus(SetText);
- return;
- } else if (!fixedAngle && (checkCommand("angle", c))) {
- setStatus(SetAngle);
- }
- break;
- }
+ default:
+ lastStatus = (Status)getStatus();
+ deleteSnapper();
+ deletePreview();
+ clearPreview();
+
+ if (checkCommand("text", c))
+ {
+ graphicView->disableCoordinateInput();
+ setStatus(SetText);
+ return;
+ }
+ else if (!fixedAngle && (checkCommand("angle", c)))
+ setStatus(SetAngle);
+ break;
+ }
}
+QStringList RS_ActionDimLinear::getAvailableCommands()
+{
+ QStringList cmd;
+ switch (getStatus())
+ {
+ case SetExtPoint1:
+ case SetExtPoint2:
+ case SetDefPoint:
+ cmd += command("text");
-QStringList RS_ActionDimLinear::getAvailableCommands() {
- QStringList cmd;
-
- switch (getStatus()) {
- case SetExtPoint1:
- case SetExtPoint2:
- case SetDefPoint:
- cmd += command("text");
- if (!fixedAngle) {
- cmd += command("angle");
- }
- break;
+ if (!fixedAngle)
+ cmd += command("angle");
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return cmd;
+ return cmd;
}
-
-void RS_ActionDimLinear::updateMouseButtonHints() {
- if (RS_DIALOGFACTORY!=NULL) {
- switch (getStatus()) {
- case SetExtPoint1:
- RS_DIALOGFACTORY->updateMouseWidget(
- tr("Specify first extension line origin"),
- tr("Cancel"));
- break;
- case SetExtPoint2:
- RS_DIALOGFACTORY->updateMouseWidget(
- tr("Specify second extension line origin"),
- tr("Back"));
- break;
- case SetDefPoint:
- RS_DIALOGFACTORY->updateMouseWidget(
- tr("Specify dimension line location"),
- tr("Back"));
- break;
- case SetText:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
- break;
- case SetAngle:
- RS_DIALOGFACTORY->updateMouseWidget(
- tr("Enter dimension line angle:"), "");
- break;
- default:
- RS_DIALOGFACTORY->updateMouseWidget("", "");
- break;
- }
- }
+void RS_ActionDimLinear::updateMouseButtonHints()
+{
+ if (RS_DIALOGFACTORY != NULL)
+ {
+ switch (getStatus())
+ {
+ case SetExtPoint1:
+ RS_DIALOGFACTORY->updateMouseWidget(
+ tr("Specify first extension line origin"), tr("Cancel"));
+ break;
+
+ case SetExtPoint2:
+ RS_DIALOGFACTORY->updateMouseWidget(
+ tr("Specify second extension line origin"), tr("Back"));
+ break;
+
+ case SetDefPoint:
+ RS_DIALOGFACTORY->updateMouseWidget(
+ tr("Specify dimension line location"), tr("Back"));
+ break;
+
+ case SetText:
+ RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
+ break;
+
+ case SetAngle:
+ RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), "");
+ break;
+
+ default:
+ RS_DIALOGFACTORY->updateMouseWidget("", "");
+ break;
+ }
+ }
}
+void RS_ActionDimLinear::showOptions()
+{
+ RS_ActionInterface::showOptions();
-
-void RS_ActionDimLinear::showOptions() {
- RS_ActionInterface::showOptions();
-
- if (RS_DIALOGFACTORY!=NULL) {
- RS_DIALOGFACTORY->requestOptions(this, true, true);
- }
+ if (RS_DIALOGFACTORY != NULL)
+ RS_DIALOGFACTORY->requestOptions(this, true, true);
}
+void RS_ActionDimLinear::hideOptions()
+{
+ RS_ActionInterface::hideOptions();
+ if (RS_DIALOGFACTORY != NULL)
+ RS_DIALOGFACTORY->requestOptions(this, false);
+}
-void RS_ActionDimLinear::hideOptions() {
- RS_ActionInterface::hideOptions();
-
- if (RS_DIALOGFACTORY!=NULL) {
- RS_DIALOGFACTORY->requestOptions(this, false);
- }
+double RS_ActionDimLinear::getAngle()
+{
+ return edata.angle;
}
+void RS_ActionDimLinear::setAngle(double a)
+{
+ edata.angle = a;
+}
+bool RS_ActionDimLinear::hasFixedAngle()
+{
+ return fixedAngle;
+}
-// EOF