missioncommand / mil-sym-java

(RETIRED) MIL-STD-2525 B and C rendering library and web service
Apache License 2.0
67 stars 36 forks source link

hasModifier/canSymbolHaveModifier Failure - Part 2 #29

Closed david-melendez closed 7 years ago

david-melendez commented 8 years ago

NOTE: hasModifier calls canSymbolHaveModifier

A canSymbolHaveModifier call can fail if the specified symbol supports the "AM" modifier but not the "M" modifier. For example, the following code will return true instead of false.

boolean result = SymbolUtilities.canHaveSymbolModifier("G*F*ATC---****X", "M", 1);

Note that the XML for this symbol (below) shows that this symbol does NOT support the "M" modifier but it does support the "AM" modifier.

  <SYMBOL>
    <SYMBOLID>G*F*ATC---****X</SYMBOLID>
    <GEOMETRY>area</GEOMETRY>
    <DRAWCATEGORY>16</DRAWCATEGORY>
    <MAXPOINTS>1</MAXPOINTS>
    <MINPOINTS>1</MINPOINTS>
    <MODIFIERS>T.AM.</MODIFIERS>
    <DESCRIPTION>Circular Target</DESCRIPTION>
    <HIERARCHY>2.X.4.3.1.2</HIERARCHY>
    <ALPHAHIERARCHY>TACGRP.FSUPP.ARS.ARATGT.CIRTGT</ALPHAHIERARCHY>
    <PATH>Tactical Graphics/Fire Support/Areas/Area Target</PATH>
  </SYMBOL>

The problem is that the canSymbolHaveModifier checks to see if the MODIFIERS element has the specified modifier followed by a period. This means that "M" returns true because the code finds the string "M." in the string (i.e., T.AM.). This occurs in two places in the code (see =====>).

public static boolean canSymbolHaveModifier(String symbolID, String tgModifier, int symStd)
       {
           String basic = null;
           SymbolDef sd = null;
           boolean returnVal = false;

            try
            {

                basic = SymbolUtilities.getBasicSymbolID(symbolID);
                sd = SymbolDefTable.getInstance().getSymbolDef(basic, symStd);
                if(sd != null)
                {
                    int dc = sd.getDrawCategory();
                    if(tgModifier.equals(ModifiersTG.AM_DISTANCE))
                    {
                        switch(dc)
                        {
                            case SymbolDef.DRAW_CATEGORY_RECTANGULAR_PARAMETERED_AUTOSHAPE:
                            case SymbolDef.DRAW_CATEGORY_SECTOR_PARAMETERED_AUTOSHAPE:
                            case SymbolDef.DRAW_CATEGORY_TWO_POINT_RECT_PARAMETERED_AUTOSHAPE: 
                                returnVal = true;
                                break;
                            case SymbolDef.DRAW_CATEGORY_CIRCULAR_PARAMETERED_AUTOSHAPE:
                            case SymbolDef.DRAW_CATEGORY_CIRCULAR_RANGEFAN_AUTOSHAPE:
                                returnVal = true;
                                break;
                            case SymbolDef.DRAW_CATEGORY_LINE:
   ======>             if(sd.getModifiers().indexOf(tgModifier + ".")>-1)
                                    returnVal = true;
                                break;
                            default:
                                returnVal = false;
                        }
                    }
                    else if(tgModifier.equals(ModifiersTG.AN_AZIMUTH))
                    {
                        switch(dc)
                        {
                            case SymbolDef.DRAW_CATEGORY_RECTANGULAR_PARAMETERED_AUTOSHAPE:
                            case SymbolDef.DRAW_CATEGORY_SECTOR_PARAMETERED_AUTOSHAPE:
                                returnVal = true;
                                break;
                            default:
                                returnVal = false;
                        }
                    }
                    else
                    {
  ======>     sd.getModifiers().indexOf(tgModifier + ".")>-1)
                            returnVal = true;
                    }
                }

                return returnVal;

            }
            catch(Exception exc)
            {
                ErrorLogger.LogException("SymbolUtilties", "canSymbolHaveModifier", exc);
            }
            return returnVal;
       }
michael-spinelli commented 8 years ago

I need to update the documentation in the code and on the wiki. Really you should be using the the constants from ModifiersTG and ModifiersUnits. If you're checking against a symbolCode that starts with 'G' or 'W', you'd use ModifiersTG. Everything else you'd use ModifiersUnits. ModifiersTG does not have 'M' Higher Formation. So you shouldn't run into the issue you're describing above. However, that could come up with 'N' and 'AN'.
I'll add some checks so you don't get anymore false positives.

david-melendez commented 8 years ago

Thank you for the clarification.

David Melendez

mailto:david.melendez@nova-tech-solutions.com david.melendez@nova-tech-solutions.com

Software Engineer

Nova Tech Solutions

From: Michael Spinelli [mailto:notifications@github.com] Sent: Tuesday, October 18, 2016 2:58 PM To: missioncommand/mil-sym-java mil-sym-java@noreply.github.com Cc: david-melendez david.melendez@nova-tech-solutions.com; Author author@noreply.github.com Subject: Re: [missioncommand/mil-sym-java] hasModifier/canSymbolHaveModifier Failure - Part 2 (#29)

I need to update the documentation in the code and on the wiki. Really you should be using the the constants from ModifiersTG and ModifiersUnits. If you're checking against a symbolCode that starts with 'G' or 'W', you'd use ModifiersTG. Everything else you'd use ModifiersUnits. ModifiersTG does not have 'M' Higher Formation. So you shouldn't run into the issue you're describing above. However, that could come up with 'N' and 'AN'.

I'll add some checks so you don't get anymore false positives.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/missioncommand/mil-sym-java/issues/29#issuecomment-254621125 , or mute the thread https://github.com/notifications/unsubscribe-auth/AVkzUyD0lDEH1at2d7JvaIGtCSzo30gTks5q1SSwgaJpZM4KaHgL .

No virus found in this message. Checked by AVG - www.avg.com http://www.avg.com Version: 2016.0.7859 / Virus Database: 4664/13232 - Release Date: 10/18/16


No virus found in this message. Checked by AVG - www.avg.com http://www.avg.com Version: 2016.0.7797 / Virus Database: 4664/13229 - Release Date: 10/17/16