-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oscylogram.cs
160 lines (131 loc) · 5.25 KB
/
Oscylogram.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
namespace AnalizatorFalkowy
{
public class Oscylogram
{
private Graphics graphicsRysunek;
private Pen pen;
private RysunekSygnalu rysunekSygnalu;
private PictureBox pictureBoxRysunek;
private TrackBar zoomTrackBar;
private HScrollBar scrollBar;
private Skala skalaLiniowa;
private int czestotliwoscProbkowania;
public int CzestotliwoscProbkowania
{
get { return czestotliwoscProbkowania; }
}
public Graphics GraphicsRysunek
{
get { return graphicsRysunek; }
}
internal RysunekSygnalu RysunekSygnalu
{
get { return rysunekSygnalu; }
}
public int Pzesuniecie
{
get { return scrollBar.Value; }
}
public int Skala
{
get { return zoomTrackBar.Value; }
}
public Oscylogram(RysunekSygnalu rysunekSygnalu, PlikWave plikWave, PictureBox pictureBoxRysunek, PictureBox pbSkalaDefX, PictureBox pbSkalaDefY,
TrackBar zoomTrackBar, HScrollBar scrollBar)
{
this.rysunekSygnalu = rysunekSygnalu;
this.pictureBoxRysunek = pictureBoxRysunek;
this.zoomTrackBar = zoomTrackBar;
this.scrollBar = scrollBar;
czestotliwoscProbkowania = plikWave.CzestotliwoscProbkowania;
zoomTrackBar.Value = 0;
UstawZoom();
scrollBar.Value = 0;
UstawMaxScroll();
pen = new Pen(new SolidBrush(Color.Black));
skalaLiniowa = new SkalaOscylogram(this, plikWave, pictureBoxRysunek, pbSkalaDefX, pbSkalaDefY);
}
private void UstawZoom()
{
zoomTrackBar.Maximum = rysunekSygnalu.MaxSkala;
zoomTrackBar.Enabled = (zoomTrackBar.Maximum > 0);
}
private void UstawMaxScroll()
{
int scrollMax = rysunekSygnalu.DlugoscSygnaluZeskalowanego - pictureBoxRysunek.Width;
if (scrollMax > 0)
scrollBar.Maximum = scrollMax;
else
scrollBar.Maximum = 0;
scrollBar.Enabled = scrollBar.Maximum > 0;
}
private void UstawMaxScroll(out int staryMaxScroll)
{
staryMaxScroll = scrollBar.Maximum;
UstawMaxScroll();
}
public void Resize()
{
rysunekSygnalu.Odswiez();
skalaLiniowa.Odswiez();
UstawZoom();
UstawMaxINowaPozycjScroll();
Rysuj();
}
public void Zoom()
{
rysunekSygnalu.Skala = zoomTrackBar.Value;
skalaLiniowa.Odswiez();
UstawMaxINowaPozycjScroll();
Rysuj();
}
private void UstawMaxINowaPozycjScroll()
{
//zapisujemy wartosc scrolla ze wzgledu na to, ze przy zmianie wartosci scrolBar.Maximum na mniejsza niz scrollBar.Value
//scrollBar.Value automatycznie przyjmuje wartosc scrollBar.Maximum
int staryScroll = scrollBar.Value;
int staryMaxScroll;
UstawMaxScroll(out staryMaxScroll);
double dScroll = (scrollBar.Maximum + pictureBoxRysunek.Width) / (double)(staryMaxScroll + pictureBoxRysunek.Width);
int nowyScroll = (int)(staryScroll * dScroll);
if (nowyScroll > scrollBar.Maximum)
scrollBar.Value = scrollBar.Maximum;
else if (nowyScroll < scrollBar.Minimum)
scrollBar.Value = scrollBar.Minimum;
else
scrollBar.Value = nowyScroll;
}
public void Rysuj()
{
pictureBoxRysunek.Image = new Bitmap(pictureBoxRysunek.Width, pictureBoxRysunek.Height);
graphicsRysunek = Graphics.FromImage(pictureBoxRysunek.Image);
skalaLiniowa.Rysuj();
graphicsRysunek.DrawLines(pen, ZwrocTablicePunktowOd(scrollBar.Value));
Application.DoEvents();
}
private Point[] ZwrocTablicePunktowOd(int przesuniecie)
{
int indexStart = przesuniecie * rysunekSygnalu.IloscPunktowNaX;
while (rysunekSygnalu.Rysunek[indexStart].X < przesuniecie)
indexStart++;
int indexStop = indexStart + pictureBoxRysunek.Width * rysunekSygnalu.IloscPunktowNaX - 1;
int pictureBoxWidthMinusJeden = pictureBoxRysunek.Width - 1;
while (rysunekSygnalu.Rysunek[indexStop].X - przesuniecie < pictureBoxWidthMinusJeden)
indexStop++;
Point[] tabPoint = new Point[indexStop - indexStart];
for (int i = 0, j = indexStart; i < tabPoint.Length; i++, j++)
{
tabPoint[i].X = rysunekSygnalu.Rysunek[j].X - przesuniecie;
tabPoint[i].Y = rysunekSygnalu.Rysunek[j].Y;
}
return tabPoint;
}
}
}