コード例 #1
0
        //================================================================================================//
        // get value of single term
        //================================================================================================//
        private static int ProcessAssignTerm(SignalHead head, List <SignalScripts.SCRScripts.SCRStatTerm> statementTerms, SignalScripts.SCRScripts.SCRStatTerm term, int[] localFloats)
        {
            int termvalue = 0;

            if (term.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                termvalue = FunctionValue(head, term, localFloats);
            }
            else if (term.PartParameter != null)
            {
                // for non-function terms only first entry is valid
                SignalScripts.SCRScripts.SCRParameterType parameter = term.PartParameter[0];
                termvalue = TermValue(head, parameter, localFloats);
            }
            else if (term.TermNumber > 0)
            {
                termvalue = ProcessSubTerm(head, statementTerms, term.TermNumber, localFloats);
            }
            return(termvalue);
        }
コード例 #2
0
ファイル: SIGSCRfile.cs プロジェクト: robwor/openrails
        //================================================================================================//
        //
        // get value of single term
        //
        //================================================================================================//

        public int SH_processAssignTerm(SignalHead thisHead, List <SignalScripts.SCRScripts.SCRStatTerm> StatementTerms,
                                        SignalScripts.SCRScripts.SCRStatTerm thisTerm, int sublevel,
                                        int[] localFloats, SIGSCRfile sigscr)
        {
            int termvalue = 0;

            if (thisTerm.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                termvalue = SH_function_value(thisHead, thisTerm, localFloats, sigscr);
            }
            else if (thisTerm.PartParameter != null)
            {
                // for non-function terms only first entry is valid

                SignalScripts.SCRScripts.SCRParameterType thisParameter = thisTerm.PartParameter[0];
                termvalue = SH_termvalue(thisHead, thisParameter, localFloats, sigscr);
            }
            else if (thisTerm.sublevel > 0)
            {
                termvalue = SH_processSubTerm(thisHead, StatementTerms, thisTerm.sublevel, localFloats, sigscr);
            }

            return(termvalue);
        }
