예제 #1
0
        protected override CalcValue GetValue()
        {
            switch (CodeFun)
            {
            case "void":
                return(new CalcValue());

            case "owner":
                var cv = CalcRun.Owner.CalcValue;
                if (cv.ParentParam == null)
                {
                    cv = cv.LinkClone(CalcRun.Owner);
                }
                return(cv);

            case "caller":
                return(new CalcValue {
                    ParentParam = CalcRun.Caller
                });

            case "getelement":
                if (Inputs[1].Type != CalcValueType.Single || Inputs[1].SingleValue.Type != SingleType.Moment)
                {
                    return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Индекс массива должен быть отдельным значением", CalcParam.Code)))));
                }
                Moment m = Inputs[1].SingleValue.Moment;
                if (m.DataType.LessOrEquals(DataType.Integer))
                {
                    if (Inputs[0].IntArray == null || !Inputs[0].IntArray.ContainsKey(m.Integer))
                    {
                        return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Несуществующий индекс массива (" + m.Integer + ")", CalcParam.Code)))));
                    }
                    return(Inputs[0].IntArray[m.Integer].CalcValue);
                }
                if (Inputs[0].StringArray == null || !Inputs[0].StringArray.ContainsKey(m.String))
                {
                    return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Несуществующий индекс массива (" + m.String + ")", CalcParam.Code)))));
                }
                return(Inputs[0].StringArray[m.String].CalcValue);

            case "signal":
                return(Inputs[0].Signal.Object.Signals[Inputs[1].SingleValue.LastMoment.String].CalcValue);

            case "signalbool":
            case "signalint":
            case "signalreal":
            case "signalstring":
                string     c   = Inputs[0].SingleValue.LastMoment.String ?? "";
                CalcSignal sig = null;
                if (CalcParam.Project.SignalsSources.ContainsKey(c))
                {
                    sig = CalcParam.Project.SignalsSources[c];
                }
                if (CalcParam.Project.Objects.ContainsKey(c))
                {
                    sig = CalcParam.Project.Objects[c].DefaultSignal;
                }
                if (sig == null || !sig.DataType.LessOrEquals(CodeFun.Substring(6).ToDataType()))
                {
                    return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Строка задает несуществующий сигнал или сигнал недопустимого типа (" + c + ")", CalcParam.Code)))));
                }
                return(sig.CalcValue);

            case "takecode":
            case "takename":
            case "takeunits":
            case "taketask":
            case "takecomment":
            case "takecodesignal":
            case "takenamesignal":
                CalcParam cp = null;
                if (Inputs.Length == 0)
                {
                    cp = CalcParam;
                }
                else if (Inputs[0].ParentParam != null)
                {
                    cp = Inputs[0].ParentParam.CalcParam;
                }
                else if (Inputs[0].Signal != null)
                {
                    var si = Inputs[0].Signal;
                    return(new CalcValue(new SingleValue(new Moment(CalcRun.ThreadCalc.PeriodBegin,
                                                                    CodeFun == "takecode" ? si.CodeObject :
                                                                    CodeFun == "takecodesignal" ? si.CodeSignal :
                                                                    CodeFun == "takename" ? si.NameObject :
                                                                    CodeFun == "takenamesignal" ? si.NameSignal : si.Units))));
                }
                if (cp != null)
                {
                    return(new CalcValue(new SingleValue(new Moment(CalcRun.ThreadCalc.PeriodBegin,
                                                                    CodeFun == "takecode" ? cp.Code :
                                                                    CodeFun == "takename" ? cp.Name :
                                                                    CodeFun == "taketask" ? cp.Task :
                                                                    CodeFun == "takecomment" ? cp.Comment : cp.Units))));
                }
                return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Параметр функции получения характеристики не задает расчетный параметр или сигнал", CalcParam.Code)))));

            case "prevabs":
            case "prevmom":
            case "prev":
            case "prevperiod":
            case "prevhour":
            case "prevhourperiod":
            case "prevday":
            case "prevdayperiod":
                return(new CalcValue(CalcPrev(CodeFun, Inputs)));
            }
            return(null);
        }
예제 #2
0
 public SignalVal(CalcSignal signal, ErrMom err = null)
 {
     Signal     = signal;
     _calcValue = Signal.SourceSignal.MomentsVal;
     _error     = err;
 }