Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,27 +5,30 @@ import json
|
|
| 5 |
st.set_page_config(page_title="DCM Assembly Visualizer", layout="wide")
|
| 6 |
st.title("DCM Assembly Visualizer")
|
| 7 |
|
| 8 |
-
# === Parser Function ===
|
| 9 |
def parse_dcm_assembly(uploaded_file):
|
| 10 |
-
lines = uploaded_file.read().decode().splitlines()
|
| 11 |
|
| 12 |
geometry = {}
|
| 13 |
parts = []
|
| 14 |
-
constraints =
|
| 15 |
-
current_class = None
|
| 16 |
-
current_id = None
|
| 17 |
-
tag_to_label = {}
|
| 18 |
|
| 19 |
temp_geom = {}
|
| 20 |
temp_part = {}
|
| 21 |
temp_constraint = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
for line in lines:
|
| 24 |
line = line.strip()
|
|
|
|
| 25 |
if line.startswith("CLASS"):
|
| 26 |
parts_line = line.split()
|
| 27 |
current_class = parts_line[1]
|
| 28 |
current_id = int(parts_line[2])
|
|
|
|
| 29 |
if current_class == "PLANE":
|
| 30 |
temp_geom = {"tag": current_id}
|
| 31 |
elif current_class == "WORK_PLANE":
|
|
@@ -34,39 +37,60 @@ def parse_dcm_assembly(uploaded_file):
|
|
| 34 |
temp_part = {"member_tags": []}
|
| 35 |
elif current_class == "CONSTRAINT":
|
| 36 |
temp_constraint = {}
|
| 37 |
-
elif
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
elif
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
return {
|
| 65 |
-
"geometry":
|
| 66 |
"parts": parts,
|
| 67 |
-
"constraints":
|
| 68 |
}
|
| 69 |
|
|
|
|
| 70 |
# === File Upload ===
|
| 71 |
file1 = st.file_uploader("Upload File A", type=["txt"])
|
| 72 |
file2 = st.file_uploader("Upload File B", type=["txt"])
|
|
|
|
| 5 |
st.set_page_config(page_title="DCM Assembly Visualizer", layout="wide")
|
| 6 |
st.title("DCM Assembly Visualizer")
|
| 7 |
|
|
|
|
| 8 |
def parse_dcm_assembly(uploaded_file):
|
| 9 |
+
lines = uploaded_file.read().decode("utf-8").splitlines()
|
| 10 |
|
| 11 |
geometry = {}
|
| 12 |
parts = []
|
| 13 |
+
constraints = {}
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
temp_geom = {}
|
| 16 |
temp_part = {}
|
| 17 |
temp_constraint = {}
|
| 18 |
+
current_class = None
|
| 19 |
+
current_id = None
|
| 20 |
+
|
| 21 |
+
plane_label_map = {} # tag → label (from WORK_PLANE)
|
| 22 |
+
plane_point_map = {} # tag → base point + normal
|
| 23 |
|
| 24 |
for line in lines:
|
| 25 |
line = line.strip()
|
| 26 |
+
|
| 27 |
if line.startswith("CLASS"):
|
| 28 |
parts_line = line.split()
|
| 29 |
current_class = parts_line[1]
|
| 30 |
current_id = int(parts_line[2])
|
| 31 |
+
|
| 32 |
if current_class == "PLANE":
|
| 33 |
temp_geom = {"tag": current_id}
|
| 34 |
elif current_class == "WORK_PLANE":
|
|
|
|
| 37 |
temp_part = {"member_tags": []}
|
| 38 |
elif current_class == "CONSTRAINT":
|
| 39 |
temp_constraint = {}
|
| 40 |
+
elif current_class == "PLANE":
|
| 41 |
+
if line.startswith("FBASE_POINT"):
|
| 42 |
+
temp_geom["base_point"] = tuple(map(float, line.split()[1:]))
|
| 43 |
+
elif line.startswith("FNORMAL"):
|
| 44 |
+
temp_geom["normal"] = tuple(map(float, line.split()[1:]))
|
| 45 |
+
elif line.startswith("FIN_SET"):
|
| 46 |
+
plane_point_map[temp_geom["tag"]] = temp_geom
|
| 47 |
+
elif current_class == "WORK_PLANE":
|
| 48 |
+
if line.startswith("FMY_PLANE TAG"):
|
| 49 |
+
temp_geom["plane_tag"] = int(line.split()[-1])
|
| 50 |
+
elif line.startswith("DCM3_TEXT_LABEL"):
|
| 51 |
+
temp_geom["label"] = line.split(" ", 1)[1].strip()
|
| 52 |
+
elif line == "#":
|
| 53 |
+
tag = temp_geom.get("plane_tag")
|
| 54 |
+
if tag is not None:
|
| 55 |
+
plane_label_map[tag] = temp_geom.get("label", "")
|
| 56 |
+
elif current_class == "SET":
|
| 57 |
+
if line.startswith("DCM3_TEXT_LABEL"):
|
| 58 |
+
temp_part["name"] = line.split(" ", 1)[1].strip()
|
| 59 |
+
elif line.startswith("FMEMBER TAGS"):
|
| 60 |
+
tags = list(map(int, line.split()[2:]))
|
| 61 |
+
temp_part["member_tags"].extend(tags)
|
| 62 |
+
elif line == "#":
|
| 63 |
+
parts.append(temp_part)
|
| 64 |
+
elif current_class == "CONSTRAINT":
|
| 65 |
+
if line.startswith("FEND_1 TAG"):
|
| 66 |
+
temp_constraint["from"] = int(line.split()[-1])
|
| 67 |
+
elif line.startswith("FEND_2 TAG"):
|
| 68 |
+
temp_constraint["to"] = int(line.split()[-1])
|
| 69 |
+
elif line.startswith("DCM3_TEXT_LABEL"):
|
| 70 |
+
temp_constraint["label"] = line.split(" ", 1)[1].strip()
|
| 71 |
+
elif line == "#":
|
| 72 |
+
if "from" in temp_constraint and "to" in temp_constraint:
|
| 73 |
+
constraints[(temp_constraint["from"], temp_constraint["to"])] = temp_constraint["label"]
|
| 74 |
+
|
| 75 |
+
# Build final geometry dict
|
| 76 |
+
final_geometry = {}
|
| 77 |
+
for tag, data in plane_point_map.items():
|
| 78 |
+
final_geometry[tag] = {
|
| 79 |
+
"base_point": data["base_point"],
|
| 80 |
+
"normal": data["normal"],
|
| 81 |
+
"label": plane_label_map.get(tag, "")
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
# Build final constraint list
|
| 85 |
+
constraint_list = [{"from": f, "to": t, "label": lbl} for (f, t), lbl in constraints.items()]
|
| 86 |
|
| 87 |
return {
|
| 88 |
+
"geometry": final_geometry,
|
| 89 |
"parts": parts,
|
| 90 |
+
"constraints": constraint_list
|
| 91 |
}
|
| 92 |
|
| 93 |
+
|
| 94 |
# === File Upload ===
|
| 95 |
file1 = st.file_uploader("Upload File A", type=["txt"])
|
| 96 |
file2 = st.file_uploader("Upload File B", type=["txt"])
|