// 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
+// Portions copyright (C) 2001-2003 RibbonSoft
+// Copyright (C) 2010 Underground Software
+// See the README and GPLv2 files for licensing and warranty information
//
// JLH = James L. Hammons <jlhamm@acm.org>
//
#include "actiondrawlinebisector.h"
-#include "rs_commandevent.h"
-#include "rs_creation.h"
-#include "rs_dialogfactory.h"
+#include "commandevent.h"
+#include "creation.h"
+#include "debug.h"
+#include "dialogfactory.h"
#include "graphicview.h"
-#include "rs_preview.h"
+#include "preview.h"
-ActionDrawLineBisector::ActionDrawLineBisector(RS_EntityContainer & container, GraphicView & graphicView):
- ActionInterface("Draw Bisectors", container, graphicView)
+ActionDrawLineBisector::ActionDrawLineBisector(EntityContainer & container,
+ GraphicView & graphicView):
+ ActionInterface("Draw Bisectors", container, graphicView),
+ bisector(NULL), line1(NULL), line2(NULL), length(10.0), number(1),
+ coord1(Vector(false)), coord2(Vector(false)), lastStatus(SetLine1)
{
- bisector = NULL;
- length = 10.0;
- line1 = NULL;
- line2 = NULL;
- number = 1;
- coord1 = Vector(false);
- coord2 = Vector(false);
- lastStatus = SetLine1;
+ graphicView.snapper.SetVisible(false);
}
ActionDrawLineBisector::~ActionDrawLineBisector()
void ActionDrawLineBisector::trigger()
{
ActionInterface::trigger();
-
- //if (bisector!=NULL) {
- RS_Creation creation(container, graphicView);
- creation.createBisector(coord1,
- coord2,
- length,
- number,
- line1,
- line2);
- /*RS_Entity* newEntity = NULL;
-
- newEntity = new RS_Line(container,
- bisector->getData());
-
- if (newEntity!=NULL) {
- newEntity->setLayerToActive();
- newEntity->setPenToActive();
- container->addEntity(newEntity);
-
- // upd. undo list:
- if (document!=NULL) {
- document->startUndoCycle();
- document->addUndoable(newEntity);
- document->endUndoCycle();
- }
- graphicView->drawEntity(newEntity);
- setStatus(SetLine1);
- }
- //reset();
- delete bisector;
- bisector = NULL;
- */
- /*} else {
- RS_DEBUG->print("ActionDrawLineBisector::trigger:"
- " Entity is NULL\n");
- }*/
+ Creation creation(container, graphicView);
+ creation.createBisector(coord1, coord2, length, number, line1, line2);
+ graphicView->redraw();
}
void ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
{
- RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent begin");
+ DEBUG->print("ActionDrawLineBisector::mouseMoveEvent begin");
Vector mouse = Vector(graphicView->toGraphX(e->x()),
- graphicView->toGraphY(e->y()));
+ graphicView->toGraphY(e->y()));
switch (getStatus())
{
case SetLine2:
{
coord2 = mouse;
- RS_Entity * en = catchEntity(e, RS2::ResolveAll);
+ Entity * en = catchEntity(e, RS2::ResolveAll);
if (en && en->rtti() == RS2::EntityLine)
{
-// line2 = (RS_Line *)en;
-//
-// deletePreview();
-// clearPreview();
-//
-// RS_Creation creation(preview, NULL, false);
-// creation.createBisector(coord1, coord2, length, number, line1, line2);
-// drawPreview();
+ line2 = (Line *)en;
+ graphicView->preview.clear();
+ Creation creation(&(graphicView->preview), NULL, false);
+ creation.createBisector(coord1, coord2, length, number, line1, line2);
}
}
break;
break;
}
- RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent end");
+ graphicView->redraw();
+ DEBUG->print("ActionDrawLineBisector::mouseMoveEvent end");
}
void ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e)
{
if (e->button() == Qt::RightButton)
{
- deletePreview();
- clearPreview();
+// deletePreview();
+// clearPreview();
init(getStatus() - 1);
}
else
case SetLine1:
{
coord1 = mouse;
- RS_Entity * en = catchEntity(e, RS2::ResolveAll);
+ Entity * en = catchEntity(e, RS2::ResolveAll);
- if (en != NULL && en->rtti() == RS2::EntityLine)
- line1 = (RS_Line *)en;
+ if (en && en->rtti() == RS2::EntityLine)
+ {
+ line1 = (Line *)en;
+ setStatus(SetLine2);
+ }
}
- setStatus(SetLine2);
break;
case SetLine2:
}
}
-void ActionDrawLineBisector::commandEvent(RS_CommandEvent * e)
+void ActionDrawLineBisector::commandEvent(CommandEvent * e)
{
QString c = e->getCommand().toLower();
if (checkCommand("help", c))
{
- RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ getAvailableCommands().join(", "));
return;
}
if (checkCommand("length", c))
{
- deleteSnapper();
- deletePreview();
- clearPreview();
+// deleteSnapper();
+// deletePreview();
+// clearPreview();
setStatus(SetLength);
}
else if (checkCommand("number", c))
{
- deleteSnapper();
- deletePreview();
- clearPreview();
+// deleteSnapper();
+// deletePreview();
+// clearPreview();
setStatus(SetNumber);
}
+
break;
- case SetLength: {
+ case SetLength:
+ {
bool ok;
- double l = RS_Math::eval(c, &ok);
+ double l = Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
length = l;
else
- RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
- RS_DIALOGFACTORY->requestOptions(this, true, true);
+ DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+
+ DIALOGFACTORY->requestOptions(this, true, true);
setStatus(lastStatus);
}
- break;
+ break;
- case SetNumber: {
+ case SetNumber:
+ {
bool ok;
- int n = (int)RS_Math::eval(c, &ok);
+ int n = (int)Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
number = n;
else
- RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
- RS_DIALOGFACTORY->requestOptions(this, true, true);
+ DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+
+ DIALOGFACTORY->requestOptions(this, true, true);
setStatus(lastStatus);
}
- break;
+ break;
default:
break;
switch (getStatus())
{
case SetLine1:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
- tr("Cancel"));
+ DIALOGFACTORY->updateMouseWidget(tr("Select first line"), tr("Cancel"));
break;
case SetLine2:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
- tr("Back"));
+ DIALOGFACTORY->updateMouseWidget(tr("Select second line"), tr("Back"));
break;
case SetLength:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"),
- tr("Back"));
+ DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"), tr("Back"));
break;
case SetNumber:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"),
- tr("Back"));
+ DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"), tr("Back"));
break;
default:
- RS_DIALOGFACTORY->updateMouseWidget("", "");
+ DIALOGFACTORY->updateMouseWidget("", "");
break;
}
}
void ActionDrawLineBisector::showOptions()
{
ActionInterface::showOptions();
-
- RS_DIALOGFACTORY->requestOptions(this, true);
+ DIALOGFACTORY->requestOptions(this, true);
}
void ActionDrawLineBisector::hideOptions()
{
ActionInterface::hideOptions();
-
- RS_DIALOGFACTORY->requestOptions(this, false);
+ DIALOGFACTORY->requestOptions(this, false);
}
void ActionDrawLineBisector::updateMouseCursor()
void ActionDrawLineBisector::updateToolBar()
{
- RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
+ DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
}
void ActionDrawLineBisector::setLength(double l)