]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondimension.cpp
d4d3c66aa5c72f48b567bd336a2b150fc73e41f9
[architektonas] / src / actions / actiondimension.cpp
1 // actiondimension.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/03/2010  Added this text. :-)
13 //
14
15 #include "actiondimension.h"
16
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19
20 ActionDimension::ActionDimension(const char * name, RS_EntityContainer & container, GraphicView & graphicView):
21         ActionInterface(name, container, graphicView)
22 {
23         reset();
24 }
25
26 ActionDimension::~ActionDimension()
27 {
28 }
29
30 void ActionDimension::reset()
31 {
32         data = RS_DimensionData(Vector(false), Vector(false), RS2::VAlignMiddle,
33                         RS2::HAlignCenter, RS2::Exact, 1.0, "", "Standard", 0.0);
34         diameter = false;
35 }
36
37 void ActionDimension::init(int status)
38 {
39         ActionInterface::init(status);
40 }
41
42 void ActionDimension::hideOptions()
43 {
44         ActionInterface::hideOptions();
45
46         if (RS_DIALOGFACTORY != NULL)
47                 RS_DIALOGFACTORY->requestOptions(this, false);
48 }
49
50 void ActionDimension::showOptions()
51 {
52         ActionInterface::showOptions();
53
54         if (RS_DIALOGFACTORY != NULL)
55                 RS_DIALOGFACTORY->requestOptions(this, true, true);
56 }
57
58 void ActionDimension::updateMouseCursor()
59 {
60         graphicView->setMouseCursor(RS2::CadCursor);
61 }
62
63 void ActionDimension::updateToolBar()
64 {
65         if (RS_DIALOGFACTORY != NULL)
66         {
67                 if (!isFinished())
68                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
69                 else
70                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);
71         }
72 }
73
74 QString ActionDimension::getText()
75 {
76         if (!data.text.isEmpty())
77                 return data.text;
78
79         QString l = label;
80
81         if (l.isEmpty() && (diameter || !tol1.isEmpty() || !tol2.isEmpty()))
82                 l = "<>";
83
84         if (diameter)
85                 l = QChar(0x2205) + l;
86
87         if (!tol1.isEmpty() || !tol2.isEmpty())
88                 l += QString("\\S%1\\%2;").arg(tol1).arg(tol2);
89
90         return l;
91 }
92
93 void ActionDimension::setText(const QString & t)
94 {
95         data.text = t;
96 }
97
98 QString ActionDimension::getLabel()
99 {
100         return label;
101 }
102
103 void ActionDimension::setLabel(const QString & t)
104 {
105         label = t;
106 }
107
108 QString ActionDimension::getTol1()
109 {
110         return tol1;
111 }
112
113 void ActionDimension::setTol1(const QString & t)
114 {
115         tol1 = t;
116 }
117
118 QString ActionDimension::getTol2()
119 {
120         return tol2;
121 }
122
123 void ActionDimension::setTol2(const QString & t)
124 {
125         tol2 = t;
126 }
127
128 bool ActionDimension::getDiameter()
129 {
130         return diameter;
131 }
132
133 void ActionDimension::setDiameter(bool d)
134 {
135         diameter = d;
136 }
137
138 /*static*/ bool ActionDimension::isDimensionAction(RS2::ActionType type)
139 {
140         return (type == RS2::ActionDimAligned
141                 || type == RS2::ActionDimLinear
142                 || type == RS2::ActionDimAngular
143                 || type == RS2::ActionDimDiametric
144                 || type == RS2::ActionDimRadial);
145 }
146