Example #1
0
 public RoutePlanner(PathShape path, Map map, PathFinder pathFinder)
 {
     this.path       = path;
     nav             = HardwareAPI.Navigation.i;
     this.map        = map;
     this.pathFinder = pathFinder;
 }
        /// <inheritdoc/>
        public override void Draw(object dc, PathShape path, double dx, double dy, object db, object r)
        {
            var _gfx = dc as XGraphics;

            var gp = path.Geometry.ToXGraphicsPath(dx, dy, _scaleToPage);

            if (path.IsFilled && path.IsStroked)
            {
                _gfx.DrawPath(
                    ToXPen(path.Style, _scaleToPage, _sourceDpi, _targetDpi),
                    ToXSolidBrush(path.Style.Fill),
                    gp);
            }
            else if (path.IsFilled && !path.IsStroked)
            {
                _gfx.DrawPath(
                    ToXSolidBrush(path.Style.Fill),
                    gp);
            }
            else if (!path.IsFilled && path.IsStroked)
            {
                _gfx.DrawPath(
                    ToXPen(path.Style, _scaleToPage, _sourceDpi, _targetDpi),
                    gp);
            }
        }
Example #3
0
        private void StartInternal(IToolContext context, double x, double y, Modifier modifier)
        {
            Filters?.Any(f => f.Process(context, ref x, ref y));

            _path = new PathShape()
            {
                FillRule = Settings.FillRule,
                Style    = context.CurrentStyle
            };

            _figure = new FigureShape()
            {
                IsFilled = Settings.IsFilled,
                IsClosed = Settings.IsClosed
            };

            _path.Figures.Add(_figure);

            _previousPoint = new PointShape(x, y, context.PointShape);

            context.WorkingContainer.Shapes.Add(_path);

            context.Capture?.Invoke();
            context.Invalidate?.Invoke();

            CurrentState = State.Points;
        }
Example #4
0
 /// <summary>
 /// Initialize new instance of <see cref="ToolPathSelection"/> class.
 /// </summary>
 /// <param name="layer">The selection shapes layer.</param>
 /// <param name="shape">The selected shape.</param>
 /// <param name="style">The selection shapes style.</param>
 /// <param name="point">The selection point shape.</param>
 public ToolPathSelection(LayerContainer layer, PathShape shape, ShapeStyle style, BaseShape point)
 {
     _layer = layer;
     _path  = shape;
     _style = style;
     _point = point;
 }
Example #5
0
        public PathShape GetPathShape()
        {
            PathShape path = new PathShape();

            path.path = pathFinder.getPath();
            return(path);
        }
Example #6
0
    void Start()
    {
        AddToGrid();

        childSingle = Instantiate(pathData.single, transform);
        children.Add(childSingle);
        childDeadend = Instantiate(pathData.deadend, transform);
        children.Add(childDeadend);
        childCorner = Instantiate(pathData.corner, transform);
        children.Add(childCorner);
        childStraight = Instantiate(pathData.straight, transform);
        children.Add(childStraight);
        childSplit = Instantiate(pathData.split, transform);
        children.Add(childSplit);
        childCross = Instantiate(pathData.cross, transform);
        children.Add(childCross);
        childCornerFill = Instantiate(pathData.cornerFill, transform);
        children.Add(childCornerFill);
        childSideFill = Instantiate(pathData.sideFill, transform);
        children.Add(childSideFill);
        childCenterFill = Instantiate(pathData.centerFill, transform);
        children.Add(childCenterFill);

        myShape = PathShape.CenterFill;
        SetPathShape(PathShape.Single, 0);
        FindNeighbours();
    }
