/// <summary> /// Generate the headquarters rendering for the passed in symbol. /// </summary> /// <param name="ms"> /// The military symbol for which to provide the headquarters rendering. /// </param> /// <returns> /// The graphics Shape object that represents the headquarters rendering. /// </returns> private static Shape GenerateHeadquarters(MilSymbol ms) { Rect b = ms.BaseRect; double headquartersFactor = SymbolData.GetHqFactor(ms.SymbolCode); return(new Path { Style = SymbolData.GetStyle("BS10"), Data = new PathGeometry { Figures = new PathFigureCollection { new PathFigure { // The +/- HalfWidth accounts for the Bounds being on the outside of the symbol StartPoint = new Point(b.Left + SymbolData.HalfWidth, b.Top + (headquartersFactor * b.Height)), Segments = new PathSegmentCollection { new LineSegment { Point = new Point(b.Left + SymbolData.HalfWidth, b.Bottom + (0.3 * b.Width)) } } } } } }); }
/// <summary> /// Generate a TextBlock label based on an integer value. /// </summary> /// <param name="x"> /// The x coordinate for the TextBlock. /// </param> /// <param name="y"> /// The y coordinate for the TextBlock. /// </param> /// <param name="integerLabel"> /// The integer label to be displayed. /// </param> /// <param name="style"> /// The style for the label. /// </param> /// <returns> /// The TextBlock containing the integer as a label. /// </returns> internal static TextBlock IntegerLabel( double x, // a reference point for the horizontal location double y, // the top of the label - for now string integerLabel, // the label string style) // the label's style { var label = new TextBlock { Style = SymbolData.GetStyle(style) }; double result; if (!double.TryParse(integerLabel, out result)) { return(null); } if (result < 0.0 || result > 99999.0) { return(null); // negative or too many digits } integerLabel = Math.Round(result).ToString(Culture); label.Text = integerLabel; label.FindTextExtent(); var multiplier = (label.TextAlignment == TextAlignment.Center) ? 0.5 : (label.TextAlignment == TextAlignment.Right) ? 1.0 : 0.0; SetTopLeft(label, x - (multiplier * label.Width), y); return(label); }
/// <summary> /// Initializes static members of the <see cref="MilLabels"/> class. /// </summary> static MilLabels() { var styles = new Style[LabelCount]; styles[TopLabels] = SymbolData.GetStyle("TopLabels"); styles[BigLabels] = SymbolData.GetStyle("BigLabels"); styles[LeftLabels] = SymbolData.GetStyle("LeftLabels"); styles[RightLabels] = SymbolData.GetStyle("RightLabels"); styles[TacticalGraphicsLabels] = SymbolData.GetStyle("TacticalGraphicsLabels"); LabelStyles.Add(DefaultStyle, styles); }
/// <summary> /// Generate the feint dummy rendering for the passed in symbol. /// </summary> /// <param name="ms"> /// The military symbol for which to provide the feint dummy rendering. /// </param> /// <param name="height"> /// The height at which to provide the feint dummy rendering. /// </param> /// <returns> /// The graphics Path object that represents the feint dummy rendering. /// </returns> private static Path GenerateFeintDummy(MilSymbol ms, ref double height) { if (!string.IsNullOrEmpty(Echelon.GetEchelonSymbol(ms.SymbolCode))) { height = ms.Bounds.Top; } if (SymbolData.IsTopFlat(ms.SymbolCode)) { double minimum = ms.BaseRect.Top; if (height >= minimum) { height = minimum - 28; } } double bottom = height + 23; height = height - 27; const double Wide = 126; var st = new Style(typeof(Shape)) { BasedOn = SymbolData.GetStyle("BS10") }; st.SetDashArray(3, 1); return(new Path { Style = st, Data = new PathGeometry { Figures = new PathFigureCollection { new PathFigure { StartPoint = new Point(-Wide, bottom), Segments = new PathSegmentCollection { new LineSegment { Point = new Point(0.0, height) }, new LineSegment { Point = new Point(Wide, bottom) } } } } } }); }
/// <summary> /// Return the cache of styles for the particular symbol. /// </summary> /// <param name="style"> /// The style for which to retrieve the array of styles. /// </param> /// <returns> /// An array of styles, such as left labels, right labels, etc. that match the passed in style. /// </returns> internal static Style[] GetStyles(Style style) { if (style == null) { return(LabelStyles[DefaultStyle]); } if (LabelStyles.ContainsKey(style)) { return(LabelStyles[style]); } var styles = new Style[LabelCount]; styles[TopLabels] = new Style(typeof(TextBlock)) { BasedOn = SymbolData.GetStyle("TopLabels") }; styles[BigLabels] = new Style(typeof(TextBlock)) { BasedOn = SymbolData.GetStyle("BigLabels") }; styles[LeftLabels] = new Style(typeof(TextBlock)) { BasedOn = SymbolData.GetStyle("LeftLabels") }; styles[RightLabels] = new Style(typeof(TextBlock)) { BasedOn = SymbolData.GetStyle("RightLabels") }; styles[TacticalGraphicsLabels] = new Style(typeof(TextBlock)) { BasedOn = SymbolData.GetStyle("TacticalGraphicsLabels") }; var tb = new TextBlock { Style = style }; SetSingleProperty(TextBlock.ForegroundProperty, tb.Foreground, ref styles); SetSingleProperty(TextBlock.FontSizeProperty, tb.FontSize, ref styles); SetSingleProperty(TextBlock.FontFamilyProperty, tb.FontFamily, ref styles); SetSingleProperty(TextBlock.FontWeightProperty, tb.FontWeight, ref styles); LabelStyles.Add(style, styles); return(styles); }
/// <summary> /// Returns the arrow representing a direction of travel for a mil symbol /// </summary> /// <param name="symbolCode">Code for the mil symbol</param> /// <param name="labels">The labels for the symbol, we're looking for "Q"</param> /// <param name="extraOffset">An extra offset for tactical graphics</param> /// <returns>The arrow shape representing the direction of travel</returns> internal static Shape GenerateQ( string symbolCode, IDictionary <string, string> labels, double extraOffset) { if (!SymbolData.Check(ref symbolCode)) { return(null); } string q; if (!labels.TryGetValue("Q", out q)) { return(null); } double angle; if (!double.TryParse(q, out angle)) { return(null); } double off = 0.0; if (CategoryBattleDimension.GetCode(symbolCode) == CategoryBattleDimension.BdGround) { off = SymbolData.GetBounds(symbolCode).Bottom; } off += extraOffset; return(new Path { Style = SymbolData.GetStyle("BS10"), Data = new PathGeometry { Figures = new PathFigureCollection { GenerateArrowPoints(off, angle) } } }); }
/// <summary> /// Generate the middle label for the symbol. /// </summary> /// <param name="symbolCode"> /// The symbol code for which to generate the labels. /// </param> /// <param name="labels"> /// The dictionary of labels to generate. /// </param> /// <returns> /// A TextBlock that represents the rendered labels. /// </returns> internal static TextBlock GenerateMiddle(string symbolCode, IDictionary <string, string> labels) { if (!SymbolData.Check(ref symbolCode)) { return(null); } if (labels == null) { return(null); } var middle = new TextBlock { Style = SymbolData.GetStyle("MiddleLabels") }; bool gotLine = false; ProcessLabels(labels, true, new[] { "AA" }, middle, ref gotLine); middle.FindTextExtent(); SetTopLeft(middle, -middle.Width / 2, -middle.Height / 2); return(middle); }
/// <summary> /// Generate the task force rendering for the passed in symbol. /// </summary> /// <param name="ms"> /// The military symbol for which to provide the task force rendering. /// </param> /// <param name="height"> /// The height at which to provide the task force rendering. /// </param> /// <returns> /// The graphics Path object that represents the task force rendering. /// </returns> private static Path GenerateTaskForce(MilSymbol ms, out double height) { height = -185; double bottom = 0; const double Wide = 54; int si = StandardIdentity.GetNormalizedStandardIdentity(ms.SymbolCode); if (SymbolData.IsTopFlat(ms.SymbolCode)) { bottom = ms.BaseRect.Top; if (si == StandardIdentity.Unknown) { bottom += SymbolData.HalfWidth; } height = bottom - 75; } else { int bd = CategoryBattleDimension.GetCode(ms.SymbolCode); bool ap = bd == CategoryBattleDimension.BdSpace || bd == CategoryBattleDimension.BdAir; // The cases cover those surfaces which are flat on top versus those that are not switch (si) { case StandardIdentity.Unknown: if (ap) { height = -230; // space bottom = -133; } else { height = -250; // ground bottom = -154; } break; case StandardIdentity.Hostile: if (ap) { height = -230; // space bottom = -107; } else { height = -253; // ground bottom = -119; } break; case StandardIdentity.Friend: height = -222; if (ap) { bottom = -121; // space } else { bottom = -137; // ground circles } break; } } return(new Path { Style = SymbolData.GetStyle("BS10"), Data = new PathGeometry { Figures = new PathFigureCollection { new PathFigure { StartPoint = new Point(Wide, bottom), Segments = new PathSegmentCollection { new LineSegment { Point = new Point(Wide, height) }, new LineSegment { Point = new Point(-Wide, height) }, new LineSegment { Point = new Point(-Wide, bottom) } } } } } }); }