private void btnImplementationsNew_Click(object sender, RoutedEventArgs e) { winNewComponentImplementation newComImplementation = new winNewComponentImplementation(); newComImplementation.Owner = this; newComImplementation.ImplementationSet = cbxImplementationsSet.Text; if (newComImplementation.ShowDialog() == true) { if (cbxImplementationsSet.SelectedItem == null) { ComponentRepresentations.Add(new ImplementationConversionCollection() { ImplementationSet = cbxImplementationsSet.Text }); cbxImplementationsSet.SelectedItem = ComponentRepresentations.Last(); } ImplementationConversion conversion = newComImplementation.GetChosenComponent(); // Don't allow duplicates if ((cbxImplementationsSet.SelectedItem as ImplementationConversionCollection).Items.FirstOrDefault(item => item.ImplementationName == conversion.ImplementationName) != null) { TaskDialogInterop.TaskDialog.ShowMessage(this, "The item could not be added because it is already present.\r\n\r\nYou can add this item again if you delete its current representation first.", "Could Not Add Item", TaskDialogInterop.TaskDialogCommonButtons.Close, TaskDialogInterop.VistaTaskDialogIcon.Warning); } else { (cbxImplementationsSet.SelectedItem as ImplementationConversionCollection).Items.Add(newComImplementation.GetChosenComponent()); // Add to ComponentHelper's list of conversions ComponentDescription description = ComponentHelper.FindDescription(conversion.ToGUID); ComponentConfiguration theConfiguration = description.Metadata.Configurations.FirstOrDefault(check => check.Name == conversion.ToConfiguration); ComponentHelper.SetStandardComponent(cbxImplementationsSet.Text, conversion.ImplementationName, description, theConfiguration); } } }
public static List <ImplementationConversionCollection> LoadImplementationConversions() { var implementationConversions = new List <ImplementationConversionCollection>(); if (File.Exists(implementationsFilePath)) { try { XmlDocument implDoc = new XmlDocument(); implDoc.Load(implementationsFilePath); XmlNodeList sourceNodes = implDoc.SelectNodes("/implementations/source"); foreach (XmlNode sourceNode in sourceNodes) { string collection = sourceNode.Attributes["definitions"].InnerText; ImplementationConversionCollection newCollection = new ImplementationConversionCollection(); newCollection.ImplementationSet = collection; foreach (XmlNode childNode in sourceNode.ChildNodes) { if (childNode.Name != "add") { continue; } string item = childNode.Attributes["item"].InnerText; Guid guid = Guid.Empty; XmlNode guidNode = childNode.SelectSingleNode("guid"); if (guidNode != null) { guid = new Guid(guidNode.InnerText); } string configuration = null; XmlNode configurationNode = childNode.SelectSingleNode("configuration"); if (configurationNode != null) { configuration = configurationNode.InnerText; } ComponentDescription description = ComponentHelper.FindDescription(guid); if (description != null) { ImplementationConversion newConversion = new ImplementationConversion(); newConversion.ImplementationName = item; newConversion.ToName = description.ComponentName; newConversion.ToGUID = description.Metadata.GUID; ComponentConfiguration theConfiguration = null; if (configuration != null) { theConfiguration = description.Metadata.Configurations.FirstOrDefault(check => check.Name == configuration); if (theConfiguration != null) { newConversion.ToConfiguration = theConfiguration.Name; if (theConfiguration.Icon != null) { newConversion.ToIcon = theConfiguration.Icon; } else { newConversion.ToIcon = description.Metadata.Icon; } } else if (description.Metadata.Icon != null) { newConversion.ToIcon = description.Metadata.Icon; } } else if (description.Metadata.Icon != null) { newConversion.ToIcon = description.Metadata.Icon; } newCollection.Items.Add(newConversion); ComponentHelper.SetStandardComponent(newCollection.ImplementationSet, newConversion.ImplementationName, description, theConfiguration); } } implementationConversions.Add(newCollection); } } catch (Exception) { // Invalid XML file } } return(implementationConversions); }
/// <summary> /// Populates the toolbox from the xml file. /// </summary> public static List <List <IToolboxItem> > LoadToolbox() { var result = new List <List <IToolboxItem> >(); XmlDocument toolboxSettings = new XmlDocument(); toolboxSettings.Load(toolboxSettingsPath); XmlNodeList categoryNodes = toolboxSettings.SelectNodes("/display/category"); foreach (XmlNode categoryNode in categoryNodes) { var newCategory = new List <IToolboxItem>(); foreach (XmlNode node in categoryNode.ChildNodes) { if (node.Name == "component") { XmlElement element = node as XmlElement; ComponentDescription description; if (element.HasAttribute("guid")) { description = ComponentHelper.FindDescription(new Guid(element.Attributes["guid"].InnerText)); } else if (element.HasAttribute("type")) { description = ComponentHelper.FindDescription(element.Attributes["type"].InnerText); } else { continue; } ComponentConfiguration configuration = null; if (element.HasAttribute("configuration")) { configuration = description.Metadata.Configurations.FirstOrDefault(configItem => configItem.Name == element.Attributes["configuration"].InnerText); } var newItem = new IdentifierWithShortcut(); newItem.Identifier = new ComponentIdentifier(description, configuration); if (newItem.Icon.LoadedIcons.Count == 0) { newItem.Icon.LoadIcons(); } // Shortcut if (element.HasAttribute("key") && KeyTextConverter.IsValidLetterKey(element.Attributes["key"].InnerText)) { Key key = (Key)Enum.Parse(typeof(Key), element.Attributes["key"].InnerText); newItem.ShortcutKey = key; } newCategory.Add(newItem); } } if (newCategory.Count > 0) { result.Add(newCategory); } } return(result); }
/// <summary> /// Converts a <see cref="IODocument"/> to a <see cref="CircuitDocument"/>. /// </summary> /// <param name="document">The IODocument to convert.</param> /// <returns>A CircuitDocument constructed from the IODocument.</returns> public static CircuitDocument ToCircuitDocument(this IODocument document, IDocumentReader reader, out List <IOComponentType> unavailableComponents) { CircuitDocument circuitDocument = new CircuitDocument(); circuitDocument.Size = document.Size; // Set metadata circuitDocument.Metadata = new CircuitDocumentMetadata(null, null, document.Metadata); // Add components unavailableComponents = new List <IOComponentType>(); foreach (IOComponent component in document.Components) { ComponentIdentifier identifier = null; // Find description if (component.Type.GUID != Guid.Empty && ComponentHelper.IsDescriptionAvailable(component.Type.GUID)) { identifier = new ComponentIdentifier(ComponentHelper.FindDescription(component.Type.GUID)); } if (identifier == null && reader.IsDescriptionEmbedded(component.Type)) { identifier = LoadDescription(reader.GetEmbeddedDescription(component.Type), component.Type); } if (identifier == null && component.Type.IsStandard) { identifier = ComponentHelper.GetStandardComponent(component.Type.Collection, component.Type.Item); } if (identifier != null) { // Add full component Dictionary <string, object> properties = new Dictionary <string, object>(); foreach (var property in component.Properties) { properties.Add(property.Key, property.Value); } Component addComponent = Component.Create(identifier, properties); addComponent.Layout(component.Location.Value.X, component.Location.Value.Y, (component.Size.HasValue ? component.Size.Value : identifier.Description.MinSize), component.Orientation.Value, component.IsFlipped == true); addComponent.ImplementMinimumSize(addComponent.Description.MinSize); FlagOptions flagOptions = ComponentHelper.ApplyFlags(addComponent); if ((flagOptions & FlagOptions.HorizontalOnly) == FlagOptions.HorizontalOnly && component.Orientation == Orientation.Vertical) { addComponent.Orientation = Orientation.Horizontal; } else if ((flagOptions & FlagOptions.VerticalOnly) == FlagOptions.VerticalOnly && component.Orientation == Orientation.Horizontal) { addComponent.Orientation = Orientation.Vertical; } circuitDocument.Elements.Add(addComponent); } else { // Add disabled component if (!unavailableComponents.Contains(component.Type)) { unavailableComponents.Add(component.Type); } DisabledComponent addComponent = new DisabledComponent(); Dictionary <string, object> properties = new Dictionary <string, object>(); foreach (var property in component.Properties) { addComponent.Properties.Add(property.Key, property.Value); } addComponent.ImplementationCollection = component.Type.Collection; addComponent.ImplementationItem = component.Type.Item; addComponent.Name = component.Type.Name; addComponent.GUID = component.Type.GUID; if (component.Location.HasValue) { addComponent.Location = new Vector(component.Location.Value.X, component.Location.Value.Y); } addComponent.Size = component.Size; addComponent.Orientation = component.Orientation; circuitDocument.DisabledComponents.Add(addComponent); } } // Add wires IOComponentType wireType = new IOComponentType("wire"); if (ComponentHelper.WireDescription == null) { unavailableComponents.Add(wireType); } else { foreach (IOWire wire in document.Wires) { Dictionary <string, object> properties = new Dictionary <string, object>(4); properties.Add("@x", wire.Location.X); properties.Add("@y", wire.Location.Y); properties.Add("@orientation", wire.Orientation == Orientation.Horizontal); properties.Add("@size", wire.Size); Component wireComponent = Component.Create(ComponentHelper.WireDescription, properties); wireComponent.Layout(wire.Location.X, wire.Location.Y, wire.Size, wire.Orientation, false); wireComponent.ApplyConnections(circuitDocument); circuitDocument.Elements.Add(wireComponent); } } // Connections foreach (Component component in circuitDocument.Components) { component.ApplyConnections(circuitDocument); } return(circuitDocument); }