Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions opennurbs_3dm_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2525,15 +2525,36 @@ ON_MeshModifiers& ON_3dmObjectAttributes::MeshModifiers(void) const
return m_private->m_mesh_modifiers;
}

const ON_SimpleArray<ON_Decal*>& ON_3dmObjectAttributes::GetDecalArray(void) const
const ON_SimpleArray<ON_Decal*>& ON_3dmObjectAttributes::GetDecalArray(void) const // Deprecated.
{
std::vector<std::shared_ptr<ON_Decal>> decals;
GetDecalArray(decals);

static ON_SimpleArray<ON_Decal*> dummy;
dummy.Destroy();

for (const auto& decal_sp : decals)
{
dummy.Append(decal_sp.get());
}

return dummy;
}

void ON_3dmObjectAttributes::GetDecalArray(std::vector<std::shared_ptr<ON_Decal>>& array_out) const
{
if (nullptr == m_private)
m_private = new ON_3dmObjectAttributesPrivate(this);

return m_private->m_decals.GetDecalArray();
array_out = m_private->m_decals.GetDecalArray();
}

ON_Decal* ON_3dmObjectAttributes::AddDecal(void) // Deprecated.
{
return AddDecalEx().get();
}

ON_Decal* ON_3dmObjectAttributes::AddDecal(void)
const std::shared_ptr<ON_Decal> ON_3dmObjectAttributes::AddDecalEx(void)
{
if (nullptr == m_private)
m_private = new ON_3dmObjectAttributesPrivate(this);
Expand Down
13 changes: 10 additions & 3 deletions opennurbs_3dm_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,26 @@ class ON_CLASS ON_3dmObjectAttributes : public ON_Object

// Decals.

// This method is deprecated in favor of the one below.
ON_DEPRECATED const ON_SimpleArray<ON_Decal*>& GetDecalArray(void) const;

/*
Description:
Get an array of decals that are stored on this attributes object.
Do not store or delete pointers from the array.
Param array_out is first cleared and then filled with shared pointers to decals (if any).
Do not store or delete raw pointers from the array.
*/
const ON_SimpleArray<ON_Decal*>& GetDecalArray(void) const;
void GetDecalArray(std::vector<std::shared_ptr<ON_Decal>>& array_out) const;

// This method is deprecated in favor of AddDecalEx().
ON_DEPRECATED ON_Decal* AddDecal(void);

/*
Description:
Add a new decal to this attributes object. The returned pointer points to an object
that is owned by the attributes. Do not store or delete it.
*/
ON_Decal* AddDecal(void);
const std::shared_ptr<ON_Decal> AddDecalEx(void);

/*
Description:
Expand Down
164 changes: 106 additions & 58 deletions opennurbs_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4620,6 +4620,24 @@ ON_BinaryArchive::WriteObject( const ON_Object& model_object )
return Internal_WriteObject(V2_text_dot);
}
break;

case ON::object_type::subd_object:
{
if (m_3dm_version >= 60)
break;
const ON_SubD* subd = ON_SubD::Cast(&model_object);
if (nullptr == subd)
break;

// Use a SubD mesh proxy for V5 and earlier file formats.
std::unique_ptr<ON_Mesh> mesh(ON_SubDMeshProxyUserData::MeshProxyFromSubD(subd));
if (nullptr == mesh)
return false;

return Internal_WriteObject(*mesh.get());
}
break;

default:
break;
}
Expand Down Expand Up @@ -6578,65 +6596,95 @@ bool ON_BinaryArchive::EndRead3dmChunk(bool bSupressPartiallyReadChunkWarning)
{
// partially read chunk - happens when chunks are skipped or old code
// reads a new minor version of a chunk whnich has added information.
if ( file_offset != c->m_start_offset )
if ( file_offset != c->m_start_offset)
{
if ( m_3dm_version != 1 || (m_error_message_mask&0x02) == 0 )
for (;;)
{
// when reading v1 files, there are some situations where
// it is reasonable to attempt to read 4 bytes at the end
// of a file. The above test prevents making a call
// to ON_WARNING() in these situations.

unsigned int file_year = 0;
unsigned int file_month = 0;
unsigned int file_date = 0;
unsigned int file_major_version = 0;
const bool bHaveFileDate = ON_VersionNumberParse(
m_3dm_opennurbs_version,
&file_major_version,
0,
&file_year,
&file_month,
&file_date,
0
);
if (bSupressPartiallyReadChunkWarning)
{
// The calling code expects there to be a partially read chunk.
break;
}

const unsigned int file_ymd
= bHaveFileDate
? ((file_year * 100 + file_month) * 100 + file_date)
: 0;
// The calling code had no reason to supress warnings about this chunk
// being partially read.
const bool bIsV1EndOfFile = this->Archive3dmVersion() == 1 && 0 != (m_error_message_mask & 0x02);
if (bIsV1EndOfFile)
{
// when reading v1 files, there are some situations where
// it is reasonable to attempt to read 4 bytes at the end
// of a file. The above test prevents making a call
// to ON_WARNING() in these situations.
break;
}

unsigned int app_year = 0;
unsigned int app_month = 0;
unsigned int app_date = 0;
unsigned int app_major_version = 0;
const bool bHaveAppDate = ON_VersionNumberParse(
// m_3dm_opennurbs_version = version of opennurbs that wrote this 3dm file
// "onver" is short for opennurbs version
unsigned int file_writer_onver_year = 0;
unsigned int file_writer_onver_month = 0;
unsigned int file_writer_onver_date = 0;
unsigned int file_writer_onver_major_version = 0;
const bool bHaveFileONVer = ON_VersionNumberParse(
m_3dm_opennurbs_version,
&file_writer_onver_major_version,
nullptr,
&file_writer_onver_year,
&file_writer_onver_month,
&file_writer_onver_date,
nullptr
);

if (false == bHaveFileONVer)
break; // weird for sure, but we can't compare nothing to something

const unsigned int file_writer_version_ymd
= ((file_writer_onver_year * 100 + file_writer_onver_month) * 100 + file_writer_onver_date);

// ON::Version = version of this instance of opennurbs
unsigned int this_onver_year = 0;
unsigned int this_onver_month = 0;
unsigned int this_onver_date = 0;
unsigned int this_onver_major_version = 0;
const bool bHaveThisONVer = ON_VersionNumberParse(
ON::Version(),
&app_major_version,
0,
&app_year,
&app_month,
&app_date,
0
);

const unsigned int app_ymd
= bHaveAppDate
? ((app_year * 100 + app_month) * 100 + app_date)
: 0;

if (file_major_version <= app_major_version
&& file_ymd <= app_ymd
)
&this_onver_major_version,
nullptr,
&this_onver_year,
&this_onver_month,
&this_onver_date,
nullptr
);

if (false == bHaveThisONVer)
break; // weird for sure, but we can't compare nothing to something

const unsigned int this_onver_ymd
= ((this_onver_year * 100 + this_onver_month) * 100 + this_onver_date);

const bool bOldCodeReadingNewFile
= this_onver_major_version < file_writer_onver_major_version
|| (this_onver_major_version == file_writer_onver_major_version && this_onver_ymd < file_writer_version_ymd)
;
if (bOldCodeReadingNewFile)
{
// We are reading a file written by this version or an
// earlier version of opennurbs.
// There should not be any partially read chunks.
if (!bSupressPartiallyReadChunkWarning)
{
ON_WARNING("ON_BinaryArchive::EndRead3dmChunk: partially read chunk - skipping bytes at end of current chunk.");
}
// The code that wrote this file is newer than the code that is reading this file.
// For example, SaveAs V7 in Rhino 8 will use v8 code to write a v7 file and Rhino 7 might be reading the file.
//
// Or a newer version of Rhino N wrote the file and a user with an older version of Rhino N
// is reading the file.
//
// In these two cases, the new code may have added new saved new information at the end of
// this chunk that was not saved by the older version.
break;
}

// We are reading a file written by this version or an earlier version of opennurbs.
// This chunk should have been completely read. Typically, this is a bug that can
// be fixed after carefully studying why it occured.
// Issue a warning and continue reading.
ON_WARNING("ON_BinaryArchive::EndRead3dmChunk: partially read chunk - skipping bytes at end of current chunk.");

break;
}
}

Expand Down Expand Up @@ -18424,12 +18472,12 @@ const void* ON_Read3dmBufferArchive::Buffer() const
return (const void*)m_buffer;
}

ON_Write3dmBufferArchive::ON_Write3dmBufferArchive(
size_t initial_sizeof_buffer,
size_t max_sizeof_buffer,
int archive_3dm_version,
unsigned int archive_opennurbs_version
)
ON_Write3dmBufferArchive::ON_Write3dmBufferArchive(
size_t initial_sizeof_buffer,
size_t max_sizeof_buffer,
int archive_3dm_version,
unsigned int archive_opennurbs_version
)
: ON_BinaryArchive(ON::archive_mode::write3dm)
, m_p(0)
, m_buffer(0)
Expand Down
4 changes: 0 additions & 4 deletions opennurbs_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,6 @@ ON_UuidPtr* ON_UuidPtrList::SearchHelper(const ON_UUID* uuid) const
return p;
}

// static_assert(sizeof(ON_UuidPairList) == sizeof(ON_UuidPairList2), "ON_UuidPairList and ON_UuidPairList2 are not the same size");
// static_assert(sizeof(ON_UuidPtrList) == sizeof(ON_UuidPtrList2), "ON_UuidPtrList and ON_UuidPtrList2 are not the same size");
// static_assert(sizeof(ON_UuidIndexList) == sizeof(ON_UuidIndexList2), "ON_UuidIndexList and ON_UuidIndexList2 are not the same size");

template <typename T>
struct ON_UuidList2_Private
{
Expand Down
Loading