Ejemplo n.º 1
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 2)
            {
                if ((values[0] is double) && (values[1] is LfPointViewModel))
                {
                    double              pos     = (double)values[0];
                    LfPointViewModel    vertex  = (LfPointViewModel)values[1];
                    IBoxPointsInterface boxVm   = vertex.PointsParent;
                    LfShapeViewModel    shapeVm = (LfShapeViewModel)vertex.PointsParent;

                    Point p;

                    if (parameter as string == "x")
                    {
                        p = new Point(pos, vertex.PosY);
                        Point rp = shapeVm.RotatedPointFromLocal(p);
                        return(rp.X);
                    }
                    else
                    {
                        p = new Point(vertex.PosX, pos);
                        Point rp = shapeVm.RotatedPointFromLocal(p);
                        return(rp.Y);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 2)
            {
                if ((values[0] is double) && (values[1] is LfPointViewModel))
                {
                    LfPointViewModel    origVertex = (LfPointViewModel)values[1];
                    IBoxPointsInterface boxVm      = origVertex.PointsParent;
                    LfShapeViewModel    shapeVm    = (LfShapeViewModel)origVertex.PointsParent;

                    int i = boxVm.PointVms.IndexOf(origVertex);

                    if (i == -1)
                    {
                        return(null);
                    }

                    LfPointViewModel vertex;

                    if (i > 0)
                    {
                        vertex = boxVm.PointVms[i - 1];
                    }
                    else
                    {
                        vertex = boxVm.PointVms[boxVm.PointVms.Count() - 1];
                    }

                    Point p  = new Point(vertex.PosX, vertex.PosY);
                    Point rp = shapeVm.RotatedPointFromLocal(p);

                    if (parameter as string == "x")
                    {
                        return(rp.X);
                    }
                    else
                    {
                        return(rp.Y);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Values should be: PosX, PosY, Angle and either a LfDragablePointViewModel
            // or a LfPointViewModel with its parent a IBoxPointsInterface.
            // Parameter is "x" or "y", returns rotated point x or y value, depending on parameter.
            // PosX and PosY is not really used, but they will force an update if they are
            // changed
            if (values.Count() == 4)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is double))
                {
                    Point  p     = new Point(0, 0);
                    double angle = (double)values[2];

                    if (values[3] is LfDragablePointViewModel)
                    {
                        LfDragablePointViewModel vertex;

                        LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[3];
                        LfPolygonViewModel       polygon    = origVertex.Parent;

                        // Resolve the previous point, it is index - 1
                        // except if index == 0, in which case it is
                        // count - 1
                        int i = polygon.PointVms.IndexOf(origVertex);

                        if (i == -1)
                        {
                            return(null);
                        }


                        if (i > 0)
                        {
                            vertex = polygon.PointVms[i - 1];
                        }
                        else
                        {
                            vertex = polygon.PointVms[polygon.PointVms.Count() - 1];
                        }

                        p = new Point(vertex.PosX, vertex.PosY);
                    }
                    else if (values[3] is LfPointViewModel)
                    {
                        LfPointViewModel vertex;

                        LfPointViewModel    origVertex = (LfPointViewModel)values[3];
                        IBoxPointsInterface boxVm      = origVertex.PointsParent;

                        int i = boxVm.PointVms.IndexOf(origVertex);

                        if (i == -1)
                        {
                            return(null);
                        }

                        if (i > 0)
                        {
                            vertex = boxVm.PointVms[i - 1];
                        }
                        else
                        {
                            vertex = boxVm.PointVms[boxVm.PointVms.Count() - 1];
                        }

                        p = new Point(vertex.PosX, vertex.PosY);
                    }
                    else
                    {
                        return(null);
                    }

                    Point rp = CoordinateTransformations.RotatedPointFromLocal(p, angle);

                    if (parameter as string == "x")
                    {
                        return(rp.X);
                    }
                    return(rp.Y);
                }
            }

            return(null);
        }