public void Redraw(Transform toScreen)
        {
            _controlLines.Clear();

            _polyBezier.Points.Clear();

            _toScreen = toScreen;

            for (int i = 0; i < _controlLocateables.Count; i++)
            {
                int index = (int)Math.Ceiling(i / 2.0);

                var controlLine1 = new PathFigure()
                {
                    StartPoint = toScreen.Transform(_mainLocateables[index].Location)
                };

                controlLine1.Segments.Add(new LineSegment()
                {
                    Point = toScreen.Transform(_controlLocateables[i].Location)
                });

                _controlLines.Add(controlLine1);
            }

            for (int i = 1; i < _mainLocateables.Count; i++)
            {
                int index = 2 * i - 2;

                _polyBezier.Points.Add(toScreen.Transform(_controlLocateables[index].Location));
                _polyBezier.Points.Add(toScreen.Transform(_controlLocateables[index + 1].Location));
                _polyBezier.Points.Add(toScreen.Transform(_mainLocateables[i].Location));
            }

            PathFigure mainFigure = new PathFigure()
            {
                StartPoint = toScreen.Transform(_mainLocateables[0].Location)
            };

            mainFigure.Segments.Add(_polyBezier);

            PathGeometry mainGeometry = new PathGeometry(new List <PathFigure>()
            {
                mainFigure
            });

            this._mainPath = new Path()
            {
                Tag = "PolyBezier _mainPath temp Tag", Data = mainGeometry, Stroke = _stroke, StrokeThickness = 4, Opacity = .9, Cursor = Cursors.Hand
            };

            _mainPath.Tag = new LayerTag(0)
            {
                Layer = this, IsTiled = false, LayerType = LayerType.EditableItem
            };



            this._mainPath.MouseRightButtonDown += _mainPath_MouseRightButtonDown;

            _mainPath.MouseEnter += (sender, e) => { _mainPath.StrokeThickness = 6; };
            _mainPath.MouseLeave += (sender, e) => { _mainPath.StrokeThickness = 4; };

            PathFigureCollection controlFigureCollection = new PathFigureCollection(_controlLines);

            PathGeometry controlGeometry = new PathGeometry(controlFigureCollection);

            this._controlPath = new Path()
            {
                Data = controlGeometry, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 1
            };

            _controlPath.Tag = new LayerTag(0)
            {
                Layer = this, IsTiled = false, LayerType = LayerType.EditableItem
            };

            this._mainLayer = new SpecialPointLayer($"POLYBEZIER MAIN {Id}", _mainLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem)
            {
                AlwaysTop = true
            };

            this._controlLayer = new SpecialPointLayer($"POLYBEZIER CONTROL {Id}", _controlLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem)
            {
                AlwaysTop = true
            };


            this._mainPath.MouseLeftButtonDown += (sender, e) =>
            {
                this.IsControlsShown = !this.IsControlsShown;

                var newVisibility = this.IsControlsShown ? Visibility.Visible : Visibility.Collapsed;

                this.GetControlPath().Visibility = newVisibility;

                if (this.IsControlsShown)
                {
                    AddLayer(this.GetControlPointLayer());
                }
                else
                {
                    RemoveLayer(this.GetControlPointLayer());
                }
            };

            //if (IsDecorated)
            //{
            Decorate();
            //}
        }
Beispiel #2
0
 public void AddLayer(SpecialPointLayer layer)
 {
     this.RequestAddSpecialPointLayer?.Invoke(layer);
 }
        public void Initialize()
        {
            _mainLocateables.Clear();

            _controlLocateables.Clear();

            _controlLines.Clear();

            _polyBezier.Points.Clear();

            this._mainLocateables = mercatorPolyline.Select(i => AsLocateable(i, Colors.Green)).ToList();

            for (int i = 0; i < _mainLocateables.Count; i++)
            {
                _mainLocateables[i].OnPositionChanged += mainLocateable_OnPositionChanged;

                var locateable = _mainLocateables[i];

                _mainLocateables[i].Element.MouseRightButtonDown += (sender, e) =>
                {
                    mainElement_MouseRightButtonDown(locateable, e);
                };

                var point = mercatorPolyline[i];

                var control1 = AsLocateable(point, Colors.Gray);

                var controlLine1 = new PathFigure()
                {
                    StartPoint = _toScreen.Transform(_mainLocateables[i].Location)
                };

                controlLine1.Segments.Add(new LineSegment()
                {
                    Point = _toScreen.Transform(control1.Location)
                });

                control1.OnPositionChanged += controlLocateable_OnPositionChanged;

                this._controlLocateables.Add(control1);

                _controlLines.Add(controlLine1);

                if (i == 0 || i == _mainLocateables.Count - 1)
                {
                    continue;
                }

                var control2 = AsLocateable(point, Colors.Gray);

                var controlLine2 = new PathFigure()
                {
                    StartPoint = _toScreen.Transform(_mainLocateables[i].Location)
                };
                controlLine2.Segments.Add(new LineSegment()
                {
                    Point = _toScreen.Transform(control2.Location)
                });

                control2.OnPositionChanged += controlLocateable_OnPositionChanged;

                this._controlLocateables.Add(control2);

                _controlLines.Add(controlLine2);
            }

            for (int i = 1; i < _mainLocateables.Count; i++)
            {
                int index = 2 * i - 2;

                _polyBezier.Points.Add(_toScreen.Transform(_controlLocateables[index].Location));
                _polyBezier.Points.Add(_toScreen.Transform(_controlLocateables[index + 1].Location));
                _polyBezier.Points.Add(_toScreen.Transform(_mainLocateables[i].Location));
            }

            PathFigure mainFigure = new PathFigure()
            {
                StartPoint = _toScreen.Transform(_mainLocateables[0].Location)
            };

            mainFigure.Segments.Add(_polyBezier);

            PathGeometry mainGeometry = new PathGeometry(new List <PathFigure>()
            {
                mainFigure
            });

            this._mainPath = new Path()
            {
                Data = mainGeometry, Stroke = _stroke, StrokeThickness = 3, Opacity = .9
            };


            PathFigureCollection controlFigureCollection = new PathFigureCollection(_controlLines);

            PathGeometry controlGeometry = new PathGeometry(controlFigureCollection);

            this._controlPath = new Path()
            {
                Data = controlGeometry, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 1
            };

            this._mainLayer = new SpecialPointLayer("1", _mainLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem)
            {
                AlwaysTop = true
            };

            this._controlLayer = new SpecialPointLayer("2", _controlLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem)
            {
                AlwaysTop = true
            };
        }