Point Cloud Library (PCL)  1.9.1-dev
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:
46  // ON_Object virtual interface. See ON_Object
47  // for details.
48 
49  // virtual
50  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
51  // virtual
52  void Dump( ON_TextLog& ) const;
53  // virtual
54  unsigned int SizeOf() const;
55  // virtual
56  ON_BOOL32 Write(ON_BinaryArchive&) const;
57  // virtual
58  ON_BOOL32 Read(ON_BinaryArchive&);
59 
60  /*
61  Returns:
62  True if successful.
63  (xform is invertable or didn't need to be).
64  */
65  bool Transform( const ON_Xform& xform );
66 
67  // attributes of geometry and dimension table objects
68 public:
71 
72  // Default C++ copy constructor and operator= work fine
73  // Do not provide custom versions
74  // NO // ON_3dmObjectAttributes(const ON_3dmObjectAttributes&);
75  // NO // ON_3dmObjectAttributes& operator=(const ON_3dmObjectAttributes&);
76 
77  bool operator==(const ON_3dmObjectAttributes&) const;
78  bool operator!=(const ON_3dmObjectAttributes&) const;
79 
80  // Initializes all attributes to the default values.
81  void Default();
82 
83  // Interface ////////////////////////////////////////////////////////
84 
85  // An OpenNURBS object must be in one of three modes: normal, locked
86  // or hidden. If an object is in normal mode, then the object's layer
87  // controls visibility and selectability. If an object is locked, then
88  // the object's layer controls visibility by the object cannot be selected.
89  // If the object is hidden, it is not visible and it cannot be selected.
90  ON::object_mode Mode() const;
91  void SetMode( ON::object_mode ); // See Mode().
92 
93  /*
94  Description:
95  Use this query to determine if an object is part of an
96  instance definition.
97  Returns:
98  True if the object is part of an instance definition.
99  */
100  bool IsInstanceDefinitionObject() const;
101 
102  /*
103  Returns:
104  Returns true if object is visible.
105  See Also:
106  ON_3dmObjectAttributes::SetVisible
107  */
108  bool IsVisible() const;
109 
110  /*
111  Description:
112  Controls object visibility
113  Parameters:
114  bVisible - [in] true to make object visible,
115  false to make object invisible
116  See Also:
117  ON_3dmObjectAttributes::IsVisible
118  */
119  void SetVisible( bool bVisible );
120 
121  // The Linetype used to display an OpenNURBS object is specified in one of two ways.
122  // If LinetypeSource() is ON::linetype_from_layer, then the object's layer
123  // ON_Layer::Linetype() is used.
124  // If LinetypeSource() is ON::linetype_from_object, then value of m_linetype is used.
125  ON::object_linetype_source LinetypeSource() const;
126  void SetLinetypeSource( ON::object_linetype_source ); // See LinetypeSource().
127 
128  // The color used to display an OpenNURBS object is specified in one of three ways.
129  // If ColorSource() is ON::color_from_layer, then the object's layer
130  // ON_Layer::Color() is used.
131  // If ColorSource() is ON::color_from_object, then value of m_color is used.
132  // If ColorSource() is ON::color_from_material, then the diffuse color of the object's
133  // render material is used. See ON_3dmObjectAttributes::MaterialSource() to
134  // determine where to get the definition of the object's render material.
135  ON::object_color_source ColorSource() const;
136  void SetColorSource( ON::object_color_source ); // See ColorSource().
137 
138  // The color used to plot an OpenNURBS object on paper is specified
139  // in one of three ways.
140  // If PlotColorSource() is ON::plot_color_from_layer, then the object's layer
141  // ON_Layer::PlotColor() is used.
142  // If PlotColorSource() is ON::plot_color_from_object, then value of PlotColor() is used.
143  ON::plot_color_source PlotColorSource() const;
144  void SetPlotColorSource( ON::plot_color_source ); // See PlotColorSource().
145 
146  ON::plot_weight_source PlotWeightSource() const;
147  void SetPlotWeightSource( ON::plot_weight_source );
148 
149 
150  // OpenNURBS objects can be displayed in one of three ways: wireframe,
151  // shaded, or render preview. If the display mode is ON::default_display,
152  // then the display mode of the viewport detrmines how the object
153  // is displayed. If the display mode is ON::wireframe_display,
154  // ON::shaded_display, or ON::renderpreview_display, then the object is
155  // forced to display in that mode.
156  ON::display_mode DisplayMode() const;
157  void SetDisplayMode( ON::display_mode ); // See DisplayMode().
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 NULL. When an OpenNURBS object is added to a model, the
203  // value is checked. If the value is NULL, a new UUID is created. If the
204  // value is not NULL but it is already used by another object in the model,
205  // a new UUID is created. If the value is not NULL 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.
209 
210  // OpenNURBS object have optional text names. More than one object in
211  // a model can have the same name and some objects may have no name.
213 
214  // OpenNURBS objects may have an URL. There are no restrictions on what
215  // value this URL may have. As an example, if the object came from a
216  // commercial part library, the URL might point to the definition of that
217  // part.
219 
220  // Layer definitions in an OpenNURBS model are stored in a layer table.
221  // The layer table is conceptually an array of ON_Layer classes. Every
222  // OpenNURBS object in a model is on some layer. The object's layer
223  // is specified by zero based indicies into the ON_Layer array.
225 
226  // Linetype definitions in an OpenNURBS model are stored in a linetype table.
227  // The linetype table is conceptually an array of ON_Linetype classes. Every
228  // OpenNURBS object in a model references some linetype. The object's linetype
229  // is specified by zero based indicies into the ON_Linetype array.
230  // index 0 is reserved for continuous linetype (no pattern)
232 
233  // Rendering material:
234  // If you want something simple and fast, set
235  // m_material_index to the index of the rendering material
236  // and ignore m_rendering_attributes.
237  // If you are developing a high quality plug-in renderer,
238  // and a user is assigning one of your fabulous rendering
239  // materials to this object, then add rendering material
240  // information to the m_rendering_attributes.m_materials[]
241  // array.
242  //
243  // Developers:
244  // As soon as m_rendering_attributes.m_materials[] is not empty,
245  // rendering material queries slow down. Do not populate
246  // m_rendering_attributes.m_materials[] when setting
247  // m_material_index will take care of your needs.
250 
251  //////////////////////////////////////////////////////////////////
252  //
253  // BEGIN: Per object mesh parameter support
254  //
255 
256  /*
257  Parameters:
258  mp - [in]
259  per object mesh parameters
260  Returns:
261  True if successful.
262  */
263  bool SetCustomRenderMeshParameters(const class ON_MeshParameters& mp);
264 
265  /*
266  Parameters:
267  bEnable - [in]
268  true to enable use of the per object mesh parameters.
269  false to disable use of the per object mesh parameters.
270  Returns:
271  False if the object doe not have per object mesh parameters
272  and bEnable was true. Use SetMeshParameters() to set
273  per object mesh parameters.
274  Remarks:
275  Sets the value of ON_MeshParameters::m_bCustomSettingsDisabled
276  to !bEnable
277  */
278  bool EnableCustomRenderMeshParameters(bool bEnable);
279 
280  /*
281  Returns:
282  Null or a pointer to fragile mesh parameters.
283  If a non-null pointer is returned, copy it and use the copy.
284  * DO NOT SAVE THIS POINTER FOR LATER USE. A call to
285  DeleteMeshParameters() will delete the class.
286  * DO NOT const_cast the returned pointer and change its
287  settings. You must use either SetMeshParameters()
288  or EnableMeshParameters() to change settings.
289  Remarks:
290  If the value of ON_MeshParameters::m_bCustomSettingsDisabled is
291  true, then do no use these parameters to make a render mesh.
292  */
293  const ON_MeshParameters* CustomRenderMeshParameters() const;
294 
295  /*
296  Description:
297  Deletes any per object mesh parameters.
298  */
299  void DeleteCustomRenderMeshParameters();
300 
301  //
302  // END: Per object mesh parameter support
303  //
304  //////////////////////////////////////////////////////////////////
305 
306 
307  /*
308  Description:
309  Determine if the simple material should come from
310  the object or from it's layer.
311  High quality rendering plug-ins should use m_rendering_attributes.
312  Returns:
313  Where to get material information if you do are too lazy
314  to look in m_rendering_attributes.m_materials[].
315  */
316  ON::object_material_source MaterialSource() const;
317 
318  /*
319  Description:
320  Specifies if the simple material should be the one
321  indicated by the material index or the one indicated
322  by the object's layer.
323  Parameters:
324  ms - [in]
325  */
326  void SetMaterialSource( ON::object_material_source ms );
327 
328  // If ON::color_from_object == ColorSource(), then m_color is the object's
329  // display color.
331 
332  // If ON::plot_color_from_object == PlotColorSource(), then m_color is the object's
333  // display color.
335 
336  // Display order used to force objects to be drawn on top or behind each other
337  // 0 = draw object in standard depth buffered order
338  // <0 = draw object behind "normal" draw order objects
339  // >0 = draw object on top of "noraml" draw order objects
340  // Larger number draws on top of smaller number.
342 
343  // Plot weight in millimeters.
344  // =0.0 means use the default width
345  // <0.0 means don't plot (visible for screen display, but does not show on plot)
347 
348  // Used to indicate an object has a decoration (like an arrowhead on a curve)
349  ON::object_decoration m_object_decoration;
350 
351  // When a surface object is displayed in wireframe, m_wire_density controls
352  // how many isoparametric wires are used.
353  //
354  // @table
355  // value number of isoparametric wires
356  // -1 boundary wires
357  // 0 boundary and knot wires
358  // 1 boundary and knot wires and, if there are no
359  // interior knots, a single interior wire.
360  // N>=2 boundary and knot wires and (N-1) interior wires
362 
363 
364  // If m_viewport_id is nil, the object is active in
365  // all viewports. If m_viewport_id is not nil, then
366  // this object is only active in a specific view.
367  // This field is primarily used to assign page space
368  // objects to a specific page, but it can also be used
369  // to restrict model space to a specific view.
371 
372  // Starting with V4, objects can be in either model space
373  // or page space. If an object is in page space, then
374  // m_viewport_id is not nil and identifies the page it
375  // is on.
376  ON::active_space m_space;
377 
378 private:
379  bool m_bVisible;
380  unsigned char m_mode; // (m_mode % 16) = ON::object_mode values
381  // (m_mode / 16) = ON::display_mode values
382  unsigned char m_color_source; // ON::object_color_source values
383  unsigned char m_plot_color_source; // ON::plot_color_source values
384  unsigned char m_plot_weight_source; // ON::plot_weight_source values
385  unsigned char m_material_source; // ON::object_material_source values
386  unsigned char m_linetype_source; // ON::object_linetype_source values
387 
388  unsigned char m_reserved_0;
389 
390  ON_SimpleArray<int> m_group; // array of zero based group indices
391 public:
392 
393  // group interface
394 
395  // returns number of groups object belongs to
396  int GroupCount() const;
397 
398  // Returns and array an array of GroupCount() zero based
399  // group indices. If GroupCount() is zero, then GroupList()
400  // returns NULL.
401  const int* GroupList() const;
402 
403  // Returns GroupCount() and puts a list of zero based group indices
404  // into the array.
405  int GetGroupList(ON_SimpleArray<int>&) const;
406 
407  // Returns the index of the last group in the group list
408  // or -1 if the object is not in any groups
409  int TopGroup() const;
410 
411  // Returns true if object is in group with the specified index
412  ON_BOOL32 IsInGroup(
413  int // zero based group index
414  ) const;
415 
416  // Returns true if the object is in any of the groups in the list
417  ON_BOOL32 IsInGroups(
418  int, // group_list_count
419  const int* // group_list[] array
420  ) const;
421 
422  // Returns true if object is in any of the groups in the list
423  ON_BOOL32 IsInGroups(
424  const ON_SimpleArray<int>& // group_list[] array
425  ) const;
426 
427  // Adds object to the group with specified index by appending index to
428  // group list (If the object is already in group, nothing is changed.)
429  void AddToGroup(
430  int // zero based group index
431  );
432 
433  // Removes object from the group with specified index. If the
434  // object is not in the group, nothing is changed.
435  void RemoveFromGroup(
436  int // zero based group index
437  );
438 
439  // removes the object from the last group in the group list
440  void RemoveFromTopGroup();
441 
442  // Removes object from all groups.
443  void RemoveFromAllGroups();
444 
445 
446  // display material references
447 
448  /*
449  Description:
450  Searches for a matching display material. For a given
451  viewport id, there is at most one display material.
452  For a given display material id, there can be multiple
453  viewports. If there is a display reference in the
454  list with a nil viewport id, then the display material
455  will be used in all viewports that are not explictly
456  referenced in other ON_DisplayMaterialRefs.
457 
458  Parameters:
459  search_material - [in]
460  found_material - [out]
461 
462  If FindDisplayMaterialRef(), the input value of search_material
463  is never changed. If FindDisplayMaterialRef() returns true,
464  the chart shows the output value of display_material. When
465  there are multiple possibilities for a match, the matches
466  at the top of the chart have higher priority.
467 
468  search_material found_material
469  input value output value
470 
471  (nil,nil) (nil,did) if (nil,did) is in the list.
472  (nil,did) (vid,did) if (vid,did) is in the list.
473  (nil,did) (nil,did) if (nil,did) is in the list.
474  (vid,nil) (vid,did) if (vid,did) is in the list
475  (vid,nil) (vid,did) if (nil,did) is in the list
476  (vid,did) (vid,did) if (vid,did) is in the list.
477 
478  Example:
479  ON_UUID display_material_id = ON_nil_uuid;
480  ON_Viewport vp = ...;
481  ON_DisplayMaterialRef search_dm;
482  search_dm.m_viewport_id = vp.ViewportId();
483  ON_DisplayMaterialRef found_dm;
484  if ( attributes.FindDisplayMaterial(search_dm, &found_dm) )
485  {
486  display_material_id = found_dm.m_display_material_id;
487  }
488 
489  Returns:
490  True if a matching display material is found.
491  See Also:
492  ON_3dmObjectAttributes::AddDisplayMaterialRef
493  ON_3dmObjectAttributes::RemoveDisplayMaterialRef
494  */
495  bool FindDisplayMaterialRef(
496  const ON_DisplayMaterialRef& search_material,
497  ON_DisplayMaterialRef* found_material = NULL
498  ) const;
499 
500  /*
501  Description:
502  Quick way to see if a viewport has a special material.
503  Parameters:
504  viewport_id - [in]
505  display_material_id - [out]
506  Returns:
507  True if a material_id is assigned.
508  */
509  bool FindDisplayMaterialId(
510  const ON_UUID& viewport_id,
511  ON_UUID* display_material_id = NULL
512  ) const;
513 
514  /*
515  Description:
516  Add a display material reference to the attributes. If
517  there is an existing entry with a matching viewport id,
518  the existing entry is replaced.
519  Parameters:
520  display_material - [in]
521  Returns:
522  True if input is valid (material id != nil)
523  See Also:
524  ON_3dmObjectAttributes::FindDisplayMaterialRef
525  ON_3dmObjectAttributes::RemoveDisplayMaterialRef
526  */
527  bool AddDisplayMaterialRef(
528  ON_DisplayMaterialRef display_material
529  );
530 
531  /*
532  Description:
533  Remove a display material reference from the list.
534  Parameters:
535  viewport_id - [in] Any display material references
536  with this viewport id will be removed. If nil,
537  then viewport_id is ignored.
538  display_material_id - [in]
539  Any display material references that match the
540  viewport_id and have this display_material_id
541  will be removed. If nil, then display_material_id
542  is ignored.
543  Returns:
544  True if a display material reference was removed.
545  See Also:
546  ON_3dmObjectAttributes::FindDisplayMaterialRef
547  ON_3dmObjectAttributes::AddDisplayMaterialRef
548  */
549  bool RemoveDisplayMaterialRef(
550  ON_UUID viewport_id,
551  ON_UUID display_material_id = ON_nil_uuid
552  );
553 
554  /*
555  Description:
556  Remove a the entire display material reference list.
557  */
558  void RemoveAllDisplayMaterialRefs();
559 
560  /*
561  Returns:
562  Number of diplay material refences.
563  */
564  int DisplayMaterialRefCount() const;
565 
567 
568 private:
569  bool WriteV5Helper( ON_BinaryArchive& file ) const;
570  bool ReadV5Helper( ON_BinaryArchive& file );
571 };
572 
573 #endif
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
ON::object_decoration m_object_decoration
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
virtual unsigned int SizeOf() const
virtual void Dump(ON_TextLog &) const
ON_SimpleArray< ON_DisplayMaterialRef > m_dmref
ON_ObjectRenderingAttributes m_rendering_attributes