1 /****************************************************************************
2 ** $Id: rs_actiondrawarctangential.cpp 1161 2004-12-09 23:10:09Z 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_actiondrawarctangential.h"
30 #include "rs_snapper.h"
31 #include "rs_dialogfactory.h"
35 RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_PreviewActionInterface("Draw arcs tangential",
38 container, graphicView) {
44 RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential() {}
47 QAction* RS_ActionDrawArcTangential::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
49 QAction * action = new QAction(tr("&Tangential"), 0);
50 // QAction* action = new QAction(tr("Arc: Tangential"),
52 // QKeySequence(), NULL);
53 action->setStatusTip(tr("Draw arcs tangential to base entity"));
58 void RS_ActionDrawArcTangential::reset() {
61 point = Vector(false);
66 void RS_ActionDrawArcTangential::init(int status) {
67 RS_PreviewActionInterface::init(status);
74 void RS_ActionDrawArcTangential::trigger() {
75 RS_PreviewActionInterface::trigger();
77 if (point.valid==false || baseEntity==NULL) {
78 RS_DEBUG->print("RS_ActionDrawArcTangential::trigger: "
79 "conditions not met");
84 RS_Arc* arc = new RS_Arc(container, data);
85 arc->setLayerToActive();
86 arc->setPenToActive();
87 container->addEntity(arc);
91 document->startUndoCycle();
92 document->addUndoable(arc);
93 document->endUndoCycle();
97 graphicView->moveRelativeZero(Vector(0.0,0.0));
98 graphicView->drawEntity(arc);
99 graphicView->moveRelativeZero(arc->getCenter());
102 setStatus(SetBaseEntity);
108 void RS_ActionDrawArcTangential::preparePreview() {
109 if (baseEntity!=NULL && point.valid) {
113 startPoint = baseEntity->getStartpoint();
114 direction = RS_Math::correctAngle(baseEntity->getDirection1()+M_PI);
116 startPoint = baseEntity->getEndpoint();
117 direction = RS_Math::correctAngle(baseEntity->getDirection2()+M_PI);
120 RS_Arc arc(NULL, RS_ArcData());
121 bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius);
123 data = arc.getData();
129 void RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent* e) {
130 switch (getStatus()) {
135 point = snapPoint(e);
137 if (data.isValid()) {
138 RS_Arc* arc = new RS_Arc(preview, data);
141 preview->addEntity(arc);
154 void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent* e) {
155 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
156 switch (getStatus()) {
159 case SetBaseEntity: {
160 Vector coord = graphicView->toGraph(e->x(), e->y());
161 RS_Entity* entity = catchEntity(coord, RS2::ResolveAll);
163 if (entity->isAtomic()) {
164 baseEntity = (RS_AtomicEntity*)entity;
165 if (baseEntity->getStartpoint().distanceTo(coord) <
166 baseEntity->getEndpoint().distanceTo(coord)) {
169 isStartPoint = false;
171 setStatus(SetEndAngle);
172 updateMouseButtonHints();
183 // set angle (point that defines the angle)
185 RS_CoordinateEvent ce(snapPoint(e));
186 coordinateEvent(&ce);
190 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
199 void RS_ActionDrawArcTangential::coordinateEvent(RS_CoordinateEvent* e) {
203 Vector mouse = e->getCoordinate();
205 switch (getStatus()) {
221 void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent* e) {
222 QString c = e->getCommand().toLower();
224 if (checkCommand("help", c)) {
225 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
226 + getAvailableCommands().join(", "));
233 QStringList RS_ActionDrawArcTangential::getAvailableCommands() {
239 void RS_ActionDrawArcTangential::showOptions() {
240 RS_ActionInterface::showOptions();
242 if (RS_DIALOGFACTORY!=NULL) {
243 RS_DIALOGFACTORY->requestOptions(this, true);
245 updateMouseButtonHints();
250 void RS_ActionDrawArcTangential::hideOptions() {
251 RS_ActionInterface::hideOptions();
253 if (RS_DIALOGFACTORY!=NULL) {
254 RS_DIALOGFACTORY->requestOptions(this, false);
260 void RS_ActionDrawArcTangential::updateMouseButtonHints() {
261 switch (getStatus()) {
263 RS_DIALOGFACTORY->updateMouseWidget(
264 tr("Specify base entity"),
268 RS_DIALOGFACTORY->updateMouseWidget(
269 tr("Specify end angle"), tr("Back"));
272 RS_DIALOGFACTORY->updateMouseWidget("", "");
279 void RS_ActionDrawArcTangential::updateMouseCursor() {
280 graphicView->setMouseCursor(RS2::CadCursor);
285 void RS_ActionDrawArcTangential::updateToolBar() {
287 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
289 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);