コード例 #3
0
ファイル: SIGSCRfile.cs プロジェクト: robwor/openrails
        //================================================================================================//
        //
        // return function value
        // Possible functions :
        //                        BLOCK_STATE
        //                        ROUTE_SET
        //                        NEXT_SIG_LR
        //                        NEXT_SIG_MR
        //                        THIS_SIG_LR
        //                        THIS_SIG_MR
        //                        OPP_SIG_LR
        //                        OPP_SIG_MR
        //                        DIST_MULTI_SIG_MR
        //                        SIG_FEATURE
        //                        DEF_DRAW_STATE
        //                        HASHEAD
        //                        DEBUG_HEADER   (does not return a value)
        //                        DEBUG_OUT      (does not return a value)
        //
        //================================================================================================//

        public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRStatTerm thisTerm,
                                     int[] localFloats, SIGSCRfile sigscr)
        {
            int return_value     = 0;
            int parameter1_value = 0;
            int parameter2_value = 0;

            // extract parameters (max. 2)

            if (thisTerm.PartParameter != null)
            {
                if (thisTerm.PartParameter.Length >= 1)
                {
                    SignalScripts.SCRScripts.SCRParameterType thisParameter = thisTerm.PartParameter[0];
                    parameter1_value = SH_termvalue(thisHead, thisParameter,
                                                    localFloats, sigscr);
                }

                if (thisTerm.PartParameter.Length >= 2)
                {
                    SignalScripts.SCRScripts.SCRParameterType thisParameter = thisTerm.PartParameter[1];
                    parameter2_value = SH_termvalue(thisHead, thisParameter,
                                                    localFloats, sigscr);
                }
            }

            // switch on function

            SignalScripts.SCRExternalFunctions thisFunction = thisTerm.Function;
            String dumpfile = String.Empty;

            switch (thisFunction)
            {
            // BlockState

            case (SignalScripts.SCRExternalFunctions.BLOCK_STATE):
                return_value = (int)thisHead.mainSignal.block_state();
                break;

            // Route set

            case (SignalScripts.SCRExternalFunctions.ROUTE_SET):
                return_value = (int)thisHead.route_set();
                break;

            // next_sig_lr

            case (SignalScripts.SCRExternalFunctions.NEXT_SIG_LR):
                return_value = (int)thisHead.next_sig_lr((MstsSignalFunction)parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " NEXT_SIG_LR : Located signal : " +
                                       thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    var sob = new StringBuilder();
                    sob.AppendFormat(" NEXT_SIG_LR : Located signal : {0}", thisHead.mainSignal.sigfound[parameter1_value].ToString());

                    if (thisHead.mainSignal.sigfound[parameter1_value] > 0)
                    {
                        SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[thisHead.mainSignal.sigfound[parameter1_value]];
                        sob.AppendFormat(" (");

                        foreach (SignalHead otherHead in otherSignal.SignalHeads)
                        {
                            sob.AppendFormat(" {0} ", otherHead.TDBIndex);
                        }

                        sob.AppendFormat(") ");
                    }
                    sob.AppendFormat("\n");

                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", sob.ToString());
                }
#endif

                break;

            // next_sig_mr

            case (SignalScripts.SCRExternalFunctions.NEXT_SIG_MR):
                return_value = (int)thisHead.next_sig_mr((MstsSignalFunction)parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " NEXT_SIG_LR : Located signal : " +
                                       thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                       " NEXT_SIG_LR : Located signal : " +
                                       thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
                }
#endif
                break;

            // this_sig_lr

            case (SignalScripts.SCRExternalFunctions.THIS_SIG_LR):
                bool             sigfound_lr    = false;
                MstsSignalAspect returnState_lr = thisHead.this_sig_lr((MstsSignalFunction)parameter1_value, ref sigfound_lr);
                return_value = sigfound_lr ? (int)returnState_lr : -1;
                break;

            // this_sig_mr

            case (SignalScripts.SCRExternalFunctions.THIS_SIG_MR):
                bool             sigfound_mr    = false;
                MstsSignalAspect returnState_mr = thisHead.this_sig_mr((MstsSignalFunction)parameter1_value, ref sigfound_mr);
                return_value = sigfound_mr ? (int)returnState_mr : -1;
                break;

            // opp_sig_lr

            case (SignalScripts.SCRExternalFunctions.OPP_SIG_LR):
                return_value = (int)thisHead.opp_sig_lr((MstsSignalFunction)parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    SignalObject foundSignal = null;
                    int          dummy       = (int)thisHead.opp_sig_lr((MstsSignalFunction)parameter1_value, ref foundSignal);
                    int          foundRef    = foundSignal != null ? foundSignal.thisRef : -1;
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " OPP_SIG_LR : Located signal : " + foundRef.ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    SignalObject foundSignal = null;
                    int          dummy       = (int)thisHead.opp_sig_lr((MstsSignalFunction)parameter1_value, ref foundSignal);
                    int          foundRef    = foundSignal != null ? foundSignal.thisRef : -1;
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                       " OPP_SIG_LR : Located signal : " + foundRef.ToString() + "\n");
                }
#endif
                break;

            // opp_sig_mr

            case (SignalScripts.SCRExternalFunctions.OPP_SIG_MR):
                return_value = (int)thisHead.opp_sig_mr((MstsSignalFunction)parameter1_value);
                break;

            // next_nsig_lr

            case (SignalScripts.SCRExternalFunctions.NEXT_NSIG_LR):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                return_value = (int)thisHead.next_nsig_lr((MstsSignalFunction)parameter1_value, parameter2_value, dumpfile);
                break;

            // dist_multi_sig_mr

            case (SignalScripts.SCRExternalFunctions.DIST_MULTI_SIG_MR):

                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif

                return_value = (int)thisHead.dist_multi_sig_mr(
                    (MstsSignalFunction)parameter1_value,
                    (MstsSignalFunction)parameter2_value,
                    dumpfile);

                break;

            // sig_feature

            case (SignalScripts.SCRExternalFunctions.SIG_FEATURE):
                bool temp_value;
                temp_value   = thisHead.sig_feature(parameter1_value);
                return_value = Convert.ToInt32(temp_value);
                break;

            // approach control position

            case (SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_POSITION):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.ApproachControlPosition(parameter1_value, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            // approach control speed

            case (SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_SPEED):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.ApproachControlSpeed(parameter1_value, parameter2_value, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            // Check for CallOn

            case (SignalScripts.SCRExternalFunctions.TRAINHASCALLON):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.TrainHasCallOn(true, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            // Check for CallOn

            case (SignalScripts.SCRExternalFunctions.TRAINHASCALLON_RESTRICTED):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.TrainHasCallOn(false, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            case (SignalScripts.SCRExternalFunctions.HASHEAD):
                return_value = thisHead.mainSignal.HasHead(parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " HASHEAD : required head : " + parameter1_value + " ; state :  " + return_value + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                       " HASHEAD : required head : " + parameter1_value + " ; state :  " + return_value + "\n");
                }
#endif
                break;

            // def_draw_state

            case (SignalScripts.SCRExternalFunctions.DEF_DRAW_STATE):
                return_value = thisHead.def_draw_state((MstsSignalAspect)parameter1_value);
                break;

            // DEBUG routine : to be implemented later

            default:
                break;
            }

#if DEBUG_PRINT_ENABLED
            if (thisHead.mainSignal.enabledTrain != null)
            {
                File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                   "Function Result : " + thisFunction.ToString() + "(" + parameter1_value.ToString() + ") = " +
                                   return_value.ToString() + "\n");
            }
#endif
#if DEBUG_PRINT_PROCESS
            if (TDB_debug_ref.Contains(thisHead.TDBIndex))
            {
                File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                   "Function Result : " + thisFunction.ToString() + "(" + parameter1_value.ToString() + ") = " +
                                   return_value.ToString() + "\n");
            }
#endif

            // check sign

            if (thisTerm.TermOperator == SignalScripts.SCRTermOperator.MINUS)
            {
                return_value = -(return_value);
            }

            return(return_value);
        }
