ObjectUI.py 16 KB

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