/// <summary> /// Performs initialization when the adapter's node is set</summary> protected override void OnNodeSet() { m_subGraphs = new HashSet <Group>(); m_circuits = new HashSet <Circuit>(); m_historyContexts = new HashSet <HistoryContext>(); foreach (DomNode node in DomNode.Subtree) { if (CircuitUtil.IsGroupTemplateInstance(node)) { var template = CircuitUtil.GetGroupTemplate(node); m_templateInstances.Add(template.DomNode, node); m_subGraphs.Add(template); } else if (node.Is <Group>()) { m_subGraphs.Add(node.Cast <Group>()); } else if (node.Is <Circuit>()) { m_circuits.Add(node.Cast <Circuit>()); } } base.OnNodeSet(); }
private void ToggleHideUnconnectedPins() { if (m_targetRef == null || m_targetRef.Target == null) { return; } var group = m_targetRef.Target.Cast <Group>(); if (CircuitUtil.IsGroupTemplateInstance(m_targetRef.Target)) { group = CircuitUtil.GetGroupTemplate(m_targetRef.Target); // for template instances, force update template group pin connectivity // because currently the pin connectivity of a group template is computed on-demand var graphValidator = m_targetRef.Target.Cast <DomNode>().GetRoot().As <CircuitValidator>(); if (graphValidator == null) // it is possible to hold on a templated instance that is converting to a copy instance during rapid mouse clicks, // where the templated instance is no longer a child of root node { return; } graphValidator.UpdateTemplateInfo(group); } // CTE does not set group’s parent during deserialization, // this call ensures the group pins’ external connectivity updated group.UpdateGroupPinInfo(); if (m_allUnconnectedHidden) { foreach (var grpPin in group.InputGroupPins) { foreach (var childGroupPin in grpPin.SinkChain(true)) { childGroupPin.Visible = true; } } foreach (var grpPin in group.OutputGroupPins) { foreach (var childGroupPin in grpPin.SinkChain(false)) { childGroupPin.Visible = true; } } } else { foreach (var grpPin in group.InputGroupPins) { grpPin.Visible = grpPin.Info.ExternalConnected; } foreach (var grpPin in group.OutputGroupPins) { grpPin.Visible = grpPin.Info.ExternalConnected; } } }
/// <summary> /// Updates the pin external connectivity of the connecting group</summary> /// <param name="wire">Wire that has been added or removed in the DOM node tree</param> private void UpdateGroupPinConnectivity(Wire wire) { if (wire.InputElement == null || wire.OutputElement == null) { return; } var updatedNodes = new List <DomNode>(); // need to update the pin external connectivity of the connecting group if (CircuitUtil.IsGroupTemplateInstance(wire.InputElement.DomNode)) { var template = CircuitUtil.GetGroupTemplate(wire.InputElement.DomNode); if (template != null) // if the template is not missing { updatedNodes.Add(template.DomNode); UpdateTemplateInfo(template); } } else if (wire.InputElement.DomNode.Is <Group>()) { updatedNodes.Add(wire.InputElement.DomNode); wire.InputElement.DomNode.Cast <Group>().UpdateGroupPinInfo(); } if (CircuitUtil.IsGroupTemplateInstance(wire.OutputElement.DomNode)) { var template = CircuitUtil.GetGroupTemplate(wire.OutputElement.DomNode); if (template != null) // if the template is not missing { updatedNodes.Add(template.DomNode); UpdateTemplateInfo(template); } } else if (wire.OutputElement.DomNode.Is <Group>()) { updatedNodes.Add(wire.OutputElement.DomNode); wire.OutputElement.DomNode.Cast <Group>().UpdateGroupPinInfo(); } // let's assume all the updated groups have changed connectivity, and notify the graph adaptors foreach (var group in updatedNodes) { var editingContext = group.As <CircuitEditingContext>(); if (editingContext != null) { editingContext.NotifyObjectChanged(group); } } }
private void RemoveSubtree(DomNode root) { foreach (DomNode node in root.Subtree) { if (CircuitUtil.IsGroupTemplateInstance(node)) { var template = CircuitUtil.GetGroupTemplate(node); m_templateInstances.Remove(template.DomNode, node); } else if (node.Is <Group>()) { m_subGraphs.Remove(node.Cast <Group>()); } else if (node.Is <Circuit>()) { m_circuits.Remove(node.Cast <Circuit>()); } } }
private void AddSubtree(DomNode root) { foreach (DomNode node in root.Subtree) { if (CircuitUtil.IsGroupTemplateInstance(node)) { var template = CircuitUtil.GetGroupTemplate(node); if (template != null) // if the template is not missing { m_templateInstances.Add(template.DomNode, node); m_subGraphs.Add(template); } } else if (node.Is <Group>()) { m_subGraphs.Add(node.Cast <Group>()); } else if (node.Is <Circuit>()) { m_circuits.Add(node.Cast <Circuit>()); } } }
/// <summary> /// Performs initialization when the adapter's node is set</summary> protected override void OnNodeSet() { m_subGraphs = new HashSet <Group>(); m_circuits = new HashSet <Circuit>(); m_historyContexts = new HashSet <HistoryContext>(); foreach (DomNode node in DomNode.Subtree) { if (CircuitUtil.IsGroupTemplateInstance(node)) { var template = CircuitUtil.GetGroupTemplate(node); if (template != null) { m_templateInstances.Add(template.DomNode, node); m_subGraphs.Add(template); } } else if (node.Is <Group>()) { m_subGraphs.Add(node.Cast <Group>()); } else if (node.Is <Circuit>()) { m_circuits.Add(node.Cast <Circuit>()); } } base.OnNodeSet(); // Since templates may be externally referenced & edited, better to validate and fix the dangling wires // that were connected to already deleted sub-nodes of a template if (m_templateInstances.Keys.Any()) { UpdateWires(m_subGraphs); UpdateWires(m_circuits); } }
/// <summary> /// Gets the current rendering style for an item</summary> /// <param name="item">Rendered item</param> /// <returns>Rendering style set by SetStyle, Normal if no override is set</returns> public virtual DiagramDrawingStyle GetStyle(object item) { DiagramDrawingStyle result = DiagramDrawingStyle.Normal; // no override if (m_visibilityContext != null && !m_visibilityContext.IsVisible(item)) { result = DiagramDrawingStyle.Hidden; } else if (item == m_hoverObject || item == m_hoverSubObject) { if (CircuitUtil.IsGroupTemplateInstance(item)) { result = DiagramDrawingStyle.TemplatedInstance; } else if (item.Is <Group>()) { result = DiagramDrawingStyle.CopyInstance; } else { result = DiagramDrawingStyle.Hot; } } else if (m_selectionContext != null && m_selectionContext.SelectionContains(item)) { if (m_selectionContext.LastSelected.Equals(item)) { result = DiagramDrawingStyle.LastSelected; } else { result = DiagramDrawingStyle.Selected; } } else if (m_selectionPathProvider != null && m_selectionPathProvider.IncludedPath(item) != null) { if (CircuitUtil.IsGroupTemplateInstance(item)) { result = DiagramDrawingStyle.TemplatedInstance; } else if (item.Is <Group>()) { result = DiagramDrawingStyle.CopyInstance; } else { result = DiagramDrawingStyle.Hot; } } else if (m_renderer.RouteConnecting != null) { // connection context cue: highlight edges that connect to the starting node if (item.Is <TEdge>()) { var edge = item.Cast <TEdge>(); if (m_renderer.RouteConnecting.StartNode.Equals(edge.FromNode) || m_renderer.RouteConnecting.StartNode.Equals(edge.ToNode)) { result = DiagramDrawingStyle.Hot; } } } return(result); }