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