File size: 3,059 Bytes
13b4e72 b5a4200 c77aacd 0664784 13b4e72 c77aacd b5a4200 0664784 b5a4200 13b4e72 b5a4200 0664784 b5a4200 0664784 b5a4200 0664784 c77aacd 0664784 b5a4200 13b4e72 b5a4200 13b4e72 b5a4200 13b4e72 b5a4200 13b4e72 b5a4200 13b4e72 b5a4200 c77aacd c256b8e |
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 |
# app.py
import streamlit as st
import pandas as pd
from streamlit_ace import st_ace
from python_gcode_checker import run_checks
from settings_report_details import generate_detailed_report
def analyze_gcode(gcode, depth_max=0.1):
errors, warnings = run_checks(gcode, depth_max)
config_report = generate_detailed_report(gcode)
return errors, warnings, config_report
def format_issues(issues):
formatted = []
for line_num, message in issues:
if line_num > 0:
formatted.append(f"Line {line_num}: {message}")
else:
formatted.append(message) # No "Line 0" for general warnings/errors
return formatted
def parse_config_report(config_report):
config_lines = config_report.strip().split('\n')
config_data = {"Setting": [], "Value": []}
for line in config_lines:
if ':' in line:
key, value = line.split(':', 1)
config_data["Setting"].append(key.strip())
config_data["Value"].append(value.strip())
return pd.DataFrame(config_data)
st.title("G-code Programming Assistant (v0.1)")
st.markdown("""
Welcome to the G-code Assistant! This tool helps you verify and analyze your G-code for potential errors and warnings before running it on your machine.
**Note:** This tool is limited to simple carving operations on a CNC milling machine.
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 **nico.aspra@bicol-u.edu.ph**.
""")
depth_max = st.number_input("Maximum Depth of Cut", min_value=0.0, value=0.1, step=0.1, format="%.1f")
# Use Ace editor for G-code input with line numbering
gcode_input = st_ace(language='text', theme='cobalt', placeholder="Enter G-code here...", font_size=14, height=300)
if st.button("Analyze G-code"):
errors, warnings, config_report = analyze_gcode(gcode_input, depth_max)
st.subheader(f"Errors ({len(errors)})")
if errors:
for message in format_issues(errors):
st.error(message)
else:
st.success("No errors found.")
st.subheader(f"Warnings ({len(warnings)})")
if warnings:
for message in format_issues(warnings):
st.warning(message)
else:
st.info("No warnings found.")
st.subheader("Configuration Settings")
config_df = parse_config_report(config_report)
st.table(config_df)
# # Embed NC Viewer for G-code visualization
# st.subheader("G-code Visualization (NC Viewer)")
# gcode_query_param = st.query_params.get("gcode", gcode_input) # Replace deprecated method
# ncviewer_url = f"https://ncviewer.com/?code={gcode_query_param}"
# st.markdown(
# f'<iframe src="{ncviewer_url}" width="100%" height="600" frameborder="0"></iframe>',
# unsafe_allow_html=True
# )
st.markdown("""
---
<div style="text-align: center; font-size: small;">
Developed by <strong>Aspra, N.</strong> | © 2024 All Rights Reserved
</div>
""", unsafe_allow_html=True) |