opennurbs_dimension.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_DIMENSION_INC_)
18 #define OPENNURBS_DIMENSION_INC_
19 
20 #if defined(ON_DLL_TEMPLATE)
21 ON_DLL_TEMPLATE template ON_ClassArray< class ON_DimStyle >;
22 #endif
23 
24 class ON_CLASS ON_Dimension : public ON_Annotation
25 {
26  ON_OBJECT_DECLARE(ON_Dimension);
27 
28 public:
29 #pragma region RH_C_SHARED_ENUM [ON_Dimension::ForceArrow] [Rhino.Geometry.Dimension.ForceArrow] [nested:int]
30  /// <summary>
31  /// Arrowheads forced Inside, or Outside of extension lines, or moved to fit.
32  /// </summary>
33  enum class ForceArrow : unsigned int
34  {
35  /// <summary> </summary>
36  Auto = 0,
37  /// <summary> </summary>
38  Inside = 1,
39  /// <summary> </summary>
40  Outside = 2,
41  };
42 #pragma endregion
43 
44  static ON_Dimension::ForceArrow ForceArrowFromUnsigned(
45  unsigned int force_arrow_as_unsigned);
46 
47 #pragma region RH_C_SHARED_ENUM [ON_Dimension::ForceText] [Rhino.Geometry.Dimension.ForceText] [nested:int]
48  /// <summary>
49  /// Text forced Inside, Right or Left of extension lines, or moved to fit (Auto).
50  /// </summary>
51  enum class ForceText : unsigned int
52  {
53  /// <summary> </summary>
54  Auto = 0,
55  /// <summary> </summary>
56  Inside = 1,
57  /// <summary> </summary>
58  Right = 2,
59  /// <summary> </summary>
60  Left = 3,
61  };
62 #pragma endregion
63 
64  static ON_Dimension::ForceText ForceTextFromUnsigned(
65  unsigned int force_text_as_unsigned);
66 
67 
68 protected:
69  ON_Dimension( ON::AnnotationType annotation_type );
70  ~ON_Dimension();
71  ON_Dimension(const ON_Dimension& src);
72  ON_Dimension& operator=(const ON_Dimension& src);
73 
74 private:
75  ON_Dimension() = delete;
76  void Internal_Destroy();
77  void Internal_CopyFrom(const ON_Dimension& src);
78 
79 public:
80  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
81 
82  virtual ON_2dPoint DefaultTextPoint() const;
83  virtual bool UseDefaultTextPoint() const;
84  virtual void SetUseDefaultTextPoint(bool usedefault);
85 
86  // Text center-midpoint in dimension plane
87  ON_2dPoint TextPoint() const;
88  void Set2dTextPoint(const ON_2dPoint& textpoint);
89 
90  const wchar_t* UserText() const;
91  void SetUserText(const wchar_t* text);
92  const wchar_t* PlainUserText() const;
93 
94  // Computes measurement value as a number
95  virtual double Measurement() const = 0;
96 
97  // Add to natural rotation
98  double TextRotation() const;
99  void SetTextRotation(double rotation_radians);
100 
101  bool ArrowIsFlipped(int i) const;
102  void FlipArrow(int i, bool flip) const;
103 
104  // If the dimension is a paper space object and the geometry being dimensioned is in
105  // model space, in a detail viewport, DetailMeasured() will have the UUID of the detail
106  // that the dimension references. Otherwise DetailMeasured() will be ON_nil_uuid.
107  ON_UUID DetailMeasured() const;
108  void SetDetailMeasured(ON_UUID uuid);
109 
110  // If DetailMeasured() returns ON_nil_uuid, DistanceScale() has no meaning
111  // If the dimension is in page space and measures model space geometry,
112  // DistanceScale() is the conversion from the model space distance being measured
113  // to the paper space distance spanned by the dimension geometry.
114  // When the zoom factor of the detail view changes, the distance scale will change
115  double DistanceScale() const;
116  void SetDistanceScale(double distance_scale) const;
117 
118  //virtual bool GetBBox(
119  // const ON_Viewport* vp,
120  // double dimscale,
121  // const ON_DimStyle* dimstyle,
122  // double* boxmin,
123  // double* boxmax,
124  // bool bGrow = 0) const = 0;
125 
126  virtual bool GetTextRect(ON_3dPoint text_rect[4]) const;
127 
128  // Remakes dimension text geometry object and sets it on the dimension
129  virtual bool UpdateDimensionText(
130  ON::LengthUnitSystem units_in,
131  const ON_DimStyle* dimstyle
132  ) const;
133 
134  // Makes text geometry for a dimension
135  ON_TextContent* RebuildDimensionText(
136  ON::LengthUnitSystem units_in,
137  const ON_DimStyle* dimstyle,
138  bool expandanglebrackets // replace <> with the formatted distance
139  ) const;
140 
141  virtual bool GetDistanceDisplayText(
142  ON::LengthUnitSystem units_in,
143  const ON_DimStyle* dimstyle,
144  ON_wString& displaytext) const;
145 
146  static bool GetCentermarkDisplay(
147  const ON_Plane& plane,
148  const ON_2dPoint center,
149  double marksize,
150  double radius,
152  ON_Line lines[6],
153  bool isline[6],
154  int maxlines
155  );
156 
157  static bool GetCentermarkSnapPoints(
158  const ON_Plane& plane,
159  const ON_2dPoint center,
160  double marksize,
161  double radius,
163  ON_3dPoint points[13],
164  bool ispoint[13]);
165 
166 
167  ON_Dimension::ForceArrow ForceArrowPosition() const;
168  void SetForceArrowPosition(ForceArrow force);
169 
170  ON_Dimension::ForceText ForceTextPosition() const;
171  void SetForceTextPosition(ForceText force);
172 
173 protected:
174  ON_wString m_user_text = L"<>"; // If user overridden, or "<>" to use default
175  double m_text_rotation = 0.0;
177 
178  bool m_use_default_text_point = true;
179  ON_2dPoint m_user_text_point = ON_2dPoint::UnsetPoint; // Text point if default isn't used
180 
181  mutable bool m_flip_arrow_1 = false;
182  mutable bool m_flip_arrow_2 = false;
183  mutable bool m_text_outside = false;
184  ForceArrow m_force_arrows = ForceArrow::Auto;
185  ForceText m_force_textpos = ForceText::Auto;
186 
187 
188  // UUID of detail if dimension is in page space measuring model space geometry
189  ON_UUID m_detail_measured = ON_nil_uuid;
190  // Conversion from model space size to paper space size if dimension is in page space measuring model space geometry
191  mutable double m_distance_scale = 1.0;
192 
193  bool Internal_WriteDimension(
194  ON_BinaryArchive& // serialize definition to binary archive
195  ) const;
196 
197  bool Internal_ReadDimension(
198  ON_BinaryArchive& // restore definition from binary archive
199  );
200 };
201 
202 class ON_CLASS ON_DimLinear : public ON_Dimension
203 {
204  ON_OBJECT_DECLARE(ON_DimLinear);
205 
206 public:
207  ON_DimLinear();
208  ~ON_DimLinear() = default;
209  ON_DimLinear(const ON_DimLinear& src) = default;
210  ON_DimLinear& operator=(const ON_DimLinear& src) = default;
211 
212  static const ON_DimLinear Empty;
213 
214  /*
215  Description:
216  Create a V6 linear dimension from a V5 linear dimension
217  The function is used when reading V5 files.
218  Parameters:
219  V5_linear_dimension -[in]
220  annotation_context - [in]
221  Dimstyle and other information referenced by V5_linear_dimension or nullptr if not available.
222  destination - [in]
223  If destination is not nullptr, then the V6 linear dimension is constructed
224  in destination. If destination is nullptr, then the new V6 linear dimension
225  is allocated with a call to new ON_DimLinear().
226  */
227  static ON_DimLinear* CreateFromV5DimLinear(
228  const class ON_OBSOLETE_V5_DimLinear& V5_linear_dimension,
229  const class ON_3dmAnnotationContext* annotation_context,
230  ON_DimLinear* destination
231  );
232 
233 
234  /*
235  Parameters:
236  annotation_type - [in]
237  annotation type to test
238  Returns:
239  True if input parameter is one of the valid linear dimension types
240  ON::AnnotationType::Aligned or ON::AnnotationType::Rotated.
241  */
242  static bool IsValidLinearDimensionType(
243  ON::AnnotationType annotation_type
244  );
245 
246  /*
247  Parameters:
248  linear_dimension_type - [in]
249  ON::AnnotationType::Aligned or ON::AnnotationType::Rotated.
250  Returns:
251  True if input parameter is valid and type is set.
252  */
253  bool SetLinearDimensionType(
254  ON::AnnotationType linear_dimension_type
255  );
256 
257  bool Write(
258  ON_BinaryArchive& // serialize definition to binary archive
259  ) const override;
260 
261  bool Read(
262  ON_BinaryArchive& // restore definition from binary archive
263  ) override;
264 
265  bool Transform(const ON_Xform& xform) override;
266 
267  // virtual ON_Geometry GetBBox override
268  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
269 
270  bool GetAnnotationBoundingBox(
271  const ON_Viewport* vp,
272  const ON_DimStyle* dimstyle,
273  double dimscale,
274  double* boxmin,
275  double* boxmax,
276  bool bGrow = false
277  ) const override; // ON_Annotation override
278 
279  // Gets transform for dimension text from ON_xy_plane to 3d display location
280  bool GetTextXform(
281  const ON_Viewport* vp,
282  const ON_DimStyle* dimstyle,
283  double dimscale,
284  ON_Xform& text_xform_out
285  ) const override;
286 
287  bool Create(
288  ON::AnnotationType dim_type,
289  const ON_UUID style_id,
290  const ON_Plane& plane,
291  const ON_3dVector& ref_horizontal,
292  const ON_3dPoint& def_pt1,
293  const ON_3dPoint& def_pt2,
294  const ON_3dPoint& dimline_pt,
295  double rotation_in_plane = 0.0
296  );
297 
298  /*
299  Description:
300  Create an aligned linear dimension. The dimension line is
301  parallel to the segment connecting the extension points.
302  Parameters:
303  extension_point0 - [in]
304  extension_point1 - [in]
305  locations of one of the points being dimensioned.
306  The dimension line will be parallel to the segment
307  connecting these points.
308  dimension_line_point - [in]
309  a point on the linear dimension line.
310  plane_normal - [in]
311  A vector perpindcular to the line between the extension points
312  that defines the orientation of the dimension's plane.
313  dim_style_id - [in]
314  destination - [in]
315  If nullptr, the returned ON_DimLinear is allocated by operator new.
316  Otherwise, the reuturned ON_DimLinear is created in destination.
317  */
318  static ON_DimLinear* CreateAligned(
319  ON_3dPoint extension_point0,
320  ON_3dPoint extension_point1,
321  ON_3dPoint dimension_line_point,
322  ON_3dVector plane_normal,
323  ON_UUID style_id,
324  ON_DimLinear* destination
325  );
326 
327  /*
328  Description:
329  Create a rotated linear dimension to the document.
330  The dimension line is explicitly specified.
331  Parameters:
332  extension_point0 - [in]
333  extension_point1 - [in]
334  locations of one of the points being dimensioned.
335  The dimension line will be parallel to the segment
336  connecting these points.
337  dimension_line - [in]
338  the dimension line. This is treated as an infinite
339  line and the points are automatically calculated.
340  plane_normal - [in]
341  A vector perpindcular to the line between the extension points
342  that defines the orientation of the dimension's plane.
343  The dimension line is projected to this plane.
344  dim_style_id - [in]
345  destination - [in]
346  If nullptr, the returned ON_DimLinear is allocated by operator new.
347  Otherwise, the reuturned ON_DimLinear is created in destination.
348  */
349  static ON_DimLinear* CreateRotated(
350  ON_3dPoint extension_point0,
351  ON_3dPoint extension_point1,
352  ON_Line dimension_line,
353  ON_3dVector plane_normal,
354  ON_UUID style_id,
355  ON_DimLinear* destination
356  );
357 
358  // virtual
359  double Measurement() const override;
360  ON_2dPoint DefaultTextPoint() const override;
361 
362  // DefPoint1 is m_plane.origin
363  // Meaasurement is between DefPoint1 and DefPoint2
364  // parallel to the m_plane x-axis.
365  ON_2dPoint DefPoint1() const;
366  ON_2dPoint DefPoint2() const;
367  ON_2dPoint DimlinePoint() const;
368 
369  void Set2dDefPoint1(ON_2dPoint pt);
370  void Set2dDefPoint2(ON_2dPoint pt);
371  void Set2dDimlinePoint(ON_2dPoint pt);
372 
373  void Set3dDefPoint1(ON_3dPoint pt);
374  void Set3dDefPoint2(ON_3dPoint pt);
375  void Set3dDimlinePoint(ON_3dPoint pt);
376 
377  ON_2dPoint ArrowPoint1() const; // Calculated
378  ON_2dPoint ArrowPoint2() const; // Calculated
379 
380  bool Get3dPoints(
381  ON_3dPoint* defpt1,
382  ON_3dPoint* defpt2,
383  ON_3dPoint* arrowpt1,
384  ON_3dPoint* arrowpt2,
385  ON_3dPoint* dimline,
386  ON_3dPoint* textpt) const;
387 
388  bool GetDisplayLines(
389  const ON_Viewport* vp,
390  const ON_DimStyle* style,
391  double dimscale,
392  ON_3dPoint text_rect[4],
393  ON_Line lines[4],
394  bool isline[4],
395  int maxlines) const;
397  void GetArrowXform(
398  int which_end,
399  double scale,
400  bool arrowflipped,
401  bool from_the_back,
402  ON_Xform& arrow_xform_out) const;
403 
404 protected:
405  ON_2dPoint m_def_pt_2 = ON_2dPoint::UnsetPoint;
406  ON_2dPoint m_dimline_pt = ON_2dPoint::UnsetPoint;
407 };
408 
409 //---------------------------------------------------------------------
410 
411 class ON_CLASS ON_DimAngular : public ON_Dimension
412 {
413  ON_OBJECT_DECLARE(ON_DimAngular);
414 
415 public:
416  ON_DimAngular();
417  ~ON_DimAngular() = default;
418  ON_DimAngular(const ON_DimAngular& src) = default;
419  ON_DimAngular& operator=(const ON_DimAngular& src) = default;
420 
421  static const ON_DimAngular Empty;
422 
423  /*
424  Parameters:
425  annotation_type - [in]
426  annotation type to test
427  Returns:
428  True if input parameter is one of the valid linear dimension types
429  ON::AnnotationType::Angular or ON::AnnotationType::Angular3pt.
430  */
431  static bool IsValidAngularDimensionType(
432  ON::AnnotationType annotation_type
433  );
434 
435  /*
436  Parameters:
437  angular_dimension_type - [in]
438  ON::AnnotationType::Angular or ON::AnnotationType::Angular3pt.
439  Returns:
440  True if input parameter is valid and type is set.
441  */
442  bool SetAngularDimensionType(
443  ON::AnnotationType angular_dimension_type
444  );
445 
446  static ON_DimAngular* CreateFromV5DimAngular(
447  const class ON_OBSOLETE_V5_DimAngular& V5_dim_angle,
448  const class ON_3dmAnnotationContext* annotation_context,
449  ON_DimAngular* destination
450  );
451 
452  bool Write(
453  ON_BinaryArchive& // serialize definition to binary archive
454  ) const override;
455 
456  bool Read(
457  ON_BinaryArchive& // restore definition from binary archive
458  ) override;
459 
460  bool Transform(const ON_Xform& xform) override;
461 
462  // virtual ON_Geometry GetBBox override
463  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
464 
465  bool GetAnnotationBoundingBox(
466  const ON_Viewport* vp,
467  const ON_DimStyle* dimstyle,
468  double dimscale,
469  double* boxmin,
470  double* boxmax,
471  bool bGrow = false
472  ) const override; // ON_Annotation override
473 
474  // Gets transform for dimension text from ON_xy_plane to 3d display location
475  bool GetTextXform(
476  const ON_Viewport* vp,
477  const ON_DimStyle* dimstyle,
478  double dimscale,
479  ON_Xform& text_xform_out
480  ) const override;
481 
482  /*
483  Parameters:
484  dim_style - [in]
485  Pass nullptr if a dim_style is not available.
486  arc - [in]
487  arc being dimensioned
488  offset - [in]
489  distance from the arc being dimensioned to the angular dimension arc.
490  When offset > 0, the dimension is outside the arc's circle.
491  When offset < 0 and > - arc.Radius(), the dimension is inside the arc's circle.
492  In all other cases, the angular dimension arc is on the arc.
493  Returns:
494  True if successful.
495  False if input is not valid. In this case ON_DimAngle::Empty settings are returned.
496  */
497  bool Create(
498  const ON_DimStyle* dim_style,
499  ON_Arc arc,
500  double offset
501  );
502 
503  /*
504  Description:
505  The angle between the lines is dimensioned.
506 
507  If the lines intersect in a single point, that point is used as the center
508  of the angular dimension arc. In this case, there are eight possible angles
509  to dimension. The point_on_angular_dimension_arc and point_on_line parameters
510  are used to select the correct angle to dimension. If a point_on_line parameter
511  is not set, the corresponding line's midpoint is used.
512 
513  If the lines are colinear, the point on the line closest to
514  point_on_angular_dimension_arc is the center of the angular dimension arc.
515 
516  Parameters:
517  dim_style - [in]
518  Pass nullptr if a dim_style is not available.
519  line1 - [in]
520  point_on_line1 - [in]
521  If point_on_line1 is specified, it inidicates which semi-infinite portion of line1 to dimension.
522  Otherwise the midpoint of lne1 as a segment is used.
523  When in doubt, pass ON_3dPoint::UnsetPoint.
524  line2 - [in]
525  point_on_line2 - [in]
526  If point_on_line2 is specified, it inidicates which semi-infinite portion of line2 to dimension.
527  Otherwise the midpoint of line2 as a segment is used.
528  When in doubt, pass ON_3dPoint::UnsetPoint.
529  point_on_angular_dimension_arc - [in]
530  A point on the interior of the angular dimension arc.
531  bSetExtensionPoints - [in]
532  If bSetExtensionPoints is true, and a point_on_line parameter is valid, that point
533  is used as the extension point. Otherwise the angular dimension arc endpoint is used.
534  Returns:
535  True if successful.
536  False if input is not valid. In this case ON_DimAngle::Empty settings are returned.
537  */
538  bool Create(
539  const ON_DimStyle* dim_style,
540  ON_Line line1,
541  ON_3dPoint point_on_line1,
542  ON_Line line2,
543  ON_3dPoint point_on_line2,
544  ON_3dPoint point_on_angular_dimension_arc,
545  bool bSetExtensionPoints
546  );
547 
548  bool Create(
549  const ON_UUID style_id,
550  const ON_Plane& plane,
551  const ON_3dVector& ref_horizontal,
552  const ON_3dPoint& center_pt,
553  const ON_3dPoint& extension_pt1, // point on first extension vector
554  const ON_3dPoint& extension_pt2, // point on second extension vector
555  const ON_3dPoint& dimline_pt // point on dimension line
556  );
557 
558  bool Create(
559  const ON_UUID style_id,
560  const ON_Plane& plane,
561  const ON_3dVector& ref_horizontal,
562  const ON_3dPoint& extension_pt1, // start of first extension line
563  const ON_3dPoint& extension_pt2, // start of second extension line
564  const ON_3dPoint& direction_pt1, // point on first extension vector
565  const ON_3dPoint& direction_pt2, // point on second extension vector
566  const ON_3dPoint& dimline_pt // point on dimension line
567  );
568 
569  bool AdjustFromPoints(
570  const ON_Plane& plane,
571  const ON_3dPoint& center_pt,
572  const ON_3dPoint& extension_pt1, // point on first extension vector
573  const ON_3dPoint& extension_pt2, // point on second extension vector
574  const ON_3dPoint& dimline_pt // point on dimension line
575  );
576 
577  bool AdjustFromPoints(
578  const ON_Plane& plane,
579  const ON_3dPoint& extension_pt1, // start of first extension line
580  const ON_3dPoint& extension_pt2, // start of second extension line
581  const ON_3dPoint& direction_pt1, // point on first extension vector
582  const ON_3dPoint& direction_pt2, // point on second extension vector
583  const ON_3dPoint& dimline_pt // point on dimension line
584  );
585 
586  static bool FindAngleVertex(
587  ON_Line lines[2],
588  ON_3dPoint pickpoints[2],
589  const ON_Plane& plane,
590  ON_3dPoint& centerpoint_out);
591 
592 
593  bool UpdateDimensionText(const ON_DimStyle* dimstyle) const;
594 
595  bool GetAngleDisplayText(const ON_DimStyle* dimstyle, ON_wString& displaytext) const;
596 
597  // virtual
598  double Measurement() const override; // angle in radians
599  ON_2dPoint DefaultTextPoint() const override;
600  bool GetAngles(double* start_ang, double* end_ang, double* mid_ang) const;
601  double Radius() const;
602 
603  // CenterPoint is m_plane.origin
604  // Measurement is angle between m_vec_1 & m_vec_2 in radians
605  ON_2dPoint CenterPoint() const;
606  ON_2dPoint DefPoint1() const; // Start of first extension
607  ON_2dPoint DefPoint2() const; // Start of second extension
608  ON_2dPoint DimlinePoint() const; // Point on dimension arc
609  ON_2dPoint UserTextPoint() const; // Text point if user positioned
610  ON_2dVector ExtDir1() const; // Direction of first extension
611  ON_2dVector ExtDir2() const; // Direction of second extension
612  void SetExtDir1(const ON_2dVector& dir1);
613  void SetExtDir2(const ON_2dVector& dir2);
614 
615  void SetUserTextPoint(const ON_3dPoint& point);
616 
617  void Set2dCenterPoint(ON_2dPoint pt); // Apex of angle
618  void Set2dDefPoint1(ON_2dPoint pt); // Point where first extension starts
619  void Set2dDefPoint2(ON_2dPoint pt); // Point where second extension starts
620  void Set2dDimlinePoint(ON_2dPoint pt); // Point on dimension arc
621 
622  //void Set2dDefPoint1(ON_2dPoint pt); // Point where first extension starts
623  //void Set2dDefPoint2(ON_2dPoint pt); // Point where second extension starts
624  //void Set2dDimlinePoint(ON_2dPoint pt); // Point on dimension arc
625 
626  //void Set3dCenterPoint(ON_3dPoint pt);
627  //void Set3dDefPoint1(ON_3dPoint pt);
628  //void Set3dDefPoint2(ON_3dPoint pt);
629  //void Set3dDimlinePoint(ON_3dPoint pt);
630 
631  ON_2dPoint ArrowPoint1() const; // Calculated - start of arc
632  ON_2dPoint ArrowPoint2() const; // Calculated - end of arc
633 
634  bool Get3dPoints(
635  ON_3dPoint* center,
636  ON_3dPoint* defpt1,
637  ON_3dPoint* defpt2,
638  ON_3dPoint* arrowpt1,
639  ON_3dPoint* arrowpt2,
640  ON_3dPoint* dimline,
641  ON_3dPoint* textpt) const;
642 
643  bool GetDisplayLines(
644  const ON_Viewport* vp,
645  const ON_DimStyle* style,
646  double dimscale,
647  const ON_3dPoint text_rect[4],
648  ON_Line lines[2],
649  bool isline[2],
650  ON_Arc arcs[2],
651  bool isarc[2],
652  int maxlines,
653  int maxarcs) const;
654 
655  void GetArrowXform(
656  int which_end,
657  double arrowlength,
658  bool arrowflipped,
659  bool from_the_back,
660  ON_Xform& arrow_xform_out) const;
661 
662  bool UpdateDimensionText(
663  ON::LengthUnitSystem units_in,
664  const ON_DimStyle* dimstyle) const override;
666  bool GetDistanceDisplayText(
667  ON::LengthUnitSystem units_in,
668  const ON_DimStyle* dimstyle,
669  ON_wString& displaytext) const override;
670 
671 protected:
672  // Center point is at plane origin (0,0)
673  ON_2dVector m_vec_1 = ON_2dVector::XAxis;
675  double m_ext_offset_1 = 0.0; // distance along m_vec_1 to start extension line 1
676  double m_ext_offset_2 = 0.0; // distance along m_vec_2 to start extension line 2
677  ON_2dPoint m_dimline_pt = ON_2dPoint(1.0, 1.0); // point on interior of dimension arc
678 };
679 
680 //---------------------------------------------------------------------
681 
682 class ON_CLASS ON_DimRadial : public ON_Dimension
683 {
684  ON_OBJECT_DECLARE(ON_DimRadial);
685 
686 public:
687  ON_DimRadial();
688  ~ON_DimRadial() = default;
689  ON_DimRadial(const ON_DimRadial& src) = default;
690  ON_DimRadial& operator=(const ON_DimRadial& src) = default;
691 
692  static const ON_DimRadial Empty;
693 
694 
695  /*
696  Description:
697  Create a V6 radial dimension from a V5 radial dimension
698  The function is used when reading V5 files.
699  Parameters:
700  V5_radial_dimension -[in]
701  annotation_context - [in]
702  Dimstyle and other information referenced by V5_radial_dimension or nullptr if not available.
703  destination - [in]
704  If destination is not nullptr, then the V6 radial dimension is constructed
705  in destination. If destination is nullptr, then the new V6 radial dimension
706  is allocated with a call to new ON_DimRadial().
707  */
708  static ON_DimRadial* CreateFromV5DimRadial(
709  const class ON_OBSOLETE_V5_DimRadial& V5_radial_dimension,
710  const class ON_3dmAnnotationContext* annotation_context,
711  ON_DimRadial* destination
712  );
713 
714  /*
715  Parameters:
716  annotation_type - [in]
717  annotation type to test
718  Returns:
719  True if input parameter is one of the valid radial dimension types
720  ON::AnnotationType::Radius or ON::AnnotationType::Diameter.
721  */
722  static bool IsValidRadialDimensionType(
723  ON::AnnotationType annotation_type
724  );
725 
726  /*
727  Parameters:
728  radial_dimension_type - [in]
729  ON::AnnotationType::Radius or ON::AnnotationType::Diameter.
730  Returns:
731  True if input parameter is valid and type is set.
732  */
733  bool SetRadialDimensionType(
734  ON::AnnotationType radial_dimension_type
735  );
736 
737  bool Write(
738  ON_BinaryArchive& // serialize definition to binary archive
739  ) const override;
740 
741  bool Read(
742  ON_BinaryArchive& // restore definition from binary archive
743  ) override;
744 
745  bool Transform(const ON_Xform& xform) override;
746 
747  // virtual ON_Geometry GetBBox override
748  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
749 
750  bool GetAnnotationBoundingBox(
751  const ON_Viewport* vp,
752  const ON_DimStyle* dimstyle,
753  double dimscale,
754  double* boxmin,
755  double* boxmax,
756  bool bGrow = false
757  ) const override; // ON_Annotation override
758 
759  // Gets transform for dimension text from ON_xy_plane to 3d display location
760  bool GetTextXform(
761  const ON_Viewport* vp,
762  const ON_DimStyle* dimstyle,
763  double dimscale,
764  ON_Xform& text_xform_out
765  ) const override;
766 
767  bool Create(
768  ON::AnnotationType type,
769  const ON_UUID style_id,
770  const ON_Plane& plane,
771  const ON_3dPoint& center_pt,
772  const ON_3dPoint& radius_pt,
773  const ON_3dPoint& dimline_pt
774  );
775 
776  bool AdjustFromPoints(
777  const ON_Plane& plane,
778  const ON_3dPoint& center_pt,
779  const ON_3dPoint& radius_pt,
780  const ON_3dPoint& dimline_pt
781  );
782 
783  double Measurement() const override;
784 
785  ON_2dPoint DefaultTextPoint() const override;
786  ON_2dPoint CenterPoint() const;
787  ON_2dPoint RadiusPoint() const; // Point on arc being measured
788  ON_2dPoint DimlinePoint() const; // Endpoint of leader tail, not including landing
789  ON_2dPoint KneePoint() const; // Point where leader tail bends
790 
791  void Set2dCenterPoint(ON_2dPoint pt);
792  void Set2dRadiusPoint(ON_2dPoint pt);
793  void Set2dDimlinePoint(ON_2dPoint pt);
794 
795  void Set3dCenterPoint(ON_3dPoint pt);
796  void Set3dRadiusPoint(ON_3dPoint pt);
797  void Set3dDimlinePoint(ON_3dPoint pt);
798 
799  bool Get3dPoints(
800  ON_3dPoint* center_pt,
801  ON_3dPoint* radius_pt,
802  ON_3dPoint* dimline_pt,
803  ON_3dPoint* knee_pt) const;
804 
805  bool GetDisplayLines(
806  const ON_DimStyle* style,
807  double dimscale,
808  ON_3dPoint text_rect[4],
809  ON_Line lines[9],
810  bool isline[9],
811  int maxlines) const;
812 
813  void GetArrowXform(
814  double scale,
815  ON_Xform& arrow_xform_out) const;
816 
817 protected:
819  ON_2dPoint m_dimline_pt = ON_2dPoint::UnsetPoint;
820 };
821 
822 
823 //---------------------------------------------------------------------
824 // + dimpt
825 // |
826 // |
827 // |
828 // + kinkpt2
829 // \
830 // \ kinkoffset2
831 // \
832 // + kinkpt1
833 // |
834 // | kinkoffset1
835 // |
836 // + ldrpt
837 // 1
838 // 2
839 // 3
840 
841 class ON_CLASS ON_DimOrdinate : public ON_Dimension
842 {
843  ON_OBJECT_DECLARE(ON_DimOrdinate);
844 
845 public:
846  ON_DimOrdinate();
847  ~ON_DimOrdinate() = default;
848  ON_DimOrdinate(const ON_DimOrdinate& src) = default;
849  ON_DimOrdinate& operator=(const ON_DimOrdinate& src) = default;
850 
851  static const ON_DimOrdinate Empty;
852 
853 #pragma region RH_C_SHARED_ENUM [ON_DimOrdinate::MeasuredDirection] [Rhino.Geometry.OrdinateDimension.MeasuredDirection] [nested:byte]
854  /// <summary>
855  /// Ordinate dimension measures x or y direction
856  /// </summary>
857  enum class MeasuredDirection : unsigned char
858  {
859  /// <summary> </summary>
860  Unset = 0,
861  /// <summary> Measures horizontal distance </summary>
862  Xaxis = 1,
863  /// <summary> Measures vertical distance </summary>
864  Yaxis = 2,
865  };
866 #pragma endregion
867 
868  static ON_DimOrdinate::MeasuredDirection MeasuredDirectionFromUnsigned(
869  unsigned int measured_direction_as_unsigned
870  );
871 
872  static ON_DimOrdinate* CreateFromV5DimOrdinate(
873  const class ON_OBSOLETE_V5_DimOrdinate& V5_dim_ordinate,
874  const class ON_3dmAnnotationContext* annotation_context,
875  ON_DimOrdinate* destination
876  );
877 
878  bool Write(
879  ON_BinaryArchive& archive
880  ) const override;
881 
882  bool Read(
883  ON_BinaryArchive& archive
884  ) override;
885 
886  bool Transform(const ON_Xform& xform) override;
887 
888  // virtual ON_Geometry GetBBox override
889  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
890 
891  bool GetAnnotationBoundingBox(
892  const ON_Viewport* vp,
893  const ON_DimStyle* dimstyle,
894  double dimscale,
895  double* boxmin,
896  double* boxmax,
897  bool bGrow = false
898  ) const override; // ON_Annotation override
899 
900  // Gets transform for dimension text from ON_xy_plane to 3d display location
901  bool GetTextXform(
902  const ON_Viewport* vp,
903  const ON_DimStyle* dimstyle,
904  double dimscale,
905  ON_Xform& text_xform_out
906  ) const override;
907 
908  bool Create(
909  const ON_UUID style_id,
910  const ON_Plane& plane,
911  MeasuredDirection direction,
912  const ON_3dPoint& basept,
913  const ON_3dPoint& defpt,
914  const ON_3dPoint& ldrpt,
915  double kinkoffset1,
916  double kinkoffset2
917  );
918 
919  bool AdjustFromPoints(
920  const ON_Plane& plane,
921  MeasuredDirection direction,
922  const ON_3dPoint& basept,
923  const ON_3dPoint& defpt,
924  const ON_3dPoint& ldrpt,
925  double kinkoffset1,
926  double kinkoffset2
927  );
928 
929  ON_2dPoint DefPt() const;
930  ON_2dPoint LeaderPt() const;
931  ON_2dPoint KinkPt1() const;
932  ON_2dPoint KinkPt2() const;
933  double KinkOffset1() const;
934  double KinkOffset2() const;
935 
936  void Set2dDefPt(ON_2dPoint pt);
937  void Set2dLeaderPt(ON_2dPoint pt);
938  void SetKinkOffset1(double d);
939  void SetKinkOffset2(double d);
940 
941  void Set3dBasePoint(ON_3dPoint pt);
942  void Set3dDefPt(ON_3dPoint pt);
943  void Set3dLeaderPt(ON_3dPoint pt);
944 
945  ON_3dPoint Get3dBasePoint() const;
946  ON_3dPoint Get3dDefPt() const;
947  ON_3dPoint Get3dLeaderPt() const;
948  ON_3dPoint Get3dKinkPt1(double default_kink_offset = 1.0) const;
949  ON_3dPoint Get3dKinkPt2(double default_kink_offset = 1.0) const;
950 
951  bool Get3dPoints(
952  ON_3dPoint* base_pt,
953  ON_3dPoint* def_pt,
954  ON_3dPoint* ldr_pt,
955  ON_3dPoint* kink_pt1,
956  ON_3dPoint* kink_pt2,
957  double default_kink_offset = 1.0) const;
958 
959  bool GetDisplayLines(
960  const ON_DimStyle* style,
961  double dimscale,
962  ON_3dPoint text_rect[4],
963  ON_Line lines[3],
964  bool isline[3],
965  int maxlines) const;
967  bool CalcKinkPoints(
968  ON_2dPoint defpt,
969  ON_2dPoint ldrpt,
970  MeasuredDirection direction,
971  double default_kink_offset,
972  ON_2dPoint& kinkpt1_out,
973  ON_2dPoint& kinkpt2_out) const;
974 
975  MeasuredDirection ImpliedDirection(
976  ON_2dPoint defpt,
977  ON_2dPoint ldrpt
978  ) const;
979 
980  MeasuredDirection GetMeasuredDirection() const;
981  void SetMeasuredDirection(MeasuredDirection direction);
982 
983  double Measurement() const override;
984 
985 protected:
986  // Plane origin is base for measurements
987  // Measurements are from plane origin to dimension point
988  // in either x or y axis direction
989  MeasuredDirection m_direction = MeasuredDirection::Unset;
990 
993 
994  double m_kink_offset_1 = ON_UNSET_VALUE; // measures from defpt1 toward defpt2 to kink1
995  double m_kink_offset_2 = ON_UNSET_VALUE; // measures from kink1 toward defpt2 to kink2
996 };
997 
998 
999 //---------------------------------------------------------------------
1000 
1001 class ON_CLASS ON_Centermark : public ON_Dimension
1002 {
1003  ON_OBJECT_DECLARE(ON_Centermark);
1004 
1005 public:
1006  ON_Centermark();
1007  ~ON_Centermark() = default;
1008  ON_Centermark(const ON_Centermark& src) = default;
1009  ON_Centermark& operator=(const ON_Centermark& src) = default;
1010 
1011  static const ON_Centermark Empty;
1012 
1013  bool Write(
1014  ON_BinaryArchive& // serialize definition to binary archive
1015  ) const override;
1016 
1017  bool Read(
1018  ON_BinaryArchive& // restore definition from binary archive
1019  ) override;
1020 
1021  bool Transform(const ON_Xform& xform) override;
1022 
1023  bool GetTextXform(
1024  const ON_Viewport*,
1025  const ON_DimStyle*,
1026  double,
1027  ON_Xform&
1028  ) const override;
1029 
1030  // virtual ON_Geometry GetBBox override
1031  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
1032 
1033  bool GetAnnotationBoundingBox(
1034  const ON_Viewport* vp,
1035  const ON_DimStyle* dimstyle,
1036  double dimscale,
1037  double* boxmin,
1038  double* boxmax,
1039  bool bGrow = false
1040  ) const override; // ON_Annotation override
1041 
1042  bool Create(
1043  const ON_UUID style_id,
1044  const ON_Plane& plane,
1045  const ON_3dPoint& center_pt,
1046  const double radius
1047  );
1048 
1049  bool AdjustFromPoints(
1050  const ON_Plane& plane,
1051  const ON_3dPoint& center_pt
1052  );
1053 
1054  double Measurement() const override;
1055 
1056  ON_2dPoint CenterPoint() const;
1057  void Set2dCenterPoint(ON_2dPoint pt);
1058  void Set3dCenterPoint(ON_3dPoint pt);
1059 
1060  bool GetDisplayLines(
1061  const ON_DimStyle* style,
1062  double dimscale,
1063  ON_Line lines[6],
1064  bool isline[6],
1065  int maxlines) const;
1066 
1067  double Radius() const; // radius of marked circle
1068  void SetRadius(double radius);
1069 
1070 private:
1071  double m_radius = 0.0;
1072 };
1073 
1074 
1075 
1076 
1077 #endif
1078 
Definition: opennurbs_annotationbase.h:23
ON_UUID is a 16 byte universally unique identifier.
Definition: opennurbs_uuid.h:32
Definition: opennurbs_dimension.h:401
Definition: opennurbs_dimension.h:978
centermark_style
Style for drawing centermark for Radial dimensions and Centermark objects
Definition: opennurbs_dimensionstyle.h:996
An ON_Arc is a subcurve of 3d circle.
Definition: opennurbs_arc.h:33
MeasuredDirection
Ordinate dimension measures x or y direction
Definition: opennurbs_dimension.h:834
Definition: opennurbs_dimension.h:202
Definition: opennurbs_string.h:2020
Definition: opennurbs_dimensionstyle.h:218
Context for an annotation object. This context is required when converting current annotation objects...
Definition: opennurbs_archive.h:1592
ForceArrow
Arrowheads forced Inside, or Outside of extension lines, or moved to fit.
Definition: opennurbs_dimension.h:33
Definition: opennurbs_point.h:277
Definition: opennurbs_text.h:28
ON_wString m_plain_user_text
Definition: opennurbs_dimension.h:176
static const ON_2dVector YAxis
Definition: opennurbs_point.h:854
Definition: opennurbs_dimension.h:665
static const ON_2dVector XAxis
Definition: opennurbs_point.h:853
Definition: opennurbs_xform.h:28
Definition: opennurbs_dimension.h:24
static const ON_DimLinear Empty
Definition: opennurbs_dimension.h:212
Definition: opennurbs_dimension.h:818
Definition: opennurbs_line.h:20
static const ON_2dPoint UnsetPoint
Definition: opennurbs_point.h:291
Definition: opennurbs_array.h:409
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
Definition: opennurbs_viewport.h:31
Definition: opennurbs_point.h:460
Definition: opennurbs_plane.h:20
ForceText
Text forced Inside, Right or Left of extension lines, or moved to fit (Auto).
Definition: opennurbs_dimension.h:51
Definition: opennurbs_point.h:839
Definition: opennurbs_point.h:1152