diff --git a/opennurbs.h b/opennurbs.h index 89a5aaa5..37d356a6 100644 --- a/opennurbs.h +++ b/opennurbs.h @@ -163,19 +163,19 @@ #include "opennurbs_photogrammetry.h" #include "opennurbs_xml.h" // XML classes. -#include "opennurbs_current_environment.h" // RDK Current Environment support. -#include "opennurbs_dithering.h" // RDK Dithering support. -#include "opennurbs_embedded_file.h" // RDK Embedded file support. -#include "opennurbs_ground_plane.h" // RDK Ground Plane support. -#include "opennurbs_linear_workflow.h" // RDK Linear Workflow support. -#include "opennurbs_render_content.h" // RDK Render content support. -#include "opennurbs_render_channels.h" // RDK Render channels support. -#include "opennurbs_safe_frame.h" // RDK Safe Frame support. -#include "opennurbs_skylight.h" // RDK Skylight support. -#include "opennurbs_sun.h" // RDK Sun support. -#include "opennurbs_post_effects.h" // RDK Post Effect support. -#include "opennurbs_decals.h" // RDK Decal support. -#include "opennurbs_mesh_modifiers.h" // RDK Mesh Modifiers support. +#include "opennurbs_current_environment.h" // Current Environment support. +#include "opennurbs_dithering.h" // Dithering support. +#include "opennurbs_embedded_file.h" // Embedded file support. +#include "opennurbs_ground_plane.h" // Ground Plane support. +#include "opennurbs_linear_workflow.h" // Linear Workflow support. +#include "opennurbs_render_content.h" // Render content support. +#include "opennurbs_render_channels.h" // Render channels support. +#include "opennurbs_safe_frame.h" // Safe Frame support. +#include "opennurbs_skylight.h" // Skylight support. +#include "opennurbs_sun.h" // Sun support. +#include "opennurbs_post_effects.h" // Post Effect support. +#include "opennurbs_decals.h" // Decal support. +#include "opennurbs_mesh_modifiers.h" // Mesh Modifiers support. #include "opennurbs_extensions.h" #include "opennurbs_freetype.h" diff --git a/opennurbs_3dm_settings.cpp b/opennurbs_3dm_settings.cpp index d0e88bd3..4947f2d9 100644 --- a/opennurbs_3dm_settings.cpp +++ b/opennurbs_3dm_settings.cpp @@ -699,23 +699,93 @@ double ON_3dmUnitsAndTolerances::Scale( ON::LengthUnitSystem us ) const return ON::UnitScale( us, m_unit_system ); } - -bool ON_3dmUnitsAndTolerances::TolerancesAreValid() const +bool ON_3dmUnitsAndTolerances::IsValid() const { - for(;;) + for (;;) { - if ( !(m_absolute_tolerance > 0.0) ) + if (!(m_distance_display_precision >= 0 && m_distance_display_precision <= 7)) break; - if ( !(m_angle_tolerance > 0.0 && m_angle_tolerance <= ON_PI) ) + if (!((int)m_distance_display_mode >= 0 && (int)m_distance_display_mode <= 3)) break; - if ( !( m_relative_tolerance > 0.0 && m_relative_tolerance < 1.0) ) + if (!TolerancesAreValid()) break; return true; } + return false; +} +double ON_3dmUnitsAndTolerances::AbsoluteTolerance() const +{ + return m_absolute_tolerance; +} + +void ON_3dmUnitsAndTolerances::SetAbsoluteTolerance(double absolute_tolerance) +{ + if (absolute_tolerance > 0.0) + m_absolute_tolerance = absolute_tolerance; +} + +double ON_3dmUnitsAndTolerances::AngleTolerance() const +{ + return m_angle_tolerance; +} + +void ON_3dmUnitsAndTolerances::SetAngleTolerance(double angle_tolerance) +{ + if (angle_tolerance > 0.0 && angle_tolerance <= ON_PI) + m_angle_tolerance = angle_tolerance; +} + +double ON_3dmUnitsAndTolerances::RelativeTolerance() const +{ + return m_relative_tolerance; +} + +void ON_3dmUnitsAndTolerances::SetRelativeTolerance(double relative_tolerance) +{ + if (relative_tolerance > 0.0 && relative_tolerance < 1.0) + m_relative_tolerance = relative_tolerance; +} + +ON::OBSOLETE_DistanceDisplayMode ON_3dmUnitsAndTolerances::DistanceDisplayMode() const +{ + return m_distance_display_mode; +} + +void ON_3dmUnitsAndTolerances::SetDistanceDisplayMode(ON::OBSOLETE_DistanceDisplayMode distance_display_mode) +{ + m_distance_display_mode = distance_display_mode; +} + +int ON_3dmUnitsAndTolerances::DistanceDisplayPrecision() const +{ + return m_distance_display_precision; +} + +void ON_3dmUnitsAndTolerances::SetDistanceDisplayPrecision(int distance_display_precision) +{ + if (distance_display_precision >= 0 && distance_display_precision <= 7) + m_distance_display_precision = distance_display_precision; +} + +bool ON_3dmUnitsAndTolerances::TolerancesAreValid() const +{ + for (;;) + { + if (!(m_absolute_tolerance > 0.0)) + break; + + if (!(m_angle_tolerance > 0.0 && m_angle_tolerance <= ON_PI)) + break; + + if (!(m_relative_tolerance > 0.0 && m_relative_tolerance < 1.0)) + break; + + return true; + } return false; } diff --git a/opennurbs_3dm_settings.h b/opennurbs_3dm_settings.h index a4994e0d..e27e8984 100644 --- a/opennurbs_3dm_settings.h +++ b/opennurbs_3dm_settings.h @@ -38,11 +38,29 @@ public: void Dump( ON_TextLog& ) const; - /* - Returns: - True if tolerances (m_absolute_tolerance, m_angle_tolerance, m_relative_tolerance) - are set to valid values. - */ + bool IsValid() const; + + // Gets and sets the absolute tolerance in units, > 0.0 + double AbsoluteTolerance() const; + void SetAbsoluteTolerance(double absolute_tolerance); + + // Gets and sets the angle tolerance in radians, > 0.0 and <= ON_PI + double AngleTolerance() const; + void SetAngleTolerance(double angle_tolerance); + + // Gets and sets the relative tolerance, fraction > 0.0 and < 1.0 + double RelativeTolerance() const; + void SetRelativeTolerance(double relative_tolerance); + + // Gets and sets the distance display mode + ON::OBSOLETE_DistanceDisplayMode DistanceDisplayMode() const; + void SetDistanceDisplayMode(ON::OBSOLETE_DistanceDisplayMode distance_display_mode); + + // Gets and sets the distance display precision, >= 0 and <= 7 + int DistanceDisplayPrecision() const; + void SetDistanceDisplayPrecision(int distance_display_precision); + + // Returns true if absolute, angle, and relative tolerances values are valid. bool TolerancesAreValid() const; /* @@ -55,16 +73,15 @@ public: to ON_3dmUnitsAndTolerances::DefaultValue.m_relative_tolerance. Returns: 0: all tolerances were valid - 0 != (rc & 1): + 0 != (rc & 1): m_absolute_tolerance was invalid and set to the default value - 0 != (rc & 2): + 0 != (rc & 2): m_angle_tolerance was invalid and set to the default value - 0 != (rc & 4): + 0 != (rc & 4): m_relative_tolerance was invalid and set to the default value */ unsigned int SetInvalidTolerancesToDefaultValues(); - ////////// // Returns scale factor that needs to be applied to change from // the argument's unit system to m_unit_system. // When m_unit_system is not ON::LengthUnitSystem::CustomUnits, @@ -73,16 +90,14 @@ public: // Scale(us) = ON::UnitScale(us,ON::LengthUnitSystem::Meters)*m_custom_unit_scale. double Scale( ON::LengthUnitSystem ) const; + // Expert access to member variables ON_UnitSystem m_unit_system = ON_UnitSystem::Millimeters; - - double m_absolute_tolerance = 0.001; // in units > 0.0 - double m_angle_tolerance = ON_PI/180.0; // in radians > 0.0 and <= ON_PI - double m_relative_tolerance = 0.01; // fraction > 0.0 and < 1.0 - + double m_absolute_tolerance = 0.001; // in units > 0.0 + double m_angle_tolerance = ON_PI/180.0; // in radians > 0.0 and <= ON_PI + double m_relative_tolerance = 0.01; // fraction > 0.0 and < 1.0 ON::OBSOLETE_DistanceDisplayMode m_distance_display_mode = ON::OBSOLETE_DistanceDisplayMode::Decimal; // decimal or fractional - int m_distance_display_precision = 3; // decimal mode: number of decimal places - // fractional modes: - // denominator = (1/2)^m_distance_display_precision + int m_distance_display_precision = 3; // decimal mode: number of decimal places + // fractional modes: denominator = (1/2)^m_distance_display_precision public: /* diff --git a/opennurbs_bounding_box.cpp b/opennurbs_bounding_box.cpp index 5a90cba7..6d943e6e 100644 --- a/opennurbs_bounding_box.cpp +++ b/opennurbs_bounding_box.cpp @@ -172,27 +172,24 @@ bool ON_BoundingBox::GetEdges( ON_Line edges[12] ) const { - int i; ON_Line line; - int edge_count = 0; - if ( IsValid() ) + bool rc = IsValid(); + if (rc) { - for ( i = 0; i < 3; i++ ) + for (unsigned i = 0U; i < 12; i++ ) { - - + edges[i] = Edge(i); } } - - if ( 12 != edge_count ) + else { edges[0].from = ON_3dPoint::UnsetPoint; edges[0].to = ON_3dPoint::UnsetPoint; - for ( i = 1; i < 12; i++ ) + for (unsigned i = 1U; i < 12; i++ ) edges[i] = edges[0]; } - return (12 == edge_count); + return rc; } diff --git a/opennurbs_curve.cpp b/opennurbs_curve.cpp index ad063d90..0c17ebd8 100644 --- a/opennurbs_curve.cpp +++ b/opennurbs_curve.cpp @@ -1868,7 +1868,7 @@ bool ON_NurbsCurve::RepairBadKnots( double knot_tolerance, bool bRepair ) if ( m_order >= 2 && m_cv_count > m_order && 0 != m_cv && 0 != m_knot && m_dim > 0 - && m_cv_stride >= (m_is_rat)?(m_dim+1):m_dim + && (m_cv_stride >= m_is_rat ? m_dim + 1 : m_dim) && m_knot[m_cv_count-1] - m_knot[m_order-2] > knot_tolerance ) { diff --git a/opennurbs_decals.cpp b/opennurbs_decals.cpp index 4fa4de76..ce31d8d8 100644 --- a/opennurbs_decals.cpp +++ b/opennurbs_decals.cpp @@ -209,6 +209,7 @@ void ON_Decal::SetMapping(Mappings m) case ON_Decal::Mappings::Planar: s = ON_RDK_UD_DECAL_MAPPING_PLANAR; break; case ON_Decal::Mappings::Spherical: s = ON_RDK_UD_DECAL_MAPPING_SPHERICAL; break; case ON_Decal::Mappings::Cylindrical: s = ON_RDK_UD_DECAL_MAPPING_CYLINDRICAL; break; + case ON_Decal::Mappings::None: break; } m_impl->SetParameter(XMLPath(), ON_RDK_UD_DECAL_MAPPING, s); @@ -238,6 +239,7 @@ void ON_Decal::SetProjection(Projections p) case ON_Decal::Projections::Forward: s = ON_RDK_UD_DECAL_PROJECTION_FORWARD; break; case ON_Decal::Projections::Backward: s = ON_RDK_UD_DECAL_PROJECTION_BACKWARD; break; case ON_Decal::Projections::Both: s = ON_RDK_UD_DECAL_PROJECTION_BOTH; break; + case ON_Decal::Projections::None: break; } m_impl->SetParameter(XMLPath(), ON_RDK_UD_DECAL_PROJECTION, s); @@ -373,7 +375,7 @@ ON_DecalCollection::~ON_DecalCollection() } } -void ON_DecalCollection::CreateDecalsFromXML(const ONX_Model& model) +void ON_DecalCollection::CreateDecalsFromXML(const ONX_Model& model, int archive_3dm_version) { ONX_ModelComponentIterator cit(model, ON_ModelComponent::Type::ModelGeometry); const auto* component = cit.FirstComponent(); @@ -385,7 +387,7 @@ void ON_DecalCollection::CreateDecalsFromXML(const ONX_Model& model) // Get the entire XML off of the attributes user data. ON_wString xml; - ONX_Model::GetRDKObjectInformation(*attr, xml); + GetRDKObjectInformation(*attr, xml, archive_3dm_version); if (xml.IsEmpty()) continue; // No XML found on the component's attributes. @@ -401,7 +403,7 @@ void ON_DecalCollection::CreateDecalsFromXML(const ONX_Model& model) } } -void ON_DecalCollection::CreateXMLFromDecals(const ONX_Model& model) +void ON_DecalCollection::CreateXMLFromDecals(const ONX_Model& model, int archive_3dm_version) { for (int i = 0; i < m_items.Count(); i++) { @@ -422,7 +424,7 @@ void ON_DecalCollection::CreateXMLFromDecals(const ONX_Model& model) ON_XMLRootNode root; ON_wString xml; - ONX_Model::GetRDKObjectInformation(*attr, xml); + GetRDKObjectInformation(*attr, xml, archive_3dm_version); if (xml.IsNotEmpty()) { if (ON_XMLNode::ReadError == root.ReadFromStream(xml)) @@ -447,7 +449,7 @@ void ON_DecalCollection::CreateXMLFromDecals(const ONX_Model& model) new_decals_node->ReadFromStream(decals_xml); // Set the item's XML to the attributes user data. - SetRDKObjectInformation(*attr, root.String()); + SetRDKObjectInformation(*attr, root.String(), archive_3dm_version); } } } @@ -472,6 +474,19 @@ ON_DecalCollection::Item* ON_DecalCollection::FindItem(const ON_UUID& component_ return nullptr; } +ON_DecalCollection::Item* ON_DecalCollection::ItemAt(int index) const +{ + if ((index < 0) || (index >= m_items.Count())) + return nullptr; + + return m_items[index]; +} + +int ON_DecalCollection::ItemCount(void) const +{ + return m_items.Count(); +} + ON_Decal* ON_DecalCollection::AddDecal(const ON_ModelComponent& component) { ON_XMLNode decals_node(ON_RDK_UD_DECALS); @@ -614,14 +629,27 @@ ON_Decal* ON_DecalCollection::Item::GetDecal(const ON_UUID& id) const class ON_DecalIterator::CImpl { public: - CImpl(ONX_Model& model, const ON_ModelComponent& component) + CImpl(ONX_Model& model) : m_model(model) { } + virtual ~CImpl() { } + + virtual ON_Decal* Next(void) = 0; + +protected: + ONX_Model& m_model; + int m_decal_index = -1; +}; + +class CImpl_PerComponent : public ON_DecalIterator::CImpl +{ +public: + CImpl_PerComponent(ONX_Model& model, const ON_ModelComponent& component) : - m_model(model) + CImpl(model) { m_component_id = component.Id(); } - ON_Decal* Next(void) + virtual ON_Decal* Next(void) override { if (nullptr == m_item) { @@ -638,15 +666,58 @@ public: } public: - ONX_Model& m_model; ON_UUID m_component_id; - int m_decal_index = -1; ON_DecalCollection::Item* m_item = nullptr; }; -ON_DecalIterator::ON_DecalIterator(ONX_Model& model, const ON_ModelComponent& component) +class CImpl_All : public ON_DecalIterator::CImpl { - m_impl = new CImpl(model, component); +public: + CImpl_All(ONX_Model& model) : CImpl(model) { } + + virtual ON_Decal* Next(void) override + { + if (!m_populated) + { + const auto& collection = GetDecalCollection(m_model); + + for (int i = 0; i < collection.ItemCount(); i++) + { + const auto* item = collection.ItemAt(i); + + int d = 0; + ON_Decal* decal = nullptr; + while (nullptr != (decal = item->GetDecal(d++))) + { + m_decals.Append(decal); + } + } + + m_decal_index = 0; + m_populated = true; + } + + if (m_decal_index >= m_decals.Count()) + return nullptr; + + return m_decals[m_decal_index++]; + } + +private: + ON_SimpleArray m_decals; + bool m_populated = false; +}; + +ON_DecalIterator::ON_DecalIterator(ONX_Model& model, const ON_ModelComponent* component) +{ + if (nullptr != component) + { + m_impl = new CImpl_PerComponent(model, *component); + } + else + { + m_impl = new CImpl_All(model); + } } ON_DecalIterator::~ON_DecalIterator() diff --git a/opennurbs_decals.h b/opennurbs_decals.h index e27e3932..823b734f 100644 --- a/opennurbs_decals.h +++ b/opennurbs_decals.h @@ -147,15 +147,16 @@ private: class ON_CLASS ON_DecalIterator final { public: - ON_DecalIterator(class ONX_Model& model, const ON_ModelComponent& component); + ON_DecalIterator(class ONX_Model& model, const ON_ModelComponent* component); ~ON_DecalIterator(); // Returns a pointer to the next decal or null if there are no more. The returned pointer // points to an object inside the ONX_Model. You should not store this pointer. ON_Decal* Next(void) const; -private: class CImpl; + +private: CImpl* m_impl; }; diff --git a/opennurbs_defines.h b/opennurbs_defines.h index ec8d1046..f1bd665f 100644 --- a/opennurbs_defines.h +++ b/opennurbs_defines.h @@ -2926,22 +2926,6 @@ public: public: ON_COMPONENT_INDEX m_ci = ON_COMPONENT_INDEX::UnsetComponentIndex; double m_x = ON_DBL_QNAN; -}; - -enum class RhRdkChangeContext : int // Context of a change to document or content parameters. -{ - Unset = -1, // Value when BeginChange() has not been called. - UI = 0, // Change occurred as a result of user activity in the UI. - Drop = 1, // Change occurred as a result of drag and drop. - Program = 2, // Change occurred as a result of internal program activity. - Ignore = 3, // Change can be disregarded. - Tree = 4, // Change occurred within the content tree (e.g., nodes reordered). - Undo = 5, // Change occurred as a result of an undo or redo operation. - Reserved = 6, // Reserved for RDK internal use only [SDK_UNFREEZE] - Serialize = 7, // Change occurred during serialization (loading). - RealTimeUI = 8, // Change occurred as a result of 'real-time' user activity in the (content) UI. - // The content's preview, UI, group members and registerable properties are not updated. - Script = 9, // Change occurred as a result of executing a script. }; #endif diff --git a/opennurbs_dimension.cpp b/opennurbs_dimension.cpp index a703eb3a..f8881304 100644 --- a/opennurbs_dimension.cpp +++ b/opennurbs_dimension.cpp @@ -5507,6 +5507,8 @@ double ON_DimOrdinate::Measurement() const case MeasuredDirection::Yaxis: m = m_def_pt.y; break; + case MeasuredDirection::Unset: + break; } if (DistanceScale() != 1.0) m *= DistanceScale(); diff --git a/opennurbs_embedded_file.cpp b/opennurbs_embedded_file.cpp index 7a15644a..e2a3acd4 100644 --- a/opennurbs_embedded_file.cpp +++ b/opennurbs_embedded_file.cpp @@ -114,6 +114,9 @@ bool ON_EmbeddedFile::CImpl::LoadFile(const wchar_t* filename) bool ON_EmbeddedFile::CImpl::SaveFile(const wchar_t* filename) const { + if (0 == m_data.m_length) + return false; // Not loaded. + // Open the file for writing. auto* pFile = ON_FileStream::Open(filename, L"wb"); if (nullptr == pFile) diff --git a/opennurbs_extensions.cpp b/opennurbs_extensions.cpp index cb67b477..9c04aa4d 100644 --- a/opennurbs_extensions.cpp +++ b/opennurbs_extensions.cpp @@ -302,16 +302,16 @@ public: using EmbeddedFileMap = std::unordered_map; - bool GetRDKDocumentXML(ON_wString& xml, bool embedded_files) const; - ONX_Model_UserData* GetRDKDocumentUserData(void) const; + bool GetRDKDocumentXML(ON_wString& xml, bool embedded_files, int archive_3dm_version) const; + ONX_Model_UserData* GetRDKDocumentUserData(int archive_3dm_version) const; void PopulateDefaultRDKDocumentXML(ON_XMLRootNode& root) const; - bool PopulateRDKComponents(void); - bool UpdateRDKUserData(void); + bool PopulateRDKComponents(int archive_3dm_version); + bool UpdateRDKUserData(int archive_3dm_version); bool CreateRenderContentFromXML(class ON_XMLNode& model_node, RenderContentKinds kind); bool CreatePostEffectsFromXML(ON_XMLNode& model_node, ON_PostEffect::Types type); bool CreateXMLFromRenderContent(ON_XMLNode& model_node, RenderContentKinds kind) const; bool CreateXMLFromPostEffects(ON_XMLNode& model_node, ON_PostEffect::Types type) const; - bool SetRDKDocumentInformation(const wchar_t* xml, ONX_Model_UserData& docud) const; + bool SetRDKDocumentInformation(const wchar_t* xml, ONX_Model_UserData& docud, int archive_3dm_version) const; ON_XMLNode* GetRenderContentSectionNode(ON_XMLNode& model_node, RenderContentKinds kind) const; ON_XMLNode* GetPostEffectSectionNode(ON_XMLNode& model_node, ON_PostEffect::Types type) const; static void RemoveAllEmbeddedFiles(ONX_Model& model); @@ -2986,7 +2986,8 @@ bool ONX_Model::Read(ON_BinaryArchive& archive, unsigned int table_filter, return false; // Having read the model data, populate the RDK components. - m_extension->PopulateRDKComponents(); + const auto archive_3dm_version = archive.Archive3dmVersion(); + m_extension->PopulateRDKComponents(archive_3dm_version); return true; } @@ -3039,7 +3040,7 @@ bool ONX_Model::Write(const wchar_t* filename, int version, ON_TextLog* error_lo bool ONX_Model::Write(ON_BinaryArchive& archive, int version, ON_TextLog* error_log) const { - m_extension->UpdateRDKUserData(); + m_extension->UpdateRDKUserData(version); if ( 0 != version ) { @@ -4874,7 +4875,7 @@ ONX_Model::Extension::~Extension() { } -ONX_Model_UserData* ONX_Model::Extension::GetRDKDocumentUserData(void) const +ONX_Model_UserData* ONX_Model::Extension::GetRDKDocumentUserData(int archive_3dm_version) const { // Try to find existing RDK document user data. for (int i = 0; i < m_model.m_userdata_table.Count(); i++) @@ -4882,7 +4883,7 @@ ONX_Model_UserData* ONX_Model::Extension::GetRDKDocumentUserData(void) const auto* pUserData = m_model.m_userdata_table[i]; if (nullptr != pUserData) { - if (ONX_Model::IsRDKDocumentInformation(*pUserData)) + if (::IsRDKDocumentInformation(*pUserData)) return pUserData; // Found it. } } @@ -4891,12 +4892,12 @@ ONX_Model_UserData* ONX_Model::Extension::GetRDKDocumentUserData(void) const auto* ud = new ONX_Model_UserData; ud->m_goo.m_typecode = TCODE_USER_RECORD; ud->m_uuid = RdkPlugInId(); - ud->m_usertable_3dm_version = ON_BinaryArchive::CurrentArchiveVersion(); + ud->m_usertable_3dm_version = archive_3dm_version; ud->m_usertable_opennurbs_version = ON::Version(); ON_XMLRootNode root; PopulateDefaultRDKDocumentXML(root); - SetRDKDocumentInformation(root.String(), *ud); + SetRDKDocumentInformation(root.String(), *ud, archive_3dm_version); m_model.m_userdata_table.Append(ud); @@ -4911,12 +4912,12 @@ void ONX_Model::Extension::PopulateDefaultRDKDocumentXML(ON_XMLRootNode& root) c GetRenderContentSectionNode(root, RenderContentKinds::Texture); } -bool ONX_Model::Extension::GetRDKDocumentXML(ON_wString& xml, bool embedded_files) const +bool ONX_Model::Extension::GetRDKDocumentXML(ON_wString& xml, bool embedded_files, int archive_3dm_version) const { // Gets the entire RDK document XML as a string in 'xml'. If 'embedded_files' is true, // ON_EmbeddedFile objects are created for each embedded file. - const auto* pUserData = GetRDKDocumentUserData(); + const auto* pUserData = GetRDKDocumentUserData(archive_3dm_version); if (nullptr != pUserData) { auto* model = embedded_files ? &m_model : nullptr; @@ -5064,12 +5065,12 @@ bool ONX_Model::Extension::CreateXMLFromPostEffects(ON_XMLNode& doc_root_node, O return true; } -bool ONX_Model::Extension::PopulateRDKComponents(void) +bool ONX_Model::Extension::PopulateRDKComponents(int archive_3dm_version) { // Get the entire RDK document XML. This includes not only render contents // but also Sun, GroundPlane and other RDK document data. Ignore embedded files. ON_wString xml; - if (!GetRDKDocumentXML(xml, true)) + if (!GetRDKDocumentXML(xml, true, archive_3dm_version)) return false; // Read the entire XML into m_doc_node. @@ -5088,16 +5089,19 @@ bool ONX_Model::Extension::PopulateRDKComponents(void) CreatePostEffectsFromXML(m_doc_node, ON_PostEffect::Types::Late); // Create the decal collection. - m_decal_collection.CreateDecalsFromXML(m_model); + m_decal_collection.CreateDecalsFromXML(m_model, archive_3dm_version); // Create the mesh modifiers. - m_mesh_modifier_collection.CreateMeshModifiersFromXML(m_model); + m_mesh_modifier_collection.CreateMeshModifiersFromXML(m_model, archive_3dm_version); return true; } -bool ONX_Model::Extension::UpdateRDKUserData(void) +bool ONX_Model::Extension::UpdateRDKUserData(int archive_3dm_version) { + if (0 == archive_3dm_version) + archive_3dm_version = ON_BinaryArchive::CurrentArchiveVersion(); + // For each kind, convert the render content hierarchy to fresh XML. CreateXMLFromRenderContent(m_doc_node, RenderContentKinds::Material); CreateXMLFromRenderContent(m_doc_node, RenderContentKinds::Environment); @@ -5109,19 +5113,20 @@ bool ONX_Model::Extension::UpdateRDKUserData(void) CreateXMLFromPostEffects(m_doc_node, ON_PostEffect::Types::Late); // Convert the decal collection to fresh XML. - m_decal_collection.CreateXMLFromDecals(m_model); + m_decal_collection.CreateXMLFromDecals(m_model, archive_3dm_version); // Convert the mesh modifier collection to fresh XML. - m_mesh_modifier_collection.CreateXMLFromMeshModifiers(m_model); + m_mesh_modifier_collection.CreateXMLFromMeshModifiers(m_model, archive_3dm_version); // Get the RDK document user data. - auto* pUserData = GetRDKDocumentUserData(); + auto* pUserData = GetRDKDocumentUserData(archive_3dm_version); if (nullptr == pUserData) return false; // Shouldn't happen because we were able to get the XML earlier. // Get the entire document XML as a string and set it to the user data. ON_wString xml = m_doc_node.String(); - SetRDKDocumentInformation(xml, *pUserData); + pUserData->m_usertable_3dm_version = archive_3dm_version; + SetRDKDocumentInformation(xml, *pUserData, archive_3dm_version); return true; } @@ -5171,7 +5176,7 @@ ON_DecalCollection& GetDecalCollection(ONX_Model& model) return model.m_extension->m_decal_collection; } -ON_DecalIterator ONX_Model::GetDecalIterator(const ON_ModelComponent& component) +ON_DecalIterator ONX_Model::GetDecalIterator(const ON_ModelComponent* component) { return ON_DecalIterator(*this, component); } @@ -5191,11 +5196,16 @@ ON_MeshModifiers* ONX_Model::GetMeshModifiers(const ON_ModelComponent& component return m_extension->m_mesh_modifier_collection.Find(component); } -bool ONX_Model::IsRDKDocumentInformation(const ONX_Model_UserData& docud) +bool IsRDKDocumentInformation(const ONX_Model_UserData& docud) { return (0 == ON_UuidCompare(RdkPlugInId(), docud.m_uuid)) && (docud.m_goo.m_value >= 4) && (nullptr != docud.m_goo.m_goo); } +bool ONX_Model::IsRDKDocumentInformation(const ONX_Model_UserData& docud) +{ + return ::IsRDKDocumentInformation(docud); +} + static size_t ArchiveLengthUpToEmbeddedFiles(size_t utf8_length) { // version utf8_length utf8_buf @@ -5208,7 +5218,12 @@ static size_t ArchiveLengthUpToEmbeddedFiles(size_t utf8_length) bool ONX_Model::GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers) { ON_SimpleArray dummy; - return GetRDKEmbeddedFiles(docud, paths, embedded_files_as_buffers, dummy); + return ::GetRDKEmbeddedFiles(docud, paths, embedded_files_as_buffers, dummy); +} + +bool ONX_Model::GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers, ON_SimpleArray& buffer_sizes) // Static. +{ + return ::GetRDKEmbeddedFiles(docud, paths, embedded_files_as_buffers, buffer_sizes); } bool ONX_Model::GetRDKDocumentInformation(const ONX_Model_UserData& docud, ON_wString& xml) // Static. @@ -5327,7 +5342,7 @@ static bool ReadEmbeddedFilePathsFromArchive(ON_Read3dmBufferArchive& archive, i bool ONX_Model::GetRDKEmbeddedFilePaths(const ONX_Model_UserData& docud, ON_ClassArray& paths) { - if (!ONX_Model::IsRDKDocumentInformation(docud)) + if (!::IsRDKDocumentInformation(docud)) return false; ON_Read3dmBufferArchive archive(docud.m_goo.m_value, docud.m_goo.m_goo, false, docud.m_usertable_3dm_version, docud.m_usertable_opennurbs_version); @@ -5339,9 +5354,9 @@ bool ONX_Model::GetRDKEmbeddedFilePaths(const ONX_Model_UserData& docud, ON_Clas return true; } -bool ONX_Model::GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers, ON_SimpleArray& buffer_sizes) +bool GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers, ON_SimpleArray& buffer_sizes) { - if (!ONX_Model::IsRDKDocumentInformation(docud)) + if (!::IsRDKDocumentInformation(docud)) return false; ON_Read3dmBufferArchive a(docud.m_goo.m_value, docud.m_goo.m_goo, false, docud.m_usertable_3dm_version, docud.m_usertable_opennurbs_version); @@ -5385,7 +5400,7 @@ bool ONX_Model::GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArr bool ONX_Model::GetRDKEmbeddedFile(const ONX_Model_UserData& docud, const wchar_t* path, ON_SimpleArray& bytes) { - if (!ONX_Model::IsRDKDocumentInformation(docud)) + if (!::IsRDKDocumentInformation(docud)) return false; ON_Read3dmBufferArchive archive(docud.m_goo.m_value, docud.m_goo.m_goo, false, docud.m_usertable_3dm_version, docud.m_usertable_opennurbs_version); @@ -5451,7 +5466,7 @@ void ONX_Model::Extension::RemoveAllEmbeddedFiles(ONX_Model& model) bool ONX_Model::Extension::GetEntireRDKDocument(const ONX_Model_UserData& docud, ON_wString& xml, ONX_Model* model) // Static. { - if (!ONX_Model::IsRDKDocumentInformation(docud)) + if (!::IsRDKDocumentInformation(docud)) return false; ON_Read3dmBufferArchive archive(docud.m_goo.m_value, docud.m_goo.m_goo, false, docud.m_usertable_3dm_version, docud.m_usertable_opennurbs_version); @@ -5533,7 +5548,7 @@ bool ONX_Model::Extension::GetEntireRDKDocument(const ONX_Model_UserData& docud, return xml.Length() > 0; } -bool ONX_Model::Extension::SetRDKDocumentInformation(const wchar_t* xml, ONX_Model_UserData& docud) const +bool ONX_Model::Extension::SetRDKDocumentInformation(const wchar_t* xml, ONX_Model_UserData& docud, int archive_3dm_version) const { ON_Write3dmBufferArchive archive(0, 0, docud.m_usertable_3dm_version, docud.m_usertable_opennurbs_version); @@ -5627,14 +5642,13 @@ static bool IsMeshModifierObjectUserData(ON_UserData& objectud) return false; } -bool ONX_Model::IsRDKObjectInformation(const ON_UserData& objectud) +bool ONX_Model::IsRDKObjectInformation(const ON_UserData& objectud) // Static. { return nullptr != RDKObjectUserDataHelper(&objectud); } -bool CreateArchiveBufferFromXML(const ON_wString& xml, ON_Buffer& buf) +bool CreateArchiveBufferFromXML(const ON_wString& xml, ON_Buffer& buf, int archive_3dm_version) { - const auto archive_3dm_version = ON_BinaryArchive::CurrentArchiveVersion(); const auto archive_opennurbs_version_number = ON::Version(); // I don't know if this is correct. ON_Write3dmBufferArchive archive(0, 0, archive_3dm_version, archive_opennurbs_version_number); @@ -5671,10 +5685,10 @@ bool CreateArchiveBufferFromXML(const ON_wString& xml, ON_Buffer& buf) return true; } -bool SetXMLToUserData(const ON_wString& xml, ON_UserData& ud) +bool SetXMLToUserData(const ON_wString& xml, ON_UserData& ud, int archive_3dm_version) { ON_Buffer buf; - if (!CreateArchiveBufferFromXML(xml, buf)) + if (!CreateArchiveBufferFromXML(xml, buf, archive_3dm_version)) return false; ON_BinaryArchiveBuffer arc(ON::archive_mode::read, &buf); @@ -5683,15 +5697,14 @@ bool SetXMLToUserData(const ON_wString& xml, ON_UserData& ud) return true; } -bool SetRDKObjectInformation(ON_Object& object, const ON_wString& xml) +bool SetRDKObjectInformation(ON_Object& object, const ON_wString& xml, int archive_3dm_version) { // Create a buffer from the XML. ON_Buffer buf; - if (!CreateArchiveBufferFromXML(xml, buf)) + if (!CreateArchiveBufferFromXML(xml, buf, archive_3dm_version)) return false; - const auto archive_3dm_version = ON_BinaryArchive::CurrentArchiveVersion(); - const auto archive_opennurbs_version = ON::Version(); + const auto archive_opennurbs_version = ON::Version(); // I don't know if this is correct. // Create an archive from the buffer. ON_BinaryArchiveBuffer archive(ON::archive_mode::read, &buf); @@ -5727,7 +5740,7 @@ bool SetRDKObjectInformation(ON_Object& object, const ON_wString& xml) return true; } -bool ONX_Model::GetRDKObjectInformation(const ON_Object& object, ON_wString& xml) // Static. +bool GetRDKObjectInformation(const ON_Object& object, ON_wString& xml, int archive_3dm_version) // Static. { xml.SetLength(0); @@ -5759,7 +5772,6 @@ bool ONX_Model::GetRDKObjectInformation(const ON_Object& object, ON_wString& xml buf.SeekFromStart(0); buf.Read(sizeof_buffer, buffer); - const auto archive_3dm_version = ON_BinaryArchive::CurrentArchiveVersion(); const auto archive_opennurbs_version_number = ON::Version(); ON_Read3dmBufferArchive archive(sizeof_buffer, buffer, false, archive_3dm_version, archive_opennurbs_version_number); @@ -5820,7 +5832,7 @@ bool ONX_Model::GetRDKObjectInformation(const ON_Object& object, ON_wString& xml return xml.Length() > 0; } -static bool GetMeshModifierUserDataXML(ON_UserData& ud, ON_wString& xml) +static bool GetMeshModifierUserDataXML(ON_UserData& ud, ON_wString& xml, int archive_3dm_version) { ON_Buffer buf; ON_BinaryArchiveBuffer arc(ON::archive_mode::write, &buf); @@ -5833,7 +5845,6 @@ static bool GetMeshModifierUserDataXML(ON_UserData& ud, ON_wString& xml) buf.SeekFromStart(0); buf.Read(sizeof_buffer, buffer); - const auto archive_3dm_version = ON_BinaryArchive::CurrentArchiveVersion(); const auto archive_opennurbs_version_number = ON::Version(); ON_Read3dmBufferArchive archive(sizeof_buffer, buffer, false, archive_3dm_version, archive_opennurbs_version_number); @@ -5894,7 +5905,13 @@ static bool GetMeshModifierUserDataXML(ON_UserData& ud, ON_wString& xml) return true; } -bool ONX_Model::GetMeshModifierObjectInformation(const ON_Object& object, ON_wString& xml) // Static. +bool ONX_Model::GetRDKObjectInformation(const ON_Object& object, ON_wString& xml) // Static. +{ + // Deprecated; only for backward compatibility. + return ::GetRDKObjectInformation(object, xml, ON_BinaryArchive::CurrentArchiveVersion()); +} + +bool GetMeshModifierObjectInformation(const ON_Object& object, ON_wString& xml, int archive_3dm_version) { xml = L""; @@ -5910,7 +5927,7 @@ bool ONX_Model::GetMeshModifierObjectInformation(const ON_Object& object, ON_wSt if (IsMeshModifierObjectUserData(*ud)) { ON_wString ud_xml; - GetMeshModifierUserDataXML(*ud, ud_xml); + GetMeshModifierUserDataXML(*ud, ud_xml, archive_3dm_version); ON_XMLRootNode root; root.ReadFromStream(ud_xml); @@ -5949,7 +5966,7 @@ static ON_UserData* GetMeshModifierUserData(ON_Object& object, const ON_UUID& uu return nullptr; // TODO: ////////////////////////////////////////////////////////// } -void SetMeshModifierObjectInformation(ON_Object& object, const ON_UUID& uuid_mm, const ON_MeshModifier& mm) +void SetMeshModifierObjectInformation(ON_Object& object, const ON_UUID& uuid_mm, const ON_MeshModifier& mm, int archive_3dm_version) { ON_XMLRootNode r1; r1.ReadFromStream(mm.XML()); // Does not include node. @@ -5960,6 +5977,6 @@ void SetMeshModifierObjectInformation(ON_Object& object, const ON_UUID& uuid_mm, auto* ud = GetMeshModifierUserData(object, uuid_mm); if (nullptr != ud) { - SetXMLToUserData(r2.String(), *ud); + SetXMLToUserData(r2.String(), *ud, archive_3dm_version); } } diff --git a/opennurbs_extensions.h b/opennurbs_extensions.h index bd0d4748..b61874fb 100644 --- a/opennurbs_extensions.h +++ b/opennurbs_extensions.h @@ -1587,38 +1587,41 @@ private: public: ///////////////////////////////////////////////////////////////////// // - // BEGIN Render Development Toolkit (RDK) information - // + // BEGIN Rendering information // - // RDK Safe Frame. + // Safe Frame. ON_SafeFrame& SafeFrame(void) const; - // RDK Ground Plane. + // Ground Plane. ON_GroundPlane& GroundPlane(void) const; - // RDK Linear Workflow. + // Linear Workflow. ON_LinearWorkflow& LinearWorkflow(void) const; - // RDK Current Environment. + // Current Environment. ON_CurrentEnvironment& CurrentEnvironment(void) const; - // RDK Skylight. + // Skylight. ON_Skylight& Skylight(void) const; - // RDK Sun. + // Sun. ON_Sun& Sun(void) const; - // RDK Dithering. + // Dithering. ON_Dithering& Dithering(void) const; - // RDK Render Channels. + // Render Channels. ON_RenderChannels& RenderChannels(void) const; - // Get RDK Decals stored on a particular component. Generally, only model components of type ModelGeometry - // have decals on them. Returns a decal iterator which allows access to the decals. If there are no - // decals on the component, the iterator will be empty and return null if Next() is called. - ON_DecalIterator GetDecalIterator(const ON_ModelComponent& component); + // - If 'component' is not null, this gets decals stored on that component. Generally, only model + // components of type ModelGeometry have decals on them. + // If there are no decals on the component, the iterator will be empty and return null if Next() is called. + // + // - If 'component' is null, then this gets all decals from all model components. + // + // Returns a decal iterator which allows access to the decals. + ON_DecalIterator GetDecalIterator(const ON_ModelComponent* component); // Adds a new decal to a particular component. // Returns a pointer to the decal if successful, or null on failure. @@ -1632,53 +1635,32 @@ public: // have mesh modifiers on them. Returns an object which provides access to the various mesh modifiers. ON_MeshModifiers* GetMeshModifiers(const ON_ModelComponent& component); - // The following functions allow the developer access to the information saved per document or per-object in the 3dm file by the - // RDK plug-in, built into Rhino. There are two parts to this information - the XML data that constitutes the information - // about materials, textures and environments in addition to some of the document settings such as sun data, skylighting - // ground plane and so on - and the embedded support files which are saved as byte-for-byte copies of the actual file data - // for the original files. Typically, these embedded files will be textures used by materials, environments or decals. - - // Call this function to determine if RDK document information has been saved in this model and can be read using the GetRDKDocumentInfomation function. - // Returns true if RDK document information is available. + ON_DEPRECATED_MSG("This function is deprecated.") static bool IsRDKDocumentInformation(const ONX_Model_UserData& docud); - // This function returns the entire XML associated with the RDK document data for this file. The XML will include details about - // materials, textures and environments as well as sun, skylighting, ground plane and so on. - // Returns true if RDK document information is available. + ON_DEPRECATED_MSG("This function is deprecated.") static bool GetRDKDocumentInformation(const ONX_Model_UserData& docud, ON_wString& rdk_xml_document_data); - // This function is deprecated in favor of the one below. ON_DEPRECATED_MSG("This function is deprecated as it did not return the buffer sizes, making it useless") static bool GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers); - // This function returns the embedded support files written with this document. The returned arrays will be empty if no support filers were saved. - // Typically, these files will be used by materials and environments. Rhino unpacks these files into a folder with the suffix "embedded_files" next to the - // 3dm file on disk. This is only supported for Version 6 files onwards. - // Returns true if embedded files were found. + ON_DEPRECATED_MSG("This function is deprecated in favor of ON_EmbeddedFile.") static bool GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers, ON_SimpleArray& buffer_sizes); - // This function returns the full paths of the embedded support files written with this document. The returned arrays will be empty if no support filers were saved. - // This function is similar to GetRDKEmbeddedFiles, but is faster and uses less memory to return only the paths. Use the paths (exactly the strings returned from - // this function) to extract the embedded files using GetRDKEmbeddedFile(). + ON_DEPRECATED_MSG("This function is deprecated in favor of ON_EmbeddedFile.") static bool GetRDKEmbeddedFilePaths(const ONX_Model_UserData& docud, ON_ClassArray& paths); - // This function extracts one embedded file from the support files written with this document. Use the exact path as returned from GetRDKEmbeddedFilePaths(). + ON_DEPRECATED_MSG("This function is deprecated in favor of ON_EmbeddedFile.") static bool GetRDKEmbeddedFile(const ONX_Model_UserData& docud, const wchar_t* path, ON_SimpleArray& bytes); - // Call this function to determine if RDK object information has saved in this model and can be read using the GetRDKObjectInformation function. - // Returns true if RDK object information is available. + ON_DEPRECATED_MSG("This function is deprecated.") static bool IsRDKObjectInformation(const ON_UserData& objectud); - // This function returns the entire RDK XML associated with the object. The XML includes details about decals. - // Returns true if RDK object information is available. + ON_DEPRECATED_MSG("This function is deprecated. Please use GetDecalIterator(), AddDecal() and GetDecal() instead.") static bool GetRDKObjectInformation(const ON_Object& object, ON_wString& xml); - // This function returns the entire mesh modifier XML associated with the object. - // Returns true if mesh modifier information is available on the object. - static bool GetMeshModifierObjectInformation(const ON_Object& object, ON_wString& xml); - // - // END Render Development Toolkit (RDK) information + // END Rendering information // ///////////////////////////////////////////////////////////////////// diff --git a/opennurbs_internal_defines.h b/opennurbs_internal_defines.h index ab86066a..cafe1099 100644 --- a/opennurbs_internal_defines.h +++ b/opennurbs_internal_defines.h @@ -60,10 +60,14 @@ const ON_3dmObjectAttributes* GetComponentAttributes(const ON_ModelComponent& co ON_RenderContent* NewRenderContentFromNode(const class ON_XMLNode& node); ON_PostEffect* NewPostEffectFromNode(ON_XMLNode& node); void SetRenderContentNodeRecursive(const ON_RenderContent& rc, ON_XMLNode& node); -bool CreateArchiveBufferFromXML(const ON_wString& xml, ON_Buffer& buf); +bool CreateArchiveBufferFromXML(const ON_wString& xml, ON_Buffer& buf, int archive_3dm_version); ON_XMLNode* FindPostEffectNodeForId(const ON_XMLNode& sectionNode, const ON_UUID& id); -bool SetRDKObjectInformation(ON_Object& object, const ON_wString& xml); -void SetMeshModifierObjectInformation(ON_Object& object, const ON_UUID& uuid_mm, const ON_MeshModifier& mm); +bool GetRDKObjectInformation(const ON_Object& object, ON_wString& xml, int archive_3dm_version); +bool SetRDKObjectInformation(ON_Object& object, const ON_wString& xml, int archive_3dm_version); +bool GetRDKEmbeddedFiles(const ONX_Model_UserData& docud, ON_ClassArray& paths, ON_SimpleArray& embedded_files_as_buffers, ON_SimpleArray& buffer_sizes); +bool GetMeshModifierObjectInformation(const ON_Object& object, ON_wString& xml, int archive_3dm_version); +void SetMeshModifierObjectInformation(ON_Object& object, const ON_UUID& uuid_mm, const ON_MeshModifier& mm, int archive_3dm_version); +bool IsRDKDocumentInformation(const ONX_Model_UserData& docud); template inline T Lerp(float t, const T& l, const T& h) { return l + T(t) * (h - l); } template inline T Lerp(double t, const T& l, const T& h) { return l + T(t) * (h - l); } @@ -128,10 +132,10 @@ public: }; // Create the decals from all model components that have decal user data. - void CreateDecalsFromXML(const ONX_Model& model); + void CreateDecalsFromXML(const ONX_Model& model, int archive_3dm_version); // Convert the decals back to XML for all model components that have decal user data. - void CreateXMLFromDecals(const ONX_Model& model); + void CreateXMLFromDecals(const ONX_Model& model, int archive_3dm_version); // Find the item index for a certain component. int FindItemIndex(const ON_UUID& component_id) const; @@ -139,6 +143,12 @@ public: // Find the item for a certain component. Item* FindItem(const ON_UUID& component_id) const; + // Get the item at an index. + Item* ItemAt(int index) const; + + // Get the number of items. + int ItemCount(void) const; + // Add a new decal to a certain component. ON_Decal* AddDecal(const ON_ModelComponent& component); @@ -185,10 +195,10 @@ public: ON_MeshModifiers* Find(const ON_ModelComponent& component); // Create the mesh modifiers from all model components that have mesh modifier user data. - bool CreateMeshModifiersFromXML(const ONX_Model& model); + bool CreateMeshModifiersFromXML(const ONX_Model& model, int archive_3dm_version); // Convert the mesh modifiers back to XML for all model components that have mesh modifier user data. - bool CreateXMLFromMeshModifiers(const ONX_Model& model); + bool CreateXMLFromMeshModifiers(const ONX_Model& model, int archive_3dm_version); private: std::unordered_map m_map; diff --git a/opennurbs_material.h b/opennurbs_material.h index 94c30176..804b84ee 100644 --- a/opennurbs_material.h +++ b/opennurbs_material.h @@ -294,7 +294,7 @@ public: static ON_UUID PhysicallyBasedUserdataId(void); private: - // The value of m_rdk_material_id idetifies an RDK (rendering development kit) + // The value of m_rdk_material_id identifies an RDK (rendering development kit) // material. Multiple materials in a Rhino model can refer to the same // RDK material id. In V5 this value is stored in user data. In V6 it is // saved in the m_rdk_material_id field. diff --git a/opennurbs_mesh.cpp b/opennurbs_mesh.cpp index 5a62439a..3faf6efa 100644 --- a/opennurbs_mesh.cpp +++ b/opennurbs_mesh.cpp @@ -11291,6 +11291,9 @@ unsigned int ON_MeshComponentRef::VertexIndex() const if ( ((unsigned int)m_mesh_ci.m_index) < m_mesh->m_V.UnsignedCount() ) vi = (unsigned int)m_mesh_ci.m_index; break; + + default: + break; } } return vi; @@ -11390,6 +11393,9 @@ unsigned int ON_MeshComponentRef::GetMeshTopologyVertexAndPoint( return (unsigned int)m_mesh_ci.m_index; } break; + + default: + break; } } } @@ -11516,6 +11522,9 @@ unsigned int ON_MeshComponentRef::GetMeshFace( } } break; + + default: + break; } } @@ -11542,6 +11551,9 @@ unsigned int ON_MeshComponentRef::MeshNgonIndex() const if ( 0 != m_mesh->Ngon(m_mesh_ci.m_index) ) ngon_index = (unsigned int)m_mesh_ci.m_index; break; + + default: + break; } } return ngon_index; @@ -11607,6 +11619,9 @@ const ON_COMPONENT_INDEX ON_MeshTopology::TopVertexComponentIndex( return ci; } break; + + default: + break; } return ON_COMPONENT_INDEX::UnsetComponentIndex; @@ -12024,6 +12039,9 @@ void ON_MappingTag::Dump( ON_TextLog& text_log ) const case ON_TextureMapping::TYPE::ocs_mapping: text_log.Print("ocs"); break; + case ON_TextureMapping::TYPE::false_colors: + text_log.Print("false colors"); + break; } text_log.Print("\n"); @@ -13733,6 +13751,9 @@ bool ON_Mesh::DeleteComponents( if (cdex >= ngon_count0) return false; break; + + default: + break; } } } @@ -13847,6 +13868,9 @@ bool ON_Mesh::DeleteComponents( } } break; + + default: + break; } } @@ -15503,6 +15527,9 @@ unsigned int ON_Mesh::DissolveOrDelete( } } break; + + default: + break; }; } diff --git a/opennurbs_mesh_modifiers.cpp b/opennurbs_mesh_modifiers.cpp index 693b0d7b..64b24ca5 100644 --- a/opennurbs_mesh_modifiers.cpp +++ b/opennurbs_mesh_modifiers.cpp @@ -1356,7 +1356,7 @@ ON_MeshModifiers* ON_MeshModifierCollection::Find(const ON_ModelComponent& compo return nullptr; } -bool ON_MeshModifierCollection::CreateMeshModifiersFromXML(const ONX_Model& model) +bool ON_MeshModifierCollection::CreateMeshModifiersFromXML(const ONX_Model& model, int archive_3dm_version) { ONX_ModelComponentIterator cit(model, ON_ModelComponent::Type::ModelGeometry); const auto* component = cit.FirstComponent(); @@ -1368,7 +1368,7 @@ bool ON_MeshModifierCollection::CreateMeshModifiersFromXML(const ONX_Model& mode // Get the entire XML off of the attributes user data. ON_wString xml; - ONX_Model::GetMeshModifierObjectInformation(*attr, xml); + ::GetMeshModifierObjectInformation(*attr, xml, archive_3dm_version); if (xml.IsEmpty()) continue; // No XML found on the component's attributes. @@ -1405,7 +1405,7 @@ static const ON_UUID uuid_thickening_user_data = 0x6aa7ccc3, 0x2721, 0x410f, { 0xaa, 0x56, 0xe8, 0xab, 0x4f, 0x3e, 0xce, 0x67 } }; -bool ON_MeshModifierCollection::CreateXMLFromMeshModifiers(const ONX_Model& model) +bool ON_MeshModifierCollection::CreateXMLFromMeshModifiers(const ONX_Model& model, int archive_3dm_version) { for (const auto& elem : m_map) { @@ -1421,11 +1421,11 @@ bool ON_MeshModifierCollection::CreateXMLFromMeshModifiers(const ONX_Model& mode if (nullptr == attr) continue; // Should never happen because we have an item for the object. - SetMeshModifierObjectInformation(*attr, uuid_displacement_user_data, mesh_modifiers->Displacement()); - SetMeshModifierObjectInformation(*attr, uuid_edge_softening_user_data, mesh_modifiers->EdgeSoftening()); - SetMeshModifierObjectInformation(*attr, uuid_thickening_user_data, mesh_modifiers->Thickening()); - SetMeshModifierObjectInformation(*attr, uuid_curve_piping_user_data, mesh_modifiers->CurvePiping()); - SetMeshModifierObjectInformation(*attr, uuid_shutlining_user_data, mesh_modifiers->Shutlining()); + SetMeshModifierObjectInformation(*attr, uuid_displacement_user_data, mesh_modifiers->Displacement(), archive_3dm_version); + SetMeshModifierObjectInformation(*attr, uuid_edge_softening_user_data, mesh_modifiers->EdgeSoftening(), archive_3dm_version); + SetMeshModifierObjectInformation(*attr, uuid_thickening_user_data, mesh_modifiers->Thickening(), archive_3dm_version); + SetMeshModifierObjectInformation(*attr, uuid_curve_piping_user_data, mesh_modifiers->CurvePiping(), archive_3dm_version); + SetMeshModifierObjectInformation(*attr, uuid_shutlining_user_data, mesh_modifiers->Shutlining(), archive_3dm_version); } return true; diff --git a/opennurbs_model_component.cpp b/opennurbs_model_component.cpp index 1d522975..cfd44693 100644 --- a/opennurbs_model_component.cpp +++ b/opennurbs_model_component.cpp @@ -944,7 +944,7 @@ const ON_wString ON_ModelComponent::DeletedName() const const wchar_t* ON_ModelComponent::NameAsPointer() const { - return static_cast(Name()); + return NameIsSet() ? m_component_name : ON_wString::EmptyString; } const ON_wString ON_ModelComponent::RemoveAllReferencePrefixDelimiters( diff --git a/opennurbs_public_version.h b/opennurbs_public_version.h index 327abf14..bc15a66a 100644 --- a/opennurbs_public_version.h +++ b/opennurbs_public_version.h @@ -14,10 +14,10 @@ // first step in each build. // #define RMA_VERSION_YEAR 2022 -#define RMA_VERSION_MONTH 7 -#define RMA_VERSION_DATE 28 -#define RMA_VERSION_HOUR 4 -#define RMA_VERSION_MINUTE 30 +#define RMA_VERSION_MONTH 8 +#define RMA_VERSION_DATE 12 +#define RMA_VERSION_HOUR 10 +#define RMA_VERSION_MINUTE 9 //////////////////////////////////////////////////////////////// // @@ -35,8 +35,8 @@ // 3 = build system release build #define RMA_VERSION_BRANCH 0 -#define VERSION_WITH_COMMAS 8,0,22209,4300 -#define VERSION_WITH_PERIODS 8.0.22209.04300 +#define VERSION_WITH_COMMAS 8,0,22224,10090 +#define VERSION_WITH_PERIODS 8.0.22224.10090 #define COPYRIGHT "Copyright (C) 1993-2022, 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.22209.04300" -#define RMA_VERSION_WITH_PERIODS_WSTRING L"8.0.22209.04300" +#define RMA_VERSION_WITH_PERIODS_STRING "8.0.22224.10090" +#define RMA_VERSION_WITH_PERIODS_WSTRING L"8.0.22224.10090" diff --git a/opennurbs_render_content.cpp b/opennurbs_render_content.cpp index b86f7511..54d3a36a 100644 --- a/opennurbs_render_content.cpp +++ b/opennurbs_render_content.cpp @@ -22,15 +22,29 @@ #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs #endif -#define ON_POSTFIX_SECTION L"-section" -#define ON_PARAMETERS L"parameters" -#define ON_PARAMETERS_V8 L"parameters-v8" -#define ON_SIMULATION L"simulation" +#define ON_TYPE_NAME L"type-name" +#define ON_TYPE_ID L"type-id" +#define ON_INSTANCE_ID L"instance-id" +#define ON_RENDER_ENGINE_ID L"render-engine-id" +#define ON_PLUG_IN_ID L"plug-in-id" +#define ON_GROUP_ID L"group-id" +#define ON_INSTANCE_NAME L"instance-name" +#define ON_CHILD_SLOT_NAME L"child-slot-name" +#define ON_NOTES L"notes" +#define ON_TAGS L"tags" +#define ON_HIDDEN L"hidden" +#define ON_REFERENCE L"reference" +#define ON_AUTO_DELETE L"auto-delete" +#define ON_ENV_BACKGROUND_COLOR L"background-color" +#define ON_POSTFIX_SECTION L"-section" +#define ON_PARAMETERS L"parameters" +#define ON_PARAMETERS_V8 L"parameters-v8" +#define ON_SIMULATION L"simulation" -#define ON_RDK_POSTFIX_SECTION L"-section" -#define ON_RDK_PARAMETERS L"parameters" -#define ON_RDK_PARAMETERS_V8 L"parameters-v8" -#define ON_RDK_SIMULATION L"simulation" +#define ON_POSTFIX_SECTION L"-section" +#define ON_PARAMETERS L"parameters" +#define ON_PARAMETERS_V8 L"parameters-v8" +#define ON_SIMULATION L"simulation" #define ON_ENV_PROJ_BOX L"box" #define ON_ENV_PROJ_CUBE_MAP L"cubemap" @@ -496,7 +510,7 @@ ON_RenderContent::CImpl::~CImpl() const ON_XMLNode* ON_RenderContent::CImpl::XMLNode_Simulation(void) const { - return m_node.GetNamedChild(ON_RDK_SIMULATION); + return m_node.GetNamedChild(ON_SIMULATION); } ON_XMLVariant ON_RenderContent::CImpl::GetPropertyValue(const wchar_t* name) const @@ -581,10 +595,10 @@ void ON_RenderContent::CImpl::SetXMLNode(const ON_XMLNode& node) m_node = node_copy; // Copy the XML instance name to the component name. - m_render_content.SetName(GetPropertyValue(ON_RDK_INSTANCE_NAME).AsString()); + m_render_content.SetName(GetPropertyValue(ON_INSTANCE_NAME).AsString()); // Copy the XML instance id to the component id. - m_render_content.SetId(GetPropertyValue(ON_RDK_INSTANCE_ID).AsUuid()); + m_render_content.SetId(GetPropertyValue(ON_INSTANCE_ID).AsUuid()); } bool ON_RenderContent::CImpl::AddChild(ON_RenderContent& child) @@ -744,7 +758,7 @@ bool ON_RenderContent::CImpl::SetChild(ON_RenderContent* child, const wchar_t* c if ((nullptr == child_slot_name) || (0 == child_slot_name[0])) return false; - child->m_impl->SetPropertyValue(ON_RDK_CHILD_SLOT_NAME, child_slot_name); + child->m_impl->SetPropertyValue(ON_CHILD_SLOT_NAME, child_slot_name); } // Get any existing child with the same child slot name (may be null). @@ -777,10 +791,10 @@ bool ON_RenderContent::CImpl::SetChild(ON_RenderContent* child, const wchar_t* c void SetRenderContentNodeRecursive(const ON_RenderContent& rc, ON_XMLNode& node) { // Copy the component name to the XML instance name. - rc.m_impl->SetPropertyValue(ON_RDK_INSTANCE_NAME, rc.Name()); + rc.m_impl->SetPropertyValue(ON_INSTANCE_NAME, rc.Name()); // Copy the component id to the XML instance id. - rc.m_impl->SetPropertyValue(ON_RDK_INSTANCE_ID, rc.Id()); + rc.m_impl->SetPropertyValue(ON_INSTANCE_ID, rc.Id()); auto* child_node = new ON_XMLNode(rc.XMLNode()); node.AttachChildNode(child_node); @@ -824,10 +838,10 @@ ON_RenderContent::ON_RenderContent(const wchar_t* kind) SetId(uuid); // Set the plug-in id to the RDK plug-in id. - m_impl->InternalSetPropertyValue(ON_RDK_PLUG_IN_ID, RdkPlugInId()); + m_impl->InternalSetPropertyValue(ON_PLUG_IN_ID, RdkPlugInId()); // Set the render engine id to 'universal'. - m_impl->InternalSetPropertyValue(ON_RDK_RENDER_ENGINE_ID, UniversalRenderEngineId()); + m_impl->InternalSetPropertyValue(ON_RENDER_ENGINE_ID, UniversalRenderEngineId()); } ON_RenderContent::ON_RenderContent(const ON_RenderContent& rc) @@ -858,102 +872,102 @@ const ON_RenderContent& ON_RenderContent::operator = (const ON_RenderContent& rc ON_wString ON_RenderContent::TypeName(void) const { - return m_impl->GetPropertyValue(ON_RDK_TYPE_NAME).AsString(); + return m_impl->GetPropertyValue(ON_TYPE_NAME).AsString(); } void ON_RenderContent::SetTypeName(const wchar_t* name) { - m_impl->SetPropertyValue(ON_RDK_TYPE_NAME, name); + m_impl->SetPropertyValue(ON_TYPE_NAME, name); } ON_wString ON_RenderContent::Notes(void) const { - return m_impl->GetPropertyValue(ON_RDK_NOTES).AsString(); + return m_impl->GetPropertyValue(ON_NOTES).AsString(); } void ON_RenderContent::SetNotes(const wchar_t* notes) { - m_impl->SetPropertyValue(ON_RDK_NOTES, notes); + m_impl->SetPropertyValue(ON_NOTES, notes); } ON_wString ON_RenderContent::Tags(void) const { - return m_impl->GetPropertyValue(ON_RDK_TAGS).AsString(); + return m_impl->GetPropertyValue(ON_TAGS).AsString(); } void ON_RenderContent::SetTags(const wchar_t* tags) { - m_impl->SetPropertyValue(ON_RDK_TAGS, tags); + m_impl->SetPropertyValue(ON_TAGS, tags); } ON_UUID ON_RenderContent::TypeId(void) const { - return m_impl->GetPropertyValue(ON_RDK_TYPE_ID).AsUuid(); + return m_impl->GetPropertyValue(ON_TYPE_ID).AsUuid(); } void ON_RenderContent::SetTypeId(const ON_UUID& uuid) { - m_impl->SetPropertyValue(ON_RDK_TYPE_ID, uuid); + m_impl->SetPropertyValue(ON_TYPE_ID, uuid); } ON_UUID ON_RenderContent::RenderEngineId(void) const { - return m_impl->GetPropertyValue(ON_RDK_RENDER_ENGINE_ID).AsUuid(); + return m_impl->GetPropertyValue(ON_RENDER_ENGINE_ID).AsUuid(); } void ON_RenderContent::SetRenderEngineId(const ON_UUID& uuid) { - m_impl->SetPropertyValue(ON_RDK_RENDER_ENGINE_ID, uuid); + m_impl->SetPropertyValue(ON_RENDER_ENGINE_ID, uuid); } ON_UUID ON_RenderContent::PlugInId(void) const { - return m_impl->GetPropertyValue(ON_RDK_PLUG_IN_ID).AsUuid(); + return m_impl->GetPropertyValue(ON_PLUG_IN_ID).AsUuid(); } void ON_RenderContent::SetPlugInId(const ON_UUID& uuid) { - m_impl->SetPropertyValue(ON_RDK_PLUG_IN_ID, uuid); + m_impl->SetPropertyValue(ON_PLUG_IN_ID, uuid); } ON_UUID ON_RenderContent::GroupId(void) const { - return m_impl->GetPropertyValue(ON_RDK_GROUP_ID).AsUuid(); + return m_impl->GetPropertyValue(ON_GROUP_ID).AsUuid(); } void ON_RenderContent::SetGroupId(const ON_UUID& group) { - m_impl->SetPropertyValue(ON_RDK_GROUP_ID, group); + m_impl->SetPropertyValue(ON_GROUP_ID, group); } bool ON_RenderContent::Hidden(void) const { - return m_impl->GetPropertyValue(ON_RDK_HIDDEN).AsBool(); + return m_impl->GetPropertyValue(ON_HIDDEN).AsBool(); } void ON_RenderContent::SetHidden(bool hidden) { - m_impl->SetPropertyValue(ON_RDK_HIDDEN, hidden); + m_impl->SetPropertyValue(ON_HIDDEN, hidden); } bool ON_RenderContent::Reference(void) const { - return m_impl->GetPropertyValue(ON_RDK_REFERENCE).AsBool(); + return m_impl->GetPropertyValue(ON_REFERENCE).AsBool(); } void ON_RenderContent::SetReference(bool ref) { - m_impl->SetPropertyValue(ON_RDK_REFERENCE, ref); + m_impl->SetPropertyValue(ON_REFERENCE, ref); } bool ON_RenderContent::AutoDelete(void) const { - return m_impl->GetPropertyValue(ON_RDK_AUTO_DELETE).AsBool(); + return m_impl->GetPropertyValue(ON_AUTO_DELETE).AsBool(); } void ON_RenderContent::SetAutoDelete(bool autodel) { - m_impl->SetPropertyValue(ON_RDK_AUTO_DELETE, autodel); + m_impl->SetPropertyValue(ON_AUTO_DELETE, autodel); } ON_XMLVariant ON_RenderContent::GetParameter(const wchar_t* name) const @@ -964,7 +978,7 @@ ON_XMLVariant ON_RenderContent::GetParameter(const wchar_t* name) const value.SetNull(); // Try to get the new V8 parameter section. - const auto* node = m_impl->m_node.GetNamedChild(ON_RDK_PARAMETERS_V8); + const auto* node = m_impl->m_node.GetNamedChild(ON_PARAMETERS_V8); if (nullptr != node) { // Got it, so use the new ON_XMLParametersV8 to get the parameter's value. @@ -975,7 +989,7 @@ ON_XMLVariant ON_RenderContent::GetParameter(const wchar_t* name) const { // Either no V8 section was found or the parameter isn't there yet. // Try to get the legacy parameter section. This should not fail. - node = m_impl->m_node.GetNamedChild(ON_RDK_PARAMETERS); + node = m_impl->m_node.GetNamedChild(ON_PARAMETERS); if (nullptr != node) { // Got it, so use the legacy ON_XMLParameters to get the parameter's value. @@ -994,7 +1008,7 @@ bool ON_RenderContent::SetParameter(const wchar_t* name, const ON_XMLVariant& va bool success = false; // Create / get the new V8 parameter section. - auto* node = m_impl->m_node.CreateNodeAtPath(ON_RDK_PARAMETERS_V8); + auto* node = m_impl->m_node.CreateNodeAtPath(ON_PARAMETERS_V8); if (nullptr != node) { // Use the new ON_XMLParametersV8 to write the parameter's value. @@ -1004,7 +1018,7 @@ bool ON_RenderContent::SetParameter(const wchar_t* name, const ON_XMLVariant& va } // Create / get the legacy parameter section. - node = m_impl->m_node.CreateNodeAtPath(ON_RDK_PARAMETERS); + node = m_impl->m_node.CreateNodeAtPath(ON_PARAMETERS); if (nullptr != node) { // Use the legacy ON_XMLParameters to write the parameter's value. @@ -1063,12 +1077,12 @@ bool ON_RenderContent::DeleteChild(const wchar_t* child_slot_name) ON_wString ON_RenderContent::ChildSlotName(void) const { - return m_impl->GetPropertyValue(ON_RDK_CHILD_SLOT_NAME).AsString(); + return m_impl->GetPropertyValue(ON_CHILD_SLOT_NAME).AsString(); } void ON_RenderContent::SetChildSlotName(const wchar_t* csn) { - m_impl->SetPropertyValue(ON_RDK_CHILD_SLOT_NAME, csn); + m_impl->SetPropertyValue(ON_CHILD_SLOT_NAME, csn); } bool ON_RenderContent::ChildSlotOn(const wchar_t* child_slot_name) const diff --git a/opennurbs_render_content.h b/opennurbs_render_content.h index 908030cf..2b3ea5a1 100644 --- a/opennurbs_render_content.h +++ b/opennurbs_render_content.h @@ -14,22 +14,6 @@ #if !defined(ON_RENDER_CONTENT_INC_) #define ON_RENDER_CONTENT_INC_ -#define ON_RDK_TYPE_NAME L"type-name" -#define ON_RDK_TYPE_ID L"type-id" -#define ON_RDK_INSTANCE_ID L"instance-id" -#define ON_RDK_RENDER_ENGINE_ID L"render-engine-id" -#define ON_RDK_PLUG_IN_ID L"plug-in-id" -#define ON_RDK_GROUP_ID L"group-id" -#define ON_RDK_INSTANCE_NAME L"instance-name" -#define ON_RDK_CHILD_SLOT_NAME L"child-slot-name" -#define ON_RDK_NOTES L"notes" -#define ON_RDK_TAGS L"tags" -#define ON_RDK_HIDDEN L"hidden" -#define ON_RDK_REFERENCE L"reference" -#define ON_RDK_AUTO_DELETE L"auto-delete" - -#define ON_RDK_ENV_BACKGROUND_COLOR L"background-color" - // ON_Environment class ON_CLASS ON_Environment : public ON_Object diff --git a/opennurbs_skylight.cpp b/opennurbs_skylight.cpp index e5ad0470..67e37c4f 100644 --- a/opennurbs_skylight.cpp +++ b/opennurbs_skylight.cpp @@ -39,6 +39,11 @@ static const wchar_t* XMLPath(void) return ON_RDK_DOCUMENT ON_RDK_SLASH ON_RDK_SETTINGS ON_RDK_SLASH ON_RDK_SUN; } +ON_Skylight::ON_Skylight() +{ + m_impl = new CImpl; +} + ON_Skylight::ON_Skylight(ON_XMLNode& model_node) { m_impl = new CImpl(model_node); diff --git a/opennurbs_string.cpp b/opennurbs_string.cpp index c1d7d4b5..04f49531 100644 --- a/opennurbs_string.cpp +++ b/opennurbs_string.cpp @@ -796,11 +796,22 @@ void ON_String::Append( const unsigned char* s , int count ) AppendToArray(count,s); } - const ON_String& ON_String::operator+=(const ON_String& s) { - AppendToArray(s); - return *this; + // 28th July 2022 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-69587 + // When the strings are the same object AppendToArray() doesn't work properly. The safest + // thing to do is copy the incoming string so they are not the same object anymore. + if (this == &s) + { + ON_String copy = s; + AppendToArray(copy); + } + else + { + AppendToArray(s); + } + + return *this; } const ON_String& ON_String::operator+=( char s ) diff --git a/opennurbs_subd.cpp b/opennurbs_subd.cpp index 8bb7a5f0..3fada286 100644 --- a/opennurbs_subd.cpp +++ b/opennurbs_subd.cpp @@ -1255,6 +1255,8 @@ const ON_ComponentStatus ON_SubDComponentPtr::Status() const return face->m_status; } break; + case ON_SubDComponentPtr::Type::Unset: + break; } return ON_ComponentStatus::NoneSet; } @@ -1286,6 +1288,8 @@ unsigned int ON_SubDComponentPtr::SetStatus( return face->m_status.SetStatus(status); } break; + case ON_SubDComponentPtr::Type::Unset: + break; } return ON_SUBD_RETURN_ERROR(0); } @@ -1318,6 +1322,8 @@ unsigned int ON_SubDComponentPtr::SetStates( return face->m_status.SetStates(states_to_set); } break; + case ON_SubDComponentPtr::Type::Unset: + break; } return ON_SUBD_RETURN_ERROR(0); } @@ -1350,6 +1356,8 @@ unsigned int ON_SubDComponentPtr::ClearStates( return face->m_status.ClearStates(states_to_clear); } break; + case ON_SubDComponentPtr::Type::Unset: + break; } return ON_SUBD_RETURN_ERROR(0); } @@ -1832,6 +1840,8 @@ class ON_SubDComponentBase* ON_SubDComponentPtr::ComponentBase(ON_SubDComponentP case ON_SubDComponentPtr::Type::Edge: case ON_SubDComponentPtr::Type::Face: return (ptr_type == type_filter || ON_SubDComponentPtr::Type::Unset == type_filter) ? ((class ON_SubDComponentBase*)ON_SUBD_COMPONENT_POINTER(m_ptr)) : nullptr; + case ON_SubDComponentPtr::Type::Unset: + break; } return nullptr; } @@ -6510,6 +6520,8 @@ static bool IsValidSubDEdgeTag( case ON_SubDVertexTag::Dart: ++dart_vertex_count; break; + case ON_SubDVertexTag::Unset: + break; } }; @@ -7262,6 +7274,9 @@ unsigned int ON_SubD::DumpTopology( case ON_TextureMapping::TYPE::ocs_mapping: text_log.Print("ocs"); break; + case ON_TextureMapping::TYPE::false_colors: + text_log.Print("false colors"); + break; } text_log.PrintNewLine(); text_log.Print("m_mapping_id = "); @@ -9369,6 +9384,8 @@ const ON_SubDComponentPtr ON_SubDHeap::InHeap(const class ON_SubDComponentBase* case ON_SubDComponentPtr::Type::Face: return ON_SubDComponentPtr::Create((const ON_SubDFace*)b); break; + case ON_SubDComponentPtr::Type::Unset: + break; } } } @@ -13011,6 +13028,7 @@ unsigned int ON_SubDimple::Internal_GlobalQuadSubdivideFace( } if (make_ngons_pack) { + // TODO: Use ON_SubDFace::GetNgonSubPackRectSizeAndDelta() instead? pack_id = max_pack_id; // Will be incremented later const unsigned int k = f0_edge_count / 4; const unsigned int r = f0_edge_count % 4; @@ -13123,6 +13141,7 @@ unsigned int ON_SubDimple::Internal_GlobalQuadSubdivideFace( { if (make_ngons_pack) { + // TODO: Use ON_SubDFace::GetNgonSubPackRectSizeAndDelta() instead? ++pack_id; const unsigned int quadrant = (i * 4) / f0_edge_count; const unsigned int prevsizes = ( @@ -15934,6 +15953,9 @@ bool ON_SubD::DeleteComponentsForExperts( face->m_status = ON_ComponentStatus::AllSet; } break; + + case ON_SubDComponentPtr::Type::Unset: + break; } } @@ -15958,6 +15980,8 @@ bool ON_SubD::DeleteComponentsForExperts( case ON_SubDComponentPtr::Type::Face: deleted_face_count++; break; + case ON_SubDComponentPtr::Type::Unset: + break; } continue; } @@ -17324,6 +17348,9 @@ static unsigned int Internal_MarkStuffAndMaybeMoveVertices( } } break; + + case ON_SubDComponentPtr::Type::Unset: + break; } } @@ -22711,6 +22738,8 @@ bool ON_SubDComponentFilter::AcceptComponent(ON_COMPONENT_INDEX component_index, if (ON_SubDComponentPtr::Type::Face != cptr.ComponentType()) return false; break; + default: // 30 unhandled enum values + break; } return AcceptComponent(cptr); } @@ -22739,6 +22768,8 @@ bool ON_SubDComponentFilter::AcceptComponent(ON_SubDComponentPtr cptr) const case ON_SubDComponentPtr::Type::Face: return AcceptFace(cptr.Face()); break; + case ON_SubDComponentPtr::Type::Unset: + break; } return false; } diff --git a/opennurbs_subd_eval.cpp b/opennurbs_subd_eval.cpp index c2dc2a39..a5c31ac6 100644 --- a/opennurbs_subd_eval.cpp +++ b/opennurbs_subd_eval.cpp @@ -833,6 +833,9 @@ const ON_3dPoint ON_SubDVertex::Point(ON_SubDComponentLocation point_location) c case ON_SubDComponentLocation::Surface: return this->SurfacePoint(); break; + case ON_SubDComponentLocation::Unset: + return ON_3dPoint::NanPoint; + break; } return ON_3dPoint::NanPoint; } diff --git a/opennurbs_subd_ref.cpp b/opennurbs_subd_ref.cpp index d96f8a13..72f20916 100644 --- a/opennurbs_subd_ref.cpp +++ b/opennurbs_subd_ref.cpp @@ -446,7 +446,10 @@ bool ON_SubDComponentRef::GetBBox( switch (m_component_ptr.ComponentType()) { - case ON_SubDComponentPtr::Type::Vertex: + case ON_SubDComponentPtr::Type::Unset: + break; + + case ON_SubDComponentPtr::Type::Vertex: { const ON_SubDVertex* vertex = m_component_ptr.Vertex(); if ( nullptr == vertex ) @@ -458,6 +461,9 @@ bool ON_SubDComponentRef::GetBBox( case ON_SubDComponentLocation::ControlNet: bbox = vertex->ControlNetBoundingBox(); break; + + case ON_SubDComponentLocation::Unset: + break; } } break; @@ -473,6 +479,8 @@ bool ON_SubDComponentRef::GetBBox( case ON_SubDComponentLocation::ControlNet: bbox = edge->ControlNetBoundingBox(); break; + case ON_SubDComponentLocation::Unset: + break; } } break; @@ -488,6 +496,8 @@ bool ON_SubDComponentRef::GetBBox( case ON_SubDComponentLocation::ControlNet: bbox = face->ControlNetBoundingBox(); break; + case ON_SubDComponentLocation::Unset: + break; } } break; @@ -582,7 +592,10 @@ bool ON_SubDComponentRefList::Internal_UpdateCount(const ON_SubDComponentRef& r, ON_SubDComponentPtr cptr = r.ComponentPtr(); switch (cptr.ComponentType()) { - case ON_SubDComponentPtr::Type::Vertex: + case ON_SubDComponentPtr::Type::Unset: + break; + + case ON_SubDComponentPtr::Type::Vertex: { const ON_SubDVertex* v = cptr.Vertex(); if (nullptr == v) @@ -605,6 +618,8 @@ bool ON_SubDComponentRefList::Internal_UpdateCount(const ON_SubDComponentRef& r, m_subd_vertex_dart_count += i; rc = true; break; + case ON_SubDVertexTag::Unset: + break; } } break; @@ -625,6 +640,8 @@ bool ON_SubDComponentRefList::Internal_UpdateCount(const ON_SubDComponentRef& r, m_subd_edge_crease_count += i; rc = true; break; + case ON_SubDEdgeTag::Unset: + break; } } break; @@ -856,6 +873,8 @@ int ON_SubDComponentRefList::VertexCount(ON_SubDVertexTag vertex_tag) const case ON_SubDVertexTag::Dart: c = m_subd_vertex_dart_count; break; + case ON_SubDVertexTag::Unset: + break; } return c; @@ -879,6 +898,8 @@ int ON_SubDComponentRefList::EdgeCount(ON_SubDEdgeTag edge_tag) const case ON_SubDEdgeTag::Crease: c = m_subd_edge_crease_count; break; + case ON_SubDEdgeTag::SmoothX: + break; } return c; } diff --git a/opennurbs_subd_sector.cpp b/opennurbs_subd_sector.cpp index fc3173be..b9d7f4a0 100644 --- a/opennurbs_subd_sector.cpp +++ b/opennurbs_subd_sector.cpp @@ -774,6 +774,8 @@ ON_SubDSectorType ON_SubDSectorType::Create( case ON_SubDVertexTag::Dart: return ON_SubDSectorType::CreateDartSectorType(sector_face_count); break; + default: + break; } return ON_SUBD_RETURN_ERROR(ON_SubDSectorType::Empty); diff --git a/opennurbs_wstring.cpp b/opennurbs_wstring.cpp index 8cb4be9d..bc0603c5 100644 --- a/opennurbs_wstring.cpp +++ b/opennurbs_wstring.cpp @@ -1252,8 +1252,20 @@ void ON_wString::Append( const wchar_t* s, int count ) const ON_wString& ON_wString::operator+=(const ON_wString& s) { - AppendToArray(s); - return *this; + // 28th July 2022 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-69587 + // When the strings are the same object AppendToArray() doesn't work properly. The safest + // thing to do is copy the incoming string so they are not the same object anymore. + if (this == &s) + { + ON_wString copy = s; + AppendToArray(copy); + } + else + { + AppendToArray(s); + } + + return *this; } const ON_wString& ON_wString::operator+=(const ON_String& s) diff --git a/opennurbs_xml.cpp b/opennurbs_xml.cpp index 2307655d..33f8c448 100644 --- a/opennurbs_xml.cpp +++ b/opennurbs_xml.cpp @@ -128,6 +128,8 @@ const wchar_t* ON_StringFromUnits(ON::LengthUnitSystem units) case ON::LengthUnitSystem::NauticalMiles: return L"nautical-miles"; case ON::LengthUnitSystem::Parsecs: return L"parsecs"; case ON::LengthUnitSystem::Yards: return L"yards"; + default: + break; } return L"none"; @@ -371,9 +373,11 @@ bool ON_UnicodeTextFile::CImpl::ReadString(ON_wString& s) case Types::UTF16: return ReadStringFromUTF16(s); + + case Types::Unknown: + default: + return false; } - - return false; } bool ON_UnicodeTextFile::CImpl::WriteString(const wchar_t* wsz) @@ -385,9 +389,11 @@ bool ON_UnicodeTextFile::CImpl::WriteString(const wchar_t* wsz) case Types::UTF16: return WriteStringToUTF16(wsz); + + case Types::Unknown: + default: + return false; } - - return false; } bool ON_UnicodeTextFile::CImpl::ReadStringFromUTF8(ON_wString& s) @@ -1267,9 +1273,10 @@ bool ON_XMLVariant::AsBool(void) const if (m_impl->m_sVal.CompareNoCase(L"true") == 0) return true; if (m_impl->m_sVal.CompareNoCase(L"t") == 0) return true; return ON_wtoi(m_impl->m_sVal) != 0; + + default: + return false; } - - return false; } int ON_XMLVariant::AsInteger(void) const @@ -1288,7 +1295,8 @@ int ON_XMLVariant::AsInteger(void) const if (m_impl->m_sVal.CompareNoCase(L"t") == 0) return true; return ON_wtoi(m_impl->m_sVal); - default: return 0; + default: + return 0; } } @@ -1303,9 +1311,10 @@ double ON_XMLVariant::AsDouble(void) const case Types::Double: return m_impl->m_dVal; case Types::Integer: return double (m_impl->m_iVal); case Types::String: return ON_wtof(m_impl->m_sVal); + + default: + return 0.0; } - - return 0.0; } float ON_XMLVariant::AsFloat(void) const @@ -1319,9 +1328,10 @@ float ON_XMLVariant::AsFloat(void) const case Types::Double: return float(m_impl->m_dVal); case Types::Integer: return float(m_impl->m_iVal); case Types::String: return float(ON_wtof(m_impl->m_sVal)); + + default: + return 0.0f; } - - return 0.0f; } ON_2dPoint ON_XMLVariant::As2dPoint(void) const @@ -1430,6 +1440,9 @@ ON_4fColor ON_XMLVariant::AsColor(void) const case Types::DoubleArray4: case Types::DoubleColor4: col.SetRGBA(float(m_impl->m_aVal[0]), float(m_impl->m_aVal[1]), float(m_impl->m_aVal[2]), float(m_impl->m_aVal[3])); + + default: + break; } return col; @@ -1463,9 +1476,9 @@ time_t ON_XMLVariant::AsTime(void) const case Types::Time: return m_impl->m_timeVal; + + default: return 0; } - - return 0; } ON_Buffer ON_XMLVariant::AsBuffer(void) const @@ -1473,7 +1486,10 @@ ON_Buffer ON_XMLVariant::AsBuffer(void) const DoAutoTyping(Types::Buffer); ON_Buffer buf; - +#if defined(ON_RUNTIME_APPLE) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wswitch" +#endif switch (m_impl->m_type) { case Types::Buffer: @@ -1494,7 +1510,9 @@ ON_Buffer ON_XMLVariant::AsBuffer(void) const } break; } - +#if defined(ON_RUNTIME_APPLE) +#pragma clang diagnostic pop +#endif return buf; } @@ -1566,6 +1584,10 @@ ON_wString ON_XMLVariant::AsString(void) const delete[] buf; return m_impl->m_sVal; } + + case Types::Null: + default: + break; } return L""; @@ -1709,9 +1731,10 @@ ON_wString ON_XMLVariant::TypeAsString(void) const case Types::String: return L"string"; case Types::Time: return L"time"; case Types::Buffer: return L"buffer"; + case Types::Null: + default: + return L"null"; } - - return L"null"; } template @@ -2302,9 +2325,10 @@ static const wchar_t* StringFromPropType(ON_XMLVariant::Types vt) case ON_XMLVariant::Types::DoubleArray2: return L"2da"; case ON_XMLVariant::Types::DoubleArray3: return L"3da"; case ON_XMLVariant::Types::DoubleArray4: return L"4da"; + case ON_XMLVariant::Types::Null: + default: + return L"null"; } - - return L"null"; } static ON_XMLVariant::Types PropTypeFromString(const ON_wString& s) @@ -2812,7 +2836,7 @@ bool ON_XMLNode::CImpl::GetNextTag(ON_wString& tag, wchar_t*& pBuffer, bool bVal { if (0 == *start) { - OUTPUT_DEBUG_STRING_EOL(L"Tag not found"); + OUTPUT_DEBUG_STRING_EOL(L"Start of tag '<' not found"); return false; } @@ -2826,7 +2850,7 @@ bool ON_XMLNode::CImpl::GetNextTag(ON_wString& tag, wchar_t*& pBuffer, bool bVal { if (0 == *start) { - OUTPUT_DEBUG_STRING_EOL(L"End tag not found"); + OUTPUT_DEBUG_STRING_EOL(L"End of document description tag '>' not found"); return false; } @@ -2846,7 +2870,7 @@ bool ON_XMLNode::CImpl::GetNextTag(ON_wString& tag, wchar_t*& pBuffer, bool bVal { if (0 == *start) { - OUTPUT_DEBUG_STRING_EOL(L"End tag not found"); + OUTPUT_DEBUG_STRING_EOL(L"End of comment tag '>' not found"); return false; } @@ -2864,7 +2888,7 @@ bool ON_XMLNode::CImpl::GetNextTag(ON_wString& tag, wchar_t*& pBuffer, bool bVal { if (0 == *pEnd) { - OUTPUT_DEBUG_STRING_EOL(L"End tag not found"); + OUTPUT_DEBUG_STRING_EOL(L"End of tag '>' not found"); return false; } @@ -2875,6 +2899,9 @@ bool ON_XMLNode::CImpl::GetNextTag(ON_wString& tag, wchar_t*& pBuffer, bool bVal // Copy the tag into the ready-made string. const auto numChars = int(pEnd - start + 1); + if (numChars < 2) + return false; + tag.Set(start, numChars); if (bValidateTag) @@ -3431,6 +3458,12 @@ bool ON_XMLNode::CImpl::GetPropertiesFromTag(const ON_wString& sTag) bool ON_XMLNode::CImpl::IsClosingTag(const ON_wString& sTag) const { + if (sTag.Length() < 3) + return false; + + if (sTag[0] != L'<') + return false; + if (sTag[1] != L'/') return false; @@ -3784,17 +3817,17 @@ bool ON_XMLNode::WriteToSegmentedStream(ON_XMLSegmentedStream& segs, bool includ ON_wString ON_XMLNode::GetNameFromTag(const wchar_t* wszTag) // Static. { - ON_wString tag = wszTag; - tag.TrimLeft(L"/ "); + ON_wString name = wszTag; + name.TrimLeft(L"/ "); - const int pos = tag.Find(L' '); + const int pos = name.Find(L' '); if (pos >= 0) { - tag.SetLength(pos); + name.SetLength(pos); } - return tag; + return name; } ON_XMLNode* ON_XMLNode::FirstChild(void) const @@ -3867,16 +3900,22 @@ ON__UINT32 ON_XMLNode::ReadFromStream(const wchar_t* stream, bool bWarningsAsErr wchar_t* pBuffer = const_cast(stream); ON_wString tag; - m_impl->GetNextTag(tag, pBuffer, bValidateTags); + + // 1st August 2022 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-66795 + // The original code was not checking GetNextTag() for failure and blindly continuing with an empty tag. + // Then in some places it assumed that the tag was not empty. This is confusing because I thought + // this was causing RH-66795, but it couldn't be because this bug was not in 7.x, and RH-66795 is 7.13. + if (!m_impl->GetNextTag(tag, pBuffer, bValidateTags)) + return ReadError; + + if (tag.IsEmpty()) + return ReadError; m_impl->m_last_read_buf_ptr = (void*)stream; - if (!tag.IsEmpty()) - { - m_impl->GetPropertiesFromTag(tag); - } + m_impl->GetPropertiesFromTag(tag); - const auto pos1 = tag.Length() - 2; + const auto pos1 = tag.Length() - 2; // Assumes the tag is not empty. if (tag[pos1] != L'/') { // This tag either has children, or a default property. @@ -3909,7 +3948,14 @@ ON__UINT32 ON_XMLNode::ReadFromStream(const wchar_t* stream, bool bWarningsAsErr } pBuffer = start; - m_impl->GetNextTag(tag, pBuffer, bValidateTags); + + // 1st August 2022 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-66795 + // The original code was not checking GetNextTag() for failure and blindly continuing with + // an empty tag. This caused continuous child recursion because the buffer pointer was + // still pointing at the same (bad) XML. This is confusing because I thought this was causing + // RH-66795, but it couldn't be because this bug was not in 7.x, and RH-66795 is 7.13. + if (!m_impl->GetNextTag(tag, pBuffer, bValidateTags)) + return ReadError; bClosingTag = m_impl->IsClosingTag(tag); diff --git a/opennurbs_xml.h b/opennurbs_xml.h index a1d6cab7..977a69b5 100644 --- a/opennurbs_xml.h +++ b/opennurbs_xml.h @@ -589,6 +589,12 @@ protected: ON_DECL bool ON_RunXMLTests(const wchar_t* test_folder); +//////////////////////////////////////////////////////////////////////////////////////////// +// +// ON_RdkUserData is for internal use only and is not intended for use by SDK clients. +// +//////////////////////////////////////////////////////////////////////////////////////////// + class ON_CLASS ON_RdkUserData : public ON_XMLUserData { private: