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
public class AddFactResponse
{
//class to Read AddFact Responses.
public string factUri;
public string factValUri;
......@@ -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...
public class PointFact : Fact
{
......@@ -51,13 +53,25 @@ public PointFact(int i,Vector3 P, Vector3 N) {
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
{
//an infinite Line through the Points Pid1 and Pid2
public int Pid1, Pid2;
}
public class LineFact : Fact
{
//Id's of the 2 Point-Facts that are connected
......@@ -81,8 +95,17 @@ public LineFact(int i, int pid1, int pid2) {
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
{
//Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is
......@@ -91,7 +114,8 @@ public class AngleFact : Fact
//only for temporary Use of AngleFacts
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.Pid1 = pid1;
this.Pid2 = pid2;
......@@ -102,14 +126,24 @@ public AngleFact(int i, int pid1, int pid2, int pid3) {
double v = Vector3.Angle((pf1.Point - pf2.Point), (pf1.Point - pf2.Point));
string body = @"{" +
@"""left"":""" + pf1.backendURI + @"""," +
@"""middle"":""" + pf2.backendURI + @""","+
@"""right"":""" + pf3.backendURI + @""","+
@"""middle"":""" + pf2.backendURI + @"""," +
@"""right"":""" + pf3.backendURI + @"""," +
@"""value"":" + v +
"}";
AddFactResponse res = AddFactResponse.sendAdd("localhost:8081/fact/add/angle", body);
this.backendURI = res.factUri;
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
{
......
......@@ -47,6 +47,9 @@ public void UpdateDisplay2()
}
}
string getLetter(int Id) {
return ((Char)(64 + Id + 1)).ToString();
}
private GameObject CreateDisplay(Transform transform, Fact fact)
{
......@@ -55,8 +58,8 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
case LineFact f:
{
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(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid2].Id;
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter( CommunicationEvents.Facts[f.Pid1].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid2].Id );
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
......@@ -64,9 +67,9 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
case AngleFact f:
{
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(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid2].Id;
obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid3].Id;
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid1].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid2].Id);
obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid3].Id);
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
......@@ -74,7 +77,7 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
case PointFact f:
{
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;
return obj;
}
......
......@@ -14,7 +14,6 @@ public void OnDrag(PointerEventData eventData){
dragged = true;
}
transform.position = Input.mousePosition;
Debug.Log(gameObject.GetComponent<FactWrapper>().fact.backendURI);
}
public void OnEndDrag(PointerEventData eventData){
......
......@@ -3,10 +3,13 @@
using UnityEngine;
using TMPro;
using UnityEngine.Networking;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml.Linq;
public class ScrollDetails : MonoBehaviour
{
public GameObject cursor;
public GameObject parameterDisplayPrefab;
public Scroll scroll;
......@@ -20,18 +23,18 @@ public class ScrollDetails : MonoBehaviour
public Vector3 GetPosition(int i)
{
return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items ), 0f);
return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items), 0f);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void setScroll(Scroll s) {
......@@ -67,12 +70,12 @@ public void magicButton() {
string FAIL = "FAIL";
class ViewResponse {
public string view;
public string view;
}
private string sendView() {
string jsonRequest = @"{";
jsonRequest = jsonRequest + @" ""from"":""" + this.scroll.problemTheory + @""", ";
jsonRequest = jsonRequest + @" ""from"":""" + this.scroll.problemTheory + @""", ";
jsonRequest = jsonRequest + @" ""to"":""" + this.situationTheory + @""", ";
jsonRequest = jsonRequest + @" ""mappings"": { ";
......@@ -82,7 +85,7 @@ private string sendView() {
Fact fact_i = ParameterDisplays[i].GetComponentInChildren<DropHandling>().currentFact;
var drophandler = ParameterDisplays[i].GetComponentInChildren<DropHandling>();
Declaration decl_i = scroll.declarations[i];
jsonRequest = jsonRequest + @" """+decl_i.identifier +@""":""" + fact_i.backendURI + @""",";
jsonRequest = jsonRequest + @" """ + decl_i.identifier + @""":""" + fact_i.backendURI + @""",";
if (decl_i.value != null && fact_i.backendValueURI != null)
{
jsonRequest = jsonRequest + @" """ + decl_i.value + @""":""" + fact_i.backendValueURI + @""",";
......@@ -91,7 +94,7 @@ private string sendView() {
//removing the last ','
jsonRequest = jsonRequest.Substring(0, jsonRequest.Length - 1);
jsonRequest = jsonRequest + "}}";
UnityWebRequest www = UnityWebRequest.Put("localhost:8081/view/add", jsonRequest);
www.method = UnityWebRequest.kHttpVerbPOST;
var async = www.Send();
......@@ -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) {
string path = "localhost:8081/pushout?";
path = path + "problem=" + this.scroll.problemTheory + "&";
......@@ -128,8 +186,50 @@ private string pushout(string view) {
else
{
string answer = www.downloadHandler.text;
return answer;
readPushout(answer);
return "true";
//return answer;
//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.
Finish editing this message first!
Please register or to comment