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,793 +1,805 @@
1
- from math import atan, sqrt, tau
2
-
3
- import wx
4
-
5
- from meerk40t.core.units import Length
6
- from meerk40t.gui.icons import (
7
- icon_instruct_circle,
8
- icon_instruct_rect,
9
- icon_instruct_square,
10
- )
11
- from meerk40t.gui.mwindow import MWindow
12
- from meerk40t.gui.wxutils import dip_size
13
- from meerk40t.kernel import signal_listener
14
-
15
- _ = wx.GetTranslation
16
-
17
-
18
- DEFAULT_LEN = "5cm"
19
-
20
-
21
- class LaserToolPanel(wx.Panel):
22
- def __init__(self, *args, context=None, **kwds):
23
- # begin wxGlade: clsLasertools.__init__
24
- kwds["style"] = kwds.get("style", 0) | wx.TAB_TRAVERSAL
25
- wx.Panel.__init__(self, *args, **kwds)
26
- self.context = context
27
- self.coord_a = None
28
- self.coord_b = None
29
- self.coord_c = None
30
- self.laserposition = None
31
-
32
- sizer_main = wx.BoxSizer(wx.VERTICAL)
33
-
34
- self.nbook_lasertools = wx.Notebook(self, wx.ID_ANY)
35
- sizer_main.Add(self.nbook_lasertools, 1, wx.EXPAND, 0)
36
-
37
- # ------------------------ Circle with 3 points
38
-
39
- self.nb_circle = wx.Panel(self.nbook_lasertools, wx.ID_ANY)
40
- self.nbook_lasertools.AddPage(self.nb_circle, _("Find center"))
41
-
42
- self.sizer_circle = wx.BoxSizer(wx.VERTICAL)
43
-
44
- sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
45
- self.sizer_circle.Add(sizer_9, 0, wx.EXPAND, 0)
46
-
47
- sizer_10 = wx.BoxSizer(wx.VERTICAL)
48
- sizer_9.Add(sizer_10, 0, wx.EXPAND, 0)
49
-
50
- sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
51
- sizer_10.Add(sizer_1, 1, wx.EXPAND, 0)
52
-
53
- label_1 = wx.StaticText(self.nb_circle, wx.ID_ANY, _("A"))
54
- sizer_1.Add(label_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
55
-
56
- self.btn_set_circle_1 = wx.Button(self.nb_circle, wx.ID_ANY, _("Use position"))
57
- self.btn_set_circle_1.SetToolTip(
58
- _("Place the laser over the desired point and click...")
59
- )
60
- sizer_1.Add(self.btn_set_circle_1, 0, wx.EXPAND, 0)
61
-
62
- # How big should graphics become?
63
- desired_height = 6 * self.btn_set_circle_1.Size[1]
64
-
65
- self.lbl_pos_1 = wx.StaticText(self.nb_circle, wx.ID_ANY, _("<empty>"))
66
- sizer_1.Add(self.lbl_pos_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
67
-
68
- sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
69
- sizer_10.Add(sizer_2, 1, wx.EXPAND, 0)
70
-
71
- label_2 = wx.StaticText(self.nb_circle, wx.ID_ANY, _("B"))
72
- sizer_2.Add(label_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
73
-
74
- self.btn_set_circle_2 = wx.Button(self.nb_circle, wx.ID_ANY, _("Use position"))
75
- self.btn_set_circle_2.SetToolTip(
76
- _("Place the laser over the desired point and click...")
77
- )
78
- sizer_2.Add(self.btn_set_circle_2, 0, wx.EXPAND, 0)
79
-
80
- self.lbl_pos_2 = wx.StaticText(self.nb_circle, wx.ID_ANY, _("<empty>"))
81
- sizer_2.Add(self.lbl_pos_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
82
-
83
- sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
84
- sizer_10.Add(sizer_3, 1, wx.EXPAND, 0)
85
-
86
- label_3 = wx.StaticText(self.nb_circle, wx.ID_ANY, _("C"))
87
- sizer_3.Add(label_3, 0, wx.ALIGN_CENTER_VERTICAL, 0)
88
-
89
- self.btn_set_circle_3 = wx.Button(self.nb_circle, wx.ID_ANY, _("Use position"))
90
- self.btn_set_circle_3.SetToolTip(
91
- _("Place the laser over the desired point and click...")
92
- )
93
- sizer_3.Add(self.btn_set_circle_3, 0, wx.EXPAND, 0)
94
-
95
- self.lbl_pos_3 = wx.StaticText(self.nb_circle, wx.ID_ANY, _("<empty>"))
96
- sizer_3.Add(self.lbl_pos_3, 0, wx.ALIGN_CENTER_VERTICAL, 0)
97
-
98
- img_instruction_1 = wx.StaticBitmap(
99
- self.nb_circle,
100
- wx.ID_ANY,
101
- self.fitted_bitmap(icon_instruct_circle, desired_height),
102
- )
103
- instructions = _(
104
- "Instruction: place the laser on three points on the circumference of the circle on the bed and confirm the position by clicking on the buttons below.\nMK will find the center for you and place the laser above it or will recreate the circle for further processing."
105
- )
106
- img_instruction_1.SetToolTip(instructions)
107
- sizer_9.Add(img_instruction_1, 1, 0, 0)
108
-
109
- sizer_chk = wx.BoxSizer(wx.HORIZONTAL)
110
- self.sizer_circle.Add(sizer_chk, 0, wx.EXPAND, 0)
111
- self.check_ref_circle = wx.CheckBox(
112
- self.nb_circle, wx.ID_ANY, _("Make reference")
113
- )
114
- sizer_chk.Add(self.check_ref_circle, 0, wx.ALIGN_CENTER_VERTICAL, 0)
115
- self.check_circle = wx.CheckBox(self.nb_circle, wx.ID_ANY, _("Mark Center"))
116
- sizer_chk.Add(self.check_circle, 0, wx.ALIGN_CENTER_VERTICAL, 0)
117
-
118
- sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
119
- self.sizer_circle.Add(sizer_4, 0, wx.EXPAND, 0)
120
-
121
- self.btn_move_to_center = wx.Button(
122
- self.nb_circle, wx.ID_ANY, _("Move to center")
123
- )
124
- sizer_4.Add(self.btn_move_to_center, 0, wx.ALIGN_CENTER_VERTICAL, 0)
125
-
126
- self.btn_create_circle = wx.Button(
127
- self.nb_circle, wx.ID_ANY, _("Create circle")
128
- )
129
- sizer_4.Add(self.btn_create_circle, 0, wx.EXPAND, 0)
130
-
131
- # ------------------------ Rectangle with 2 points
132
-
133
- self.nb_rectangle = wx.Panel(self.nbook_lasertools, wx.ID_ANY)
134
- self.nbook_lasertools.AddPage(self.nb_rectangle, _("Place frame"))
135
-
136
- self.sizer_rectangle = wx.BoxSizer(wx.VERTICAL)
137
-
138
- sizer_rect_hor = wx.BoxSizer(wx.HORIZONTAL)
139
- self.sizer_rectangle.Add(sizer_rect_hor, 0, wx.EXPAND, 0)
140
-
141
- sizer_rect_vert = wx.BoxSizer(wx.VERTICAL)
142
- sizer_rect_hor.Add(sizer_rect_vert, 0, wx.EXPAND, 0)
143
-
144
- sizer_5a = wx.BoxSizer(wx.HORIZONTAL)
145
- sizer_rect_vert.Add(sizer_5a, 1, wx.EXPAND, 0)
146
-
147
- label_corner_1 = wx.StaticText(self.nb_rectangle, wx.ID_ANY, _("Corner 1"))
148
- sizer_5a.Add(label_corner_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
149
-
150
- self.btn_set_rect_1 = wx.Button(self.nb_rectangle, wx.ID_ANY, _("Use position"))
151
- self.btn_set_rect_1.SetToolTip(
152
- _("Place the laser over the desired point and click...")
153
- )
154
- sizer_5a.Add(self.btn_set_rect_1, 0, wx.EXPAND, 0)
155
-
156
- self.lbl_pos_7 = wx.StaticText(self.nb_rectangle, wx.ID_ANY, _("<empty>"))
157
- sizer_5a.Add(self.lbl_pos_7, 0, wx.ALIGN_CENTER_VERTICAL, 0)
158
-
159
- sizer_6a = wx.BoxSizer(wx.HORIZONTAL)
160
- sizer_rect_vert.Add(sizer_6a, 1, wx.EXPAND, 0)
161
-
162
- label_corner_2 = wx.StaticText(self.nb_rectangle, wx.ID_ANY, _("Corner 2"))
163
- sizer_6a.Add(label_corner_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
164
-
165
- self.btn_set_rect_2 = wx.Button(self.nb_rectangle, wx.ID_ANY, _("Use position"))
166
- self.btn_set_rect_2.SetToolTip(
167
- _("Place the laser over the desired point and click...")
168
- )
169
- sizer_6a.Add(self.btn_set_rect_2, 0, wx.EXPAND, 0)
170
-
171
- self.lbl_pos_8 = wx.StaticText(self.nb_rectangle, wx.ID_ANY, _("<empty>"))
172
- sizer_6a.Add(self.lbl_pos_8, 0, wx.ALIGN_CENTER_VERTICAL, 0)
173
-
174
- self.img_instruction_2 = wx.StaticBitmap(
175
- self.nb_rectangle,
176
- wx.ID_ANY,
177
- self.fitted_bitmap(icon_instruct_rect, desired_height),
178
- )
179
- instructions = _(
180
- "Instruction: place the laser on one corner of the encompassing rectangle and confirm the position by clicking on the buttons below. Then choose the opposing corner.\nMK will create a rectangle for you for further processing."
181
- )
182
- self.img_instruction_2.SetToolTip(instructions)
183
- sizer_rect_hor.Add(self.img_instruction_2, 1, 0, 0)
184
-
185
- sizer_chk_rect = wx.BoxSizer(wx.HORIZONTAL)
186
- self.sizer_rectangle.Add(sizer_chk_rect, 0, wx.EXPAND, 0)
187
- self.check_ref_frame = wx.CheckBox(
188
- self.nb_rectangle, wx.ID_ANY, _("Make reference")
189
- )
190
- sizer_chk_rect.Add(self.check_ref_frame, 0, wx.ALIGN_CENTER_VERTICAL, 0)
191
-
192
- sizer_8a = wx.BoxSizer(wx.HORIZONTAL)
193
- self.sizer_rectangle.Add(sizer_8a, 0, wx.EXPAND, 0)
194
-
195
- self.btn_create_frame = wx.Button(
196
- self.nb_rectangle, wx.ID_ANY, _("Create frame")
197
- )
198
- sizer_8a.Add(self.btn_create_frame, 0, wx.EXPAND, 0)
199
-
200
- # ------------------------ Square with 3 points
201
-
202
- self.nb_square = wx.Panel(self.nbook_lasertools, wx.ID_ANY)
203
- self.nbook_lasertools.AddPage(self.nb_square, _("Place square"))
204
-
205
- self.sizer_square = wx.BoxSizer(wx.VERTICAL)
206
-
207
- sizer_sqare_hor = wx.BoxSizer(wx.HORIZONTAL)
208
- self.sizer_square.Add(sizer_sqare_hor, 0, wx.EXPAND, 0)
209
-
210
- sizer_sqare_vert = wx.BoxSizer(wx.VERTICAL)
211
- sizer_sqare_hor.Add(sizer_sqare_vert, 0, wx.EXPAND, 0)
212
-
213
- sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
214
- sizer_sqare_vert.Add(sizer_5, 1, wx.EXPAND, 0)
215
-
216
- label_4 = wx.StaticText(self.nb_square, wx.ID_ANY, _("Side A 1"))
217
- label_4.SetMinSize(dip_size(self.nb_square, 45, -1))
218
- sizer_5.Add(label_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
219
-
220
- self.btn_set_square_1 = wx.Button(self.nb_square, wx.ID_ANY, _("Use position"))
221
- self.btn_set_square_1.SetToolTip(
222
- _("Place the laser over the desired point and click...")
223
- )
224
- sizer_5.Add(self.btn_set_square_1, 0, wx.EXPAND, 0)
225
-
226
- self.lbl_pos_4 = wx.StaticText(self.nb_square, wx.ID_ANY, _("<empty>"))
227
- sizer_5.Add(self.lbl_pos_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
228
-
229
- sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
230
- sizer_sqare_vert.Add(sizer_6, 1, wx.EXPAND, 0)
231
-
232
- label_5 = wx.StaticText(self.nb_square, wx.ID_ANY, _("Side A 2"))
233
- label_5.SetMinSize(dip_size(self.nb_square, 45, -1))
234
- sizer_6.Add(label_5, 0, wx.ALIGN_CENTER_VERTICAL, 0)
235
-
236
- self.btn_set_square_2 = wx.Button(self.nb_square, wx.ID_ANY, _("Use position"))
237
- self.btn_set_square_2.SetToolTip(
238
- _("Place the laser over the desired point and click...")
239
- )
240
- sizer_6.Add(self.btn_set_square_2, 0, wx.EXPAND, 0)
241
-
242
- self.lbl_pos_5 = wx.StaticText(self.nb_square, wx.ID_ANY, _("<empty>"))
243
- sizer_6.Add(self.lbl_pos_5, 0, wx.ALIGN_CENTER_VERTICAL, 0)
244
-
245
- sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
246
- sizer_sqare_vert.Add(sizer_7, 1, wx.EXPAND, 0)
247
-
248
- label_6 = wx.StaticText(self.nb_square, wx.ID_ANY, _("Side B"))
249
- label_6.SetMinSize(dip_size(self.nb_square, 45, -1))
250
- sizer_7.Add(label_6, 0, wx.ALIGN_CENTER_VERTICAL, 0)
251
-
252
- self.btn_set_square_3 = wx.Button(self.nb_square, wx.ID_ANY, _("Use position"))
253
- self.btn_set_square_3.SetToolTip(
254
- _("Place the laser over the desired point and click...")
255
- )
256
- sizer_7.Add(self.btn_set_square_3, 0, wx.EXPAND, 0)
257
-
258
- self.lbl_pos_6 = wx.StaticText(self.nb_square, wx.ID_ANY, _("<empty>"))
259
- sizer_7.Add(self.lbl_pos_6, 0, wx.ALIGN_CENTER_VERTICAL, 0)
260
-
261
- size_width = wx.BoxSizer(wx.HORIZONTAL)
262
- sizer_sqare_vert.Add(size_width, 1, wx.EXPAND, 0)
263
-
264
- label_wd = wx.StaticText(self.nb_square, wx.ID_ANY, _("Dimension"))
265
- size_width.Add(label_wd, 0, wx.ALIGN_CENTER_VERTICAL, 0)
266
-
267
- self.txt_width = wx.TextCtrl(self.nb_square, wx.ID_ANY, DEFAULT_LEN)
268
- self.txt_width.SetToolTip(_("Extension of the square to create"))
269
- self.txt_width.SetMinSize(dip_size(self.nb_square, 60, -1))
270
- size_width.Add(self.txt_width, 0, wx.EXPAND, 0)
271
-
272
- self.img_instruction_3 = wx.StaticBitmap(
273
- self.nb_square,
274
- wx.ID_ANY,
275
- self.fitted_bitmap(icon_instruct_square, desired_height),
276
- )
277
- instructions = _(
278
- "Instruction: place the laser on two points of one side of a square on the bed and confirm the position by clicking on the buttons below. Then choose one point on the other side of the corner.\nMK will create a square for you for further processing."
279
- )
280
- self.img_instruction_3.SetToolTip(instructions)
281
- sizer_sqare_hor.Add(self.img_instruction_3, 1, 0, 0)
282
-
283
- sizer_chk_square = wx.BoxSizer(wx.HORIZONTAL)
284
- self.sizer_square.Add(sizer_chk_square, 0, wx.EXPAND, 0)
285
- self.check_ref_square = wx.CheckBox(
286
- self.nb_square, wx.ID_ANY, _("Make reference")
287
- )
288
- sizer_chk_square.Add(self.check_ref_square, 0, wx.ALIGN_CENTER_VERTICAL, 0)
289
- self.check_square = wx.CheckBox(self.nb_square, wx.ID_ANY, _("Mark Corner"))
290
- sizer_chk_square.Add(self.check_square, 0, wx.ALIGN_CENTER_VERTICAL, 0)
291
-
292
- sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
293
- self.sizer_square.Add(sizer_8, 0, wx.EXPAND, 0)
294
-
295
- self.btn_create_square = wx.Button(
296
- self.nb_square, wx.ID_ANY, _("Create square")
297
- )
298
- sizer_8.Add(self.btn_create_square, 0, wx.EXPAND, 0)
299
-
300
- self.nb_square.SetSizer(self.sizer_square)
301
-
302
- self.nb_circle.SetSizer(self.sizer_circle)
303
-
304
- self.nb_rectangle.SetSizer(self.sizer_rectangle)
305
-
306
- self.SetSizer(sizer_main)
307
- sizer_main.Fit(self)
308
-
309
- self.Layout()
310
- self.check_input()
311
- self.btn_set_circle_1.Bind(wx.EVT_BUTTON, self.on_click_get1)
312
- self.btn_set_circle_2.Bind(wx.EVT_BUTTON, self.on_click_get2)
313
- self.btn_set_circle_3.Bind(wx.EVT_BUTTON, self.on_click_get3)
314
- self.btn_move_to_center.Bind(wx.EVT_BUTTON, self.on_btn_move_center)
315
- self.btn_create_circle.Bind(wx.EVT_BUTTON, self.on_btn_create_circle)
316
- self.btn_set_rect_1.Bind(wx.EVT_BUTTON, self.on_click_get1)
317
- self.btn_set_rect_2.Bind(wx.EVT_BUTTON, self.on_click_get2)
318
- self.btn_create_frame.Bind(wx.EVT_BUTTON, self.on_btn_create_frame)
319
-
320
- self.btn_set_square_1.Bind(wx.EVT_BUTTON, self.on_click_get1)
321
- self.btn_set_square_2.Bind(wx.EVT_BUTTON, self.on_click_get2)
322
- self.btn_set_square_3.Bind(wx.EVT_BUTTON, self.on_click_get3)
323
- self.txt_width.Bind(wx.EVT_KILL_FOCUS, self.on_text_change)
324
- self.btn_create_square.Bind(wx.EVT_BUTTON, self.on_btn_create_square)
325
- # self.img_instruction_3.Bind(wx.EVT_LEFT_DCLICK, self.create_scenario)
326
- # end wxGlade
327
-
328
- def fitted_bitmap(self, picture, available_height):
329
- bmp = picture.GetBitmap()
330
- bmp_width, bmp_height = bmp.Size
331
- factor = int(4 * available_height / bmp_height) / 4
332
- # print(f"Img: {factor}, Available:{available_height} vs ht={bmp_height}")
333
- if factor > 1:
334
- bmp_width *= factor
335
- bmp_height *= factor
336
- return picture.GetBitmap(resize=(bmp_width, bmp_height))
337
-
338
- # scenario = 8
339
- #
340
- # def create_scenario(self, event):
341
- # event.Skip()
342
- # self.scenario += 1
343
- # l1 ="10cm"
344
- # self.txt_width.SetValue(l1)
345
- # if self.scenario in (1, 2, 3, 4):
346
- # c1 = (20 * UNITS_PER_MM, 20 * UNITS_PER_MM)
347
- # c2 = (50 * UNITS_PER_MM, 20 * UNITS_PER_MM)
348
- # else:
349
- # c1 = (20 * UNITS_PER_MM, 20 * UNITS_PER_MM)
350
- # c2 = (20 * UNITS_PER_MM, 50 * UNITS_PER_MM)
351
- # if self.scenario in (1, 5):
352
- # c3 = (10 * UNITS_PER_MM, 70 * UNITS_PER_MM)
353
- # elif self.scenario in (2, 6):
354
- # c3 = (10 * UNITS_PER_MM, 0 * UNITS_PER_MM)
355
- # elif self.scenario in (3, 7):
356
- # c3 = (70 * UNITS_PER_MM, 70 * UNITS_PER_MM)
357
- # elif self.scenario in (4, 8):
358
- # c3 = (70 * UNITS_PER_MM, 0 * UNITS_PER_MM)
359
-
360
- # if self.scenario == 9:
361
- # c1 = (20 * UNITS_PER_MM, 20 * UNITS_PER_MM)
362
- # c2 = (30 * UNITS_PER_MM, 50 * UNITS_PER_MM)
363
- # c3 = (70 * UNITS_PER_MM, 10 * UNITS_PER_MM)
364
- # self.set_coord(idx=0, position=c1)
365
- # self.set_coord(idx=1, position=c2)
366
- # self.set_coord(idx=2, position=c3)
367
- # if self.scenario>=9:
368
- # self.scenario = 0
369
-
370
- def set_coord(self, idx=0, position=None):
371
- if position is None:
372
- label_string = _("<empty>")
373
- else:
374
- p = self.context
375
- units = p.units_name
376
- label_string = (
377
- f"({str(Length(amount=position[0], digits=1, preferred_units=units))}, "
378
- f"{str(Length(amount=position[1], digits=1, preferred_units=units))})"
379
- )
380
- if idx == 0:
381
- self.lbl_pos_1.Label = label_string
382
- self.lbl_pos_4.Label = label_string
383
- self.lbl_pos_7.Label = label_string
384
- self.coord_a = position
385
- self.check_input()
386
- elif idx == 1:
387
- self.lbl_pos_2.Label = label_string
388
- self.lbl_pos_5.Label = label_string
389
- self.lbl_pos_8.Label = label_string
390
- self.coord_b = position
391
- self.check_input()
392
- elif idx == 2:
393
- self.lbl_pos_3.Label = label_string
394
- self.lbl_pos_6.Label = label_string
395
- self.coord_c = position
396
- self.check_input()
397
- self.sizer_circle.Layout()
398
- self.sizer_square.Layout()
399
- self.sizer_rectangle.Layout()
400
-
401
- def check_input(self):
402
- if self.coord_a is None or self.coord_b is None or self.coord_c is None:
403
- value = False
404
- else:
405
- value = True
406
- self.btn_create_circle.Enable(value)
407
- self.btn_move_to_center.Enable(value)
408
- self.btn_create_square.Enable(value)
409
- if self.coord_a is None or self.coord_b is None:
410
- value = False
411
- else:
412
- value = True
413
- self.btn_create_frame.Enable(value)
414
-
415
- def on_click_get1(self, event):
416
- # Current Laserposition
417
- self.set_coord(idx=0, position=self.laserposition)
418
-
419
- def on_click_get2(self, event):
420
- # Current Laserposition
421
- self.set_coord(idx=1, position=self.laserposition)
422
- event.Skip()
423
-
424
- def on_click_get3(self, event):
425
- # Current Laserposition
426
- self.set_coord(idx=2, position=self.laserposition)
427
- event.Skip()
428
-
429
- def on_text_change(self, event):
430
- event.Skip()
431
- try:
432
- l = Length(self.txt_width.GetValue())
433
- except (ValueError, AttributeError):
434
- self.txt_width.SetValue(DEFAULT_LEN)
435
-
436
- def calculate_center(self):
437
- """
438
- Let's recall how the equation of a circle looks like in general form:
439
- x^2+y^2+2ax+2by+c=0
440
-
441
- Since all three points should belong to one circle, we can write a system of equations.
442
-
443
- x_1^2+y_1^2+2ax_1+2by_1+c=0\\x_2^2+y_2^2+2ax_2+2by_2+c=0\\x_3^2+y_3^2+2ax_3+2by_3+c=0
444
-
445
- The values (x_1, y_1), (x_2, y_2) and (x_3, y_3) are known. Let's rearrange with respect to unknowns a, b and c.
446
-
447
- 2x_1a+2y_1b+c + x_1^2+y_1^2+=0\\2x_2a+2y_2b+c+x_2^2+y_2^2=0\\2x_3a+2y_3b+c+x_3^2+y_3^2=0
448
- """
449
- result = True
450
- center = None
451
- radius = None
452
- x12 = self.coord_a[0] - self.coord_b[0]
453
- x13 = self.coord_a[0] - self.coord_c[0]
454
-
455
- y12 = self.coord_a[1] - self.coord_b[1]
456
- y13 = self.coord_a[1] - self.coord_c[1]
457
-
458
- y31 = self.coord_c[1] - self.coord_a[1]
459
- y21 = self.coord_b[1] - self.coord_a[1]
460
-
461
- x31 = self.coord_c[0] - self.coord_a[0]
462
- x21 = self.coord_b[0] - self.coord_a[0]
463
-
464
- # coord_a[0]^2 - coord_c[0]^2
465
- sx13 = pow(self.coord_a[0], 2) - pow(self.coord_c[0], 2)
466
-
467
- # self.coord_a[1]^2 - self.coord_c[1]^2
468
- sy13 = pow(self.coord_a[1], 2) - pow(self.coord_c[1], 2)
469
-
470
- sx21 = pow(self.coord_b[0], 2) - pow(self.coord_a[0], 2)
471
- sy21 = pow(self.coord_b[1], 2) - pow(self.coord_a[1], 2)
472
- try:
473
- f = (sx13 * x12 + sy13 * x12 + sx21 * x13 + sy21 * x13) // (
474
- 2 * (y31 * x12 - y21 * x13)
475
- )
476
-
477
- g = (sx13 * y12 + sy13 * y12 + sx21 * y13 + sy21 * y13) // (
478
- 2 * (x31 * y12 - x21 * y13)
479
- )
480
- except (ZeroDivisionError, ArithmeticError):
481
- return False, None, None
482
-
483
- c = (
484
- -pow(self.coord_a[0], 2)
485
- - pow(self.coord_a[1], 2)
486
- - 2 * g * self.coord_a[0]
487
- - 2 * f * self.coord_a[1]
488
- )
489
-
490
- # eqn of circle be x^2 + y^2 + 2*g*x + 2*f*y + c = 0
491
- # where centre is (h = -g, k = -f) and
492
- # radius r as r^2 = h^2 + k^2 - c
493
- h = -g
494
- k = -f
495
- sqr_of_r = h * h + k * k - c
496
-
497
- # r is the radius
498
- if sqr_of_r < 0:
499
- result = False
500
- else:
501
- r = round(sqrt(sqr_of_r), 5)
502
-
503
- # print("Centre = (", h, ", ", k, ")")
504
- # print("Radius = ", r)
505
- center = (h, k)
506
- radius = r
507
- return result, center, radius
508
-
509
- def calculate_square(self):
510
- result = True
511
- center = None
512
- angle = 0
513
- signx = 1
514
- signy = 1
515
- # equation for the first line through (x1, y1)-(x2, y2)
516
- # y = a1 * x + b1
517
- dx1 = self.coord_a[0] - self.coord_b[0]
518
- dy1 = self.coord_a[1] - self.coord_b[1]
519
- if dx1 == 0 and dy1 == 0:
520
- result = False
521
- if self.coord_a == self.coord_b:
522
- result = False
523
- if self.coord_a == self.coord_c:
524
- result = False
525
- if self.coord_b == self.coord_c:
526
- result = False
527
-
528
- if dx1 == 0:
529
- a1 = float("inf")
530
- b1 = 0
531
- else:
532
- a1 = dy1 / dx1
533
- b1 = self.coord_a[1] - self.coord_a[0] * a1
534
-
535
- if dx1 == 0:
536
- center = (self.coord_a[0], self.coord_c[1])
537
- elif dy1 == 0:
538
- center = (self.coord_c[0], self.coord_a[1])
539
- else:
540
- # regular line
541
- # line 1
542
- # y = a1 * x + b1
543
- # orthogonal line
544
- a2 = -1 / a1
545
- b2 = self.coord_c[1] - self.coord_c[0] * a2
546
-
547
- x0 = (b2 - b1) / (a1 - a2)
548
- y0 = a1 * x0 + b1
549
- center = (x0, y0)
550
- dx1 = 0
551
- dy1 = 0
552
- angle = atan(a1)
553
-
554
- mid_a_x = (self.coord_a[0] + self.coord_b[0]) / 2
555
- mid_a_y = (self.coord_a[1] + self.coord_b[1]) / 2
556
- if abs(dx1) < abs(dy1): # A is a 'vertical' line
557
- if mid_a_y < center[1]:
558
- if self.coord_c[0] >= center[0]:
559
- segment = 4
560
- else:
561
- segment = 3
562
- else:
563
- if self.coord_c[0] >= center[0]:
564
- segment = 1
565
- else:
566
- segment = 2
567
- else: # Horizontal line
568
- if mid_a_x < center[0]:
569
- if self.coord_c[1] >= center[1]:
570
- segment = 2
571
- else:
572
- segment = 3
573
- else:
574
- if self.coord_c[1] >= center[1]:
575
- segment = 1
576
- else:
577
- segment = 4
578
- if segment == 1:
579
- signx = +1
580
- signy = +1
581
- elif segment == 2:
582
- signx = -1
583
- signy = +1
584
- elif segment == 3:
585
- signx = -1
586
- signy = -1
587
- elif segment == 4:
588
- signx = +1
589
- signy = -1
590
-
591
- # print (center, angle / tau * 360)
592
- return result, center, angle, signx, signy
593
-
594
- def calculate_frame(self):
595
- result = False
596
- left_top = (0, 0)
597
- width = 0
598
- height = 0
599
- if self.coord_a is not None and self.coord_b is not None:
600
- x0 = self.coord_a[0]
601
- x1 = self.coord_b[0]
602
- y0 = self.coord_a[1]
603
- y1 = self.coord_b[1]
604
- width = abs(x0 - x1)
605
- height = abs(y0 - y1)
606
- xx = min(x0, x1)
607
- yy = min(y0, y1)
608
- if width != 0 and height != 0:
609
- left_top = (xx, yy)
610
- result = True
611
- return result, left_top, width, height
612
-
613
- def on_btn_move_center(self, event): # wxGlade: clsLasertools.<event_handler>
614
- result, center, radius = self.calculate_center()
615
- if result:
616
- p = self.context
617
- units = p.units_name
618
- cx = float(Length(amount=center[0], digits=5, preferred_units=units))
619
- cy = float(Length(amount=center[1], digits=5, preferred_units=units))
620
- if self.context.elements.classify_new:
621
- option = " classify"
622
- postsignal = "tree_changed"
623
- else:
624
- option = ""
625
- postsignal = ""
626
- if self.check_circle.GetValue():
627
- self.context(
628
- f"circle "
629
- f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
630
- f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
631
- f"1mm stroke blue{option}\n"
632
- )
633
- if postsignal != "":
634
- self.context.signal(postsignal)
635
- if (
636
- cx < 0
637
- or cy < 0
638
- or cx > self.context.device.view.unit_width
639
- or cy > self.context.device.view.unit_height
640
- ):
641
- message = (
642
- _("The circles center seems to lie outside the bed-dimensions!")
643
- + "\n"
644
- )
645
- message += (
646
- _("If you continue to move to the center, then the laserhead might")
647
- + "\n"
648
- )
649
- message += _(
650
- "slam into the walls and get damaged! Do you really want to proceed?"
651
- )
652
- caption = _("Dangerous coordinates")
653
- dlg = wx.MessageDialog(
654
- self,
655
- message,
656
- caption,
657
- wx.YES_NO | wx.ICON_WARNING,
658
- )
659
- dlgresult = dlg.ShowModal()
660
- dlg.Destroy()
661
- if dlgresult != wx.ID_YES:
662
- return
663
- self.context(
664
- f"move_absolute "
665
- f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
666
- f"{str(Length(amount=center[1], digits=5, preferred_units=units))}\n"
667
- )
668
-
669
- def on_btn_create_circle(self, event): # wxGlade: clsLasertools.<event_handler>
670
- result, center, radius = self.calculate_center()
671
- if result:
672
- p = self.context
673
- units = p.units_name
674
- if self.context.elements.classify_new:
675
- option = " classify"
676
- postsignal = "tree_changed"
677
- else:
678
- option = ""
679
- postsignal = ""
680
- if self.check_circle.GetValue():
681
- self.context(
682
- f"circle "
683
- f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
684
- f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
685
- f"1mm stroke blue{option}\n"
686
- )
687
- self.context(
688
- f"circle "
689
- f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
690
- f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
691
- f"{str(Length(amount=radius, digits=5, preferred_units=units))}{option}\n"
692
- )
693
- if self.check_ref_circle.GetValue():
694
- self.context("reference\n")
695
- if postsignal != "":
696
- self.context.signal(postsignal)
697
- event.Skip()
698
-
699
- def on_btn_create_frame(self, event): # wxGlade: clsLasertools.<event_handler>
700
- result, left_top, width, height = self.calculate_frame()
701
-
702
- if result:
703
- p = self.context
704
- units = p.units_name
705
- if self.context.elements.classify_new:
706
- option = " classify"
707
- postsignal = "tree_changed"
708
- else:
709
- option = ""
710
- postsignal = ""
711
-
712
- self.context(
713
- f"rect "
714
- f"{str(Length(amount=left_top[0], digits=5, preferred_units=units))} "
715
- f"{str(Length(amount=left_top[1], digits=5, preferred_units=units))} "
716
- f"{str(Length(amount=width, digits=5, preferred_units=units))} "
717
- f"{str(Length(amount=height, digits=5, preferred_units=units))}"
718
- f"{option}\n"
719
- )
720
- if self.check_ref_frame.GetValue():
721
- self.context("reference\n")
722
- if postsignal != "":
723
- self.context.signal(postsignal)
724
- event.Skip()
725
-
726
- def on_btn_create_square(self, event): # wxGlade: clsLasertools.<event_handler>
727
- try:
728
- dim_x = Length(self.txt_width.GetValue())
729
- dim_y = Length(self.txt_width.GetValue())
730
- except ValueError:
731
- dim_x = Length(DEFAULT_LEN)
732
- dim_y = Length(DEFAULT_LEN)
733
- result, center, angle, signx, signy = self.calculate_square()
734
- dim_x *= signx
735
- dim_y *= signy
736
- angle = angle * 360 / tau
737
- if result:
738
- p = self.context
739
- units = p.units_name
740
-
741
- # self.context("circle {x}mm {y}mm 2mm stroke green".format(x=round(self.coord_a[0]/UNITS_PER_MM,2),y=round(self.coord_a[1]/UNITS_PER_MM,2)) )
742
- # self.context("circle {x}mm {y}mm 2mm stroke green".format(x=round(self.coord_b[0]/UNITS_PER_MM,2),y=round(self.coord_b[1]/UNITS_PER_MM,2)) )
743
- # self.context("circle {x}mm {y}mm 2mm stroke red".format(x=round(self.coord_c[0]/UNITS_PER_MM,2),y=round(self.coord_c[1]/UNITS_PER_MM,2)) )
744
-
745
- if self.check_square.GetValue():
746
- self.context(
747
- f"circle "
748
- f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
749
- f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
750
- f"1mm stroke black\n"
751
- )
752
- self.context(
753
- f"rect "
754
- f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
755
- f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
756
- f"{str(dim_x.length_mm)} "
757
- f"{str(dim_y.length_mm)} "
758
- f"rotate {angle}deg "
759
- f"-x {str(Length(amount=center[0], digits=5, preferred_units=units))} "
760
- f"-y {str(Length(amount=center[1], digits=5, preferred_units=units))}\n"
761
- )
762
- if self.check_ref_square.GetValue():
763
- self.context("reference\n")
764
- event.Skip()
765
-
766
- @signal_listener("driver;position")
767
- @signal_listener("emulator;position")
768
- @signal_listener("status;position")
769
- def on_update_laser(self, origin, pos):
770
- self.laserposition = (pos[2], pos[3])
771
-
772
-
773
- class LaserTool(MWindow):
774
- def __init__(self, *args, **kwds):
775
- super().__init__(551, 234, submenu="Operations", *args, **kwds)
776
- self.panel = LaserToolPanel(self, wx.ID_ANY, context=self.context)
777
- _icon = wx.NullIcon
778
- # _icon.CopyFromBitmap(icons8_computer_support.GetBitmap())
779
- self.SetIcon(_icon)
780
- self.SetTitle(_("Place Template"))
781
-
782
- def window_open(self):
783
- pass
784
-
785
- def window_close(self):
786
- pass
787
-
788
- def delegates(self):
789
- yield self.panel
790
-
791
- @staticmethod
792
- def submenu():
793
- return "Laser-Tools", "Place Template"
1
+ from math import atan, sqrt, tau
2
+
3
+ import wx
4
+
5
+ from meerk40t.core.units import Length
6
+ from meerk40t.gui.icons import (
7
+ icon_instruct_circle,
8
+ icon_instruct_rect,
9
+ icon_instruct_square,
10
+ )
11
+ from meerk40t.gui.mwindow import MWindow
12
+ from meerk40t.gui.wxutils import (
13
+ TextCtrl,
14
+ dip_size,
15
+ wxButton,
16
+ wxCheckBox,
17
+ wxStaticBitmap,
18
+ wxStaticText,
19
+ )
20
+ from meerk40t.kernel import signal_listener
21
+
22
+ _ = wx.GetTranslation
23
+
24
+
25
+ DEFAULT_LEN = "5cm"
26
+
27
+
28
+ class LaserToolPanel(wx.Panel):
29
+ def __init__(self, *args, context=None, **kwds):
30
+ # begin wxGlade: clsLasertools.__init__
31
+ kwds["style"] = kwds.get("style", 0) | wx.TAB_TRAVERSAL
32
+ wx.Panel.__init__(self, *args, **kwds)
33
+ self.context = context
34
+ self.context.themes.set_window_colors(self)
35
+ self.SetHelpText("templates")
36
+ self.coord_a = None
37
+ self.coord_b = None
38
+ self.coord_c = None
39
+ self.laserposition = None
40
+
41
+ sizer_main = wx.BoxSizer(wx.VERTICAL)
42
+
43
+ self.nbook_lasertools = wx.Notebook(self, wx.ID_ANY)
44
+ self.context.themes.set_window_colors(self.nbook_lasertools)
45
+
46
+ sizer_main.Add(self.nbook_lasertools, 1, wx.EXPAND, 0)
47
+
48
+ # ------------------------ Circle with 3 points
49
+
50
+ self.nb_circle = wx.Panel(self.nbook_lasertools, wx.ID_ANY)
51
+ self.nbook_lasertools.AddPage(self.nb_circle, _("Find center"))
52
+
53
+ self.sizer_circle = wx.BoxSizer(wx.VERTICAL)
54
+
55
+ sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
56
+ self.sizer_circle.Add(sizer_9, 0, wx.EXPAND, 0)
57
+
58
+ sizer_10 = wx.BoxSizer(wx.VERTICAL)
59
+ sizer_9.Add(sizer_10, 0, wx.EXPAND, 0)
60
+
61
+ sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
62
+ sizer_10.Add(sizer_1, 1, wx.EXPAND, 0)
63
+
64
+ label_1 = wxStaticText(self.nb_circle, wx.ID_ANY, _("A"))
65
+ sizer_1.Add(label_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
66
+
67
+ self.btn_set_circle_1 = wxButton(self.nb_circle, wx.ID_ANY, _("Use position"))
68
+ self.btn_set_circle_1.SetToolTip(
69
+ _("Place the laser over the desired point and click...")
70
+ )
71
+ sizer_1.Add(self.btn_set_circle_1, 0, wx.EXPAND, 0)
72
+
73
+ # How big should graphics become?
74
+ desired_height = 6 * self.btn_set_circle_1.Size[1]
75
+
76
+ self.lbl_pos_1 = wxStaticText(self.nb_circle, wx.ID_ANY, _("<empty>"))
77
+ sizer_1.Add(self.lbl_pos_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
78
+
79
+ sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
80
+ sizer_10.Add(sizer_2, 1, wx.EXPAND, 0)
81
+
82
+ label_2 = wxStaticText(self.nb_circle, wx.ID_ANY, _("B"))
83
+ sizer_2.Add(label_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
84
+
85
+ self.btn_set_circle_2 = wxButton(self.nb_circle, wx.ID_ANY, _("Use position"))
86
+ self.btn_set_circle_2.SetToolTip(
87
+ _("Place the laser over the desired point and click...")
88
+ )
89
+ sizer_2.Add(self.btn_set_circle_2, 0, wx.EXPAND, 0)
90
+
91
+ self.lbl_pos_2 = wxStaticText(self.nb_circle, wx.ID_ANY, _("<empty>"))
92
+ sizer_2.Add(self.lbl_pos_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
93
+
94
+ sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
95
+ sizer_10.Add(sizer_3, 1, wx.EXPAND, 0)
96
+
97
+ label_3 = wxStaticText(self.nb_circle, wx.ID_ANY, _("C"))
98
+ sizer_3.Add(label_3, 0, wx.ALIGN_CENTER_VERTICAL, 0)
99
+
100
+ self.btn_set_circle_3 = wxButton(self.nb_circle, wx.ID_ANY, _("Use position"))
101
+ self.btn_set_circle_3.SetToolTip(
102
+ _("Place the laser over the desired point and click...")
103
+ )
104
+ sizer_3.Add(self.btn_set_circle_3, 0, wx.EXPAND, 0)
105
+
106
+ self.lbl_pos_3 = wxStaticText(self.nb_circle, wx.ID_ANY, _("<empty>"))
107
+ sizer_3.Add(self.lbl_pos_3, 0, wx.ALIGN_CENTER_VERTICAL, 0)
108
+
109
+ img_instruction_1 = wxStaticBitmap(
110
+ self.nb_circle,
111
+ wx.ID_ANY,
112
+ self.fitted_bitmap(icon_instruct_circle, desired_height),
113
+ )
114
+ instructions = _(
115
+ "Instruction: place the laser on three points on the circumference of the circle on the bed and confirm the position by clicking on the buttons below.\nMK will find the center for you and place the laser above it or will recreate the circle for further processing."
116
+ )
117
+ img_instruction_1.SetToolTip(instructions)
118
+ sizer_9.Add(img_instruction_1, 1, 0, 0)
119
+
120
+ sizer_chk = wx.BoxSizer(wx.HORIZONTAL)
121
+ self.sizer_circle.Add(sizer_chk, 0, wx.EXPAND, 0)
122
+ self.check_ref_circle = wxCheckBox(
123
+ self.nb_circle, wx.ID_ANY, _("Make reference")
124
+ )
125
+ sizer_chk.Add(self.check_ref_circle, 0, wx.ALIGN_CENTER_VERTICAL, 0)
126
+ self.check_circle = wxCheckBox(self.nb_circle, wx.ID_ANY, _("Mark Center"))
127
+ sizer_chk.Add(self.check_circle, 0, wx.ALIGN_CENTER_VERTICAL, 0)
128
+
129
+ sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
130
+ self.sizer_circle.Add(sizer_4, 0, wx.EXPAND, 0)
131
+
132
+ self.btn_move_to_center = wxButton(
133
+ self.nb_circle, wx.ID_ANY, _("Move to center")
134
+ )
135
+ sizer_4.Add(self.btn_move_to_center, 0, wx.ALIGN_CENTER_VERTICAL, 0)
136
+
137
+ self.btn_create_circle = wxButton(self.nb_circle, wx.ID_ANY, _("Create circle"))
138
+ sizer_4.Add(self.btn_create_circle, 0, wx.EXPAND, 0)
139
+
140
+ # ------------------------ Rectangle with 2 points
141
+
142
+ self.nb_rectangle = wx.Panel(self.nbook_lasertools, wx.ID_ANY)
143
+ self.nbook_lasertools.AddPage(self.nb_rectangle, _("Place frame"))
144
+
145
+ self.sizer_rectangle = wx.BoxSizer(wx.VERTICAL)
146
+
147
+ sizer_rect_hor = wx.BoxSizer(wx.HORIZONTAL)
148
+ self.sizer_rectangle.Add(sizer_rect_hor, 0, wx.EXPAND, 0)
149
+
150
+ sizer_rect_vert = wx.BoxSizer(wx.VERTICAL)
151
+ sizer_rect_hor.Add(sizer_rect_vert, 0, wx.EXPAND, 0)
152
+
153
+ sizer_5a = wx.BoxSizer(wx.HORIZONTAL)
154
+ sizer_rect_vert.Add(sizer_5a, 1, wx.EXPAND, 0)
155
+
156
+ label_corner_1 = wxStaticText(self.nb_rectangle, wx.ID_ANY, _("Corner 1"))
157
+ sizer_5a.Add(label_corner_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
158
+
159
+ self.btn_set_rect_1 = wxButton(self.nb_rectangle, wx.ID_ANY, _("Use position"))
160
+ self.btn_set_rect_1.SetToolTip(
161
+ _("Place the laser over the desired point and click...")
162
+ )
163
+ sizer_5a.Add(self.btn_set_rect_1, 0, wx.EXPAND, 0)
164
+
165
+ self.lbl_pos_7 = wxStaticText(self.nb_rectangle, wx.ID_ANY, _("<empty>"))
166
+ sizer_5a.Add(self.lbl_pos_7, 0, wx.ALIGN_CENTER_VERTICAL, 0)
167
+
168
+ sizer_6a = wx.BoxSizer(wx.HORIZONTAL)
169
+ sizer_rect_vert.Add(sizer_6a, 1, wx.EXPAND, 0)
170
+
171
+ label_corner_2 = wxStaticText(self.nb_rectangle, wx.ID_ANY, _("Corner 2"))
172
+ sizer_6a.Add(label_corner_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
173
+
174
+ self.btn_set_rect_2 = wxButton(self.nb_rectangle, wx.ID_ANY, _("Use position"))
175
+ self.btn_set_rect_2.SetToolTip(
176
+ _("Place the laser over the desired point and click...")
177
+ )
178
+ sizer_6a.Add(self.btn_set_rect_2, 0, wx.EXPAND, 0)
179
+
180
+ self.lbl_pos_8 = wxStaticText(self.nb_rectangle, wx.ID_ANY, _("<empty>"))
181
+ sizer_6a.Add(self.lbl_pos_8, 0, wx.ALIGN_CENTER_VERTICAL, 0)
182
+
183
+ self.img_instruction_2 = wxStaticBitmap(
184
+ self.nb_rectangle,
185
+ wx.ID_ANY,
186
+ self.fitted_bitmap(icon_instruct_rect, desired_height),
187
+ )
188
+ instructions = _(
189
+ "Instruction: place the laser on one corner of the encompassing rectangle and confirm the position by clicking on the buttons below. Then choose the opposing corner.\nMK will create a rectangle for you for further processing."
190
+ )
191
+ self.img_instruction_2.SetToolTip(instructions)
192
+ sizer_rect_hor.Add(self.img_instruction_2, 1, 0, 0)
193
+
194
+ sizer_chk_rect = wx.BoxSizer(wx.HORIZONTAL)
195
+ self.sizer_rectangle.Add(sizer_chk_rect, 0, wx.EXPAND, 0)
196
+ self.check_ref_frame = wxCheckBox(
197
+ self.nb_rectangle, wx.ID_ANY, _("Make reference")
198
+ )
199
+ sizer_chk_rect.Add(self.check_ref_frame, 0, wx.ALIGN_CENTER_VERTICAL, 0)
200
+
201
+ sizer_8a = wx.BoxSizer(wx.HORIZONTAL)
202
+ self.sizer_rectangle.Add(sizer_8a, 0, wx.EXPAND, 0)
203
+
204
+ self.btn_create_frame = wxButton(
205
+ self.nb_rectangle, wx.ID_ANY, _("Create frame")
206
+ )
207
+ sizer_8a.Add(self.btn_create_frame, 0, wx.EXPAND, 0)
208
+
209
+ # ------------------------ Square with 3 points
210
+
211
+ self.nb_square = wx.Panel(self.nbook_lasertools, wx.ID_ANY)
212
+ self.nbook_lasertools.AddPage(self.nb_square, _("Place square"))
213
+
214
+ self.sizer_square = wx.BoxSizer(wx.VERTICAL)
215
+
216
+ sizer_sqare_hor = wx.BoxSizer(wx.HORIZONTAL)
217
+ self.sizer_square.Add(sizer_sqare_hor, 0, wx.EXPAND, 0)
218
+
219
+ sizer_sqare_vert = wx.BoxSizer(wx.VERTICAL)
220
+ sizer_sqare_hor.Add(sizer_sqare_vert, 0, wx.EXPAND, 0)
221
+
222
+ sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
223
+ sizer_sqare_vert.Add(sizer_5, 1, wx.EXPAND, 0)
224
+
225
+ label_4 = wxStaticText(self.nb_square, wx.ID_ANY, _("Side A 1"))
226
+ label_4.SetMinSize(dip_size(self.nb_square, 45, -1))
227
+ sizer_5.Add(label_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
228
+
229
+ self.btn_set_square_1 = wxButton(self.nb_square, wx.ID_ANY, _("Use position"))
230
+ self.btn_set_square_1.SetToolTip(
231
+ _("Place the laser over the desired point and click...")
232
+ )
233
+ sizer_5.Add(self.btn_set_square_1, 0, wx.EXPAND, 0)
234
+
235
+ self.lbl_pos_4 = wxStaticText(self.nb_square, wx.ID_ANY, _("<empty>"))
236
+ sizer_5.Add(self.lbl_pos_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
237
+
238
+ sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
239
+ sizer_sqare_vert.Add(sizer_6, 1, wx.EXPAND, 0)
240
+
241
+ label_5 = wxStaticText(self.nb_square, wx.ID_ANY, _("Side A 2"))
242
+ label_5.SetMinSize(dip_size(self.nb_square, 45, -1))
243
+ sizer_6.Add(label_5, 0, wx.ALIGN_CENTER_VERTICAL, 0)
244
+
245
+ self.btn_set_square_2 = wxButton(self.nb_square, wx.ID_ANY, _("Use position"))
246
+ self.btn_set_square_2.SetToolTip(
247
+ _("Place the laser over the desired point and click...")
248
+ )
249
+ sizer_6.Add(self.btn_set_square_2, 0, wx.EXPAND, 0)
250
+
251
+ self.lbl_pos_5 = wxStaticText(self.nb_square, wx.ID_ANY, _("<empty>"))
252
+ sizer_6.Add(self.lbl_pos_5, 0, wx.ALIGN_CENTER_VERTICAL, 0)
253
+
254
+ sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
255
+ sizer_sqare_vert.Add(sizer_7, 1, wx.EXPAND, 0)
256
+
257
+ label_6 = wxStaticText(self.nb_square, wx.ID_ANY, _("Side B"))
258
+ label_6.SetMinSize(dip_size(self.nb_square, 45, -1))
259
+ sizer_7.Add(label_6, 0, wx.ALIGN_CENTER_VERTICAL, 0)
260
+
261
+ self.btn_set_square_3 = wxButton(self.nb_square, wx.ID_ANY, _("Use position"))
262
+ self.btn_set_square_3.SetToolTip(
263
+ _("Place the laser over the desired point and click...")
264
+ )
265
+ sizer_7.Add(self.btn_set_square_3, 0, wx.EXPAND, 0)
266
+
267
+ self.lbl_pos_6 = wxStaticText(self.nb_square, wx.ID_ANY, _("<empty>"))
268
+ sizer_7.Add(self.lbl_pos_6, 0, wx.ALIGN_CENTER_VERTICAL, 0)
269
+
270
+ size_width = wx.BoxSizer(wx.HORIZONTAL)
271
+ sizer_sqare_vert.Add(size_width, 1, wx.EXPAND, 0)
272
+
273
+ label_wd = wxStaticText(self.nb_square, wx.ID_ANY, _("Dimension"))
274
+ size_width.Add(label_wd, 0, wx.ALIGN_CENTER_VERTICAL, 0)
275
+
276
+ self.txt_width = TextCtrl(self.nb_square, wx.ID_ANY, DEFAULT_LEN)
277
+ self.txt_width.SetToolTip(_("Extension of the square to create"))
278
+ self.txt_width.SetMinSize(dip_size(self.nb_square, 60, -1))
279
+ size_width.Add(self.txt_width, 0, wx.EXPAND, 0)
280
+
281
+ self.img_instruction_3 = wxStaticBitmap(
282
+ self.nb_square,
283
+ wx.ID_ANY,
284
+ self.fitted_bitmap(icon_instruct_square, desired_height),
285
+ )
286
+ instructions = _(
287
+ "Instruction: place the laser on two points of one side of a square on the bed and confirm the position by clicking on the buttons below. Then choose one point on the other side of the corner.\nMK will create a square for you for further processing."
288
+ )
289
+ self.img_instruction_3.SetToolTip(instructions)
290
+ sizer_sqare_hor.Add(self.img_instruction_3, 1, 0, 0)
291
+
292
+ sizer_chk_square = wx.BoxSizer(wx.HORIZONTAL)
293
+ self.sizer_square.Add(sizer_chk_square, 0, wx.EXPAND, 0)
294
+ self.check_ref_square = wxCheckBox(
295
+ self.nb_square, wx.ID_ANY, _("Make reference")
296
+ )
297
+ sizer_chk_square.Add(self.check_ref_square, 0, wx.ALIGN_CENTER_VERTICAL, 0)
298
+ self.check_square = wxCheckBox(self.nb_square, wx.ID_ANY, _("Mark Corner"))
299
+ sizer_chk_square.Add(self.check_square, 0, wx.ALIGN_CENTER_VERTICAL, 0)
300
+
301
+ sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
302
+ self.sizer_square.Add(sizer_8, 0, wx.EXPAND, 0)
303
+
304
+ self.btn_create_square = wxButton(self.nb_square, wx.ID_ANY, _("Create square"))
305
+ sizer_8.Add(self.btn_create_square, 0, wx.EXPAND, 0)
306
+
307
+ self.nb_square.SetSizer(self.sizer_square)
308
+
309
+ self.nb_circle.SetSizer(self.sizer_circle)
310
+
311
+ self.nb_rectangle.SetSizer(self.sizer_rectangle)
312
+
313
+ self.SetSizer(sizer_main)
314
+ sizer_main.Fit(self)
315
+
316
+ self.Layout()
317
+ self.check_input()
318
+ self.btn_set_circle_1.Bind(wx.EVT_BUTTON, self.on_click_get1)
319
+ self.btn_set_circle_2.Bind(wx.EVT_BUTTON, self.on_click_get2)
320
+ self.btn_set_circle_3.Bind(wx.EVT_BUTTON, self.on_click_get3)
321
+ self.btn_move_to_center.Bind(wx.EVT_BUTTON, self.on_btn_move_center)
322
+ self.btn_create_circle.Bind(wx.EVT_BUTTON, self.on_btn_create_circle)
323
+ self.btn_set_rect_1.Bind(wx.EVT_BUTTON, self.on_click_get1)
324
+ self.btn_set_rect_2.Bind(wx.EVT_BUTTON, self.on_click_get2)
325
+ self.btn_create_frame.Bind(wx.EVT_BUTTON, self.on_btn_create_frame)
326
+
327
+ self.btn_set_square_1.Bind(wx.EVT_BUTTON, self.on_click_get1)
328
+ self.btn_set_square_2.Bind(wx.EVT_BUTTON, self.on_click_get2)
329
+ self.btn_set_square_3.Bind(wx.EVT_BUTTON, self.on_click_get3)
330
+ self.txt_width.Bind(wx.EVT_KILL_FOCUS, self.on_text_change)
331
+ self.btn_create_square.Bind(wx.EVT_BUTTON, self.on_btn_create_square)
332
+ # self.img_instruction_3.Bind(wx.EVT_LEFT_DCLICK, self.create_scenario)
333
+ # end wxGlade
334
+
335
+ def fitted_bitmap(self, picture, available_height):
336
+ bmp = picture.GetBitmap()
337
+ bmp_width, bmp_height = bmp.Size
338
+ factor = int(4 * available_height / bmp_height) / 4
339
+ # print(f"Img: {factor}, Available:{available_height} vs ht={bmp_height}")
340
+ if factor > 1:
341
+ bmp_width *= factor
342
+ bmp_height *= factor
343
+ bmp_width *= self.context.root.bitmap_correction_scale
344
+ bmp_height *= self.context.root.bitmap_correction_scale
345
+ return picture.GetBitmap(resize=(bmp_width, bmp_height))
346
+
347
+ # scenario = 8
348
+ #
349
+ # def create_scenario(self, event):
350
+ # event.Skip()
351
+ # self.scenario += 1
352
+ # l1 ="10cm"
353
+ # self.txt_width.SetValue(l1)
354
+ # if self.scenario in (1, 2, 3, 4):
355
+ # c1 = (20 * UNITS_PER_MM, 20 * UNITS_PER_MM)
356
+ # c2 = (50 * UNITS_PER_MM, 20 * UNITS_PER_MM)
357
+ # else:
358
+ # c1 = (20 * UNITS_PER_MM, 20 * UNITS_PER_MM)
359
+ # c2 = (20 * UNITS_PER_MM, 50 * UNITS_PER_MM)
360
+ # if self.scenario in (1, 5):
361
+ # c3 = (10 * UNITS_PER_MM, 70 * UNITS_PER_MM)
362
+ # elif self.scenario in (2, 6):
363
+ # c3 = (10 * UNITS_PER_MM, 0 * UNITS_PER_MM)
364
+ # elif self.scenario in (3, 7):
365
+ # c3 = (70 * UNITS_PER_MM, 70 * UNITS_PER_MM)
366
+ # elif self.scenario in (4, 8):
367
+ # c3 = (70 * UNITS_PER_MM, 0 * UNITS_PER_MM)
368
+
369
+ # if self.scenario == 9:
370
+ # c1 = (20 * UNITS_PER_MM, 20 * UNITS_PER_MM)
371
+ # c2 = (30 * UNITS_PER_MM, 50 * UNITS_PER_MM)
372
+ # c3 = (70 * UNITS_PER_MM, 10 * UNITS_PER_MM)
373
+ # self.set_coord(idx=0, position=c1)
374
+ # self.set_coord(idx=1, position=c2)
375
+ # self.set_coord(idx=2, position=c3)
376
+ # if self.scenario>=9:
377
+ # self.scenario = 0
378
+
379
+ def set_coord(self, idx=0, position=None):
380
+ if position is None:
381
+ label_string = _("<empty>")
382
+ else:
383
+ p = self.context
384
+ units = p.units_name
385
+ label_string = (
386
+ f"({str(Length(amount=position[0], digits=1, preferred_units=units))}, "
387
+ f"{str(Length(amount=position[1], digits=1, preferred_units=units))})"
388
+ )
389
+ if idx == 0:
390
+ self.lbl_pos_1.Label = label_string
391
+ self.lbl_pos_4.Label = label_string
392
+ self.lbl_pos_7.Label = label_string
393
+ self.coord_a = position
394
+ self.check_input()
395
+ elif idx == 1:
396
+ self.lbl_pos_2.Label = label_string
397
+ self.lbl_pos_5.Label = label_string
398
+ self.lbl_pos_8.Label = label_string
399
+ self.coord_b = position
400
+ self.check_input()
401
+ elif idx == 2:
402
+ self.lbl_pos_3.Label = label_string
403
+ self.lbl_pos_6.Label = label_string
404
+ self.coord_c = position
405
+ self.check_input()
406
+ self.sizer_circle.Layout()
407
+ self.sizer_square.Layout()
408
+ self.sizer_rectangle.Layout()
409
+
410
+ def check_input(self):
411
+ if self.coord_a is None or self.coord_b is None or self.coord_c is None:
412
+ value = False
413
+ else:
414
+ value = True
415
+ self.btn_create_circle.Enable(value)
416
+ self.btn_move_to_center.Enable(value)
417
+ self.btn_create_square.Enable(value)
418
+ if self.coord_a is None or self.coord_b is None:
419
+ value = False
420
+ else:
421
+ value = True
422
+ self.btn_create_frame.Enable(value)
423
+
424
+ def on_click_get1(self, event):
425
+ # Current Laserposition
426
+ self.set_coord(idx=0, position=self.laserposition)
427
+
428
+ def on_click_get2(self, event):
429
+ # Current Laserposition
430
+ self.set_coord(idx=1, position=self.laserposition)
431
+ event.Skip()
432
+
433
+ def on_click_get3(self, event):
434
+ # Current Laserposition
435
+ self.set_coord(idx=2, position=self.laserposition)
436
+ event.Skip()
437
+
438
+ def on_text_change(self, event):
439
+ event.Skip()
440
+ try:
441
+ l = Length(self.txt_width.GetValue())
442
+ except (ValueError, AttributeError):
443
+ self.txt_width.SetValue(DEFAULT_LEN)
444
+
445
+ def calculate_center(self):
446
+ """
447
+ Let's recall how the equation of a circle looks like in general form:
448
+ x^2+y^2+2ax+2by+c=0
449
+
450
+ Since all three points should belong to one circle, we can write a system of equations.
451
+
452
+ x_1^2+y_1^2+2ax_1+2by_1+c=0\\x_2^2+y_2^2+2ax_2+2by_2+c=0\\x_3^2+y_3^2+2ax_3+2by_3+c=0
453
+
454
+ The values (x_1, y_1), (x_2, y_2) and (x_3, y_3) are known. Let's rearrange with respect to unknowns a, b and c.
455
+
456
+ 2x_1a+2y_1b+c + x_1^2+y_1^2+=0\\2x_2a+2y_2b+c+x_2^2+y_2^2=0\\2x_3a+2y_3b+c+x_3^2+y_3^2=0
457
+ """
458
+ result = True
459
+ radius = None
460
+ x12 = self.coord_a[0] - self.coord_b[0]
461
+ x13 = self.coord_a[0] - self.coord_c[0]
462
+
463
+ y12 = self.coord_a[1] - self.coord_b[1]
464
+ y13 = self.coord_a[1] - self.coord_c[1]
465
+
466
+ y31 = self.coord_c[1] - self.coord_a[1]
467
+ y21 = self.coord_b[1] - self.coord_a[1]
468
+
469
+ x31 = self.coord_c[0] - self.coord_a[0]
470
+ x21 = self.coord_b[0] - self.coord_a[0]
471
+
472
+ # coord_a[0]^2 - coord_c[0]^2
473
+ sx13 = pow(self.coord_a[0], 2) - pow(self.coord_c[0], 2)
474
+
475
+ # self.coord_a[1]^2 - self.coord_c[1]^2
476
+ sy13 = pow(self.coord_a[1], 2) - pow(self.coord_c[1], 2)
477
+
478
+ sx21 = pow(self.coord_b[0], 2) - pow(self.coord_a[0], 2)
479
+ sy21 = pow(self.coord_b[1], 2) - pow(self.coord_a[1], 2)
480
+ try:
481
+ f = (sx13 * x12 + sy13 * x12 + sx21 * x13 + sy21 * x13) // (
482
+ 2 * (y31 * x12 - y21 * x13)
483
+ )
484
+
485
+ g = (sx13 * y12 + sy13 * y12 + sx21 * y13 + sy21 * y13) // (
486
+ 2 * (x31 * y12 - x21 * y13)
487
+ )
488
+ except (ZeroDivisionError, ArithmeticError):
489
+ return False, None, None
490
+
491
+ c = (
492
+ -pow(self.coord_a[0], 2)
493
+ - pow(self.coord_a[1], 2)
494
+ - 2 * g * self.coord_a[0]
495
+ - 2 * f * self.coord_a[1]
496
+ )
497
+
498
+ # eqn of circle be x^2 + y^2 + 2*g*x + 2*f*y + c = 0
499
+ # where centre is (h = -g, k = -f) and
500
+ # radius r as r^2 = h^2 + k^2 - c
501
+ h = -g
502
+ k = -f
503
+ sqr_of_r = h * h + k * k - c
504
+
505
+ # r is the radius
506
+ if sqr_of_r < 0:
507
+ result = False
508
+ else:
509
+ radius = round(sqrt(sqr_of_r), 5)
510
+
511
+ # print("Centre = (", h, ", ", k, ")")
512
+ # print("Radius = ", r)
513
+ center = (h, k)
514
+ return result, center, radius
515
+
516
+ def calculate_square(self):
517
+ result = True
518
+ angle = 0
519
+ signx = 1
520
+ signy = 1
521
+ # equation for the first line through (x1, y1)-(x2, y2)
522
+ # y = a1 * x + b1
523
+ dx1 = self.coord_a[0] - self.coord_b[0]
524
+ dy1 = self.coord_a[1] - self.coord_b[1]
525
+ if dx1 == 0 and dy1 == 0:
526
+ result = False
527
+ if self.coord_a == self.coord_b:
528
+ result = False
529
+ if self.coord_a == self.coord_c:
530
+ result = False
531
+ if self.coord_b == self.coord_c:
532
+ result = False
533
+
534
+ if dx1 == 0:
535
+ a1 = float("inf")
536
+ b1 = 0
537
+ else:
538
+ a1 = dy1 / dx1
539
+ b1 = self.coord_a[1] - self.coord_a[0] * a1
540
+
541
+ if dx1 == 0:
542
+ center = (self.coord_a[0], self.coord_c[1])
543
+ elif dy1 == 0:
544
+ center = (self.coord_c[0], self.coord_a[1])
545
+ else:
546
+ # regular line
547
+ # line 1
548
+ # y = a1 * x + b1
549
+ # orthogonal line
550
+ a2 = -1 / a1
551
+ b2 = self.coord_c[1] - self.coord_c[0] * a2
552
+
553
+ x0 = (b2 - b1) / (a1 - a2)
554
+ y0 = a1 * x0 + b1
555
+ center = (x0, y0)
556
+ dx1 = 0
557
+ dy1 = 0
558
+ angle = atan(a1)
559
+
560
+ mid_a_x = (self.coord_a[0] + self.coord_b[0]) / 2
561
+ mid_a_y = (self.coord_a[1] + self.coord_b[1]) / 2
562
+ if abs(dx1) < abs(dy1): # A is a 'vertical' line
563
+ if mid_a_y < center[1]:
564
+ if self.coord_c[0] >= center[0]:
565
+ segment = 4
566
+ else:
567
+ segment = 3
568
+ else:
569
+ if self.coord_c[0] >= center[0]:
570
+ segment = 1
571
+ else:
572
+ segment = 2
573
+ else: # Horizontal line
574
+ if mid_a_x < center[0]:
575
+ if self.coord_c[1] >= center[1]:
576
+ segment = 2
577
+ else:
578
+ segment = 3
579
+ else:
580
+ if self.coord_c[1] >= center[1]:
581
+ segment = 1
582
+ else:
583
+ segment = 4
584
+ if segment == 1:
585
+ signx = +1
586
+ signy = +1
587
+ elif segment == 2:
588
+ signx = -1
589
+ signy = +1
590
+ elif segment == 3:
591
+ signx = -1
592
+ signy = -1
593
+ elif segment == 4:
594
+ signx = +1
595
+ signy = -1
596
+
597
+ # print (center, angle / tau * 360)
598
+ return result, center, angle, signx, signy
599
+
600
+ def calculate_frame(self):
601
+ result = False
602
+ left_top = (0, 0)
603
+ width = 0
604
+ height = 0
605
+ if self.coord_a is not None and self.coord_b is not None:
606
+ x0 = self.coord_a[0]
607
+ x1 = self.coord_b[0]
608
+ y0 = self.coord_a[1]
609
+ y1 = self.coord_b[1]
610
+ width = abs(x0 - x1)
611
+ height = abs(y0 - y1)
612
+ xx = min(x0, x1)
613
+ yy = min(y0, y1)
614
+ if width != 0 and height != 0:
615
+ left_top = (xx, yy)
616
+ result = True
617
+ return result, left_top, width, height
618
+
619
+ def on_btn_move_center(self, event): # wxGlade: clsLasertools.<event_handler>
620
+ result, center, radius = self.calculate_center()
621
+ if result:
622
+ p = self.context
623
+ units = p.units_name
624
+ cx = float(Length(amount=center[0], digits=5, preferred_units=units))
625
+ cy = float(Length(amount=center[1], digits=5, preferred_units=units))
626
+ if self.context.elements.classify_new:
627
+ option = " classify"
628
+ postsignal = "tree_changed"
629
+ else:
630
+ option = ""
631
+ postsignal = ""
632
+ if self.check_circle.GetValue():
633
+ self.context(
634
+ f"circle "
635
+ f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
636
+ f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
637
+ f"1mm stroke blue{option}\n"
638
+ )
639
+ if postsignal != "":
640
+ self.context.signal(postsignal)
641
+ if (
642
+ cx < 0
643
+ or cy < 0
644
+ or cx > self.context.device.view.unit_width
645
+ or cy > self.context.device.view.unit_height
646
+ ):
647
+ message = (
648
+ _("The circles center seems to lie outside the bed-dimensions!")
649
+ + "\n"
650
+ )
651
+ message += (
652
+ _("If you continue to move to the center, then the laserhead might")
653
+ + "\n"
654
+ )
655
+ message += _(
656
+ "slam into the walls and get damaged! Do you really want to proceed?"
657
+ )
658
+ caption = _("Dangerous coordinates")
659
+ dlg = wx.MessageDialog(
660
+ self,
661
+ message,
662
+ caption,
663
+ wx.YES_NO | wx.ICON_WARNING,
664
+ )
665
+ dlgresult = dlg.ShowModal()
666
+ dlg.Destroy()
667
+ if dlgresult != wx.ID_YES:
668
+ return
669
+ self.context(
670
+ f"move_absolute "
671
+ f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
672
+ f"{str(Length(amount=center[1], digits=5, preferred_units=units))}\n"
673
+ )
674
+
675
+ def on_btn_create_circle(self, event): # wxGlade: clsLasertools.<event_handler>
676
+ result, center, radius = self.calculate_center()
677
+ if result:
678
+ p = self.context
679
+ units = p.units_name
680
+ if self.context.elements.classify_new:
681
+ option = " classify"
682
+ postsignal = "tree_changed"
683
+ else:
684
+ option = ""
685
+ postsignal = ""
686
+ if self.check_circle.GetValue():
687
+ self.context(
688
+ f"circle "
689
+ f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
690
+ f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
691
+ f"1mm stroke blue{option}\n"
692
+ )
693
+ self.context(
694
+ f"circle "
695
+ f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
696
+ f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
697
+ f"{str(Length(amount=radius, digits=5, preferred_units=units))}{option}\n"
698
+ )
699
+ if self.check_ref_circle.GetValue():
700
+ self.context("reference\n")
701
+ if postsignal != "":
702
+ self.context.signal(postsignal)
703
+ event.Skip()
704
+
705
+ def on_btn_create_frame(self, event): # wxGlade: clsLasertools.<event_handler>
706
+ result, left_top, width, height = self.calculate_frame()
707
+
708
+ if result:
709
+ p = self.context
710
+ units = p.units_name
711
+ if self.context.elements.classify_new:
712
+ option = " classify"
713
+ postsignal = "tree_changed"
714
+ else:
715
+ option = ""
716
+ postsignal = ""
717
+
718
+ self.context(
719
+ f"rect "
720
+ f"{str(Length(amount=left_top[0], digits=5, preferred_units=units))} "
721
+ f"{str(Length(amount=left_top[1], digits=5, preferred_units=units))} "
722
+ f"{str(Length(amount=width, digits=5, preferred_units=units))} "
723
+ f"{str(Length(amount=height, digits=5, preferred_units=units))}"
724
+ f"{option}\n"
725
+ )
726
+ if self.check_ref_frame.GetValue():
727
+ self.context("reference\n")
728
+ if postsignal != "":
729
+ self.context.signal(postsignal)
730
+ event.Skip()
731
+
732
+ def on_btn_create_square(self, event): # wxGlade: clsLasertools.<event_handler>
733
+ try:
734
+ dim_x = Length(self.txt_width.GetValue())
735
+ dim_y = Length(self.txt_width.GetValue())
736
+ except ValueError:
737
+ dim_x = Length(DEFAULT_LEN)
738
+ dim_y = Length(DEFAULT_LEN)
739
+ result, center, angle, signx, signy = self.calculate_square()
740
+ dim_x *= signx
741
+ dim_y *= signy
742
+ angle = angle * 360 / tau
743
+ if result:
744
+ p = self.context
745
+ units = p.units_name
746
+
747
+ # self.context("circle {x}mm {y}mm 2mm stroke green".format(x=round(self.coord_a[0]/UNITS_PER_MM,2),y=round(self.coord_a[1]/UNITS_PER_MM,2)) )
748
+ # self.context("circle {x}mm {y}mm 2mm stroke green".format(x=round(self.coord_b[0]/UNITS_PER_MM,2),y=round(self.coord_b[1]/UNITS_PER_MM,2)) )
749
+ # self.context("circle {x}mm {y}mm 2mm stroke red".format(x=round(self.coord_c[0]/UNITS_PER_MM,2),y=round(self.coord_c[1]/UNITS_PER_MM,2)) )
750
+
751
+ if self.check_square.GetValue():
752
+ self.context(
753
+ f"circle "
754
+ f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
755
+ f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
756
+ f"1mm stroke black\n"
757
+ )
758
+ self.context(
759
+ f"rect "
760
+ f"{str(Length(amount=center[0], digits=5, preferred_units=units))} "
761
+ f"{str(Length(amount=center[1], digits=5, preferred_units=units))} "
762
+ f"{str(dim_x.length_mm)} "
763
+ f"{str(dim_y.length_mm)} "
764
+ f"rotate {angle}deg "
765
+ f"-x {str(Length(amount=center[0], digits=5, preferred_units=units))} "
766
+ f"-y {str(Length(amount=center[1], digits=5, preferred_units=units))}\n"
767
+ )
768
+ if self.check_ref_square.GetValue():
769
+ self.context("reference\n")
770
+ event.Skip()
771
+
772
+ @signal_listener("driver;position")
773
+ @signal_listener("emulator;position")
774
+ @signal_listener("status;position")
775
+ def on_update_laser(self, origin, pos):
776
+ self.laserposition = (pos[2], pos[3])
777
+
778
+
779
+ class LaserTool(MWindow):
780
+ def __init__(self, *args, **kwds):
781
+ super().__init__(551, 234, submenu="Operations", *args, **kwds)
782
+ self.panel = LaserToolPanel(self, wx.ID_ANY, context=self.context)
783
+ self.sizer.Add(self.panel, 1, wx.EXPAND, 0)
784
+ _icon = wx.NullIcon
785
+ # _icon.CopyFromBitmap(icons8_computer_support.GetBitmap())
786
+ self.SetIcon(_icon)
787
+ self.SetTitle(_("Place Template"))
788
+ self.restore_aspect()
789
+
790
+ def window_open(self):
791
+ pass
792
+
793
+ def window_close(self):
794
+ pass
795
+
796
+ def delegates(self):
797
+ yield self.panel
798
+
799
+ @staticmethod
800
+ def submenu():
801
+ return "Laser-Tools", "Place Template"
802
+
803
+ @staticmethod
804
+ def helptext():
805
+ return _("Define and use some templates for repetitive laser jobs")