defaults.py 37 KB

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