//public void SetValueToVector(Phrase path, string unit, object value) //{ // string vector_name = ((Word)(path.Value[0])).LValue; // Phrase inner_node = path.Value[2]; // Vector parent_vector = (Vector)this.GVT.Vars[unit].Find(v => v.Name == vector_name); // //SLT.Scalar updated_scalar = (Scalar)this.ParentModel.GVT.Vars[unit].Find(o => o.Name == name); // SLT.Object updated_obj = parent_vector.FindNode(inner_node);//Scalar or Link // updated_obj.SetValue(value); //} //GET public SLT.Object GetObjectByID(int id) { //SLT.Link finded_link = (Link)this.ParentModel.GVT.Vars[unit].Find(o => o.Name == name); SLT.Object result = this.Memory.GetObjectByID(id); return(result); }
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); } } }
public void AddToUnit(Object obj, string unit_name) { SLT.Object finded = this.Vars[unit_name].Find(o => (o.Name == obj.Name)); if (finded != null) { finded.SetValue(obj.GetValue()); } else { this.Vars[unit_name].Add(obj); } }
public Object AddSingletonObject(Object o) { SLT.Object finded = this.Cells.Find(c => ((c.Name == o.Name) && (c.Unit == o.Unit))); if (finded != null) { finded.SetValue(o.GetValue()); return(finded); } o.ID = this.ID_Object_Counter; this.Cells.Add(o); this.ID_Object_Counter++; return(o); }
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); }