void ON_SetBinaryArchiveOpenNURBSVersion(ON_BinaryArchive& file, unsigned int value) { if ( ON_VersionNumberIsValid(value) ) { // can be yyyymmddn or a number from ON_VersionNumberConstruct(). file.m_3dm_opennurbs_version = value; } else if ( ON_VersionNumberIsYearMonthDateFormat(file.Archive3dmVersion(),value) ) { // can be yyyymmddn or a number from ON_VersionNumberConstruct(). if ( 9 == (value%10) && value <= 201712319 ) { // 9 marked debug versions. unsigned int n = file.Archive3dmVersion(); if ( n >= 50 && 0 == (n%10) ) n /= 10; if ( n > 0 && n < 9 ) value = ((value/10)*10) + n; } file.m_3dm_opennurbs_version = value; } else { ON_ERROR("ON_SetBinaryArchiveOpenNURBSVersion - invalid opennurbs version"); file.m_3dm_opennurbs_version = 0; } }
BOOL ON_BrepEdge::Read( ON_BinaryArchive& file ) { int bReversed = false; ON_Interval proxy_domain; BOOL rc = file.ReadInt( &m_edge_index ); if (rc) rc = file.ReadInt( &m_c3i ); if (rc) rc = file.ReadInt( &bReversed ); if (rc) rc = file.ReadInterval( proxy_domain ); if (rc) rc = file.ReadInt( 2, m_vi ); if (rc) rc = file.ReadArray( m_ti ); if (rc) rc = file.ReadDouble( &m_tolerance ); ON_Interval domain = proxy_domain; if ( file.Archive3dmVersion() >= 3 && file.ArchiveOpenNURBSVersion() >= 200206180 ) { if (rc) { rc = file.ReadInterval(domain); if ( !rc) domain = proxy_domain; } } SetProxyCurve( NULL, proxy_domain ); if ( bReversed ) ON_CurveProxy::Reverse(); SetDomain(domain); return rc; }
BOOL ON_BrepTrim::Write( ON_BinaryArchive& file ) const { ON_3dPoint P(0.0,0.0,0.0); BOOL rc = file.WriteInt( m_trim_index ); int i; if ( rc ) rc = file.WriteInt( m_c2i ); if ( rc ) rc = file.WriteInterval( ProxyCurveDomain() ); if ( rc ) rc = file.WriteInt( m_ei ); if ( rc ) rc = file.WriteInt( 2, m_vi ); if ( rc ) rc = file.WriteInt( m_bRev3d ); i = m_type; if ( rc ) rc = file.WriteInt( i ); i = m_iso; if ( rc ) rc = file.WriteInt( i ); if ( rc ) rc = file.WriteInt( m_li ); if ( rc ) rc = file.WriteDouble( 2, m_tolerance ); if ( file.Archive3dmVersion() < 3 ) { if ( rc ) rc = file.WritePoint( P ); // m_P[0] ); if ( rc ) rc = file.WritePoint( P ); // m_P[1] ); } else { // trim proxy curve information added in version 200206180 if (rc ) rc = file.WriteInterval( Domain() ); unsigned char b[24]; memset(b,0,sizeof(b)); b[0] = ProxyCurveIsReversed() ? 1 : 0; if (rc) rc = file.WriteChar(8,b); b[0] = 0; if (rc) rc = file.WriteChar(24,b); } if ( rc ) rc = file.WriteDouble( m__legacy_2d_tol ); if ( rc ) rc = file.WriteDouble( m__legacy_3d_tol ); return rc; }
BOOL ON_BrepEdge::Write( ON_BinaryArchive& file ) const { BOOL rc = file.WriteInt( m_edge_index ); if (rc) rc = file.WriteInt( m_c3i ); int i = ProxyCurveIsReversed() ? 1 : 0; if (rc) rc = file.WriteInt( i ); if (rc) rc = file.WriteInterval( ProxyCurveDomain() ); if (rc) rc = file.WriteInt( 2, m_vi ); if (rc) rc = file.WriteArray( m_ti ); if (rc) rc = file.WriteDouble( m_tolerance ); if ( file.Archive3dmVersion() >= 3 ) { // added in opennurbs version 200206180 if (rc) rc = file.WriteInterval( Domain() ); } return rc; }
bool ON_CheckSum::Write(ON_BinaryArchive& archive) const { bool rc = false; if ( archive.Archive3dmVersion() < 4 ) { // V3 files had other information // 48 bytes of zeros will work ok unsigned char b[48]; memset(b,0,sizeof(b)); rc = archive.WriteByte(48,b); } else { rc = archive.WriteBigSize(m_size); if (rc) rc = archive.WriteBigTime(m_time); if (rc) rc = archive.WriteInt(8,&m_crc[0]); } return rc; }
bool ON_CheckSum::Read(ON_BinaryArchive& archive) { bool rc; Zero(); rc = archive.ReadBigSize(&m_size); if (rc) rc = archive.ReadBigTime(&m_time); if (rc) rc = archive.ReadInt(8,&m_crc[0]); if ( archive.ArchiveOpenNURBSVersion() < 200603100 || archive.Archive3dmVersion() < 4 ) { // ON_CheckSums in V3 archives and V4 archives with // version < 200603100 have the same size but an // incompatible format. These were not used. Zero(); } return rc; }
ON_BOOL32 ON_3dmObjectAttributes::Write( ON_BinaryArchive& file ) const { if ( file.Archive3dmVersion() >= 5 ) { // added at opennurbs version 200712190 return WriteV5Helper(file); } bool rc = file.Write3dmChunkVersion(1,7); // version 1.0 fields if (rc) rc = file.WriteUuid(m_uuid); if (rc) rc = file.WriteInt(m_layer_index); if (rc) rc = file.WriteInt(m_material_index); if (rc) rc = file.WriteColor(m_color); if (rc) { // OBSOLETE if (rc) rc = file.WriteLineStyle(m_line_style); // 23 March 2005 Dale Lear short s; s = (short)m_object_decoration; if (rc) rc = file.WriteShort(s); s = 0; if (rc) rc = file.WriteShort(s); if (rc) rc = file.WriteDouble(0.0); if (rc) rc = file.WriteDouble(1.0); } if (rc) rc = file.WriteInt(m_wire_density); if (rc) rc = file.WriteChar(m_mode); if (rc) rc = file.WriteChar(m_color_source); if (rc) rc = file.WriteChar(m_linetype_source); if (rc) rc = file.WriteChar(m_material_source); if (rc) rc = file.WriteString(m_name); if (rc) rc = file.WriteString(m_url); // version 1.1 fields if (rc) rc = file.WriteArray(m_group); // version 1.2 fields if (rc) rc = file.WriteBool(m_bVisible); // version 1.3 fields if (rc) rc = file.WriteArray(m_dmref); // version 1.4 fields - 23 March 2005 Dale Lear if (rc) rc = file.WriteInt(m_object_decoration); if (rc) rc = file.WriteChar(m_plot_color_source); if (rc) rc = file.WriteColor(m_plot_color); if (rc) rc = file.WriteChar(m_plot_weight_source); if (rc) rc = file.WriteDouble(m_plot_weight_mm); // version 1.5 fields 11 April 2005 if (rc) rc = file.WriteInt(m_linetype_index); // version 1.6 fields 2 September 2005 if (rc) { unsigned char uc = 0; switch(m_space) { case ON::no_space: uc = 0; break; case ON::model_space: uc = 0; break; case ON::page_space: uc = 1; break; } rc = file.WriteChar(uc); } if (rc) { // 22 Sep 2006 - the way ON_3dmObjectAttiributes indicates // that an object is put on a particular page view changed // from being saved in the m_dmref[] list to using the // m_space and m_viewport_id settings. But the file format // cannot change at this point. So, the bAddPagespaceDMR // is here to save the page info in the old dmr format. int count = m_dmref.Count(); if ( count < 0 ) count = 0; bool bAddPagespaceDMR = ( ON::page_space == m_space && !ON_UuidIsNil(m_viewport_id) ); rc = file.WriteInt( bAddPagespaceDMR ? (count+1) : count ); if ( rc && bAddPagespaceDMR ) { rc = file.WriteUuid(m_viewport_id); if (rc) rc = file.WriteUuid(ON_ObsoletePageSpaceObjectId); } int i; for ( i = 0; i < count && rc; i++ ) { const ON_DisplayMaterialRef& dmr = m_dmref[i]; rc = file.WriteUuid(dmr.m_viewport_id); if (rc) rc = file.WriteUuid(dmr.m_display_material_id); } } // version 1.7 fields 6 June 2006 if (rc) rc = m_rendering_attributes.Write(file); return rc; }
ON_BOOL32 ON_3dmObjectAttributes::Read( ON_BinaryArchive& file ) { Default(); if ( file.Archive3dmVersion() >= 5 && file.ArchiveOpenNURBSVersion() >= 200712190 ) { return ReadV5Helper(file); } int i; int major_version = 0; int minor_version = 0; bool rc = file.Read3dmChunkVersion(&major_version,&minor_version); if ( rc && major_version == 1 ) { if (rc) rc = file.ReadUuid(m_uuid); if (rc) rc = file.ReadInt(&m_layer_index); if (rc) rc = file.ReadInt(&m_material_index); if (rc) rc = file.ReadColor(m_color); while(rc) { // OBSOLETE if (rc) rc = file.ReadLineStyle(m_line_style); // 23 March 2005 Dale Lear // replaced with short s = 0; double x; rc = file.ReadShort(&s); if (!rc) break; if ( file.Archive3dmVersion() < 4 || file.ArchiveOpenNURBSVersion() < 200503170 ) { // ignore unused linestyle info in old files // This bit keeps the curve arrowheads from V3 showing up // in V4. m_object_decoration = ON::ObjectDecoration( (s & ON::both_arrowhead) ); } rc = file.ReadShort(&s); if (!rc) break; rc = file.ReadDouble(&x); if (!rc) break; rc = file.ReadDouble(&x); break; } if (rc) rc = file.ReadInt(&m_wire_density); if (rc) rc = file.ReadChar(&m_mode); if (rc) rc = file.ReadChar(&m_color_source); if (rc) m_color_source = (unsigned char)ON::ObjectColorSource(m_color_source); if (rc) rc = file.ReadChar(&m_linetype_source); if (rc) m_linetype_source = (unsigned char)ON::ObjectLinetypeSource(m_linetype_source); if (rc) rc = file.ReadChar(&m_material_source); if (rc) m_material_source = (unsigned char)ON::ObjectMaterialSource(m_material_source); if (rc) rc = file.ReadString(m_name); if (rc) rc = file.ReadString(m_url); m_bVisible = (Mode() != ON::hidden_object); if ( rc && minor_version >= 1 ) { rc = file.ReadArray( m_group ); if ( rc && minor_version >= 2 ) { rc = file.ReadBool(&m_bVisible); if ( rc && minor_version >= 3 ) { rc = file.ReadArray(m_dmref); if (rc && minor_version >= 4 ) { // 23 March 2005 Dale Lear // Added m_plot_color_source and m_plot_color i = 0; if (rc) rc = file.ReadInt(&i); if (rc) m_object_decoration = ON::ObjectDecoration(i); if (rc) rc = file.ReadChar(&m_plot_color_source); if (rc) m_plot_color_source = (unsigned char)ON::PlotColorSource(m_plot_color_source); if (rc) rc = file.ReadColor( m_plot_color ); if (rc) rc = file.ReadChar(&m_plot_weight_source); if (rc) m_plot_weight_source = (unsigned char)ON::PlotWeightSource(m_plot_weight_source); if (rc) rc = file.ReadDouble(&m_plot_weight_mm); if (rc && minor_version >= 5 ) { // version 1.5 fields 11 April 2005 if (rc) rc = file.ReadInt(&m_linetype_index); // version 1.6 fields 2 September 2005 if (rc && minor_version >= 6 ) { unsigned char uc = 0; rc = file.ReadChar(&uc); if (rc) { m_space = (1 == uc) ? ON::page_space : ON::model_space; m_dmref.Empty(); int i, count=0; rc = file.ReadInt(&count); if (rc && count > 0) { m_dmref.SetCapacity(count); for ( i = 0; i < count && rc; i++) { ON_DisplayMaterialRef& dmr = m_dmref.AppendNew(); rc = file.ReadUuid(dmr.m_viewport_id); if (rc) rc = file.ReadUuid(dmr.m_display_material_id); if ( rc ) { // Assigning an object to a page started out as // using dmrs. The way the runtime info is saved // has changed, but, at this point, I can't change // the way the information is saved in the file and // it doesn't matter. if ( 0 == ON_UuidCompare(&ON_ObsoletePageSpaceObjectId,&dmr.m_display_material_id) ) { m_viewport_id = dmr.m_viewport_id; m_dmref.Remove(); } } } if ( 0 == m_dmref.Count() ) m_dmref.Destroy(); } } if ( rc && minor_version >= 7 ) { // version 1.7 fields 6 June 2006 if (rc) rc = m_rendering_attributes.Read(file); } } } } } } } } else { rc = false; } return rc; }
BOOL ON_Brep::Write( ON_BinaryArchive& file ) const { const ON_Brep* brep = this; ON_Brep* v2brep = 0; if ( file.Archive3dmVersion() <= 2 && !IsValidForV2() ) { v2brep = ON_Brep::New(*this); v2brep->MakeValidForV2(); brep = v2brep; } //BOOL rc = file.Write3dmChunkVersion(3,0); // serialization version //BOOL rc = file.Write3dmChunkVersion(3,1); // added meshes BOOL rc = file.Write3dmChunkVersion(3,2); // added m_is_solid // 2d curves if (rc) rc = brep->m_C2.Write(file); // 3d curves if (rc) rc = brep->m_C3.Write(file); // untrimmed surfaces if (rc) rc = brep->m_S.Write(file); // vertices if (rc) rc = brep->m_V.Write(file); // edges if (rc) rc = brep->m_E.Write(file); // trims if (rc) rc = brep->m_T.Write(file); // loops if (rc) rc = brep->m_L.Write(file); // faces if (rc) rc = brep->m_F.Write(file); // bounding box if (rc) rc = file.WritePoint( brep->m_bbox.m_min ); if (rc) rc = file.WritePoint( brep->m_bbox.m_max ); // end of chunk version 3.0 if (rc) { // added for chunk version 3.1 const int face_count = brep->m_F.Count(); int fi; unsigned char b; // write render meshes rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 ); if ( rc ) { for ( fi = 0; rc && fi < face_count; fi++ ) { const ON_Mesh* mesh = file.Save3dmRenderMeshes() ? brep->m_F[fi].m_render_mesh : 0; b = mesh ? 1 : 0; file.WriteChar(b); if (mesh) { rc = file.WriteObject(*mesh); } } if ( !file.EndWrite3dmChunk() ) { rc = false; } } // write analysis meshes rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 ); if ( rc ) { for ( fi = 0; rc && fi < face_count; fi++ ) { const ON_Mesh* mesh = file.Save3dmAnalysisMeshes() ? brep->m_F[fi].m_analysis_mesh : 0; b = mesh ? 1 : 0; file.WriteChar(b); if (mesh) { rc = file.WriteObject(*mesh); } } if ( !file.EndWrite3dmChunk() ) rc = false; } } // end of chunk version 3.1 // use value of "this" m_is_solid to avoid expensive // calculation on the v2brep if ( !file.WriteInt( m_is_solid ) ) rc = false; // end of chunk version 3.2 if ( 0 != v2brep ) delete v2brep; return rc; }
BOOL ON_BrepTrim::Read( ON_BinaryArchive& file ) { ON_3dPoint P[2]; int i; BOOL rc = file.ReadInt( &m_trim_index ); if ( rc ) rc = file.ReadInt( &m_c2i ); if ( rc ) { ON_Interval d; rc = file.ReadInterval( d ); if (rc) { SetProxyCurveDomain(d); SetDomain(d); } } if ( rc ) rc = file.ReadInt( &m_ei ); if ( rc ) rc = file.ReadInt( 2, m_vi ); if ( rc ) { i = m_bRev3d; rc = file.ReadInt( &i ); if (rc) m_bRev3d = (i!=0); } i = unknown; if ( rc ) rc = file.ReadInt( &i ); switch (i) { case unknown: m_type = unknown; break; case boundary: m_type = boundary; break; case mated: m_type = mated; break; case seam: m_type = seam; break; case singular: m_type = singular; break; } i = ON_Surface::not_iso; if ( rc ) rc = file.ReadInt( &i ); switch(i) { case ON_Surface::not_iso: m_iso = ON_Surface::not_iso; break; case ON_Surface::x_iso: m_iso = ON_Surface::x_iso; break; case ON_Surface::y_iso: m_iso = ON_Surface::y_iso; break; case ON_Surface::W_iso: m_iso = ON_Surface::W_iso; break; case ON_Surface::S_iso: m_iso = ON_Surface::S_iso; break; case ON_Surface::E_iso: m_iso = ON_Surface::E_iso; break; case ON_Surface::N_iso: m_iso = ON_Surface::N_iso; break; } if ( rc ) rc = file.ReadInt( &m_li ); if ( rc ) rc = file.ReadDouble( 2, m_tolerance ); if ( file.Archive3dmVersion() >= 3 && file.ArchiveOpenNURBSVersion() >= 200206180 ) { // read trim proxy curve information added in version 200206180 ON_Interval d = ProxyCurveDomain(); if (rc ) { rc = file.ReadInterval( d ); if ( !rc ) d = ProxyCurveDomain(); } unsigned char b[24]; memset(b,0,sizeof(b)); bool bProxyCurveIsReversed = false; if (rc) { rc = file.ReadChar(8,b); if (rc && b[0] == 1 ) bProxyCurveIsReversed = true; } if (rc) rc = file.ReadChar(24,b); if ( bProxyCurveIsReversed ) ON_CurveProxy::Reverse(); SetDomain(d); } else { if ( rc ) rc = file.ReadPoint( P[0] ); //m_P[0] ); if ( rc ) rc = file.ReadPoint( P[1] ); //m_P[1] ); } if ( rc ) rc = file.ReadDouble( &m__legacy_2d_tol ); if ( rc ) rc = file.ReadDouble( &m__legacy_3d_tol ); return rc; }
bool ON_3dmProperties::Write(ON_BinaryArchive& file) const { bool rc = true; // This short chunk identifies the version of OpenNURBS that was used to write this file. const unsigned int version_number_to_write = ON_BinaryArchive::ArchiveOpenNURBSVersionToWrite(file.Archive3dmVersion(), ON::Version()); rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_OPENNURBS_VERSION, version_number_to_write); if (rc) rc = file.EndWrite3dmChunk(); if (!rc) return false; // This chunk added November 5, 2015 const ON_wString archive_full_path = file.ArchiveFullPath().IsEmpty() ? m_3dmArchiveFullPathName : file.ArchiveFullPath(); if (archive_full_path.IsNotEmpty()) { if (!file.BeginWrite3dmChunk(TCODE_PROPERTIES_AS_FILE_NAME, 0)) return false; rc = file.WriteString(file.ArchiveFullPath()); if (!file.EndWrite3dmChunk()) rc = false; if (!rc) return false; } // optional TCODE_PROPERTIES_REVISIONHISTORY chunk - file creation/revision information if ( rc && m_RevisionHistory.IsValid() ) { rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_REVISIONHISTORY,0); if ( rc ) { rc = m_RevisionHistory.Write(file); if ( !file.EndWrite3dmChunk() ) rc = false; } } // optional TCODE_PROPERTIES_NOTES chunk - file notes if ( rc && m_Notes.IsValid() ) { rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_NOTES,0); if ( rc ) { rc = m_Notes.Write(file); if ( !file.EndWrite3dmChunk() ) rc = false; } } //// When merging Mac code please note that the //// TCODE_PROPERTIES_PREVIEWIMAGE chunk is OBSOLETE. //// DO NOT WRITE THEM IN V6 FILES. If performance is an //// issue, we will address it some other way. // optional TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE chunk - bitmap preview if ( rc && m_PreviewImage.IsValid() && file.Save3dmPreviewImage()) { rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE,0); if ( rc ) { rc = m_PreviewImage.WriteCompressed(file); if ( !file.EndWrite3dmChunk() ) rc = false; } } // optional TCODE_PROPERTIES_APPLICATION chunk - application information if ( rc && m_Application.IsValid() ) { rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_APPLICATION,0); if ( rc ) { rc = m_Application.Write(file); if ( !file.EndWrite3dmChunk() ) rc = false; } } // required TCODE_ENDOFTABLE chunk - marks end of properties table if ( rc ) { rc = file.BeginWrite3dmChunk( TCODE_ENDOFTABLE, 0 ); if ( rc ) { if ( !file.EndWrite3dmChunk() ) rc = false; } } return rc; }
bool ON_3dmProperties::Read(ON_BinaryArchive& file ) { *this = ON_3dmProperties::Empty; bool rc = true; unsigned int tcode; ON__INT64 value; for(;;) { rc = file.BeginRead3dmBigChunk( &tcode, &value ); if ( !rc ) break; switch(tcode) { case TCODE_PROPERTIES_OPENNURBS_VERSION: { unsigned int opennurbs_version = 0; if ( value > 0 && value <= 0xFFFFFFFFll) { opennurbs_version = (unsigned int)((ON__UINT64)value); } if ( !ON_VersionNumberIsValid(opennurbs_version) && !ON_VersionNumberIsYearMonthDateFormat(file.Archive3dmVersion(),opennurbs_version) ) { ON_ERROR("ON_3dmProperties::Read - TCODE_PROPERTIES_OPENNURBS_VERSION corrupt value"); rc = false; } ON_SetBinaryArchiveOpenNURBSVersion(file,opennurbs_version); } break; case TCODE_PROPERTIES_AS_FILE_NAME: rc = file.ReadString(m_3dmArchiveFullPathName); break; case TCODE_PROPERTIES_REVISIONHISTORY: // file creation/revision information rc = m_RevisionHistory.Read(file); break; case TCODE_PROPERTIES_NOTES: // file notes rc = m_Notes.Read(file); break; case TCODE_PROPERTIES_PREVIEWIMAGE: // uncompressed preview image rc = m_PreviewImage.ReadUncompressed(file); break; case TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE: // compressed preview image rc = m_PreviewImage.ReadCompressed(file); break; case TCODE_PROPERTIES_APPLICATION: // application that created 3dm file rc = m_Application.Read(file); break; default: // information added in future will be skipped by file.EndRead3dmChunk() break; } if ( !file.EndRead3dmChunk() ) rc = false; if (!rc) break; if ( TCODE_ENDOFTABLE == tcode ) break; } return rc; }
ON_BOOL32 ON_InstanceDefinition::Write( ON_BinaryArchive& binary_archive ) const { bool rc = binary_archive.Write3dmChunkVersion(1,5); // version 1.0 fields if ( rc ) rc = binary_archive.WriteUuid( m_uuid ); if ( rc ) { if ( binary_archive.Archive3dmVersion() >= 4 && ON_InstanceDefinition::linked_def == m_idef_update_type ) { // linked instance definition geometry is never in the file ON_SimpleArray<ON_UUID> empty_uuid_list; rc = binary_archive.WriteArray( empty_uuid_list ); } else { rc = binary_archive.WriteArray( m_object_uuid ); } } if ( rc ) rc = binary_archive.WriteString( m_name ); if ( rc ) rc = binary_archive.WriteString( m_description ); if ( rc ) rc = binary_archive.WriteString( m_url ); if ( rc ) rc = binary_archive.WriteString( m_url_tag ); if ( rc ) rc = binary_archive.WriteBoundingBox( m_bbox ); // m_idef_update_type was an unsigned int and got changed to an enum. Read and write // as an unsigned int to support backwards compatibility if ( rc ) rc = binary_archive.WriteInt( (unsigned int)m_idef_update_type ); if ( rc ) rc = binary_archive.WriteString( m_source_archive ); // version 1.1 fields if (rc) rc = m_source_archive_checksum.Write( binary_archive ); // version 1.2 fields if (rc) rc = binary_archive.WriteInt( m_us.m_unit_system ); // version 1.3 fields - added 6 March 2006 if (rc) rc = binary_archive.WriteDouble( m_us.m_custom_unit_scale ); if ( rc ) rc = binary_archive.WriteBool( m_source_bRelativePath ); // version 1.4 fields if (rc) rc = m_us.Write(binary_archive); // version 1.5 fields if (rc) rc = binary_archive.WriteInt(m_idef_update_depth); return rc; }
BOOL ON_UnknownUserData::Read( ON_BinaryArchive& file ) { m_buffer = onrealloc( m_buffer, m_sizeof_buffer ); m_3dm_version = file.Archive3dmVersion(); return file.ReadByte(m_sizeof_buffer,m_buffer); }
ON_BOOL32 ON_InstanceDefinition::Read( ON_BinaryArchive& binary_archive ) { int major_version = 0; int minor_version = 0; m_idef_layer_style = 0; m_us.m_custom_unit_scale = 0.0; m_us.m_custom_unit_name.Destroy(); m_us.m_unit_system = ON::no_unit_system; m_source_bRelativePath = false; m_source_archive.Destroy(); bool rc = binary_archive.Read3dmChunkVersion(&major_version,&minor_version); if ( rc ) { if ( major_version != 1 ) rc = false; // version 1.0 fields if ( rc ) rc = binary_archive.ReadUuid( m_uuid ); if ( rc ) rc = binary_archive.ReadArray( m_object_uuid ); if ( rc ) rc = binary_archive.ReadString( m_name ); if ( rc ) rc = binary_archive.ReadString( m_description ); if ( rc ) rc = binary_archive.ReadString( m_url ); if ( rc ) rc = binary_archive.ReadString( m_url_tag ); if ( rc ) rc = binary_archive.ReadBoundingBox( m_bbox ); // m_idef_update_type was an unsigned int and got changed to an enum. Read and write // as an unsigned int to support backwards compatibility unsigned int source = m_idef_update_type; if ( rc ) rc = binary_archive.ReadInt( &source ); if( rc) m_idef_update_type = ON_InstanceDefinition::IdefUpdateType(source); if ( rc ) rc = binary_archive.ReadString( m_source_archive ); // version 1.1 fields if ( minor_version >= 1 ) { if ( rc ) rc = m_source_archive_checksum.Read( binary_archive ); } // version 1.2 fields if ( minor_version >= 2 ) { int us = ON::no_unit_system; if ( rc ) rc = binary_archive.ReadInt( &us ); m_us.m_unit_system = ON::UnitSystem(us); if ( ON::custom_unit_system != m_us.m_unit_system && ON::no_unit_system != m_us.m_unit_system ) { m_us.m_custom_unit_scale = ON::UnitScale( m_us.m_unit_system, ON::meters ); } else { m_us.m_custom_unit_scale = 0.0; } if ( minor_version >= 3 ) { // version 1.3 fields - added 6 March 2006 //int us = ON::no_unit_system; if ( rc ) rc = binary_archive.ReadDouble( &m_us.m_custom_unit_scale ); if ( rc ) rc = binary_archive.ReadBool( &m_source_bRelativePath ); if ( rc && minor_version >= 4 ) { rc = m_us.Read(binary_archive); if (rc && minor_version >= 5 ) { rc = binary_archive.ReadInt(&m_idef_update_depth); if ( rc && minor_version >= 6 ) { unsigned int i = 0; rc = binary_archive.ReadInt(&i); if ( i && i > 0 && i < 256 ) m_idef_layer_style = (unsigned char)i; } } } } } if ( ON_InstanceDefinition::embedded_def == m_idef_update_type ) { // 7 February 2012 // "embedded_def" is obsolete. if (m_source_archive.Length() > 0 ) m_idef_update_type = ON_InstanceDefinition::linked_and_embedded_def; else DestroySourceArchive(); // convert to static } if ( ON_InstanceDefinition::linked_def == m_idef_update_type ) { if ( m_idef_layer_style < 1 || m_idef_layer_style > 2 ) { // The goal of the next if/else clause is for Rhino users // to see what they saw when they created the file. if ( binary_archive.Archive3dmVersion() < 50 ) { // V4 linked blocks and early V5 linked blocks treated // layers and materials the way newer "active" idefs work, // so when I read an archive with version < 50, the // default will be 1 for "active". m_idef_layer_style = 1; } else { // The more recent V5 linked blocks treated layers and materials // the way "reference" style idefs work, so when I read an // archive with version >= 50 (meaning recent V5), the default // will be 2 for "reference". m_idef_layer_style = 2; } } } else { m_idef_layer_style= 0; } } return rc; }
ON_BOOL32 ON_InstanceDefinition::Write( ON_BinaryArchive& binary_archive ) const { bool rc = binary_archive.Write3dmChunkVersion(1,6); // version 1.0 fields if ( rc ) rc = binary_archive.WriteUuid( m_uuid ); if ( rc ) { if ( binary_archive.Archive3dmVersion() >= 4 && ON_InstanceDefinition::linked_def == m_idef_update_type ) { // linked instance definition geometry is never in the file ON_SimpleArray<ON_UUID> empty_uuid_list; rc = binary_archive.WriteArray( empty_uuid_list ); } else { rc = binary_archive.WriteArray( m_object_uuid ); } } if ( rc ) rc = binary_archive.WriteString( m_name ); if ( rc ) rc = binary_archive.WriteString( m_description ); if ( rc ) rc = binary_archive.WriteString( m_url ); if ( rc ) rc = binary_archive.WriteString( m_url_tag ); if ( rc ) rc = binary_archive.WriteBoundingBox( m_bbox ); // m_idef_update_type was an unsigned int and got changed to an enum. Read and write // as an unsigned int to support backwards compatibility const unsigned int idef_update_type = (unsigned int)this->IdefUpdateType(); if ( rc ) rc = binary_archive.WriteInt( idef_update_type ); if ( rc ) { // 7 February 2012 // Purge source archive information from static_defs if ( ON_InstanceDefinition::static_def == idef_update_type ) { ON_wString empty_string; rc = binary_archive.WriteString( empty_string ); } else rc = binary_archive.WriteString( m_source_archive ); } // version 1.1 fields if (rc) { // 7 February 2012 // Purge source archive information from static_defs if ( ON_InstanceDefinition::static_def == idef_update_type ) ON_CheckSum::UnsetCheckSum.Write(binary_archive); else rc = m_source_archive_checksum.Write( binary_archive ); } // version 1.2 fields if (rc) rc = binary_archive.WriteInt( m_us.m_unit_system ); // version 1.3 fields - added 6 March 2006 if (rc) rc = binary_archive.WriteDouble( m_us.m_custom_unit_scale ); if ( rc ) { bool b = (ON_InstanceDefinition::static_def == idef_update_type) ? false : m_source_bRelativePath; rc = binary_archive.WriteBool( b ); } // version 1.4 fields if (rc) rc = m_us.Write(binary_archive); // version 1.5 fields if (rc) rc = binary_archive.WriteInt(m_idef_update_depth); // version 1.6 fields ( added 14 February 2012 ) if (rc) rc = binary_archive.WriteInt( m_idef_layer_style ); return rc; }