private void GenerateItems() { MacroCache macroCache = MacroCache.Instance; List <string> macroNames = macroCache.GetMacroNames(); macroNames.Sort(String.Compare); foreach (string name in macroNames) { //Symbol symbol = macroCache.GetSymbol(name); GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Macro), MacroCache.Instance.GetMacro(name)); element.Location = new PointF(element.Bounds.X * -1, element.Bounds.Y * -1); int width = (int)element.Bounds.Width + 1; int height = (int)element.Bounds.Height + 1; if (width < 48) { width = 48; } if (height < 48) { height = 48; } if (width > 48 && height <= 48) { element.Location = new PointF(element.Location.X, element.Location.Y + (width - height)); height = width; } if (height > 48 && width <= 48) { element.Location = new PointF(element.Location.X + (height - width), element.Location.Y); width = height; } Image img = new Bitmap(width, height); element.Paint(Graphics.FromImage(img)); imageList_Symbols.Images.Add(name, img); ListViewItem item = listView_Macros.Items.Add(name, imageList_Symbols.Images.IndexOfKey(name)); } }
//private Connection ConvertConnectionData(ConnectionData connectionData) //directly done in CreateElements() //{ // Connection connection = new Connection(); // connection.Name = connectionData.Name; // return connection; //} private InputOutputElement ConvertElementData(BaseElementData elemData, bool createGraphics, Dictionary <BaseElement, BaseElementData> elemDict, SignalList signals) { InputOutputElement io = null; //determine type string desiredType = String.Empty; if (elemData is ClockData) { desiredType = typeof(Clock).Name; } if (elemData is ConstantInputData) { desiredType = typeof(ConstantInput).Name; } if (elemData is InputElementData) { desiredType = typeof(SignalInput).Name; } if (elemData is OutputElementData) { desiredType = typeof(SignalOutput).Name; } if (elemData is IOElementData) { desiredType = (elemData as IOElementData).Type; } if (elemData is MacroElementData) { desiredType = typeof(Macro).Name; MacroCache cache = MacroCache.Instance; MacroElementData macroElementData = elemData as MacroElementData; io = cache.GetMacro(macroElementData.Type); if (io == null) { string loaded = cache.LoadMacro(macroElementData.Reference); if (String.IsNullOrEmpty(loaded)) { throw new MacroReferenceNotFoundException(String.Format("Macro not found: \"{0}\".", macroElementData.Type)); } else if (loaded.CompareTo(macroElementData.Type) != 0) { throw new MacroReferenceTypeMismatchException(String.Format("Desired macro type \"{0}\" mismatches type \"{1}\" contained in file \"{2}\".", macroElementData.Type, loaded, macroElementData.Reference)); } io = cache.GetMacro(macroElementData.Type); } if (createGraphics) { GraphicBaseElement graphic = GraphicObjectFactory.CreateInstance(typeof(Macro), io); graphic.Location = new PointF(elemData.X, elemData.Y); } } if (String.IsNullOrEmpty(desiredType)) { throw new NotImplementedException(String.Format("Restoring of Type {0} not implemented", elemData.GetType().Name)); //return null; } //create instance of io element type type (not macros) foreach (Type type in m_ElementTypes) { if (type.Name.Equals(desiredType)) { io = (InputOutputElement)Activator.CreateInstance(type); if (elemData is InputElementData) { InputElementData inelemData = elemData as InputElementData; if (signals != null) { foreach (Signal signal in signals) { if (signal.Name.Equals(inelemData.SignalName)) { (io as SignalInput).Signal = signal; } } } } if (createGraphics) { GraphicBaseElement graphic = GraphicObjectFactory.CreateInstance(type, io); graphic.Location = new PointF(elemData.X, elemData.Y); } break; } } if (io == null) { return(null); } //restore terminals if (elemData is ClockData) { ClockData clockData = elemData as ClockData; io.OutputCount = clockData.Outputs.Length; RestoreTerminals(clockData.Outputs, io.Outputs); Clock clock = io as Clock; clock.HighDuration = clockData.HighDuration; clock.LowDuration = clockData.LowDuration; } if (elemData is ConstantInputData) { ConstantInputData inelemData = elemData as ConstantInputData; StateTypeConverter stateconv = new StateTypeConverter(); (io as ConstantInput).State = (State)stateconv.ConvertFromString(inelemData.State.Trim()); io.OutputCount = inelemData.Outputs.Length; RestoreTerminals(inelemData.Outputs, io.Outputs); } if (elemData is InputElementData) { InputElementData inelemData = elemData as InputElementData; io.OutputCount = inelemData.Outputs.Length; RestoreTerminals(inelemData.Outputs, io.Outputs); if (signals != null) { foreach (Signal signal in signals) { if (signal.Name.Equals(inelemData.SignalName)) { (io as SignalInput).Signal = signal; } } } } if (elemData is OutputElementData) { OutputElementData outelemData = elemData as OutputElementData; (io as SignalOutput).SignalName = outelemData.SignalName; io.InputCount = outelemData.Inputs.Length; RestoreTerminals(outelemData.Inputs, io.Inputs); } if (elemData is IOElementData || elemData is MacroElementData) { IOElementData ioelemData = elemData as IOElementData; io.InputCount = ioelemData.Inputs.Length; io.OutputCount = ioelemData.Outputs.Length; RestoreTerminals(ioelemData.Inputs, io.Inputs); RestoreTerminals(ioelemData.Outputs, io.Outputs); io.UpdateIndex = ioelemData.Index; io.UnitDelay = ioelemData.UnitDelay; io.NegEdgeDelay = ioelemData.NegativeEdgeDelay; io.PosEdgeDelay = ioelemData.PositiveEdgeDelay; } io.Name = elemData.Name; elemDict.Add(io, elemData); return(io); }