-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodePreviewWindow.pde
More file actions
98 lines (78 loc) · 2.58 KB
/
CodePreviewWindow.pde
File metadata and controls
98 lines (78 loc) · 2.58 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
import controlP5.*;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
public class CodePreviewWindow extends PApplet {
ControlP5 cp5;
Textarea codeArea;
String codeText;
public CodePreviewWindow(String codeText) {
this.codeText = codeText;
}
public void settings() {
size(800, 500);
}
public void setup() {
surface.setTitle("Generated Code Preview");
surface.setLocation(150, 150);
cp5 = new ControlP5(this);
codeArea = cp5.addTextarea("codeArea")
.setText(codeText)
.setPosition(20, 20)
.setSize(760, 400)
.setFont(createFont("Courier", 12))
.setLineHeight(14)
.setColor(color(0))
.setColorBackground(color(250))
.setColorForeground(color(200));
cp5.addButton("copyToClipboard")
.setLabel("Copy to clipboard")
.setPosition(20, 440)
.setSize(200, 30);
cp5.addButton("refreshCodePreview")
.setLabel("Refresh preview")
.setPosition(240, 440)
.setSize(200, 30);
}
public void draw() {
background(250);
cp5.draw();
}
public void updateText(String newCode) {
codeText = newCode;
codeArea.setText(codeText);
}
public void copyToClipboard() {
println("[DEBUG] copyToClipboard triggered");
String text = codeArea.getText();
println("[DEBUG] text =\n" + text);
StringSelection selection = new StringSelection(text);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
println("[DEBUG] Copied to clipboard.");
}
public String generateStrategyCode() {
String result = "// Strategy generated by StrategyEditor\n";
result += "// Total points: " + StrategyEditor.points.size() + "\n\n";
for (int i = 0; i < StrategyEditor.points.size(); i++) {
StrategyPoint p = StrategyEditor.points.get(i);
// Alignement si activé
if (p.useAlign) {
if (p.orientation.equals("CUSTOM")) {
result += "async motion.align(RobotCompass::" + p.compass + ", " + p.customAngle + ".0);\n";
} else {
result += "async motion.align(RobotCompass::" + p.compass + ", getCompassOrientation(TableCompass::" + p.orientation + "));\n";
}
}
// Appel go()
if (p.poiName != null) {
result += "async motion.go(" + p.poiName + "); // Step " + (i + 1) + " - POI " + p.poiName + "\n";
} else {
result += "async motion.go(" + int(p.x_mm) + ", " + int(p.y_mm) + "); // Step " + (i + 1) + "\n";
}
}
return result;
}
public void refreshCodePreview() {
previewWindow.updateText(generateStrategyCode());
println("[GUI] Code preview updated.");
}
}