Example #7
0
 public void Draw(object dc, ShapeRenderer renderer, PathShape path, ISelection selection, double dx, double dy)
 {
     foreach (var figure in path.Figures)
     {
         DrawFigure(dc, renderer, figure, selection, dx, dy);
     }
 }
            /// <summary>
            /// Updates resources data from <see cref="VectorPath"/> instance.
            /// </summary>
            /// <param name="pathResource">The path resource.</param>
            /// <param name="vogkResource">The vector origination data resource.</param>
            /// <param name="socoResource">The solid color resource.</param>
            /// <param name="vectorPath">The vector path.</param>
            /// <param name="imageSize">The image size to correct converting point coordinates.</param>
            private static void UpdateResources(VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource socoResource, VectorPath vectorPath, Size imageSize)
            {
                pathResource.Version     = vectorPath.Version;
                pathResource.IsNotLinked = vectorPath.IsNotLinked;
                pathResource.IsDisabled  = vectorPath.IsDisabled;
                pathResource.IsInverted  = vectorPath.IsInverted;

                List <VectorShapeOriginSettings> originSettings = new List <VectorShapeOriginSettings>();
                List <VectorPathRecord>          path           = new List <VectorPathRecord>();

                path.Add(new PathFillRuleRecord(null));
                path.Add(new InitialFillRuleRecord(vectorPath.IsFillStartsWithAllPixels));
                for (ushort i = 0; i < vectorPath.Shapes.Count; i++)
                {
                    PathShape shape = vectorPath.Shapes[i];
                    shape.ShapeIndex = i;
                    path.AddRange(shape.ToVectorPathRecords(imageSize));
                    originSettings.Add(new VectorShapeOriginSettings()
                    {
                        IsShapeInvalidated = true, OriginIndex = i
                    });
                }

                pathResource.Paths = path.ToArray();
                vogkResource.ShapeOriginSettings = originSettings.ToArray();

                socoResource.Color = vectorPath.FillColor;
            }
        public PointD V; // Vector for directional effect

        #endregion Fields

        #region Constructors

        public ToolParameter(PathShape shape)
        {
            C = 0.75;
            FilterEnabled = true;
            FilterVisible = true;
            InUse = false;
            Shape = shape;
        }
Example #10
0
        /// <summary>
        /// Returns a geoJson map into a heat map.
        /// </summary>
        /// <param name="geoJson">The geoJson.</param>
        /// <param name="values">The values.</param>
        /// <param name="heatMap">The heat map.</param>
        /// <param name="heatStops">The heat stops.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="fill">The fill.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="projector">The projector.</param>
        /// <returns></returns>
        public static IEnumerable<PathShape> AsHeatMapShapes(
            this GeoJsonFile geoJson,
            Dictionary<string, double> values,
            LvcColor[] heatMap, List<Tuple<double, LvcColor>> heatStops,
            LvcColor stroke,
            LvcColor fill,
            float thickness,
            MapProjector projector)
        {
            var paths = new List<PathShape>();

            var weightBounds = new Bounds();
            foreach (var value in values)
            {
                weightBounds.AppendValue(value.Value);
            }

            var d = new double[0][][][];

            foreach (var feature in geoJson.Features ?? new GeoJsonFeature[0])
            {
                var name = feature.Properties is not null ? feature.Properties["shortName"] : "";
                LvcColor? baseColor = values.TryGetValue(name, out var weight)
                    ? HeatFunctions.InterpolateColor((float)weight, weightBounds, heatMap, heatStops)
                    : null;

                foreach (var geometry in feature.Geometry?.Coordinates ?? d)
                {
                    foreach (var segment in geometry)
                    {
                        var path = new PathShape
                        {
                            StrokeColor = stroke,
                            FillColor = baseColor ?? fill,
                            StrokeThickness = thickness,
                            IsClosed = true
                        };
                        var isFirst = true;
                        foreach (var point in segment)
                        {
                            var p = projector.ToMap(point);

                            if (isFirst)
                            {
                                isFirst = false;
                                path.AddCommand(new MoveToPathCommand { X = p[0], Y = p[1] });
                                continue;
                            }

                            path.AddCommand(new LineSegment { X = p[0], Y = p[1] });
                        }
                        paths.Add(path);
                    }
                }
            }

            return paths;
        }
