Skip to content
Snippets Groups Projects
Commit 7fdd3c1a authored by Benjamin Bösl's avatar Benjamin Bösl
Browse files

started pushout readout

parent d30780b8
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ public abstract class Fact ...@@ -11,6 +11,7 @@ public abstract class Fact
public class AddFactResponse public class AddFactResponse
{ {
//class to Read AddFact Responses.
public string factUri; public string factUri;
public string factValUri; public string factValUri;
...@@ -35,6 +36,7 @@ public static AddFactResponse sendAdd(string path, string body) { ...@@ -35,6 +36,7 @@ public static AddFactResponse sendAdd(string path, string body) {
} }
} }
} }
//I am not sure if we ever need to attach these to an object, so one script for all for now... //I am not sure if we ever need to attach these to an object, so one script for all for now...
public class PointFact : Fact public class PointFact : Fact
{ {
...@@ -51,13 +53,25 @@ public PointFact(int i,Vector3 P, Vector3 N) { ...@@ -51,13 +53,25 @@ public PointFact(int i,Vector3 P, Vector3 N) {
this.backendURI = res.factUri; this.backendURI = res.factUri;
} }
public PointFact(int i, float a, float b, float c, string uri)
{
this.Id = i;
this.Point = new Vector3(a,b,c);
this.Normal = new Vector3(0,1,0);
this.backendURI = uri;
}
} }
public class OpenLineFact : Fact public class OpenLineFact : Fact
{ {
//an infinite Line through the Points Pid1 and Pid2 //an infinite Line through the Points Pid1 and Pid2
public int Pid1, Pid2; public int Pid1, Pid2;
} }
public class LineFact : Fact public class LineFact : Fact
{ {
//Id's of the 2 Point-Facts that are connected //Id's of the 2 Point-Facts that are connected
...@@ -81,8 +95,17 @@ public LineFact(int i, int pid1, int pid2) { ...@@ -81,8 +95,17 @@ public LineFact(int i, int pid1, int pid2) {
this.backendValueURI = res.factValUri; this.backendValueURI = res.factValUri;
} }
public LineFact(int i, int pid1, int pid2, string uri, string valuri) {
this.Id = i;
this.Pid1 = pid1;
this.Pid2 = pid2;
this.backendURI = uri;
this.backendValueURI = valuri;
}
} }
public class AngleFact : Fact public class AngleFact : Fact
{ {
//Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is //Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is
...@@ -91,7 +114,8 @@ public class AngleFact : Fact ...@@ -91,7 +114,8 @@ public class AngleFact : Fact
//only for temporary Use of AngleFacts //only for temporary Use of AngleFacts
public AngleFact() { } public AngleFact() { }
public AngleFact(int i, int pid1, int pid2, int pid3) { public AngleFact(int i, int pid1, int pid2, int pid3)
{
this.Id = i; this.Id = i;
this.Pid1 = pid1; this.Pid1 = pid1;
this.Pid2 = pid2; this.Pid2 = pid2;
...@@ -110,6 +134,16 @@ public AngleFact(int i, int pid1, int pid2, int pid3) { ...@@ -110,6 +134,16 @@ public AngleFact(int i, int pid1, int pid2, int pid3) {
this.backendURI = res.factUri; this.backendURI = res.factUri;
this.backendValueURI = res.factValUri; this.backendValueURI = res.factValUri;
} }
public AngleFact(int i, int pid1, int pid2, int pid3, string uri, string valuri)
{
this.Id = i;
this.Pid1 = pid1;
this.Pid2 = pid2;
this.Pid3 = pid3;
this.backendURI = uri;
this.backendValueURI = valuri;
}
} }
public class OnLineFact : Fact public class OnLineFact : Fact
{ {
......
...@@ -47,6 +47,9 @@ public void UpdateDisplay2() ...@@ -47,6 +47,9 @@ public void UpdateDisplay2()
} }
} }
string getLetter(int Id) {
return ((Char)(64 + Id + 1)).ToString();
}
private GameObject CreateDisplay(Transform transform, Fact fact) private GameObject CreateDisplay(Transform transform, Fact fact)
{ {
...@@ -55,8 +58,8 @@ private GameObject CreateDisplay(Transform transform, Fact fact) ...@@ -55,8 +58,8 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
case LineFact f: case LineFact f:
{ {
var obj = Instantiate(prefab_Distance, Vector3.zero, Quaternion.identity, transform); var obj = Instantiate(prefab_Distance, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid1].Id; obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter( CommunicationEvents.Facts[f.Pid1].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid2].Id; obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid2].Id );
obj.GetComponent<FactWrapper>().fact = f; obj.GetComponent<FactWrapper>().fact = f;
return obj; return obj;
} }
...@@ -64,9 +67,9 @@ private GameObject CreateDisplay(Transform transform, Fact fact) ...@@ -64,9 +67,9 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
case AngleFact f: case AngleFact f:
{ {
var obj = Instantiate(prefab_Angle, Vector3.zero, Quaternion.identity, transform); var obj = Instantiate(prefab_Angle, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid1].Id; obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid1].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid2].Id; obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid2].Id);
obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid3].Id; obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid3].Id);
obj.GetComponent<FactWrapper>().fact = f; obj.GetComponent<FactWrapper>().fact = f;
return obj; return obj;
} }
...@@ -74,7 +77,7 @@ private GameObject CreateDisplay(Transform transform, Fact fact) ...@@ -74,7 +77,7 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
case PointFact f: case PointFact f:
{ {
var obj = Instantiate(prefab_Point, Vector3.zero, Quaternion.identity, transform); var obj = Instantiate(prefab_Point, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + f.Id; obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(f.Id );
obj.GetComponent<FactWrapper>().fact = f; obj.GetComponent<FactWrapper>().fact = f;
return obj; return obj;
} }
......
...@@ -14,7 +14,6 @@ public void OnDrag(PointerEventData eventData){ ...@@ -14,7 +14,6 @@ public void OnDrag(PointerEventData eventData){
dragged = true; dragged = true;
} }
transform.position = Input.mousePosition; transform.position = Input.mousePosition;
Debug.Log(gameObject.GetComponent<FactWrapper>().fact.backendURI);
} }
public void OnEndDrag(PointerEventData eventData){ public void OnEndDrag(PointerEventData eventData){
......
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
using UnityEngine; using UnityEngine;
using TMPro; using TMPro;
using UnityEngine.Networking; using UnityEngine.Networking;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml.Linq;
public class ScrollDetails : MonoBehaviour public class ScrollDetails : MonoBehaviour
{ {
public GameObject cursor;
public GameObject parameterDisplayPrefab; public GameObject parameterDisplayPrefab;
public Scroll scroll; public Scroll scroll;
...@@ -110,6 +113,61 @@ private string sendView() { ...@@ -110,6 +113,61 @@ private string sendView() {
} }
class PushoutReturn {
public string newSituation;
public PushoutFact[] outputs;
}
public class PushoutFact {
// generic class to make a common Supertype for all PushoutResponses
public string uri;
public string value;
public string a;
public string b;
public string c;
public string pointA;
public string pointB;
public string left;
public string middle;
public string right;
public bool isVector() {
return a != null &&
b != null &&
c != null &&
pointA == null &&
pointB == null &&
value == null &&
left == null &&
middle == null &&
right == null;
}
public bool isDistance()
{
return a == null &&
b == null &&
c == null &&
pointA != null &&
pointB != null &&
value != null &&
left == null &&
middle == null &&
right == null;
}
public bool isAngle()
{
return a == null &&
b == null &&
c == null &&
pointA == null &&
pointB == null &&
value != null &&
left != null &&
middle != null &&
right != null;
}
}
private string pushout(string view) { private string pushout(string view) {
string path = "localhost:8081/pushout?"; string path = "localhost:8081/pushout?";
path = path + "problem=" + this.scroll.problemTheory + "&"; path = path + "problem=" + this.scroll.problemTheory + "&";
...@@ -128,8 +186,50 @@ private string pushout(string view) { ...@@ -128,8 +186,50 @@ private string pushout(string view) {
else else
{ {
string answer = www.downloadHandler.text; string answer = www.downloadHandler.text;
return answer; readPushout(answer);
return "true";
//return answer;
//TODO Parse Anwser from JSON TO FACTS... //TODO Parse Anwser from JSON TO FACTS...
} }
} }
private void readPushout(string txt) {
PushoutReturn ret = JsonUtility.FromJson<PushoutReturn>(txt);
this.situationTheory = ret.newSituation;
FactManager factManager = cursor.GetComponent<FactManager>();
for (int i = 0; i < ret.outputs.Length; i++) {
PushoutFact f = ret.outputs[i];
if (f.isVector()) {
float a = float.Parse(f.a);
float b = float.Parse(f.b);
float c = float.Parse(f.c);
int id = factManager.GetFirstEmptyID();
PointFact pf = new PointFact(id, a, b, c, f.uri);
CommunicationEvents.Facts.Insert(id, pf);
CommunicationEvents.AddFactEvent.Invoke(pf);
}
if (f.isDistance()) {
int id = factManager.GetFirstEmptyID();
int pid1 = getIdforBackendURI(f.pointA);
int pid2 = getIdforBackendURI(f.pointB);
LineFact lf = new LineFact(id, pid1, pid2, f.uri, f.value);
CommunicationEvents.Facts.Insert(id, lf);
CommunicationEvents.AddFactEvent.Invoke(lf);
}
if (f.isAngle()){
int id = factManager.GetFirstEmptyID();
int pid1 = getIdforBackendURI(f.left);
int pid2 = getIdforBackendURI(f.middle);
int pid3 = getIdforBackendURI(f.right);
AngleFact af = new AngleFact(id, pid1, pid2, pid3, f.uri, f.value);
CommunicationEvents.Facts.Insert(id, af);
CommunicationEvents.AddFactEvent.Invoke(af);
}
}
}
private int getIdforBackendURI(string uri) {
return CommunicationEvents.Facts.Find(x => x.backendURI.Equals(uri)).Id;
}
} }
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment