]> Shamusworld >> Repos - architektonas/blob - src/base/dimdiametric.cpp
In the middle of chasing down MDI not activating bug, renaming of Graphic to
[architektonas] / src / base / dimdiametric.cpp
1 // 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 "dimdiametric.h"
18
19 #include "text.h"
20 #include "solid.h"
21 #include "drawing.h"
22 #include "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 DimDiametric::DimDiametric(EntityContainer * parent, const DimensionData & d,
32         const DimDiametricData & ed): Dimension(parent, d), edata(ed)
33 {
34     calculateBorders();
35 }
36
37 /*virtual*/ DimDiametric::~DimDiametric()
38 {
39 }
40
41 /*virtual*/ Entity * DimDiametric::clone()
42 {
43         DimDiametric * d = new 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 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 DimDiametricData 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 DimDiametric::getMeasuredLabel()
71 {
72     // Definitive dimension line:
73     double dist = data.definitionPoint.distanceTo(edata.definitionPoint);
74         Drawing * drawing = GetDrawing();
75
76         if (drawing)
77                 return Units::formatLinear(dist, drawing->getUnit(),
78                         drawing->getLinearFormat(), drawing->getLinearPrecision());
79
80     return QString("%1").arg(dist);
81 }
82
83 VectorSolutions DimDiametric::getRefPoints()
84 {
85         VectorSolutions ret(edata.definitionPoint, data.definitionPoint, data.middleOfText);
86         return ret;
87 }
88
89 /**
90  * Updates the sub entities of this dimension. Called when the
91  * dimension or the position, alignment, .. changes.
92  *
93  * @param autoText Automatically reposition the text label
94  */
95 void DimDiametric::update(bool autoText)
96 {
97         DEBUG->print("DimDiametric::update");
98         clear();
99
100         if (isUndone())
101                 return;
102
103         // dimension line:
104         updateCreateDimensionLine(data.definitionPoint, edata.definitionPoint, true, true, autoText);
105         calculateBorders();
106 }
107
108 Vector DimDiametric::getDefinitionPoint()
109 {
110         return edata.definitionPoint;
111 }
112
113 double DimDiametric::getLeader()
114 {
115         return edata.leader;
116 }
117
118 void DimDiametric::move(Vector offset)
119 {
120     Dimension::move(offset);
121
122     edata.definitionPoint.move(offset);
123     update();
124 }
125
126 void DimDiametric::rotate(Vector center, double angle)
127 {
128     Dimension::rotate(center, angle);
129
130     edata.definitionPoint.rotate(center, angle);
131     update();
132 }
133
134 void DimDiametric::scale(Vector center, Vector factor) {
135     Dimension::scale(center, factor);
136
137     edata.definitionPoint.scale(center, factor);
138         edata.leader*=factor.x;
139     update();
140 }
141
142 void DimDiametric::mirror(Vector axisPoint1, Vector axisPoint2) {
143     Dimension::mirror(axisPoint1, axisPoint2);
144
145     edata.definitionPoint.mirror(axisPoint1, axisPoint2);
146     update();
147 }
148
149 void DimDiametric::moveRef(const Vector& ref, const Vector& offset)
150 {
151     if (ref.distanceTo(edata.definitionPoint)<1.0e-4) {
152                 Vector c = (edata.definitionPoint + data.definitionPoint)/2.0;
153                 double d = c.distanceTo(edata.definitionPoint);
154                 double a = c.angleTo(edata.definitionPoint + offset);
155
156                 Vector v;
157                 v.setPolar(d, a);
158         edata.definitionPoint = c + v;
159                 data.definitionPoint = c - v;
160                 update(true);
161     }
162     else if (ref.distanceTo(data.definitionPoint)<1.0e-4) {
163                 Vector c = (edata.definitionPoint + data.definitionPoint)/2.0;
164                 double d = c.distanceTo(data.definitionPoint);
165                 double a = c.angleTo(data.definitionPoint + offset);
166
167                 Vector v;
168                 v.setPolar(d, a);
169         data.definitionPoint = c + v;
170                 edata.definitionPoint = c - v;
171                 update(true);
172     }
173         else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
174         data.middleOfText.move(offset);
175                 update(false);
176     }
177 }
178
179 /**
180  * Dumps the point's data to stdout.
181  */
182 std::ostream & operator<<(std::ostream & os, const DimDiametric & d)
183 {
184     os << " DimDiametric: " << d.getData() << "\n" << d.getEData() << "\n";
185     return os;
186 }