//内存处理
        private void PixelTool_Click(object sender, RoutedEventArgs e)
        {
            BitmapImage bitmapImage = originImage.Source as BitmapImage;

            MenuItem mi      = e.Source as MenuItem;
            string   commond = mi.Header.ToString();

            if (commond == "暗角")
            {
                //targetImage.Source = ToolClass.Vignetting(bitmapImage);
            }
            else if (commond == "亮度")
            {
                //targetImage.Source = ToolClass.Brightness(bitmapImage);
            }
            else if (commond == "去色")
            {
                targetImage.Source = RAMTool.Decolorize(bitmapImage);
            }
            else if (commond == "二值化")
            {
                //targetImage.Source = RAMTool.GTo2Bit(bitmapImage);
                targetImage.Source = PointTool.OtsuThreshold(bitmapImage);
            }
            else if (commond == "浮雕")
            {
                //targetImage.Source = ToolClass.Relief(bitmapImage);
            }
            else if (commond == "马赛克")
            {
                //targetImage.Source = ToolClass.Mosaic(bitmapImage);
            }
            else if (commond == "扩散")
            {
                //targetImage.Source = ToolClass.Biffusion(bitmapImage);
            }
        }
Beispiel #2
0
        //public bool PtReduce(double x_nLinePrecision, double x_nCirclePrecision, ref List<DataType.StaubliRobotData.St_JointRx> x_ListJoint, ref List<DataType.StaubliRobotData.St_PointRx> x_ListPoint, out List<int> x_ListIndex)
        //{
        //    x_ListIndex = null;
        //    ParseData ParseTool =new ParseData();
        //    bool l_bResult = false;
        //    List<int> l_ListIndex = new List<int>();
        //    List<DataType.StaubliRobotData.St_PointRx> l_ListPoint = new List<DataType.StaubliRobotData.St_PointRx>();
        //    List<DataType.StaubliRobotData.St_JointRx> l_ListJoint = new List<DataType.StaubliRobotData.St_JointRx>();
        //    int i = 0, j = 0, k = 0, l = 0, m = 0;

        //    if (x_ListPoint == null || x_ListJoint == null || x_ListPoint.Count != x_ListJoint.Count)
        //    {
        //        l_bResult = false;
        //    }
        //    else
        //    {
        //        do
        //        {
        //            l_bResult = true;
        //            do
        //            {
        //                i = m; j = m + 1; k = m + 2; l = m + 3;
        //                if (m <= x_ListPoint.Count - 4)
        //                {
        //                    l_bResult = PointTool.ThreeColline(x_ListPoint[i], x_ListPoint[j], x_ListPoint[k], x_nLinePrecision);
        //                    if (l_bResult == true) { m = m + 1; l_ListIndex.Add(j); }
        //                }
        //                else
        //                {
        //                    l_bResult = false;
        //                }
        //            }
        //            while (l_bResult == true);
        //            l_bResult = true;
        //            do
        //            {
        //                i = m; j = m + 1; k = m + 2; l = m + 3;
        //                if (m <= x_ListPoint.Count - 4)
        //                {
        //                    l_bResult = PointTool.IsOnCircle(x_ListPoint[i], x_ListPoint[j], x_ListPoint[k], x_ListPoint[l], x_nLinePrecision, x_nCirclePrecision);
        //                    if (l_bResult == true) { m = m + 1; l_ListIndex.Add(j); } else { m = m + 2; }
        //                }
        //                else
        //                {
        //                    l_bResult = false;
        //                }
        //            }
        //            while (l_bResult == true);
        //        }
        //        while (m <= x_ListPoint.Count - 4);


        //        for (int x = 0; x <= x_ListPoint.Count - 1; x++)
        //        {
        //            bool l_bSame = false;
        //            l_bSame = ParseTool.FindInt(x, l_ListIndex);
        //            if (l_bSame == false)
        //            {
        //                l_ListPoint.Add(x_ListPoint[x]);
        //                l_ListJoint.Add(x_ListJoint[x]);
        //            }
        //        }
        //        x_ListIndex = l_ListIndex;
        //        x_ListPoint = l_ListPoint;
        //        x_ListJoint = l_ListJoint;
        //        l_bResult = true;
        //    }

        //    return l_bResult;
        //}


        public bool PtReduce(double x_nLinePrecision, double x_nCirclePrecision, ref List <DataType.StaubliRobotData.St_JointRx> x_ListJoint, ref List <DataType.StaubliRobotData.St_PointRx> x_ListPoint, out List <int> x_ListIndex, out List <string> x_ListIdentifier)
        {
            x_ListIndex      = null;
            x_ListIdentifier = null;
            ParseData     ParseTool        = new ParseData();
            bool          l_bResult        = false;
            bool          l_bLine          = false;
            bool          l_bCircle        = false;
            List <int>    l_ListIndex      = new List <int>();
            List <string> l_ListIdentifier = new List <string>();

            List <DataType.StaubliRobotData.St_PointRx> l_ListPoint = new List <DataType.StaubliRobotData.St_PointRx>();
            List <DataType.StaubliRobotData.St_JointRx> l_ListJoint = new List <DataType.StaubliRobotData.St_JointRx>();
            int    n = 0, i = 1;
            int    l_nCount = x_ListPoint.Count;
            double l_nAngle = new double();
            double l_nLineDeviation = new double();
            double l_nCircleDeviation = new double();

            //double l_nRadius1 = new double();
            //double l_nRadius2 = new double();

            if (x_ListPoint == null || x_ListJoint == null || x_ListPoint.Count != x_ListJoint.Count)
            {
                l_bResult = false;
            }
            else
            {
                l_ListIndex.Add(n);
                l_ListIdentifier.Add("MOVEJ");
                i = 1;
                do
                {
                    i         = 1;
                    l_bLine   = false;
                    l_bCircle = false;
                    l_bLine   = PointTool.CKYThreeColline(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], x_nLinePrecision, ref l_nLineDeviation);
                    if (n + 2 + i <= l_nCount - 1)
                    {
                        l_bCircle = PointTool.CKYIsOnCircle(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], x_ListPoint[n + 2 + i], x_nLinePrecision, x_nCirclePrecision, ref l_nCircleDeviation);
                    }
                    if (l_bLine == true && l_bCircle == true)
                    {
                        if (l_nLineDeviation < l_nCircleDeviation)
                        {
                            l_bResult = true;
                        }
                        else
                        {
                            l_bResult = false;
                        }
                    }
                    else
                    {
                        l_bResult = PointTool.CKYThreeColline(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], x_nLinePrecision, ref l_nLineDeviation);
                    }
                    if (l_bResult == true)
                    {
                        if (n + 2 == l_nCount - 1)
                        {
                            l_ListIndex.Add(n + 2);
                            l_ListIdentifier.Add("MOVEJ");
                        }
                        else
                        {
                            do
                            {
                                l_bResult = PointTool.CKYThreeColline(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2 + i], x_nLinePrecision, ref l_nLineDeviation);
                                if (l_bResult == true)
                                {
                                    if (n + 2 + i == l_nCount - 1)
                                    {
                                        l_ListIndex.Add(n + 2 + i);
                                        l_ListIdentifier.Add("MOVEJ");
                                        break;
                                    }
                                    else
                                    {
                                        i = i + 1;
                                    }
                                }
                                else
                                {
                                    l_ListIndex.Add(n + 2 + i - 1);
                                    l_ListIdentifier.Add("MOVEJ");
                                    break;
                                }
                            }while (l_bResult == true && n + 2 + i <= l_nCount - 1);
                        }
                    }
                    else
                    {
                        if (n + 2 == l_nCount - 1)
                        {
                            l_bResult = BasicMathTool.VectAngle(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], ref l_nAngle);
                            if (l_nAngle <= 180 && l_bResult == true)
                            {
                                l_ListIndex.Add(n + 1);
                                l_ListIndex.Add(n + 2);
                                l_ListIdentifier.Add("MOVEC");
                                l_ListIdentifier.Add("MOVEC");
                                break;
                            }
                            else
                            {
                                l_ListIndex.Add(n + 1);
                                l_ListIndex.Add(n + 2);
                                l_ListIdentifier.Add("MOVEJ");
                                l_ListIdentifier.Add("MOVEJ");
                                break;
                            }
                        }
                        else
                        {
                            l_bResult = BasicMathTool.VectAngle(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], ref l_nAngle);
                            if (l_nAngle <= 178 && l_bResult == true)
                            {
                                do
                                {
                                    if (i == 1)
                                    {
                                        l_bResult = PointTool.CKYIsOnCircle(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], x_ListPoint[n + 2 + i], x_nLinePrecision, x_nCirclePrecision, ref l_nCircleDeviation);
                                    }
                                    else
                                    {
                                        l_bResult = PointTool.CKYIsOnCircle(x_ListPoint[n + 1], x_ListPoint[n + 2], x_ListPoint[n + 3], x_ListPoint[n + 2 + i], x_nLinePrecision, x_nCirclePrecision, ref l_nCircleDeviation);
                                    }

                                    if (l_bResult == true)
                                    {
                                        if (n + 2 + i == l_nCount - 1)
                                        {
                                            l_bResult = BasicMathTool.VectAngle(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], ref l_nAngle);
                                            if (l_nAngle <= 180 && l_bResult == true)
                                            {
                                                l_ListIndex.Add(n + 1 + i / 2);
                                                l_ListIndex.Add(n + 2 + i);
                                                l_ListIdentifier.Add("MOVEC");
                                                l_ListIdentifier.Add("MOVEC");
                                                break;
                                            }
                                            else
                                            {
                                                l_ListIndex.Add(n + 1);
                                                l_ListIndex.Add(n + 2);
                                                l_ListIndex.Add(n + 2 + i);
                                                l_ListIdentifier.Add("MOVEC");
                                                l_ListIdentifier.Add("MOVEC");
                                                l_ListIdentifier.Add("MOVEJ");
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            l_bResult = BasicMathTool.VectAngle(x_ListPoint[n], x_ListPoint[n + 1], x_ListPoint[n + 2], ref l_nAngle);
                                            if (l_nAngle <= 178 && l_bResult == true)
                                            {
                                                i = i + 1;
                                            }
                                            else
                                            {
                                                l_ListIndex.Add(n + 1 + i / 2);
                                                l_ListIndex.Add(n + 2 + i);
                                                l_ListIdentifier.Add("MOVEC");
                                                l_ListIdentifier.Add("MOVEC");
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        l_ListIndex.Add(n + 1 + i / 2);
                                        l_ListIndex.Add(n + 2 + i - 1);
                                        l_ListIdentifier.Add("MOVEC");
                                        l_ListIdentifier.Add("MOVEC");
                                        break;
                                    }
                                }while (l_bResult == true && n + 2 + i <= l_nCount - 1);
                            }
                            else
                            {
                                l_ListIndex.Add(n + 1);
                                l_ListIndex.Add(n + 2);
                                l_ListIdentifier.Add("MOVEJ");
                                l_ListIdentifier.Add("MOVEJ");
                            }
                        }
                    }
                    if (n + 2 + i == l_nCount - 1)
                    {
                        l_ListIndex.Add(n + 2 + i);
                        l_ListIdentifier.Add("MOVEJ");
                        break;
                    }
                    else
                    {
                        n = n + 2 + i - 1;
                    }
                }while (n + 2 <= l_nCount - 1);

                for (int j = 0; j <= l_ListIndex.Count - 1; j++)
                {
                    l_ListPoint.Add(x_ListPoint[l_ListIndex[j]]);
                    l_ListJoint.Add(x_ListJoint[l_ListIndex[j]]);
                }
                x_ListIndex      = l_ListIndex;
                x_ListIdentifier = l_ListIdentifier;
                x_ListJoint      = l_ListJoint;
                x_ListPoint      = l_ListPoint;
                l_bResult        = true;
            }
            return(l_bResult);
        }
        public IToolContext CreateToolContext()
        {
            var editorToolContext = new EditorToolContext()
            {
                ContainerFactory = this
            };

            var hitTest = new HitTest();

            var tools = new ObservableCollection <ITool>();

            var noneTool = new NoneTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = false,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    },
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = false,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    }
                },
                Settings = new NoneToolSettings()
            };

            var selectionTool = new SelectionTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = false,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new SelectionToolSettings()
                {
                    Mode                  = SelectionMode.Point | SelectionMode.Shape,
                    Targets               = SelectionTargets.Shapes,
                    SelectionModifier     = Modifier.Control,
                    ConnectionModifier    = Modifier.Shift,
                    SelectionStyle        = "Selection",
                    ClearSelectionOnClean = false,
                    HitTestRadius         = 7.0,
                    ConnectPoints         = true,
                    ConnectTestRadius     = 10.0,
                    DisconnectPoints      = true,
                    DisconnectTestRadius  = 10.0
                }
            };

            var pointTool = new PointTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new PointToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var lineTool = new LineTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>
                {
                    new LineLineIntersection()
                    {
                        Intersections = new ObservableCollection <IPointShape>(),
                        Settings      = new LineLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new RectangleLineIntersection()
                    {
                        Intersections = new ObservableCollection <IPointShape>(),
                        Settings      = new RectangleLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new EllipseLineIntersection()
                    {
                        Intersections = new ObservableCollection <IPointShape>(),
                        Settings      = new EllipseLineSettings()
                        {
                            IsEnabled = true
                        }
                    }
                },
                Filters = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new LineToolSettings()
                {
                    ConnectPoints      = true,
                    HitTestRadius      = 7.0,
                    SplitIntersections = false
                }
            };

            var polyLineTool = new PolyLineTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>
                {
                    new LineLineIntersection()
                    {
                        Intersections = new ObservableCollection <IPointShape>(),
                        Settings      = new LineLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new RectangleLineIntersection()
                    {
                        Intersections = new ObservableCollection <IPointShape>(),
                        Settings      = new RectangleLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new EllipseLineIntersection()
                    {
                        Intersections = new ObservableCollection <IPointShape>(),
                        Settings      = new EllipseLineSettings()
                        {
                            IsEnabled = true
                        }
                    }
                },
                Filters = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new PolyLineToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var cubicBezierTool = new CubicBezierTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new CubicBezierToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var quadraticBezierTool = new QuadraticBezierTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new QuadraticBezierToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var conicTool = new ConicTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new ConicToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0,
                    Weight        = 1.0
                }
            };

            var pathTool = new PathTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new PathToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0,
                    FillType      = PathFillType.Winding,
                    IsFilled      = true,
                    IsClosed      = true
                }
            };

            pathTool.Settings.Tools = new ObservableCollection <ITool>
            {
                new LineTool(),
                new CubicBezierTool(),
                new QuadraticBezierTool(),
                new ConicTool(),
                new MoveTool(pathTool)
            };
            pathTool.Settings.CurrentTool = pathTool.Settings.Tools[0];

            var scribbleTool = new ScribbleTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = false,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new ScribbleToolSettings()
                {
                    Simplify = true,
                    Epsilon  = 1.0,
                    FillType = PathFillType.Winding,
                    IsFilled = false,
                    IsClosed = false
                }
            };

            var rectangleTool = new RectangleTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new RectangleToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var ellipseTool = new EllipseTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new EllipseToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var textTool = new TextTool()
            {
                Intersections = new ObservableCollection <IPointIntersection>(),
                Filters       = new ObservableCollection <IPointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = "Guide"
                        }
                    },
                    new LineSnapPointFilter()
                    {
                        Guides   = new ObservableCollection <IBaseShape>(),
                        Settings = new LineSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Target       = LineSnapTarget.Shapes,
                            Mode         = LineSnapMode.Point
                                           | LineSnapMode.Middle
                                           | LineSnapMode.Nearest
                                           | LineSnapMode.Intersection
                                           | LineSnapMode.Horizontal
                                           | LineSnapMode.Vertical,
                            Threshold  = 10.0,
                            GuideStyle = "Guide"
                        }
                    }
                },
                Settings = new TextToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            void SetToolDefaults(ITool tool)
            {
                tool.CurrentIntersection = tool.Intersections.Count > 0 ? tool.Intersections[0] : null;
                tool.CurrentFilter       = tool.Filters.Count > 0 ? tool.Filters[0] : null;
            }

            SetToolDefaults(noneTool);
            SetToolDefaults(selectionTool);
            SetToolDefaults(pointTool);
            SetToolDefaults(lineTool);
            SetToolDefaults(polyLineTool);
            SetToolDefaults(cubicBezierTool);
            SetToolDefaults(quadraticBezierTool);
            SetToolDefaults(conicTool);
            SetToolDefaults(pathTool);
            SetToolDefaults(scribbleTool);
            SetToolDefaults(rectangleTool);
            SetToolDefaults(ellipseTool);
            SetToolDefaults(textTool);

            tools.Add(noneTool);
            tools.Add(selectionTool);
            tools.Add(pointTool);
            tools.Add(lineTool);
            tools.Add(polyLineTool);
            tools.Add(cubicBezierTool);
            tools.Add(quadraticBezierTool);
            tools.Add(conicTool);
            tools.Add(pathTool);
            tools.Add(scribbleTool);
            tools.Add(rectangleTool);
            tools.Add(ellipseTool);
            tools.Add(textTool);

            editorToolContext.Selection        = selectionTool;
            editorToolContext.HitTest          = hitTest;
            editorToolContext.CurrentDirectory = null;
            editorToolContext.Files            = new ObservableCollection <string>();

            editorToolContext.StyleLibrary = null;
            editorToolContext.GroupLibrary = null;

            var pointTemplate = new RectangleShape(new PointShape(-4, -4, null), new PointShape(4, 4, null))
            {
                Points  = new ObservableCollection <IPointShape>(),
                Text    = new Text(),
                StyleId = "PointTemplate"
            };

            pointTemplate.StartPoint.Owner = pointTemplate;
            pointTemplate.Point.Owner      = pointTemplate;

            editorToolContext.PointTemplate = pointTemplate;

            editorToolContext.ContainerViews = new ObservableCollection <IContainerView>();
            editorToolContext.ContainerView  = null;
            editorToolContext.Tools          = tools;
            editorToolContext.CurrentTool    = selectionTool;
            editorToolContext.EditMode       = EditMode.Mouse;

            return(editorToolContext);
        }
