mirror of
https://github.com/mcneel/opennurbs.git
synced 2026-03-17 23:16:02 +08:00
Sync changes from upstream repository
This commit is contained in:
@@ -26,11 +26,6 @@
|
||||
|
||||
static ON_4dPoint UNSET_4D_POINT = ON_4dPoint(ON_UNSET_VALUE, ON_UNSET_VALUE, ON_UNSET_VALUE, ON_UNSET_VALUE);
|
||||
|
||||
ON_DECAL_CRC ON_DecalCRCFromNode(const ON_XMLNode& node)
|
||||
{
|
||||
return ON_Decal::ComputeDecalCRC(0, node);
|
||||
}
|
||||
|
||||
class ON_Decal::CImpl : public ON_InternalXMLImpl
|
||||
{
|
||||
public:
|
||||
@@ -147,6 +142,8 @@ void ON_Decal::CImpl::SetParameter(const wchar_t* param_name, const ON_XMLVarian
|
||||
|
||||
ON_UUID ON_Decal::CImpl::TextureInstanceId(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (!_cache.texture_instance_id_set)
|
||||
{
|
||||
_cache.texture_instance_id = GetParameter(ON_RDK_DECAL_TEXTURE_INSTANCE, ON_nil_uuid).AsUuid();
|
||||
@@ -158,6 +155,8 @@ ON_UUID ON_Decal::CImpl::TextureInstanceId(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetTextureInstanceId(const ON_UUID& id)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (!_cache.texture_instance_id_set || (_cache.texture_instance_id != id))
|
||||
{
|
||||
_cache.texture_instance_id = id;
|
||||
@@ -168,6 +167,8 @@ void ON_Decal::CImpl::SetTextureInstanceId(const ON_UUID& id)
|
||||
|
||||
ON_Decal::Mappings ON_Decal::CImpl::Mapping(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (Mappings::None == _cache.mapping)
|
||||
{
|
||||
const ON_wString s = GetParameter(ON_RDK_DECAL_MAPPING, ON_RDK_DECAL_MAPPING_UV).AsString();
|
||||
@@ -179,6 +180,8 @@ ON_Decal::Mappings ON_Decal::CImpl::Mapping(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetMapping(Mappings m)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.mapping != m)
|
||||
{
|
||||
_cache.mapping = m;
|
||||
@@ -200,6 +203,8 @@ void ON_Decal::CImpl::SetMapping(Mappings m)
|
||||
|
||||
ON_Decal::Projections ON_Decal::CImpl::Projection(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (Projections::None == _cache.projection)
|
||||
{
|
||||
const ON_wString s = GetParameter(ON_RDK_DECAL_PROJECTION, ON_RDK_DECAL_PROJECTION_NONE).AsString();
|
||||
@@ -215,6 +220,8 @@ ON_Decal::Projections ON_Decal::CImpl::Projection(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetProjection(Projections v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.projection != v)
|
||||
{
|
||||
_cache.projection = v;
|
||||
@@ -235,6 +242,8 @@ void ON_Decal::CImpl::SetProjection(Projections v)
|
||||
|
||||
bool ON_Decal::CImpl::MapToInside(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (unset_bool == _cache.map_to_inside)
|
||||
{
|
||||
_cache.map_to_inside = GetParameter(ON_RDK_DECAL_MAP_TO_INSIDE_ON, false).AsBool() ? 1 : 0;
|
||||
@@ -245,6 +254,8 @@ bool ON_Decal::CImpl::MapToInside(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetMapToInside(bool b)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
const int i = b ? 1 : 0;
|
||||
if (_cache.map_to_inside != i)
|
||||
{
|
||||
@@ -255,6 +266,8 @@ void ON_Decal::CImpl::SetMapToInside(bool b)
|
||||
|
||||
double ON_Decal::CImpl::Transparency(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_UNSET_VALUE == _cache.transparency)
|
||||
{
|
||||
_cache.transparency = GetParameter(ON_RDK_DECAL_TRANSPARENCY, 0.0).AsDouble();
|
||||
@@ -265,6 +278,8 @@ double ON_Decal::CImpl::Transparency(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetTransparency(double v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.transparency != v)
|
||||
{
|
||||
_cache.transparency = v;
|
||||
@@ -274,6 +289,8 @@ void ON_Decal::CImpl::SetTransparency(double v)
|
||||
|
||||
ON_3dPoint ON_Decal::CImpl::Origin(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_3dPoint::UnsetPoint == _cache.origin)
|
||||
{
|
||||
_cache.origin = GetParameter(ON_RDK_DECAL_ORIGIN, ON_3dPoint::Origin).As3dPoint();
|
||||
@@ -284,6 +301,8 @@ ON_3dPoint ON_Decal::CImpl::Origin(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetOrigin(const ON_3dPoint& pt)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.origin != pt)
|
||||
{
|
||||
_cache.origin = pt;
|
||||
@@ -293,6 +312,8 @@ void ON_Decal::CImpl::SetOrigin(const ON_3dPoint& pt)
|
||||
|
||||
ON_3dVector ON_Decal::CImpl::VectorUp(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_3dVector::UnsetVector == _cache.vector_up)
|
||||
{
|
||||
_cache.vector_up = GetParameter(ON_RDK_DECAL_VECTOR_UP, ON_3dPoint::Origin).As3dPoint();
|
||||
@@ -303,6 +324,8 @@ ON_3dVector ON_Decal::CImpl::VectorUp(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetVectorUp(const ON_3dVector& v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.vector_up != v)
|
||||
{
|
||||
_cache.vector_up = v;
|
||||
@@ -312,6 +335,8 @@ void ON_Decal::CImpl::SetVectorUp(const ON_3dVector& v)
|
||||
|
||||
ON_3dVector ON_Decal::CImpl::VectorAcross(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_3dVector::UnsetVector == _cache.vector_across)
|
||||
{
|
||||
_cache.vector_across = GetParameter(ON_RDK_DECAL_VECTOR_ACROSS, ON_3dPoint::Origin).As3dPoint();
|
||||
@@ -322,6 +347,8 @@ ON_3dVector ON_Decal::CImpl::VectorAcross(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetVectorAcross(const ON_3dVector& v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.vector_across != v)
|
||||
{
|
||||
_cache.vector_across = v;
|
||||
@@ -331,6 +358,8 @@ void ON_Decal::CImpl::SetVectorAcross(const ON_3dVector& v)
|
||||
|
||||
double ON_Decal::CImpl::Height(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_UNSET_VALUE == _cache.height)
|
||||
{
|
||||
_cache.height = GetParameter(ON_RDK_DECAL_HEIGHT, 1.0).AsDouble();
|
||||
@@ -341,6 +370,8 @@ double ON_Decal::CImpl::Height(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetHeight(double v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.height != v)
|
||||
{
|
||||
_cache.height = v;
|
||||
@@ -350,6 +381,8 @@ void ON_Decal::CImpl::SetHeight(double v)
|
||||
|
||||
double ON_Decal::CImpl::Radius(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_UNSET_VALUE == _cache.radius)
|
||||
{
|
||||
_cache.radius = GetParameter(ON_RDK_DECAL_RADIUS, 1.0).AsDouble();
|
||||
@@ -360,6 +393,8 @@ double ON_Decal::CImpl::Radius(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetRadius(double v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (_cache.radius != v)
|
||||
{
|
||||
_cache.radius = v;
|
||||
@@ -369,6 +404,8 @@ void ON_Decal::CImpl::SetRadius(double v)
|
||||
|
||||
bool ON_Decal::CImpl::IsVisible(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (unset_bool == _cache.visible)
|
||||
{
|
||||
_cache.visible = GetParameter(ON_RDK_DECAL_IS_VISIBLE, true).AsBool();
|
||||
@@ -379,6 +416,8 @@ bool ON_Decal::CImpl::IsVisible(void) const
|
||||
|
||||
void ON_Decal::CImpl::SetIsVisible(bool b)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
const int i = b ? 1 : 0;
|
||||
if (_cache.visible != i)
|
||||
{
|
||||
@@ -389,6 +428,8 @@ void ON_Decal::CImpl::SetIsVisible(bool b)
|
||||
|
||||
void ON_Decal::CImpl::GetHorzSweep(double& sta, double& end) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_2dPoint::UnsetPoint == _cache.horz_sweep)
|
||||
{
|
||||
_cache.horz_sweep.x = GetParameter(ON_RDK_DECAL_HORZ_SWEEP_STA, 0.0).AsDouble();
|
||||
@@ -401,6 +442,8 @@ void ON_Decal::CImpl::GetHorzSweep(double& sta, double& end) const
|
||||
|
||||
void ON_Decal::CImpl::SetHorzSweep(double sta, double end)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
const auto sweep = ON_2dPoint(sta, end);
|
||||
if (_cache.horz_sweep != sweep)
|
||||
{
|
||||
@@ -412,6 +455,8 @@ void ON_Decal::CImpl::SetHorzSweep(double sta, double end)
|
||||
|
||||
void ON_Decal::CImpl::GetVertSweep(double& sta, double& end) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (ON_2dPoint::UnsetPoint == _cache.vert_sweep)
|
||||
{
|
||||
_cache.vert_sweep.x = GetParameter(ON_RDK_DECAL_VERT_SWEEP_STA, 0.0).AsDouble();
|
||||
@@ -424,6 +469,8 @@ void ON_Decal::CImpl::GetVertSweep(double& sta, double& end) const
|
||||
|
||||
void ON_Decal::CImpl::SetVertSweep(double sta, double end)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
const auto sweep = ON_2dPoint(sta, end);
|
||||
if (_cache.vert_sweep != sweep)
|
||||
{
|
||||
@@ -435,6 +482,8 @@ void ON_Decal::CImpl::SetVertSweep(double sta, double end)
|
||||
|
||||
void ON_Decal::CImpl::GetUVBounds(double& min_u, double& min_v, double& max_u, double& max_v) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (UNSET_4D_POINT == _cache.uv_bounds)
|
||||
{
|
||||
_cache.uv_bounds.x = GetParameter(ON_RDK_DECAL_MIN_U, 0.0).AsDouble();
|
||||
@@ -451,6 +500,8 @@ void ON_Decal::CImpl::GetUVBounds(double& min_u, double& min_v, double& max_u, d
|
||||
|
||||
void ON_Decal::CImpl::SetUVBounds(double min_u, double min_v, double max_u, double max_v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
const auto bounds = ON_4dPoint(min_u, min_v, max_u, max_v);
|
||||
if (_cache.uv_bounds != bounds)
|
||||
{
|
||||
@@ -464,6 +515,8 @@ void ON_Decal::CImpl::SetUVBounds(double min_u, double min_v, double max_u, doub
|
||||
|
||||
ON_XMLNode* ON_Decal::CImpl::FindCustomNodeForRenderEngine(const ON_UUID& renderEngineId) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
ON_XMLNode* child_node = nullptr;
|
||||
auto it = Node().GetChildIterator();
|
||||
while (nullptr != (child_node = it.GetNextChild()))
|
||||
@@ -521,6 +574,9 @@ const ON_Decal& ON_Decal::operator = (const ON_Decal& d)
|
||||
{
|
||||
if (this != &d)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg1(_impl->_mutex);
|
||||
std::lock_guard<std::recursive_mutex> lg2(d._impl->_mutex);
|
||||
|
||||
_impl->Node() = d._impl->Node();
|
||||
}
|
||||
|
||||
@@ -531,6 +587,9 @@ bool ON_Decal::operator == (const ON_Decal& d) const
|
||||
{
|
||||
// This only checks if the basic parameters are equal. It ignores any custom data.
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lg1(_impl->_mutex);
|
||||
std::lock_guard<std::recursive_mutex> lg2(d._impl->_mutex);
|
||||
|
||||
if (TextureInstanceId() != d.TextureInstanceId()) return false;
|
||||
if (Mapping() != d.Mapping()) return false;
|
||||
if (Projection() != d.Projection()) return false;
|
||||
@@ -715,18 +774,10 @@ ON_UUID ON_Decal::Id(void) const
|
||||
return _impl->Id();
|
||||
}
|
||||
|
||||
ON_DECAL_CRC ON_Decal::DecalCRC(void) const
|
||||
{
|
||||
return ComputeDecalCRC(0, _impl->Node());
|
||||
}
|
||||
|
||||
ON__UINT32 ON_Decal::DataCRC(ON__UINT32 current_remainder) const
|
||||
{
|
||||
return ComputeDecalCRC(current_remainder, _impl->Node());
|
||||
}
|
||||
|
||||
void ON_Decal::GetCustomXML(const ON_UUID& renderEngineId, ON_XMLNode& custom_param_node) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_impl->_mutex);
|
||||
|
||||
custom_param_node.Clear();
|
||||
custom_param_node.SetTagName(ON_RDK_DECAL_CUSTOM_PARAMS);
|
||||
|
||||
@@ -760,7 +811,12 @@ bool ON_Decal::SetCustomXML(const ON_UUID& renderEngineId, const ON_XMLNode& cus
|
||||
}
|
||||
|
||||
// Attach the new custom node and set its 'renderer' property to be the render engine id.
|
||||
custom_node = _impl->Node().AttachChildNode(new ON_XMLNode(ON_RDK_DECAL_CUSTOM));
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_impl->_mutex);
|
||||
|
||||
custom_node = _impl->Node().AttachChildNode(new ON_XMLNode(ON_RDK_DECAL_CUSTOM));
|
||||
}
|
||||
|
||||
ON_XMLProperty prop(ON_RDK_DECAL_CUSTOM_RENDERER, renderEngineId);
|
||||
custom_node->SetProperty(prop);
|
||||
|
||||
@@ -779,9 +835,11 @@ void ON_Decal::AppendCustomXML(const ON_XMLNode& custom_node)
|
||||
ON_XMLNode* child = custom_node.FirstChild();
|
||||
while (nullptr != child)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_impl->_mutex);
|
||||
|
||||
_impl->Node().AttachChildNode(new ON_XMLNode(*child));
|
||||
|
||||
child = custom_node.NextSibling();
|
||||
child = child->NextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,7 +1057,7 @@ static void DecalUpdateCRC_Custom(const ON_XMLNode& decal_node, ON_DECAL_CRC& cr
|
||||
}
|
||||
}
|
||||
|
||||
ON_DECAL_CRC ON_Decal::ComputeDecalCRC(ON__UINT32 current_remainder, const ON_XMLNode& decal_node) // Static.
|
||||
static ON_DECAL_CRC ComputeDecalCRC(ON__UINT32 current_remainder, const ON_XMLNode& decal_node) // Static.
|
||||
{
|
||||
// The CRC of a decal is a unique value based on its state. It's created by CRC-ing all the decal properties
|
||||
// that affect the decal's appearance. We do not include the 'IsTemporary' property in the CRC because whether
|
||||
@@ -1021,7 +1079,7 @@ ON_DECAL_CRC ON_Decal::ComputeDecalCRC(ON__UINT32 current_remainder, const ON_XM
|
||||
|
||||
const ON_Decal::Mappings mapping = MappingFromString(d.Mapping().AsString());
|
||||
|
||||
if (Mappings::UV == mapping)
|
||||
if (ON_Decal::Mappings::UV == mapping)
|
||||
{
|
||||
DecalUpdateCRC(crc, d.MinU() ON_DECAL_PROP_NAME(L"min_u"));
|
||||
DecalUpdateCRC(crc, d.MinV() ON_DECAL_PROP_NAME(L"min_v"));
|
||||
@@ -1034,26 +1092,26 @@ ON_DECAL_CRC ON_Decal::ComputeDecalCRC(ON__UINT32 current_remainder, const ON_XM
|
||||
DecalUpdateCRC(crc, d.VectorUp() ON_DECAL_PROP_NAME(L"up"));
|
||||
DecalUpdateCRC(crc, d.VectorAcross() ON_DECAL_PROP_NAME(L"across"));
|
||||
|
||||
if ((Mappings::Cylindrical == mapping) || (Mappings::Spherical == mapping))
|
||||
if ((ON_Decal::Mappings::Cylindrical == mapping) || (ON_Decal::Mappings::Spherical == mapping))
|
||||
{
|
||||
DecalUpdateCRC(crc, d.MapToInside() ON_DECAL_PROP_NAME(L"map_to_inside"));
|
||||
DecalUpdateCRC(crc, d.Radius() ON_DECAL_PROP_NAME(L"radius"));
|
||||
DecalUpdateCRC(crc, d.HorzSweepSta() ON_DECAL_PROP_NAME(L"horz_sweep_sta"));
|
||||
DecalUpdateCRC(crc, d.HorzSweepEnd() ON_DECAL_PROP_NAME(L"horz_sweep_end"));
|
||||
|
||||
if (Mappings::Cylindrical == mapping)
|
||||
if (ON_Decal::Mappings::Cylindrical == mapping)
|
||||
{
|
||||
DecalUpdateCRC(crc, d.Height() ON_DECAL_PROP_NAME(L"height"));
|
||||
}
|
||||
else
|
||||
if (Mappings::Spherical == mapping)
|
||||
if (ON_Decal::Mappings::Spherical == mapping)
|
||||
{
|
||||
DecalUpdateCRC(crc, d.VertSweepSta() ON_DECAL_PROP_NAME(L"vert_sweep_sta"));
|
||||
DecalUpdateCRC(crc, d.VertSweepEnd() ON_DECAL_PROP_NAME(L"vert_sweep_end"));
|
||||
}
|
||||
}
|
||||
else
|
||||
if (Mappings::Planar == mapping)
|
||||
if (ON_Decal::Mappings::Planar == mapping)
|
||||
{
|
||||
DecalUpdateCRC(crc, d.Projection() ON_DECAL_PROP_NAME(L"projection"));
|
||||
}
|
||||
@@ -1069,6 +1127,25 @@ ON_DECAL_CRC ON_Decal::ComputeDecalCRC(ON__UINT32 current_remainder, const ON_XM
|
||||
return crc;
|
||||
}
|
||||
|
||||
ON_DECAL_CRC ON_DecalCRCFromNode(const ON_XMLNode& node)
|
||||
{
|
||||
return ComputeDecalCRC(0, node);
|
||||
}
|
||||
|
||||
ON_DECAL_CRC ON_Decal::DecalCRC(void) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_impl->_mutex);
|
||||
|
||||
return ComputeDecalCRC(0, _impl->Node());
|
||||
}
|
||||
|
||||
ON__UINT32 ON_Decal::DataCRC(ON__UINT32 current_remainder) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_impl->_mutex);
|
||||
|
||||
return ComputeDecalCRC(current_remainder, _impl->Node());
|
||||
}
|
||||
|
||||
// ON_DecalCollection
|
||||
|
||||
ON_DecalCollection::~ON_DecalCollection()
|
||||
@@ -1078,7 +1155,9 @@ ON_DecalCollection::~ON_DecalCollection()
|
||||
|
||||
int ON_DecalCollection::FindDecalIndex(const ON_UUID& id) const
|
||||
{
|
||||
for (int i = 0; i < m_decals.Count(); i++)
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
for (int i = 0; i < m_decals.size(); i++)
|
||||
{
|
||||
if (m_decals[i]->Id() == id)
|
||||
return i;
|
||||
@@ -1087,12 +1166,12 @@ int ON_DecalCollection::FindDecalIndex(const ON_UUID& id) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
ON_Decal* ON_DecalCollection::AddDecal(void)
|
||||
std::shared_ptr<ON_Decal> ON_DecalCollection::AddDecal(void)
|
||||
{
|
||||
// Ensure the array is populated before adding a new decal.
|
||||
GetDecalArray();
|
||||
|
||||
ON_Decal* decal = nullptr;
|
||||
std::shared_ptr<ON_Decal> decal;
|
||||
|
||||
ON_XMLNode* decals_node = m_root_node.CreateNodeAtPath(ON_RDK_UD_ROOT ON_XML_SLASH ON_RDK_DECALS);
|
||||
if (nullptr != decals_node)
|
||||
@@ -1103,8 +1182,12 @@ ON_Decal* ON_DecalCollection::AddDecal(void)
|
||||
|
||||
// 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);
|
||||
decal = std::make_shared<ON_Decal>(*this, *decal_node);
|
||||
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
m_decals.push_back(decal);
|
||||
}
|
||||
|
||||
SetChanged();
|
||||
}
|
||||
@@ -1143,16 +1226,21 @@ bool ON_DecalCollection::RemoveDecal(const ON_Decal& decal)
|
||||
return false;
|
||||
|
||||
// Delete it.
|
||||
delete m_decals[index];
|
||||
m_decals.Remove(index);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
m_decals.erase(m_decals.begin() + index);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ON_DecalCollection::RemoveAllDecals(void)
|
||||
{
|
||||
m_root_node.Clear();
|
||||
m_root_node.CreateNodeAtPath(ON_RDK_UD_ROOT);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
m_root_node.Clear();
|
||||
m_root_node.CreateNodeAtPath(ON_RDK_UD_ROOT);
|
||||
}
|
||||
|
||||
ClearDecalArray();
|
||||
}
|
||||
@@ -1161,16 +1249,12 @@ void ON_DecalCollection::ClearDecalArray(void)
|
||||
{
|
||||
// 12th July 2023 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-75697
|
||||
// Only call SetChanged() if a decal is actually deleted.
|
||||
const int count = m_decals.Count();
|
||||
if (count > 0)
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (!m_decals.empty())
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
delete m_decals[i];
|
||||
}
|
||||
|
||||
m_decals.Destroy();
|
||||
|
||||
m_decals.clear();
|
||||
SetChanged();
|
||||
}
|
||||
|
||||
@@ -1179,14 +1263,15 @@ void ON_DecalCollection::ClearDecalArray(void)
|
||||
|
||||
const ON_DecalCollection& ON_DecalCollection::operator = (const ON_DecalCollection& dc)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
ClearDecalArray();
|
||||
|
||||
for (int i = 0; i < dc.m_decals.Count(); i++)
|
||||
for (const auto& decal : dc.m_decals)
|
||||
{
|
||||
ON_Decal* decal = dc.m_decals[i];
|
||||
if (nullptr != decal)
|
||||
if (decal)
|
||||
{
|
||||
m_decals.Append(new ON_Decal(*decal));
|
||||
m_decals.push_back(std::make_shared<ON_Decal>(*decal));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1195,22 +1280,20 @@ const ON_DecalCollection& ON_DecalCollection::operator = (const ON_DecalCollecti
|
||||
return *this;
|
||||
}
|
||||
|
||||
const ON_SimpleArray<ON_Decal*>& ON_DecalCollection::GetDecalArray(void) const
|
||||
const std::vector<std::shared_ptr<ON_Decal>>& ON_DecalCollection::GetDecalArray(void) const
|
||||
{
|
||||
// 19th February 2025 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-86089
|
||||
// The m_populated flag is an optimization designed to make sure we only populate the array when something
|
||||
// changes. Unfortunately, in Rhino 8, I forgot to add code to detect when a decal changes externally to this
|
||||
// class, and the array (which is essentially a cache) becomes invalid. This is fixed in Rhino 9 but the fix
|
||||
// is too complicated to backport to Rhino 8, so to get around this I'm just going to remove the optimization.
|
||||
// The m_populated flag is an optimization designed to make sure we only populate the array when
|
||||
// something changes. Unfortunately, in Rhino 8, I forgot to add code to detect when a decal changes
|
||||
// externally to this class, and the array (which is essentially a cache) becomes invalid. This is
|
||||
// fixed in Rhino 9 but the fix is too complicated to backport to Rhino 8, so to get around this I'm
|
||||
// just going to remove the optimization.
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
//if (!m_populated) // Always repopulate the array.
|
||||
{
|
||||
for (int i = 0; i < m_decals.Count(); i++)
|
||||
{
|
||||
delete m_decals[i];
|
||||
}
|
||||
|
||||
m_decals.Destroy();
|
||||
m_decals.clear();
|
||||
|
||||
Populate();
|
||||
|
||||
@@ -1225,6 +1308,8 @@ void ON_DecalCollection::Populate(void) const
|
||||
if (nullptr == m_attr)
|
||||
return;
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lg(_mutex);
|
||||
|
||||
if (GetEntireDecalXML(*m_attr, m_root_node))
|
||||
{
|
||||
const wchar_t* path = ON_RDK_UD_ROOT ON_XML_SLASH ON_RDK_DECALS;
|
||||
@@ -1232,13 +1317,13 @@ void ON_DecalCollection::Populate(void) const
|
||||
if (nullptr != decals_node)
|
||||
{
|
||||
// Iterate over the decals under the decals node adding a new decal for each one.
|
||||
ON_ASSERT(m_decals.Count() == 0);
|
||||
ON_ASSERT(m_decals.size() == 0);
|
||||
auto it = decals_node->GetChildIterator();
|
||||
ON_XMLNode* child_node = nullptr;
|
||||
while (nullptr != (child_node = it.GetNextChild()))
|
||||
{
|
||||
auto* decal = new ON_Decal(*const_cast<ON_DecalCollection*>(this), *child_node);
|
||||
m_decals.Append(decal);
|
||||
auto decal = std::make_shared<ON_Decal>(*const_cast<ON_DecalCollection*>(this), *child_node);
|
||||
m_decals.push_back(decal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user