]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondimension.cpp
864b771065123aeeda2e805def4154259dfe87e5
[architektonas] / src / actions / rs_actiondimension.cpp
1 // rs_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 "rs_actiondimension.h"
16
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19
20 RS_ActionDimension::RS_ActionDimension(const char * name, RS_EntityContainer & container, GraphicView & graphicView):
21         RS_PreviewActionInterface(name, container, graphicView)
22 {
23         reset();
24 }
25
26 RS_ActionDimension::~RS_ActionDimension()
27 {
28 }
29
30 void RS_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 RS_ActionDimension::init(int status)
38 {
39         RS_PreviewActionInterface::init(status);
40 }
41
42 void RS_ActionDimension::hideOptions()
43 {
44         RS_ActionInterface::hideOptions();
45
46         if (RS_DIALOGFACTORY != NULL)
47                 RS_DIALOGFACTORY->requestOptions(this, false);
48 }
49
50 void RS_ActionDimension::showOptions()
51 {
52         RS_ActionInterface::showOptions();
53
54         if (RS_DIALOGFACTORY != NULL)
55                 RS_DIALOGFACTORY->requestOptions(this, true, true);
56 }
57
58 void RS_ActionDimension::updateMouseCursor()
59 {
60         graphicView->setMouseCursor(RS2::CadCursor);
61 }
62
63 void RS_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 RS_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 RS_ActionDimension::setText(const QString & t)
94 {
95         data.text = t;
96 }
97
98 QString RS_ActionDimension::getLabel()
99 {
100         return label;
101 }
102
103 void RS_ActionDimension::setLabel(const QString & t)
104 {
105         label = t;
106 }
107
108 QString RS_ActionDimension::getTol1()
109 {
110         return tol1;
111 }
112
113 void RS_ActionDimension::setTol1(const QString & t)
114 {
115         tol1 = t;
116 }
117
118 QString RS_ActionDimension::getTol2()
119 {
120         return tol2;
121 }
122
123 void RS_ActionDimension::setTol2(const QString & t)
124 {
125         tol2 = t;
126 }
127
128 bool RS_ActionDimension::getDiameter()
129 {
130         return diameter;
131 }
132
133 void RS_ActionDimension::setDiameter(bool d)
134 {
135         diameter = d;
136 }
137
138 /*static*/ bool RS_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