using System; using System.Collections.Generic; using Simulator.Data; using UVC.UI.Window.PropertyWindow; public static class PropertyHelper { public static void SaveChange(object source, object value, string name) { var path = PathIndexer.GetNodePath(source); Patch updateData = new Patch(); updateData.value = value; UpdateValueStack.AddPatch($"{path}.{name}", value); } public static PropertyGroup CreatePositionGroup( string groupId, ComponentDataBase data, PropertyWindow propertyWindow, Action saveChange) { var group = new PropertyGroup(groupId, "위치 및 회전", isExpanded: true); group.AddItems(new IPropertyItem[] { new FloatProperty("x_position", "X 좌표(m)", data.physical.position.x) { }.Bind( setter: v => { data.physical.position.x = v; saveChange(data, v, "physical.position.x"); } ), new FloatProperty("y_position", "y 좌표(m)", data.physical.position.y) { }.Bind( setter: v => { data.physical.position.y = v; saveChange(data, v, "physical.position.y"); } ), new FloatProperty("orientation", "회전(°)", data.physical.orientation) { }.Bind( setter: v => { data.physical.orientation = v; saveChange(data, v, "physical.orientation"); propertyWindow.ApplyExternalValue("orientation", RotationSnap.SnapOrientation(v), false); } ), }); return group; } public static PropertyGroup CreatePositionGroup( string groupId, Physical physical, object dataOwner, PropertyWindow propertyWindow, Action saveChange) { var group = new PropertyGroup(groupId, "위치 및 회전", isExpanded: true); group.AddItems(new IPropertyItem[] { new FloatProperty("x_position", "X 좌표(m)", physical.position.x) { }.Bind( setter: v => { physical.position.x = v; saveChange(dataOwner, v, "physical.position.x"); } ), new FloatProperty("y_position", "y 좌표(m)", physical.position.y) { }.Bind( setter: v => { physical.position.y = v; saveChange(dataOwner, v, "physical.position.y"); } ), new FloatProperty("orientation", "회전(°)", physical.orientation) { }.Bind( setter: v => { physical.orientation = v; saveChange(dataOwner, v, "physical.orientation"); propertyWindow.ApplyExternalValue("orientation", RotationSnap.SnapOrientation(v), false); } ), }); return group; } public static PropertyGroup CreateConnectionGroup( string groupId, string label, List items, Action saveChange) { var group = new PropertyGroup(groupId, label, isExpanded: true); if (items == null || items.Count == 0) { group.AddItem(new StringProperty($"{groupId}.no_locs", "", "연결된 항목이 없습니다.") { IsReadOnly = true }); return group; } foreach (var item in items) { string itemId = $"{groupId}.count.{item.target}"; var countProp = new IntProperty(itemId, item.target, item.required_items) .Bind(setter: v => { item.required_items = v; saveChange(item, item.required_items, "required_items"); }); group.AddItem(countProp); } return group; } }