Title: Problem with entity copying · Issue #380 · stepcode/stepcode · GitHub
Open Graph Title: Problem with entity copying · Issue #380 · stepcode/stepcode
X Title: Problem with entity copying · Issue #380 · stepcode/stepcode
Description: Part of my project involves merging parts of multiple STEP files into one. For now I basically want to merge their product shapes, eventually I will need to add various metadata to these products. However, even in the most simplified cas...
Open Graph Description: Part of my project involves merging parts of multiple STEP files into one. For now I basically want to merge their product shapes, eventually I will need to add various metadata to these products. ...
X Description: Part of my project involves merging parts of multiple STEP files into one. For now I basically want to merge their product shapes, eventually I will need to add various metadata to these products. ...
Opengraph URL: https://github.com/stepcode/stepcode/issues/380
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Problem with entity copying","articleBody":"Part of my project involves merging parts of multiple STEP files into one. For now I basically want to merge their product shapes, eventually I will need to add various metadata to these products.\r\n\r\nHowever, even in the most simplified case – taking a single STEP file and copying over only its `CARTESIAN_POINT` entities (AP242 / AP210e3), I get garbage data in the output roughly every 3-4 runs.\r\n\r\nI can try to produce a minimal example but perhaps it will be sufficient to list the core parts:\r\n\r\n 1. The STEP file is opened, similarly to how it is done in the minimal example.\r\n 2. All of the entities of its instance manager are iterated, and ones whose `EntityName()` matches an entry in the whitelist (so just `\"CARTESIAN_POINT\"`) are replicated using `entity->Replicate()` and added to a map mapping the original entity to the new one (`std::map\u003cSDAI_Application_instance *, SDAI_Application_instance *>`). Keep in mind I will need to make sure entity references are preserved after the STEP merge in the new file, so I need a structure to map the original entities to the new ones.\r\n 3. As far as I can tell, `entity->Replicate()` does a \"shallow\" copy so the attributes point to the exact same memory locations. Because of this I iterate all of the attributes of the entities and adding them to one of two queues. One is for all entity references (`std::queue\u003cSDAI_Application_instance *>`); the other is for all other types, which I stringify using `attr->asStr()` (`std::queue\u003cstd::string>`).\r\n 4. Then I iterate the new replicated entities and their origin's attributes (in the same order as before) so that I can set the attributes of the new entities by reading from the queues in the same order. Entity type attributes read from the first queue, all other read from the second queue and set the attribute value using `attr->StrToVal(strFromQueue)`.\r\n 5. The remapped entities are collected and all appended into the instance manager of a new STEP file, which then writes the output file.\r\n\r\nThe entity reference remapping actually seems to work fine, though it sounds more finicky. But in any case, in the minimal case of copying over only `CARTESIAN_POINT` instances, there are no entity references, since a `CARTESIAN_POINT` is just:\r\n\r\n```\r\nENTITY Cartesian_point\r\n SUBTYPE OF (Point);\r\n coordinates : LIST[1:3] OF length_measure;\r\nEND_ENTITY;\r\n\r\nENTITY Point\r\n ABSTRACT SUPERTYPE \r\n SUBTYPE OF (Detailed_geometric_model_element);\r\nEND_ENTITY;\r\n\r\nENTITY Detailed_geometric_model_element\r\n ABSTRACT SUPERTYPE OF (ONEOF (Direction,\r\n Axis_placement,\r\n Cartesian_transformation_2d,\r\n Cartesian_transformation_3d,\r\n Geometric_placement_operation))\r\n SUBTYPE OF (Representation_item);\r\nEND_ENTITY;\r\n\r\nENTITY Representation_item\r\n ABSTRACT SUPERTYPE ;\r\n name : OPTIONAL label;\r\nEND_ENTITY;\r\n```\r\n\r\nSo `#1 = CARTESIAN_POINT('', (0.1, 0.2, 0.3));` is a valid instance.\r\n\r\nAm I doing something wrong when restoring the primitive types? Should I do some string copies before adding the result of `asStr()` or before giving a string to `StrToVal()`? As far as I can tell, `STEPattribute` does not store / cache its string representation and `asStr()` seems to create a string using a `std::stringstream`.\r\n\r\nThe concrete case I'm testing is an input file with 256 `CARTESIAN_POINT`s, all of which have a `name` either `''` or `'Origin'` (none of them have `$` in their `name`). When the copy goes wrong, I can see some `CARTESIAN_POINT`s with `$` or even garbage data that is not even valid STEP:\r\n\r\n\r\n\r\nAny ideas? Should I try to reproduce the issue with a minimal example code?\r\n\r\nEdit: One more thing – during the execution of the copy, I do a debug trace of the string values that are passed to `StrToVal()`. They are all either `''` or `'Origin'`, as expected from the source file. This seems to suggest that the string data gets corrupted later.","author":{"url":"https://github.com/AureaNoire","@type":"Person","name":"AureaNoire"},"datePublished":"2018-09-10T14:40:03Z","url":"https://github.com/stepcode/stepcode/issues/380"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:492c0c7a-66e3-f4ed-5978-9fadf9dc2767 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9E2:D7239:1AEBDB:26129A:6B0467D8 |
| html-safe-nonce | c8946bbdc8ff5e32e789098755c913973e5a78669c8ee5797de386e5cca4196e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUUyOkQ3MjM5OjFBRUJEQjoyNjEyOUE6NkIwNDY3RDgiLCJ2aXNpdG9yX2lkIjoiMzc5MzgyOTUzODc0MDU5NDY0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 201de55349ec505b669859329685288a88fb439c8074cfcaf95306025b059aa7 |
| hovercard-subject-tag | issue:358654353 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/stepcode/stepcode/380/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ccd21f008c99ec1d700dc3745ed8ad85030a290ac417e7b36b91fe7720cc69b/stepcode/stepcode/issues/380 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ccd21f008c99ec1d700dc3745ed8ad85030a290ac417e7b36b91fe7720cc69b/stepcode/stepcode/issues/380 |
| og:image:alt | Part of my project involves merging parts of multiple STEP files into one. For now I basically want to merge their product shapes, eventually I will need to add various metadata to these products. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AureaNoire |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/stepcode/stepcode git https://github.com/stepcode/stepcode.git |
| octolytics-dimension-user_id | 1761770 |
| octolytics-dimension-user_login | stepcode |
| octolytics-dimension-repository_id | 1975387 |
| octolytics-dimension-repository_nwo | stepcode/stepcode |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1975387 |
| octolytics-dimension-repository_network_root_nwo | stepcode/stepcode |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width