nicoaspra commited on
Commit
c256b8e
·
1 Parent(s): df164c4

change footer and NC viewer commented out

Browse files
Files changed (3) hide show
  1. UI_gradio.py +0 -50
  2. gcode_analyzer_ui.py +15 -2
  3. gcode_viewer.html +99 -0
UI_gradio.py DELETED
@@ -1,50 +0,0 @@
1
- # gcode_analyzer_ui.py
2
-
3
- import gradio as gr
4
- from python_gcode_checker import run_checks
5
- from settings_report_details import generate_detailed_report
6
-
7
- def analyze_gcode(gcode, depth_max=0.1):
8
- errors, warnings = run_checks(gcode, depth_max)
9
- error_count = len(errors)
10
- warning_count = len(warnings)
11
- config_report = generate_detailed_report(gcode)
12
- return (
13
- f"Errors: {error_count}\n\n{format_issues(errors)}",
14
- f"Warnings: {warning_count}\n\n{format_issues(warnings)}",
15
- config_report,
16
- )
17
-
18
- def format_issues(issues):
19
- formatted = []
20
- for line_num, message in issues:
21
- if line_num > 0:
22
- formatted.append(f"Line {line_num}: {message}")
23
- else:
24
- formatted.append(message)
25
- return "\n".join(formatted)
26
-
27
- # Create a Gradio Interface layout
28
- app = gr.Interface(
29
- fn=analyze_gcode,
30
- inputs=[
31
- gr.Textbox(lines=20, label="Input G-code", placeholder="Enter G-code here..."),
32
- gr.Number(value=0.1, label="Maximum Depth of Cut"),
33
- ],
34
- outputs=[
35
- gr.Textbox(label="Errors", interactive=False),
36
- gr.Textbox(label="Warnings", interactive=False),
37
- gr.Textbox(label="Configuration Settings", interactive=False),
38
- ],
39
- description="""
40
- ### G-code Programming Assistant (v0.1)
41
-
42
- Welcome to the G-code Assistant! This tool is solely for educational purposes, helping you verify and analyze your G-code for potential errors and warnings before actually running it on your machine.
43
-
44
- **Note:** This tool is limited to simple carving operations on a CNC milling machine.
45
-
46
- This is a beta version, and you're free to use it for checking your G-codes. If you encounter any issues or unexpected behavior, please contact the developer at **[email protected]**.
47
- """,
48
- )
49
-
50
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
gcode_analyzer_ui.py CHANGED
@@ -66,5 +66,18 @@ if st.button("Analyze G-code"):
66
  config_df = parse_config_report(config_report)
67
  st.table(config_df)
68
 
69
- st.markdown("---")
70
- st.markdown("Developed by **Aspra, N.**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  config_df = parse_config_report(config_report)
67
  st.table(config_df)
68
 
69
+ # # Embed NC Viewer for G-code visualization
70
+ # st.subheader("G-code Visualization (NC Viewer)")
71
+ # gcode_query_param = st.query_params.get("gcode", gcode_input) # Replace deprecated method
72
+ # ncviewer_url = f"https://ncviewer.com/?code={gcode_query_param}"
73
+ # st.markdown(
74
+ # f'<iframe src="{ncviewer_url}" width="100%" height="600" frameborder="0"></iframe>',
75
+ # unsafe_allow_html=True
76
+ # )
77
+
78
+ st.markdown("""
79
+ ---
80
+ <div style="text-align: center; font-size: small;">
81
+ Developed by <strong>Aspra, N.</strong> | © 2024 All Rights Reserved
82
+ </div>
83
+ """, unsafe_allow_html=True)
gcode_viewer.html ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>G-code Viewer</title>
6
+ <style>
7
+ body {
8
+ margin: 0;
9
+ overflow: hidden;
10
+ }
11
+ canvas {
12
+ display: block;
13
+ }
14
+ </style>
15
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
16
+ </head>
17
+ <body>
18
+ <script>
19
+ // Set up the scene, camera, and renderer
20
+ const scene = new THREE.Scene();
21
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
22
+ const renderer = new THREE.WebGLRenderer();
23
+ renderer.setSize(window.innerWidth, window.innerHeight);
24
+ document.body.appendChild(renderer.domElement);
25
+
26
+ // Add a simple grid for reference
27
+ const gridHelper = new THREE.GridHelper(200, 50);
28
+ scene.add(gridHelper);
29
+
30
+ // Load and parse G-code
31
+ function loadGCode(gcode) {
32
+ const material = new THREE.LineBasicMaterial({ color: 0x00ff00 });
33
+ const points = [];
34
+ const lines = gcode.split("\n");
35
+
36
+ let currentX = 0, currentY = 0, currentZ = 0;
37
+ let isRelative = false; // Tracks whether positioning is G90 (absolute) or G91 (relative)
38
+
39
+ lines.forEach((line) => {
40
+ line = line.trim();
41
+ if (line.startsWith("G90")) {
42
+ isRelative = false; // Absolute positioning
43
+ } else if (line.startsWith("G91")) {
44
+ isRelative = true; // Incremental positioning
45
+ }
46
+
47
+ const matchX = line.match(/X([-+]?\d*\.?\d+)/);
48
+ const matchY = line.match(/Y([-+]?\d*\.?\d+)/);
49
+ const matchZ = line.match(/Z([-+]?\d*\.?\d+)/);
50
+
51
+ let newX = currentX;
52
+ let newY = currentY;
53
+ let newZ = currentZ;
54
+
55
+ if (matchX) {
56
+ const deltaX = parseFloat(matchX[1]);
57
+ newX = isRelative ? currentX + deltaX : deltaX;
58
+ }
59
+ if (matchY) {
60
+ const deltaY = parseFloat(matchY[1]);
61
+ newY = isRelative ? currentY + deltaY : deltaY;
62
+ }
63
+ if (matchZ) {
64
+ const deltaZ = parseFloat(matchZ[1]);
65
+ newZ = isRelative ? currentZ + deltaZ : deltaZ;
66
+ }
67
+
68
+ points.push(new THREE.Vector3(newX, newY, newZ));
69
+
70
+ currentX = newX;
71
+ currentY = newY;
72
+ currentZ = newZ;
73
+ });
74
+
75
+ const geometry = new THREE.BufferGeometry().setFromPoints(points);
76
+ const line = new THREE.Line(geometry, material);
77
+ scene.add(line);
78
+ }
79
+
80
+ // Add camera controls
81
+ camera.position.set(0, 50, 200);
82
+ camera.lookAt(0, 0, 0);
83
+
84
+ // Animation loop
85
+ function animate() {
86
+ requestAnimationFrame(animate);
87
+ renderer.render(scene, camera);
88
+ }
89
+ animate();
90
+
91
+ // Load G-code from global variable
92
+ if (window.gcode) {
93
+ loadGCode(window.gcode);
94
+ } else {
95
+ console.error("No G-code provided");
96
+ }
97
+ </script>
98
+ </body>
99
+ </html>