Beispiel #4
0
        public LayerContainerViewModel CreateDemoViewModel()
        {
            var hitTest = new HitTest();

            hitTest.Register(new PointHitTest());
            hitTest.Register(new LineHitTest());
            hitTest.Register(new CubicBezierHitTest());
            hitTest.Register(new QuadraticBezierHitTest());
            hitTest.Register(new GroupHitTest());
            hitTest.Register(new PathHitTest());
            hitTest.Register(new RectangleHitTest());
            hitTest.Register(new EllipseHitTest());
            hitTest.Register(new TextHitTest());

            var gridSnapPointFilter = new GridSnapPointFilter()
            {
                Settings = new GridSnapSettings()
                {
                    IsEnabled    = true,
                    EnableGuides = false,
                    Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                    GridSizeX    = 15.0,
                    GridSizeY    = 15.0,
                    GuideStyle   = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true)
                }
            };

            var lineSnapPointFilter = new LineSnapPointFilter()
            {
                Settings = new LineSnapSettings()
                {
                    IsEnabled    = true,
                    EnableGuides = false,
                    Target       = LineSnapTarget.Guides | LineSnapTarget.Shapes,
                    Mode         = LineSnapMode.Point
                                   | LineSnapMode.Middle
                                   | LineSnapMode.Nearest
                                   | LineSnapMode.Intersection
                                   | LineSnapMode.Horizontal
                                   | LineSnapMode.Vertical,
                    Threshold  = 10.0,
                    GuideStyle = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true)
                }
            };

            var tools = new ObservableCollection <ToolBase>();

            var noneTool = new NoneTool()
            {
                Settings = new NoneToolSettings()
            };

            var selectionTool = new SelectionTool()
            {
                Filters = new List <PointFilter>
                {
                    new GridSnapPointFilter()
                    {
                        Settings = new GridSnapSettings()
                        {
                            IsEnabled    = true,
                            EnableGuides = false,
                            Mode         = GridSnapMode.Horizontal | GridSnapMode.Vertical,
                            GridSizeX    = 15.0,
                            GridSizeY    = 15.0,
                            GuideStyle   = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true)
                        }
                    }
                },
                Settings = new SelectionToolSettings()
                {
                    Mode                  = SelectionMode.Point | SelectionMode.Shape,
                    Targets               = SelectionTargets.Shapes | SelectionTargets.Guides,
                    SelectionModifier     = Modifier.Control,
                    ConnectionModifier    = Modifier.Shift,
                    SelectionStyle        = new ShapeStyle(new ArgbColor(255, 0, 120, 215), new ArgbColor(60, 170, 204, 238), 2.0, true, true),
                    ClearSelectionOnClean = false,
                    HitTestRadius         = 7.0,
                    ConnectPoints         = true,
                    ConnectTestRadius     = 10.0,
                    DisconnectPoints      = true,
                    DisconnectTestRadius  = 10.0
                }
            };

            var guideTool = new GuideTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new GuideToolSettings()
                {
                    GuideStyle = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true)
                }
            };

            var pointTool = new PointTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new PointToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var lineTool = new LineTool()
            {
                Intersections = new List <PointIntersection>
                {
                    new LineLineIntersection()
                    {
                        Settings = new LineLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new RectangleLineIntersection()
                    {
                        Settings = new RectangleLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new EllipseLineIntersection()
                    {
                        Settings = new EllipseLineSettings()
                        {
                            IsEnabled = true
                        }
                    }
                },
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new LineToolSettings()
                {
                    ConnectPoints      = true,
                    HitTestRadius      = 7.0,
                    SplitIntersections = false
                }
            };

            var polyLineTool = new PolyLineTool()
            {
                Intersections = new List <PointIntersection>
                {
                    new LineLineIntersection()
                    {
                        Settings = new LineLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new RectangleLineIntersection()
                    {
                        Settings = new RectangleLineSettings()
                        {
                            IsEnabled = true
                        }
                    },
                    new EllipseLineIntersection()
                    {
                        Settings = new EllipseLineSettings()
                        {
                            IsEnabled = true
                        }
                    }
                },
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new PolyLineToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var cubicBezierTool = new CubicBezierTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new CubicBezierToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var quadraticBezierTool = new QuadraticBezierTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new QuadraticBezierToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var pathTool = new PathTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new PathToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0,
                    FillRule      = PathFillRule.EvenOdd,
                    IsFilled      = true,
                    IsClosed      = true
                }
            };

            pathTool.Settings.Tools = new ObservableCollection <ToolBase>
            {
                new LineTool(),
                new CubicBezierTool(),
                new QuadraticBezierTool(),
                new MoveTool(pathTool)
            };
            pathTool.Settings.CurrentTool = pathTool.Settings.Tools[0];

            var scribbleTool = new ScribbleTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter
                },
                Settings = new ScribbleToolSettings()
                {
                    Simplify = true,
                    Epsilon  = 1.0,
                    FillRule = PathFillRule.EvenOdd,
                    IsFilled = false,
                    IsClosed = false
                }
            };

            var rectangleTool = new RectangleTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new RectangleToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var ellipseTool = new EllipseTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new EllipseToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            var textTool = new TextTool()
            {
                Filters = new List <PointFilter>
                {
                    lineSnapPointFilter,
                    gridSnapPointFilter
                },
                Settings = new TextToolSettings()
                {
                    ConnectPoints = true,
                    HitTestRadius = 7.0
                }
            };

            tools.Add(noneTool);
            tools.Add(selectionTool);
            tools.Add(guideTool);
            tools.Add(pointTool);
            tools.Add(lineTool);
            tools.Add(polyLineTool);
            tools.Add(cubicBezierTool);
            tools.Add(quadraticBezierTool);
            tools.Add(pathTool);
            tools.Add(scribbleTool);
            tools.Add(rectangleTool);
            tools.Add(ellipseTool);
            tools.Add(textTool);

            var currentTool = tools.FirstOrDefault(t => t.Title == "Selection");

            var presenter = new DefaultShapePresenter()
            {
                Helpers = new Dictionary <Type, ShapeHelper>
                {
                    { typeof(PointShape), new PointHelper() },
                    { typeof(LineShape), new LineHelper() },
                    { typeof(CubicBezierShape), new CubicBezierHelper() },
                    { typeof(QuadraticBezierShape), new QuadraticBezierHelper() },
                    { typeof(PathShape), new PathHelper() },
                    { typeof(RectangleShape), new RectangleHelper() },
                    { typeof(EllipseShape), new EllipseHelper() },
                    { typeof(TextShape), new TextHelper() }
                }
            };

            return(new LayerContainerViewModel()
            {
                Tools = tools,
                CurrentTool = currentTool,
                Mode = EditMode.Mouse,
                Presenter = presenter,
                Renderer = null,
                HitTest = hitTest,
                CurrentContainer = null,
                WorkingContainer = null,
                CurrentStyle = null,
                PointShape = null,
                Capture = null,
                Release = null,
                Invalidate = null,
                Reset = null,
                AutoFit = null,
                StretchNone = null,
                StretchFill = null,
                StretchUniform = null,
                StretchUniformToFill = null
            });
        }