public SignalChooser(INodeWrapper nodeItem, NodeSignalIn initialSignalIn, double maxWidth, TextAlignment textAlignment) { NodeItem = nodeItem; SignalIn = initialSignalIn; MaxWidth = maxWidth; TextAlignment = textAlignment; }
protected bool TraceBackForPath(INodeWrapper <T> startingNode) { result.Clear(); NodeWrapperEx <T> nodeWrapper = startingNode as NodeWrapperEx <T>; if (nodeWrapper == null || nodeWrapper.g == float.PositiveInfinity) { return(false); } while (!nodeWrapper.node.Equals(endingNode)) { NodeWrapperEx <T> previous = default; foreach (var nei in context.GetGraphData().CollectNeighbor(nodeWrapper.node).Select(n => context.GetOrCreateNode(n))) { if (previous == null || nei.g < previous.g) { previous = nei; } } result.Add(nodeWrapper.node); nodeWrapper = previous; } result.Add(nodeWrapper.node); return(true); }
public bool DisconnectDialog(INodeWrapper requester) { if (!Connected(requester)) { return(true); } else { if (messagingService.ShowDialog(Resources.Strings.RuntimeService_Disconnect_Message, Resources.Strings.RuntimeService_Disconnect_Title, System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { var runtimeApplicationItem = FindParentRuntimeApplicationItem(requester); if (runtimeApplicationItem != null) { runtimeApplicationItem.Disconnect(); return(true); } else { // we're not inside a runtime app? return(false); } } else { return(false); } } }
public void RegisterValueWatcher(INodeWrapper nodeItem, NodeSignal signal) { if (nodeItem == null) { throw new ArgumentNullException("nodeItem"); } if (signal == null) { throw new ArgumentNullException("signal"); } var rta = FindParentRuntimeApplicationItem(nodeItem); if (rta != null) { lock (m_valueWatchers_Lock) { if (!m_valueWatchers.ContainsKey(rta)) { m_valueWatchers.Add(rta, new Dictionary <NodeSignal, int>()); } if (!m_valueWatchers[rta].ContainsKey(signal)) { m_valueWatchers[rta].Add(signal, 1); m_rtaLookup[nodeItem] = rta; } else { m_valueWatchers[rta][signal] += 1; } } } }
void EditorRoot_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { // If we want to cache the page edits at the page level before saving, then // use IsDirty = true. Otherwise, set m_pageItem.Page = EditorRoot.WorkingCopy //IsDirty = true; m_pageItem.Page = EditorRoot.WorkingCopy; }
public SignalValue(INodeWrapper nodeItem, NodeSignal initialSignal, double maxWidth, TextAlignment textAlignment, string formatString) { Signal = initialSignal; NodeItem = nodeItem; MaxWidth = maxWidth; TextAlignment = textAlignment; FormatString = formatString; }
protected void FireEditedEvent(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { if (!disableEditedDeletedEvents) { logger.Info("Firing Edited Event in item " + this.GetType().ToString()); Edited(this, oldNode, newNode); } }
private void DeviceConfiguration_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var newDC = newNode as NodeDeviceConfiguration; if (newDC != null) { RuntimeApplication = RuntimeApplication.SetDeviceConfiguration(newDC); } }
private void saveNodeState(INodeWrapper nodeWrapper, IUndoMemento memento) { if (nodeWrapper != null && memento != null) { var saveNodeWrapper = nodeWrapper; var saveNode = saveNodeWrapper.Node; memento.RedoActions.Add(() => saveNodeWrapper.StealthSetNode(saveNode)); } }
private void saveNodeState(INodeWrapper nodeWrapper, List <Action> actions) { if (nodeWrapper != null && actions != null) { var saveNodeWrapper = nodeWrapper; var saveNode = saveNodeWrapper.Node; actions.Add(() => saveNodeWrapper.StealthSetNode(saveNode)); } }
void Logic_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var newLogic = newNode as NodePageCollection; if (newLogic != null) { RuntimeApplication = RuntimeApplication.SetLogic(newLogic); } }
void Device_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldDevice = oldNode as NodeDevice; var newDevice = newNode as NodeDevice; if (oldDevice != null && newDevice != null) { Device = Device.NodeDeviceChildren.Replace(oldDevice, newDevice); } }
void AnalogInput_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldAnalogInput = oldNode as NodeAnalogInput; var newAnalogInput = newNode as NodeAnalogInput; if (oldAnalogInput != null && newAnalogInput != null) { Device = Device.NodeAnalogInputChildren.Replace(oldAnalogInput, newAnalogInput); } }
public void ChildInstruction_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldInstruction = oldNode as NodeInstruction; var newInstruction = newNode as NodeInstruction; if (oldInstruction != null && newInstruction != null) { Instruction = Instruction.NodeInstructionChildren.Replace(oldInstruction, newInstruction); } }
void InstructionGroupItem_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldInstructionGroup = oldNode as NodeInstructionGroup; var newInstructionGroup = newNode as NodeInstructionGroup; if (oldInstructionGroup != null && newInstructionGroup != null) { WorkingCopy = WorkingCopy.NodeInstructionGroupChildren.Replace(oldInstructionGroup, newInstructionGroup); } }
void Page_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldPage = oldNode as NodePage; var newPage = newNode as NodePage; if (oldPage != null && newPage != null) { PageCollection = PageCollection.NodePageChildren.Replace(oldPage, newPage); } }
void StringOutput_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldStringOutput = oldNode as NodeStringOutput; var newStringOutput = newNode as NodeStringOutput; if (oldStringOutput != null && newStringOutput != null) { Device = Device.NodeStringOutputChildren.Replace(oldStringOutput, newStringOutput); } }
void Driver_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldDriver = oldNode as NodeDriver; var newDriver = newNode as NodeDriver; if (oldDriver != null && newDriver != null) { DeviceConfiguration = DeviceConfiguration.NodeDriverChildren.Replace(oldDriver, newDriver); } }
void SignalIn_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldSignalIn = oldNode as NodeSignalIn; var newSignalIn = newNode as NodeSignalIn; if (oldSignalIn != null && newSignalIn != null) { AnalogOutput = AnalogOutput.SetSignalIn(newSignalIn); } }
void RuntimeApplication_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldRTA = oldNode as NodeRuntimeApplication; var newRTA = newNode as NodeRuntimeApplication; if (oldRTA != null && newRTA != null) { Solution = Solution.NodeRuntimeApplicationChildren.Replace(oldRTA, newRTA); } }
public NodeSignalIn SignalDialog(INodeWrapper requester, NodeSignalIn defaultSignalIn) { if (DisconnectDialog(requester)) { return(signalChooserDialog.ShowDialog(requester, defaultSignalIn)); } else { return(defaultSignalIn); } }
public INodeWrapper FindAncestorByNodeId(FieldGuid nodeId) { INodeWrapper parent = Parent; while (parent != null) { if (parent.Node.ID == nodeId) { break; } parent = parent.Parent; } return(parent); }
public INodeWrapper FindAncestorOfType(Type findType) { INodeWrapper parent = Parent; while (parent != null) { if (parent.GetType() == findType) { break; } parent = parent.Parent; } return(parent); }
/// <summary> /// Finds the item (if it exists) in the Items collection /// matching the given nodeId. It is *not* recursive. /// </summary> public INodeWrapper FindItemByNodeId(FieldGuid nodeId) { INodeWrapper retVal = null; foreach (var item in Items) { if (item.Node != null && item.Node.ID == nodeId) { retVal = item; break; } } return(retVal); }
public void ChildInstruction_Deleted(INodeWrapper sender, NodeBase deletedNode) { var deletedInstruction = deletedNode as NodeInstruction; var instructionItem = sender as IInstructionItem; if (deletedInstruction != null && instructionItem != null) { if (instructionItem.Parent == this) { instructionItem.Parent = null; } Instruction = Instruction.NodeInstructionChildren.Remove(deletedInstruction); instructionItem.Edited -= new EditedHandler(ChildInstruction_Edited); instructionItem.Deleted -= new DeletedHandler(ChildInstruction_Deleted); Items.Remove(instructionItem); } }
void RuntimeApplication_Deleted(INodeWrapper sender, NodeBase deletedNode) { var deletedRTA = deletedNode as NodeRuntimeApplication; var solutionItem = sender as RuntimeApplicationItem; if (deletedRTA != null && solutionItem != null) { if (solutionItem.Parent == this) { solutionItem.Parent = null; } Solution = Solution.NodeRuntimeApplicationChildren.Remove(deletedRTA); solutionItem.Edited -= new EditedHandler(RuntimeApplication_Edited); solutionItem.Deleted -= new DeletedHandler(RuntimeApplication_Deleted); m_Items.Remove(solutionItem); } }
void Device_Deleted(INodeWrapper sender, NodeBase deletedNode) { var deletedDevice = deletedNode as NodeDevice; var solutionItem = sender as DriverItem; if (deletedDevice != null && solutionItem != null) { if (solutionItem.Parent == this) { solutionItem.Parent = null; } Device = Device.NodeDeviceChildren.Remove(deletedDevice); solutionItem.Edited -= new EditedHandler(Device_Edited); solutionItem.Deleted -= new DeletedHandler(Device_Deleted); Items.Remove(solutionItem); } }
void InstructionGroupItem_Deleted(INodeWrapper sender, NodeBase deletedNode) { var deletedInstructionGroup = deletedNode as NodeInstructionGroup; var editorItem = sender as IEditorItem; if (deletedInstructionGroup != null && editorItem != null) { if (editorItem.Parent == this) { editorItem.Parent = null; } WorkingCopy = WorkingCopy.NodeInstructionGroupChildren.Remove(deletedInstructionGroup); editorItem.Edited -= new EditedHandler(InstructionGroupItem_Edited); editorItem.Deleted -= new DeletedHandler(InstructionGroupItem_Deleted); Items.Remove(editorItem); } }
void Driver_Deleted(INodeWrapper sender, NodeBase deletedNode) { var deletedDriver = deletedNode as NodeDriver; var solutionItem = sender as DriverItem; if (deletedDriver != null && solutionItem != null) { if (solutionItem.Parent == this) { solutionItem.Parent = null; } DeviceConfiguration = DeviceConfiguration.NodeDriverChildren.Remove(deletedDriver); solutionItem.Edited -= new EditedHandler(Driver_Edited); solutionItem.Deleted -= new DeletedHandler(Driver_Deleted); Items.Remove(solutionItem); } }
void StringOutput_Deleted(INodeWrapper sender, NodeBase deletedNode) { var deletedStringOutput = deletedNode as NodeStringOutput; var solutionItem = sender as DriverItem; if (deletedStringOutput != null && solutionItem != null) { if (solutionItem.Parent == this) { solutionItem.Parent = null; } Device = Device.NodeStringOutputChildren.Remove(deletedStringOutput); solutionItem.Edited -= new EditedHandler(StringOutput_Edited); solutionItem.Deleted -= new DeletedHandler(StringOutput_Deleted); Items.Remove(solutionItem); } }
public void DeregisterValueWatcher(INodeWrapper nodeItem, NodeSignal signal) { if (nodeItem == null) { throw new ArgumentNullException("nodeItem"); } if (signal == null) { throw new ArgumentNullException("signal"); } var rta = FindParentRuntimeApplicationItem(nodeItem); if (rta == null) { lock (m_valueWatchers_Lock) { if (m_rtaLookup.ContainsKey(nodeItem)) { rta = m_rtaLookup[nodeItem]; } } } if (rta != null) { lock (m_valueWatchers_Lock) { if (m_valueWatchers.ContainsKey(rta)) { if (m_valueWatchers[rta].ContainsKey(signal)) { m_valueWatchers[rta][signal] -= 1; if (m_valueWatchers[rta][signal] <= 0) { m_rtaLookup.Remove(nodeItem); m_valueWatchers[rta].Remove(signal); if (m_valueWatchers[rta].Count == 0) { m_valueWatchers.Remove(rta); } } } } } } }
public Tuple<NodePage, NodeRuntimeApplication> FindParentPageAndRuntimeApp(INodeWrapper requester) { var tpl = FindParentPageEditorItemPageItemAndRuntimeAppItem(requester); PageEditor.PageEditorItem pageEditorItem = tpl.Item1; PageItem pageItem = tpl.Item2; RuntimeApplicationItem runtimeAppItem = tpl.Item3; NodePage pg = null; NodeRuntimeApplication rta = null; if (pageEditorItem != null) { pg = pageEditorItem.WorkingCopy; } else if (pageItem != null) { pg = pageItem.Page; } if (runtimeAppItem != null) { rta = runtimeAppItem.RuntimeApplication; } return new Tuple<NodePage, NodeRuntimeApplication>(pg, rta); }
public void RegisterValueWatcher(INodeWrapper nodeItem, NodeSignal signal) { if (nodeItem == null) { throw new ArgumentNullException("nodeItem"); } if (signal == null) { throw new ArgumentNullException("signal"); } var rta = FindParentRuntimeApplicationItem(nodeItem); if (rta != null) { lock (m_valueWatchers_Lock) { if (!m_valueWatchers.ContainsKey(rta)) { m_valueWatchers.Add(rta, new Dictionary<NodeSignal, int>()); } if (!m_valueWatchers[rta].ContainsKey(signal)) { m_valueWatchers[rta].Add(signal,1); m_rtaLookup[nodeItem] = rta; } else { m_valueWatchers[rta][signal] += 1; } } } }
/// <summary> /// Displays the Dialog as modal /// </summary> /// <returns>Signal ID</returns> public NodeSignalIn ShowDialog(INodeWrapper requester, NodeSignalIn originalSignalIn) { m_dataTypefilter = originalSignalIn.CompatibleTypes.DataType; OriginalSignalIn = originalSignalIn; setDefaultValues(); NodeItem = requester; Window dlg = new SignalChooserDialogView(); dlg.Owner = mainWindowExport.Value; dlg.DataContext = this; dlg.ShowDialog(); if (SignalSelected) { return NodeSignalIn.BuildWith(OriginalSignalIn.DataType, OriginalSignalIn.CompatibleTypes, SignalId); } else { return NodeSignalIn.BuildWith(OriginalSignalIn.DataType, OriginalSignalIn.CompatibleTypes, Literal); } }
private Tuple<PageEditor.PageEditorItem, PageItem, RuntimeApplicationItem> FindParentPageEditorItemPageItemAndRuntimeAppItem(INodeWrapper requester) { PageEditor.PageEditorItem pageEditorItem; if (requester is PageEditor.PageEditorItem) { pageEditorItem = requester as PageEditor.PageEditorItem; } else { pageEditorItem = requester.FindAncestorOfType(typeof(PageEditor.PageEditorItem)) as PageEditor.PageEditorItem; } PageItem pageItem; if (requester is PageItem) { pageItem = requester as PageItem; } else { pageItem = requester.FindAncestorOfType(typeof(PageItem)) as PageItem; } RuntimeApplicationItem runtimeAppItem; if (pageEditorItem == null) { // we're outside of a page editor runtimeAppItem = requester.FindAncestorOfType(typeof(RuntimeApplicationItem)) as RuntimeApplicationItem; } else { // inside a page editor, we have to do some fancy footwork var pageEditor = pageEditorItem.PageEditorParent; if (pageEditor.PageItemParent != null) { pageItem = pageEditor.PageItemParent; runtimeAppItem = pageItem.FindAncestorOfType(typeof(RuntimeApplicationItem)) as RuntimeApplicationItem; } else { runtimeAppItem = null; } } return new Tuple<PageEditor.PageEditorItem, PageItem, RuntimeApplicationItem>(pageEditorItem, pageItem, runtimeAppItem); }
private void saveNodeState(INodeWrapper nodeWrapper, List<Action> actions) { if (nodeWrapper != null && actions != null) { var saveNodeWrapper = nodeWrapper; var saveNode = saveNodeWrapper.Node; actions.Add(() => saveNodeWrapper.StealthSetNode(saveNode)); } }
void DiscreteInput_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldDiscreteInput = oldNode as NodeDiscreteInput; var newDiscreteInput = newNode as NodeDiscreteInput; if (oldDiscreteInput != null && newDiscreteInput != null) { Device = Device.NodeDiscreteInputChildren.Replace(oldDiscreteInput, newDiscreteInput); } }
public static void SetNodeItem(DependencyObject target, INodeWrapper value) { target.SetValue(SignalValueBehavior.NodeItemProperty, value); }
private RuntimeApplicationItem FindParentRuntimeApplicationItem(INodeWrapper requester) { return FindParentPageEditorItemPageItemAndRuntimeAppItem(requester).Item3; }
void Instruction_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldInstruction = oldNode as NodeInstruction; var newInstruction = newNode as NodeInstruction; if (oldInstruction != null && newInstruction != null) { if (newInstruction.InstructionType != InstructionLDSeries.StaticInstructionType) { throw new InvalidOperationException("The first and only instruction in an " + Extensions.Workbench.Documents.PageEditor_.InstructionGroupItems.LD + " instruction group must be a " + InstructionLDSeries.StaticInstructionType.ToString() + " instruction."); } InstructionGroup = InstructionGroup.NodeInstructionChildren.Replace(oldInstruction, newInstruction); } }
/// <summary> /// Returns a dictionary of signal names, and those signals, in a depth /// first search of the runtime application. For those signals within /// the same page, it has no prefix, but for those in other pages or /// in the device configuration, it adds a directory-like prefix. /// </summary> public Dictionary<string, NodeSignal> SignalList(INodeWrapper requester, FieldDataType.DataTypeEnum dataTypeFilter) { var dict = new Dictionary<string, NodeSignal>(); var tpl = FindParentPageAndRuntimeApp(requester); NodePage pg = tpl.Item1; NodeRuntimeApplication rta = tpl.Item2; if (rta != null) { if (pg != null) { // Search the local page first SignalsDepthFirst(pg, string.Empty, dict, pg, dataTypeFilter); } SignalsDepthFirst(rta, string.Empty, dict, pg, dataTypeFilter); } return dict; }
public NodeSignalIn SignalDialog(INodeWrapper requester, NodeSignalIn defaultSignalIn) { if (DisconnectDialog(requester)) { return signalChooserDialog.ShowDialog(requester, defaultSignalIn); } else { return defaultSignalIn; } }
/// <summary> /// Searches the runtime application for a signal matching the given signalId /// </summary> public Tuple<string, NodeSignal> FindSignal(INodeWrapper requester, FieldGuid signalId) { var tpl = FindParentPageAndRuntimeApp(requester); NodePage pg = tpl.Item1; NodeRuntimeApplication rta = tpl.Item2; if (rta != null) { var edits = new Dictionary<NodePage,NodePage>(); if (pg != null) { // Searches the local page first var tryLocal = FindSignalAndName(pg, string.Empty, pg, signalId, edits); if (tryLocal != null) { return tryLocal; } } // Make a list of edited page copies foreach (var d in layoutManager.Documents) { var pageEditor = d as PageEditor; if (pageEditor != null) { edits.Add(pageEditor.PageItemParent.Page, pageEditor.EditorRoot.WorkingCopy); } } return FindSignalAndName(rta, string.Empty, pg, signalId, edits); } else { return null; } }
public bool DisconnectDialog(INodeWrapper requester) { if (!Connected(requester)) { return true; } else { if (messagingService.ShowDialog(Resources.Strings.RuntimeService_Disconnect_Message, Resources.Strings.RuntimeService_Disconnect_Title, System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { var runtimeApplicationItem = FindParentRuntimeApplicationItem(requester); if (runtimeApplicationItem != null) { runtimeApplicationItem.Disconnect(); return true; } else { // we're not inside a runtime app? return false; } } else { return false; } } }
public bool Connected(INodeWrapper requester) { if(requester == null) { return false; } var runtimeApplicationItem = FindParentRuntimeApplicationItem(requester); if (runtimeApplicationItem != null) { return runtimeApplicationItem.Connected; } else { // we're not inside a runtime app? return false; } }