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_actiondrawlinetangent2.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_creation.h"
36
RS_ActionDrawLineTangent2::RS_ActionDrawLineTangent2(
37
RS_EntityContainer& container,
38
RS_GraphicView& graphicView)
39
:RS_PreviewActionInterface("Draw Tangents 2", container, graphicView),
47
circleType<<RS2::EntityArc<<RS2::EntityCircle<<RS2::EntityEllipse;
48
setStatus(SetCircle1);
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)"));
60
//void RS_ActionDrawLineTangent2::init(int status) {
61
// RS_PreviewActionInterface::init(status);
62
// circle1->setHighlighted(false);
63
// graphicView->redraw(RS2::RedrawDrawing);
66
void RS_ActionDrawLineTangent2::finish(bool updateTB){
68
circle1->setHighlighted(false);
69
graphicView->redraw(RS2::RedrawDrawing);
71
RS_PreviewActionInterface::finish(updateTB);
74
void RS_ActionDrawLineTangent2::trigger() {
75
RS_PreviewActionInterface::trigger();
77
RS_Entity* newEntity = NULL;
79
newEntity = new RS_Line(container, lineData);
81
if (newEntity!=NULL) {
82
newEntity->setLayerToActive();
83
newEntity->setPenToActive();
84
container->addEntity(newEntity);
88
document->startUndoCycle();
89
document->addUndoable(newEntity);
90
document->endUndoCycle();
93
circle1->setHighlighted(false);
94
graphicView->redraw(RS2::RedrawDrawing);
98
setStatus(SetCircle1);
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
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,
123
if(tangent.get()==NULL) {
128
lineData=tangent->getData();
131
preview->addEntity(new RS_Line(preview, lineData));
137
void RS_ActionDrawLineTangent2::mouseReleaseEvent(QMouseEvent* e) {
139
if (e->button()==Qt::RightButton) {
144
circle1->setHighlighted(false);
145
graphicView->redraw(RS2::RedrawDrawing);
151
switch (getStatus()) {
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
163
circle1->setHighlighted(true);
164
setStatus(getStatus()+1);
165
graphicView->redraw(RS2::RedrawDrawing);
178
void RS_ActionDrawLineTangent2::updateMouseButtonHints() {
179
if (RS_DIALOGFACTORY!=NULL) {
180
switch (getStatus()) {
182
RS_DIALOGFACTORY->updateMouseWidget(tr("Select first circle or ellipse"),
186
RS_DIALOGFACTORY->updateMouseWidget(tr("Select second circle or ellipse"),
190
RS_DIALOGFACTORY->updateMouseWidget("", "");
198
void RS_ActionDrawLineTangent2::updateMouseCursor() {
199
graphicView->setMouseCursor(RS2::CadCursor);
204
//void RS_ActionDrawLineTangent2::updateToolBar() {
205
// if (RS_DIALOGFACTORY!=NULL) {
206
// if (isFinished()) {
207
// RS_DIALOGFACTORY->resetToolBar();