Esempio n. 1
0
        public void testSeri()
        {
            ParticleBlueprint p1 = new ParticleBlueprint();
            ParticleBlueprint p2 = new ParticleBlueprint();

            p1.properties = new Dictionary <string, string>();
            p1.methods    = new Dictionary <string, string>();
            p2.properties = new Dictionary <string, string>();
            p2.methods    = new Dictionary <string, string>();

            p1.Name     = "Point";
            p1.Quantity = 1000;
            p1.properties.Add("position", "VectorD3");
            p1.properties.Add("tposition", "VectorD3");
            p1.properties.Add("mass", "double");

            p1.methods.Add("Initialize()", "Random r = new Random(); position = new VectorD3(r.NextDouble() * 10, r.NextDouble() * 10, 0); mass = r.NextDouble(); tposition = new VectorD3(0,0,0);");
            p1.methods.Add("Calculate(Point p)", "tposition += new VectorD3(1,2,3)");
            p1.methods.Add("Calculate(Hole p)", "position += p.position");
            p1.methods.Add("Update()", "position += tposition;");

            p2.Name     = "Hole";
            p2.Quantity = 13;
            p2.properties.Add("position", "VectorD3");

            p2.methods.Add("Initialize()", "Random r = new Random(); position = new VectorD3(r.NextDouble() * 10, r.NextDouble() * 10, 0);");
            p2.methods.Add("Calculate(Point p)", "");
            p2.methods.Add("Calculate(Hole p)", "");


            SimulationConfig config = new SimulationConfig();

            config.particleBlueprints = new List <ParticleBlueprint>()
            {
                p1, p2,
            };

            //config.SimulationBoxSize = new VectorD3(5, 12, 20);
            //config.Threads = 128;

            string jsonString = JsonConvert.SerializeObject(config);

            Console.Write(jsonString);
            File.WriteAllText("PointSim.conig", jsonString);
        }
Esempio n. 2
0
        public string ClassSyntaxGenerator(ParticleBlueprint pb)
        {
            string code = "\npublic class " + pb.Name + "{\n\n";

            foreach (var t in pb.properties)
            {
                //code += "\tpublic " + t.Value + " " + t.Key + " { get; set; }\n\n";
                code += "\tpublic " + t.Value + " " + t.Key;// + ";\n\n";

                if (t.Key.EndsWith("}") || t.Key.EndsWith(";"))
                {
                    code += "\n\n";
                }
                else
                {
                    code += ";\n\n";
                }
            }

            if (!config.SelfComparableParticles)
            {
                code += "\tpublic ulong Particle_ID_Numer;\n";
                code += "\tpublic static ulong Particle_ID_Numer_Count = 0;\n";

                //Constructor that sets ID
                code += "\tpublic " + pb.Name + "(){ Particle_ID_Numer = Particle_ID_Numer_Count; Particle_ID_Numer_Count++; }\n";
            }


            foreach (var m in pb.methods)
            {
                if (m.Key == "ToString()")
                {
                    code += "\n\tpublic override string ToString(){\n";
                }
                else
                {
                    code += "\n\tpublic void " + m.Key + "{\n";
                }


                if (!config.SelfComparableParticles && m.Key.StartsWith("Calculate(" + pb.Name))
                {
                    code += "\t\tif(Particle_ID_Numer != p.Particle_ID_Numer){\n";
                    code += "\t\t\t" + m.Value;

                    if (!m.Value.EndsWith(";"))
                    {
                        code += ";";
                    }

                    code += "\n\t\t}";
                    code += "\n\t}\n";
                }
                else
                {
                    code += "\t\t" + m.Value;

                    if (!m.Value.EndsWith(";"))
                    {
                        code += ";";
                    }

                    code += "\n\t}\n";
                }
            }


            if (!pb.methods.ContainsKey("ToString()"))
            {
                code += "\n\tpublic override string ToString(){\n";

                code += "string tmp = \"" + pb.Name + "\";";

                foreach (var t in pb.properties)
                {
                    code += "tmp += \":\"+" + t.Key + ";";
                }

                code += "return tmp;";

                code += "\n\t}\n";
            }


            return(code + "}\n\n");
        }