private static XYRegion ReadXYRegion(string[] xyLine, StreamReader reader, ref int lineCount)
        {
            if (xyLine.Count() != 10)
            {
                throw new FormatException("Invalid XY region line at line " + lineCount);
            }

            XYRegion xyr;
            int      vcCount;

            try
            {
                string desc         = xyLine[1];
                int    startAddr    = Convert.ToInt32(xyLine[2]);
                int    width        = Convert.ToInt32(xyLine[3]);
                int    xOffset      = Convert.ToInt32(xyLine[4]);
                int    height       = Convert.ToInt32(xyLine[5]);
                int    yOffset      = Convert.ToInt32(xyLine[6]);
                int    rowOffset    = Convert.ToInt32(xyLine[7]);
                int    defaultValue = Convert.ToInt32(xyLine[8]);
                vcCount = Convert.ToInt32(xyLine[9]);

                xyr = new XYRegion(desc, startAddr, width, xOffset, height, yOffset, rowOffset, defaultValue, new Dictionary <int, int>());
            }
            catch
            {
                throw new FormatException("Invalid XY region line at line " + lineCount);
            }

            ReadValueCategories(reader, ref lineCount, vcCount, xyr.ValueCategories);

            return(xyr);
        }
        private static void WriteXYRegion(XYRegion xyr, StringBuilder builder)
        {
            builder.Append((int)xyr.Type + d + xyr.Description + d + xyr.StartAddress + d
                           + xyr.Width + d + xyr.XOffset + d + xyr.Height + d + xyr.YOffset + d
                           + xyr.RowOffset + d + xyr.DefaultValue + d + xyr.ValueCategories.Count + n);

            foreach (var p in xyr.ValueCategories)
            {
                builder.Append(p.Key + d + p.Value + n);
            }
        }
 public void Update(XYRegion newStruct, XYRegion oldStruct)
 {
     if (oldStruct == null)
     {
         structures.Add(newStruct);
     }
     else
     {
         oldStruct.CopyValues(newStruct);
     }
 }
