//================================================================================================// // // process single condition // //================================================================================================// public bool SH_processSingleCondition(SignalHead thisHead, SignalScripts.SCRScripts.SCRConditions thisCond, int[] localFloats, SIGSCRfile sigscr) { int term1value = 0; int term2value = 0; bool condition = true; // get value of first term #if DEBUG_PRINT_ENABLED if (thisHead.mainSignal.enabledTrain != null) { File.AppendAllText(dpe_fileLoc + @"printproc.txt", "IF Condition statement (1) : \n"); } #endif #if DEBUG_PRINT_PROCESS if (TDB_debug_ref.Contains(thisHead.TDBIndex)) { File.AppendAllText(dpr_fileLoc + @"printproc.txt", "IF Condition statement (1) : \n"); } #endif if (thisCond.Term1.Function != SignalScripts.SCRExternalFunctions.NONE) { term1value = SH_function_value(thisHead, thisCond.Term1, localFloats, sigscr); } else if (thisCond.Term1.PartParameter != null) { SignalScripts.SCRScripts.SCRParameterType thisParameter = thisCond.Term1.PartParameter[0]; #if DEBUG_PRINT_ENABLED if (thisHead.mainSignal.enabledTrain != null) { File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " + thisParameter.PartParameter.ToString() + "\n"); } #endif #if DEBUG_PRINT_PROCESS if (TDB_debug_ref.Contains(thisHead.TDBIndex)) { File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " + thisParameter.PartParameter.ToString() + "\n"); } #endif SignalScripts.SCRTermOperator thisOperator = thisCond.Term1.TermOperator; term1value = SH_termvalue(thisHead, thisParameter, localFloats, sigscr); if (thisOperator == SignalScripts.SCRTermOperator.MINUS) { term1value = -term1value; } } // get value of second term if (thisCond.Term2 == null) // if only one value : check for NOT { if (thisCond.negate1) { condition = !(Convert.ToBoolean(term1value)); } else { condition = Convert.ToBoolean(term1value); } #if DEBUG_PRINT_ENABLED if (thisHead.mainSignal.enabledTrain != null) { File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Result of single condition : " + " : " + condition.ToString() + " (NOT : " + thisCond.negate1.ToString() + ")\n\n"); } #endif #if DEBUG_PRINT_PROCESS if (TDB_debug_ref.Contains(thisHead.TDBIndex)) { File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Result of single condition : " + " : " + condition.ToString() + " (NOT : " + thisCond.negate1.ToString() + ")\n\n"); } #endif } // process second term else { #if DEBUG_PRINT_ENABLED if (thisHead.mainSignal.enabledTrain != null) { File.AppendAllText(dpe_fileLoc + @"printproc.txt", "IF Condition statement (2) : \n"); } #endif #if DEBUG_PRINT_PROCESS if (TDB_debug_ref.Contains(thisHead.TDBIndex)) { File.AppendAllText(dpr_fileLoc + @"printproc.txt", "IF Condition statement (2) : \n"); } #endif if (thisCond.Term2.Function != SignalScripts.SCRExternalFunctions.NONE) { term2value = SH_function_value(thisHead, thisCond.Term2, localFloats, sigscr); } else if (thisCond.Term2.PartParameter != null) { SignalScripts.SCRScripts.SCRParameterType thisParameter = thisCond.Term2.PartParameter[0]; #if DEBUG_PRINT_ENABLED if (thisHead.mainSignal.enabledTrain != null) { File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " + thisParameter.PartParameter.ToString() + "\n"); } #endif #if DEBUG_PRINT_PROCESS if (TDB_debug_ref.Contains(thisHead.TDBIndex)) { File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " + thisParameter.PartParameter.ToString() + "\n"); } #endif SignalScripts.SCRTermOperator thisOperator = thisCond.Term2.TermOperator; term2value = SH_termvalue(thisHead, thisParameter, localFloats, sigscr); if (thisOperator == SignalScripts.SCRTermOperator.MINUS) { term2value = -term2value; } } // check on required condition switch (thisCond.Condition) { // GT case (SignalScripts.SCRTermCondition.GT): condition = (term1value > term2value); break; // GE case (SignalScripts.SCRTermCondition.GE): condition = (term1value >= term2value); break; // LT case (SignalScripts.SCRTermCondition.LT): condition = (term1value < term2value); break; // LE case (SignalScripts.SCRTermCondition.LE): condition = (term1value <= term2value); break; // EQ case (SignalScripts.SCRTermCondition.EQ): condition = (term1value == term2value); break; // NE case (SignalScripts.SCRTermCondition.NE): condition = (term1value != term2value); break; } #if DEBUG_PRINT_ENABLED if (thisHead.mainSignal.enabledTrain != null) { File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Result of operation : " + thisCond.Condition.ToString() + " : " + condition.ToString() + "\n\n"); } #endif #if DEBUG_PRINT_PROCESS if (TDB_debug_ref.Contains(thisHead.TDBIndex)) { File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Result of operation : " + thisCond.Condition.ToString() + " : " + condition.ToString() + "\n\n"); } #endif } return(condition); }
//================================================================================================// // // process condition statement // //================================================================================================// public bool SH_processConditionStatement(SignalHead thisHead, ArrayList thisCStatList, int[] localFloats, SIGSCRfile sigscr) { // loop through all conditions bool condition = true; bool newcondition = true; bool termnegate = false; SignalScripts.SCRAndOr condstring = SignalScripts.SCRAndOr.NONE; foreach (object thisCond in thisCStatList) { // single condition : process if (thisCond is SignalScripts.SCRNegate) { termnegate = true; } else if (thisCond is SignalScripts.SCRScripts.SCRConditions) { SignalScripts.SCRScripts.SCRConditions thisSingleCond = (SignalScripts.SCRScripts.SCRConditions)thisCond; newcondition = SH_processSingleCondition(thisHead, thisSingleCond, localFloats, sigscr); if (termnegate) { termnegate = false; newcondition = newcondition ? false : true; } switch (condstring) { case (SignalScripts.SCRAndOr.AND): condition &= newcondition; break; case (SignalScripts.SCRAndOr.OR): condition |= newcondition; break; default: condition = newcondition; break; } } // AND or OR indication (to link previous and next part) else if (thisCond is SignalScripts.SCRAndOr) { condstring = (SignalScripts.SCRAndOr)thisCond; } // subcondition else { ArrayList subCond = (ArrayList)thisCond; newcondition = SH_processConditionStatement(thisHead, subCond, localFloats, sigscr); if (termnegate) { termnegate = false; newcondition = newcondition ? false : true; } switch (condstring) { case (SignalScripts.SCRAndOr.AND): condition &= newcondition; break; case (SignalScripts.SCRAndOr.OR): condition |= newcondition; break; default: condition = newcondition; break; } } } return(condition); }
//================================================================================================// // process single condition //================================================================================================// private static bool ProcessSingleCondition(SignalHead head, SignalScripts.SCRScripts.SCRConditions condition, int[] localFloats) { int term1value = 0; int term2value = 0; bool result = true; // get value of first term if (condition.Term1.Function != SignalScripts.SCRExternalFunctions.NONE) { term1value = FunctionValue(head, condition.Term1, localFloats); } else if (condition.Term1.PartParameter != null) { SignalScripts.SCRScripts.SCRParameterType parameter = condition.Term1.PartParameter[0]; term1value = TermValue(head, parameter, localFloats); if (condition.Term1.TermOperator == SignalScripts.SCRTermOperator.MINUS) { term1value = -term1value; } } // get value of second term if (condition.Term2 == null) // if only one value : check for NOT { if (condition.Term1.Negated) { result = !(Convert.ToBoolean(term1value)); } else { result = Convert.ToBoolean(term1value); } } // process second term else { if (condition.Term2.Function != SignalScripts.SCRExternalFunctions.NONE) { term2value = FunctionValue(head, condition.Term2, localFloats); } else if (condition.Term2.PartParameter != null) { SignalScripts.SCRScripts.SCRParameterType parameter = condition.Term2.PartParameter[0]; term2value = TermValue(head, parameter, localFloats); if (condition.Term2.TermOperator == SignalScripts.SCRTermOperator.MINUS) { term2value = -term2value; } } // check on required condition switch (condition.Condition) { // GT case SignalScripts.SCRTermCondition.GT: result = term1value > term2value; break; // GE case SignalScripts.SCRTermCondition.GE: result = term1value >= term2value; break; // LT case SignalScripts.SCRTermCondition.LT: result = term1value < term2value; break; // LE case SignalScripts.SCRTermCondition.LE: result = term1value <= term2value; break; // EQ case SignalScripts.SCRTermCondition.EQ: result = term1value == term2value; break; // NE case SignalScripts.SCRTermCondition.NE: result = term1value != term2value; break; } } return(result); }