Exemple #1
0
        //public void ClearOutput()
        //{
        //    this.Output = new OutputData(this.Precision);
        //}


        #region Rewrite
        void Rewrite_Objects()
        {
            GlobalVarsTable GVT = this.Model.O_Cont.GVT;

            this.Output.Objects.Rows.Clear();
            foreach (string unit in GVT.Vars.Keys.ToArray())
            {
                foreach (SLT.Object obj in GVT.Vars[unit])
                {
                    if (unit == obj.Unit)
                    {
                        string name      = obj.Name;
                        object value_obj = obj.GetValue();
                        try
                        {
                            value_obj = Convert.ToDouble(value_obj);
                            value_obj = Math.Round((double)value_obj, this.Precision);
                        }
                        catch { }
                        string value = Convert.ToString(value_obj);
                        string type  = "";
                        switch (obj.Type)
                        {
                        case SLT.ObjectType.Scalar:
                            type = "Скаляр";
                            break;

                        case SLT.ObjectType.Link:
                            type = "Ссылка";
                            break;

                        case SLT.ObjectType.Vector:
                            type = "Вектор";
                            break;

                        case SLT.ObjectType.Macro:
                            type = "Макрос";
                            break;
                        }

                        if (obj.Type == SLT.ObjectType.Vector)
                        {
                            value = ((SLT.Vector)obj).GetTree();
                        }
                        this.Output.Objects.Rows.Add(obj.Unit, obj.Name, value, type);
                        if (obj.Type == SLT.ObjectType.Vector)
                        {
                            SLT.Vector        Vec          = (SLT.Vector)obj;
                            SLT.Vector        SubVector    = (SLT.Vector)Vec;
                            List <SLT.Object> vector_value = (List <SLT.Object>)(SubVector.GetValue());
                            this.Write_Vector_to_DataTable(this.Output.Objects, vector_value);
                        }
                    }
                }
            }
        }
Exemple #2
0
        void Rewrite_Initiators()
        {
            InitiatorsTable IT = this.Model.O_Cont.IT;

            this.Output.Initiators.Rows.Clear();
            foreach (Initiator init in IT.Initiators)
            {
                int number = init.Number;

                string name;
                string value;
                string type = "";

                SLT.Object obj = this.Model.O_Cont.GetObjectFromInitiator(init);
                name = obj.Name;
                object value_obj = obj.GetValue();
                try
                {
                    value_obj = Convert.ToDouble(value_obj);
                    value_obj = Math.Round((double)value_obj, this.Precision);
                }
                catch { }

                value = Convert.ToString(value_obj);
                switch (obj.Type)
                {
                case SLT.ObjectType.Scalar:
                    type = "Скаляр";
                    break;

                case SLT.ObjectType.Link:
                    type = "Ссылка";
                    break;

                case SLT.ObjectType.Vector:
                    type = "Вектор";
                    break;

                case SLT.ObjectType.Macro:
                    type = "Макрос";
                    break;
                }
                if (obj.Type == SLT.ObjectType.Vector)
                {
                    value = ((SLT.Vector)obj).GetTree();
                }
                this.Output.Initiators.Rows.Add(number, name, value, type);
                if (obj.Type == SLT.ObjectType.Vector)
                {
                    SLT.Vector        Vec          = (SLT.Vector)obj;
                    SLT.Vector        SubVector    = (SLT.Vector)Vec;
                    List <SLT.Object> vector_value = (List <SLT.Object>)(SubVector.GetValue());
                    Write_Vector_to_DataTable(this.Output.Initiators, vector_value);
                }
            }
        }
Exemple #3
0
        void Write_Vector_to_DataTable(DataTable DT, List <SLT.Object> list)
        {
            foreach (SLT.Object obj in list)
            {
                string type = "";
                switch (obj.Type)
                {
                case SLT.ObjectType.Scalar:
                    type = "Скаляр";
                    break;

                case SLT.ObjectType.Link:
                    type = "Ссылка";
                    break;

                case SLT.ObjectType.Vector:
                    type = "Вектор";
                    break;

                case SLT.ObjectType.Macro:
                    type = "Макрос";
                    break;
                }
                if (obj.Type == SLT.ObjectType.Vector)
                {
                    SLT.Vector Subvec = (SLT.Vector)obj;
                    DT.Rows.Add("", Subvec.Name, Subvec.GetTree(), type);
                    this.Write_Vector_to_DataTable(DT, (List <SLT.Object>)Subvec.GetValue());
                }
                else
                {
                    object value_obj = obj.GetValue();
                    try
                    {
                        value_obj = Convert.ToDouble(value_obj);
                        value_obj = Math.Round((double)value_obj, this.Precision);
                    }
                    catch { }
                    DT.Rows.Add("", obj.Name, value_obj, type);
                }
            }
        }
