opennurbs_3dm_attributes.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 ////////////////////////////////////////////////////////////////
18 //
19 // defines ON_3dmObjectAttributes
20 //
21 ////////////////////////////////////////////////////////////////
22 
23 #if !defined(OPENNURBS_3DM_ATTRIBUTES_INC_)
24 #define OPENNURBS_3DM_ATTRIBUTES_INC_
25 
26 
27 /*
28 Description:
29  Top level OpenNURBS objects have geometry and attributes. The
30  geometry is stored in some class derived from ON_Geometry and
31  the attributes are stored in an ON_3dmObjectAttributes class.
32  Examples of attributes are object name, object id, display
33  attributes, group membership, layer membership, and so on.
34 
35 Remarks:
36  7 January 2003 Dale Lear
37  Derived from ON_Object so ON_UserData can be attached
38  to ON_3dmObjectAttributes.
39 */
40 
41 class ON_CLASS ON_3dmObjectAttributes : public ON_Object
42 {
43  ON_OBJECT_DECLARE(ON_3dmObjectAttributes);
44 
45 public:
48 
49 public:
50  // ON_Object virtual interface. See ON_Object
51  // for details.
52 
53  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
54  // virtual
55  void Dump( ON_TextLog& ) const override;
56  // virtual
57  unsigned int SizeOf() const override;
58  // virtual
59  bool Write(ON_BinaryArchive&) const override;
60  // virtual
61  bool Read(ON_BinaryArchive&) override;
62 
63  /*
64  Returns:
65  True if successful.
66  (xform is invertable or didn't need to be).
67  */
68  bool Transform( const ON_Xform& xform );
69 
70  // attributes of geometry and dimension table objects
71 public:
74 
75  // Default C++ copy constructor and operator= work fine
76  // Do not provide custom versions
77  // NO // ON_3dmObjectAttributes(const ON_3dmObjectAttributes&);
78  // NO // ON_3dmObjectAttributes& operator=(const ON_3dmObjectAttributes&);
79 
80  bool operator==(const ON_3dmObjectAttributes&) const;
81  bool operator!=(const ON_3dmObjectAttributes&) const;
82 
83  // Initializes all attributes to the default values.
84  void Default();
85 
86 
88  const class ON_ComponentManifest& source_manifest,
89  const class ON_ComponentManifest& destination_manifest,
90  const class ON_ManifestMap& manifest_map
91  ) override;
92 
93  // Interface ////////////////////////////////////////////////////////
94 
95  // An OpenNURBS object must be in one of three modes: normal, locked
96  // or hidden. If an object is in normal mode, then the object's layer
97  // controls visibility and selectability. If an object is locked, then
98  // the object's layer controls visibility by the object cannot be selected.
99  // If the object is hidden, it is not visible and it cannot be selected.
100  ON::object_mode Mode() const;
101  void SetMode( ON::object_mode ); // See Mode().
102 
103  /*
104  Description:
105  Use this query to determine if an object is part of an
106  instance definition.
107  Returns:
108  True if the object is part of an instance definition.
109  */
110  bool IsInstanceDefinitionObject() const;
111 
112  /*
113  Returns:
114  Returns true if object is visible.
115  See Also:
116  ON_3dmObjectAttributes::SetVisible
117  */
118  bool IsVisible() const;
119 
120  /*
121  Description:
122  Controls object visibility
123  Parameters:
124  bVisible - [in] true to make object visible,
125  false to make object invisible
126  See Also:
127  ON_3dmObjectAttributes::IsVisible
128  */
129  void SetVisible( bool bVisible );
130 
131  // The Linetype used to display an OpenNURBS object is specified in one of two ways.
132  // If LinetypeSource() is ON::linetype_from_layer, then the object's layer
133  // ON_Layer::Linetype() is used.
134  // If LinetypeSource() is ON::linetype_from_object, then value of m_linetype is used.
135  ON::object_linetype_source LinetypeSource() const;
136  void SetLinetypeSource( ON::object_linetype_source ); // See LinetypeSource().
137 
138  // The color used to display an OpenNURBS object is specified in one of three ways.
139  // If ColorSource() is ON::color_from_layer, then the object's layer
140  // ON_Layer::Color() is used.
141  // If ColorSource() is ON::color_from_object, then value of m_color is used.
142  // If ColorSource() is ON::color_from_material, then the diffuse color of the object's
143  // render material is used. See ON_3dmObjectAttributes::MaterialSource() to
144  // determine where to get the definition of the object's render material.
145  ON::object_color_source ColorSource() const;
146  void SetColorSource( ON::object_color_source ); // See ColorSource().
147 
148  // The color used to plot an OpenNURBS object on paper is specified
149  // in one of three ways.
150  // If PlotColorSource() is ON::plot_color_from_layer, then the object's layer
151  // ON_Layer::PlotColor() is used.
152  // If PlotColorSource() is ON::plot_color_from_object, then value of PlotColor() is used.
153  ON::plot_color_source PlotColorSource() const;
154  void SetPlotColorSource( ON::plot_color_source ); // See PlotColorSource().
155 
156  ON::plot_weight_source PlotWeightSource() const;
157  void SetPlotWeightSource( ON::plot_weight_source );
158 
159  /*
160  Description:
161  If "this" has attributes (color, plot weight, ...) with
162  "by parent" sources, then the values of those attributes
163  on parent_attributes are copied.
164  Parameters:
165  parent_attributes - [in]
166  parent_layer - [in]
167  control_limits - [in]
168  The bits in control_limits determine which attributes may
169  may be copied.
170  1: visibility
171  2: color
172  4: render material
173  8: plot color
174  0x10: plot weight
175  0x20: linetype
176  0x40: display order
177 
178  Returns:
179  The bits in the returned integer indicate which attributes were
180  actually modified.
181 
182  1: visibility
183  2: color
184  4: render material
185  8: plot color
186  0x10: plot weight
187  0x20: linetype
188  0x40: display order
189  */
190  //ON_DEPRECATED unsigned int ApplyParentalControl(
191  // const ON_3dmObjectAttributes& parent_attributes,
192  // unsigned int control_limits = 0xFFFFFFFF
193  // );
194 
195  unsigned int ApplyParentalControl(
196  const ON_3dmObjectAttributes& parent_attributes,
197  const ON_Layer& parent_layer,
198  unsigned int control_limits = 0xFFFFFFFF
199  );
200 
201  // Every OpenNURBS object has a UUID (universally unique identifier). The
202  // default value is nullptr. When an OpenNURBS object is added to a model, the
203  // value is checked. If the value is nullptr, a new UUID is created. If the
204  // value is not nullptr but it is already used by another object in the model,
205  // a new UUID is created. If the value is not nullptr and it is not used by
206  // another object in the model, then that value persists. When an object
207  // is updated, by a move for example, the value of m_uuid persists.
208  ON_UUID m_uuid;
209 
210  // The m_name member is public to avoid breaking the SDK.
211  // Use SetName() and Name() for proper validation.
212  // OpenNURBS object have optional text names. More than one object in
213  // a model can have the same name and some objects may have no name.
214  // ON_ModelComponent::IsValidComponentName(m_name) should be true.
215  ON_wString m_name;
216 
217  bool SetName(
218  const wchar_t* name,
219  bool bFixInvalidName
220  );
222  const ON_wString Name() const;
223 
224  // OpenNURBS objects may have an URL. There are no restrictions on what
225  // value this URL may have. As an example, if the object came from a
226  // commercial part library, the URL might point to the definition of that
227  // part.
228  ON_wString m_url;
229 
230  // Layer definitions in an OpenNURBS model are stored in a layer table.
231  // The layer table is conceptually an array of ON_Layer classes. Every
232  // OpenNURBS object in a model is on some layer. The object's layer
233  // is specified by zero based indicies into the ON_Layer array.
234  int m_layer_index;
235 
236  // Linetype definitions in an OpenNURBS model are stored in a linetype table.
237  // The linetype table is conceptually an array of ON_Linetype classes. Every
238  // OpenNURBS object in a model references some linetype. The object's linetype
239  // is specified by zero based indicies into the ON_Linetype array.
240  // index 0 is reserved for continuous linetype (no pattern)
241  int m_linetype_index;
242 
243  // Rendering material:
244  // If you want something simple and fast, set
245  // m_material_index to the index of the rendering material
246  // and ignore m_rendering_attributes.
247  // If you are developing a high quality plug-in renderer,
248  // and a user is assigning one of your fabulous rendering
249  // materials to this object, then add rendering material
250  // information to the m_rendering_attributes.m_materials[]
251  // array.
252  //
253  // Developers:
254  // As soon as m_rendering_attributes.m_materials[] is not empty,
255  // rendering material queries slow down. Do not populate
256  // m_rendering_attributes.m_materials[] when setting
257  // m_material_index will take care of your needs.
258  int m_material_index;
259  ON_ObjectRenderingAttributes m_rendering_attributes;
260 
261  //////////////////////////////////////////////////////////////////
262  //
263  // BEGIN: Per object mesh parameter support
264  //
265 
266  /*
267  Parameters:
268  mp - [in]
269  per object mesh parameters
270  Returns:
271  True if successful.
272  */
273  bool SetCustomRenderMeshParameters(const class ON_MeshParameters& mp);
274 
275  /*
276  Parameters:
277  bEnable - [in]
278  true to enable use of the per object mesh parameters.
279  false to disable use of the per object mesh parameters.
280  Returns:
281  False if the object doe not have per object mesh parameters
282  and bEnable was true. Use SetMeshParameters() to set
283  per object mesh parameters.
284  Remarks:
285  Sets the value of ON_MeshParameters::m_bCustomSettingsDisabled
286  to !bEnable
287  */
288  bool EnableCustomRenderMeshParameters(bool bEnable);
289 
290  /*
291  Returns:
292  Null or a pointer to fragile mesh parameters.
293  If a non-null pointer is returned, copy it and use the copy.
294  * DO NOT SAVE THIS POINTER FOR LATER USE. A call to
295  DeleteMeshParameters() will delete the class.
296  * DO NOT const_cast the returned pointer and change its
297  settings. You must use either SetMeshParameters()
298  or EnableMeshParameters() to change settings.
299  Remarks:
300  If the value of ON_MeshParameters::m_bCustomSettingsDisabled is
301  true, then do no use these parameters to make a render mesh.
302  */
303  const ON_MeshParameters* CustomRenderMeshParameters() const;
304 
305  /*
306  Description:
307  Deletes any per object mesh parameters.
308  */
309  void DeleteCustomRenderMeshParameters();
310 
311  //
312  // END: Per object mesh parameter support
313  //
314  //////////////////////////////////////////////////////////////////
315 
316 
317  /*
318  Description:
319  Determine if the simple material should come from
320  the object or from it's layer.
321  High quality rendering plug-ins should use m_rendering_attributes.
322  Returns:
323  Where to get material information if you do are too lazy
324  to look in m_rendering_attributes.m_materials[].
325  */
326  ON::object_material_source MaterialSource() const;
327 
328  /*
329  Description:
330  Specifies if the simple material should be the one
331  indicated by the material index or the one indicated
332  by the object's layer.
333  Parameters:
334  ms - [in]
335  */
336  void SetMaterialSource( ON::object_material_source ms );
337 
338  // If ON::color_from_object == ColorSource(), then m_color is the object's
339  // display color.
340  ON_Color m_color;
341 
342  // If ON::plot_color_from_object == PlotColorSource(), then m_color is the object's
343  // display color.
344  ON_Color m_plot_color;
346  // Display order used to force objects to be drawn on top or behind each other
347  // 0 = draw object in standard depth buffered order
348  // <0 = draw object behind "normal" draw order objects
349  // >0 = draw object on top of "noraml" draw order objects
350  // Larger number draws on top of smaller number.
351  int m_display_order;
352 
353  // Plot weight in millimeters.
354  // =0.0 means use the default width
355  // <0.0 means don't plot (visible for screen display, but does not show on plot)
356  double m_plot_weight_mm;
357 
358  // Used to indicate an object has a decoration (like an arrowhead on a curve)
359  ON::object_decoration m_object_decoration;
361  // When a surface object is displayed in wireframe, m_wire_density controls
362  // how many isoparametric wires are used.
363  //
364  // @table
365  // value number of isoparametric wires
366  // -1 boundary wires
367  // 0 boundary and knot wires
368  // 1 boundary and knot wires and, if there are no
369  // interior knots, a single interior wire.
370  // N>=2 boundary and knot wires and (N-1) interior wires
371  int m_wire_density;
372 
373 
374  // If m_viewport_id is nil, the object is active in
375  // all viewports. If m_viewport_id is not nil, then
376  // this object is only active in a specific view.
377  // This field is primarily used to assign page space
378  // objects to a specific page, but it can also be used
379  // to restrict model space to a specific view.
380  ON_UUID m_viewport_id;
381 
382  // Starting with V4, objects can be in either model space
383  // or page space. If an object is in page space, then
384  // m_viewport_id is not nil and identifies the page it
385  // is on.
386  ON::active_space m_space;
387 
388 private:
389  bool m_bVisible;
390  unsigned char m_mode; // (m_mode % 16) = ON::object_mode values
391  // (m_mode / 16) = ON::display_mode values
392  unsigned char m_color_source; // ON::object_color_source values
393  unsigned char m_plot_color_source; // ON::plot_color_source values
394  unsigned char m_plot_weight_source; // ON::plot_weight_source values
395  unsigned char m_material_source; // ON::object_material_source values
396  unsigned char m_linetype_source; // ON::object_linetype_source values
397 
398  unsigned char m_reserved_0;
399 
400  ON_Xform m_reserved_future_frame = ON_Xform::Nan;
401 
402  ON_SimpleArray<int> m_group; // array of zero based group indices
403 
404 private:
405  ON__UINT_PTR m_reserved_ptr = 0;
406 
407 public:
408  // group interface
409 
410  // returns number of groups object belongs to
411  int GroupCount() const;
412 
413  // Returns and array an array of GroupCount() zero based
414  // group indices. If GroupCount() is zero, then GroupList()
415  // returns nullptr.
416  const int* GroupList() const;
417 
418  // Returns GroupCount() and puts a list of zero based group indices
419  // into the array.
420  int GetGroupList(ON_SimpleArray<int>&) const;
421 
422  // Returns the index of the last group in the group list
423  // or -1 if the object is not in any groups
424  int TopGroup() const;
425 
426  // Returns true if object is in group with the specified index
427  bool IsInGroup(
428  int // zero based group index
429  ) const;
430 
431  // Returns true if the object is in any of the groups in the list
432  bool IsInGroups(
433  int, // group_list_count
434  const int* // group_list[] array
435  ) const;
436 
437  // Returns true if object is in any of the groups in the list
438  bool IsInGroups(
439  const ON_SimpleArray<int>& // group_list[] array
440  ) const;
441 
442  // Adds object to the group with specified index by appending index to
443  // group list (If the object is already in group, nothing is changed.)
444  void AddToGroup(
445  int // zero based group index
446  );
447 
448  // Removes object from the group with specified index. If the
449  // object is not in the group, nothing is changed.
450  void RemoveFromGroup(
451  int // zero based group index
452  );
453 
454  // removes the object from the last group in the group list
455  void RemoveFromTopGroup();
456 
457  // Removes object from all groups.
458  void RemoveFromAllGroups();
459 
460 
461  // display material references
462 
463  /*
464  Description:
465  Searches for a matching display material. For a given
466  viewport id, there is at most one display material.
467  For a given display material id, there can be multiple
468  viewports. If there is a display reference in the
469  list with a nil viewport id, then the display material
470  will be used in all viewports that are not explictly
471  referenced in other ON_DisplayMaterialRefs.
472 
473  Parameters:
474  search_material - [in]
475  found_material - [out]
476 
477  If FindDisplayMaterialRef(), the input value of search_material
478  is never changed. If FindDisplayMaterialRef() returns true,
479  the chart shows the output value of display_material. When
480  there are multiple possibilities for a match, the matches
481  at the top of the chart have higher priority.
482 
483  search_material found_material
484  input value output value
485 
486  (nil,nil) (nil,did) if (nil,did) is in the list.
487  (nil,did) (vid,did) if (vid,did) is in the list.
488  (nil,did) (nil,did) if (nil,did) is in the list.
489  (vid,nil) (vid,did) if (vid,did) is in the list
490  (vid,nil) (vid,did) if (nil,did) is in the list
491  (vid,did) (vid,did) if (vid,did) is in the list.
492 
493  Example:
494  ON_UUID display_material_id = ON_nil_uuid;
495  ON_Viewport vp = ...;
496  ON_DisplayMaterialRef search_dm;
497  search_dm.m_viewport_id = vp.ViewportId();
498  ON_DisplayMaterialRef found_dm;
499  if ( attributes.FindDisplayMaterial(search_dm, &found_dm) )
500  {
501  display_material_id = found_dm.m_display_material_id;
502  }
503 
504  Returns:
505  True if a matching display material is found.
506  See Also:
507  ON_3dmObjectAttributes::AddDisplayMaterialRef
508  ON_3dmObjectAttributes::RemoveDisplayMaterialRef
509  */
510  bool FindDisplayMaterialRef(
511  const ON_DisplayMaterialRef& search_material,
512  ON_DisplayMaterialRef* found_material = nullptr
513  ) const;
514 
515  /*
516  Description:
517  Quick way to see if a viewport has a special material.
518  Parameters:
519  viewport_id - [in]
520  display_material_id - [out]
521  Returns:
522  True if a material_id is assigned.
523  */
524  bool FindDisplayMaterialId(
525  const ON_UUID& viewport_id,
526  ON_UUID* display_material_id = nullptr
527  ) const;
528 
529  /*
530  Description:
531  Add a display material reference to the attributes. If
532  there is an existing entry with a matching viewport id,
533  the existing entry is replaced.
534  Parameters:
535  display_material - [in]
536  Returns:
537  True if input is valid (material id != nil)
538  See Also:
539  ON_3dmObjectAttributes::FindDisplayMaterialRef
540  ON_3dmObjectAttributes::RemoveDisplayMaterialRef
541  */
542  bool AddDisplayMaterialRef(
543  ON_DisplayMaterialRef display_material
544  );
545 
546  /*
547  Description:
548  Remove a display material reference from the list.
549  Parameters:
550  viewport_id - [in] Any display material references
551  with this viewport id will be removed. If nil,
552  then viewport_id is ignored.
553  display_material_id - [in]
554  Any display material references that match the
555  viewport_id and have this display_material_id
556  will be removed. If nil, then display_material_id
557  is ignored.
558  Returns:
559  True if a display material reference was removed.
560  See Also:
561  ON_3dmObjectAttributes::FindDisplayMaterialRef
562  ON_3dmObjectAttributes::AddDisplayMaterialRef
563  */
564  bool RemoveDisplayMaterialRef(
565  ON_UUID viewport_id,
566  ON_UUID display_material_id = ON_nil_uuid
567  );
568 
569  /*
570  Description:
571  Remove a the entire display material reference list.
572  */
573  void RemoveAllDisplayMaterialRefs();
574 
575  /*
576  Returns:
577  Number of diplay material refences.
578  */
579  int DisplayMaterialRefCount() const;
580 
582 
583 private:
584  bool Internal_WriteV5( ON_BinaryArchive& archive ) const;
585  bool Internal_ReadV5( ON_BinaryArchive& archive );
586 };
587 
588 #endif
589 
590 // Brian G adding another comment on Tim's machine.
ON_UUID is a 16 byte universally unique identifier.
Definition: opennurbs_uuid.h:32
virtual bool UpdateReferencedComponents(const class ON_ComponentManifest &source_manifest, const class ON_ComponentManifest &destination_manifest, const class ON_ManifestMap &manifest_map)
Uses the destination_manifest to update references to other components. This is typically done when a...
ON_ManifestIdentificationMap is used to record a map from a source manifest to a destination manifest...
Definition: opennurbs_archive.h:1464
Objects can have per viewport display properties that override a viewport&#39;s default display propertie...
Definition: opennurbs_linestyle.h:45
static const ON_3dmObjectAttributes Unset
Definition: opennurbs_3dm_attributes.h:46
Definition: opennurbs_string.h:2020
static const ON_Xform Nan
ON_Xform::Nan - every coefficient is ON_DBL_QNAN.
Definition: opennurbs_xform.h:44
Definition: opennurbs_color.h:24
Definition: opennurbs_layer.h:20
virtual unsigned int SizeOf() const
static const ON_3dmObjectAttributes DefaultAttributes
Definition: opennurbs_3dm_attributes.h:47
Definition: opennurbs_mesh.h:24
Definition: opennurbs_xform.h:28
virtual void Dump(ON_TextLog &) const
Creates a text dump of the object.
Definition: opennurbs_archive.h:478
virtual bool IsValid(class ON_TextLog *text_log=nullptr) const
Tests an object to see if its data members are correctly initialized.
Top level OpenNURBS objects have geometry and attributes. The geometry is stored in some class derive...
Definition: opennurbs_3dm_attributes.h:41
Definition: opennurbs_rendering.h:38
Pure virtual base class for all classes that must provide runtime class id or support object level 3D...
Definition: opennurbs_object.h:460
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
virtual bool Read(ON_BinaryArchive &binary_archive)
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
virtual bool Write(ON_BinaryArchive &binary_archive) const
Low level archive writing tool used by ON_BinaryArchive::WriteObject().