public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[2];

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    double angle = TextureBorderHelperClass.GetAngle(origVertex, currP, prevP);
                    BorderTextureViewModel border = TextureBorderHelperClass.GetTextureViewModel(origVertex, angle);

                    string texture = border.Texture;

                    if ((texture == "") || (texture == "notDefined"))
                    {
                        return(null);
                    }

                    string s            = GlobalConstants.ImageDirectory + texture + ".png";
                    string fullPath     = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    string fullFileName = System.IO.Path.Combine(fullPath, s);

                    return(new BitmapImage(new Uri(fullFileName)));
                }
            }

            return(null);
        }
Пример #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 LfDragablePointViewModel))
                {
                    double pos = (double)values[0];
                    LfDragablePointViewModel vertex = (LfDragablePointViewModel)values[1];
                    LfShapeViewModel         shape  = vertex.Parent;

                    Point p;

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

            return(null);
        }
        public static BorderTextureViewModel GetTextureViewModel(LfDragablePointViewModel myPoint, double angle)
        {
            // Select view model accordingly to angle
            LfStaticPolygonViewModel polygon = (LfStaticPolygonViewModel)myPoint.Parent;

            double degAngle = angle;

            if ((degAngle <= polygon.RightGroundAngle) && (degAngle > polygon.LeftGroundAngle))
            {
                return(polygon.GroundBorder);
            }

            if ((degAngle > polygon.RightGroundAngle) && (degAngle < polygon.RightCeilingAngle))
            {
                return(polygon.RightWallBorder);
            }


            if ((degAngle < polygon.LeftGroundAngle) && (degAngle > polygon.LeftCeilingAngle))
            {
                return(polygon.LeftWallBorder);
            }

            return(polygon.CeilingBorder);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[2];

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    double angle = TextureBorderHelperClass.GetAngle(origVertex, currP, prevP);
                    BorderTextureViewModel border = TextureBorderHelperClass.GetTextureViewModel(origVertex, angle);
                    Vector offset = TextureBorderHelperClass.GetOffset(origVertex, currP, prevP, angle);

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

            return(null);
        }
        public static Point GetPreviousPoint(LfDragablePointViewModel myPoint)
        {
            LfStaticPolygonViewModel polygon = (LfStaticPolygonViewModel)myPoint.Parent;

            int i = polygon.PointVms.IndexOf(myPoint);

            if (i == -1)
            {
                return(new Point(0, 0));
            }

            LfDragablePointViewModel previousVertex;

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

            Point prevP = new Point(previousVertex.PosX, previousVertex.PosY);

            return(prevP);
        }
Пример #6
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[2];

                    double shapeAngle = 0;

                    if (origVertex.Parent is LfShapeViewModel)
                    {
                        LfShapeViewModel shape = origVertex.Parent as LfShapeViewModel;

                        shapeAngle = shape.Angle;
                    }

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    double angle = TextureBorderHelperClass.GetAngle(origVertex, currP, prevP);
                    return((angle - shapeAngle) / Math.PI * 180);
                }
            }

            return(null);
        }
        public static Vector GetOffset(LfDragablePointViewModel myPoint, Point origP, Point prevP, double angle)
        {
            Vector diffV                  = origP - prevP;
            double distance               = diffV.Length;
            Vector rotatedNormal          = new Vector(-Math.Sin(angle * Math.PI / 180), Math.Cos(angle * Math.PI / 180));
            BorderTextureViewModel border = TextureBorderHelperClass.GetTextureViewModel(myPoint, angle);
            Vector offset                 = -rotatedNormal * border.HorisontalOffset;

            return(offset);
        }
