Exemplo n.º 1
0
 /// <summary>
 /// Driven nodes use AttributeParameters as input parameters.
 /// </summary>
 /// <param name="pd"></param>
 /// <param name="n"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 public override Parameter newParameter(ParameterDefinition pd,
     Node n, int index)
 {
     if (pd.IsInput)
         return new AttributeParameter(pd, n, index);
     else
         return new Parameter(pd);
 }
 public AttributeParameter(ParameterDefinition pd, Node n, int index)
     : base(pd)
 {
     set2ndValue("NULL");
     node = n;
     this.index = index;
     syncOnTypeMatch = true;
 }
Exemplo n.º 3
0
        private bool visible; // Is this paramater's tab visible.

        #endregion Fields

        #region Constructors

        public Parameter(ParameterDefinition pd)
        {
            definition = pd;
            value = null;
            dirty = true;
            defaultingWhenUnconnected = true;
            if (pd != null)
            {
                visible = pd.DefaultVisibility;
                cacheability = pd.DefaultCacheability;
            }
            else
            {
                visible = true;
                cacheability = Cacheability.OutputFullyCached;
            }
        }
Exemplo n.º 4
0
        public static bool ParseParameterAttributes(ref ParameterDefinition pd,
            String attr)
        {
            int val = 0;
            bool v;

            if (GetIntegerAttribute(attr, "private", ref val))
            {
                v = (val == 1 ? false : true);
                pd.setViewability(v);
                if (v) pd.setDefaultVisibility(false);
            }
            else if (GetIntegerAttribute(attr, "hidden", ref val))
            {
                v = (val == 1 ? false : true);
                pd.setDefaultVisibility(v);
            }

            if (GetIntegerAttribute(attr, "visible", ref val))
            {
                bool visible = false, viewable = false;
                if (val == 0)
                {
                    viewable = true;
                    visible = false;
                }
                else if (val == 1)
                {
                    viewable = true;
                    visible = true;
                }
                else if (val == 2)
                {
                    viewable = false;
                    visible = false;
                }
                pd.setViewability(viewable);
                pd.setDefaultVisibility(visible);
            }

            if (GetIntegerAttribute(attr, "cache", ref val))
                pd.setDefaultCacheability((Cacheability)val);
            if (pd.IsInput && GetIntegerAttribute(attr, "reroute", ref val) &&
                (val >= 0))
                pd.setRerouteOutput(val + 1);

            return true;
        }
Exemplo n.º 5
0
        public static bool ParseOutputLine(Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module, String line, int lineNumber)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);

            Symbol symbol;
            ParameterDefinition output;

            List<String> toks = Utils.StringTokenizer(line, ";", new String[] { "" });

            if (toks.Count < 3)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered an erroneous OUTPUT specification on line {0}.", lineNumber);
                return false;
            }

            // Parse the first substring: NAME and optional attributes
            String iname;
            int bracketStart = toks[0].IndexOf('[');
            if (bracketStart >= 0)
                iname = toks[0].Substring(0, bracketStart);
            else
                iname = toks[0];

            iname = iname.Trim();
            Regex rx = new Regex(@"^([a-zA-Z_][0-9a-zA-Z_]*)$");
            Match m = rx.Match(iname);
            if (!m.Success)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Invalid output name: {0} line {1}",
                    iname, lineNumber);
                return false;
            }

            symbol = SymbolManager.theSymbolManager.registerSymbol(iname);
            output = new ParameterDefinition(symbol);
            output.markAsOutput();
            output.setDefaultVisibility();

            if (toks[0].Contains("["))
            {
                int begin_att = toks[0].IndexOf('[');
                int end_att = toks[0].Substring(begin_att).IndexOf(']');
                String atts = null;
                if (end_att > 0)
                    atts = toks[0].Substring(begin_att, end_att);
                if (atts != null)
                    if (!ParseParameterAttributes(ref output, atts))
                    {
                        ErrorDialog ed = new ErrorDialog();
                        ed.post("Unrecognized input attribute(s) ({0}) in MDF line {1}",
                            atts, lineNumber);
                        return false;
                    }
            }

            // Parse the second substring: TYPE.
            if (!ParseMDFTypes(ref output, toks[1], lineNumber))
                return false;

            // Parse the third substring:  DESCRIPTION

            output.setDescription(toks[2]);

            module.addOutput(output);
            return true;
        }
Exemplo n.º 6
0
        public static bool ParseMDFTypes(ref ParameterDefinition param, String p, int lineNumber)
        {
            DXType input_type;
            Regex reg = new Regex(" or ");
            p = reg.Replace(p, " | ");

            List<String> types = Utils.StringTokenizer(p, "|", new String[] { "" });
            DXTypeVals type;
            foreach (String str in types)
            {
                String sstr = str.Trim();
                type = DXType.StringToType(sstr);
                if (type == DXTypeVals.UndefinedType)
                {
                    ErrorDialog ed = new ErrorDialog();
                    ed.post("Erroneous parameter type encountered in line {0}.", lineNumber);
                    return false;
                }

                input_type = new DXType(type);
                bool r = param.addType(input_type);
                Debug.Assert(r);
            }
            return true;
        }
