From 033d50582c033587d3e954d6ff0fdb7c3ea7f64c Mon Sep 17 00:00:00 2001 From: "AMCBRIDGE\\ksloboda" Date: Mon, 20 Nov 2023 15:36:10 +0200 Subject: [PATCH] add rotation to content configs --- .../LayoutFunctionCommon/LayoutStrategies.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs b/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs index d325e9a0..4050255d 100644 --- a/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs +++ b/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs @@ -33,6 +33,12 @@ public static LayoutInstantiated InstantiateLayoutByFit(SpaceConfiguration confi layoutInstantiated.ConfigName = key; break; } + else if (config.AllowRotatation && config.CellBoundary.Depth < width + 0.01 && config.CellBoundary.Width < length + 0.01) + { + layoutInstantiated.Config = GetRotatedConfig(config, -90); + layoutInstantiated.ConfigName = key; + break; + } } if (layoutInstantiated.Config == null) { @@ -874,5 +880,33 @@ public static void SetParentSpace(ElementInstance elementInstance, Guid parentSp elementInstance.AdditionalProperties["Space"] = parentSpaceId; } } + + private static ContentConfiguration GetRotatedConfig(ContentConfiguration config, double degrees) + { + var transform = new Transform().Rotated(Vector3.ZAxis, degrees); + var box = new BBox3(new List { transform.OfPoint(config.CellBoundary.Min), transform.OfPoint(config.CellBoundary.Max) }); + + // Create new config + var newConfig = new ContentConfiguration() + { + CellBoundary = new ContentConfiguration.BoundaryDefinition() { Min = box.Min, Max = box.Max, }, + ContentItems = new List() + }; + + foreach (var item in config.ContentItems) + { + var newItem = new ContentConfiguration.ContentItem() + { + Url = item.Url, + Name = item.Name, + Transform = item.Transform.Concatenated(transform), + Anchor = transform.OfPoint(item.Anchor) + }; + + newConfig.ContentItems.Add(newItem); + } + + return newConfig; + } } } \ No newline at end of file