コード例 #4
0
ファイル: SIGSCRfile.cs プロジェクト: robwor/openrails
        //================================================================================================//
        //
        // get parameter term value
        //
        //================================================================================================//

        public static int SH_termvalue(SignalHead thisHead, SignalScripts.SCRScripts.SCRParameterType thisParameter,
                                       int[] localFloats, SIGSCRfile sigscr)
        {
            int return_value = 0;

            // for non-function terms only first entry is valid

            switch (thisParameter.PartType)
            {
            // assign value to external float
            // Possible floats :
            //                        STATE
            //                        DRAW_STATE
            //                        ENABLED
            //                        BLOCK_STATE

            case (SignalScripts.SCRTermType.ExternalFloat):
                SignalScripts.SCRExternalFloats FloatType = (SignalScripts.SCRExternalFloats)thisParameter.PartParameter;

                switch (FloatType)
                {
                case SignalScripts.SCRExternalFloats.STATE:
                    return_value = (int)thisHead.state;
                    break;

                case SignalScripts.SCRExternalFloats.DRAW_STATE:
                    return_value = thisHead.draw_state;
                    break;

                case SignalScripts.SCRExternalFloats.ENABLED:
                    return_value = Convert.ToInt32(thisHead.mainSignal.enabled);
                    break;

                case SignalScripts.SCRExternalFloats.BLOCK_STATE:
                    return_value = (int)thisHead.mainSignal.block_state();
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_POSITION:
                    return_value = thisHead.ApproachControlLimitPositionM.HasValue ? Convert.ToInt32(thisHead.ApproachControlLimitPositionM.Value) : -1;
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_SPEED:
                    return_value = thisHead.ApproachControlLimitSpeedMpS.HasValue ? Convert.ToInt32(thisHead.ApproachControlLimitSpeedMpS.Value) : -1;
                    break;

                default:
                    break;
                }
                break;

            // Local float

            case (SignalScripts.SCRTermType.LocalFloat):
                return_value = localFloats[thisParameter.PartParameter];
                break;

            // all others : constants

            default:
                return_value = thisParameter.PartParameter;
                break;
            }

            return(return_value);
        }
