Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportStep does not respect unit #153

Closed
Steinblock opened this issue Jul 18, 2023 · 3 comments
Closed

ImportStep does not respect unit #153

Steinblock opened this issue Jul 18, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Steinblock
Copy link

I have a simple step file and CADability shows the width and height as 0.38 and 0.8.

image

However the part has been constructed in Autodesk Inventor 2023 and saved with unit meter. Other step viewers show the correct size of 380 and 800.

Here is the file for reference.

simple-part-mm.zip

@dsn27 dsn27 self-assigned this Sep 9, 2024
@dsn27 dsn27 added the bug Something isn't working label Sep 9, 2024
dsn27 added a commit that referenced this issue Sep 10, 2024
@dsn27
Copy link
Collaborator

dsn27 commented Sep 10, 2024

It seems like the unit is not read under all circumstances.
While there is code that is trying to figure out the units, this does not seem to work for this file.
e.g.

private double GetContextLengthFactor(Item item)
{
Item units = item.parameter["units"];
if (units != null && units.type == Item.ItemType.list)
{
foreach (Item it in units.val as List<Item>)
{
if (it.parameter.TryGetValue("conversion_factor", out Item cf))
{
if (cf.parameter.TryGetValue("value_component", out Item vc))
{
if (cf.type == Item.ItemType.lengthMeasureWithUnit && vc.val is List<Item> && (vc.val as List<Item>)[0].type == Item.ItemType.floatval)
{
double f = (vc.val as List<Item>)[0].fval;
if (cf.parameter.TryGetValue("unit_component", out Item uc))
{
}
return f; // * 1000; // why * 1000.0 ??? definitely wrong with AM3024-0x00.stp
}
}
}
}
}
return 1.0;
}

if (item.parameter.TryGetValue("units", out Item units) && units.type == Item.ItemType.list)
{
foreach (Item it in units.val as List<Item>)
{
if (it.parameter.TryGetValue("conversion_factor", out Item cf))
{
if (cf.parameter.TryGetValue("value_component", out Item vc))
{
if ((cf.type == Item.ItemType.planeAngleMeasure || cf.type == Item.ItemType.planeAngleMeasureWithUnit) && vc.val is List<Item> && (vc.val as List<Item>)[0].type == Item.ItemType.floatval)
context.toRadian = (double)(vc.val as List<Item>)[0].val;
if ((cf.type == Item.ItemType.positiveLengthMeasure || cf.type == Item.ItemType.lengthMeasureWithUnit) && vc.val is List<Item> && (vc.val as List<Item>)[0].type == Item.ItemType.floatval)
{
context.factor = (double)(vc.val as List<Item>)[0].val; // why * 1000 ? definitely wrong for 83855_elp11b.stp
if (it.parameter.TryGetValue("name", out Item name))
{
if (name.type == Item.ItemType.stringval && name.sval == "METRE") context.factor *= 1000; // added because of "PROBLEM ELE NULLPUNKT.stp"
}
}
}
}
}
}

dsn27 added a commit that referenced this issue Sep 11, 2024
@dsn27
Copy link
Collaborator

dsn27 commented Sep 11, 2024

The original code is looking for "conversion_factor" and "value_component" inside a Units Items.

But it looks like in issue153.stp the unit is available at top level and we just need to read it.

Remarks:
We should add support for other Units and check the old code.
Why is the factor always multiplied by 1000?
What happens if this code is called multiple times?

if (name.type == Item.ItemType.stringval && name.sval == "METRE") context.factor *= 1000; // added because of "PROBLEM ELE NULLPUNKT.stp"
}

We would need several STEP files that trigger this code path to check on this.

dsn27 added a commit that referenced this issue Sep 12, 2024
dsn27 added a commit that referenced this issue Sep 12, 2024
@dsn27
Copy link
Collaborator

dsn27 commented Sep 12, 2024

Closed by #182

@dsn27 dsn27 closed this as completed Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants