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

[Enhance] can provide pure draw shape api for third api to draw? #334

Open
jekoie opened this issue Nov 9, 2024 · 5 comments
Open

[Enhance] can provide pure draw shape api for third api to draw? #334

jekoie opened this issue Nov 9, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request gerber-builder Issue related to one of the code builders virtual-machine Issue related to pygerber.vm package

Comments

@jekoie
Copy link

jekoie commented Nov 9, 2024

I notes that RVMC.commands decompose the shape to Line and Arc, just two shape.The raw gerber file have mang shapes like Line, Rectangle, Obround, Polygon, Arc, Circle and Primitives(AM commands).
So can you provide basis geometry shape api, for that i can draw and manipulate the shape item by myself, not just a pictuer.For example draw gerber on pycairo, Qt, tkinter and so on.

@jekoie jekoie added bug Something isn't working virtual-machine Issue related to pygerber.vm package waiting-for-checkboxes Issue is waiting for reporter to check all relevant checkboxes in issue template labels Nov 9, 2024
@Argmaster
Copy link
Owner

Argmaster commented Nov 9, 2024

Hi,

Even though Gerber provides finite set of basic shapes, it becomes nontrivial to implement them when we take into account transformations with different origins they have to support. This would require a lot of code to handle individual shapes separately if you can even figure it all out considering how tricky composed transformations can get. With line/arc approach, everything is much more viable to implement and extend in the future, since everything is a collection of points.

With that said, If you want to create image or gerber file, please look into builder APIs, If you want to modify exiting code, you will probably need to wait for optimizer API to handle modification on existing files at Gerber AST level. This one is tricky, as it may appear that modifying Gerber file is as trivial as adding single draw wherever we feel like, but since Gerber is stateful, you have to always account for changes in state you have to do and undo to achieve shape with desired properties.

If you want to implement rendering of Gerber files with different tools, like pycairo you have mentioned, the intended way is to create class deriving from VirtualMachine similarily to how PillowVirtualMachine works and implement drawing of shapes form series of lines and arcs. You would still need to handle it even if everything was based on Gerber shapes, as there are things like regions and outline primitives with require you to draw arbitrary shapes from series of points.

In the future I will be looking into providing AST walking with hooks for more abstract concepts like shapes etc instead of individual AST node, but research has to be done here first.

@Argmaster Argmaster added enhancement New feature or request gerber-builder Issue related to one of the code builders and removed bug Something isn't working waiting-for-checkboxes Issue is waiting for reporter to check all relevant checkboxes in issue template labels Nov 9, 2024
@Argmaster
Copy link
Owner

Hello, I tried to fix the issue

This is what I did:

Add new shape types (Rectangle, Obround, Polygon, Circle) and modify the Shape class to support these new types. Also, add a new method to Shape class for drawing on different backends.

I also created pull request: #335

[!CAUTION]
Disclaimer: This fix was created by Latta AI and you should never merge before you check the correctness of generated code!

The fix provided by Latta AI might not be complete and it can serve as an inspiration.


This bug was fixed for free by Latta AI - https://latta.ai/ourmission

If you no longer want Latta AI to attempt fixing issues on your repository, you can block this account.

Useless blob of code you have made, neither it solves the issues nor it works.

@Argmaster
Copy link
Owner

@jekoie I would appreciate feedback from you regarding this issue and my response 😄

@jekoie jekoie changed the title [Enhance] can provide provide pure draw shape api for third api to draw? [Enhance] can provide pure draw shape api for third api to draw? Nov 13, 2024
@jekoie
Copy link
Author

jekoie commented Nov 13, 2024

Only use points just use fitting method(like Taylor series), those points approximate a polygon, this will made draw method cost more time and slowly.

@Argmaster
Copy link
Owner

Ok, could you provide proof of concept for your request? Some basic code how would you incorporate in extisting source. Then we can follow up on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gerber-builder Issue related to one of the code builders virtual-machine Issue related to pygerber.vm package
Projects
None yet
Development

No branches or pull requests

3 participants
@jekoie @Argmaster and others