public static void RequestTreeviewVisibility(this IMachineElementViewModel vm) { if ((vm.Parent != null) && (vm.Parent is IExpandibleElementViewModel evm) && !evm.IsExpanded) { RequestTreeviewVisibility(vm.Parent); evm.IsExpanded = true; } }
private static void AddParentTansform(IMachineElementViewModel vm, Transform3DGroup tg) { tg.Children.Add(vm.Transform); if (vm.Parent != null) { AddParentTansform(vm.Parent, tg); } }
private void ApplyUnloadTool() { if ((_loadedTool != null) /*&& (_preLoadTransform != null)*/) { _loadedTool.Transform = _preLoadTransform; Children.Add(_loadedTool); _loadedTool = null; _preLoadTransform = null; } }
private static void ApplyLinearPositionLinkAction(IMachineElementViewModel vm) { var tg = new Transform3DGroup(); tg.Children.Add(vm.Transform); var link = vm.LinkToParent as LinearPositionViewModel; var action = GetLinearPositionLinkAction(tg, vm.LinkToParent.Direction, link.Pos); link.ValueChanged += (s, e) => action(e); vm.Transform = tg; }
private void IterateMachineElementForLinks(IMachineElementViewModel vm) { if (vm.LinkToParent != null) { Links.Add(vm.LinkToParent); } foreach (var item in vm.Children) { IterateMachineElementForLinks(item); } }
private static void ApplyRotationPneumaticLinkAction(IMachineElementViewModel vm) { var rotVector = GetRotationDirection(vm.LinkToParent.Direction); var rotCenter = vm.Transform.Transform(new Point3D()); var tg = new Transform3DGroup(); var ar = new AxisAngleRotation3D(rotVector, 0.0); var tr = new RotateTransform3D(ar, rotCenter); var link = vm.LinkToParent as RotaryPneumaticViewModel; Action <double> setAction = (d) => ar.Angle = d; tg.Children.Add(vm.Transform); tg.Children.Add(tr); link.SetPosition = setAction; link.GetPosition = () => ar.Angle; link.ValueChanged += (s, e) => { //setAction(e ? link.OnPos : link.OffPos); var onPos = link.OnPos; var offPos = link.OffPos; var tOn = link.TOn; var tOff = link.TOff; if (link.IsGradualTransactionEnabled) { var to = e ? onPos : offPos; var t = e ? tOn : tOff; link.OnMovementStarting?.Invoke(link); link.SetPosition = (d) => { setAction(d); if (d == to) { link.OnMovementCompleted?.Invoke(link); } }; LinearLinkMovementManager.Add(link.Id, link.Pos, to, t); } else { var v = e ? onPos : offPos; link.OnMovementStarting?.Invoke(link); setAction(v); link.OnMovementCompleted?.Invoke(link); } }; vm.Transform = tg; }
public static PanelHolderViewModel ToViewModel(this PanelHolder ph, IMachineElementViewModel parent = null) { return(new PanelHolderViewModel() { PanelHolderId = ph.Id, Name = ph.Name, Corner = Convert(ph.Corner), Position = Convert(ph.Position), Transform = new TranslateTransform3D(ph.Position.X, ph.Position.Y, ph.Position.Z), Geometry = CreateGeometry(), Material = PhongMaterials.Blue, Parent = parent }); }
public static Transform3D GetChainTansform(this IMachineElementViewModel vm) { if (vm != null) { var tg = new Transform3DGroup(); AddParentTansform(vm, tg); return(tg); } else { return(null); } }
public static void ManageToolActivation(this IMachineElementViewModel vm, bool value) { if (vm is ToolHolderViewModel thvm) { thvm.ActiveTool = value; } else { foreach (var item in vm.Children) { var child = item as MachineElementViewModel; child.ManageToolActivation(value); } } }
private static IMachineElementViewModel GetFirstAncestorWithPneumaticLink(IMachineElementViewModel vm) { if (vm != null) { if ((vm.LinkToParent != null) && (vm.LinkToParent is TwoPositionLinkViewModel)) { return(vm); } else { return(GetFirstAncestorWithPneumaticLink(vm.Parent)); } } else { return(null); } }
private IMachineElementViewModel GetToolViewModel(Tool tool) { IMachineElementViewModel vm = null; if (tool.ToolType == TME.ToolType.AngularTransmission) { vm = AngularTransmissionViewModel.Create(tool, Position, Direction); } else if (!string.IsNullOrEmpty(tool.ConeModelFile)) { vm = ToolWithConeViewModel.Create(tool, Position, Direction); } else { vm = ToolViewModel.Create(tool, Position, Direction); } vm.Parent = this; return(vm); }
private void OnLoadToolMessage(LoadToolMessage msg) { if (msg.ToolSource == ToolHolderId) { if (Children.Count == 1) { _loadedTool = Children[0]; _preLoadTransform = _loadedTool.Transform; Children.Clear(); MessengerInstance.Send(new CompleteToolLoadingMessage() { ToolSink = msg.ToolSink, ToolModel = _loadedTool, ToolData = _tool, BackNotifyId = msg.BackNotifyId }); } else { throw new InvalidOperationException("Load tool from empty tool holder source!"); } } }
//private static void ApplyLinearPneumaticLinkAction(MachineElementViewModel vm) //{ // var tg = new Transform3DGroup(); // var tt = new TranslateTransform3D(); // var link = vm.LinkToParent as LinearPneumaticViewModel; // tg.Children.Add(vm.Transform); // tg.Children.Add(tt); // var setAction = GetSetTraslationAction(link.Direction, tt); // link.ValueChanged += (s, e) => setAction(e ? link.OnPos : link.OffPos); // vm.Transform = tg; //} private static void ApplyLinearPneumaticLinkAction(IMachineElementViewModel vm) { var tg = new Transform3DGroup(); var tt = new TranslateTransform3D(); var link = vm.LinkToParent as LinearPneumaticViewModel; tg.Children.Add(vm.Transform); tg.Children.Add(tt); var setAction = GetSetTraslationAction(link.Direction, tt); link.SetPosition = setAction; link.GetPosition = GetGetTraslationFuncion(link.Direction, tt); link.ValueChanged += (s, e) => { var onPos = link.OnPos; var offPos = link.OffPos; var tOn = link.TOn; var tOff = link.TOff; var toolActivator = link.ToolActivator; var lmevm = vm; var inserterId = link.InserterId; EvaluateLinkDataByCollision(link, e, ref onPos, offPos, ref tOn, ref tOff); if (link.IsGradualTransactionEnabled) { var to = e ? onPos : offPos; var t = e ? tOn : tOff; link.OnMovementStarting?.Invoke(link); link.SetPosition = (d) => { setAction(d); if (d == to) { link.OnMovementCompleted?.Invoke(link); if (toolActivator) { lmevm.ManageToolActivation(e); } if (inserterId > 0) { link.ManageInserter(e); } } }; LinearLinkMovementManager.Add(link.Id, link.Pos, to, t); } else { var v = e ? onPos : offPos; link.OnMovementStarting?.Invoke(link); setAction(v); link.OnMovementCompleted?.Invoke(link); if (toolActivator) { lmevm.ManageToolActivation(e); } if (inserterId > 0) { link.ManageInserter(e); } } }; vm.Transform = tg; }
private static IMachineElementViewModel GetFirstAncestorWithLinearPositionLink(IMachineElementViewModel vm, LinkDirection direction) { if (vm != null) { if ((vm.LinkToParent != null) && (vm.LinkToParent is LinearPositionViewModel lpvm) && (lpvm.Direction == direction)) { return(vm); } else { return(GetFirstAncestorWithLinearPositionLink(vm.Parent, direction)); } } else { return(null); } }
private static MachineElementViewModel ConvertModelToViewModel(Models.MachineElement me, IMachineElementViewModel parent = null) { var vm = CreateViewModel(me); UpdateFromModel(me, vm); vm.Parent = parent; foreach (var item in me.Children) { var childVm = ConvertModelToViewModel(item, vm); vm.Children.Add(childVm); } if (me.HasPanelHolder) { vm.Children.Add(me.PanelHolder.ToViewModel(vm)); } if (me.InserterType != InserterType.None) { vm.Children.Add(me.Inserter.ToViewModel(vm)); } if (me.ColiderType != ColliderGeometry.None) { vm.Children.Add(me.Collider.ToViewModel(vm)); } return(vm); }