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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/28/2010 Added this text. :-)
17 #include "dimradial.h"
27 * @para parent Parent Entity Container.
28 * @para d Common dimension geometrical data.
29 * @para ed Extended geometrical data for radial dimension.
31 DimRadial::DimRadial(EntityContainer * parent, const DimensionData & d,
32 const DimRadialData & ed): Dimension(parent, d), edata(ed)
36 /*virtual*/ DimRadial::~DimRadial()
40 /*virtual*/ Entity * DimRadial::clone()
42 DimRadial * d = new DimRadial(*this);
43 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
44 // d->entities.setAutoDelete(entities.autoDelete());
50 /** @return RS2::EntityDimRadial */
51 /*virtual*/ RS2::EntityType DimRadial::rtti() const
53 return RS2::EntityDimRadial;
57 * @return Copy of data that defines the radial dimension.
60 DimRadialData DimRadial::getEData() const
66 * @return Automatically created label for the default
67 * measurement of this dimension.
69 QString DimRadial::getMeasuredLabel()
71 // Definitive dimension line:
72 double dist = data.definitionPoint.distanceTo(edata.definitionPoint);
74 Drawing* graphic = getGraphic();
78 ret = Units::formatLinear(dist, graphic->getUnit(),
79 graphic->getLinearFormat(), graphic->getLinearPrecision());
81 ret = QString("%1").arg(dist);
88 VectorSolutions DimRadial::getRefPoints() {
89 VectorSolutions ret(edata.definitionPoint,
90 data.definitionPoint, data.middleOfText);
95 * Updates the sub entities of this dimension. Called when the
96 * dimension or the position, alignment, .. changes.
98 * @param autoText Automatically reposition the text label
100 void DimRadial::update(bool autoText)
102 DEBUG->print("DimRadial::update");
111 //updateCreateDimensionLine(data.definitionPoint, edata.definitionPoint,
114 Vector p1 = data.definitionPoint;
115 Vector p2 = edata.definitionPoint;
116 double angle = p1.angleTo(p2);
118 // text height (DIMTXT)
119 double dimtxt = getTextHeight();
120 // text distance to line (DIMGAP)
121 double dimgap = getDimensionLineGap();
123 // length of dimension line:
124 double length = p1.distanceTo(p2);
128 textData = TextData(Vector(0.0,0.0),
139 Text* text = new Text(this, textData);
140 double textWidth = text->getSize().x;
142 // do we have to put the arrow / text outside of the arc?
143 bool outsideArrow = (length<getArrowSize()*2+textWidth);
147 length += getArrowSize()*2 + textWidth;
148 arrowAngle = angle+M_PI;
157 arrow = new Solid(this, sd);
158 arrow->shapeArrow(p2,
161 arrow->setPen(Pen(RS2::FlagInvalid));
162 arrow->setLayer(NULL);
166 p3.setPolar(length, angle);
169 // Create dimension line:
170 Line* dimensionLine = new Line(this, LineData(p1, p3));
171 dimensionLine->setPen(Pen(RS2::FlagInvalid));
172 dimensionLine->setLayer(NULL);
173 addEntity(dimensionLine);
178 // rotate text so it's readable from the bottom or right (ISO)
180 if (angle>M_PI/2.0*3.0+0.001 ||
181 angle<M_PI/2.0+0.001) {
183 distV.setPolar(dimgap + dimtxt/2.0, angle+M_PI/2.0);
188 distV.setPolar(dimgap + dimtxt/2.0, angle-M_PI/2.0);
189 textAngle = angle+M_PI;
195 if (data.middleOfText.valid && !autoText) {
196 textPos = data.middleOfText;
199 textPos.setPolar(length-textWidth/2.0-getArrowSize(), angle);
201 textPos.setPolar(length/2.0, angle);
204 // move text away from dimension line:
206 data.middleOfText = textPos;
209 text->rotate(Vector(0.0,0.0), textAngle);
212 text->setPen(Pen(RS2::FlagInvalid));
213 text->setLayer(NULL);
219 Vector DimRadial::getDefinitionPoint()
221 return edata.definitionPoint;
224 double DimRadial::getLeader()
229 void DimRadial::move(Vector offset)
231 Dimension::move(offset);
233 edata.definitionPoint.move(offset);
237 void DimRadial::rotate(Vector center, double angle)
239 Dimension::rotate(center, angle);
241 edata.definitionPoint.rotate(center, angle);
247 void DimRadial::scale(Vector center, Vector factor) {
248 Dimension::scale(center, factor);
250 edata.definitionPoint.scale(center, factor);
251 edata.leader*=factor.x;
257 void DimRadial::mirror(Vector axisPoint1, Vector axisPoint2) {
258 Dimension::mirror(axisPoint1, axisPoint2);
260 edata.definitionPoint.mirror(axisPoint1, axisPoint2);
265 void DimRadial::moveRef(const Vector& ref, const Vector& offset) {
267 if (ref.distanceTo(edata.definitionPoint)<1.0e-4) {
268 double d = data.definitionPoint.distanceTo(edata.definitionPoint);
269 double a = data.definitionPoint.angleTo(edata.definitionPoint + offset);
273 edata.definitionPoint = data.definitionPoint + v;
276 else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
277 data.middleOfText.move(offset);
283 * Dumps the point's data to stdout.
285 std::ostream& operator << (std::ostream& os, const DimRadial& d) {
286 os << " DimRadial: " << d.getData() << "\n" << d.getEData() << "\n";