defaults.py 30 KB

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