mabuseif commited on
Commit
6ab6262
·
verified ·
1 Parent(s): afef4c9

Update app/components.py

Browse files
Files changed (1) hide show
  1. app/components.py +17 -14
app/components.py CHANGED
@@ -83,12 +83,15 @@ def initialize_components():
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
  """
@@ -186,13 +189,13 @@ def display_component_tab(comp_type: str):
186
  elevation_angle = ORIENTATION_MAP[elevation]
187
  surface_azimuth = (elevation_angle + rotation) % 360.0
188
 
189
- # Tilt
190
  default_tilt = 0.0 if comp_type in ["roofs", "skylights"] else 90.0
191
- tilt = st.number_input(
192
- "Tilt (°)",
193
  min_value=0.0,
194
  max_value=180.0,
195
- value=float(editor_state.get("tilt", default_tilt)),
196
  step=1.0,
197
  format="%.0f",
198
  help="Tilt angle of the component relative to horizontal (0° = horizontal, 90° = vertical)."
@@ -323,7 +326,7 @@ def display_component_tab(comp_type: str):
323
  component_data["elevation"] = elevation
324
  component_data["rotation"] = rotation
325
  component_data["surface_azimuth"] = surface_azimuth
326
- component_data["tilt"] = tilt
327
 
328
  if comp_type == "floors":
329
  component_data["contact_with_ground_percentage"] = contact_with_ground_percentage
@@ -381,7 +384,7 @@ def display_wall_window_table(comp_type: str, components: List[Dict[str, Any]]):
381
  cols[1].write("**U-Value**")
382
  cols[2].write("**Area (m²)**")
383
  cols[3].write("**Surface Azimuth (°)**")
384
- cols[4].write("**Tilt (°)**")
385
  if comp_type == "walls":
386
  cols[5].write("**Edit**")
387
  cols[6].write("**Delete**")
@@ -397,7 +400,7 @@ def display_wall_window_table(comp_type: str, components: List[Dict[str, Any]]):
397
  cols[1].write(f"{comp.get('u_value', 0.0):.3f}")
398
  cols[2].write(f"{comp['area']:.2f}")
399
  cols[3].write(f"{comp.get('surface_azimuth', 0.0):.0f}")
400
- cols[4].write(f"{comp.get('tilt', 90.0):.0f}")
401
  if comp_type == "windows":
402
  cols[5].write(f"{comp.get('shading_coefficient', 1.0):.2f}")
403
 
@@ -412,7 +415,7 @@ def display_wall_window_table(comp_type: str, components: List[Dict[str, Any]]):
412
  "area": comp["area"],
413
  "elevation": comp.get("elevation", ORIENTATION_OPTIONS[0]),
414
  "rotation": comp.get("rotation", 0.0),
415
- "tilt": comp.get("tilt", 90.0),
416
  "is_edit": True
417
  }
418
 
@@ -445,7 +448,7 @@ def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]
445
  cols[1].write("**U-Value**")
446
  cols[2].write("**Area (m²)**")
447
  cols[3].write("**Surface Azimuth (°)**")
448
- cols[4].write("**Tilt (°)**")
449
  if comp_type == "roofs":
450
  cols[5].write("**Edit**")
451
  cols[6].write("**Delete**")
@@ -461,7 +464,7 @@ def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]
461
  cols[1].write(f"{comp.get('u_value', 0.0):.3f}")
462
  cols[2].write(f"{comp['area']:.2f}")
463
  cols[3].write(f"{comp.get('surface_azimuth', 0.0):.0f}")
464
- cols[4].write(f"{comp.get('tilt', 0.0):.0f}")
465
  if comp_type == "skylights":
466
  cols[5].write(f"{comp.get('shading_coefficient', 1.0):.2f}")
467
 
@@ -476,7 +479,7 @@ def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]
476
  "area": comp["area"],
477
  "elevation": comp.get("elevation", ORIENTATION_OPTIONS[0]),
478
  "rotation": comp.get("rotation", 0.0),
479
- "tilt": comp.get("tilt", 0.0),
480
  "is_edit": True
481
  }
482
 
@@ -649,7 +652,7 @@ def display_components_help():
649
  * **Walls, Roofs, Floors**: Opaque components that use constructions from the Construction section.
650
  * **Windows, Skylights**: Transparent components that use fenestrations from the Material Library section.
651
  * **Surface Azimuth**: Direction the component faces, calculated as elevation plus rotation (0° = North, 90° = East, 180° = South, 270° = West).
652
- * **Tilt**: Angle of the component relative to horizontal (0° = horizontal, 90° = vertical).
653
  * **Parent Component**: The wall or roof that contains a window or skylight.
654
  * **Shading Coefficient (SC)**: Factor for shading devices on windows/skylights (0.0 to 1.0).
655
 
@@ -662,7 +665,7 @@ def display_components_help():
662
  **Tips:**
663
 
664
  * Use elevation (A, B, C, D) and rotation to set the surface azimuth.
665
- * For roofs and skylights, set tilt to 0° for flat surfaces.
666
  * Ensure the total area of windows doesn't exceed the area of their parent walls.
667
  * Ensure the total area of skylights doesn't exceed the area of their parent roofs.
668
  """)
 
