1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "rs_actionmodifycut.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_modification.h"
35
RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer& container,
36
RS_GraphicView& graphicView)
37
:RS_ActionInterface("Cut Entity",
38
container, graphicView) {
41
cutCoord = RS_Vector(false);
44
QAction* RS_ActionModifyCut::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
46
QAction *action = new QAction(tr("&Divide"), NULL);
47
action->setIcon(QIcon(":/extui/modifycut.png"));
48
//action->zetStatusTip(tr("Cut Entities"));
53
void RS_ActionModifyCut::init(int status) {
54
RS_ActionInterface::init(status);
59
void RS_ActionModifyCut::trigger() {
61
RS_DEBUG->print("RS_ActionModifyCut::trigger()");
63
if (cutEntity!=NULL && cutEntity->isAtomic() && cutCoord.valid &&
64
cutEntity->isPointOnEntity(cutCoord)) {
66
cutEntity->setHighlighted(false);
67
graphicView->drawEntity(cutEntity);
69
RS_Modification m(*container, graphicView);
70
m.cut(cutCoord, (RS_AtomicEntity*)cutEntity);
73
cutCoord = RS_Vector(false);
74
setStatus(ChooseCutEntity);
76
RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
82
void RS_ActionModifyCut::mouseMoveEvent(QMouseEvent* e) {
83
RS_DEBUG->print("RS_ActionModifyCut::mouseMoveEvent begin");
85
switch (getStatus()) {
97
RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
101
void RS_ActionModifyCut::mouseReleaseEvent(QMouseEvent* e) {
102
if (e->button()==Qt::LeftButton) {
103
switch (getStatus()) {
104
case ChooseCutEntity:
105
cutEntity = catchEntity(e);
106
if (cutEntity==NULL) {
107
RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
108
} else if (cutEntity->rtti()!=RS2::EntityLine &&
109
cutEntity->rtti()!=RS2::EntityArc &&
110
cutEntity->rtti()!=RS2::EntityCircle &&
111
cutEntity->rtti()!=RS2::EntityEllipse) {
113
RS_DIALOGFACTORY->commandMessage(
114
tr("Entity must be a line, arc, circle or ellipse."));
116
cutEntity->setHighlighted(true);
117
graphicView->drawEntity(cutEntity);
118
setStatus(SetCutCoord);
123
cutCoord = snapPoint(e);
124
if (cutEntity==NULL) {
125
RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
126
} else if (!cutCoord.valid) {
127
RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid."));
128
} else if (!cutEntity->isPointOnEntity(cutCoord)) {
129
RS_DIALOGFACTORY->commandMessage(
130
tr("Cutting point is not on entity."));
139
} else if (e->button()==Qt::RightButton) {
140
if (cutEntity!=NULL) {
141
cutEntity->setHighlighted(false);
142
graphicView->drawEntity(cutEntity);
150
void RS_ActionModifyCut::updateMouseButtonHints() {
151
switch (getStatus()) {
152
case ChooseCutEntity:
153
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"),
157
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"),
161
RS_DIALOGFACTORY->updateMouseWidget("", "");
168
void RS_ActionModifyCut::updateMouseCursor() {
169
graphicView->setMouseCursor(RS2::CadCursor);
174
//void RS_ActionModifyCut::updateToolBar() {
175
// //not needed any more with new snap
177
// switch (getStatus()) {
179
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
181
// case ChooseCutEntity:
183
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);