/// <summary> /// Adds a label to a UIElement at a given offset based on the text width and height. /// </summary> /// <param name="labels"> /// The dictionary of labels containing the label to render. /// </param> /// <param name="match"> /// The key to the label to render. /// </param> /// <param name="locationX"> /// The x coordinate of where to place the label. /// </param> /// <param name="locationY"> /// The y coordinate of where to place the label. /// </param> /// <param name="multiplierX"> /// The x multiplier to apply to the label's width to further offset the label. /// </param> /// <param name="multiplierY"> /// The y multiplier to apply to the label's height to further offset the label. /// </param> /// <param name="style"> /// The style with which to render the label. /// </param> /// <param name="addChild"> /// The delegate that will actually render the label into the UIElement. /// </param> /// <returns> /// The TextBlock containing the rendered label. /// </returns> internal static TextBlock GenerateSingleLabel( IDictionary <string, string> labels, string match, double locationX, double locationY, double multiplierX, double multiplierY, Style style, AddChild addChild) { if (labels == null) { return(null); } if (!labels.ContainsKey(match)) { return(null); } var tb = new TextBlock { Style = style, /*TacticalGraphicsLabels*/ Text = labels[match] }; tb.FindTextExtent(); SetTopLeft(tb, locationX - (multiplierX * tb.Width), locationY - (multiplierY * tb.Height)); addChild(match, tb); return(tb); }
/// <summary> /// Generate the labels for a tactical graphic point symbol. /// </summary> /// <param name="labels"> /// The dictionary containing the labels to be generated for the point symbol. /// </param> /// <param name="addChild"> /// The delegate to actually add the labels. /// </param> /// <param name="matches"> /// The list of keys for the labels to be generated. /// </param> /// <param name="style"> /// The style for generating the labels. /// </param> private static void TacticalGraphicsPointLabels( IDictionary <string, string> labels, AddChild addChild, IEnumerable <string> matches, Style style) { foreach (var match in matches) { TextBlock tb; switch (match) { case "H1": GenerateSingleLabel(labels, "H1", 0, -265, 0.5, 0.0, style, addChild); break; case "H": GenerateSingleLabel(labels, "H", 0, -285, 0.5, 1.0, style, addChild); break; case "T": GenerateSingleLabel(labels, "T", 80, -275, 0.0, 0.0, style, addChild); break; case "N": GenerateSingleLabel(labels, "N", 80, -95, 0.0, 1.0, style, addChild); break; case "W-": // Need '-' on end of label here if (labels.ContainsKey("W")) { DashLabels["W"] = labels["W"] + "-"; tb = GenerateSingleLabel(DashLabels, "W", -80, -275, 1.0, 0.0, style, addChild); if (tb != null) { tb.FindTextExtent(); GenerateSingleLabel(labels, "W1", -80, -275 + tb.Height, 1.0, 0.0, style, addChild); } } break; case "W": tb = GenerateSingleLabel(labels, "W", -80, -275, 1.0, 0.0, style, addChild); if (tb != null) { tb.FindTextExtent(); GenerateSingleLabel(labels, "W1", -80, -275 + tb.Height, 1.0, 0.0, style, addChild); } break; } } }
public CartesianPlane() { InitializeComponent(); m_FunctionExecutes = new List <FunctionExecute>(); ac = new AddChild(this.AddChild); m_AddChildLockObject = new object(); m_Threads = new Dictionary <IFunction, SuspendableThread>(); dl = new DrawLine(this.DrawLine); this.m_CooardinateAxisElements = new List <UIElement>(); m_FunctionLines = new Dictionary <Line, IFunction>(); }
public static IList <TNODE> FromParentChildRelationship <TROW, TKEY, TNODE>( IEnumerable <TROW> rows, GetNodeKey <TROW, TKEY> getchildkey, GetNodeKey <TROW, TKEY> getparentkey, CreateNewNode <TROW, TNODE> createnewnode, AddChild <TNODE> addchild) where TKEY : System.IComparable <TKEY> { var pairs = from row in rows let childkey = getchildkey(row) select new { childkey, row }; // first create the nodes for each distinct key var node_dic = new Dictionary <TKEY, TNODE>(); // assign create child nodes foreach (var pair in pairs) { if (node_dic.ContainsKey(pair.childkey)) { // no need to create child key } else { // need to add the child key var new_node = createnewnode(pair.row); node_dic[pair.childkey] = new_node; } } var items = from row in rows let parentkey = getparentkey(row) let childkey = getchildkey(row) let childnode = node_dic[childkey] select new { parentkey, childkey, childnode }; foreach (var item in items) { if (item.parentkey.CompareTo(item.childkey) == 0) { throw new System.ArgumentException("Parent and Child Keys cannot be the same"); } if (node_dic.ContainsKey(item.parentkey)) { var parentnode = node_dic[item.parentkey]; addchild(parentnode, item.childnode); } } var nodes = node_dic.Values.ToList(); return(nodes); }
public Schema() : base() { InstanceType = typeof(__NestedPa__); ClassName = "NestedPartial"; Properties.ClearExposed(); Html = Add <__TString__>("Html"); Html.DefaultValue = "/KitchenSink/NestedPartial.html"; Html.SetCustomAccessors((_p_) => { return(((__NestedPa__)_p_).__bf__Html__); }, (_p_, _v_) => { ((__NestedPa__)_p_).__bf__Html__ = (System.String)_v_; }, false); Name = Add <__TString__>("Name"); Name.DefaultValue = ""; Name.SetCustomAccessors((_p_) => { return(((__NestedPa__)_p_).__bf__Name__); }, (_p_, _v_) => { ((__NestedPa__)_p_).__bf__Name__ = (System.String)_v_; }, false); ChildPartial = Add <__TObject__>("ChildPartial"); ChildPartial.SetCustomAccessors((_p_) => { return(((__NestedPa__)_p_).__bf__ChildPartial__); }, (_p_, _v_) => { ((__NestedPa__)_p_).__bf__ChildPartial__ = (__Json__)_v_; }, false); AddChild = Add <__TLong__>("AddChild$"); AddChild.DefaultValue = 0L; AddChild.Editable = true; AddChild.SetCustomAccessors((_p_) => { return(((__NestedPa__)_p_).__bf__AddChild__); }, (_p_, _v_) => { ((__NestedPa__)_p_).__bf__AddChild__ = (System.Int64)_v_; }, false); AddChild.AddHandler((Json pup, Property <Int64> prop, Int64 value) => { return(new Input.AddChild() { App = (NestedPartial)pup, Template = (TLong)prop, Value = value }); }, (Json pup, Starcounter.Input <Int64> input) => { ((NestedPartial)pup).Handle((Input.AddChild)input); }); }
public static void FillChildren(StackPanel children, List <int> ids, int id) { children.Children.Clear(); ids.Clear(); var r = Database.SelectChildren(id, null).Select(x => x.Child); foreach (var item in r) { ChildButton childButton = new ChildButton(item.Nome); childButton.TextBlock.HorizontalAlignment = HorizontalAlignment.Left; var cm = new ContextMenu(); MenuItem editar = new MenuItem() { Header = "Renomear" }; cm.Items.Add(editar); editar.Click += new RoutedEventHandler((s, e) => { var a = new AddChild(item.ID, true); a.ShowDialog(); FillChildren(children, ids, id); }); var deletar = new MenuItem() { Header = "Deletar" }; cm.Items.Add(deletar); deletar.Click += new RoutedEventHandler((s, e) => { AskDeleteCascade(item.ID); FillChildren(children, ids, id); }); childButton.Grid.ContextMenu = cm; childButton.Grid.MouseLeftButtonDown += new MouseButtonEventHandler((s, e) => { ChangePage(new ViewNode(item.ID, false)); }); children.Children.Add(childButton.Grid); } }
/// <summary> /// Generate the labels for single point technical graphics. /// </summary> /// <param name="symbolCode"> /// The symbol code for the technical graphic. /// </param> /// <param name="labels"> /// The dictionary of labels for the technical graphic. /// </param> /// <param name="style"> /// The style for the labels. /// </param> /// <param name="addChild"> /// The delegate that actually adds the label to the UIElement. /// </param> internal static void GenerateTacticalGraphics( string symbolCode, IDictionary <string, string> labels, Style style, AddChild addChild) { if (!SymbolData.Check(ref symbolCode)) { return; } if (labels == null) { return; } string stencil = MilSymbolBase.CodeToStencil(symbolCode); double extraOffset; TextBlock tb; // These are special case codes that require labels switch (stencil) { case "G_MPNDP": case "G_MPNDA": case "G_MPNDT": case "G_MPNDE": case "G_MPNDB": case "G_MPNDO": case "G_MPNDD": case "G_FPPCS": case "G_FPPCB": case "G_FPPCR": case "G_FPPCH": case "G_FPPCL": TacticalGraphicsPointLabels(labels, addChild, new[] { "H", "N", "T", "W" }, style); break; case "G_GPGPP": TacticalGraphicsPointLabels(labels, addChild, new[] { "H", "H1", "N", "T", "W-" }, style); break; case "G_GPGPPK": case "G_GPGPPL": case "G_GPGPPP": case "G_GPGPPR": case "G_GPGPPE": case "G_GPGPPS": case "G_GPGPPA": case "G_GPOPP": case "G_MPBCP": case "G_SPPX": case "G_SPPC": case "G_SPPY": case "G_SPPT": case "G_SPPD": case "G_SPPE": case "G_SPPL": case "G_SPPM": case "G_SPPR": case "G_SPPU": case "G_SPPO": case "G_SPPI": case "G_SPPN": case "G_SPPSZ": case "G_SPPSA": case "G_SPPSB": case "G_SPPSC": case "G_SPPSD": case "G_SPPSE": case "G_SPPSF": case "G_SPPSG": case "G_SPPSH": case "G_SPPSI": case "G_SPPSJ": case "G_SPPAS": case "G_SPPAT": TacticalGraphicsPointLabels(labels, addChild, new[] { "H", "N", "T", "W-" }, style); break; case "G_GPGPRI": GenerateSingleLabel(labels, "T", 0, -246, 0.5, 0.5, style, addChild); break; case "G_GPGPH": GenerateSingleLabel(labels, "H", 0, 0, 0.5, 0.5, style, addChild); break; case "G_GPGPPC": GenerateSingleLabel(labels, "T", 0, -175, 0.5, 0.5, style, addChild); break; case "G_GPGPPD": GenerateSingleLabel(labels, "T", 0, 0, 0.5, 0.25, style, addChild); break; case "G_GPGPPW": GenerateSingleLabel(labels, "T", 50, 0, 0.0, 0.5, style, addChild); break; case "G_GPAPP": case "G_GPAPC": GenerateSingleLabel(labels, "T", 0, 0, 0.5, 0.25, style, addChild); break; case "G_GPDPT": GenerateSingleLabel(labels, "T", 87, -87, 0.5, 0.5, style, addChild); break; case "G_MPOHTL": GenerateSingleLabel(labels, "X", 50, -250, 0.0, 0.0, style, addChild); break; case "G_MPOHTH": GenerateSingleLabel(labels, "X", 50, -230, 0.0, 0.0, style, addChild); break; case "G_MPNZ": GenerateSingleLabel(labels, "W", -110, -300, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "V", -110, -200, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "T", -110, -100, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "H", 110, -300, 0.0, 0.0, style, addChild); GenerateSingleLabel(labels, "N", 110, -100, 0.0, 0.0, style, addChild); GenerateSingleLabel(labels, "C", 0, -300, 0.5, 1.0, style, addChild); tb = GenerateSingleLabel(labels, "Y", 0, 0, 0.5, 0.0, style, addChild); tb.FindTextExtent(); extraOffset = tb != null ? tb.Height : 0.1; addChild("Q", GenerateQ(symbolCode, labels, extraOffset)); break; case "G_MPNEB": GenerateSingleLabel(labels, "W", -110, -300, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "T", -110, -100, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "H", 110, -300, 0.0, 0.0, style, addChild); GenerateSingleLabel(labels, "N", 110, -100, 0.0, 0.0, style, addChild); tb = GenerateSingleLabel(labels, "Y", 0, 0, 0.5, 0.0, style, addChild); tb.FindTextExtent(); extraOffset = tb != null ? tb.Height : 0.1; addChild("Q", GenerateQ(symbolCode, labels, extraOffset)); break; case "G_MPNEC": GenerateSingleLabel(labels, "W", -94, -300, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "T", -94, -100, 1.0, 0.0, style, addChild); GenerateSingleLabel(labels, "H", 94, -300, 0.0, 0.0, style, addChild); GenerateSingleLabel(labels, "N", 94, -100, 0.0, 0.0, style, addChild); tb = GenerateSingleLabel(labels, "Y", 0, 0, 0.5, 0.0, style, addChild); tb.FindTextExtent(); extraOffset = tb != null ? tb.Height : 0.1; addChild("Q", GenerateQ(symbolCode, labels, extraOffset)); break; case "G_FPPTS": GenerateSingleLabel(labels, "H", 50, 75, 0.0, 0.5, style, addChild); GenerateSingleLabel(labels, "H1", -50, 75, 1.0, 0.5, style, addChild); GenerateSingleLabel(labels, "T", 50, -75, 0.0, 0.5, style, addChild); break; case "G_FPPTN": GenerateSingleLabel(labels, "T", 50, -75, 0.0, 0.5, style, addChild); break; case "G_FPPCF": GenerateSingleLabel(labels, "T", 50, 0, 0.0, 0.5, style, addChild); break; } }
/// <summary> /// Generate the labels for the single point weather symbology. /// </summary> /// <param name="symbolCode"> /// The weather symbol code. /// </param> /// <param name="labels"> /// The dictionary of labels to be displayed with the weather symbology. /// </param> /// <param name="addChild"> /// The delegate that will actually add the child to the UIElement. /// </param> internal static void GenerateWeather(string symbolCode, IDictionary <string, string> labels, AddChild addChild) { if (!SymbolData.Check(ref symbolCode)) { return; } if (labels == null) { return; } // There are very few weather codes that require labels - so we'll handle them via a case statement string label; switch (symbolCode) { case "WOS-HDS---P----": // X - altitude { double depth = 0.0; var ok = labels.ContainsKey("X") && double.TryParse(labels["X"], out depth); var splits = (ok ? depth.ToString(Culture) : "6.3").Split('.'); var meters = IntegerLabel(0, -100, splits[0], "MeterDepthLabel"); addChild("Meters", meters); // Plot the first fractional digit offset if (splits.Length > 1) { meters.FindTextExtent(); addChild( "Decimeters", IntegerLabel(meters.Width / 2, -25, splits[1].Substring(0, 1), "DecimeterDepthLabel")); } return; } case "WAS-WSF-LVP----": // X - altitude { label = labels.ContainsKey("X") ? labels["X"] : "100"; addChild("Altitude", IntegerLabel(63, -55, label, "FreezeLabel")); return; } case "WAS-WST-LVP----": // X - altitude { label = labels.ContainsKey("X") ? labels["X"] : "380"; addChild("Altitude", IntegerLabel(0, -61, label, "TropoLabel")); return; } case "WAS-PLT---P----": // low pressure { label = labels.ContainsKey("X") ? labels["X"] : "270"; addChild("Altitude", IntegerLabel(0, -136, label, "PressureLabel")); return; } case "WAS-PHT---P----": // high pressure { label = labels.ContainsKey("X") ? labels["X"] : "460"; addChild("Altitude", IntegerLabel(0, 2, label, "PressureLabel")); return; } case "WAS-WC----P----": { int cloudCover; // 0 through 9} if (labels.ContainsKey("AA") && int.TryParse(labels["AA"], out cloudCover)) { addChild("CloudCover", WindBarb.GenerateCloudCover(2, cloudCover)); } return; } case "WAS-WP----P----": // wind barb { int cloudCover; // 0 through 9} if (labels.ContainsKey("AA") && int.TryParse(labels["AA"], out cloudCover)) { addChild("CloudCover", WindBarb.GenerateCloudCover(1, cloudCover)); } double speed; // in knots double?speedIn = null; if (labels.ContainsKey("Z") && double.TryParse(labels["Z"], out speed)) { speedIn = speed; } bool southernHemisphere = labels.ContainsKey("Y") && labels["Y"].ToUpper() == "S"; double direction; // in degrees if (labels.ContainsKey("Q") && double.TryParse(labels["Q"], out direction)) { addChild("Wind", WindBarb.GenerateWind(speedIn, direction, southernHemisphere)); } return; } } }
public static IList <NODET> FromDepths <T, NODET>(IEnumerable <T> items, GetNodeDepth <T> getdepth, CreateNewNode <T, NODET> new_node, AddChild <NODET> addchild) { var root_nodes = new List <NODET>(); var stack_nodes = new Stack <NODET>(); var stack_depth = new Stack <int>(); foreach (var item in items) { var item_depth = getdepth(item); if (item_depth < 0) { throw new System.ArgumentException("getdepth returned negative value"); } var item_node = new_node(item); // Very important that these two stacks have the same number of items if (stack_depth.Count != stack_nodes.Count) { throw new System.InvalidOperationException("Stacks out of sync"); } // Remove all nodes on the stack that are too deep to be a parent while (stack_nodes.Count > 0) { if (stack_depth.Peek() >= item_depth) { stack_nodes.Pop(); stack_depth.Pop(); } else { break; } } // if there's any node in the stack, it means the top of the stack has a node that can serce as a parent if (stack_nodes.Count > 0) { var cur_node = stack_nodes.Peek(); int cur_depth = stack_depth.Peek(); if (item_depth > cur_depth) { addchild(cur_node, item_node); } } // Add the current node as a potential parent of the next item that will be processed stack_nodes.Push(item_node); stack_depth.Push(item_depth); // if there is only a single node in the stack that means that this // node is is a root node if (stack_nodes.Count == 1) { root_nodes.Add(item_node); } } return(root_nodes); }
public static NODET FromPaths <PATHT, NODET>( IEnumerable <PATHT> paths, SplitPath <PATHT> funcsplit, CreateNewNodeFromPath <PATHT, NODET> createnewnode, AddChild <NODET> addchild) { var root_dic = new Dictionary <PATHT, TreePathItem <PATHT, NODET> >(); NODET current_node = default(NODET); bool has_current_node = false; PATHT root_token = default(PATHT); bool found_root = false; var pathbuilder = new List <PATHT>(); foreach (var path in paths) { pathbuilder.Clear(); int depth = 0; var tokens = funcsplit(path); var current_dic = root_dic; foreach (var token in tokens) { pathbuilder.Add(token); if (current_dic.ContainsKey(token)) { var next_dic = current_dic[token]; current_dic = next_dic.dic; current_node = next_dic.node; has_current_node = true; } else { var new_node = createnewnode(pathbuilder.ToArray(), token, depth); if (has_current_node) { addchild(current_node, new_node); } var new_dic = new Dictionary <PATHT, TreePathItem <PATHT, NODET> >(); current_dic[token] = new TreePathItem <PATHT, NODET>(new_node, new_dic); current_dic = new_dic; current_node = new_node; has_current_node = true; if (depth == 0) { if (!found_root) { root_token = token; found_root = true; } else { throw new System.ArgumentException("Input contains multiple roots"); } } } depth++; } } if (root_dic.Count < 1) { return(default(NODET)); } else if (root_dic.Count == 1) { var new_root_node = root_dic.ElementAt(0).Value.node; return(new_root_node); } else { throw new System.InvalidOperationException("Should never get to this state"); } }