Home Information - Your home, your data, organized.
Python
Added initial sizes for paths based on type.
Anthony Cassandra5580a35d2f28
diff --git a/src/hi/apps/collection/collection_manager.py b/src/hi/apps/collection/collection_manager.pyindex 265126e4..cda29178 100644--- a/src/hi/apps/collection/collection_manager.py+++ b/src/hi/apps/collection/collection_manager.py@@ -232,7 +232,8 @@ class CollectionManager(Singleton):except CollectionPath.DoesNotExist:pass- svg_path = SvgItemFactory().get_default_svg_path_str(+ svg_path = SvgItemFactory().get_default_collection_svg_path_str(+ collection = collection,location_view = location_view,is_path_closed = is_path_closed,)diff --git a/src/hi/apps/common/svg_models.py b/src/hi/apps/common/svg_models.pyindex 608fd3b9..b24d50a1 100644--- a/src/hi/apps/common/svg_models.py+++ b/src/hi/apps/common/svg_models.py@@ -6,6 +6,12 @@ from django.core.exceptions import ValidationErrorfrom django.db import models+@dataclass+class SvgRadius:+ x : float+ y : float++@dataclassclass SvgViewBox:x : floatdiff --git a/src/hi/apps/entity/entity_manager.py b/src/hi/apps/entity/entity_manager.pyindex e9cddee2..53298cc4 100644--- a/src/hi/apps/entity/entity_manager.py+++ b/src/hi/apps/entity/entity_manager.py@@ -247,7 +247,8 @@ class EntityManager(Singleton):except EntityPath.DoesNotExist:pass- svg_path = SvgItemFactory().get_default_svg_path_str(+ svg_path = SvgItemFactory().get_default_entity_svg_path_str(+ entity = entity,location_view = location_view,is_path_closed = is_path_closed,)diff --git a/src/hi/apps/location/svg_item_factory.py b/src/hi/apps/location/svg_item_factory.pyindex 1dd8082d..9f043f20 100644--- a/src/hi/apps/location/svg_item_factory.py+++ b/src/hi/apps/location/svg_item_factory.py@@ -110,9 +110,35 @@ class SvgItemFactory( Singleton ):else:return SvgItemType.ICON+ def get_default_entity_svg_path_str( self,+ entity : Entity,+ location_view : LocationView,+ is_path_closed : bool ) -> str:+ radius = EntityStyle.get_svg_path_initial_radius( entity_type = entity.entity_type )+ return self.get_default_svg_path_str(+ location_view = location_view,+ is_path_closed = is_path_closed,+ radius_x = radius.x,+ radius_y = radius.y,+ )++ def get_default_collection_svg_path_str( self,+ collection : Collection,+ location_view : LocationView,+ is_path_closed : bool ) -> str:+ radius = CollectionStyle.get_svg_path_initial_radius( collection_type = collection.collection_type )+ return self.get_default_svg_path_str(+ location_view = location_view,+ is_path_closed = is_path_closed,+ radius_x = radius.x,+ radius_y = radius.y,+ )+def get_default_svg_path_str( self,location_view : LocationView,- is_path_closed : bool ) -> str:+ is_path_closed : bool,+ radius_x : float = None,+ radius_y : float = None ) -> str:# Note that this server-side creation of a new path is just one# place new paths can be created. During client-side path editing,@@ -121,10 +147,13 @@ class SvgItemFactory( Singleton ):# there to be some consistency.# Default display a line or rectangle in middle of current view with radius X% of viewbox+ if radius_x is None:+ radius_x = location_view.svg_view_box.width * ( self.NEW_PATH_RADIUS_PERCENT / 50.0 )+ if radius_y is None:+ radius_y = location_view.svg_view_box.height * ( self.NEW_PATH_RADIUS_PERCENT / 50.0 )+center_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )center_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )- radius_x = location_view.svg_view_box.width * ( self.NEW_PATH_RADIUS_PERCENT / 100.0 )- radius_y = location_view.svg_view_box.height * ( self.NEW_PATH_RADIUS_PERCENT / 100.0 )if is_path_closed:top_left_x = center_x - radius_xdiff --git a/src/hi/hi_styles.py b/src/hi/hi_styles.pyindex 7d2463ff..cbf5dea3 100644--- a/src/hi/hi_styles.py+++ b/src/hi/hi_styles.py@@ -1,4 +1,4 @@-from hi.apps.common.svg_models import SvgStatusStyle, SvgViewBox+from hi.apps.common.svg_models import SvgRadius, SvgStatusStyle, SvgViewBoxfrom hi.apps.collection.enums import CollectionTypefrom hi.apps.entity.enums import EntityType@@ -103,13 +103,21 @@ class CollectionStyle:fill_opacity = DEFAULT_OPACITY,),}+ CollectionTypePathInitialRadius = {+ }@classmethod- def get_svg_path_status_style( cls, collection_type : CollectionType ):+ def get_svg_path_status_style( cls, collection_type : CollectionType ) -> SvgStatusStyle:if collection_type in cls.PathCollectionTypeToSvgStatusStyle:return cls.PathCollectionTypeToSvgStatusStyle.get( collection_type )return ItemStyle.get_default_svg_path_status_style()+ @classmethod+ def get_svg_path_initial_radius( cls, collection_type : CollectionType ) -> SvgRadius:+ if collection_type in cls.CollectionTypePathInitialRadius:+ return cls.CollectionTypePathInitialRadius.get( collection_type )+ return SvgRadius( x = None, y = None )+class EntityStyle:@@ -118,7 +126,7 @@ class EntityStyle:stroke_color = '#040406',stroke_width = 2,stroke_dasharray = [],- fill_color = '#a9a9a9',+ fill_color = '#e6f0fa',fill_opacity = 1,)Area = SvgStatusStyle(@@ -139,7 +147,7 @@ class EntityStyle:)Door = SvgStatusStyle(status_value = '',- stroke_color = '#4f3022',+ stroke_color = '#c0c0c0',stroke_width = 2,stroke_dasharray = [],fill_color = '#5f3929',@@ -155,10 +163,10 @@ class EntityStyle:)Furniture = SvgStatusStyle(status_value = '',- stroke_color = '#0606a0',+ stroke_color = '#8B4513',stroke_width = 2,stroke_dasharray = [],- fill_color = '#808080',+ fill_color = '#D2B48C',fill_opacity = 1,)Greenhouse = SvgStatusStyle(@@ -195,7 +203,7 @@ class EntityStyle:)Wall = SvgStatusStyle(status_value = '',- stroke_color = '#0606a0',+ stroke_color = '#c0c0c0',stroke_width = 2,stroke_dasharray = [],fill_color = '#808080',@@ -211,10 +219,10 @@ class EntityStyle:)Window = SvgStatusStyle(status_value = '',- stroke_color = '#0606a0',+ stroke_color = '#808080',stroke_width = 2,stroke_dasharray = [],- fill_color = '#808080',+ fill_color = '#78e3df',fill_opacity = 1,)@@ -342,25 +350,38 @@ class EntityStyle:EntityType.WATER_LINE: WaterLine,EntityType.WINDOW: Window,}+ EntityTypePathInitialRadius = {+ EntityType.APPLIANCE: SvgRadius( x = 32, y = 32 ),+ EntityType.DOOR: SvgRadius( x = None, y = 16 ),+ EntityType.FURNITURE: SvgRadius( x = 64, y = 32 ),+ EntityType.WALL: SvgRadius( x = 16, y = None ),+ EntityType.WINDOW: SvgRadius( x = None, y = 16.0 ),+ }@classmethod- def get_svg_icon_viewbox( cls, entity_type : EntityType ):+ def get_svg_icon_viewbox( cls, entity_type : EntityType ) -> SvgViewBox:if entity_type in cls.EntityTypeToIconViewbox:return cls.EntityTypeToIconViewbox.get( entity_type )return ItemStyle.get_default_svg_icon_viewbox()@classmethod- def get_svg_icon_template_name( cls, entity_type : EntityType ):+ def get_svg_icon_template_name( cls, entity_type : EntityType ) -> str:if entity_type in cls.EntityTypesWithIcons:return f'entity/svg/type.{entity_type}.svg'return ItemStyle.get_default_svg_icon_template_name()@classmethod- def get_svg_path_status_style( cls, entity_type : EntityType ):+ def get_svg_path_status_style( cls, entity_type : EntityType ) -> SvgStatusStyle:if entity_type in cls.PathEntityTypeToSvgStatusStyle:return cls.PathEntityTypeToSvgStatusStyle.get( entity_type )return ItemStyle.get_default_svg_path_status_style()-++ @classmethod+ def get_svg_path_initial_radius( cls, entity_type : EntityType ) -> SvgRadius:+ if entity_type in cls.EntityTypePathInitialRadius:+ return cls.EntityTypePathInitialRadius.get( entity_type )+ return SvgRadius( x = None, y = None )+class StatusStyle: