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); }
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_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); }
private static List <XPolygon> FromPolyTree(PolyNode results, PathOrientation subjectOrientation, double scaleBy = 1000) { List <XPolygon> polygons = new List <XPolygon>(); foreach (PolyNode child in results.Childs) { PathOrientation orientation = Clipper.Orientation(child.Contour) == true ? PathOrientation.Anticlockwise : PathOrientation.Clockwise; XPolygon polygon = FromPath(child.Contour, scaleBy); polygons.Add(polygon); foreach (PolyNode childNode in child.Childs) { //polygon.InnerPaths.Add(FromPath(childNode.Contour, scaleBy)); //List<SimplePolygon> childPolygons = FromPolyTree(childNode, subjectOrientation, scaleBy); //polygons.AddRange(childPolygons); } if (orientation != subjectOrientation) { polygon.Reverse(); } //polygon.MakeLines(); } return(polygons); }
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); }
protected TransformedPath(TransformedPath prototype) { if (prototype == null) { throw new ArgumentNullException(nameof(prototype)); } m_path = prototype.m_path.Clone(); m_pathOrientation = prototype.m_pathOrientation.Clone(); }
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 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); }
protected LayoutSite(LayoutNode parent, LayoutSite prototype) { if (prototype == null) { throw new ArgumentNullException(nameof(prototype)); } m_parent = parent ?? throw new ArgumentNullException(nameof(parent)); m_path = prototype.m_path.Clone(); m_style = prototype.m_style; m_pathOrientation = prototype.m_pathOrientation.Clone(); m_node = prototype.m_node?.Clone(); }
public BuildComponentQuilt(string id, KitSpecification kitSpecification, Core.Design design) : base(id) { m_kitSpecification = kitSpecification ?? throw new ArgumentNullException(nameof(kitSpecification)); m_design = design ?? throw new ArgumentNullException(nameof(design)); m_styleKey = GetType().Name + StyleKeyDelimiter + Guid.NewGuid().ToString(); m_pageLayoutNode = new PageLayoutNode( kitSpecification.Width + (kitSpecification.BorderWidth * 2), kitSpecification.Height + (kitSpecification.BorderWidth * 2)); m_pageLayoutNode.LayoutSites[0].Node = kitSpecification.Expand(design); m_pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), new DimensionScale(1, DimensionUnits.Inch, 1, DimensionUnits.Inch)); }
public LayoutSite(LayoutNode parent, IPathGeometry pathGeometry) { if (pathGeometry == null) { throw new ArgumentNullException(nameof(pathGeometry)); } m_parent = parent ?? throw new ArgumentNullException(nameof(parent)); m_path = pathGeometry.Prototype.Clone(); m_style = null; m_pathOrientation = PathOrientation.CreateDefault(); m_node = null; }
public static List <XPolygon> Clip(ClipType clipType, List <XPolygon> subjects, List <XPolygon> clips, double scaleBy = 1000) { List <XPolygon> results = new List <XPolygon>(); Paths subjPaths = ToPaths(subjects, scaleBy); Paths clipPaths = ToPaths(clips, scaleBy); Clipper clipper = new Clipper(); clipper.AddPaths(clipPaths, PolyType.ptSubject, closed: true); clipper.AddPaths(subjPaths, PolyType.ptClip, closed: true); PolyTree result = new PolyTree(); clipper.Execute(clipType, result, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd); PathOrientation orientation = Clipper.Orientation(subjPaths.First()) == true ? PathOrientation.Anticlockwise : PathOrientation.Clockwise; return(FromPolyTree(result, orientation, scaleBy)); }
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); }
public LayoutSite(LayoutNode parent, JToken json) { if (json == null) { throw new ArgumentNullException(nameof(json)); } m_parent = parent ?? throw new ArgumentNullException(nameof(parent)); m_path = PathFactory.Create(json[JsonNames.Bounds]); m_style = (string)json[JsonNames.Style]; m_pathOrientation = new PathOrientation(json[JsonNames.PathOrientation]); var jsonNode = json[JsonNames.Node]; if (jsonNode != null) { m_node = NodeFactory.Singleton.Create(jsonNode); } }
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; } }
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; }
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 RotateRight() { PathOrientation.RotateRight(Path.SegmentCount); }
public void Flip() { PathOrientation.Flip(); }
public TransformedPath(IPath path, PathOrientation pathOrientation) { m_path = path ?? throw new ArgumentNullException(nameof(path)); m_pathOrientation = pathOrientation ?? throw new ArgumentNullException(nameof(pathOrientation)); }
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 void Copy(IPath fromPath, PathOrientation pathOrientation) { throw new NotImplementedException(); }