public KinematicVM(KinematicStructure model) { Model = model; // create the bone ViewModel tree Roots[0] = new BoneVM(model.Root, null); foreach (BoneVM item in Root) { BoneVMMap.Add(item.Model, item); } }
/// <summary> /// creates and adds a new bone to the currently selected item /// </summary> private void AddBone() { if (SelectedItem == null) { throw new InvalidOperationException("No bone selected!"); } var model = new Bone(parent: SelectedItem.Model, offset: new Vector3D(1, 0, 0)); var vm = new BoneVM(model, parent: SelectedItem); SelectedItem.Children.Add(vm); SelectedItem.Model.Children.Add(model); BoneVMMap.Add(model, vm); }
/// <summary> /// remove the currently selected bone /// </summary> private void RemoveBone() { if (SelectedItem == null) { throw new InvalidOperationException("No bone selected!"); } if (SelectedItem.Parent == null) { throw new InvalidOperationException("Can't remove root node"); } SelectedItem.Parent.Children.Remove(SelectedItem); BoneVMMap.Remove(SelectedItem.Model); }
/// <summary> /// creates new kinematic instance /// </summary> /// <param name="model">the underlying model</param> /// <param name="sensors">collection of registered sensors.</param> public KinematicVM(KinematicStructure model) { Model = model; // create the bone ViewModel tree Roots[0] = new BoneVM(model.Root, null); foreach (BoneVM item in Root) { BoneVMMap.Add(item.Model, item); } // setup commands AddBoneCommand = new RelayCommand(AddBone, CanAddBone); RemoveBoneCommand = new RelayCommand(RemoveBone, CanRemoveBone); ChangeSelectedCommand = new RelayCommand <RoutedPropertyChangedEventArgs <object> >(ChangeSelected); }