83
  migrate_component_types()
84
 
85
  def migrate_component_types():
86
+ """Add 'type' key and rename 'tilt' to 'surface_tilt' for 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
+ if comp_type != "floors" and "tilt" in component:
93
+ component["surface_tilt"] = component.pop("tilt")
94
+ logger.info(f"Renamed 'tilt' to 'surface_tilt' for component '{component['name']}'")
95
 
96
  def display_component_tab(comp_type: str):
97
  """
 
189
  elevation_angle = ORIENTATION_MAP[elevation]
190
  surface_azimuth = (elevation_angle + rotation) % 360.0
191
 
192
+ # Surface Tilt
193
  default_tilt = 0.0 if comp_type in ["roofs", "skylights"] else 90.0
194
+ surface_tilt = st.number_input(
195
+ "Surface Tilt (°)",
196
  min_value=0.0,
197
  max_value=180.0,
198
+ value=float(editor_state.get("surface_tilt", default_tilt)),
199
  step=1.0,
200
  format="%.0f",
201
  help="Tilt angle of the component relative to horizontal (0° = horizontal, 90° = vertical)."
 
326
  component_data["elevation"] = elevation
327
  component_data["rotation"] = rotation
328
  component_data["surface_azimuth"] = surface_azimuth
329
+ component_data["surface_tilt"] = surface_tilt
330
 
331
  if comp_type == "floors":
332
  component_data["contact_with_ground_percentage"] = contact_with_ground_percentage
 
384
  cols[1].write("**U-Value**")
385
  cols[2].write("**Area (m²)**")
386
  cols[3].write("**Surface Azimuth (°)**")
387
+ cols[4].write("**Surface Tilt (°)**")
388
  if comp_type == "walls":
389
  cols[5].write("**Edit**")
390
  cols[6].write("**Delete**")
 
400
  cols[1].write(f"{comp.get('u_value', 0.0):.3f}")
401
  cols[2].write(f"{comp['area']:.2f}")
402
  cols[3].write(f"{comp.get('surface_azimuth', 0.0):.0f}")
403
+ cols[4].write(f"{comp.get('surface_tilt', 90.0):.0f}")
404
  if comp_type == "windows":
405
  cols[5].write(f"{comp.get('shading_coefficient', 1.0):.2f}")
406
 
 
415
  "area": comp["area"],
416
  "elevation": comp.get("elevation", ORIENTATION_OPTIONS[0]),
417
  "rotation": comp.get("rotation", 0.0),
418
+ "surface_tilt": comp.get("surface_tilt", 90.0),
419
  "is_edit": True
420
  }
421
 
 
448
  cols[1].write("**U-Value**")
449
  cols[2].write("**Area (m²)**")
450
  cols[3].write("**Surface Azimuth (°)**")
451
+ cols[4].write("**Surface Tilt (°)**")
452
  if comp_type == "roofs":
453
  cols[5].write("**Edit**")
454
  cols[6].write("**Delete**")
 
464
  cols[1].write(f"{comp.get('u_value', 0.0):.3f}")
465
  cols[2].write(f"{comp['area']:.2f}")
466
  cols[3].write(f"{comp.get('surface_azimuth', 0.0):.0f}")
467
+ cols[4].write(f"{comp.get('surface_tilt', 0.0):.0f}")
468
  if comp_type == "skylights":
469
  cols[5].write(f"{comp.get('shading_coefficient', 1.0):.2f}")
470
 
 
479
  "area": comp["area"],
480
  "elevation": comp.get("elevation", ORIENTATION_OPTIONS[0]),
481
  "rotation": comp.get("rotation", 0.0),
482
+ "surface_tilt": comp.get("surface_tilt", 0.0),
483
  "is_edit": True
484
  }
485
 
 
652
  * **Walls, Roofs, Floors**: Opaque components that use constructions from the Construction section.
653
  * **Windows, Skylights**: Transparent components that use fenestrations from the Material Library section.
654
  * **Surface Azimuth**: Direction the component faces, calculated as elevation plus rotation (0° = North, 90° = East, 180° = South, 270° = West).
655
+ * **Surface Tilt**: Angle of the component relative to horizontal (0° = horizontal, 90° = vertical).
656
  * **Parent Component**: The wall or roof that contains a window or skylight.
657
  * **Shading Coefficient (SC)**: Factor for shading devices on windows/skylights (0.0 to 1.0).
658
 
 
665
  **Tips:**
666
 
667
  * Use elevation (A, B, C, D) and rotation to set the surface azimuth.
668
+ * For roofs and skylights, set surface tilt to 0° for flat surfaces.
669
  * Ensure the total area of windows doesn't exceed the area of their parent walls.
670
  * Ensure the total area of skylights doesn't exceed the area of their parent roofs.
671
  """)