-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimension.h
369 lines (317 loc) · 13.1 KB
/
dimension.h
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
/* -*- c++ -*-
* dimension.h
*
* Header for the Dimension class
* Copyright (C) 2002 lignum Computing, Inc. <lignumcad@lignumcomputing.com>
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DIMENSION_H
#define DIMENSION_H
#include "vectoralgebra.h"
#include "openglbase.h"
#include "arrow.h"
#include "constants.h"
class OpenGLBase;
namespace Space2D {
/*!
* This class is for drawing and selecting a 2D dimension line. The
* dimension is specified by its two reference points, its orientation
* and quite a lot of other visual attributes. It is distinct from
* DimensionView; DimensionView controls the references and placement
* of a dimension; this class is purely cosmetic and just draws what it's
* told.
*
* A dimension line can represent something other than the Cartesian
* distance between the two reference points. For example:
* |<--- 12 --->| ->\
* | 12.042 \
* | +----o \<- +----o
* | | vs. \ | |
* o-------+ | o-------+ |
* | | | |
*
* The exact distance presented in the dimension value depends on the
* direction of the extension line vector (called normal_ in the code).
*
* Here are the various positions of the arrows and the dimension value
* (according to ANSI Y14.5-1967)
* |<- # ->| : standard
* ->| # |<- : exterior arrows
* #-|<->| : exterior number at end0 (not currently supported...)
* |<->|-# : exterior number at end1 (not currently supported...)
* #->| |<- : exterior arrows and number at end0
* ->| |<-# : exterior arrows and number at end1 (not currently supported...)
*/
class Dimension {
public:
//! Dimension has two ends
enum Ends { END0=0, END1=1 };
//! The placement of the value.
enum Placement { INTERIOR, EXTERIOR_END0, EXTERIOR_END1 };
private:
//! Reference point for "Starting" end of dimension.
Point end0_;
//! Reference point for "Ending" end of dimension.
Point end1_;
//! Direction of extension line.
Vector normal_;
//! We need to lookup font metrics in order to compute the layout.
OpenGLBase* view_;
// Properties
struct ExtensionLine {
double offset; //<! distance from reference point to start of line
double thickness; //<! (printed) width of line
Point from_; //<! computed starting point
Point to_; //<! computed end point
bool use_; //<! Extension lines are not always necessary.
} extension_lines_[2];
//! User adjustment to extension position. This is in paper inches.
double extension_offset_;
//! User adjustment to text position. This is in scale inches if
//! the dimension text is INTERIOR and in paper inches if the
//! the dimension text is EXTERIOR.
double dimension_offset_;
struct DimensionLine {
double clearance; //!< separation from the end of the extension lines
double thickness; //!< rendered width of the line
} dimension_line_;
//! Holds a few rendering attributes (both arrows are drawn the same).
Arrow arrow_;
struct Arrows {
Point from_; //!< Computed starting point of arrow
Point to_; //!< Pointy end of arrow
} arrows_[2];
struct DimensionValue {
double value; //!< Dimension size
QString text; //!< string represention of value
FaceData face_data_; //!< font information
Point position; //!< Computed position of the text
Vector bbox; //!< Unrotated bounding box of text
enum Placement placement; //!< Even if the dimension CAN be interior,
//!< the user may drag it outside.
} dimension_value_;
struct DimensionLocator { // For externl dim/intern arrs, have an extra line
Point from_; //!< Locator start point
Point to_; //!< Locator end point
bool use_; //!< Locator not always necessary.
} locator_;
QString note_; //!< Additional dimension value text.
public:
Dimension ( OpenGLBase* view );
Dimension ( const Point& end0, const Point& end1, const Vector& normal,
OpenGLBase* view, const QString& note = QString::null );
void init ( void );
Point end0 ( void ) const { return end0_; }
Point end1 ( void ) const { return end1_; }
Vector normal ( void ) const { return normal_; }
void setEndsNormal ( const Point& end0, const Point& end1,const Vector& normal,
OpenGLBase* view, const QString& note = QString::null );
void setUseExtensionLine ( bool end0, bool end1 );
void setDimensionAttributes ( double extension_offset, double dimension_offset,
enum Placement placement );
void adjustExtension ( const Vector& delta );
double extensionOffset ( void ) const { return extension_offset_; }
void adjustDimension ( const Vector& delta );
double dimensionOffset ( void ) const { return dimension_offset_; }
enum Placement placement ( void ) const { return dimension_value_.placement; }
void draw ( lC::Render::Mode mode ) const;
void select ( lC::Render::Mode mode ) const;
private:
void computeLayout ( void );
};
/*!
* Retrieve the string representation of the dimension text placement.
* \param placement Placement enum to convert to string representation.
* \return string representation of placement.
*/
inline QString placementText ( enum Dimension::Placement placement )
{
switch ( placement ) {
case Dimension::EXTERIOR_END0:
return "EXTERIOR_END0";
case Dimension::EXTERIOR_END1:
return "EXTERIOR_END1";
case Dimension::INTERIOR:
return "INTERIOR";
}
return "INTERIOR";
}
/*!
* Convert string into Dimension Placement enum.
* \param text string representation of Placement enum.
* \return Dimension::Placement enum described by text.
*/
inline enum Dimension::Placement placement ( const QString& text )
{
if ( text == "EXTERIOR_END0" )
return Dimension::EXTERIOR_END0;
else if ( text == "EXTERIOR_END1" )
return Dimension::EXTERIOR_END1;
return Dimension::INTERIOR;
}
} // End of Space2D namespace
namespace Space3D {
/*!
* This class is for drawing and selecting a 3D dimension line. The
* dimension is specified by its two reference points, its orientation
* and quite a lot of other visual attributes. It is distinct from
* DimensionView; DimensionView controls the references and placement
* of a dimension; this class is purely cosmetic and just draws what it's
* told.
*
* A dimension line can represent something other than the Cartesian
* distance between the two reference points. For example:
* |<--- 12 --->| ->\
* | 12.042 \
* | +----o \<- +----o
* | | vs. \ | |
* o-------+ | o-------+ |
* | | | |
*
* The exact distance presented in the dimension value depends on the
* direction of the extension line vector (called normal_ in the code).
*
* Here are the various positions of the arrows and the dimension value
* (according to ANSI Y14.5-1967)
* |<- # ->| : standard
* ->| # |<- : exterior arrows
* #-|<->| : exterior number at end0 (not currently supported...)
* |<->|-# : exterior number at end1 (not currently supported...)
* #->| |<- : exterior arrows and number at end0
* ->| |<-# : exterior arrows and number at end1 (not currently supported...)
*/
class Dimension {
public:
//! Dimension has two ends
enum Ends { END0=0, END1=1 };
//! The placement of the value.
enum Placement { INTERIOR, EXTERIOR_END0, EXTERIOR_END1 };
private:
//! Reference point for "Starting" end of dimension.
Point end0_;
//! Reference point for "Ending" end of dimension.
Point end1_;
//! Direction of extension line.
Vector normal_;
//! We need to lookup font metrics in order to compute the layout.
OpenGLBase* view_;
//! Additional dimension value text.
QString note_;
//! The rendering mode for the dimension.
lC::Render::Mode mode_;
// Properties
struct ExtensionLine {
double offset; //<! distance from reference point to start of line
double thickness; //<! (printed) width of line
Point from_; //<! computed starting point
Point to_; //<! computed end point
bool use_; //<! Extension lines are not always necessary.
} extension_lines_[2];
//! User adjustment to extension position. This is in paper inches.
double extension_offset_;
//! User adjustment to text position. This is in scale inches if
//! the dimension text is INTERIOR and in paper inches if the
//! the dimension text is EXTERIOR.
double dimension_offset_;
struct DimensionLine {
double clearance; //!< separation from the end of the extension lines
double thickness; //!< rendered width of the line
} dimension_line_;
//! Holds a few rendering attributes (both arrows are drawn the same).
Arrow arrow_;
struct Arrows {
Point from_; //!< Computed starting point of arrow
Point to_; //!< Pointy end of arrow
} arrows_[2];
struct DimensionValue {
double value; //!< Dimension size
QString text; //!< string represention of value
FaceData face_data_; //!< font information
Point position; //!< Computed position of the text
Space2D::Point bb_min_; //!< Position of lower left corner of text in 2D
Space2D::Point bb_max_; //!< Position of upper right corner of text in 2D
Point bb_ll_; //!< Position of lower left corner of text in 3D
Point bb_lr_; //!< Position of lower right corner of text in 3D
Point bb_ur_; //!< Position of upper right corner of text in 3D
Point bb_ul_; //!< Position of upper left corner of text in 3D
enum Placement placement; //!< Even if the dimension CAN be interior,
//!< the user may drag it outside.
} dimension_value_;
struct DimensionLocator { // For externl dim/intern arrs, have an extra line
Point from_; //!< Locator start point
Point to_; //!< Locator end point
bool use_; //!< Locator not always necessary.
} locator_;
public:
Dimension ( OpenGLBase* view );
Dimension ( const Point& end0, const Point& end1, const Vector& normal,
OpenGLBase* view, const QString& note = QString::null );
void init ( void );
Point end0 ( void ) const { return end0_; }
Point end1 ( void ) const { return end1_; }
Vector normal ( void ) const { return normal_; }
lC::Render::Mode mode ( void ) const { return mode_; }
void setEndsNormal ( const Point& end0, const Point& end1,const Vector& normal,
OpenGLBase* view, const QString& note = QString::null );
void setUseExtensionLine ( bool end0, bool end1 );
void setDimensionAttributes ( double extension_offset, double dimension_offset,
enum Placement placement );
void setMode ( lC::Render::Mode mode );
void setViewNormal ( const Vector& view_normal );
void adjustExtension ( const Vector& delta );
double extensionOffset ( void ) const { return extension_offset_; }
void adjustDimension ( const Vector& delta );
double dimensionOffset ( void ) const { return dimension_offset_; }
enum Placement placement ( void ) const { return dimension_value_.placement; }
void draw ( void ) const;
void select ( void ) const;
private:
void computeLayout ( void );
};
/*!
* Retrieve the string representation of the dimension text placement.
* \param placement Placement enum to convert to string representation.
* \return string representation of placement.
*/
inline QString placementText ( enum Dimension::Placement placement )
{
switch ( placement ) {
case Dimension::EXTERIOR_END0:
return "EXTERIOR_END0";
case Dimension::EXTERIOR_END1:
return "EXTERIOR_END1";
case Dimension::INTERIOR:
return "INTERIOR";
}
return "INTERIOR";
}
/*!
* Convert string into Dimension Placement enum.
* \param text string representation of Placement enum.
* \return Dimension::Placement enum described by text.
*/
inline enum Dimension::Placement placement ( const QString& text )
{
if ( text == "EXTERIOR_END0" )
return Dimension::EXTERIOR_END0;
else if ( text == "EXTERIOR_END1" )
return Dimension::EXTERIOR_END1;
return Dimension::INTERIOR;
}
} // End of Space3D namespace
#endif // DIMENSION_H