diff --git a/Assets/Scripts/InteractionEngine/Fact.cs b/Assets/Scripts/InteractionEngine/Fact.cs index 6ea47ee48adefc75baf66805bb11180c8646f0de..f26c8e07d83537d75226c0817c340f755d781dfd 100644 --- a/Assets/Scripts/InteractionEngine/Fact.cs +++ b/Assets/Scripts/InteractionEngine/Fact.cs @@ -43,8 +43,10 @@ public static AddFactResponse sendAdd(string path, string body) //TODO: implement real asynchronous communication ... AsyncOperation op = www.SendWebRequest(); - while (!op.isDone) { } - if (www.isNetworkError || www.isHttpError) + while (!op.isDone) ; + + if (www.result == UnityWebRequest.Result.ConnectionError + || www.result == UnityWebRequest.Result.ProtocolError) { Debug.LogWarning(www.error); return new AddFactResponse(); @@ -61,18 +63,11 @@ public abstract class Fact { public GameObject Representation; - public string backendURI; + public string URI { get { return _URI; } } + protected string _URI; public string Label; - public int Id - { - get { return _id; } - set - { - _id = value; - Label = getLetter(_id); - } - } - private int _id; + + private static int LabelId = 0; public void rename(string newLabel) @@ -83,7 +78,7 @@ public void rename(string newLabel) //If FactType depends on other Facts, e.g. AngleFacts depend on 3 PointFacts public abstract Boolean hasDependentFacts(); - public abstract int[] getDependentFactIds(); + public abstract string[] getDependentFactIds(); public abstract GameObject instantiateDisplay(GameObject prefab, Transform transform); @@ -98,9 +93,11 @@ public virtual void delete() public abstract override int GetHashCode(); - public static string getLetter(int Id) + protected abstract string generateLabel(); + + protected string generateLetter() { - return ((Char)(64 + Id + 1)).ToString(); + return ((char)(64 + LabelId++ + 1)).ToString(); } } @@ -122,24 +119,33 @@ public override bool Equivalent(Fact f1, Fact f2) public abstract class AbstractLineFact: FactWrappedCRTP<AbstractLineFact> { //Id's of the 2 Point-Facts that are connected - public int Pid1, Pid2; + public string Pid1, Pid2; // normalized Direction from Pid1 to Pid2 public Vector3 Dir; //only for temporary Use of LineFacts. - public AbstractLineFact() { } + //public AbstractLineFact() { } - //public AbstractLineFact(int i, int pid1, int pid2); + public AbstractLineFact(string pid1, string pid2) + { + set_public_members(pid1, pid2); + } + + public AbstractLineFact(string pid1, string pid2, string backendURI) + { + set_public_members(pid1, pid2); + this._URI = backendURI; + } - public AbstractLineFact(int pid1, int pid2, string backendURI) + private void set_public_members(string pid1, string pid2) { this.Pid1 = pid1; this.Pid2 = pid2; + this.Label = generateLabel(); PointFact pf1 = Facts[pid1] as PointFact; PointFact pf2 = Facts[pid2] as PointFact; this.Dir = (pf2.Point - pf1.Point).normalized; - this.backendURI = backendURI; } public override bool hasDependentFacts() @@ -147,23 +153,25 @@ public override bool hasDependentFacts() return true; } - public override int[] getDependentFactIds() + public override string[] getDependentFactIds() { - return new int[] { Pid1, Pid2 }; + return new string[] { Pid1, Pid2 }; } public override int GetHashCode() { - return this.Pid1 ^ this.Pid2; + return this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode(); } } public abstract class AbstractLineFactWrappedCRTP<T>: AbstractLineFact where T: AbstractLineFactWrappedCRTP<T> { //only for temporary Use of LineFacts. - public AbstractLineFactWrappedCRTP() { } + //public AbstractLineFactWrappedCRTP() { } - public AbstractLineFactWrappedCRTP (int pid1, int pid2, string backendURI) : base(pid1, pid2, backendURI) { } + public AbstractLineFactWrappedCRTP (string pid1, string pid2) : base(pid1, pid2) { } + + public AbstractLineFactWrappedCRTP (string pid1, string pid2, string backendURI) : base(pid1, pid2, backendURI) { } protected override bool EquivalentWrapped(AbstractLineFact f1, AbstractLineFact f2) { @@ -181,11 +189,11 @@ public class PointFact : FactWrappedCRTP<PointFact> public Vector3 Normal; - public PointFact(int i, Vector3 P, Vector3 N) + public PointFact(Vector3 P, Vector3 N) { - this.Id = i; this.Point = P; this.Normal = N; + this.Label = generateLabel(); List<MMTTerm> arguments = new List<MMTTerm> { @@ -203,15 +211,16 @@ public PointFact(int i, Vector3 P, Vector3 N) string body = MMTSymbolDeclaration.ToJson(mmtDecl); AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress+"/fact/add", body); - this.backendURI = res.uri; - Debug.Log(this.backendURI); + this._URI = res.uri; + Debug.Log(this.URI); } public PointFact(float a, float b, float c, string uri) { this.Point = new Vector3(a, b, c); this.Normal = new Vector3(0, 1, 0); - this.backendURI = uri; + this.Label = generateLabel(); + this._URI = uri; } public static PointFact parseFact(Scroll.ScrollFact fact) { @@ -229,20 +238,26 @@ public static PointFact parseFact(Scroll.ScrollFact fact) { } } + protected override string generateLabel() + { + return generateLetter(); + } + public override Boolean hasDependentFacts() { return false; } - public override int[] getDependentFactIds() { - return new int[] { }; ; + public override string[] getDependentFactIds() { + return new string[] { }; ; } public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); - obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(this.Id); + obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.Label; obj.GetComponent<FactWrapper>().fact = this; return obj; } + public override int GetHashCode() { return this.Point.GetHashCode() ^ this.Normal.GetHashCode(); @@ -257,23 +272,15 @@ protected override bool EquivalentWrapped(PointFact f1, PointFact f2) public class LineFact : AbstractLineFactWrappedCRTP<LineFact> { - public LineFact(int pid1, int pid2, string backendURI) : base(pid1, pid2, backendURI) { } + public LineFact(string pid1, string pid2, string backendURI) : base(pid1, pid2, backendURI) { } - public LineFact(int i, int pid1, int pid2) + public LineFact(string pid1, string pid2) : base(pid1, pid2) { - this.Id = i; - this.Pid1 = pid1; - this.Pid2 = pid2; PointFact pf1 = Facts[pid1] as PointFact; PointFact pf2 = Facts[pid2] as PointFact; - this.Dir = (pf2.Point - pf1.Point).normalized; - - //Label is currently set to Fact.setId - //Set Label to StringConcatenation of Points - this.Label = pf1.Label + pf2.Label; - string p1URI = pf1.backendURI; - string p2URI = pf2.backendURI; + string p1URI = pf1.URI; + string p2URI = pf2.URI; float v = (pf1.Point - pf2.Point).magnitude; MMTTerm lhs = @@ -292,31 +299,35 @@ public LineFact(int i, int pid1, int pid2) MMTValueDeclaration mmtDecl = new MMTValueDeclaration(this.Label, lhs, valueTp, value); string body = MMTDeclaration.ToJson(mmtDecl); AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body); - this.backendURI = res.uri; - Debug.Log(this.backendURI); + this._URI = res.uri; + Debug.Log(this.URI); } public static LineFact parseFact(Scroll.ScrollFact fact) { - String uri = fact.@ref.uri; - String pointAUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri; - String pointBUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[1]).uri; + string uri = fact.@ref.uri; + string pointAUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri; + string pointBUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[1]).uri; - if (Facts.searchURI(pointAUri, out int pid1) - && Facts.searchURI(pointBUri, out int pid2)) - return new LineFact(pid1, pid2, uri); + if (Facts.ContainsKey(pointAUri) + && Facts.ContainsKey(pointBUri)) + return new LineFact(pointAUri, pointBUri, uri); //If dependent facts do not exist return null else { return null; } } + protected override string generateLabel() + { + return "[" + Facts[Pid1].Label + Facts[Pid2].Label + "]"; + } public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); - obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Pid1].Id); - obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Pid2].Id); + obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Pid1].Label; + obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Pid2].Label; obj.GetComponent<FactWrapper>().fact = this; return obj; } @@ -339,19 +350,15 @@ protected override bool EquivalentWrapped(LineFact f1, LineFact f2) public class RayFact : AbstractLineFactWrappedCRTP<RayFact> { - RayFact(int pid1, int pid2, string backendURI) : base(pid1, pid2, backendURI) { } + public RayFact(string pid1, string pid2, string backendURI) : base(pid1, pid2, backendURI) { } - public RayFact(int i, int pid1, int pid2) + public RayFact(string pid1, string pid2) : base(pid1, pid2) { - this.Id = i; - this.Pid1 = pid1; - this.Pid2 = pid2; PointFact pf1 = Facts[pid1] as PointFact; PointFact pf2 = Facts[pid2] as PointFact; - this.Dir = (pf2.Point - pf1.Point).normalized; - string p1URI = pf1.backendURI; - string p2URI = pf2.backendURI; + string p1URI = pf1.URI; + string p2URI = pf2.URI; List<MMTTerm> arguments = new List<MMTTerm> { @@ -368,30 +375,35 @@ public RayFact(int i, int pid1, int pid2) string body = MMTSymbolDeclaration.ToJson(mmtDecl); AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body); - this.backendURI = res.uri; - Debug.Log(this.backendURI); + this._URI = res.uri; + Debug.Log(this.URI); } public static RayFact parseFact(Scroll.ScrollFact fact) { - String uri = fact.@ref.uri; + string uri = fact.@ref.uri; if ((OMA)((Scroll.ScrollSymbolFact)fact).df != null) { - String pointAUri = ((OMS)((OMA)((Scroll.ScrollSymbolFact)fact).df).arguments[0]).uri; - String pointBUri = ((OMS)((OMA)((Scroll.ScrollSymbolFact)fact).df).arguments[1]).uri; + string pointAUri = ((OMS)((OMA)((Scroll.ScrollSymbolFact)fact).df).arguments[0]).uri; + string pointBUri = ((OMS)((OMA)((Scroll.ScrollSymbolFact)fact).df).arguments[1]).uri; - if (Facts.searchURI(pointAUri, out int pid1) - && Facts.searchURI(pointBUri, out int pid2)) - return new RayFact(pid1, pid2, uri); + if (Facts.ContainsKey(pointAUri) + && Facts.ContainsKey(pointBUri)) + return new RayFact(pointAUri, pointBUri, uri); //If dependent facts do not exist return null } return null; } + protected override string generateLabel() + { + return "–" + Facts[Pid1].Label + Facts[Pid2].Label + "–"; + } + public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); - obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(this.Id); + obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.Label; //obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts2[f.Pid2].Id); obj.GetComponent<FactWrapper>().fact = this; return obj; @@ -414,20 +426,18 @@ protected override bool EquivalentWrapped(RayFact f1, RayFact f2) public class OnLineFact : FactWrappedCRTP<OnLineFact> { //Id's of the Point and the Line it's on - public int Pid, Rid; + public string Pid, Rid; - public OnLineFact(int i, int pid, int rid) + public OnLineFact(string pid, string rid) { - this.Id = i; this.Pid = pid; this.Rid = rid; + this.Label = generateLabel(); + PointFact pf = Facts[pid] as PointFact; RayFact rf = Facts[rid] as RayFact; - string pURI = pf.backendURI; - string rURI = rf.backendURI; - - //Set Label to StringConcatenation of Points - this.Label = pf.Label + " ∈ " + rf.Label; + string pURI = pf.URI; + string rURI = rf.URI; List<MMTTerm> innerArguments = new List<MMTTerm> { @@ -449,53 +459,59 @@ public OnLineFact(int i, int pid, int rid) string body = MMTSymbolDeclaration.ToJson(mmtDecl); AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body); - this.backendURI = res.uri; - Debug.Log(this.backendURI); + this._URI = res.uri; + Debug.Log(this.URI); } - public OnLineFact(int pid, int rid, string uri) { + public OnLineFact(string pid, string rid, string uri) + { this.Pid = pid; this.Rid = rid; - this.backendURI = uri; + this.Label = generateLabel(); + this._URI = uri; } public static OnLineFact parseFact(Scroll.ScrollFact fact) { - String uri = fact.@ref.uri; - String lineUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[0]).uri; - String pointUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).uri; + string uri = fact.@ref.uri; + string lineUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[0]).uri; + string pointUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).uri; - if (Facts.searchURI(lineUri, out int rid) - && Facts.searchURI(pointUri, out int pid)) - return new OnLineFact(pid, rid, uri); + if (Facts.ContainsKey(pointUri) + && Facts.ContainsKey(lineUri)) + return new OnLineFact(pointUri, lineUri, uri); //If dependent facts do not exist return null else return null; } + protected override string generateLabel() + { + return Facts[Pid].Label + "∈" + Facts[Rid].Label; + } public override Boolean hasDependentFacts() { return true; } - public override int[] getDependentFactIds() + public override string[] getDependentFactIds() { - return new int[] { Pid, Rid }; + return new string[] { Pid, Rid }; } public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); - obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Pid].Id); - obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Rid].Id); + obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Pid].Label; + obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Rid].Label; obj.GetComponent<FactWrapper>().fact = this; return obj; } public override int GetHashCode() { - return this.Pid ^ this.Rid; + return this.Pid.GetHashCode() ^ this.Rid.GetHashCode(); } protected override bool EquivalentWrapped(OnLineFact f1, OnLineFact f2) @@ -515,43 +531,30 @@ protected override bool EquivalentWrapped(OnLineFact f1, OnLineFact f2) public class AngleFact : FactWrappedCRTP<AngleFact> { //Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is - public int Pid1, Pid2, Pid3; - - //only for temporary Use of AngleFacts - public AngleFact() { } + public string Pid1, Pid2, Pid3; + public bool is_right_angle; - public AngleFact(int i, int pid1, int pid2, int pid3) + public AngleFact(string pid1, string pid2, string pid3) { - this.Id = i; this.Pid1 = pid1; this.Pid2 = pid2; this.Pid3 = pid3; + PointFact pf1 = Facts[pid1] as PointFact; PointFact pf2 = Facts[pid2] as PointFact; PointFact pf3 = Facts[pid3] as PointFact; - string p1URI = pf1.backendURI; - string p2URI = pf2.backendURI; - string p3URI = pf3.backendURI; - float v = Vector3.Angle((pf1.Point - pf2.Point), (pf3.Point - pf2.Point)); + float v = GetAngle(); // sets is_right_angle + this.Label = generateLabel(); //needs is_right_angle MMTDeclaration mmtDecl; - - if (Mathf.Abs(v - 90.0f) < 0.01) - { - v = 90.0f; - //Label is currently set to Fact.setId - //Set Label to StringConcatenation of Points - this.Label = "⊾" + pf1.Label + pf2.Label + pf3.Label; + string p1URI = pf1.URI; + string p2URI = pf2.URI; + string p3URI = pf3.URI; + if (is_right_angle) mmtDecl = generate90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI); - } else - { - //Label is currently set to Fact.setId - //Set Label to StringConcatenation of Points - this.Label = "∠" + pf1.Label + pf2.Label + pf3.Label; mmtDecl = generateNot90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI); - } Debug.Log("angle: " + v); @@ -559,24 +562,29 @@ public AngleFact(int i, int pid1, int pid2, int pid3) Debug.Log(body); AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress+"/fact/add", body); - this.backendURI = res.uri; - Debug.Log(this.backendURI); + this._URI = res.uri; + Debug.Log(this.URI); } - public AngleFact(int Pid1, int Pid2, int Pid3, string backendURI) + public AngleFact(string Pid1, string Pid2, string Pid3, string backendURI) { this.Pid1 = Pid1; this.Pid2 = Pid2; this.Pid3 = Pid3; - this.backendURI = backendURI; + + GetAngle(); + this.Label = generateLabel(); + + this._URI = backendURI; } public static AngleFact parseFact(Scroll.ScrollFact fact) { - String uri = fact.@ref.uri; - String pointAUri; - String pointBUri; - String pointCUri; + string uri = fact.@ref.uri; + string + pointAUri, + pointBUri, + pointCUri; //If angle is not a 90Degree-Angle if (fact.GetType().Equals(typeof(Scroll.ScrollValueFact))) @@ -592,16 +600,33 @@ public static AngleFact parseFact(Scroll.ScrollFact fact) pointCUri = ((OMS)((OMA)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).arguments[2]).uri; } - if (Facts.searchURI(pointAUri, out int pid1) - && Facts.searchURI(pointBUri, out int pid2) - && Facts.searchURI(pointCUri, out int pid3)) + if (Facts.ContainsKey(pointAUri) + && Facts.ContainsKey(pointBUri) + && Facts.ContainsKey(pointCUri)) - return new AngleFact(pid1, pid2, pid3, uri); + return new AngleFact(pointAUri, pointBUri, pointCUri, uri); else //If dependent facts do not exist return null return null; } + protected override string generateLabel() + { + return (is_right_angle ? "⊾" : "∠") + Facts[Pid1].Label + Facts[Pid2].Label + Facts[Pid2].Label; + } + + private float GetAngle() + { + PointFact pf1 = Facts[Pid1] as PointFact; + PointFact pf2 = Facts[Pid2] as PointFact; + PointFact pf3 = Facts[Pid3] as PointFact; + + float v = Vector3.Angle((pf1.Point - pf2.Point), (pf3.Point - pf2.Point)); + this.is_right_angle = Mathf.Abs(v - 90.0f) < 0.01; + + return is_right_angle ? 90f : v; + } + private MMTDeclaration generate90DegreeAngleDeclaration(float val, string p1URI, string p2URI, string p3URI) { MMTTerm argument = new OMA( @@ -616,7 +641,7 @@ private MMTDeclaration generate90DegreeAngleDeclaration(float val, string p1URI, new OMS(p3URI) } ), - new OMF(val) + new OMF(val) // 90f } ); @@ -649,23 +674,23 @@ public override Boolean hasDependentFacts() return true; } - public override int[] getDependentFactIds() + public override string[] getDependentFactIds() { - return new int[] { Pid1, Pid2, Pid3 }; + return new string[] { Pid1, Pid2, Pid3 }; } public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); - obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Pid1].Id); - obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Pid2].Id); - obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(Facts[this.Pid3].Id); + obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Pid1].Label; + obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Pid2].Label; + obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = Facts[this.Pid3].Label; obj.GetComponent<FactWrapper>().fact = this; return obj; } public override int GetHashCode() { - return this.Pid1 ^ this.Pid2 ^ this.Pid3; + return this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode() ^ this.Pid3.GetHashCode(); } protected override bool EquivalentWrapped(AngleFact f1, AngleFact f2) diff --git a/Assets/Scripts/InteractionEngine/FactManager.cs b/Assets/Scripts/InteractionEngine/FactManager.cs index db0c9ecc47f187bf03c4452b73d307a99625235c..8f448fc04a1c58ffea59391f32d46c8681bbc79f 100644 --- a/Assets/Scripts/InteractionEngine/FactManager.cs +++ b/Assets/Scripts/InteractionEngine/FactManager.cs @@ -21,29 +21,29 @@ public static Fact AddFactIfNotFound(Fact fact, out bool exists, bool samestep) return Facts[Facts.Add(fact, out exists, samestep)]; } - public PointFact AddPointFact(RaycastHit hit, int id, bool samestep = false) + public PointFact AddPointFact(RaycastHit hit, bool samestep = false) { - return (PointFact) AddFactIfNotFound(new PointFact(id, hit.point, hit.normal), out bool obsolete, samestep); + return (PointFact) AddFactIfNotFound(new PointFact(hit.point, hit.normal), out bool obsolete, samestep); } - public PointFact AddPointFact(int id, Vector3 point, Vector3 normal, bool samestep = false) + public PointFact AddPointFact(Vector3 point, Vector3 normal, bool samestep = false) { - return (PointFact) AddFactIfNotFound(new PointFact(id, point, normal), out bool obsolete, samestep); + return (PointFact) AddFactIfNotFound(new PointFact(point, normal), out bool obsolete, samestep); } - public OnLineFact AddOnLineFact(int pid, int lid, int id, bool samestep = false) + public OnLineFact AddOnLineFact(string pid, string lid, bool samestep = false) { - return (OnLineFact)AddFactIfNotFound(new OnLineFact(id, pid, lid), out bool obsolete, samestep); + return (OnLineFact)AddFactIfNotFound(new OnLineFact(pid, lid), out bool obsolete, samestep); } - public LineFact AddLineFact(int pid1, int pid2, int id, bool samestep = false) + public LineFact AddLineFact(string pid1, string pid2, bool samestep = false) { - return (LineFact)AddFactIfNotFound(new LineFact(id, pid1, pid2), out bool obsolete, samestep); + return (LineFact)AddFactIfNotFound(new LineFact(pid1, pid2), out bool obsolete, samestep); } - public RayFact AddRayFact(int pid1, int pid2, int id, bool samestep = false) + public RayFact AddRayFact(string pid1, string pid2, bool samestep = false) { - RayFact rayFact = (RayFact)AddFactIfNotFound(new RayFact(id, pid1, pid2), out bool exists, samestep); + RayFact rayFact = (RayFact)AddFactIfNotFound(new RayFact(pid1, pid2), out bool exists, samestep); if (exists) return rayFact; @@ -58,7 +58,7 @@ void AddHitIfOnLine(RaycastHit hit) { if (Math3d.IsPointApproximatelyOnLine(rayP1.Point, rayFact.Dir, hit.transform.position)) { - AddOnLineFact(hit.transform.gameObject.GetComponent<FactObject>().Id, rayFact.Id, GetFirstEmptyID(), true); + AddOnLineFact(hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.URI, true); } } @@ -69,16 +69,16 @@ void AddHitIfOnLine(RaycastHit hit) AddHitIfOnLine(hit); // for good measure - AddOnLineFact(rayFact.Pid1, rayFact.Id, GetFirstEmptyID(), true); - AddOnLineFact(rayFact.Pid2, rayFact.Id, GetFirstEmptyID(), true); + AddOnLineFact(rayFact.Pid1, rayFact.URI, true); + AddOnLineFact(rayFact.Pid2, rayFact.URI, true); return rayFact; } - public AngleFact AddAngleFact(int pid1, int pid2, int pid3, int id, bool samestep = false) + public AngleFact AddAngleFact(string pid1, string pid2, string pid3, bool samestep = false) { - return (AngleFact)AddFactIfNotFound(new AngleFact(id, pid1, pid2, pid3), out bool obsolete, samestep); + return (AngleFact)AddFactIfNotFound(new AngleFact(pid1, pid2, pid3), out bool obsolete, samestep); } public int GetFirstEmptyID() diff --git a/Assets/Scripts/InteractionEngine/FactObject.cs b/Assets/Scripts/InteractionEngine/FactObject.cs index fdde5741cbe988b6d4fc07300d04e8ca5ac8060f..292b5902af18b615f1b355398dfda7bcaeba247c 100644 --- a/Assets/Scripts/InteractionEngine/FactObject.cs +++ b/Assets/Scripts/InteractionEngine/FactObject.cs @@ -4,6 +4,6 @@ public class FactObject : MonoBehaviour { //object that can represent arbitrary facts //used to access entry in global Fact Collection - public int Id; + public string URI; } diff --git a/Assets/Scripts/InteractionEngine/FactOrganizer.cs b/Assets/Scripts/InteractionEngine/FactOrganizer.cs index fdaa902e11b96df62a6748cf4ce160214574d3d1..f263b041201b7b460f53dab880f10bdcaee7ebc0 100644 --- a/Assets/Scripts/InteractionEngine/FactOrganizer.cs +++ b/Assets/Scripts/InteractionEngine/FactOrganizer.cs @@ -10,9 +10,10 @@ //TODO! use URI as key //PERF: avoid string as key (hash -> colission? -> strcmp[!]) -public class FactOrganizer: Dictionary<int, Fact> + +public class FactOrganizer: Dictionary<string, Fact> { - private Dictionary<int, meta> MetaInf = new Dictionary<int, meta>(); + private Dictionary<string, meta> MetaInf = new Dictionary<string, meta>(); private List<stepnote> Workflow = new List<stepnote>(); // notes position in Workflow for un-/redo; the pointed to element is non-acitve private int marker = 0; @@ -25,7 +26,7 @@ public class FactOrganizer: Dictionary<int, Fact> private struct stepnote { // Fact.Id - public int Id; + public string Id; // true if this Fact has been created in the same step as the last one // steproot[false] (=> steptail[true])* public bool samestep; @@ -35,7 +36,7 @@ private struct stepnote public bool creation; - public stepnote(int Id, bool samestep, bool creation, FactOrganizer that) + public stepnote(string Id, bool samestep, bool creation, FactOrganizer that) { this.Id = Id; this.samestep = samestep; @@ -72,20 +73,20 @@ public meta(int workflow_id, bool active = true) public FactOrganizer() : base() { } - public FactOrganizer(IDictionary<int, Fact> dictionary) : base(dictionary) { } + public FactOrganizer(IDictionary<string, Fact> dictionary) : base(dictionary) { } //TODO: PERF: better way than string search? -> use string as key! - public bool searchURI(string uri, out int found) + public bool searchURI(string uri, out string found) { foreach(var element in this) - if (element.Value.backendURI.Equals(uri)) + if (element.Value.URI.Equals(uri)) { found = element.Key; return true; } - found = -1; + found = null; return false; } @@ -168,25 +169,25 @@ private void PruneWorkflow() } } - public new void Add(int key, Fact value) + public new void Add(string key, Fact value) // hide { this.Add(value, out bool obsolete); } - public int Add(Fact value, out bool exists, bool samestep = false) + public string Add(Fact value, out bool exists, bool samestep = false) // also checks for duplicates and active state // returns key of actual Fact { if (resetted) this.hardreset(false); - int key; + string key; if (exists = FindEquivalent(value, out Fact found)) { //TODO: MMT: del 'fact' (value) in MMT (alt.: s.TODO in addFact) - key = found.Id; + key = found.URI; if (MetaInf[key].active) return key; } @@ -194,7 +195,7 @@ public int Add(Fact value, out bool exists, bool samestep = false) { //TODO: MMT: alt: insert in MMT if needed here/ on Invoke() (see WorkflowAdd) - key = value.Id; + key = value.URI; base.Add(key, value); MetaInf.Add(key, new meta(marker, true)); } @@ -203,7 +204,7 @@ public int Add(Fact value, out bool exists, bool samestep = false) return key; } - public new bool Remove(int key) + public new bool Remove(string key) // hide { return this.Remove(key, false); @@ -211,14 +212,14 @@ public int Add(Fact value, out bool exists, bool samestep = false) public bool Remove(Fact value, bool samestep = false) { - if (!this.ContainsKey(value.Id)) + if (!this.ContainsKey(value.URI)) return false; - this.Remove(value.Id, samestep); + this.Remove(value.URI, samestep); return true; } - public bool Remove(int key, bool samestep = false) + public bool Remove(string key, bool samestep = false) //no reset check needed (impossible state) { if (!base.ContainsKey(key)) @@ -226,7 +227,7 @@ public bool Remove(int key, bool samestep = false) //TODO: see issue #58 - safe_dependencies(key, out List<int> deletethis); + safe_dependencies(key, out List<string> deletethis); if(deletethis.Count > 0) { @@ -238,12 +239,12 @@ public bool Remove(int key, bool samestep = false) // TODO: MMT: decide dependencies there (remember virtual deletions in Unity (un-redo)!) // TODO? decrease runtime from O(n/2) - public bool safe_dependencies(int key, out List<int> dependencies) + public bool safe_dependencies(string key, out List<string> dependencies) // searches for dependencies of a Fact; returns false if any dependencies are steproots // int key: Fact to be deleted // out List<int> dependencies: dependencyList { - dependencies = new List<int>(); + dependencies = new List<string>(); int c_unsafe = 0; int pos = MetaInf[key].workflow_id; @@ -280,7 +281,7 @@ public bool safe_dependencies(int key, out List<int> dependencies) return c_unsafe == 0; } - private void yeetusdeletus(List<int> deletereverse, bool samestep = false) + private void yeetusdeletus(List<string> deletereverse, bool samestep = false) { for(int i = deletereverse.Count - 1; i >= 0; i--, samestep = true) { @@ -400,7 +401,7 @@ public void load() // TODO: see issue #58 } - private void InvokeFactEvent(bool creation, int Id) + private void InvokeFactEvent(bool creation, string Id) { if (creation) CommunicationEvents.AddFactEvent.Invoke(this[Id]); diff --git a/Assets/Scripts/InteractionEngine/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactSpawner.cs index 8f3457d799cf4c83b4edad05a16e5384ef82a113..9874aef3b20413fab3d5183935851e976ff156b5 100644 --- a/Assets/Scripts/InteractionEngine/FactSpawner.cs +++ b/Assets/Scripts/InteractionEngine/FactSpawner.cs @@ -55,9 +55,8 @@ public Fact SpawnPoint(Fact pointFact) GameObject point = GameObject.Instantiate(FactRepresentation); point.transform.position = fact.Point; point.transform.up = fact.Normal; - string letter = ((Char)(64+fact.Id+1)).ToString(); - point.GetComponentInChildren<TextMeshPro>().text = letter; - point.GetComponent<FactObject>().Id = fact.Id; + point.GetComponentInChildren<TextMeshPro>().text = fact.Label; + point.GetComponent<FactObject>().URI = fact.URI; fact.Representation = point; return fact; } @@ -91,9 +90,9 @@ public Fact SpawnLine(Fact fact) //string letter = ((Char)(64 + lineFact.Id + 1)).ToString(); //line.GetComponentInChildren<TextMeshPro>().text = letter; - line.GetComponentInChildren<TextMeshPro>().text = ((Char)(64 + pointFact1.Id + 1)).ToString() + ((Char)(64 + pointFact2.Id + 1)).ToString(); + line.GetComponentInChildren<TextMeshPro>().text = pointFact1.Label + pointFact2.Label; line.GetComponentInChildren<TextMeshPro>().text += " = " + Math.Round((point1-point2).magnitude, 2) + " m"; - line.GetComponentInChildren<FactObject>().Id = lineFact.Id; + line.GetComponentInChildren<FactObject>().URI = lineFact.URI; lineFact.Representation = line; return lineFact; @@ -134,10 +133,9 @@ public Fact SpawnRay(Fact fact) line.transform.GetChild(0).localScale = v3T; line.transform.GetChild(0).rotation = Quaternion.FromToRotation(Vector3.right, point2 - point1); - string letter = ((Char)(64 + rayFact.Id + 1)).ToString(); - line.GetComponentInChildren<TextMeshPro>().text = letter; - - line.GetComponentInChildren<FactObject>().Id = rayFact.Id; + line.GetComponentInChildren<TextMeshPro>().text = rayFact.Label; + line.GetComponentInChildren<FactObject>().URI = rayFact.URI; + rayFact.Representation = line; return rayFact; } @@ -192,14 +190,14 @@ public Fact SpawnAngle(Fact fact) foreach (CircleSegmentGenerator c in segments) c.setAngle(angleValue); - angle.GetComponentInChildren<FactObject>().Id = angleFact.Id; + angle.GetComponentInChildren<FactObject>().URI = angleFact.URI; angleFact.Representation = angle; return angleFact; } public void DeleteObject(Fact fact) { - Debug.Log("delete obj of "+ fact.Id); + Debug.Log("delete obj of "+ fact.URI); GameObject factRepresentation = fact.Representation; GameObject.Destroy(factRepresentation); } diff --git a/Assets/Scripts/InteractionEngine/Gadgets/AngleTool.cs b/Assets/Scripts/InteractionEngine/Gadgets/AngleTool.cs index e8e8e4a56cc6b2235107783c101a08544cb3af6f..ce595794e6f78ba13ee4dd80c70195a496deb323 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/AngleTool.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/AngleTool.cs @@ -49,16 +49,16 @@ public override void OnHit(RaycastHit hit) if (!this.isActiveAndEnabled) return; if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { - PointFact tempFact = (PointFact)Facts[hit.transform.GetComponent<FactObject>().Id]; + PointFact tempFact = (PointFact)Facts[hit.transform.GetComponent<FactObject>().URI]; //If two points were already selected and now the third point got selected if (this.angleModeIsFirstPointSelected && this.angleModeIsSecondPointSelected) { //Create AngleFact //Check if new Point is equal to one of the previous points -> if true -> cancel - if (!(this.angleModeFirstPointSelected.Id == tempFact.Id || this.angleModeSecondPointSelected.Id == tempFact.Id)) + if (!(this.angleModeFirstPointSelected.URI == tempFact.URI || this.angleModeSecondPointSelected.URI == tempFact.URI)) { - FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).Id, ((PointFact)this.angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id, FactManager.GetFirstEmptyID()); + FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).URI, ((PointFact)this.angleModeSecondPointSelected).URI, ((PointFact)tempFact).URI); } ResetGadget(); @@ -67,7 +67,7 @@ public override void OnHit(RaycastHit hit) else if (this.angleModeIsFirstPointSelected && !this.angleModeIsSecondPointSelected) { //Check if the 2 selected points are the same: If not - if (this.angleModeFirstPointSelected.Id != tempFact.Id) + if (this.angleModeFirstPointSelected.URI != tempFact.URI) { this.angleModeIsSecondPointSelected = true; this.angleModeSecondPointSelected = tempFact; @@ -141,9 +141,9 @@ public void UpdateCurveDrawing(Vector3 currentPosition) foreach (var entry in Facts) { Fact fact = entry.Value; - if (fact is PointFact && fact.Id != angleModeFirstPointSelected.Id && fact.Id != angleModeSecondPointSelected.Id && nearestPoint == null) + if (fact is PointFact && fact.URI != angleModeFirstPointSelected.URI && fact.URI != angleModeSecondPointSelected.URI && nearestPoint == null) nearestPoint = (PointFact)fact; - else if (fact is PointFact && fact.Id != angleModeFirstPointSelected.Id && fact.Id != angleModeSecondPointSelected.Id && (nearestPoint.Point - currentPosition).magnitude > (((PointFact)fact).Point - currentPosition).magnitude) + else if (fact is PointFact && fact.URI != angleModeFirstPointSelected.URI && fact.URI != angleModeSecondPointSelected.URI && (nearestPoint.Point - currentPosition).magnitude > (((PointFact)fact).Point - currentPosition).magnitude) nearestPoint = (PointFact)fact; } diff --git a/Assets/Scripts/InteractionEngine/Gadgets/LineTool.cs b/Assets/Scripts/InteractionEngine/Gadgets/LineTool.cs index f7b2dde78aaaf4bf31eaaba6501727e2179bf7ba..f125fbb601540006179b91ab31a1ba303531bc50 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/LineTool.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/LineTool.cs @@ -40,13 +40,13 @@ public override void OnHit(RaycastHit hit) if (!this.isActiveAndEnabled) return; if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { - Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id]; + Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().URI]; //If first point was already selected AND second point != first point - if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.Id != tempFact.Id) + if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.URI != tempFact.URI) { //Create LineFact - FactManager.AddRayFact(this.LineModeFirstPointSelected.Id, tempFact.Id, FactManager.GetFirstEmptyID()); + FactManager.AddRayFact(this.LineModeFirstPointSelected.URI, tempFact.URI); this.ResetGadget(); } @@ -70,12 +70,10 @@ public override void OnHit(RaycastHit hit) if (Physics.Raycast(hit.transform.gameObject.transform.position - Vector3.down * 2, Vector3.down, out downHit)) { - int idA = downHit.transform.gameObject.GetComponent<FactObject>().Id; - int idB = this.LineModeFirstPointSelected.Id; - int idC = FactManager.GetFirstEmptyID(); - FactManager.AddPointFact(hit, idC); //Create LineFact - FactManager.AddAngleFact(idA, idB, idC, FactManager.GetFirstEmptyID()); + var idA = downHit.transform.gameObject.GetComponent<FactObject>().URI; + var idB = this.LineModeFirstPointSelected.URI; + FactManager.AddAngleFact(idA, idB, FactManager.AddPointFact(hit).URI); this.ResetGadget(); } diff --git a/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs b/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs index 1e0e9af2e0fdaa8ef34e3fa7ac27e6174a009d88..8b8095d84aa6f0cba0e5b830d84794eb9ddaa7ae 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs @@ -47,14 +47,14 @@ void OnDisable() public override void OnHit(RaycastHit hit) { - void CreateRayAndAngles(int pidIntersectionPoint, int pidLotPoint, bool samestep) + void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool samestep) { - FactManager.AddRayFact(pidIntersectionPoint, pidLotPoint, FactManager.GetFirstEmptyID(), samestep); + FactManager.AddRayFact(pidIntersectionPoint, pidLotPoint, samestep); //TODO: create at all? / for all points on basline? FactManager.AddAngleFact( this.LotModeLineSelected.Pid1 == pidIntersectionPoint ? this.LotModeLineSelected.Pid2 : this.LotModeLineSelected.Pid1, - pidIntersectionPoint, pidLotPoint, FactManager.GetFirstEmptyID(), true); + pidIntersectionPoint, pidLotPoint, true); } if (!this.isActiveAndEnabled) return; @@ -62,19 +62,17 @@ void CreateRayAndAngles(int pidIntersectionPoint, int pidLotPoint, bool samestep //If LotPoint is on baseLine if (this.LotModeIsPointSelected && (hit.transform.gameObject.layer == LayerMask.NameToLayer("Default") || hit.transform.gameObject.layer == LayerMask.NameToLayer("Tree"))) { - var pidLotPoint = FactManager.GetFirstEmptyID(); Vector3 LotPoint = Math3d.ProjectPointOnLine(hit.point, this.LotModeLineSelected.Dir, this.LotModeIntersectionPoint.Point); - //TODO: which normal? - FactManager.AddPointFact(pidLotPoint, LotPoint, hit.normal); - CreateRayAndAngles(this.LotModeIntersectionPoint.Id, pidLotPoint, true); + //TODO: which normal? + CreateRayAndAngles(this.LotModeIntersectionPoint.URI, FactManager.AddPointFact(LotPoint, hit.normal).URI, true); this.ResetGadget(); } //If baseline already selected and point selected else if (this.LotModeIsLineSelected && !this.LotModeIsPointSelected && hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { - PointFact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id] as PointFact; + PointFact tempFact = Facts[hit.transform.GetComponent<FactObject>().URI] as PointFact; Vector3 intersectionPoint = Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, tempFact.Point); @@ -87,13 +85,12 @@ void CreateRayAndAngles(int pidIntersectionPoint, int pidLotPoint, bool samestep //TODO: test Facts existance //add Facts - var intersectionId = FactManager.GetFirstEmptyID(); - FactManager.AddPointFact(intersectionId, intersectionPoint, this.LotModeLineHit.normal); + var intersectionId = FactManager.AddPointFact(intersectionPoint, this.LotModeLineHit.normal).URI; if(this.LotModeLineSelected is RayFact) //Add OnLineFact only on Ray not Line - FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.Id, FactManager.GetFirstEmptyID(), true); + FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.URI, true); - CreateRayAndAngles(intersectionId, tempFact.Id, true); + CreateRayAndAngles(intersectionId, tempFact.URI, true); this.ResetGadget(); } @@ -102,7 +99,7 @@ void CreateRayAndAngles(int pidIntersectionPoint, int pidLotPoint, bool samestep && (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray") || hit.transform.gameObject.layer == LayerMask.NameToLayer("Line"))) { - Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id]; + Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().URI]; //Activate LineDrawing for preview this.LotModeIsLineSelected = true; diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Pendulum.cs b/Assets/Scripts/InteractionEngine/Gadgets/Pendulum.cs index 83dcf7d0bbde34ab42b570a30aaa00877db21a39..7be05aed12822de0315a733b3d38386303124b4b 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Pendulum.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Pendulum.cs @@ -45,14 +45,13 @@ public override void OnHit(RaycastHit hit) if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { - PointFact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id] as PointFact; + PointFact tempFact = Facts[hit.transform.GetComponent<FactObject>().URI] as PointFact; //Raycast downwoard RaycastHit ground; if(Physics.Raycast(tempFact.Point, Vector3.down, out ground, Mathf.Infinity, this.LayerPendulumHits.value)) { - var pid = FactManager.GetFirstEmptyID(); - FactManager.AddPointFact(ground, pid); + FactManager.AddPointFact(ground); } } } diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs b/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs index be9f29ac661eb14266257aaa005d0948e41ddcda..5acc9934e9187513bb579e35d91db29cca6b3bb9 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs @@ -28,12 +28,11 @@ public override void OnHit(RaycastHit hit) { if (!this.isActiveAndEnabled) return; - var pid = FactManager.GetFirstEmptyID(); - FactManager.AddPointFact(hit, pid); + var pid = FactManager.AddPointFact(hit).URI; if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray")) { - FactManager.AddOnLineFact(pid, hit.transform.GetComponent<FactObject>().Id, FactManager.GetFirstEmptyID(), true); + FactManager.AddOnLineFact(pid, hit.transform.GetComponent<FactObject>().URI, true); } } diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Remover.cs b/Assets/Scripts/InteractionEngine/Gadgets/Remover.cs index e942aca949951e883d30f340e48115d53b06f400..7b626909dbe94321708242d84ba950719246d07a 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Remover.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Remover.cs @@ -31,7 +31,7 @@ public override void OnHit(RaycastHit hit) return; // TODO: ask/warn user to cascade - var hid = hit.transform.GetComponent<FactObject>().Id; + var hid = hit.transform.GetComponent<FactObject>().URI; Facts.Remove(hid); } diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Tape.cs b/Assets/Scripts/InteractionEngine/Gadgets/Tape.cs index 1de81facb47ab7629bdfc7dfc7fde1a43bb0dbcf..c31d81e9811e2802ed5ad78eaa69c2530460e284 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Tape.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Tape.cs @@ -40,17 +40,17 @@ public override void OnHit(RaycastHit hit) if (!this.isActiveAndEnabled) return; if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { - Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id]; + Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().URI]; //we can only reach points that are lower than that with the measuring tape if (/*ActiveToolMode == ToolMode.CreateLineMode && */tempFact.Representation.transform.position.y > 2.5f) return; //If first point was already selected AND second point != first point - if (this.TapeModeIsFirstPointSelected && this.TapeModeFirstPointSelected.Id != tempFact.Id) + if (this.TapeModeIsFirstPointSelected && this.TapeModeFirstPointSelected.URI != tempFact.URI) { //Create LineFact - FactManager.AddLineFact(this.TapeModeFirstPointSelected.Id, tempFact.Id, FactManager.GetFirstEmptyID()); + FactManager.AddLineFact(this.TapeModeFirstPointSelected.URI, tempFact.URI); this.ResetGadget(); } @@ -74,12 +74,11 @@ public override void OnHit(RaycastHit hit) if (Physics.Raycast(hit.transform.gameObject.transform.position - Vector3.down * 2, Vector3.down, out downHit)) { - int idA = downHit.transform.gameObject.GetComponent<FactObject>().Id; - int idB = this.TapeModeFirstPointSelected.Id; - int idC = FactManager.GetFirstEmptyID(); - FactManager.AddPointFact(hit, idC); + var idA = downHit.transform.gameObject.GetComponent<FactObject>().URI; + var idB = this.TapeModeFirstPointSelected.URI; + var idC = FactManager.AddPointFact(hit).URI; //Create LineFact - FactManager.AddAngleFact(idA, idB, idC, FactManager.GetFirstEmptyID(), true); + FactManager.AddAngleFact(idA, idB, idC, true); this.ResetGadget(); } diff --git a/Assets/Scripts/InteractionEngine/SmartMenu.cs b/Assets/Scripts/InteractionEngine/SmartMenu.cs index 1146bf0de3fba2045295f991286c9dd0579a07fb..42a882c6c2fdf16f99b210fb769c9cc3bfec3074 100644 --- a/Assets/Scripts/InteractionEngine/SmartMenu.cs +++ b/Assets/Scripts/InteractionEngine/SmartMenu.cs @@ -7,7 +7,7 @@ public class SmartMenu : MonoBehaviour public void DestroyObject() { - CommunicationEvents.Facts.Remove(CommunicationEvents.Facts[transform.parent.GetComponent<FactObject>().Id]); + CommunicationEvents.Facts.Remove(CommunicationEvents.Facts[transform.parent.GetComponent<FactObject>().URI]); } diff --git a/Assets/Scripts/InteractionEngine/WorldCursor.cs b/Assets/Scripts/InteractionEngine/WorldCursor.cs index 44e9b3f54372ab444fda95016e8b1ffedfd1ac20..3109f3f061f2a59cd65c0771ab8c026a644ba6fa 100644 --- a/Assets/Scripts/InteractionEngine/WorldCursor.cs +++ b/Assets/Scripts/InteractionEngine/WorldCursor.cs @@ -88,7 +88,7 @@ void Update() if(Hit.collider.gameObject.layer == LayerMask.NameToLayer("Ray") || Hit.collider.gameObject.layer == LayerMask.NameToLayer("Line")) { - int id = Hit.collider.gameObject.GetComponent<FactObject>().Id; + var id = Hit.collider.gameObject.GetComponent<FactObject>().URI; AbstractLineFact lineFact = CommunicationEvents.Facts[id] as AbstractLineFact; PointFact p1 = CommunicationEvents.Facts[lineFact.Pid1] as PointFact; diff --git a/Assets/Scripts/InteractionEngine/ZZZ_CompletionDemo.cs b/Assets/Scripts/InteractionEngine/ZZZ_CompletionDemo.cs deleted file mode 100644 index a2784b93b85fa091bc7ad2cfc341049e8829c04f..0000000000000000000000000000000000000000 --- a/Assets/Scripts/InteractionEngine/ZZZ_CompletionDemo.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Collections; -using TMPro; -using UnityEngine; -using static CommunicationEvents; - -public class ZZZ_CompletionDemo : MonoBehaviour -{ - private GameObject FactRepresentation; - private RaycastHit point1; - private RaycastHit point2; - private RaycastHit point3; - private AngleFact angle1; - - public FactManager FactManager; - - // Start is called before the first frame update - void Start() - { - //Default FactRepresenation = Sphere-Prefab for Points - this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Sphere", typeof(GameObject)); - if (FactManager == null) FactManager = GameObject.FindObjectOfType<FactManager>(); - - point1 = new RaycastHit(); - point1.normal = new Vector3(0.0f, 1.0f, 0.0f); - point1.point = new Vector3(4.1f, 0.0f, 7.6f); - - point2 = new RaycastHit(); - point2.normal = new Vector3(0.0f, 1.0f, 0.0f); - point2.point = new Vector3(2.6f, 0.0f, 2.2f); - - point3 = new RaycastHit(); - point3.normal = new Vector3(0.0f, 1.0f, 0.0f); - point3.point = new Vector3(2.6f, 6.3f, 2.2f); - - angle1 = new AngleFact(); - angle1.Id = 3; - angle1.Pid1 = 0; - angle1.Pid2 = 1; - angle1.Pid3 = 2; - } - - // Update is called once per frame - void Update() - { - - } - - public void CompletionDemo() - { - FactManager.AddPointFact(point1, 0); - FactManager.AddPointFact(point2, 1); - FactManager.AddPointFact(point3, 2); - - StartCoroutine(SpawnAngleCoroutine()); - - } - - IEnumerator SpawnAngleCoroutine() - { - yield return new WaitUntil(() => Facts.Count >= 3); - - StartCoroutine(SpawnAngleAndAnimate(angle1)); - } - - //Spawn an angle: point with id = angleFact.Pid2 is the point where the angle gets applied - IEnumerator SpawnAngleAndAnimate(AngleFact angleFact) - { - - Vector3 point1 = (Facts[angleFact.Pid1] as PointFact).Point; - Vector3 point2 = (Facts[angleFact.Pid2] as PointFact).Point; - Vector3 point3 = (Facts[angleFact.Pid3] as PointFact).Point; - - Vector3 tempPoint1; - Vector3 tempPoint3; - - //Length of the Angle relative to the Length of the shortest of the two lines (point2->point1) and (point2->point3) - float lengthFactor = 0.3f; - //AngleGO: Triangle-Length: 3/4, Circle-Length: 1/4 - float angleGoFactorTriangleToCircle = 1.33f;// 1.27f; - - //Make 2 TempPoints positioned on length% from Point2 to Point3 and on length% from Point2 to Point1 - //Will be used for z-Coordinate of the Angle - float length = 0; - if ((point1 - point2).magnitude >= (point3 - point2).magnitude) - { - length = lengthFactor * (point3 - point2).magnitude; - tempPoint1 = point2 + length * (point1 - point2).normalized; - tempPoint3 = point2 + length * (point3 - point2).normalized; - } - else - { - length = lengthFactor * (point1 - point2).magnitude; - tempPoint1 = point2 + length * (point1 - point2).normalized; - tempPoint3 = point2 + length * (point3 - point2).normalized; - } - - //Change FactRepresentation to Angle - this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Angle", typeof(GameObject)); - GameObject angle = GameObject.Instantiate(FactRepresentation); - - //Place the Angle at position of point2 - angle.transform.position = point2; - - //Change scale and rotation, so that the angle is in between the two lines - var v3T = angle.transform.localScale; - //Calculate the Vector from point 2 to a POINT, where (point2->POINT) is orthogonal to (POINT->tempPoint3) - Vector3 tempProjection = Vector3.Project((tempPoint3 - point2), (Vector3.Lerp((tempPoint1 - point2).normalized, (tempPoint3 - point2).normalized, 0.5f))); - - //Make the Angle as long as length + length of the half-circle - v3T.x = (tempProjection).magnitude * angleGoFactorTriangleToCircle; - - //For every Coordinate x,y,z we have to devide it by the LocalScale of the Child, - //because actually the Child should be of this length and not the parent, which is only the Collider - v3T.x = v3T.x / angle.transform.GetChild(0).GetChild(0).localScale.x; - - //y of the angle-GameObject here hard coded = ratio of sphere-prefab - v3T.y = 0.05f / angle.transform.GetChild(0).GetChild(0).localScale.y; - - //z should be as long as the distance between tempPoint1 and tempPoint3 - v3T.z = (tempPoint3 - tempPoint1).magnitude / angle.transform.GetChild(0).GetChild(0).localScale.z; - - //Change Scale/Rotation of the Line-GameObject without affecting Scale of the Text - angle.transform.GetChild(0).localScale = v3T; - - //Rotate so that the rotation points from point2 to the middle of point3 and point1 - angle.transform.GetChild(0).rotation = Quaternion.FromToRotation(Vector3.right, (Vector3.Lerp((tempPoint1 - point2).normalized, (tempPoint3 - point2).normalized, 0.5f))); - //Now the rotation around that direction must also be adjusted - //We calculate the Angle not with Vector3.Angle() because it only returns absolute angle-values - float signedAngle = Mathf.Atan2(Vector3.Dot((Vector3.Lerp((tempPoint1 - point2).normalized, (tempPoint3 - point2).normalized, 0.5f)), Vector3.Cross(angle.transform.GetChild(0).forward.normalized, (tempPoint1 - tempPoint3).normalized)), Vector3.Dot(angle.transform.GetChild(0).forward.normalized, (tempPoint1 - tempPoint3).normalized)) * Mathf.Rad2Deg; - if (signedAngle < 0) - { - angle.transform.GetChild(0).RotateAround(point2, (Vector3.Lerp((tempPoint1 - point2).normalized, (tempPoint3 - point2).normalized, 0.5f)), Vector3.Angle(angle.transform.GetChild(0).forward.normalized, (tempPoint3 - tempPoint1).normalized)); - } - else - angle.transform.GetChild(0).RotateAround(point2, (Vector3.Lerp((tempPoint1 - point2).normalized, (tempPoint3 - point2).normalized, 0.5f)), Vector3.Angle(angle.transform.GetChild(0).forward.normalized, (tempPoint1 - tempPoint3).normalized)); - - //string letter = ((Char)(64 + angleFact.Id + 1)).ToString(); - //Don't need next line anymore: Cause Text is now not above, but in the centre of the angle - //angle.GetComponentInChildren<TextMeshPro>().transform.localPosition = new Vector3((0.5f * tempProjection).x, angle.GetComponentInChildren<TextMeshPro>().transform.localPosition.y, (0.5f * tempProjection).z); - - TextMeshPro[] texts = angle.GetComponentsInChildren<TextMeshPro>(); - foreach (TextMeshPro t in texts) - { - //Change Text not to the id, but to the angle-value (from both sides) AND change font-size relative to length of the angle (from both sides) - t.text = Math.Abs(Math.Round(Vector3.Angle((point1 - point2).normalized, (point3 - point2).normalized), 1)) + "°"; - t.fontSize = angle.GetComponentInChildren<TextMeshPro>().fontSize * angle.transform.GetChild(0).transform.GetChild(0).localScale.x; - } - - angle.GetComponentInChildren<FactObject>().Id = angleFact.Id; - angleFact.Representation = angle; - //Test - Animator temp = angle.GetComponentInChildren<Animator>(); - temp.SetTrigger("animateHint"); - - CommunicationEvents.parameterDisplayHint.Invoke("∠ABC"); - - yield return new WaitForSeconds(7); - - GameObject.Destroy(angle); - } -} diff --git a/Assets/Scripts/InteractionEngine/ZZZ_CompletionDemo.cs.meta b/Assets/Scripts/InteractionEngine/ZZZ_CompletionDemo.cs.meta deleted file mode 100644 index ab0e077712d35933ea5e97d1cc334609f5e9e37b..0000000000000000000000000000000000000000 --- a/Assets/Scripts/InteractionEngine/ZZZ_CompletionDemo.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2f471110eb1ee16418760feafa2a9bd0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/InventoryStuff/DisplayFacts.cs b/Assets/Scripts/InventoryStuff/DisplayFacts.cs index eace9107740d0a3409bdfd36466f3c1808cc9707..2141e6e56bf22d2df97c4b174f0af936f58ba539 100644 --- a/Assets/Scripts/InventoryStuff/DisplayFacts.cs +++ b/Assets/Scripts/InventoryStuff/DisplayFacts.cs @@ -45,20 +45,20 @@ void Start() } public void AddFact(Fact fact) { - int fid = fact.Id; + var fid = fact.URI; var obj = CreateDisplay(transform, fact); - obj.GetComponent<RectTransform>().localPosition = GetPosition(fid); - displayedFacts.Add(fact.backendURI, obj); + obj.GetComponent<RectTransform>().localPosition = GetPosition(displayedFacts.Count); + displayedFacts.Add(fact.URI, obj); } public void RemoveFact(Fact fact) { - GameObject.Destroy(displayedFacts[fact.backendURI]); - displayedFacts.Remove(fact.backendURI); + GameObject.Destroy(displayedFacts[fact.URI]); + displayedFacts.Remove(fact.URI); } public void AnimateFact(Fact fact) { - var factIcon = displayedFacts[fact.backendURI]; + var factIcon = displayedFacts[fact.URI]; factIcon.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); } diff --git a/Assets/Scripts/InventoryStuff/DisplayScrolls.cs b/Assets/Scripts/InventoryStuff/DisplayScrolls.cs index ad3b639e3c0ace2641a14ddcbb8cf0e9f6e34670..fbd9abf21f1faa7448ff70b8ce88481b46114a79 100644 --- a/Assets/Scripts/InventoryStuff/DisplayScrolls.cs +++ b/Assets/Scripts/InventoryStuff/DisplayScrolls.cs @@ -68,8 +68,10 @@ IEnumerator getScrollsfromServer() { request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); request.method = UnityWebRequest.kHttpVerbGET; - yield return request.Send(); - if (request.isNetworkError || request.isHttpError) + yield return request.SendWebRequest(); + + if (request.result == UnityWebRequest.Result.ConnectionError + || request.result == UnityWebRequest.Result.ProtocolError) { Debug.LogWarning(request.error); Debug.Log("GET Scroll/list failed. Attempt: " + (i + 1).ToString()); @@ -80,7 +82,8 @@ IEnumerator getScrollsfromServer() } } - if (request.isNetworkError || request.isHttpError) + if (request.result == UnityWebRequest.Result.ConnectionError + || request.result == UnityWebRequest.Result.ProtocolError) { Debug.LogWarning(request.error); string jsonString = File.ReadAllText(Application.streamingAssetsPath + "/scrolls.json"); diff --git a/Assets/Scripts/InventoryStuff/DropHandling.cs b/Assets/Scripts/InventoryStuff/DropHandling.cs index b9f19cf42b830341f91178032088127f4dd1a33f..bf5b3035d8bff7571a0fca2670a850e05ba1ea6e 100644 --- a/Assets/Scripts/InventoryStuff/DropHandling.cs +++ b/Assets/Scripts/InventoryStuff/DropHandling.cs @@ -25,7 +25,7 @@ public void OnDrop(PointerEventData eventData) current.transform.SetParent(gameObject.transform, false); currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact; - Debug.Log("recieved Fact: " + currentFact.backendURI); + Debug.Log("recieved Fact: " + currentFact.URI); CommunicationEvents.NewAssignmentEvent.Invoke(); } diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs index 02644e1ae75ab4b0406404aca6a7612ca133a9c0..ba0fb8d3bbf60dcfc0be8a34389df2ca652d90c9 100644 --- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs +++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs @@ -114,13 +114,14 @@ IEnumerator sendView(string endpoint) UnityWebRequest www = UnityWebRequest.Put(ServerAdress + endpoint, body); www.method = UnityWebRequest.kHttpVerbPOST; www.SetRequestHeader("Content-Type", "application/json"); - var async = www.Send(); + var async = www.SendWebRequest(); while (!async.isDone) { //Non blocking wait for one frame, for letting the game do other things yield return null; } - if (www.isNetworkError || www.isHttpError) + if (www.result == UnityWebRequest.Result.ConnectionError + || www.result == UnityWebRequest.Result.ProtocolError) { Debug.Log(www.error); currentMmtAnswer = null; @@ -145,7 +146,7 @@ private string prepareScrollAssignments() if (tempFact != null) { listEntry.fact = new Scroll.UriReference(this.scroll.requiredFacts[i].@ref.uri); - listEntry.assignment = new JSONManager.OMS(tempFact.backendURI); + listEntry.assignment = new JSONManager.OMS(tempFact.URI); assignmentList.Add(listEntry); } } @@ -167,9 +168,6 @@ private void readPushout(List<Scroll.ScrollFact> pushoutFacts) Fact newFact = ParsingDictionary.parseFactDictionary[pushoutFacts[i].getType()].Invoke(pushoutFacts[i]); if (newFact != null) { - int id = factManager.GetFirstEmptyID(); - newFact.Id = id; - FactManager.AddFactIfNotFound(newFact, out bool exists, samestep); if(!exists) PushoutFactEvent.Invoke(newFact); @@ -223,7 +221,7 @@ public List<string> processRenderedScroll(Scroll rendered, List<string> hintUris if (currentFact != null && currentFact.hasDependentFacts()) { //Hint available for abstract-problem uri - hintUris.Add(currentFact.backendURI); + hintUris.Add(currentFact.URI); LatestRenderedHints.Add(currentFact); } } @@ -238,9 +236,9 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) { if (suitableCompletion != null) { - if (Facts.searchURI(suitableCompletion.assignment.uri, out int factId)) + if (Facts.ContainsKey(suitableCompletion.assignment.uri)) { - fact = Facts[factId]; + fact = Facts[suitableCompletion.assignment.uri]; //Animate ScrollParameter scrollParameter.GetComponentInChildren<ImageHintAnimation>().AnimationTrigger(); //Animate Fact in FactPanel @@ -249,10 +247,10 @@ public void animateHint(GameObject scrollParameter, string scrollParameterUri) { fact.Representation.GetComponentInChildren<MeshRendererHintAnimation>().AnimationTrigger(); } } - else if (LatestRenderedHints.Exists(x => x.backendURI.Equals(scrollParameterUri))) + else if (LatestRenderedHints.Exists(x => x.URI.Equals(scrollParameterUri))) { - fact = LatestRenderedHints.Find(x => x.backendURI.Equals(scrollParameterUri)); - int factId = fact.Id; + fact = LatestRenderedHints.Find(x => x.URI.Equals(scrollParameterUri)); + var factId = fact.URI; //If there is an equal existing fact -> Animate that fact AND ScrollParameter if (Facts.ContainsKey(factId)) diff --git a/Assets/Scripts/StartServer.cs b/Assets/Scripts/StartServer.cs index dcb7d8426be089c5445b0848aed31d466d72e95f..6f4a69df8ec04eaa2a94f9ad8f21e57b5cb1a2e6 100644 --- a/Assets/Scripts/StartServer.cs +++ b/Assets/Scripts/StartServer.cs @@ -81,7 +81,9 @@ IEnumerator ServerRoutine() { UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); yield return request.SendWebRequest(); - if (request.isNetworkError || request.isHttpError) + + if (request.result == UnityWebRequest.Result.ConnectionError + || request.result == UnityWebRequest.Result.ProtocolError) { UnityEngine.Debug.Log("no running server " + request.error); @@ -106,7 +108,8 @@ IEnumerator ServerRoutine() { request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); yield return request.SendWebRequest(); - if (request.isNetworkError || request.isHttpError) + if (request.result == UnityWebRequest.Result.ConnectionError + || request.result == UnityWebRequest.Result.ProtocolError) { // UnityEngine.Debug.Log("no running server"); } diff --git a/Assets/Standard Assets/Utility/ActivateTrigger.cs b/Assets/Standard Assets/Utility/ActivateTrigger.cs index c83f5404de679fdd137f384104319fbed8ecc834..02a7e0afaf1650e566dea656e0faec07987bec3f 100644 --- a/Assets/Standard Assets/Utility/ActivateTrigger.cs +++ b/Assets/Standard Assets/Utility/ActivateTrigger.cs @@ -53,7 +53,7 @@ private void DoActivateTrigger() { Instantiate(source, targetGameObject.transform.position, targetGameObject.transform.rotation); - DestroyObject(targetGameObject); + Destroy(targetGameObject); } } break; diff --git a/Assets/Standard Assets/Utility/TimedObjectDestructor.cs b/Assets/Standard Assets/Utility/TimedObjectDestructor.cs index ff681d6d1bc9cb791e1e3065c903001d4b847063..1ddc5c990e8f580aeb9fdf0441c1d9c89901c18d 100644 --- a/Assets/Standard Assets/Utility/TimedObjectDestructor.cs +++ b/Assets/Standard Assets/Utility/TimedObjectDestructor.cs @@ -20,7 +20,7 @@ private void DestroyNow() { transform.DetachChildren(); } - DestroyObject(gameObject); + Destroy(gameObject); } } }