// // ComponentInstance.cs - represents an instance of a Component in a component designer layout // // Author: // Michael Becker // // Copyright (c) 2011-2020 Mike Becker's Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; using MBS.Framework.Drawing; namespace UniversalEditor.ObjectModels.Designer { /// /// Represents an instance of a in a component designer layout. /// public class ComponentInstance : ICloneable { public class ComponentInstanceCollection : System.Collections.ObjectModel.Collection { } public ComponentInstance(Component component, Rectangle rectangle, PropertyValue[] propertyValues = null) { Component = component; X = new Measurement(rectangle.X, MeasurementUnit.Pixel); Y = new Measurement(rectangle.Y, MeasurementUnit.Pixel); Width = new Measurement(rectangle.Width, MeasurementUnit.Pixel); Height = new Measurement(rectangle.Height, MeasurementUnit.Pixel); if (propertyValues != null) { for (int i = 0; i < propertyValues.Length; i++) { PropertyValues.Add(propertyValues[i]); } } } public object Clone() { ComponentInstance clone = new ComponentInstance(Component, new Rectangle(X.Value, Y.Value, Width.Value, Height.Value)); clone.ID = ID; clone.Component = Component; for (int i = 0; i < PropertyValues.Count; i++) { clone.PropertyValues.Add(PropertyValues[i].Clone() as PropertyValue); } clone.X = X; clone.Y = Y; clone.Z = Z; clone.Width = Width; clone.Height = Height; clone.Depth = Depth; return clone; } /// /// Gets or sets the globally-unique identifier for this . /// /// The globally-unique identifier for this . public Guid ID { get; set; } = Guid.Empty; /// /// Gets or sets the for which this is an instance. /// /// The for which this is an instance. public Component Component { get; set; } = null; /// /// Gets a collection of instances representing connections this has to other s. /// /// The connections this has to other s. public ConnectionValue.ConnectionValueCollection ConnectionValues { get; } = new ConnectionValue.ConnectionValueCollection(); /// /// Gets a collection of instances representing instance-specific values for the properties of the associated . /// /// The instance-specific values for the properties of the associated . public PropertyValue.PropertyValueCollection PropertyValues { get; } = new PropertyValue.PropertyValueCollection(); /// /// The distance between the left edge of the design and the left edge of the component. /// public Measurement X { get; set; } = new Measurement(0, MeasurementUnit.Pixel); /// /// The distance between the top edge of the design and the top edge of the component. /// public Measurement Y { get; set; } = new Measurement(0, MeasurementUnit.Pixel); /// /// The position of this component in the front/back order if the layout is two-dimensional, or along the Z axis if the layout is three-dimensional. /// public Measurement Z { get; set; } = new Measurement(0, MeasurementUnit.Pixel); /// /// The width of the component. /// public Measurement Width { get; set; } = new Measurement(0, MeasurementUnit.Pixel); /// /// The height of the component. /// public Measurement Height { get; set; } = new Measurement(0, MeasurementUnit.Pixel); /// /// The depth of the component. /// public Measurement Depth { get; set; } = new Measurement(0, MeasurementUnit.Pixel); } }