//Default test implementations public MockGSAApp(IGSASettings settings = null, IGSAProxy proxy = null, IGSACacheForKit cache = null, IGSAMessenger messenger = null) { Cache = cache ?? new GSACache(); Settings = settings ?? new MockSettings(); if (proxy == null) { /* * var mockGSAObject = new Mock<IGSAProxy>(); * * mockGSAObject.Setup(x => x.NodeAt(It.IsAny<double>(), It.IsAny<double>(), It.IsAny<double>(), It.IsAny<double>())) * .Returns(new Func<double, double, double, double, int>(MockGSAProxy.NodeAt)); * mockGSAObject.Setup(x => x.FormatApplicationIdSidTag(It.IsAny<string>())) * .Returns(new Func<string, string>(MockGSAProxy.FormatApplicationIdSidTag)); * mockGSAObject.Setup(x => x.FormatSidTags(It.IsAny<string>(), It.IsAny<string>())) * .Returns(new Func<string, string, string>(MockGSAProxy.FormatSidTags)); * mockGSAObject.Setup(x => x.ConvertGSAList(It.IsAny<string>(), It.IsAny<GSAEntity>())) * .Returns(new Func<string, GSAEntity, int[]>(MockGSAProxy.ConvertGSAList)); * mockGSAObject.SetupGet(x => x.GwaDelimiter).Returns(GSAProxy.GwaDelimiter); * mockGSAObject.Setup(x => x.GetUnits()).Returns("m"); * * Proxy = mockGSAObject.Object; */ Proxy = new TestProxy(); } else { Proxy = proxy; } Messenger = messenger ?? new MockGSAMessenger(); }
//Default test implementations public MockGSAApp(IGSASettings settings = null, IGSAProxy proxy = null, IGSACacheForKit cache = null, IGSAMessenger messenger = null) { Cache = cache ?? new GSACache(); Settings = settings ?? new MockSettings(); if (proxy == null) { var mockGSAObject = new Mock <IGSAProxy>(); mockGSAObject.Setup(x => x.ParseGeneralGwa(It.IsAny <string>(), out It.Ref <string> .IsAny, out It.Ref <int?> .IsAny, out It.Ref <string> .IsAny, out It.Ref <string> .IsAny, out It.Ref <string> .IsAny, out It.Ref <GwaSetCommandType?> .IsAny, It.IsAny <bool>())) .Callback(new MockGSAProxy.ParseCallback(MockGSAProxy.ParseGeneralGwa)); mockGSAObject.Setup(x => x.NodeAt(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>())) .Returns(new Func <double, double, double, double, int>(MockGSAProxy.NodeAt)); mockGSAObject.Setup(x => x.FormatApplicationIdSidTag(It.IsAny <string>())) .Returns(new Func <string, string>(MockGSAProxy.FormatApplicationIdSidTag)); mockGSAObject.Setup(x => x.FormatSidTags(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Func <string, string, string>(MockGSAProxy.FormatSidTags)); mockGSAObject.Setup(x => x.ConvertGSAList(It.IsAny <string>(), It.IsAny <GSAEntity>())) .Returns(new Func <string, GSAEntity, int[]>(MockGSAProxy.ConvertGSAList)); mockGSAObject.SetupGet(x => x.GwaDelimiter).Returns(GSAProxy.GwaDelimiter); mockGSAObject.Setup(x => x.GetUnits()).Returns("m"); Proxy = mockGSAObject.Object; } else { Proxy = proxy; } Messenger = messenger ?? new MockGSAMessenger(); }
public string SetGWACommand(IGSAProxy GSA, int group = 0) { if (this.Value == null) { return(""); } var spring = this.Value as Structural0DSpring; var keyword = typeof(GSA0DSpring).GetGSAKeyword(); var index = Initialiser.Cache.ResolveIndex(keyword, spring.ApplicationId); var propRef = 0; try { propRef = Initialiser.Cache.LookupIndex(typeof(GSASpringProperty).GetGSAKeyword(), spring.PropertyRef).Value; } catch { } var ls = new List <string> { "SET", keyword + ":" + HelperClass.GenerateSID(spring), index.ToString(), spring.Name == null || spring.Name == "" ? " " : spring.Name, "NO_RGB", "GRD_SPRING", //type propRef.ToString(), //Property group.ToString(), //Group //"1", //Group }; //Topology for (var i = 0; i < spring.Value.Count(); i += 3) { ls.Add(HelperClass.NodeAt(spring.Value[i], spring.Value[i + 1], spring.Value[i + 2], Initialiser.Settings.CoincidentNodeAllowance).ToString()); } ls.Add("0"); // Orientation Node ls.Add("0"); //Angle ls.Add("NO_RLS"); //is_rls ls.Add("0"); ls.Add("0"); ls.Add("0"); ls.Add("0"); //ls.Add("NORMAL"); // Action // TODO: EL.4 SUPPORT ls.Add((spring.Dummy.HasValue && spring.Dummy.Value) ? "DUMMY" : ""); return(string.Join("\t", ls)); }
/// <summary> /// Calculates the local axis of a point from a GSA node axis. /// </summary> /// <param name="axis">ID of GSA node axis</param> /// <param name="gwaRecord">GWA record of AXIS if used</param> /// <param name="evalAtCoor">Coordinates to evaluate axis at</param> /// <returns>Axis</returns> public static StructuralAxis Parse0DAxis(int axis, IGSAProxy interfacer, out string gwaRecord, double[] evalAtCoor = null) { Vector3D x; Vector3D y; Vector3D z; gwaRecord = null; switch (axis) { case 0: // Global return(new StructuralAxis( new StructuralVectorThree(new double[] { 1, 0, 0 }), new StructuralVectorThree(new double[] { 0, 1, 0 }), new StructuralVectorThree(new double[] { 0, 0, 1 }) )); case -11: // X elevation return(new StructuralAxis( new StructuralVectorThree(new double[] { 0, -1, 0 }), new StructuralVectorThree(new double[] { 0, 0, 1 }), new StructuralVectorThree(new double[] { -1, 0, 0 }) )); case -12: // Y elevation return(new StructuralAxis( new StructuralVectorThree(new double[] { 1, 0, 0 }), new StructuralVectorThree(new double[] { 0, 0, 1 }), new StructuralVectorThree(new double[] { 0, -1, 0 }) )); case -14: // Vertical return(new StructuralAxis( new StructuralVectorThree(new double[] { 0, 0, 1 }), new StructuralVectorThree(new double[] { 1, 0, 0 }), new StructuralVectorThree(new double[] { 0, 1, 0 }) )); case -13: // Global cylindrical x = new Vector3D(evalAtCoor[0], evalAtCoor[1], 0); x.Normalize(); z = new Vector3D(0, 0, 1); y = Vector3D.CrossProduct(z, x); return(new StructuralAxis( new StructuralVectorThree(new double[] { x.X, x.Y, x.Z }), new StructuralVectorThree(new double[] { y.X, y.Y, y.Z }), new StructuralVectorThree(new double[] { z.X, z.Y, z.Z }) )); default: //string res = Initialiser.Interface.GetGWARecords("GET\tAXIS\t" + axis.ToString()).FirstOrDefault(); var res = Initialiser.Cache.GetGwa("AXIS.1", axis).First(); gwaRecord = res; var pieces = res.Split(new char[] { '\t' }); if (pieces.Length < 13) { return(new StructuralAxis( new StructuralVectorThree(new double[] { 1, 0, 0 }), new StructuralVectorThree(new double[] { 0, 1, 0 }), new StructuralVectorThree(new double[] { 0, 0, 1 }) )); } var origin = new Vector3D(Convert.ToDouble(pieces[4]), Convert.ToDouble(pieces[5]), Convert.ToDouble(pieces[6])); var X = new Vector3D(Convert.ToDouble(pieces[7]), Convert.ToDouble(pieces[8]), Convert.ToDouble(pieces[9])); X.Normalize(); var Yp = new Vector3D(Convert.ToDouble(pieces[10]), Convert.ToDouble(pieces[11]), Convert.ToDouble(pieces[12])); var Z = Vector3D.CrossProduct(X, Yp); Z.Normalize(); var Y = Vector3D.CrossProduct(Z, X); var pos = new Vector3D(0, 0, 0); if (evalAtCoor == null) { pieces[3] = "CART"; } else { pos = new Vector3D(evalAtCoor[0] - origin.X, evalAtCoor[1] - origin.Y, evalAtCoor[2] - origin.Z); if (pos.Length == 0) { pieces[3] = "CART"; } } switch (pieces[3]) { case "CART": return(new StructuralAxis( new StructuralVectorThree(new double[] { X.X, X.Y, X.Z }), new StructuralVectorThree(new double[] { Y.X, Y.Y, Y.Z }), new StructuralVectorThree(new double[] { Z.X, Z.Y, Z.Z }) )); case "CYL": x = new Vector3D(pos.X, pos.Y, 0); x.Normalize(); z = Z; y = Vector3D.CrossProduct(Z, x); y.Normalize(); return(new StructuralAxis( new StructuralVectorThree(new double[] { x.X, x.Y, x.Z }), new StructuralVectorThree(new double[] { y.X, y.Y, y.Z }), new StructuralVectorThree(new double[] { z.X, z.Y, z.Z }) )); case "SPH": x = pos; x.Normalize(); z = Vector3D.CrossProduct(Z, x); z.Normalize(); y = Vector3D.CrossProduct(z, x); z.Normalize(); return(new StructuralAxis( new StructuralVectorThree(new double[] { x.X, x.Y, x.Z }), new StructuralVectorThree(new double[] { y.X, y.Y, y.Z }), new StructuralVectorThree(new double[] { z.X, z.Y, z.Z }) )); default: return(new StructuralAxis( new StructuralVectorThree(new double[] { 1, 0, 0 }), new StructuralVectorThree(new double[] { 0, 1, 0 }), new StructuralVectorThree(new double[] { 0, 0, 1 }) )); } } }
public static bool SetSidSpeckleRecords(string emailAddress, string serverAddress, IGSAProxy proxy, List <SidSpeckleRecord> receiverStreamInfo, List <SidSpeckleRecord> senderStreamInfo) { string key = emailAddress + "&" + serverAddress.Replace(':', '&'); string res = proxy.GetTopLevelSid(); List <string[]> sids = Regex.Matches(res, @"(?<={).*?(?=})").Cast <Match>() .Select(m => m.Value.Split(new char[] { ':' })) .Where(s => s.Length == 2) .ToList(); sids.RemoveAll(S => S[0] == "SpeckleSender&" + key || S[0] == "SpeckleReceiver&" + key || string.IsNullOrEmpty(S[1])); List <string> senderList = new List <string>(); if (senderStreamInfo != null) { foreach (var si in senderStreamInfo) { senderList.AddRange(new[] { si.Bucket, si.StreamId, si.ClientId }); } if (senderList.Count() > 0) { sids.Add(new string[] { "SpeckleSender&" + key, string.Join("&", senderList) }); } } List <string> receiverList = new List <string>(); if (receiverStreamInfo != null) { foreach (var si in receiverStreamInfo) { receiverList.AddRange(new[] { si.StreamId, si.Bucket }); } if (receiverList.Count() > 0) { sids.Add(new string[] { "SpeckleReceiver&" + key, string.Join("&", receiverList) }); } } string sidRecord = ""; foreach (string[] s in sids) { sidRecord += "{" + s[0] + ":" + s[1] + "}"; } return(proxy.SetTopLevelSid(sidRecord)); }
public static bool GetSidSpeckleRecords(string emailAddress, string serverAddress, IGSAProxy proxy, out List <SidSpeckleRecord> receiverStreamInfo, out List <SidSpeckleRecord> senderStreamInfo) { receiverStreamInfo = new List <SidSpeckleRecord>(); senderStreamInfo = new List <SidSpeckleRecord>(); try { string key = emailAddress + "&" + serverAddress.Replace(':', '&'); string res = proxy.GetTopLevelSid(); if (res == "") { return(true); } List <string[]> sids = Regex.Matches(res, @"(?<={).*?(?=})").Cast <Match>() .Select(m => m.Value.Split(new char[] { ':' })) .Where(s => s.Length == 2) .ToList(); string[] senderList = sids.Where(s => s[0].TrimEnd('/').Equals(("SpeckleSender&" + key).TrimEnd('/'))).FirstOrDefault(); string[] receiverList = sids.Where(s => s[0].TrimEnd('/').Equals(("SpeckleReceiver&" + key).TrimEnd('/'))).FirstOrDefault(); if (senderList != null && !string.IsNullOrEmpty(senderList[1])) { string[] senders = senderList[1].Split(new char[] { '&' }); for (int i = 0; i < senders.Length; i += 3) { senderStreamInfo.Add(new SidSpeckleRecord(senders[i + 1], senders[i], senders[i + 2])); } } if (receiverList != null && !string.IsNullOrEmpty(receiverList[1])) { string[] receivers = receiverList[1].Split(new char[] { '&' }); for (int i = 0; i < receivers.Length; i += 2) { receiverStreamInfo.Add(new SidSpeckleRecord(receivers[i], receivers[i + 1])); } } return(true); } catch { // If fail to read, clear client SIDs //SenderInfo.Clear(); //ReceiverInfo.Clear(); return(SetSidSpeckleRecords(emailAddress, serverAddress, proxy, null, null)); } }
public string SetGWACommand(IGSAProxy GSA, int group = 0) { if (this.Value == null) { return(""); } var spring = this.Value as Structural0DSpring; if (spring.Value == null || spring.Value.Count() == 0) { return(""); } var keyword = typeof(GSA0DSpring).GetGSAKeyword(); var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, spring.ApplicationId); var propKeyword = typeof(GSASpringProperty).GetGSAKeyword(); var indexResult = Initialiser.AppResources.Cache.LookupIndex(propKeyword, spring.PropertyRef); //If the reference can't be found, then reserve a new index so that it at least doesn't point to any other existing record var propRef = indexResult ?? Initialiser.AppResources.Cache.ResolveIndex(propKeyword, spring.PropertyRef); if (indexResult == null && spring.ApplicationId != null) { if (spring.PropertyRef == null) { Helper.SafeDisplay("Blank property references found for these Application IDs:", spring.ApplicationId); } else { Helper.SafeDisplay("Spring property references not found:", spring.ApplicationId + " referencing " + spring.PropertyRef); } } var sid = Helper.GenerateSID(spring); var ls = new List <string> { "SET", keyword + (string.IsNullOrEmpty(sid) ? "" : ":" + sid), index.ToString(), spring.Name == null || spring.Name == "" ? " " : spring.Name, "NO_RGB", "GRD_SPRING", //type propRef.ToString(), //Property group.ToString(), //Group //"1", //Group }; //Topology for (var i = 0; i < spring.Value.Count(); i += 3) { ls.Add(Initialiser.AppResources.Proxy.NodeAt(spring.Value[i], spring.Value[i + 1], spring.Value[i + 2], Initialiser.AppResources.Settings.CoincidentNodeAllowance).ToString()); } ls.Add("0"); // Orientation Node ls.Add("0"); //Angle ls.Add("NO_RLS"); //is_rls ls.Add("0"); ls.Add("0"); ls.Add("0"); ls.Add("0"); ls.Add(""); // parent_member ls.Add((spring.Dummy.HasValue && spring.Dummy.Value) ? "DUMMY" : ""); return(string.Join(Initialiser.AppResources.Proxy.GwaDelimiter.ToString(), ls)); }