Exemplo n.º 1
0
        public void Shape_Transformation_Calculation_Should_Not_Be_Deferred_To_Arrange_When_Strech_Is_None()
        {
            var shape = new Polygon()
            {
                Points = new List <Point>
                {
                    new Point(0, 0),
                    new Point(10, 5),
                    new Point(0, 10)
                },
                Stretch = Stretch.None
            };

            var availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);

            shape.Measure(availableSize);
            Geometry  postMeasureGeometry  = shape.RenderedGeometry;
            Transform postMeasureTransform = postMeasureGeometry.Transform;

            var finalSize = new Size(100, 50);
            var finalRect = new Rect(finalSize);

            shape.Arrange(finalRect);

            Geometry  postArrangeGeometry  = shape.RenderedGeometry;
            Transform postArrangeTransform = postArrangeGeometry.Transform;

            Assert.Equal(postMeasureGeometry, postArrangeGeometry);
            Assert.Equal(postMeasureTransform, postArrangeTransform);
            Assert.Equal(finalSize, shape.Bounds.Size);
        }
Exemplo n.º 2
0
        public void UpdateCell()
        {
            var points = new PointCollection
            {
                new Point(MapEditorModelView.CellHalfWidth, 0),
                new Point(MapEditorModelView.CellWidth, MapEditorModelView.CellHalfHeight),
                new Point(MapEditorModelView.CellHalfWidth, MapEditorModelView.CellHeight),
                new Point(0, MapEditorModelView.CellHalfHeight)
            };

            var polygon = new Polygon
            {
                Points          = points,
                Stroke          = Brushes.Gray,
                StrokeThickness = 4,
                Fill            = m_cellBrush,
            };

            polygon.Measure(new System.Windows.Size((int)MapEditorModelView.CellWidth, (int)MapEditorModelView.CellHeight));
            polygon.Arrange(new Rect(new System.Windows.Size((int)MapEditorModelView.CellWidth, (int)MapEditorModelView.CellHeight)));

            var render = new RenderTargetBitmap((int)MapEditorModelView.CellWidth,
                                                (int)MapEditorModelView.CellHeight, 96, 96, PixelFormats.Pbgra32);

            render.Render(polygon);
            ImageSource = render;
        }
Exemplo n.º 3
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     _topTriangle.Arrange(new Rect(_position, finalSize));
     _bottomTriangle.Arrange(
         new Rect(new Point(_position.X, double.IsNaN(Height) ? finalSize.Height : _position.Y + Height + 2),
                  finalSize));
     return(finalSize);
 }
Exemplo n.º 4
0
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Point[] curvePoints =
        {
            new Point(10, 10),
            new Point(13, 11),
            new Point(15, 30),
            new Point(17, 10),
            new Point(20, 10),
            new Point(30, 15),
            new Point(30, 30),
            new Point(60, 40),
            new Point(65, 55),
            new Point(40, 60),
            new Point(40, 65),
            new Point(58, 70),
            new Point(60, 60),
            new Point(90, 60),
            new Point(90, 85),
            new Point(70, 61),
            new Point(60, 85),
            new Point(30, 85),
            new Point(12, 80),
            new Point(12, 78),
            new Point(16, 75),
            new Point(13, 68),
            new Point(17, 65),
            new Point(6,  62),
            new Point(16, 60),
            new Point(28, 56),
            new Point(27, 45),
            new Point(15, 32),
            new Point(15, 50),
            new Point(5,  50),
            new Point(10, 40)
        };
        var pointCollection = new PointCollection(curvePoints);
        var polygon         = new Polygon
        {
            Stroke          = Brushes.GreenYellow,
            StrokeThickness = 1,
            Fill            = Brushes.Blue,
            Points          = pointCollection
        };
        const int cx = 800;
        const int cy = 600;

        polygon.Measure(new Size(cx, cy));
        polygon.Arrange(new Rect(0, 0, cx, cy));
        RenderTargetBitmap bmp = new RenderTargetBitmap(cx, cy, 120, 96, PixelFormats.Pbgra32);

        bmp.Render(polygon);
        _image.Source = bmp;
    }
        /// <summary>
        /// Draw the rotation handle and the outline of
        /// the element.
        /// </summary>
        /// <param name="finalSize">The final area within the
        /// parent that this element should use to arrange
        /// itself and its children.</param>
        /// <returns>The actual size used. </returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (strokeBounds.IsEmpty)
            {
                return(finalSize);
            }

            arrow.Arrange(new Rect(finalSize));
            linkPath.Arrange(new Rect(finalSize));
            polygon.Arrange(new Rect(finalSize));
            return(finalSize);
        }
