mirror of
https://github.com/mcneel/opennurbs.git
synced 2026-04-19 04:36:09 +08:00
Sync changes from upstream repository
Co-authored-by: Steve Baer <steve@mcneel.com> Co-authored-by: Nathan Letwory <nathan@mcneel.com> Co-authored-by: Dale Lear <dalelear@mcneel.com>
This commit is contained in:
committed by
Will Pearson
parent
b844466e88
commit
799431a63b
@@ -4943,4 +4943,194 @@ int ON_Viewport::InViewFrustum(
|
||||
return cr.InViewFrustum(count,p);
|
||||
}
|
||||
|
||||
class ON_CLASS ON_ViewportUserData : public ON_UserData
|
||||
{
|
||||
ON_OBJECT_DECLARE(ON_ViewportUserData);
|
||||
|
||||
public:
|
||||
ON_ViewportUserData();
|
||||
~ON_ViewportUserData() = default;
|
||||
ON_ViewportUserData(const ON_ViewportUserData& src);
|
||||
ON_ViewportUserData& operator=(const ON_ViewportUserData& src);
|
||||
|
||||
static ON_ViewportUserData* FromObject(const ON_Object* obj);
|
||||
static ON_ViewportUserData* FromObject(ON_Object* obj, bool createAndAttachIfMissing);
|
||||
|
||||
// override virtual ON_UserData::GetDescription function
|
||||
bool GetDescription(ON_wString& description) override;
|
||||
|
||||
// override virtual ON_Object::SizeOf function
|
||||
unsigned int SizeOf() const override;
|
||||
|
||||
// override virtual ON_Object::DataCRC function
|
||||
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
|
||||
|
||||
// override virtual ON_Object::Dump function
|
||||
void Dump(ON_TextLog& text_log) const override;
|
||||
|
||||
// override virtual ON_UserData::Archive function
|
||||
bool WriteToArchive(
|
||||
const class ON_BinaryArchive& archive,
|
||||
const class ON_Object* parent_object
|
||||
) const override;
|
||||
|
||||
// override virtual ON_Object::Write function
|
||||
bool Write(ON_BinaryArchive& binary_archive) const override;
|
||||
|
||||
// override virtual ON_Object::Read function
|
||||
bool Read(ON_BinaryArchive& binary_archive) override;
|
||||
|
||||
public:
|
||||
// The description, or contents, of the viewport.
|
||||
ON_wString m_description;
|
||||
};
|
||||
|
||||
ON_OBJECT_IMPLEMENT(ON_ViewportUserData, ON_UserData, "DA2B97F8-5B76-4C50-8504-9A7CFC8AD62C");
|
||||
|
||||
ON_ViewportUserData::ON_ViewportUserData()
|
||||
{
|
||||
m_userdata_uuid = ON_CLASS_ID(ON_ViewportUserData);
|
||||
m_application_uuid = ON_opennurbs6_id;
|
||||
m_userdata_copycount = 1;
|
||||
}
|
||||
|
||||
ON_ViewportUserData::ON_ViewportUserData(const ON_ViewportUserData& src)
|
||||
: ON_UserData(src)
|
||||
, m_description(src.m_description)
|
||||
{
|
||||
m_userdata_uuid = ON_CLASS_ID(ON_ViewportUserData);
|
||||
m_application_uuid = ON_opennurbs6_id;
|
||||
m_userdata_copycount = 1;
|
||||
}
|
||||
|
||||
ON_ViewportUserData& ON_ViewportUserData::operator=(const ON_ViewportUserData& src)
|
||||
{
|
||||
if (this != &src)
|
||||
{
|
||||
ON_UserData::operator=(src);
|
||||
m_description = src.m_description;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ON_ViewportUserData* ON_ViewportUserData::FromObject(const ON_Object* obj)
|
||||
{
|
||||
if (nullptr == obj)
|
||||
return nullptr;
|
||||
return ON_ViewportUserData::Cast(obj->GetUserData(ON_CLASS_ID(ON_ViewportUserData)));
|
||||
}
|
||||
|
||||
ON_ViewportUserData* ON_ViewportUserData::FromObject(ON_Object* obj, bool createAndAttachIfMissing)
|
||||
{
|
||||
if (nullptr == obj)
|
||||
return nullptr;
|
||||
ON_ViewportUserData* rc = ON_ViewportUserData::Cast(obj->GetUserData(ON_CLASS_ID(ON_ViewportUserData)));
|
||||
if (nullptr == rc && createAndAttachIfMissing)
|
||||
{
|
||||
rc = new ON_ViewportUserData();
|
||||
if (!obj->AttachUserData(rc))
|
||||
{
|
||||
delete rc;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool ON_ViewportUserData::GetDescription(ON_wString& description)
|
||||
{
|
||||
description = L"Viewport UserData";
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int ON_ViewportUserData::SizeOf() const
|
||||
{
|
||||
unsigned int sz = ON_UserData::SizeOf();
|
||||
sz += sizeof(*this) - sizeof(ON_UserData);
|
||||
sz += m_description.SizeOf();
|
||||
return sz;
|
||||
}
|
||||
|
||||
ON__UINT32 ON_ViewportUserData::DataCRC(ON__UINT32 current_remainder) const
|
||||
{
|
||||
current_remainder = m_description.DataCRC(current_remainder);
|
||||
return current_remainder;
|
||||
}
|
||||
|
||||
void ON_ViewportUserData::Dump(ON_TextLog& text_log) const
|
||||
{
|
||||
const wchar_t* pszDescription = static_cast<const wchar_t*>(m_description);
|
||||
if (nullptr == pszDescription)
|
||||
pszDescription = L"";
|
||||
text_log.Print("Description = \"%ls\"\n", pszDescription);
|
||||
}
|
||||
|
||||
bool ON_ViewportUserData::WriteToArchive(const ON_BinaryArchive & archive, const ON_Object * parent_object) const
|
||||
{
|
||||
return (archive.Archive3dmVersion() >= 60);
|
||||
}
|
||||
|
||||
bool ON_ViewportUserData::Write(ON_BinaryArchive& archive) const
|
||||
{
|
||||
bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK, 1, 0);
|
||||
if (!rc)
|
||||
return false;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// 1.0 fields
|
||||
rc = archive.WriteString(m_description);
|
||||
if (!rc) break;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!archive.EndWrite3dmChunk())
|
||||
rc = false;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool ON_ViewportUserData::Read(ON_BinaryArchive& archive)
|
||||
{
|
||||
int major_version = 0;
|
||||
int minor_version = 0;
|
||||
bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK, &major_version, &minor_version);
|
||||
if (!rc)
|
||||
return false;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
rc = (1 == major_version);
|
||||
if (!rc) break;
|
||||
|
||||
// 1.0 fields
|
||||
rc = archive.ReadString(m_description);
|
||||
if (!rc) break;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!archive.EndRead3dmChunk())
|
||||
rc = false;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
ON_wString ON_Viewport::Description() const
|
||||
{
|
||||
ON_wString rc;
|
||||
ON_ViewportUserData* data = ON_ViewportUserData::FromObject(this);
|
||||
if (data)
|
||||
rc = data->m_description;
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool ON_Viewport::SetDescription(const wchar_t* description)
|
||||
{
|
||||
ON_ViewportUserData* data = ON_ViewportUserData::FromObject(this, true);
|
||||
if (nullptr == data)
|
||||
return false;
|
||||
data->m_description = description;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user