Ejemplo n.º 1
0
        public static bool SetMilitarySymbolGraphicLayers(ref MilitarySymbol milSymbol)
        {
            if (!System.IO.Directory.Exists(ImageFilesHome))
            {
                System.Diagnostics.Trace.WriteLine("--> Images Home *DOES NOT EXIST* : " + ImageFilesHome);
                return(false);
            }

            if ((milSymbol == null) || (milSymbol.Id == null) ||
                (milSymbol.GraphicLayers == null) || (!milSymbol.Id.IsValid))
            {
                return(false);
            }

            milSymbol.GraphicLayers.Clear();

            //////////////////////////////////////////////////////////////////////////
            // Assembly the layers

            // Start with the Frame (if framed)
            if (TypeUtilities.HasFrame(milSymbol.Id.SymbolSet, milSymbol.Id.EntityCode))
            {
                string frameIconNameWithFullPath =
                    GetFrameIconNameWithFullPath(
                        milSymbol.Id.StandardIdentity,
                        milSymbol.Id.Affiliation,
                        milSymbol.Id.SymbolSet,
                        milSymbol.Id.Status);

                if (!string.IsNullOrEmpty(frameIconNameWithFullPath))
                {
                    milSymbol.GraphicLayers.Add(frameIconNameWithFullPath);
                }
            }
            //////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////
            // Main Icon Layer (all symbols should have this)
            string mainIconNameFullPath = GetMainIconNameWithFullPath(ref milSymbol);

            milSymbol.GraphicLayers.Add(mainIconNameFullPath);
            //////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////
            // Skip the remaining if no more layers needed
            bool skipRemainingLayers = !TypeUtilities.HasFrame(milSymbol.Id.SymbolSet);

            if (!skipRemainingLayers)
            {
                StringBuilder sb = new StringBuilder();

                // Main Icon Modfier 1
                if (!string.IsNullOrEmpty(milSymbol.Id.ModifierOne) &&
                    (milSymbol.Id.ModifierOne != "00"))    // TODO: find better way of checking that this isn't set/valid
                {
                    sb.Clear();
                    sb.Append(ImageFilesHome);

                    string modifierIconNameWithFolder =
                        GetModfierIconNameWithFolder(ref milSymbol, 1);

                    sb.Append(modifierIconNameWithFolder);
                    milSymbol.GraphicLayers.Add(sb.ToString());
                }

                // Main Icon Modfier 2
                if (!string.IsNullOrEmpty(milSymbol.Id.ModifierTwo) &&
                    (milSymbol.Id.ModifierTwo != "00"))    // TODO: find better way of checking that this isn't set/valid
                {
                    sb.Clear();
                    sb.Append(ImageFilesHome);

                    string modifierIconNameWithFolder =
                        GetModfierIconNameWithFolder(ref milSymbol, 2);

                    sb.Append(modifierIconNameWithFolder);
                    milSymbol.GraphicLayers.Add(sb.ToString());
                }

                // Echelon/Mobility Modifier
                if (milSymbol.Id.EchelonMobility != EchelonMobilityType.NoEchelonMobility)
                {
                    string echelonIconNameWithFullPath =
                        GetEchelonIconNameWithFullPath(
                            milSymbol.Id.SymbolSet,
                            milSymbol.Id.Affiliation,
                            milSymbol.Id.EchelonMobility);

                    if (echelonIconNameWithFullPath.Length > 0)
                    {
                        milSymbol.GraphicLayers.Add(echelonIconNameWithFullPath);
                    }
                }

                // Headquarters/TF/FD Modifier
                if (milSymbol.Id.HeadquartersTaskForceDummy !=
                    HeadquartersTaskForceDummyType.NoHQTFDummyModifier)
                {
                    string hqTfFdIconNameWithFullPath =
                        GetHqTfFdIconNameWithFullPath(
                            milSymbol.Id.SymbolSet,
                            milSymbol.Id.Affiliation,
                            milSymbol.Id.HeadquartersTaskForceDummy);

                    if (hqTfFdIconNameWithFullPath.Length > 0)
                    {
                        milSymbol.GraphicLayers.Add(hqTfFdIconNameWithFullPath);
                    }
                }

                // Status/Operational Condition Icon
                // (Note: if "planned" was set in the frame used above)
                if ((milSymbol.Id.Status != StatusType.NotSet) &&
                    (milSymbol.Id.Status > StatusType.Planned_Anticipated_Suspect))
                {
                    string opConditionIconNameWithFullPath =
                        GetOperationalConditionNameWithFullPath(
                            milSymbol.Id.SymbolSet,
                            milSymbol.Id.Affiliation,
                            milSymbol.Id.Status);

                    if (opConditionIconNameWithFullPath.Length > 0)
                    {
                        milSymbol.GraphicLayers.Add(opConditionIconNameWithFullPath);
                    }
                }

                if (milSymbol.Id.IsLandUnitSpecialEntity)
                {
                    // TABLE D-V. "Land unit icons – special entity subtypes"
                    string landUnitSpecialEntityIconNameWithFullPath =
                        GetLandUnitSpecialEntityIconNameWithFullPath(milSymbol.Id);

                    if (landUnitSpecialEntityIconNameWithFullPath.Length > 0)
                    {
                        milSymbol.GraphicLayers.Add(landUnitSpecialEntityIconNameWithFullPath);
                    }
                }
            } // end skipRemainingLayers

            // check this before we add debug/unknown icons at the end
            int validLayerCount = 0;

            // Look at the layers to see if any do not exist:
            foreach (string graphicLayer in milSymbol.GraphicLayers)
            {
                if (!System.IO.File.Exists(graphicLayer))
                {
                    System.Diagnostics.Trace.WriteLine("SetMilitarySymbolGraphicLayers: Could not find layer: " + graphicLayer);
                }
                else
                {
                    validLayerCount++;
                }
            }

            bool success = validLayerCount > 0;

            if (AddReferenceCenterPoint)
            {
                // For testing if icons are centered properly:
                // Outer Circle:
                string centerIcon = ImageFilesHome +
                                    @"Appendices\ControlMeasures\25200500.svg"; // (Large Yellow Circle)
                milSymbol.GraphicLayers.Add(centerIcon);

                // Center Dot/Crosshair:
                string centerIcon2 = ImageFilesHome +
                                                                        // @"Appendices\Land\10130300.svg"; // (Center Black Circle)
                                     @"Appendices\Land\10161300_2.svg"; // (Center Black Crosshairs)
                milSymbol.GraphicLayers.Add(centerIcon2);
            }

            if (!success)
            {
                // add a default symbol
                string defaultUnknownIcon = ImageFilesHome + @"Appendices\98100000.svg";
                milSymbol.GraphicLayers.Add(defaultUnknownIcon);
            }

            return(success);
        }
