001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005
006package armyc2.c5isr.JavaLineArray;
007import java.util.ArrayList;
008
009import armyc2.c5isr.JavaTacticalRenderer.TGLight;
010import armyc2.c5isr.renderer.utilities.ErrorLogger;
011import armyc2.c5isr.renderer.utilities.RendererException;
012import armyc2.c5isr.renderer.utilities.RendererSettings;
013
014/**
015 * A class for the interface between the points calculation CELineArray and
016 * the tactical renderer.
017 *
018 */
019public final class CELineArray {
020    private static final String _className="CELineArray";
021    /**
022    * public function to return the line count required for all of the symbols
023    *
024    * @param plArrayOfLongs the client points as an array of POINT2 in pixels.
025    * @param lElements the number of client points.
026    * @param ChannelWidth the chanel width in pixels
027    *
028    * @return the number of points which will be required for the symbol.
029    */
030    public static int CGetLineCountDouble(TGLight tg,
031            double[] plArrayOfLongs,
032            int lElements, //number of points
033            int ChannelWidth) {
034        int lResult = 0;
035        try {
036            //declarations
037            int lPtrcntr = 0;
038            int lLowerFlotCount = 0, lUpperFlotCount = 0;
039            POINT2[] pLinePoints = new POINT2[lElements];
040            POINT2[] pLowerLinePoints = new POINT2[lElements],
041                    pUpperLinePoints = new POINT2[lElements],
042                    pUpperLowerLinePoints = new POINT2[2 * lElements + 2];
043            short i = 0;
044            //end declarations
045
046            if (lElements <= 0) {
047                return -1;
048            }
049
050            lineutility.InitializePOINT2Array(pLinePoints);
051            lineutility.InitializePOINT2Array(pUpperLinePoints);
052            lineutility.InitializePOINT2Array(pLowerLinePoints);
053            for (i = 0; i < lElements; i++) {
054                pLinePoints[i].x = plArrayOfLongs[lPtrcntr];
055                lPtrcntr++;
056                pLinePoints[i].y = plArrayOfLongs[lPtrcntr];
057                lPtrcntr++;
058            }
059            for (i = 0; i < lElements; i++) {
060                pLowerLinePoints[i] = new POINT2(pLinePoints[i]);
061                pUpperLinePoints[i] = new POINT2(pLinePoints[i]);
062            }
063
064            switch (tg.get_LineType()) {
065                case TacticalLines.CHANNEL:
066                case TacticalLines.CHANNEL_FLARED:
067                case TacticalLines.CHANNEL_DASHED:
068                    lResult = 2 * lElements;
069                    break;
070                case TacticalLines.MAIN:
071                case TacticalLines.MAIN_STRAIGHT:
072                case TacticalLines.AIRAOA:
073                case TacticalLines.SPT:
074                case TacticalLines.SPT_STRAIGHT:
075                    //points for these need not be bounded
076                    //they have an extra 8 points for the arrowhead
077                    lResult = 2 * lElements + 8;
078                    break;
079                case TacticalLines.CATK:
080                    lResult = 2 * lElements + 8;
081                    break;
082                case TacticalLines.CATKBYFIRE:
083                    lResult = 2 * lElements + 17;
084                    break;
085                case TacticalLines.AAAAA:
086                    lResult = 2 * lElements + 19;
087                    break;
088                case TacticalLines.LC:
089                    pUpperLinePoints = Channels.GetChannelArray2Double(1, pUpperLinePoints, 1, lElements, tg.get_LineType(), ChannelWidth);
090                    pLowerLinePoints = Channels.GetChannelArray2Double(1, pLowerLinePoints, 0, lElements, tg.get_LineType(), ChannelWidth);
091                    lUpperFlotCount = flot.GetFlotCountDouble(pUpperLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), lElements);
092                    lLowerFlotCount = flot.GetFlotCountDouble(pLowerLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), lElements);
093                    lResult = lUpperFlotCount + lLowerFlotCount;
094                    break;
095                default:
096                    //call GetCountersDouble for the remaining line types.
097                    lResult = countsupport.GetCountersDouble(tg, lElements, pLinePoints, null);
098                    break;
099            }
100
101
102            //clean up
103            //pvblCounters = null;
104            pLinePoints = null;
105            pLowerLinePoints = null;
106            pUpperLinePoints = null;
107            pUpperLowerLinePoints = null;
108            //GC.Collect();
109        } catch (Exception exc) {
110            ErrorLogger.LogException(_className ,"CGetLineCountDouble",
111                    new RendererException("Failed inside CGetLineCount " + Integer.toString(tg.get_LineType()), exc));
112        }
113        return (lResult);
114    }
115    /**
116     * Return true is the line type is a channel type
117     * @param lineType line type
118     * @return
119     */
120    public static int CIsChannel(int lineType) {
121        int lResult = 0;
122        try {
123            switch (lineType) {
124                case TacticalLines.CATK:
125                case TacticalLines.CATKBYFIRE:
126                case TacticalLines.LC:
127                case TacticalLines.AIRAOA:
128                case TacticalLines.AAAAA:
129                case TacticalLines.MAIN:
130                case TacticalLines.MAIN_STRAIGHT:
131                case TacticalLines.SPT:
132                case TacticalLines.SPT_STRAIGHT:
133                case TacticalLines.UNSP:
134                case TacticalLines.SFENCE:
135                case TacticalLines.DFENCE:
136                case TacticalLines.DOUBLEA:
137                case TacticalLines.LWFENCE:
138                case TacticalLines.HWFENCE:
139                case TacticalLines.SINGLEC:
140                case TacticalLines.DOUBLEC:
141                case TacticalLines.TRIPLE:
142                case TacticalLines.CHANNEL:
143                case TacticalLines.CHANNEL_FLARED:
144                case TacticalLines.CHANNEL_DASHED:
145                    lResult = 1;
146                    break;
147                default:
148                    lResult = 0;
149                    break;
150            }
151        } 
152        catch (Exception exc)
153        {
154            ErrorLogger.LogException(_className ,"CIsChannel",
155                    new RendererException("Failed inside CIsChannel " + Integer.toString(lineType), exc));
156        }
157        return lResult;
158    }
159    private static String _client="";
160    public static void setClient(String value)
161    {
162        _client=value;
163        Channels.setClient(value);
164    }
165    public static String getClient()
166    {
167        return _client;
168    }
169//    public static void setMinLength(double value)
170//    {
171//        DISMSupport.setMinLength(value);
172//        arraysupport.setMinLength(value);
173//        countsupport.setMinLength(value);
174//        return;
175//    }
176}