Esempio n. 1
0
    public bool ClearKnowledgeOfConnection(LLDNBase gnb)
    {
        bool any = false;

        foreach (ParamBase pb in this.genParams)
        {
            if (pb.type != ParamBase.Type.PCMInput)
            {
                continue;
            }

            ParamConnection pc = pb as ParamConnection;
            if (pc.IsConnected() == false)
            {
                continue;
            }

            if (pc.Reference == gnb)
            {
                pc.SetReference(null);
                any = true;
            }
        }
        return(any);
    }
Esempio n. 2
0
    /// <summary>
    /// Check if the node has a parameter that references a GNBase
    /// </summary>
    /// <param name="gb">The GNBase to compare against.</param>
    /// <returns>True if the node contains a parameter referencing the node, else false.</returns>
    public bool HierarchyContains(LLDNBase gb, bool checkSelf = true)
    {
        if (checkSelf == true && this == gb)
        {
            return(true);
        }

        foreach (ParamBase pb in this.genParams)
        {
            if (pb.type != ParamBase.Type.PCMInput)
            {
                continue;
            }

            ParamConnection pc = pb as ParamConnection;
            if (pc.IsConnected() == false)
            {
                continue;
            }

            if (pc.Reference == gb)
            {
                return(true);
            }

            if (pc.Reference.HierarchyContains(gb) == true)
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 3
0
    /// <summary>
    /// Clear all PCM connection parameters in the node.
    /// </summary>
    public void ClearAllConnections()
    {
        foreach (ParamBase pb in this.genParams)
        {
            if (pb.type != ParamBase.Type.PCMInput)
            {
                continue;
            }

            ParamConnection pc = pb as ParamConnection;
            if (pc.IsConnected() == false)
            {
                continue;
            }

            pc.SetReference(null);
        }
    }
Esempio n. 4
0
    public bool SetConnection(ParamConnection ownedConParam, LLDNBase newConnection)
    {
        if (ownedConParam.IsConnected() == true)
        {
            if (ownedConParam.Reference == newConnection)
            {
                return(true);
            }

            if (newConnection.HierarchyContains(this) == true)
            {
                return(false);
            }
        }

        ownedConParam.SetReference(newConnection);
        return(true);
    }
Esempio n. 5
0
    public WiringDocument Clone(string newName)
    {
        // Fill up the directory. Used so we can use existing
        // cloning utilities for cloning connection params.
        Dictionary <string, LLDNBase> thisLookup =
            new Dictionary <string, LLDNBase>();

        foreach (LLDNBase gnb in this.generators)
        {
            thisLookup.Add(gnb.GUID, gnb);
        }

        // Copy all the generators.
        Dictionary <LLDNBase, LLDNBase> thisToThatMap =
            new Dictionary <LLDNBase, LLDNBase>();

        WiringDocument wd = new WiringDocument(false, null);

        foreach (LLDNBase gnb in this.generators)
        {
            LLDNBase clone = gnb.Clone(thisLookup);
            clone.cachedUILocation = gnb.cachedUILocation;
            wd.generators.Add(clone);
            thisToThatMap.Add(gnb, clone);
        }

        // Convert the connections to point to their own equivalents.
        foreach (LLDNBase gnb in wd.generators)
        {
            foreach (ParamBase pb in gnb.nodeParams)
            {
                if (pb.type == ParamBase.Type.PCMInput)
                {
                    ParamConnection pcon = pb as ParamConnection;
                    if (pcon.IsConnected() == false)
                    {
                        continue;
                    }

                    LLDNBase conv;
                    if (thisToThatMap.TryGetValue(pcon.Reference, out conv) == true)
                    {
                        pcon.SetReference(conv);
                    }
                    else
                    {
                        pcon.ClearReference();
                    }
                }
            }
        }

        // Fix up the output
        if (this.output != null)
        {
            LLDNBase gbOutput = thisToThatMap[this.output];
            if (gbOutput != null && gbOutput.nodeType == LLDNBase.NodeType.Output)
            {
                wd.output = (LLDNOutput)gbOutput;
            }
        }

        // Finish
        if (string.IsNullOrEmpty(newName) == false)
        {
            wd.SetName(newName);
        }
        else
        {
            wd.SetName(this.name);
        }

        return(wd);
    }