예제 #1
0
        private static Vector3D GetRotationDirection(RotaryPneumaticViewModel vm)
        {
            Vector3D vector;

            switch (vm.Direction)
            {
            case LinkDirection.X: vector = new Vector3D(1.0, 0.0, 0.0); break;

            case LinkDirection.Y: vector = new Vector3D(0.0, 1.0, 0.0); break;

            case LinkDirection.Z: vector = new Vector3D(0.0, 0.0, 1.0); break;

            default: throw new ArgumentException("Invalid rotation direction!");
            }

            return(vector);
        }
예제 #2
0
        public static MachineViewModels.ViewModels.Links.ILinkViewModel Convert(this ILink link, MachineElementViewModel mevm, Transform3DGroup transformGroup, Point3D rotationCenter)
        {
            if (link == null)
            {
                return(null);
            }

            if (link is LinearPosition linPos)
            {
                var vm     = new LinearPositionViewModel();
                var action = GetLinearPositionLinkAction(transformGroup, linPos.Direction, linPos.Pos);

                MachineViewModels.Extensions.LinkExtensions.UpdateViewModel(vm, linPos);
                vm.Description = mevm.Name;
                if (action != null)
                {
                    vm.ValueChanged += (s, e) => action(e);
                }

                return(vm);
            }
            else if (link is LinearPneumatic pnmPos)
            {
                var vm = new LinearPneumaticViewModel();

                MachineViewModels.Extensions.LinkExtensions.UpdateViewModel(vm, pnmPos);
                vm.Description = mevm.Name;
                ApplyLinearPneumaticLinkAction(transformGroup, vm, mevm);

                return(vm);
            }
            else if (link is RotaryPneumatic pnmRot)
            {
                var vm = new RotaryPneumaticViewModel();

                MachineViewModels.Extensions.LinkExtensions.UpdateViewModel(vm, pnmRot);
                vm.Description = mevm.Name;
                ApplyRotaryPneumaticLinkAction(transformGroup, rotationCenter, vm);

                return(vm);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
예제 #3
0
        private static void ApplyRotaryPneumaticLinkAction(Transform3DGroup transformGroup, Point3D rotationCenter, RotaryPneumaticViewModel vm)
        {
            if (transformGroup != null)
            {
                var             stopAnimation = new DoubleAnimation();
                Vector3D        vector        = GetRotationDirection(vm);
                var             ar            = new AxisAngleRotation3D(vector, 0.0);
                var             tr            = new RotateTransform3D(ar, rotationCenter);
                var             dp            = AxisAngleRotation3D.AngleProperty;
                Action <double> setAction     = (d) => ar.Angle = d;

                vm.SetPosition = setAction;
                vm.GetPosition = () => ar.Angle;

                transformGroup.Children.Add(tr);

                vm.ValueChanged += (s, e) =>
                {
                    var onPos  = vm.OnPos;
                    var offPos = vm.OffPos;
                    var tOn    = vm.TOn;
                    var tOff   = vm.TOff;

                    if (vm.IsGradualTransactionEnabled)
                    {
                        var to = e ? onPos : offPos;
                        var t  = e ? tOn : tOff;
                        vm.OnMovementStarting?.Invoke(vm);
                        vm.SetPosition = (d) =>
                        {
                            setAction(d);
                            if (d == to)
                            {
                                vm.OnMovementCompleted?.Invoke(vm);
                            }
                        };
                        LinearLinkMovementManager.Add(vm.Id, vm.Pos, to, t);
                    }
                    else
                    {
                        var v = e ? onPos : offPos;
                        vm.OnMovementStarting?.Invoke(vm);
                        setAction(v);
                        vm.OnMovementCompleted?.Invoke(vm);
                    }
                };
            }
        }