@operato/scene-wheel-sorter 8.0.0-beta.1 → 8.0.0

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.
@@ -1,69 +0,0 @@
1
- import { Component, ComponentNature, Polygon } from '@hatiolab/things-scene'
2
-
3
- /*
4
- * Copyright © HatioLab Inc. All rights reserved.
5
- */
6
- import MixinRoller from './mixin-conveyor'
7
-
8
- const NATURE: ComponentNature = {
9
- mutable: false,
10
- resizable: true,
11
- rotatable: true,
12
- properties: [
13
- {
14
- type: 'select',
15
- label: 'conveyor-type',
16
- name: 'conveyorType',
17
- property: {
18
- options: [
19
- {
20
- display: 'Roller',
21
- value: 0
22
- },
23
- {
24
- display: 'Belt',
25
- value: 1
26
- }
27
- ]
28
- }
29
- },
30
- {
31
- type: 'number',
32
- label: 'roll-width',
33
- name: 'rollWidth'
34
- },
35
- {
36
- type: 'number',
37
- label: 'value',
38
- name: 'value'
39
- },
40
- {
41
- type: 'checkbox',
42
- label: 'animation',
43
- name: 'animated'
44
- }
45
- ],
46
- help: 'scene/component/conveyor-join-trapezoid'
47
- }
48
-
49
- const STAT_IDLE = 0
50
- const STAT_RUN = 1
51
- const STAT_CHUTE_FULL = 3
52
- const STAT_ERROR = 4
53
-
54
- export default class ConveyorJoinTrapezoid extends MixinRoller(Polygon) {
55
- get nature() {
56
- return NATURE
57
- }
58
-
59
- is3dish() {
60
- return false
61
- }
62
-
63
- render(context: CanvasRenderingContext2D) {
64
- this.getState('animated') && this.animOnState()
65
- super.render(context)
66
- }
67
- }
68
-
69
- Component.register('conveyor-join-trapezoid', ConveyorJoinTrapezoid as any)
@@ -1,205 +0,0 @@
1
- import { Component, ComponentNature, Donut, POSITION } from '@hatiolab/things-scene'
2
-
3
- import MixinRoller from './mixin-conveyor'
4
-
5
- const NATURE: ComponentNature = {
6
- mutable: false,
7
- resizable: true,
8
- rotatable: true,
9
- properties: [
10
- {
11
- type: 'select',
12
- label: 'conveyor-type',
13
- name: 'conveyorType',
14
- property: {
15
- options: [
16
- {
17
- display: 'Roller',
18
- value: 0
19
- },
20
- {
21
- display: 'Belt',
22
- value: 1
23
- }
24
- ]
25
- }
26
- },
27
- {
28
- type: 'angle',
29
- label: 'start-angle',
30
- name: 'startAngle'
31
- },
32
- {
33
- type: 'angle',
34
- label: 'end-angle',
35
- name: 'endAngle'
36
- },
37
- {
38
- type: 'number',
39
- label: 'ratio',
40
- name: 'ratio'
41
- },
42
- {
43
- type: 'number',
44
- label: 'roll-width',
45
- name: 'rollWidth'
46
- },
47
- {
48
- type: 'number',
49
- label: 'value',
50
- name: 'value'
51
- },
52
- {
53
- type: 'checkbox',
54
- label: 'animation',
55
- name: 'animated'
56
- }
57
- ],
58
- help: 'scene/component/conveyor-join'
59
- }
60
-
61
- var controlHandler = {
62
- ondragmove: function (point: POSITION, index: number, component: Component) {
63
- var { cx, cy, rx, ry, startAngle, endAngle } = component.model
64
-
65
- var { x, y } = component.transcoordP2S(point.x, point.y)
66
-
67
- const angle = (startAngle + endAngle) / 2
68
-
69
- /* 원점으로부터 최대 거리 */
70
- const dx = Math.abs(rx * Math.sin(angle))
71
- const dy = Math.abs(ry * Math.cos(angle))
72
- const distance = Math.sqrt(dx * dx + dy * dy)
73
-
74
- /* 원점으로부터 현재 컨트롤 위치까지의 거리 */
75
- const px = Math.abs(cx - x)
76
- const py = Math.abs(cy - y)
77
- const pdistance = Math.sqrt(px * px + py * py)
78
-
79
- var ratio = (pdistance / distance) * 100
80
-
81
- ratio = ratio >= 100 || ratio <= -100 ? 100 : Math.abs(ratio)
82
-
83
- component.set({ ratio })
84
- }
85
- }
86
-
87
- var antiClockWiseControlHandler = {
88
- ondragmove: function (point: POSITION, index: number, component: Component) {
89
- var { cx, cy } = component.model
90
-
91
- var transcoorded = component.transcoordP2S(point.x, point.y)
92
-
93
- var theta = Math.atan2(-(transcoorded.y - cy), transcoorded.x - cx)
94
-
95
- if (theta > 0 && theta <= Math.PI / 2) theta = Math.PI / 2
96
- if (theta < 0 && theta >= -Math.PI / 2) theta = -Math.PI / 2
97
-
98
- const startAngle = (-theta + Math.PI / 2 - Math.PI * 2) % (Math.PI * 2)
99
-
100
- component.set({ startAngle })
101
- }
102
- }
103
-
104
- var clockwiseControlHandler = {
105
- ondragmove: function (point: POSITION, index: number, component: Component) {
106
- var { cx, cy } = component.model
107
-
108
- var transcoorded = component.transcoordP2S(point.x, point.y)
109
-
110
- var theta = Math.atan2(-(transcoorded.y - cy), transcoorded.x - cx)
111
-
112
- if (theta > 0) if (theta >= Math.PI / 2) theta = Math.PI / 2
113
- if (theta < 0) if (theta <= -Math.PI / 2) theta = -Math.PI / 2
114
-
115
- var endAngle = -theta + Math.PI / 2
116
-
117
- component.set({ endAngle })
118
- }
119
- }
120
-
121
- function normalizeAngle(angle: number): number {
122
- angle = angle % (2 * Math.PI)
123
- if (angle <= -Math.PI) {
124
- angle += 2 * Math.PI
125
- } else if (angle > Math.PI) {
126
- angle -= 2 * Math.PI
127
- }
128
- return angle
129
- }
130
-
131
- export default class ConveyorJoin extends MixinRoller(Donut) {
132
- get nature() {
133
- return NATURE
134
- }
135
-
136
- is3dish() {
137
- return false
138
- }
139
-
140
- contains(x: number, y: number) {
141
- var { cx, cy, rx, ry, ratio, startAngle, endAngle } = this.state
142
- rx = Math.abs(rx)
143
- ry = Math.abs(ry)
144
-
145
- const normx = (x - cx) / (rx * 2 - 0.5)
146
- const normy = (y - cy) / (ry * 2 - 0.5)
147
- const ratiox = (x - cx) / ((rx / 100) * ratio * 2 - 0.5)
148
- const ratioy = (y - cy) / ((ry / 100) * ratio * 2 - 0.5)
149
-
150
- if (normx * normx + normy * normy < 0.25 && ratiox * ratiox + ratioy * ratioy > 0.25) {
151
- const angle = normalizeAngle(Math.atan2(-normy, normx) - Math.PI / 2)
152
-
153
- if (angle >= startAngle && angle <= endAngle) {
154
- return true
155
- }
156
- }
157
-
158
- return false
159
- }
160
-
161
- render(ctx: CanvasRenderingContext2D) {
162
- var { ratio = 50, cx, cy, rx, ry, startAngle = 0, endAngle = Math.PI / 2, animated = false } = this.state
163
-
164
- animated && this.animOnState()
165
-
166
- ctx.beginPath()
167
-
168
- startAngle = (startAngle - Math.PI / 2 - Math.PI * 2) % (Math.PI * 2)
169
- endAngle -= Math.PI / 2
170
-
171
- ctx.ellipse(cx, cy, Math.abs(rx), Math.abs(ry), 0, startAngle, endAngle)
172
- ctx.ellipse(cx, cy, Math.abs((rx / 100) * ratio), Math.abs((ry / 100) * ratio), 0, endAngle, startAngle, true)
173
-
174
- ctx.lineTo(rx * Math.cos(startAngle) + cx, ry * Math.sin(startAngle) + cy)
175
- }
176
-
177
- get controls() {
178
- var { cx, cy, rx, ry, ratio, startAngle, endAngle } = this.state
179
-
180
- var controls = []
181
-
182
- controls.push({
183
- x: cx + ((rx + (rx * ratio) / 100) / 2) * Math.sin(startAngle),
184
- y: cy - ((ry + (ry * ratio) / 100) / 2) * Math.cos(startAngle),
185
- handler: antiClockWiseControlHandler
186
- })
187
-
188
- controls.push({
189
- x: cx + ((rx + (rx * ratio) / 100) / 2) * Math.sin(endAngle),
190
- y: cy - ((ry + (ry * ratio) / 100) / 2) * Math.cos(endAngle),
191
- handler: clockwiseControlHandler
192
- })
193
-
194
- const angle = (startAngle + endAngle) / 2
195
- controls.push({
196
- x: cx + ((rx * ratio) / 100) * Math.sin(angle),
197
- y: cy - ((ry * ratio) / 100) * Math.cos(angle),
198
- handler: controlHandler
199
- })
200
-
201
- return controls
202
- }
203
- }
204
-
205
- Component.register('conveyor-join', ConveyorJoin as any)
package/src/conveyor.ts DELETED
@@ -1,69 +0,0 @@
1
- import { Component, ComponentNature, RectPath, Shape } from '@hatiolab/things-scene'
2
-
3
- /*
4
- * Copyright © HatioLab Inc. All rights reserved.
5
- */
6
- import MixinRoller from './mixin-conveyor'
7
-
8
- const NATURE: ComponentNature = {
9
- mutable: false,
10
- resizable: true,
11
- rotatable: true,
12
- properties: [
13
- {
14
- type: 'select',
15
- label: 'conveyor-type',
16
- name: 'conveyorType',
17
- property: {
18
- options: [
19
- {
20
- display: 'Roller',
21
- value: 0
22
- },
23
- {
24
- display: 'Belt',
25
- value: 1
26
- }
27
- ]
28
- }
29
- },
30
- {
31
- type: 'number',
32
- label: 'roll-width',
33
- name: 'rollWidth'
34
- },
35
- {
36
- type: 'number',
37
- label: 'value',
38
- name: 'value'
39
- },
40
- {
41
- type: 'checkbox',
42
- label: 'animation',
43
- name: 'animated'
44
- }
45
- ],
46
- help: 'scene/component/conveyor'
47
- }
48
-
49
- export default class Conveyor extends MixinRoller(RectPath(Shape)) {
50
- get nature() {
51
- return NATURE
52
- }
53
-
54
- render(ctx: CanvasRenderingContext2D) {
55
- var { width, height, left, top, animated = false } = this.state
56
-
57
- animated && this.animOnState()
58
-
59
- ctx.beginPath()
60
- ctx.rect(left, top, width, height)
61
- }
62
-
63
- is3dish() {
64
- return false
65
- }
66
- }
67
-
68
- Component.register('conveyor', Conveyor as any)
69
- Component.register('conveyor-belt', Conveyor as any)
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- export { default as Conveyor } from './conveyor'
5
- export { default as ConveyorJoin } from './conveyor-join'
6
- export { default as ConveyorJoinTrapezoid } from './conveyor-join-trapezoid'
7
- export { default as WheelSorter } from './wheel-sorter'
8
- export { default as Scanner } from './scanner'
@@ -1,169 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Class, Component, ValueHolder } from '@hatiolab/things-scene'
5
-
6
- const TYPE_ROLLER = 0
7
- const TYPE_BELT = 1
8
-
9
- const FILL_STYLES = ['#ccc', '#afd0f1', '#afd0f1', '#ffba00', '#e9746b'] // IDLE, RUN, RUN(REVERSE), WARN, ERROR
10
- const STROKE_STYLES = ['#999', '#87b1db', '#87b1db', '#d96f21', '#a73928'] // IDLE, RUN, RUN(REVERSE), WARN, ERROR
11
-
12
- type RollerPattern = {
13
- width: number
14
- height: number
15
- }
16
-
17
- function pattern_for_belt_type(component: any) {
18
- var { height } = component.bounds
19
-
20
- var { rollWidth = 10 } = component.model
21
-
22
- var width = Math.max(rollWidth, 1)
23
-
24
- var color = FILL_STYLES[component.value] || FILL_STYLES[0]
25
- var stroke = STROKE_STYLES[component.value] || STROKE_STYLES[0]
26
- var lineWidth = 1
27
-
28
- if (!component._roller_pattern) component._roller_pattern = document.createElement('canvas')
29
-
30
- component._roller_pattern.width = width
31
- component._roller_pattern.height = height
32
-
33
- var context = component._roller_pattern.getContext('2d')
34
-
35
- context.beginPath()
36
- context.fillStyle = color
37
- context.strokeStyle = stroke
38
- context.lineWidth = lineWidth
39
-
40
- context.moveTo(0, 0)
41
- context.lineTo(width, 0)
42
- context.lineTo(width, height)
43
- context.lineTo(0, height)
44
- context.lineTo(0, 0)
45
- context.fill()
46
-
47
- context.beginPath()
48
-
49
- context.globalAlpha = 0.2
50
-
51
- var x_for_belt = (component._step || 0) % width
52
- if (component.value == 2) x_for_belt = width - x_for_belt
53
-
54
- context.moveTo(x_for_belt, height)
55
- context.lineTo(x_for_belt, 0)
56
-
57
- context.stroke()
58
-
59
- return component._roller_pattern
60
- }
61
-
62
- function pattern_for_roller_type(component: any) {
63
- var { height } = component.bounds
64
-
65
- var { rollWidth = 10, animated } = component.model
66
-
67
- // var modelWidth = component.model.width;
68
-
69
- var width = Math.max(rollWidth, 1)
70
-
71
- var color = FILL_STYLES[component.value] || FILL_STYLES[0]
72
- var stroke = STROKE_STYLES[component.value] || STROKE_STYLES[0]
73
- var lineWidth = Math.min(1, width / 10)
74
-
75
- width += lineWidth * 2
76
-
77
- if (!component._roller_pattern) component._roller_pattern = document.createElement('canvas')
78
-
79
- var gap = Math.floor((width * 2) / 3)
80
-
81
- // while (Math.round(modelWidth - width) % (width + gap) > gap) {
82
- // gap++
83
- // console.log(gap, Math.round(modelWidth - width) % (width + gap))
84
- // }
85
-
86
- component._roller_pattern.width = width + gap
87
- component._roller_pattern.height = height
88
-
89
- var context = component._roller_pattern.getContext('2d')
90
-
91
- context.beginPath()
92
- context.fillStyle = color
93
- context.strokeStyle = stroke
94
- context.lineWidth = lineWidth
95
-
96
- context.ellipse(lineWidth + width / 2, height - width / 4 - lineWidth, width / 2, width / 4, 0, 0, Math.PI)
97
-
98
- context.moveTo(lineWidth, height - width / 4)
99
- context.lineTo(lineWidth, width / 4)
100
-
101
- context.ellipse(lineWidth + width / 2, width / 4 + lineWidth, width / 2, width / 4, 0, Math.PI, 0)
102
-
103
- context.lineTo(lineWidth + width, height - width / 4)
104
-
105
- context.fill()
106
- context.stroke()
107
-
108
- context.globalAlpha = 0.2
109
-
110
- context.lineWidth = width / 3
111
-
112
- if (animated) {
113
- var x_for_roll = component._step % width
114
- if (component.value == 2) x_for_roll = width - x_for_roll
115
-
116
- context.moveTo(x_for_roll, height - width / 4)
117
- context.lineTo(x_for_roll, width / 4)
118
-
119
- context.stroke()
120
- }
121
-
122
- return component._roller_pattern
123
- }
124
-
125
- const patterns = [pattern_for_roller_type, pattern_for_belt_type]
126
-
127
- export default (superclass: Class) => {
128
- var A = class extends ValueHolder(superclass) {
129
- dispose() {
130
- super.dispose()
131
- delete this._roller_pattern
132
- }
133
-
134
- animOnState() {
135
- if ((this.value !== 1 && this.value !== 2) || this.disposed) return
136
-
137
- if (!this._step || this._step > 40000) this._step = this.value == 0
138
-
139
- this._step++
140
-
141
- var self = this
142
-
143
- requestAnimationFrame(function () {
144
- self.clearCache('fillStyle')
145
- self.invalidate()
146
- })
147
- }
148
-
149
- get conveyorType() {
150
- var conveyorType = this.getState('conveyorType')
151
- if (conveyorType != TYPE_BELT && conveyorType != TYPE_ROLLER) conveyorType = TYPE_ROLLER
152
- return conveyorType
153
- }
154
-
155
- get fillStyle() {
156
- return {
157
- image: patterns[this.conveyorType](this),
158
- offsetX: 0,
159
- offsetY: 0,
160
- type: 'pattern'
161
- }
162
- }
163
- }
164
-
165
- Component.memoize(A.prototype, 'fillStyle', false)
166
- Component.memoize(A.prototype, 'conveyorType', false)
167
-
168
- return A
169
- }
@@ -1,122 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Class, Component, ValueHolder } from '@hatiolab/things-scene'
5
-
6
- const FILL_STYLES = ['rgba(0,0,0,.4)', 'rgba(175,208,241,.7)', 'rgba(255,186,0,.7)', 'rgba(198,50,40,.7)'] // IDLE, RUN, WARN, ERROR
7
- const STROKE_STYLES = ['rgba(0,0,0,.7)', 'rgba(175,208,241,1)', 'rgba(255,186,0,1)', 'rgba(198,50,40,1)'] // IDLE, RUN, WARN, ERROR
8
-
9
- function pattern(component: any) {
10
- var { width, height } = component.bounds
11
-
12
- var color = FILL_STYLES[component.value] || FILL_STYLES[0]
13
- var stroke = STROKE_STYLES[component.value] || STROKE_STYLES[0]
14
- var lineWidth = 1
15
-
16
- if (!component._scanner_pattern) component._scanner_pattern = document.createElement('canvas')
17
-
18
- component._scanner_pattern.width = width
19
- component._scanner_pattern.height = height
20
-
21
- var ctx = component._scanner_pattern.getContext('2d')
22
-
23
- var radius = width / 10
24
- var left = 0
25
- var top = 0
26
-
27
- // outer box
28
- ctx.beginPath()
29
- ctx.fillStyle = color
30
- ctx.strokeStyle = stroke
31
-
32
- ctx.rect(0, 0, width, height)
33
- ctx.fill()
34
- // ctx.stroke();
35
-
36
- // inner box
37
- radius = width / 40
38
- left = width / 4
39
- top = height / 4
40
-
41
- ctx.beginPath()
42
- ctx.fillStyle = 'rgba(0,0,0,.7)'
43
- ctx.strokeStyle = null
44
-
45
- ctx.moveTo(left + radius, top)
46
- ctx.lineTo(left + width / 2 - radius, top)
47
- ctx.quadraticCurveTo(left + width / 2, top, left + width / 2, top + radius)
48
- ctx.lineTo(left + width / 2, top + height / 2 - radius)
49
- ctx.quadraticCurveTo(left + width / 2, top + height / 2, left + width / 2 - radius, top + height / 2)
50
- ctx.lineTo(left + radius, top + height / 2)
51
- ctx.quadraticCurveTo(left, top + height / 2, left, top + height / 2 - radius)
52
- ctx.lineTo(left, top + radius)
53
- ctx.quadraticCurveTo(left, top, left + radius, top)
54
- ctx.fill()
55
-
56
- // barcode
57
- left = left + width * 0.1
58
- top = top + height * 0.05
59
-
60
- var offsetTop = 0
61
- var barcodeAreaWidth = width * 0.3
62
- var barcodeAreaHeight = height * 0.4
63
-
64
- ctx.beginPath()
65
- ctx.fillStyle = '#fff'
66
-
67
- ctx.moveTo(left, top)
68
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, (barcodeAreaHeight / 14) * 0.9)
69
- offsetTop = (barcodeAreaHeight / 14) * 2
70
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, (barcodeAreaHeight / 14) * 0.3)
71
- offsetTop = (barcodeAreaHeight / 14) * 4
72
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, (barcodeAreaHeight / 14) * 0.4)
73
- offsetTop = (barcodeAreaHeight / 14) * 6
74
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, (barcodeAreaHeight / 14) * 0.8)
75
- offsetTop = (barcodeAreaHeight / 14) * 8
76
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, (barcodeAreaHeight / 14) * 0.6)
77
- offsetTop = (barcodeAreaHeight / 14) * 10
78
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, barcodeAreaHeight / 14)
79
- offsetTop = (barcodeAreaHeight / 14) * 11
80
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, barcodeAreaHeight / 14)
81
- offsetTop = (barcodeAreaHeight / 14) * 14
82
- ctx.rect(left, top + offsetTop, barcodeAreaWidth, (barcodeAreaHeight / 14) * 0.3)
83
-
84
- ctx.fill()
85
-
86
- // lazer
87
- ctx.beginPath()
88
- left = width / 2
89
- top = height * 0.1
90
-
91
- ctx.strokeStyle = '#cc3300'
92
- ctx.lineWidth = 1
93
- ctx.moveTo(left, top)
94
- ctx.lineTo(left, height * 0.9)
95
-
96
- ctx.stroke()
97
-
98
- return component._scanner_pattern
99
- }
100
-
101
- export default (superclass: Class) => {
102
- var A = class extends ValueHolder(superclass) {
103
- dispose() {
104
- super.dispose()
105
- delete this._scanner_pattern
106
- }
107
-
108
- get fillStyle() {
109
- return {
110
- image: pattern(this),
111
- offsetX: 0,
112
- offsetY: 0,
113
- type: 'pattern',
114
- fitPattern: true
115
- }
116
- }
117
- }
118
-
119
- Component.memoize(A.prototype, 'fillStyle', false)
120
-
121
- return A
122
- }