1 // rs_actionmodifytrim.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "rs_actionmodifytrim.h"
17 #include "rs_snapper.h"
20 * @param both Trim both entities.
22 RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer& container,
23 RS_GraphicView& graphicView, bool both)
24 :RS_PreviewActionInterface("Trim Entity",
25 container, graphicView) {
28 trimCoord = Vector(false);
30 limitCoord = Vector(false);
34 QAction * RS_ActionModifyTrim::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
41 case RS2::ActionModifyTrim:
42 action = new QAction(tr("&Trim"), 0);
43 // action = new QAction(tr("Trim"), tr("&Trim"),
44 // QKeySequence(), NULL);
45 action->setStatusTip(tr("Trim Entities"));
48 case RS2::ActionModifyTrim2:
49 action = new QAction(tr("&Trim Two"), 0);
50 // action = new QAction(tr("Trim Two"), tr("&Trim Two"),
51 // QKeySequence(), NULL);
52 action->setStatusTip(tr("Trim two Entities"));
60 void RS_ActionModifyTrim::init(int status) {
61 RS_ActionInterface::init(status);
63 snapMode = RS2::SnapFree;
64 snapRes = RS2::RestrictNothing;
70 void RS_ActionModifyTrim::trigger() {
72 RS_DEBUG->print("RS_ActionModifyTrim::trigger()");
74 if (trimEntity!=NULL && trimEntity->isAtomic() &&
75 limitEntity!=NULL /* && limitEntity->isAtomic()*/) {
77 RS_Modification m(*container, graphicView);
78 m.trim(trimCoord, (RS_AtomicEntity*)trimEntity,
79 limitCoord, /*(RS_AtomicEntity*)*/limitEntity,
84 limitEntity->setHighlighted(false);
85 graphicView->drawEntity(limitEntity);
86 setStatus(ChooseLimitEntity);
88 setStatus(ChooseTrimEntity);
91 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
97 void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent* e) {
98 RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin");
100 Vector mouse = graphicView->toGraph(e->x(), e->y());
101 RS_Entity* se = catchEntity(e);
103 switch (getStatus()) {
104 case ChooseLimitEntity:
109 case ChooseTrimEntity:
118 RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
123 void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent* e) {
124 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
126 Vector mouse = graphicView->toGraph(e->x(), e->y());
127 RS_Entity* se = catchEntity(e);
129 switch (getStatus()) {
130 case ChooseLimitEntity:
133 if (limitEntity!=NULL /*&& limitEntity->isAtomic()*/) {
134 limitEntity->setHighlighted(true);
135 graphicView->drawEntity(limitEntity);
136 setStatus(ChooseTrimEntity);
140 case ChooseTrimEntity:
143 if (trimEntity!=NULL && trimEntity->isAtomic()) {
151 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
154 if (limitEntity!=NULL) {
155 limitEntity->setHighlighted(false);
156 graphicView->drawEntity(limitEntity);
164 void RS_ActionModifyTrim::updateMouseButtonHints() {
165 switch (getStatus()) {
166 case ChooseLimitEntity:
168 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"),
171 RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"),
175 case ChooseTrimEntity:
177 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"),
180 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"),
185 RS_DIALOGFACTORY->updateMouseWidget("", "");
192 void RS_ActionModifyTrim::updateMouseCursor() {
193 graphicView->setMouseCursor(RS2::CadCursor);
198 void RS_ActionModifyTrim::updateToolBar() {
199 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);