1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
28
#include "rs_dimdiametric.h"
31
#include "rs_graphic.h"
38
* @para parent Parent Entity Container.
39
* @para d Common dimension geometrical data.
40
* @para ed Extended geometrical data for diametric dimension.
42
RS_DimDiametric::RS_DimDiametric(RS_EntityContainer* parent,
43
const RS_DimensionData& d,
44
const RS_DimDiametricData& ed)
45
: RS_Dimension(parent, d), edata(ed) {
53
* @return Automatically created label for the default
54
* measurement of this dimension.
56
QString RS_DimDiametric::getMeasuredLabel() {
58
// Definitive dimension line:
59
double dist = data.definitionPoint.distanceTo(edata.definitionPoint) * getGeneralFactor();
61
RS_Graphic* graphic = getGraphic();
65
ret = RS_Units::formatLinear(dist, graphic->getUnit(),
66
graphic->getLinearFormat(), graphic->getLinearPrecision());
69
ret = QString("%1").arg(dist);
77
RS_VectorSolutions RS_DimDiametric::getRefPoints() {
78
RS_VectorSolutions ret(edata.definitionPoint,
79
data.definitionPoint, data.middleOfText);
85
* Updates the sub entities of this dimension. Called when the
86
* dimension or the position, alignment, .. changes.
88
* @param autoText Automatically reposition the text label
90
void RS_DimDiametric::updateDim(bool autoText) {
92
RS_DEBUG->print("RS_DimDiametric::update");
101
updateCreateDimensionLine(data.definitionPoint, edata.definitionPoint,
102
true, true, autoText);
109
void RS_DimDiametric::move(const RS_Vector& offset) {
110
RS_Dimension::move(offset);
112
edata.definitionPoint.move(offset);
118
void RS_DimDiametric::rotate(const RS_Vector& center, const double& angle) {
119
rotate(center,RS_Vector(angle));
122
void RS_DimDiametric::rotate(const RS_Vector& center, const RS_Vector& angleVector) {
123
RS_Dimension::rotate(center, angleVector);
125
edata.definitionPoint.rotate(center, angleVector);
130
void RS_DimDiametric::scale(const RS_Vector& center, const RS_Vector& factor) {
131
RS_Dimension::scale(center, factor);
133
edata.definitionPoint.scale(center, factor);
134
edata.leader*=factor.x;
140
void RS_DimDiametric::mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) {
141
RS_Dimension::mirror(axisPoint1, axisPoint2);
143
edata.definitionPoint.mirror(axisPoint1, axisPoint2);
149
void RS_DimDiametric::moveRef(const RS_Vector& ref, const RS_Vector& offset) {
151
if (ref.distanceTo(edata.definitionPoint)<1.0e-4) {
152
RS_Vector c = (edata.definitionPoint + data.definitionPoint)/2.0;
153
double d = c.distanceTo(edata.definitionPoint);
154
double a = c.angleTo(edata.definitionPoint + offset);
158
edata.definitionPoint = c + v;
159
data.definitionPoint = c - v;
162
else if (ref.distanceTo(data.definitionPoint)<1.0e-4) {
163
RS_Vector c = (edata.definitionPoint + data.definitionPoint)/2.0;
164
double d = c.distanceTo(data.definitionPoint);
165
double a = c.angleTo(data.definitionPoint + offset);
169
data.definitionPoint = c + v;
170
edata.definitionPoint = c - v;
173
else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
174
data.middleOfText.move(offset);
182
* Dumps the point's data to stdout.
184
std::ostream& operator << (std::ostream& os, const RS_DimDiametric& d) {
185
os << " DimDiametric: " << d.getData() << "\n" << d.getEData() << "\n";