defaults.py 36 KB

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