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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/28/2010 Added this text. :-)
15 #include "rs_dimradial.h"
17 #include "rs_graphic.h"
25 * @para parent Parent Entity Container.
26 * @para d Common dimension geometrical data.
27 * @para ed Extended geometrical data for radial dimension.
29 RS_DimRadial::RS_DimRadial(RS_EntityContainer * parent, const RS_DimensionData & d,
30 const RS_DimRadialData & ed): RS_Dimension(parent, d), edata(ed)
34 /*virtual*/ RS_DimRadial::~RS_DimRadial()
38 /*virtual*/ RS_Entity * RS_DimRadial::clone()
40 RS_DimRadial * d = new RS_DimRadial(*this);
41 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
42 // d->entities.setAutoDelete(entities.autoDelete());
48 /** @return RS2::EntityDimRadial */
49 /*virtual*/ RS2::EntityType RS_DimRadial::rtti() const
51 return RS2::EntityDimRadial;
55 * @return Copy of data that defines the radial dimension.
58 RS_DimRadialData RS_DimRadial::getEData() const
64 * @return Automatically created label for the default
65 * measurement of this dimension.
67 QString RS_DimRadial::getMeasuredLabel()
69 // Definitive dimension line:
70 double dist = data.definitionPoint.distanceTo(edata.definitionPoint);
72 RS_Graphic* graphic = getGraphic();
76 ret = RS_Units::formatLinear(dist, graphic->getUnit(),
77 graphic->getLinearFormat(), graphic->getLinearPrecision());
79 ret = QString("%1").arg(dist);
86 VectorSolutions RS_DimRadial::getRefPoints() {
87 VectorSolutions ret(edata.definitionPoint,
88 data.definitionPoint, data.middleOfText);
93 * Updates the sub entities of this dimension. Called when the
94 * dimension or the position, alignment, .. changes.
96 * @param autoText Automatically reposition the text label
98 void RS_DimRadial::update(bool autoText)
100 RS_DEBUG->print("RS_DimRadial::update");
109 //updateCreateDimensionLine(data.definitionPoint, edata.definitionPoint,
112 Vector p1 = data.definitionPoint;
113 Vector p2 = edata.definitionPoint;
114 double angle = p1.angleTo(p2);
116 // text height (DIMTXT)
117 double dimtxt = getTextHeight();
118 // text distance to line (DIMGAP)
119 double dimgap = getDimensionLineGap();
121 // length of dimension line:
122 double length = p1.distanceTo(p2);
124 RS_TextData textData;
126 textData = RS_TextData(Vector(0.0,0.0),
137 RS_Text* text = new RS_Text(this, textData);
138 double textWidth = text->getSize().x;
140 // do we have to put the arrow / text outside of the arc?
141 bool outsideArrow = (length<getArrowSize()*2+textWidth);
145 length += getArrowSize()*2 + textWidth;
146 arrowAngle = angle+M_PI;
155 arrow = new RS_Solid(this, sd);
156 arrow->shapeArrow(p2,
159 arrow->setPen(RS_Pen(RS2::FlagInvalid));
160 arrow->setLayer(NULL);
164 p3.setPolar(length, angle);
167 // Create dimension line:
168 RS_Line* dimensionLine = new RS_Line(this, RS_LineData(p1, p3));
169 dimensionLine->setPen(RS_Pen(RS2::FlagInvalid));
170 dimensionLine->setLayer(NULL);
171 addEntity(dimensionLine);
176 // rotate text so it's readable from the bottom or right (ISO)
178 if (angle>M_PI/2.0*3.0+0.001 ||
179 angle<M_PI/2.0+0.001) {
181 distV.setPolar(dimgap + dimtxt/2.0, angle+M_PI/2.0);
186 distV.setPolar(dimgap + dimtxt/2.0, angle-M_PI/2.0);
187 textAngle = angle+M_PI;
193 if (data.middleOfText.valid && !autoText) {
194 textPos = data.middleOfText;
197 textPos.setPolar(length-textWidth/2.0-getArrowSize(), angle);
199 textPos.setPolar(length/2.0, angle);
202 // move text away from dimension line:
204 data.middleOfText = textPos;
207 text->rotate(Vector(0.0,0.0), textAngle);
210 text->setPen(RS_Pen(RS2::FlagInvalid));
211 text->setLayer(NULL);
217 Vector RS_DimRadial::getDefinitionPoint()
219 return edata.definitionPoint;
222 double RS_DimRadial::getLeader()
227 void RS_DimRadial::move(Vector offset)
229 RS_Dimension::move(offset);
231 edata.definitionPoint.move(offset);
235 void RS_DimRadial::rotate(Vector center, double angle)
237 RS_Dimension::rotate(center, angle);
239 edata.definitionPoint.rotate(center, angle);
245 void RS_DimRadial::scale(Vector center, Vector factor) {
246 RS_Dimension::scale(center, factor);
248 edata.definitionPoint.scale(center, factor);
249 edata.leader*=factor.x;
255 void RS_DimRadial::mirror(Vector axisPoint1, Vector axisPoint2) {
256 RS_Dimension::mirror(axisPoint1, axisPoint2);
258 edata.definitionPoint.mirror(axisPoint1, axisPoint2);
263 void RS_DimRadial::moveRef(const Vector& ref, const Vector& offset) {
265 if (ref.distanceTo(edata.definitionPoint)<1.0e-4) {
266 double d = data.definitionPoint.distanceTo(edata.definitionPoint);
267 double a = data.definitionPoint.angleTo(edata.definitionPoint + offset);
271 edata.definitionPoint = data.definitionPoint + v;
274 else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
275 data.middleOfText.move(offset);
281 * Dumps the point's data to stdout.
283 std::ostream& operator << (std::ostream& os, const RS_DimRadial& d) {
284 os << " DimRadial: " << d.getData() << "\n" << d.getEData() << "\n";