1 /****************************************************************************
2 ** $Id: rs_actioninfoangle.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_actioninfoangle.h"
29 #include "rs_information.h"
30 #include "rs_snapper.h"
34 RS_ActionInfoAngle::RS_ActionInfoAngle(RS_EntityContainer& container,
35 RS_GraphicView& graphicView)
36 :RS_PreviewActionInterface("Info Angle",
37 container, graphicView) {}
40 QAction * RS_ActionInfoAngle::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
42 QAction * action = new QAction(tr("&Angle between two lines"), 0);
43 // QAction* action = new QAction(tr("Angle between two lines"),
44 // tr("&Angle between two lines"),
45 // QKeySequence(), NULL);
46 action->setStatusTip(tr("Measures the angle between two lines"));
51 void RS_ActionInfoAngle::init(int status) {
52 RS_ActionInterface::init(status);
58 void RS_ActionInfoAngle::trigger() {
60 RS_DEBUG->print("RS_ActionInfoAngle::trigger()");
63 if (entity1!=NULL && entity2!=NULL) {
65 RS_Information::getIntersection(entity1, entity2, false);
68 intersection = sol.get(0);
70 if (intersection.valid && point1.valid && point2.valid) {
71 double angle1 = intersection.angleTo(point1);
72 double angle2 = intersection.angleTo(point2);
73 double angle = fabs(angle2-angle1);
76 str.sprintf("%.6f", RS_Math::rad2deg(angle));
77 RS_DIALOGFACTORY->commandMessage(tr("Angle: %1%2")
78 .arg(str).arg(QChar(0xB0)));
81 RS_DIALOGFACTORY->commandMessage(tr("Lines are parallel"));
88 void RS_ActionInfoAngle::mouseMoveEvent(QMouseEvent* /*e*/) {
89 RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent begin");
91 switch (getStatus()) {
102 RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent end");
107 void RS_ActionInfoAngle::mouseReleaseEvent(QMouseEvent* e) {
108 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
110 Vector mouse(graphicView->toGraphX(e->x()),
111 graphicView->toGraphY(e->y()));
113 switch (getStatus()) {
115 entity1 = catchEntity(e);
116 if (entity1!=NULL && entity1->rtti()==RS2::EntityLine) {
117 point1 = entity1->getNearestPointOnEntity(mouse);
118 setStatus(SetEntity2);
123 entity2 = catchEntity(e);
124 if (entity2!=NULL && entity2->rtti()==RS2::EntityLine) {
125 point2 = entity2->getNearestPointOnEntity(mouse);
127 setStatus(SetEntity1);
134 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
143 void RS_ActionInfoAngle::updateMouseButtonHints() {
144 switch (getStatus()) {
146 RS_DIALOGFACTORY->updateMouseWidget(
147 tr("Specify first line"),
151 RS_DIALOGFACTORY->updateMouseWidget(
152 tr("Specify second line"),
156 RS_DIALOGFACTORY->updateMouseWidget("", "");
163 void RS_ActionInfoAngle::updateMouseCursor() {
164 graphicView->setMouseCursor(RS2::CadCursor);
169 void RS_ActionInfoAngle::updateToolBar() {
170 switch (getStatus()) {
173 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
176 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);