Skip to content

Commit

Permalink
Add EditorWindows to debug LayerData
Browse files Browse the repository at this point in the history
These editor windows will help determine whether projects correctly load the styles from disk
  • Loading branch information
mvriel committed Oct 28, 2024
1 parent 0e62a91 commit 6e0db0c
Show file tree
Hide file tree
Showing 19 changed files with 334 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Assets/Scripts/Editor/Layers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/GeoJsonLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJsonLayerGameObject))]
public class GeoJsonLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJsonLayerGameObject)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/GeoJsonLineLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJSONLineLayer))]
public class GeoJsonLineLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJSONLineLayer)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/GeoJsonPointLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJSONPointLayer))]
public class GeoJsonPointLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJSONPointLayer)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJSONPolygonLayer))]
public class GeoJsonPolygonLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJSONPolygonLayer)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(HierarchicalObjectLayerGameObject))]
public class HierarchicalObjectLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
VisualElement root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (HierarchicalObjectLayerGameObject)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 150 additions & 0 deletions Assets/Scripts/Editor/Layers/LayerDataVisualElements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Netherlands3D.LayerStyles;
using Netherlands3D.Twin.Layers;
using UnityEngine;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
public static class LayerDataVisualElements
{
public static void LayerData(LayerData layerData, VisualElement root)
{
// Add a divider first
root.Add(Divider(2, 8));
root.Add(Heading("Layer Data"));
root.Add(Divider());

if (layerData == null)
{
root.Add(FieldContent("This layer doesn't have any data associated with it (yet)."));
return;
}

root.Add(FieldWithCaption("Name", layerData.Name));
root.Add(FieldWithCaption("Color", ColorUtility.ToHtmlStringRGBA(layerData.Color)));

root.Add(FieldCaption("Styles"));
if (layerData.Styles.Count == 0)
{
root.Add(FieldContent("This layer doesn't have any styles associated with it (yet)."));
}

bool first = true;
foreach (var (_, style) in layerData.Styles)
{
var foldout = StyleFoldout(style);
// first should be folded out, rest collapsed by default
foldout.value = first;
if (first) first = false;

root.Add(foldout);
}
}

private static Foldout StyleFoldout(LayerStyle layerStyle)
{
var foldout = new Foldout { text = layerStyle.Metadata.Name };
var group = GroupWithBorder();
group.Add(FieldWithCaption("Name", layerStyle.Metadata.Name));
group.Add(FieldCaption("Rules"));
if (layerStyle.StylingRules.Count == 0)
{
group.Add(FieldContent("This style doesn't have any styling rules associated with it (yet)."));
}
foreach (var stylingRule in layerStyle.StylingRules)
{
group.Add(StyleRuleFoldout(stylingRule));
}
foldout.Add(group);

return foldout;
}

private static Foldout StyleRuleFoldout(StylingRule stylingRule)
{
var ruleFoldout = new Foldout { text = stylingRule.Name };
ruleFoldout.Add(FieldWithCaption("Name", stylingRule.Name));
ruleFoldout.Add(FieldWithCaption("Selector", "If " + stylingRule.Selector));
var styles = stylingRule.Symbolizer.ToString();
ruleFoldout.Add(FieldWithCaption("Styles", string.IsNullOrEmpty(styles) ? "[None]" : styles ));

return ruleFoldout;
}

private static VisualElement FieldWithCaption(string caption, string content)
{
var group = new VisualElement()
{
style =
{
marginBottom = 4
}
};
group.Add(FieldCaption(caption));
group.Add(FieldContent(content));

return group;
}

private static Label FieldCaption(string caption)
{
return new Label(caption) { style = { unityFontStyleAndWeight = FontStyle.Bold}};
}

private static Label FieldContent(string content)
{
return new Label(content);
}

private static VisualElement GroupWithBorder()
{
return new VisualElement
{
style =
{
borderTopWidth = 1,
borderRightWidth = 1,
borderBottomWidth = 1,
borderLeftWidth = 1,
borderBottomColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
borderTopColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
borderLeftColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
borderRightColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
paddingLeft = 4,
paddingRight = 8,
paddingTop = 4,
paddingBottom = 4,
marginTop = 4,
marginBottom = 4
}
};
}

private static VisualElement Divider(int thickness = 1, int marginTop = 4, int marginBottom = 4)
{
return new VisualElement
{
style =
{
height = thickness,
marginTop = marginTop,
marginBottom = marginBottom,
backgroundColor = new Color(0.7f, 0.7f, 0.7f)
}
};
}

private static VisualElement Heading(string caption)
{
return new Label(caption)
{
style =
{
unityFontStyleAndWeight = FontStyle.Bold,
fontSize = 14,
marginBottom = 4
}
};
}
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Editor/Layers/LayerDataVisualElements.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/WfsGeoJsonLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(WFSGeoJsonLayerGameObject))]
public class WfsGeoJsonLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (WFSGeoJsonLayerGameObject)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public void AddAndVisualizeFeature<T>(Feature feature, CoordinateSystem original

private Material GetMaterialInstance()
{
var strokeColor = LayerData.DefaultSymbolizer?.GetStrokeColor() ?? Color.white;
return new Material(lineRenderer3D.LineMaterial)
{
color = LayerData.DefaultSymbolizer?.GetStrokeColor() ?? Color.white
color = strokeColor
};
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Layers/LayerTypes/LayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public bool HasValidCredentials

[JsonIgnore] public bool HasProperties => layerProperties.Count > 0;

[JsonIgnore] private Dictionary<string, LayerStyle> Styles => styles;
[JsonIgnore] public Dictionary<string, LayerStyle> Styles => styles;

/// <summary>
/// Every layer has a default style, this is a style that applies to all objects and features in this
Expand Down
5 changes: 5 additions & 0 deletions Assets/_BuildingBlocks/LayerStyles/Scripts/BoolExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public override object Resolve(ExpressionContext context)
{
return value;
}

public override string ToString()
{
return this.value ? "true" : "false";
}
}
}
Loading

0 comments on commit 6e0db0c

Please sign in to comment.