Пример #1
0
        }//constructure

        /// <summary>
        /// Handle all requests for ray tracing including generating new ray trace model, drawing rays from a model, or
        /// delete ray. 
        /// </summary>
        /// <param name="newRequest">All the parameter send from modSendCommand()</param>
        public void handleARequest(RayTraceRequest newRequest)
        {
            //If the command is to generating a new ray tracer model
            if (newRequest.command == "RayTrace0To1" || newRequest.command == "RayTrace0ToMax")
            {
                currentModel.deleteRays();
                currentModel = new RayTracer();

                if (newRequest.command == "RayTrace0To1")
                {
                    currentModel.RayTrace(true, m_scene, newRequest.input1, newRequest.scriptID);
                }
                else
                {
                    currentModel.RayTrace(false, m_scene, newRequest.input1, newRequest.scriptID);
                }
            }//if

            //If the command is to select from the existed model (reading a model from a file)
            //Input1 in the newRequest must contains file name. 
            else if(newRequest.command == "RayTraceFromModel")
            {
                string model = System.IO.File.ReadAllText(@EssentialPaths.getRTModelPath() + newRequest.input1 + ".txt");
                currentModel.deleteRays();
                currentModel = new RayTracer();
                currentModel.RayTraceFromModel(model, m_scene, newRequest.scriptID);
            }
            
            //If the command is to get all ray tracer model name
            else if(newRequest.command == "GetAllModelsName")
            {
                string allModels = System.IO.File.ReadAllText(@EssentialPaths.getModelListPath());
                m_commsMod.DispatchReply(newRequest.scriptID, 1, "AllModelsName//" + allModels, "");
            }

            //Else, it is other ray trace commands such as drawing, deleting, calculating power. 
            else
            {
                switch (newRequest.command)
                {
                    case "DeleteRayTrace":
                        currentModel.deleteRays();
                        break;

                    case "IDtype0": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(0, 0);
                        break;

                    case "IDtype1": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(1, 0);
                        break;

                    case "IDtype2": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(2, 0);
                        break;

                    case "IDtype3": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(3, 0);
                        break;

                    case "IDtype4": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(4, 0);
                        break;

                    case "IDtype5": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(5, 0);
                        break;

                    case "DrawNextPath":
                    case "DrawPrevPath":
                        currentModel.deleteRays();
                        //Get number of reflection and element index
                        string[] tokens = newRequest.input1.Split('_');
                        currentModel.drawRayPath(int.Parse(tokens[0]), int.Parse(tokens[1]));
                        break;



                    //This method can only be called after the ray tracer model has been initialised and post initialised
                    //Input1 contains no of reflection, pathID, and rayID (keys), Input2 contains the position of where 
                    //the ray was pressed;
                    case "getStrengthAt": 
                        double signalStrength = currentModel.getStrengthAt(newRequest.input1, newRequest.input2);
                        m_log.DebugFormat("[strength = ]" + signalStrength.ToString());
                        m_commsMod.DispatchReply(newRequest.scriptID, 1, "Strength: " + signalStrength.ToString(), "");
                        break;
                    default: break;
                }//switch
                
            }//else
        }
Пример #2
0
        void ProcessScriptCommand(UUID scriptID, string reqId, string command, string input1, string input2)
        {
            // Example of how to send message back to the script as an acknowledgement
            //m_commsMod.DispatchReply(scriptID, 1, "Command received: " + module, "");
            //m_commsMod.DispatchReply(scriptID, 1, "String 1: " + input1, "");
            //m_commsMod.DispatchReply(scriptID, 1, "String 2: " + input2, "");

            //If command = mymod
            if (command == "MYMOD")
            {
                string[] tokens = input1.Split(new char[] { '_' }, StringSplitOptions.None);
                string value = tokens[0];
                string unit = tokens[1];
                Conversion.Initialize();
                string result = Conversion.workOnUnit(value, unit);
                result = result + "|";
                m_commsMod.DispatchReply(scriptID, 1, result.Split('|')[0], "");
            }
            else //Ray Tracer Command
            {
                RayTraceRequest request = new RayTraceRequest(scriptID, command, input1, input2);
                rayTracerRequestHandler.handleARequest(request);
            }

        }//ProcessScriptCommand