Example #1
0
        public static string GetModfierIconName(ref MilitarySymbol milSymbol, int modifierNumber)
        {
            StringBuilder sb = new StringBuilder();

            if (!((modifierNumber == 1) || (modifierNumber == 2)))
            {
                return(string.Empty);
            }

            string sModifierNumber = "1";
            string sModifier       = milSymbol.Id.ModifierOne;

            if (modifierNumber == 2)
            {
                sModifierNumber = "2";
                sModifier       = milSymbol.Id.ModifierTwo;
            }

            string symbolSetString = TypeUtilities.EnumHelper.getEnumValAsString(milSymbol.Id.SymbolSet, 2);

            string modifierIcon = symbolSetString + sModifier + sModifierNumber;

            sb.Append(modifierIcon);

            return(sb.ToString());
        }
Example #2
0
        public bool Equals(MilitarySymbol ms)
        {
            if ((System.Object)ms == null)
            {
                return(false);
            }

            return((Id == ms.Id) && (Shape == ms.Shape));
        }
Example #3
0
        // same as ImageFilesHome + GetMainIconNameWithFolder
        public static string GetMainIconNameWithFullPath(ref MilitarySymbol milSymbol)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(ImageFilesHome);

            string mainIconNameWithoutImageFilesHome = GetMainIconNameWithFolder(ref milSymbol);

            sb.Append(mainIconNameWithoutImageFilesHome);

            string mainIconNameFullPath = sb.ToString();

            // WORKAROUND/TRICKY: some center icon symbols that need to touch fram have _0, _1, _2, _3 suffix instead of base version
            // Method: Find the frame suffix from the affiliation & add _0, _1, _2, _3 accordingly
            // Also test for 2 other exceptional cases while we are at it
            if (!System.IO.File.Exists(mainIconNameFullPath))
            {
                StandardIdentityAffiliationType mappedAffiliation = milSymbol.Id.Affiliation;

                if (milSymbol.Id.StandardIdentity == StandardIdentityRealExerciseSimType.Exercise)
                {
                    // Exceptional case for these 2 (has a friend frame)
                    if ((mappedAffiliation == StandardIdentityAffiliationType.Suspect_Joker) ||
                        (mappedAffiliation == StandardIdentityAffiliationType.Hostile))
                    {
                        mappedAffiliation = StandardIdentityAffiliationType.Friend;
                    }
                }

                string newFrameSuffix =
                    TypeUtilities.AffiliationFrameToSuffixName[mappedAffiliation] + ImageSuffix;

                // more exceptional cases:
                if (milSymbol.Id.SymbolSet == SymbolSetType.Control_Measures)
                {
                    // use ".a" instead - 6 symbols
                    newFrameSuffix = ".a" + ImageSuffix;
                }
                else if (milSymbol.Id.SymbolSet == SymbolSetType.Atmospheric)
                {
                    // use ".0" instead - only 1 symbol 45140200.0
                    newFrameSuffix = ".0" + ImageSuffix;
                }

                string subMainIconName = mainIconNameFullPath;
                subMainIconName = subMainIconName.Replace(ImageSuffix, newFrameSuffix);
                if (System.IO.File.Exists(subMainIconName)) // if the other file/version exists, use that one
                {
                    mainIconNameFullPath = subMainIconName;
                }
            }

            return(mainIconNameFullPath);
        }
Example #4
0
        // MainIconNameWithFolder
        // Appendices\{SymbolSetTypeName}\SymbolSetType + EntityCode
        // e.g. Appendices\Air\01110000.svg ==> { 01 } + { 110000 }
        public static string GetMainIconNameWithFolder(ref MilitarySymbol milSymbol)
        {
            StringBuilder sb = new StringBuilder();

            string currentAppendixHome = GetIconFolderName(milSymbol.Id.SymbolSet);

            sb.Append(currentAppendixHome);

            string mainIconName = GetMainIconName(ref milSymbol);

            sb.Append(mainIconName);
            sb.Append(ImageSuffix);

            return(sb.ToString());
        }
Example #5
0
        public override bool Equals(System.Object obj)
        {
            if ((System.Object)obj == null)
            {
                return(false);
            }

            MilitarySymbol ms = obj as MilitarySymbol;

            if ((System.Object)ms == null)
            {
                return(false);
            }

            return(Equals(ms));
        }
Example #6
0
        public static string GetModfierIconNameWithFolder(ref MilitarySymbol milSymbol, int modifierNumber)
        {
            if (!((modifierNumber == 1) || (modifierNumber == 2)))
            {
                return(string.Empty);
            }

            string sModifierCode = (modifierNumber == 1) ? milSymbol.Id.ModifierOne : milSymbol.Id.ModifierTwo;

            int modifierCodeInt = Convert.ToInt32(sModifierCode);

            string modifierIconNameWithFolder = GetModfierIconNameWithFolder(
                milSymbol.Id.SymbolSet, modifierNumber, modifierCodeInt);

            return(modifierIconNameWithFolder);
        }
