~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/lib/engine/rs_dimdiametric.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
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.
 
13
**
 
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.
 
18
**
 
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
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
 
 
28
#include "rs_dimdiametric.h"
 
29
#include "rs_mtext.h"
 
30
#include "rs_solid.h"
 
31
#include "rs_graphic.h"
 
32
#include "rs_units.h"
 
33
 
 
34
 
 
35
/**
 
36
 * Constructor.
 
37
 *
 
38
 * @para parent Parent Entity Container.
 
39
 * @para d Common dimension geometrical data.
 
40
 * @para ed Extended geometrical data for diametric dimension.
 
41
 */
 
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) {
 
46
 
 
47
    calculateBorders();
 
48
}
 
49
 
 
50
 
 
51
 
 
52
/**
 
53
 * @return Automatically created label for the default
 
54
 * measurement of this dimension.
 
55
 */
 
56
QString RS_DimDiametric::getMeasuredLabel() {
 
57
 
 
58
    // Definitive dimension line:
 
59
    double dist = data.definitionPoint.distanceTo(edata.definitionPoint) * getGeneralFactor();
 
60
 
 
61
        RS_Graphic* graphic = getGraphic();
 
62
 
 
63
    QString ret;
 
64
        if (graphic!=NULL) {
 
65
                ret = RS_Units::formatLinear(dist, graphic->getUnit(),
 
66
                        graphic->getLinearFormat(), graphic->getLinearPrecision());
 
67
        }
 
68
        else {
 
69
        ret = QString("%1").arg(dist);
 
70
        }
 
71
 
 
72
    return ret;
 
73
}
 
74
 
 
75
 
 
76
 
 
77
RS_VectorSolutions RS_DimDiametric::getRefPoints() {
 
78
        RS_VectorSolutions ret(edata.definitionPoint,
 
79
                                                data.definitionPoint, data.middleOfText);
 
80
        return ret;
 
81
}
 
82
 
 
83
 
 
84
/**
 
85
 * Updates the sub entities of this dimension. Called when the
 
86
 * dimension or the position, alignment, .. changes.
 
87
 *
 
88
 * @param autoText Automatically reposition the text label
 
89
 */
 
90
void RS_DimDiametric::updateDim(bool autoText) {
 
91
 
 
92
    RS_DEBUG->print("RS_DimDiametric::update");
 
93
 
 
94
    clear();
 
95
 
 
96
        if (isUndone()) {
 
97
                return;
 
98
        }
 
99
 
 
100
    // dimension line:
 
101
    updateCreateDimensionLine(data.definitionPoint, edata.definitionPoint,
 
102
        true, true, autoText);
 
103
 
 
104
    calculateBorders();
 
105
}
 
106
 
 
107
 
 
108
 
 
109
void RS_DimDiametric::move(const RS_Vector& offset) {
 
110
    RS_Dimension::move(offset);
 
111
 
 
112
    edata.definitionPoint.move(offset);
 
113
    update();
 
114
}
 
115
 
 
116
 
 
117
 
 
118
void RS_DimDiametric::rotate(const RS_Vector& center, const double& angle) {
 
119
    rotate(center,RS_Vector(angle));
 
120
}
 
121
 
 
122
void RS_DimDiametric::rotate(const RS_Vector& center, const RS_Vector& angleVector) {
 
123
    RS_Dimension::rotate(center, angleVector);
 
124
 
 
125
    edata.definitionPoint.rotate(center, angleVector);
 
126
    update();
 
127
}
 
128
 
 
129
 
 
130
void RS_DimDiametric::scale(const RS_Vector& center, const RS_Vector& factor) {
 
131
    RS_Dimension::scale(center, factor);
 
132
 
 
133
    edata.definitionPoint.scale(center, factor);
 
134
        edata.leader*=factor.x;
 
135
    update();
 
136
}
 
137
 
 
138
 
 
139
 
 
140
void RS_DimDiametric::mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) {
 
141
    RS_Dimension::mirror(axisPoint1, axisPoint2);
 
142
 
 
143
    edata.definitionPoint.mirror(axisPoint1, axisPoint2);
 
144
    update();
 
145
}
 
146
 
 
147
 
 
148
 
 
149
void RS_DimDiametric::moveRef(const RS_Vector& ref, const RS_Vector& offset) {
 
150
 
 
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);
 
155
 
 
156
                RS_Vector v;
 
157
                v.setPolar(d, a);
 
158
        edata.definitionPoint = c + v;
 
159
                data.definitionPoint = c - v;
 
160
                updateDim(true);
 
161
    }
 
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);
 
166
 
 
167
                RS_Vector v;
 
168
                v.setPolar(d, a);
 
169
        data.definitionPoint = c + v;
 
170
                edata.definitionPoint = c - v;
 
171
                updateDim(true);
 
172
    }
 
173
        else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
 
174
        data.middleOfText.move(offset);
 
175
                updateDim(false);
 
176
    }
 
177
}
 
178
 
 
179
 
 
180
 
 
181
/**
 
182
 * Dumps the point's data to stdout.
 
183
 */
 
184
std::ostream& operator << (std::ostream& os, const RS_DimDiametric& d) {
 
185
    os << " DimDiametric: " << d.getData() << "\n" << d.getEData() << "\n";
 
186
    return os;
 
187
}
 
188