Exemplo n.º 6
0
        public static void DrawSiteZone()
        {
            Polygon site = new Polygon
            {
                Points          = StaticVariables.Coordinates_Site,
                Stroke          = Brushes.DarkOrange,
                StrokeThickness = 2
            };

            site.Arrange(new Rect(StaticVariables.win.uniformGrid.RenderSize));
            site.Measure(StaticVariables.win.uniformGrid.RenderSize);


            Polygon restrictionZone = new Polygon
            {
                Points          = StaticVariables.Coordinates_RestrictionZone,
                Stroke          = Brushes.Red,
                StrokeThickness = 2
            };

            restrictionZone.Arrange(new Rect(StaticVariables.win.uniformGrid.RenderSize));
            restrictionZone.Measure(StaticVariables.win.uniformGrid.RenderSize);


            CombinedGeometry geometry = new CombinedGeometry()
            {
                GeometryCombineMode = GeometryCombineMode.Exclude
            };

            geometry.Geometry1 = site.RenderedGeometry;
            geometry.Geometry2 = restrictionZone.RenderedGeometry;

            StaticVariables.win.path.Data = geometry;

            //**************************************************************
            //Works until here, below just effort to do something. All in all, I create initial shape geometry in which u could render geometries.

            //int length = int.Parse(StaticVariables.win.lengthTextBox.Text);
            //int width = int.Parse(StaticVariables.win.widthTextBox.Text);
            //int rowSpacing = int.Parse(StaticVariables.win.rowSpacingTextBox.Text);
            //int columnSpacing = int.Parse(StaticVariables.win.columnSpacingTextBox.Text);



            //var totalShapeArea = geometry.GetArea();
            //double adjustedWidth = length + columnSpacing;
            //double adjustedHeight = width + rowSpacing;
            //double solarPanelArea = (length + columnSpacing) * (width + rowSpacing);
            //var possiblePanelsNumber = Math.Round(totalShapeArea / solarPanelArea);


            //GeometryGroup myGeometryGroup = new GeometryGroup();
            //myGeometryGroup.Children.Add(geometry);



            //RectangleGeometry myRectGeometry = new RectangleGeometry();
            //myRectGeometry.Rect = new Rect(new Size(adjustedWidth, adjustedHeight));
            //myGeometryGroup.Children.Add(myRectGeometry);


            //StaticVariables.win.path.Data = myGeometryGroup;
            //StaticVariables.win.path.Stroke = Brushes.Blue;
        }
