-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathladder_editor.html
More file actions
1926 lines (1789 loc) · 106 KB
/
ladder_editor.html
File metadata and controls
1926 lines (1789 loc) · 106 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--
Copyright 2025 Emiliano Gonzalez (egonzalez . hiperion @ gmail . com))
Project Site: https://github.com/hiperiondev/ladder-editor
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ladder PLC Editor</title>
<style>
/* CSS Variables for consistent and maintainable sizing across the editor */
:root {
--cell-size: 60px; /* Size of each grid cell */
--label-width: 40px; /* Width of row and column labels */
--controls-height: 60px;/* Height of the network control area */
}
/* Media query for responsive design on small screens (max-width: 600px) */
@media (max-width: 600px) {
:root {
--cell-size: 40px; /* Smaller cell size for compact screens */
--label-width: 30px; /* Reduced label width */
--controls-height: 50px;/* Reduced controls height */
}
/* Hides table headers in symbol values table for better mobile display */
#symbolValues th {
display: none;
}
}
/* General styling for the body of the page */
body {
font-family: Arial, sans-serif; /* Sets a clean, readable font */
background-color: #f0f0f0; /* Light gray background */
margin: 20px; /* Adds padding around the content */
overflow-x: auto; /* Allows horizontal scrolling if needed */
}
/* Styles the controls section containing action buttons */
#controls {
margin-bottom: 20px; /* Space below the controls for separation */
}
/* Container for all network diagrams, arranged vertically */
#networks-container {
display: flex;
flex-direction: column;
gap: 20px; /* Space between individual networks */
}
/* Wrapper for each network, including its controls and table */
.network-wrapper {
position: relative; /* Allows absolute positioning of child elements */
display: block;
margin-bottom: 20px; /* Space below each network */
}
/* Styles the grid table representing a ladder logic network */
.network-table {
border-collapse: collapse; /* Removes gaps between cells */
background-color: #fff; /* White background for the grid */
box-shadow: 0 0 10px rgba(0,0,0,0.1); /* Subtle shadow for depth */
margin-left: var(--label-width); /* Offset for row labels */
margin-top: calc(var(--controls-height) + 20px); /* Space for controls */
margin-bottom: 40px; /* Extra space below the table */
border: 1px solid #ddd; /* Light border around the table */
}
/* Styles individual cells in the network table */
.network-table td {
width: var(--cell-size); /* Fixed width from CSS variable */
height: var(--cell-size); /* Fixed height from CSS variable */
border: 1px solid #ddd; /* Light border for cell outlines */
padding: 0; /* Removes default padding */
text-align: center; /* Centers content horizontally */
vertical-align: middle; /* Centers content vertically */
cursor: pointer; /* Indicates cells are clickable */
position: relative; /* For positioning SVGs or bars */
overflow: visible; /* Allows SVGs to extend beyond cell */
box-sizing: border-box; /* Includes border in size calculations */
background-color: #fff; /* White background for cells */
}
/* Hover effect for cells to indicate interactivity */
.network-table td:hover {
background-color: #f5f5f5; /* Light gray on hover */
}
/* Ensures SVGs within cells fit properly */
.network-table td svg {
width: 100%; /* Fills the cell width */
height: 100%; /* Fills the cell height */
display: block;
margin: 0 auto; /* Centers the SVG */
object-fit: contain; /* Maintains SVG aspect ratio */
preserveAspectRatio: meet;/* Preserves SVG proportions */
}
/* Styles for SVGs spanning multiple cells (e.g., timers) */
.multi-cell-svg {
position: absolute; /* Positions SVG over multiple rows */
top: 0;
left: 0;
width: var(--cell-size); /* Matches cell width */
}
/* Common styles for row and column labels */
.row-label, .col-label {
font-size: 14px; /* Readable font size */
font-weight: bold; /* Bold for emphasis */
color: #333; /* Dark gray color */
position: absolute; /* Absolute positioning relative to wrapper */
pointer-events: none; /* Prevents interference with clicks */
}
/* Specific styles for row labels (left of the grid) */
.row-label {
width: var(--label-width); /* Fixed width from CSS variable */
text-align: right; /* Right-aligned text */
left: 0;
padding-right: 6px; /* Space between label and grid */
top: calc(var(--controls-height) + 20px + var(--row-index) * var(--cell-size) + (var(--cell-size) / 2)); /* Positions based on row index */
transform: translateY(-50%); /* Vertically centers the label */
}
/* Specific styles for column labels (above the grid) */
.col-label {
width: var(--cell-size); /* Matches cell width */
text-align: center; /* Centers the label text */
top: calc(var(--controls-height) + 20px - 3px - 14px); /* Positions above grid */
left: calc(var(--label-width) + var(--col-index) * var(--cell-size)); /* Positions based on column index */
}
/* Styles the symbol values table container */
#symbolValues {
margin-top: 20px; /* Space above the table */
background-color: #fff; /* White background */
padding: 15px; /* Internal padding */
border-radius: 8px; /* Rounded corners */
box-shadow: 0 0 5px rgba(0,0,0,0.1); /* Subtle shadow */
}
/* Styles the table inside the symbol values container */
#symbolValues table {
width: 100%; /* Full width of the container */
border-collapse: collapse; /* Removes gaps between cells */
margin-top: 10px; /* Space above the table */
}
/* Styles table headers and cells in symbol values table */
#symbolValues th, #symbolValues td {
border: 1px solid #ddd; /* Light border for cells */
padding: 8px; /* Internal padding */
text-align: left; /* Left-aligned text */
}
/* Styles table headers specifically */
#symbolValues th {
background-color: #0288d1; /* Blue background */
color: white; /* White text */
}
/* Alternating row colors for readability */
#symbolValues tr:nth-child(even) td.data {
background-color: #fffde7; /* Light yellow for even rows */
}
#symbolValues tr:nth-child(odd) td.data {
background-color: #f5f5f5; /* Light gray for odd rows */
}
/* Specific column styling in symbol values table */
#symbolValues td.network-id {
background-color: #e0f7fa; /* Light cyan for network ID */
}
#symbolValues td.symbol {
background-color: #e6ffe6; /* Light green for symbol names */
}
/* Styles for the symbol and data type context menus */
#symbolMenu, #dataTypeMenu {
position: absolute; /* Positions at click location */
background-color: #fff; /* White background */
border: 1px solid #ccc; /* Light border */
box-shadow: 0 2px 5px rgba(0,0,0,0.2); /* Shadow for depth */
z-index: 1000; /* Ensures menu appears above other elements */
padding: 5px; /* Internal padding */
display: none; /* Hidden by default */
min-width: 150px; /* Minimum width for readability */
}
/* Styles for items within the menus */
.menu-item {
padding: 5px 10px; /* Padding for clickable area */
cursor: pointer; /* Indicates interactivity */
}
.menu-item:hover {
background-color: #e0e0e0; /* Gray hover effect */
}
/* Styles for data entry sections in the data type menu */
.value-entry {
margin-bottom: 10px; /* Space between entries */
}
.value-label {
font-weight: bold; /* Bold labels */
margin-right: 5px; /* Space before input */
}
.value-pair {
display: flex; /* Flexbox for alignment */
align-items: center;/* Vertically centers items */
margin: 5px 0; /* Vertical spacing */
}
.value-pair select, .value-pair input, .value-pair span {
margin-right: 5px; /* Space between elements */
font-size: 12px; /* Smaller font for compactness */
}
/* General button styling */
button {
padding: 5px 10px; /* Padding for size */
margin-right: 5px; /* Space between buttons */
background-color: #4CAF50; /* Green background */
color: white; /* White text */
border: none; /* No border */
cursor: pointer; /* Indicates clickability */
}
button:hover {
background-color: #45a049; /* Darker green on hover */
}
/* Specific styling for delete buttons */
.delete-button {
background-color: #ff0000; /* Red background */
}
.delete-button:hover {
background-color: #cc0000; /* Darker red on hover */
}
/* Styling for input fields (e.g., resize inputs) */
input {
padding: 5px; /* Internal padding */
margin-right: 10px;/* Space after input */
width: 60px; /* Fixed width */
}
/* Controls section for each network (resize, delete) */
.network-controls {
position: absolute; /* Positions above the table */
top: 0;
left: 0;
display: flex; /* Flexbox for horizontal layout */
align-items: center;/* Vertically centers items */
padding: 5px 0; /* Vertical padding */
z-index: 10; /* Ensures visibility over table */
}
/* Label displaying the network number */
.network-label {
position: absolute; /* Positioned above controls */
top: -20px; /* Offset above the wrapper */
left: 0;
font-weight: bold; /* Bold text */
width: 150px; /* Fixed width */
white-space: nowrap; /* Prevents wrapping */
overflow: hidden; /* Hides overflow */
text-overflow: ellipsis; /* Adds ellipsis for long text */
}
/* Styles for vertical bars connecting ladder rungs */
.vertical-bar {
position: absolute; /* Positioned over the grid */
z-index: 100; /* Ensures visibility */
}
@media (max-width: 600px) {
.row-label, .col-label {
font-size: 12px; /* Smaller font size */
}
.row-label {
left: 0;
padding-right: 6px; /* Adjusted padding */
}
.col-label {
top: calc(var(--controls-height) + 20px - 3px - 12px); /* Adjusted position */
}
input {
width: 50px; /* Smaller input width */
}
.network-label {
width: 120px; /* Reduced width */
}
#symbolValues table {
font-size: 12px; /* Smaller font */
}
#symbolValues th, #symbolValues td {
padding: 5px; /* Reduced padding */
}
/* Converts table to block layout for mobile */
#symbolValues table, #symbolValues thead, #symbolValues tbody, #symbolValues th, #symbolValues td, #symbolValues tr {
display: block;
}
#symbolValues thead {
display: none; /* Hides headers */
}
#symbolValues tr {
margin-bottom: 15px; /* Space between rows */
}
#symbolValues td {
border: none; /* Removes borders */
position: relative; /* For pseudo-element positioning */
padding-left: 50%; /* Space for labels */
text-align: left; /* Left-aligned text */
}
/* Adds labels before each cell using data-label attribute */
#symbolValues td::before {
content: attr(data-label);
position: absolute;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
font-weight: bold;
}
#symbolValues td.data {
word-wrap: break-word; /* Allows text wrapping */
}
}
/* Animation for blinking effect to highlight elements */
.blinking {
animation: backgroundBlink 1s infinite; /* Blinks background */
}
.blinking svg [stroke] {
animation: strokeBlink 1s infinite; /* Blinks SVG stroke */
}
.blinking svg text {
animation: fillBlink 1s infinite; /* Blinks SVG text */
}
@keyframes backgroundBlink {
0% { background-color: #fff; }
50% { background-color: lightgray; } /* Light red at peak */
100% { background-color: #fff; }
}
@keyframes strokeBlink {
0% { stroke: gray; }
50% { stroke: black; }
100% { stroke: gray; }
}
@keyframes fillBlink {
0% { fill: gray; }
50% { fill: black; }
100% { fill: gray; }
}
tr.blinking td {
animation: rowBlink 1s infinite; /* Blinks entire row */
}
@keyframes rowBlink {
0% { background-color: #fff; }
50% { background-color: lightgray; }
100% { background-color: #fff; }
}
/* Highlights active cells (e.g., during WebSocket updates) */
td.active {
background-color: yellow; /* Yellow background */
}
</style>
</head>
<body>
<!-- Controls for managing networks and actions -->
<div id="controls">
<!-- Button to add a new network -->
<button onclick="addNetwork()">Add Network</button>
<!-- Button to save networks (via WebSocket or file) -->
<button onclick="saveNetworks()">Save</button>
<!-- Hidden file input for loading networks from JSON -->
<input type="file" id="loadFile" accept=".json" style="display: none;" onchange="loadNetworks(event)">
<!-- Button to trigger loading (file or server) -->
<button onclick="initiateLoad()">Load</button>
<!-- Button to undo the last action -->
<button onclick="undo()">Undo</button>
<!-- Button to redo an undone action -->
<button onclick="redo()">Redo</button>
<!-- WebSocket connection status indicator -->
<div id="ws-indicator" style="display: inline-block; width: 20px; height: 20px; border-radius: 50%; background-color: red; margin-left: 10px;"></div>
<!-- Start/Stop button -->
<button id="start-stop-button" style="background-color: green; margin-left: 10px;">Start</button>
</div>
<!-- Container where all network diagrams are dynamically added -->
<div id="networks-container"></div>
<!-- Context menu for selecting ladder logic symbols -->
<div id="symbolMenu"></div>
<!-- Context menu for setting data types and values -->
<div id="dataTypeMenu"></div>
<!-- Table displaying all symbols and their associated data -->
<div id="symbolValues"></div>
<script>
// List of supported data types for symbol data entries
const dataTypes = [
"NONE", "M", "Q", "I", "Cd", "Cr", "Td", "Tr", "IW", "QW", "C", "T",
"D", "CSTR", "REAL", "MS", "10MS", "100MS",
"SEC", "MIN", "K"
];
// Definitions of ladder logic symbols with their properties
const symbols = {
"NOP": { // No Operation symbol
cells: 1, // Occupies 1 cell
dataEntries: [], // No data required
svg: `<svg viewBox="0 0 60 60"><rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2"/><text x="30" y="25" font-size="12" text-anchor="middle" fill="gray">NOP</text></svg>`,
pins: [{ left: false, right: false }] // No connections
},
"CONN": { // Connection line symbol
cells: 1,
dataEntries: [],
svg: `<svg viewBox="0 0 60 60"><line x1="0" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2"/></svg>`,
pins: [{ left: true, right: true }] // Connects left and right
},
"NEG": { // Negation symbol
cells: 1,
dataEntries: [],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">NEG</text></svg>`,
pins: [{ left: true, right: true }]
},
"NO": { // Normally Open contact
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["I", "Q", "M", "D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60"><line x1="0" y1="30" x2="20" y2="30" stroke="gray" stroke-width="2"/><line x1="20" y1="20" x2="20" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="20" x2="40" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2"/></svg>`,
pins: [{ left: true, right: true }]
},
"NC": { // Normally Closed contact
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["I", "Q", "M", "D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60"><line x1="0" y1="30" x2="20" y2="30" stroke="gray" stroke-width="2"/><line x1="20" y1="20" x2="20" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="20" x2="40" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2"/><line x1="20" y1="40" x2="40" y2="20" stroke="gray" stroke-width="2"/></svg>`,
pins: [{ left: true, right: true }]
},
"RE": { // Rising Edge contact
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["I", "Q", "M", "D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60"><line x1="0" y1="30" x2="20" y2="30" stroke="gray" stroke-width="2"/><line x1="20" y1="20" x2="20" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="20" x2="40" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2"/><text x="30" y="35" font-size="12" text-anchor="middle" fill="gray">P</text></svg>`,
pins: [{ left: true, right: true }]
},
"FE": { // Falling Edge contact
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["I", "Q", "M", "D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60"><line x1="0" y1="30" x2="20" y2="30" stroke="gray" stroke-width="2"/><line x1="20" y1="20" x2="20" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="20" x2="40" y2="40" stroke="gray" stroke-width="2"/><line x1="40" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2"/><text x="30" y="35" font-size="12" text-anchor="middle" fill="gray">N</text></svg>`,
pins: [{ left: true, right: true }]
},
"COIL": { // Standard coil
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["M", "Q"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg3" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs3" /> <line x1="0" y1="30" x2="20.790773" y2="30" stroke="#808080" stroke-width="2" id="line1" /> <text x="20" y="35" font-size="16" fill="gray" id="text1">(</text> <text x="35" y="35" font-size="16" fill="gray" id="text3">)</text> <line x1="38.945633" y1="30" x2="60" y2="30" stroke="#808080" stroke-width="2" id="line3" /></svg>`,
pins: [{ left: true, right: true }]
},
"COILL": { // Latch (Set) coil
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["M", "Q"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg3" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs3" /> <line x1="0" y1="30" x2="20.790773" y2="30" stroke="#808080" stroke-width="2" id="line1" /> <text x="20" y="35" font-size="16" fill="gray" id="text1">(</text> <text x="30.077431" y="34.868206" font-size="12px" text-anchor="middle" fill="#808080" id="text2">L</text> <text x="35" y="35" font-size="16" fill="gray" id="text3">)</text> <line x1="38.945633" y1="30" x2="60" y2="30" stroke="#808080" stroke-width="2" id="line3" /></svg>`,
pins: [{ left: true, right: true }]
},
"COILU": { // Unlatch (Reset) coil
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["M", "Q"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg3" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs3" /> <line x1="0" y1="30" x2="20.790773" y2="30" stroke="#808080" stroke-width="2" id="line1" /> <text x="20" y="35" font-size="16" fill="gray" id="text1">(</text> <text x="30.077431" y="34.868206" font-size="12px" text-anchor="middle" fill="#808080" id="text2">U</text> <text x="35" y="35" font-size="16" fill="gray" id="text3">)</text> <line x1="38.945633" y1="30" x2="60" y2="30" stroke="#808080" stroke-width="2" id="line3" /></svg>`,
pins: [{ left: true, right: true }]
},
"TON": { // On-Delay Timer
cells: 2,
dataEntries: [
{ name: "timer", allowedTypes: ["T"] },
{ name: "basetime", allowedTypes: ["MS", "10MS", "100MS", "SEC", "MIN"] }
],
svg: `<svg viewBox="0 0 60 120" version="1.1" id="svg4" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs4" /> <rect x="10" y="10" width="40" height="100" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13" y="40" font-size="10px" fill="#808080" id="text2">IN</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="34.472816" y="39.736408" font-size="10px" fill="#808080" id="text3">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line3" /> <text x="35.395386" y="99.868202" font-size="10px" fill="#808080" id="text4">Q1</text> <line x1="50" y1="90.527176" x2="60" y2="90.527176" stroke="#808080" stroke-width="2" id="line4" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.658978" y="10.868204" /> <text x="30.049425" y="23.522242" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">TON</text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true }
]
},
"TOF": { // Off-Delay Timer
cells: 2,
dataEntries: [
{ name: "timer", allowedTypes: ["T"] },
{ name: "basetime", allowedTypes: ["MS", "10MS", "100MS", "SEC", "MIN"] }
],
svg: `<svg viewBox="0 0 60 120" version="1.1" id="svg4" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs4" /> <rect x="10" y="10" width="40" height="100" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13" y="40" font-size="10px" fill="#808080" id="text2">IN</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="34.472816" y="39.736408" font-size="10px" fill="#808080" id="text3">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line3" /> <text x="35.395386" y="99.868202" font-size="10px" fill="#808080" id="text4">Q1</text> <line x1="50" y1="90.527176" x2="60" y2="90.527176" stroke="#808080" stroke-width="2" id="line4" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.658978" y="10.868204" /> <text x="30.049425" y="23.522242" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">TOF</text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true }
]
},
"TP": { // Pulse Timer
cells: 2,
dataEntries: [
{ name: "timer", allowedTypes: ["T"] },
{ name: "basetime", allowedTypes: ["MS", "10MS", "100MS", "SEC", "MIN"] }
],
svg: `<svg viewBox="0 0 60 120" version="1.1" id="svg4" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs4" /> <rect x="10" y="10" width="40" height="100" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13" y="40" font-size="10px" fill="#808080" id="text2">IN</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="34.472816" y="39.736408" font-size="10px" fill="#808080" id="text3">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line3" /> <text x="35.395386" y="99.868202" font-size="10px" fill="#808080" id="text4">Q1</text> <line x1="50" y1="90.527176" x2="60" y2="90.527176" stroke="#808080" stroke-width="2" id="line4" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.658978" y="10.868204" /> <text x="30.049425" y="23.522242" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">TP</text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true }
]
},
"CTU": { // Up Counter
cells: 2,
dataEntries: [
{ name: "counter", allowedTypes: ["C"] },
{ name: "preset value", allowedTypes: ["NONE"] }
],
svg: `<svg viewBox="0 0 60 120" version="1.1" id="svg5" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs5" /> <rect x="10" y="10" width="40" height="100" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13" y="40" font-size="10px" fill="#808080" id="text2">CU</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="34.341022" y="39.868206" font-size="10px" fill="#808080" id="text4">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line4" /> <text x="35" y="100" font-size="10" fill="gray" id="text5">Q1</text> <line x1="50" y1="90.263588" x2="60" y2="90.263588" stroke="#808080" stroke-width="2" id="line5" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.672158" y="10.876442" /> <text x="30.062603" y="23.530479" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">CTU</text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true }
]
},
"CTD": { // Down Counter
cells: 2,
dataEntries: [
{ name: "counter", allowedTypes: ["C"] },
{ name: "preset value", allowedTypes: ["NONE"] }
],
svg: `<svg viewBox="0 0 60 120" version="1.1" id="svg5" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs5" /> <rect x="10" y="10" width="40" height="100" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13" y="40" font-size="10px" fill="#808080" id="text2">CU</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="34.341022" y="39.868206" font-size="10px" fill="#808080" id="text4">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line4" /> <text x="35" y="100" font-size="10" fill="gray" id="text5">Q1</text> <line x1="50" y1="90.263588" x2="60" y2="90.263588" stroke="#808080" stroke-width="2" id="line5" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.672158" y="10.876442" /> <text x="30.062603" y="23.530479" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">CTD</text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true }
]
},
"MOV": { // Move operation
cells: 1,
dataEntries: [
{ name: "from", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "to", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">MOV</text></svg>`,
pins: [{ left: true, right: true }]
},
"SUB": { // Subtraction operation
cells: 3,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 180" version="1.1" id="svg5" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs5" /> <rect x="10" y="10" width="40" height="160" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13.023065" y="40" font-size="10px" fill="#808080" id="text2">IN</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="33.790775" y="40" font-size="10px" fill="#808080" id="text3">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line3" /> <text x="35" y="100" font-size="10" fill="gray" id="text4">Q1</text> <line x1="50.197693" y1="90.593079" x2="60.197693" y2="90.593079" stroke="#808080" stroke-width="2" id="line4" /> <text x="35" y="160" font-size="10" fill="gray" id="text5">Q2</text> <line x1="50" y1="151.18616" x2="60" y2="151.18616" stroke="#808080" stroke-width="2" id="line5" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.403625" y="10.835256" /> <text x="29.794073" y="23.489292" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000"><tspan style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:sans-serif;-inkscape-font-specification:sans-serif" id="tspan5">SUB</tspan></text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true },
{ left: false, right: true }
]
},
"ADD": { // Addition operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">ADD</text></svg>`,
pins: [{ left: true, right: true }]
},
"MUL": { // Multiplication operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">MUL</text></svg>`,
pins: [{ left: true, right: true }]
},
"DIV": { // Division operation
cells: 2,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 120" version="1.1" id="svg4" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs4" /> <rect x="10" y="10" width="40" height="100" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <text x="13" y="40" font-size="10px" fill="#808080" id="text2">IN</text> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line2" /> <text x="34.472816" y="40" font-size="10px" fill="#808080" id="text3">Q0</text> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line3" /> <text x="35" y="100" font-size="10" fill="gray" id="text4">Q1</text> <line x1="50" y1="90.527176" x2="60" y2="90.527176" stroke="#808080" stroke-width="2" id="line4" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.851729" y="10.906096" /> <text x="30.242176" y="23.560133" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">DIV</text></svg>`,
pins: [
{ left: true, right: true },
{ left: false, right: true }
]
},
"MOD": { // Modulus operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">MOD</text></svg>`,
pins: [{ left: true, right: true }]
},
"SHL": { // Shift Left operation
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">SHL</text></svg>`,
pins: [{ left: true, right: true }]
},
"SHR": { // Shift Right operation
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">SHR</text></svg>`,
pins: [{ left: true, right: true }]
},
"ROL": { // Rotate Left operation
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">ROL</text></svg>`,
pins: [{ left: true, right: true }]
},
"ROR": { // Rotate Right operation
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">ROR</text></svg>`,
pins: [{ left: true, right: true }]
},
"AND": { // Logical AND operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">AND</text></svg>`,
pins: [{ left: true, right: true }]
},
"OR": { // Logical OR operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">OR</text></svg>`,
pins: [{ left: true, right: true }]
},
"XOR": { // Logical XOR operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">XOR</text></svg>`,
pins: [{ left: true, right: true }]
},
"NOT": { // Logical NOT operation
cells: 1,
dataEntries: [
{ name: "value", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "result", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">NOT</text></svg>`,
pins: [{ left: true, right: true }]
},
"EQ": { // Equal comparison
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">EQ</text></svg>`,
pins: [{ left: true, right: true }]
},
"GT": { // Greater Than comparison
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">GT</text></svg>`,
pins: [{ left: true, right: true }]
},
"GE": { // Greater or Equal comparison
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">GE</text></svg>`,
pins: [{ left: true, right: true }]
},
"LT": { // Less Than comparison
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">LT</text></svg>`,
pins: [{ left: true, right: true }]
},
"LE": { // Less or Equal comparison
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">LE</text></svg>`,
pins: [{ left: true, right: true }]
},
"NE": { // Not Equal comparison
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">NE</text></svg>`,
pins: [{ left: true, right: true }]
},
"TMOV": { // Table Move operation
cells: 1,
dataEntries: [
{ name: "value1", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "value2", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] },
{ name: "to", allowedTypes: ["D", "T", "C", "IW", "K", "QW"] }
],
svg: `<svg viewBox="0 0 60 60" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <defs id="defs2" /> <line x1="0" y1="30" x2="10" y2="30" stroke="gray" stroke-width="2" id="line1" /> <rect x="10" y="10" width="40" height="40" fill="none" stroke="gray" stroke-width="2" id="rect1" /> <line x1="50" y1="30" x2="60" y2="30" stroke="gray" stroke-width="2" id="line2" /> <rect style="opacity:0.363002;fill:#999999" id="rect4" width="38.484348" height="17.133444" x="10.822076" y="11.023065" /> <text x="30.212521" y="23.677101" font-size="12px" text-anchor="middle" fill="gray" id="text1" style="fill:#000000">TMOV</text></svg>`,
pins: [{ left: true, right: true }]
}
};
// Validates if a string is a valid unsigned 32-bit integer
function isValidUInt32(str) {
const num = parseInt(str, 10);
return /^\d+$/.test(str) && !isNaN(num) && num >= 0 && num <= 4294967295;
}
// Validates Q or I type values (format "m.p" where m and p are 0-255)
function isValidQorI(value) {
const parts = value.split('.');
if (parts.length !== 2) return false;
return parts.every(part => {
const num = parseInt(part, 10);
return /^\d+$/.test(part) && !isNaN(num) && num >= 0 && num <= 255;
});
}
// Validates real number format (e.g., "1.23", "-4.5e2")
function isValidReal(value) {
return /^[-+]?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?$/.test(value);
}
// Validates string values (accepts any string for CSTR)
function isValidCSTR(value) {
return true;
}
// Validates input value based on its data type
function validateValue(type, value) {
switch (type) {
case "NONE":
case "M":
case "Cd":
case "Cr":
case "Td":
case "Tr":
case "IW":
case "QW":
case "C":
case "T":
case "D":
case "MS":
case "10MS":
case "100MS":
case "SEC":
case "MIN":
case "K":
return isValidUInt32(value);
case "Q":
case "I":
return isValidQorI(value);
case "CSTR":
return isValidCSTR(value);
case "REAL":
return isValidReal(value);
default:
return false;
}
}
// Returns the default value based on data type
function getDefaultValue(type) {
switch (type) {
case "Q":
case "I":
return "0.0";
case "CSTR":
return "";
case "REAL":
return "0.0";
default:
return "0";
}
}
// Constants defining maximum limits for the editor
const MAX_ROWS = 100; // Maximum rows per network
const MAX_COLS = 100; // Maximum columns per network
const MAX_NETWORKS = 10; // Maximum number of networks
// List of coil-type symbols
const coilSymbols = ["COIL", "COILL", "COILU"];
// Global variables for editor state
let networks = []; // Array of all networks
let networkCounter = 0; // Counter for assigning network IDs
let history = []; // History stack for undo/redo
let historyIndex = -1; // Current position in history
let currentMenu = null; // Tracks the currently open menu
let sameDimensionsFlag = false; // Flag to enforce same dimensions across networks
// Class representing a single ladder logic network
class Network {
constructor(rows, cols, id = null) {
this.id = id !== null ? id : networkCounter++; // Assigns unique ID
this.rows = rows; // Number of rows in the grid
this.cols = cols; // Number of columns in the grid
// Initializes grid with NOP symbols
this.networkData = Array(rows).fill().map(() => Array(cols).fill().map(() => ({
symbol: "NOP",
bar: false, // Indicates vertical bar presence
data: [] // Data entries for the symbol
})));
this.createNetworkElement(); // Creates HTML elements for the network
}
// Creates the DOM elements for the network
createNetworkElement() {
const container = document.getElementById('networks-container');
const wrapper = document.createElement('div');
wrapper.className = 'network-wrapper';
wrapper.id = `network-container-${this.id}`;
const label = document.createElement('div');
label.className = 'network-label';
label.textContent = `Network ${this.id}`;
const controls = document.createElement('div');
controls.className = 'network-controls';
const rowsLabel = document.createElement('label');
rowsLabel.textContent = 'Rows: ';
const rowsInput = document.createElement('input');
rowsInput.type = 'number';
rowsInput.id = `rows-${this.id}`;
rowsInput.value = this.rows;
rowsInput.min = '1';
rowsLabel.appendChild(rowsInput);
const colsLabel = document.createElement('label');
colsLabel.textContent = 'Cols: ';
const colsInput = document.createElement('input');
colsInput.type = 'number';
colsInput.id = `cols-${this.id}`;
colsInput.value = this.cols;
colsInput.min = '1';
colsLabel.appendChild(colsInput);
const resizeButton = document.createElement('button');
resizeButton.textContent = 'Resize';
resizeButton.onclick = () => resizeNetwork(this.id);
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-button';
deleteButton.textContent = 'Delete';
deleteButton.onclick = () => deleteOrClearNetwork(this.id);
controls.appendChild(rowsLabel);
controls.appendChild(colsLabel);
controls.appendChild(resizeButton);
controls.appendChild(deleteButton);
const table = document.createElement('table');
table.id = `network-${this.id}`;
table.className = 'network-table';
wrapper.appendChild(label);
wrapper.appendChild(controls);
wrapper.appendChild(table);
container.appendChild(wrapper);
}
// Clears the network by resetting all cells to NOP
clear() {
this.networkData = Array(this.rows).fill().map(() => Array(this.cols).fill().map(() => ({
symbol: "NOP",
bar: false,
data: []
})));
this.renderNetwork();
renderSymbolValues();
}
// Resizes the network grid, preserving data where possible
resize(newRows, newCols) {
const oldRows = this.rows;
const oldCols = this.cols;
let truncateWarning = false;
for (let i = 0; i < oldRows; i++) {
for (let j = 0; j < oldCols; j++) {
const cell = this.networkData[i][j];
if (cell.symbol !== "NOP" && cell.symbol !== "occupied") {
const symbol = symbols[cell.symbol];
if (i + symbol.cells > newRows || j >= newCols) {
truncateWarning = true;
}
}
}
}
if (truncateWarning) {
showToast("Warning: Some symbols may be removed due to smaller dimensions.");
}
this.rows = newRows;
this.cols = newCols;
const newNetworkData = Array(newRows).fill().map(() => Array(newCols).fill().map(() => ({
symbol: "NOP",
bar: false,
data: []
})));
for (let i = 0; i < Math.min(oldRows, newRows); i++) {
for (let j = 0; j < Math.min(oldCols, newCols); j++) {
const cell = this.networkData[i][j];
if (cell.symbol !== "NOP" && cell.symbol !== "occupied") {
const symbol = symbols[cell.symbol];
if (i + symbol.cells <= newRows) {
newNetworkData[i][j] = { ...cell };
for (let k = 1; k < symbol.cells && i + k < newRows; k++) {
newNetworkData[i + k][j] = {
symbol: "occupied",
bar: false,
data: []
};
}
}
} else {
newNetworkData[i][j] = { ...cell };
}
}
}
this.networkData = newNetworkData;