コード例 #5
0
ファイル: SIGSCRfile.cs プロジェクト: robwor/openrails
        //================================================================================================//
        //
        // 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);
        }
コード例 #6
0
        //================================================================================================//
        // 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);
        }
コード例 #7
0
        //================================================================================================//
        // return function value
        // Possible functions : see enum SCRExternalFunctions
        //================================================================================================//
        private static int FunctionValue(SignalHead head, SignalScripts.SCRScripts.SCRStatTerm term, int[] localFloats)
        {
            int result     = 0;
            int parameter1 = 0;
            int parameter2 = 0;

            // extract parameters (max. 2)

            if (term.PartParameter != null)
            {
                if (term.PartParameter.Length >= 1)
                {
                    SignalScripts.SCRScripts.SCRParameterType parameter = term.PartParameter[0];
                    parameter1 = TermValue(head, parameter, localFloats);
                }

                if (term.PartParameter.Length >= 2)
                {
                    SignalScripts.SCRScripts.SCRParameterType parameter = term.PartParameter[1];
                    parameter2 = TermValue(head, parameter, localFloats);
                }
            }

            // switch on function
            switch (term.Function)
            {
            // BlockState
            case SignalScripts.SCRExternalFunctions.BLOCK_STATE:
                result = (int)head.MainSignal.BlockState();
                break;

            // Route set
            case SignalScripts.SCRExternalFunctions.ROUTE_SET:
                result = head.VerifyRouteSet();
                break;

            // next_sig_lr
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_LR:
                result = (int)head.NextSignalLR(parameter1);
                break;

            // next_sig_mr
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_MR:
                result = (int)head.NextSignalMR(parameter1);
                break;

            // this_sig_lr
            case SignalScripts.SCRExternalFunctions.THIS_SIG_LR:
                SignalAspectState returnState_lr = head.ThisSignalLR(parameter1);
                result = returnState_lr != SignalAspectState.Unknown ? (int)returnState_lr : -1;
                break;

            // this_sig_mr
            case SignalScripts.SCRExternalFunctions.THIS_SIG_MR:
                SignalAspectState returnState_mr = head.ThisSignalMR(parameter1);
                result = returnState_mr != SignalAspectState.Unknown ? (int)returnState_mr : -1;
                break;

            // opp_sig_lr
            case SignalScripts.SCRExternalFunctions.OPP_SIG_LR:
                result = (int)head.OppositeSignalLR(parameter1);
                break;

            // opp_sig_mr
            case SignalScripts.SCRExternalFunctions.OPP_SIG_MR:
                result = (int)head.OppositeSignalMR(parameter1);
                break;

            // next_nsig_lr
            case SignalScripts.SCRExternalFunctions.NEXT_NSIG_LR:
                result = (int)head.NextNthSignalLR(parameter1, parameter2);
                break;

            // dist_multi_sig_mr
            case SignalScripts.SCRExternalFunctions.DIST_MULTI_SIG_MR:
                result = (int)head.MRSignalMultiOnRoute(parameter1, parameter2);
                break;

            // dist_multi_sig_mr_of_lr
            case SignalScripts.SCRExternalFunctions.DIST_MULTI_SIG_MR_OF_LR:
                result = (int)head.LRSignalMultiOnRoute(parameter1, parameter2);
                break;

            // next_sig_id
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_ID:
                result = head.NextSignalId(parameter1);
                break;

            // next_nsig_id
            case SignalScripts.SCRExternalFunctions.NEXT_NSIG_ID:
                result = head.NextNthSignalId(parameter1, parameter2);
                break;

            // opp_sig_id
            case SignalScripts.SCRExternalFunctions.OPP_SIG_ID:
                result = head.OppositeSignalId(parameter1);
                break;

            // id_sig_enabled
            case SignalScripts.SCRExternalFunctions.ID_SIG_ENABLED:
                result = head.SignalEnabledById(parameter1);
                break;

            // id_sig_lr
            case SignalScripts.SCRExternalFunctions.ID_SIG_LR:
                result = (int)head.SignalLRById(parameter1, parameter2);
                break;

            // sig_feature
            case SignalScripts.SCRExternalFunctions.SIG_FEATURE:
                result = Convert.ToInt32(head.VerifySignalFeature(parameter1));
                break;

            // allow to clear to partial route
            case SignalScripts.SCRExternalFunctions.ALLOW_CLEAR_TO_PARTIAL_ROUTE:
                head.MainSignal.AllowClearPartialRoute(parameter1);
                break;

            // approach control position
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_POSITION:
                result = Convert.ToInt32(head.MainSignal.ApproachControlPosition(parameter1, false));
                break;

            // approach control position forced
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_POSITION_FORCED:
                result = Convert.ToInt32(head.MainSignal.ApproachControlPosition(parameter1, true));
                break;

            // approach control speed
            case (SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_SPEED):
                result = Convert.ToInt32(head.MainSignal.ApproachControlSpeed(parameter1, parameter2));
                break;

            // approach control next stop
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_NEXT_STOP:
                result = Convert.ToInt32(head.MainSignal.ApproachControlNextStop(parameter1, parameter2));
                break;

            // Lock claim for approach control
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_LOCK_CLAIM:
                head.MainSignal.LockClaim();
                break;

            // Activate timing trigger
            case (SignalScripts.SCRExternalFunctions.ACTIVATE_TIMING_TRIGGER):
                head.MainSignal.ActivateTimingTrigger();
                break;

            // Check timing trigger
            case SignalScripts.SCRExternalFunctions.CHECK_TIMING_TRIGGER:
                result = Convert.ToInt32(head.MainSignal.CheckTimingTrigger(parameter1));
                break;

            // Check for CallOn
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(true, false));
                break;

            // Check for CallOn Restricted
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON_RESTRICTED:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(false, false));
                break;

            // Check for CallOn
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON_ADVANCED:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(true, true));
                break;

            // Check for CallOn Restricted
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON_RESTRICTED_ADVANCED:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(false, true));
                break;

            // check if train needs next signal
            case SignalScripts.SCRExternalFunctions.TRAIN_REQUIRES_NEXT_SIGNAL:
                result = Convert.ToInt32(head.MainSignal.RequiresNextSignal(parameter1, parameter2));
                break;

            case SignalScripts.SCRExternalFunctions.FIND_REQ_NORMAL_SIGNAL:
                result = head.MainSignal.FindRequiredNormalSignal(parameter1);
                break;

            // check if route upto required signal is fully cleared
            case SignalScripts.SCRExternalFunctions.ROUTE_CLEARED_TO_SIGNAL:
                result = (int)head.MainSignal.RouteClearedToSignal(parameter1, false);
                break;

            // check if route upto required signal is fully cleared, but allow callon
            case SignalScripts.SCRExternalFunctions.ROUTE_CLEARED_TO_SIGNAL_CALLON:
                result = (int)head.MainSignal.RouteClearedToSignal(parameter1, true);
                break;

            // check if specified head enabled
            case SignalScripts.SCRExternalFunctions.HASHEAD:
                result = head.MainSignal.HasHead(parameter1);
                break;

            // increase active value of SignalNumClearAhead
            case SignalScripts.SCRExternalFunctions.INCREASE_SIGNALNUMCLEARAHEAD:
                head.MainSignal.IncreaseSignalNumClearAhead(parameter1);
                break;

            // decrease active value of SignalNumClearAhead
            case SignalScripts.SCRExternalFunctions.DECREASE_SIGNALNUMCLEARAHEAD:
                head.MainSignal.DecreaseSignalNumClearAhead(parameter1);
                break;

            // set active value of SignalNumClearAhead
            case SignalScripts.SCRExternalFunctions.SET_SIGNALNUMCLEARAHEAD:
                head.MainSignal.SetSignalNumClearAhead(parameter1);
                break;

            // reset active value of SignalNumClearAhead to default
            case SignalScripts.SCRExternalFunctions.RESET_SIGNALNUMCLEARAHEAD:
                head.MainSignal.ResetSignalNumClearAhead();
                break;

            // store_lvar
            case SignalScripts.SCRExternalFunctions.STORE_LVAR:
                head.StoreLocalVariable(parameter1, parameter2);
                break;

            // this_sig_lvar
            case SignalScripts.SCRExternalFunctions.THIS_SIG_LVAR:
                result = head.ThisSignalLocalVariable(parameter1);
                break;

            // next_sig_lvar
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_LVAR:
                result = head.NextSignalLocalVariable(parameter1, parameter2);
                break;

            // id_sig_lvar
            case SignalScripts.SCRExternalFunctions.ID_SIG_LVAR:
                result = head.LocalVariableBySignalId(parameter1, parameter2);
                break;

            // this_sig_noupdate
            case SignalScripts.SCRExternalFunctions.THIS_SIG_NOUPDATE:
                head.MainSignal.Static = true;
                break;

            // this_sig_hasnormalsubtype
            case SignalScripts.SCRExternalFunctions.THIS_SIG_HASNORMALSUBTYPE:
                result = head.SignalHasNormalSubtype(parameter1);
                break;

            // next_sig_hasnormalsubtype
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_HASNORMALSUBTYPE:
                result = head.NextSignalHasNormalSubtype(parameter1);
                break;

            // next_sig_hasnormalsubtype
            case SignalScripts.SCRExternalFunctions.ID_SIG_HASNORMALSUBTYPE:
                result = head.SignalHasNormalSubtypeById(parameter1, parameter2);
                break;

            // switchstand
            case SignalScripts.SCRExternalFunctions.SWITCHSTAND:
                result = head.Switchstand(parameter1, parameter2);
                break;

            // def_draw_state
            case SignalScripts.SCRExternalFunctions.DEF_DRAW_STATE:
                result = head.DefaultDrawState((SignalAspectState)parameter1);
                break;

            // DEBUG routine : to be implemented later
            default:
                break;
            }
            // check sign
            if (term.TermOperator == SignalScripts.SCRTermOperator.MINUS)
            {
                result = -result;
            }

            return(result);
        }
