/* =========================================================================================
         * Saving and Loading
         * =========================================================================================
         */
        private void Save()
        {
            Cursor csr = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            NameControls();

            foreach (Control c in Controls)
            {
                if (LogicGate1.IsLogicGate1(c) || LogicGate2.IsLogicGate2(c) || LogicGate.IsNibble(c))
                {
                    SerializedLogicGate slg = new SerializedLogicGate();
                    slg.Location = c.Location;
                    slg.Type = c.GetType().FullName;
                    slg.Name = c.Name;
                    if (LogicGate1.IsLogicGate1(c))
                    {
                        LogicGate1 g = (LogicGate1)c;
                        if (g.InputPoint.Connected.Count == 0) { slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint.IO, true)); }
                        else { slg.inputs.Add(new SerializedLogicGate.Inputs(false, false)); }
                        getConnected(g.OutputPoint, ref slg);
                    }
                    else if (LogicGate2.IsLogicGate2(c))
                    {
                        LogicGate2 g = (LogicGate2)c;
                        if (g.InputPoint0.Connected.Count == 0) { slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint0.IO, true)); }
                        else slg.inputs.Add(new SerializedLogicGate.Inputs(false, false));
                        if (g.InputPoint1.Connected.Count == 0) { slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint1.IO, true)); }
                        else slg.inputs.Add(new SerializedLogicGate.Inputs(false, false));
                        getConnected(g.OutputPoint, ref slg);
                    }
                    else if (LogicGate.IsNibble(c))
                    {
                        Nibble g = (Nibble)c;
                        if (g.InputPoint0.Connected.Count == 0) slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint0.IO, true));
                        else slg.inputs.Add(new SerializedLogicGate.Inputs(false, false));
                        if (g.InputPoint1.Connected.Count == 0) slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint1.IO, true));
                        else slg.inputs.Add(new SerializedLogicGate.Inputs(false, false));
                        if (g.InputPoint2.Connected.Count == 0) slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint2.IO, true));
                        else slg.inputs.Add(new SerializedLogicGate.Inputs(false, false));
                        if (g.InputPoint3.Connected.Count == 0) slg.inputs.Add(new SerializedLogicGate.Inputs(g.InputPoint3.IO, true));
                        else slg.inputs.Add(new SerializedLogicGate.Inputs(false, false));

                        getConnected(g.OutputPoint0, ref slg);
                        getConnected(g.OutputPoint1, ref slg);
                        getConnected(g.OutputPoint2, ref slg);
                        getConnected(g.OutputPoint3, ref slg);
                    }
                    p.LogicGates.Add(slg);
                }
            }

            p.Size = s;
            p.FontSize = fs;

            System.Xml.Serialization.XmlSerializer formatter = new System.Xml.Serialization.XmlSerializer(typeof(Project));
            Stream stream = new FileStream(p.FileName, FileMode.Create, FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, p);
            stream.Close();
            Cursor.Current = csr;
        }
 private void getConnected(IOPoint iop, ref SerializedLogicGate slg)
 {
     SerializedLogicGate.Outputs outputlist = new SerializedLogicGate.Outputs();
     foreach (IOPoint iop2 in iop.Connected)
     {
         Connector c = (Connector)iop2.Parent;
         Debug.Print(((Control)c.OutputPoint.Connected[0].Parent).Name);
         outputlist.ConnectedTo.Add(((Control)c.OutputPoint.Connected[0].Parent).Name + "." + c.OutputPoint.Connected[0].Name);
     }
     slg.outputs.Add(outputlist);
 }