File size: 4,103 Bytes
c3a365b
 
8161707
 
c3a365b
 
 
 
 
 
 
 
 
8161707
 
c3a365b
 
8161707
c3a365b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8161707
c3a365b
 
 
 
 
8161707
c3a365b
 
 
8161707
c3a365b
 
8161707
c3a365b
8161707
c3a365b
 
 
 
8161707
c3a365b
 
 
 
8161707
c3a365b
 
 
 
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
import streamlit as st
import json
import os

# ---- Optional: define parser directly here or import from module ----
def parse_dcm_assembly(uploaded_file):
    lines = uploaded_file.read().decode("utf-8").splitlines()
    geometry = {}
    constraints = []
    parts = []
    set_geom_map = {}
    current = {}
    label = None

    for line in lines:
        line = line.strip()
        if line.startswith("CLASS "):
            if current:
                if current["type"] == "SET":
                    parts.append({
                        "name": current.get("label", ""),
                        "member_tags": current.get("member_tags", [])
                    })
                elif current["type"] == "PLANE":
                    geometry[current["id"]] = {
                        "base_point": current.get("base_point"),
                        "normal": current.get("normal"),
                        "label": current.get("label", "")
                    }
                elif current["type"] == "WORK_PLANE":
                    tag = current.get("tag")
                    if tag in geometry:
                        geometry[tag]["label"] = current.get("label", "")
                elif current["type"] == "CONSTRAINT":
                    constraints.append({
                        "from": current.get("end_1"),
                        "to": current.get("end_2"),
                        "label": current.get("label", "")
                    })
            parts_of_line = line.split()
            current = {
                "type": parts_of_line[1],
                "id": int(parts_of_line[2])
            }
        elif line.startswith("FBASE_POINT"):
            current["base_point"] = tuple(map(float, line.split()[1:]))
        elif line.startswith("FNORMAL"):
            current["normal"] = tuple(map(float, line.split()[1:]))
        elif line.startswith("FMY_PLANE TAG"):
            current["tag"] = int(line.split()[-1])
        elif line.startswith("DCM3_TEXT_LABEL"):
            current["label"] = line.split("DCM3_TEXT_LABEL", 1)[-1].strip()
        elif line.startswith("FMEMBER TAGS"):
            current["member_tags"] = list(map(int, line.split()[2:]))
        elif line.startswith("FEND_1 TAG"):
            current["end_1"] = int(line.split()[-1])
        elif line.startswith("FEND_2 TAG"):
            current["end_2"] = int(line.split()[-1])
    if current:
        if current["type"] == "SET":
            parts.append({
                "name": current.get("label", ""),
                "member_tags": current.get("member_tags", [])
            })
        elif current["type"] == "PLANE":
            geometry[current["id"]] = {
                "base_point": current.get("base_point"),
                "normal": current.get("normal"),
                "label": current.get("label", "")
            }
        elif current["type"] == "WORK_PLANE":
            tag = current.get("tag")
            if tag in geometry:
                geometry[tag]["label"] = current.get("label", "")
        elif current["type"] == "CONSTRAINT":
            constraints.append({
                "from": current.get("end_1"),
                "to": current.get("end_2"),
                "label": current.get("label", "")
            })

    return {
        "geometry": geometry,
        "constraints": constraints,
        "parts": parts
    }

# ---- Streamlit UI and file handling ----
st.set_page_config(layout="wide")
st.title("DCM Assembly Visualizer")

file1 = st.file_uploader("Upload File A", type=["txt"])
file2 = st.file_uploader("Upload File B", type=["txt"])

parsed_files = []

if file1:
    parsed_files.append(("red", "blue", parse_dcm_assembly(file1)))
if file2:
    parsed_files.append(("purple", "orange", parse_dcm_assembly(file2)))

if parsed_files:
    os.makedirs("static", exist_ok=True)
    with open("static/parsed_data.json", "w") as f:
        json.dump({"files": parsed_files}, f, indent=2)

    st.components.v1.html(
        '<iframe src="static/index.html" width="100%" height="800" style="border:none;"></iframe>',
        height=800,
    )