Ejemplo n.º 1
0
 public Element(ElemKey d, int c, signals.ICircuitElement o)
 {
     descr     = d;
     circuitId = c;
     obj       = o;
 }
Ejemplo n.º 2
0
        public Circuit construct()
        {
            Dictionary <int, Circuit.Element> result    = new Dictionary <int, Circuit.Element>();
            Dictionary <Element, object>      elmResult = new Dictionary <Element, object>();

            foreach (KeyValuePair <int, Element> here in contents)
            {
                Element elm = here.Value;
                if (elm.availObjects.Count != 1)
                {
                    throw new ApplicationException("expecting all elements to have exactly one solution");
                }
                signals.ICircuitConnectible avail = elm.availObjects[0];
                signals.ICircuitElement     newOb = null;
                switch (elm.type)
                {
                case ElementType.Module:
                {
                    signals.IBlockDriver drv = avail as signals.IBlockDriver;
                    if (drv != null)
                    {
                        newOb = drv.Create();
                    }
                    else
                    {
                        newOb = (signals.IBlock)avail;
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                case ElementType.FunctionOnOut:
                    newOb = ((signals.IFunctionSpec)avail).Create();
                    break;
                }
                result.Add(elm.circuitId, new Circuit.Element(new ElemKey(elm), elm.circuitId, newOb));
                elmResult.Add(elm, newOb);
            }

            foreach (KeyValuePair <EndpointKey, EndpointKey> conn in connections)
            {
                EndpointKey from    = conn.Key;
                EndpointKey to      = conn.Value;
                object      fromObj = elmResult[from.elem];
                object      toObj   = elmResult[to.elem];
                switch (from.elem.type)
                {
                case ElementType.Module:
                {
                    signals.IOutEndpoint outEP = from.OutputEP((signals.IBlock)fromObj);
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IEPSendTo inEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(inEP);
                        break;
                    }
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                {
                    signals.IInputFunction func = ((signals.IFunction)fromObj).Input;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                        throw new ApplicationException("incompatible connection types");
                    }
                    break;
                }

                case ElementType.FunctionOnOut:
                {
                    signals.IOutputFunction func = ((signals.IFunction)fromObj).Output;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IOutEndpoint outEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(func);
                        break;
                    }
                    }
                    break;
                }
                }
            }
            return(new Circuit(result));
        }