-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriggerArea.qml
158 lines (149 loc) · 4 KB
/
TriggerArea.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import QtQuick 2.0
Item{
id: rect
anchors.fill:parent
property var p0Coord: null
property var p1Coord: null
property var p2Coord: null
property var p3Coord: null
property int index: 0
property int minSize: map.width/100
property var k: map.width/1500
property var selected: objectList.selected
property var state: stateList.selected
visible: currentTrig == rect
Rectangle{
id:rec
x: p0.x
y: p0.y
width: p2.x-p0.x
height: p2.y-p0.y
color: "transparent"
border.width: map.width/500
border.color: colors[index]
}
Item{
id:corners
DragAnchor{
id:p0
center: p0Coord
onUpdated: {
p0.x = Math.min(p0.x,p2.x-minSize)
p0.y = Math.min(p0.y,p2.y-minSize)
p1.y=p0.y
p3.x=p0.x
updateItems()
}
}
DragAnchor{
id:p1
center: p1Coord
onUpdated: {
p1.x = Math.max(p1.x,p3.x+minSize)
p1.y = Math.min(p1.y,p3.y-minSize)
p0.y=p1.y
p2.x=p1.x
updateItems()
}
}
DragAnchor{
id:p2
center: p2Coord
onUpdated: {
p2.x = Math.max(p2.x,p0.x+minSize)
p2.y = Math.max(p2.y,p0.y+minSize)
p3.y=p2.y
p1.x=p2.x
updateItems()
print(p2.x)
}
}
DragAnchor{
id:p3
center: p3Coord
onUpdated: {
p3.x = Math.min(p3.x,p1.x-minSize)
p3.y = Math.max(p3.y,p1.y+minSize)
p2.y=p3.y
p0.x=p3.x
updateItems()
}
}
}
Column{
id: objectList
property var selected: ""
anchors.left: rec.right
anchors.top:rec.top
GuiRadioButton{
id:screw
text:"Screw"
visible: false
group: objectList
}
GuiRadioButton{
id:hole
text:"Hole"
visible: false
group: objectList
}
}
Column{
id:stateList
property var selected: ""
anchors.right: rec.left
anchors.top:rec.top
GuiRadioButton{
id:screwed
text:"Screwed"
visible: screw.checked && triggerPannel.useState
group: stateList
}
GuiRadioButton{
id:unscrewed
text:"Unscrewed"
visible: screw.checked && triggerPannel.useState
group: stateList
}
}
function updateItems(){
var objectTypes=[]
for(var i=0; i<pois.children.length; i++){
var poi = pois.children[i]
if (poi.enabled && poi.type && inHull(poi)){
if(objectTypes.indexOf(poi.type)===-1)
objectTypes.push(poi.type)
}
}
screw.visible = (objectTypes.indexOf("screw")!==-1)
hole.visible = (objectTypes.indexOf("hole")!==-1)
p0Coord.x = p0.x
p1Coord.x = p1.x
p2Coord.x = p2.x
p3Coord.x = p3.x
p0Coord.y = p0.y
p1Coord.y = p1.y
p2Coord.y = p2.y
p3Coord.y = p3.y
}
function inHull(poi){
if(poi.x>p0.x && poi.x<p1.x && poi.y>p0.y && poi.y<p3.y)
return true
return false
}
function getTrigger(pos,state){
var msg ="trigger_"+index.toString()+";"+selected+";"
var p0_coord = p0.getCoord().split(",")
var p2_coord = p2.getCoord().split(",")
if(pos)
msg+="pix_pose:"+p0_coord[0]+"-"+p2_coord[0]+"_"+p0_coord[1]+"-"+p2_coord[1]
if(state && pos)
msg+=","
if(state)
msg+="state:"+stateList.selected
return msg;
}
Component.onCompleted: updateItems()
function selected(val){
}
}