Example #11
0
        private void PointsInternal(IToolContext context, double x, double y, Modifier modifier)
        {
            CurrentState = State.Start;

            if (Settings?.Simplify ?? true)
            {
                List <PointShape> points  = _path.GetPoints().Distinct().ToList();
                List <Vector2>    vectors = points.Select(p => new Vector2((float)p.X, (float)p.Y)).ToList();
                int      count            = vectors.Count;
                RDP      rdp      = new RDP();
                BitArray accepted = rdp.DouglasPeucker(vectors, 0, count - 1, Settings?.Epsilon ?? 1.0);
                int      removed  = 0;
                for (int i = 0; i <= count - 1; ++i)
                {
                    if (!accepted[i])
                    {
                        points.RemoveAt(i - removed);
                        ++removed;
                    }
                }

                _figure.Shapes.Clear();
                _figure.MarkAsDirty(true);

                if (points.Count >= 2)
                {
                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        var line = new LineShape()
                        {
                            StartPoint = points[i],
                            Point      = points[i + 1],
                            Style      = context.CurrentStyle
                        };
                        _figure.Shapes.Add(line);
                    }
                }
            }

            context.WorkingContainer.Shapes.Remove(_path);

            if (_path.Validate(true) == true)
            {
                context.CurrentContainer.Shapes.Add(_path);
            }

            _path          = null;
            _figure        = null;
            _previousPoint = null;
            _nextPoint     = null;

            Filters?.ForEach(f => f.Clear(context));

            context.Release?.Invoke();
            context.Invalidate?.Invoke();
        }
Example #12
0
        public void DrawPath(object dc, PathShape path, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SkiaHelper.ToSKPathFillType(path.FillType)
            };

            SkiaHelper.AddPath(null, path, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(path, styleId, dx, dy, scale, geometry));
        }
Example #13
0
        /// <inheritdoc/>
        public override void Draw(object dc, PathShape path, double dx, double dy, object db, object r)
        {
            if (path.Geometry == null)
            {
                return;
            }

            var _dc = dc as DrawingContext;

            var style = path.Style;

            if (style == null)
            {
                return;
            }

            double thickness = style.Thickness / _state.ZoomX;
            double half      = thickness / 2.0;

            Tuple <Brush, Pen> styleCached = _styleCache.Get(style);
            Brush fill;
            Pen   stroke;

            if (styleCached != null)
            {
                fill   = styleCached.Item1;
                stroke = styleCached.Item2;
            }
            else
            {
                fill   = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                _styleCache.Set(style, Tuple.Create(fill, stroke));
            }

            Tuple <Path.PathGeometry, StreamGeometry, ShapeStyle> pcache = _pathCache.Get(path);
            StreamGeometry sg;

            if (pcache != null &&
                pcache.Item1 == path.Geometry &&
                pcache.Item3 == style)
            {
                sg = pcache.Item2;
                _dc.DrawGeometry(path.IsFilled ? fill : null, path.IsStroked ? stroke : null, sg);
            }
            else
            {
                sg = path.Geometry.ToStreamGeometry(dx, dy);

                // TODO: Enable PathShape caching, cache is disabled to enable PathHelper to work.
                //_pathCache.Set(path, Tuple.Create(path.Geometry, sg, style));

                _dc.DrawGeometry(path.IsFilled ? fill : null, path.IsStroked ? stroke : null, sg);
            }
        }
    private Vector3[] TranslateShape(Vector3 point, Vector3 forward, PathShape shape)
    {
        Vector3[]  translatedShape = new Vector3[shape.shape.Length];
        Quaternion forwardRotation = Quaternion.LookRotation(forward);

        for (int i = 0; i < shape.shape.Length; i++)
        {
            translatedShape[i] = (forwardRotation * shape.shape[i]) + point;
        }
        return(translatedShape);
    }
Example #15
0
        public void Create(IToolContext context)
        {
            _path = new PathShape()
            {
                FillRule = Settings.FillRule,
                Style    = context.CurrentStyle
            };

            context.WorkingContainer.Shapes.Add(_path);
            context.Renderer.Selected.Add(_path);
        }
        /// <inheritdoc/>
        public override void Draw(object dc, PathShape path, double dx, double dy, object db, object r)
        {
            var canvas = dc as SKCanvas;

            using (SKPaint brush = ToSKPaintBrush(path.Style.Fill))
                using (SKPaint pen = ToSKPaintPen(path.Style, _scaleToPage, _sourceDpi, _targetDpi))
                    using (var spath = path.Geometry.ToSKPath(dx, dy, _scaleToPage))
                    {
                        DrawPathInternal(canvas, brush, pen, path.IsStroked, path.IsFilled, spath);
                    }
        }
