opennurbs_3dm_attributes.cpp
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00018 
00019 ON_OBJECT_IMPLEMENT( ON_3dmObjectAttributes, ON_Object, "A828C015-09F5-477c-8665-F0482F5D6996" );
00020 
00021 ON_3dmObjectAttributes::ON_3dmObjectAttributes()
00022 {
00023   Default();
00024 }
00025 
00026 ON_3dmObjectAttributes::~ON_3dmObjectAttributes()
00027 {}
00028 
00029 /*
00030 void ON_3dmObjectAttributes::CopyHelper(const ON_3dmObjectAttributes& src)
00031 {
00032   // private helper for the copy constructor and operator=.
00033   m_uuid = src.m_uuid;
00034   m_name = src.m_name;
00035   m_url  = src.m_url;
00036   m_layer_index = src.m_layer_index;
00037   m_material_index = src.m_material_index;
00038   m_color = src.m_color;
00039   m_object_decoration = src.m_object_decoration;
00040   m_wire_density = src.m_wire_density;
00041   m_mode = src.m_mode;
00042   m_color_source = src.m_color_source;
00043   m_material_source = src.m_material_source;
00044   m_group = src.m_group;
00045   m_bVisible = src.m_bVisible;
00046   m_linetype_index = src.m_linetype_index;
00047   m_linetype_source = src.m_linetype_source;
00048 }
00049 */
00050 
00051 /*
00052 ON_3dmObjectAttributes::ON_3dmObjectAttributes(const ON_3dmObjectAttributes& src) 
00053                        : ON_Object(src)
00054 {
00055   Default();
00056   CopyHelper(src);
00057 }
00058 */
00059 
00060 bool ON_3dmObjectAttributes::operator==(const ON_3dmObjectAttributes& other) const
00061 {
00062   if ( ON_UuidCompare( m_uuid, other.m_uuid ) )
00063     return false;
00064   if ( m_name.Compare(other.m_name) )
00065     return false;
00066   if ( m_url.Compare(other.m_url) )
00067     return false;
00068   if ( m_layer_index != other.m_layer_index )
00069     return false;
00070   if ( m_material_index != other.m_material_index )
00071     return false;
00072   if ( m_linetype_index != other.m_linetype_index )
00073     return false;
00074   if ( m_color != other.m_color )
00075     return false;
00076   if ( m_plot_color != other.m_plot_color )
00077     return false;
00078   if ( m_display_order != other.m_display_order )
00079     return false;
00080   if ( m_object_decoration != other.m_object_decoration )
00081     return false;
00082   if ( m_wire_density != other.m_wire_density )
00083     return false;
00084   if ( m_mode != other.m_mode )
00085     return false;
00086   if ( m_color_source != other.m_color_source )
00087     return false;
00088   if ( m_linetype_source != other.m_linetype_source )
00089     return false;
00090   if ( m_plot_color_source != other.m_plot_color_source )
00091     return false;
00092   if ( m_material_source != other.m_material_source )
00093     return false;
00094   if ( m_plot_weight_mm != other.m_plot_weight_mm )
00095     return false;
00096   if ( m_plot_weight_source != other.m_plot_weight_source )
00097     return false;
00098 
00099   int count = m_group.Count();
00100   if ( count != other.m_group.Count() )
00101     return false;
00102   if ( count > 0 )
00103   {
00104     const int* a = m_group.Array();
00105     const int* b = other.m_group.Array();
00106     if ( memcmp( a, b, count*sizeof(*a) ) )
00107       return false;
00108   }
00109 
00110   if ( m_bVisible != other.m_bVisible )
00111     return false;
00112 
00113   if ( m_rendering_attributes.Compare(other.m_rendering_attributes) )
00114     return false;
00115 
00116   if ( m_space != other.m_space)
00117     return false;
00118 
00119   if ( m_viewport_id != other.m_viewport_id )
00120     return false;
00121 
00122   if ( m_dmref != other.m_dmref )
00123     return false;
00124 
00125   return true;
00126 }
00127 
00128 bool ON_3dmObjectAttributes::operator!=(const ON_3dmObjectAttributes& other) const
00129 {
00130   return !ON_3dmObjectAttributes::operator==(other);
00131 }
00132 
00133 
00134 /*
00135 ON_3dmObjectAttributes& ON_3dmObjectAttributes::operator=(const ON_3dmObjectAttributes& src )
00136 {
00137   if ( this != &src ) 
00138   {
00139     ON_Object::operator=(src);
00140     CopyHelper(src);
00141   }
00142   return *this;
00143 }
00144 */
00145 
00146 void ON_3dmObjectAttributes::Default()
00147 {
00148   PurgeUserData();
00149   m_uuid = ON_nil_uuid;
00150   m_name.Destroy();
00151   m_url.Destroy();
00152   m_layer_index = 0;
00153   m_linetype_index = -1; // continuous
00154   m_material_index = -1; // white diffuse
00155   m_rendering_attributes.Default();
00156   m_color = ON_Color(0,0,0);
00157   m_plot_color = ON_Color(0,0,0); // Do not change to ON_UNSET_COLOR
00158   m_display_order = 0;
00159   m_plot_weight_mm = 0.0;
00160   m_object_decoration = ON::no_object_decoration;
00161   m_wire_density = 1;
00162   m_mode = ON::normal_object;
00163   m_bVisible = true;
00164   m_color_source       = ON::color_from_layer;
00165   m_material_source    = ON::material_from_layer;
00166   m_linetype_source    = ON::linetype_from_layer;
00167   m_plot_color_source  = ON::plot_color_from_layer;
00168   m_plot_weight_source = ON::plot_weight_from_layer;
00169   m_group.Destroy();
00170   m_space = ON::model_space;
00171   m_viewport_id = ON_nil_uuid;
00172   m_dmref.Destroy();
00173 }
00174 
00175 
00176 // {9BBB37E9-2131-4fb8-B9C6-5524859B98B8}
00177 const ON_UUID ON_ObsoletePageSpaceObjectId =
00178 { 0x9bbb37e9, 0x2131, 0x4fb8, { 0xb9, 0xc6, 0x55, 0x24, 0x85, 0x9b, 0x98, 0xb8 } };
00179 
00180 
00181 bool ON_3dmObjectAttributes::ReadV5Helper( ON_BinaryArchive& file )
00182 {
00183   unsigned char itemid, c;
00184   int major_version = 0;
00185   int minor_version = 0;
00186   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00187   if ( rc && 2 != major_version )
00188     rc = false;
00189 
00190   itemid = 0xFF;
00191 
00192   while(rc)
00193   {
00194     if (!rc) break;
00195     rc = file.ReadUuid(m_uuid);
00196     if (!rc) break;
00197     rc = file.ReadInt(&m_layer_index);
00198     if (!rc) break;
00199 
00200     // read non-default settings - skip everything else
00201     rc = file.ReadChar(&itemid);
00202     if (!rc) break;
00203     if ( 0 == itemid )
00204       break;
00205     
00206     if ( 1 == itemid )
00207     {
00208       rc = file.ReadString(m_name);
00209       if (!rc) break;
00210       rc = file.ReadChar(&itemid);
00211       if ( !rc || 0 == itemid ) break;
00212     }
00213     if ( 2 == itemid )
00214     {
00215       rc = file.ReadString(m_url);
00216       if (!rc) break;
00217       rc = file.ReadChar(&itemid);
00218       if ( !rc || 0 == itemid ) break;
00219     }
00220     if ( 3 == itemid )
00221     {
00222       rc = file.ReadInt(&m_linetype_index);
00223       if (!rc) break;
00224       rc = file.ReadChar(&itemid);
00225       if ( !rc || 0 == itemid ) break;
00226     }
00227     if ( 4 == itemid )
00228     {
00229       rc = file.ReadInt(&m_material_index);
00230       if (!rc) break;
00231       rc = file.ReadChar(&itemid);
00232       if ( !rc || 0 == itemid ) break;
00233     }
00234     if ( 5 == itemid )
00235     {
00236       rc = m_rendering_attributes.Read(file);
00237       if (!rc) break;
00238       rc = file.ReadChar(&itemid);
00239       if ( !rc || 0 == itemid ) break;
00240     }
00241     if ( 6 == itemid )
00242     {
00243       rc = file.ReadColor(m_color);
00244       if (!rc) break;
00245       rc = file.ReadChar(&itemid);
00246       if ( !rc || 0 == itemid ) break;
00247     }
00248     if ( 7 == itemid )
00249     {
00250       rc = file.ReadColor(m_plot_color);
00251       if (!rc) break;
00252       rc = file.ReadChar(&itemid);
00253       if ( !rc || 0 == itemid ) break;
00254     }
00255     if ( 8 == itemid )
00256     {
00257       rc = file.ReadDouble(&m_plot_weight_mm);
00258       if (!rc) break;
00259       rc = file.ReadChar(&itemid);
00260       if ( !rc || 0 == itemid ) break;
00261     }
00262     if ( 9 == itemid )
00263     {
00264       rc = file.ReadChar(&c);
00265       if (!rc) break;
00266       m_object_decoration = ON::ObjectDecoration(c);
00267       rc = file.ReadChar(&itemid);
00268       if ( !rc || 0 == itemid ) break;
00269     }
00270     if ( 10 == itemid )
00271     {
00272       rc = file.ReadInt(&m_wire_density);
00273       if (!rc) break;
00274       rc = file.ReadChar(&itemid);
00275       if ( !rc || 0 == itemid ) break;
00276     }
00277     if ( 11 == itemid )
00278     {
00279       rc = file.ReadBool(&m_bVisible);
00280       if (!rc) break;
00281       rc = file.ReadChar(&itemid);
00282       if ( !rc || 0 == itemid ) break;
00283     }
00284     if ( 12 == itemid )
00285     {
00286       rc = file.ReadChar(&m_mode);
00287       if (!rc) break;
00288       rc = file.ReadChar(&itemid);
00289       if ( !rc || 0 == itemid ) break;
00290     }
00291     if ( 13 == itemid )
00292     {
00293       rc = file.ReadChar(&m_color_source);
00294       if (!rc) break;
00295       rc = file.ReadChar(&itemid);
00296       if ( !rc || 0 == itemid ) break;
00297     }
00298     if ( 14 == itemid )
00299     {
00300       rc = file.ReadChar(&m_plot_color_source);
00301       if (!rc) break;
00302       rc = file.ReadChar(&itemid);
00303       if ( !rc || 0 == itemid ) break;
00304     }
00305     if ( 15 == itemid )
00306     {
00307       rc = file.ReadChar(&m_plot_weight_source);
00308       if (!rc) break;
00309       rc = file.ReadChar(&itemid);
00310       if ( !rc || 0 == itemid ) break;
00311     }
00312     if ( 16 == itemid )
00313     {
00314       rc = file.ReadChar(&m_material_source);
00315       if (!rc) break;
00316       rc = file.ReadChar(&itemid);
00317       if ( !rc || 0 == itemid ) break;
00318     }
00319     if ( 17 == itemid )
00320     {
00321       rc = file.ReadChar(&m_linetype_source);
00322       if (!rc) break;
00323       rc = file.ReadChar(&itemid);
00324       if ( !rc || 0 == itemid ) break;
00325     }
00326     if ( 18 == itemid )
00327     {
00328       rc = file.ReadArray(m_group);
00329       if (!rc) break;
00330       rc = file.ReadChar(&itemid);
00331       if ( !rc || 0 == itemid ) break;
00332     }
00333     if ( 19 == itemid )
00334     {
00335       rc = file.ReadChar(&c);
00336       if (!rc) break;
00337       m_space = ON::ActiveSpace(c);
00338       rc = file.ReadChar(&itemid);
00339       if ( !rc || 0 == itemid ) break;
00340     }
00341     if ( 20 == itemid )
00342     {
00343       rc = file.ReadUuid(m_viewport_id);
00344       if (!rc) break;
00345       rc = file.ReadChar(&itemid);
00346       if ( !rc || 0 == itemid ) break;
00347     }
00348     if ( 21 == itemid )
00349     {
00350       rc = file.ReadArray(m_dmref);
00351       if (!rc) break;
00352       rc = file.ReadChar(&itemid);
00353       if ( !rc || 0 == itemid ) break;
00354     }
00355 
00356     // items 1 - 21 are in chunk version 2.0 files
00357     if ( minor_version <= 0 )
00358       break;
00359 
00360     // 28 Nov. 2009 - S. Baer
00361     // Added m_display_order to version 2.1 files
00362     if ( 22 == itemid )
00363     {
00364       rc = file.ReadInt(&m_display_order);
00365       if (!rc) break;
00366       rc = file.ReadChar(&itemid);
00367       if ( !rc || 0 == itemid ) break;
00368     }
00369 
00370     if ( minor_version <= 1 )
00371       break;
00372 
00373     // Add new item reading above this code, and increment the "22"
00374     // in the following if statement to an appropriate value, and
00375     // update the comment.  Be sure to test reading of old and
00376     // new files by old and new code, before checking in your
00377     // changes.
00378     //
00379     if ( itemid > 22 )
00380     {
00381       // we are reading file written with code newer
00382       // than this code (minor_version > 1)
00383       itemid = 0;
00384     }
00385 
00386     break;
00387   }
00388 
00389   if ( rc && 0 != itemid )
00390   {
00391     ON_ERROR("Bug in ON_3dmObjectAttributes::ReadV5Helper or WriteV5Helper");
00392   }
00393 
00394   return rc;
00395 }
00396 
00397 ON_BOOL32 ON_3dmObjectAttributes::Read( ON_BinaryArchive& file )
00398 {
00399   Default();
00400   if (    file.Archive3dmVersion() >= 5 
00401        && file.ArchiveOpenNURBSVersion() >= 200712190 )
00402   {
00403     return ReadV5Helper(file);
00404   }
00405   int i;
00406   int major_version = 0;
00407   int minor_version = 0;
00408   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00409   if ( rc && major_version == 1 ) 
00410   {
00411     if (rc) rc = file.ReadUuid(m_uuid);
00412     if (rc) rc = file.ReadInt(&m_layer_index);
00413     if (rc) rc = file.ReadInt(&m_material_index);
00414     if (rc) rc = file.ReadColor(m_color);
00415     
00416     while(rc)
00417     {
00418       // OBSOLETE if (rc) rc = file.ReadLineStyle(m_line_style); // 23 March 2005 Dale Lear
00419       // replaced with
00420       short s = 0;
00421       double x;
00422       rc = file.ReadShort(&s); 
00423       if (!rc) break;
00424       if ( file.Archive3dmVersion() < 4 || file.ArchiveOpenNURBSVersion() < 200503170 )
00425       {
00426         // ignore unused linestyle info in old files
00427         // This bit keeps the curve arrowheads from V3 showing up
00428         // in V4.
00429         m_object_decoration = ON::ObjectDecoration( (s & ON::both_arrowhead) );
00430       }
00431       rc = file.ReadShort(&s);
00432       if (!rc) break;
00433       rc = file.ReadDouble(&x);
00434       if (!rc) break;
00435       rc = file.ReadDouble(&x);
00436       break;
00437     }
00438 
00439     if (rc) rc = file.ReadInt(&m_wire_density);
00440     if (rc) rc = file.ReadChar(&m_mode);
00441 
00442     if (rc) rc = file.ReadChar(&m_color_source);
00443     if (rc) m_color_source = (unsigned char)ON::ObjectColorSource(m_color_source);
00444 
00445     if (rc) rc = file.ReadChar(&m_linetype_source);
00446     if (rc) m_linetype_source = (unsigned char)ON::ObjectLinetypeSource(m_linetype_source);
00447 
00448     if (rc) rc = file.ReadChar(&m_material_source);
00449     if (rc) m_material_source = (unsigned char)ON::ObjectMaterialSource(m_material_source);
00450 
00451     if (rc) rc = file.ReadString(m_name);
00452     if (rc) rc = file.ReadString(m_url);
00453 
00454     m_bVisible = (Mode() != ON::hidden_object);
00455     if ( rc && minor_version >= 1 ) 
00456     {
00457       rc = file.ReadArray( m_group );
00458       if ( rc && minor_version >= 2 )
00459       {
00460         rc = file.ReadBool(&m_bVisible);
00461 
00462         if ( rc && minor_version >= 3 )
00463         {
00464           rc = file.ReadArray(m_dmref);     
00465 
00466           if (rc && minor_version >= 4 )
00467           {
00468             // 23 March 2005 Dale Lear
00469             //    Added m_plot_color_source and m_plot_color
00470             i = 0;
00471             if (rc) rc = file.ReadInt(&i);
00472             if (rc) m_object_decoration = ON::ObjectDecoration(i);
00473             if (rc) rc = file.ReadChar(&m_plot_color_source);
00474             if (rc) m_plot_color_source = (unsigned char)ON::PlotColorSource(m_plot_color_source);
00475             if (rc) rc = file.ReadColor( m_plot_color );
00476             if (rc) rc = file.ReadChar(&m_plot_weight_source);
00477             if (rc) m_plot_weight_source = (unsigned char)ON::PlotWeightSource(m_plot_weight_source);
00478             if (rc) rc = file.ReadDouble(&m_plot_weight_mm);
00479 
00480 
00481             if (rc && minor_version >= 5 )
00482             {
00483               // version 1.5 fields 11 April 2005
00484               if (rc) rc = file.ReadInt(&m_linetype_index);
00485 
00486               // version 1.6 fields 2 September 2005
00487               if (rc && minor_version >= 6 )
00488               {
00489                 unsigned char uc = 0;
00490                 rc = file.ReadChar(&uc);
00491                 if (rc)
00492                 {
00493                   m_space = (1 == uc) ? ON::page_space : ON::model_space;
00494                   m_dmref.Empty();
00495                   int i, count=0;
00496                   rc = file.ReadInt(&count);
00497                   if (rc && count > 0)
00498                   {
00499                     m_dmref.SetCapacity(count);
00500                     for ( i = 0; i < count && rc; i++)
00501                     {
00502                       ON_DisplayMaterialRef& dmr = m_dmref.AppendNew();
00503                       rc = file.ReadUuid(dmr.m_viewport_id);
00504                       if (rc) rc = file.ReadUuid(dmr.m_display_material_id);
00505                       if ( rc )
00506                       {
00507                         // Assigning an object to a page started out as
00508                         // using dmrs.  The way the runtime info is saved
00509                         // has changed, but, at this point, I can't change
00510                         // the way the information is saved in the file and
00511                         // it doesn't matter.
00512                         if ( 0 == ON_UuidCompare(&ON_ObsoletePageSpaceObjectId,&dmr.m_display_material_id) )
00513                         {
00514                           m_viewport_id = dmr.m_viewport_id;
00515                           m_dmref.Remove();
00516                         }
00517                       }
00518                     }
00519                     if ( 0 == m_dmref.Count() )
00520                       m_dmref.Destroy();
00521                   }
00522                 }
00523 
00524                 if ( rc && minor_version >= 7 )
00525                 {
00526                   // version 1.7 fields 6 June 2006
00527                   if (rc) rc = m_rendering_attributes.Read(file);
00528                 }
00529               }
00530             }
00531           }
00532         }
00533       }
00534     }
00535   }
00536   else 
00537   {
00538     rc = false;
00539   }
00540   return rc;
00541 }
00542 
00543 bool ON_3dmObjectAttributes::WriteV5Helper( ON_BinaryArchive& file ) const
00544 {
00545   unsigned char c;
00546   // 29 Nov. 2009 S. Baer
00547   // Chunk version updated to 2.1 in order to support m_display_order
00548   bool rc = file.Write3dmChunkVersion(2,1);
00549   while(rc)
00550   {
00551     if (!rc) break;
00552     rc = file.WriteUuid(m_uuid);
00553     if (!rc) break;
00554     rc = file.WriteInt(m_layer_index);
00555     if (!rc) break;
00556 
00557     // write non-default settings - skip everything else
00558     if ( !m_name.IsEmpty() )
00559     {
00560       c = 1;
00561       rc = file.WriteChar(c);
00562       if (!rc) break;
00563       rc = file.WriteString(m_name);
00564       if (!rc) break;
00565     }
00566     if ( !m_url.IsEmpty() )
00567     {
00568       c = 2;
00569       rc = file.WriteChar(c);
00570       if (!rc) break;
00571       rc = file.WriteString(m_url);
00572       if (!rc) break;
00573     }
00574     if ( -1 != m_linetype_index )
00575     {
00576       c = 3;
00577       rc = file.WriteChar(c);
00578       if (!rc) break;
00579       rc = file.WriteInt(m_linetype_index);
00580       if (!rc) break;
00581     }
00582     if ( -1 != m_material_index )
00583     {
00584       c = 4;
00585       rc = file.WriteChar(c);
00586       if (!rc) break;
00587       rc = file.WriteInt(m_material_index);
00588       if (!rc) break;
00589     }
00590     if (    m_rendering_attributes.m_mappings.Count() > 0
00591          || m_rendering_attributes.m_materials.Count() > 0
00592          || true != m_rendering_attributes.m_bCastsShadows
00593          || true != m_rendering_attributes.m_bReceivesShadows
00594          || false != m_rendering_attributes.AdvancedTexturePreview()
00595          )
00596     {
00597       c = 5;
00598       rc = file.WriteChar(c);
00599       if (!rc) break;
00600       rc = m_rendering_attributes.Write(file);
00601       if (!rc) break;
00602     }
00603     if ( 0 != m_color )
00604     {
00605       c = 6;
00606       rc = file.WriteChar(c);
00607       if (!rc) break;
00608       rc = file.WriteColor(m_color);
00609       if (!rc) break;
00610     }
00611     if ( 0 != m_plot_color )
00612     {
00613       c = 7;
00614       rc = file.WriteChar(c);
00615       if (!rc) break;
00616       rc = file.WriteColor(m_plot_color);
00617       if (!rc) break;
00618     }
00619     if ( 0.0 != m_plot_weight_mm )
00620     {
00621       c = 8;
00622       rc = file.WriteChar(c);
00623       if (!rc) break;
00624       rc = file.WriteDouble(m_plot_weight_mm);
00625       if (!rc) break;
00626     }
00627     if ( ON::no_object_decoration != m_object_decoration )
00628     {
00629       c = 9;
00630       rc = file.WriteChar(c);
00631       if (!rc) break;
00632       c = (unsigned char)m_object_decoration;
00633       rc = file.WriteChar(c);
00634       if (!rc) break;
00635     }
00636     if ( 1 != m_wire_density )
00637     {
00638       c = 10;
00639       rc = file.WriteChar(c);
00640       if (!rc) break;
00641       rc = file.WriteInt(m_wire_density);
00642       if (!rc) break;
00643     }
00644     if ( true != m_bVisible )
00645     {
00646       c = 11;
00647       rc = file.WriteChar(c);
00648       if (!rc) break;
00649       rc = file.WriteBool(m_bVisible);
00650       if (!rc) break;
00651     }
00652     if ( ON::normal_object != m_mode )
00653     {
00654       c = 12;
00655       rc = file.WriteChar(c);
00656       if (!rc) break;
00657       rc = file.WriteChar(m_mode);
00658       if (!rc) break;
00659     }
00660     if ( ON::color_from_layer != m_color_source )
00661     {
00662       c = 13;
00663       rc = file.WriteChar(c);
00664       if (!rc) break;
00665       rc = file.WriteChar(m_color_source);
00666       if (!rc) break;
00667     }
00668     if ( ON::plot_color_from_layer != m_plot_color_source )
00669     {
00670       c = 14;
00671       rc = file.WriteChar(c);
00672       if (!rc) break;
00673       rc = file.WriteChar(m_plot_color_source);
00674       if (!rc) break;
00675     }
00676     if ( ON::plot_weight_from_layer != m_plot_weight_source )
00677     {
00678       c = 15;
00679       rc = file.WriteChar(c);
00680       if (!rc) break;
00681       rc = file.WriteChar(m_plot_weight_source);
00682       if (!rc) break;
00683     }
00684     if ( ON::material_from_layer != m_material_source )
00685     {
00686       c = 16;
00687       rc = file.WriteChar(c);
00688       if (!rc) break;
00689       rc = file.WriteChar(m_material_source);
00690       if (!rc) break;
00691     }
00692     if ( ON::linetype_from_layer != m_linetype_source )
00693     {
00694       c = 17;
00695       rc = file.WriteChar(c);
00696       if (!rc) break;
00697       rc = file.WriteChar(m_linetype_source);
00698       if (!rc) break;
00699     }
00700     if ( m_group.Count() > 0 )
00701     {
00702       c = 18;
00703       rc = file.WriteChar(c);
00704       if (!rc) break;
00705       rc = file.WriteArray(m_group);
00706       if (!rc) break;
00707     }
00708     if ( ON::model_space != m_space )
00709     {
00710       c = 19;
00711       rc = file.WriteChar(c);
00712       if (!rc) break;
00713       c = (unsigned char)m_space;
00714       rc = file.WriteChar(c);
00715       if (!rc) break;
00716     }
00717     if ( !ON_UuidIsNil(m_viewport_id) )
00718     {
00719       c = 20;
00720       rc = file.WriteChar(c);
00721       if (!rc) break;
00722       rc = file.WriteUuid(m_viewport_id);
00723       if (!rc) break;
00724     }
00725     if ( m_dmref.Count() > 0 )
00726     {
00727       c = 21;
00728       rc = file.WriteChar(c);
00729       if (!rc) break;
00730       rc = file.WriteArray(m_dmref);
00731       if (!rc) break;
00732     }
00733 
00734     // 29 Nov. 2009 - S. Baer
00735     // Only write m_display_order if it's value!=0
00736     // m_display_order is written to version 2.1 files
00737     if ( 0 != m_display_order )
00738     {
00739       c = 22;
00740       rc = file.WriteChar(c);
00741       if (!rc) break;
00742       rc = file.WriteInt(m_display_order);
00743       if (!rc) break;
00744     }
00745 
00746     // 0 indicates end of attributes;
00747     c = 0;
00748     rc = file.WriteChar(c);
00749     break;
00750   }
00751   return rc;
00752 }
00753 
00754 ON_BOOL32 ON_3dmObjectAttributes::Write( ON_BinaryArchive& file ) const
00755 {
00756   if ( file.Archive3dmVersion() >= 5 )
00757   {
00758     // added at opennurbs version 200712190
00759     return WriteV5Helper(file);
00760   }
00761 
00762   bool rc = file.Write3dmChunkVersion(1,7);
00763   // version 1.0 fields
00764   if (rc) rc = file.WriteUuid(m_uuid);
00765   if (rc) rc = file.WriteInt(m_layer_index);
00766   if (rc) rc = file.WriteInt(m_material_index);
00767   if (rc) rc = file.WriteColor(m_color);
00768 
00769   if (rc)
00770   {
00771     // OBSOLETE if (rc) rc = file.WriteLineStyle(m_line_style); // 23 March 2005 Dale Lear
00772     short s;
00773     s = (short)m_object_decoration;
00774     if (rc) rc = file.WriteShort(s);
00775     s = 0;
00776     if (rc) rc = file.WriteShort(s);
00777     if (rc) rc = file.WriteDouble(0.0);
00778     if (rc) rc = file.WriteDouble(1.0);
00779   }
00780 
00781   if (rc) rc = file.WriteInt(m_wire_density);
00782   if (rc) rc = file.WriteChar(m_mode);
00783   if (rc) rc = file.WriteChar(m_color_source);
00784   if (rc) rc = file.WriteChar(m_linetype_source);
00785   if (rc) rc = file.WriteChar(m_material_source);
00786   if (rc) rc = file.WriteString(m_name);
00787   if (rc) rc = file.WriteString(m_url);
00788 
00789   // version 1.1 fields
00790   if (rc) rc = file.WriteArray(m_group);
00791 
00792   // version 1.2 fields
00793   if (rc) rc = file.WriteBool(m_bVisible);
00794 
00795   // version 1.3 fields
00796   if (rc) rc = file.WriteArray(m_dmref);
00797 
00798   // version 1.4 fields - 23 March 2005 Dale Lear
00799   if (rc) rc = file.WriteInt(m_object_decoration);
00800   if (rc) rc = file.WriteChar(m_plot_color_source);
00801   if (rc) rc = file.WriteColor(m_plot_color);
00802   if (rc) rc = file.WriteChar(m_plot_weight_source);
00803   if (rc) rc = file.WriteDouble(m_plot_weight_mm);
00804 
00805   // version 1.5 fields 11 April 2005
00806   if (rc) rc = file.WriteInt(m_linetype_index);
00807 
00808   // version 1.6 fields 2 September 2005
00809   if (rc)
00810   {
00811     unsigned char uc = 0;
00812     switch(m_space)
00813     {
00814     case ON::no_space:    uc = 0; break;
00815     case ON::model_space: uc = 0; break;
00816     case ON::page_space:  uc = 1; break;
00817     }
00818     rc = file.WriteChar(uc);
00819   }
00820   if (rc)
00821   {
00822     // 22 Sep 2006 - the way ON_3dmObjectAttiributes indicates
00823     // that an object is put on a particular page view changed
00824     // from being saved in the m_dmref[] list to using the
00825     // m_space and m_viewport_id settings.  But the file format
00826     // cannot change at this point.  So, the bAddPagespaceDMR
00827     // is here to save the page info in the old dmr format.
00828     int count = m_dmref.Count();
00829     if ( count < 0 )
00830       count = 0;
00831     bool bAddPagespaceDMR = ( ON::page_space == m_space && !ON_UuidIsNil(m_viewport_id) );
00832     rc = file.WriteInt( bAddPagespaceDMR ? (count+1) : count );
00833     if ( rc && bAddPagespaceDMR )
00834     {
00835       rc = file.WriteUuid(m_viewport_id);
00836       if (rc) rc = file.WriteUuid(ON_ObsoletePageSpaceObjectId);
00837     }
00838     int i;
00839     for ( i = 0; i < count && rc; i++ )
00840     {
00841       const ON_DisplayMaterialRef& dmr = m_dmref[i];
00842       rc = file.WriteUuid(dmr.m_viewport_id);
00843       if (rc) rc = file.WriteUuid(dmr.m_display_material_id);
00844     }
00845   }
00846 
00847   // version 1.7 fields 6 June 2006
00848   if (rc) rc = m_rendering_attributes.Write(file);
00849 
00850   return rc;
00851 }
00852 
00853 
00854 bool ON_3dmObjectAttributes::Transform( const ON_Xform& xform )
00855 {
00856   // Please discuss any changes with Dale Lear.
00857   ON_Object::TransformUserData(xform);
00858   return m_rendering_attributes.Transform(xform);
00859 }
00860 
00861 ON_BOOL32 ON_3dmObjectAttributes::IsValid( ON_TextLog* text_log ) const
00862 {
00863   if ( ON_UuidIsNil(m_uuid) )
00864   {
00865     if ( text_log )
00866     {
00867       text_log->Print("Object id is nil - this is not valid.\n");
00868     }
00869     return false;
00870   }
00871 
00872   if ( !m_rendering_attributes.IsValid(text_log) )
00873   {
00874     if ( text_log )
00875     {
00876       text_log->Print("Object rendering attributes are not valid.\n");
00877     }
00878     return false;
00879   }
00880 
00881   return true;
00882 }
00883 
00884 unsigned int ON_3dmObjectAttributes::SizeOf() const
00885 {
00886   unsigned int sz = sizeof(*this) - sizeof(ON_Object) 
00887                   + m_name.Length()*sizeof(wchar_t)
00888                   + m_url.Length()*sizeof(wchar_t)
00889                   + m_group.SizeOfArray()
00890                   + ON_Object::SizeOf();
00891   return sz;
00892 }
00893 
00894 void ON_3dmObjectAttributes::Dump( ON_TextLog& dump ) const
00895 {
00896   const wchar_t* wsName = m_name;
00897   if ( !wsName )
00898     wsName = L"";
00899   dump.Print("object name = \"%ls\"\n",wsName);
00900 
00901   dump.Print("object uuid = ");
00902   dump.Print(m_uuid);
00903   dump.Print("\n");
00904 
00905   const char* sMode = "unknown";
00906   switch( Mode() )
00907   {
00908   case ON::normal_object:
00909     sMode = "normal";
00910     break;
00911   case ON::hidden_object:
00912     sMode = "hidden";
00913     break;
00914   case ON::locked_object:
00915     sMode = "locked";
00916     break;
00917   default:
00918     sMode = "unknown";
00919     break;
00920   }
00921   dump.Print("object mode = %s\n",sMode); // sSMode is const char*
00922 
00923   dump.Print("object layer index = %d\n",m_layer_index);
00924   dump.Print("object material index = %d\n",m_material_index);
00925   const char* sMaterialSource = "unknown";
00926   switch(MaterialSource()) {
00927   case ON::material_from_layer: sMaterialSource = "layer material"; break;
00928   case ON::material_from_object: sMaterialSource = "object material"; break;
00929   case ON::material_from_parent: sMaterialSource = "parent material"; break;
00930   }
00931   dump.Print("material source = %s\n",sMaterialSource); // sMaterialSource is const char*
00932   const int group_count = GroupCount();
00933   if ( group_count > 0 ) {
00934     const int* group = GroupList();
00935     dump.Print("groups: ");
00936     int i;
00937     for ( i = 0; i < group_count; i++ ) {
00938       if ( i )
00939         dump.Print(",%d",group[i]);
00940       else
00941         dump.Print("%d",group[i]);
00942     }
00943     dump.Print("\n");
00944   }
00945 }
00946 
00947 ON::object_mode ON_3dmObjectAttributes::Mode() const
00948 {
00949   return ON::ObjectMode( m_mode%16 );
00950 }
00951 
00952 void ON_3dmObjectAttributes::SetMode( ON::object_mode m )
00953 {
00954   int om = ON::ObjectMode(m);
00955   int dm = DisplayMode();
00956   m_mode = (unsigned char)(16*dm+om);
00957 
00958   // temporary
00959   m_bVisible = (om != ON::hidden_object);
00960 }
00961 
00962 bool ON_3dmObjectAttributes::IsInstanceDefinitionObject() const
00963 {
00964   return (ON::idef_object == Mode());
00965 }
00966 
00967 bool ON_3dmObjectAttributes::IsVisible() const
00968 {
00969   return m_bVisible;
00970 }
00971 
00972 void ON_3dmObjectAttributes::SetVisible( bool bVisible )
00973 {
00974   if ( m_bVisible != (bVisible?true:false) )
00975   {
00976     m_bVisible = (bVisible?true:false);
00977 
00978     // temporary
00979     if ( Mode() != ON::idef_object )
00980       SetMode( m_bVisible ? ON::normal_object : ON::hidden_object );
00981   }
00982 }
00983 
00984 
00985 ON::display_mode ON_3dmObjectAttributes::DisplayMode() const
00986 {
00987   return ON::DisplayMode( m_mode/16 );
00988 }
00989 
00990 unsigned int ON_3dmObjectAttributes::ApplyParentalControl( 
00991         const ON_3dmObjectAttributes& parents_attributes,
00992         unsigned int control_limits
00993         )
00994 {
00995   ON_ERROR("Do not use deprecated version of ON_3dmObjectAttributes::ApplyParentalControl()");
00996   ON_Layer bogus_layer;
00997   bogus_layer.m_layer_index = -1;
00998   return ApplyParentalControl(parents_attributes,bogus_layer,control_limits);
00999 }
01000 
01001 unsigned int ON_3dmObjectAttributes::ApplyParentalControl( 
01002         const ON_3dmObjectAttributes& parents_attributes,
01003         const ON_Layer& parent_layer,
01004         unsigned int control_limits
01005         )
01006 {
01007   unsigned int rc = 0;
01008 
01009   if ( m_bVisible && !parents_attributes.m_bVisible )
01010   {
01011     if ( 0 != (0x01 & control_limits) )
01012     {
01013       rc |= 0x01;
01014       m_bVisible = false;
01015     }
01016   }
01017 
01018   if ( ON::color_from_parent == m_color_source )
01019   {
01020     if ( 0 != (0x02 & control_limits) )
01021     {
01022       rc |= 0x02;
01023       m_color_source = parents_attributes.m_color_source;
01024       m_color        = parents_attributes.m_color;
01025       // 2010 March 10 Dale Lear
01026       //   Changing the layer index is wrong!
01027       //   Color by parent means COLOR and not LAYER
01028       // WRONG! // m_layer_index = parents_attributes.m_layer_index;
01029       if ( ON::color_from_layer == m_color_source && parent_layer.m_layer_index >= 0 )
01030       {
01031         // this object will use the parent layer's color
01032         m_color_source = ON::color_from_object;
01033         m_color = parent_layer.m_color;
01034       }
01035     }
01036   }
01037 
01038   if ( ON::material_from_parent == m_material_source )
01039   {
01040     if ( 0 != (0x04 & control_limits) )
01041     {
01042       rc |= 0x04;
01043       m_material_source = parents_attributes.m_material_source;
01044       m_material_index  = parents_attributes.m_material_index;
01045       // 2010 March 10 Dale Lear
01046       //   Changing the layer index is wrong!
01047       //   Material by parent means MATERIAL and not LAYER
01048       // WRONG! // m_layer_index = parents_attributes.m_layer_index;
01049       if ( ON::material_from_layer == m_material_source && parent_layer.m_layer_index >= 0 )
01050       {
01051         // this object will use the parent layer's material
01052         m_material_source = ON::material_from_object;
01053         m_material_index = parent_layer.m_material_index;
01054       }
01055     }
01056   }
01057 
01058   if ( ON::plot_color_from_parent == m_plot_color_source )
01059   {
01060     if ( 0 != (0x08 & control_limits) )
01061     {
01062       rc |= 0x08;
01063       m_plot_color_source = parents_attributes.m_plot_color_source;
01064       m_plot_color        = parents_attributes.m_plot_color;
01065       if ( ON::plot_color_from_layer == m_plot_color_source && parent_layer.m_layer_index >= 0 )
01066       {
01067         // this object will use the parent layer's plot color
01068         m_plot_color_source = ON::plot_color_from_object;
01069         m_plot_color        = parent_layer.m_plot_color;
01070       }
01071     }
01072   }
01073 
01074   if ( ON::plot_weight_from_parent == m_plot_weight_source )
01075   {
01076     if ( 0 != (0x10 & control_limits) )
01077     {
01078       rc |= 0x10;
01079       m_plot_weight_source = parents_attributes.m_plot_weight_source;
01080       m_plot_weight_mm     = parents_attributes.m_plot_weight_mm;
01081       if ( ON::plot_weight_from_layer == m_plot_weight_source && parent_layer.m_layer_index >= 0 )
01082       {
01083         // this object will use the parent layer's plot weight
01084         m_plot_weight_source = ON::plot_weight_from_object;
01085         m_plot_weight_mm     = parent_layer.m_plot_weight_mm;
01086       }
01087     }
01088   }
01089 
01090   if ( ON::linetype_from_parent == m_linetype_source )
01091   {
01092     if ( 0 != (0x20 & control_limits) )
01093     {
01094       rc |= 0x20;
01095       m_linetype_source = parents_attributes.m_linetype_source;
01096       m_linetype_index  = parents_attributes.m_linetype_index;
01097       if ( ON::linetype_from_layer == m_linetype_source && parent_layer.m_layer_index >= 0 )
01098       {
01099         // this object will use the parent layer's line type
01100         m_linetype_source = ON::linetype_from_object;
01101         m_linetype_index  = parent_layer.m_linetype_index;
01102       }
01103     }
01104   }
01105   
01106   if ( 0 != (0x40 & control_limits) )
01107   {
01108     rc |= 0x40;
01109     m_display_order = parents_attributes.m_display_order;
01110   }
01111 
01112   return rc;
01113 }
01114 
01115 
01116 void ON_3dmObjectAttributes::SetDisplayMode( ON::display_mode m )
01117 {
01118   int om = Mode();
01119   int dm = ON::DisplayMode(m);
01120   m_mode = (unsigned char)(16*dm+om);
01121 }
01122 
01123 ON::object_color_source ON_3dmObjectAttributes::ColorSource() const
01124 {
01125   return ON::ObjectColorSource(m_color_source);
01126 }
01127 
01128 void ON_3dmObjectAttributes::SetColorSource( ON::object_color_source c )
01129 {
01130   m_color_source = (unsigned char)ON::ObjectColorSource(c);
01131 }
01132 
01133 ON::object_linetype_source ON_3dmObjectAttributes::LinetypeSource() const
01134 {
01135   return ON::ObjectLinetypeSource(m_linetype_source);
01136 }
01137 
01138 void ON_3dmObjectAttributes::SetLinetypeSource( ON::object_linetype_source c )
01139 {
01140   m_linetype_source = (unsigned char)ON::ObjectLinetypeSource(c);
01141 }
01142 
01143 ON::object_material_source ON_3dmObjectAttributes::MaterialSource() const
01144 {
01145   return ON::ObjectMaterialSource(m_material_source);
01146 }
01147 
01148 void ON_3dmObjectAttributes::SetMaterialSource( ON::object_material_source c )
01149 {
01150   m_material_source = (unsigned char)ON::ObjectMaterialSource(c);
01151 }
01152 
01153 
01154 ON::plot_color_source ON_3dmObjectAttributes::PlotColorSource() const
01155 {
01156   return ON::PlotColorSource(m_plot_color_source);
01157 }
01158 
01159 void ON_3dmObjectAttributes::SetPlotColorSource( ON::plot_color_source pcs )
01160 {
01161   m_plot_color_source = (unsigned char)ON::PlotColorSource(pcs);
01162 }
01163 
01164 ON::plot_weight_source ON_3dmObjectAttributes::PlotWeightSource() const
01165 {
01166   return ON::PlotWeightSource(m_plot_weight_source);
01167 }
01168 
01169 void ON_3dmObjectAttributes::SetPlotWeightSource( ON::plot_weight_source pws )
01170 {
01171   m_plot_weight_source = (unsigned char)ON::PlotColorSource(pws);
01172 }
01173 
01174 
01175 int ON_3dmObjectAttributes::GroupCount() const
01176 {
01177   return m_group.Count();
01178 }
01179 
01181 // returns an int array of GroupCount() zero based group indices
01182 const int* ON_3dmObjectAttributes::GroupList() const
01183 {
01184   return (m_group.Count()>0) ? m_group.Array() : 0;
01185 }
01186 
01187 int ON_3dmObjectAttributes::GetGroupList(ON_SimpleArray<int>& group_list) const
01188 {
01189   group_list = m_group;
01190   return group_list.Count();
01191 }
01192 
01194 // returns true if object is in group with specified index
01195 ON_BOOL32 ON_3dmObjectAttributes::IsInGroup(
01196   int group_index // zero based group index
01197   ) const
01198 {
01199   ON_BOOL32 rc = false;
01200   const int count = m_group.Count();
01201   int i;
01202   for ( i = 0; i < count; i++ ) {
01203     if (m_group[i] == group_index) {
01204       rc = true;
01205       break;
01206     }
01207   }
01208   return rc;
01209 }
01210 
01211 ON_BOOL32 ON_3dmObjectAttributes::IsInGroups( int group_count, const int* group_list ) const
01212 {
01213   // returns true if object is in any of the groups in the list
01214   ON_BOOL32 rc = false;
01215   if ( group_count > 0 && group_list ) {
01216     const int obj_group_count  = GroupCount();
01217     const int* obj_group_list = GroupList();
01218     // in practice these arrays will be very short and this search will be fast
01219     int i, j;
01220     for ( i = 0; i < obj_group_count; i++ ) for ( j = 0; j < group_count; j++ ) {
01221       if ( obj_group_list[i] == group_list[j] )
01222         return true;
01223     }
01224   }
01225   return rc;
01226 }
01227 
01228 ON_BOOL32 ON_3dmObjectAttributes::IsInGroups( const ON_SimpleArray<int>& group_list ) const
01229 {
01230   return IsInGroups( group_list.Count(), group_list.Array() );
01231 }
01232 
01233 
01235 // Adds object to group with specified index (If object is already in
01236 // group, nothing is changed.)
01237 void ON_3dmObjectAttributes::AddToGroup(
01238   int group_index // zero based group index
01239   )
01240 {
01241   if ( group_index >= 0 ) {
01242     if ( !IsInGroup(group_index) )
01243       m_group.Append(group_index);
01244   }
01245 }
01246 
01248 // returns the index of the last group in the group list
01249 // or -1 if the object is not in any groups
01250 int ON_3dmObjectAttributes::TopGroup() const
01251 {
01252   const int* top_group = m_group.Last();
01253   return top_group ? *top_group : -1;
01254 }
01255 
01257 // removes the object from the last group in the group list
01258 void ON_3dmObjectAttributes::RemoveFromTopGroup()
01259 {
01260   int c = m_group.Count();
01261   if ( c > 0 ) {
01262     c--;
01263     m_group.SetCount(c);
01264   }
01265 }
01266 
01268 // Removes object from group with specified index.  If object is not
01269 // in the group, nothing is changed.
01270 void ON_3dmObjectAttributes::RemoveFromGroup(
01271   int group_index // zero based group index
01272   )
01273 {
01274   int i;
01275   const int count = m_group.Count();
01276   for ( i = 0; i < count; i++ ) {
01277     if (m_group[i] == group_index) {
01278       m_group.Remove(i);
01279       break;
01280     }
01281   }
01282 }
01283 
01285 // Removes object from all groups.
01286 void ON_3dmObjectAttributes::RemoveFromAllGroups()
01287 {
01288   m_group.Destroy();
01289 }
01290 
01291 
01292 bool ON_3dmObjectAttributes::FindDisplayMaterialId( 
01293       const ON_UUID& viewport_id, 
01294       ON_UUID* display_material_id
01295       ) const
01296 {
01297   bool rc = false;
01298   if ( m_dmref.Count() > 0 )
01299   {
01300     ON_DisplayMaterialRef search_material, found_material;
01301     search_material.m_viewport_id = viewport_id;
01302     if ( 0 != (rc = FindDisplayMaterialRef(search_material,&found_material)) )
01303     {
01304       if ( display_material_id )
01305         *display_material_id = found_material.m_display_material_id;
01306     }
01307   }
01308   return rc;
01309 }
01310 
01311 
01312 bool ON_3dmObjectAttributes::FindDisplayMaterialRef(
01313   const ON_DisplayMaterialRef& search_material,
01314   ON_DisplayMaterialRef* found_material
01315   ) const
01316 {
01317   int i = m_dmref.Count();
01318   if ( i > 0 )
01319   {
01320     int j = -1;
01321     if ( search_material.m_viewport_id != ON_nil_uuid )
01322     {
01323       if ( search_material.m_display_material_id != ON_nil_uuid )
01324       {
01325         while(i--)
01326         {
01327           if ( (m_dmref[i].m_display_material_id == search_material.m_display_material_id) &&
01328                (m_dmref[i].m_viewport_id == search_material.m_viewport_id) )
01329           {
01330             if(found_material)
01331               *found_material = m_dmref[i];
01332             return true;
01333           }
01334         }
01335       }
01336       else
01337       {
01338         while(i--)
01339         {
01340           const ON_UUID& vid = m_dmref[i].m_viewport_id;
01341           if ( vid == search_material.m_viewport_id )
01342           {
01343             if(found_material)
01344               *found_material = m_dmref[i];
01345             return true;
01346           }
01347           if ( vid == ON_nil_uuid )
01348           {
01349             j = i;
01350           }
01351         }
01352         if ( j >= 0 )
01353         {
01354           if(found_material)
01355             *found_material = m_dmref[j];
01356           return true;
01357         }
01358       }
01359     }
01360     else
01361     {
01362       if ( search_material.m_display_material_id != ON_nil_uuid )
01363       {
01364         while(i--)
01365         {
01366           if ( m_dmref[i].m_display_material_id == search_material.m_display_material_id )
01367           {
01368             if ( m_dmref[i].m_viewport_id == ON_nil_uuid )
01369             {
01370               if(found_material)
01371                 *found_material = m_dmref[i];
01372               return true;
01373             }
01374             if ( j < 0 )
01375               j = i;
01376           }
01377         }
01378         if ( j >= 0 )
01379         {
01380           if(found_material)
01381             *found_material = m_dmref[j];
01382           return true;
01383         }
01384       }
01385       else
01386       {
01387         while(i--)
01388         {
01389           if ( m_dmref[i].m_viewport_id == ON_nil_uuid )
01390           {
01391             if(found_material)
01392               *found_material = m_dmref[i];
01393             return true;
01394           }
01395         }
01396       }
01397     }
01398   }
01399   return false;
01400 }
01401 
01402 
01403 bool ON_3dmObjectAttributes::AddDisplayMaterialRef(
01404   ON_DisplayMaterialRef display_material
01405   )
01406 {
01407   bool rc = false;
01408   if ( !(display_material.m_display_material_id == ON_nil_uuid) )
01409   {
01410     int i = m_dmref.Count();
01411     while(i--)
01412     {
01413       if ( m_dmref[i].m_viewport_id == display_material.m_viewport_id )
01414       {
01415          m_dmref[i] = display_material;
01416          return true;
01417       }
01418     }
01419     m_dmref.Append(display_material);
01420   }
01421   return rc;
01422 }
01423 
01424 void ON_3dmObjectAttributes::RemoveAllDisplayMaterialRefs()
01425 {
01426   m_dmref.Destroy();
01427 }
01428 
01429 bool ON_3dmObjectAttributes::RemoveDisplayMaterialRef(
01430   ON_UUID viewport_id,
01431   ON_UUID display_material_id
01432   )
01433 {
01434   bool rc = false;
01435   int i = m_dmref.Count();
01436   if ( i > 0 )
01437   {
01438     const bool bCheckViewportId = !ON_UuidIsNil(viewport_id);
01439     const bool bCheckMaterialId = !ON_UuidIsNil(display_material_id);
01440     if ( bCheckViewportId || bCheckMaterialId )
01441     {
01442       while(i--)
01443       {
01444         if ( bCheckViewportId && m_dmref[i].m_viewport_id != viewport_id )
01445           continue;
01446         if ( bCheckMaterialId && m_dmref[i].m_display_material_id != display_material_id )
01447           continue;
01448 
01449         // remove this item
01450         rc = true;
01451         m_dmref.Remove(i);
01452       }
01453     }
01454     else
01455     {
01456       // 20 Sep 2006 Dale Lear - this was added so we can
01457       // remove all entries with non-nil viewport and nil
01458       // uuid.
01459       while(i--)
01460       {
01461         if (   !ON_UuidIsNil(m_dmref[i].m_viewport_id)
01462              && ON_UuidIsNil(m_dmref[i].m_display_material_id)
01463            )
01464         {
01465           // remove this item
01466           rc = true;
01467           m_dmref.Remove(i);
01468         }
01469       }
01470     }
01471   }
01472   return rc;
01473 }
01474 
01475 int ON_3dmObjectAttributes::DisplayMaterialRefCount() const
01476 {
01477   return m_dmref.Count();
01478 }
01479 
01480 // {1403A7E4-E7AD-4a01-A2AA-41DAE6BE7ECB}
01481 const ON_UUID ON_DisplayMaterialRef::m_invisible_in_detail_id = 
01482 { 0x1403a7e4, 0xe7ad, 0x4a01, { 0xa2, 0xaa, 0x41, 0xda, 0xe6, 0xbe, 0x7e, 0xcb } };
01483 
01484 
01485 ON_DisplayMaterialRef::ON_DisplayMaterialRef()
01486 {
01487   m_viewport_id = ON_nil_uuid;
01488   m_display_material_id = ON_nil_uuid;
01489 }
01490 
01491 bool ON_DisplayMaterialRef::operator==(const ON_DisplayMaterialRef& other) const
01492 {
01493   return (Compare(other)==0); 
01494 }
01495 
01496 bool ON_DisplayMaterialRef::operator!=(const ON_DisplayMaterialRef& other) const
01497 {
01498   return (Compare(other)!=0); 
01499 }
01500 
01501 int ON_DisplayMaterialRef::Compare(const ON_DisplayMaterialRef& other) const
01502 {
01503   int i = ON_UuidCompare(m_viewport_id,other.m_viewport_id);
01504   if (0==i)
01505     i = ON_UuidCompare(m_display_material_id,other.m_display_material_id);
01506   return i;
01507 }
01508 
01509 bool ON_DisplayMaterialRef::operator<(const ON_DisplayMaterialRef& other) const
01510 {
01511   return (Compare(other)<0); 
01512 }
01513 
01514 bool ON_DisplayMaterialRef::operator<=(const ON_DisplayMaterialRef& other) const
01515 {
01516   return (Compare(other)<=0); 
01517 }
01518 
01519 bool ON_DisplayMaterialRef::operator>(const ON_DisplayMaterialRef& other) const
01520 {
01521   return (Compare(other)>0); 
01522 }
01523 
01524 bool ON_DisplayMaterialRef::operator>=(const ON_DisplayMaterialRef& other) const
01525 {
01526   return (Compare(other)>=0); 
01527 }
01528 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:58