File size: 14,499 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/***************************************************************************
 *   Copyright (c) 2022 WandererFan <wandererfan@gmail.com>                *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/

# include <gp_Ax3.hxx>
# include <gp_Trsf.hxx>
# include <gp_Vec.hxx>


#include <Base/Console.h>
#include <Base/Converter.h>
#include <Base/Tools.h>

#include "DimensionGeometry.h"
#include "DrawUtil.h"
#include "DrawViewPart.h"
#include "DrawViewDetail.h"


using namespace TechDraw;
using DU = DrawUtil;

pointPair::pointPair(const pointPair& pp)
{
    first(pp.first());
    second(pp.second());
    overrideFirst(pp.extensionLineFirst());
    overrideSecond(pp.extensionLineSecond());
}

// set extension line points from argument base points
void pointPair::setExtensionLine(const pointPair& pp){
    overrideFirst(pp.first());
    overrideSecond(pp.second());
}

//move the points by offset
void pointPair::move(const Base::Vector3d& offset)
{
    m_first = m_first - offset;
    m_second = m_second - offset;
    m_overrideFirst = m_overrideFirst - offset;
    m_overrideSecond = m_overrideSecond - offset;
}

//move the points by factor
void pointPair::scale(double factor)
{
    m_first = m_first * factor;
    m_second = m_second * factor;
    m_overrideFirst = m_overrideFirst * factor;
    m_overrideSecond = m_overrideSecond * factor;
}

// project the points onto the dvp's paper plane.
void pointPair::project(const DrawViewPart* dvp)
{
    auto detailView = dynamic_cast<const DrawViewDetail*>(dvp);
    if (detailView) {
        m_first = detailView->mapPoint3dToDetail(m_first) * detailView->getScale();
        m_second = detailView->mapPoint3dToDetail(m_second) * detailView->getScale();
        m_overrideFirst = detailView->mapPoint3dToDetail(m_overrideFirst) * detailView->getScale();
        m_overrideSecond = detailView->mapPoint3dToDetail(m_overrideSecond) * detailView->getScale();
        return;
    }
    m_first = dvp->projectPoint(m_first) * dvp->getScale();
    m_second = dvp->projectPoint(m_second) * dvp->getScale();
    m_overrideFirst = dvp->projectPoint(m_overrideFirst) * dvp->getScale();
    m_overrideSecond = dvp->projectPoint(m_overrideSecond) * dvp->getScale();
}

// map the points onto the dvp's XY coordinate system
// this routine is no longer needed since we now use the hlr projector instead
// of "projectToPlane" from Vector3d
void pointPair::mapToPage(const DrawViewPart* dvp)
{
    gp_Trsf xOXYZ;
    gp_Ax3 OXYZ;
    xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getRotatedCS()));

    gp_Vec gvFirst = Base::convertTo<gp_Vec>(m_first).Transformed(xOXYZ);
    m_first = Base::convertTo<Base::Vector3d>(gvFirst);
    gp_Vec gvSecond = Base::convertTo<gp_Vec>(m_second).Transformed(xOXYZ);
    m_second = Base::convertTo<Base::Vector3d>(gvSecond);
}

// this routine is no longer needed since we now use the dvp's projectPoint
// which performs Y inversion by default
void pointPair::invertY()
{
    m_first = DU::invertY(m_first);
    m_second = DU::invertY(m_second);
}

void pointPair::dump(const std::string& text) const
{
    Base::Console().message("pointPair - %s\n", text.c_str());
    Base::Console().message("pointPair - first: %s  second: %s\n",
                            DU::formatVector(first()).c_str(), DU::formatVector(second()).c_str());
}

//! return unscaled, unrotated version of this pointPair.  caller is responsible for
//! for ensuring this pointPair is in scaled, rotated form before calling this method.
pointPair pointPair::toCanonicalForm(DrawViewPart* dvp) const
{
    pointPair result;
    // invert points?
    result.m_first = CosmeticVertex::makeCanonicalPoint(dvp, m_first);
    result.m_second = CosmeticVertex::makeCanonicalPoint(dvp, m_second);
    result.m_overrideFirst = CosmeticVertex::makeCanonicalPoint(dvp, m_overrideFirst);
    result.m_overrideSecond = CosmeticVertex::makeCanonicalPoint(dvp, m_overrideSecond);
    return result;
}

//! return scaled and rotated version of this pointPair.  caller is responsible for
//! for ensuring this pointPair is in canonical form before calling this method.
pointPair pointPair::toDisplayForm(DrawViewPart* dvp) const
{
    pointPair result;

    // invert points?
    result.m_first = m_first * dvp->getScale();
    result.m_second = m_second * dvp->getScale();
    result.m_overrideFirst = m_overrideFirst * dvp->getScale();
    result.m_overrideSecond = m_overrideSecond * dvp->getScale();
    auto rotationDeg = dvp->Rotation.getValue();
    if (rotationDeg != 0.0) {
        auto rotationRad = Base::toRadians(rotationDeg);
        result.m_first.RotateZ(rotationRad);
        result.m_second.RotateZ(rotationRad);
        result.m_overrideFirst.RotateZ(rotationRad);
        result.m_overrideSecond.RotateZ(rotationRad);
    }
    return result;
}



anglePoints::anglePoints()
{
    m_ends.first(Base::Vector3d(0.0, 0.0, 0.0));
    m_ends.second(Base::Vector3d(0.0, 0.0, 0.0));
    m_vertex = Base::Vector3d(0.0, 0.0, 0.0);
}

anglePoints::anglePoints(const anglePoints& ap) : m_ends(ap.ends()), m_vertex(ap.vertex()) {}

anglePoints& anglePoints::operator=(const anglePoints& ap)
{
    m_ends = ap.ends();
    m_vertex = ap.vertex();
    return *this;
}

// move the points by offset
void anglePoints::move(const Base::Vector3d& offset)
{
    m_ends.move(offset);
    m_vertex = m_vertex - offset;
}

// project the points onto the dvp's paper plane.
void anglePoints::project(const DrawViewPart* dvp)
{
    m_ends.project(dvp);
    m_vertex = dvp->projectPoint(m_vertex) * dvp->getScale();
}

// map the points onto the dvp's XY coordinate system
// obsolete. see above.
void anglePoints::mapToPage(const DrawViewPart* dvp)
{
    m_ends.mapToPage(dvp);

    gp_Trsf xOXYZ;
    gp_Ax3 OXYZ;
    xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getRotatedCS()));
    gp_Vec gvVertex = Base::convertTo<gp_Vec>(m_vertex).Transformed(xOXYZ);
    m_vertex = Base::convertTo<Base::Vector3d>(gvVertex);
}

// map the points onto the coordinate system used for drawing where -Y direction is "up"
// obsolete. see above
void anglePoints::invertY()
{
    m_ends.invertY();
    m_vertex = DU::invertY(m_vertex);
}

//! return unscaled, unrotated version of this anglePoints.  caller is responsible for
//! for ensuring this anglePoints is in scaled, rotated form before calling this method.
anglePoints anglePoints::toCanonicalForm(DrawViewPart* dvp) const
{
    anglePoints result;
    result.m_ends = m_ends.toCanonicalForm(dvp);
    result.m_vertex = CosmeticVertex::makeCanonicalPoint(dvp, m_vertex);
    return result;
}

//! return scaled and rotated version of this anglePoints.  caller is responsible for
//! for ensuring this anglePoints is in canonical form before calling this method.
anglePoints anglePoints::toDisplayForm(DrawViewPart* dvp) const
{
    anglePoints result;
    result.m_ends = m_ends.toDisplayForm(dvp);
    result.m_vertex = m_vertex * dvp->getScale();
    auto rotationDeg = dvp->Rotation.getValue();
    if (rotationDeg != 0.0) {
        auto rotationRad = Base::toRadians(rotationDeg);
        result.m_vertex.RotateZ(rotationRad);
    }
    return result;
}
void anglePoints::dump(const std::string& text) const
{
    Base::Console().message("anglePoints - %s\n", text.c_str());
    Base::Console().message("anglePoints - ends - first: %s  second: %s\n",
                            DU::formatVector(first()).c_str(), DU::formatVector(second()).c_str());
    Base::Console().message("anglePoints - vertex: %s\n", DU::formatVector(vertex()).c_str());
}

arcPoints::arcPoints() :
    isArc(false),
    radius(0.0),
    arcCW(false)
{
    center = Base::Vector3d(0.0, 0.0, 0.0);
    onCurve.first(Base::Vector3d(0.0, 0.0, 0.0));
    onCurve.second(Base::Vector3d(0.0, 0.0, 0.0));
    arcEnds.first(Base::Vector3d(0.0, 0.0, 0.0));
    arcEnds.second(Base::Vector3d(0.0, 0.0, 0.0));
    midArc = Base::Vector3d(0.0, 0.0, 0.0);
}

arcPoints& arcPoints::operator=(const arcPoints& ap)
{
    isArc = ap.isArc;
    radius = ap.radius;
    center = ap.center;
    onCurve = ap.onCurve;
    arcEnds = ap.arcEnds;
    midArc = ap.midArc;
    arcCW = ap.arcCW;
    return *this;
}

void arcPoints::move(const Base::Vector3d& offset)
{
    center = center - offset;
    onCurve.first(onCurve.first() - offset);
    onCurve.second(onCurve.second() - offset);
    arcEnds.first(arcEnds.first() - offset);
    arcEnds.second(arcEnds.second() - offset);
    midArc = midArc - offset;
}

void arcPoints::project(const DrawViewPart* dvp)
{
    radius = radius * dvp->getScale();
    center = dvp->projectPoint(center) * dvp->getScale();
    onCurve.first(dvp->projectPoint(onCurve.first()) * dvp->getScale());
    onCurve.second(dvp->projectPoint(onCurve.second()) * dvp->getScale());
    arcEnds.first(dvp->projectPoint(arcEnds.first()) * dvp->getScale());
    arcEnds.second(dvp->projectPoint(arcEnds.second()) * dvp->getScale());
    midArc = dvp->projectPoint(midArc) * dvp->getScale();
}

// obsolete. see above
void arcPoints::mapToPage(const DrawViewPart* dvp)
{
    gp_Trsf xOXYZ;
    gp_Ax3 OXYZ;
    xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getRotatedCS()));

    gp_Vec gvCenter = Base::convertTo<gp_Vec>(center).Transformed(xOXYZ);
    center = Base::convertTo<Base::Vector3d>(gvCenter);
    gp_Vec gvOnCurve1 = Base::convertTo<gp_Vec>(onCurve.first()).Transformed(xOXYZ);
    onCurve.first(Base::convertTo<Base::Vector3d>(gvOnCurve1));
    gp_Vec gvOnCurve2 = Base::convertTo<gp_Vec>(onCurve.second()).Transformed(xOXYZ);
    onCurve.second(Base::convertTo<Base::Vector3d>(gvOnCurve2));
    gp_Vec gvArcEnds1 = Base::convertTo<gp_Vec>(arcEnds.first()).Transformed(xOXYZ);
    arcEnds.first(Base::convertTo<Base::Vector3d>(gvArcEnds1));
    gp_Vec gvArcEnds2 = Base::convertTo<gp_Vec>(arcEnds.second()).Transformed(xOXYZ);
    arcEnds.second(Base::convertTo<Base::Vector3d>(gvArcEnds2));
    gp_Vec gvMidArc = Base::convertTo<gp_Vec>(midArc).Transformed(xOXYZ);
    midArc = Base::convertTo<Base::Vector3d>(gvMidArc);
}

// obsolete. see above
void arcPoints::invertY()
{
    center = DU::invertY(center);
    onCurve.invertY();
    arcEnds.invertY();
    midArc = DU::invertY(midArc);
}

//! return scaled and rotated version of this arcPoints.  caller is responsible for
//! for ensuring this arcPoints is in canonical form before calling this method.
arcPoints arcPoints::toDisplayForm(DrawViewPart* dvp) const
{
    arcPoints result;
    result.onCurve = onCurve.toDisplayForm(dvp);
    result.arcEnds = arcEnds.toDisplayForm(dvp);
    result.center = center * dvp->getScale();
    result.midArc = midArc * dvp->getScale();
    result.radius = radius * dvp->getScale();
    auto rotationDeg = dvp->Rotation.getValue();
    if (rotationDeg != 0.0) {
        auto rotationRad = Base::toRadians(rotationDeg);
        result.center.RotateZ(rotationRad);
        result.midArc.RotateZ(rotationRad);
    }
    return result;
}

//! return unscaled, unrotated version of this arcPoints.  caller is responsible for
//! for ensuring this arcPoints is in scaled, rotated form before calling this method.
arcPoints arcPoints::toCanonicalForm(DrawViewPart* dvp) const
{
    arcPoints result;
    result.onCurve = onCurve.toCanonicalForm(dvp);
    result.arcEnds = arcEnds.toCanonicalForm(dvp);
    result.center = CosmeticVertex::makeCanonicalPoint(dvp, center);
    result.midArc = CosmeticVertex::makeCanonicalPoint(dvp, midArc);
    result.radius = radius / dvp->getScale();
    return result;
}


void arcPoints::dump(const std::string& text) const
{
    Base::Console().message("arcPoints - %s\n", text.c_str());
    Base::Console().message("arcPoints - radius: %.3f center: %s\n", radius,
                            DrawUtil::formatVector(center).c_str());
    Base::Console().message("arcPoints - isArc: %d arcCW: %d\n", isArc, arcCW);
    Base::Console().message("arcPoints - onCurve: %s  %s\n",
                            DrawUtil::formatVector(onCurve.first()).c_str(),
                            DrawUtil::formatVector(onCurve.second()).c_str());
    Base::Console().message("arcPoints - arcEnds: %s  %s\n",
                            DrawUtil::formatVector(arcEnds.first()).c_str(),
                            DrawUtil::formatVector(arcEnds.second()).c_str());
    Base::Console().message("arcPoints - midArc: %s\n", DrawUtil::formatVector(midArc).c_str());
}


areaPoint::areaPoint() :
    area(0.0),
    actualArea(0.0),
    center(Base::Vector3d())
{
}

areaPoint& areaPoint::operator=(const areaPoint& ap)
{
    area = ap.area;
    center = ap.center;
    actualArea = ap.actualArea;
    return *this;
}

void areaPoint::move(const Base::Vector3d& offset)
{
    center = center - offset;
}

void areaPoint::project(const DrawViewPart* dvp)
{
    center = dvp->projectPoint(center) * dvp->getScale();
}

void areaPoint::invertY()
{
    center = DU::invertY(center);
}

void areaPoint::dump(const std::string& text) const
{
    Base::Console().message("areaPoint - %s\n", text.c_str());
    Base::Console().message("areaPoint - area: %.3f center: %s\n", area,
        DrawUtil::formatVector(center).c_str());
}