Example #17
0
        internal static void AddPath(IToolContext context, PathShape path, double dx, double dy, SKPath geometry)
        {
            geometry.FillType = ToSKPathFillType(path.FillType);

            foreach (var shape in path.Shapes)
            {
                if (shape is FigureShape figure)
                {
                    AddFigure(context, figure, dx, dy, geometry);
                }
            }
        }
Example #18
0
        public void Draw(object dc, IShapeRenderer renderer, PathShape path, ISelectionState selectionState, double dx, double dy, double scale)
        {
            if (selectionState.IsSelected(path))
            {
                DrawBoxFromPoints(dc, renderer, path, dx, dy, scale);
            }

            foreach (var shape in path.Shapes)
            {
                shape.Decorator?.Draw(dc, shape, renderer, selectionState, dx, dy, scale);
            }
        }
Example #19
0
        /// <inheritdoc/>
        PathShape IShapeFactory.Path(PathGeometry geometry, bool isStroked, bool isFilled)
        {
            var style = _editor.Project.CurrentStyleLibrary.Selected;
            var path  = PathShape.Create(
                "",
                _editor.Project.Options.CloneStyle ? style.Clone() : style,
                geometry,
                isStroked,
                isFilled);

            _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, path);
            return(path);
        }
Example #20
0
    private Vector3[] TranslateShape(Vector3 point, Vector3 forward, PathShape shape)
    {
        var translatedShape = new Vector3[pathShape.shape.Length];

        // create rotation using forward
        var forwardRotation = Quaternion.LookRotation(forward);

        for (var i = 0; i < pathShape.shape.Length; i++)
        {
            translatedShape[i] = (forwardRotation * pathShape.shape[i]) + point;
        }

        return(translatedShape);
    }
