~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/actions/rs_actiondrawlinetangent2.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_actiondrawlinetangent2.h"
 
28
 
 
29
#include <QAction>
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
#include "rs_creation.h"
 
33
 
 
34
 
 
35
 
 
36
RS_ActionDrawLineTangent2::RS_ActionDrawLineTangent2(
 
37
    RS_EntityContainer& container,
 
38
    RS_GraphicView& graphicView)
 
39
        :RS_PreviewActionInterface("Draw Tangents 2", container, graphicView),
 
40
          valid(false)
 
41
{
 
42
 
 
43
    circle1 = NULL;
 
44
    circle2 = NULL;
 
45
 
 
46
    circleType.clear();
 
47
    circleType<<RS2::EntityArc<<RS2::EntityCircle<<RS2::EntityEllipse;
 
48
    setStatus(SetCircle1);
 
49
}
 
50
 
 
51
QAction* RS_ActionDrawLineTangent2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
 
52
        // tr("Tan&gent (C,C)"),
 
53
    QAction* action = new QAction(tr("Tangent (C,C)"), NULL);
 
54
        action->setIcon(QIcon(":/extui/linestan2.png"));
 
55
    //action->zetStatusTip(tr("Draw tangent (circle, circle)"));
 
56
 
 
57
    return action;
 
58
}
 
59
 
 
60
//void RS_ActionDrawLineTangent2::init(int status) {
 
61
//    RS_PreviewActionInterface::init(status);
 
62
//    circle1->setHighlighted(false);
 
63
//    graphicView->redraw(RS2::RedrawDrawing);
 
64
//}
 
65
 
 
66
void RS_ActionDrawLineTangent2::finish(bool updateTB){
 
67
    if(circle1!=NULL){
 
68
        circle1->setHighlighted(false);
 
69
        graphicView->redraw(RS2::RedrawDrawing);
 
70
    }
 
71
    RS_PreviewActionInterface::finish(updateTB);
 
72
}
 
73
 
 
74
void RS_ActionDrawLineTangent2::trigger() {
 
75
    RS_PreviewActionInterface::trigger();
 
76
 
 
77
    RS_Entity* newEntity = NULL;
 
78
 
 
79
    newEntity = new RS_Line(container, lineData);
 
80
 
 
81
    if (newEntity!=NULL) {
 
82
        newEntity->setLayerToActive();
 
83
        newEntity->setPenToActive();
 
84
        container->addEntity(newEntity);
 
85
 
 
86
        // upd. undo list:
 
87
        if (document!=NULL) {
 
88
            document->startUndoCycle();
 
89
            document->addUndoable(newEntity);
 
90
            document->endUndoCycle();
 
91
        }
 
92
        if(circle1!=NULL){
 
93
            circle1->setHighlighted(false);
 
94
            graphicView->redraw(RS2::RedrawDrawing);
 
95
            circle1=NULL;
 
96
        }
 
97
 
 
98
        setStatus(SetCircle1);
 
99
    }
 
100
    tangent.reset();
 
101
}
 
102
 
 
103
 
 
104
 
 
105
void RS_ActionDrawLineTangent2::mouseMoveEvent(QMouseEvent* e) {
 
106
//    RS_DEBUG->print("RS_ActionDrawLineTangent2::mouseMoveEvent begin");
 
107
    if(getStatus() != SetCircle2) return;
 
108
    circle2= catchEntity(e, circleType, RS2::ResolveAll);
 
109
    if(circle2==NULL) return;
 
110
    if(circle2->rtti()!=RS2::EntityCircle &&
 
111
            circle2->rtti()!=RS2::EntityEllipse &&
 
112
            circle2->rtti()!=RS2::EntityArc
 
113
            ) {
 
114
        circle2=NULL;
 
115
        return;
 
116
    }
 
117
    RS_Creation creation(NULL, NULL);
 
118
    RS_Vector mouse(graphicView->toGraphX(e->x()),
 
119
                    graphicView->toGraphY(e->y()));
 
120
    tangent.reset(creation.createTangent2(mouse,
 
121
                                          circle1,
 
122
                                          circle2));
 
123
    if(tangent.get()==NULL) {
 
124
        valid=false;
 
125
        return;
 
126
    }
 
127
    valid=true;
 
128
    lineData=tangent->getData();
 
129
 
 
130
    deletePreview();
 
131
    preview->addEntity(new RS_Line(preview, lineData));
 
132
    drawPreview();
 
133
}
 
134
 
 
135
 
 
136
 
 
137
void RS_ActionDrawLineTangent2::mouseReleaseEvent(QMouseEvent* e) {
 
138
 
 
139
    if (e->button()==Qt::RightButton) {
 
140
        deletePreview();
 
141
        if(getStatus()>=0){
 
142
            init(getStatus()-1);
 
143
            if(circle1!=NULL){
 
144
                circle1->setHighlighted(false);
 
145
                graphicView->redraw(RS2::RedrawDrawing);
 
146
                deletePreview();
 
147
            }
 
148
        }
 
149
        return;
 
150
    }
 
151
    switch (getStatus()) {
 
152
    case SetCircle1:
 
153
    {
 
154
        circle1 = catchEntity(e, circleType, RS2::ResolveAll);
 
155
        if(circle1==NULL) return;
 
156
        if(circle1->rtti()!=RS2::EntityCircle &&
 
157
                circle1->rtti()!=RS2::EntityEllipse &&
 
158
                circle1->rtti()!=RS2::EntityArc
 
159
                ) {
 
160
            circle1=NULL;
 
161
            return;
 
162
        }
 
163
        circle1->setHighlighted(true);
 
164
        setStatus(getStatus()+1);
 
165
        graphicView->redraw(RS2::RedrawDrawing);
 
166
    }
 
167
        break;
 
168
 
 
169
    case SetCircle2:
 
170
        if(valid) trigger();
 
171
        break;
 
172
    }
 
173
 
 
174
}
 
175
 
 
176
 
 
177
 
 
178
void RS_ActionDrawLineTangent2::updateMouseButtonHints() {
 
179
    if (RS_DIALOGFACTORY!=NULL) {
 
180
        switch (getStatus()) {
 
181
        case SetCircle1:
 
182
            RS_DIALOGFACTORY->updateMouseWidget(tr("Select first circle or ellipse"),
 
183
                                                tr("Cancel"));
 
184
            break;
 
185
        case SetCircle2:
 
186
            RS_DIALOGFACTORY->updateMouseWidget(tr("Select second circle or ellipse"),
 
187
                                                tr("Back"));
 
188
            break;
 
189
        default:
 
190
            RS_DIALOGFACTORY->updateMouseWidget("", "");
 
191
            break;
 
192
        }
 
193
    }
 
194
}
 
195
 
 
196
 
 
197
 
 
198
void RS_ActionDrawLineTangent2::updateMouseCursor() {
 
199
    graphicView->setMouseCursor(RS2::CadCursor);
 
200
}
 
201
 
 
202
 
 
203
 
 
204
//void RS_ActionDrawLineTangent2::updateToolBar() {
 
205
//    if (RS_DIALOGFACTORY!=NULL) {
 
206
//        if (isFinished()) {
 
207
//            RS_DIALOGFACTORY->resetToolBar();
 
208
//        }
 
209
//    }
 
210
//}
 
211
 
 
212
 
 
213
 
 
214
// EOF