meerk40t / meerk40t

Hackable Laser software for K40 / GRBL / Fibre Lasers
MIT License
233 stars 62 forks source link

Fix delayed tree item label update for break subpath #2695

Closed jpirnay closed 1 week ago

jpirnay commented 1 week ago

Resolves issues #2692

Summary by Sourcery

Fix the delayed update of tree item labels when breaking subpaths by emitting the appropriate signal and refactor node attribute handling for clarity.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This PR fixes an issue with delayed tree item label updates for break subpath operations. The implementation changes how node attributes are stored and handled during subpath creation, switching from a list-based to a dictionary-based approach. It also adds proper attribute initialization during subnode creation and implements element property reload signaling for affected groups.

Sequence diagram for element subpath processing

sequenceDiagram
    participant User
    participant System
    participant Node
    participant GroupNode
    participant SubNode

    User->>System: Initiate element_subpath
    System->>Node: Iterate over data nodes
    Node->>System: Provide node attributes
    System->>GroupNode: Replace node with group node
    System->>Node: Check for final_geometry
    Node-->>System: Return geometry
    System->>System: Iterate over subpaths
    System->>SubNode: Add subnode with attributes
    System->>System: Append subnode to elems
    System->>GroupNode: Append group node to elements_nodes
    System->>System: Signal element_property_reload
    System->>User: Return elements and nodes

Updated class diagram for node attribute handling

classDiagram
    class Node {
        -label: String
        -attributes: Dict
        +replace_node(type, label)
        +final_geometry()
    }
    class GroupNode {
        +add(geometry, type, label, stroke, fill)
    }
    class SubNode {
        +setattr(key, value)
    }
    Node --> GroupNode : replace_node
    GroupNode --> SubNode : add
    SubNode --> Node : setattr

File-Level Changes

Change Details Files
Refactored node attributes storage from list to dictionary
  • Changed node_attributes from list to dictionary structure
  • Updated attribute storage to use key-value pairs instead of list entries
meerk40t/core/elements/branches.py
Enhanced subnode creation with direct attribute initialization
  • Added direct stroke and fill attribute initialization in subnode creation
  • Improved attribute assignment using dictionary get() method with None fallback
meerk40t/core/elements/branches.py
Added group tracking and property reload signaling
  • Introduced groups list to track created group nodes
  • Added element_property_reload signal emission for created groups
meerk40t/core/elements/branches.py

Possibly linked issues


Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).