defaults.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. import os
  2. import stat
  3. import sys
  4. from copy import deepcopy
  5. from Common import LoudDict
  6. from camlib import to_dict, CNCjob, Geometry
  7. import simplejson
  8. import logging
  9. import gettext
  10. import appTranslation as fcTranslate
  11. import builtins
  12. from appParsers.ParseExcellon import Excellon
  13. from appParsers.ParseGerber import Gerber
  14. fcTranslate.apply_language('strings')
  15. if '_' not in builtins.__dict__:
  16. _ = gettext.gettext
  17. log = logging.getLogger('FlatCAMDefaults')
  18. class FlatCAMDefaults:
  19. factory_defaults = {
  20. # Global
  21. "version": 8.992, # defaults format version, not necessarily equal to app version
  22. "first_run": True,
  23. "root_folder_path": '',
  24. "global_serial": 0,
  25. "global_stats": dict(),
  26. "global_tabs_detachable": True,
  27. "global_coords_show": True,
  28. "global_delta_coords_show": False,
  29. "global_grid_show": True,
  30. "global_status_show": True,
  31. "global_jump_ref": 'abs',
  32. "global_locate_pt": 'bl',
  33. "global_toolbar_view": 511,
  34. "global_background_timeout": 300000, # Default value is 5 minutes
  35. "global_verbose_error_level": 0, # Shell verbosity 0 = default
  36. # (python trace only for unknown errors),
  37. # 1 = show trace(show trace always),
  38. # 2 = (For the future).
  39. "global_grid_context_menu": {
  40. 'in': [0.01, 0.02, 0.025, 0.05, 0.1],
  41. 'mm': [0.1, 0.2, 0.5, 1, 2.54]
  42. },
  43. "global_hud": True,
  44. # Persistence
  45. "global_last_folder": None,
  46. "global_last_save_folder": None,
  47. # Default window geometry
  48. "global_def_win_x": 100,
  49. "global_def_win_y": 100,
  50. "global_def_win_w": 1024,
  51. "global_def_win_h": 650,
  52. "global_def_notebook_width": 1,
  53. # Constants...
  54. "global_defaults_save_period_ms": 20000, # Time between default saves.
  55. "global_shell_shape": [500, 300], # Shape of the shell in pixels.
  56. "global_recent_limit": 10, # Max. items in recent list.
  57. "fit_key": 'V',
  58. "zoom_out_key": '-',
  59. "zoom_in_key": '=',
  60. "grid_toggle_key": 'G',
  61. "global_zoom_ratio": 1.5,
  62. "global_point_clipboard_format": "(%.*f, %.*f)",
  63. "global_zdownrate": None,
  64. "global_tcl_path": '',
  65. # General APP Preferences
  66. "units": "MM",
  67. "decimals_inch": 4,
  68. "decimals_metric": 4,
  69. "global_graphic_engine": '3D',
  70. "global_app_level": 'b',
  71. "global_portable": False,
  72. "global_language": 'English',
  73. "global_systray_icon": True,
  74. "global_shell_at_startup": False, # Show the shell at startup.
  75. "global_project_at_startup": False,
  76. "global_version_check": True,
  77. "global_send_stats": True,
  78. "global_worker_number": 2,
  79. "global_tolerance": 0.005,
  80. "global_save_compressed": True,
  81. "global_compression_level": 3,
  82. "global_autosave": False,
  83. "global_autosave_timeout": 300000,
  84. "global_tpdf_tmargin": 15.0,
  85. "global_tpdf_bmargin": 10.0,
  86. "global_tpdf_lmargin": 20.0,
  87. "global_tpdf_rmargin": 20.0,
  88. # General GUI Preferences
  89. "global_theme": 'white',
  90. "global_gray_icons": False,
  91. "global_layout": "compact",
  92. "global_hover": False,
  93. "global_selection_shape": True,
  94. "global_sel_fill": '#a5a5ffbf',
  95. "global_sel_line": '#0000ffbf',
  96. "global_alt_sel_fill": '#BBF268BF',
  97. "global_alt_sel_line": '#006E20BF',
  98. "global_draw_color": '#FF0000',
  99. "global_sel_draw_color": '#0000FF',
  100. "global_proj_item_color": '#000000',
  101. "global_proj_item_dis_color": '#b7b7cb',
  102. "global_project_autohide": True,
  103. # General App Settings
  104. "global_gridx": 1.0,
  105. "global_gridy": 1.0,
  106. "global_snap_max": 0.05,
  107. "global_workspace": False,
  108. "global_workspaceT": "A4",
  109. "global_workspace_orientation": 'p',
  110. "global_cursor_type": "small",
  111. "global_cursor_size": 20,
  112. "global_cursor_width": 2,
  113. "global_cursor_color": '#FF0000',
  114. "global_cursor_color_enabled": True,
  115. "global_pan_button": '2',
  116. "global_mselect_key": 'Control',
  117. "global_delete_confirmation": True,
  118. "global_allow_edit_in_project_tab": False,
  119. "global_open_style": True,
  120. "global_toggle_tooltips": True,
  121. "global_machinist_setting": False,
  122. "global_bookmarks": dict(),
  123. "global_bookmarks_limit": 10,
  124. "global_activity_icon": 'Ball green',
  125. # Gerber General
  126. "gerber_plot": True,
  127. "gerber_solid": True,
  128. "gerber_multicolored": False,
  129. "gerber_circle_steps": 64,
  130. "gerber_use_buffer_for_union": True,
  131. "gerber_clean_apertures": True,
  132. "gerber_extra_buffering": True,
  133. "gerber_plot_fill": '#BBF268BF',
  134. "gerber_plot_line": '#006E20BF',
  135. "gerber_def_units": 'IN',
  136. "gerber_def_zeros": 'L',
  137. "gerber_save_filters": "Gerber File .gbr (*.gbr);;Gerber File .bot (*.bot);;Gerber File .bsm (*.bsm);;"
  138. "Gerber File .cmp (*.cmp);;Gerber File .crc (*.crc);;Gerber File .crs (*.crs);;"
  139. "Gerber File .gb0 (*.gb0);;Gerber File .gb1 (*.gb1);;Gerber File .gb2 (*.gb2);;"
  140. "Gerber File .gb3 (*.gb3);;Gerber File .gb4 (*.gb4);;Gerber File .gb5 (*.gb5);;"
  141. "Gerber File .gb6 (*.gb6);;Gerber File .gb7 (*.gb7);;Gerber File .gb8 (*.gb8);;"
  142. "Gerber File .gb9 (*.gb9);;Gerber File .gbd (*.gbd);;Gerber File .gbl (*.gbl);;"
  143. "Gerber File .gbo (*.gbo);;Gerber File .gbp (*.gbp);;Gerber File .gbs (*.gbs);;"
  144. "Gerber File .gdo (*.gdo);;Gerber File .ger (*.ger);;Gerber File .gko (*.gko);;"
  145. "Gerber File .gm1 (*.gm1);;Gerber File .gm2 (*.gm2);;Gerber File .gm3 (*.gm3);;"
  146. "Gerber File .grb (*.grb);;Gerber File .gtl (*.gtl);;Gerber File .gto (*.gto);;"
  147. "Gerber File .gtp (*.gtp);;Gerber File .gts (*.gts);;Gerber File .ly15 (*.ly15);;"
  148. "Gerber File .ly2 (*.ly2);;Gerber File .mil (*.mil);;"
  149. "Gerber File .outline (*.outline);;Gerber File .pho (*.pho);;"
  150. "Gerber File .plc (*.plc);;Gerber File .pls (*.pls);;Gerber File .smb (*.smb);;"
  151. "Gerber File .smt (*.smt);;Gerber File .sol (*.sol);;Gerber File .spb (*.spb);;"
  152. "Gerber File .spt (*.spt);;Gerber File .ssb (*.ssb);;Gerber File .sst (*.sst);;"
  153. "Gerber File .stc (*.stc);;Gerber File .sts (*.sts);;Gerber File .top (*.top);;"
  154. "Gerber File .tsm (*.tsm);;Gerber File .art (*.art)"
  155. "All Files (*.*)",
  156. # Gerber Options
  157. "gerber_noncoppermargin": 0.1,
  158. "gerber_noncopperrounded": False,
  159. "gerber_bboxmargin": 0.1,
  160. "gerber_bboxrounded": False,
  161. # Gerber Advanced Options
  162. "gerber_aperture_display": False,
  163. "gerber_aperture_scale_factor": 1.0,
  164. "gerber_aperture_buffer_factor": 0.0,
  165. "gerber_follow": False,
  166. "gerber_buffering": "full",
  167. "gerber_delayed_buffering": True,
  168. "gerber_simplification": False,
  169. "gerber_simp_tolerance": 0.0005,
  170. # Gerber Export
  171. "gerber_exp_units": 'IN',
  172. "gerber_exp_integer": 2,
  173. "gerber_exp_decimals": 4,
  174. "gerber_exp_zeros": 'L',
  175. # Gerber Editor
  176. "gerber_editor_sel_limit": 30,
  177. "gerber_editor_newcode": 10,
  178. "gerber_editor_newsize": 0.8,
  179. "gerber_editor_newtype": 'C',
  180. "gerber_editor_newdim": "0.5, 0.5",
  181. "gerber_editor_array_size": 5,
  182. "gerber_editor_lin_axis": 'X',
  183. "gerber_editor_lin_pitch": 0.1,
  184. "gerber_editor_lin_angle": 0.0,
  185. "gerber_editor_circ_dir": 'CW',
  186. "gerber_editor_circ_angle": 0.0,
  187. "gerber_editor_scale_f": 1.0,
  188. "gerber_editor_buff_f": 0.1,
  189. "gerber_editor_ma_low": 0.0,
  190. "gerber_editor_ma_high": 1.0,
  191. # Excellon General
  192. "excellon_plot": True,
  193. "excellon_solid": True,
  194. "excellon_multicolored": False,
  195. "excellon_merge_fuse_tools": True,
  196. "excellon_format_upper_in": 2,
  197. "excellon_format_lower_in": 4,
  198. "excellon_format_upper_mm": 3,
  199. "excellon_format_lower_mm": 3,
  200. "excellon_zeros": "T",
  201. "excellon_units": "INCH",
  202. "excellon_update": True,
  203. "excellon_optimization_type": 'B',
  204. "excellon_search_time": 3,
  205. "excellon_save_filters": "Excellon File .txt (*.txt);;Excellon File .drd (*.drd);;"
  206. "Excellon File .drill (*.drill);;"
  207. "Excellon File .drl (*.drl);;Excellon File .exc (*.exc);;"
  208. "Excellon File .ncd (*.ncd);;Excellon File .tap (*.tap);;"
  209. "Excellon File .xln (*.xln);;All Files (*.*)",
  210. "excellon_plot_fill": '#C40000BF',
  211. "excellon_plot_line": '#750000BF',
  212. # Excellon Options
  213. "excellon_operation": "drill",
  214. "excellon_tool_order": 'no',
  215. "excellon_milling_type": "drills",
  216. "excellon_milling_dia": 0.8,
  217. "excellon_cutz": -1.7,
  218. "excellon_multidepth": False,
  219. "excellon_depthperpass": 0.7,
  220. "excellon_travelz": 2,
  221. "excellon_endz": 0.5,
  222. "excellon_endxy": None,
  223. "excellon_feedrate_z": 300,
  224. "excellon_spindlespeed": 0,
  225. "excellon_dwell": False,
  226. "excellon_dwelltime": 1,
  227. "excellon_toolchange": False,
  228. "excellon_toolchangez": 15,
  229. "excellon_ppname_e": 'default',
  230. "excellon_tooldia": 0.8,
  231. "excellon_slot_tooldia": 1.8,
  232. "excellon_gcode_type": "drills",
  233. "excellon_area_exclusion": False,
  234. "excellon_area_shape": "polygon",
  235. "excellon_area_strategy": "over",
  236. "excellon_area_overz": 1.0,
  237. # Excellon Advanced Options
  238. "excellon_offset": 0.0,
  239. "excellon_toolchangexy": "0.0, 0.0",
  240. "excellon_startz": None,
  241. "excellon_feedrate_rapid": 1500,
  242. "excellon_z_pdepth": -0.02,
  243. "excellon_feedrate_probe": 75,
  244. "excellon_spindledir": 'CW',
  245. "excellon_f_plunge": False,
  246. "excellon_f_retract": False,
  247. "excellon_drill_slots": False,
  248. "excellon_drill_overlap": 0.0,
  249. "excellon_last_drill": True,
  250. # Excellon Export
  251. "excellon_exp_units": 'INCH',
  252. "excellon_exp_format": 'dec',
  253. "excellon_exp_integer": 2,
  254. "excellon_exp_decimals": 4,
  255. "excellon_exp_zeros": 'LZ',
  256. "excellon_exp_slot_type": 'routing',
  257. # Excellon Editor
  258. "excellon_editor_sel_limit": 30,
  259. "excellon_editor_newdia": 1.0,
  260. "excellon_editor_array_size": 5,
  261. "excellon_editor_lin_dir": 'X',
  262. "excellon_editor_lin_pitch": 2.54,
  263. "excellon_editor_lin_angle": 0.0,
  264. "excellon_editor_circ_dir": 'CW',
  265. "excellon_editor_circ_angle": 12,
  266. # Excellon Slots
  267. "excellon_editor_slot_direction": 'X',
  268. "excellon_editor_slot_angle": 0.0,
  269. "excellon_editor_slot_length": 5.0,
  270. # Excellon Slot Array
  271. "excellon_editor_slot_array_size": 5,
  272. "excellon_editor_slot_lin_dir": 'X',
  273. "excellon_editor_slot_lin_pitch": 2.54,
  274. "excellon_editor_slot_lin_angle": 0.0,
  275. "excellon_editor_slot_circ_dir": 'CW',
  276. "excellon_editor_slot_circ_angle": 0.0,
  277. # Geometry General
  278. "geometry_plot": True,
  279. "geometry_multicolored": False,
  280. "geometry_circle_steps": 64,
  281. "geometry_cnctooldia": "2.4",
  282. "geometry_merge_fuse_tools": True,
  283. "geometry_plot_line": "#FF0000",
  284. # Geometry Options
  285. "geometry_cutz": -2.4,
  286. "geometry_vtipdia": 0.1,
  287. "geometry_vtipangle": 30,
  288. "geometry_multidepth": False,
  289. "geometry_depthperpass": 0.8,
  290. "geometry_travelz": 2,
  291. "geometry_toolchange": False,
  292. "geometry_toolchangez": 15.0,
  293. "geometry_endz": 15.0,
  294. "geometry_endxy": None,
  295. "geometry_feedrate": 120,
  296. "geometry_feedrate_z": 60,
  297. "geometry_spindlespeed": 0,
  298. "geometry_dwell": False,
  299. "geometry_dwelltime": 1,
  300. "geometry_ppname_g": 'default',
  301. # Geometry Advanced Options
  302. "geometry_toolchangexy": "0.0, 0.0",
  303. "geometry_startz": None,
  304. "geometry_feedrate_rapid": 1500,
  305. "geometry_extracut": False,
  306. "geometry_extracut_length": 0.1,
  307. "geometry_z_pdepth": -0.02,
  308. "geometry_f_plunge": False,
  309. "geometry_spindledir": 'CW',
  310. "geometry_feedrate_probe": 75,
  311. "geometry_segx": 0.0,
  312. "geometry_segy": 0.0,
  313. "geometry_area_exclusion": False,
  314. "geometry_area_shape": "polygon",
  315. "geometry_area_strategy": "over",
  316. "geometry_area_overz": 1.0,
  317. # Geometry Editor
  318. "geometry_editor_sel_limit": 30,
  319. "geometry_editor_milling_type": "cl",
  320. # CNC Job General
  321. "cncjob_plot": True,
  322. "cncjob_plot_kind": 'all',
  323. "cncjob_annotation": True,
  324. "cncjob_tooldia": 1.0,
  325. "cncjob_coords_type": "G90",
  326. "cncjob_coords_decimals": 4,
  327. "cncjob_fr_decimals": 2,
  328. "cncjob_steps_per_circle": 64,
  329. "cncjob_footer": False,
  330. "cncjob_line_ending": False,
  331. "cncjob_save_filters": "G-Code Files .nc (*.nc);;G-Code Files .din (*.din);;G-Code Files .dnc (*.dnc);;"
  332. "G-Code Files .ecs (*.ecs);;G-Code Files .eia (*.eia);;G-Code Files .fan (*.fan);;"
  333. "G-Code Files .fgc (*.fgc);;G-Code Files .fnc (*.fnc);;G-Code Files . gc (*.gc);;"
  334. "G-Code Files .gcd (*.gcd);;G-Code Files .gcode (*.gcode);;G-Code Files .h (*.h);;"
  335. "G-Code Files .hnc (*.hnc);;G-Code Files .i (*.i);;G-Code Files .min (*.min);;"
  336. "G-Code Files .mpf (*.mpf);;G-Code Files .mpr (*.mpr);;G-Code Files .cnc (*.cnc);;"
  337. "G-Code Files .ncc (*.ncc);;G-Code Files .ncg (*.ncg);;G-Code Files .ncp (*.ncp);;"
  338. "G-Code Files .ngc (*.ngc);;G-Code Files .out (*.out);;G-Code Files .ply (*.ply);;"
  339. "G-Code Files .sbp (*.sbp);;G-Code Files .tap (*.tap);;G-Code Files .xpi (*.xpi);;"
  340. "All Files (*.*)",
  341. "cncjob_plot_line": '#4650BDFF',
  342. "cncjob_plot_fill": '#5E6CFFFF',
  343. "cncjob_travel_line": '#B5AB3A4C',
  344. "cncjob_travel_fill": '#F0E24D4C',
  345. # CNC Job Options
  346. "cncjob_prepend": "",
  347. "cncjob_append": "",
  348. # CNC Job Advanced Options
  349. "cncjob_toolchange_macro": "",
  350. "cncjob_toolchange_macro_enable": False,
  351. "cncjob_annotation_fontsize": 9,
  352. "cncjob_annotation_fontcolor": '#990000',
  353. # Isolation Routing Tool
  354. "tools_iso_tooldia": "0.1",
  355. "tools_iso_order": 'rev',
  356. "tools_iso_tool_type": 'C1',
  357. "tools_iso_tool_vtipdia": 0.1,
  358. "tools_iso_tool_vtipangle": 30,
  359. "tools_iso_tool_cutz": -0.05,
  360. "tools_iso_newdia": 0.1,
  361. "tools_iso_passes": 1,
  362. "tools_iso_overlap": 10,
  363. "tools_iso_milling_type": "cl",
  364. "tools_iso_follow": False,
  365. "tools_iso_isotype": "full",
  366. "tools_iso_rest": False,
  367. "tools_iso_combine_passes": True,
  368. "tools_iso_isoexcept": False,
  369. "tools_iso_selection": _("All"),
  370. "tools_iso_poly_ints": False,
  371. "tools_iso_force": True,
  372. "tools_iso_area_shape": "square",
  373. "tools_iso_plotting": 'normal',
  374. # NCC Tool
  375. "tools_ncctools": "1.0, 0.5",
  376. "tools_nccorder": 'rev',
  377. "tools_nccoperation": 'clear',
  378. "tools_nccoverlap": 40,
  379. "tools_nccmargin": 1.0,
  380. "tools_nccmethod": _("Seed"),
  381. "tools_nccconnect": True,
  382. "tools_ncccontour": True,
  383. "tools_nccrest": False,
  384. "tools_ncc_offset_choice": False,
  385. "tools_ncc_offset_value": 0.0000,
  386. "tools_nccref": _('Itself'),
  387. "tools_ncc_area_shape": "square",
  388. "tools_nccmilling_type": 'cl',
  389. "tools_ncctool_type": 'C1',
  390. "tools_ncccutz": -0.05,
  391. "tools_ncctipdia": 0.1,
  392. "tools_ncctipangle": 30,
  393. "tools_nccnewdia": 0.1,
  394. "tools_ncc_plotting": 'normal',
  395. # Cutout Tool
  396. "tools_cutouttooldia": 2.4,
  397. "tools_cutoutkind": "single",
  398. "tools_cutoutmargin": 0.1,
  399. "tools_cutout_z": -1.8,
  400. "tools_cutout_depthperpass": 0.6,
  401. "tools_cutout_mdepth": True,
  402. "tools_cutoutgapsize": 4,
  403. "tools_gaps_ff": "4",
  404. "tools_cutout_convexshape": False,
  405. "tools_cutout_big_cursor": True,
  406. # Paint Tool
  407. "tools_painttooldia": 0.3,
  408. "tools_paintorder": 'rev',
  409. "tools_paintoverlap": 20,
  410. "tools_paintoffset": 0.0,
  411. "tools_paintmethod": _("Seed"),
  412. "tools_selectmethod": _("All"),
  413. "tools_paint_area_shape": "square",
  414. "tools_pathconnect": True,
  415. "tools_paintcontour": True,
  416. "tools_paint_plotting": 'normal',
  417. "tools_paintrest": False,
  418. "tools_painttool_type": 'C1',
  419. "tools_paintcutz": -0.05,
  420. "tools_painttipdia": 0.1,
  421. "tools_painttipangle": 30,
  422. "tools_paintnewdia": 0.1,
  423. # 2-Sided Tool
  424. "tools_2sided_mirror_axis": "X",
  425. "tools_2sided_axis_loc": "point",
  426. "tools_2sided_drilldia": 3.125,
  427. "tools_2sided_allign_axis": "X",
  428. # Film Tool
  429. "tools_film_type": 'neg',
  430. "tools_film_boundary": 1.0,
  431. "tools_film_scale_stroke": 0,
  432. "tools_film_color": '#000000',
  433. "tools_film_scale_cb": False,
  434. "tools_film_scale_x_entry": 1.0,
  435. "tools_film_scale_y_entry": 1.0,
  436. "tools_film_skew_cb": False,
  437. "tools_film_skew_x_entry": 0.0,
  438. "tools_film_skew_y_entry": 0.0,
  439. "tools_film_skew_ref_radio": 'bottomleft',
  440. "tools_film_mirror_cb": False,
  441. "tools_film_mirror_axis_radio": 'none',
  442. "tools_film_file_type_radio": 'svg',
  443. "tools_film_orientation": 'p',
  444. "tools_film_pagesize": 'A4',
  445. # Panel Tool
  446. "tools_panelize_spacing_columns": 0.0,
  447. "tools_panelize_spacing_rows": 0.0,
  448. "tools_panelize_columns": 1,
  449. "tools_panelize_rows": 1,
  450. "tools_panelize_optimization": True,
  451. "tools_panelize_constrain": False,
  452. "tools_panelize_constrainx": 200.0,
  453. "tools_panelize_constrainy": 290.0,
  454. "tools_panelize_panel_type": 'gerber',
  455. # Calculators Tool
  456. "tools_calc_vshape_tip_dia": 0.2,
  457. "tools_calc_vshape_tip_angle": 30,
  458. "tools_calc_vshape_cut_z": 0.05,
  459. "tools_calc_electro_length": 10.0,
  460. "tools_calc_electro_width": 10.0,
  461. "tools_calc_electro_cdensity": 13.0,
  462. "tools_calc_electro_growth": 10.0,
  463. # Transform Tool
  464. "tools_transform_reference": _("Selection"),
  465. "tools_transform_ref_object": _("Gerber"),
  466. "tools_transform_ref_point": "0, 0",
  467. "tools_transform_rotate": 90,
  468. "tools_transform_skew_x": 0.0,
  469. "tools_transform_skew_y": 0.0,
  470. "tools_transform_skew_link": True,
  471. "tools_transform_scale_x": 1.0,
  472. "tools_transform_scale_y": 1.0,
  473. "tools_transform_scale_link": True,
  474. "tools_transform_offset_x": 0.0,
  475. "tools_transform_offset_y": 0.0,
  476. "tools_transform_buffer_dis": 0.0,
  477. "tools_transform_buffer_factor": 100.0,
  478. "tools_transform_buffer_corner": True,
  479. # SolderPaste Tool
  480. "tools_solderpaste_tools": "1.0, 0.3",
  481. "tools_solderpaste_new": 0.3,
  482. "tools_solderpaste_z_start": 0.05,
  483. "tools_solderpaste_z_dispense": 0.1,
  484. "tools_solderpaste_z_stop": 0.05,
  485. "tools_solderpaste_z_travel": 0.1,
  486. "tools_solderpaste_z_toolchange": 1.0,
  487. "tools_solderpaste_xy_toolchange": "0.0, 0.0",
  488. "tools_solderpaste_frxy": 150,
  489. "tools_solderpaste_frz": 150,
  490. "tools_solderpaste_frz_dispense": 1.0,
  491. "tools_solderpaste_speedfwd": 300,
  492. "tools_solderpaste_dwellfwd": 1,
  493. "tools_solderpaste_speedrev": 200,
  494. "tools_solderpaste_dwellrev": 1,
  495. "tools_solderpaste_pp": 'Paste_1',
  496. # Subtract Tool
  497. "tools_sub_close_paths": True,
  498. # Distance Tool
  499. "tools_dist_snap_center": False,
  500. # Corner Markers Tool
  501. "tools_corners_thickness": 0.1,
  502. "tools_corners_length": 3.0,
  503. "tools_corners_margin": 0.0,
  504. # ########################################################################################################
  505. # ################################ TOOLS 2 ###############################################################
  506. # ########################################################################################################
  507. # Optimal Tool
  508. "tools_opt_precision": 4,
  509. # Check Rules Tool
  510. "tools_cr_trace_size": True,
  511. "tools_cr_trace_size_val": 0.25,
  512. "tools_cr_c2c": True,
  513. "tools_cr_c2c_val": 0.25,
  514. "tools_cr_c2o": True,
  515. "tools_cr_c2o_val": 1.0,
  516. "tools_cr_s2s": True,
  517. "tools_cr_s2s_val": 0.25,
  518. "tools_cr_s2sm": True,
  519. "tools_cr_s2sm_val": 0.25,
  520. "tools_cr_s2o": True,
  521. "tools_cr_s2o_val": 1.0,
  522. "tools_cr_sm2sm": True,
  523. "tools_cr_sm2sm_val": 0.25,
  524. "tools_cr_ri": True,
  525. "tools_cr_ri_val": 0.3,
  526. "tools_cr_h2h": True,
  527. "tools_cr_h2h_val": 0.3,
  528. "tools_cr_dh": True,
  529. "tools_cr_dh_val": 0.3,
  530. # QRCode Tool
  531. "tools_qrcode_version": 1,
  532. "tools_qrcode_error": 'L',
  533. "tools_qrcode_box_size": 3,
  534. "tools_qrcode_border_size": 4,
  535. "tools_qrcode_qrdata": '',
  536. "tools_qrcode_polarity": 'pos',
  537. "tools_qrcode_rounded": 's',
  538. "tools_qrcode_fill_color": '#000000',
  539. "tools_qrcode_back_color": '#FFFFFF',
  540. "tools_qrcode_sel_limit": 330,
  541. # Copper Thieving Tool
  542. "tools_copper_thieving_clearance": 0.25,
  543. "tools_copper_thieving_margin": 1.0,
  544. "tools_copper_thieving_reference": 'itself',
  545. "tools_copper_thieving_box_type": 'rect',
  546. "tools_copper_thieving_circle_steps": 64,
  547. "tools_copper_thieving_fill_type": 'solid',
  548. "tools_copper_thieving_dots_dia": 1.0,
  549. "tools_copper_thieving_dots_spacing": 2.0,
  550. "tools_copper_thieving_squares_size": 1.0,
  551. "tools_copper_thieving_squares_spacing": 2.0,
  552. "tools_copper_thieving_lines_size": 0.25,
  553. "tools_copper_thieving_lines_spacing": 2.0,
  554. "tools_copper_thieving_rb_margin": 1.0,
  555. "tools_copper_thieving_rb_thickness": 1.0,
  556. "tools_copper_thieving_mask_clearance": 0.0,
  557. # Fiducials Tool
  558. "tools_fiducials_dia": 1.0,
  559. "tools_fiducials_margin": 1.0,
  560. "tools_fiducials_mode": 'auto',
  561. "tools_fiducials_second_pos": 'up',
  562. "tools_fiducials_type": 'circular',
  563. "tools_fiducials_line_thickness": 0.25,
  564. # Calibration Tool
  565. "tools_cal_calsource": 'object',
  566. "tools_cal_travelz": 2.0,
  567. "tools_cal_verz": 0.1,
  568. "tools_cal_zeroz": False,
  569. "tools_cal_toolchangez": 15,
  570. "tools_cal_toolchange_xy": '',
  571. "tools_cal_sec_point": 'tl',
  572. # Drills Extraction Tool
  573. "tools_edrills_hole_type": 'fixed',
  574. "tools_edrills_hole_fixed_dia": 0.5,
  575. "tools_edrills_hole_prop_factor": 80.0,
  576. "tools_edrills_circular_ring": 0.2,
  577. "tools_edrills_oblong_ring": 0.2,
  578. "tools_edrills_square_ring": 0.2,
  579. "tools_edrills_rectangular_ring": 0.2,
  580. "tools_edrills_others_ring": 0.2,
  581. "tools_edrills_circular": True,
  582. "tools_edrills_oblong": False,
  583. "tools_edrills_square": False,
  584. "tools_edrills_rectangular": False,
  585. "tools_edrills_others": False,
  586. # Punch Gerber Tool
  587. "tools_punch_hole_type": 'exc',
  588. "tools_punch_hole_fixed_dia": 0.5,
  589. "tools_punch_hole_prop_factor": 80.0,
  590. "tools_punch_circular_ring": 0.2,
  591. "tools_punch_oblong_ring": 0.2,
  592. "tools_punch_square_ring": 0.2,
  593. "tools_punch_rectangular_ring": 0.2,
  594. "tools_punch_others_ring": 0.2,
  595. "tools_punch_circular": True,
  596. "tools_punch_oblong": False,
  597. "tools_punch_square": True,
  598. "tools_punch_rectangular": False,
  599. "tools_punch_others": False,
  600. # Align Objects Tool
  601. "tools_align_objects_align_type": 'sp',
  602. # Invert Gerber Tool
  603. "tools_invert_margin": 0.1,
  604. "tools_invert_join_style": 's',
  605. # Utilities
  606. # file associations
  607. "fa_excellon": 'drd, drill, drl, exc, ncd, tap, xln',
  608. "fa_gcode": 'cnc, din, dnc, ecs, eia, fan, fgc, fnc, gc, gcd, gcode, h, hnc, i, min, mpf, mpr, nc, ncc, '
  609. 'ncg, ncp, ngc, out, ply, rol, sbp, tap, xpi',
  610. "fa_gerber": 'art, bot, bsm, cmp, crc, crs, dim, gb0, gb1, gb2, gb3, gb4, gb5, gb6, gb7, gb8, gb9, gbd, '
  611. 'gbl, gbo, gbp, gbr, gbs, gdo, ger, gko, gm1, gm2, gm3, grb, gtl, gto, gtp, gts, ly15, ly2, '
  612. 'mil, outline, pho, plc, pls, smb, smt, sol, spb, spt, ssb, sst, stc, sts, top, tsm',
  613. # Keyword list
  614. "util_autocomplete_keywords": 'Desktop, Documents, FlatConfig, FlatPrj, False, '
  615. 'Marius, My Documents, Paste_1, '
  616. 'Repetier, Roland_MDX_20, True, Users, Toolchange_Custom, '
  617. 'Toolchange_Probe_MACH3, '
  618. 'Toolchange_manual, Users, all, axis, auto, axisoffset, '
  619. 'box, center_x, center_y, columns, combine, connect, contour, default, '
  620. 'depthperpass, dia, diatol, dist, drilled_dias, drillz, dpp, dwelltime, '
  621. 'endxy, endz, extracut_length, f, feedrate, '
  622. 'feedrate_z, grbl_11, GRBL_laser, gridoffsety, gridx, gridy, has_offset, '
  623. 'holes, hpgl, iso_type, line_xyz, margin, marlin, method, milled_dias, '
  624. 'minoffset, name, offset, opt_type, order, outname, overlap, '
  625. 'passes, postamble, pp, ppname_e, ppname_g, preamble, radius, ref, rest, '
  626. 'rows, shellvar_, scale_factor, spacing_columns, spacing_rows, spindlespeed, '
  627. 'startz, startxy, toolchange_xy, toolchangez, '
  628. 'tooldia, travelz, use_threads, value, x, x0, x1, y, y0, y1, z_cut, '
  629. 'z_move',
  630. "script_autocompleter": True,
  631. "script_text": "",
  632. "script_plot": True,
  633. "script_source_file": "",
  634. "document_autocompleter": False,
  635. "document_text": "",
  636. "document_plot": True,
  637. "document_source_file": "",
  638. "document_font_color": '#000000',
  639. "document_sel_color": '#0055ff',
  640. "document_font_size": 6,
  641. "document_tab_size": 80,
  642. }
  643. @classmethod
  644. def save_factory_defaults(cls, file_path: str, version: float):
  645. """Writes the factory defaults to a file at the given path, overwriting any existing file."""
  646. # Delete any existing factory defaults file
  647. if os.path.isfile(file_path):
  648. # check if it has content other than an empty dict, because if it does we don't need it to be updated
  649. # each time the app starts
  650. with open(file_path, "r") as file:
  651. f_defaults = simplejson.loads(file.read())
  652. if f_defaults:
  653. return
  654. os.chmod(file_path, stat.S_IRWXO | stat.S_IWRITE | stat.S_IWGRP)
  655. os.remove(file_path)
  656. cls.factory_defaults['version'] = version
  657. try:
  658. # recreate a new factory defaults file and save the factory defaults data into it
  659. f_f_def_s = open(file_path, "w")
  660. simplejson.dump(cls.factory_defaults, f_f_def_s, default=to_dict, indent=2, sort_keys=True)
  661. f_f_def_s.close()
  662. # and then make the factory_defaults.FlatConfig file read_only
  663. # so it can't be modified after creation.
  664. os.chmod(file_path, stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH)
  665. log.debug("FlatCAM factory defaults written to: %s" % file_path)
  666. except Exception as e:
  667. log.error("save_factory_defaults() -> %s" % str(e))
  668. def __init__(self, callback=lambda x: None):
  669. """
  670. :param callback: A method called each time that one of the values are changed in the self.defaults LouDict
  671. """
  672. self.defaults = LoudDict()
  673. self.defaults.update(self.factory_defaults)
  674. self.current_defaults = {} # copy used for restoring after cancelled prefs changes
  675. self.current_defaults.update(self.factory_defaults)
  676. self.old_defaults_found = False
  677. self.defaults.set_change_callback(callback)
  678. # #### Pass-through to the defaults LoudDict #####
  679. def __len__(self):
  680. return self.defaults.__len__()
  681. def __getitem__(self, item):
  682. return self.defaults.__getitem__(item)
  683. def __setitem__(self, key, value):
  684. return self.defaults.__setitem__(key, value)
  685. def __delitem__(self, key):
  686. return self.defaults.__delitem__(key)
  687. def __iter__(self):
  688. return self.defaults.__iter__()
  689. def __getattr__(self, item):
  690. # Unfortunately this method alone is not enough to pass through the other magic methods above.
  691. return self.defaults.__getattribute__(item)
  692. # #### Additional Methods #####
  693. def write(self, filename: str):
  694. """Saves the defaults to a file on disk"""
  695. with open(filename, "w") as file:
  696. simplejson.dump(self.defaults, file, default=to_dict, indent=2, sort_keys=True)
  697. def load(self, filename: str):
  698. """Loads the defaults from a file on disk, performing migration if required."""
  699. # Read in the file
  700. try:
  701. f = open(filename)
  702. options = f.read()
  703. f.close()
  704. except IOError:
  705. log.error("Could not load defaults file.")
  706. self.inform.emit('[ERROR] %s' % _("Could not load defaults file."))
  707. # in case the defaults file can't be loaded, show all toolbars
  708. self.defaults["global_toolbar_view"] = 511
  709. return
  710. # Parse the JSON
  711. try:
  712. defaults = simplejson.loads(options)
  713. except Exception:
  714. # in case the defaults file can't be loaded, show all toolbars
  715. self.defaults["global_toolbar_view"] = 511
  716. e = sys.exc_info()[0]
  717. log.error(str(e))
  718. self.inform.emit('[ERROR] %s' % _("Failed to parse defaults file."))
  719. return
  720. if defaults is None:
  721. return
  722. # Perform migration if necessary but only if the defaults dict is not empty
  723. if self.__is_old_defaults(defaults) and defaults:
  724. self.old_defaults_found = True
  725. defaults = self.__migrate_old_defaults(defaults=defaults)
  726. else:
  727. self.old_defaults_found = False
  728. # Save the resulting defaults
  729. self.defaults.update(defaults)
  730. self.current_defaults.update(self.defaults)
  731. log.debug("FlatCAM defaults loaded from: %s" % filename)
  732. def __is_old_defaults(self, defaults: dict) -> bool:
  733. """Takes a defaults dict and determines whether or not migration is necessary."""
  734. return 'version' not in defaults or defaults['version'] != self.factory_defaults['version']
  735. def __migrate_old_defaults(self, defaults: dict) -> dict:
  736. """Performs migration on the passed-in defaults dictionary, and returns the migrated dict"""
  737. migrated = {}
  738. for k, v in defaults.items():
  739. if k in self.factory_defaults and k != 'version':
  740. # check if the types are the same. Because some types (tuple, float, int etc)
  741. # may be stored as strings we check their types.
  742. try:
  743. target = eval(self.defaults[k])
  744. except (NameError, TypeError, SyntaxError):
  745. # it's an unknown string leave it as it is
  746. target = deepcopy(self.factory_defaults[k])
  747. try:
  748. source = eval(v)
  749. except (NameError, TypeError, SyntaxError):
  750. # it's an unknown string leave it as it is
  751. source = deepcopy(v)
  752. if type(target) == type(source):
  753. migrated[k] = v
  754. return migrated
  755. def reset_to_factory_defaults(self):
  756. self.defaults.update(self.factory_defaults)
  757. self.current_defaults.update(self.factory_defaults)
  758. self.old_defaults_found = False
  759. def propagate_defaults(self):
  760. """
  761. This method is used to set default values in classes. It's
  762. an alternative to project options but allows the use
  763. of values invisible to the user.
  764. """
  765. log.debug("propagate_defaults()")
  766. # Which objects to update the given parameters.
  767. routes = {
  768. "global_zdownrate": CNCjob,
  769. "excellon_zeros": Excellon,
  770. "excellon_format_upper_in": Excellon,
  771. "excellon_format_lower_in": Excellon,
  772. "excellon_format_upper_mm": Excellon,
  773. "excellon_format_lower_mm": Excellon,
  774. "excellon_units": Excellon,
  775. "gerber_use_buffer_for_union": Gerber,
  776. "geometry_multidepth": Geometry
  777. }
  778. for param in routes:
  779. if param in routes[param].defaults:
  780. try:
  781. routes[param].defaults[param] = self.defaults[param]
  782. except KeyError:
  783. log.error("FlatCAMApp.propagate_defaults() --> ERROR: " + param + " not in defaults.")
  784. else:
  785. # Try extracting the name:
  786. # classname_param here is param in the object
  787. if param.find(routes[param].__name__.lower() + "_") == 0:
  788. p = param[len(routes[param].__name__) + 1:]
  789. if p in routes[param].defaults:
  790. routes[param].defaults[p] = self.defaults[param]
  791. def report_usage(self, resource):
  792. """
  793. Increments usage counter for the given resource
  794. in self.defaults['global_stats'].
  795. :param resource: Name of the resource.
  796. :return: None
  797. """
  798. if resource in self.defaults['global_stats']:
  799. self.defaults['global_stats'][resource] += 1
  800. else:
  801. self.defaults['global_stats'][resource] = 1