Пример #8
0
        public void RemovePoint(LfDragablePointViewModel point)
        {
            if (LocalModelObject == null)
            {
                return;
            }

            PointVms.Remove(point);
            LocalModelObject.RemovePoint(point.ModelObject);

            InvalidateAll();
            ParentVm.OnPropertyChanged("");
        }
        public LfDragablePointViewModel AddPoint(LfPolygonViewModel polyVm, Point position)
        {
            LfPolygonViewModel newPolygon = polyVm;
            Point parentObjectOrigo       = new Point(newPolygon.ParentVm.PosX, newPolygon.ParentVm.PosY);
            Point shapeOrigo = new Point(newPolygon.PosX, newPolygon.PosY);

            shapeOrigo.Offset(parentObjectOrigo.X, parentObjectOrigo.Y);
            Point localClickPoint = new Point();

            localClickPoint = (Point)(position - shapeOrigo);

            LfDragablePointViewModel newPoint = newPolygon.AddPoint(localClickPoint);

            return(newPoint);
        }
Пример #10
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is LfDragablePointViewModel)
            {
                LfDragablePointViewModel vertex = (LfDragablePointViewModel)value;
                LfShapeViewModel         shape  = vertex.Parent;

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

                return(rp.Y);
            }

            return(null);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[2];

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    Vector v     = (currP - prevP);
                    return(v.Length);
                }
            }

            return(null);
        }
        public static double GetAngle(LfDragablePointViewModel myPoint, Point origP, Point prevP)
        {
            LfStaticPolygonViewModel polygon = (LfStaticPolygonViewModel)myPoint.Parent;

            Vector diffV = origP - prevP;

            double angle = Math.Atan2(diffV.Y, diffV.X);

            angle += Math.PI;

            if (angle > Math.PI)
            {
                angle -= Math.PI * 2;
            }

            return(angle / Math.PI * 180);
        }
Пример #13
0
        public LfDragablePointViewModel AddPoint(Point point)
        {
            if (LocalModelObject == null)
            {
                return(null);
            }

            LfDragablePoint          np       = new LfDragablePoint(GetFreeVertexIndex(), point.X, point.Y);
            LfDragablePointViewModel newPoint = new LfDragablePointViewModel(this, ParentVm, MainVm, this, np);

            PointVms.Add(newPoint);
            LocalModelObject.AddPoint(newPoint.ModelObject);

            InvalidateAll();
            ParentVm.OnPropertyChanged("");

            return(newPoint);
        }
Пример #14
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is LfDragablePointViewModel) && (values[2] is TriangleViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[1];
                    LfPolygonViewModel       polygon    = origVertex.Parent;
                    TriangleViewModel        tvm        = (TriangleViewModel)values[2];

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

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

                    LfDragablePointViewModel vertex;

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

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

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

            return(null);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 4)
            {
                if ((values[0] is double) && (values[1] is double) &&
                    (values[2] is double) && (values[3] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[3];
                    double shapeAngle = (double)values[2];

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    double angle = TextureBorderHelperClass.GetAngle(origVertex, currP, prevP);
                    return(angle + shapeAngle);
                }
            }

            return(null);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[2];

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    double angle = TextureBorderHelperClass.GetAngle(origVertex, currP, prevP);
                    BorderTextureViewModel border = TextureBorderHelperClass.GetTextureViewModel(origVertex, angle);

                    Rect r = new Rect(0, 0, border.TextureWidth, border.TextureHeight);

                    return(r);
                }
            }

            return(null);
        }
