meerk40t 0.9.3001__py2.py3-none-any.whl → 0.9.7020__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. meerk40t/__init__.py +1 -1
  2. meerk40t/balormk/balor_params.py +167 -167
  3. meerk40t/balormk/clone_loader.py +457 -457
  4. meerk40t/balormk/controller.py +1566 -1512
  5. meerk40t/balormk/cylindermod.py +64 -0
  6. meerk40t/balormk/device.py +966 -1959
  7. meerk40t/balormk/driver.py +778 -591
  8. meerk40t/balormk/galvo_commands.py +1194 -0
  9. meerk40t/balormk/gui/balorconfig.py +237 -111
  10. meerk40t/balormk/gui/balorcontroller.py +191 -184
  11. meerk40t/balormk/gui/baloroperationproperties.py +116 -115
  12. meerk40t/balormk/gui/corscene.py +845 -0
  13. meerk40t/balormk/gui/gui.py +179 -147
  14. meerk40t/balormk/livelightjob.py +466 -382
  15. meerk40t/balormk/mock_connection.py +131 -109
  16. meerk40t/balormk/plugin.py +133 -135
  17. meerk40t/balormk/usb_connection.py +306 -301
  18. meerk40t/camera/__init__.py +1 -1
  19. meerk40t/camera/camera.py +514 -397
  20. meerk40t/camera/gui/camerapanel.py +1241 -1095
  21. meerk40t/camera/gui/gui.py +58 -58
  22. meerk40t/camera/plugin.py +441 -399
  23. meerk40t/ch341/__init__.py +27 -27
  24. meerk40t/ch341/ch341device.py +628 -628
  25. meerk40t/ch341/libusb.py +595 -589
  26. meerk40t/ch341/mock.py +171 -171
  27. meerk40t/ch341/windriver.py +157 -157
  28. meerk40t/constants.py +13 -0
  29. meerk40t/core/__init__.py +1 -1
  30. meerk40t/core/bindalias.py +550 -539
  31. meerk40t/core/core.py +47 -47
  32. meerk40t/core/cutcode/cubiccut.py +73 -73
  33. meerk40t/core/cutcode/cutcode.py +315 -312
  34. meerk40t/core/cutcode/cutgroup.py +141 -137
  35. meerk40t/core/cutcode/cutobject.py +192 -185
  36. meerk40t/core/cutcode/dwellcut.py +37 -37
  37. meerk40t/core/cutcode/gotocut.py +29 -29
  38. meerk40t/core/cutcode/homecut.py +29 -29
  39. meerk40t/core/cutcode/inputcut.py +34 -34
  40. meerk40t/core/cutcode/linecut.py +33 -33
  41. meerk40t/core/cutcode/outputcut.py +34 -34
  42. meerk40t/core/cutcode/plotcut.py +335 -335
  43. meerk40t/core/cutcode/quadcut.py +61 -61
  44. meerk40t/core/cutcode/rastercut.py +168 -148
  45. meerk40t/core/cutcode/waitcut.py +34 -34
  46. meerk40t/core/cutplan.py +1843 -1316
  47. meerk40t/core/drivers.py +330 -329
  48. meerk40t/core/elements/align.py +801 -669
  49. meerk40t/core/elements/branches.py +1858 -1507
  50. meerk40t/core/elements/clipboard.py +229 -219
  51. meerk40t/core/elements/element_treeops.py +4595 -2837
  52. meerk40t/core/elements/element_types.py +125 -105
  53. meerk40t/core/elements/elements.py +4315 -3617
  54. meerk40t/core/elements/files.py +117 -64
  55. meerk40t/core/elements/geometry.py +473 -224
  56. meerk40t/core/elements/grid.py +467 -316
  57. meerk40t/core/elements/materials.py +158 -94
  58. meerk40t/core/elements/notes.py +50 -38
  59. meerk40t/core/elements/offset_clpr.py +934 -912
  60. meerk40t/core/elements/offset_mk.py +963 -955
  61. meerk40t/core/elements/penbox.py +339 -267
  62. meerk40t/core/elements/placements.py +300 -83
  63. meerk40t/core/elements/render.py +785 -687
  64. meerk40t/core/elements/shapes.py +2618 -2092
  65. meerk40t/core/elements/testcases.py +105 -0
  66. meerk40t/core/elements/trace.py +651 -563
  67. meerk40t/core/elements/tree_commands.py +415 -409
  68. meerk40t/core/elements/undo_redo.py +116 -58
  69. meerk40t/core/elements/wordlist.py +319 -200
  70. meerk40t/core/exceptions.py +9 -9
  71. meerk40t/core/laserjob.py +220 -220
  72. meerk40t/core/logging.py +63 -63
  73. meerk40t/core/node/blobnode.py +83 -86
  74. meerk40t/core/node/bootstrap.py +105 -103
  75. meerk40t/core/node/branch_elems.py +40 -31
  76. meerk40t/core/node/branch_ops.py +45 -38
  77. meerk40t/core/node/branch_regmark.py +48 -41
  78. meerk40t/core/node/cutnode.py +29 -32
  79. meerk40t/core/node/effect_hatch.py +375 -257
  80. meerk40t/core/node/effect_warp.py +398 -0
  81. meerk40t/core/node/effect_wobble.py +441 -309
  82. meerk40t/core/node/elem_ellipse.py +404 -309
  83. meerk40t/core/node/elem_image.py +1082 -801
  84. meerk40t/core/node/elem_line.py +358 -292
  85. meerk40t/core/node/elem_path.py +259 -201
  86. meerk40t/core/node/elem_point.py +129 -102
  87. meerk40t/core/node/elem_polyline.py +310 -246
  88. meerk40t/core/node/elem_rect.py +376 -286
  89. meerk40t/core/node/elem_text.py +445 -418
  90. meerk40t/core/node/filenode.py +59 -40
  91. meerk40t/core/node/groupnode.py +138 -74
  92. meerk40t/core/node/image_processed.py +777 -766
  93. meerk40t/core/node/image_raster.py +156 -113
  94. meerk40t/core/node/layernode.py +31 -31
  95. meerk40t/core/node/mixins.py +135 -107
  96. meerk40t/core/node/node.py +1427 -1304
  97. meerk40t/core/node/nutils.py +117 -114
  98. meerk40t/core/node/op_cut.py +463 -335
  99. meerk40t/core/node/op_dots.py +296 -251
  100. meerk40t/core/node/op_engrave.py +414 -311
  101. meerk40t/core/node/op_image.py +755 -369
  102. meerk40t/core/node/op_raster.py +787 -522
  103. meerk40t/core/node/place_current.py +37 -40
  104. meerk40t/core/node/place_point.py +329 -126
  105. meerk40t/core/node/refnode.py +58 -47
  106. meerk40t/core/node/rootnode.py +225 -219
  107. meerk40t/core/node/util_console.py +48 -48
  108. meerk40t/core/node/util_goto.py +84 -65
  109. meerk40t/core/node/util_home.py +61 -61
  110. meerk40t/core/node/util_input.py +102 -102
  111. meerk40t/core/node/util_output.py +102 -102
  112. meerk40t/core/node/util_wait.py +65 -65
  113. meerk40t/core/parameters.py +709 -707
  114. meerk40t/core/planner.py +875 -785
  115. meerk40t/core/plotplanner.py +656 -652
  116. meerk40t/core/space.py +120 -113
  117. meerk40t/core/spoolers.py +706 -705
  118. meerk40t/core/svg_io.py +1836 -1549
  119. meerk40t/core/treeop.py +534 -445
  120. meerk40t/core/undos.py +278 -124
  121. meerk40t/core/units.py +784 -680
  122. meerk40t/core/view.py +393 -322
  123. meerk40t/core/webhelp.py +62 -62
  124. meerk40t/core/wordlist.py +513 -504
  125. meerk40t/cylinder/cylinder.py +247 -0
  126. meerk40t/cylinder/gui/cylindersettings.py +41 -0
  127. meerk40t/cylinder/gui/gui.py +24 -0
  128. meerk40t/device/__init__.py +1 -1
  129. meerk40t/device/basedevice.py +322 -123
  130. meerk40t/device/devicechoices.py +50 -0
  131. meerk40t/device/dummydevice.py +163 -128
  132. meerk40t/device/gui/defaultactions.py +618 -602
  133. meerk40t/device/gui/effectspanel.py +114 -0
  134. meerk40t/device/gui/formatterpanel.py +253 -290
  135. meerk40t/device/gui/warningpanel.py +337 -260
  136. meerk40t/device/mixins.py +13 -13
  137. meerk40t/dxf/__init__.py +1 -1
  138. meerk40t/dxf/dxf_io.py +766 -554
  139. meerk40t/dxf/plugin.py +47 -35
  140. meerk40t/external_plugins.py +79 -79
  141. meerk40t/external_plugins_build.py +28 -28
  142. meerk40t/extra/cag.py +112 -116
  143. meerk40t/extra/coolant.py +403 -0
  144. meerk40t/extra/encode_detect.py +204 -0
  145. meerk40t/extra/ezd.py +1165 -1165
  146. meerk40t/extra/hershey.py +834 -340
  147. meerk40t/extra/imageactions.py +322 -316
  148. meerk40t/extra/inkscape.py +628 -622
  149. meerk40t/extra/lbrn.py +424 -424
  150. meerk40t/extra/outerworld.py +283 -0
  151. meerk40t/extra/param_functions.py +1542 -1556
  152. meerk40t/extra/potrace.py +257 -253
  153. meerk40t/extra/serial_exchange.py +118 -0
  154. meerk40t/extra/updater.py +602 -453
  155. meerk40t/extra/vectrace.py +147 -146
  156. meerk40t/extra/winsleep.py +83 -83
  157. meerk40t/extra/xcs_reader.py +597 -0
  158. meerk40t/fill/fills.py +781 -335
  159. meerk40t/fill/patternfill.py +1061 -1061
  160. meerk40t/fill/patterns.py +614 -567
  161. meerk40t/grbl/control.py +87 -87
  162. meerk40t/grbl/controller.py +990 -903
  163. meerk40t/grbl/device.py +1084 -768
  164. meerk40t/grbl/driver.py +989 -771
  165. meerk40t/grbl/emulator.py +532 -497
  166. meerk40t/grbl/gcodejob.py +783 -767
  167. meerk40t/grbl/gui/grblconfiguration.py +373 -298
  168. meerk40t/grbl/gui/grblcontroller.py +485 -271
  169. meerk40t/grbl/gui/grblhardwareconfig.py +269 -153
  170. meerk40t/grbl/gui/grbloperationconfig.py +105 -0
  171. meerk40t/grbl/gui/gui.py +147 -116
  172. meerk40t/grbl/interpreter.py +44 -44
  173. meerk40t/grbl/loader.py +22 -22
  174. meerk40t/grbl/mock_connection.py +56 -56
  175. meerk40t/grbl/plugin.py +294 -264
  176. meerk40t/grbl/serial_connection.py +93 -88
  177. meerk40t/grbl/tcp_connection.py +81 -79
  178. meerk40t/grbl/ws_connection.py +112 -0
  179. meerk40t/gui/__init__.py +1 -1
  180. meerk40t/gui/about.py +2042 -296
  181. meerk40t/gui/alignment.py +1644 -1608
  182. meerk40t/gui/autoexec.py +199 -0
  183. meerk40t/gui/basicops.py +791 -670
  184. meerk40t/gui/bufferview.py +77 -71
  185. meerk40t/gui/busy.py +232 -133
  186. meerk40t/gui/choicepropertypanel.py +1662 -1469
  187. meerk40t/gui/consolepanel.py +706 -542
  188. meerk40t/gui/devicepanel.py +687 -581
  189. meerk40t/gui/dialogoptions.py +110 -107
  190. meerk40t/gui/executejob.py +316 -306
  191. meerk40t/gui/fonts.py +90 -90
  192. meerk40t/gui/functionwrapper.py +252 -0
  193. meerk40t/gui/gui_mixins.py +729 -0
  194. meerk40t/gui/guicolors.py +205 -182
  195. meerk40t/gui/help_assets/help_assets.py +218 -201
  196. meerk40t/gui/helper.py +154 -0
  197. meerk40t/gui/hersheymanager.py +1440 -846
  198. meerk40t/gui/icons.py +3422 -2747
  199. meerk40t/gui/imagesplitter.py +555 -508
  200. meerk40t/gui/keymap.py +354 -344
  201. meerk40t/gui/laserpanel.py +897 -806
  202. meerk40t/gui/laserrender.py +1470 -1232
  203. meerk40t/gui/lasertoolpanel.py +805 -793
  204. meerk40t/gui/magnetoptions.py +436 -0
  205. meerk40t/gui/materialmanager.py +2944 -0
  206. meerk40t/gui/materialtest.py +1722 -1694
  207. meerk40t/gui/mkdebug.py +646 -359
  208. meerk40t/gui/mwindow.py +163 -140
  209. meerk40t/gui/navigationpanels.py +2605 -2467
  210. meerk40t/gui/notes.py +143 -142
  211. meerk40t/gui/opassignment.py +414 -410
  212. meerk40t/gui/operation_info.py +310 -299
  213. meerk40t/gui/plugin.py +500 -328
  214. meerk40t/gui/position.py +714 -669
  215. meerk40t/gui/preferences.py +901 -650
  216. meerk40t/gui/propertypanels/attributes.py +1461 -1131
  217. meerk40t/gui/propertypanels/blobproperty.py +117 -114
  218. meerk40t/gui/propertypanels/consoleproperty.py +83 -80
  219. meerk40t/gui/propertypanels/gotoproperty.py +77 -0
  220. meerk40t/gui/propertypanels/groupproperties.py +223 -217
  221. meerk40t/gui/propertypanels/hatchproperty.py +489 -469
  222. meerk40t/gui/propertypanels/imageproperty.py +2244 -1384
  223. meerk40t/gui/propertypanels/inputproperty.py +59 -58
  224. meerk40t/gui/propertypanels/opbranchproperties.py +82 -80
  225. meerk40t/gui/propertypanels/operationpropertymain.py +1890 -1638
  226. meerk40t/gui/propertypanels/outputproperty.py +59 -58
  227. meerk40t/gui/propertypanels/pathproperty.py +389 -380
  228. meerk40t/gui/propertypanels/placementproperty.py +1214 -383
  229. meerk40t/gui/propertypanels/pointproperty.py +140 -136
  230. meerk40t/gui/propertypanels/propertywindow.py +313 -181
  231. meerk40t/gui/propertypanels/rasterwizardpanels.py +996 -912
  232. meerk40t/gui/propertypanels/regbranchproperties.py +76 -0
  233. meerk40t/gui/propertypanels/textproperty.py +770 -755
  234. meerk40t/gui/propertypanels/waitproperty.py +56 -55
  235. meerk40t/gui/propertypanels/warpproperty.py +121 -0
  236. meerk40t/gui/propertypanels/wobbleproperty.py +255 -204
  237. meerk40t/gui/ribbon.py +2471 -2210
  238. meerk40t/gui/scene/scene.py +1100 -1051
  239. meerk40t/gui/scene/sceneconst.py +22 -22
  240. meerk40t/gui/scene/scenepanel.py +439 -349
  241. meerk40t/gui/scene/scenespacewidget.py +365 -365
  242. meerk40t/gui/scene/widget.py +518 -505
  243. meerk40t/gui/scenewidgets/affinemover.py +215 -215
  244. meerk40t/gui/scenewidgets/attractionwidget.py +315 -309
  245. meerk40t/gui/scenewidgets/bedwidget.py +120 -97
  246. meerk40t/gui/scenewidgets/elementswidget.py +137 -107
  247. meerk40t/gui/scenewidgets/gridwidget.py +785 -745
  248. meerk40t/gui/scenewidgets/guidewidget.py +765 -765
  249. meerk40t/gui/scenewidgets/laserpathwidget.py +66 -66
  250. meerk40t/gui/scenewidgets/machineoriginwidget.py +86 -86
  251. meerk40t/gui/scenewidgets/nodeselector.py +28 -28
  252. meerk40t/gui/scenewidgets/rectselectwidget.py +592 -346
  253. meerk40t/gui/scenewidgets/relocatewidget.py +33 -33
  254. meerk40t/gui/scenewidgets/reticlewidget.py +83 -83
  255. meerk40t/gui/scenewidgets/selectionwidget.py +2958 -2756
  256. meerk40t/gui/simpleui.py +362 -333
  257. meerk40t/gui/simulation.py +2451 -2094
  258. meerk40t/gui/snapoptions.py +208 -203
  259. meerk40t/gui/spoolerpanel.py +1227 -1180
  260. meerk40t/gui/statusbarwidgets/defaultoperations.py +480 -353
  261. meerk40t/gui/statusbarwidgets/infowidget.py +520 -483
  262. meerk40t/gui/statusbarwidgets/opassignwidget.py +356 -355
  263. meerk40t/gui/statusbarwidgets/selectionwidget.py +172 -171
  264. meerk40t/gui/statusbarwidgets/shapepropwidget.py +754 -236
  265. meerk40t/gui/statusbarwidgets/statusbar.py +272 -260
  266. meerk40t/gui/statusbarwidgets/statusbarwidget.py +268 -270
  267. meerk40t/gui/statusbarwidgets/strokewidget.py +267 -251
  268. meerk40t/gui/themes.py +200 -78
  269. meerk40t/gui/tips.py +590 -0
  270. meerk40t/gui/toolwidgets/circlebrush.py +35 -35
  271. meerk40t/gui/toolwidgets/toolcircle.py +248 -242
  272. meerk40t/gui/toolwidgets/toolcontainer.py +82 -77
  273. meerk40t/gui/toolwidgets/tooldraw.py +97 -90
  274. meerk40t/gui/toolwidgets/toolellipse.py +219 -212
  275. meerk40t/gui/toolwidgets/toolimagecut.py +25 -132
  276. meerk40t/gui/toolwidgets/toolline.py +39 -144
  277. meerk40t/gui/toolwidgets/toollinetext.py +79 -236
  278. meerk40t/gui/toolwidgets/toollinetext_inline.py +296 -0
  279. meerk40t/gui/toolwidgets/toolmeasure.py +163 -216
  280. meerk40t/gui/toolwidgets/toolnodeedit.py +2088 -2074
  281. meerk40t/gui/toolwidgets/toolnodemove.py +92 -94
  282. meerk40t/gui/toolwidgets/toolparameter.py +754 -668
  283. meerk40t/gui/toolwidgets/toolplacement.py +108 -108
  284. meerk40t/gui/toolwidgets/toolpoint.py +68 -59
  285. meerk40t/gui/toolwidgets/toolpointlistbuilder.py +294 -0
  286. meerk40t/gui/toolwidgets/toolpointmove.py +183 -0
  287. meerk40t/gui/toolwidgets/toolpolygon.py +288 -403
  288. meerk40t/gui/toolwidgets/toolpolyline.py +38 -196
  289. meerk40t/gui/toolwidgets/toolrect.py +211 -207
  290. meerk40t/gui/toolwidgets/toolrelocate.py +72 -72
  291. meerk40t/gui/toolwidgets/toolribbon.py +598 -113
  292. meerk40t/gui/toolwidgets/tooltabedit.py +546 -0
  293. meerk40t/gui/toolwidgets/tooltext.py +98 -89
  294. meerk40t/gui/toolwidgets/toolvector.py +213 -204
  295. meerk40t/gui/toolwidgets/toolwidget.py +39 -39
  296. meerk40t/gui/usbconnect.py +98 -91
  297. meerk40t/gui/utilitywidgets/buttonwidget.py +18 -18
  298. meerk40t/gui/utilitywidgets/checkboxwidget.py +90 -90
  299. meerk40t/gui/utilitywidgets/controlwidget.py +14 -14
  300. meerk40t/gui/utilitywidgets/cyclocycloidwidget.py +343 -340
  301. meerk40t/gui/utilitywidgets/debugwidgets.py +148 -0
  302. meerk40t/gui/utilitywidgets/handlewidget.py +27 -27
  303. meerk40t/gui/utilitywidgets/harmonograph.py +450 -447
  304. meerk40t/gui/utilitywidgets/openclosewidget.py +40 -40
  305. meerk40t/gui/utilitywidgets/rotationwidget.py +54 -54
  306. meerk40t/gui/utilitywidgets/scalewidget.py +75 -75
  307. meerk40t/gui/utilitywidgets/seekbarwidget.py +183 -183
  308. meerk40t/gui/utilitywidgets/togglewidget.py +142 -142
  309. meerk40t/gui/utilitywidgets/toolbarwidget.py +8 -8
  310. meerk40t/gui/wordlisteditor.py +985 -931
  311. meerk40t/gui/wxmeerk40t.py +1447 -1169
  312. meerk40t/gui/wxmmain.py +5644 -4112
  313. meerk40t/gui/wxmribbon.py +1591 -1076
  314. meerk40t/gui/wxmscene.py +1631 -1453
  315. meerk40t/gui/wxmtree.py +2416 -2089
  316. meerk40t/gui/wxutils.py +1769 -1099
  317. meerk40t/gui/zmatrix.py +102 -102
  318. meerk40t/image/__init__.py +1 -1
  319. meerk40t/image/dither.py +429 -0
  320. meerk40t/image/imagetools.py +2793 -2269
  321. meerk40t/internal_plugins.py +150 -130
  322. meerk40t/kernel/__init__.py +63 -12
  323. meerk40t/kernel/channel.py +259 -212
  324. meerk40t/kernel/context.py +538 -538
  325. meerk40t/kernel/exceptions.py +41 -41
  326. meerk40t/kernel/functions.py +463 -414
  327. meerk40t/kernel/jobs.py +100 -100
  328. meerk40t/kernel/kernel.py +3828 -3571
  329. meerk40t/kernel/lifecycles.py +71 -71
  330. meerk40t/kernel/module.py +49 -49
  331. meerk40t/kernel/service.py +147 -147
  332. meerk40t/kernel/settings.py +383 -343
  333. meerk40t/lihuiyu/controller.py +883 -876
  334. meerk40t/lihuiyu/device.py +1181 -1069
  335. meerk40t/lihuiyu/driver.py +1466 -1372
  336. meerk40t/lihuiyu/gui/gui.py +127 -106
  337. meerk40t/lihuiyu/gui/lhyaccelgui.py +377 -363
  338. meerk40t/lihuiyu/gui/lhycontrollergui.py +741 -651
  339. meerk40t/lihuiyu/gui/lhydrivergui.py +470 -446
  340. meerk40t/lihuiyu/gui/lhyoperationproperties.py +238 -237
  341. meerk40t/lihuiyu/gui/tcpcontroller.py +226 -190
  342. meerk40t/lihuiyu/interpreter.py +53 -53
  343. meerk40t/lihuiyu/laserspeed.py +450 -450
  344. meerk40t/lihuiyu/loader.py +90 -90
  345. meerk40t/lihuiyu/parser.py +404 -404
  346. meerk40t/lihuiyu/plugin.py +101 -102
  347. meerk40t/lihuiyu/tcp_connection.py +111 -109
  348. meerk40t/main.py +231 -165
  349. meerk40t/moshi/builder.py +788 -781
  350. meerk40t/moshi/controller.py +505 -499
  351. meerk40t/moshi/device.py +495 -442
  352. meerk40t/moshi/driver.py +862 -696
  353. meerk40t/moshi/gui/gui.py +78 -76
  354. meerk40t/moshi/gui/moshicontrollergui.py +538 -522
  355. meerk40t/moshi/gui/moshidrivergui.py +87 -75
  356. meerk40t/moshi/plugin.py +43 -43
  357. meerk40t/network/console_server.py +140 -57
  358. meerk40t/network/kernelserver.py +10 -9
  359. meerk40t/network/tcp_server.py +142 -140
  360. meerk40t/network/udp_server.py +103 -77
  361. meerk40t/network/web_server.py +404 -0
  362. meerk40t/newly/controller.py +1158 -1144
  363. meerk40t/newly/device.py +874 -732
  364. meerk40t/newly/driver.py +540 -412
  365. meerk40t/newly/gui/gui.py +219 -188
  366. meerk40t/newly/gui/newlyconfig.py +116 -101
  367. meerk40t/newly/gui/newlycontroller.py +193 -186
  368. meerk40t/newly/gui/operationproperties.py +51 -51
  369. meerk40t/newly/mock_connection.py +82 -82
  370. meerk40t/newly/newly_params.py +56 -56
  371. meerk40t/newly/plugin.py +1214 -1246
  372. meerk40t/newly/usb_connection.py +322 -322
  373. meerk40t/rotary/gui/gui.py +52 -46
  374. meerk40t/rotary/gui/rotarysettings.py +240 -232
  375. meerk40t/rotary/rotary.py +202 -98
  376. meerk40t/ruida/control.py +291 -91
  377. meerk40t/ruida/controller.py +138 -1088
  378. meerk40t/ruida/device.py +676 -231
  379. meerk40t/ruida/driver.py +534 -472
  380. meerk40t/ruida/emulator.py +1494 -1491
  381. meerk40t/ruida/exceptions.py +4 -4
  382. meerk40t/ruida/gui/gui.py +71 -76
  383. meerk40t/ruida/gui/ruidaconfig.py +239 -72
  384. meerk40t/ruida/gui/ruidacontroller.py +187 -184
  385. meerk40t/ruida/gui/ruidaoperationproperties.py +48 -47
  386. meerk40t/ruida/loader.py +54 -52
  387. meerk40t/ruida/mock_connection.py +57 -109
  388. meerk40t/ruida/plugin.py +124 -87
  389. meerk40t/ruida/rdjob.py +2084 -945
  390. meerk40t/ruida/serial_connection.py +116 -0
  391. meerk40t/ruida/tcp_connection.py +146 -0
  392. meerk40t/ruida/udp_connection.py +73 -0
  393. meerk40t/svgelements.py +9671 -9669
  394. meerk40t/tools/driver_to_path.py +584 -579
  395. meerk40t/tools/geomstr.py +5583 -4680
  396. meerk40t/tools/jhfparser.py +357 -292
  397. meerk40t/tools/kerftest.py +904 -890
  398. meerk40t/tools/livinghinges.py +1168 -1033
  399. meerk40t/tools/pathtools.py +987 -949
  400. meerk40t/tools/pmatrix.py +234 -0
  401. meerk40t/tools/pointfinder.py +942 -942
  402. meerk40t/tools/polybool.py +941 -940
  403. meerk40t/tools/rasterplotter.py +1660 -547
  404. meerk40t/tools/shxparser.py +1047 -901
  405. meerk40t/tools/ttfparser.py +726 -446
  406. meerk40t/tools/zinglplotter.py +595 -593
  407. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/LICENSE +21 -21
  408. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/METADATA +150 -139
  409. meerk40t-0.9.7020.dist-info/RECORD +446 -0
  410. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/WHEEL +1 -1
  411. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/top_level.txt +0 -1
  412. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/zip-safe +1 -1
  413. meerk40t/balormk/elementlightjob.py +0 -159
  414. meerk40t-0.9.3001.dist-info/RECORD +0 -437
  415. test/bootstrap.py +0 -63
  416. test/test_cli.py +0 -12
  417. test/test_core_cutcode.py +0 -418
  418. test/test_core_elements.py +0 -144
  419. test/test_core_plotplanner.py +0 -397
  420. test/test_core_viewports.py +0 -312
  421. test/test_drivers_grbl.py +0 -108
  422. test/test_drivers_lihuiyu.py +0 -443
  423. test/test_drivers_newly.py +0 -113
  424. test/test_element_degenerate_points.py +0 -43
  425. test/test_elements_classify.py +0 -97
  426. test/test_elements_penbox.py +0 -22
  427. test/test_file_svg.py +0 -176
  428. test/test_fill.py +0 -155
  429. test/test_geomstr.py +0 -1523
  430. test/test_geomstr_nodes.py +0 -18
  431. test/test_imagetools_actualize.py +0 -306
  432. test/test_imagetools_wizard.py +0 -258
  433. test/test_kernel.py +0 -200
  434. test/test_laser_speeds.py +0 -3303
  435. test/test_length.py +0 -57
  436. test/test_lifecycle.py +0 -66
  437. test/test_operations.py +0 -251
  438. test/test_operations_hatch.py +0 -57
  439. test/test_ruida.py +0 -19
  440. test/test_spooler.py +0 -22
  441. test/test_tools_rasterplotter.py +0 -29
  442. test/test_wobble.py +0 -133
  443. test/test_zingl.py +0 -124
  444. {test → meerk40t/cylinder}/__init__.py +0 -0
  445. /meerk40t/{core/element_commands.py → cylinder/gui/__init__.py} +0 -0
  446. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/entry_points.txt +0 -0
