示例#1
0
 public static Dowel DowelToScrew(Screw scr, Materials what, Materials wher)
 {
     foreach(Dowel dwl in Storage.dowelsDB)
     {
         switch (dwl.type) {
         case DowelType.Nail:
             //don't used this way...
             break;
         case DowelType.Butterfly:
             if (wher == Materials.GKL)
             if ((scr.lenght < (dwl.lenght / 0.8)) && (scr.lenght > (dwl.lenght * 0.8)))
             if (scr.d >= dwl.accepted_screw_d [0] && scr.d <= dwl.accepted_screw_d [dwl.accepted_screw_d.Length - 1])
                 return dwl;
             break;
         case DowelType.Standart:
             if ((scr.lenght < (dwl.lenght / 0.8)) && (scr.lenght > (dwl.lenght * 0.8)))
             if (scr.d >= dwl.accepted_screw_d [0] && scr.d <= dwl.accepted_screw_d [dwl.accepted_screw_d.Length - 1])
                 return dwl;
             break;
         }
     }
     return null;
 }
示例#2
0
		public static void ReadDataResoursesScrew ()
		{
			ScrewType type;
			float max_avulsion_force;
			float max_cut_force;
			bool is_throughwall;
			bool is_selfdrill;
			float d;
			float lenght;
			Materials[] accepted_material;
			float max_a;
			float max_s;

			string s;
			StreamReader strr = new StreamReader(GetStreamFromResource("Summer_work.Data.Screw.dat"));
			while ((s = strr.ReadLine()) != null) {
				if(s[0] == '#')
					while ((s = strr.ReadLine ()) != null && (s[0] == '#'));
				if(s == null)
					return;
				string t;
				t = s.Substring(0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);
				Summer_work.ScrewType.TryParse<Summer_work.ScrewType>(t, out type);
				t = s.Substring (0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);
				max_avulsion_force = float.Parse (t);
				t = s.Substring (0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);
				max_cut_force = float.Parse (t);
				if (s [0] == '1')
					is_throughwall = true;
				else
					is_throughwall = false;
				s = s.Remove (0, 2);
				if (s [0] == '1')
					is_selfdrill = true;
				else
					is_selfdrill = false;
				s = s.Remove (0, 2);
				t = s.Substring (0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);
				d = float.Parse (t);
				t = s.Substring (0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);
				lenght = float.Parse (t);
				t = s.Substring (0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);

				//Используя регулярные выражения (pattern - что ищем, source - где ищем):
				int sizeOfMat = new Regex (",").Matches (t).Count;
				accepted_material = new Materials[sizeOfMat+1];
				for (int i = 0; i < sizeOfMat; i++) {
					string t1 = t.Substring(0, t.IndexOf(","));
					t = t.Remove(0, t.IndexOf(",")+1);
					Materials.TryParse<Summer_work.Materials>(t1, out accepted_material[i]);

				}
				Materials.TryParse<Summer_work.Materials>(t, out accepted_material[sizeOfMat]);

				t = s.Substring (0, s.IndexOf (" "));
				s = s.Remove (0, s.IndexOf (" ") + 1);
				max_a = float.Parse (t);
				max_s = float.Parse (s);

				Screw sc = new Screw(type, max_avulsion_force, max_cut_force, is_throughwall, is_selfdrill, d, lenght, accepted_material, max_a, max_s);
				Storage.screwDB.Add(sc);
			}
		}