Exemple #1
0
        /// <summary>
        /// Removes Terminals when needed
        /// </summary>
        protected void RemoveTerminals()
        {
            InputOutputElement ioElement = LinkedObject as InputOutputElement;
            //remove Outputs
            int count = CountTerminals(DirectionType.Output);

            while (count > ioElement.OutputCount)
            {
                GraphicTerminal terminal = m_Terminals.FindLast(delegate(GraphicTerminal element)
                {
                    return((element.LinkedObject as Terminal).Direction == DirectionType.Output);
                });
                RemoveTerminal(terminal);
                count--;
            }
            //remove Inputs
            count = CountTerminals(DirectionType.Input);
            while (count > ioElement.InputCount)
            {
                GraphicTerminal terminal = m_Terminals.FindLast(delegate(GraphicTerminal element)
                {
                    return((element.LinkedObject as Terminal).Direction == DirectionType.Input);
                });
                RemoveTerminal(terminal);
                count--;
            }
        }
        /// <summary>
        /// Disconnects a Terminal from this Connection
        /// </summary>
        /// <param name="graphicTerminal">the Terminal to disconnect</param>
        public void DisconnectTerminal(GraphicTerminal graphicTerminal)
        {
            Terminal   terminal   = graphicTerminal.LinkedObject as Terminal;
            Connection connection = LinkedObject as Connection;

            connection.DisconnectTerminal(terminal);
            graphicTerminal.OnLocationChanged -= GraphicTerminal_OnLocationChanged;
            //BuildBody();
        }
        /// <summary>
        /// Connects a Terminal to this Connection
        /// </summary>
        /// <param name="graphicTerminal">the Terminal to connect</param>
        public void ConnectTerminal(GraphicTerminal graphicTerminal)
        {
            Terminal   terminal   = graphicTerminal.LinkedObject as Terminal;
            Connection connection = LinkedObject as Connection;

            connection.ConnectTerminal(terminal);
            graphicTerminal.OnLocationChanged += new LocationChangeEvent(GraphicTerminal_OnLocationChanged);
            //new NotifyEvent(GraphicTerminal_OnLocationChanged);
            //BuildBody();
        }
Exemple #4
0
 /// <summary>
 /// Adds a terminal to this Element
 /// </summary>
 /// <param name="terminal">the terminal</param>
 protected void AddTerminal(GraphicTerminal terminal)
 {
     if (m_Terminals == null)
     {
         m_Terminals = new List <GraphicTerminal>(1);
     }
     if (m_Terminals.Contains(terminal) == false)
     {
         m_Terminals.Add(terminal);
     }
 }
Exemple #5
0
 /// <summary>
 /// Removes a terminal from this element
 /// </summary>
 /// <param name="graphicTerminal">the terminal</param>
 protected void RemoveTerminal(GraphicTerminal graphicTerminal)
 {
     if (m_Terminals.Contains(graphicTerminal))
     {
         //remove crossing references (in case garbage collector is dumb)
         Terminal terminal = (graphicTerminal.LinkedObject as Terminal);
         if (terminal != null)
         {
             terminal.LinkedObject = null;
         }
         graphicTerminal.LinkedObject = null;
         ////disconnect if connected
         //if (terminal.IsConnected)
         //{
         //    terminal.Connection.DisconnectTerminal(terminal);
         //}
         m_Terminals.Remove(graphicTerminal);
     }
 }
 private string GenerateNodeName()
 {
     if (m_Parent == null)
     {
         return(String.Empty);
     }
     if (m_Parent is GraphicConnection)
     {
         return(String.Format("{0:x4}{1:x4}", (int)Location.X, (int)Location.Y));
     }
     else if (m_Parent is GraphicTerminal)
     {
         GraphicTerminal terminal = m_Parent as GraphicTerminal;
         string          ioName   = String.Empty;
         if ((m_Parent.LinkedObject as Terminal).ParentIO != null)
         {
             ioName = (m_Parent.LinkedObject as Terminal).ParentIO.Name;
         }
         return(String.Format("{0}/{1}", ioName, terminal.Name));
     }
     throw new NotSupportedException("Parent type not supported");
 }
        private static GraphicBaseElement CreateElement(string name, BaseElement logic)
        {
            //Terminals
            if (name.Equals(typeof(Terminal).Name))
            {
                GraphicBaseElement element = new GraphicTerminal(logic);
                element.Name = logic.Name;
                return(element);
            }
            //Connections
            if (name.Equals(typeof(Connection).Name))
            {
                GraphicBaseElement element = new GraphicConnection(logic);
                element.Name = logic.Name;
                return(element);
            }
            //Macros
            if (name.Equals(typeof(Macro).Name))
            {
                Macro        macro        = logic as Macro;
                GraphicMacro graphicMacro = new GraphicMacro(logic, MacroCache.Instance.GetSymbol(macro.TypeName));

                return(graphicMacro);
            }
            //Gates
            if (name.Equals(typeof(AndGate).Name) || name.Equals(typeof(NandGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"&", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(OrGate).Name) || name.Equals(typeof(NorGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"≥1", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(BufferGate).Name) || name.Equals(typeof(NotGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"1", new PointF(4, 0));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(XorGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"=m", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(XnorGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"=", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            //if (name.Equals(typeof(Delay).Name))
            //{
            //    GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
            //    TextElement text = new TextElement(@"|-|", new PointF(4, 4));
            //    io.AddChild(text);
            //    return io;
            //}
            //Signals
            if (name.Equals(typeof(Clock).Name))
            {
                Clock clock = (Clock)logic;
                GraphicInputOutputElement graphicClock = new GraphicClock(logic);
                return(graphicClock);
            }
            if (name.Equals(typeof(ConstantInput).Name) || name.Equals(typeof(SignalInput).Name))
            {
                GraphicInputOutputElement sig = new GraphicInput(logic);
                TextElement text = null;
                if (logic is SignalInput)
                {
                    text = new TextElement((logic as SignalInput).SignalName, new PointF(2, 0));
                }
                else
                {
                    text = new TextElement((logic as ConstantInput).State.ToString().Substring(0, 2), new PointF(2, 0));
                }
                if (text != null)
                {
                    sig.AddChild(text);
                }
                return(sig);
            }
            if (name.Equals(typeof(SignalOutput).Name))
            {
                SignalOutput output           = (SignalOutput)logic;
                GraphicInputOutputElement sig = new GraphicOutput(logic);
                TextElement text = new TextElement(output.SignalName, new PointF(2, 0));
                sig.AddChild(text);
                return(sig);
            }
            return(null);
        }