Exemplo n.º 1
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;
        }
        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;
        }