Skip to content

Instantly share code, notes, and snippets.

@dj1711572002
Created September 20, 2022 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj1711572002/ec9a51146b71d2650f44ca53a81a0b37 to your computer and use it in GitHub Desktop.
Save dj1711572002/ec9a51146b71d2650f44ca53a81a0b37 to your computer and use it in GitHub Desktop.
C# RTK_Trace Plot Viewer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Diagnostics;
using Microsoft.VisualBasic.FileIO;
using static System.Windows.Forms.AxHost;
namespace ITP_LPS_rev013
{
public partial class Form1 : Form
{
const int blen = 3000;//処理データ単位3000行を1ブロックにしてBitmapメモリー節約
int rN;
int rowN;//dgv rowCount
String fname;
public double[] f;
public double[] fout;
public double [] fkekka;
//
int[,] dgv=new int[30000,16];
//bitmap definition
//picturebox size-----------
const int pic1w = 1000;
const int pic1h = 500;
const int pic2w = 500;
const int pic2h = 500;
const int pic3w = 500;
const int pic3h = 500;
const int bw = blen;//180000 ;
const int xysize = 10000;
Bitmap sourceBitmap = new Bitmap(bw, pic1h);//X軸bw個 data(10msec周期で300秒) Y軸
Bitmap trimmedBitmap = new Bitmap(pic1w, pic1h);//PictuerBox1に貼りこむBitmap
Bitmap xyBitmap = new Bitmap(xysize, xysize);//xyプロットのソース
Bitmap p2Bitmap = new Bitmap(pic2w,pic2h);//picturebox2のBitmap
Bitmap p3Bitmap = new Bitmap(pic3w, pic3h);//picturebox2のBitmap
//-XYPLOT-----------------
double scalex, scaley;
double scale0 = 1;
int blockn = 0;//データブロックNo ComboBox7のINDEX値
int blockn_1 = 0;//1個前のブロックNo
long lonW, latH;
long [] maxlon =new long [10];
long [] minlon =new long[10];
long [] maxlat = new long[10];
long [] minlat = new long[10];
int a =1;
int a_1 = 1;
double wheelPos = 0;// Mouse Wheel Position
double wheelVal;
//-------------------データブロック構造体----------------------------
public struct data_block
{
public int blockSize;
public int blockNo;
public int startRow;
public int endRow;
public long maxlon;
public long minlon;
public long maxlat;
public long minlat;
public long lonW;//全幅
public long latH;//全高
}
data_block[] dbk;
int alln;//全ブロック数
//--------------------------------------------------------------------
//----------------------------------------------------------------
//ComboBoxArray
private System.Windows.Forms.ComboBox[] CBarry;
//CheckBox Arry
private System.Windows.Forms.CheckBox[] CKarry;
//picturebox2
int cp2x, cp2y;//Mouse座標
//Struct GraphLine
public Color []samples= new Color[] { Color.Red, Color.Blue, Color.Green ,Color.Yellow,Color.Aqua,Color.DeepPink,Color.BlanchedAlmond};
struct lines
{
public string name;//LIne名 選択されたデータ名
public bool available;//Lineが有効:true 無効:false
public int colN;//Column番号
public Color clr;
public int sa;//data 間隔
public int rN_avail;
public int period;
public int x;
public int x_1;
public int y;
public int y_1;
public int max;
public int min;
public int baseL;//Graph base Line 1/2 1/1
public int uscale;//headMot=100000
}
lines[] gline;//gline global
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.BaudRate = 115200;
serialPort1.Parity = Parity.None;
serialPort1.DataBits = 8;
serialPort1.StopBits = StopBits.One;
serialPort1.Handshake = Handshake.None;
serialPort1.PortName = portComboBox.Text;
serialPort1.Open();
//file name timestanmp
DateTime dt = DateTime.Now;
fname = dt.ToString($"{dt:MMddHHmm}");
string fpath = "C:/RTK_LOG/";
fname = fpath + fname + ".csv";
textBox2.Text = fname;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "ITP_LPS_rev013";
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
portComboBox.Items.Add(port);
}
if (portComboBox.Items.Count > 0)
{
portComboBox.SelectedIndex = 0;
}
rN = 0;
//---------------------------------
// this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseWheel);
//comboBox7 MovingAverage 初期値0
//comboBox配列で一括定義------------------------------
this.CBarry = new System.Windows.Forms.ComboBox[6];
this.CKarry = new System.Windows.Forms.CheckBox[6];
//ボタンコントロールの配列にすでに作成されているインスタンスを代入
this.CBarry[0] = this.comboBox1;
this.CBarry[1] = this.comboBox2;
this.CBarry[2] = this.comboBox3;
this.CBarry[3] = this.comboBox4;
this.CBarry[4] = this.comboBox5;
this.CBarry[5] = this.comboBox6;
//チェックボックス配列
this.CKarry[0] = this.checkBox2;
this.CKarry[1] = this.checkBox3;
this.CKarry[2] = this.checkBox4;
this.CKarry[3] = this.checkBox5;
this.CKarry[4] = this.checkBox6;
this.CKarry[5] = this.checkBox7;
//combobox color
// comboBox1.BackColor = Color.Red;
int ia;
for (ia = 0; ia <6; ia++)
{
CBarry[ia].BackColor=samples[ia];
CBarry[ia].Items.Add("無し");
CBarry[ia].Items.Add("No");
CBarry[ia].Items.Add("itow");
CBarry[ia].Items.Add("f9p_gSpeed(10Hz)");
CBarry[ia].Items.Add("f9p_gSpeed(50Hz)");
CBarry[ia].Items.Add("f9p_headMot(10Hz)");
CBarry[ia].Items.Add("f9p_headMot(50Hz)");
CBarry[ia].Items.Add("lon(10Hz)");
CBarry[ia].Items.Add("lon(50Hz)");
CBarry[ia].Items.Add("lat(10Hz)");
CBarry[ia].Items.Add("lat(50Hz)");
CBarry[ia].Items.Add("f9p_velN(10Hz)");
CBarry[ia].Items.Add("f9p_velN(50Hz)");
CBarry[ia].Items.Add("f9p_velE(10Hz)");
CBarry[ia].Items.Add("f9p_velE(50Hz)");
CBarry[ia].Items.Add("f9p_velD(10Hz)");
CBarry[ia].Items.Add("f9p_velD(50Hz)");
CBarry[ia].Items.Add("flags");
CBarry[ia].Items.Add("hacc");
CBarry[ia].Items.Add("m9n_gSpeed(25Hz)");
CBarry[ia].Items.Add("m9n_gSpeed(50Hz)");
CBarry[ia].Items.Add("m9n_headMot(25Hz)");
CBarry[ia].Items.Add("m9n_headMot(50Hz)");
CBarry[ia].Items.Add("m9n_velN(25Hz)");
CBarry[ia].Items.Add("m9n_velN(50Hz)");
CBarry[ia].Items.Add("m9n_velE(25Hz)");
CBarry[ia].Items.Add("m9n_velE(50Hz)");
CBarry[ia].Items.Add("m9n_velD(25Hz)");
CBarry[ia].Items.Add("m9n_velD(50Hz)");
//MA
CBarry[ia].Items.Add("m9n_gSpeed_MA(25Hz)");
CBarry[ia].Items.Add("m9n_gSpeed_MA(50Hz)");
CBarry[ia].Items.Add("m9n_headMot_MA(25Hz)");
CBarry[ia].Items.Add("m9n_headMot_MA(50Hz)");
CBarry[ia].Items.Add("m9n_velN_MA(25Hz)");
CBarry[ia].Items.Add("m9n_velN_MA(50Hz)");
CBarry[ia].Items.Add("m9n_velE_MA(25Hz)");
CBarry[ia].Items.Add("m9n_velE_MA(50Hz)");
CBarry[ia].Items.Add("m9n_velD_MA(25Hz)");
CBarry[ia].Items.Add("m9n_velD_MA(50Hz)");
CBarry[ia].SelectedIndex = 0;
}
//Mouse Wheel
this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
label5.Text = "1";
 
}
private void Form1_MouseWheel(object sender, MouseEventArgs e)
{
double stepplus = 0.2;
double stepminus1 = -0.5;
double stepminus = -0.1;
if (e.Delta > 0)//拡大倍率 1>wheelVal
{
//wheelVal =(e.Delta/120 + Convert.ToInt32(label4.Text));
wheelVal = (stepplus + Convert.ToDouble(label5.Text));
}
else if (e.Delta < 0)//縮小倍率 1< wheelVal
{
wheelVal =(stepminus + Convert.ToDouble(label5.Text) );
if (wheelVal <= 0)
{
wheelVal = 0.01 ;
}
else
{
wheelVal = wheelVal;
}
}
else if (e.Delta==0)
{
// label4.Text = "1";
}
Debug.Print("e.Delta="+e.Delta.ToString()+",wheelVal=" + wheelVal.ToString());
//label4.Text ="倍率";
label5.Text = wheelVal.ToString("n2");
}
private void name2gline(int comN)
{
string name= CBarry[comN].Text;
gline[comN].name = name;
gline[comN].clr = samples[comN];
gline[comN].available = true;
gline[comN].max = 10000;
gline[comN].min = -10000;
gline[comN].baseL = 2;
gline[comN].uscale = 1;
int coln= 0;
if (name == "無し") { gline[comN].colN = -1;gline[comN].available = false; }
if (name == "No") { gline[comN].colN = 0; }
if (name == "itow") { gline[comN].colN = 1; }
if (name == "f9p_gSpeed(10Hz)") { gline[comN].colN = 2; gline[comN].sa = 5;gline[comN].period = 100; }
if (name == "f9p_gSpeed(50Hz)") { gline[comN].colN = 2; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "f9p_headMot(10Hz)") { gline[comN].colN = 3; gline[comN].sa = 5; gline[comN].period = 100;gline[comN].max = 36000000; gline[comN].min = 0;gline[comN].baseL = 1; gline[comN].uscale = 100000; }
if (name == "f9p_headMot(50Hz)") { gline[comN].colN = 3; gline[comN].sa = 1; gline[comN].period = 20;gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; }
if (name == "lon(10Hz)") { gline[comN].colN = 4; gline[comN].sa = 5; gline[comN].period = 100; }
if (name == "lon(50Hz)") { gline[comN].colN = 4; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "lat(10Hz)") { gline[comN].colN = 5; gline[comN].sa = 5; gline[comN].period = 100; }
if (name == "lat(50Hz)") { gline[comN].colN = 5; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "f9p_velN(10Hz)") { gline[comN].colN = 6; gline[comN].sa = 5; gline[comN].period = 100; }
if (name == "f9p_velN(50Hz)") { gline[comN].colN = 6; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "f9p_velE(10Hz)") { gline[comN].colN = 7; gline[comN].sa = 5; gline[comN].period = 100; }
if (name == "f9p_velE(50Hz)") { gline[comN].colN = 7; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "f9p_velD(10Hz)") { gline[comN].colN = 8; gline[comN].sa = 5; gline[comN].period = 100; }
if (name == "f9p_velD(50Hz)") { gline[comN].colN = 8; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "flags") { gline[comN].colN = 9;}
if (name == "hacc") { gline[comN].colN = 10; }
if (name == "m9n_gSpeed(25Hz)") { gline[comN].colN = 11; gline[comN].sa = 2; gline[comN].period =40; }
if (name == "m9n_gSpeed(50Hz)") { gline[comN].colN = 11; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "m9n_headMot(25Hz)") { gline[comN].colN = 12; gline[comN].sa = 2; gline[comN].period = 40; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; }
if (name == "m9n_headMot(50Hz)") { gline[comN].colN = 12; gline[comN].sa = 1; gline[comN].period = 20; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; }
if (name == "m9n_velN(25Hz)") { gline[comN].colN = 13; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_velN(50Hz)") { gline[comN].colN = 13; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "m9n_velE(25Hz)") { gline[comN].colN = 14; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_velE(50Hz)") { gline[comN].colN = 14; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "m9n_velD(25Hz)") { gline[comN].colN = 15; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_velD(50Hz)") { gline[comN].colN = 15; gline[comN].sa = 1; gline[comN].period = 20; }
//MA
if (name == "m9n_gSpeed_MA(25Hz)") { gline[comN].colN = 16; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_gSpeed_MA(50Hz)") { gline[comN].colN = 16; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "m9n_headMot_MA(25Hz)") { gline[comN].colN = 17; gline[comN].sa = 2; gline[comN].period = 40; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; }
if (name == "m9n_headMot_MA(50Hz)") { gline[comN].colN = 17; gline[comN].sa = 1; gline[comN].period = 20; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; }
if (name == "m9n_velN_MA(25Hz)") { gline[comN].colN = 18; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_velN_MA(50Hz)") { gline[comN].colN = 18; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "m9n_velE_MA(25Hz)") { gline[comN].colN = 19; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_velE_MA(50Hz)") { gline[comN].colN = 19; gline[comN].sa = 1; gline[comN].period = 20; }
if (name == "m9n_velD_MA(25Hz)") { gline[comN].colN = 20; gline[comN].sa = 2; gline[comN].period = 40; }
if (name == "m9n_velD_MA(50Hz)") { gline[comN].colN = 20; gline[comN].sa = 1; gline[comN].period = 20; }
}
private void button5_Click(object sender, EventArgs e)
{
//*******************************************************************************************************************
// BryantFilter2(double[] f,double []fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs)
//*******************************************************************************************************************
//Input Array making 11:M9N_gSpeed,12:M9N_headMot,13:M9N_velN,14:M9N_velE,15:M9N_velD
int i,j,k, n;
int l = 0;
int m = 0;
int roN = dgv1.RowCount;
f = new double[roN];//Globalで定義
fout= new double[roN];//Globalで定義
fkekka = new double[rowN];//Globalで定義
int fc = Convert.ToInt32(textBox12.Text);// 2;//CUt off Hz
int fs = Convert.ToInt32(textBox11.Text);//25;//Sampling Hz
for (i = 11; i < 16; i++)//列カウンタ//M9N 11=gSpeed,12=headMot,13=velN,14=velE,15=velD
{
m = 0;
for (j = 0; j < roN - 1; j++)//f配列作成
{
int itow = Convert.ToInt32(dgv1.Rows[j].Cells[1].Value);
if (itow % 40 == 0)//25Hzデータ抽出
{
f[m] = Convert.ToDouble(dgv1.Rows[j].Cells[i].Value);
double dummy = f[m];
// Debug.Print("Make:f[" + m.ToString() + ",0]=" + f[m, 0].ToString());
m++;
}
}
//BryantFilter2(double[] f,double []fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs)
BryantFilter2(f, fout, 1, m - 1, 0, 1, fc, fs);
Debug.Print("Filter Finished m-1=" + (m - 1).ToString());
int mi = 0;
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
for (l = 0; l < roN; l++)
{
int itow = Convert.ToInt32(dgv1.Rows[l].Cells[1].Value);
if (itow % 40 == 0)
{
int ifout = Convert.ToInt32(fout[mi]);
dgv1.Rows[l].Cells[i + 5].Value =ifout.ToString();
//Debug.Print("Kekka:fout[" + l.ToString() + "]=" + fout[mi].ToString() + "fkekka=" + fkekka[mi].ToString());
mi++;
}
}
}
// ====================積分機能========================================================
if(checkBox9.Checked==true)
{
int ii, jj;
double dt = 0.02;
for(ii=2;ii<dgv1.RowCount-1;ii++)
{
//M9N filter 20msec補間
if (Convert.ToInt32(dgv1.Rows[ii].Cells[1].Value)%40==20)
{
//M9N_gSpeed_MA(Filtered)
int val_1 = Convert.ToInt32(dgv1.Rows[ii - 1].Cells[16].Value);
int val_2= Convert.ToInt32(dgv1.Rows[ii + 1].Cells[16].Value);
dgv1.Rows[ii].Cells[16].Value =((val_2-val_1)/2+val_1).ToString();
// M9N_headMot_MA(Filtered)
val_1 = Convert.ToInt32(dgv1.Rows[ii - 1].Cells[17].Value);
val_2 = Convert.ToInt32(dgv1.Rows[ii + 1].Cells[17].Value);
dgv1.Rows[ii].Cells[17].Value = ((val_2 - val_1) / 2 + val_1).ToString();
//M9N_velN_MA(Filtered)
val_1 = Convert.ToInt32(dgv1.Rows[ii - 1].Cells[18].Value);
val_2 = Convert.ToInt32(dgv1.Rows[ii + 1].Cells[18].Value);
dgv1.Rows[ii].Cells[18].Value = ((val_2 - val_1) / 2 + val_1).ToString();
//M9N_velE_MA(Filtered)
val_1 = Convert.ToInt32(dgv1.Rows[ii - 1].Cells[19].Value);
val_2 = Convert.ToInt32(dgv1.Rows[ii + 1].Cells[19].Value);
dgv1.Rows[ii].Cells[19].Value = ((val_2 - val_1) / 2 + val_1).ToString();
//M9N_velD_MA(Filtered)
val_1 = Convert.ToInt32(dgv1.Rows[ii - 1].Cells[20].Value);
val_2 = Convert.ToInt32(dgv1.Rows[ii + 1].Cells[20].Value);
dgv1.Rows[ii].Cells[20].Value = ((val_2 - val_1) / 2 + val_1).ToString();
}
//f9p_gSpeed
dgv1.Rows[ii].Cells[21].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[2].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[2].Value)) / 2 * dt).ToString();
//f9p?velN
dgv1.Rows[ii].Cells[22].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[6].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[6].Value)) / 2 * dt).ToString();
//f9p_velE
dgv1.Rows[ii].Cells[23].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[7].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[7].Value)) / 2 * dt).ToString();
//f9p_velD
dgv1.Rows[ii].Cells[24].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[8].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[8].Value)) / 2 * dt).ToString();
//M9N_gSpped
dgv1.Rows[ii].Cells[25].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[16].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[16].Value)) / 2 * dt).ToString();
//M9N_velN
dgv1.Rows[ii].Cells[26].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[18].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[18].Value)) / 2 * dt).ToString();
//M9N_velE
dgv1.Rows[ii].Cells[27].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[19].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[19].Value)) / 2 * dt).ToString();
//M9N_velD
dgv1.Rows[ii].Cells[28].Value = ((Convert.ToDouble(dgv1.Rows[ii].Cells[20].Value) + Convert.ToDouble(dgv1.Rows[ii - 1].Cells[20].Value)) / 2 * dt).ToString();
}
}
}//button5 filter
//=======================================================================================
//=======================Low Pass Filter=================================================
//=======================================================================================
//private void BryantFilter2(double[,] f,double [,]fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs)
private void BryantFilter2(double[] f, double []fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs)
{
int i, j;
double[] temp = new double[rowmax];
for(i=rowmin;i<rowmax;i++)
{
for (j = colmin; j <= colmax; j++)
{
temp[i] = f[i];
fout[i] = f[i];
// Debug.Print("temp[" + i.ToString() + ",0]=" + temp[i, 0].ToString());
}
}
//Bryant のバターワースフィルタ,臨床歩行分析入門より
double FF,W,B,c,D;
FF = fc / fs;
W = Math.Tan(3.14159 * FF);
B = 1 + Math.Sqrt(2) * W + W * W;
c = 2 * (1 - W * W) / B;
D = -(1 - Math.Sqrt(2) * W + W * W) / B;
j =0;
for (i = rowmin + 2; i < rowmax-1; i ++)
{
fout[i] = (temp[i] + 2 * temp[i - 1] + temp[i - 2]) * W *W / B + c * fout[i - 1] + D * fout[i - 2];
// Debug.Print("InFilter:temp["+i.ToString()+","+j.ToString()+"]=" + temp[i].ToString() + ",fout["+i.ToString()+"]=" + fout[i].ToString());
}
Debug.Print("Pass1"+"rowmax="+rowmax.ToString());
//反対側からもう一度
for (i = rowmin; i < rowmax; i++)
{
j = 0;
temp[i] = fout[i];
}
for( i = rowmax -3;i> rowmin;i--)
{
fout[i] = (temp[i] + 2 * temp[i + 1] + temp[i + 2]) * W * W / B + c * fout[i + 1] + D * fout[i + 2];
fkekka[i] = fout[i];
// Debug.Print("GyakunFilter:temp[" + i.ToString()+ "]=" + temp[i].ToString() + ",fout[]=" + fout[i].ToString(), "fkekka=" + fkekka[i].ToString());
}
}// BryantFileter END=================================================================
//====================================================================================
//private void countCombo(int[] LiN, int[] sa)
private void countCombo()
{
//構造体
this.gline = new lines[6];
int icom;//combobox No
for (icom = 0; icom < 6; icom++)
{
if (CBarry[icom].SelectedIndex > 0)
{
gline[icom].available = true;
name2gline(icom);
// richTextBox1.AppendText(gline[icom].name + ","+gline[icom].colN+","+gline[icom].sa+","+gline[icom].period+","+"\r");
}
else
{
gline[icom].available = false;
}
}
}
// button 2で、グラフ
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
ReadDialog();
}
delegate void SetTextCallback(string text);
private void Response(string text)
{
if (textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(Response);
BeginInvoke(d, new object[] { text });
}
else
{
// textBox1.AppendText(text + "\n");
//===============データグリッドビュー dgv1へ記録===================
// string[] data =( text+",\n").Split(',');//カンマ区切りにばらす
string[] data = text.Split(',');//カンマ区切りにばらす
int cN = 21;// data.Length16+5;
//data[] to string
int iN;
string datas = "";
for (iN = 0; iN < cN; iN++)
{
datas = datas + "," + data[iN];
// Debug.Print("data[" + iN.ToString() + "]=" + data[iN]);
}
datas = datas + "\r\n";
// Debug.Print("rN=" + rN.ToString()+"text=" + datas);
// 自動csv保存 書き込むファイルが既に存在している場合は、Appendする
System.IO.StreamWriter sw = new System.IO.StreamWriter(@fname, true, System.Text.Encoding.GetEncoding("shift_jis"));
//TextBox1.Textの内容を書き込む
sw.Write(datas);
//閉じる
sw.Close();
if (rN == 0)//行カウントrN==0のときdgv1定義
{
//dgv1.DefaultCellStyle.Font = new Font("Tahoma", 10);
//dgv1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
dgv1.ColumnCount = cN;
dgv1.RowCount = 2;
dgv1.RowHeadersWidth = 100;
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
// dgv1.Columns[0].DefaultCellStyle.Alignment =DataGridViewContentAlignment.TopLeft;
}
rN++;
dgv1.FirstDisplayedScrollingRowIndex = rN;
dgv1.Rows.Add(data);//dgv1書き込み
dgv1.Rows[rN].HeaderCell.Value = rN.ToString();
//=================================================================
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
serialPort1.NewLine = "\r\n";
string str = serialPort1.ReadLine();
Response(str);
}
private void button3_Click(object sender, EventArgs e)
{
serialPort1.Close();
}
//****************************************************************************************************************
//****************************************************************************************************************
//==================Open File Dialog READ FILE==============================
//****************************************************************************************************************
//****************************************************************************************************************
private void ReadDialog()
{
int irn = 0;
int icn = 0;
//sourceBitmap_clear();
//OpenFileDialogクラスのインスタンスを作成
OpenFileDialog ofd = new OpenFileDialog();
//ダイアログを表示する
if (ofd.ShowDialog() == DialogResult.OK)
{
// DataGridView初期化(データクリア)
dgv1.Columns.Clear();
dgv1.Rows.Clear();
// dgv1 set
dgv1.ColumnCount = 29;
dgv1.RowCount = 2;
dgv1.RowHeadersWidth = 80;
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
headerName();
rowN = 0;
//OKボタンがクリックされたとき、選択されたファイルを読み取り専用で開く
textBox2.Text = ofd.FileName;
using (var parser = new TextFieldParser(ofd.FileName))////@"C:\Test\car1.csv"))
{
parser.Delimiters = new string[] { "," };
while (!parser.EndOfData)
{
//Console.WriteLine("-----");
string[] fields;
fields = parser.ReadFields();
rowN++;
//string sf = fields.ToString();
//string[] sdata=fields.Split(",");
int colsize = fields.Length;
int colcount;
for (colcount = 0; colcount < colsize; colcount++)
{
dgv[rowN, colcount] = Convert.ToInt32(fields[colcount]);
}
// dgv[rowN,]
if (checkBox1.Checked == true)
{
dgv1.Rows.Add(fields);//dgv1書き込み
dgv1.Rows[rowN].HeaderCell.Value = rowN.ToString();
}
}
label1.Text = "dgvRows=" + rowN.ToString();
}
}
//-----data_block 宣言------------------------------------
alln = Convert.ToInt32(Math.Ceiling((double)rowN / blen));
dbk = new data_block[alln+2];
long celval4, celval5;
//==================================================================================
//=========================構造体 初期値 入力=====================================
//==================================================================================
int bn;
for (bn = 1; bn < alln+1; bn++)
{
// a = Convert.ToInt32(Math.Ceiling((double)irn / blen));//aはブロックNO、切り上げてカウント0-3000はブロックNo=1
dbk[bn].blockSize = blen;
dbk[bn].blockNo = bn;
if (bn == 1)
{
dbk[bn].startRow = 1;
Debug.Print("dbk[" + bn.ToString() + "].startRow=" + dbk[bn].startRow);
}
else
{
dbk[bn].startRow = (bn - 1) * blen;
Debug.Print("dbk[" + bn.ToString() + "].startRow=" + dbk[bn].startRow);
}
if (bn <alln)
{
dbk[bn].endRow = bn * blen - 1;
}
else
{
dbk[bn].endRow =rowN-1;
}
Debug.Print("dbk[" + bn.ToString() + "].endRow=" + dbk[bn].endRow);
dbk[bn].maxlon = 0;
dbk[bn].minlon = 10000000000;
dbk[bn].maxlat = 0;
dbk[bn].minlat = 10000000000;
//combobox7 set
comboBox7.Items.Add(bn.ToString());
}
//-------------------------------------------------------------------------------
for (bn = 1; bn < alln+1; bn++)
{
for (irn = dbk[bn].startRow; irn < dbk[bn].endRow + 1; irn++)//行スキャン
{
celval4 = dgv[irn, 4];
celval5 = dgv[irn, 5];
if (dbk[bn].maxlon < celval4) { dbk[bn].maxlon = celval4; }
if (dbk[bn].minlon > celval4) { dbk[bn].minlon = celval4; }
if (dbk[bn].maxlat < celval5) { dbk[bn].maxlat = celval5; }
if (dbk[bn].minlat > celval5) { dbk[bn].minlat = celval5; }
}
Debug.Print("dbk["+ bn.ToString() + "].maxlon=" + dbk[bn].maxlon + ",dbk[].minlon=" + dbk[bn].minlon);
Debug.Print("dbk["+bn.ToString() + "].maxlat=" + dbk[bn].maxlat + ",dbk[].minlat=" + dbk[bn].minlat);
}
int ia;
//last Allblock ---------------
dbk[alln + 1].startRow = 1;
dbk[alln + 1].endRow = rowN - 1;
dbk[alln + 1].maxlon = 0;
dbk[alln + 1].minlon = 10000000000;
dbk[alln + 1].maxlat = 0;
dbk[alln + 1].minlat = 100000000000;
comboBox7.Items.Add((alln + 1).ToString());
Debug.Print("dbk[" + (alln + 1).ToString() + "].startRow=" + dbk[alln + 1].startRow);
Debug.Print("dbk[" + (alln + 1).ToString() + "].endRow=" + dbk[alln + 1].endRow);
for (ia = 1; ia <alln+1; ia++)
{
//lon max min
if (dbk[ia].maxlon> dbk[alln+1].maxlon) { dbk[alln+1].maxlon = dbk[ia].maxlon; }
if (dbk[ia].minlon < dbk[alln+1].minlon) { dbk[alln+1].minlon = dbk[ia].minlon; }
//lat max min
if (dbk[ia].maxlat> dbk[alln+1].maxlat) { dbk[alln+1].maxlat = dbk[ia].maxlat; }
if (dbk[ia].minlat < dbk[alln+1].minlat) { dbk[alln+1].minlat = dbk[ia].minlat; }
}
//------lonW latH -------------------------
for (ia = 1; ia < alln + 2; ia++)
{
dbk[ia].lonW = dbk[ia].maxlon - dbk[ia].minlon;
dbk[ia].latH = dbk[ia].maxlat - dbk[ia].minlat;
}
// All result
Debug.Print("All:dbk[alln+1].maxlon[" + (alln+1).ToString() + "]=" + dbk[alln+1].maxlon.ToString() + ",dbk[alln+1].minlon=" + dbk[alln+1].minlon.ToString());
Debug.Print("All:dbk[alln+1].maxlat[" + (alln+1).ToString() + "]=" + dbk[alln+1].maxlat.ToString() + ",dbk[alln+1].minlat=" + dbk[alln+1].minlat.ToString());
// Debug.Print("All:maxlat[" + (amax+1).ToString() + "]=" + maxlat[amax+1].ToString() + ",minlat[]=" + minlat[amax+1].ToString());
// comboBox7.Items.Add(amax.ToString());
//lonW = maxlon[(rowN/blen)-1] - minlon[(rowN / blen) - 1];
//latH = maxlat[(rowN / blen) - 1] - minlat[(rowN / blen) - 1];
//label2.Text = "lonW="+lonW.ToString();
//label3.Text = "latH=" + latH.ToString();
// label4.Text = "";
//label5.Text = "";
}//File read End  *******************************************************************************************************************
//**********************************************************************************************************************:::
//***************************************************************************************************************************
//--readDialog() end-----------------------------------------------------------------------------------------------------
//======================================================
//===========dgvSave===================================
//====================================================
private void dgvsave()
{
int i,j;
//Filename Timestamp
DateTime dt = DateTime.Now;
string fn = dt.ToString($"{dt:MMddHHmmss}");
string fnstrng="c:/RTK_Log/dgv_"+fn+".csv";
string hdstrng= "c:/RTK_Log/head_" + fn + ".csv";
int dgvron = dgv1.RowCount;
int dgvcln = dgv1.ColumnCount;
Debug.Print("dgvron=" + dgvron.ToString() + ",dgvcln=" + dgvcln.ToString());
using (StreamWriter sw = new StreamWriter(@fnstrng, false, Encoding.UTF8))
{
for (i = 1; i < dgvron-1; i++)
{
string dgvrow = "";
for (j = 0; j < dgvcln; j++)
{
dgvrow = dgvrow + dgv1.Rows[i].Cells[j].Value+",";
}
sw.WriteLine(dgvrow);
}
}
//-----------HeaderText save----------------------
if (checkBox8.Checked == true)
{
using (StreamWriter sw = new StreamWriter(@hdstrng, false, Encoding.UTF8))
{
string dgvhead = "";
for (j = 0; j < dgvcln; j++)
{
dgvhead = dgvhead + dgv1.Columns[j].HeaderCell.Value+",";
//Debug.Print("i=" + i.ToString() + ",dgvhead=" + dgvhead);
}
sw.WriteLine(dgvhead);
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
// pictureBox1.Visible = false;
dgv1.Visible = true;
}
else
{
dgv1.Visible = false;
//pictureBox1.Visible = true;
}
}
private void headerName()
{
{
dgv1.ColumnHeadersDefaultCellStyle.Font = new Font(dgv1.Font, FontStyle.Bold);
//DataGridView1の行ヘッダーに行番号を表示する
dgv1.Columns[0].HeaderText = "No";
dgv1.Columns[1].HeaderText = "itow";
dgv1.Columns[2].HeaderText = "f9p_gSpeed";
dgv1.Columns[3].HeaderText = "f9p_headMot";
dgv1.Columns[4].HeaderText = "lon";
dgv1.Columns[5].HeaderText = "lat";
dgv1.Columns[6].HeaderText = "f9p_velN";
dgv1.Columns[7].HeaderText = "f9p_velE";
dgv1.Columns[8].HeaderText = "f9p_velD";
dgv1.Columns[9].HeaderText = "flags";
dgv1.Columns[10].HeaderText = "hacc";
dgv1.Columns[11].HeaderText = "m9n_gSpeed";
dgv1.Columns[12].HeaderText = "m9n_headMot";
dgv1.Columns[13].HeaderText = "m9n_velN";
dgv1.Columns[14].HeaderText = "m9n_velE";
dgv1.Columns[15].HeaderText = "m9n_velD";
dgv1.Columns[16].HeaderText = "m9n_gSpeed_MA";
dgv1.Columns[17].HeaderText = "m9n_headMot_MA";
dgv1.Columns[18].HeaderText = "m9n_velN_MA";
dgv1.Columns[19].HeaderText = "m9n_velE_MA";
dgv1.Columns[20].HeaderText = "m9n_velD_MA";
//
dgv1.Columns[21].HeaderText = "igr_f9p_gSpeed";
dgv1.Columns[22].HeaderText = "igr_f9p_velN";
dgv1.Columns[23].HeaderText = "igr_f9p_velE";
dgv1.Columns[24].HeaderText = "igr_f9p_velD";
dgv1.Columns[25].HeaderText = "igr_m9n_gSpeed_MA";
dgv1.Columns[26].HeaderText = "igr_m9n_velN_MA";
dgv1.Columns[27].HeaderText = "igr_m9n_velE_MA";
dgv1.Columns[28].HeaderText = "igr_m9n_velD_MA";
//ヘッダーとすべてのセルの内容に合わせて、列の幅を自動調整する
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
int i;
for (i = 0; i < 29; i++)
{
dgv1.Rows[0].Cells[i].Value = i.ToString();
}
}
}
//==================PLOT ボタン押し=========================================
private void button4_Click(object sender, EventArgs e)//PLOT4 ボタン押してグラフ開始
{
if (checkBox10.Checked ==true)
{
pictureBox1.Visible = true;
}
else
{
pictureBox1.Visible = false;
}
//グラフパラメータセッツアップ
//comboBox配列から読み取り
countCombo();//comboBox 6個からプロット列と周期を読み取るgline[]構造体を作成
//source Bitmapを作成
makeSrcBitmap();
int ir;
pictureBox1.Visible = true;
hScrollBar1.Minimum = 0;
int xdot = timeScale();
hScrollBar1.Maximum = rowN*xdot;
hScrollBar1.Value = rowN*xdot;
textBox3.Text = Convert.ToInt32(hScrollBar1.Value/xdot).ToString();
Debug.Print("button4:xdot=" + xdot.ToString() + "hscrollBar.Max=" + hScrollBar1.Maximum);
sourceCut(rowN*xdot);
//xyplot
xyplot();
}
// ------SourceBitmapの作成------------------------------
private void makeSrcBitmap()
{
int gsel;//gline selector
int irn;
int pw = pictureBox1.Width;
int ph = pictureBox1.Height;
int velMax = 10000;
int velMin = -10000;
int headMax = 36000000;
int headMin = 0;
int xdot = timeScale();
// double yscale = (double)ph / (velMax - velMin);
Graphics g1 = Graphics.FromImage(sourceBitmap);
g1.Clear(Color.Black);
for (gsel=0;gsel<6;gsel++)
{
if(gline[gsel].available==true)
{
int pmsec = gline[gsel].period;
int psa = gline[gsel].sa;
int pcoln = gline[gsel].colN;
double yscale = (double)ph / (gline[gsel].max - gline[gsel].min);
//Debug.Print("gline[" + gsel.ToString() + "].colN=" + gline[gsel].colN.ToString());
for (irn=2;irn<rowN;irn++)
{
int itow0 = Convert.ToInt32(dgv1.Rows[irn].Cells[1].Value);
// Debug.Print("itow0=" + itow0.ToString() + "gline[" + gsel.ToString() + "].colN=" + gline[gsel].colN.ToString());
Pen p = new Pen(samples[gsel], 1);
Brush b1 = new SolidBrush(samples[gsel]);
if ( itow0%pmsec==0 && irn>psa)
{
// Debug.Print("irn=" + irn.ToString() + "psa=" + psa.ToString());
int y0 = Convert.ToInt32(dgv1.Rows[irn].Cells[pcoln].Value);
int y0_1 = Convert.ToInt32(dgv1.Rows[irn-psa].Cells[pcoln].Value);
int px = irn*xdot;
int px_1 = (irn - psa)*xdot;
int py0 = ph / gline[gsel].baseL - (int)((double)y0 * yscale);
int py0_1 = ph / gline[gsel].baseL - (int)((double)y0_1 * yscale);
// g1.DrawLine(Pens.Blue, px, py0, px - 1, py0_1);
g1.DrawLine(p, px, py0, px_1, py0_1);
Color c = samples[gsel];
if (CKarry[gsel].Checked == true) { g1.FillEllipse(b1, px, py0, 5, 5); }
// Debug.Print("itow0="+itow0.ToString()+"px=" + px.ToString()+"py0="+py0.ToString()+"px_1="+px_1.ToString()+"py0_1="+py0_1.ToString());
}
}
}
}
}
private int timeScale()
{
int dot=Convert.ToInt32(textBox10.Text);
if (dot * dgv1.RowCount >bw)
{
dot = (int)(bw / dgv1.RowCount);
if (dot == 0) { dot = 1; }
}
return dot;
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int cx = hScrollBar1.Value;
int pW = pictureBox1.Width;
int dot = Convert.ToInt32(textBox10.Text);
int posn = (int)cx / dot;
textBox3.Text = posn.ToString();
int xdot = timeScale();
int rcx = (int)((cx - pW / 2) / xdot);
textBox13.Text = rcx.ToString();
Debug.Print("cx="+cx.ToString()+"pW="+pW.ToString()+"dot="+dot.ToString()+"posn="+posn.ToString()+"xdot="+xdot.ToString()+"rcx="+rcx.ToString());
sourceCut(cx);
//----------センターカーソルのY値読み込み 表示--------------------------------------------------------
string g0s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[0].colN].Value) / gline[0].uscale).ToString();
string g1s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[1].colN].Value) / gline[1].uscale).ToString();
string g2s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[2].colN].Value) / gline[2].uscale).ToString();
string g3s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[3].colN].Value) / gline[3].uscale).ToString();
string g4s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[4].colN].Value) / gline[4].uscale).ToString();
string g5s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[5].colN].Value) / gline[5].uscale).ToString();
if (gline[0].available == true && cx>pW/2) { textBox4.Text = g0s; }
if (gline[1].available == true && cx > pW / 2) { textBox5.Text =g1s; }
if (gline[2].available == true && cx > pW / 2) { textBox6.Text = g2s; }
if (gline[3].available == true && cx > pW / 2) { textBox7.Text = g3s; }
if (gline[4].available == true && cx > pW / 2) { textBox8.Text = g4s; }
if (gline[5].available == true && cx > pW / 2) { textBox9.Text = g5s; }
}
// soukrceBitamapを切り取って
private void sourceCut(int cx)
{
Graphics g2 = Graphics.FromImage(trimmedBitmap);
g2.Clear(Color.Black);
int pW = 1000;
int startX = 0;
if (cx > pW)
{
startX = cx - pW;
}
else
{
startX = 0;
}
if (checkBox10.Checked == true)
{
pictureBox1.Visible = true;
}
else
{
pictureBox1.Visible = false;
}
Rectangle srcRect = new Rectangle(startX, 0, pW, 500);
Rectangle desRect = new Rectangle(0, 0, pW, 500);
g2.DrawImage(sourceBitmap, desRect, srcRect, GraphicsUnit.Pixel);
//Center Cursor
g2.DrawLine(Pens.White, pW / 2, 0, pW / 2, pictureBox1.Height);
pictureBox1.Image = trimmedBitmap;
}
//*******************************************************************************************************
//------xybitmap picturebox2 ----------------------------------------
private void xyplot()
{
Graphics srcxy = Graphics.FromImage(xyBitmap);
Graphics desxy = Graphics.FromImage(p2Bitmap);
srcxy.Clear(Color.Black);
int ix, irow;
int px = 0;
int py = 0;
int px_1, py_1;
// int pic2w = 300;
// int PIC2H = 300;
int bitxyw = xysize;// 3000;
int bitxyh = xysize;// 3000;
long valx, valy;
long valxi, valyi;
//
blockn_1 = blockn;
blockn = comboBox7.SelectedIndex + 1;//blen個毎にブロック切り替え
Debug.Print("XYPLOT:blockn=" + blockn.ToString() + "dbk[].minlon=" + dbk[blockn].minlon.ToString() + "dbk[].minlat=" + dbk[blockn].minlat.ToString());
// int startrow = (blockn - 2) * blen;
// if (blockn == comboBox7.Items.Count)//all
//{
// startrow = 1;
// }
//
lonW = dbk[blockn].lonW; //maxlon[blockn] - minlon[blockn];
latH = dbk[blockn].latH;//maxlat[blockn] - minlat[blockn];
//Debug.Print("lonW=" + lonW.ToString() + ",latH=" + latH.ToString());
//------------------------ソースxybitmap へ縮小プロット---------------------------------
scalex = (double)(lonW * 1.1 / bitxyw);//lonWは、xysize 20000全幅cm/dot
scaley = (double)(latH * 1.1 / bitxyh);//latHは全高cm/dot
if (scalex > scaley) { scale0 = scalex; }//大きいスケールを採用
if (scalex < scaley) { scale0 = scaley; }
//textBox14.Text = scale0.ToString();
label3.Text ="縦="+(latH/100).ToString()+"m,横="+(lonW/100).ToString()+ "m, 縮尺"+scale0.ToString("n2")+"cm/dot";
//int endblock = 0;
//if (rowN > (blockn - 1) * blen) //最後のブロックでない場合のエンド行No
//{
// endblock = (blockn - 1) * blen;
//}
//else
//{
// endblock = rowN - 2;
//}
for (irow = dbk[blockn].startRow; irow < dbk[blockn].endRow; irow++)//dgv1.RowCount - 3; irow++)
{
if (dgv[irow, 4] > 0 && dgv[irow, 5] > 0)
{
if (checkBox1.Checked == true)
{
valx = Convert.ToInt32(dgv1.Rows[irow].Cells[4].Value);//lon
valy = Convert.ToInt32(dgv1.Rows[irow].Cells[5].Value);//lat
}
else
{
valx = dgv[irow, 4];//Convert.ToInt32(dgv1.Rows[irow].Cells[4].Value);//lon
valy = dgv[irow, 5];//Convert.ToInt32(dgv1.Rows[irow].Cells[5].Value);//lat
}
valxi = valx - dbk[blockn].minlon;
valyi = valy - dbk[blockn].minlat;
px_1 = px;
px = Convert.ToInt32((double)valxi / scale0);
py_1 = py;
py = Convert.ToInt32((double)valyi / scale0);
//
// All block での色分け
Color cxy;
if(blockn>alln)
{
a = Convert.ToInt32(Math.Ceiling((double)irow / blen));
cxy = samples[a-1];
}
else
{
cxy = samples[blockn - 1];
}
//
if (checkBox11.Checked == true)
{
// Pen p = new Pen(Color.LawnGreen, 2);
Pen p = new Pen(cxy, 2);
srcxy.DrawLine(p, px, py, px_1, py_1);
}
// Brush b1 = new SolidBrush(samples[blockn - 1]);
Brush b1 = new SolidBrush(cxy);
// Debug.Print("irow=" + irow.ToString() + ",px=" + px.ToString() + "py=" + py.ToString());
if (dgv[irow, 1]%100 == 0)//F9P 100msec
{
int diam = 16;
int pxd = px - diam / 2;
int pyd = py - diam / 2;
srcxy.FillEllipse(b1, pxd, pyd, 16, 16);
}
}
}
// Debug.Print("irow="+irow.otring()+"px,py="+px.ToString() +","+ py.ToString());
//縮小表示 3000x3000を300x300へ縮小表示-------------------------------------------------
Rectangle srcrect = new Rectangle(0, 0, xysize, xysize);
Rectangle desrect = new Rectangle(0, 0, pic2w, pic2h);
desxy.DrawImage(xyBitmap, desrect, srcrect, GraphicsUnit.Pixel);
pictureBox2.Image = p2Bitmap;
Debug.Print("scale0=" + scale0.ToString() + "px,py=" + px.ToString() + "," + py.ToString());
}//Picturebox2 xyplot******************************************************************************************************
//picturebox2 Mousepoint Cut ===========================================
private void xycut(double magni)
{
int cutcenterx = cp2x*(int)(xysize/pic2w);//
int cutcentery = cp2y*(int)(xysize/pic2h);//
//int lefttopx = cutcenterx - pic2w/2;
//int lefttopy= cutcentery - pic2h/2;
//magniでカット面積縮小
int lefttopx = (int)(cutcenterx - (pic2w / 2)/magni);
int lefttopy =(int)(cutcentery -( pic2h / 2)/magni);
// Debug.Print("lefttopx=" + lefttopx.ToString() + "lefttopy=" + lefttopy.ToString());
Graphics g3 = Graphics.FromImage(p3Bitmap);
g3.Clear(Color.Black);
// magni = 10;
if (magni == 0) { magni = 1; }
int magniw = Convert.ToInt32((double)pic3w/magni );
int magnih = Convert.ToInt32((double)pic3h/magni );
Rectangle srcxyRect = new Rectangle(lefttopx, lefttopy, magniw,magnih);
Rectangle desxyRect = new Rectangle(0, 0,pic3w, pic3h);
g3.DrawImage(xyBitmap, desxyRect, srcxyRect, GraphicsUnit.Pixel);
//---------------縮尺目盛り------------
Brush b2 = new SolidBrush(Color.White);
g3.FillEllipse(b2, 10,10, 10, 10);
g3.FillEllipse(b2, 110, 10, 10, 10);
Pen p2 = new Pen(Color.White, 2);
g3.DrawLine(p2, 15, 15, 115, 15);
string shukumoji = (scale0 / magni).ToString("n1")+"m";
//フォントオブジェクトの作成
Font fnt = new Font("MS UI Gothic", 16);
//文字列を位置(0,0)、青色で表示
g3.DrawString(shukumoji, fnt, Brushes.White, 130,8);
pictureBox3.Image=p3Bitmap;
}
//pictureBox1 iClear
private void sourceBitmap_clear()
{
Graphics g4 = Graphics.FromImage(sourceBitmap);
g4.Clear(Color.Black);
pictureBox1.Image = sourceBitmap;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void dgv1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
{
int cno = comboBox7.SelectedIndex;
if (cno < 6)
{
comboBox7.BackColor = samples[cno];//= Color.FromArgb(86, 61, 124))
}
/*
comboBox7.Items.Add("0");
comboBox7.Items.Add("1");
comboBox7.Items.Add("2");
comboBox7.Items.Add("3");
comboBox7.Items.Add("4");
comboBox7.Items.Add("5");
comboBox7.Items.Add("All");
comboBox7.SelectedIndex = 6;
*/
}
private void pictureBox2_Click(object sender, EventArgs e)
{
//画面座標でマウスポインタの位置を取得する
System.Drawing.Point sp = System.Windows.Forms.Cursor.Position;
//画面座標をクライアント座標に変換する
System.Drawing.Point cp = this.PointToClient(sp);
//X座標を取得する
int x = cp.X;
//Y座標を取得する
int y = cp.Y;
int p2top=pictureBox2.Top;
int p2left= pictureBox2.Left;
cp2x = cp.X - p2left;//pirctreBox2のマウスポイント
cp2y = cp.Y - p2top;
label6.Text = "cpx=" + cp2x.ToString() + "cpy=" + cp2y.ToString();
wheelVal= Convert.ToDouble(label5.Text);
xycut(wheelVal);
}
private void button6_Click(object sender, EventArgs e)
{
dgvsave();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment