Facebook
From Thundering Pintail, 4 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 210
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace Elektromagnes
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         CElektromagnesNurnikowy en = new CElektromagnesNurnikowy();
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void btnZamknij_Click(object sender, EventArgs e)
  23.         {
  24.             Close();
  25.         }
  26.  
  27.         private void Form1_Load(object sender, EventArgs e)
  28.         {
  29.             tbInfo.AppendText("Start.\r\n\r\n");
  30.             tbInfo.AppendText("Program do obliczania elektromagnesu nurnikowego\r\n\r\n");
  31.             tbInfo.AppendText("Projekt: Krzysztof Kurzawa\r\n");
  32.             tbInfo.AppendText("Kierunek: Mechatronika\r\n");
  33.             tbInfo.AppendText("Rok III Semestr VI\r\n");
  34.             tbInfo.AppendText("Grupa EIUM2\r\n");
  35.             tbInfo.AppendText("Nr albumu: 130790\r\n");
  36.         }
  37.  
  38.         private void bImportBH_Click(object sender, EventArgs e)
  39.         {
  40.             ofdImportBH.InitialDirectory = Application.StartupPath;
  41.             if(ofdImportBH.ShowDialog()==DialogResult.OK)
  42.             {
  43.                 tbInfo.AppendText("Wczytuję charakterystykę BH z pliku: " + ofdImportBH.FileName);
  44.  
  45.                 if (en.importBH(ofdImportBH.FileName))
  46.                 {
  47.                     tbInfo.AppendText("\r\nWczytano poprawnie.");
  48.                     en.plotBH(chBH);
  49.                 }
  50.                 else
  51.                     tbInfo.AppendText("\r\nNIE wczytano.");
  52.  
  53.                 tbInfo.AppendText("\r\nKoniec wczytywania.\r\n");
  54.             }
  55.         }
  56.  
  57.         private void chBH_Click(object sender, EventArgs e)
  58.         {
  59.  
  60.         }
  61.  
  62.         private void chart1_Click(object sender, EventArgs e)
  63.         {
  64.  
  65.         }
  66.  
  67.         private void btnOblicz_Click(object sender, EventArgs e)
  68.         {
  69.             tbInfo.AppendText("Start obliczeń...\r\n");
  70.  
  71.             en.Napiecie = float.Parse(tbU.Text);
  72.             tbInfo.AppendText("Napiecie:\t\t\t" + en.Napiecie.ToString() + "\t[V]\r\n");
  73.             en.Sila = float.Parse(tbF.Text);
  74.             tbInfo.AppendText("Sila:\t\t\t" + en.Sila.ToString() + "\t[N]\r\n");
  75.             en.Indukcja = float.Parse(tbB.Text);
  76.             tbInfo.AppendText("Indukcja:\t\t\t" + en.Indukcja.ToString() + "\t[T]\r\n");
  77.             en.Szczelina = float.Parse(tbx.Text);
  78.             tbInfo.AppendText("Szczelina powietrza:\t" + en.Szczelina.ToString() + "\t[m]\r\n");
  79.  
  80.            
  81.             en.Sn1 = (float)((float.Parse(tbF.Text) * 2 * 4 * Math.PI * Math.Pow(10, -7))/(Math.Pow(float.Parse(tbB.Text),2))) ;
  82.             tbInfo.AppendText("Pole przekroju:\t" + en.Sn1.ToString() + "\t[m^2]\r\n");
  83.             en.Dn = (float)(Math.Sqrt((4 * en.Sn1) / Math.PI));
  84.             tbInfo.AppendText("Średnica nura:\t" + en.Dn.ToString() + "\t[m]\r\n");
  85.             en.Dzew1 = (en.Dn + 2 * float.Parse(tbc.Text));
  86.             tbInfo.AppendText("Średnica zewnętrzna zwojów:\t" + en.Dzew1.ToString() + "\t[m]\r\n");
  87.             en.Dzk1 = (float)(Math.Sqrt(Math.Pow(en.Dn, 2) + Math.Pow(en.Dzew1, 2)));
  88.             tbInfo.AppendText("Średnica zewnętrzna korpusu elektromagnesu:\t" + en.Dzk1.ToString() + "\t[m]\r\n");
  89.             en.Hz = (float.Parse(tbh.Text) + 2 * float.Parse(tbhp.Text));
  90.             tbInfo.AppendText("Całkowita wysokość elektromagnesu:\t" + en.Hz.ToString() + "\t[m]\r\n");
  91.             en.Fi = (float.Parse(tbB.Text) * (en.Sn1));
  92.             tbInfo.AppendText("Strumień stały dla wszystkich punktów obwodu:\t" + en.Fi.ToString() + "\t[Wb]\r\n");
  93.             tbInfo.AppendText("Pola powierzchni przekroju w charakterystycznych punktach obwodu magnetycznego:\r\n");
  94.             en.S11 = (float)((Math.PI * Math.Pow(en.Dn, 2)) / 4);
  95.             tbInfo.AppendText("S1:\t" + en.S11.ToString() + "\t[m^2]\r\n");
  96.  
  97.  
  98.  
  99.  
  100.             en.Obliczone = true;
  101.  
  102.             tbInfo.AppendText("Koniec obliczeń.\r\n");
  103.         }
  104.  
  105.         private void tpStruktura_Paint(object sender, PaintEventArgs e)
  106.         {
  107.            
  108.             {
  109.                 int wys = tpStruktura.Height;
  110.                 int szer = tpStruktura.Width;
  111.                
  112.  
  113.                 CRysunek R1 = new CRysunek();
  114.                 R1.X1 = 10;
  115.                 R1.Y1 = 10;
  116.                 R1.X2 = 90;
  117.                 R1.Y2 = 10;
  118.                 R1.X3 = 90;
  119.                 R1.Y3 = 150;
  120.                 R1.X4 = 10;
  121.                 R1.Y4 = 150;
  122.                
  123.                 Point[] obszar =
  124.                 {  
  125.                     (new Point((int) R1.X1, (int) R1.Y1)),
  126.                     (new Point((int) R1.X2, (int) R1.Y2)),
  127.                     (new Point((int) R1.X3, (int) R1.Y3)),
  128.                     (new Point((int) R1.X4, (int) R1.Y4))
  129.                 };
  130.  
  131.                 double Bmax = 1.5;
  132.                 double Bmin = 0.0;
  133.  
  134.                 double B = 0.75;
  135.                 double B_kolor = 255*(B / (Bmax - Bmin));
  136.  
  137.  
  138.                 Color kolor = Color.FromArgb(0, (int) B_kolor, 0);
  139.  
  140.                 Pen p1 = new Pen(kolor, 3);
  141.  
  142.                 e.Graphics.DrawPolygon(p1, obszar);
  143.  
  144.                
  145.                 Brush b1 = new SolidBrush(kolor);
  146.                 e.Graphics.FillPolygon(b1, obszar);
  147.  
  148.  
  149.             }
  150.         }
  151.  
  152.         private void btnZapiszRysunek_Click(object sender, EventArgs e)
  153.         {
  154.             SaveFileDialog zapiszDialog = new SaveFileDialog();
  155.             zapiszDialog.Filter = "Bitmap |*.bmp";
  156.             zapiszDialog.InitialDirectory = Application.StartupPath;
  157.             if (zapiszDialog.ShowDialog() == DialogResult.OK)
  158.             {
  159.                 Bitmap bitmapa = new Bitmap(tpStruktura.Width, tpStruktura.Height);
  160.                 tpStruktura.DrawToBitmap(bitmapa, new Rectangle(0, 0, bitmapa.Width, bitmapa.Height));
  161.                 bitmapa.Save(zapiszDialog.FileName, ImageFormat.Bmp);
  162.             }
  163.         }
  164.     }
  165. }
  166.