示例#1
0
        private void PlaceBone(JointVM firstJoint, JointVM secondJoint)
        {
            var bone   = new Bone(firstJoint.Model, secondJoint.Model);
            var boneVM = new BoneVM(bone);

            if (CanvasVM.Creature.CreatureStructureVM.BoneCollectionVM.Any(b =>
            {
                if (b.FirstJoint.Model.Tracker == firstJoint.Model.Tracker &&
                    b.SecondJoint.Model.Tracker == secondJoint.Model.Tracker)
                {
                    return(true);
                }
                if (b.FirstJoint.Model.Tracker == secondJoint.Model.Tracker &&
                    b.SecondJoint.Model.Tracker == firstJoint.Model.Tracker)
                {
                    return(true);
                }
                return(false);
            }))
            {
                var infoMessage = new InfoMessage("Bone already placed between those joints", TimeSpan.FromSeconds(2), Brushes.Red);
                InfoMessageCollection.AddInfoMessageWithoutTracking(infoMessage);
                return;
            }

            var changeOperation = new ChangeOperation(c => { c.Creature.CreatureStructureVM.BoneCollectionVM.Add(boneVM); },
                                                      c => { c.Creature.CreatureStructureVM.BoneCollectionVM.Remove(boneVM); });

            CanvasVM.HistoryStack.AddOperation(changeOperation);
            Reset();
            FirstJoint = secondJoint;
            CanvasVM.PreviewBone.From = FirstJoint.Position;
        }
示例#2
0
        public void GetEnumrator_GetEnumratorTest_GetEnumratorTrue()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var model = new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            };
            var boneVM = new BoneVM(model);

            collObjectCollection.Insert(1, boneVM);

            // ReSharper disable once GenericEnumeratorNotDisposed
            var enumrator = collObjectCollection.GetEnumerator();

            int count = 0;

            while (enumrator.MoveNext())
            {
                count++;
            }

            Assert.AreEqual(count, 3);
        }
示例#3
0
        private void cb_sensors_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var appvm = AppVM.GetCurrent();

            SensorVM sensor = e.AddedItems[0] as SensorVM; // we assume comboBox so theres always a single selected item
            BoneVM   bone   = (BoneVM)DataContext;
            var      arg    = new Tuple <BoneVM, SensorVM>(bone, sensor);

            if (appvm.AssignSensorToBoneCommand.CanExecute(arg))
            {
                appvm.AssignSensorToBoneCommand.Execute(arg);
            }
            ;
        }
示例#4
0
        public void CopyTo_CopyTest_CopyTrue()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var model = new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            };
            var boneVM = new BoneVM(model);

            collObjectCollection.Insert(1, boneVM);
            var boneVms = new BoneVM[collObjectCollection.Count];

            collObjectCollection.CopyTo(boneVms, 0);

            bool contains = boneVms[1].Density.Equals(density);

            Assert.True(contains);
        }
示例#5
0
        public void Add_AddItem_AddedTrue()
        {//updates
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            // creatureStructure.Bones.Select(b=>new BoneVM(b)).ToList()
            // creatureStructure.Bones.Select(b=>new BoneVM(b)).ToList()
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var boneVM = new BoneVM(new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            });

            collObjectCollection.Add(boneVM);

            int afterCount = collObjectCollection.Count;

            Assert.AreEqual(afterCount, 3);
        }
示例#6
0
        public void IndexOf_ViewModelIndexTest_SameIndexFalse()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var model = new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            };
            var boneVM = new BoneVM(model);

            collObjectCollection.Insert(1, boneVM);

            int index = collObjectCollection.IndexOf(boneVM);

            Assert.IsFalse(index != 1);
        }
示例#7
0
        public void Remove_RemoveTest_RemoveFalse()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var model = new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            };
            var boneVM = new BoneVM(model);

            collObjectCollection.Add(boneVM);

            bool removed = collObjectCollection.Remove(boneVM);

            Assert.AreNotEqual(removed, false);
        }
示例#8
0
        public void Clear_ClearTest_ClearTrue()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var model = new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            };
            var boneVM = new BoneVM(model);

            collObjectCollection.Add(boneVM);

            collObjectCollection.Clear();

            Assert.AreEqual(collObjectCollection.Count, 0);
        }
示例#9
0
        public void Insert_InsertSameModelItem_NotSupportedExceptionTrue()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var model = new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            };
            var boneVM = new BoneVM(model);

            collObjectCollection.Insert(0, boneVM);
            var boneVM2 = new BoneVM(model);

            Assert.Throws <NotSupportedException>(() => collObjectCollection.Insert(0, boneVM2));
        }
示例#10
0
        public void Insert_InsertItem_InsertedFalse()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var collObjectCollection = new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList());
            var boneVM = new BoneVM(new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            });

            collObjectCollection.Insert(0, boneVM);

            int afterCount = collObjectCollection.Count;

            Assert.AreNotEqual(afterCount, 2);
        }
示例#11
0
        public void Add_AddSameViewModelItem_NotSupportedExceptionTrue()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var creatureStructure = new CreatureStructure()
            {
                Bones =
                {
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    },
                    new Bone(firstJoint, secondJoint)
                    {
                        SecondJoint = secondJoint,FirstJoint           = firstJoint, Density = density
                    }
                },
                Joints = { new Joint()
                           {
                               Position = new Vector2(5, 10)
                           }, new Joint()
                           {
                               Position = new Vector2(5, 10)
                           } }
            };
            var boneVM = new BoneVM(new Bone(firstJoint, secondJoint)
            {
                SecondJoint = secondJoint, FirstJoint = firstJoint, Density = density
            });

            new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList()).Add(boneVM);

            Assert.Throws <NotSupportedException>(() => new EncapsulatingObservableCollection <BoneVM, Bone>(creatureStructure.Bones, creatureStructure.Bones.Select(b => new BoneVM(b)).ToList()).Add(boneVM));
        }
示例#12
0
        public void FirstJoint_SetSameValueTest_ReturnsSameValueTrue()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var bone = new Bone(firstJoint, secondJoint)
            {
                Density = density, FirstJoint = firstJoint, SecondJoint = secondJoint
            };
            var boneVM = new BoneVM(bone);

            boneVM.FirstJoint = boneVM.FirstJoint;

            double lengthRLength = boneVM.FirstJoint.Position.Length;

            Assert.AreEqual(firstJoint.Position.Length, lengthRLength);
        }
示例#13
0
        public void Density_SetDifferentValueTest_ReturnsSecondValueFalse()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var bone = new Bone(firstJoint, secondJoint)
            {
                Density = density, FirstJoint = firstJoint, SecondJoint = secondJoint
            };
            var boneVM = new BoneVM(bone)
            {
                Density = 3
            };

            float densityResult = boneVM.Density;

            Assert.AreNotEqual(2, densityResult);
        }
示例#14
0
        public void SecondJoint_SetDifferentValueTest_ReturnsSecondValueFalse()
        {
            const float density    = 2;
            var         firstJoint = new Joint()
            {
                Position = new Vector2(5, 10)
            };
            var secondJoint = new Joint()
            {
                Position = new Vector2(3, 10)
            };
            var bone = new Bone(firstJoint, secondJoint)
            {
                Density = density, FirstJoint = firstJoint, SecondJoint = secondJoint
            };
            var boneVM = new BoneVM(bone)
            {
                SecondJoint = new JointVM(firstJoint)
            };

            double lengthRLength = boneVM.SecondJoint.Position.Length;

            Assert.AreNotEqual(secondJoint.Position.Length, lengthRLength);
        }