opennurbs_leader.h
1 
2 /* $NoKeywords: $ */
3 /*
4 //
5 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
6 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
7 // McNeel & Associates.
8 //
9 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
10 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
11 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
12 //
13 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
14 //
15 ////////////////////////////////////////////////////////////////
16 */
17 
18 // ON_Leader class
19 #ifndef OPENNURBS_LEADER_H_INCLUDED
20 #define OPENNURBS_LEADER_H_INCLUDED
21 
22 
23 class ON_CLASS ON_Leader : public ON_Annotation
24 {
25  ON_OBJECT_DECLARE(ON_Leader);
26 
27 public:
28  ON_Leader();
29  ~ON_Leader();
30 
31  ON_Leader(const ON_Leader& src);
32  ON_Leader& operator=(const ON_Leader& src);
33 
34  static const ON_Leader Empty;
35 
36 private:
37  void Internal_Destroy();
38  void Internal_CopyFrom(const ON_Leader& src);
39 
40 public:
41 
42  /*
43  Parameters:
44  dimstyle - [in]
45  If you want to specify text appearance or other custom properties ...
46  ON_DimStyle style = ON_DimStyle::DimStyleFromProperties( doc->DimStyleContext().CurrentDimStyle(), ... );
47  style.Set...(...);
48  Then pass &style
49 
50  Remarks:
51  Parses text string and makes runs
52  */
53  bool Create(
54  const wchar_t* leader_text,
55  const ON_DimStyle* dimstyle,
56  int point_count,
57  const ON_3dPoint* points,
58  const ON_Plane& plane,
59  bool bWrapped,
60  double rect_width
61  );
62 
63  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
64  void Dump(ON_TextLog& log) const override;
65  bool Write(ON_BinaryArchive& file) const override;
66  bool Read(ON_BinaryArchive& file) override;
67  ON::object_type ObjectType() const override;
68 
69  /*
70  Description:
71  Create a V6 leader from a V5 leader.
72  The function is used when reading V5 files.
73  Parameters:
74  v5_leader -[in]
75  dim_style - [in]
76  Dimstyle referenced by v5_leader or nullptr if not available.
77  destination - [in]
78  If destination is not nullptr, then the V6 leader is constructed
79  in destination. If destination is nullptr, then the new V6 leader
80  is allocated with a call to new ON_Leader().
81  */
82  static ON_Leader* CreateFromV5Leader(
83  const class ON_OBSOLETE_V5_Leader& V5_leader,
84  const class ON_3dmAnnotationContext* annotation_context,
85  ON_Leader* destination
86  );
87 
88  int Dimension() const override;
89 
90  // virtual ON_Geometry GetBBox override
91  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
92 
94  const ON_Viewport* vp,
95  const ON_DimStyle* dimstyle,
96  double dimscale,
97  double* boxmin,
98  double* boxmax,
99  bool bGrow = false
100  ) const override; // ON_Annotation override
101 
102  bool Transform(const ON_Xform& xform) override;
103 
104  bool GetTextGripPoints(
105  ON_2dPoint& base,
106  ON_2dPoint& width,
107  const ON_DimStyle* dimstyle,
108  double textscale) const;
109 
110  //bool Explode(
111  // const ON_DimStyle* dimstyle,
112  // ON_SimpleArray<const ON_Geometry*> object_parts) const;
113 
114  // Transforms text from natural position at origin to
115  // 3d location as it displays in the leader
116  bool GetTextXform(
117  const ON_Viewport* vp,
118  const ON_DimStyle* dimstyle,
119  double dimscale,
120  ON_Xform& text_xform_out
121  ) const override;
122 
123  void UpdateTextAlignment(ON_2dVector angle); // Sets text to right or left justified per leader direction
124 
125  const ON_NurbsCurve* Curve(
126  const ON_DimStyle* dimstyle
127  ) const; // cached curve for display and picking
128  void DeleteCurve() const;
129 
130  void SetPlane(ON_Plane plane);
131 
132  //// TailDirection is the tangent direction
133  //// of the end of the leader tail
134  //// Returns 1,0 if there isn't a tangent
135  ON_2dVector TailDirection(const ON_DimStyle* dimstyle) const;
136 
137  // These do nothing and return false if
138  // HasLanding is false
139  // Otherwise, they return a line added to the
140  // tail of the leader in the direction of
141  // LeaderContentAngleStyle()
142  bool LandingLine2d(
143  const ON_DimStyle* style,
144  double dimscale,
145  ON_Line& line) const;
146  bool LandingLine3d(
147  const ON_DimStyle* style,
148  double dimscale,
149  ON_Line& line) const;
150 
151  ON__UINT32 PointCount() const;
152  void SetPoints2d(int count, const ON_2dPoint* points);
153  void SetPoints3d(int count, const ON_3dPoint* points);
154  bool SetPoint2d(int idx, ON_2dPoint point);
155  bool SetPoint3d(int idx, ON_3dPoint point);
156  void InsertPoint2d(int atidx, ON_2dPoint point);
157  void InsertPoint3d(int atidx, ON_3dPoint point);
158  void AppendPoint2d(ON_2dPoint point);
159  bool AppendPoint3d(ON_3dPoint point);
160  void RemovePoint(int idx);
161  bool Point2d(int idx, ON_2dPoint& point) const;
162  bool Point3d(int idx, ON_3dPoint& point) const;
163 
164  bool GetTextPoint2d(
165  const ON_DimStyle* dimstyle,
166  double leaderscale,
167  ON_2dPoint& point) const;
168  //bool GetTextPoint3d(ON_3dPoint& point) const;
169  ON_2dPointArray& Points2d();
170  const ON_2dPointArray& Points2d() const;
171 
172  void InvalidateTextPoint();
173  bool UpdateTextPosition(
174  const ON_DimStyle* dimstyle,
175  double leaderscale);
176 
177 private:
178  ON_2dPointArray m_points;
179 
180  // runtime
181  mutable ON_NurbsCurve* m_curve = nullptr; // Deleted by ~ON_Leader()
182  mutable ON_2dPoint m_text_point = ON_2dPoint::UnsetPoint;
183 };
184 
185 
186 
187 #endif
188 
Definition: opennurbs_annotationbase.h:23
virtual bool Transform(const ON_Xform &xform)
Transforms the object.
virtual int Dimension() const
Dimension of the object.
virtual bool GetBBox(double *boxmin, double *boxmax, bool bGrowBox=false) const
This is the virtual function that actually calculates axis aligned bounding boxes.
void SetPlane(const ON_Plane &plane)
ON_Leader class.
Definition: opennurbs_leader.h:23
static const ON_Leader Empty
Definition: opennurbs_leader.h:34
Definition: opennurbs_dimensionstyle.h:218
bool IsValid(class ON_TextLog *text_log=nullptr) const override
Tests an object to see if its data members are correctly initialized.
Context for an annotation object. This context is required when converting current annotation objects...
Definition: opennurbs_archive.h:1592
virtual bool GetAnnotationBoundingBox(const ON_Viewport *vp, const ON_DimStyle *dimstyle, double dimscale, double *boxmin, double *boxmax, bool bGrow=false) const =0
Definition: opennurbs_point.h:277
Definition: opennurbs_xform.h:28
ON::object_type ObjectType() const override
Useful for switch statements that need to differentiate between basic object types like points...
ON_Annotation & operator=(const ON_Annotation &src)
virtual void Dump(ON_TextLog &) const
Creates a text dump of the object.
Definition: opennurbs_line.h:20
static const ON_2dPoint UnsetPoint
Definition: opennurbs_point.h:291
Definition: opennurbs_nurbscurve.h:26
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
Definition: opennurbs_viewport.h:31
virtual bool Read(ON_BinaryArchive &binary_archive)
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
Definition: opennurbs_point.h:460
virtual bool Write(ON_BinaryArchive &binary_archive) const
Low level archive writing tool used by ON_BinaryArchive::WriteObject().
virtual bool GetTextXform(const ON_Viewport *vp, const ON_DimStyle *dimstyle, double dimscale, ON_Xform &text_xform_out) const =0
Definition: opennurbs_plane.h:20
Definition: opennurbs_point.h:839
Definition: opennurbs_point.h:1973