/// <summary> /// Removes a child from this element /// </summary> /// <param name="child">the child</param> internal virtual void RemoveChild(GraphicBaseElement child) { if (m_Children.Contains(child)) { m_Children.Remove(child); child.Parent = null; } }
protected override void AddTerminals() { InputOutputElement ioElement = LinkedObject as InputOutputElement; //add the Output GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Terminal), ioElement.Outputs[0]); element.Location = new PointF(GraphicConstants.GraphicSignalWidth, GraphicConstants.GraphicSignalHeight / 2); AddTerminal(element as GraphicTerminal); }
internal override void RemoveChild(GraphicBaseElement child) { base.RemoveChild(child); if (child is ConnectionLine) { ConnectionLine line = child as ConnectionLine; line.DetachNodes(); } }
/// <summary> /// Adds a child to this Element /// </summary> /// <param name="child">the child</param> internal virtual void AddChild(GraphicBaseElement child) { if (m_Children == null) { m_Children = new List <GraphicBaseElement>(1); } if (m_Children.Contains(child) == false && child.Parent == null) { m_Children.Add(child); child.Parent = this; } }
/// <summary> /// Returns a graphic element corresponding to the given logic Element /// </summary> /// <param name="logicType">type of the logic element to create graphic element for</param> /// <param name="logic">logic object that will be linked to the graphic element</param> /// <returns>new graphic element</returns> public static GraphicBaseElement CreateInstance(Type logicType, BaseElement logic) { try { if (logicType == null) { throw new ArgumentNullException("logicType"); } // get graphic corresponding to given element from cache GraphicBaseElement element = CreateElement(logicType.Name, logic); return(element); } catch (KeyNotFoundException exception) { throw new ArgumentException("Element Not Found", exception); } }
/// <summary> /// Adds terminals when needed /// </summary> protected virtual void AddTerminals() { InputOutputElement ioElement = LinkedObject as InputOutputElement; //add Outputs int count = CountTerminals(DirectionType.Output); while (count < ioElement.OutputCount) { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Terminal), ioElement.Outputs[count]); if (ioElement.Outputs[count].Negated) { element.Location = new PointF(GraphicConstants.GraphicElementWidth, GraphicConstants.GraphicElementUpperSpace + count * GraphicConstants.GraphicElementTerminalSpace - 3); } else { element.Location = new PointF(GraphicConstants.GraphicElementWidth, GraphicConstants.GraphicElementUpperSpace + count * GraphicConstants.GraphicElementTerminalSpace); } AddTerminal(element as GraphicTerminal); count++; } //add Inputs count = CountTerminals(DirectionType.Input); while (count < ioElement.InputCount) { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Terminal), ioElement.Inputs[count]); if (ioElement.Inputs[count].Negated) { element.Location = new PointF(-GraphicConstants.GraphicTerminalWidth, GraphicConstants.GraphicElementUpperSpace + count * GraphicConstants.GraphicElementTerminalSpace - 3); } else { element.Location = new PointF(-GraphicConstants.GraphicTerminalWidth, GraphicConstants.GraphicElementUpperSpace + count * GraphicConstants.GraphicElementTerminalSpace); } element.Angle = 180; AddTerminal(element as GraphicTerminal); count++; } }
/// <summary> /// Adds terminals /// </summary> protected override void AddTerminals() { Macro macro = LinkedObject as Macro; foreach (SymbolPart part in m_Symbol) { if (part is PortPart) { PortPart port = (PortPart)part; Terminal term = macro.GetTerminalByName(port.Name); if (term != null) { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Terminal), term); element.Name = port.Name; element.Location = port.Location; element.Angle = port.Angle; AddTerminal(element as GraphicTerminal); } } } }
internal override void AddChild(GraphicBaseElement child) { base.AddChild(child); m_Children.Sort(delegate(GraphicBaseElement a, GraphicBaseElement b) { //Lines are 'greater' than Nodes if (a is ConnectionNode) { if (b is ConnectionNode) { return(0); } return(-1); } else if (b is ConnectionNode) { return(1); } return(0); }); }
/// <summary> /// Creates a clone of th given element /// Currently only clones of GraphicInputOutputElement are supported /// </summary> /// <param name="element">element to clone</param> /// <returns>cloned element</returns> public static GraphicBaseElement CreateClone(GraphicBaseElement element) { if (element.GetType().Equals(typeof(GraphicMacro))) { BaseElement macro = ((Macro)element.LinkedObject).Clone(); GraphicMacro graphicMacro = new GraphicMacro(macro, (element as GraphicMacro).m_Symbol); if (element.Children != null) { foreach (GraphicBaseElement child in element.Children) { GraphicBaseElement childClone = CreateClone(child); graphicMacro.AddChild(childClone); } } return(graphicMacro); } if (element.GetType().Equals(typeof(GraphicInputOutputElement))) { BaseElement logic = ((InputOutputElement)element.LinkedObject).Clone(); GraphicInputOutputElement io = new GraphicInputOutputElement(logic); if (element.Children != null) { foreach (GraphicBaseElement child in element.Children) { GraphicBaseElement childClone = CreateClone(child); io.AddChild(childClone); } } return(io); } if (element.GetType().Equals(typeof(GraphicClock))) { BaseElement logic = ((Clock)element.LinkedObject).Clone(); GraphicInputOutputElement grClock = new GraphicClock(logic); if (element.Children != null) { foreach (GraphicBaseElement child in element.Children) { GraphicBaseElement childClone = CreateClone(child); grClock.AddChild(childClone); } } return(grClock); } if (element.GetType().Equals(typeof(GraphicInput))) { BaseElement logic = ((ConstantInput)element.LinkedObject).Clone(); GraphicInputOutputElement sig = new GraphicInput(logic); if (element.Children != null) { foreach (GraphicBaseElement child in element.Children) { GraphicBaseElement childClone = CreateClone(child); sig.AddChild(childClone); } } return(sig); } if (element.GetType().Equals(typeof(GraphicOutput))) { BaseElement logic = ((SignalOutput)element.LinkedObject).Clone(); GraphicInputOutputElement sig = new GraphicOutput(logic); if (element.Children != null) { foreach (GraphicBaseElement child in element.Children) { GraphicBaseElement childClone = CreateClone(child); sig.AddChild(childClone); } } return(sig); } if (element.GetType().Equals(typeof(TextElement))) { TextElement orig = (element as TextElement); TextElement text = new TextElement(orig.Text, orig.Location); text.FontName = orig.FontName; text.FontSize = orig.FontSize; return(text); } return(null); }
/// <summary> /// No children are supported for TextElements /// </summary> /// <param name="child"></param> /// <exception cref="NotSupportedException"></exception> internal override void RemoveChild(GraphicBaseElement child) { throw new NotSupportedException(); }