this is my new module, PureGerber. It allows you to view Gerber files in PureBasic (on a canvas or an image right now).
Right now, this module is not finished, but I wanted to allow you s sneak peak into its recent state. Only tested under Windows 7/10/11.
What is still missing:
- BlockMode is currently under development.
- Stepmode missing.
- Usage of variables missing (don't know if I will support this).
- Some deprecated functions are missing (don't know which of them I will include).
- Zooming on the GerberGadget uses 0,0 as origin and not the current mouse position.
Crappy demo usage:
- Drop Gerber file on the window to view it.
- Mousewheel to zoom.
- Hold left mouse button and move the mouse to move the picture.
- Right mouse button to reset position and zoom.
Useful links:
- Reference Gerber Viewer: https://gerber-viewer.ucamco.com/
- Gerber Layout Format Specification: https://www.ucamco.com/en/guest/downloads/gerber-format
Some important information:
- As stated, this module ins't complete yet.
- This modules uses VectorDrawing and RegEx.
- This module contains some "disabled" code. This is for future features and features under development.
Demo:
Code: Select all
EnableExplicit
XIncludeFile "PureGerber.pbi"
UseModule PureGerber
Runtime Enumeration Windows
#W_Main
EndEnumeration
Runtime Enumeration Gadgets
#G_Canvas
EndEnumeration
#D_Main =0
#XML = 0
Global *Gerber.Gerber,Temp$
Temp$="<window id='#W_Main' name='MainWindow' text='Gerbera' width='600' height='500' Minwidth='100' minheight='100' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget'>"+
"<canvas id='#G_Canvas' flags='#PB_Canvas_ClipMouse|#PB_Canvas_Keyboard'/>"+
"</window>"
ParseXML(#XML,Temp$)
CreateDialog(#D_Main)
OpenXMLDialog(#D_Main,#XML,"MainWindow")
SetWindowState(#W_Main,#PB_Window_Maximize)
EnableGadgetDrop(#G_Canvas,#PB_Drop_Files,#PB_Drag_Copy|#PB_Drag_Link|#PB_Drag_Move)
GerberGadget(#G_Canvas,0,0,0,0,*Gerber,#Gerber_Flag_Canvas)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_GadgetDrop
If IsGerber(*Gerber)
FreeGerber(*Gerber)
EndIf
*Gerber=CreateGerberDataFromFile(EventDropFiles())
CompilerIf #PB_Compiler_OS=#PB_OS_Windows
*Gerber\Colors\BackgroundColor=GetSysColor_(#COLOR_BTNFACE)
CompilerElse
*Gerber\Colors\BackgroundColor=#White
CompilerEndIf
*Gerber\Colors\ForegroundColor=#Black
*Gerber\FillMode=#Gerber_FillMode_Fill
AssignGerberToGadget(#G_Canvas,*Gerber)
SetWindowTitle(#W_Main,"Gerbera - "+*Gerber\FileName$)
If *Gerber=0 Or ListSize(*Gerber\Log\Errors())<>0
Temp$=*Gerber\FileName$+#CRLF$
ForEach *Gerber\Log\Errors()
Temp$+#CRLF$+*Gerber\Log\Errors()
Next
MessageRequester("Error list",Temp$,#PB_MessageRequester_Error)
EndIf
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_RightClick
Select EventGadget()
Case #G_Canvas
ResetGerberGadgetData(#G_Canvas)
EndSelect
EndSelect
EndSelect
ForEver

I will update this post and the following, when releasing updates. As much as I appreciate helping comments, please wait until it's feature complete, before helping me with optimizing it!
Update 20.09.2023:
Many improvements for the renderer. Unfortunately I realized that some things aren't rendered correctly (like too big circles). I'm on it, but maybe the renderer needs to be completely rewritten. I also added a mutex into the drawing functions, so it should be threadsafe, if only the internal functions are used. Maybe some more functions to set parameters are needed (so it will be completely threadsafe).
Update 18.10.2023:
All known bugs fixed. Optional caching function (which will be improved in the next version) which speeds up drawing a lot.
Update 20.10.2023:
All known bugs fixed. Caching enabled for both views.
Update 25.10.2023:
Another bugfix release.
Update 17.01.2024:
Bug fixes and added rotation to GerberGadget.
Update 27.01.2024:
BlockMode, SVG output, compatibility with all OS, bugfixes, optimizations.
More coming soon...
Download Gerber module form GitHub: https://github.com/jacdelad/PureGerber