-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrain_tool.html
More file actions
384 lines (319 loc) · 8.49 KB
/
train_tool.html
File metadata and controls
384 lines (319 loc) · 8.49 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!DOCTYPE html>
<html lang="en">
<head>
<title>TRAIN TOOL</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body style="background-color: #edeeee;margin-left: 100px;margin-right: 100px">
<div style="" class="">
<div class="panel-heading text-center">
<h1>MAP TRAIN TOOL</h1>
</div>
<div class="row" >
<div class="form-group col-sm-3">
<p>ct: Quầy phục vụ</p>
<p>bx: Hộp</p>
<p>cv: Khoang</p>
<p>bd: Bed</p>
</div>
<div class="form-group col-sm-3">
<p>s: Ghế xuôi</p>
<p>rs: Ghế ngược</p>
<p>tb: Bàn</p>
<p>sh: Kệ</p>
</div>
<div class="form-group col-sm-3">
<p>br: Vật cản</p>
<p>wc: Toilet</p>
<p>lb: Nhà tắm</p>
</div>
<div class="form-group col-sm-3">
<p>tx: Text</p>
<p>bd: Bed</p>
<p>fo: Tầng</p>
</div>
</div>
</div>
<div class="row" >
<div class="col-sm-7" style="">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="rowN" placeholder="Số dòng">
</div>
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="columnM" placeholder="Số cột">
</div>
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="floorM" placeholder="Số tầng" value="1">
</div>
<button type="button" class="btn btn-success col-sm-1" onclick="createMatrix()">Create</button>
</div>
<div class="row">
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="ratioCell" placeholder="Tỉ lệ width/height" value="1">
</div>
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="padding" placeholder="padding" value = "5">
</div>
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="paddingWidth" placeholder="padding Width" value = "5">
</div>
</div>
<div class="row">
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="titleToa" placeholder="title toa">
</div>
<div class="form-group col-sm-3">
<input type="text" class="form-control" id="marginHoli" placeholder="margin holizontal" value = "40">
</div>
</div>
</div>
<div class="panel-body">
<div id="matrixFloor" >
</div>
</div>
</div>
</div>
<div class="col-sm-1 text-center" style="">
<button type="button" class="btn btn-primary" onclick="exportJSON()">Generate JSON</button>
</div>
<div class="col-sm-4" style="">
<div class="panel panel-default">
<div class="panel-heading">Result</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12 " id = "resultJson">
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var n=0;
var m = 0;
var f = 1;
var ratioCell = 1;
var padding = 5;
var titleToa = "";
var marginHoli = 40
var paddingWidth = 5;
function exportJSON(){
this.getConfig();
let objFinal = {}
objFinal.width = this.m;
objFinal.height = this.n;
objFinal.ratioCell = this.ratioCell;
objFinal.padding = this.padding
objFinal.title = this.titleToa
objFinal.marginHoli = this.marginHoli
objFinal.paddingWidth = this.paddingWidth
let floorLists = new Array(this.f)
for(let i=0;i<this.f;i++){
floorLists[i] = this.exportFloor(i)
}
objFinal.floors = floorLists
document.getElementById("resultJson").innerHTML = JSON.stringify(objFinal);
}
function getConfig(){
let wis = document.getElementById('ratioCell').value;
let pas = document.getElementById('padding').value;
let tis = document.getElementById('titleToa').value;
let hos = document.getElementById('marginHoli').value;
let pasW = document.getElementById('paddingWidth').value;
this.ratioCell = parseInt(wis)
this.padding = parseInt(pas)
this.titleToa = tis
this.marginHoli = parseInt(hos)
this.paddingWidth = parseInt(pasW)
}
function exportFloor(k){
let matrix = this.getMatrix(this.n,this.m,k);
let jsonExport = this.findJSON(matrix,this.n,this.m);
jsonExport = this.formatData(jsonExport,this.n,this.m)
return jsonExport
}
function formatData(matrix,n,m){
for(let i = 0;i<n;i++){
matrix[i] = matrix[i].filter(function(n){ return n != null });
}
return matrix
}
function findJSON(matrix,x,y){
let obj = {}
obj.coor = {x:0,y:0}
let arrFull = new Array(x);
for(let i = 0;i<x;i++){
let arrCell = new Array(y);
for(let j = 0;j<y;j++){
let value =matrix[i][j]
if(value != ""){
let distance = this.findWidthHeightComponent(matrix,i,j)
arrCell[j] = this.getComponent(matrix[i][j],i,j,distance.width,distance.height);
}
}
arrFull[i] = arrCell;
}
return arrFull
}
function getComponent(value,i,j,width,height){
let obj = {
"pos":{
"x":i,
"y":j,
"width":width,
"height":height,
},
"title":""
}
if(value == "")
return obj
let items = value.split("_");
switch(items[0]){
case "s":
obj.type = "seat"
obj.id = items[1]
break;
case "rs":
obj.type = "reSeat"
obj.id = items[1]
break;
case "tb":
obj.type = "table"
break;
case "br":
obj.type = "barrier"
break;
case "wc":
obj.type = "toilet"
break;
case "lb":
obj.type = "lavabo"
break;
case "tx":
obj.type = "text"
break;
case "bd":
obj.type = "bed"
obj.id = items[1]
break;
case "cv":
obj.type = "cavity"
obj.title = "Khoang " + items[1]
break;
case "fo":
obj.type = "floor"
obj.title = "Tầng " + items[1]
break;
case "sh":
obj.type = "shelf"
obj.title ="Kê dụng cụ"
break;
case "ct":
obj.type = "counter"
obj.title ="Quầy phục vụ"
break;
case "bx":
obj.type = "box"
break;
}
return obj
}
function findWidthHeightComponent(matrix,px,py){
// if(matrix[px][py] == "s" || matrix[px][py] == "rs" || matrix[px][py] == "fo" || matrix[px][py] == "cv" || matrix[px][py] == "bd"){
// return {width:1,height:1}
// }
let x=0;
let y=0;
for(let i = px;i<matrix.length;i++){
if(matrix[i][py] == matrix[px][py]){
x++;
}else{
break;
}
}
for(let j = py;j<matrix[0].length;j++){
if(matrix[px][j] == matrix[px][py]){
y++;
}else{
break;
}
}
for(let i = 0;i<x;i++){
for(let j = 0;j<y;j++){
if(i==0 && j == 0){
}else{
matrix[px + i][ py + j] = ""
}
}
}
return {width:y,height:x}
}
function createMatrix() {
let ns = document.getElementById('rowN').value;
let ms = document.getElementById('columnM').value;
let fs = document.getElementById('floorM').value;
let wis = document.getElementById('ratioCell').value;
let pas = document.getElementById('padding').value;
this.n = parseInt(ns)
this.m = parseInt(ms)
this.f = parseInt(fs)
this.ratioCell = parseInt(wis)
this.padding = parseInt(pas)
let floor = ''
for(let k=0;k<f;k++){
let matrix = '';
for(let i=0;i<n;i++){
let rowMatrix = ''
for(let j=0;j<m;j++){
let id =k+""+ i + "" +j + ""
rowMatrix+= '<div class="col-sm-1" >'
+'<input style="width:100%;height:100%;border-style: solid;border-width: 1px;" type="text" id = '+id+' >'
+'</div>'
}
matrix+= '<div class="row">'
+rowMatrix
+'</div>'
}
let isHr = '<hr/>'
if(k==f-1){
isHr = ''
}
floor+=
'<div class="row" >'
+'<div class="col-sm-1" >'
+'<p>Tầng '+(k+1)+'</p>'
+'</div>'
+'<div class="col-sm-11 " id = "matrix">'
+matrix
+'</div>'
+'</div>'
+isHr
// floor+= matrix
}
document.getElementById("matrixFloor").innerHTML = floor;
// return matrix;
}
function getMatrix(n,m,k){
console.log("abc" +n)
var matrix = new Array(n);
for (var i = 0; i < n; i++) {
matrix[i] = new Array(m);
}
for(let i=0;i<n;i++){
for(let j = 0;j<m;j++){
let id = k+""+i + "" +j + ""
matrix[i][j] = document.getElementById(id).value;
console.log( matrix[i][j])
}
}
return matrix
}
</script>
</html>