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,669 +1,801 @@
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 meerk40t.svgelements import Viewbox
6
-
7
- from .element_types import *
8
-
9
-
10
- def plugin(kernel, lifecycle=None):
11
- _ = kernel.translation
12
- if lifecycle == "postboot":
13
- init_commands(kernel)
14
-
15
-
16
- def init_commands(kernel):
17
- self = kernel.elements
18
-
19
- _ = kernel.translation
20
-
21
- # ==========
22
- # ALIGN SUBTYPE
23
- # Align consist of top level node objects that can be manipulated within the scene.
24
- # ==========
25
-
26
- def _align_xy(
27
- channel,
28
- _,
29
- mode,
30
- bounds,
31
- elements,
32
- align_x=None,
33
- align_y=None,
34
- asgroup=None,
35
- **kwargs,
36
- ):
37
- """
38
- This routine prepares the data according to some validation.
39
-
40
- The complete validation stuff...
41
- """
42
- if elements is None:
43
- return
44
- if align_x is None or align_y is None:
45
- channel(_("You need to provide parameters for both x and y"))
46
- return
47
- align_bounds = None
48
- align_x = align_x.lower()
49
- align_y = align_y.lower()
50
- if align_x not in ("min", "max", "center", "none"):
51
- channel(_("Invalid alignment parameter for x"))
52
- return
53
- if align_y not in ("min", "max", "center", "none"):
54
- channel(_("Invalid alignment parameter for y"))
55
- return
56
- if mode == "default":
57
- if len(elements) < 2:
58
- channel(_("No sense in aligning an element to itself"))
59
- return
60
- # boundaries are the selection boundaries,
61
- # will be calculated later
62
- elif mode == "first":
63
- if len(elements) < 2:
64
- channel(_("No sense in aligning an element to itself"))
65
- return
66
- elements.sort(key=lambda n: n.emphasized_time)
67
- # Is there a noticeable difference?!
68
- # If not then we fall back to default
69
- delta = abs(elements[0].emphasized_time - elements[-1].emphasized_time)
70
- if delta > 0.5:
71
- align_bounds = elements[0].bounds
72
- # print (f"Use bounds of first element, delta was: {delta:.2f}")
73
- # print (f"Time 1: {elements[0].type} - {elements[0]._emphasized_time}, Time 2: {elements[-1].type} - {elements[-1]._emphasized_time}")
74
- # elements.pop(0)
75
- elif mode == "last":
76
- if len(elements) < 2:
77
- channel(_("No sense in aligning an element to itself"))
78
- return
79
- elements.sort(reverse=True, key=lambda n: n.emphasized_time)
80
- # Is there a noticeable difference?!
81
- # If not then we fall back to default
82
- # print(f"Mode: {mode}, type={elements[0].type}")
83
- delta = abs(elements[0].emphasized_time - elements[-1].emphasized_time)
84
- if delta > 0.5:
85
- align_bounds = elements[0].bounds
86
- # print (f"Use bounds of last element, delta was: {delta:.2f}")
87
- # elements.pop(0)
88
- elif mode == "bed":
89
- align_bounds = bounds
90
- elif mode == "ref":
91
- align_bounds = bounds
92
- self.align_elements(
93
- data=elements,
94
- alignbounds=align_bounds,
95
- positionx=align_x,
96
- positiony=align_y,
97
- as_group=asgroup,
98
- )
99
-
100
- @self.console_command(
101
- "push",
102
- help=_("pushes the current align mode to the stack"),
103
- input_type="align",
104
- output_type="align",
105
- )
106
- def alignmode_push(channel, _, data, **kwargs):
107
- """
108
- Special command to push the current values on the stack
109
- """
110
- mode, group, bound, elements = data
111
- self._align_stack.append((mode, group, bound))
112
- return "align", (mode, group, bound, elements)
113
-
114
- @self.console_command(
115
- "pop",
116
- help=_("pushes the current align mode to the stack"),
117
- input_type="align",
118
- output_type="align",
119
- )
120
- def alignmode_pop(channel, _, data, **kwargs):
121
- """
122
- Special command to push the current values on the stack
123
- """
124
- mode, group, bound, elements = data
125
- if len(self._align_stack) > 0:
126
- (
127
- self._align_mode,
128
- self._align_group,
129
- self._align_boundaries,
130
- ) = self._align_stack.pop()
131
- mode = self._align_mode
132
- group = self._align_group
133
- bound = self._align_boundaries
134
- channel(_("New alignmode = {mode}").format(mode=self._align_mode))
135
- if self._align_boundaries is not None:
136
- channel(
137
- _("Align boundaries = {bound}").format(
138
- bound=str(self._align_boundaries)
139
- )
140
- )
141
- return "align", (mode, group, bound, elements)
142
-
143
- @self.console_command(
144
- "group",
145
- help=_("Set the requested alignment to treat selection as group"),
146
- input_type="align",
147
- output_type="align",
148
- )
149
- def alignmode_group(command, channel, _, data, **kwargs):
150
- mode, group, bound, elements = data
151
- group = True
152
- return "align", (mode, group, bound, elements)
153
-
154
- @self.console_command(
155
- "individual",
156
- help=_("Set the requested alignment to treat selection as individuals"),
157
- input_type="align",
158
- output_type="align",
159
- )
160
- def alignmode_individual(command, channel, _, data, **kwargs):
161
- mode, group, bound, elements = data
162
- group = False
163
- return "align", (mode, group, bound, elements)
164
-
165
- @self.console_command(
166
- "default",
167
- help=_("align within selection - all equal"),
168
- input_type="align",
169
- output_type="align",
170
- )
171
- def alignmode_default(channel, _, data, **kwargs):
172
- """
173
- Set the alignment mode to default
174
- """
175
- mode, group, bound, elements = data
176
- mode = "default"
177
- bound = None
178
- self._align_mode = mode
179
- self._align_boundaries = bound
180
- channel(_("New alignmode = {mode}").format(mode=self._align_mode))
181
- if self._align_boundaries is not None:
182
- channel(
183
- _("Align boundaries = {bound}").format(
184
- bound=str(self._align_boundaries)
185
- )
186
- )
187
- return "align", (mode, group, bound, elements)
188
-
189
- @self.console_command(
190
- "first",
191
- help=_("Set the requested alignment to first element selected"),
192
- input_type="align",
193
- output_type="align",
194
- )
195
- def alignmode_first(command, channel, _, data, **kwargs):
196
- mode, group, bound, elements = data
197
- mode = "first"
198
- bound = None
199
- self._align_mode = mode
200
- self._align_boundaries = bound
201
- channel(_("New alignmode = {mode}").format(mode=self._align_mode))
202
- if self._align_boundaries is not None:
203
- channel(
204
- _("Align boundaries = {bound}").format(
205
- bound=str(self._align_boundaries)
206
- )
207
- )
208
- return "align", (mode, group, bound, elements)
209
-
210
- @self.console_command(
211
- "last",
212
- help=_("Set the requested alignment to last element selected"),
213
- input_type="align",
214
- output_type="align",
215
- )
216
- def alignmode_last(command, channel, _, data, **kwargs):
217
- mode, group, bound, elements = data
218
- mode = "last"
219
- bound = None
220
- self._align_mode = mode
221
- self._align_boundaries = bound
222
- channel(_("New alignmode = {mode}").format(mode=self._align_mode))
223
- if self._align_boundaries is not None:
224
- channel(
225
- _("Align boundaries = {bound}").format(
226
- bound=str(self._align_boundaries)
227
- )
228
- )
229
- return "align", (mode, group, bound, elements)
230
-
231
- @self.console_command(
232
- "bed",
233
- help=_("Set the requested alignment to within the bed"),
234
- input_type="align",
235
- output_type="align",
236
- )
237
- def alignmode_bed(channel, _, data, **kwargs):
238
- mode, group, bound, elements = data
239
- mode = "bed"
240
- device_width = self.length_x("100%")
241
- device_height = self.length_y("100%")
242
- bound = (0, 0, device_width, device_height)
243
- self._align_mode = mode
244
- self._align_boundaries = bound
245
- channel(_("New alignmode = {mode}").format(mode=self._align_mode))
246
- if self._align_boundaries is not None:
247
- channel(
248
- _("Align boundaries = {bound}").format(
249
- bound=str(self._align_boundaries)
250
- )
251
- )
252
- return "align", (mode, group, bound, elements)
253
-
254
- @self.console_option(
255
- "boundaries", "b", type=self.bounds, parallel_cast=True, nargs=4
256
- )
257
- @self.console_command(
258
- "ref",
259
- help=_("Set the requested alignment to the reference object"),
260
- input_type="align",
261
- output_type="align",
262
- )
263
- def alignmode_ref(channel, _, data, boundaries, **kwargs):
264
- mode, group, bound, elements = data
265
- if boundaries is None:
266
- channel(
267
- _("You need to provide the boundaries for align-mode {mode}").format(
268
- mode="ref"
269
- )
270
- )
271
- return
272
- mode = "ref"
273
- bound = boundaries
274
- self._align_mode = mode
275
- self._align_boundaries = bound
276
- channel(_("New alignmode = {mode}").format(mode=self._align_mode))
277
- if self._align_boundaries is not None:
278
- channel(
279
- _("Align boundaries = {bound}").format(
280
- bound=str(self._align_boundaries)
281
- )
282
- )
283
- return "align", (mode, group, bound, elements)
284
-
285
- @self.console_command(
286
- "align",
287
- help=_("align selected elements"),
288
- input_type=("elements", None),
289
- output_type="align",
290
- )
291
- def align_elements_base(command, channel, _, data=None, remainder=None, **kwargs):
292
- """
293
- Base align commands. Triggers other base commands within the command context
294
- 'align'.
295
- """
296
- if not remainder:
297
- channel(
298
- "top\nbottom\nleft\nright\ncenter\ncenterh\ncenterv\nspaceh\nspacev\n"
299
- "<any valid svg:Preserve Aspect Ratio, eg xminymin>"
300
- )
301
- # Bunch of other things.
302
- return
303
- if data is None:
304
- data = list(self.elems(emphasized=True))
305
- return "align", (
306
- self._align_mode,
307
- self._align_group,
308
- self._align_boundaries,
309
- data,
310
- )
311
-
312
- @self.console_argument(
313
- "alignx", type=str, help=_("One of 'min', 'center', 'max', 'none'")
314
- )
315
- @self.console_argument(
316
- "aligny", type=str, help=_("One of 'min', 'center', 'max', 'none'")
317
- )
318
- @self.console_command(
319
- "xy",
320
- help=_("align elements in x and y"),
321
- input_type="align",
322
- output_type="align",
323
- )
324
- def subtype_align_xy(
325
- command,
326
- channel,
327
- _,
328
- data=None,
329
- alignx=None,
330
- aligny=None,
331
- **kwargs,
332
- ):
333
- mode, group, bound, elements = data
334
- _align_xy(channel, _, mode, bound, elements, alignx, aligny, group)
335
- return "align", (mode, group, bound, elements)
336
-
337
- @self.console_command(
338
- "top",
339
- help=_("align elements at top"),
340
- input_type="align",
341
- output_type="align",
342
- )
343
- def subtype_align_top(command, channel, _, data=None, **kwargs):
344
- mode, group, bound, elements = data
345
- _align_xy(channel, _, mode, bound, elements, "none", "min", group)
346
- return "align", (mode, group, bound, elements)
347
-
348
- @self.console_command(
349
- "bottom",
350
- help=_("align elements at bottom"),
351
- input_type="align",
352
- output_type="align",
353
- )
354
- def subtype_align_bottom(command, channel, _, data=None, **kwargs):
355
- mode, group, bound, elements = data
356
- _align_xy(channel, _, mode, bound, elements, "none", "max", group)
357
- return "align", (mode, group, bound, elements)
358
-
359
- @self.console_command(
360
- "left",
361
- help=_("align elements at left"),
362
- input_type="align",
363
- output_type="align",
364
- )
365
- def subtype_align_left(command, channel, _, data=None, **kwargs):
366
- mode, group, bound, elements = data
367
- _align_xy(channel, _, mode, bound, elements, "min", "none", group)
368
- return "align", (mode, group, bound, elements)
369
-
370
- @self.console_command(
371
- "right",
372
- help=_("align elements at right"),
373
- input_type="align",
374
- output_type="align",
375
- )
376
- def subtype_align_right(command, channel, _, data=None, **kwargs):
377
- mode, group, bound, elements = data
378
- _align_xy(channel, _, mode, bound, elements, "max", "none", group)
379
- return "align", (mode, group, bound, elements)
380
-
381
- @self.console_command(
382
- "center",
383
- help=_("align elements at center"),
384
- input_type="align",
385
- output_type="align",
386
- )
387
- def subtype_align_center(command, channel, _, data=None, **kwargs):
388
- mode, group, bound, elements = data
389
- _align_xy(channel, _, mode, bound, elements, "center", "center", group)
390
- return "align", (mode, group, bound, elements)
391
-
392
- @self.console_command(
393
- "centerh",
394
- help=_("align elements at center horizontally"),
395
- input_type="align",
396
- output_type="align",
397
- )
398
- def subtype_align_centerh(command, channel, _, data=None, **kwargs):
399
- mode, group, bound, elements = data
400
- _align_xy(channel, _, mode, bound, elements, "center", "none", group)
401
- return "align", (mode, group, bound, elements)
402
-
403
- @self.console_command(
404
- "centerv",
405
- help=_("align elements at center vertically"),
406
- input_type="align",
407
- output_type="align",
408
- )
409
- def subtype_align_centerv(command, channel, _, data=None, **kwargs):
410
- mode, group, bound, elements = data
411
- _align_xy(channel, _, mode, bound, elements, "none", "center", group)
412
- return "align", (mode, group, bound, elements)
413
-
414
- def distribute_elements(elements, in_x: bool = True, distance: bool = True):
415
- if len(elements) <= 2: # Cannot distribute 2 or fewer items.
416
- return
417
- if in_x:
418
- elements.sort(key=lambda n: n.bounds[0]) # sort by left edge
419
- else:
420
- elements.sort(key=lambda n: n.bounds[1]) # sort by top edge
421
- boundary_points = []
422
- for node in elements:
423
- boundary_points.append(node.bounds)
424
- if not len(boundary_points):
425
- return
426
- if in_x:
427
- idx = 0
428
- else:
429
- idx = 1
430
- if distance:
431
- left_edge = boundary_points[0][idx]
432
- right_edge = boundary_points[-1][idx + 2]
433
- dim_total = right_edge - left_edge
434
- dim_available = dim_total
435
- for node in elements:
436
- bounds = node.bounds
437
- dim_available -= bounds[idx + 2] - bounds[idx]
438
- distributed_distance = dim_available / (len(elements) - 1)
439
- dim_pos = left_edge
440
- else:
441
- left_edge = (boundary_points[0][idx] + boundary_points[0][idx + 2]) / 2
442
- right_edge = (boundary_points[-1][idx] + boundary_points[-1][idx + 2]) / 2
443
- dim_total = right_edge - left_edge
444
- dim_available = dim_total
445
- dim_pos = left_edge
446
- distributed_distance = dim_available / (len(elements) - 1)
447
-
448
- for node in elements:
449
- subbox = node.bounds
450
- if distance:
451
- delta = subbox[idx] - dim_pos
452
- dim_pos += subbox[idx + 2] - subbox[idx] + distributed_distance
453
- else:
454
- delta = (subbox[idx] + subbox[idx + 2]) / 2 - dim_pos
455
- dim_pos += distributed_distance
456
- if in_x:
457
- dx = -delta
458
- dy = 0
459
- else:
460
- dx = 0
461
- dy = -delta
462
- if dx != 0 or dy != 0:
463
- self.translate_node(node, dx, dy)
464
-
465
- @self.console_command(
466
- "spaceh",
467
- help=_("distribute elements across horizontal space"),
468
- input_type="align",
469
- output_type="align",
470
- )
471
- def subtype_align_spaceh(command, channel, _, data=None, **kwargs):
472
- mode, group, bound, raw_elements = data
473
- haslock = False
474
- for node in raw_elements:
475
- if not node.can_move(self.lock_allows_move):
476
- haslock = True
477
- break
478
- if haslock:
479
- channel(_("Your selection contains a locked element, that cannot be moved"))
480
- return "align", (mode, group, bound, raw_elements)
481
- elements = self.condense_elements(raw_elements)
482
- distribute_elements(elements, in_x=True, distance=True)
483
- self.signal("refresh_scene", "Scene")
484
- return "align", (mode, group, bound, elements)
485
-
486
- @self.console_command(
487
- "spaceh2",
488
- help=_("distribute elements across horizontal space"),
489
- input_type="align",
490
- output_type="align",
491
- )
492
- def subtype_align_spaceh2(command, channel, _, data=None, **kwargs):
493
- mode, group, bound, raw_elements = data
494
- haslock = False
495
- for node in raw_elements:
496
- if not node.can_move(self.lock_allows_move):
497
- haslock = True
498
- break
499
- if haslock:
500
- channel(_("Your selection contains a locked element, that cannot be moved"))
501
- return "align", (mode, group, bound, raw_elements)
502
- elements = self.condense_elements(raw_elements)
503
- distribute_elements(elements, in_x=True, distance=False)
504
- self.signal("refresh_scene", "Scene")
505
- return "align", (mode, group, bound, elements)
506
-
507
- @self.console_command(
508
- "spacev",
509
- help=_("distribute elements across vertical space"),
510
- input_type="align",
511
- output_type="align",
512
- )
513
- def subtype_align_spacev(command, channel, _, data=None, **kwargs):
514
- mode, group, bound, raw_elements = data
515
- haslock = False
516
- for node in raw_elements:
517
- if not node.can_move(self.lock_allows_move):
518
- haslock = True
519
- break
520
- if haslock:
521
- channel(_("Your selection contains a locked element, that cannot be moved"))
522
- return "align", (mode, group, bound, raw_elements)
523
- elements = self.condense_elements(raw_elements)
524
- distribute_elements(elements, in_x=False, distance=True)
525
- self.signal("refresh_scene", "Scene")
526
- return "align", (mode, group, bound, elements)
527
-
528
- @self.console_command(
529
- "spacev2",
530
- help=_("distribute elements across vertical space"),
531
- input_type="align",
532
- output_type="align",
533
- )
534
- def subtype_align_spacev2(command, channel, _, data=None, **kwargs):
535
- mode, group, bound, raw_elements = data
536
- haslock = False
537
- for node in raw_elements:
538
- if not node.can_move(self.lock_allows_move):
539
- haslock = True
540
- break
541
- if haslock:
542
- channel(_("Your selection contains a locked element, that cannot be moved"))
543
- return "align", (mode, group, bound, raw_elements)
544
- elements = self.condense_elements(raw_elements)
545
- distribute_elements(elements, in_x=False, distance=False)
546
- self.signal("refresh_scene", "Scene")
547
- return "align", (mode, group, bound, elements)
548
-
549
- @self.console_argument(
550
- "preserve_aspect_ratio",
551
- type=str,
552
- default="none",
553
- help="preserve aspect ratio value",
554
- )
555
- @self.console_command(
556
- "view",
557
- help=_("align elements within viewbox"),
558
- input_type="align",
559
- output_type="align",
560
- )
561
- def subtype_align(
562
- command, channel, _, data=None, preserve_aspect_ratio="none", **kwargs
563
- ):
564
- """
565
- Align the elements to within the bed according to SVG Viewbox rules. The following aspect ratios
566
- are valid. These should define all the valid methods of centering data within the laser bed.
567
- "xminymin",
568
- "xmidymin",
569
- "xmaxymin",
570
- "xminymid",
571
- "xmidymid",
572
- "xmaxymid",
573
- "xminymax",
574
- "xmidymax",
575
- "xmaxymax",
576
- "xminymin meet",
577
- "xmidymin meet",
578
- "xmaxymin meet",
579
- "xminymid meet",
580
- "xmidymid meet",
581
- "xmaxymid meet",
582
- "xminymax meet",
583
- "xmidymax meet",
584
- "xmaxymax meet",
585
- "xminymin slice",
586
- "xmidymin slice",
587
- "xmaxymin slice",
588
- "xminymid slice",
589
- "xmidymid slice",
590
- "xmaxymid slice",
591
- "xminymax slice",
592
- "xmidymax slice",
593
- "xmaxymax slice",
594
- "none"
595
- """
596
- mode, group, bound, elements = data
597
- boundary_points = []
598
- for node in elements:
599
- boundary_points.append(node.bounds)
600
- if not len(boundary_points):
601
- return
602
-
603
- haslock = False
604
- for node in elements:
605
- if not node.can_move(self.lock_allows_move):
606
- haslock = True
607
- break
608
- if haslock:
609
- channel(_("Your selection contains a locked element, that cannot be moved"))
610
- return
611
- left_edge = min([e[0] for e in boundary_points])
612
- top_edge = min([e[1] for e in boundary_points])
613
- right_edge = max([e[2] for e in boundary_points])
614
- bottom_edge = max([e[3] for e in boundary_points])
615
-
616
- if preserve_aspect_ratio in (
617
- "xminymin",
618
- "xmidymin",
619
- "xmaxymin",
620
- "xminymid",
621
- "xmidymid",
622
- "xmaxymid",
623
- "xminymax",
624
- "xmidymax",
625
- "xmaxymax",
626
- "xminymin meet",
627
- "xmidymin meet",
628
- "xmaxymin meet",
629
- "xminymid meet",
630
- "xmidymid meet",
631
- "xmaxymid meet",
632
- "xminymax meet",
633
- "xmidymax meet",
634
- "xmaxymax meet",
635
- "xminymin slice",
636
- "xmidymin slice",
637
- "xmaxymin slice",
638
- "xminymid slice",
639
- "xmidymid slice",
640
- "xmaxymid slice",
641
- "xminymax slice",
642
- "xmidymax slice",
643
- "xmaxymax slice",
644
- "none",
645
- ):
646
- for node in elements:
647
- device_width = self.length_x("100%")
648
- device_height = self.length_y("100%")
649
-
650
- matrix = Viewbox.viewbox_transform(
651
- 0,
652
- 0,
653
- device_width,
654
- device_height,
655
- left_edge,
656
- top_edge,
657
- right_edge - left_edge,
658
- bottom_edge - top_edge,
659
- preserve_aspect_ratio,
660
- )
661
- for q in node.flat(types=elem_nodes):
662
- try:
663
- q.matrix *= matrix
664
- q.modified()
665
- except AttributeError:
666
- continue
667
- for q in node.flat(types=("file", "group")):
668
- q.modified()
669
- return "align", (mode, group, bound, elements)
1
+ """
2
+ This module provides a set of console commands for managing alignment operations within the application.
3
+ These commands allow users to align elements based on various criteria, including their position and grouping.
4
+
5
+ It uses a probably overly complicated system of alignment settings that are pushed and popped on an alignment
6
+ stack. This feature was never really used, so its just a bit too much sophisticated?!
7
+
8
+ Functions:
9
+ - plugin(kernel, lifecycle=None): Initializes the plugin and sets up alignment commands.
10
+ - init_commands(kernel): Initializes the alignment commands and defines the associated operations.
11
+ - _align_xy(channel, _, mode, bounds, data, align_x=None, align_y=None, asgroup=None, **kwargs): Prepares the data for alignment based on the specified parameters.
12
+ Args:
13
+ channel: The communication channel for messages.
14
+ mode: The alignment mode to apply.
15
+ bounds: The bounds for alignment.
16
+ data: The elements to align.
17
+ align_x: The alignment parameter for the x-axis.
18
+ align_y: The alignment parameter for the y-axis.
19
+ asgroup: A flag indicating whether to treat the selection as a group.
20
+ Returns:
21
+ None
22
+ - alignmode_push(channel, _, data, **kwargs): Pushes the current alignment mode onto the stack for later retrieval.
23
+ Args:
24
+ channel: The communication channel for messages.
25
+ data: The current alignment data.
26
+ Returns:
27
+ A tuple containing the alignment type and the current alignment data.
28
+ - alignmode_pop(channel, _, data, **kwargs): Pops the last alignment mode from the stack and sets it as the current mode.
29
+ Args:
30
+ channel: The communication channel for messages.
31
+ data: The current alignment data.
32
+ Returns:
33
+ A tuple containing the alignment type and the updated alignment data.
34
+ - alignmode_group(command, channel, _, data, **kwargs): Sets the alignment mode to treat the selection as a group.
35
+ Args:
36
+ command: The command context.
37
+ channel: The communication channel for messages.
38
+ data: The current alignment data.
39
+ Returns:
40
+ A tuple containing the alignment type and the updated alignment data.
41
+ - alignmode_individual(command, channel, _, data, **kwargs): Sets the alignment mode to treat the selection as individual elements.
42
+ Args:
43
+ command: The command context.
44
+ channel: The communication channel for messages.
45
+ data: The current alignment data.
46
+ Returns:
47
+ A tuple containing the alignment type and the updated alignment data.
48
+ - alignmode_default(channel, _, data, **kwargs): Sets the alignment mode to default, aligning all selected elements equally.
49
+ Args:
50
+ channel: The communication channel for messages.
51
+ data: The current alignment data.
52
+ Returns:
53
+ A tuple containing the alignment type and the updated alignment data.
54
+ - alignmode_first(command, channel, _, data, **kwargs): Sets the alignment mode to the first element selected.
55
+ Args:
56
+ command: The command context.
57
+ channel: The communication channel for messages.
58
+ data: The current alignment data.
59
+ Returns:
60
+ A tuple containing the alignment type and the updated alignment data.
61
+ - alignmode_last(command, channel, _, data, **kwargs): Sets the alignment mode to the last element selected.
62
+ Args:
63
+ command: The command context.
64
+ channel: The communication channel for messages.
65
+ data: The current alignment data.
66
+ Returns:
67
+ A tuple containing the alignment type and the updated alignment data.
68
+ - alignmode_bed(channel, _, data, **kwargs): Sets the alignment mode to align elements within the bed dimensions.
69
+ Args:
70
+ channel: The communication channel for messages.
71
+ data: The current alignment data.
72
+ Returns:
73
+ A tuple containing the alignment type and the updated alignment data.
74
+ - alignmode_ref(channel, _, data, boundaries, **kwargs): Sets the alignment mode to align elements to a specified reference object.
75
+ Args:
76
+ channel: The communication channel for messages.
77
+ data: The current alignment data.
78
+ boundaries: The boundaries for alignment.
79
+ Returns:
80
+ A tuple containing the alignment type and the updated alignment data.
81
+ - align_elements_base(command, channel, _, data=None, remainder=None, **kwargs): Base command for aligning selected elements.
82
+ Args:
83
+ command: The command context.
84
+ channel: The communication channel for messages.
85
+ data: The elements to align.
86
+ remainder: Additional command arguments.
87
+ Returns:
88
+ A tuple containing the alignment type and the updated alignment data.
89
+ - subtype_align_xy(command, channel, _, data=None, alignx=None, aligny=None, **kwargs): Aligns elements based on specified x and y alignment parameters.
90
+ Args:
91
+ command: The command context.
92
+ channel: The communication channel for messages.
93
+ data: The elements to align.
94
+ alignx: The alignment parameter for the x-axis.
95
+ aligny: The alignment parameter for the y-axis.
96
+ Returns:
97
+ A tuple containing the alignment type and the updated alignment data.
98
+ - subtype_align_spaceh(command, channel, _, data=None, **kwargs): Distributes selected elements across horizontal space.
99
+ Args:
100
+ command: The command context.
101
+ channel: The communication channel for messages.
102
+ data: The elements to distribute.
103
+ Returns:
104
+ A tuple containing the alignment type and the updated alignment data.
105
+ - subtype_align_spacev(command, channel, _, data=None, **kwargs): Distributes selected elements across vertical space.
106
+ Args:
107
+ command: The command context.
108
+ channel: The communication channel for messages.
109
+ data: The elements to distribute.
110
+ Returns:
111
+ A tuple containing the alignment type and the updated alignment data.
112
+ - subtype_align_spaceh2(command, channel, _, data=None, **kwargs): Distributes selected elements across horizontal space without considering distance.
113
+ Args:
114
+ command: The command context.
115
+ channel: The communication channel for messages.
116
+ data: The elements to distribute.
117
+ Returns:
118
+ A tuple containing the alignment type and the updated alignment data.
119
+ - subtype_align_spacev2(command, channel, _, data=None, **kwargs): Distributes selected elements across vertical space without considering distance.
120
+ Args:
121
+ command: The command context.
122
+ channel: The communication channel for messages.
123
+ data: The elements to distribute.
124
+ Returns:
125
+ A tuple containing the alignment type and the updated alignment data.
126
+ - subtype_align(command, channel, _, data=None, preserve_aspect_ratio="none", **kwargs): Aligns elements within the viewbox according to specified aspect ratio rules.
127
+ Args:
128
+ command: The command context.
129
+ channel: The communication channel for messages.
130
+ data: The elements to align.
131
+ preserve_aspect_ratio: The aspect ratio to preserve during alignment.
132
+ Returns:
133
+ A tuple containing the alignment type and the updated alignment data.
134
+ """
135
+
136
+ """
137
+ This is a giant list of console commands that deal with and often implement the elements system in the program.
138
+ """
139
+
140
+ from meerk40t.svgelements import Viewbox
141
+
142
+ from .element_types import *
143
+
144
+
145
+ def plugin(kernel, lifecycle=None):
146
+ _ = kernel.translation
147
+ if lifecycle == "postboot":
148
+ init_commands(kernel)
149
+
150
+
151
+ def init_commands(kernel):
152
+ self = kernel.elements
153
+
154
+ _ = kernel.translation
155
+
156
+ # ==========
157
+ # ALIGN SUBTYPE
158
+ # Align consist of top level node objects that can be manipulated within the scene.
159
+ # ==========
160
+
161
+ def _align_xy(
162
+ channel,
163
+ _,
164
+ mode,
165
+ bounds,
166
+ data,
167
+ align_x=None,
168
+ align_y=None,
169
+ asgroup=None,
170
+ **kwargs,
171
+ ):
172
+ """
173
+ This routine prepares the data according to some validation.
174
+
175
+ The complete validation stuff...
176
+ """
177
+ if data is None:
178
+ return
179
+ if align_x is None or align_y is None:
180
+ channel(_("You need to provide parameters for both x and y"))
181
+ return
182
+ align_bounds = None
183
+ align_x = align_x.lower()
184
+ align_y = align_y.lower()
185
+ if align_x not in ("min", "max", "center", "none"):
186
+ channel(_("Invalid alignment parameter for x"))
187
+ return
188
+ if align_y not in ("min", "max", "center", "none"):
189
+ channel(_("Invalid alignment parameter for y"))
190
+ return
191
+ elements = self.condense_elements(data)
192
+
193
+ if mode == "default":
194
+ if len(elements) < 2:
195
+ channel(_("No sense in aligning an element to itself"))
196
+ return
197
+ # boundaries are the selection boundaries,
198
+ # will be calculated later
199
+ elif mode == "first":
200
+ if len(elements) < 2:
201
+ channel(_("No sense in aligning an element to itself"))
202
+ return
203
+ elements.sort(key=lambda n: n.emphasized_time)
204
+ # Is there a noticeable difference?!
205
+ # If not then we fall back to default
206
+ delta = abs(elements[0].emphasized_time - elements[-1].emphasized_time)
207
+ if delta > 0.5:
208
+ align_bounds = elements[0].bounds
209
+ # print (f"Use bounds of first element, delta was: {delta:.2f}")
210
+ # print (f"Time 1: {elements[0].type} - {elements[0]._emphasized_time}, Time 2: {elements[-1].type} - {elements[-1]._emphasized_time}")
211
+ # elements.pop(0)
212
+ elif mode == "last":
213
+ if len(elements) < 2:
214
+ channel(_("No sense in aligning an element to itself"))
215
+ return
216
+ elements.sort(reverse=True, key=lambda n: n.emphasized_time)
217
+ # Is there a noticeable difference?!
218
+ # If not then we fall back to default
219
+ # print(f"Mode: {mode}, type={elements[0].type}")
220
+ delta = abs(elements[0].emphasized_time - elements[-1].emphasized_time)
221
+ if delta > 0.5:
222
+ align_bounds = elements[0].bounds
223
+ # print (f"Use bounds of last element, delta was: {delta:.2f}")
224
+ # elements.pop(0)
225
+ elif mode == "bed":
226
+ align_bounds = bounds
227
+ elif mode == "ref":
228
+ align_bounds = bounds
229
+ self.align_elements(
230
+ data_to_align=elements,
231
+ alignbounds=align_bounds,
232
+ positionx=align_x,
233
+ positiony=align_y,
234
+ as_group=asgroup,
235
+ )
236
+
237
+ @self.console_command(
238
+ "push",
239
+ help=_("pushes the current align mode to the stack"),
240
+ input_type="align",
241
+ output_type="align",
242
+ )
243
+ def alignmode_push(channel, _, data, **kwargs):
244
+ """
245
+ Special command to push the current values on the stack
246
+ """
247
+ mode, group, bound, elements = data
248
+ self._align_stack.append((mode, group, bound))
249
+ return "align", (mode, group, bound, elements)
250
+
251
+ @self.console_command(
252
+ "pop",
253
+ help=_("pushes the current align mode to the stack"),
254
+ input_type="align",
255
+ output_type="align",
256
+ )
257
+ def alignmode_pop(channel, _, data, **kwargs):
258
+ """
259
+ Special command to push the current values on the stack
260
+ """
261
+ mode, group, bound, elements = data
262
+ if len(self._align_stack) > 0:
263
+ (
264
+ self._align_mode,
265
+ self._align_group,
266
+ self._align_boundaries,
267
+ ) = self._align_stack.pop()
268
+ mode = self._align_mode
269
+ group = self._align_group
270
+ bound = self._align_boundaries
271
+ channel(_("New alignmode = {mode}").format(mode=self._align_mode))
272
+ if self._align_boundaries is not None:
273
+ channel(
274
+ _("Align boundaries = {bound}").format(
275
+ bound=str(self._align_boundaries)
276
+ )
277
+ )
278
+ return "align", (mode, group, bound, elements)
279
+
280
+ @self.console_command(
281
+ "group",
282
+ help=_("Set the requested alignment to treat selection as group"),
283
+ input_type="align",
284
+ output_type="align",
285
+ )
286
+ def alignmode_group(command, channel, _, data, **kwargs):
287
+ mode, group, bound, elements = data
288
+ group = True
289
+ return "align", (mode, group, bound, elements)
290
+
291
+ @self.console_command(
292
+ "individual",
293
+ help=_("Set the requested alignment to treat selection as individuals"),
294
+ input_type="align",
295
+ output_type="align",
296
+ )
297
+ def alignmode_individual(command, channel, _, data, **kwargs):
298
+ mode, group, bound, elements = data
299
+ group = False
300
+ return "align", (mode, group, bound, elements)
301
+
302
+ @self.console_command(
303
+ "default",
304
+ help=_("align within selection - all equal"),
305
+ input_type="align",
306
+ output_type="align",
307
+ )
308
+ def alignmode_default(channel, _, data, **kwargs):
309
+ """
310
+ Set the alignment mode to default
311
+ """
312
+ mode, group, bound, elements = data
313
+ mode = "default"
314
+ bound = None
315
+ self._align_mode = mode
316
+ self._align_boundaries = bound
317
+ channel(_("New alignmode = {mode}").format(mode=self._align_mode))
318
+ if self._align_boundaries is not None:
319
+ channel(
320
+ _("Align boundaries = {bound}").format(
321
+ bound=str(self._align_boundaries)
322
+ )
323
+ )
324
+ return "align", (mode, group, bound, elements)
325
+
326
+ @self.console_command(
327
+ "first",
328
+ help=_("Set the requested alignment to first element selected"),
329
+ input_type="align",
330
+ output_type="align",
331
+ )
332
+ def alignmode_first(command, channel, _, data, **kwargs):
333
+ mode, group, bound, elements = data
334
+ mode = "first"
335
+ bound = None
336
+ self._align_mode = mode
337
+ self._align_boundaries = bound
338
+ channel(_("New alignmode = {mode}").format(mode=self._align_mode))
339
+ if self._align_boundaries is not None:
340
+ channel(
341
+ _("Align boundaries = {bound}").format(
342
+ bound=str(self._align_boundaries)
343
+ )
344
+ )
345
+ return "align", (mode, group, bound, elements)
346
+
347
+ @self.console_command(
348
+ "last",
349
+ help=_("Set the requested alignment to last element selected"),
350
+ input_type="align",
351
+ output_type="align",
352
+ )
353
+ def alignmode_last(command, channel, _, data, **kwargs):
354
+ mode, group, bound, elements = data
355
+ mode = "last"
356
+ bound = None
357
+ self._align_mode = mode
358
+ self._align_boundaries = bound
359
+ channel(_("New alignmode = {mode}").format(mode=self._align_mode))
360
+ if self._align_boundaries is not None:
361
+ channel(
362
+ _("Align boundaries = {bound}").format(
363
+ bound=str(self._align_boundaries)
364
+ )
365
+ )
366
+ return "align", (mode, group, bound, elements)
367
+
368
+ @self.console_command(
369
+ "bed",
370
+ help=_("Set the requested alignment to within the bed"),
371
+ input_type="align",
372
+ output_type="align",
373
+ )
374
+ def alignmode_bed(channel, _, data, **kwargs):
375
+ mode, group, bound, elements = data
376
+ mode = "bed"
377
+ device_width = self.length_x("100%")
378
+ device_height = self.length_y("100%")
379
+ bound = (0, 0, device_width, device_height)
380
+ self._align_mode = mode
381
+ self._align_boundaries = bound
382
+ channel(_("New alignmode = {mode}").format(mode=self._align_mode))
383
+ if self._align_boundaries is not None:
384
+ channel(
385
+ _("Align boundaries = {bound}").format(
386
+ bound=str(self._align_boundaries)
387
+ )
388
+ )
389
+ return "align", (mode, group, bound, elements)
390
+
391
+ @self.console_option(
392
+ "boundaries", "b", type=self.bounds, parallel_cast=True, nargs=4
393
+ )
394
+ @self.console_command(
395
+ "ref",
396
+ help=_("Set the requested alignment to the reference object"),
397
+ input_type="align",
398
+ output_type="align",
399
+ )
400
+ def alignmode_ref(channel, _, data, boundaries, **kwargs):
401
+ mode, group, bound, elements = data
402
+ if boundaries is None:
403
+ channel(
404
+ _("You need to provide the boundaries for align-mode {mode}").format(
405
+ mode="ref"
406
+ )
407
+ )
408
+ return
409
+ mode = "ref"
410
+ bound = boundaries
411
+ self._align_mode = mode
412
+ self._align_boundaries = bound
413
+ channel(_("New alignmode = {mode}").format(mode=self._align_mode))
414
+ if self._align_boundaries is not None:
415
+ channel(
416
+ _("Align boundaries = {bound}").format(
417
+ bound=str(self._align_boundaries)
418
+ )
419
+ )
420
+ return "align", (mode, group, bound, elements)
421
+
422
+ @self.console_command(
423
+ "align",
424
+ help=_("align selected elements"),
425
+ input_type=("elements", None),
426
+ output_type="align",
427
+ )
428
+ def align_elements_base(command, channel, _, data=None, remainder=None, **kwargs):
429
+ """
430
+ Base align commands. Triggers other base commands within the command context
431
+ 'align'.
432
+ """
433
+ if not remainder:
434
+ channel(
435
+ "top\nbottom\nleft\nright\ncenter\ncenterh\ncenterv\nspaceh\nspacev\n"
436
+ "<any valid svg:Preserve Aspect Ratio, eg xminymin>"
437
+ )
438
+ # Bunch of other things.
439
+ return
440
+ if data is None:
441
+ data = list(self.elems(emphasized=True))
442
+ return "align", (
443
+ self._align_mode,
444
+ self._align_group,
445
+ self._align_boundaries,
446
+ data,
447
+ )
448
+
449
+ @self.console_argument(
450
+ "alignx", type=str, help=_("One of 'min', 'center', 'max', 'none'")
451
+ )
452
+ @self.console_argument(
453
+ "aligny", type=str, help=_("One of 'min', 'center', 'max', 'none'")
454
+ )
455
+ @self.console_command(
456
+ "xy",
457
+ help=_("align elements in x and y"),
458
+ input_type="align",
459
+ output_type="align",
460
+ )
461
+ def subtype_align_xy(
462
+ command,
463
+ channel,
464
+ _,
465
+ data=None,
466
+ alignx=None,
467
+ aligny=None,
468
+ **kwargs,
469
+ ):
470
+ mode, group, bound, elements = data
471
+ _align_xy(channel, _, mode, bound, elements, alignx, aligny, group)
472
+ return "align", (mode, group, bound, elements)
473
+
474
+ @self.console_command(
475
+ "top",
476
+ help=_("align elements at top"),
477
+ input_type="align",
478
+ output_type="align",
479
+ )
480
+ def subtype_align_top(command, channel, _, data=None, **kwargs):
481
+ mode, group, bound, elements = data
482
+ _align_xy(channel, _, mode, bound, elements, "none", "min", group)
483
+ return "align", (mode, group, bound, elements)
484
+
485
+ @self.console_command(
486
+ "bottom",
487
+ help=_("align elements at bottom"),
488
+ input_type="align",
489
+ output_type="align",
490
+ )
491
+ def subtype_align_bottom(command, channel, _, data=None, **kwargs):
492
+ mode, group, bound, elements = data
493
+ _align_xy(channel, _, mode, bound, elements, "none", "max", group)
494
+ return "align", (mode, group, bound, elements)
495
+
496
+ @self.console_command(
497
+ "left",
498
+ help=_("align elements at left"),
499
+ input_type="align",
500
+ output_type="align",
501
+ )
502
+ def subtype_align_left(command, channel, _, data=None, **kwargs):
503
+ mode, group, bound, elements = data
504
+ _align_xy(channel, _, mode, bound, elements, "min", "none", group)
505
+ return "align", (mode, group, bound, elements)
506
+
507
+ @self.console_command(
508
+ "right",
509
+ help=_("align elements at right"),
510
+ input_type="align",
511
+ output_type="align",
512
+ )
513
+ def subtype_align_right(command, channel, _, data=None, **kwargs):
514
+ mode, group, bound, elements = data
515
+ _align_xy(channel, _, mode, bound, elements, "max", "none", group)
516
+ return "align", (mode, group, bound, elements)
517
+
518
+ @self.console_command(
519
+ "center",
520
+ help=_("align elements at center"),
521
+ input_type="align",
522
+ output_type="align",
523
+ )
524
+ def subtype_align_center(command, channel, _, data=None, **kwargs):
525
+ mode, group, bound, elements = data
526
+ _align_xy(channel, _, mode, bound, elements, "center", "center", group)
527
+ return "align", (mode, group, bound, elements)
528
+
529
+ @self.console_command(
530
+ "centerh",
531
+ help=_("align elements at center horizontally"),
532
+ input_type="align",
533
+ output_type="align",
534
+ )
535
+ def subtype_align_centerh(command, channel, _, data=None, **kwargs):
536
+ mode, group, bound, elements = data
537
+ _align_xy(channel, _, mode, bound, elements, "center", "none", group)
538
+ return "align", (mode, group, bound, elements)
539
+
540
+ @self.console_command(
541
+ "centerv",
542
+ help=_("align elements at center vertically"),
543
+ input_type="align",
544
+ output_type="align",
545
+ )
546
+ def subtype_align_centerv(command, channel, _, data=None, **kwargs):
547
+ mode, group, bound, elements = data
548
+ _align_xy(channel, _, mode, bound, elements, "none", "center", group)
549
+ return "align", (mode, group, bound, elements)
550
+
551
+ def distribute_elements(elements, in_x: bool = True, distance: bool = True):
552
+ if len(elements) <= 2: # Cannot distribute 2 or fewer items.
553
+ return
554
+ if in_x:
555
+ elements.sort(key=lambda n: n.bounds[0]) # sort by left edge
556
+ else:
557
+ elements.sort(key=lambda n: n.bounds[1]) # sort by top edge
558
+ boundary_points = [node.bounds for node in elements]
559
+ if not boundary_points:
560
+ return
561
+ idx = 0 if in_x else 1
562
+ if distance:
563
+ left_edge = boundary_points[0][idx]
564
+ right_edge = boundary_points[-1][idx + 2]
565
+ dim_total = right_edge - left_edge
566
+ dim_available = dim_total
567
+ for node in elements:
568
+ bounds = node.bounds
569
+ dim_available -= bounds[idx + 2] - bounds[idx]
570
+ distributed_distance = dim_available / (len(elements) - 1)
571
+ dim_pos = left_edge
572
+ else:
573
+ left_edge = (boundary_points[0][idx] + boundary_points[0][idx + 2]) / 2
574
+ right_edge = (boundary_points[-1][idx] + boundary_points[-1][idx + 2]) / 2
575
+ dim_total = right_edge - left_edge
576
+ dim_available = dim_total
577
+ dim_pos = left_edge
578
+ distributed_distance = dim_available / (len(elements) - 1)
579
+
580
+ # _("Distribute")
581
+ with self.undoscope("Distribute"):
582
+ for node in elements:
583
+ subbox = node.bounds
584
+ if distance:
585
+ delta = subbox[idx] - dim_pos
586
+ dim_pos += subbox[idx + 2] - subbox[idx] + distributed_distance
587
+ else:
588
+ delta = (subbox[idx] + subbox[idx + 2]) / 2 - dim_pos
589
+ dim_pos += distributed_distance
590
+ if in_x:
591
+ dx = -delta
592
+ dy = 0
593
+ else:
594
+ dx = 0
595
+ dy = -delta
596
+ if dx != 0 or dy != 0:
597
+ self.translate_node(node, dx, dy)
598
+
599
+ @self.console_command(
600
+ "spaceh",
601
+ help=_("distribute elements across horizontal space"),
602
+ input_type="align",
603
+ output_type="align",
604
+ )
605
+ def subtype_align_spaceh(command, channel, _, data=None, **kwargs):
606
+ mode, group, bound, raw_elements = data
607
+ haslock = False
608
+ for node in raw_elements:
609
+ if not node.can_move(self.lock_allows_move):
610
+ haslock = True
611
+ break
612
+ if haslock:
613
+ channel(_("Your selection contains a locked element, that cannot be moved"))
614
+ return "align", (mode, group, bound, raw_elements)
615
+ elements = self.condense_elements(raw_elements)
616
+ distribute_elements(elements, in_x=True, distance=True)
617
+ self.signal("refresh_scene", "Scene")
618
+ return "align", (mode, group, bound, elements)
619
+
620
+ @self.console_command(
621
+ "spaceh2",
622
+ help=_("distribute elements across horizontal space"),
623
+ input_type="align",
624
+ output_type="align",
625
+ )
626
+ def subtype_align_spaceh2(command, channel, _, data=None, **kwargs):
627
+ mode, group, bound, raw_elements = data
628
+ haslock = False
629
+ for node in raw_elements:
630
+ if not node.can_move(self.lock_allows_move):
631
+ haslock = True
632
+ break
633
+ if haslock:
634
+ channel(_("Your selection contains a locked element, that cannot be moved"))
635
+ return "align", (mode, group, bound, raw_elements)
636
+ elements = self.condense_elements(raw_elements)
637
+ distribute_elements(elements, in_x=True, distance=False)
638
+ self.signal("refresh_scene", "Scene")
639
+ return "align", (mode, group, bound, elements)
640
+
641
+ @self.console_command(
642
+ "spacev",
643
+ help=_("distribute elements across vertical space"),
644
+ input_type="align",
645
+ output_type="align",
646
+ )
647
+ def subtype_align_spacev(command, channel, _, data=None, **kwargs):
648
+ mode, group, bound, raw_elements = data
649
+ haslock = False
650
+ for node in raw_elements:
651
+ if not node.can_move(self.lock_allows_move):
652
+ haslock = True
653
+ break
654
+ if haslock:
655
+ channel(_("Your selection contains a locked element, that cannot be moved"))
656
+ return "align", (mode, group, bound, raw_elements)
657
+ elements = self.condense_elements(raw_elements)
658
+ distribute_elements(elements, in_x=False, distance=True)
659
+ self.signal("refresh_scene", "Scene")
660
+ return "align", (mode, group, bound, elements)
661
+
662
+ @self.console_command(
663
+ "spacev2",
664
+ help=_("distribute elements across vertical space"),
665
+ input_type="align",
666
+ output_type="align",
667
+ )
668
+ def subtype_align_spacev2(command, channel, _, data=None, **kwargs):
669
+ mode, group, bound, raw_elements = data
670
+ haslock = False
671
+ for node in raw_elements:
672
+ if not node.can_move(self.lock_allows_move):
673
+ haslock = True
674
+ break
675
+ if haslock:
676
+ channel(_("Your selection contains a locked element, that cannot be moved"))
677
+ return "align", (mode, group, bound, raw_elements)
678
+ elements = self.condense_elements(raw_elements)
679
+ distribute_elements(elements, in_x=False, distance=False)
680
+ self.signal("refresh_scene", "Scene")
681
+ return "align", (mode, group, bound, elements)
682
+
683
+ @self.console_argument(
684
+ "preserve_aspect_ratio",
685
+ type=str,
686
+ default="none",
687
+ help="preserve aspect ratio value",
688
+ )
689
+ @self.console_command(
690
+ "view",
691
+ help=_("align elements within viewbox"),
692
+ input_type="align",
693
+ output_type="align",
694
+ )
695
+ def subtype_align(
696
+ command, channel, _, data=None, preserve_aspect_ratio="none", **kwargs
697
+ ):
698
+ """
699
+ Align the elements to within the bed according to SVG Viewbox rules. The following aspect ratios
700
+ are valid. These should define all the valid methods of centering data within the laser bed.
701
+ "xminymin",
702
+ "xmidymin",
703
+ "xmaxymin",
704
+ "xminymid",
705
+ "xmidymid",
706
+ "xmaxymid",
707
+ "xminymax",
708
+ "xmidymax",
709
+ "xmaxymax",
710
+ "xminymin meet",
711
+ "xmidymin meet",
712
+ "xmaxymin meet",
713
+ "xminymid meet",
714
+ "xmidymid meet",
715
+ "xmaxymid meet",
716
+ "xminymax meet",
717
+ "xmidymax meet",
718
+ "xmaxymax meet",
719
+ "xminymin slice",
720
+ "xmidymin slice",
721
+ "xmaxymin slice",
722
+ "xminymid slice",
723
+ "xmidymid slice",
724
+ "xmaxymid slice",
725
+ "xminymax slice",
726
+ "xmidymax slice",
727
+ "xmaxymax slice",
728
+ "none"
729
+ """
730
+ mode, group, bound, elements = data
731
+ boundary_points = [node.bounds for node in elements]
732
+ if not boundary_points:
733
+ return
734
+
735
+ haslock = False
736
+ for node in elements:
737
+ if not node.can_move(self.lock_allows_move):
738
+ haslock = True
739
+ break
740
+ if haslock:
741
+ channel(_("Your selection contains a locked element, that cannot be moved"))
742
+ return
743
+ left_edge = min([e[0] for e in boundary_points])
744
+ top_edge = min(e[1] for e in boundary_points)
745
+ right_edge = max(e[2] for e in boundary_points)
746
+ bottom_edge = max(e[3] for e in boundary_points)
747
+
748
+ if preserve_aspect_ratio in (
749
+ "xminymin",
750
+ "xmidymin",
751
+ "xmaxymin",
752
+ "xminymid",
753
+ "xmidymid",
754
+ "xmaxymid",
755
+ "xminymax",
756
+ "xmidymax",
757
+ "xmaxymax",
758
+ "xminymin meet",
759
+ "xmidymin meet",
760
+ "xmaxymin meet",
761
+ "xminymid meet",
762
+ "xmidymid meet",
763
+ "xmaxymid meet",
764
+ "xminymax meet",
765
+ "xmidymax meet",
766
+ "xmaxymax meet",
767
+ "xminymin slice",
768
+ "xmidymin slice",
769
+ "xmaxymin slice",
770
+ "xminymid slice",
771
+ "xmidymid slice",
772
+ "xmaxymid slice",
773
+ "xminymax slice",
774
+ "xmidymax slice",
775
+ "xmaxymax slice",
776
+ "none",
777
+ ):
778
+ for node in elements:
779
+ device_width = self.length_x("100%")
780
+ device_height = self.length_y("100%")
781
+
782
+ matrix = Viewbox.viewbox_transform(
783
+ 0,
784
+ 0,
785
+ device_width,
786
+ device_height,
787
+ left_edge,
788
+ top_edge,
789
+ right_edge - left_edge,
790
+ bottom_edge - top_edge,
791
+ preserve_aspect_ratio,
792
+ )
793
+ for q in node.flat(types=elem_nodes):
794
+ try:
795
+ q.matrix *= matrix
796
+ q.modified()
797
+ except AttributeError:
798
+ continue
799
+ for q in node.flat(types=("file", "group")):
800
+ q.modified()
801
+ return "align", (mode, group, bound, elements)