Ejemplo n.º 2
0
        public static bool ConvertCodeCharlieToDelta(string code2525Charlie,
                                                     out SymbolIdCode code2525Delta)
        {
            code2525Delta = SymbolIdCode.DefaultSymbolIdCode;

            if (code2525Charlie.Length < 10)
            {
                return(false);
            }

            string code2525CharlieUpper = code2525Charlie.ToUpper();

            SymbolLookup codeLookup = GetSymbolLookup();

            string symbolSetString, entityString, mod1String, mod2String;

            bool success = codeLookup.GetDeltaCodeFromCharlie(code2525CharlieUpper, out symbolSetString,
                                                              out entityString, out mod1String, out mod2String);

            if (!success || string.IsNullOrEmpty(symbolSetString) || string.IsNullOrEmpty(entityString) ||
                entityString.Length != 6)
            {
                return(false);
            }

            // TRICKY/WORKAROUND: to ones with "TABLE D-V. Land unit icons–special entity subtypes"
            if (entityString.EndsWith("95") || entityString.EndsWith("96") ||
                entityString.EndsWith("97") || entityString.EndsWith("98"))
            {
                entityString = entityString.Substring(0, 4) + "00";

                // TODO: test/implement this in MilitarySymbol + drawing to see if we can get it to show up
            }

            code2525Delta.SymbolSet = (SymbolSetType)
                                      TypeUtilities.EnumHelper.getEnumFromHashCodeString(typeof(SymbolSetType), symbolSetString);
            code2525Delta.EntityCode = entityString;
            if (!string.IsNullOrEmpty(mod1String))
            {
                code2525Delta.ModifierOne = mod1String;
            }
            if (!string.IsNullOrEmpty(mod2String))
            {
                code2525Delta.ModifierTwo = mod2String;
            }

            char affilChar = code2525CharlieUpper[1];

            foreach (KeyValuePair <StandardIdentityAffiliationType, char> kvp in TypeUtilities.AffiliationToCharlieChar)
            {
                if (kvp.Value == affilChar)
                {
                    code2525Delta.Affiliation = kvp.Key;
                    break;
                }
            }

            char planningChar = code2525CharlieUpper[3];

            if (!TypeUtilities.IsWeather(code2525Delta.SymbolSet))
            {
                foreach (KeyValuePair <StatusType, char> kvp in TypeUtilities.StatusToCharlieChar)
                {
                    if (kvp.Value == planningChar)
                    {
                        code2525Delta.Status = kvp.Key;
                        break;
                    }
                }
            } // ! IsWeather

            if (code2525Charlie.Length < 12) // allow codes to be 10 or 15, but don't go past here if not > 12
            {
                return(true);
            }

            if (TypeUtilities.HasFrame(code2525Delta.SymbolSet))
            {
                char hqFdTfChar = code2525CharlieUpper[10];
                foreach (KeyValuePair <HeadquartersTaskForceDummyType, char> kvp in TypeUtilities.HqTfFdToCharlieChar)
                {
                    if (kvp.Value == hqFdTfChar)
                    {
                        code2525Delta.HeadquartersTaskForceDummy = kvp.Key;
                        break;
                    }
                }

                char echelonChar = code2525CharlieUpper[11];
                foreach (KeyValuePair <EchelonMobilityType, char> kvp in TypeUtilities.EchelonMobilityToCharlieChar)
                {
                    if (kvp.Value == echelonChar)
                    {
                        code2525Delta.EchelonMobility = kvp.Key;
                        break;
                    }
                }
            } // HasFrame

            return(true);
        }