Exemplo n.º 7
0
        private Geometry ReadSvgNode(XElement node)
        {
            Geometry result = null;

            switch (node.Name.LocalName.ToLower())
            {
            case "svg":
            {
                double?newwidth;
                double?newheight;
                Rect?  newviewbox;

                newwidth   = GetDoubleAttribute(node.Attribute("width"));
                newheight  = GetDoubleAttribute(node.Attribute("height"));
                newviewbox = GetRectAttribute(node.Attribute("viewBox"));

                Clip                  = newviewbox.HasValue ? new RectangleGeometry(newviewbox.Value) : null;
                Width                 = newviewbox.HasValue ? newviewbox.Value.Right : newwidth.HasValue ? newwidth.Value : double.NaN;
                Height                = newviewbox.HasValue ? newviewbox.Value.Bottom : newheight.HasValue ? newheight.Value : double.NaN;
                ViewBox               = newviewbox.HasValue ? newviewbox.Value : Rect.Empty;
                ViewBoxWidth          = newviewbox.HasValue ? newviewbox.Value.Width : double.NaN;
                ViewBoxHeight         = newviewbox.HasValue ? newviewbox.Value.Height : double.NaN;
                translateTransform.X  = newviewbox.HasValue ? -newviewbox.Value.X : 0;
                translateTransform.Y  = newviewbox.HasValue ? -newviewbox.Value.Y : 0;
                scaleTransform.ScaleX = newviewbox.HasValue ? newviewbox.Value.Right / (double)newviewbox.Value.Width : 1;
                scaleTransform.ScaleY = newviewbox.HasValue ? newviewbox.Value.Bottom / (double)newviewbox.Value.Height : 1;

                GeometryGroup geometrygroup = new GeometryGroup()
                {
                    FillRule = FillRule.Nonzero
                };
                if (node.HasElements)
                {
                    foreach (XElement child in node.Elements())
                    {
                        var geometry = ReadSvgNode(child);
                        if (geometry != null)
                        {
                            geometrygroup.Children.Add(geometry);
                        }
                    }
                }
                result = geometrygroup;
                break;
            }

            case "g":
            {
                GeometryGroup geometrygroup = new GeometryGroup()
                {
                    FillRule = FillRule.Nonzero
                };
                if (node.HasElements)
                {
                    foreach (XElement child in node.Elements())
                    {
                        var geometry = ReadSvgNode(child);
                        if (geometry != null)
                        {
                            geometrygroup.Children.Add(geometry);
                        }
                    }
                }
                result = geometrygroup;
                break;
            }

            case "path":
            {
                foreach (var attr in node.Attributes())
                {
                    if (attr.Name.LocalName == "d" && !string.IsNullOrEmpty(attr.Value))
                    {
                        try
                        {
                            return(Geometry.Parse(attr.Value));
                        }
                        catch { }
                    }
                }
                break;
            }

            case "line":
            {
                double x1, y1, x2, y2;
                if (GetDoubleAttribute(node.Attribute("x1"), out x1) && GetDoubleAttribute(node.Attribute("y1"), out y1) && GetDoubleAttribute(node.Attribute("x2"), out x2) && GetDoubleAttribute(node.Attribute("y2"), out y2))
                {
                    result = new LineGeometry(new Point(x1, y2), new Point(x2, y2));
                }
                break;
            }

            case "rect":
            {
                double x, y, w, h;
                if (GetDoubleAttribute(node.Attribute("x"), out x) && GetDoubleAttribute(node.Attribute("y"), out y) && GetDoubleAttribute(node.Attribute("width"), out w) && GetDoubleAttribute(node.Attribute("height"), out h))
                {
                    result = new RectangleGeometry(new Rect(x, y, w, h));
                }
                break;
            }

            case "ellipse":
            {
                double cx, cy, rx, ry;
                if (GetDoubleAttribute(node.Attribute("cx"), out cx) && GetDoubleAttribute(node.Attribute("cy"), out cy) && GetDoubleAttribute(node.Attribute("rx"), out rx) && GetDoubleAttribute(node.Attribute("ry"), out ry))
                {
                    result = new EllipseGeometry(new Point(cx, cy), rx, ry);
                }
                break;
            }

            case "circle":
            {
                double cx, cy, r;
                if (GetDoubleAttribute(node.Attribute("cx"), out cx) && GetDoubleAttribute(node.Attribute("cy"), out cy) && GetDoubleAttribute(node.Attribute("r"), out r))
                {
                    result = new EllipseGeometry(new Point(cx, cy), r, r);
                }
                break;
            }

            case "polyline":
            {
                try
                {
                    Polyline   polyline = new Polyline();
                    XAttribute attr     = node.Attribute("points");
                    if (attr != null && !string.IsNullOrEmpty(attr.Value))
                    {
                        polyline.Points = PointCollection.Parse(attr.Value);
                        polyline.Measure(ViewBox.Size);
                        polyline.Arrange(ViewBox);
                        result = polyline.RenderedGeometry;
                    }
                }
                catch { }
                break;
            }

            case "polygon":
            {
                try
                {
                    Polygon    polygon = new Polygon();
                    XAttribute attr    = node.Attribute("points");
                    if (attr != null && !string.IsNullOrEmpty(attr.Value))
                    {
                        polygon.Points = PointCollection.Parse(attr.Value);
                        polygon.Measure(ViewBox.Size);
                        polygon.Arrange(ViewBox);
                        result = polygon.RenderedGeometry;
                    }
                }
                catch { }
                break;
            }
            }

            if (result != null)
            {
                result.Transform = GetTransformAttribute(node.Attribute("transform"));
            }

            return(result);
        }