Beispiel #1
0
 public CalcValue(SingleValue value, CalcUnit signal = null)
 {
     Type        = CalcValueType.Single;
     SingleValue = value;
     Signal      = signal;
     Error       = value.Error;
 }
Beispiel #2
0
        //Чтение списка сигналов
        private void ReadSignals()
        {
            AddEvent("Чтение списка сигналов");
            SignalsReceivers.Clear();
            if (ThreadCalc.IsReadSources)
            {
                SignalsSources.Clear();
                _signalsCodes.Clear();
            }

            using (var rec = new ReaderAdo(File, "SELECT * FROM SignalsInUse"))
            {
                int i = 0, n = rec.RecordCount("SELECT Count(*) FROM SignalsInUse");
                while (rec.Read())
                {
                    var sig = new CalcUnit(rec, this, true);
                    if (IsError)
                    {
                        return;
                    }
                    if (ThreadCalc.IsReadSources && !sig.SourceName.IsEmpty())
                    {
                        _signalsCodes.Add(sig.FullCode, sig.DataType);
                        SignalsSources.Add(sig.FullCode, sig);
                        if (sig.CodeObject != null)//null для сигналов ручного ввода
                        {
                            if (!Objects.ContainsKey(sig.CodeObject))
                            {
                                Objects.Add(sig.CodeObject, new CalcObject(sig.CodeObject));
                            }
                            var ob = Objects[sig.CodeObject];
                            ob.Signals.Add(sig.CodeSignal, sig);
                            sig.Object = ob;
                            if (sig.Default)
                            {
                                ob.DefaultSignal = sig;
                            }
                        }
                    }
                    if (ThreadCalc.IsWriteReceivers && !sig.ReceiverName.IsEmpty())
                    {
                        SignalsReceivers.Add(sig.FullCode, sig);
                    }
                    if (++i % 50 == 0)
                    {
                        Procent = i * 100.0 / n;
                    }
                }
            }
        }
Beispiel #3
0
        protected override CalcValue GetValue(CalcParamRun calcRun)
        {
            switch (Code)
            {
            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("Индекс массива должен быть отдельным значением", _calc.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 + ")", _calc.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 + ")", _calc.Code)))));
                }
                return(Inputs[0].StringArray[m.String].CalcValue);

            case "signal":
                try { return(Inputs[0].Signal.Object.Signals[Inputs[1].SingleValue.LastMoment.String].CalcValue); }
                catch { return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Недопустимые параметры функции Сигнал", _calc.Code))))); }

            case "signalbool":
            case "signalint":
            case "signalreal":
            case "signalstring":
                string   c   = Inputs[0].SingleValue.LastMoment.String ?? "";
                CalcUnit sig = null;
                if (_calc.Project.SignalsSources.ContainsKey(c))
                {
                    sig = _calc.Project.SignalsSources[c];
                }
                if (_calc.Project.Objects.ContainsKey(c))
                {
                    sig = _calc.Project.Objects[c].DefaultSignal;
                }
                if (sig == null || !sig.DataType.LessOrEquals(Code.Substring(6).ToDataType()))
                {
                    return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Строка задает несуществующий сигнал или сигнал недопустимого типа (" + c + ")", _calc.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 = _calc;
                }
                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,
                                                                    Code == "takecode" ? si.CodeObject :
                                                                    Code == "takecodesignal" ? si.CodeSignal :
                                                                    Code == "takename" ? si.NameObject :
                                                                    Code == "takenamesignal" ? si.NameSignal : si.Units))));
                }
                if (cp != null)
                {
                    return(new CalcValue(new SingleValue(new Moment(calcRun.ThreadCalc.PeriodBegin,
                                                                    Code == "takecode" ? cp.Code :
                                                                    Code == "takename" ? cp.Name :
                                                                    Code == "taketask" ? cp.Task :
                                                                    Code == "takecomment" ? cp.Comment : cp.Units))));
                }
                return(new CalcValue(new SingleValue(new Moment(false, new ErrorCalc("Параметр функции получения характеристики не задает расчетный параметр или сигнал", _calc.Code)))));

            case "prevabs":
            case "prevmom":
            case "prev":
            case "prevperiod":
            case "prevhour":
            case "prevhourperiod":
            case "prevday":
            case "prevdayperiod":
                return(new CalcValue(CalcPrev(Code, Inputs, calcRun)));
            }
            return(null);
        }