예제 #1
0
        internal static void Save(MachineInfo machineInfo)
        {
            try
            {
                var axisStack = new Stack <string>();
                var axisList  = new List <string>();

                // save all controls and collect all bound axes
                foreach (BlockInfo blockInfo in machineInfo.Blocks)
                {
                    if (ControlManager.Blocks.ContainsKey(blockInfo.Guid))
                    {
                        var controls = ControlManager.GetActiveBlockControls(blockInfo.Guid);
                        if (controls.Count == 0)
                        {
                            continue;
                        }
                        var control_names = new List <string>();
                        foreach (Control c in controls)
                        {
                            if (!axisStack.Contains(c.Axis))
                            {
                                axisStack.Push(c.Axis);
                            }
                            control_names.Add(c.Name);
                            c.Save(blockInfo);
                        }
                        blockInfo.BlockData.Write("ac-controllist", control_names.ToArray());
                    }
                }

                // go through stack and save all axes and chained axes
                while (axisStack.Count > 0)
                {
                    var a = AxisManager.Get(axisStack.Pop());
                    if (a == null || axisList.Contains(a.Name))
                    {
                        continue;
                    }
                    axisList.Add(a.Name);
                    if (a.Type == AxisType.Chain)
                    {
                        var chain = a as ChainAxis;
                        axisStack.Push(chain.SubAxis1);
                        axisStack.Push(chain.SubAxis2);
                    }
                    if (a.Type == AxisType.Custom)
                    {
                        var custom = a as CustomAxis;
                        foreach (var linked in custom.LinkedAxes)
                        {
                            axisStack.Push(linked);
                        }
                    }
                    a.Save(machineInfo);
                }

                // save axis list and metadata
                if (axisList.Count != 0)
                {
                    machineInfo.MachineData.Write("ac-version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    machineInfo.MachineData.Write("ac-axislist", axisList.ToArray());
                }
            }
            catch (Exception e)
            {
                Debug.Log("[ACM]: Error saving machine's controls.");
                Debug.LogException(e);
            }
        }