Exemplo n.º 7
0
        public static bool ParseInputLine(Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module, String line, int lineNumber)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);
            ParameterDefinition input = null;
            Symbol symbol;

            List<String> toks = Utils.StringTokenizer(line, ";", new String[] { "" });

            if (toks.Count < 3)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered an erroneous INPUT specification on line {0}.", lineNumber);
                return false;
            }

            // Parse the first substring: NAME and optional attributes
            String iname;
            int bracketStart = toks[0].IndexOf('[');
            if (bracketStart >= 0)
                iname = toks[0].Substring(0, bracketStart);
            else
                iname = toks[0];

            iname = iname.Trim();
            Regex rx = new Regex(@"^([a-zA-Z_]\w*)$");
            Match m = rx.Match(iname);
            if (!m.Success)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Invalid input name: {0} line {1}",
                    iname, lineNumber);
                return false;
            }

            symbol = SymbolManager.theSymbolManager.registerSymbol(iname);
            input = new ParameterDefinition(symbol);
            input.markAsInput();
            input.setDefaultVisibility();

            if (toks[0].Contains("["))
            {
                int begin_att = toks[0].IndexOf('[');
                int end_att = toks[0].Substring(begin_att).IndexOf(']');
                String atts = null;
                if (end_att > 0)
                    atts = toks[0].Substring(begin_att, end_att);
                if (atts != null)
                    if (!ParseParameterAttributes(ref input, atts))
                    {
                        ErrorDialog ed = new ErrorDialog();
                        ed.post("Unrecognized input attribute(s) ({0}) in MDF line {1}",
                            atts, lineNumber);
                        return false;
                    }
            }

            // Parse the second substring: TYPE.
            if (!ParseMDFTypes(ref input, toks[1], lineNumber))
                return false;

            // Parse the third substring:  DEFAULT VALUE.

            // If the value is equal to "(none)", then mark this parameter
            // as a required parameter.

            toks[2] = toks[2].Trim();
            if (toks[2].StartsWith("("))
            { // A descriptive value
                if (toks[2] == "(none)")
                    input.setRequired();
                else
                    input.setNotRequired();
                input.setDescriptiveValue(toks[2]);
            }
            else if (!input.setDefaultValue(toks[2]))
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Default value given on line {0} not one of given types.", lineNumber);
                return false;
            }

            // Add the fourth substring:  DESCRIPTION
            // Description can be blank
            if (toks.Count == 3)
                input.setDescription("");
            else
                input.setDescription(toks[3]);

            module.addInput(input);
            return true;
        }
        public override bool initialize()
        {
            base.initialize();
            Network net = getNetwork();
            if (!net.IsMacro)
                net.makeMacro(true);
            MacroDefinition md = net.Definition;
            ParameterDefinition param = null;

            bool input = IsInput;
            if (!md.IsReadingNet)
            {
                param = new ParameterDefinition(Symbol.zero);
                param.addType(new DXType(DXTypeVals.ObjectType));
            }

            if (input)
            {
                if (!md.IsReadingNet)
                {
                    int n = md.getFirstAvailableInputPosition();
                    param.markAsInput();
                    if (n <= md.InputCount)
                    {
                        ParameterDefinition dummyPd = md.getInputDefinition(n);
                        Debug.Assert(dummyPd.IsDummy);
                        md.replaceInput(param, dummyPd);
                    }
                    else
                    {
                        md.addInput(param);
                    }
                    setIndex(n);
                    param.setName(String.Format("input_{0}", index));
                    param.setDefaultValue("(no default)");
                }
                // The Parameter  must have its own ParameterDefinition since
                // it may change depending upon what we are connected to.
                // FIXME: ParameterDefinition should have a dup() method.
                Parameter p = getOutputParameter(1);
                ParameterDefinition pd = p.Definition;
                ParameterDefinition newpd = pd.duplicate();
                p.setDefinition(newpd);
            }
            else
            {
                if (!md.IsReadingNet)
                {
                    int n = md.getFirstAvailableOutputPosition();
                    param.markAsOutput();
                    if (n <= md.OutputCount)
                    {
                        ParameterDefinition dummyPd = md.getOutputDefinition(n);
                        Debug.Assert(dummyPd.IsDummy);
                        md.replaceOutput(param, dummyPd);
                    }
                    else
                    {
                        md.addOutput(param);
                    }
                    setIndex(n);
                    param.setName(String.Format("output_{0}", index));
                    param.setDefaultValue("(no default)");
                }
                Parameter p = getInputParameter(1);
                ParameterDefinition pd = p.Definition;
                ParameterDefinition newpd = pd.duplicate();
                p.setDefinition(newpd);
            }
            return true;
        }
Exemplo n.º 9
0
 public void setDefinition(ParameterDefinition pd)
 {
     definition = pd;
 }
Exemplo n.º 10
0
        public ParameterDefinition duplicate(ParameterDefinition newpd)
        {
            if (newpd == null)
                newpd = new ParameterDefinition(NameSymbol);

            newpd.description = null;
            newpd.typeStrings = null;

            newpd.default_value = null;
            newpd.is_input = this.is_input;
            newpd.required = this.required;
            newpd.default_visibility = this.default_visibility;
            newpd.viewable = this.viewable;
            newpd.defaultCacheability = this.defaultCacheability;
            newpd.writeableCacheability = this.writeableCacheability;
            newpd.rerouteOutput = this.rerouteOutput;
            newpd.dummy = this.dummy;

            // Now reset everything that is owned by this parameter defn.
            newpd.setDescription(this.Description);
            if (IsDefaultValue)
                newpd.setDefaultValue(this.DefaultValue);
            else
                newpd.setDescriptiveValue(this.DefaultValue);

            foreach (DXType t in this.types)
            {
                DXType newt = t.duplicate();
                newpd.addType(newt);
            }
            return newpd;
        }
Exemplo n.º 11
0
 public BinaryParameter(ParameterDefinition pd)
     : base(pd)
 {
     secondValue = new Parameter(pd);
 }