Пример #17
0
        public LfDragablePointViewModel InsertPoint(Point insertMe, LfDragablePointViewModel insertBeforeMe)
        {
            if (LocalModelObject == null)
            {
                return(null);
            }

            LfDragablePoint          np       = new LfDragablePoint(GetFreeVertexIndex(), insertMe.X, insertMe.Y);
            LfDragablePointViewModel newPoint = new LfDragablePointViewModel(this, ParentVm, MainVm, this, np);

            int index = 0;

            if (insertBeforeMe != null)
            {
                index = PointVms.IndexOf(insertBeforeMe);
            }

            if (index >= 0)
            {
                PointVms.Insert(index, newPoint);
            }

            if (insertBeforeMe != null)
            {
                LocalModelObject.InsertPoint(newPoint.ModelObject, insertBeforeMe.ModelObject);
            }
            else
            {
                LocalModelObject.InsertPoint(newPoint.ModelObject, null);
            }

            InvalidateAll();
            ParentVm.OnPropertyChanged("");

            return(newPoint);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is double) && (values[2] is LfDragablePointViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[2];

                    Point  currP = TextureBorderHelperClass.GetOriginalPoint(origVertex);
                    Point  prevP = TextureBorderHelperClass.GetPreviousPoint(origVertex);
                    double angle = TextureBorderHelperClass.GetAngle(origVertex, currP, prevP);
                    BorderTextureViewModel border = TextureBorderHelperClass.GetTextureViewModel(origVertex, angle);

                    if ((border.Texture == "") || (border.Texture == "notDefined"))
                    {
                        return(Visibility.Collapsed);
                    }

                    return(Visibility.Visible);
                }
            }

            return(null);
        }
        public static Point GetOriginalPoint(LfDragablePointViewModel myPoint)
        {
            Point origP = new Point(myPoint.PosX, myPoint.PosY);

            return(origP);
        }
Пример #20
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);
        }
        private StateShapeCollectionViewModel SetShapes(CompoundObject co, bool enabledChildren = true)
        {
            StateShapeCollectionViewModel shapes = new StateShapeCollectionViewModel(this, this, MainVm, enabledChildren);

            foreach (LfSpriteBox sb in co.SpriteBoxes)
            {
                LfSpriteBoxViewModel shapevm = new LfSpriteBoxViewModel(shapes, this, MainVm, sb, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfSpritePolygon sp in co.SpritePolygons)
            {
                LfSpritePolygonViewModel shapevm = new LfSpritePolygonViewModel(shapes, this, MainVm, sp, enabledChildren);

                foreach (LfDragablePoint dragPoint in sp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticBox sb in co.StaticBoxes)
            {
                LfStaticBoxViewModel shapevm = new LfStaticBoxViewModel(shapes, this, MainVm, sb, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticCircle sb in co.StaticCircles)
            {
                LfStaticCircleViewModel shapevm = new LfStaticCircleViewModel(shapes, this, MainVm, sb, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticPolygon sp in co.StaticPolygons)
            {
                LfStaticPolygonViewModel shapevm = new LfStaticPolygonViewModel(shapes, this, MainVm, sp, enabledChildren);

                foreach (LfDragablePoint dragPoint in sp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicBox db in co.DynamicBoxes)
            {
                LfDynamicBoxViewModel shapevm = new LfDynamicBoxViewModel(shapes, this, MainVm, db, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicCircle db in co.DynamicCircles)
            {
                LfDynamicCircleViewModel shapevm = new LfDynamicCircleViewModel(shapes, this, MainVm, db, enabledChildren);
                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicPolygon dp in co.DynamicPolygons)
            {
                LfDynamicPolygonViewModel shapevm = new LfDynamicPolygonViewModel(shapes, this, MainVm, dp, enabledChildren);

                foreach (LfDragablePoint dragPoint in dp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfStaticBoxedSpritePolygon bsp in co.StaticBoxedSpritePolygons)
            {
                LfStaticBoxedSpritePolygonViewModel shapevm = new LfStaticBoxedSpritePolygonViewModel(shapes, this, MainVm, bsp, enabledChildren);

                foreach (LfDragablePoint dragPoint in bsp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            foreach (LfDynamicBoxedSpritePolygon bsp in co.DynamicBoxedSpritePolygons)
            {
                LfDynamicBoxedSpritePolygonViewModel shapevm = new LfDynamicBoxedSpritePolygonViewModel(shapes, this, MainVm, bsp, enabledChildren);

                foreach (LfDragablePoint dragPoint in bsp.Points)
                {
                    LfDragablePointViewModel dragPointVm = new LfDragablePointViewModel(shapevm, this, MainVm, shapevm, dragPoint, enabledChildren);
                    shapevm.PointVms.Add(dragPointVm);
                }

                shapes.Shapes.Add(shapevm);
            }

            return(shapes);
        }