Example #21
0
    public void SetPathShape(PathShape newShape, float rot)
    {
        if (myShape != newShape)
        {
            for (int i = 0; i < children.Count; i++)
            {
                children[i].SetActive(false);
            }

            if (newShape == PathShape.Single)
            {
                children[0].SetActive(true); children[0].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.Deadend)
            {
                children[1].SetActive(true); children[1].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.Corner)
            {
                children[2].SetActive(true); children[2].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.Straight)
            {
                children[3].SetActive(true); children[3].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.Split)
            {
                children[4].SetActive(true); children[4].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.Cross)
            {
                children[5].SetActive(true); children[5].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.CornerFill)
            {
                children[6].SetActive(true); children[6].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.SideFill)
            {
                children[7].SetActive(true); children[7].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            if (newShape == PathShape.CenterFill)
            {
                children[8].SetActive(true); children[8].transform.rotation = Quaternion.Euler(new Vector3(0, rot, 0));
            }
            myShape = newShape;
        }
    }
Example #22
0
        /// <inheritdoc/>
        public override void Draw(object dc, PathShape path, double dx, double dy, object db, object r)
        {
            if (!path.IsStroked && !path.IsFilled)
            {
                return;
            }

            var dxf   = dc as DxfDocument;
            var style = path.Style;

            CreateHatchBoundsAndEntitiess(path.Geometry, dx, dy, out IList <HatchBoundaryPath> bounds, out ICollection <EntityObject> entities);
            if (entities == null || bounds == null)
            {
                return;
            }

            if (path.IsFilled)
            {
                var fill             = ToColor(style.Fill);
                var fillTransparency = ToTransparency(style.Fill);

                var hatch = new Hatch(HatchPattern.Solid, bounds, false);
                hatch.Layer = _currentLayer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                dxf.AddEntity(hatch);
            }

            if (path.IsStroked)
            {
                // TODO: Add support for Closed paths.

                var stroke            = ToColor(style.Stroke);
                var strokeTansparency = ToTransparency(style.Stroke);
                var lineweight        = ToLineweight(style.Thickness);

                foreach (var entity in entities)
                {
                    entity.Layer = _currentLayer;
                    entity.Color = stroke;
                    entity.Transparency.Value = strokeTansparency;
                    entity.Lineweight         = lineweight;
                    dxf.AddEntity(entity);
                }
            }
        }
Example #23
0
        private void CleanInternal(IToolContext context)
        {
            CurrentState = State.Start;

            Filters?.ForEach(f => f.Clear(context));

            if (_path != null)
            {
                context.WorkingContainer.Shapes.Remove(_path);
                _path          = null;
                _figure        = null;
                _previousPoint = null;
                _nextPoint     = null;
            }

            context.Release?.Invoke();
            context.Invalidate?.Invoke();
        }
Example #24
0
        /// <inheritdoc/>
        public override void Draw(object dc, PathShape path, double dx, double dy, object db, object r)
        {
            if (!path.IsFilled && !path.IsStroked)
            {
                return;
            }

            var _dc = dc as AM.DrawingContext;

            var g = path.Geometry.ToGeometry(dx, dy);

            var brush = ToBrush(path.Style.Fill);
            var pen   = ToPen(path.Style, _scaleToPage);

            _dc.DrawGeometry(
                path.IsFilled ? brush : null,
                path.IsStroked ? pen : null,
                g);
        }
        public void TestRestoreLinks()
        {
            // load a different scene for this test
            TestManager.Helpers.OpenSceneFromFile(Path.Combine(TestManager.Helpers.TestDataDir, @"EntityShapeTest\RestoreLink.scene"));

            EntityShape entity = EditorManager.Scene.FindShapeByName("Entity") as EntityShape;

            Assert.IsNotNull(entity);

            // the map has an anim entity which is attached to a path
            Assert.AreEqual(entity.EntityClass, "AnimEntity_cl");
            Assert.AreEqual(entity.LinkSources.Count, 1);
            Assert.AreEqual(entity.LinkTargets.Count, 0);
            Assert.AreEqual(entity.LinkBidirections.Count, 0);

            // verify the link is there
            LinkSource linkSrc = (LinkSource)entity.LinkSources[0];

            Assert.AreEqual(linkSrc.Links.Count, 1);
            LinkTarget linkTgt   = (LinkTarget)linkSrc.Links[0];
            PathShape  pathShape = linkTgt.OwnerShape as PathShape;

            Assert.IsNotNull(pathShape);
            Assert.AreEqual(pathShape.LinkTargets.Count, 1);
            Assert.AreEqual(pathShape.LinkTargets[0].Links.Count, 1);

            // setting a new entity class removes the link
            IAction myAction = SetPropertyAction.CreateSetPropertyAction(entity, "EntityClass", "VisBaseEntity_cl");

            myAction.Do();
            Assert.AreEqual(entity.LinkSources.Count, 0);
            Assert.AreEqual(pathShape.LinkTargets.Count, 1);
            Assert.AreEqual(pathShape.LinkTargets[0].Links.Count, 0); // not conected to entity anymore

            // now the link should be restored again
            myAction.Undo();
            Assert.AreEqual(entity.LinkSources.Count, 1);
            Assert.AreEqual(entity.LinkSources[0].Links.Count, 1);
            Assert.AreEqual(entity.LinkSources[0].Links[0].OwnerShape, pathShape);
            Assert.AreEqual(pathShape.LinkTargets.Count, 1);
            Assert.AreEqual(pathShape.LinkTargets[0].Links.Count, 1);
        }
        //ExStart:ClassesToManipulateVectorPathObjects
        //ExSummary:The following code example provides classes to manipulate the vector path objects and demonstrates how to use those classes.

        private static void CreatingVectorPathExample(string outputPsd = "outputPsd.psd")
        {
            using (var psdImage = (PsdImage)Image.Create(new PsdOptions()
            {
                Source = new StreamSource(new MemoryStream()),
            }, 500, 500))
            {
                FillLayer layer = FillLayer.CreateInstance(FillType.Color);
                psdImage.AddLayer(layer);

                VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(layer);
                vectorPath.FillColor = Color.IndianRed;
                PathShape shape = new PathShape();
                shape.Points.Add(new BezierKnot(new PointF(50, 150), true));
                shape.Points.Add(new BezierKnot(new PointF(100, 200), true));
                shape.Points.Add(new BezierKnot(new PointF(0, 200), true));
                vectorPath.Shapes.Add(shape);
                VectorDataProvider.UpdateLayerFromVectorPath(layer, vectorPath, true);

                psdImage.Save(outputPsd);
            }
        }
Example #27
0
        private void CreatePathNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            PathShape shape = new PathShape();

            shape.Points = new ShapePoint[] {
                new ShapePoint(new PointF(0, 20), PathPointType.Start),
                new ShapePoint(new PointF(50, 0), PathPointType.Line),
                new ShapePoint(new PointF(0, -20), PathPointType.Line),
                new ShapePoint(new PointF(100, 0), PathPointType.Line),
                new ShapePoint(new PointF(0, 20), PathPointType.CloseSubpath | PathPointType.Line)
            };

            SolidBrushObject brush = new SolidBrushObject(Color.Red);

            shape.Appearance.ContentBrush = brush;

            shape.Name = "pathNeedle";
            needleShape.Add(shape);
        }
