Newer
Older
using System;
using System.Collections.Generic;
Marco Zimmer
committed
using JsonSubTypes;
using static SOMDocManager;
using UnityEngine.ProBuilder;
using Unity.Mathematics;
using System.Runtime.ExceptionServices;
public static class ParsingDictionary
//TODO? get rid of this, use reflection? instead, if possible
//TODO: docu
public static Dictionary<string, Func<MMTDeclaration, Fact>> parseFactDictionary = new() {
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ MMT_OMS_URI.Point,
PointFact.parseFact },
{ MMT_OMS_URI.Metric,
LineFact.parseFact },
{ MMT_OMS_URI.Angle,
AngleFact.parseFact },
{ MMT_OMS_URI.Eq,
AngleFact.parseFact },
{ MMT_OMS_URI.RightAngle,
RightAngleFact.parseFact },
{ MMT_OMS_URI.LineType,
RayFact.parseFact },
{ MMT_OMS_URI.LineOf,
RayFact.parseFact },
{ MMT_OMS_URI.OnLine,
OnLineFact.parseFact },
{ MMT_OMS_URI.ParallelLine,
ParallelLineFact.parseFact },
{ MMT_OMS_URI.CircleType3d,
CircleFact.parseFact },
{ MMT_OMS_URI.OnCircle,
OnCircleFact.parseFact },
{ MMT_OMS_URI.AnglePlaneLine,
AngleCircleLineFact.parseFact },
{ MMT_OMS_URI.RadiusCircleMetric,
RadiusFact.parseFact },
{ MMT_OMS_URI.AreaCircle,
AreaCircleFact.parseFact },
{ MMT_OMS_URI.OrthoCircleLine,
OrthogonalCircleLineFact.parseFact },
{ MMT_OMS_URI.VolumeCone,
ConeVolumeFact.parseFact },
{ MMT_OMS_URI.TruncatedVolumeCone,
TruncatedConeVolumeFact.parseFact },
{ MMT_OMS_URI.CylinderVolume,
CylinderVolumeFact.parseFact },
{ MMT_OMS_URI.TestType,
TestFact.parseFact },
{ MMT_OMS_URI.EqualityCircles,
EqualCirclesFact.parseFact },
{ MMT_OMS_URI.UnEqualityCircles,
{ MMT_OMS_URI.ListLiteral,
ListFact.parseFact },
// TODO: get rid of this
public static Dictionary<string, string> parseTermsToId = new();
/// <summary>
/// %Fact representation of Unity; mostly mirrors Facts of MMT.
/// </summary>
Marco Zimmer
committed
[JsonConverter(typeof(JsonSubtypes), "s_type")]
[JsonSubtypes.KnownSubType(typeof(PointFact), nameof(PointFact))]
[JsonSubtypes.KnownSubType(typeof(LineFact), nameof(LineFact))]
[JsonSubtypes.KnownSubType(typeof(RayFact), nameof(RayFact))]
[JsonSubtypes.KnownSubType(typeof(OnLineFact), nameof(OnLineFact))]
[JsonSubtypes.KnownSubType(typeof(AngleFact), nameof(AngleFact))]
[JsonSubtypes.KnownSubType(typeof(CircleFact), nameof(CircleFact))]
[JsonSubtypes.KnownSubType(typeof(ParallelLineFact), nameof(ParallelLineFact))]
[JsonSubtypes.KnownSubType(typeof(OnCircleFact), nameof(OnCircleFact))]
[JsonSubtypes.KnownSubType(typeof(AngleCircleLineFact), nameof(AngleCircleLineFact))]
[JsonSubtypes.KnownSubType(typeof(OrthogonalCircleLineFact), nameof(OrthogonalCircleLineFact))]
[JsonSubtypes.KnownSubType(typeof(AreaCircleFact), nameof(AreaCircleFact))]
[JsonSubtypes.KnownSubType(typeof(RadiusFact), nameof(RadiusFact))]
[JsonSubtypes.KnownSubType(typeof(ConeVolumeFact), nameof(ConeVolumeFact))]
[JsonSubtypes.KnownSubType(typeof(TruncatedConeVolumeFact), nameof(TruncatedConeVolumeFact))]
[JsonSubtypes.KnownSubType(typeof(RightAngleFact), nameof(RightAngleFact))]
[JsonSubtypes.KnownSubType(typeof(CylinderVolumeFact), nameof(CylinderVolumeFact))]
[JsonSubtypes.KnownSubType(typeof(TestFact), nameof(TestFact))]
[JsonSubtypes.KnownSubType(typeof(EqualCirclesFact), nameof(EqualCirclesFact))]
[JsonSubtypes.KnownSubType(typeof(UnEqualCirclesFact), nameof(UnEqualCirclesFact))]
[JsonSubtypes.KnownSubType(typeof(AttachedPositionFunction), nameof(AttachedPositionFunction))]
[JsonSubtypes.KnownSubType(typeof(FunctionFact), nameof(FunctionFact))]
[JsonSubtypes.KnownSubType(typeof(FunctionCallFact), nameof(FunctionCallFact))]
[JsonSubtypes.KnownSubType(typeof(ListFact), nameof(ListFact))]
[JsonSubtypes.KnownSubType(typeof(TupelFact), nameof(TupelFact))]
MaZiFAU
committed
//[JsonSubtypes.KnownSubType(typeof(FunctionFact<T0, TResult>), "FunctionFact<T0, TResult>")] //TODO: generics? => nameof does not work (generic agnostic)
//[JsonSubtypes.KnownSubType(typeof(FunctionFactFloat<Vector3>), "FunctionFact<System.Single, UnityEngine.Vector3>")]
/// <summary>
/// Reference to <c>GameObject</c> that represents this Fact in the GameWorld.
/// </summary>
/// <summary>
/// Collection of <c>Type</c>s of *all* available <see cref="Fact"/>s to choose from.
/// </summary>
[JsonIgnore]
public static readonly Type[] Types = TypeExtensions<Fact>.UAssemblyInheritenceTypes;
Marco Zimmer
committed
/// <value>
/// [ClassName] for JSON de-/serialization.
/// Automatically set in <see cref="Fact()"/> for <b>NON-Generiy-Types</b>!
/// Also add JsonSubtypes.KnownSubType decorator for deserialization to Fact!
Marco Zimmer
committed
/// </value>
protected string s_type;
Marco Zimmer
committed
MaZiFAU
committed
/// <returns><see langword="true"/> if Fact depends on other \ref Fact "Facts"; equivalent to <see cref="getDependentFactIds"/> returns non empty array</returns>
[JsonIgnore]
public virtual bool HasDependentFacts => DependentFactIds.Length > 0;
MaZiFAU
committed
/// <returns> array of Fact <see cref="Id"> Ids </see> on which this Fact depends.</returns>
/// <example><see cref="AngleFact"/> needs 3 <see cref="PointFact"/>s to be defined.</example>
MaZiFAU
committed
public string[] DependentFactIds => _DependentFactIds ??= GetGetDependentFactIds();
private string[] _DependentFactIds;
/// <returns> array of Fact <see cref="Id"> Ids </see> on which this Fact depends.</returns>
/// <example><see cref="AngleFact"/> needs 3 <see cref="PointFact"/>s to be defined.</example>
protected abstract string[] GetGetDependentFactIds();
/// <value>
/// Unique Id. e.g.: MMT URI
/// </value>
//while (FetchURICoroutine.MoveNext()) ; //active wait for server
//private IEnumerator FetchURICoroutine = IEnumeratorExtensions.yield_break;
/// <summary>
/// MMT URI
/// </summary>
Marco Zimmer
committed
/// <value>
/// <c>get</c> initiates and subsequently updates a human readable name. <remarks>Should be called once a constructor call to be initiated.</remarks>
/// <c>set</c> calls <see cref="rename(string)"/>
/// </value>
public string Label
{
get
{ // in case of renamed dependables
return _Facts == null // JsonSerialization toggle (_Facts.GetNumberOfFacts() == 0 && this is not PointFact) // JsonSerialization toggle && allow first (Point)Fact to be created
|| (hasCustomLabel && _CustomLabel != null)
Marco Zimmer
committed
? _CustomLabel
: generateLabel();
Marco Zimmer
committed
}
set
{
if (_Facts == null) // JsonSerialization toggle)
{
_CustomLabel = value;
LabelId = -LabelId;
return;
}
/// <value>
/// Is true if Fact has a custom <see cref="Label"/> which is not <c>null</c> or <c>""</c>.
/// </value>
public bool hasCustomLabel => LabelId < 0;
/// <summary>
/// Stores custom <see cref="Label"/> if set.
/// </summary>
Marco Zimmer
committed
protected string _CustomLabel = null;
/// <summary>
/// Counter to organize auto generated <see cref="Label"/>.
/// Set to negative, if custom \ref Label is assigned.
/// </summary>
// property for JSON to set AFTER Label => declare AFTER Label
public int LabelId { get; set; }
/// <summary>
Loading
Loading full blame...