コード例 #1
0
        /// <summary>
        /// Converts a Circuit instance into seraliazable CircuitData object
        /// </summary>
        /// <param name="circuit">the circuit to convert</param>
        /// <returns>converted circuitdata</returns>
        public CircuitData ConvertFromCircuit(Circuit circuit)
        {
            CircuitData circuitData = new CircuitData(circuit.Name);

            CreateElementData(circuitData, circuit);
            return(circuitData);
        }
コード例 #2
0
        private void CreateElements(Circuit circuit, CircuitData circuitData, SignalList signals, bool createGraphics)
        {
            Dictionary <BaseElement, BaseElementData> elemDict = new Dictionary <BaseElement, BaseElementData>();

            foreach (BaseElementData elemData in circuitData.Elements)
            {
                InputOutputElement element = null;
                element = ConvertElementData(elemData, createGraphics, elemDict, signals);
                if (element != null)
                {
                    circuit.AddElement(element);
                }
            }
            foreach (ConnectionData connectionData in circuitData.Connections)
            {
                Connection connection = new Connection();
                connection.Name = connectionData.Name;
                ConnectTerminals(connection, circuit, elemDict);
                if (connection.Terminals.Count > 0)
                {
                    if (createGraphics)
                    {
                        GraphicConnection graphicConnection =
                            GraphicObjectFactory.CreateInstance(typeof(Connection), connection) as GraphicConnection;
                        CreateConnectionLines(circuit, graphicConnection, connectionData);
                    }
                    circuit.AddElement(connection);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Converts (restores) deserialized CircuitData object into a Circuit instance.
        /// Creation of graphical objects for GUI is determined by parameter.
        /// </summary>
        /// <param name="circuitData">deserialized CircuitData object</param>
        /// <param name="signals">the corresponding Signals for the circuit</param>
        /// <param name="createGraphics">states whether to create graphical objects</param>
        /// <returns>restored Circuit instance</returns>
        public Circuit ConvertToCircuit(CircuitData circuitData, SignalList signals, bool createGraphics)
        {
            Circuit circuit = new Circuit();

            CreateElements(circuit, circuitData, signals, createGraphics);
            return(circuit);
        }
コード例 #4
0
        /// <summary>
        /// Serializes a Circuits converted to CircuitData objects to a XML file
        /// </summary>
        /// <param name="fileName">The filename of the file</param>
        /// <param name="circuitData">The CircuitData object to serialize</param>
        public static void SerializeCircuit(string fileName, CircuitData circuitData)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(CircuitData));
            FileStream    fs         = new FileStream(fileName, FileMode.Create);

            serializer.Serialize(fs, circuitData);
            fs.Close();
        }
コード例 #5
0
        /// <summary>
        /// Deserializes a XML file to a CircuitData object, which can be converted to Circuits.
        /// </summary>
        /// <param name="fileName">The filename of the file</param>
        /// <returns>The deserialized CircuitData object</returns>
        public static CircuitData DeserializeCircuit(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                return(new CircuitData());
            }
            XmlSerializer serializer  = new XmlSerializer(typeof(CircuitData));
            FileStream    fs          = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            CircuitData   circuitData = (CircuitData)serializer.Deserialize(fs);

            fs.Close();
            return(circuitData);
        }
コード例 #6
0
        private void CreateElementData(CircuitData circuitData, Circuit circuit)
        {
            List <BaseElementData> elements    = new List <BaseElementData>();
            List <ConnectionData>  connections = new List <ConnectionData>();

            foreach (BaseElement be in circuit)
            {
                if (be is Connection)
                {
                    ConnectionData connData = ConvertConnection(be);
                    connections.Add(connData);
                }
                else if (be is InputOutputElement)
                {
                    BaseElementData elemData = ConvertIOElement(be);
                    if (elemData != null)
                    {
                        elements.Add(elemData);
                    }
                }
            }
            circuitData.Elements    = elements.ToArray();
            circuitData.Connections = connections.ToArray();
        }
コード例 #7
0
 /// <summary>
 /// Converts (restores) deserialized CircuitData object into a Circuit instance.
 /// Creation of graphical objects for GUI is determined by parameter.
 /// </summary>
 /// <param name="circuitData">deserialized CircuitData object</param>
 /// <param name="createGraphics">states whether to create graphical objects</param>
 /// <returns>restored Circuit instance</returns>
 public Circuit ConvertToCircuit(CircuitData circuitData, bool createGraphics)
 {
     return(ConvertToCircuit(circuitData, null, createGraphics));
 }
コード例 #8
0
 /// <summary>
 /// Converts (restores) deserialized CircuitData object into a Circuit instance.
 /// Graphical objects for GUI are not created.
 /// </summary>
 /// <param name="circuitData">deserialized CircuitData object</param>
 /// <returns>restored Circuit instance</returns>
 public Circuit ConvertToCircuit(CircuitData circuitData)
 {
     return(ConvertToCircuit(circuitData, null, false));
 }