Beispiel #1
0
        /// <summary>
        /// Traverses a given path of groups, starting at the last (picked) item through a given destination group, for the pin
        /// that corresponds to the given group pin in the last group in the path. The last (innermost) group of "hitPath" is the picked item.</summary>
        /// <typeparam name="TEdgeRoute">Pin</typeparam>
        /// <param name="hitPath">Path of groups to traverse</param>
        /// <param name="destNode">Destination group (last group to search) which contains the pin searched for</param>
        /// <param name="hitRoute">Pin in innermost group where search begins</param>
        /// <returns>Group pin in destination group "destNode" corresponding to "hitRoute" group pin in innermost group in path</returns>
        static public TEdgeRoute EdgeRouteTraverser <TEdgeRoute>(AdaptablePath <object> hitPath, object destNode, TEdgeRoute hitRoute)
            where TEdgeRoute : class, ICircuitPin
        {
            if (!hitPath.Last.Is <Element>())
            {
                return(null);
            }
            int fromIndex = hitPath.Count - 1; //start from the hit sub-item

            int toIndex = hitPath.IndexOf(destNode);

            if (toIndex < 0 || toIndex > fromIndex)
            {
                return(null);
            }


            var circuitPin     = hitRoute;
            var currentElement = hitPath.Last;

            for (int i = fromIndex - 1; i >= toIndex; --i)
            {
                ICircuitPin matchedPin = null;
                var         parent     = hitPath[i];
                if (parent.Is <Group>())
                {
                    var group = parent.Cast <Group>();
                    foreach (var pin in group.AllInputGroupPins)
                    {
                        var grpPin = pin.Cast <GroupPin>();
                        if (grpPin.InternalElement.Equals(currentElement) &&
                            grpPin.InternalElement.InputPin(grpPin.InternalPinName) == circuitPin)
                        {
                            matchedPin = grpPin;
                            break;
                        }
                    }
                    if (matchedPin == null)
                    {
                        foreach (var pin in group.OutputGroupPins)
                        {
                            var grpPin = pin.Cast <GroupPin>();
                            if (grpPin.InternalElement.Equals(currentElement) &&
                                grpPin.InternalElement.OutputPin(grpPin.InternalPinName) == circuitPin)
                            {
                                matchedPin = grpPin;
                                break;
                            }
                        }
                    }
                }
                if (matchedPin == null)
                {
                    return(null);
                }
                circuitPin     = matchedPin.Cast <TEdgeRoute>();
                currentElement = parent;
            }
            return(circuitPin);
        }
Beispiel #2
0
 /// <summary>
 /// Tests if the element has a given output pin.</summary>
 /// <param name="pin">Pin to test</param>
 /// <returns>True iff the element has the given output pin</returns>
 public virtual bool HasOutputPin(ICircuitPin pin)
 {
     if (this.Is <Group>())
     {
         return(this.Cast <Group>().HasOutputPin(pin));
     }
     return(Type.Outputs.Contains(pin));
 }
Beispiel #3
0
 /// <summary>
 /// Constructor specifying circuit element type's attributes</summary>
 /// <param name="name">Element type's name</param>
 /// <param name="isConnector">Whether the element type is a connector</param>
 /// <param name="size">Element type's size</param>
 /// <param name="image">Element type's image</param>
 /// <param name="inputPins">Array of input pins</param>
 /// <param name="outputPins">Array of output pins</param>
 public ElementType(
     string name,
     bool isConnector,
     Size size,
     Image image,
     ICircuitPin[] inputPins,
     ICircuitPin[] outputPins)
 {
     Set(name, isConnector, size, image, inputPins, outputPins);
 }
Beispiel #4
0
 /// <summary>
 /// Tests if group has a given input pin</summary>
 /// <param name="pin">Pin to test</param>
 /// <returns>True iff group contains the given input pin</returns>
 public override bool HasInputPin(ICircuitPin pin)
 {
     if (m_targetGroup == null)
     {
         return(false);                // disallow connecting to a missing type
     }
     if (InputGroupPins.Contains(pin)) // check group pins in the proxy
     {
         return(true);
     }
     return(m_targetGroup.HasInputPin(pin)); // check group pins in the original group target
 }
Beispiel #5
0
 /// <summary>
 /// Sets circuit element type's attributes</summary>
 /// <param name="name">Element type's name</param>
 /// <param name="isConnector">Whether the element type is a connector</param>
 /// <param name="size">Element type's size</param>
 /// <param name="image">Element type's image</param>
 /// <param name="inputPins">Array of input pins</param>
 /// <param name="outputPins">Array of output pins</param>
 public void Set(
     string name,
     bool isConnector,
     Size size,
     Image image,
     ICircuitPin[] inputPins,
     ICircuitPin[] outputPins)
 {
     m_name = name;
     m_isConnector = isConnector;
     //m_size = size;
     m_image = image;
     m_inputPins = inputPins.OrderBy(n => n.Index).ToArray();
     m_outputPins = outputPins.OrderBy(n => n.Index).ToArray();
 }
Beispiel #6
0
 /// <summary>
 /// Sets circuit element type's attributes</summary>
 /// <param name="name">Element type's name</param>
 /// <param name="isConnector">Whether the element type is a connector</param>
 /// <param name="size">Element type's size</param>
 /// <param name="image">Element type's image</param>
 /// <param name="inputPins">Array of input pins</param>
 /// <param name="outputPins">Array of output pins</param>
 public void Set(
     string name,
     bool isConnector,
     Size size,
     Image image,
     ICircuitPin[] inputPins,
     ICircuitPin[] outputPins)
 {
     m_name = name;
     m_isConnector = isConnector;
     m_size = size;
     m_image = image;
     m_inputPins = inputPins;
     m_outputPins = outputPins;
 }
