Fix bug 1368: Layer linetype patterns are empty when using custom lay… #1369
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug description
When rendering a DXF document with the drawing addon's Frontend class and passing a custom layout properties parameter to the draw_layout method, entities with linetype set to "BYLAYER" (or no explicit linetype attribute, which defaults to "BYLAYER") are rendered as solid lines instead of using their layer's linetype pattern (dashes, dots, etc.).
This happens because of an initialization order bug in the RenderContext class:
During RenderContext initialization, the method that sets up the current layout is called before the line patterns are loaded from the document's linetype table
When layers are initialized and their properties are resolved, the line pattern dictionary is still empty, so all layers get cached with an empty continuous pattern (empty tuple)
When Frontend's draw_layout method receives a custom layout properties parameter, it skips calling the layout setup method again (which would re-cache the layers with correct patterns)
Entities that use BYLAYER linetype resolution inherit the empty patterns from the cached layer properties
The bug does NOT occur when:
The layout properties parameter is NOT passed to draw_layout (Frontend calls the layout setup method again, re-caching layers with correct patterns after line patterns are loaded)
Entities have explicit linetype attributes set directly (bypasses BYLAYER resolution and looks up patterns directly)
Fix
Call
_load_line_patternbeforeself.set_current_layoutin the__init__ofRenderContext.Added a unit test and verified the other tests passed.