From ea4882ffc9d1e809e0d8955c5f90caa51305c55e Mon Sep 17 00:00:00 2001 From: Bozo The Builder Date: Fri, 9 Jun 2023 14:54:39 -0700 Subject: [PATCH] Sync changes from upstream repository Co-authored-by: Andrew Le Bihan Co-authored-by: croudyj Co-authored-by: Dale Lear Co-authored-by: Greg Arden Co-authored-by: Pierre Cuvilliers Co-authored-by: Steve Baer --- opennurbs_3dm_attributes.cpp | 14 ++-- opennurbs_3dm_attributes.h | 12 ++-- opennurbs_3dm_settings.h | 2 - opennurbs_arccurve.h | 3 - opennurbs_brep.h | 6 +- opennurbs_curveproxy.h | 1 - opennurbs_decals.cpp | 105 +++++++++++++++++----------- opennurbs_decals.h | 3 + opennurbs_internal_defines.h | 7 +- opennurbs_plane.h | 4 +- opennurbs_planesurface.cpp | 4 +- opennurbs_public_version.h | 16 ++--- opennurbs_render_content.cpp | 6 +- opennurbs_render_content.h | 6 +- opennurbs_statics.cpp | 10 +++ opennurbs_subd.cpp | 2 - opennurbs_subd.h | 8 +++ opennurbs_sun.cpp | 130 +++++++++++++++++++++++++++++------ opennurbs_sun.h | 6 ++ opennurbs_texture.h | 2 + opennurbs_xml.cpp | 11 +++ opennurbs_xml.h | 12 ++++ 22 files changed, 267 insertions(+), 103 deletions(-) diff --git a/opennurbs_3dm_attributes.cpp b/opennurbs_3dm_attributes.cpp index 3fb2942c..f9aa9384 100644 --- a/opennurbs_3dm_attributes.cpp +++ b/opennurbs_3dm_attributes.cpp @@ -2529,22 +2529,20 @@ ON_Decal* ON_3dmObjectAttributes::AddDecal(void) return m_private->m_decals.AddDecal(); } -bool ON_3dmObjectAttributes::DeleteDecal(ON_Decal& decal) +bool ON_3dmObjectAttributes::RemoveDecal(ON_Decal& decal) { if (nullptr == m_private) m_private = new ON_3dmObjectAttributesPrivate(this); - return m_private->m_decals.DeleteDecal(decal); + return m_private->m_decals.RemoveDecal(decal); } -void ON_3dmObjectAttributes::DeleteAllDecals(void) +void ON_3dmObjectAttributes::RemoveAllDecals(void) { - //if (nullptr == m_private) - // m_private = new ON_3dmObjectAttributesPrivate(this); + if (nullptr == m_private) + m_private = new ON_3dmObjectAttributesPrivate(this); - // Delete all the user data? [JOHN-DECAL-FIX] - // TODO: -// return m_private->m_decals.DeleteAllDecals(); + return m_private->m_decals.RemoveAllDecals(); } // {1403A7E4-E7AD-4a01-A2AA-41DAE6BE7ECB} diff --git a/opennurbs_3dm_attributes.h b/opennurbs_3dm_attributes.h index c86be876..d4862795 100644 --- a/opennurbs_3dm_attributes.h +++ b/opennurbs_3dm_attributes.h @@ -44,7 +44,9 @@ public: True if successful. (xform is invertable or didn't need to be). */ - ON_DEPRECATED_MSG("Prefer the version that takes a const ON_Geometry* - for object frame support.") bool Transform( const ON_Xform& xform ); + ON_DEPRECATED_MSG("Prefer the version that takes a const ON_Geometry* - for object frame support.") + bool Transform( const ON_Xform& xform ); + bool Transform(const ON_Geometry* pOriginalGeometry, const ON_Xform& xform); // attributes of geometry and dimension table objects @@ -532,15 +534,15 @@ public: /* Description: - Delete a decal from this attributes object. Returns true if successful, else false. + Remove a decal from this attributes object. Returns true if successful, else false. */ - bool DeleteDecal(ON_Decal& decal); + bool RemoveDecal(ON_Decal& decal); /* Description: - Delete all decals from this attributes object. + Remove all decals from this attributes object. */ - void DeleteAllDecals(void); + void RemoveAllDecals(void); // Mesh Modifiers. diff --git a/opennurbs_3dm_settings.h b/opennurbs_3dm_settings.h index cf0931c8..8ce73354 100644 --- a/opennurbs_3dm_settings.h +++ b/opennurbs_3dm_settings.h @@ -14,8 +14,6 @@ #if !defined(OPENNURBS_3DM_SETTINGS_INC_) #define OPENNURBS_3DM_SETTINGS_INC_ -#include "opennurbs_post_effects.h" - /////////////////////////////////////////////////////////////////////// // // units and tolerances diff --git a/opennurbs_arccurve.h b/opennurbs_arccurve.h index 3c02ab41..3481f03d 100644 --- a/opennurbs_arccurve.h +++ b/opennurbs_arccurve.h @@ -378,9 +378,6 @@ public: // The dimension of a arc curve can be 2 or 3. // (2 so ON_ArcCurve can be used as a trimming curve) int m_dim = 3; - - // TODO ON_LineCurve::GetClosestPoint( ON_Curve&...) doesn't need an override. - #pragma warning(suppress : 4266) }; diff --git a/opennurbs_brep.h b/opennurbs_brep.h index 39b9aae3..5876194e 100644 --- a/opennurbs_brep.h +++ b/opennurbs_brep.h @@ -1144,7 +1144,8 @@ public: CRhinoObject::MeshCount CRhinoObject::IsMeshable */ - ON_DEPRECATED_MSG("Support for bDeleteMesh no longer supported") void DestroyMesh( ON::mesh_type mesh_type, bool bDeleteMesh); + ON_DEPRECATED_MSG("Support for bDeleteMesh no longer supported") + void DestroyMesh( ON::mesh_type mesh_type, bool bDeleteMesh); /* Description: @@ -1827,7 +1828,8 @@ public: ON_BrepFace::Mesh ON_BrepFace::SetMesh */ - ON_DEPRECATED_MSG("bDeleteMesh=false is no longer supported") void DestroyMesh( ON::mesh_type mesh_type, bool bDeleteMesh); + ON_DEPRECATED_MSG("bDeleteMesh=false is no longer supported") + void DestroyMesh( ON::mesh_type mesh_type, bool bDeleteMesh); /* Description: diff --git a/opennurbs_curveproxy.h b/opennurbs_curveproxy.h index 749fdf62..61bda601 100644 --- a/opennurbs_curveproxy.h +++ b/opennurbs_curveproxy.h @@ -458,7 +458,6 @@ public: double, // curve_t double* // nurbs_t ) const override; - }; diff --git a/opennurbs_decals.cpp b/opennurbs_decals.cpp index b4360487..2d80514a 100644 --- a/opennurbs_decals.cpp +++ b/opennurbs_decals.cpp @@ -26,6 +26,11 @@ static ON_4dPoint UNSET_4D_POINT = ON_4dPoint(ON_UNSET_VALUE, ON_UNSET_VALUE, ON_UNSET_VALUE, ON_UNSET_VALUE); +ON__UINT32 ON_DecalCRCFromNode(const ON_XMLNode& node) +{ + return ON_Decal::ComputeDecalCRC(0, node); +} + class ON_Decal::CImpl : public ON_InternalXMLImpl { public: @@ -966,40 +971,92 @@ ON__UINT32 ON_Decal::ComputeDecalCRC(ON__UINT32 crc, const ON_XMLNode& node) // ON_DecalCollection::~ON_DecalCollection() { - DeleteAllDecals(); + ClearDecalArray(); } -int ON_DecalCollection::FindDecalIndex(const ON_Decal& decal) const +int ON_DecalCollection::FindDecalIndex(const ON_UUID& id) const { for (int i = 0; i < m_decals.Count(); i++) { - if (decal.Id() == m_decals[i]->Id()) + if (m_decals[i]->Id() == id) return i; } return -1; } -bool ON_DecalCollection::DeleteDecal(ON_Decal& decal) +ON_Decal* ON_DecalCollection::AddDecal(void) +{ + // Ensure the array is populated before adding a new decal. + GetDecalArray(); + + ON_Decal* decal = nullptr; + + ON_XMLNode* decals_node = m_root_node.CreateNodeAtPath(ON_RDK_UD_ROOT ON_XML_SLASH ON_RDK_DECALS); + if (nullptr != decals_node) + { + // Add an XML node for the new decal. + auto* decal_node = new ON_XMLNode(ON_RDK_DECAL); + decals_node->AttachChildNode(decal_node); + + // Add the new decal. It stores a pointer to the new XML node. This is safe because + // the decals have the same lifetime as the root node that owns the XML nodes. + decal = new ON_Decal(*this, *decal_node); + m_decals.Append(decal); + + SetChanged(); + } + + return decal; +} + +bool ON_DecalCollection::RemoveDecal(const ON_Decal& decal) { // Ensure the array is populated before deleting a decal. GetDecalArray(); - const int index = FindDecalIndex(decal); + // Remove the decal from the XML by finding the XML node with the same decal CRC + // and then deleting that node. + const ON__UINT32 decal_crc = decal.DecalCRC(); + + const wchar_t* path = ON_RDK_UD_ROOT ON_XML_SLASH ON_RDK_DECALS; + ON_XMLNode* decals_node = m_root_node.GetNodeAtPath(path); + if (nullptr != decals_node) + { + auto it = decals_node->GetChildIterator(); + ON_XMLNode* child_node = nullptr; + while (nullptr != (child_node = it.GetNextChild())) + { + if (ON_DecalCRCFromNode(*child_node) == decal_crc) + { + child_node->Remove(); + break; + } + } + } + + // Find the decal in the array. + const int index = FindDecalIndex(decal.Id()); if (index < 0) return false; + // Delete it. delete m_decals[index]; m_decals.Remove(index); return true; } -void ON_DecalCollection::DeleteAllDecals(void) +void ON_DecalCollection::RemoveAllDecals(void) { m_root_node.Clear(); m_root_node.CreateNodeAtPath(ON_RDK_UD_ROOT); + ClearDecalArray(); +} + +void ON_DecalCollection::ClearDecalArray(void) +{ for (int i = 0; i < m_decals.Count(); i++) { delete m_decals[i]; @@ -1007,14 +1064,14 @@ void ON_DecalCollection::DeleteAllDecals(void) m_decals.Destroy(); - m_populated = true; + m_populated = false; SetChanged(); } const ON_DecalCollection& ON_DecalCollection::operator = (const ON_DecalCollection& dc) { - DeleteAllDecals(); + ClearDecalArray(); for (int i = 0; i < dc.m_decals.Count(); i++) { @@ -1065,43 +1122,13 @@ void ON_DecalCollection::Populate(void) const void ON_DecalCollection::SetChanged(void) { - ON_ASSERT(m_populated); - - if (m_populated) - m_changed = true; -} - -ON_Decal* ON_DecalCollection::AddDecal(void) -{ - // Ensure the array is populated before adding a new decal. - GetDecalArray(); - - ON_Decal* decal = nullptr; - - ON_XMLNode* decals_node = m_root_node.CreateNodeAtPath(ON_RDK_UD_ROOT ON_XML_SLASH ON_RDK_DECALS); - if (nullptr != decals_node) - { - // Add an XML node for the new decal. - auto* decal_node = new ON_XMLNode(ON_RDK_DECAL); - decals_node->AttachChildNode(decal_node); - - // Add the new decal. It stores a pointer to the new XML node. This is safe because - // the decals have the same lifetime as the root node that owns the XML nodes. - decal = new ON_Decal(*this, *decal_node); - m_decals.Append(decal); - - SetChanged(); - } - - return decal; + m_changed = true; } void ON_DecalCollection::UpdateUserData(unsigned int archive_3dm_version) const { if (m_changed) { - ON_ASSERT(m_populated); - SetRDKObjectInformation(*m_attr, m_root_node.String(), archive_3dm_version); m_changed = false; diff --git a/opennurbs_decals.h b/opennurbs_decals.h index 30af54a4..ca6d5c5e 100644 --- a/opennurbs_decals.h +++ b/opennurbs_decals.h @@ -174,4 +174,7 @@ private: CImpl* _impl; }; +// For internal use only. +ON__UINT32 ON_DECL ON_DecalCRCFromNode(const ON_XMLNode& node); + #endif diff --git a/opennurbs_internal_defines.h b/opennurbs_internal_defines.h index e58bb168..7925d7c5 100644 --- a/opennurbs_internal_defines.h +++ b/opennurbs_internal_defines.h @@ -109,8 +109,9 @@ public: const ON_DecalCollection& operator = (const ON_DecalCollection& dc); ON_Decal* AddDecal(void); - bool DeleteDecal(ON_Decal& decal); - void DeleteAllDecals(void); + bool RemoveDecal(const ON_Decal&); + void RemoveAllDecals(void); + void ClearDecalArray(void); const ON_SimpleArray& GetDecalArray(void) const; void SetChanged(void); @@ -119,7 +120,7 @@ public: private: void Populate(void) const; - int FindDecalIndex(const ON_Decal&) const; + int FindDecalIndex(const ON_UUID& id) const; private: ON_3dmObjectAttributes* m_attr; diff --git a/opennurbs_plane.h b/opennurbs_plane.h index 480ad73c..6b71c251 100644 --- a/opennurbs_plane.h +++ b/opennurbs_plane.h @@ -656,7 +656,7 @@ public: bool DepthEnabled() const; void SetDepthEnabled(bool on); - // Default is true + // Default is false bool ParticipationListsEnabled() const; void SetParticipationListsEnabled(bool on); @@ -674,7 +674,7 @@ public: private: bool m_depth_enabled = false; - bool m_participation_lists_enabled = true; + bool m_participation_lists_enabled = false; char m_reserved; ON_ClippingPlaneDataStore m_data_store; diff --git a/opennurbs_planesurface.cpp b/opennurbs_planesurface.cpp index 4ceb0ab5..4a0a632c 100644 --- a/opennurbs_planesurface.cpp +++ b/opennurbs_planesurface.cpp @@ -1133,7 +1133,7 @@ void ON_ClippingPlane::Default() m_plane_id = ON_nil_uuid; m_bEnabled = true; m_depth_enabled = false; - m_participation_lists_enabled = true; + m_participation_lists_enabled = false; DeleteClippingPlaneData(m_data_store); } @@ -1541,7 +1541,7 @@ bool ON_ClippingPlane::Write( ON_BinaryArchive& file ) const rc = file.WriteBool(data->m_is_exclusion_list); if (!rc) break; } - if (!m_participation_lists_enabled) + if (m_participation_lists_enabled) { unsigned char c = ON_ClippingPlaneTypeCodes::ClipParticipationEnabled; // 13 rc = file.WriteChar(c); diff --git a/opennurbs_public_version.h b/opennurbs_public_version.h index 8a7f5109..fd7a38f6 100644 --- a/opennurbs_public_version.h +++ b/opennurbs_public_version.h @@ -14,10 +14,10 @@ // first step in each build. // #define RMA_VERSION_YEAR 2023 -#define RMA_VERSION_MONTH 5 -#define RMA_VERSION_DATE 26 -#define RMA_VERSION_HOUR 13 -#define RMA_VERSION_MINUTE 4 +#define RMA_VERSION_MONTH 6 +#define RMA_VERSION_DATE 9 +#define RMA_VERSION_HOUR 14 +#define RMA_VERSION_MINUTE 36 //////////////////////////////////////////////////////////////// // @@ -35,8 +35,8 @@ // 3 = build system release build #define RMA_VERSION_BRANCH 0 -#define VERSION_WITH_COMMAS 8,0,23146,13040 -#define VERSION_WITH_PERIODS 8.0.23146.13040 +#define VERSION_WITH_COMMAS 8,0,23160,14360 +#define VERSION_WITH_PERIODS 8.0.23160.14360 #define COPYRIGHT "Copyright (C) 1993-2023, Robert McNeel & Associates. All Rights Reserved." #define SPECIAL_BUILD_DESCRIPTION "Public OpenNURBS C++ 3dm file IO library." @@ -47,8 +47,8 @@ #define RMA_VERSION_NUMBER_SR_STRING "SR0" #define RMA_VERSION_NUMBER_SR_WSTRING L"SR0" -#define RMA_VERSION_WITH_PERIODS_STRING "8.0.23146.13040" -#define RMA_VERSION_WITH_PERIODS_WSTRING L"8.0.23146.13040" +#define RMA_VERSION_WITH_PERIODS_STRING "8.0.23160.14360" +#define RMA_VERSION_WITH_PERIODS_WSTRING L"8.0.23160.14360" diff --git a/opennurbs_render_content.cpp b/opennurbs_render_content.cpp index 2c9560bc..0757ea4b 100644 --- a/opennurbs_render_content.cpp +++ b/opennurbs_render_content.cpp @@ -1177,7 +1177,7 @@ ON_XMLVariant ParamHelper(const ON_XMLParameters& p, const wchar_t* name) return value; } -ON_Material ON_RenderMaterial::SimulatedMaterial(void) const +ON_Material ON_RenderMaterial::ToOnMaterial(void) const { std::lock_guard lg(m_impl->m_mutex); @@ -1322,7 +1322,7 @@ const ON_RenderEnvironment& ON_RenderEnvironment::operator = (const ON_RenderEnv return *this; } -ON_Environment ON_RenderEnvironment::SimulatedEnvironment(void) const +ON_Environment ON_RenderEnvironment::ToOnEnvironment(void) const { std::lock_guard lg(m_impl->m_mutex); @@ -1387,7 +1387,7 @@ const ON_RenderTexture& ON_RenderTexture::operator = (const ON_RenderTexture& te return *this; } -ON_Texture ON_RenderTexture::SimulatedTexture(void) const +ON_Texture ON_RenderTexture::ToOnTexture(void) const { std::lock_guard lg(m_impl->m_mutex); diff --git a/opennurbs_render_content.h b/opennurbs_render_content.h index 4be300c0..a146d09b 100644 --- a/opennurbs_render_content.h +++ b/opennurbs_render_content.h @@ -254,7 +254,7 @@ public: virtual const ON_RenderContent& operator = (const ON_RenderContent&) override; virtual const ON_RenderMaterial& operator = (const ON_RenderMaterial&); - virtual ON_Material SimulatedMaterial(void) const; + virtual ON_Material ToOnMaterial(void) const; }; class ON_CLASS ON_RenderEnvironment : public ON_RenderContent @@ -269,7 +269,7 @@ public: virtual const ON_RenderContent& operator = (const ON_RenderContent&) override; virtual const ON_RenderEnvironment& operator = (const ON_RenderEnvironment&); - virtual ON_Environment SimulatedEnvironment(void) const; + virtual ON_Environment ToOnEnvironment(void) const; }; class ON_CLASS ON_RenderTexture : public ON_RenderContent @@ -284,7 +284,7 @@ public: virtual const ON_RenderContent& operator = (const ON_RenderContent&) override; virtual const ON_RenderTexture& operator = (const ON_RenderTexture&); - virtual ON_Texture SimulatedTexture(void) const; + virtual ON_Texture ToOnTexture(void) const; }; #endif diff --git a/opennurbs_statics.cpp b/opennurbs_statics.cpp index 20e6b955..f6bfbd50 100644 --- a/opennurbs_statics.cpp +++ b/opennurbs_statics.cpp @@ -2925,9 +2925,19 @@ static ON_SubDFromMeshParameters Internal_ConvexCornersAndInteriorCreases() return cp; } +static ON_SubDFromMeshParameters Internal_ConvexAndConcaveCornersAndInteriorCreases() +{ + ON_SubDFromMeshParameters cp; + cp.SetInteriorCreaseOption(ON_SubDFromMeshParameters::InteriorCreaseOption::AtMeshDoubleEdge); + cp.SetConvexCornerOption(ON_SubDFromMeshParameters::ConvexCornerOption::AtMeshCorner); + cp.SetConcaveCornerOption(ON_SubDFromMeshParameters::ConcaveCornerOption::AtMeshCorner); + return cp; +} + const ON_SubDFromMeshParameters ON_SubDFromMeshParameters::Smooth; const ON_SubDFromMeshParameters ON_SubDFromMeshParameters::InteriorCreases = Internal_InteriorCreases(); const ON_SubDFromMeshParameters ON_SubDFromMeshParameters::ConvexCornersAndInteriorCreases = Internal_ConvexCornersAndInteriorCreases(); +const ON_SubDFromMeshParameters ON_SubDFromMeshParameters::ConvexAndConcaveCornersAndInteriorCreases = Internal_ConvexAndConcaveCornersAndInteriorCreases(); const ON_SubDFromSurfaceParameters ON_SubDFromSurfaceParameters::Default; diff --git a/opennurbs_subd.cpp b/opennurbs_subd.cpp index fafba475..90300c7c 100644 --- a/opennurbs_subd.cpp +++ b/opennurbs_subd.cpp @@ -19045,8 +19045,6 @@ void ON_SubDVertexQuadSector::Internal_CopyFrom(const ON_SubDVertexQuadSector& s if ( ON_SubDVertexTag::Corner == center_vertex_tag) this->m_sector_coefficient = src.m_sector_coefficient; - const unsigned subdivision_level = src.SubdivisionLevel(); - const unsigned vertex_count = src.SectorVertexCount(); for (unsigned vi = 0; vi < vertex_count; ++vi) { diff --git a/opennurbs_subd.h b/opennurbs_subd.h index 1ad09d3f..5658cd2a 100644 --- a/opennurbs_subd.h +++ b/opennurbs_subd.h @@ -16946,10 +16946,18 @@ public: // Create an interior sub-D crease along all input mesh double edges. static const ON_SubDFromMeshParameters InteriorCreases; + // Create an interior sub-D crease along all input mesh double edges. // Look for convex corners at sub-D vertices with 2 edges // that have an included angle <= 90 degrees. static const ON_SubDFromMeshParameters ConvexCornersAndInteriorCreases; + // Create an interior sub-D crease along all input mesh double edges. + // Look for convex corners at sub-D vertices with 2 edges + // that have an included angle <= 90 degrees. + // Look for concave corners at sub-D vertices with 3 edges + // that have an included angle >= 270 degrees. + static const ON_SubDFromMeshParameters ConvexAndConcaveCornersAndInteriorCreases; + /////////////////////////////////////////////////////////////////////////////////////// // // Custom interior crease options diff --git a/opennurbs_sun.cpp b/opennurbs_sun.cpp index b82ea0d6..5527b076 100644 --- a/opennurbs_sun.cpp +++ b/opennurbs_sun.cpp @@ -586,7 +586,7 @@ public: void SetIntensity(double d); double ShadowIntensity(void) const; void SetShadowIntensity(double d); - bool IsUsingManualControl(void) const { return ManualControlAllowed() && ManualControlOn(); } + bool IsUsingManualControl(void) const; private: void UpdateAziAlt(void) const; @@ -600,6 +600,14 @@ public: ON_SunEngine::Accuracy _accuracy = ON_SunEngine::Accuracy::Minimum; }; +bool ON_Sun::CImpl::IsUsingManualControl(void) const +{ + // If manual control has been set on even if it's not 'allowed', consider it on anyway. + // This makes it easier for clients that set manual control on without knowing they are supposed + // to also allow it. I'm not even sure why it wouldn't be allowed nowadays. TODO: Ask Andy. + return ManualControlOn(); +} + void ON_Sun::CImpl::GetEarthAnchorPlane(ON_3dVector& anchor_north, ON_Plane& plane) const { ON_3dVector anchor_east = _earth_anchor_point->ModelEast(); @@ -677,16 +685,20 @@ void ON_Sun::CImpl::UpdateAziAlt(void) const } } -bool ON_Sun::CImpl::EnableAllowed(void) - const { return GetParameter(XMLPath_Sun(), ON_RDK_SUN_ENABLE_ALLOWED, false); } +bool ON_Sun::CImpl::EnableAllowed(void) const +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_ENABLE_ALLOWED, false); +} void ON_Sun::CImpl::SetEnableAllowed(bool allowed) { SetParameter(XMLPath_Sun(), ON_RDK_SUN_ENABLE_ALLOWED, allowed); } -bool ON_Sun::CImpl::EnableOn(void) - const { return GetParameter(XMLPath_Sun(), ON_RDK_SUN_ENABLE_ON, false); } +bool ON_Sun::CImpl::EnableOn(void) const +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_ENABLE_ON, false); +} void ON_Sun::CImpl::SetEnableOn(bool on) { @@ -694,15 +706,19 @@ void ON_Sun::CImpl::SetEnableOn(bool on) } bool ON_Sun::CImpl::ManualControlAllowed(void) const - { return GetParameter(XMLPath_Sun(), ON_RDK_SUN_MANUAL_CONTROL_ALLOWED, false); } +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_MANUAL_CONTROL_ALLOWED, false); +} void ON_Sun::CImpl::SetManualControlAllowed(bool allowed) { SetParameter(XMLPath_Sun(), ON_RDK_SUN_MANUAL_CONTROL_ALLOWED, allowed); } -bool ON_Sun::CImpl::ManualControlOn(void) - const { return GetParameter(XMLPath_Sun(), ON_RDK_SUN_MANUAL_CONTROL_ON, false); } +bool ON_Sun::CImpl::ManualControlOn(void) const +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_MANUAL_CONTROL_ON, false); +} void ON_Sun::CImpl::SetManualControlOn(bool manual) { @@ -739,8 +755,10 @@ void ON_Sun::CImpl::SetAltitude(double altitude) SetParameter(XMLPath_Sun(), ON_RDK_SUN_ALTITUDE, altitude); } -double ON_Sun::CImpl::TimeZone(void) - const { return GetParameter(XMLPath_Sun(), ON_RDK_SUN_OBSERVER_TIMEZONE, 0.0); } +double ON_Sun::CImpl::TimeZone(void) const +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_OBSERVER_TIMEZONE, 0.0); +} void ON_Sun::CImpl::SetTimeZone(double hours) { @@ -748,8 +766,10 @@ void ON_Sun::CImpl::SetTimeZone(double hours) _calc_dirty = true; } -bool ON_Sun::CImpl::DaylightSavingOn(void) - const { return GetParameter(XMLPath_Sun(), ON_RDK_SUN_DAYLIGHT_SAVING_ON, false); } +bool ON_Sun::CImpl::DaylightSavingOn(void) const +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_DAYLIGHT_SAVING_ON, false); +} void ON_Sun::CImpl::SetDaylightSavingOn(bool on) { @@ -758,7 +778,9 @@ void ON_Sun::CImpl::SetDaylightSavingOn(bool on) } int ON_Sun::CImpl::DaylightSavingMinutes(void) const -{ return GetParameter(XMLPath_Sun(), ON_RDK_SUN_DAYLIGHT_SAVING_MINUTES, 0); } +{ + return GetParameter(XMLPath_Sun(), ON_RDK_SUN_DAYLIGHT_SAVING_MINUTES, 0); +} void ON_Sun::CImpl::SetDaylightSavingMinutes(int minutes) { @@ -1001,7 +1023,7 @@ const ON_Sun& ON_Sun::operator = (const ON_Sun& sun) bool ON_Sun::operator == (const ON_Sun& sun) const { // When checking equality, we need to directly check the underlying storage. So we can't allow - // virtual overrides to execute because they might hide the real values we want to copy. + // virtual overrides to execute because they might hide the real values we want to check. if (ON_Sun::EnableAllowed() != sun.ON_Sun::EnableAllowed()) return false; if (ON_Sun::EnableOn() != sun.ON_Sun::EnableOn()) return false; @@ -1021,16 +1043,13 @@ bool ON_Sun::operator == (const ON_Sun& sun) const ON_Sun::LocalDateTime(y1, m1, d1, h1); sun.ON_Sun::LocalDateTime(y2, m2, d2, h2); - if ((y1 != y2) || (m1 != m2) || (d1 != d2)) - return false; - - if (!IsDoubleEqual(h1, h2)) + if ((y1 != y2) || (m1 != m2) || (d1 != d2) || !IsDoubleEqual(h1, h2)) return false; if (_impl->IsUsingManualControl()) { - if (!IsDoubleEqual(ON_Sun::Azimuth() , sun.ON_Sun::Azimuth())) return false; - if (!IsDoubleEqual(ON_Sun::Altitude() , sun.ON_Sun::Altitude())) return false; + if (!IsDoubleEqual(ON_Sun::Azimuth() , sun.ON_Sun::Azimuth())) return false; + if (!IsDoubleEqual(ON_Sun::Altitude(), sun.ON_Sun::Altitude())) return false; } return true; @@ -1474,3 +1493,74 @@ void ON_Sun::OnInternalXmlChanged(const ON_Sun* sun) SetLongitude(sun->Longitude()); } } + +static const int SunVersion = 1; + +bool ON_Sun::WriteToArchive(ON_BinaryArchive& archive) const +{ + if (!archive.WriteInt(SunVersion)) + return false; + + ON_XMLRootNode root; + SaveToXMLNode(root); + + auto length_wide = root.WriteToStream(nullptr, 0); + if (length_wide <= 0) + return false; + + ON_wString sXML; + sXML.ReserveArray(size_t(length_wide + 1)); + length_wide = root.WriteToStream(sXML.Array(), length_wide); + if (length_wide <= 0) + return false; + + const auto* wsz = static_cast(sXML); + + const auto length_utf8 = ON_ConvertWideCharToUTF8(false, wsz, -1, nullptr, 0, nullptr, 0, 0, nullptr); + auto utf8 = std::unique_ptr(new char[length_utf8]); + auto* pUTF8 = utf8.get(); + ON_ConvertWideCharToUTF8(false, wsz, -1, pUTF8, length_utf8, nullptr, 0, 0, nullptr); + + // Write the length of the UTF8 buffer to the archive. + if (!archive.WriteInt(length_utf8)) + return false; + + // Write the UTF8 buffer to the archive. + if (!archive.WriteChar(length_utf8, pUTF8)) + return false; + + return true; +} + +bool ON_Sun::ReadFromArchive(ON_BinaryArchive& archive) +{ + int version = 0; + if (!archive.ReadInt(&version)) + return false; + + if (SunVersion != version) + return false; + + int length_utf8 = 0; + if (!archive.ReadInt(&length_utf8)) + return false; + + auto utf8 = std::unique_ptr(new char[size_t(length_utf8)+1]); + auto* pUTF8 = utf8.get(); + + if (!archive.ReadChar(length_utf8, pUTF8)) + return false; + + pUTF8[length_utf8] = 0; // Terminator. + + const auto length_wide = ON_ConvertUTF8ToWideChar(false, pUTF8, -1, nullptr, 0, nullptr, 0, 0, nullptr); + auto wide = std::unique_ptr(new wchar_t[length_wide + 1]); + auto* pWide = wide.get(); + ON_ConvertUTF8ToWideChar(false, pUTF8, -1, pWide, length_wide + 1, nullptr, 0, 0, nullptr); + + ON_XMLRootNode root; + root.ReadFromStream(pWide); + LoadFromXMLNode(root); + + return true; +} diff --git a/opennurbs_sun.h b/opennurbs_sun.h index 411af2d6..38f45b73 100644 --- a/opennurbs_sun.h +++ b/opennurbs_sun.h @@ -251,6 +251,12 @@ public: // Save the sun properties to a 'sun' XML node. virtual void SaveToXMLNode(ON_XMLNode& node) const; + // Write the sun properties to an archive. + virtual bool WriteToArchive(ON_BinaryArchive& archive) const; + + // Read the sun properties from an archive that was created by WriteToArchive(). + virtual bool ReadFromArchive(ON_BinaryArchive& archive); + // Emergency virtual function for future expansion. virtual void* EVF(const wchar_t* func, void* data); diff --git a/opennurbs_texture.h b/opennurbs_texture.h index 21778d60..aa427716 100644 --- a/opennurbs_texture.h +++ b/opennurbs_texture.h @@ -337,6 +337,8 @@ public: pbr_displacement_texture = 28U, pbr_clearcoat_bump_texture = 29U, pbr_alpha_texture = 30U, + pbr_opacity_texture = 3U, + pbr_bump_texture = 2U, // emap_texture is OBSOLETE - set m_mapping_channel_id = ON_MappingChannel::emap_mapping emap_texture = 86U // spherical environment mapping. diff --git a/opennurbs_xml.cpp b/opennurbs_xml.cpp index 634f24a2..aa1edde6 100644 --- a/opennurbs_xml.cpp +++ b/opennurbs_xml.cpp @@ -5374,4 +5374,15 @@ void* ON_RdkDocumentDefaults::EVF(const wchar_t*, void*) return nullptr; } +ON_XMLParamBlock::ON_XMLParamBlock() + : + _reserved(0), + ON_XMLParameters(_node) +{ +} + +ON_XMLParamBlock::~ON_XMLParamBlock() +{ +} + #pragma ON_PRAGMA_WARNING_POP diff --git a/opennurbs_xml.h b/opennurbs_xml.h index 9129f5fe..cec2f4e6 100644 --- a/opennurbs_xml.h +++ b/opennurbs_xml.h @@ -847,6 +847,18 @@ protected: virtual ON_XMLNode* FindNodeByNameProperty(const wchar_t* param_name) const; }; +// Class ON_XMLParamBlock is ON_XMLParameters with a built-in XML node. +class ON_CLASS ON_XMLParamBlock : public ON_XMLParameters +{ +public: + ON_XMLParamBlock(); + virtual ~ON_XMLParamBlock(); + +private: + ON_XMLRootNode _node; + ON__UINT64 _reserved; +}; + ON_DECL bool ON_RunXMLTests(const wchar_t* test_folder); ////////////////////////////////////////////////////////////////////////////////////////////