#include "rs_actionmodifytrim.h"
-#include "rs_snapper.h"
+#include "rs_dialogfactory.h"
+#include "rs_modification.h"
/**
* @param both Trim both entities.
*/
-RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer& container,
- RS_GraphicView& graphicView, bool both)
- :RS_PreviewActionInterface("Trim Entity",
- container, graphicView) {
-
- trimEntity = NULL;
- trimCoord = Vector(false);
- limitEntity = NULL;
- limitCoord = Vector(false);
- this->both = both;
+RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer & container,
+ GraphicView & graphicView, bool both): RS_PreviewActionInterface("Trim Entity",
+ container, graphicView)
+{
+ trimEntity = NULL;
+ trimCoord = Vector(false);
+ limitEntity = NULL;
+ limitCoord = Vector(false);
+ this->both = both;
}
-QAction * RS_ActionModifyTrim::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
+RS_ActionModifyTrim::~RS_ActionModifyTrim()
{
- QAction * action;
-
- switch (type)
- {
- default:
- case RS2::ActionModifyTrim:
- action = new QAction(tr("&Trim"), 0);
-// action = new QAction(tr("Trim"), tr("&Trim"),
-// QKeySequence(), NULL);
- action->setStatusTip(tr("Trim Entities"));
- break;
-
- case RS2::ActionModifyTrim2:
- action = new QAction(tr("&Trim Two"), 0);
-// action = new QAction(tr("Trim Two"), tr("&Trim Two"),
-// QKeySequence(), NULL);
- action->setStatusTip(tr("Trim two Entities"));
- break;
- }
-
- return action;
}
+void RS_ActionModifyTrim::init(int status)
+{
+ RS_ActionInterface::init(status);
-void RS_ActionModifyTrim::init(int status) {
- RS_ActionInterface::init(status);
-
- snapMode = RS2::SnapFree;
- snapRes = RS2::RestrictNothing;
-
+ snapMode = RS2::SnapFree;
+ snapRes = RS2::RestrictNothing;
}
+void RS_ActionModifyTrim::trigger()
+{
+ RS_DEBUG->print("RS_ActionModifyTrim::trigger()");
-
-void RS_ActionModifyTrim::trigger() {
-
- RS_DEBUG->print("RS_ActionModifyTrim::trigger()");
-
- if (trimEntity!=NULL && trimEntity->isAtomic() &&
- limitEntity!=NULL /* && limitEntity->isAtomic()*/) {
-
- RS_Modification m(*container, graphicView);
- m.trim(trimCoord, (RS_AtomicEntity*)trimEntity,
- limitCoord, /*(RS_AtomicEntity*)*/limitEntity,
- both);
-
- trimEntity = NULL;
- if (both) {
- limitEntity->setHighlighted(false);
- graphicView->drawEntity(limitEntity);
- setStatus(ChooseLimitEntity);
- } else {
- setStatus(ChooseTrimEntity);
- }
-
- RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
- }
+ if (trimEntity != NULL && trimEntity->isAtomic()
+ && limitEntity != NULL /* && limitEntity->isAtomic()*/)
+ {
+ RS_Modification m(*container, graphicView);
+ m.trim(trimCoord, (RS_AtomicEntity *)trimEntity,
+ limitCoord, /*(RS_AtomicEntity*)*/ limitEntity,
+ both);
+
+ trimEntity = NULL;
+
+ if (both)
+ {
+ limitEntity->setHighlighted(false);
+ graphicView->drawEntity(limitEntity);
+ setStatus(ChooseLimitEntity);
+ }
+ else
+ setStatus(ChooseTrimEntity);
+
+ RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
+ }
}
+void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent * e)
+{
+ RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin");
+ Vector mouse = graphicView->toGraph(e->x(), e->y());
+ RS_Entity * se = catchEntity(e);
-void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent* e) {
- RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin");
-
- Vector mouse = graphicView->toGraph(e->x(), e->y());
- RS_Entity* se = catchEntity(e);
-
- switch (getStatus()) {
- case ChooseLimitEntity:
- limitCoord = mouse;
- limitEntity = se;
- break;
+ switch (getStatus())
+ {
+ case ChooseLimitEntity:
+ limitCoord = mouse;
+ limitEntity = se;
+ break;
- case ChooseTrimEntity:
- trimCoord = mouse;
- trimEntity = se;
- break;
+ case ChooseTrimEntity:
+ trimCoord = mouse;
+ trimEntity = se;
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
+ RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
}
-
-
-void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent* e) {
- if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-
- Vector mouse = graphicView->toGraph(e->x(), e->y());
- RS_Entity* se = catchEntity(e);
-
- switch (getStatus()) {
- case ChooseLimitEntity:
- limitCoord = mouse;
- limitEntity = se;
- if (limitEntity!=NULL /*&& limitEntity->isAtomic()*/) {
- limitEntity->setHighlighted(true);
- graphicView->drawEntity(limitEntity);
- setStatus(ChooseTrimEntity);
- }
- break;
-
- case ChooseTrimEntity:
- trimCoord = mouse;
- trimEntity = se;
- if (trimEntity!=NULL && trimEntity->isAtomic()) {
- trigger();
- }
- break;
-
- default:
- break;
- }
- } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
- deletePreview();
- deleteSnapper();
- if (limitEntity!=NULL) {
- limitEntity->setHighlighted(false);
- graphicView->drawEntity(limitEntity);
- }
- init(getStatus()-1);
- }
+void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
+{
+ if (e->button() == Qt::LeftButton)
+ {
+ Vector mouse = graphicView->toGraph(e->x(), e->y());
+ RS_Entity * se = catchEntity(e);
+
+ switch (getStatus())
+ {
+ case ChooseLimitEntity:
+ limitCoord = mouse;
+ limitEntity = se;
+
+ if (limitEntity != NULL /*&& limitEntity->isAtomic()*/)
+ {
+ limitEntity->setHighlighted(true);
+ graphicView->drawEntity(limitEntity);
+ setStatus(ChooseTrimEntity);
+ }
+ break;
+
+ case ChooseTrimEntity:
+ trimCoord = mouse;
+ trimEntity = se;
+
+ if (trimEntity != NULL && trimEntity->isAtomic())
+ trigger();
+ break;
+
+ default:
+ break;
+ }
+ }
+ else if (e->button() == Qt::RightButton)
+ {
+ deletePreview();
+ deleteSnapper();
+
+ if (limitEntity != NULL)
+ {
+ limitEntity->setHighlighted(false);
+ graphicView->drawEntity(limitEntity);
+ }
+ init(getStatus() - 1);
+ }
}
+void RS_ActionModifyTrim::updateMouseButtonHints()
+{
+ switch (getStatus())
+ {
+ case ChooseLimitEntity:
+
+ if (both)
+ RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"),
+ tr("Cancel"));
+ else
+ RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"),
+ tr("Back"));
+ break;
+ case ChooseTrimEntity:
-void RS_ActionModifyTrim::updateMouseButtonHints() {
- switch (getStatus()) {
- case ChooseLimitEntity:
- if (both) {
- RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"),
- tr("Cancel"));
- } else {
- RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"),
- tr("Back"));
- }
- break;
- case ChooseTrimEntity:
- if (both) {
- RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"),
- tr("Cancel"));
- } else {
- RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"),
- tr("Back"));
- }
- break;
- default:
- RS_DIALOGFACTORY->updateMouseWidget("", "");
- break;
- }
-}
-
-
+ if (both)
+ RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"),
+ tr("Cancel"));
+ else
+ RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"),
+ tr("Back"));
+ break;
-void RS_ActionModifyTrim::updateMouseCursor() {
- graphicView->setMouseCursor(RS2::CadCursor);
+ default:
+ RS_DIALOGFACTORY->updateMouseWidget("", "");
+ break;
+ }
}
-
-
-void RS_ActionModifyTrim::updateToolBar() {
- RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
+void RS_ActionModifyTrim::updateMouseCursor()
+{
+ graphicView->setMouseCursor(RS2::CadCursor);
}
+void RS_ActionModifyTrim::updateToolBar()
+{
+ RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
+}