Example #7
0
        public static string GetMainIconName(ref MilitarySymbol milSymbol)
        {
            string mainIcon;

            if (milSymbol.Id.IsLandUnitSpecialEntity) // Special/Exceptional Case for this
            {
                string altEntityCode = milSymbol.Id.EntityField + milSymbol.Id.EntityTypeField + "00";
                mainIcon = GetMainIconName(milSymbol.Id.SymbolSet, altEntityCode);
            }
            else
            {
                mainIcon = GetMainIconName(milSymbol.Id.SymbolSet, milSymbol.Id.EntityCode);
            }

            return(mainIcon);
        }
        public MilitarySymbol CreateSymbolFromStringProperties(
            // SymbolSetType symbolSet,
            StandardIdentityAffiliationType affiliation,
            string symbolSetString, string entityCode, string geoType,
            string entityName, string entityTypeName, string entitySubTypeName,
            string centralIconTypeString)
        {
            if ((string.IsNullOrEmpty(symbolSetString) || symbolSetString.Length != 2))
            {
                System.Diagnostics.Trace.WriteLine("CreateSymbolFromStringProperties - Bad Symbol Set Code");
                return(null);
            }

            if ((string.IsNullOrEmpty(entityCode) || entityCode.Length != 6))
            {
                System.Diagnostics.Trace.WriteLine("CreateSymbolFromStringProperties - Bad Entity Code");
                return(null);
            }

            MilitarySymbol retSymbol = new MilitarySymbol();

            SymbolIdCode sidc = new SymbolIdCode();

            sidc.Affiliation       = affiliation;
            sidc.SymbolSetAsString = symbolSetString;
            sidc.EntityCode        = entityCode;

            SymbolSetType symbolSet = (SymbolSetType)
                                      TypeUtilities.EnumHelper.getEnumFromHashCodeString(typeof(SymbolSetType), symbolSetString);

            string symbolSetName = TypeUtilities.EnumHelper.getStringFromEnum(symbolSet);

            retSymbol.Id                = sidc;
            retSymbol.Shape             = (ShapeType)TypeUtilities.EnumHelper.getEnumFromString(typeof(ShapeType), geoType);
            retSymbol.CentralIconFormat = (CentralIconType)TypeUtilities.EnumHelper.getEnumFromString(typeof(CentralIconType), centralIconTypeString);

            return(retSymbol);
        }
        public static bool ExportSymbol(SymbolIdCode code, out System.Drawing.Bitmap exportBitmap,
                                        System.Drawing.Size size)
        {
            if (!code.IsValid)
            {
                exportBitmap = null;
                return(false);
            }

            SvgSymbol svgSymbol = new SvgSymbol();

            SvgSymbol.ImageSize = size;

            MilitarySymbol milSymbol = new MilitarySymbol();

            milSymbol.Id = code;

            MilitarySymbolToGraphicLayersMaker.SetMilitarySymbolGraphicLayers(ref milSymbol);

            exportBitmap = SvgSymbol.GetBitmap(milSymbol.GraphicLayers);

            return(exportBitmap != null);
        }
        /// <summary>
        /// Search the Charlie table and create a list of all of these symbols that can be
        /// created/mapped to Delta
        /// </summary>
        public List <MilitarySymbol> GetMilitarySymbolsFromCharlie()
        {
            Initialize();

            List <MilitarySymbol> symbolList = new List <MilitarySymbol>();

            var results = from row in LegacyCodeMappingTable.AsEnumerable()
                          select row;

            // Check that search returned something
            int resultCount = results.Count();

            if (resultCount < 1)
            {
                System.Diagnostics.Trace.WriteLine("WARNING: Empty result of LegacyCodeMappingTable search");
                // TODO: add search params to the debug output
                return(symbolList); // empty list
            }

            foreach (DataRow row in results)
            {
                string legacyCode = row["2525Charlie"] as string;

                if (!string.IsNullOrWhiteSpace(legacyCode))
                {
                    MilitarySymbol milSymbol = new MilitarySymbol();
                    milSymbol.Legacy2525Code = legacyCode;

                    // TODO: set MilitarySymbol.Shape from SymbolId

                    symbolList.Add(milSymbol);
                }
            }

            return(symbolList);
        }
        /// <summary>
        /// Creates a symbol by looking up the SymbolSet + {any} Entity Name
        /// And then it sets the Affiliation if provided
        /// - this is just a simple/basic test
        /// </summary>
        public MilitarySymbol CreateSymbolByEntityName(string entityName,
                                                       SymbolSetType symbolSet = SymbolSetType.NotSet,
                                                       StandardIdentityAffiliationType affiliation = StandardIdentityAffiliationType.Unknown)
        {
            Initialize();

            if (EntityTable == null)
            {
                return(null);
            }

            var results = from row in EntityTable.AsEnumerable()
                          where ((row.Field <string>("EntitySubType").Contains(entityName)
                                  | (row.Field <string>("EntityType").Contains(entityName)
                                     | (row.Field <string>("Entity").Contains(entityName)))))
                          select row;

            int resultCount = results.Count();

            if (resultCount < 1)
            {
                System.Diagnostics.Trace.WriteLine("Entity Name not found: " + entityName);
                return(null);
            }

            if (symbolSet != SymbolSetType.NotSet)
            {
                // filter results if this is set
                string symbolSetToSearch = TypeUtilities.EnumHelper.getEnumValAsString(symbolSet, 2);

                results = from row in results
                          where (row.Field <string>("SymbolSet") == symbolSetToSearch)
                          select row;
            }

            resultCount = results.Count();

            if (resultCount < 1)
            {
                System.Diagnostics.Trace.WriteLine("Entity Name not found: " + entityName +
                                                   " in SymbolSet: " + symbolSet);
                return(null);
            }

            MilitarySymbol retSymbol = null;

            foreach (DataRow row in results)
            {
                string symbolSetString = row["SymbolSet"] as string;
                string entityCode      = row["Code"] as string;
                string geoType         = row["GeometryType"] as string;

                string entityNameFromLookup        = row["Entity"] as string;
                string entityTypeNameFromLookup    = row["EntityType"] as string;
                string entitySubTypeNameFromLookup = row["EntitySubType"] as string;

                string centralIconTypeString = row["IconType"] as string;

                retSymbol = CreateSymbolFromStringProperties(
                    affiliation, symbolSetString, entityCode, geoType,
                    entityNameFromLookup, entityTypeNameFromLookup, entitySubTypeNameFromLookup,
                    centralIconTypeString);

                // TODO: figure out what to do if we get more than 1 result
                break;
            }

            return(retSymbol);
        }
        /// <summary>
        /// Search based on the one or more attributes supplied
        /// Default param (symbolSet == NotSet) returns all symbols with affiliation set to Unknown
        /// </summary>
        public List <MilitarySymbol> GetMilitarySymbols(SymbolSetType symbolSet = SymbolSetType.NotSet,
                                                        StandardIdentityAffiliationType affiliation = StandardIdentityAffiliationType.Unknown,
                                                        string entityNameString        = "", string entityTypeNameString = "",
                                                        string entitySubTypeNameString = "", bool exactEntityMatchOnly   = false)
        {
            Initialize();

            List <MilitarySymbol> symbolList = new List <MilitarySymbol>();

            if (EntityTable == null)
            {
                return(symbolList); // nothing
            }
            string symbolSetToSearch = TypeUtilities.EnumHelper.getEnumValAsString(symbolSet, 2);

            var results = from row in EntityTable.AsEnumerable()
                          where (row.Field <string>("SymbolSet") == symbolSetToSearch)
                          select row;

            if (symbolSet == SymbolSetType.NotSet)
            {
                results = from row in EntityTable.AsEnumerable()
                          select row;
            }

            // Check that search returned something
            int resultCount = results.Count();

            if (resultCount < 1)
            {
                System.Diagnostics.Trace.WriteLine("WARNING: Empty result of EntityTable search: " + symbolSetToSearch);
                // TODO: add search params to the debug output
                return(symbolList); // empty list
            }

            ////////////////////////////////////////////////////////////////
            // Filters for Entity, EntityType, EntitySubType if these are suppied

            // TRICKY: exactEntityMatchOnly if we only want the 1 that matches exactly, versus all of the
            // type, subtype matches
            if (exactEntityMatchOnly)
            {
                results = from row in results
                          where ((row.Field <string>("Entity") == entityNameString)
                                 & (row.Field <string>("EntityType") == entityTypeNameString)
                                 & (row.Field <string>("EntitySubType") == entitySubTypeNameString))
                          select row;
            }
            else if (!string.IsNullOrEmpty(entityNameString))
            {
                // filter results if this is set
                results = from row in results
                          where (row.Field <string>("Entity") == entityNameString)
                          select row;

                if (!string.IsNullOrEmpty(entityTypeNameString))
                {
                    // filter results if this is set
                    results = from row in results
                              where (row.Field <string>("EntityType") == entityTypeNameString)
                              select row;

                    if (!string.IsNullOrEmpty(entitySubTypeNameString))
                    {
                        // filter results if this is set
                        results = from row in results
                                  where (row.Field <string>("EntitySubType") == entitySubTypeNameString)
                                  select row;
                    }
                }
            }

            // Check that search returned something
            resultCount = results.Count();
            if (resultCount < 1)
            {
                System.Diagnostics.Trace.WriteLine("WARNING: Empty result of search");
                // TODO: add search params to the debug output
                return(symbolList); // empty list
            }

            foreach (DataRow row in results)
            {
                string symbolSetString = row["SymbolSet"] as string;
                string entityCode      = row["Code"] as string;
                string geoType         = row["GeometryType"] as string;

                string entityName        = row["Entity"] as string;
                string entityTypeName    = row["EntityType"] as string;
                string entitySubTypeName = row["EntitySubType"] as string;

                string centralIconTypeString = row["IconType"] as string;

                MilitarySymbol createSymbol = CreateSymbolFromStringProperties(
                    affiliation, symbolSetString, entityCode, geoType,
                    entityName, entityTypeName, entitySubTypeName, centralIconTypeString);

                if (createSymbol != null)
                {
                    symbolList.Add(createSymbol);
                }
            }

            return(symbolList);
        }
Example #13
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);
        }