Spaces:
Sleeping
Sleeping
Update app/components.py
Browse files- app/components.py +19 -2
app/components.py
CHANGED
@@ -71,7 +71,7 @@ def display_components_page():
|
|
71 |
st.rerun()
|
72 |
|
73 |
def initialize_components():
|
74 |
-
"""Initialize components in session state if not present."""
|
75 |
if "components" not in st.session_state.project_data:
|
76 |
st.session_state.project_data["components"] = {
|
77 |
"walls": [],
|
@@ -80,6 +80,15 @@ def initialize_components():
|
|
80 |
"windows": [],
|
81 |
"skylights": []
|
82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
def display_component_tab(comp_type: str):
|
85 |
"""
|
@@ -295,11 +304,19 @@ def display_component_tab(comp_type: str):
|
|
295 |
st.error("Component name must be unique.")
|
296 |
return
|
297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
# Create component data
|
299 |
component_data = {
|
300 |
"id": str(uuid.uuid4()),
|
301 |
"name": name,
|
302 |
-
"area": area
|
|
|
303 |
}
|
304 |
|
305 |
if comp_type in ["walls", "windows", "roofs", "skylights"]:
|
|
|
71 |
st.rerun()
|
72 |
|
73 |
def initialize_components():
|
74 |
+
"""Initialize components in session state if not present and migrate existing components."""
|
75 |
if "components" not in st.session_state.project_data:
|
76 |
st.session_state.project_data["components"] = {
|
77 |
"walls": [],
|
|
|
80 |
"windows": [],
|
81 |
"skylights": []
|
82 |
}
|
83 |
+
migrate_component_types()
|
84 |
+
|
85 |
+
def migrate_component_types():
|
86 |
+
"""Add 'type' key to existing components for backward compatibility."""
|
87 |
+
for comp_type in st.session_state.project_data["components"]:
|
88 |
+
for component in st.session_state.project_data["components"][comp_type]:
|
89 |
+
if "type" not in component:
|
90 |
+
component["type"] = comp_type
|
91 |
+
logger.info(f"Added type '{comp_type}' to component '{component['name']}'")
|
92 |
|
93 |
def display_component_tab(comp_type: str):
|
94 |
"""
|
|
|
304 |
st.error("Component name must be unique.")
|
305 |
return
|
306 |
|
307 |
+
# Validate component type
|
308 |
+
valid_types = set(COMPONENT_TYPES) # {'Walls', 'Roofs', 'Floors', 'Windows', 'Skylights'}
|
309 |
+
if comp_type not in [t.lower() for t in valid_types]:
|
310 |
+
st.error(f"Invalid component type '{comp_type}'. Please select a valid type.")
|
311 |
+
logger.error(f"Invalid component type '{comp_type}' for component '{name}'.")
|
312 |
+
return
|
313 |
+
|
314 |
# Create component data
|
315 |
component_data = {
|
316 |
"id": str(uuid.uuid4()),
|
317 |
"name": name,
|
318 |
+
"area": area,
|
319 |
+
"type": comp_type, # Explicitly set the component type
|
320 |
}
|
321 |
|
322 |
if comp_type in ["walls", "windows", "roofs", "skylights"]:
|