コード例 #1
0
ファイル: MilHats.cs プロジェクト: HillHouse/MilSym
        /// <summary>
        /// Generate the feint dummy rendering for the passed in symbol.
        /// </summary>
        /// <param name="ms">
        /// The military symbol for which to provide the feint dummy rendering.
        /// </param>
        /// <param name="height">
        /// The height at which to provide the feint dummy rendering.
        /// </param>
        /// <returns>
        /// The graphics Path object that represents the feint dummy rendering.
        /// </returns>
        private static Path GenerateFeintDummy(MilSymbol ms, ref double height)
        {
            if (!string.IsNullOrEmpty(Echelon.GetEchelonSymbol(ms.SymbolCode)))
            {
                height = ms.Bounds.Top;
            }

            if (SymbolData.IsTopFlat(ms.SymbolCode))
            {
                double minimum = ms.BaseRect.Top;
                if (height >= minimum)
                {
                    height = minimum - 28;
                }
            }

            double bottom = height + 23;

            height = height - 27;
            const double Wide = 126;

            var st = new Style(typeof(Shape))
            {
                BasedOn = SymbolData.GetStyle("BS10")
            };

            st.SetDashArray(3, 1);

            return(new Path
            {
                Style = st,
                Data = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        new PathFigure
                        {
                            StartPoint = new Point(-Wide, bottom),
                            Segments = new PathSegmentCollection
                            {
                                new LineSegment {
                                    Point = new Point(0.0, height)
                                },
                                new LineSegment {
                                    Point = new Point(Wide, bottom)
                                }
                            }
                        }
                    }
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// The main zone generating method.
        /// </summary>
        /// <param name="mg">
        /// The MilGraphic associated with the zone to be generated.
        /// </param>
        /// <param name="isClosed">
        /// Whether or not the zone outline is to be closed since this method can be used for polylines as well.
        /// </param>
        /// <param name="count">
        /// The count of the map locations making up the zone.
        /// </param>
        /// <param name="anchors">
        /// The map locations making up the zone.
        /// </param>
        /// <param name="pointAnchors">
        /// The locations in ResourceDictionary space.
        /// </param>
        /// <returns>
        /// A Path representing the map locations, to be associated with the MilGraphic.
        /// </returns>
        public static Path GenerateLines(
            MilGraphic mg,
            bool isClosed,        // do we close the boundary
            int count,            // the number of transformed points to use in boundary
            IList <ILocation> anchors,
            out IList <Point> pointAnchors)
        {
            IList <Point> pointCp1 = null;
            IList <Point> pointCp2 = null;

            pointAnchors = MapHelper.LatLonsToPixels(anchors, 2.0);

            // Need to convert the cardinal spline points into Bezier spline control points
            if (mg.IsSpline)
            {
                ClosedBezierSpline.GetCurveControlPoints(count, pointAnchors, out pointCp1, out pointCp2);
            }

            ScaleData(pointAnchors, pointCp1, pointCp2);

            // Generate Bezier or line segments for insertion into a figure collection
            PathFigureCollection figures;

            if (mg.IsSpline)
            {
                figures = new PathFigureCollection
                {
                    new PathFigure
                    {
                        Segments = GenerateBezierSegments(count, pointAnchors, pointCp1, pointCp2, isClosed)
                    }
                };
            }
            else
            {
                switch (mg.StencilType)
                {
                case "ObstacleZone":
                case "ObstacleBelt":
                    pointAnchors.Add(pointAnchors[0]);
                    figures = MilLine.GenerateDecoratedSegments(
                        mg, DecoratedType.Triangular, false, count + 1, pointAnchors);
                    pointAnchors.RemoveAt(count);
                    break;

                case "ObstacleRestrictedArea":
                case "ObstacleFreeArea":
                    pointAnchors.Add(pointAnchors[0]);
                    figures = MilLine.GenerateDecoratedSegments(
                        mg, DecoratedType.Triangular, true, count + 1, pointAnchors);
                    pointAnchors.RemoveAt(count);
                    break;

                case "Boundaries":
                    figures = MilLine.GenerateDecoratedSegments(mg, DecoratedType.Echelon, true, count, pointAnchors);
                    var labels      = new[] { mg.LabelT, Echelon.GetEchelonSymbol(mg.SymbolCode), mg.LabelT1 };
                    int figureCount = figures.Count;
                    for (int i = 0; i < figureCount - 1; i++)
                    {
                        var pls = figures[i].Segments[0] as PolyLineSegment;
                        if (pls == null)
                        {
                            continue;
                        }

                        var pc = pls.Points.Count - 1;
                        if (pc > 0)
                        {
                            mg.AddChild(
                                "Label" + i,
                                MilLine.GenerateLabels(
                                    mg, labels, pls.Points[pc], pls.Points[pc - 1], pointAnchors[0], new Point(1.0, 0.5)));
                        }
                    }

                    break;

                default:
                    figures = new PathFigureCollection
                    {
                        new PathFigure
                        {
                            Segments = GeneratePolygonSegments(count, pointAnchors)
                        }
                    };
                    break;
                }
            }

            // In most cases we have a single figure
            figures[0].StartPoint = pointAnchors[0];
            figures[0].IsClosed   = isClosed;

            var path = new Path
            {
                Data = new PathGeometry {
                    Figures = figures
                },
                Style = mg.ContentControl.UnframedLine
            };

            if (mg.StencilType == "ObstacleRestrictedArea")
            {
                path.Fill = HatchBrush(mg.ContentControl.Brush);
            }
#if WINDOWS_UWP
            path.SetBinding(Shape.StrokeThicknessProperty, new Binding()
            {
                Path = new PropertyPath("LineThickness"), Source = mg.ContentControl
            });
#else
            path.SetBinding(Shape.StrokeThicknessProperty, new Binding("LineThickness")
            {
                Source = mg.ContentControl
            });
#endif
            return(path);
        }