Skip to content

Commit

Permalink
Merge pull request mcneel#22 from mcneel/update-1608126584-v7.1.20343…
Browse files Browse the repository at this point in the history
….09491

Sync changes from upstream repository
  • Loading branch information
sbaer committed Dec 16, 2020
2 parents 990401a + 488533e commit c20e599
Show file tree
Hide file tree
Showing 54 changed files with 4,010 additions and 882 deletions.
153 changes: 108 additions & 45 deletions opennurbs_3dm_settings.cpp
Expand Up @@ -37,7 +37,7 @@ static double ON_Internal_UnitSystemCtorMetersPerUnit(
switch (length_unit_system)
{
case ON::LengthUnitSystem::None:
meters_per_unit = 0.0;
meters_per_unit = 1.0;
break;
case ON::LengthUnitSystem::Angstroms:
case ON::LengthUnitSystem::Nanometers:
Expand All @@ -63,7 +63,7 @@ static double ON_Internal_UnitSystemCtorMetersPerUnit(
case ON::LengthUnitSystem::AstronomicalUnits:
case ON::LengthUnitSystem::LightYears:
case ON::LengthUnitSystem::Parsecs:
meters_per_unit = ON::UnitScale(ON::LengthUnitSystem::Meters, length_unit_system);
meters_per_unit = ON::UnitScale(length_unit_system, ON::LengthUnitSystem::Meters);
break;
case ON::LengthUnitSystem::CustomUnits:
meters_per_unit = 1.0;
Expand All @@ -81,7 +81,7 @@ static double ON_Internal_UnitSystemCtorMetersPerUnit(

ON_UnitSystem::ON_UnitSystem(ON::LengthUnitSystem length_unit_system)
: m_unit_system(ON::LengthUnitSystemFromUnsigned(static_cast<unsigned int>(length_unit_system)))
, m_meters_per_unit(ON_Internal_UnitSystemCtorMetersPerUnit(m_unit_system))
, m_meters_per_custom_unit(ON_Internal_UnitSystemCtorMetersPerUnit(m_unit_system))
{}

ON_UnitSystem& ON_UnitSystem::operator=(
Expand All @@ -100,7 +100,7 @@ bool ON_UnitSystem::operator==(const ON_UnitSystem& other) const

if ( ON::LengthUnitSystem::CustomUnits == m_unit_system )
{
if ( !(m_meters_per_unit == other.m_meters_per_unit) )
if ( !(m_meters_per_custom_unit == other.m_meters_per_custom_unit) )
return false;
if ( false == m_custom_unit_name.EqualOrdinal(other.m_custom_unit_name,false) )
return false;
Expand All @@ -116,7 +116,7 @@ bool ON_UnitSystem::operator!=(const ON_UnitSystem& other) const

if ( ON::LengthUnitSystem::CustomUnits == m_unit_system )
{
if ( m_meters_per_unit != other.m_meters_per_unit )
if (m_meters_per_custom_unit != other.m_meters_per_custom_unit)
return true;
if ( false == m_custom_unit_name.EqualOrdinal(other.m_custom_unit_name,false) )
return true;
Expand All @@ -129,36 +129,25 @@ bool ON_UnitSystem::IsValid() const
{
if ( m_unit_system != ON::LengthUnitSystemFromUnsigned(static_cast<unsigned int>(m_unit_system)) )
{
// bogus enum value
// invalid enum value
return false;
}

if (ON::LengthUnitSystem::None == m_unit_system)
{
if (!(0.0 == m_meters_per_unit))
return false;
}
else
if (ON::LengthUnitSystem::Unset == m_unit_system)
return false;

if (ON::LengthUnitSystem::CustomUnits == m_unit_system)
{
if (!(m_meters_per_unit > 0.0 && m_meters_per_unit < ON_UNSET_POSITIVE_VALUE))
{
// m_meters_per_unit should be > 0.0 and a valid double
if (false == ON_IsValidPositiveNumber(m_meters_per_custom_unit))
return false;
}

if (ON::LengthUnitSystem::CustomUnits != m_unit_system)
{
if (m_meters_per_unit != ON::UnitScale(ON::LengthUnitSystem::Meters, m_unit_system))
return false;
}
}

return true;
}

bool ON_UnitSystem::IsSet() const
{
return ( ON::LengthUnitSystem::None != m_unit_system && IsValid() );
return (ON::LengthUnitSystem::Unset != m_unit_system && ON::LengthUnitSystem::None != m_unit_system && IsValid() );
}

bool ON_UnitSystem::IsCustomUnitSystem() const
Expand Down Expand Up @@ -188,17 +177,18 @@ void ON_UnitSystem::SetCustomUnitSystem(
double meters_per_custom_unit
)
{
ON_wString local_str(custom_unit_name);
local_str.TrimLeftAndRight();
m_unit_system = ON::LengthUnitSystem::CustomUnits;
m_custom_unit_name = custom_unit_name;
m_custom_unit_name.TrimLeftAndRight();
if (meters_per_custom_unit > 0.0 && meters_per_custom_unit < ON_UNSET_POSITIVE_VALUE)
m_custom_unit_name = local_str;
if ( ON_IsValidPositiveNumber(meters_per_custom_unit) )
{
m_meters_per_unit = meters_per_custom_unit;
m_meters_per_custom_unit = meters_per_custom_unit;
}
else
{
ON_ERROR("Invalid meters_per_custom_unit parameter");
m_meters_per_unit = 1.0; // must be > 0.0 and < ON_UNSET_POSITIVE_VALUE
m_meters_per_custom_unit = 1.0; // must be > 0.0 and < ON_UNSET_POSITIVE_VALUE
}
}

Expand All @@ -213,7 +203,7 @@ void ON_UnitSystem::SetCustomUnitSystemName(
{
const double meters_per_custom_unit
= bIsCustomUnitSystem
? m_meters_per_unit
? m_meters_per_custom_unit
: 1.0;
SetCustomUnitSystem(local_name, meters_per_custom_unit);
}
Expand All @@ -223,24 +213,82 @@ void ON_UnitSystem::SetCustomUnitSystemScale(
double meters_per_custom_unit
)
{
const bool bIsCustomUnitSystem = (ON::LengthUnitSystem::CustomUnits == m_unit_system);
if (meters_per_custom_unit != m_meters_per_unit || bIsCustomUnitSystem)
if (ON_IsValidPositiveNumber(meters_per_custom_unit))
{
if (meters_per_custom_unit > 0.0 && meters_per_custom_unit < ON_UNSET_POSITIVE_VALUE)
const bool bIsCustomUnitSystem = (ON::LengthUnitSystem::CustomUnits == m_unit_system);
if (false == (meters_per_custom_unit == m_meters_per_custom_unit) || bIsCustomUnitSystem)
{
ON_wString unit_system_name
const ON_wString unit_system_name
= (ON::LengthUnitSystem::CustomUnits == m_unit_system)
? unit_system_name
? m_custom_unit_name
: ON_wString::EmptyString;
SetCustomUnitSystem(unit_system_name, meters_per_custom_unit);
}
}
}

double ON_UnitSystem::MetersPerUnit(
double unset_return_value
) const
{
switch (m_unit_system)
{
case ON::LengthUnitSystem::None:
return 1.0;
break;
case ON::LengthUnitSystem::CustomUnits:
return m_meters_per_custom_unit;
break;
case ON::LengthUnitSystem::Unset:
return unset_return_value;
break;
default:
break;
}
return ON::UnitScale(m_unit_system, ON::LengthUnitSystem::Meters);
}

double ON_UnitSystem::MillimetersPerUnit(
double unset_return_value
) const
{
switch (m_unit_system)
{
case ON::LengthUnitSystem::None:
return 1.0;
break;
case ON::LengthUnitSystem::CustomUnits:
return 1000.0*m_meters_per_custom_unit;
break;
case ON::LengthUnitSystem::Unset:
return unset_return_value;
break;
default:
break;
}
return ON::UnitScale(m_unit_system, ON::LengthUnitSystem::Millimeters);
}

double ON_UnitSystem::MetersPerUnit() const
{
return m_meters_per_unit;
// NOTE WELL:
// https://mcneel.myjetbrains.com/youtrack/issue/RH-60700
// For standard units, this function returns the WRONG value (inverse of the correct value).
// The reason is the Rhino 6 VRay plug-in assumes the incorrect value is returned
// and V6 VRay does not work correctly in Rhino 7 if the correct value is returned.
// After some discussion (see the bug above), we will leave the invers bug in
// ON_UnitSystem::MetersPerUnit(), deprecate ON_UnitSystem::MetersPerUnit(),
// and add a new function that returns the correct answer.
if (ON::LengthUnitSystem::CustomUnits == m_unit_system)
{
// correct answer for custome units - V6 behavior.
return m_meters_per_custom_unit; //
}


// For standard units, the inverse of the correct answer is returned
// to preserve V6 bug so VRay works in Rhino 7.
return 1.0/ON_UnitSystem::MetersPerUnit(ON_DBL_QNAN);
}

ON::LengthUnitSystem ON_UnitSystem::UnitSystem() const
Expand Down Expand Up @@ -438,12 +486,20 @@ const ON_wString& ON_UnitSystem::UnitSystemName() const
break;

case ON::LengthUnitSystem::CustomUnits:
if (m_custom_unit_name.IsEmpty())
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"custom units", s_name);
return s_name;
}
return m_custom_unit_name;
break;

case ON::LengthUnitSystem::Unset:
{
return ON_wString::EmptyString;
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"unset", s_name);
return s_name;
}
break;
}
Expand Down Expand Up @@ -493,7 +549,7 @@ bool ON_UnitSystem::Read( ON_BinaryArchive& file )
{
m_unit_system = us;
m_custom_unit_name = custom_unit_name;
m_meters_per_unit = meters_per_unit;
m_meters_per_custom_unit = meters_per_unit;
}
else
{
Expand Down Expand Up @@ -529,9 +585,9 @@ bool ON_UnitSystem::Write( ON_BinaryArchive& file ) const
{
if (!file.WriteInt(static_cast<unsigned int>(m_unit_system)))
break;
if (!file.WriteDouble(m_meters_per_unit))
if (!file.WriteDouble(ON::LengthUnitSystem::CustomUnits == m_unit_system ? m_meters_per_custom_unit : ON::UnitScale(m_unit_system, ON::LengthUnitSystem::Meters)))
break;
if (!file.WriteString(m_custom_unit_name))
if (!file.WriteString(ON::LengthUnitSystem::CustomUnits == m_unit_system ? m_custom_unit_name : ON_wString::EmptyString))
break;
rc = true;
break;
Expand All @@ -543,15 +599,22 @@ bool ON_UnitSystem::Write( ON_BinaryArchive& file ) const
return rc;
}

void ON_UnitSystem::Dump( ON_TextLog& dump ) const
const ON_wString ON_UnitSystem::ToString() const
{
ON_wString sUnitSystem(UnitSystemName());
if ( ON::LengthUnitSystem::CustomUnits == m_unit_system)
ON_wString str(UnitSystemName());
if (ON::LengthUnitSystem::CustomUnits == m_unit_system)
{
ON_wString meters_per_unit;
meters_per_unit.Format(L" (= %g meters )", m_meters_per_unit);
sUnitSystem += meters_per_unit;
meters_per_unit.Format(L" (= %g meters )", m_meters_per_custom_unit);
str += meters_per_unit;
}
return str;

}

void ON_UnitSystem::Dump( ON_TextLog& dump ) const
{
const ON_wString sUnitSystem(ToString());
dump.Print("Unit system: %ls\n",static_cast<const wchar_t*>(sUnitSystem));
}

Expand Down Expand Up @@ -580,7 +643,7 @@ bool ON_3dmUnitsAndTolerances::Write( ON_BinaryArchive& file ) const
if ( rc ) rc = file.WriteInt( i );

// added in version 102
if ( rc ) rc = file.WriteDouble( m_unit_system.MetersPerUnit() );
if ( rc ) rc = file.WriteDouble( m_unit_system.MetersPerUnit(ON_DBL_QNAN));
if ( rc ) rc = file.WriteString( (ON::LengthUnitSystem::CustomUnits == m_unit_system.UnitSystem() ? m_unit_system.UnitSystemName() : ON_wString::EmptyString) );
return rc;
}
Expand Down
22 changes: 21 additions & 1 deletion opennurbs_annotationbase.cpp
Expand Up @@ -158,8 +158,16 @@ static bool Internal_UpdateOverrideCandidateParentId(
{
for (;;)
{
if (0 == archive.ReferenceModelSerialNumber() && 0 == archive.InstanceDefinitionModelSerialNumber())
if (
false == archive.CheckForRemappedIds()
&& 0 == archive.ReferenceModelSerialNumber()
&& 0 == archive.InstanceDefinitionModelSerialNumber()
)
{
return false; // common situation - no change reqired
}


if (nullptr == override_candidate)
break;
const ON_UUID archive_parent_id = override_candidate->ParentId();
Expand Down Expand Up @@ -812,11 +820,23 @@ bool ON_Annotation::IsOverrideStylePointer(

bool ON_Annotation::AllowTextScaling() const
{
// These functions are being added to continue the V5 behavior of
// per-object text scaling. There is no user interface
// in V6 or V7 that shows this setting or that allows a user
// to change this setting.
// AllowTextScaling() = false means the effective dimstyle value
// of DimScale() (model space scale factor) is ignored (treated as if it were 1).
return m_allow_text_scaling;
}

void ON_Annotation::SetAllowTextScaling(bool scale)
{
// These functions are being added to continue the V5 behavior of
// per-object text scaling. There is no user interface
// in V6 or V7 that shows this setting or that allows a user
// to change this setting.
// AllowTextScaling() = false means the effective dimstyle value
// of DimScale() (model space scale factor) is ignored (treated as if it were 1).
if (scale != m_allow_text_scaling)
{
m_allow_text_scaling = scale ? true : false;
Expand Down
29 changes: 28 additions & 1 deletion opennurbs_annotationbase.h
Expand Up @@ -346,6 +346,29 @@ class ON_CLASS ON_Annotation : public ON_Geometry
bool bRequireSetOverrides
) const;


/*
Description:
Conceptually, calling this function applies ON_DimsStyle(scale) to the
dimstyle information used for this annotation.
When an annotation object is in **layout/page space**, this is
the only way top get properties like TextHeight() to scale properly.
When an annotation object is in **model space** and
**model space scaling is enabled**,
then calling this->SetDimScale(this->DimScale()*scale)
will work as well.
Parameters:
parent_dimstyle - [in]
scale - [in]
*/
void ScaleOverrideDimstyle(
const ON_DimStyle* parent_dimstyle,
double scale
);

protected:
static bool Internal_IsOverrideDimStyleCandidate(
const ON_DimStyle* override_style_candidate,
Expand Down Expand Up @@ -432,7 +455,11 @@ class ON_CLASS ON_Annotation : public ON_Geometry
) const;

// These functions are being added to continue the V5 behavior of
// per-object text scaling
// per-object text scaling. There is no user interface
// in V6 or V7 that shows this setting or that allows a user
// to change this setting.
// AllowTextScaling() = false means the effective dimstyle value
// of DimScale() (model space scale factor) is ignored (treated as if it were 1).
bool AllowTextScaling() const;
void SetAllowTextScaling(bool scale);

Expand Down

0 comments on commit c20e599

Please sign in to comment.