コード例 #8
0
        //================================================================================================//
        // get parameter term value
        //================================================================================================//
        private static int TermValue(SignalHead head, SignalScripts.SCRScripts.SCRParameterType parameter, int[] localFloats)
        {
            int result = 0;

            // for non-function terms only first entry is valid
            switch (parameter.PartType)
            {
            // assign value to external float
            // Possible floats :
            //                        STATE
            //                        DRAW_STATE
            //                        ENABLED
            //                        BLOCK_STATE

            case (SignalScripts.SCRTermType.ExternalFloat):
                SignalScripts.SCRExternalFloats floatType = (SignalScripts.SCRExternalFloats)parameter.PartParameter;

                switch (floatType)
                {
                case SignalScripts.SCRExternalFloats.STATE:
                    result = (int)head.SignalIndicationState;
                    break;

                case SignalScripts.SCRExternalFloats.DRAW_STATE:
                    result = head.DrawState;
                    break;

                case SignalScripts.SCRExternalFloats.ENABLED:
                    result = Convert.ToInt32(head.MainSignal.Enabled);
                    break;

                case SignalScripts.SCRExternalFloats.BLOCK_STATE:
                    result = (int)head.MainSignal.BlockState();
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_POSITION:
                    result = head.ApproachControlLimitPositionM.HasValue ? Convert.ToInt32(head.ApproachControlLimitPositionM.Value) : -1;
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_SPEED:
                    result = head.ApproachControlLimitSpeedMpS.HasValue ? Convert.ToInt32(head.ApproachControlLimitSpeedMpS.Value) : -1;
                    break;

                default:
                    break;
                }
                break;

            // Local float
            case (SignalScripts.SCRTermType.LocalFloat):
                result = localFloats[parameter.PartParameter];
                break;

            // all others : constants
            default:
                result = parameter.PartParameter;
                break;
            }

            return(result);
        }