Example #28
0
        /// <inheritdoc/>
        public override void Draw(object dc, PathShape path, double dx, double dy, object db, object r)
        {
            var _gfx = dc as Graphics;

            var gp = path.Geometry.ToGraphicsPath(dx, dy, _scaleToPage);

            if (path.IsFilled && path.IsStroked)
            {
                var brush = ToSolidBrush(path.Style.Fill);
                var pen   = ToPen(path.Style, _scaleToPage);
                _gfx.FillPath(
                    brush,
                    gp);
                _gfx.DrawPath(
                    pen,
                    gp);
                brush.Dispose();
                pen.Dispose();
            }
            else if (path.IsFilled && !path.IsStroked)
            {
                var brush = ToSolidBrush(path.Style.Fill);
                _gfx.FillPath(
                    brush,
                    gp);
                brush.Dispose();
            }
            else if (!path.IsFilled && path.IsStroked)
            {
                var pen = ToPen(path.Style, _scaleToPage);
                _gfx.DrawPath(
                    pen,
                    gp);
                pen.Dispose();
            }
        }
Example #29
0
        private void CleanInternal(IToolContext context)
        {
            CleanCurrentTool(context);

            Filters?.ForEach(f => f.Clear(context));

            if (_path != null)
            {
                context.WorkingContainer.Shapes.Remove(_path);
                context.Renderer.Selected.Remove(_path);

                if (_path.Validate(true) == true)
                {
                    context.CurrentContainer.Shapes.Add(_path);
                }

                Settings.PreviousTool = null;
                SetNextPoint(null);
                SetContext(null);

                _path   = null;
                _figure = null;
            }
        }
 public RegionToolParameter(PathShape shape)
     : base(shape)
 {
 }
 public AspectRatioToolParameter(PathShape shape)
     : base(shape)
 {
 }
		private static void DistressMethod2()
		{
			VectorDesign design = VectorDesign.Load(@"DistressDesign.PV", VectorDesignFileTypes.Pv);
			design.Render(@"DistressDesign-Method2-Original.PNG", RenderFormats.Png, 300, design.ColourContext);

			// Distress method #2 is similar to method #1, 
			// however, in this case:
			// 1. Create a distress pattern. This must be a vector design.
			//    It is simply white "random" objects on a transparent background.
			// 2. Combine the distress objects with a bounding rectangle to "invert" them from
			//    a bunch of filled objects, to a bunch of holes in a rectangle.
			// 3. Use the new distress object as a clipping mask over the design.
			//    Some scaling of the distress pattern may be necessary to make it look good.
			// 4. Rendering the merged design.
			//
			// Unlike method #1, this method will work when rendering onto a transparent background.
			
			var designBounds = design.GetBounds();

			
			VectorDesign distress = VectorDesign.Load(@"DistressPattern.PV", VectorDesignFileTypes.Pv);
			var distressBounds = distress.GetBounds();

			// Create a new rectangle shape into which we'll add the distress shapes as "holes".
			Path rectangle = new Path();
			rectangle.Triples.Add(new PathTriple(distressBounds.TopLeft));
			rectangle.Triples.Add(new PathTriple(distressBounds.TopRight));
			rectangle.Triples.Add(new PathTriple(distressBounds.BottomRight));
			rectangle.Triples.Add(new PathTriple(distressBounds.BottomLeft));
			rectangle.IsClosed = true;

			var distressShape = new PathShape();
			distressShape.AddPath(rectangle);

			// Take all the objects from the distress design
			// and copy them to our PathShape instead.
			var distressFirstPage = distress.Pages.First();
			var distressFirstLayer = distressFirstPage.Layers.First();

			foreach (var shapeObject in distress.ShapeObjects)
			{
				PathShape pathShape = shapeObject.Shape as PathShape;
				if (pathShape != null)
				{
					distressShape.AddPaths(pathShape.Paths);
				}
			}

			// At this point, distressShape should be a rectangle with a bunch of "holes" in it.

			// Move the distress so it's center is at the same location as the design's center
			var translate = Matrix3x2.Translate(designBounds.Center.X - distressBounds.Center.X, designBounds.Center.Y - distressBounds.Center.Y);
			distressShape.ApplyTransform(translate);

			// Depending on the distress, you may need to scale it.
			// Calculate an appropriate scaling factor based on your use case.
			//var scale = Matrix3x2.Scale(...);
			//distressShape.ApplyTransform(scale);

			// This will be our clipping mask
			ShapeObject distressObject = new ShapeObject();
			distressObject.Shape = distressShape;
			//distressObject.Fill = new SolidFill(new RGBColour(0, 0, 0));

			// Create a new design to act as our resulting "distressed" design
			VectorDesign result = new VectorDesign();
			result.ColourContext = design.ColourContext;
			design.ResourceManager.CopyContentsTo(result.ResourceManager);
			var resultPage = result.NewPage();
			var resultLayer = resultPage.NewLayer();

			// Copy all items from the source design to our new group object
			GroupObject newGroup = new GroupObject();

			design.ProcessObjects(obj => 
				{
					newGroup.AddObject(obj);
					return obj;
				});

			// Add the clipping mask to the group as our clipping mask
			newGroup.AddObject(distressObject);
			newGroup.IsClipped = true;
			
			resultLayer.AddObject(newGroup);
			

			// Render on a white background
			result.Render(@"DistressDesign-Method2-Final.PNG", RenderFormats.Png, 300, design.ColourContext);
		}
Example #33
0
        public static Shape AddToList(SVG svg, List <Shape> list, XmlNode childnode, Shape parent)
        {
            if (childnode.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            Shape retVal = null;

            if (childnode.Name == SVGTags.sStyle)
            {
                var match = _regexStyle.Match(childnode.InnerText);
                while (match.Success)
                {
                    var name  = match.Groups[1].Value.Trim();
                    var value = match.Groups[2].Value;
                    svg.m_styles.Add(name, new List <XmlAttribute>());
                    foreach (ShapeUtil.Attribute styleitem in XmlUtil.SplitStyle(svg, value))
                    {
                        svg.m_styles[name].Add(new XmlUtil.StyleItem(childnode, styleitem.Name, styleitem.Value));
                    }
                    match = match.NextMatch();
                }
            }
            else if (childnode.Name == SVGTags.sShapeRect)
            {
                retVal = new RectangleShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sFilter)
            {
                retVal = new Filter(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sFeGaussianBlur)
            {
                retVal = new FilterFeGaussianBlur(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sShapeCircle)
            {
                retVal = new CircleShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapeEllipse)
            {
                retVal = new EllipseShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapeLine)
            {
                retVal = new LineShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapePolyline)
            {
                retVal = new PolylineShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapePolygon)
            {
                retVal = new PolygonShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapePath)
            {
                retVal = new PathShape(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sClipPath)
            {
                retVal = new Clip(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sShapeGroup || childnode.Name == SVGTags.sSwitch)
            {
                retVal = new Group(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sShapeUse)
            {
                retVal = new UseShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapeImage)
            {
                retVal = new ImageShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sAnimate)
            {
                retVal = new Animate(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sAnimateColor)
            {
                retVal = new AnimateColor(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sAnimateMotion)
            {
                retVal = new AnimateMotion(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sAnimateTransform)
            {
                retVal = new AnimateTransform(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sText)
            {
                retVal = new TextShape(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sLinearGradient)
            {
                svg.PaintServers.Create(childnode);
                return(null);
            }
            else if (childnode.Name == SVGTags.sRadialGradient)
            {
                svg.PaintServers.Create(childnode);
                return(null);
            }
            else if (childnode.Name == SVGTags.sDefinitions)
            {
                ReadDefs(svg, list, childnode);
                return(null);
            }

            if (retVal != null)
            {
                list.Add(retVal);
                if (retVal.Id.Length > 0)
                {
                    svg.AddShape(retVal.Id, retVal);
                }
            }

            return(retVal);
        }
		static void ClipObjectTo(GroupObject groupObject, Bounds boundingBox)
		{
			List<PathTriple> triples = new List<PathTriple>()
				{
					new PathTriple(boundingBox.TopLeft),
					new PathTriple(boundingBox.TopRight),
					new PathTriple(boundingBox.BottomRight),
					new PathTriple(boundingBox.BottomLeft)
				};
			PathShape clipPathShape = new PathShape();
			clipPathShape.AddPath(new Path(triples)
			{
				IsClosed = true
			});
			// clipPathShape is now a rectangle with coordinates matching our bounding box.

			// We turn that into a ShapeObject
			ShapeObject clipShape = new ShapeObject();
			clipShape.Shape = clipPathShape;

			// Add it to the group object and turn on clipping.
			groupObject.IsClipped = true;
			groupObject.AddObject(clipShape);
		}
Example #35
0
        public static Shape AddToList(SVG svg, List <Shape> list, XmlNode childnode, Shape parent)
        {
            if (childnode.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            Shape retVal = null;

            var nodeName = GetNodeName(childnode);

            if (nodeName == null)
            {
                return(null);
            }
            if (nodeName == SVGTags.sStyle)
            {
                StyleParser.ParseStyle(svg, childnode.InnerText);
            }
            else if (nodeName == SVGTags.sShapeRect)
            {
                retVal = new RectangleShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sFilter)
            {
                retVal = new Filter(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sFeGaussianBlur)
            {
                retVal = new FilterFeGaussianBlur(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sShapeCircle)
            {
                retVal = new CircleShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapeEllipse)
            {
                retVal = new EllipseShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapeLine)
            {
                retVal = new LineShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapePolyline)
            {
                retVal = new PolylineShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapePolygon)
            {
                retVal = new PolygonShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapePath)
            {
                retVal = new PathShape(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sClipPath)
            {
                retVal = new Clip(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sShapeGroup)
            {
                retVal = new Group(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sSwitch)
            {
                retVal = new Group(svg, childnode, parent)
                {
                    IsSwitch = true
                }
            }
            ;
            else if (nodeName == SVGTags.sShapeUse)
            {
                retVal = new UseShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapeImage)
            {
                retVal = new ImageShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sAnimate)
            {
                retVal = new Animate(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sAnimateColor)
            {
                retVal = new AnimateColor(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sAnimateMotion)
            {
                retVal = new AnimateMotion(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sAnimateTransform)
            {
                retVal = new AnimateTransform(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sText)
            {
                retVal = new TextShape(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sLinearGradient)
            {
                svg.PaintServers.Create(svg, childnode);
                return(null);
            }
            else if (nodeName == SVGTags.sRadialGradient)
            {
                svg.PaintServers.Create(svg, childnode);
                return(null);
            }
            else if (nodeName == SVGTags.sDefinitions)
            {
                ReadDefs(svg, list, childnode);
                return(null);
            }
            else if (nodeName == SVGTags.sSymbol)
            {
                retVal = new Group(svg, childnode, parent);
            }

            if (retVal != null)
            {
                list.Add(retVal);
                if (retVal.Id.Length > 0)
                {
                    svg.AddShape(retVal.Id, retVal);
                }
            }

            if (nodeName == SVGTags.sSymbol)
            {
                return(null);
            }

            return(retVal);
        }