Exemple #4
0
        int ExecuteAction(Action action)
        {
            string unit_name = action.ParentOperator.ParentSubprogram.Unit.Name;
            string label;
            string unit;
            bool   islast;

            switch (action.Name)
            {
            case ActionName.Assign:
                Phrase     var_ph = (Phrase)action.Parameters[0];
                SLT.Object var    = this.GetObject(var_ph);

                Phrase value_ph = (Phrase)action.Parameters[1];
                object value_obj;    // = ConvertValueToObject(value_ph);
                if (value_ph.PhType == PhraseType.Initiator_Word)
                {
                    //пассивизация инициатора
                    value_obj = GetObjectFromLink(value_ph).ID;
                }
                else
                {
                    value_obj = ConvertValueToObject(value_ph);
                }
                var.SetValue(value_obj);
                break;

            case ActionName.Create:
                string var_name   = (string)action.Parameters[0];
                Phrase vartype_ph = (Phrase)action.Parameters[1];

                SLT.Object new_obj = new SLT.Scalar("", "");    //заглушка

                //для скаляра
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.ScalarVarType_Word))
                {
                    new_obj = new SLT.Scalar(var_name, unit_name);
                }
                //для вектора
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.VectorVarType_Word))
                {
                    Phrase description_line_ph = vartype_ph.Value.Find(ph => ph.PhType == PhraseType.DescriptionLine);
                    new_obj = new SLT.Vector(var_name, unit_name, this.ParentModel.Analyzer.CreateObjectsFromDesciptionLine(description_line_ph, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name));
                }
                //для ссылки
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.LinkVarType_Word))
                {
                    new_obj = new SLT.Link(var_name, unit_name);
                }
                //для макроса
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.MacroVarType_Word))
                {
                }
                //this.ParentModel.O_Cont.CreateObject(new_obj,this.INITIATOR.NextOperator.ParentSubprogram SUBPROGRAM.Unit.Name);
                this.ParentModel.O_Cont.CreateObject(new_obj, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name);

                //list.Add(new_obj);
                break;

            case ActionName.Delete:
                string deleted_name = Convert.ToString(action.Parameters[0]);
                if (deleted_name == "True")
                {
                    int deleted_id = this.INITIATOR.ID_of_MemoryCell;
                    this.ParentModel.O_Cont.IT.Delete(deleted_id);
                }
                else
                {
                    //Objects.Object del_obj= this.ParentModel.O_Cont.GetObjectByName(deleted_name,this.SUBPROGRAM.Unit.Name);
                    SLT.Object del_obj = this.ParentModel.O_Cont.GetObjectByName(deleted_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name);
                    //if (del_obj.Unit == this.SUBPROGRAM.Unit.Name)
                    if (del_obj.Unit == this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name)
                    {
                        this.ParentModel.O_Cont.DeleteObjectByID(del_obj.ID);
                    }
                }
                break;

            case ActionName.Terminate:
                string terminated_name = Convert.ToString(action.Parameters[0]);
                int    terminated_id   = this.INITIATOR.ID_of_MemoryCell;
                this.ParentModel.O_Cont.DeleteInitiatorByID(terminated_id);
                break;

            case ActionName.Write_to_CT:
                Phrase condition;
                if (typeof(bool) == action.Parameters[0].GetType())
                {
                    if ((bool)action.Parameters[0])
                    {
                        condition = new Phrase(PhraseType.True);
                    }
                    else
                    {
                        condition = new Phrase(PhraseType.False);
                    }
                }
                else
                {
                    condition = (Phrase)action.Parameters[0];
                }
                string link_name       = Convert.ToString(action.Parameters[1]);
                bool   to_the_begining = (bool)action.Parameters[2];
                label  = (string)action.Parameters[3];
                unit   = (string)action.Parameters[4];
                islast = (bool)action.Parameters[5];

                Initiator  init;
                Subprogram subp;
                try
                {
                    subp = this.ParentModel.ST_Cont.FindSubprogramByLabelAndUnit(label, unit);
                }
                catch (RunTimeError e)
                {
                    throw new RunTimeError(e);
                }

                if (link_name == "True")
                {
                    init = this.INITIATOR;
                }
                else
                {
                    //init = this.ParentModel.O_Cont.ActivateFromLink(link_name, this.SUBPROGRAM.Unit.Name);
                    init = this.ParentModel.O_Cont.ActivateFromLink(link_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name);
                }
                //init.NextOperator = subp;
                init.NextOperator = subp.Operators[0];

                if (to_the_begining)
                {
                    this.TC_Cont.InsertConditionRecord(condition, init, subp, islast);
                }
                else
                {
                    this.TC_Cont.AddConditionRecord(condition, init, subp, islast);
                }
                break;

            case ActionName.Write_to_FTT:
                Phrase time_exp = (Phrase)action.Parameters[0];
                double time     = Convert.ToDouble(this.ComputeArithmeticExpression(time_exp));
                label  = (string)action.Parameters[3];
                unit   = (string)action.Parameters[4];
                islast = (bool)action.Parameters[5];

                init = this.INITIATOR;
                subp = this.ParentModel.ST_Cont.FindSubprogramByLabelAndUnit(label, unit);
                this.TC_Cont.AddTimeRecord(time, init, subp, islast);
                break;
            }
            return(1);
        }