public BuildComponentRectangle(string id, FabricStyle fabricStyle, Area area) : base(id) { if (fabricStyle == null) { throw new ArgumentNullException(nameof(fabricStyle)); } if (area == null) { throw new ArgumentNullException(nameof(area)); } if (area.Width < area.Height) { area = new Area(area.Height, area.Width); } m_area = area; m_styleKey = CreateStyleKey(fabricStyle, area); var rectangleShapeNode = new RectangleShapeNode(fabricStyle); var scale = DimensionScale.CreateIdentity(area.Width.Unit); rectangleShapeNode.UpdatePath(PathGeometries.Rectangle.CreatePath(m_area.Width, m_area.Height), PathOrientation.CreateDefault(), scale); m_rectangleShapeNode = rectangleShapeNode; }
private static MDesign_BlockPreview MDesign_BlockPreview(BlockComponent blockComponent, int size) { if (blockComponent == null) { throw new ArgumentNullException(nameof(blockComponent)); } var blockSize = new Dimension(12, DimensionUnits.Inch); var scale = new DimensionScale(blockSize.Value, blockSize.Unit, size, DimensionUnits.Pixel); var pageLayout = new PageLayoutNode(blockSize * scale, blockSize * scale); pageLayout.LayoutSites[0].Node = blockComponent.Expand(false); pageLayout.UpdateBounds(PathOrientation.CreateDefault(), scale); var result = new MDesign_BlockPreview() { Width = (int)(blockSize * scale).Value, Height = (int)(blockSize * scale).Value, Shapes = MDesign_Shapes(pageLayout) }; return(result); }
private static XDesign_LayoutPreview XDesign_LayoutPreview(LayoutComponent layoutComponent, int size) { var blockSize = new Dimension(12, DimensionUnits.Inch); var layoutWidth = blockSize * layoutComponent.ColumnCount; var layoutHeight = blockSize * layoutComponent.RowCount; var maxDimension = layoutWidth > layoutHeight ? layoutWidth : layoutHeight; var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size, DimensionUnits.Pixel); var pageLayoutNode = new PageLayoutNode(layoutWidth * scale, layoutHeight * scale); pageLayoutNode.LayoutSites[0].Node = layoutComponent.Expand(false); pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); var result = new XDesign_LayoutPreview() { width = (int)(layoutWidth * scale).Value, height = (int)(layoutHeight * scale).Value, layoutSites = XDesign_LayoutSites(pageLayoutNode, Palettes.Rainbow) }; return(result); }
public override void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale) { base.UpdatePath(path, pathOrientation, scale); //Trace.TraceInformation("HalfSquareTriangleLayout::ResizeChildren"); // Upper left triangle { IPath pathUpperLeft = PathGeometries.Triangle.CreatePath(new PathPoint[] { Path.GetSegment(3).Origin, Path.GetSegment(0).Origin, Path.GetSegment(1).Origin }); //Trace.TraceInformation("Upper left = {0}", path.ToString()); LayoutSite layoutSite = LayoutSites[0]; layoutSite.UpdatePath(pathUpperLeft, scale); } // Lower right triangle. // { IPath pathLowerRight = PathGeometries.Triangle.CreatePath(new PathPoint[] { Path.GetSegment(1).Origin, Path.GetSegment(2).Origin, Path.GetSegment(3).Origin }); //Trace.TraceInformation("Lower right = {0}", path.ToString()); LayoutSite layoutSite = LayoutSites[1]; layoutSite.UpdatePath(pathLowerRight, scale); } }
public Image CreateBitmap(Design design, int size, bool enableTexture) { if (design.LayoutComponent == null) { return(s_blankImage); } var designSize = design.GetStandardSizes().Where(r => r.Preferred).Single(); // Determine scale that will resize design to the specified maximum pixel dimension. // var maxDimension = designSize.Width > designSize.Height ? designSize.Width : designSize.Height; var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size - 1, DimensionUnits.Pixel); // Rescale design. // var pageLayoutNode = new PageLayoutNode(designSize.Width * scale, designSize.Height * scale); pageLayoutNode.LayoutSites[0].Node = design.LayoutComponent.Expand(true); pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); var image = CreateBitmap(pageLayoutNode, size, enableTexture); return(image); }
private static XDesign_DesignPreview XDesign_DesignPreview(Design.Core.Design design, int size) { if (design == null) { throw new ArgumentNullException(nameof(design)); } var result = new XDesign_DesignPreview(); if (design.LayoutComponent != null) { var designSize = design.GetStandardSizes().Where(r => r.Preferred).Single(); var maxDimension = designSize.Width > designSize.Height ? designSize.Width : designSize.Height; var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size, DimensionUnits.Pixel); var pageLayoutNode = new PageLayoutNode(designSize.Width * scale, designSize.Height * scale); pageLayoutNode.LayoutSites[0].Node = design.LayoutComponent.Expand(true); pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); //result.layoutSites = CreateLayoutSiteDataArray(pageLayoutNode.LayoutSites, Palettes.Rainbow); result.shapes = XDesign_Shapes(pageLayoutNode); } return(result); }
public override void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale) { base.UpdatePath(path, pathOrientation, scale); if (path.GetBounds().Empty) { return; } //Trace.TraceInformation("GridLayout::ResizeChildren"); var columnRatio = 1.0 / ColumnCount; //Trace.TraceInformation("columnRatio = {0}", columnRatio); var rowRatio = 1.0 / RowCount; //Trace.TraceInformation("rowRatio = {0}", rowRatio); for (var column = 0; column < ColumnCount; ++column) { for (var row = 0; row < RowCount; ++row) { var columnSpan = GetColumnSpan(row, column); var rowSpan = GetRowSpan(row, column); var top1 = Path.Interpolate(0, column * columnRatio); var top2 = Path.Interpolate(0, (column + columnSpan) * columnRatio); var bottom1 = Path.Interpolate(2, 1.0 - (column * columnRatio)); var bottom2 = Path.Interpolate(2, 1.0 - ((column + columnSpan) * columnRatio)); var right1 = Path.Interpolate(1, row * rowRatio); var right2 = Path.Interpolate(1, (row + rowSpan) * rowRatio); var left1 = Path.Interpolate(3, 1.0 - (row * rowRatio)); var left2 = Path.Interpolate(3, 1.0 - ((row + rowSpan) * rowRatio)); var p1 = Geometry.Intersection(top1, bottom1, right1, left1); var p2 = Geometry.Intersection(top2, bottom2, right1, left1); var p3 = Geometry.Intersection(top2, bottom2, right2, left2); var p4 = Geometry.Intersection(top1, bottom1, right2, left2); if (p1.IsInvalid || p2.IsInvalid || p3.IsInvalid || p4.IsInvalid) { throw new InvalidOperationException(); } else { var pathCell = PathGeometries.Rectangle.CreatePath( new PathPoint[] { p1, p2, p3, p4 }); //Trace.TraceInformation("Layout {0},{1} = {2}", row, column, path.ToString()); var layoutSite = GetLayoutSite(row, column); layoutSite.UpdatePath(pathCell, scale); } } } }
public override void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale) { base.UpdatePath(path, pathOrientation, scale); LayoutSite layoutSite = LayoutSites[0]; layoutSite.UpdatePath(Path, scale); }
private void UpdateNodeBounds(DimensionScale scale) { var node = Node; if (node != null) { node.UpdatePath(Path, PathOrientation, scale); } }
public Image CreateBitmap(Pattern pattern, int width, int height, DimensionScale scale) { var image = new Bitmap(width + 1, height + 1); using (Graphics graphics = Graphics.FromImage(image)) { Render(graphics, pattern, width, height, scale); } return(image); }
public override Image CreateImage(DimensionScale scale) { if (m_node == null) { return(null); } var renderer = new DesignRenderer(); return(renderer.CreateBitmap(m_node, scale, false)); }
public virtual void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale) { if (path != null) { Path.Copy(path, pathOrientation); m_visible = true; } else { m_visible = false; } }
public override void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale) { base.UpdatePath(path, pathOrientation, scale); //Trace.TraceInformation("FlyingGooseLayout::ResizeChildren"); PathPoint topMidpoint = Path.Interpolate(0, 0.5); PathPoint bottomMidpoint = Path.Interpolate(2, 0.5); // Upper left triangle { IPath pathUpperLeft = PathGeometries.Triangle.CreatePath(new PathPoint[] { Path.GetSegment(3).Origin, Path.GetSegment(0).Origin, topMidpoint }); //Trace.TraceInformation("Upper left = {0}", path.ToString()); LayoutSite layoutSite = LayoutSites[0]; layoutSite.UpdatePath(pathUpperLeft, scale); } // Upper right triangle. // { IPath pathUpperRight = PathGeometries.Triangle.CreatePath(new PathPoint[] { topMidpoint, Path.GetSegment(1).Origin, Path.GetSegment(2).Origin }); //Trace.TraceInformation("Upper right = {0}", path.ToString()); LayoutSite layoutSite = LayoutSites[1]; layoutSite.UpdatePath(pathUpperRight, scale); } // Lower left triangle { IPath pathLowerLeft = PathGeometries.Triangle.CreatePath(new PathPoint[] { topMidpoint, bottomMidpoint, Path.GetSegment(3).Origin }); //Trace.TraceInformation("Lower left = {0}", path.ToString()); LayoutSite layoutSite = LayoutSites[2]; layoutSite.UpdatePath(pathLowerLeft, scale); } // Lower right triangle. // { IPath pathLowerRight = PathGeometries.Triangle.CreatePath(new PathPoint[] { Path.GetSegment(2).Origin, bottomMidpoint, topMidpoint }); //Trace.TraceInformation("Lower right= {0}", path.ToString()); LayoutSite layoutSite = LayoutSites[3]; layoutSite.UpdatePath(pathLowerRight, scale); } }
public BuildComponentFlyingGoose(string id, FabricStyle fabricStyleBody, FabricStyle fabricStyleCorner, Area area, bool trim) : base(id) { if (fabricStyleBody == null) { throw new ArgumentNullException(nameof(fabricStyleBody)); } if (fabricStyleCorner == null) { throw new ArgumentNullException(nameof(fabricStyleCorner)); } if (area == null) { throw new ArgumentNullException(nameof(area)); } if (area.Width < area.Height) { area = new Area(area.Height, area.Width); } m_area = area; m_fabricStyles = new FabricStyle[] { fabricStyleBody, fabricStyleCorner }; m_trim = trim; m_styleKey = CreateStyleKey(fabricStyleBody, fabricStyleCorner, area); var halfSquareTriangleNode1 = new HalfSquareTriangleLayoutNode(); halfSquareTriangleNode1.LayoutSites[0].Node = new TriangleShapeNode(fabricStyleCorner); halfSquareTriangleNode1.LayoutSites[1].Node = new TriangleShapeNode(fabricStyleBody); var halfSquareTriangleNode2 = new HalfSquareTriangleLayoutNode(); halfSquareTriangleNode2.LayoutSites[0].Node = new TriangleShapeNode(fabricStyleCorner); halfSquareTriangleNode2.LayoutSites[1].Node = new TriangleShapeNode(fabricStyleBody); var gridLayoutNode = new GridLayoutNode(1, 2); gridLayoutNode.GetLayoutSite(0, 0).Node = halfSquareTriangleNode1; gridLayoutNode.GetLayoutSite(0, 1).Node = halfSquareTriangleNode2; gridLayoutNode.GetLayoutSite(0, 1).PathOrientation.PointOffset = 3; var scale = DimensionScale.CreateIdentity(area.Width.Unit); gridLayoutNode.UpdatePath(PathGeometries.Rectangle.CreatePath(area.Width, area.Height), PathOrientation.CreateDefault(), scale); m_gridLayoutNode = gridLayoutNode; }
public void UpdateBounds(PathOrientation pathOrientation, DimensionScale scale) { var zero = new Dimension(0, m_width.Unit); var path = PathGeometries.Rectangle.CreatePath( new PathPoint[] { new PathPoint(zero, zero), new PathPoint(m_width, zero), new PathPoint(m_width, m_height), new PathPoint(zero, m_height) }); UpdatePath(path, pathOrientation, scale); }
public Image CreateBitmap(Pattern pattern, DimensionScale scale) { var width = (int)(pattern.FabricSize.Width * scale).Value; var height = (int)(pattern.FabricSize.Height * scale).Value; var image = new Bitmap(width + 1, height + 1); using (Graphics graphics = Graphics.FromImage(image)) { Render(graphics, pattern, width, height, scale); } return(image); }
public Image CreateBitmap(Node node, DimensionScale scale, bool enableTexture) { // Determine scale that will resize design to the specified maximum pixel dimension. // var nodeBounds = node.Path.GetBounds(); var nodeWidth = nodeBounds.MaximumX - nodeBounds.MinimumX; var nodeHeight = nodeBounds.MaximumY - nodeBounds.MinimumY; // Rescale design. // var pageLayoutNode = new PageLayoutNode(nodeWidth * scale, nodeHeight * scale); pageLayoutNode.LayoutSites[0].Node = node.Clone(); pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); var image = CreateBitmap(pageLayoutNode, 0, enableTexture); return(image); }
private void RenderKit(Graphics graphics, Kit kit, int size) { if (kit.Design.LayoutComponent != null) { var maxDimension = kit.KitSpecification.Width > kit.KitSpecification.Height ? kit.KitSpecification.Width : kit.KitSpecification.Height; var origin = new Point(); var scale = new DimensionScale(maxDimension.Value, maxDimension.Unit, size, DimensionUnits.Pixel); var pageLayoutNode = new PageLayoutNode(kit.KitSpecification.Width * scale, kit.KitSpecification.Height * scale); pageLayoutNode.LayoutSites[0].Node = kit.Expand(); pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); var shapeNodes = new List <ShapeNode>(); pageLayoutNode.AddShapeNodesTo(shapeNodes); foreach (var shapeNode in shapeNodes) { RenderShapeNode(graphics, shapeNode, origin); } } }
public async Task <byte[]> GetBlockThumbnailAsync(string blockId, int thumbnailSize) { using var log = BeginFunction(nameof(DesignMicroService), nameof(GetBlockThumbnailAsync), blockId, thumbnailSize); try { await Task.CompletedTask; var provider = new DatabaseBlockComponentProvider(QuiltContextFactory); var entry = provider.GetComponent(BlockComponent.TypeName, Constants.DefaultComponentCategory, blockId); var node = entry.Component.Expand(true); var blockDimension = new Dimension(1, DimensionUnits.Inch); var thumbnailDimension = new Dimension(thumbnailSize, DimensionUnits.Pixel); var scale = new DimensionScale(1, DimensionUnits.Inch, thumbnailSize, DimensionUnits.Pixel); var pageLayoutNode = new PageLayoutNode(blockDimension * scale, blockDimension * scale); pageLayoutNode.LayoutSites[0].Node = node; pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); var renderer = new DesignRenderer(); using var image = renderer.CreateBitmap(node, DimensionScale.CreateIdentity(DimensionUnits.Pixel), false); using var ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); var result = ms.ToArray(); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
private static MKit_KitBuildItem MKit_KitBuildItem(KitBuildItem item, DimensionScale scale) { var name = item.BuildItemType == BuildComponentTypes.Yardage || item.BuildItemType == BuildComponentTypes.Piece || item.BuildItemType == BuildComponentTypes.Component ? item.BuildItemSubtype : item.BuildItemType == BuildComponentTypes.Block ? item.BuildItemSubtype == "Quilt Layout" ? "Quilt Top" : "Block" : item.BuildItemType == BuildComponentTypes.Quilt ? "Quilt" : "?"; var itemData = new MKit_KitBuildItem() { Id = item.Id, Name = name, Quantity = item.Quantity, Width = item.Area.Width.ToString(), Height = item.Area.Height.ToString(), PartId = item.PartId, Image = MKit_KitBuildItemImage(item, scale) }; if (item.FabricStyles.Count >= 1) { itemData.Sku1 = item.FabricStyles[0].Sku; itemData.WebColor1 = item.FabricStyles[0].Color.WebColor; } if (item.FabricStyles.Count >= 2) { itemData.Sku2 = item.FabricStyles[1].Sku; itemData.WebColor2 = item.FabricStyles[1].Color.WebColor; } return(itemData); }
public override Image CreateImage(DimensionScale scale) { var renderer = new PatternRenderer(); return(renderer.CreateBitmap(m_pattern, scale)); }
public override void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale) { base.UpdatePath(path, pathOrientation, scale); var scaledWidth = (m_width * scale).Value; // Outer points // var p1 = path.Offset(0, scaledWidth); var p2 = path.Offset(0, -scaledWidth); var p3 = path.Offset(1, scaledWidth); var p4 = path.Offset(1, -scaledWidth); var p5 = path.Offset(2, scaledWidth); var p6 = path.Offset(2, -scaledWidth); var p7 = path.Offset(3, scaledWidth); var p8 = path.Offset(3, -scaledWidth); // Inner points // var q1 = new PathPoint(p1.X, p3.Y); var q2 = new PathPoint(p2.X, p3.Y); var q3 = new PathPoint(p5.X, p4.Y); var q4 = new PathPoint(p6.X, p4.Y); // Resize layout site. // var pathInner = PathGeometries.Rectangle.CreatePath( new PathPoint[] { q1, q2, q3, q4 }); LayoutSites[0].UpdatePath(pathInner, scale); // Recompute border shapes. // var borderTop = PathGeometries.Rectangle.CreatePath( new PathPoint[] { path.GetSegment(0).Origin, path.GetSegment(1).Origin, p3, p8 }); var borderRight = PathGeometries.Rectangle.CreatePath( new PathPoint[] { p3, p4, q3, q2 }); var borderBottom = PathGeometries.Rectangle.CreatePath( new PathPoint[] { path.GetSegment(2).Origin, path.GetSegment(3).Origin, p7, p4 }); var borderLeft = PathGeometries.Rectangle.CreatePath( new PathPoint[] { p7, p8, q1, q4 }); var borderPaths = new List <IPath>(); var maxBorderPieceLength = new Dimension(20, DimensionUnits.Inch) * scale; borderPaths.AddRange(SplitPath(borderTop, maxBorderPieceLength)); borderPaths.AddRange(SplitPath(borderRight, maxBorderPieceLength)); borderPaths.AddRange(SplitPath(borderBottom, maxBorderPieceLength)); borderPaths.AddRange(SplitPath(borderLeft, maxBorderPieceLength)); m_borderShapes.Clear(); foreach (var borderPath in borderPaths) { var shape = new RectangleShapeNode(m_fabricStyle); shape.UpdatePath(borderPath, pathOrientation, scale); m_borderShapes.Add(shape); } }
public abstract Image CreateImage(DimensionScale scale);
public void UpdatePath(IPath path, DimensionScale scale) { Path.Copy(path); UpdateNodeBounds(scale); }
private void Render(Graphics graphics, Pattern pattern, int width, int height, DimensionScale scale) { graphics.FillRectangle(Brushes.LightGray, 0, 0, width, height); graphics.DrawRectangle(Pens.Black, 0, 0, width, height); using var stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; foreach (var region in pattern.PatternElements) { var sourceX = (int)(region.Source.X * scale).Value; var sourceY = (int)(region.Source.Y * scale).Value; var targetX = (int)(region.Target.X * scale).Value; var targetY = (int)(region.Target.Y * scale).Value; var regionWidth = targetX - sourceX; var regionHeight = targetY - sourceY; graphics.FillRectangle(Brushes.White, sourceX, sourceY, regionWidth, regionHeight); graphics.DrawRectangle(Pens.Black, sourceX, sourceY, regionWidth, regionHeight); graphics.DrawString(region.Id, SystemFonts.DefaultFont, Brushes.Black, new RectangleF(sourceX, sourceY, regionWidth, regionHeight), stringFormat); } }