using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Elektromagnes
{
public partial class Form1 : Form
{
CElektromagnesNurnikowy en
= new CElektromagnesNurnikowy
();
public Form1()
{
InitializeComponent();
}
private void btnZamknij_Click(object sender, EventArgs e)
{
Close();
}
private void Form1_Load(object sender, EventArgs e)
{
tbInfo.AppendText("Start.\r\n\r\n");
tbInfo.AppendText("Program do obliczania elektromagnesu nurnikowego\r\n\r\n");
tbInfo.AppendText("Projekt: Krzysztof Kurzawa\r\n");
tbInfo.AppendText("Kierunek: Mechatronika\r\n");
tbInfo.AppendText("Rok III Semestr VI\r\n");
tbInfo.AppendText("Grupa EIUM2\r\n");
tbInfo.AppendText("Nr albumu: 130790\r\n");
}
private void bImportBH_Click(object sender, EventArgs e)
{
ofdImportBH.InitialDirectory = Application.StartupPath;
if(ofdImportBH.ShowDialog()==DialogResult.OK)
{
tbInfo.AppendText("Wczytuję charakterystykę BH z pliku: " + ofdImportBH.FileName);
if (en.importBH(ofdImportBH.FileName))
{
tbInfo.AppendText("\r\nWczytano poprawnie.");
en.plotBH(chBH);
}
else
tbInfo.AppendText("\r\nNIE wczytano.");
tbInfo.AppendText("\r\nKoniec wczytywania.\r\n");
}
}
private void chBH_Click(object sender, EventArgs e)
{
}
private void chart1_Click(object sender, EventArgs e)
{
}
private void btnOblicz_Click(object sender, EventArgs e)
{
tbInfo.AppendText("Start obliczeń...\r\n");
en.Napiecie = float.Parse(tbU.Text);
tbInfo.AppendText("Napiecie:\t\t\t" + en.Napiecie.ToString() + "\t[V]\r\n");
en.Sila = float.Parse(tbF.Text);
tbInfo.AppendText("Sila:\t\t\t" + en.Sila.ToString() + "\t[N]\r\n");
en.Indukcja = float.Parse(tbB.Text);
tbInfo.AppendText("Indukcja:\t\t\t" + en.Indukcja.ToString() + "\t[T]\r\n");
en.Szczelina = float.Parse(tbx.Text);
tbInfo.AppendText("Szczelina powietrza:\t" + en.Szczelina.ToString() + "\t[m]\r\n");
en.Sn1 = (float)((float.Parse(tbF.Text) * 2 * 4 * Math.PI * Math.Pow(10, -7))/(Math.Pow(float.Parse(tbB.Text),2))) ;
tbInfo.AppendText("Pole przekroju:\t" + en.Sn1.ToString() + "\t[m^2]\r\n");
en.Dn = (float)(Math.Sqrt((4 * en.Sn1) / Math.PI));
tbInfo.AppendText("Średnica nura:\t" + en.Dn.ToString() + "\t[m]\r\n");
en.Dzew1 = (en.Dn + 2 * float.Parse(tbc.Text));
tbInfo.AppendText("Średnica zewnętrzna zwojów:\t" + en.Dzew1.ToString() + "\t[m]\r\n");
en.Dzk1 = (float)(Math.Sqrt(Math.Pow(en.Dn, 2) + Math.Pow(en.Dzew1, 2)));
tbInfo.AppendText("Średnica zewnętrzna korpusu elektromagnesu:\t" + en.Dzk1.ToString() + "\t[m]\r\n");
en.Hz = (float.Parse(tbh.Text) + 2 * float.Parse(tbhp.Text));
tbInfo.AppendText("Całkowita wysokość elektromagnesu:\t" + en.Hz.ToString() + "\t[m]\r\n");
en.Fi = (float.Parse(tbB.Text) * (en.Sn1));
tbInfo.AppendText("Strumień stały dla wszystkich punktów obwodu:\t" + en.Fi.ToString() + "\t[Wb]\r\n");
tbInfo.AppendText("Pola powierzchni przekroju w charakterystycznych punktach obwodu magnetycznego:\r\n");
en.S11 = (float)((Math.PI * Math.Pow(en.Dn, 2)) / 4);
tbInfo.AppendText("S1:\t" + en.S11.ToString() + "\t[m^2]\r\n");
en.Obliczone = true;
tbInfo.AppendText("Koniec obliczeń.\r\n");
}
private void tpStruktura_Paint(object sender, PaintEventArgs e)
{
{
int wys = tpStruktura.Height;
int szer = tpStruktura.Width;
CRysunek R1
= new CRysunek
();
R1.X1 = 10;
R1.Y1 = 10;
R1.X2 = 90;
R1.Y2 = 10;
R1.X3 = 90;
R1.Y3 = 150;
R1.X4 = 10;
R1.Y4 = 150;
Point[] obszar =
{
(new Point
((int) R1
.X1,
(int) R1
.Y1)),
(new Point
((int) R1
.X2,
(int) R1
.Y2)),
(new Point
((int) R1
.X3,
(int) R1
.Y3)),
(new Point
((int) R1
.X4,
(int) R1
.Y4))
};
double Bmax = 1.5;
double Bmin = 0.0;
double B = 0.75;
double B_kolor = 255*(B / (Bmax - Bmin));
Color kolor = Color.FromArgb(0, (int) B_kolor, 0);
Pen p1
= new Pen
(kolor,
3);
e.Graphics.DrawPolygon(p1, obszar);
Brush b1
= new SolidBrush
(kolor
);
e.Graphics.FillPolygon(b1, obszar);
}
}
private void btnZapiszRysunek_Click(object sender, EventArgs e)
{
SaveFileDialog zapiszDialog
= new SaveFileDialog
();
zapiszDialog.Filter = "Bitmap |*.bmp";
zapiszDialog.InitialDirectory = Application.StartupPath;
if (zapiszDialog.ShowDialog() == DialogResult.OK)
{
Bitmap bitmapa
= new Bitmap
(tpStruktura
.Width, tpStruktura
.Height);
tpStruktura
.DrawToBitmap(bitmapa,
new Rectangle
(0,
0, bitmapa
.Width, bitmapa
.Height));
bitmapa.Save(zapiszDialog.FileName, ImageFormat.Bmp);
}
}
}
}