opennurbs_linetype.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_LINETYPE_INC_)
18 #define OPENNURBS_LINETYPE_INC_
19 
20 
21 // Description:
22 // Determine if a line width is deemed to be a "hairline width" in Rhino
23 // Any width that is >0 and < 0.001 mm is a hairline width for printing
24 // Parameters:
25 // width_mm: [in] the width to examine in millimeters
26 // Returns:
27 // true if this is a hairline width
28 ON_DECL bool ON_IsHairlinePrintWidth( double width_mm );
29 
30 // Description:
31 // Return a width in millimeters that is a valid hairline width in rhino
32 ON_DECL double ON_HairlinePrintWidth();
33 
34 
35 
36 
37 //////////////////////////////////////////////////////////////////////
38 // class ON_Linetype
39 
40 class ON_CLASS ON_Linetype : public ON_ModelComponent
41 {
42  ON_OBJECT_DECLARE(ON_Linetype);
43 
44 public:
45  // no attributes are set.
46  static const ON_Linetype Unset;
47 
48  // index = -1, id, name and pattern are set.
49  static const ON_Linetype Continuous;
50 
51  // index = -2, id, name and pattern are set.
52  static const ON_Linetype ByLayer;
53 
54  // index = -3, id, name and pattern are set.
55  static const ON_Linetype ByParent;
56 
57  /*
58  Parameters:
59  model_component_reference - [in]
60  none_return_value - [in]
61  value to return if ON_Linetype::Cast(model_component_ref.ModelComponent())
62  is nullptr
63  Returns:
64  If ON_Linetype::Cast(model_component_ref.ModelComponent()) is not nullptr,
65  that pointer is returned. Otherwise, none_return_value is returned.
66  */
67  static const ON_Linetype* FromModelComponentRef(
68  const class ON_ModelComponentReference& model_component_reference,
69  const ON_Linetype* none_return_value
70  );
71 
72 public:
73 
74  ON_Linetype() ON_NOEXCEPT;
75  ~ON_Linetype() = default;
76  ON_Linetype(const ON_Linetype&);
77  ON_Linetype& operator=(const ON_Linetype&) = default;
78 
79  /*
80  Description:
81  Tests that name is set and there is at least one non-zero length segment
82  */
83  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
84 
85  void Dump( ON_TextLog& ) const override; // for debugging
86 
87  /*
88  Description:
89  Write to file
90  */
91  bool Write(
92  ON_BinaryArchive& // serialize definition to binary archive
93  ) const override;
94 
95  /*
96  Description:
97  Read from file
98  */
99  bool Read(
100  ON_BinaryArchive& // restore definition from binary archive
101  ) override;
102 
103 
104  //////////////////////////////////////////////////////////////////////
105  //
106  // Interface
107 
108  bool PatternIsSet() const;
109  bool ClearPattern();
110  bool PatternIsLocked() const;
111  void LockPattern();
112 
113  /*
114  Description:
115  Returns the total length of one repeat of the pattern
116  */
117  double PatternLength() const;
118 
119 
120  /*
121  Description:
122  Returns the number of segments in the pattern
123  */
124  int SegmentCount() const;
125 
126  /*
127  Description:
128  Adds a segment to the pattern
129  Returns:
130  Index of the added segment.
131  */
132  int AppendSegment( const ON_LinetypeSegment& segment);
133 
134  /*
135  Description:
136  Removes a segment in the linetype.
137  Parameters:
138  index - [in]
139  Zero based index of the segment to remove.
140  Returns:
141  True if the segment index was removed.
142  */
143  bool RemoveSegment( int index );
144 
145  /*
146  Description:
147  Sets the segment at index to match segment
148  */
149  bool SetSegment( int index, const ON_LinetypeSegment& segment);
150 
151  /*
152  Description:
153  Sets the length and type of the segment at index
154  */
155  bool SetSegment( int index, double length, ON_LinetypeSegment::eSegType type);
156 
157  /*
158  Description:
159  Returns a copy of the segment at index
160  */
161  ON_LinetypeSegment Segment( int index) const;
162 
163  /*
164  Description:
165  Expert user function to get access to the segment array
166  for rapid calculations.
167  */
168  // Returns nullptr if the line pattern is locked.
169  ON_SimpleArray<ON_LinetypeSegment>* ExpertSegments();
170 
171  const ON_SimpleArray<ON_LinetypeSegment>& Segments() const;
172 
173 private:
174  enum : unsigned char
175  {
176  pattern_bit = 1
177  };
178  unsigned char m_is_set_bits = 0;
179  unsigned char m_is_locked_bits = 0;
180  unsigned short m_reserved1 = 0;
181  unsigned int m_reserved2 = 0;
183 };
184 
185 #if defined(ON_DLL_TEMPLATE)
186 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_Linetype*>;
187 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<const ON_Linetype*>;
188 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Linetype>;
189 #endif
190 
191 #endif
192 
The ON_ModelComponent class is a base class for all components in a model and manages the index...
Definition: opennurbs_model_component.h:24
Definition: opennurbs_array.h:36
ON_Object array is used to store lists of classes that are derived from ON_Object. It differs from ON_ClassArray in that the virtual ON_Object::MemoryRelocate function is called when growing the dynamic array requires changing the location of the memory buffer used to store the elements in the array.
Definition: opennurbs_array.h:725
class ON_LinetypeSegment
Definition: opennurbs_linestyle.h:88
static const ON_ModelComponent Unset
Definition: opennurbs_model_component.h:222
class ON_Linetype
Definition: opennurbs_linetype.h:42
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
Definition: opennurbs_model_component.h:1622