@fmsim/machine 0.0.49

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 (274) hide show
  1. package/dist/agv-line.js +48 -0
  2. package/dist/agv-line.js.map +1 -0
  3. package/dist/agv.js +43 -0
  4. package/dist/agv.js.map +1 -0
  5. package/dist/buffer.js +40 -0
  6. package/dist/buffer.js.map +1 -0
  7. package/dist/conveyor-join.js +169 -0
  8. package/dist/conveyor-join.js.map +1 -0
  9. package/dist/conveyor.js +84 -0
  10. package/dist/conveyor.js.map +1 -0
  11. package/dist/crane.js +55 -0
  12. package/dist/crane.js.map +1 -0
  13. package/dist/data-subscription.js +126 -0
  14. package/dist/data-subscription.js.map +1 -0
  15. package/dist/editors/index.js +2 -0
  16. package/dist/editors/index.js.map +1 -0
  17. package/dist/equipment.js +18 -0
  18. package/dist/equipment.js.map +1 -0
  19. package/dist/features/client-api.js +45 -0
  20. package/dist/features/client-api.js.map +1 -0
  21. package/dist/features/conveyor-mixin.js +54 -0
  22. package/dist/features/conveyor-mixin.js.map +1 -0
  23. package/dist/features/mcs-event-handler-mixin.js +65 -0
  24. package/dist/features/mcs-event-handler-mixin.js.map +1 -0
  25. package/dist/features/mcs-status-default.js +67 -0
  26. package/dist/features/mcs-status-default.js.map +1 -0
  27. package/dist/features/mcs-status-mixin.js +39 -0
  28. package/dist/features/mcs-status-mixin.js.map +1 -0
  29. package/dist/features/mcs-transport-mixin.js +39 -0
  30. package/dist/features/mcs-transport-mixin.js.map +1 -0
  31. package/dist/features/mcs-zone-mixin.js +18 -0
  32. package/dist/features/mcs-zone-mixin.js.map +1 -0
  33. package/dist/groups/index.js +10 -0
  34. package/dist/groups/index.js.map +1 -0
  35. package/dist/groups/mcs-acs.js +24 -0
  36. package/dist/groups/mcs-acs.js.map +1 -0
  37. package/dist/groups/mcs-bcs.js +27 -0
  38. package/dist/groups/mcs-bcs.js.map +1 -0
  39. package/dist/groups/mcs-ccs.js +25 -0
  40. package/dist/groups/mcs-ccs.js.map +1 -0
  41. package/dist/groups/mcs-ecs.js +23 -0
  42. package/dist/groups/mcs-ecs.js.map +1 -0
  43. package/dist/groups/mcs-ocs.js +25 -0
  44. package/dist/groups/mcs-ocs.js.map +1 -0
  45. package/dist/groups/mcs-path.js +28 -0
  46. package/dist/groups/mcs-path.js.map +1 -0
  47. package/dist/groups/mcs-scs.js +26 -0
  48. package/dist/groups/mcs-scs.js.map +1 -0
  49. package/dist/groups/mcs-shape.js +26 -0
  50. package/dist/groups/mcs-shape.js.map +1 -0
  51. package/dist/index.js +25 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/mcs-carrier-holder.js +107 -0
  54. package/dist/mcs-carrier-holder.js.map +1 -0
  55. package/dist/mcs-gauge-capacity-bar.js +170 -0
  56. package/dist/mcs-gauge-capacity-bar.js.map +1 -0
  57. package/dist/mcs-gauge-capacity-circle.js +91 -0
  58. package/dist/mcs-gauge-capacity-circle.js.map +1 -0
  59. package/dist/mcs-machine.js +84 -0
  60. package/dist/mcs-machine.js.map +1 -0
  61. package/dist/mcs-popup.js +82 -0
  62. package/dist/mcs-popup.js.map +1 -0
  63. package/dist/mcs-transport.js +18 -0
  64. package/dist/mcs-transport.js.map +1 -0
  65. package/dist/mcs-unit.js +78 -0
  66. package/dist/mcs-unit.js.map +1 -0
  67. package/dist/mcs-vehicle.js +69 -0
  68. package/dist/mcs-vehicle.js.map +1 -0
  69. package/dist/mcs-zone-unit.js +11 -0
  70. package/dist/mcs-zone-unit.js.map +1 -0
  71. package/dist/oht-line.js +32 -0
  72. package/dist/oht-line.js.map +1 -0
  73. package/dist/oht.js +42 -0
  74. package/dist/oht.js.map +1 -0
  75. package/dist/port.js +32 -0
  76. package/dist/port.js.map +1 -0
  77. package/dist/rtv-rail.js +36 -0
  78. package/dist/rtv-rail.js.map +1 -0
  79. package/dist/shelf.js +41 -0
  80. package/dist/shelf.js.map +1 -0
  81. package/dist/shuttle.js +49 -0
  82. package/dist/shuttle.js.map +1 -0
  83. package/dist/stocker-capacity-bar.js +171 -0
  84. package/dist/stocker-capacity-bar.js.map +1 -0
  85. package/dist/stocker.js +36 -0
  86. package/dist/stocker.js.map +1 -0
  87. package/dist/templates/agv-line-corner.js +34 -0
  88. package/dist/templates/agv-line-corner.js.map +1 -0
  89. package/dist/templates/agv-line-cross.js +34 -0
  90. package/dist/templates/agv-line-cross.js.map +1 -0
  91. package/dist/templates/agv-line-horizontal.js +34 -0
  92. package/dist/templates/agv-line-horizontal.js.map +1 -0
  93. package/dist/templates/agv-line-vertical.js +34 -0
  94. package/dist/templates/agv-line-vertical.js.map +1 -0
  95. package/dist/templates/agv-line.js +15 -0
  96. package/dist/templates/agv-line.js.map +1 -0
  97. package/dist/templates/agv.js +15 -0
  98. package/dist/templates/agv.js.map +1 -0
  99. package/dist/templates/buffer.js +15 -0
  100. package/dist/templates/buffer.js.map +1 -0
  101. package/dist/templates/conveyor-corner.js +33 -0
  102. package/dist/templates/conveyor-corner.js.map +1 -0
  103. package/dist/templates/conveyor-join.js +21 -0
  104. package/dist/templates/conveyor-join.js.map +1 -0
  105. package/dist/templates/conveyor-left.js +33 -0
  106. package/dist/templates/conveyor-left.js.map +1 -0
  107. package/dist/templates/conveyor-middle.js +33 -0
  108. package/dist/templates/conveyor-middle.js.map +1 -0
  109. package/dist/templates/conveyor-right.js +33 -0
  110. package/dist/templates/conveyor-right.js.map +1 -0
  111. package/dist/templates/conveyor.js +18 -0
  112. package/dist/templates/conveyor.js.map +1 -0
  113. package/dist/templates/crane.js +15 -0
  114. package/dist/templates/crane.js.map +1 -0
  115. package/dist/templates/data-subscription.js +16 -0
  116. package/dist/templates/data-subscription.js.map +1 -0
  117. package/dist/templates/equipment.js +15 -0
  118. package/dist/templates/equipment.js.map +1 -0
  119. package/dist/templates/index.js +35 -0
  120. package/dist/templates/index.js.map +1 -0
  121. package/dist/templates/mcs-gauge-capacity-bar.js +18 -0
  122. package/dist/templates/mcs-gauge-capacity-bar.js.map +1 -0
  123. package/dist/templates/mcs-gauge-capacity-circle.js +18 -0
  124. package/dist/templates/mcs-gauge-capacity-circle.js.map +1 -0
  125. package/dist/templates/oht-line-corner.js +34 -0
  126. package/dist/templates/oht-line-corner.js.map +1 -0
  127. package/dist/templates/oht-line-cross.js +34 -0
  128. package/dist/templates/oht-line-cross.js.map +1 -0
  129. package/dist/templates/oht-line-horizontal.js +34 -0
  130. package/dist/templates/oht-line-horizontal.js.map +1 -0
  131. package/dist/templates/oht-line-vertical.js +34 -0
  132. package/dist/templates/oht-line-vertical.js.map +1 -0
  133. package/dist/templates/oht-line.js +15 -0
  134. package/dist/templates/oht-line.js.map +1 -0
  135. package/dist/templates/oht.js +15 -0
  136. package/dist/templates/oht.js.map +1 -0
  137. package/dist/templates/port.js +15 -0
  138. package/dist/templates/port.js.map +1 -0
  139. package/dist/templates/rtv-corner.js +33 -0
  140. package/dist/templates/rtv-corner.js.map +1 -0
  141. package/dist/templates/rtv-left.js +33 -0
  142. package/dist/templates/rtv-left.js.map +1 -0
  143. package/dist/templates/rtv-middle.js +33 -0
  144. package/dist/templates/rtv-middle.js.map +1 -0
  145. package/dist/templates/rtv-rail.js +15 -0
  146. package/dist/templates/rtv-rail.js.map +1 -0
  147. package/dist/templates/rtv-right.js +33 -0
  148. package/dist/templates/rtv-right.js.map +1 -0
  149. package/dist/templates/rtv.js +15 -0
  150. package/dist/templates/rtv.js.map +1 -0
  151. package/dist/templates/shelf.js +15 -0
  152. package/dist/templates/shelf.js.map +1 -0
  153. package/dist/templates/shuttle.js +15 -0
  154. package/dist/templates/shuttle.js.map +1 -0
  155. package/dist/templates/stocker-capacity-bar.js +18 -0
  156. package/dist/templates/stocker-capacity-bar.js.map +1 -0
  157. package/dist/templates/stocker-capacity-circle.js +18 -0
  158. package/dist/templates/stocker-capacity-circle.js.map +1 -0
  159. package/dist/templates/stocker.js +16 -0
  160. package/dist/templates/stocker.js.map +1 -0
  161. package/dist/templates/zone-capacity-bar.js +19 -0
  162. package/dist/templates/zone-capacity-bar.js.map +1 -0
  163. package/dist/tsconfig.tsbuildinfo +1 -0
  164. package/dist/utils/get-locale.js +19 -0
  165. package/dist/utils/get-locale.js.map +1 -0
  166. package/dist/utils/get-value-on-ranges.js +23 -0
  167. package/dist/utils/get-value-on-ranges.js.map +1 -0
  168. package/dist/utils/normalize-angle.js +11 -0
  169. package/dist/utils/normalize-angle.js.map +1 -0
  170. package/dist/utils/safe-round.js +9 -0
  171. package/dist/utils/safe-round.js.map +1 -0
  172. package/dist/zone-capacity-bar.js +162 -0
  173. package/dist/zone-capacity-bar.js.map +1 -0
  174. package/icons/agv-line.png +0 -0
  175. package/icons/agv.png +0 -0
  176. package/icons/buffer.png +0 -0
  177. package/icons/conveyor-corner.png +0 -0
  178. package/icons/conveyor-corner.svg +10 -0
  179. package/icons/conveyor-join.png +0 -0
  180. package/icons/conveyor-left.png +0 -0
  181. package/icons/conveyor-left.svg +6 -0
  182. package/icons/conveyor-middle.png +0 -0
  183. package/icons/conveyor-middle.svg +5 -0
  184. package/icons/conveyor-right.png +0 -0
  185. package/icons/conveyor-right.svg +6 -0
  186. package/icons/conveyor.png +0 -0
  187. package/icons/crane.png +0 -0
  188. package/icons/equipment.png +0 -0
  189. package/icons/icon-data-subscription.png +0 -0
  190. package/icons/oht-line.png +0 -0
  191. package/icons/oht.png +0 -0
  192. package/icons/pallet-empty.svg +3 -0
  193. package/icons/pallet.svg +11 -0
  194. package/icons/path-position.svg +5 -0
  195. package/icons/port.png +0 -0
  196. package/icons/process.png +0 -0
  197. package/icons/rtv-rail.png +0 -0
  198. package/icons/rtv.png +0 -0
  199. package/icons/shelf.png +0 -0
  200. package/icons/shuttle.png +0 -0
  201. package/icons/stocker-capacity-bar.png +0 -0
  202. package/icons/stocker-capacity-circle.png +0 -0
  203. package/icons/stocker.png +0 -0
  204. package/icons/symbol-data-subscription.png +0 -0
  205. package/icons/vehicle.png +0 -0
  206. package/icons/zone-capacity-bar.png +0 -0
  207. package/migration-samples/model.json +7964 -0
  208. package/package.json +59 -0
  209. package/src/agv-line.ts +59 -0
  210. package/src/agv.ts +56 -0
  211. package/src/buffer.ts +50 -0
  212. package/src/conveyor-join.ts +208 -0
  213. package/src/conveyor.ts +101 -0
  214. package/src/crane.ts +72 -0
  215. package/src/data-subscription.ts +150 -0
  216. package/src/editors/index.ts +0 -0
  217. package/src/equipment.ts +21 -0
  218. package/src/features/client-api.ts +52 -0
  219. package/src/features/conveyor-mixin.ts +75 -0
  220. package/src/features/mcs-status-default.ts +76 -0
  221. package/src/features/mcs-status-mixin.ts +53 -0
  222. package/src/features/mcs-zone-mixin.ts +23 -0
  223. package/src/groups/index.ts +10 -0
  224. package/src/groups/mcs-acs.ts +24 -0
  225. package/src/groups/mcs-bcs.ts +27 -0
  226. package/src/groups/mcs-ccs.ts +25 -0
  227. package/src/groups/mcs-ecs.ts +23 -0
  228. package/src/groups/mcs-ocs.ts +25 -0
  229. package/src/groups/mcs-path.ts +28 -0
  230. package/src/groups/mcs-scs.ts +26 -0
  231. package/src/groups/mcs-shape.ts +26 -0
  232. package/src/index.ts +29 -0
  233. package/src/mcs-carrier-holder.ts +141 -0
  234. package/src/mcs-gauge-capacity-circle.ts +113 -0
  235. package/src/mcs-machine.ts +101 -0
  236. package/src/mcs-popup.ts +99 -0
  237. package/src/mcs-transport.ts +20 -0
  238. package/src/mcs-unit.ts +91 -0
  239. package/src/mcs-vehicle.ts +79 -0
  240. package/src/oht-line.ts +43 -0
  241. package/src/oht.ts +55 -0
  242. package/src/port.ts +41 -0
  243. package/src/shelf.ts +53 -0
  244. package/src/shuttle.ts +65 -0
  245. package/src/stocker-capacity-bar.ts +220 -0
  246. package/src/stocker.ts +45 -0
  247. package/src/templates/agv-line.ts +15 -0
  248. package/src/templates/agv.ts +15 -0
  249. package/src/templates/buffer.ts +15 -0
  250. package/src/templates/conveyor.ts +18 -0
  251. package/src/templates/crane.ts +15 -0
  252. package/src/templates/data-subscription.js +16 -0
  253. package/src/templates/equipment.ts +15 -0
  254. package/src/templates/index.ts +43 -0
  255. package/src/templates/oht-line.ts +15 -0
  256. package/src/templates/oht.ts +15 -0
  257. package/src/templates/port.ts +15 -0
  258. package/src/templates/shelf.ts +15 -0
  259. package/src/templates/shuttle.ts +15 -0
  260. package/src/templates/stocker-capacity-bar.ts +18 -0
  261. package/src/templates/stocker-capacity-circle.ts +18 -0
  262. package/src/templates/stocker.ts +16 -0
  263. package/src/templates/zone-capacity-bar.ts +19 -0
  264. package/src/utils/get-locale.ts +22 -0
  265. package/src/utils/get-value-on-ranges.ts +25 -0
  266. package/src/utils/normalize-angle.ts +9 -0
  267. package/src/utils/safe-round.ts +8 -0
  268. package/src/zone-capacity-bar.ts +209 -0
  269. package/things-scene.config.js +7 -0
  270. package/translations/en.json +7 -0
  271. package/translations/ja.json +7 -0
  272. package/translations/ko.json +7 -0
  273. package/translations/ms.json +7 -0
  274. package/translations/zh.json +7 -0
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@fmsim/machine",
3
+ "description": "Layout View를 구성하는 설비(machine)들과 유닛을 구현한 모듈입니다.",
4
+ "author": "heartyoh",
5
+ "version": "0.0.49",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "things-scene": true,
9
+ "publishConfig": {
10
+ "access": "public",
11
+ "@fmsim:registry": "https://registry.npmjs.org"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/heartyoh/fmsim.git",
16
+ "directory": "packages/machine"
17
+ },
18
+ "scripts": {
19
+ "serve": "tsc && things-factory-dev",
20
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
21
+ "build": "tsc",
22
+ "prepublish": "tsc",
23
+ "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
24
+ "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
25
+ "migration": "things-factory-migration"
26
+ },
27
+ "dependencies": {
28
+ "@hatiolab/things-scene": "^3.2.0",
29
+ "subscriptions-transport-ws": "^0.11.0"
30
+ },
31
+ "devDependencies": {
32
+ "@hatiolab/prettier-config": "^1.0.0",
33
+ "@things-factory/builder": "^6.0.0",
34
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
35
+ "@typescript-eslint/parser": "^4.33.0",
36
+ "@web/dev-server": "^0.2.1",
37
+ "concurrently": "^8.0.1",
38
+ "eslint": "^8.39.0",
39
+ "eslint-config-prettier": "^8.3.0",
40
+ "husky": "^8.0.3",
41
+ "lint-staged": "^13.2.2",
42
+ "prettier": "^2.4.1",
43
+ "tslib": "^2.3.1",
44
+ "typescript": "^5.0.4"
45
+ },
46
+ "prettier": "@hatiolab/prettier-config",
47
+ "husky": {
48
+ "hooks": {
49
+ "pre-commit": "lint-staged"
50
+ }
51
+ },
52
+ "lint-staged": {
53
+ "*.ts": [
54
+ "eslint --fix",
55
+ "prettier --write"
56
+ ]
57
+ },
58
+ "gitHead": "59b7cd248a3b0e637d4e124a28829441c4b258b2"
59
+ }
@@ -0,0 +1,59 @@
1
+ import { Component, ComponentNature } from '@hatiolab/things-scene'
2
+ import MCSTransport from './mcs-transport'
3
+
4
+ const NATURE: ComponentNature = {
5
+ mutable: false,
6
+ resizable: true,
7
+ rotatable: true,
8
+ properties: [...MCSTransport.properties]
9
+ }
10
+
11
+ export default class AGVLine extends MCSTransport {
12
+ static get nature() {
13
+ return NATURE
14
+ }
15
+
16
+ containable(component: Component) {
17
+ return ['AGV'].includes(component.state.type)
18
+ }
19
+
20
+ get auxColor() {
21
+ return '#333'
22
+ }
23
+
24
+ render(context: CanvasRenderingContext2D) {
25
+ const { left, top, width, height } = this.bounds
26
+
27
+ context.beginPath()
28
+
29
+ context.translate(left, top)
30
+
31
+ context.fillStyle = this.statusColor!
32
+ context.strokeStyle = this.auxColor!
33
+ context.setLineDash([3])
34
+
35
+ context.fillRect(0, 0, width, height)
36
+
37
+ if (width > height) {
38
+ context.moveTo(0, 0)
39
+ context.lineTo(width, 0)
40
+ // context.moveTo(0, height / 2)
41
+ // context.lineTo(width, height / 2)
42
+ context.moveTo(0, height)
43
+ context.lineTo(width, height)
44
+ } else {
45
+ context.moveTo(0, 0)
46
+ context.lineTo(0, height)
47
+ // context.moveTo(width / 2, 0)
48
+ // context.lineTo(width / 2, height)
49
+ context.moveTo(width, 0)
50
+ context.lineTo(width, height)
51
+ }
52
+
53
+ context.stroke()
54
+
55
+ context.translate(-left, -top)
56
+ }
57
+ }
58
+
59
+ Component.register('AGVLine', AGVLine)
package/src/agv.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { Component, ComponentNature, Properties } from '@hatiolab/things-scene'
2
+ import MCSVehicle from './mcs-vehicle'
3
+
4
+ const NATURE: ComponentNature = {
5
+ mutable: false,
6
+ resizable: true,
7
+ rotatable: true,
8
+ properties: [...MCSVehicle.properties]
9
+ }
10
+
11
+ const GAP = 2
12
+ export default class AGV extends MCSVehicle {
13
+ static get nature() {
14
+ return NATURE
15
+ }
16
+
17
+ get auxColor() {
18
+ return 'black'
19
+ }
20
+
21
+ render(ctx: CanvasRenderingContext2D) {
22
+ var { left, top, width, height } = this.bounds
23
+
24
+ ctx.translate(left, top)
25
+ ctx.beginPath()
26
+
27
+ ctx.strokeStyle = this.auxColor
28
+ ctx.fillStyle = this.statusColor!
29
+ ctx.lineWidth = 1
30
+ ctx.lineCap = 'round'
31
+ ctx.setLineDash([])
32
+
33
+ const radius = Math.round(Math.min(width, height) * 0.1)
34
+ ctx.roundRect(1, 0, width - 2, height, radius)
35
+ ctx.roundRect(GAP + 1, GAP, width - (GAP + 1) * 2, height - GAP * 2, radius - 1)
36
+
37
+ ctx.fill()
38
+ ctx.stroke()
39
+
40
+ ctx.beginPath()
41
+
42
+ // draw wheel metapore
43
+ ctx.strokeStyle = 'black'
44
+
45
+ ctx.moveTo(0, (height * 1) / 3)
46
+ ctx.lineTo(0, (height * 2) / 3)
47
+ ctx.moveTo(width, (height * 1) / 3)
48
+ ctx.lineTo(width, (height * 2) / 3)
49
+
50
+ ctx.stroke()
51
+
52
+ ctx.translate(-left, -top)
53
+ }
54
+ }
55
+
56
+ Component.register('AGV', AGV)
package/src/buffer.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { Component, ComponentNature } from '@hatiolab/things-scene'
2
+ import MCSMachine from './mcs-machine'
3
+
4
+ const NATURE: ComponentNature = {
5
+ mutable: false,
6
+ resizable: true,
7
+ rotatable: true,
8
+ properties: [...MCSMachine.properties]
9
+ }
10
+
11
+ export default class Buffer extends MCSMachine {
12
+ static get nature() {
13
+ return NATURE
14
+ }
15
+
16
+ containable(component: Component) {
17
+ return super.containable(component) || ['Port'].includes(component.state.type)
18
+ }
19
+
20
+ render(ctx) {
21
+ var { lineWidth } = this.state
22
+ var { left, top, width, height } = this.bounds
23
+
24
+ const offset = Math.round(Math.min(width, height) * 0.2)
25
+
26
+ ctx.beginPath()
27
+ ctx.translate(left, top)
28
+
29
+ ctx.strokeStyle = this.auxColor
30
+ ctx.fillStyle = this.statusColor!
31
+ ctx.lineWidth = lineWidth || 1
32
+ ctx.lineCap = 'round'
33
+ ctx.setLineDash([])
34
+
35
+ ctx.moveTo(offset, 0)
36
+ ctx.lineTo(width - offset, 0)
37
+ ctx.lineTo(width, height / 2)
38
+ ctx.lineTo(width - offset, height)
39
+ ctx.lineTo(offset, height)
40
+ ctx.lineTo(0, height / 2)
41
+ ctx.lineTo(offset, 0)
42
+
43
+ ctx.translate(-left, -top)
44
+
45
+ ctx.fill()
46
+ ctx.stroke()
47
+ }
48
+ }
49
+
50
+ Component.register('Buffer', Buffer)
@@ -0,0 +1,208 @@
1
+ import { Component, ComponentNature, Control, POSITION } from '@hatiolab/things-scene'
2
+ import MCSTransport from './mcs-transport'
3
+ import { ConveyorMixin } from './features/conveyor-mixin'
4
+ import { normalizeAngle } from './utils/normalize-angle'
5
+
6
+ const NATURE: ComponentNature = {
7
+ mutable: false,
8
+ resizable: true,
9
+ rotatable: true,
10
+ properties: [
11
+ ...MCSTransport.properties,
12
+ {
13
+ type: 'angle',
14
+ label: 'start-angle',
15
+ name: 'startAngle'
16
+ },
17
+ {
18
+ type: 'angle',
19
+ label: 'end-angle',
20
+ name: 'endAngle'
21
+ },
22
+ {
23
+ type: 'number',
24
+ label: 'ratio',
25
+ name: 'ratio'
26
+ },
27
+ {
28
+ type: 'number',
29
+ label: 'roll-width',
30
+ name: 'rollWidth'
31
+ }
32
+ ]
33
+ }
34
+
35
+ var controlHandler = {
36
+ ondragmove: function (point: POSITION, index: number, component: Component) {
37
+ var { cx, cy, rx, ry, startAngle, endAngle } = component.model
38
+
39
+ var { x, y } = component.transcoordP2S(point.x, point.y)
40
+
41
+ const angle = (startAngle + endAngle) / 2
42
+
43
+ /* 원점으로부터 최대 거리 */
44
+ const dx = Math.abs(rx * Math.sin(angle))
45
+ const dy = Math.abs(ry * Math.cos(angle))
46
+ const distance = Math.sqrt(dx * dx + dy * dy)
47
+
48
+ /* 원점으로부터 현재 컨트롤 위치까지의 거리 */
49
+ const px = Math.abs(cx - x)
50
+ const py = Math.abs(cy - y)
51
+ const pdistance = Math.sqrt(px * px + py * py)
52
+
53
+ var ratio = (pdistance / distance) * 100
54
+
55
+ ratio = ratio >= 100 || ratio <= -100 ? 100 : Math.abs(ratio)
56
+
57
+ component.set({ ratio })
58
+ }
59
+ }
60
+
61
+ var antiClockWiseControlHandler = {
62
+ ondragmove: function (point: POSITION, index: number, component: Component) {
63
+ var { cx, cy } = component.model
64
+
65
+ var transcoorded = component.transcoordP2S(point.x, point.y)
66
+
67
+ var theta = Math.atan2(-(transcoorded.y - cy), transcoorded.x - cx)
68
+
69
+ if (theta > 0 && theta <= Math.PI / 2) theta = Math.PI / 2
70
+ if (theta < 0 && theta >= -Math.PI / 2) theta = -Math.PI / 2
71
+
72
+ const startAngle = (-theta + Math.PI / 2 - Math.PI * 2) % (Math.PI * 2)
73
+
74
+ component.set({ startAngle })
75
+ }
76
+ }
77
+
78
+ var clockwiseControlHandler = {
79
+ ondragmove: function (point: POSITION, index: number, component: Component) {
80
+ var { cx, cy } = component.model
81
+
82
+ var transcoorded = component.transcoordP2S(point.x, point.y)
83
+
84
+ var theta = Math.atan2(-(transcoorded.y - cy), transcoorded.x - cx)
85
+
86
+ if (theta > 0) if (theta >= Math.PI / 2) theta = Math.PI / 2
87
+ if (theta < 0) if (theta <= -Math.PI / 2) theta = -Math.PI / 2
88
+
89
+ var endAngle = -theta + Math.PI / 2
90
+
91
+ component.set({ endAngle })
92
+ }
93
+ }
94
+
95
+ export default class ConveyorJoin extends ConveyorMixin(MCSTransport) {
96
+ get nature() {
97
+ return NATURE
98
+ }
99
+
100
+ containable(component: Component) {
101
+ return ['Shuttle', 'Port'].includes(component.state.type)
102
+ }
103
+
104
+ contains(x: number, y: number) {
105
+ var { cx, cy, rx, ry, ratio, startAngle, endAngle } = this.state
106
+ rx = Math.abs(rx)
107
+ ry = Math.abs(ry)
108
+
109
+ const normx = (x - cx) / (rx * 2 - 0.5)
110
+ const normy = (y - cy) / (ry * 2 - 0.5)
111
+ const ratiox = (x - cx) / ((rx / 100) * ratio * 2 - 0.5)
112
+ const ratioy = (y - cy) / ((ry / 100) * ratio * 2 - 0.5)
113
+
114
+ if (normx * normx + normy * normy < 0.25 && ratiox * ratiox + ratioy * ratioy > 0.25) {
115
+ const angle = normalizeAngle(Math.atan2(-normy, normx) - Math.PI / 2)
116
+
117
+ if (angle >= startAngle && angle <= endAngle) {
118
+ return true
119
+ }
120
+ }
121
+
122
+ return false
123
+ }
124
+
125
+ render(context: CanvasRenderingContext2D) {
126
+ var { ratio = 50, cx, cy, rx, ry, startAngle = 0, endAngle = Math.PI / 2 } = this.state
127
+
128
+ context.beginPath()
129
+
130
+ startAngle -= Math.PI / 2
131
+ endAngle -= Math.PI / 2
132
+
133
+ /* outer ellipse and inner ellipse */
134
+ context.ellipse(cx, cy, Math.abs(rx), Math.abs(ry), 0, startAngle, endAngle)
135
+ context.ellipse(cx, cy, Math.abs((rx / 100) * ratio), Math.abs((ry / 100) * ratio), 0, endAngle, startAngle, true)
136
+
137
+ context.lineTo(rx * Math.cos(startAngle) + cx, ry * Math.sin(startAngle) + cy)
138
+
139
+ this.drawFill(context)
140
+ this.drawStroke(context)
141
+ }
142
+
143
+ get path() {
144
+ var { cx, cy, rx, ry } = this.state
145
+
146
+ return [
147
+ {
148
+ x: cx - rx,
149
+ y: cy - ry
150
+ },
151
+ {
152
+ x: cx + rx,
153
+ y: cy - ry
154
+ },
155
+ {
156
+ x: cx + rx,
157
+ y: cy + ry
158
+ },
159
+ {
160
+ x: cx - rx,
161
+ y: cy + ry
162
+ }
163
+ ]
164
+ }
165
+
166
+ set path(path) {
167
+ var left_top = path[0]
168
+ var right_bottom = path[2]
169
+
170
+ this.set({
171
+ cx: left_top.x + (right_bottom.x - left_top.x) / 2,
172
+ cy: left_top.y + (right_bottom.y - left_top.y) / 2,
173
+ rx: (right_bottom.x - left_top.x) / 2,
174
+ ry: (right_bottom.y - left_top.y) / 2
175
+ })
176
+ }
177
+
178
+ get controls(): Control[] {
179
+ var { cx, cy, rx, ry, ratio, startAngle, endAngle } = this.state
180
+
181
+ var controls = [] as Control[]
182
+
183
+ controls.push({
184
+ x: cx + ((rx + (rx * ratio) / 100) / 2) * Math.sin(startAngle),
185
+ y: cy - ((ry + (ry * ratio) / 100) / 2) * Math.cos(startAngle),
186
+ handler: antiClockWiseControlHandler
187
+ })
188
+
189
+ controls.push({
190
+ x: cx + ((rx + (rx * ratio) / 100) / 2) * Math.sin(endAngle),
191
+ y: cy - ((ry + (ry * ratio) / 100) / 2) * Math.cos(endAngle),
192
+ handler: clockwiseControlHandler
193
+ })
194
+
195
+ const angle = (startAngle + endAngle) / 2
196
+ controls.push({
197
+ x: cx + ((rx * ratio) / 100) * Math.sin(angle),
198
+ y: cy - ((ry * ratio) / 100) * Math.cos(angle),
199
+ handler: controlHandler
200
+ })
201
+
202
+ return controls
203
+ }
204
+ }
205
+
206
+ Component.memoize(ConveyorJoin.prototype, 'controls', false)
207
+
208
+ Component.register('ConveyorJoin', ConveyorJoin as any)
@@ -0,0 +1,101 @@
1
+ import { Component, ComponentNature } from '@hatiolab/things-scene'
2
+ import MCSTransport from './mcs-transport'
3
+
4
+ const NATURE: ComponentNature = {
5
+ mutable: false,
6
+ resizable: true,
7
+ rotatable: true,
8
+ properties: [
9
+ {
10
+ type: 'select',
11
+ label: 'conveyor-type',
12
+ name: 'conveyorType',
13
+ property: {
14
+ options: ['', 'conveyor', 'rail']
15
+ }
16
+ },
17
+ ...MCSTransport.properties
18
+ ],
19
+ help: 'scene/component/conveyor'
20
+ }
21
+
22
+ export default class Conveyor extends MCSTransport {
23
+ static get nature() {
24
+ return NATURE
25
+ }
26
+
27
+ get auxColor() {
28
+ return '#777'
29
+ }
30
+
31
+ containable(component: Component) {
32
+ return ['Shuttle', 'Port'].includes(component.state.type)
33
+ }
34
+
35
+ renderConveyor(ctx: CanvasRenderingContext2D) {
36
+ const { left, top, width, height } = this.bounds
37
+
38
+ const rollWidth = Math.max(10, Math.min(width, height) / 2)
39
+
40
+ ctx.beginPath()
41
+ ctx.fillStyle = this.statusColor!
42
+ ctx.strokeStyle = this.auxColor!
43
+ ctx.lineWidth = 1
44
+
45
+ ctx.translate(left, top)
46
+ ctx.rect(0, 0, width, height)
47
+ ctx.fill()
48
+ ctx.stroke()
49
+
50
+ ctx.beginPath()
51
+ ctx.strokeStyle = '#aaa'
52
+
53
+ if (width > height) {
54
+ for (let d = 0; d < width; d += rollWidth) {
55
+ ctx.moveTo(d, 0)
56
+ ctx.lineTo(d, height)
57
+ }
58
+ } else {
59
+ for (let d = 0; d < height; d += rollWidth) {
60
+ ctx.moveTo(0, d)
61
+ ctx.lineTo(width, d)
62
+ }
63
+ }
64
+
65
+ ctx.stroke()
66
+
67
+ ctx.translate(-left, -top)
68
+ }
69
+
70
+ renderRtvRail(ctx: CanvasRenderingContext2D) {
71
+ const { left, top, width, height } = this.bounds
72
+
73
+ ctx.beginPath()
74
+
75
+ ctx.translate(left, top)
76
+
77
+ ctx.fillStyle = this.statusColor!
78
+
79
+ if (width > height) {
80
+ ctx.fillRect(0, 0, width, (height * 1) / 5)
81
+ ctx.fillRect(0, (height * 4) / 5, width, (height * 1) / 5)
82
+ } else {
83
+ ctx.fillRect(0, 0, (width * 1) / 5, height)
84
+ ctx.fillRect((width * 4) / 5, 0, (width * 1) / 5, height)
85
+ }
86
+
87
+ ctx.translate(-left, -top)
88
+ }
89
+
90
+ render(ctx: CanvasRenderingContext2D) {
91
+ const { conveyorType } = this.state
92
+
93
+ if (conveyorType == 'rail') {
94
+ this.renderRtvRail(ctx)
95
+ } else {
96
+ this.renderConveyor(ctx)
97
+ }
98
+ }
99
+ }
100
+
101
+ Component.register('Conveyor', Conveyor)
package/src/crane.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { Component, ComponentNature, Properties } from '@hatiolab/things-scene'
2
+ import MCSVehicle from './mcs-vehicle'
3
+
4
+ const NATURE: ComponentNature = {
5
+ mutable: false,
6
+ resizable: true,
7
+ rotatable: true,
8
+ properties: [...MCSVehicle.properties]
9
+ }
10
+
11
+ const GAP = 2
12
+
13
+ export default class Crane extends MCSVehicle {
14
+ static get nature() {
15
+ return NATURE
16
+ }
17
+
18
+ get auxColor() {
19
+ return 'black'
20
+ }
21
+
22
+ render(ctx: CanvasRenderingContext2D) {
23
+ var { left, top, width, height } = this.bounds
24
+ const { x: cx, y: cy } = this.center
25
+ const rx = width / 2
26
+ const ry = height / 2
27
+
28
+ const round = Math.min(rx, ry) * 0.5
29
+
30
+ ctx.translate(left, top)
31
+ ctx.beginPath()
32
+
33
+ ctx.strokeStyle = this.auxColor
34
+ ctx.fillStyle = this.statusColor!
35
+ ctx.lineWidth = 1
36
+ ctx.lineCap = 'round'
37
+ ctx.setLineDash([])
38
+
39
+ const radius = Math.round(Math.min(width, height) * 0.1)
40
+ ctx.roundRect(1, 0, width - 2, height, radius)
41
+ ctx.roundRect(GAP + 1, GAP, width - (GAP + 1) * 2, height - GAP * 2, radius - 1)
42
+ ctx.fill()
43
+ ctx.stroke()
44
+
45
+ ctx.beginPath()
46
+ ctx.arc(cx - left, cy - top, round, 0, Math.PI * 2)
47
+ ctx.stroke()
48
+
49
+ ctx.beginPath()
50
+ ctx.roundRect(width / 2 - (round * 2) / 4 - round / 8, height / 2 - (round * 6) / 5, round / 4, (round * 6) / 5, 1)
51
+ ctx.roundRect(width / 2 + (round * 2) / 4 - round / 8, height / 2 - (round * 6) / 5, round / 4, (round * 6) / 5, 1)
52
+
53
+ ctx.fill()
54
+ ctx.stroke()
55
+
56
+ ctx.beginPath()
57
+
58
+ // draw crane bar metapore
59
+ ctx.strokeStyle = 'black'
60
+ ctx.lineWidth = 3
61
+ ctx.lineCap = 'butt'
62
+
63
+ ctx.moveTo(GAP * 3, height / 2)
64
+ ctx.lineTo(width - GAP * 3, height / 2)
65
+
66
+ ctx.stroke()
67
+
68
+ ctx.translate(-left, -top)
69
+ }
70
+ }
71
+
72
+ Component.register('Crane', Crane)