Beispiel #1
0
        public Instruction(string line, StateCadImporter owner)
        {
            Owner = owner;
            string[] sections = line.Split(new char[] { ' ' }, 17);
            Head = sections[0] + " " + sections[1];

            Parameter = new int[14];
            for (int i = 0; i < Parameter.Length; i++)
            {
                Parameter[i] = Convert.ToInt32(sections[i + 2]);
            }

            Text = sections[16].Split('\x02');
        }
Beispiel #2
0
        public bool ImportStateCADFile(byte[] data)
        {
            for (int i = 0; i < data.Length; i++)
            {
                data[i] ^= 0x80;
            }
            StateCadImporter importer             = new StateCadImporter(Encoding.Default.GetString(data), MainSheet.Sketch, 4f);
            Dictionary <int, DrawableObject> list = new Dictionary <int, DrawableObject>();

            Rectangle sheet = importer.DrawArea;

            sheet.Inflate(400, 400);
            MainSheet.Size = Util.ScaleSize(sheet.Size, 4f);
            DrawableObject select = null;

            foreach (Instruction inst in importer.Instructions)
            {
                switch (inst.Head)
                {
                case "variable add":
                    if (inst.Parameter[10] == 1)    //Input
                    {
                        Variables.AddVariable(new BooleanInput(inst.Name));
                    }
                    else if (inst.Parameter[10] == 2)     //Output
                    {
                        Variables.AddVariable(new BooleanOutput(inst.Name));
                    }
                    else if (inst.Parameter[10] == 6)     //Flag
                    {
                        Variables.AddVariable(new BooleanFlag(inst.Name));
                    }
                    break;

                case "state add":
                    if (inst.Parameter[11] == 0)     //Origin
                    {
                        list.Add(inst.StateId, inst.GetOrigin());
                    }
                    else if (inst.Parameter[11] == 224)    //State
                    {
                        list.Add(inst.StateId, inst.GetState());
                    }
                    else if (inst.Parameter[11] == 176)     //Alias
                    {
                        list.Add(inst.StateId, inst.GetAlias());
                    }
                    break;

                case "state select":
                    select = list[inst.StateId];
                    break;

                case "transition add":
                    int idx = importer.Instructions.IndexOf(inst);
                    inst.GetTransition(importer.Instructions.GetRange(idx, 5), select, list);
                    break;

                case "text add":
                    if (inst.Text[3] == "")
                    {
                        inst.GetText();
                    }
                    else
                    {
                        inst.GetEcuation();
                    }
                    break;
                }
            }

            foreach (Instruction inst in importer.Instructions)
            {
                switch (inst.Head)
                {
                case "state add":
                    if (inst.Parameter[11] == 176)     //Alias
                    {
                        var salias = list[inst.StateId] as StateAlias;
                        salias.PointingTo = inst.Text[1];
                    }
                    break;
                }
            }
            return(true);
        }