]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioninfoangle.cpp
Initial import
[architektonas] / src / actions / rs_actioninfoangle.cpp
1 /****************************************************************************
2 ** $Id: rs_actioninfoangle.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
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.
12 **
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.
16 **
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.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actioninfoangle.h"
28
29 #include "rs_information.h"
30 #include "rs_snapper.h"
31
32
33
34 RS_ActionInfoAngle::RS_ActionInfoAngle(RS_EntityContainer& container,
35                                        RS_GraphicView& graphicView)
36         :RS_PreviewActionInterface("Info Angle",
37                            container, graphicView) {}
38
39
40 QAction * RS_ActionInfoAngle::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
41 {
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"));
47         return action;
48 }
49
50
51 void RS_ActionInfoAngle::init(int status) {
52     RS_ActionInterface::init(status);
53
54 }
55
56
57
58 void RS_ActionInfoAngle::trigger() {
59
60     RS_DEBUG->print("RS_ActionInfoAngle::trigger()");
61     deleteSnapper();
62
63     if (entity1!=NULL && entity2!=NULL) {
64         VectorSolutions sol =
65             RS_Information::getIntersection(entity1, entity2, false);
66
67         if (sol.hasValid()) {
68             intersection = sol.get(0);
69
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);
74
75                 QString str;
76                 str.sprintf("%.6f", RS_Math::rad2deg(angle));
77                 RS_DIALOGFACTORY->commandMessage(tr("Angle: %1%2")
78                                                  .arg(str).arg(QChar(0xB0)));
79             }
80         } else {
81             RS_DIALOGFACTORY->commandMessage(tr("Lines are parallel"));
82         }
83     }
84 }
85
86
87
88 void RS_ActionInfoAngle::mouseMoveEvent(QMouseEvent* /*e*/) {
89     RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent begin");
90
91     switch (getStatus()) {
92     case SetEntity1:
93         break;
94
95     case SetEntity2:
96         break;
97
98     default:
99         break;
100     }
101
102     RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent end");
103 }
104
105
106
107 void RS_ActionInfoAngle::mouseReleaseEvent(QMouseEvent* e) {
108     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
109
110         Vector mouse(graphicView->toGraphX(e->x()),
111                         graphicView->toGraphY(e->y()));
112
113         switch (getStatus()) {
114         case SetEntity1:
115             entity1 = catchEntity(e);
116             if (entity1!=NULL && entity1->rtti()==RS2::EntityLine) {
117                 point1 = entity1->getNearestPointOnEntity(mouse);
118                 setStatus(SetEntity2);
119             }
120             break;
121
122         case SetEntity2:
123             entity2 = catchEntity(e);
124             if (entity2!=NULL && entity2->rtti()==RS2::EntityLine) {
125                 point2 = entity2->getNearestPointOnEntity(mouse);
126                 trigger();
127                 setStatus(SetEntity1);
128             }
129             break;
130
131         default:
132             break;
133         }
134     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
135         deletePreview();
136         deleteSnapper();
137         init(getStatus()-1);
138     }
139 }
140
141
142
143 void RS_ActionInfoAngle::updateMouseButtonHints() {
144     switch (getStatus()) {
145     case SetEntity1:
146         RS_DIALOGFACTORY->updateMouseWidget(
147             tr("Specify first line"),
148             tr("Cancel"));
149         break;
150     case SetEntity2:
151         RS_DIALOGFACTORY->updateMouseWidget(
152             tr("Specify second line"),
153             tr("Back"));
154         break;
155     default:
156         RS_DIALOGFACTORY->updateMouseWidget("", "");
157         break;
158     }
159 }
160
161
162
163 void RS_ActionInfoAngle::updateMouseCursor() {
164     graphicView->setMouseCursor(RS2::CadCursor);
165 }
166
167
168
169 void RS_ActionInfoAngle::updateToolBar() {
170     switch (getStatus()) {
171     case SetEntity1:
172     case SetEntity2:
173         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
174         break;
175     default:
176         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
177         break;
178     }
179 }
180
181
182 // EOF