Beispiel #4
0
 public XYRegion(XYRegion copyXY)
     : base(copyXY)
 {
     startAddress    = copyXY.startAddress;
     width           = copyXY.width;
     xOffset         = copyXY.xOffset;
     yOffset         = copyXY.yOffset;
     height          = copyXY.height;
     rowOffset       = copyXY.rowOffset;
     defaultValue    = copyXY.defaultValue;
     valueCategories = new Dictionary <int, int>(copyXY.valueCategories);
 }
        public XYFormManager(XYRegion ox = null)
        {
            oldXY = ox;

            if (oldXY != null)
            {
                vcm = new ValueCategoriesharedManager(new Dictionary <int, int>(ox.ValueCategories));
            }
            else
            {
                vcm = new ValueCategoriesharedManager(new Dictionary <int, int>());
            }

            observers = new List <IStructureObserver <XYRegion> >();
        }
        public bool Confirm(string description, string addressString, decimal widthDec, decimal heightDec,
                            decimal rowOffsetDec, decimal xStartDec, decimal yStartDec, decimal defaultValueDec)
        {
            if (description == "" || addressString == "")
            {
                return(false);
            }

            int address      = Convert.ToInt32(addressString, 16);
            int width        = (int)Math.Round(widthDec);
            int height       = (int)Math.Round(heightDec);
            int rowOffset    = (int)Math.Round(rowOffsetDec);
            int xStart       = (int)Math.Round(xStartDec);
            int yStart       = (int)Math.Round(yStartDec);
            int defaultValue = (int)Math.Round(defaultValueDec);

            newXY = new XYRegion(description, address, width, xStart, height, yStart, rowOffset, defaultValue, vcm.ValueCategories);
            Notify();

            return(true);
        }
        public XYRegionForm(ISharedManager sm, IXYFormManager xy, string title, XYRegion xyr = null)
        {
            sharedManager = sm;
            xyManager     = xy;

            InitializeComponent();
            Text = title;
            ValueCategoryDataGrid.DataSource = xyManager.UpdateValueCategories();

            if (xyr != null)
            {
                AddressTextBox.Text     = xyr.StartAddress.ToString("X");
                DescriptionTextBox.Text = xyr.Description;

                WidthUpDown.Value        = xyr.Width;
                HeightUpDown.Value       = xyr.Height;
                RowOffsetUpDown.Value    = xyr.RowOffset;
                XStartUpDown.Value       = xyr.XOffset;
                YStartUpDown.Value       = xyr.YOffset;
                DefaultValueUpDown.Value = xyr.DefaultValue;
            }
        }
        public static void TestSaveFunction()
        {
            List <IntegerAddress> xCursors = new List <IntegerAddress>();
            List <IntegerAddress> yCursors = new List <IntegerAddress>();

            xCursors.Add(new IntegerAddress(0x326, "Cursor X", -96, (decimal)1 / 8));
            yCursors.Add(new IntegerAddress(0x327, "Cursor Y", -48, (decimal)1 / 8));

            Dictionary <int, int> orientationValues = new Dictionary <int, int>();

            orientationValues[0]  = 1;
            orientationValues[2]  = 2;
            orientationValues[4]  = 3;
            orientationValues[6]  = 4;
            orientationValues[8]  = 5;
            orientationValues[10] = 6;
            orientationValues[12] = 7;
            orientationValues[14] = 8;
            orientationValues[16] = 9;
            orientationValues[18] = 10;
            orientationValues[20] = 9;
            orientationValues[22] = 10;
            orientationValues[24] = 11;
            orientationValues[26] = 11;
            orientationValues[28] = 11;
            orientationValues[30] = 11;
            orientationValues[32] = 12;
            orientationValues[34] = 13;
            orientationValues[36] = 12;
            orientationValues[38] = 13;
            orientationValues[40] = 14;
            orientationValues[42] = 15;
            orientationValues[44] = 16;
            orientationValues[46] = 17;
            orientationValues[48] = 18;
            orientationValues[50] = 19;
            orientationValues[52] = 18;
            orientationValues[54] = 19;

            InformationAddress shapeAndOrientation = new InformationAddress(0x317, "Block shape and orientation", 0, orientationValues);

            Dictionary <int, int> cv1 = new Dictionary <int, int>();

            cv1[0] = 0;

            XYRegion placedBlockLocations = new XYRegion("Placed block locations", 0x100, 12, -1, 0x17, -2, 0x10, 1, cv1);

            List <IntegerAddress> scoreAddresses = new List <IntegerAddress>();

            scoreAddresses.Add(new IntegerAddress(0x270, "Score 1", 0, 1));
            scoreAddresses.Add(new IntegerAddress(0x271, "Score 2", 0, 256));
            scoreAddresses.Add(new IntegerAddress(0x272, "Score 3", 0, 256 * 256));
            scoreAddresses.Add(new IntegerAddress(0x273, "Score 4", 0, 256 * 256 * 256));

            List <MemStructObject> planeObjects = new List <MemStructObject>();

            planeObjects.Add(placedBlockLocations);

            AddressPlane mainPlane = new AddressPlane(planeObjects, "Main plane", -6, 6, -1, 10, 1, xCursors, yCursors);

            List <MemStructObject> structures = new List <MemStructObject>();

            structures.Add(mainPlane);
            structures.Add(shapeAndOrientation);

            List <CategoryColor> cc = new List <CategoryColor>();

            cc.Add(new CategoryColor(Color.Black, 0));
            cc.Add(new CategoryColor(Color.White, 1));

            List <string> buttons = new List <string>();

            buttons.Add("P1 A");
            buttons.Add("P1 B");
            buttons.Add("P1 Down");
            buttons.Add("P1 Left");
            buttons.Add("P1 Right");

            DatabaseSettings settings = new DatabaseSettings(cc, buttons, 300, 30, 0x1912, 80, 600, 20);

            Stream fs = File.Create("Tetris & Dr. Mario - Tetris.plcf");

            WriteFile(structures, scoreAddresses, settings, fs);
        }