1 /****************************************************************************
2 ** $Id: rs_actiondrawlinetangent1.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actiondrawlinetangent1.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
34 RS_ActionDrawLineTangent1::RS_ActionDrawLineTangent1(
35 RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_PreviewActionInterface("Draw Tangents 1", container, graphicView) {
40 point = Vector(false);
45 QAction* RS_ActionDrawLineTangent1::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
47 QAction * action = new QAction(tr("&Tangent (P,C)"), 0);
48 // QAction* action = new QAction(tr("Tangent (P,C)"), tr("&Tangent (P,C)"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Draw tangent (point, circle)"));
54 void RS_ActionDrawLineTangent1::trigger() {
55 RS_PreviewActionInterface::trigger();
58 RS_Entity* newEntity = NULL;
60 newEntity = new RS_Line(container,
63 if (newEntity!=NULL) {
64 newEntity->setLayerToActive();
65 newEntity->setPenToActive();
66 container->addEntity(newEntity);
70 document->startUndoCycle();
71 document->addUndoable(newEntity);
72 document->endUndoCycle();
76 graphicView->drawEntity(newEntity);
83 RS_DEBUG->print("RS_ActionDrawLineTangent1::trigger:"
90 void RS_ActionDrawLineTangent1::mouseMoveEvent(QMouseEvent* e) {
91 RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent begin");
93 Vector mouse(graphicView->toGraphX(e->x()),
94 graphicView->toGraphY(e->y()));
96 switch (getStatus()) {
102 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
103 if (en!=NULL && (en->rtti()==RS2::EntityCircle ||
104 en->rtti()==RS2::EntityArc ||
105 en->rtti()==RS2::EntityEllipse)) {
108 RS_Creation creation(NULL, NULL);
109 RS_Line* t = creation.createTangent1(mouse,
117 tangent = (RS_Line*)t->clone();
121 preview->addEntity(t);
132 RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent end");
137 void RS_ActionDrawLineTangent1::mouseReleaseEvent(QMouseEvent* e) {
139 if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
145 switch (getStatus()) {
147 RS_CoordinateEvent ce(snapPoint(e));
148 coordinateEvent(&ce);
161 void RS_ActionDrawLineTangent1::coordinateEvent(RS_CoordinateEvent* e) {
166 switch (getStatus()) {
168 point = e->getCoordinate();
170 graphicView->moveRelativeZero(point);
171 setStatus(SetCircle);
180 void RS_ActionDrawLineTangent1::updateMouseButtonHints() {
181 if (RS_DIALOGFACTORY!=NULL) {
182 switch (getStatus()) {
184 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"),
188 RS_DIALOGFACTORY->updateMouseWidget(tr("Select circle, arc or ellipse"),
192 RS_DIALOGFACTORY->updateMouseWidget("", "");
200 void RS_ActionDrawLineTangent1::updateMouseCursor() {
201 graphicView->setMouseCursor(RS2::CadCursor);
206 void RS_ActionDrawLineTangent1::updateToolBar() {
207 if (RS_DIALOGFACTORY!=NULL) {
209 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
211 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);