Beispiel #7
0
        /// <summary>
        /// Tests if the element has a given output pin</summary>
        /// <param name="pin">Pin to test</param>
        /// <returns>True iff the element has the given output pin</returns>
        public virtual bool HasOutputPin(ICircuitPin pin)
        {
            if (this.Is<Group>())
                return this.Cast<Group>().HasOutputPin(pin);
            return Type.Outputs.Contains(pin);

        }
Beispiel #8
0
        private void DefineCircuitType(
            DomNodeType type,
            string elementTypeName,
            string imageName,
            ICircuitPin[] inputs,
            ICircuitPin[] outputs)
        {
            // create an element type and add it to the type metadata
            // For now, let all circuit elements be used as 'connectors' which means
            //  that their pins will be used to create the pins on a master instance.
            bool isConnector = true; //(inputs.Length + outputs.Length) == 1;
            var image = string.IsNullOrEmpty(imageName) ? null : ResourceUtil.GetImage32(imageName);
            type.SetTag<ICircuitElementType>(
                new ElementType(
                    elementTypeName,
                    isConnector,
                    new Size(),
                    image,
                    inputs,
                    outputs));


        }
        // DFS traversal based bytecode gen
        void BuildByteCodeForNode(BytecodeGenContext byteCodeContext, ScriptNodeLinkCache linkCache, ICircuitPin inputPin, IList <ScriptNodeConnection> samePinLinks)
        {
            if (samePinLinks == null || samePinLinks.Count == 0) // if nothing linked just take constant
            {
                var node = linkCache.As <ScriptNode>();
                BuildByteCode_AppendPropertyValueLoad(byteCodeContext, node.DomNode, inputPin);
            }
            else
            {
                delByteCodeHandler byteCodeHandler;
                if (!m_ByteCodeGen.TryGetValue(inputPin.TypeName.ToString(), out byteCodeHandler))
                {
                    throw new Exception("Bytecode handler not found for :" + inputPin.TypeName.ToString());
                }

                byteCodeHandler(byteCodeContext, linkCache, inputPin, samePinLinks);
            }
            //
        }
        void BuildByteCode_AppendPropertyValueLoad(BytecodeGenContext byteCodeContext, DomNode node, ICircuitPin inputPin)
        {
            var attrInfo = node.Type.GetAttributeInfo(inputPin.Name.ToString());
            var value    = node.GetAttribute(attrInfo);

            if (value == null)
            {
                byteCodeContext.Builder.AppendLoadI(0);
                return;
            }

            switch (attrInfo.Type.Name)
            {
            case "boolean":
                byteCodeContext.Builder.AppendLoadI((bool)value ? 1 : 0);
                break;

            case "decimal":
                decimal decVal = (decimal)value;
                if ((decVal - (Int64)decVal) != 0)
                {
                    byteCodeContext.Builder.AppendLoadF((float)decVal);
                }
                else
                {
                    byteCodeContext.Builder.AppendLoadI((int)decVal);
                }
                break;

            case "double":
                double dblVal = (double)value;
                if ((dblVal - (Int64)dblVal) != 0)
                {
                    byteCodeContext.Builder.AppendLoadF((float)dblVal);
                }
                else
                {
                    byteCodeContext.Builder.AppendLoadI((int)dblVal);
                }
                break;

            case "float":
                float fltVal = (float)value;
                if ((fltVal - (Int64)fltVal) != 0)
                {
                    byteCodeContext.Builder.AppendLoadF(fltVal);
                }
                else
                {
                    byteCodeContext.Builder.AppendLoadI((int)fltVal);
                }
                break;

            case "int":
                byteCodeContext.Builder.AppendLoadI((int)value);
                break;

            case "string":
                byteCodeContext.Builder.AppendLoadString((string)value);
                break;

            default:
                throw new Exception("Not supported load bytecode type:" + attrInfo.Type.Name);
            }
        }
 void BuildByteCode_AppendIntPin(BytecodeGenContext byteCodeContext, ScriptNodeLinkCache linkCache, ICircuitPin inputPin, IList <ScriptNodeConnection> samePinLinks)
 {
 }
        void BuildByteCode_AppendBooleanPin(BytecodeGenContext byteCodeContext, ScriptNodeLinkCache linkCache, ICircuitPin inputPin, IList <ScriptNodeConnection> samePinLinks)
        {
            if (samePinLinks.Count != 1)
            {
                throw new Exception("Invalid link count for " + inputPin.Name);
            }

            var connection   = samePinLinks[0];
            var outElement   = connection.OutputElement;
            var outLinkCache = outElement.As <ScriptNodeLinkCache>();
        }
Beispiel #13
0
 /// <summary>
 /// Convert pin index to display order</summary>
 /// <param name="pin">Pin to get</param>
 /// <param name="inputSide">Whether input side or not</param>
 /// <returns>Integer representing display order</returns>
 /// <remarks>Usually ICircuitPin.Index also indicates the display order.
 /// Override this method if pin's index does not correspond to display order.</remarks>
 public virtual int PinDisplayOrder(ICircuitPin pin, bool inputSide)
 {
     return(pin.Index);
 }