/// <summary> /// Event handler for when the label string has changed. /// </summary> /// <param name="dp"> /// The symbol whose label string has changed. /// </param> /// <param name="ea"> /// This parameter is ignored. /// </param> private static void OnLabelStringChanged(DependencyObject dp, DependencyPropertyChangedEventArgs ea) { if (dp is MilSymbol ms) { ms.labels = MilLabels.Generate(ms.LabelString, ms.labels); ms.GenerateLabels(null); } }
/// <summary> /// Always generates the entire symbol. /// The symbol code should not change very often. /// </summary> private void GenerateSymbol() { try { // Only draw after we have the symbol code, if drawing via method call if (this.suppressRefresh) { return; } string symbolCode = this.SymbolCode; // Reinitialize this.IsDirty = true; // set a dirty flag to indicate the symbol needs updating this.bounds = Rect.Empty; this.BaseRect = Rect.Empty; this.Children.Clear(); // tried to cheap this one out - but that doesn't work well this.elements.Clear(); // Get the base symbol from "the" resource dictionary var baseSymbol = new MilSymbolBase(symbolCode, this.LineBrush, this.FillBrush); if (baseSymbol.Empty) { return; } this.AddChild("Base", baseSymbol); var styles = MilLabels.GetStyles(this.LabelStyle); // There is only label decoration for weather codes int schemeKey = CodingScheme.GetCode(symbolCode); if (schemeKey == CodingScheme.Weather || schemeKey == CodingScheme.TacticalGraphics) { this.GenerateLabels(styles); return; } // Add in the echelon marking. // "high" is the maximum height from the decoration this.high = Echelon.Generate(this, symbolCode); // Draw headquarters, feint dummy, task force, and installation. // "high" is the maximum height from the decoration this.high = MilHats.Generate(this, symbolCode); // Take care of any Joker, Faker, or Exercise character this.AddChild( "JFE", MilLabels.GenerateJokerFakerExercise(symbolCode, this.labels, styles[MilLabels.BigLabels])); // Add the black ribbon on the base symbol for space this.AddChild("Space", MilSymbolBase.GenerateSpace(symbolCode)); // Indicate whether the entity is damaged or destroyed this.AddChild("OC", StatusOperationalCapacity.Generate(symbolCode)); // Add the mobility to the base of the symbol this.AddChild("Mobility", DrawMobility.GenerateMobility(symbolCode)); // We have to (re)generate the labels because the symbol code extent may be different this.GenerateLabels(styles); } catch (Exception ex) { Log.WriteMessage(LogLevel.Error, "Unable to construct military symbol", ex); } }
/// <summary> /// Selectively (re)generates labels. /// </summary> /// <param name="styles"> /// An optional list of styles to apply to the labels. /// </param> private void GenerateLabels(IList <Style> styles) { try { if (this.suppressRefresh) { return; } string symbolCode = this.SymbolCode; if (symbolCode == null) { return; } if (this.labels == null) { return; } if (styles == null) { styles = MilLabels.GetStyles(this.LabelStyle); } this.IsDirty = true; int schemeKey = CodingScheme.GetCode(symbolCode); if (schemeKey == CodingScheme.Weather) { // All extraneous information for weather is in the labels. MilLabels.GenerateWeather(symbolCode, this.labels, this.AddChild); return; } if (schemeKey == CodingScheme.TacticalGraphics) { MilLabels.GenerateTacticalGraphics( symbolCode, this.labels, styles[MilLabels.TacticalGraphicsLabels], this.AddChild); return; } // Generate labels to the left of the symbol this.AddChild("Left", MilLabels.GenerateLeft(symbolCode, this.labels, styles[MilLabels.LeftLabels])); // Generate labels to the right of the symbol this.AddChild("Right", MilLabels.GenerateRight(symbolCode, this.labels, styles[MilLabels.RightLabels])); // This is just the quantity, if specified this.AddChild("Top", MilLabels.GenerateTop(this.high, symbolCode, this.labels, styles[MilLabels.TopLabels])); // This is just the C2 headquarters label this.AddChild("Middle", MilLabels.GenerateMiddle(symbolCode, this.labels)); // This is the direction of movement (which apparently requires a label value) this.AddChild("Q", MilLabels.GenerateQ(symbolCode, this.labels, 0.0)); } catch (Exception ex) { Log.WriteMessage(LogLevel.Error, "Unable to add labels to symbol", ex); } }