~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/actions/rs_actionmodifycut.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
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.
 
13
**
 
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.
 
18
**
 
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
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
#include "rs_actionmodifycut.h"
 
28
 
 
29
#include <QAction>
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
#include "rs_modification.h"
 
33
 
 
34
 
 
35
RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer& container,
 
36
                                       RS_GraphicView& graphicView)
 
37
        :RS_ActionInterface("Cut Entity",
 
38
                    container, graphicView) {
 
39
 
 
40
    cutEntity = NULL;
 
41
    cutCoord = RS_Vector(false);
 
42
}
 
43
 
 
44
QAction* RS_ActionModifyCut::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
 
45
        // tr("Divide")
 
46
        QAction *action = new QAction(tr("&Divide"), NULL);
 
47
        action->setIcon(QIcon(":/extui/modifycut.png"));
 
48
        //action->zetStatusTip(tr("Cut Entities"));
 
49
    return action;
 
50
}
 
51
 
 
52
 
 
53
void RS_ActionModifyCut::init(int status) {
 
54
    RS_ActionInterface::init(status);
 
55
}
 
56
 
 
57
 
 
58
 
 
59
void RS_ActionModifyCut::trigger() {
 
60
 
 
61
    RS_DEBUG->print("RS_ActionModifyCut::trigger()");
 
62
 
 
63
    if (cutEntity!=NULL && cutEntity->isAtomic() && cutCoord.valid &&
 
64
            cutEntity->isPointOnEntity(cutCoord)) {
 
65
 
 
66
        cutEntity->setHighlighted(false);
 
67
        graphicView->drawEntity(cutEntity);
 
68
 
 
69
        RS_Modification m(*container, graphicView);
 
70
        m.cut(cutCoord, (RS_AtomicEntity*)cutEntity);
 
71
 
 
72
        cutEntity = NULL;
 
73
        cutCoord = RS_Vector(false);
 
74
        setStatus(ChooseCutEntity);
 
75
 
 
76
        RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
 
77
    }
 
78
}
 
79
 
 
80
 
 
81
 
 
82
void RS_ActionModifyCut::mouseMoveEvent(QMouseEvent* e) {
 
83
    RS_DEBUG->print("RS_ActionModifyCut::mouseMoveEvent begin");
 
84
 
 
85
    switch (getStatus()) {
 
86
    case ChooseCutEntity:
 
87
        break;
 
88
 
 
89
    case SetCutCoord:
 
90
        snapPoint(e);
 
91
        break;
 
92
 
 
93
    default:
 
94
        break;
 
95
    }
 
96
 
 
97
    RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
 
98
}
 
99
 
 
100
 
 
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) {
 
112
 
 
113
                RS_DIALOGFACTORY->commandMessage(
 
114
                    tr("Entity must be a line, arc, circle or ellipse."));
 
115
            } else {
 
116
                cutEntity->setHighlighted(true);
 
117
                graphicView->drawEntity(cutEntity);
 
118
                setStatus(SetCutCoord);
 
119
            }
 
120
            break;
 
121
 
 
122
        case 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."));
 
131
            } else {
 
132
                trigger();
 
133
            }
 
134
            break;
 
135
 
 
136
        default:
 
137
            break;
 
138
        }
 
139
    } else if (e->button()==Qt::RightButton) {
 
140
        if (cutEntity!=NULL) {
 
141
            cutEntity->setHighlighted(false);
 
142
            graphicView->drawEntity(cutEntity);
 
143
        }
 
144
        init(getStatus()-1);
 
145
    }
 
146
}
 
147
 
 
148
 
 
149
 
 
150
void RS_ActionModifyCut::updateMouseButtonHints() {
 
151
    switch (getStatus()) {
 
152
    case ChooseCutEntity:
 
153
        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"),
 
154
                                            tr("Cancel"));
 
155
        break;
 
156
    case SetCutCoord:
 
157
        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"),
 
158
                                            tr("Back"));
 
159
        break;
 
160
    default:
 
161
        RS_DIALOGFACTORY->updateMouseWidget("", "");
 
162
        break;
 
163
    }
 
164
}
 
165
 
 
166
 
 
167
 
 
168
void RS_ActionModifyCut::updateMouseCursor() {
 
169
    graphicView->setMouseCursor(RS2::CadCursor);
 
170
}
 
171
 
 
172
 
 
173
 
 
174
//void RS_ActionModifyCut::updateToolBar() {
 
175
//    //not needed any more with new snap
 
176
//    return;
 
177
//    switch (getStatus()) {
 
178
//    case SetCutCoord:
 
179
//        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
 
180
//        break;
 
181
//    case ChooseCutEntity:
 
182
//    default:
 
183
//        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
 
184
//        break;
 
185
//    }
 
186
//}
 
187
 
 
188
 
 
189
// EOF