]> Shamusworld >> Repos - architektonas/blob - src/base/rs_dimdiametric.cpp
Initial import
[architektonas] / src / base / rs_dimdiametric.cpp
1 // rs_dimdiametric.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  05/28/2010  Added this text. :-)
13 //
14
15 #include "rs_dimdiametric.h"
16
17 #include "rs_text.h"
18 #include "rs_solid.h"
19 #include "rs_graphic.h"
20 #include "rs_units.h"
21
22 /**
23  * Constructor.
24  *
25  * @para parent Parent Entity Container.
26  * @para d Common dimension geometrical data.
27  * @para ed Extended geometrical data for diametric dimension.
28  */
29 RS_DimDiametric::RS_DimDiametric(RS_EntityContainer * parent, const RS_DimensionData & d,
30         const RS_DimDiametricData & ed): RS_Dimension(parent, d), edata(ed)
31 {
32     calculateBorders();
33 }
34
35 /*virtual*/ RS_DimDiametric::~RS_DimDiametric()
36 {
37 }
38
39 /*virtual*/ RS_Entity * RS_DimDiametric::clone()
40 {
41         RS_DimDiametric * d = new RS_DimDiametric(*this);
42 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
43 //      d->entities.setAutoDelete(entities.autoDelete());
44         d->initId();
45         d->detach();
46         return d;
47 }
48
49 /**     @return RS2::EntityDimDiametric */
50 /*virtual*/ RS2::EntityType RS_DimDiametric::rtti() const
51 {
52         return RS2::EntityDimDiametric;
53 }
54
55 /**
56  * @return Copy of data that defines the diametric dimension.
57  * @see getData()
58  */
59 RS_DimDiametricData RS_DimDiametric::getEData() const
60 {
61         return edata;
62 }
63
64 /**
65  * @return Automatically created label for the default
66  * measurement of this dimension.
67  */
68 QString RS_DimDiametric::getMeasuredLabel()
69 {
70     // Definitive dimension line:
71     double dist = data.definitionPoint.distanceTo(edata.definitionPoint);
72
73         RS_Graphic* graphic = getGraphic();
74
75     QString ret;
76         if (graphic!=NULL) {
77                 ret = RS_Units::formatLinear(dist, graphic->getUnit(),
78                         graphic->getLinearFormat(), graphic->getLinearPrecision());
79         }
80         else {
81         ret = QString("%1").arg(dist);
82         }
83
84     return ret;
85 }
86
87 VectorSolutions RS_DimDiametric::getRefPoints()
88 {
89         VectorSolutions ret(edata.definitionPoint, data.definitionPoint, data.middleOfText);
90         return ret;
91 }
92
93 /**
94  * Updates the sub entities of this dimension. Called when the
95  * dimension or the position, alignment, .. changes.
96  *
97  * @param autoText Automatically reposition the text label
98  */
99 void RS_DimDiametric::update(bool autoText)
100 {
101         RS_DEBUG->print("RS_DimDiametric::update");
102         clear();
103
104         if (isUndone())
105                 return;
106
107         // dimension line:
108         updateCreateDimensionLine(data.definitionPoint, edata.definitionPoint, true, true, autoText);
109         calculateBorders();
110 }
111
112 Vector RS_DimDiametric::getDefinitionPoint()
113 {
114         return edata.definitionPoint;
115 }
116
117 double RS_DimDiametric::getLeader()
118 {
119         return edata.leader;
120 }
121
122 void RS_DimDiametric::move(Vector offset)
123 {
124     RS_Dimension::move(offset);
125
126     edata.definitionPoint.move(offset);
127     update();
128 }
129
130 void RS_DimDiametric::rotate(Vector center, double angle)
131 {
132     RS_Dimension::rotate(center, angle);
133
134     edata.definitionPoint.rotate(center, angle);
135     update();
136 }
137
138 void RS_DimDiametric::scale(Vector center, Vector factor) {
139     RS_Dimension::scale(center, factor);
140
141     edata.definitionPoint.scale(center, factor);
142         edata.leader*=factor.x;
143     update();
144 }
145
146 void RS_DimDiametric::mirror(Vector axisPoint1, Vector axisPoint2) {
147     RS_Dimension::mirror(axisPoint1, axisPoint2);
148
149     edata.definitionPoint.mirror(axisPoint1, axisPoint2);
150     update();
151 }
152
153 void RS_DimDiametric::moveRef(const Vector& ref, const Vector& offset)
154 {
155     if (ref.distanceTo(edata.definitionPoint)<1.0e-4) {
156                 Vector c = (edata.definitionPoint + data.definitionPoint)/2.0;
157                 double d = c.distanceTo(edata.definitionPoint);
158                 double a = c.angleTo(edata.definitionPoint + offset);
159
160                 Vector v;
161                 v.setPolar(d, a);
162         edata.definitionPoint = c + v;
163                 data.definitionPoint = c - v;
164                 update(true);
165     }
166     else if (ref.distanceTo(data.definitionPoint)<1.0e-4) {
167                 Vector c = (edata.definitionPoint + data.definitionPoint)/2.0;
168                 double d = c.distanceTo(data.definitionPoint);
169                 double a = c.angleTo(data.definitionPoint + offset);
170
171                 Vector v;
172                 v.setPolar(d, a);
173         data.definitionPoint = c + v;
174                 edata.definitionPoint = c - v;
175                 update(true);
176     }
177         else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
178         data.middleOfText.move(offset);
179                 update(false);
180     }
181 }
182
183 /**
184  * Dumps the point's data to stdout.
185  */
186 std::ostream & operator<<(std::ostream & os, const RS_DimDiametric & d)
187 {
188     os << " DimDiametric: " << d.getData() << "\n" << d.getEData() << "\n";
189     return os;
190 }