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
117 changes: 58 additions & 59 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,46 @@ 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
);

const unsigned int file_ymd
= bHaveFileDate
? ((file_year * 100 + file_month) * 100 + file_date)
: 0;

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(
ON::Version(),
&app_major_version,
0,
&app_year,
&app_month,
&app_date,
0
);
if (bSupressPartiallyReadChunkWarning)
{
// The calling code expects there to be a partially read chunk.
break;
}

const unsigned int app_ymd
= bHaveAppDate
? ((app_year * 100 + app_month) * 100 + app_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;
}

if (file_major_version <= app_major_version
&& file_ymd <= app_ymd
)
// m_3dm_opennurbs_version = version of opennurbs that wrote this 3dm file.
// ON::Version() = this version of opennurbs.
if (ON_VersionNumberCompare(m_3dm_opennurbs_version, ON::Version(), 2) <= 0)
{
// 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.");
}
// We are reading a file that was 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.
// Either there is a bug in the reading or writing of the chunk or new informaton was
// added at the end of a chunk and the opennurbs major version or YYMMDD was not
// correctly set.
// In rare cases, somebody did something more seriously wrong and likely harder to figure out.
//
// In any case, issue a warning and continue reading. This is not a fatal problem but
// it indicates information is being lost.
ON_WARNING("ON_BinaryArchive::EndRead3dmChunk: partially read chunk - skipping bytes at end of current chunk.");
}

break;
}
}

Expand Down Expand Up @@ -18424,12 +18423,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