ObjectUI.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. from gi.repository import Gtk
  2. import re
  3. from copy import copy
  4. from GUIElements import *
  5. class ObjectUI(Gtk.VBox):
  6. def __init__(self, icon_file='share/flatcam_icon32.png', title='FlatCAM Object'):
  7. Gtk.VBox.__init__(self, spacing=3, margin=5, vexpand=False)
  8. ## Page Title box (spacing between children)
  9. self.title_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 2)
  10. self.pack_start(self.title_box, expand=False, fill=False, padding=2)
  11. ## Page Title icon
  12. self.icon = Gtk.Image.new_from_file(icon_file)
  13. self.title_box.pack_start(self.icon, expand=False, fill=False, padding=2)
  14. ## Title label
  15. self.title_label = Gtk.Label()
  16. self.title_label.set_markup("<b>" + title + "</b>")
  17. self.title_label.set_justify(Gtk.Justification.CENTER)
  18. self.title_box.pack_start(self.title_label, expand=False, fill=False, padding=2)
  19. ## Object name
  20. self.name_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 2)
  21. self.pack_start(self.name_box, expand=True, fill=False, padding=2)
  22. name_label = Gtk.Label('Name:')
  23. name_label.set_justify(Gtk.Justification.RIGHT)
  24. self.name_box.pack_start(name_label,
  25. expand=False, fill=False, padding=2)
  26. self.name_entry = FCEntry()
  27. self.name_box.pack_start(self.name_entry, expand=True, fill=False, padding=2)
  28. ## Box box for custom widgets
  29. self.custom_box = Gtk.VBox(spacing=3, margin=0, vexpand=False)
  30. self.pack_start(self.custom_box, expand=False, fill=False, padding=0)
  31. ## Common to all objects
  32. ## Scale
  33. self.scale_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  34. self.scale_label.set_markup('<b>Scale:</b>')
  35. self.pack_start(self.scale_label, expand=True, fill=False, padding=2)
  36. grid5 = Gtk.Grid(column_spacing=3, row_spacing=2)
  37. self.pack_start(grid5, expand=True, fill=False, padding=2)
  38. # Factor
  39. l10 = Gtk.Label('Factor:', xalign=1)
  40. grid5.attach(l10, 0, 0, 1, 1)
  41. self.scale_entry = FloatEntry()
  42. self.scale_entry.set_text("1.0")
  43. grid5.attach(self.scale_entry, 1, 0, 1, 1)
  44. # GO Button
  45. self.scale_button = Gtk.Button(label='Scale')
  46. self.pack_start(self.scale_button, expand=True, fill=False, padding=2)
  47. ## Offset
  48. self.offset_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  49. self.offset_label.set_markup('<b>Offset:</b>')
  50. self.pack_start(self.offset_label, expand=True, fill=False, padding=2)
  51. grid6 = Gtk.Grid(column_spacing=3, row_spacing=2)
  52. self.pack_start(grid6, expand=True, fill=False, padding=2)
  53. # Vector
  54. l11 = Gtk.Label('Offset Vector:', xalign=1)
  55. grid6.attach(l11, 0, 0, 1, 1)
  56. self.offsetvector_entry = FCEntry()
  57. self.offsetvector_entry.set_text("(0.0, 0.0)")
  58. grid6.attach(self.offsetvector_entry, 1, 0, 1, 1)
  59. self.offset_button = Gtk.Button(label='Scale')
  60. self.pack_start(self.offset_button, expand=True, fill=False, padding=2)
  61. def set_field(self, name, value):
  62. getattr(self, name).set_value(value)
  63. def get_field(self, name):
  64. return getattr(self, name).get_value()
  65. class CNCObjectUI(ObjectUI):
  66. def __init__(self):
  67. ObjectUI.__init__(self, title='CNC Job Object', icon_file='share/cnc32.png')
  68. ## Plot options
  69. self.plot_options_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  70. self.plot_options_label.set_markup("<b>Plot Options:</b>")
  71. self.pack_start(self.plot_options_label, expand=False, fill=True, padding=2)
  72. grid0 = Gtk.Grid(column_spacing=3, row_spacing=2)
  73. self.pack_start(grid0, expand=True, fill=False, padding=2)
  74. # Plot CB
  75. self.plot_cb = FCCheckBox(label='Plot')
  76. grid0.attach(self.plot_cb, 0, 0, 2, 1)
  77. # Tool dia for plot
  78. l1 = Gtk.Label('Tool dia:', xalign=1)
  79. grid0.attach(l1, 0, 1, 1, 1)
  80. self.tooldia_entry = LengthEntry()
  81. grid0.attach(self.tooldia_entry, 1, 1, 1, 1)
  82. # Update plot button
  83. self.updateplot_button = Gtk.Button(label='Update Plot')
  84. self.pack_start(self.updateplot_button, expand=True, fill=False, padding=2)
  85. ## Export G-Code
  86. self.export_gcode_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  87. self.export_gcode_label.set_markup("<b>Export G-Code:</b>")
  88. self.pack_start(self.export_gcode_label, expand=True, fill=False, padding=2)
  89. # GO Button
  90. self.export_gcode_button = Gtk.Button(label='Export G-Code')
  91. self.pack_start(self.export_gcode_button, expand=True, fill=False, padding=2)
  92. class GeometryObjectUI(ObjectUI):
  93. def __init__(self):
  94. ObjectUI.__init__(self, title='Geometry Object', icon_file='share/geometry32.png')
  95. ## Plot options
  96. self.plot_options_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  97. self.plot_options_label.set_markup("<b>Plot Options:</b>")
  98. self.custom_box.pack_start(self.plot_options_label, expand=False, fill=True, padding=2)
  99. grid0 = Gtk.Grid(column_spacing=3, row_spacing=2)
  100. self.custom_box.pack_start(grid0, expand=True, fill=False, padding=2)
  101. # Plot CB
  102. self.plot_cb = FCCheckBox(label='Plot')
  103. grid0.attach(self.plot_cb, 0, 0, 1, 1)
  104. ## Create CNC Job
  105. self.cncjob_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  106. self.cncjob_label.set_markup('<b>Create CNC Job:</b>')
  107. self.custom_box.pack_start(self.cncjob_label, expand=True, fill=False, padding=2)
  108. grid1 = Gtk.Grid(column_spacing=3, row_spacing=2)
  109. self.custom_box.pack_start(grid1, expand=True, fill=False, padding=2)
  110. # Cut Z
  111. l1 = Gtk.Label('Cut Z:', xalign=1)
  112. grid1.attach(l1, 0, 0, 1, 1)
  113. self.cutz_entry = LengthEntry()
  114. grid1.attach(self.cutz_entry, 1, 0, 1, 1)
  115. # Travel Z
  116. l2 = Gtk.Label('Travel Z:', xalign=1)
  117. grid1.attach(l2, 0, 1, 1, 1)
  118. self.travelz_entry = LengthEntry()
  119. grid1.attach(self.travelz_entry, 1, 1, 1, 1)
  120. l3 = Gtk.Label('Feed rate:', xalign=1)
  121. grid1.attach(l3, 0, 2, 1, 1)
  122. self.cncfeedrate_entry = LengthEntry()
  123. grid1.attach(self.cncfeedrate_entry, 1, 2, 1, 1)
  124. l4 = Gtk.Label('Tool dia:', xalign=1)
  125. grid1.attach(l4, 0, 3, 1, 1)
  126. self.cnctooldia_entry = LengthEntry()
  127. grid1.attach(self.cnctooldia_entry, 1, 3, 1, 1)
  128. self.generate_cnc_button = Gtk.Button(label='Generate')
  129. self.custom_box.pack_start(self.generate_cnc_button, expand=True, fill=False, padding=2)
  130. ## Paint Area
  131. self.paint_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  132. self.paint_label.set_markup('<b>Paint Area:</b>')
  133. self.custom_box.pack_start(self.paint_label, expand=True, fill=False, padding=2)
  134. grid2 = Gtk.Grid(column_spacing=3, row_spacing=2)
  135. self.custom_box.pack_start(grid2, expand=True, fill=False, padding=2)
  136. # Tool dia
  137. l5 = Gtk.Label('Tool dia:', xalign=1)
  138. grid2.attach(l5, 0, 0, 1, 1)
  139. self.painttooldia_entry = LengthEntry()
  140. grid2.attach(self.painttooldia_entry, 1, 0, 1, 1)
  141. # Overlap
  142. l6 = Gtk.Label('Overlap:', xalign=1)
  143. grid2.attach(l6, 0, 1, 1, 1)
  144. self.paintoverlap_entry = LengthEntry()
  145. grid2.attach(self.paintoverlap_entry, 1, 1, 1, 1)
  146. # Margin
  147. l7 = Gtk.Label('Margin:', xalign=1)
  148. grid2.attach(l7, 0, 2, 1, 1)
  149. self.paintmargin_entry = LengthEntry()
  150. grid2.attach(self.paintmargin_entry, 1, 2, 1, 1)
  151. # GO Button
  152. self.generate_paint_button = Gtk.Button(label='Generate')
  153. self.custom_box.pack_start(self.generate_paint_button, expand=True, fill=False, padding=2)
  154. class ExcellonObjectUI(ObjectUI):
  155. def __init__(self):
  156. ObjectUI.__init__(self, title='Excellon Object', icon_file='share/drill32.png')
  157. ## Plot options
  158. self.plot_options_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  159. self.plot_options_label.set_markup("<b>Plot Options:</b>")
  160. self.custom_box.pack_start(self.plot_options_label, expand=False, fill=True, padding=2)
  161. grid0 = Gtk.Grid(column_spacing=3, row_spacing=2)
  162. self.custom_box.pack_start(grid0, expand=True, fill=False, padding=2)
  163. self.plot_cb = FCCheckBox(label='Plot')
  164. grid0.attach(self.plot_cb, 0, 0, 1, 1)
  165. self.solid_cb = FCCheckBox(label='Solid')
  166. grid0.attach(self.solid_cb, 1, 0, 1, 1)
  167. ## Create CNC Job
  168. self.cncjob_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  169. self.cncjob_label.set_markup('<b>Create CNC Job</b>')
  170. self.custom_box.pack_start(self.cncjob_label, expand=True, fill=False, padding=2)
  171. grid1 = Gtk.Grid(column_spacing=3, row_spacing=2)
  172. self.custom_box.pack_start(grid1, expand=True, fill=False, padding=2)
  173. l1 = Gtk.Label('Cut Z:', xalign=1)
  174. grid1.attach(l1, 0, 0, 1, 1)
  175. self.cutz_entry = LengthEntry()
  176. grid1.attach(self.cutz_entry, 1, 0, 1, 1)
  177. l2 = Gtk.Label('Travel Z:', xalign=1)
  178. grid1.attach(l2, 0, 1, 1, 1)
  179. self.travelz_entry = LengthEntry()
  180. grid1.attach(self.travelz_entry, 1, 1, 1, 1)
  181. l3 = Gtk.Label('Feed rate:', xalign=1)
  182. grid1.attach(l3, 0, 2, 1, 1)
  183. self.feedrate_entry = LengthEntry()
  184. grid1.attach(self.feedrate_entry, 1, 2, 1, 1)
  185. l4 = Gtk.Label('Tools:', xalign=1)
  186. grid1.attach(l4, 0, 3, 1, 1)
  187. boxt = Gtk.Box()
  188. grid1.attach(boxt, 1, 3, 1, 1)
  189. self.tools_entry = FCEntry()
  190. boxt.pack_start(self.tools_entry, expand=True, fill=False, padding=2)
  191. self.choose_tools_button = Gtk.Button(label='Choose...')
  192. boxt.pack_start(self.choose_tools_button, expand=True, fill=False, padding=2)
  193. self.generate_cnc_button = Gtk.Button(label='Generate')
  194. self.custom_box.pack_start(self.generate_cnc_button, expand=True, fill=False, padding=2)
  195. class GerberObjectUI(ObjectUI):
  196. def __init__(self):
  197. ObjectUI.__init__(self, title='Gerber Object')
  198. ## Plot options
  199. self.plot_options_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  200. self.plot_options_label.set_markup("<b>Plot Options:</b>")
  201. self.custom_box.pack_start(self.plot_options_label, expand=False, fill=True, padding=2)
  202. grid0 = Gtk.Grid(column_spacing=3, row_spacing=2)
  203. self.custom_box.pack_start(grid0, expand=True, fill=False, padding=2)
  204. # Plot CB
  205. self.plot_cb = FCCheckBox(label='Plot')
  206. grid0.attach(self.plot_cb, 0, 0, 1, 1)
  207. # Solid CB
  208. self.solid_cb = FCCheckBox(label='Solid')
  209. grid0.attach(self.solid_cb, 1, 0, 1, 1)
  210. # Multicolored CB
  211. self.multicolored_cb = FCCheckBox(label='Multicolored')
  212. grid0.attach(self.multicolored_cb, 2, 0, 1, 1)
  213. ## Isolation Routing
  214. self.isolation_routing_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  215. self.isolation_routing_label.set_markup("<b>Isolation Routing:</b>")
  216. self.custom_box.pack_start(self.isolation_routing_label, expand=True, fill=False, padding=2)
  217. grid = Gtk.Grid(column_spacing=3, row_spacing=2)
  218. self.custom_box.pack_start(grid, expand=True, fill=False, padding=2)
  219. l1 = Gtk.Label('Tool diam:', xalign=1)
  220. grid.attach(l1, 0, 0, 1, 1)
  221. self.iso_tool_dia_entry = LengthEntry()
  222. grid.attach(self.iso_tool_dia_entry, 1, 0, 1, 1)
  223. l2 = Gtk.Label('Width (# passes):', xalign=1)
  224. grid.attach(l2, 0, 1, 1, 1)
  225. self.iso_width_entry = IntEntry()
  226. grid.attach(self.iso_width_entry, 1, 1, 1, 1)
  227. l3 = Gtk.Label('Pass overlap:', xalign=1)
  228. grid.attach(l3, 0, 2, 1, 1)
  229. self.iso_overlap_entry = FloatEntry()
  230. grid.attach(self.iso_overlap_entry, 1, 2, 1, 1)
  231. self.generate_iso_button = Gtk.Button(label='Generate Geometry')
  232. self.custom_box.pack_start(self.generate_iso_button, expand=True, fill=False, padding=2)
  233. ## Board cuttout
  234. self.isolation_routing_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  235. self.isolation_routing_label.set_markup("<b>Board cutout:</b>")
  236. self.custom_box.pack_start(self.isolation_routing_label, expand=True, fill=False, padding=2)
  237. grid2 = Gtk.Grid(column_spacing=3, row_spacing=2)
  238. self.custom_box.pack_start(grid2, expand=True, fill=False, padding=2)
  239. l4 = Gtk.Label('Tool dia:', xalign=1)
  240. grid2.attach(l4, 0, 0, 1, 1)
  241. self.cutout_tooldia_entry = LengthEntry()
  242. grid2.attach(self.cutout_tooldia_entry, 1, 0, 1, 1)
  243. l5 = Gtk.Label('Margin:', xalign=1)
  244. grid2.attach(l5, 0, 1, 1, 1)
  245. self.cutout_margin_entry = LengthEntry()
  246. grid2.attach(self.cutout_margin_entry, 1, 1, 1, 1)
  247. l6 = Gtk.Label('Gap size:', xalign=1)
  248. grid2.attach(l6, 0, 2, 1, 1)
  249. self.cutout_gap_entry = LengthEntry()
  250. grid2.attach(self.cutout_gap_entry, 1, 2, 1, 1)
  251. l7 = Gtk.Label('Gaps:', xalign=1)
  252. grid2.attach(l7, 0, 3, 1, 1)
  253. self.gaps_radio = RadioSet([{'label': '2 (T/B)', 'value': 'tb'},
  254. {'label': '2 (L/R)', 'value': 'lr'},
  255. {'label': '4', 'value': '4'}])
  256. grid2.attach(self.gaps_radio, 1, 3, 1, 1)
  257. self.generate_cutout_button = Gtk.Button(label='Generate Geometry')
  258. self.custom_box.pack_start(self.generate_cutout_button, expand=True, fill=False, padding=2)
  259. ## Non-copper regions
  260. self.noncopper_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  261. self.noncopper_label.set_markup("<b>Non-copper regions:</b>")
  262. self.custom_box.pack_start(self.noncopper_label, expand=True, fill=False, padding=2)
  263. grid3 = Gtk.Grid(column_spacing=3, row_spacing=2)
  264. self.custom_box.pack_start(grid3, expand=True, fill=False, padding=2)
  265. l8 = Gtk.Label('Boundary margin:', xalign=1)
  266. grid3.attach(l8, 0, 0, 1, 1)
  267. self.noncopper_margin_entry = LengthEntry()
  268. grid3.attach(self.noncopper_margin_entry, 1, 0, 1, 1)
  269. self.noncopper_rounded_cb = FCCheckBox(label="Rounded corners")
  270. grid3.attach(self.noncopper_rounded_cb, 0, 1, 2, 1)
  271. self.generate_noncopper_button = Gtk.Button(label='Generate Geometry')
  272. self.custom_box.pack_start(self.generate_noncopper_button, expand=True, fill=False, padding=2)
  273. ## Bounding box
  274. self.boundingbox_label = Gtk.Label(justify=Gtk.Justification.LEFT, xalign=0, margin_top=5)
  275. self.boundingbox_label.set_markup('<b>Bounding Box:</b>')
  276. self.custom_box.pack_start(self.boundingbox_label, expand=True, fill=False, padding=2)
  277. grid4 = Gtk.Grid(column_spacing=3, row_spacing=2)
  278. self.custom_box.pack_start(grid4, expand=True, fill=False, padding=2)
  279. l9 = Gtk.Label('Boundary Margin:', xalign=1)
  280. grid4.attach(l9, 0, 0, 1, 1)
  281. self.bbmargin_entry = LengthEntry()
  282. grid4.attach(self.bbmargin_entry, 1, 0, 1, 1)
  283. self.bbrounded_cb = FCCheckBox(label="Rounded corners")
  284. grid4.attach(self.bbrounded_cb, 0, 1, 2, 1)
  285. self.generate_bb_button = Gtk.Button(label='Generate Geometry')
  286. self.custom_box.pack_start(self.generate_bb_button, expand=True, fill=False, padding=2)