Ejemplo n.º 1
0
        public virtual void RenderComponent(PositionalComponent component, IDrawingContext drawingContext, bool ignoreOffset = true)
        {
            var description = descriptionLookup.GetDescription(component.Type);

            if (description == null)
            {
                throw new ApplicationException($"No component description available for {component.Type}");
            }

            var flags = description.DetermineFlags(component);

            var layoutOptions = new LayoutOptions
            {
                Absolute    = !ignoreOffset,
                AlignMiddle = (flags & FlagOptions.MiddleMustAlign) == FlagOptions.MiddleMustAlign,
                GridSize    = 10.0
            };

            var layoutContext = new LayoutContext(layoutOptions, p => GetFormattedVariable(p, component, description));

            foreach (var renderDescription in description.RenderDescriptions)
            {
                if (renderDescription.Conditions.IsMet(component, description))
                {
                    renderDescription.Render(component, layoutContext, drawingContext);
                }
            }
        }
Ejemplo n.º 2
0
        private IList <ConnectionPoint> GetConnectionPoints(PositionalComponent component, LayoutOptions layoutOptions)
        {
            var description = descriptionLookup.GetDescription(component.Type);

            if (description == null)
            {
                throw new ApplicationException($"No component description available for {component.Type}");
            }

            return(connectionPositioner.PositionConnections(component, description, layoutOptions));
        }
        public ConfigurationDefinition ReadDefinition(Stream input)
        {
            var yaml = deserializer.Deserialize <YamlTemplate>(new StreamReader(input));

            var guid            = Guid.Parse(yaml.Metadata.Guid);
            var descriptionGuid = Guid.Parse(yaml.Template.Guid);

            var description = componentDescriptionLookup.GetDescription(new TypeDescriptionComponentType(descriptionGuid, ComponentType.Unknown(yaml.Template.Name)));

            if (description == null)
            {
                throw new InvalidOperationException("Base description for template not found.");
            }

            var metadata = new DefinitionMetadata
            {
                Guid        = guid,
                Description = yaml.Metadata.Description,
                Name        = yaml.Metadata.Name,
                Version     = yaml.Metadata.Version,
            };

            var properties = new Dictionary <PropertyName, PropertyValue>();

            foreach (var setter in yaml.Properties)
            {
                var componentProperty = description.Properties.FirstOrDefault(x => x.Name == setter.Name);
                if (componentProperty == null)
                {
                    throw new InvalidOperationException($"Property '{setter.Name}' does not exist on component type '{description.ComponentName}'");
                }

                PropertyValue value;
                switch (componentProperty.Type)
                {
                case PropertyType.Boolean:
                {
                    value = new PropertyValue((bool)setter.Value);
                    break;
                }

                case PropertyType.Decimal:
                {
                    value = new PropertyValue((double)setter.Value);
                    break;
                }

                case PropertyType.Integer:
                {
                    value = new PropertyValue((int)setter.Value);
                    break;
                }

                case PropertyType.Enum:
                case PropertyType.String:
                {
                    value = new PropertyValue((string)setter.Value);
                    break;
                }

                default:
                {
                    throw new NotSupportedException("Unknown property type.");
                }
                }

                properties.Add(componentProperty.SerializedName, value);
            }

            var configuration = new ComponentConfiguration(null, yaml.Metadata.Name, properties);

            return(new ConfigurationDefinition(metadata, description, configuration));
        }
Ejemplo n.º 4
0
        private IList <ConnectionPoint> GetConnectionPoints(PositionalComponent component, LayoutOptions layoutOptions)
        {
            var description = descriptionLookup.GetDescription(component.Type);

            return(connectionPositioner.PositionConnections(component, description, layoutOptions));
        }
Ejemplo n.º 5
0
        protected void SizeComponent(PositionalComponent component, Primitives.Point start, Primitives.Point end, double gridSize)
        {
            // reverse points if necessary
            Primitives.Point newStart = start;
            Primitives.Point newEnd   = end;
            bool             switched = false;

            if (start.X < end.X)
            {
                newStart = end;
                newEnd   = start;
                switched = true;
            }

            if (true) // snap to grid
            {
                if (Math.IEEERemainder(newStart.X, 20d) != 0)
                {
                    newStart = newStart.WithNewX(newStart.SnapToGrid(gridSize).X);
                }
                if (Math.IEEERemainder(newStart.Y, 20d) != 0)
                {
                    newStart = newStart.WithNewY(newStart.SnapToGrid(gridSize).Y);
                }
                if (Math.IEEERemainder(newEnd.X, 20d) != 0)
                {
                    newEnd = newEnd.WithNewX(newEnd.SnapToGrid(gridSize).X);
                }
                if (Math.IEEERemainder(newEnd.Y, 20d) != 0)
                {
                    newEnd = newEnd.WithNewY(newEnd.SnapToGrid(gridSize).Y);
                }
            }
            if (true) // snap to horizontal or vertical
            {
                double height  = Math.Max(newStart.Y, newEnd.Y) - Math.Min(newStart.Y, newEnd.Y);
                double length  = Math.Sqrt(Math.Pow(newEnd.X - newStart.X, 2d) + Math.Pow(newEnd.Y - newStart.Y, 2d));
                double bearing = Math.Acos(height / length) * (180 / Math.PI);

                if (bearing <= 45 && switched)
                {
                    newStart = newStart.WithNewX(newEnd.X);
                }
                else if (bearing <= 45 && !switched)
                {
                    newEnd = newEnd.WithNewX(newStart.X);
                }
                else if (bearing > 45 && switched)
                {
                    newStart = newStart.WithNewY(newEnd.Y);
                }
                else
                {
                    newEnd = newEnd.WithNewY(newStart.Y);
                }
            }

            if (newStart.X > newEnd.X || newStart.Y > newEnd.Y)
            {
                component.Layout.Location = new Primitives.Point(newEnd.X, newEnd.Y);
                if (newStart.X == newEnd.X)
                {
                    component.Layout.Size        = newStart.Y - newEnd.Y;
                    component.Layout.Orientation = Orientation.Vertical;
                }
                else
                {
                    component.Layout.Size        = newStart.X - newEnd.X;
                    component.Layout.Orientation = Orientation.Horizontal;
                }
            }
            else
            {
                component.Layout.Location = new Primitives.Point(newStart.X, newStart.Y);
                if (newStart.X == newEnd.X)
                {
                    component.Layout.Size        = newEnd.Y - newStart.Y;
                    component.Layout.Orientation = Orientation.Vertical;
                }
                else
                {
                    component.Layout.Size        = newEnd.X - newStart.X;
                    component.Layout.Orientation = Orientation.Horizontal;
                }
            }

            var description = descriptionLookup.GetDescription(component.Type);

            //FlagOptions flagOptions = ApplyFlags(component);
            //if ((flagOptions & FlagOptions.HorizontalOnly) == FlagOptions.HorizontalOnly && component.Layout.Orientation == Orientation.Vertical)
            //{
            //    component.Layout.Orientation = Orientation.Horizontal;
            //    component.Layout.Size = component.Layout.Description.MinSize;
            //}
            //else if ((flagOptions & FlagOptions.VerticalOnly) == FlagOptions.VerticalOnly && component.Layout.Orientation == Orientation.Horizontal)
            //{
            //    component.Layout.Orientation = Orientation.Vertical;
            //    component.Layout.Size = component.Layout.Description.MinSize;
            //}

            double minAllowedSize = Math.Max(description.MinSize, gridSize);

            if (component.Layout.Size < minAllowedSize)
            {
                component.Layout.Size = minAllowedSize;
            }
        }