@@ -1,563 +1,651 @@
1
- """
2
- This is a giant list of console commands that deal with and often implement the elements system in the program.
3
- """
4
-
5
- from math import cos, isinf, sin, sqrt, tau
6
- from random import randint, shuffle
7
-
8
- from meerk40t.core.units import Length
9
- from meerk40t.svgelements import Circle, Path, Point, Polyline
10
-
11
-
12
- def plugin(kernel, lifecycle=None):
13
- _ = kernel.translation
14
- if lifecycle == "postboot":
15
- init_commands(kernel)
16
-
17
-
18
- def dist(a, b):
19
- """
20
- Function to return the Euclidean distance between two points
21
- @param a:
22
- @param b:
23
- @return:
24
- """
25
- return sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2))
26
-
27
-
28
- def is_inside(center, radius, p):
29
- """
30
- Function to check whether a point lies inside or on the boundaries of the circle
31
- @param center:
32
- @param radius:
33
- @param p:
34
- @return:
35
- """
36
- return dist(center, p) <= radius
37
-
38
-
39
- # The following two functions are used
40
- # To find the equation of the circle when
41
- # three points are given.
42
-
43
-
44
- def get_circle_center(bx, by, cx, cy):
45
- """
46
- Helper method to get a circle defined by 3 points
47
- @param bx:
48
- @param by:
49
- @param cx:
50
- @param cy:
51
- @return:
52
- """
53
-
54
- B = bx * bx + by * by
55
- C = cx * cx + cy * cy
56
- D = bx * cy - by * cx
57
- return [(cy * B - by * C) / (2 * D), (bx * C - cx * B) / (2 * D)]
58
-
59
-
60
- def circle_from1(A, B):
61
- """
62
- Function to return the smallest circle that intersects 2 points
63
- @param A:
64
- @param B:
65
- @return:
66
- """
67
- # Set the center to be the midpoint of A and B
68
- C = [(A[0] + B[0]) / 2.0, (A[1] + B[1]) / 2.0]
69
-
70
- # Set the radius to be half the distance AB
71
- return C, dist(A, B) / 2.0
72
-
73
-
74
- def circle_from2(A, B, C):
75
- """
76
- Function to return a unique circle that intersects three points
77
- @param A:
78
- @param B:
79
- @param C:
80
- @return:
81
- """
82
- if A == B:
83
- I, radius = circle_from1(A, C)
84
- return I, radius
85
- elif A == C:
86
- I, radius = circle_from1(A, B)
87
- return I, radius
88
- elif B == C:
89
- I, radius = circle_from1(A, B)
90
- return I, radius
91
- else:
92
- I = get_circle_center(B[0] - A[0], B[1] - A[1], C[0] - A[0], C[1] - A[1])
93
- I[0] += A[0]
94
- I[1] += A[1]
95
- radius = dist(I, A)
96
- return I, radius
97
-
98
-
99
- def is_valid_circle(center, radius, P):
100
- """
101
- Function to check whether a circle encloses the given points
102
-
103
- @param center:
104
- @param radius:
105
- @param P:
106
- @return:
107
- """
108
-
109
- # Iterating through all the points
110
- # to check whether the points
111
- # lie inside the circle or not
112
- for p in P:
113
- if not is_inside(center, radius, p):
114
- return False
115
- return True
116
-
117
-
118
- def min_circle_trivial(P):
119
- """
120
- Function to return the minimum enclosing circle for N <= 3
121
- @param P:
122
- @return:
123
- """
124
- assert len(P) <= 3
125
-
126
- if not P:
127
- return [0, 0], 0
128
-
129
- elif len(P) == 1:
130
- return P[0], 0
131
-
132
- elif len(P) == 2:
133
- center, radius = circle_from1(P[0], P[1])
134
- return center, radius
135
-
136
- # To check if MEC can be determined
137
- # by 2 points only
138
- for i in range(3):
139
- for j in range(i + 1, 3):
140
- center, radius = circle_from1(P[i], P[j])
141
- if is_valid_circle(center, radius, P):
142
- return center, radius
143
-
144
- center, radius = circle_from2(P[0], P[1], P[2])
145
- return center, radius
146
-
147
-
148
- def welzl_helper(P, R, n):
149
- """
150
- Returns the MEC using Welzl's algorithm takes a set of input points P and a set R points on the circle boundary.
151
- n represents the number of points in P that are not yet processed.
152
-
153
- @param P:
154
- @param R:
155
- @param n:
156
- @return:
157
- """
158
- # print (f"Welzl_helper. P={len(P)} pts, R={len(R)} pts, n={n}")
159
- # Base case when all points processed or |R| = 3
160
- if n <= 0 or len(R) == 3:
161
- center, radius = min_circle_trivial(R)
162
- return center, radius
163
-
164
- # Pick a random point randomly
165
- idx = randint(0, n - 1)
166
- p = P[idx]
167
-
168
- # Put the picked point at the end of P
169
- # since it's more efficient than
170
- # deleting from the middle of the vector
171
- P[idx], P[n - 1] = P[n - 1], P[idx]
172
-
173
- # Get the MEC circle d from the
174
- # set of points P - :p
175
- dcenter, dradius = welzl_helper(P, R.copy(), n - 1)
176
-
177
- # If d contains p, return d
178
- if is_inside(dcenter, dradius, p):
179
- return dcenter, dradius
180
-
181
- # Otherwise, must be on the boundary of the MEC
182
- R.append(p)
183
-
184
- # Return the MEC for P - :p and R U :p
185
- dcenter, dradius = welzl_helper(P, R.copy(), n - 1)
186
- return dcenter, dradius
187
-
188
-
189
- def welzl(P):
190
- P_copy = P.copy()
191
- shuffle(P_copy)
192
- center, radius = welzl_helper(P_copy, [], len(P_copy))
193
- return center, radius
194
-
195
-
196
- def generate_hull_shape_segment(data):
197
- pts = []
198
- for node in data:
199
- try:
200
- path = node.as_path()
201
- except AttributeError:
202
- path = None
203
- if path is not None:
204
- p = path.first_point
205
- pts.append(p)
206
- for segment in path:
207
- p = segment.end
208
- pts.append(p)
209
- else:
210
- bounds = node.bounds
211
- if bounds:
212
- pts.extend(
213
- [
214
- (bounds[0], bounds[1]),
215
- (bounds[0], bounds[3]),
216
- (bounds[2], bounds[1]),
217
- (bounds[2], bounds[3]),
218
- (bounds[0], bounds[1]),
219
- ]
220
- )
221
- return pts
222
-
223
-
224
- def generate_hull_shape_quick(data):
225
- if not data:
226
- return []
227
- min_val = [float("inf"), float("inf")]
228
- max_val = [-float("inf"), -float("inf")]
229
- for node in data:
230
- bounds = node.bounds
231
- if bounds:
232
- min_val[0] = min(min_val[0], bounds[0])
233
- min_val[1] = min(min_val[1], bounds[1])
234
- max_val[0] = max(max_val[0], bounds[2])
235
- max_val[1] = max(max_val[1], bounds[3])
236
- if isinf(min_val[0]):
237
- return []
238
- return [
239
- (min_val[0], min_val[1]),
240
- (max_val[0], min_val[1]),
241
- (max_val[0], max_val[1]),
242
- (min_val[0], max_val[1]),
243
- (min_val[0], min_val[1]),
244
- ]
245
-
246
-
247
- def generate_hull_shape_hull(data):
248
- pts = []
249
- for node in data:
250
- try:
251
- path = node.as_path()
252
- p = path.first_point
253
- if p is None:
254
- continue
255
- pts.append(p)
256
- for segment in path:
257
- pts.append(segment.end)
258
- pts.append(p)
259
- except AttributeError:
260
- bounds = node.bounds
261
- if bounds:
262
- pts.extend(
263
- [
264
- (bounds[0], bounds[1]),
265
- (bounds[0], bounds[3]),
266
- (bounds[2], bounds[1]),
267
- (bounds[2], bounds[3]),
268
- ]
269
- )
270
- hull = list(Point.convex_hull(pts))
271
- if len(hull) != 0:
272
- hull.append(hull[0]) # loop
273
- return hull
274
-
275
-
276
- def generate_hull_shape_complex(data, resolution=None):
277
- if resolution is None:
278
- resolution = 500 # How coarse / fine shall a subpath be split
279
- else:
280
- resolution = int(resolution)
281
- pts = []
282
- for node in data:
283
- try:
284
- path = node.as_path()
285
-
286
- from numpy import linspace
287
-
288
- for subpath in path.as_subpaths():
289
- psp = Path(subpath)
290
- p = psp.first_point
291
- pts.append(p)
292
- positions = linspace(0, 1, num=resolution, endpoint=True)
293
- subj = psp.npoint(positions)
294
- s = list(map(Point, subj))
295
- pts.extend(s)
296
- except AttributeError:
297
- bounds = node.bounds
298
- if bounds:
299
- pts.extend(
300
- [
301
- (bounds[0], bounds[1]),
302
- (bounds[0], bounds[3]),
303
- (bounds[2], bounds[1]),
304
- (bounds[2], bounds[3]),
305
- ]
306
- )
307
- hull = list(Point.convex_hull(pts))
308
- if len(hull) != 0:
309
- hull.append(hull[0]) # loop
310
- return hull
311
-
312
-
313
- def generate_hull_shape_circle_data(data):
314
- pts = []
315
- for node in data:
316
- try:
317
- path = node.as_path()
318
- except AttributeError:
319
- path = None
320
- if path is not None:
321
- p = path.first_point
322
- pts += [p]
323
- for segment in path:
324
- p = segment.end
325
- pts += [p]
326
- else:
327
- bounds = node.bounds
328
- if bounds:
329
- pts += [
330
- (bounds[0], bounds[1]),
331
- (bounds[0], bounds[3]),
332
- (bounds[2], bounds[1]),
333
- (bounds[2], bounds[3]),
334
- ]
335
- # We could directly call welzl, but for a significant
336
- # amount of point this will cause a huge amount
337
- # of recursive calls (which will fail)
338
- # -> so we apply it to the hull points
339
- hull = list(Point.convex_hull(pts))
340
- mec_center, mec_radius = welzl(hull)
341
-
342
- # So now we have a circle with (mec[0], mec[1]), and mec_radius
343
- return mec_center, mec_radius
344
-
345
-
346
- def generate_hull_shape_circle(data):
347
- mec_center, mec_radius = generate_hull_shape_circle_data(data)
348
-
349
- # So now we have a circle with (mec[0], mec[1]), and mec_radius
350
- hull = []
351
- RES = 100
352
- for i in range(RES):
353
- hull += [
354
- (
355
- mec_center[0] + mec_radius * cos(i / RES * tau),
356
- mec_center[1] + mec_radius * sin(i / RES * tau),
357
- )
358
- ]
359
- if len(hull) != 0:
360
- hull.append(hull[0]) # loop
361
- return hull
362
-
363
-
364
- def init_commands(kernel):
365
- self = kernel.elements
366
-
367
- _ = kernel.translation
368
-
369
- choices = [
370
- {
371
- "attr": "trace_start_method",
372
- "object": self,
373
- "default": 0,
374
- "type": int,
375
- "label": _("Delay hull trace"),
376
- "tip": _("Establish if and how an element hull trace should wait"),
377
- "page": "Laser",
378
- "section": "General",
379
- "style": "option",
380
- "display": (_("Immediate"), _("User confirmation"), _("Delay 5 seconds")),
381
- "choices": (0, 1, 2),
382
- },
383
- ]
384
- kernel.register_choices("preferences", choices)
385
-
386
- classify_new = self.post_classify
387
-
388
- # ==========
389
- # TRACE OPERATIONS
390
- # ==========
391
-
392
- @self.console_argument(
393
- "method",
394
- help=_("Method to use (one of quick, hull, complex, segment, circle)"),
395
- )
396
- @self.console_argument("resolution")
397
- @self.console_option(
398
- "start",
399
- "s",
400
- type=int,
401
- help=_("0=immediate, 1=User interaction, 2=wait for 5 seconds"),
402
- )
403
- @self.console_command(
404
- "trace",
405
- help=_("trace the given elements"),
406
- input_type=("elements", None),
407
- )
408
- def trace_trace_spooler(
409
- command,
410
- channel,
411
- _,
412
- method=None,
413
- resolution=None,
414
- start=None,
415
- data=None,
416
- **kwargs,
417
- ):
418
- if method is None:
419
- method = "quick"
420
- method = method.lower()
421
- if method not in ("segment", "quick", "hull", "complex", "circle"):
422
- channel(
423
- _(
424
- "Invalid method, please use one of quick, hull, complex, segment, circle."
425
- )
426
- )
427
- return
428
-
429
- spooler = self.device.spooler
430
- if data is None:
431
- data = list(self.elems(emphasized=True))
432
- if len(data) == 0:
433
- channel(_("No elements bounds to trace"))
434
- return
435
- if method == "segment":
436
- hull = generate_hull_shape_segment(data)
437
- elif method == "quick":
438
- hull = generate_hull_shape_quick(data)
439
- elif method == "hull":
440
- hull = generate_hull_shape_hull(data)
441
- elif method == "complex":
442
- hull = generate_hull_shape_complex(data, resolution)
443
- elif method == "circle":
444
- hull = generate_hull_shape_circle(data)
445
- else:
446
- raise ValueError
447
- if start is None:
448
- # Lets take system default
449
- start = self.trace_start_method
450
- if start < 0 or start > 2:
451
- start = 0
452
- if len(hull) == 0:
453
- channel(_("No elements bounds to trace."))
454
- return
455
-
456
- def run_shape(_spooler, startmethod, _hull):
457
- def trace_hull(startmethod=0):
458
- if startmethod == 0:
459
- # Immediately
460
- pass
461
- elif startmethod == 1:
462
- # Dialog
463
- yield "console", 'interrupt "Trace is about to start"'
464
- elif startmethod == 2:
465
- # Wait for some seconds
466
- yield "wait", 5000
467
-
468
- yield "wait_finish"
469
- yield "rapid_mode"
470
- idx = 0
471
- for p in _hull:
472
- idx += 1
473
- yield (
474
- "move_abs",
475
- Length(amount=p[0]).length_mm,
476
- Length(amount=p[1]).length_mm,
477
- )
478
-
479
- _spooler.laserjob(
480
- list(trace_hull(startmethod)), label=f"Trace Job: {method}", helper=True
481
- )
482
-
483
- run_shape(spooler, start, hull)
484
-
485
- @self.console_argument(
486
- "method",
487
- help=_("Method to use (one of quick, hull, complex, segment, circle)"),
488
- )
489
- @self.console_argument(
490
- "resolution", help=_("Resolution for complex slicing, default=500")
491
- )
492
- @self.console_command(
493
- "tracegen",
494
- help=_("create the trace around the given elements"),
495
- input_type=("elements", None),
496
- output_type="elements",
497
- )
498
- def trace_trace_generator(
499
- command,
500
- channel,
501
- _,
502
- method=None,
503
- resolution=None,
504
- data=None,
505
- post=None,
506
- **kwargs,
507
- ):
508
- if method is None:
509
- method = "quick"
510
- method = method.lower()
511
- if not method in ("segment", "quick", "hull", "complex", "circle"):
512
- channel(
513
- _(
514
- "Invalid method, please use one of quick, hull, complex, segment, circle."
515
- )
516
- )
517
- return
518
-
519
- if data is None:
520
- data = list(self.elems(emphasized=True))
521
- if len(data) == 0:
522
- channel(_("No elements bounds to trace"))
523
- return
524
- shape_type = "elem polyline"
525
- if method == "segment":
526
- hull = generate_hull_shape_segment(data)
527
- elif method == "quick":
528
- hull = generate_hull_shape_quick(data)
529
- elif method == "hull":
530
- hull = generate_hull_shape_hull(data)
531
- elif method == "complex":
532
- hull = generate_hull_shape_complex(data, resolution)
533
- elif method == "circle":
534
- shape_type = "elem ellipse"
535
- s_center, s_radius = generate_hull_shape_circle_data(data)
536
- else:
537
- raise ValueError
538
- if shape_type == "elem polyline":
539
- if len(hull) == 0:
540
- channel(_("No elements bounds to trace."))
541
- return
542
- shape = Polyline(hull)
543
- if shape.is_degenerate():
544
- channel(_("Shape is degenerate."))
545
- return "elements", data
546
- elif shape_type == "elem ellipse":
547
- shape = Circle(cx=s_center[0], cy=s_center[1], rx=s_radius, ry=s_radius)
548
- if shape.is_degenerate():
549
- channel(_("Shape is degenerate."))
550
- return "elements", data
551
- node = self.elem_branch.add(shape=shape, type=shape_type)
552
- node.stroke = self.default_stroke
553
- node.stroke_width = self.default_strokewidth
554
- node.fill = self.default_fill
555
- node.altered()
556
- self.set_emphasis([node])
557
- node.focus()
558
- data.append(node)
559
- # Newly created! Classification needed?
560
- post.append(classify_new(data))
561
- return "elements", data
562
-
563
- # --------------------------- END COMMANDS ------------------------------
1
+ """
2
+ This module contains a collection of console commands that manage and implement the elements system related to tracing shapes.
3
+ It provides functionalities for calculating minimum enclosing circles, generating hull shapes, and tracing elements based on various methods.
4
+
5
+ Functions:
6
+ - plugin: Initializes the console commands for the trace system.
7
+ - dist: Calculates the Euclidean distance between two points.
8
+ - is_inside: Checks if a point lies inside or on the boundary of a circle.
9
+ - get_circle_center: Computes the center of a circle defined by three points.
10
+ - circle_from1: Returns the smallest circle that intersects two points.
11
+ - circle_from2: Returns a unique circle that intersects three points.
12
+ - is_valid_circle: Checks if a circle encloses a given set of points.
13
+ - min_circle_trivial: Returns the minimum enclosing circle for up to three points.
14
+ - welzl_helper: Implements Welzl's algorithm to find the minimum enclosing circle.
15
+ - welzl: Finds the minimum enclosing circle using a randomized approach.
16
+ - generate_hull_shape_segment: Generates a hull shape segment from the provided data.
17
+ - generate_hull_shape_quick: Quickly generates a bounding box for the provided data.
18
+ - generate_hull_shape_hull: Generates a convex hull shape from the provided data.
19
+ - generate_hull_shape_circle_data: Computes the minimum enclosing circle for the provided data.
20
+ - generate_hull_shape_circle: Generates a circular hull shape based on the minimum enclosing circle.
21
+ - init_commands: Sets up the console commands related to tracing operations.
22
+ - trace_trace_spooler: Traces the given elements using a specified method.
23
+ - trace_trace_generator: Creates a trace around the given elements based on a specified method.
24
+
25
+ """
26
+
27
+ from math import cos, isinf, sin, sqrt, tau
28
+ from random import randint, shuffle
29
+
30
+ from meerk40t.core.units import Length
31
+ from meerk40t.svgelements import Circle, Path, Point, Polyline
32
+ from meerk40t.tools.geomstr import Geomstr
33
+
34
+ def plugin(kernel, lifecycle=None):
35
+ _ = kernel.translation
36
+ if lifecycle == "postboot":
37
+ init_commands(kernel)
38
+
39
+
40
+ def dist(a, b):
41
+ """
42
+ Function to return the Euclidean distance between two points
43
+ @param a:
44
+ @param b:
45
+ @return:
46
+ """
47
+ return sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2))
48
+
49
+
50
+ def is_inside(center, radius, p):
51
+ """
52
+ Function to check whether a point lies inside or on the boundaries of the circle
53
+ @param center:
54
+ @param radius:
55
+ @param p:
56
+ @return:
57
+ """
58
+ return dist(center, p) <= radius
59
+
60
+
61
+ # The following two functions are used
62
+ # To find the equation of the circle when
63
+ # three points are given.
64
+
65
+
66
+ def get_circle_center(bx, by, cx, cy):
67
+ """
68
+ Helper method to get a circle defined by 3 points
69
+ @param bx:
70
+ @param by:
71
+ @param cx:
72
+ @param cy:
73
+ @return:
74
+ """
75
+
76
+ B = bx * bx + by * by
77
+ C = cx * cx + cy * cy
78
+ D = bx * cy - by * cx
79
+ return [(cy * B - by * C) / (2 * D), (bx * C - cx * B) / (2 * D)]
80
+
81
+
82
+ def circle_from1(A, B):
83
+ """
84
+ Function to return the smallest circle that intersects 2 points
85
+ @param A:
86
+ @param B:
87
+ @return:
88
+ """
89
+ # Set the center to be the midpoint of A and B
90
+ C = [(A[0] + B[0]) / 2.0, (A[1] + B[1]) / 2.0]
91
+
92
+ # Set the radius to be half the distance AB
93
+ return C, dist(A, B) / 2.0
94
+
95
+
96
+ def circle_from2(A, B, C):
97
+ """
98
+ Function to return a unique circle that intersects three points
99
+ @param A:
100
+ @param B:
101
+ @param C:
102
+ @return:
103
+ """
104
+ if A == B:
105
+ I, radius = circle_from1(A, C)
106
+ return I, radius
107
+ elif A == C:
108
+ I, radius = circle_from1(A, B)
109
+ return I, radius
110
+ elif B == C:
111
+ I, radius = circle_from1(A, B)
112
+ return I, radius
113
+ else:
114
+ I = get_circle_center(B[0] - A[0], B[1] - A[1], C[0] - A[0], C[1] - A[1])
115
+ I[0] += A[0]
116
+ I[1] += A[1]
117
+ radius = dist(I, A)
118
+ return I, radius
119
+
120
+
121
+ def is_valid_circle(center, radius, P):
122
+ """
123
+ Function to check whether a circle encloses the given points
124
+
125
+ @param center:
126
+ @param radius:
127
+ @param P:
128
+ @return:
129
+ """
130
+
131
+ # Iterating through all the points
132
+ # to check whether the points
133
+ # lie inside the circle or not
134
+ for p in P:
135
+ if not is_inside(center, radius, p):
136
+ return False
137
+ return True
138
+
139
+
140
+ def min_circle_trivial(P):
141
+ """
142
+ Function to return the minimum enclosing circle for N <= 3
143
+ @param P:
144
+ @return:
145
+ """
146
+ assert len(P) <= 3
147
+
148
+ if not P:
149
+ return [0, 0], 0
150
+
151
+ elif len(P) == 1:
152
+ return P[0], 0
153
+
154
+ elif len(P) == 2:
155
+ center, radius = circle_from1(P[0], P[1])
156
+ return center, radius
157
+
158
+ # To check if MEC can be determined
159
+ # by 2 points only
160
+ for i in range(3):
161
+ for j in range(i + 1, 3):
162
+ center, radius = circle_from1(P[i], P[j])
163
+ if is_valid_circle(center, radius, P):
164
+ return center, radius
165
+
166
+ center, radius = circle_from2(P[0], P[1], P[2])
167
+ return center, radius
168
+
169
+
170
+ def welzl_helper(P, R, n):
171
+ """
172
+ Returns the MEC using Welzl's algorithm takes a set of input points P and a set R points on the circle boundary.
173
+ n represents the number of points in P that are not yet processed.
174
+
175
+ @param P:
176
+ @param R:
177
+ @param n:
178
+ @return:
179
+ """
180
+ # print (f"Welzl_helper. P={len(P)} pts, R={len(R)} pts, n={n}")
181
+ # Base case when all points processed or |R| = 3
182
+ if n <= 0 or len(R) == 3:
183
+ center, radius = min_circle_trivial(R)
184
+ return center, radius
185
+
186
+ # Pick a random point randomly
187
+ idx = randint(0, n - 1)
188
+ p = P[idx]
189
+
190
+ # Put the picked point at the end of P
191
+ # since it's more efficient than
192
+ # deleting from the middle of the vector
193
+ P[idx], P[n - 1] = P[n - 1], P[idx]
194
+
195
+ # Get the MEC circle d from the
196
+ # set of points P - :p
197
+ dcenter, dradius = welzl_helper(P, R.copy(), n - 1)
198
+
199
+ # If d contains p, return d
200
+ if is_inside(dcenter, dradius, p):
201
+ return dcenter, dradius
202
+
203
+ # Otherwise, must be on the boundary of the MEC
204
+ R.append(p)
205
+
206
+ # Return the MEC for P - :p and R U :p
207
+ dcenter, dradius = welzl_helper(P, R.copy(), n - 1)
208
+ return dcenter, dradius
209
+
210
+
211
+ def welzl(P):
212
+ P_copy = P.copy()
213
+ shuffle(P_copy)
214
+ center, radius = welzl_helper(P_copy, [], len(P_copy))
215
+ return center, radius
216
+
217
+
218
+ def generate_hull_shape_segment(data):
219
+ pts = []
220
+ for node in data:
221
+ try:
222
+ path = node.as_path()
223
+ except AttributeError:
224
+ path = None
225
+ if path is not None:
226
+ p = path.first_point
227
+ pts.append(p)
228
+ for segment in path:
229
+ p = segment.end
230
+ pts.append(p)
231
+ else:
232
+ bounds = node.bounds
233
+ if bounds:
234
+ pts.extend(
235
+ [
236
+ (bounds[0], bounds[1]),
237
+ (bounds[0], bounds[3]),
238
+ (bounds[2], bounds[1]),
239
+ (bounds[2], bounds[3]),
240
+ (bounds[0], bounds[1]),
241
+ ]
242
+ )
243
+ return pts
244
+
245
+
246
+ def generate_hull_shape_quick(data):
247
+ if not data:
248
+ return []
249
+ min_val = [float("inf"), float("inf")]
250
+ max_val = [-float("inf"), -float("inf")]
251
+ for node in data:
252
+ bounds = node.bounds
253
+ if bounds:
254
+ min_val[0] = min(min_val[0], bounds[0])
255
+ min_val[1] = min(min_val[1], bounds[1])
256
+ max_val[0] = max(max_val[0], bounds[2])
257
+ max_val[1] = max(max_val[1], bounds[3])
258
+ if isinf(min_val[0]):
259
+ return []
260
+ return [
261
+ (min_val[0], min_val[1]),
262
+ (max_val[0], min_val[1]),
263
+ (max_val[0], max_val[1]),
264
+ (min_val[0], max_val[1]),
265
+ (min_val[0], min_val[1]),
266
+ ]
267
+
268
+
269
+ def generate_hull_shape_hull(data):
270
+ # pts = []
271
+ # for node in data:
272
+ # if hasattr(node, "convex_hull"):
273
+ # ghull = node.convex_hull()
274
+ # if ghull is not None:
275
+ # for pt in ghull.as_points():
276
+ # pts.append((pt.real, pt.imag))
277
+ # continue
278
+ # try:
279
+ # path = node.as_path()
280
+ # p = path.first_point
281
+ # if p is None:
282
+ # continue
283
+ # pts.append(p)
284
+ # for segment in path:
285
+ # pts.append(segment.end)
286
+ # pts.append(p)
287
+ # except AttributeError:
288
+ # bounds = node.bounds
289
+ # if bounds:
290
+ # pts.extend(
291
+ # [
292
+ # (bounds[0], bounds[1]),
293
+ # (bounds[0], bounds[3]),
294
+ # (bounds[2], bounds[1]),
295
+ # (bounds[2], bounds[3]),
296
+ # ]
297
+ # )
298
+ # hull = list(Point.convex_hull(pts))
299
+ geometry = Geomstr()
300
+ for node in data:
301
+ try:
302
+ e = None
303
+ if hasattr(node, "convex_hull"):
304
+ e = node.convex_hull()
305
+ if e is None:
306
+ e = node.as_geometry()
307
+ except AttributeError:
308
+ continue
309
+ geometry.append(e)
310
+
311
+ # Convert to hull.
312
+ resolution = float(Length("1mm"))
313
+ hull = Geomstr.hull(geometry, distance=int(resolution))
314
+ # cpts = list(hull.as_points())
315
+ pts = list((p.real, p.imag) for p in hull.as_points())
316
+ if len(pts) != 0:
317
+ pts.append(pts[0]) # loop
318
+ return pts
319
+
320
+ """
321
+ There is no need for shape_complex any more as the regular hull routine already uses interpolation
322
+ def generate_hull_shape_complex(data, resolution=None):
323
+ if resolution is None:
324
+ resolution = 500 # How coarse / fine shall a subpath be split
325
+ else:
326
+ resolution = int(resolution)
327
+ pts = []
328
+ for node in data:
329
+ try:
330
+ path = node.as_path()
331
+
332
+ from numpy import linspace
333
+
334
+ for subpath in path.as_subpaths():
335
+ psp = Path(subpath)
336
+ p = psp.first_point
337
+ pts.append(p)
338
+ positions = linspace(0, 1, num=resolution, endpoint=True)
339
+ subj = psp.npoint(positions)
340
+ s = list(map(Point, subj))
341
+ pts.extend(s)
342
+ except AttributeError:
343
+ bounds = node.bounds
344
+ if bounds:
345
+ pts.extend(
346
+ [
347
+ (bounds[0], bounds[1]),
348
+ (bounds[0], bounds[3]),
349
+ (bounds[2], bounds[1]),
350
+ (bounds[2], bounds[3]),
351
+ ]
352
+ )
353
+ hull = list(Point.convex_hull(pts))
354
+ if len(hull) != 0:
355
+ hull.append(hull[0]) # loop
356
+ return hull
357
+ """
358
+
359
+ def generate_hull_shape_circle_data(data):
360
+ pts = []
361
+ for node in data:
362
+ try:
363
+ path = node.as_path()
364
+ except AttributeError:
365
+ path = None
366
+ if path is not None:
367
+ p = path.first_point
368
+ pts += [p]
369
+ for segment in path:
370
+ p = segment.end
371
+ pts += [p]
372
+ else:
373
+ bounds = node.bounds
374
+ if bounds:
375
+ pts += [
376
+ (bounds[0], bounds[1]),
377
+ (bounds[0], bounds[3]),
378
+ (bounds[2], bounds[1]),
379
+ (bounds[2], bounds[3]),
380
+ ]
381
+ # We could directly call welzl, but for a significant
382
+ # amount of point this will cause a huge amount
383
+ # of recursive calls (which will fail)
384
+ # -> so we apply it to the hull points
385
+ hull = list(Point.convex_hull(pts))
386
+ mec_center, mec_radius = welzl(hull)
387
+
388
+ # So now we have a circle with (mec[0], mec[1]), and mec_radius
389
+ return mec_center, mec_radius
390
+
391
+
392
+ def generate_hull_shape_circle(data):
393
+ mec_center, mec_radius = generate_hull_shape_circle_data(data)
394
+
395
+ # So now we have a circle with (mec[0], mec[1]), and mec_radius
396
+ hull = []
397
+ RES = 100
398
+ for i in range(RES):
399
+ hull += [
400
+ (
401
+ mec_center[0] + mec_radius * cos(i / RES * tau),
402
+ mec_center[1] + mec_radius * sin(i / RES * tau),
403
+ )
404
+ ]
405
+ if len(hull) != 0:
406
+ hull.append(hull[0]) # loop
407
+ return hull
408
+
409
+
410
+ def init_commands(kernel):
411
+ self = kernel.elements
412
+
413
+ _ = kernel.translation
414
+
415
+ choices = [
416
+ {
417
+ "attr": "trace_start_method",
418
+ "object": self,
419
+ "default": 0,
420
+ "type": int,
421
+ "label": _("Delay hull trace"),
422
+ "tip": _("Establish if and how an element hull trace should wait"),
423
+ "page": "Laser",
424
+ "section": "General",
425
+ "style": "option",
426
+ "display": (_("Immediate"), _("User confirmation"), _("Delay 5 seconds")),
427
+ "choices": (0, 1, 2),
428
+ },
429
+ ]
430
+ kernel.register_choices("preferences", choices)
431
+
432
+ classify_new = self.post_classify
433
+
434
+ # ==========
435
+ # TRACE OPERATIONS
436
+ # ==========
437
+
438
+ @self.console_argument(
439
+ "method",
440
+ help=_("Method to use (one of quick, hull, segment, circle)"),
441
+ )
442
+ @self.console_argument("resolution")
443
+ @self.console_option(
444
+ "start",
445
+ "s",
446
+ type=int,
447
+ help=_("0=immediate, 1=User interaction, 2=wait for 5 seconds"),
448
+ )
449
+ @self.console_option(
450
+ "force",
451
+ "f",
452
+ type=bool,
453
+ action="store_true",
454
+ help=_("force the inclusion of non-assigned/non-active elements"),
455
+ )
456
+ @self.console_command(
457
+ "trace",
458
+ help=_("trace the given elements"),
459
+ input_type=("elements", None),
460
+ )
461
+ def trace_trace_spooler(
462
+ command,
463
+ channel,
464
+ _,
465
+ method=None,
466
+ resolution=None,
467
+ start=None,
468
+ force=None,
469
+ data=None,
470
+ **kwargs,
471
+ ):
472
+ if method is None:
473
+ method = "quick"
474
+ if force is None:
475
+ force = False
476
+ method = method.lower()
477
+ if method not in ("segment", "quick", "hull", "circle"):
478
+ channel(
479
+ _(
480
+ "Invalid method, please use one of quick, hull, segment, circle."
481
+ )
482
+ )
483
+ return
484
+
485
+ spooler = self.device.spooler
486
+ if data is None:
487
+ data = list(self.elems(emphasized=True))
488
+ if len(data) == 0:
489
+ channel(_("No elements bounds to trace"))
490
+ return
491
+ # Let's see whether there are non-burnable elements
492
+ target_data = []
493
+ if force:
494
+ target_data = [e for e in data]
495
+ else:
496
+ unused = 0
497
+ for node in data:
498
+ if len(node._references) == 0 and node.type not in ("file", "group"):
499
+ unused += 1
500
+ else:
501
+ will_be_burnt = False
502
+ for refnode in node._references:
503
+ op = refnode.parent
504
+ if op is not None:
505
+ try:
506
+ if op.output:
507
+ will_be_burnt = True
508
+ break
509
+ except AttributeError:
510
+ pass
511
+ if will_be_burnt:
512
+ target_data.append(node)
513
+ else:
514
+ unused += 1
515
+ if unused > 0:
516
+ msg = _(
517
+ f"There are {unused} elements, that will not be burnt as they are not "
518
+ + "contained in ops or are in disabled operations.\n"
519
+ + "These will not be considered in the hull!\n"
520
+ + "You can force their inclusion with the --force option"
521
+ ).format(unused=unused)
522
+ channel(msg)
523
+ if method == "segment":
524
+ hull = generate_hull_shape_segment(target_data)
525
+ elif method == "quick":
526
+ hull = generate_hull_shape_quick(target_data)
527
+ elif method == "hull":
528
+ hull = generate_hull_shape_hull(target_data)
529
+ # elif method == "complex":
530
+ # hull = generate_hull_shape_complex(target_data, resolution)
531
+ elif method == "circle":
532
+ hull = generate_hull_shape_circle(target_data)
533
+ else:
534
+ raise ValueError
535
+ if start is None:
536
+ # Let's take system default
537
+ start = self.trace_start_method
538
+ if start < 0 or start > 2:
539
+ start = 0
540
+ if len(hull) == 0:
541
+ channel(_("No elements bounds to trace."))
542
+ return
543
+
544
+ def run_shape(_spooler, startmethod, _hull):
545
+ def trace_hull(startmethod=0):
546
+ if startmethod == 0:
547
+ # Immediately
548
+ pass
549
+ elif startmethod == 1:
550
+ # Dialog
551
+ yield "console", 'interrupt "Trace is about to start"'
552
+ elif startmethod == 2:
553
+ # Wait for some seconds
554
+ yield "wait", 5000
555
+
556
+ yield "wait_finish"
557
+ yield "rapid_mode"
558
+ idx = 0
559
+ for p in _hull:
560
+ idx += 1
561
+ yield (
562
+ "move_abs",
563
+ Length(amount=p[0]).length_mm,
564
+ Length(amount=p[1]).length_mm,
565
+ )
566
+
567
+ _spooler.laserjob(
568
+ list(trace_hull(startmethod)), label=f"Trace Job: {method}", helper=True
569
+ )
570
+
571
+ run_shape(spooler, start, hull)
572
+
573
+ @self.console_argument(
574
+ "method",
575
+ help=_("Method to use (one of quick, hull, segment, circle)"),
576
+ )
577
+ @self.console_argument(
578
+ "resolution", help=_("Resolution for complex slicing, default=500")
579
+ )
580
+ @self.console_command(
581
+ "tracegen",
582
+ help=_("create the trace around the given elements"),
583
+ input_type=("elements", None),
584
+ output_type="elements",
585
+ )
586
+ def trace_trace_generator(
587
+ command,
588
+ channel,
589
+ _,
590
+ method=None,
591
+ resolution=None,
592
+ data=None,
593
+ post=None,
594
+ **kwargs,
595
+ ):
596
+ if method is None:
597
+ method = "quick"
598
+ method = method.lower()
599
+ if not method in ("segment", "quick", "hull", "circle"):
600
+ channel(
601
+ _(
602
+ "Invalid method, please use one of quick, hull, segment, circle."
603
+ )
604
+ )
605
+ return
606
+
607
+ if data is None:
608
+ data = list(self.elems(emphasized=True))
609
+ if len(data) == 0:
610
+ channel(_("No elements bounds to trace"))
611
+ return
612
+ shape_type = "elem polyline"
613
+ if method == "segment":
614
+ hull = generate_hull_shape_segment(data)
615
+ elif method == "quick":
616
+ hull = generate_hull_shape_quick(data)
617
+ elif method == "hull":
618
+ hull = generate_hull_shape_hull(data)
619
+ # elif method == "complex":
620
+ # hull = generate_hull_shape_complex(data, resolution)
621
+ elif method == "circle":
622
+ shape_type = "elem ellipse"
623
+ s_center, s_radius = generate_hull_shape_circle_data(data)
624
+ else:
625
+ raise ValueError
626
+ if shape_type == "elem polyline":
627
+ if len(hull) == 0:
628
+ channel(_("No elements bounds to trace."))
629
+ return
630
+ shape = Polyline(hull)
631
+ if shape.is_degenerate():
632
+ channel(_("Shape is degenerate."))
633
+ return "elements", data
634
+ elif shape_type == "elem ellipse":
635
+ shape = Circle(cx=s_center[0], cy=s_center[1], rx=s_radius, ry=s_radius)
636
+ if shape.is_degenerate():
637
+ channel(_("Shape is degenerate."))
638
+ return "elements", data
639
+ node = self.elem_branch.add(shape=shape, type=shape_type)
640
+ node.stroke = self.default_stroke
641
+ node.stroke_width = self.default_strokewidth
642
+ node.fill = self.default_fill
643
+ node.altered()
644
+ self.set_emphasis([node])
645
+ node.focus()
646
+ data.append(node)
647
+ # Newly created! Classification needed?
648
+ post.append(classify_new(data))
649
+ return "elements", data
650
+
651
+ # --------------------------- END COMMANDS ------------------------------