java绘制铁路线_铁路站场简图绘制软件源码

【实例简介】绘制站场简图

【实例截图】

a115b5a6c9df470fa6aba58a1ed2508d.png

81fcbbc853191b60e7948a4fc8790dee.png

【核心代码】  private void pictureBox2_Click(object sender, EventArgs e)

{

if (this.getCurrentShapes().Count > 0)

{

ArrayList list = new ArrayList();

string dateHead1 = "insert into Date";

string dateHead2 = "(type,p1,p2,p3)values(";

string dateQuotation = "'";

string dateDot1 = ",";

string dateDot2 = ")";

foreach (BaseShape shape in this.getCurrentShapes())

{

string type = shape.GetType().ToString();

if (type.Equals("CAD.ArcShape"))

{

list.Add(dateHead1);

list.Add(dateHead2);

list.Add(dateQuotation);

list.Add(type);

list.Add(dateQuotation);

list.Add(dateDot1);

list.Add(dateQuotation);

list.Add(shape.getP1());

list.Add(dateQuotation);

list.Add(dateDot1);

list.Add(dateQuotation);

list.Add(shape.getP2());

list.Add(dateQuotation);

list.Add(dateDot1);

list.Add(dateQuotation);

list.Add(((ArcShape)shape).getP3());

list.Add(dateQuotation);

list.Add(dateDot2);

}

else

{

list.Add(dateHead1);

list.Add(dateHead2);

list.Add(dateQuotation);

list.Add(type);

list.Add(dateQuotation);

list.Add(dateDot1);

list.Add(dateQuotation);

list.Add(shape.getP1());

list.Add(dateQuotation);

list.Add(dateDot1);

list.Add(dateQuotation);

list.Add(shape.getP2());

list.Add(dateQuotation);

list.Add(dateDot1);

list.Add(dateQuotation);

list.Add(dateQuotation);

list.Add(dateDot2);

}

}

// 创建文件。如果文件存在则覆盖

saveFileDialog1.Filter = "数据库文件|*.sql|文本文件| *.txt";

// 创建写入流

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

StreamWriter wr = new StreamWriter(saveFileDialog1.FileName, true);

//FileStream fs = File.Open(@"d:\内容.sql", FileMode.Create);

//StreamWriter wr = new StreamWriter(fs, System.Text.Encoding.UTF8);

// 将ArrayList中的每个项逐一写入文件

for (int i = 0; i < list.Count; i )

{

wr.WriteLine(list[i]);

}

// 关闭写入流

wr.Flush();

wr.Close();

// 关闭文件

//fs.Close();

}

}

else

{

MessageBox.Show("当前界面没有图形!");

}

}

private void pictureBox2_Click_1(object sender, EventArgs e)

{

if (this.getCurrentShapes().Count > 0)

{

saveFileDialog3.Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Gif 图片|*.gif|Png 图片|*.png|Wmf  图片|*.wmf";

saveFileDialog3.FileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") "-"; ;//设置默认文件名

if (saveFileDialog3.ShowDialog() == DialogResult.OK)

{

this.pictureBox1.Image = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);

Graphics g = Graphics.FromImage(this.pictureBox1.Image);

Graphics.FromImage(this.pictureBox1.Image).Clear(Color.White);//消除底图的黑色

for (int i = 0; i < currentShapes.Count; i )

{

string Type = ((BaseShape)currentShapes[i]).GetType().ToString();

switch (Type)

{

case "CAD.LineShape":

g.DrawLine(new Pen(((BaseShape)currentShapes[i]).penColor, (float)((((BaseShape)currentShapes[i]).penwidth) * 1.7)),

((BaseShape)currentShapes[i]).getP1(), ((BaseShape)currentShapes[i]).getP2());

Pen p = new Pen(Color.White, (((BaseShape)currentShapes[i]).penwidth));

p.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //自定义样式

p.DashPattern = new float[] { 7, 5 };

g.DrawLine(p, ((BaseShape)currentShapes[i]).getP1(), ((BaseShape)currentShapes[i]).getP2());

break;

case "CAD.RectangleShape":

g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X, ((BaseShape)currentShapes[i]).getP1().Y, (((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X), (((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y));

g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X, ((BaseShape)currentShapes[i]).getP2().Y, (((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X), (((BaseShape)currentShapes[i]).getP1().Y - ((BaseShape)currentShapes[i]).getP2().Y));

g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP2().X, ((BaseShape)currentShapes[i]).getP2().Y, (((BaseShape)currentShapes[i]).getP1().X - ((BaseShape)currentShapes[i]).getP2().X), (((BaseShape)currentShapes[i]).getP1().Y - ((BaseShape)currentShapes[i]).getP2().Y));

g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP2().X, ((BaseShape)currentShapes[i]).getP1().Y, (((BaseShape)currentShapes[i]).getP1().X - ((BaseShape)currentShapes[i]).getP2().X), (((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y));

break;

case "CAD.EllipseShape":

g.DrawEllipse(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X, ((BaseShape)currentShapes[i]).getP1().Y, (((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X), (((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y));

break;

case "CAD.CircleShape":

int r = (int)Math.Pow(Math.Pow(((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X, 2) Math.Pow(((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y, 2), 0.5);

g.DrawEllipse(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X - r, ((BaseShape)currentShapes[i]).getP1().Y - r, 2 * r, 2 * r);

break;

case "CAD.ArcShape":

DrawArcFromThreePoint(((ArcShape)currentShapes[i]).getP1().X,

((ArcShape)currentShapes[i]).getP1().Y,

((ArcShape)currentShapes[i]).getP2().X,

((ArcShape)currentShapes[i]).getP2().Y,

((ArcShape)currentShapes[i]).getP3().X,

((ArcShape)currentShapes[i]).getP3().Y);

g.DrawArc(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth),

(int)Arcx, (int)Arcy, (int)ArcRadius1, (int)ArcRadius2,

(int)Arcangle1, (int)Arcangle2);

break;

case "CAD.AssistShape":

Point p1 = ((AssistShape)currentShapes[i]).getP1();

Point p2 = ((AssistShape)currentShapes[i]).getP2();

Point p3 = ((AssistShape)currentShapes[i]).getP3();

Pen p_assist1 = new Pen(Color.Green, 0);

p_assist1.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //自定义样式

p_assist1.DashPattern = new float[] { 2, 1 };

g.DrawLine(p_assist1, p1.X, p1.Y, p1.X, p3.Y);

g.DrawLine(p_assist1, p2.X, p2.Y, p2.X, p3.Y);

g.DrawLine(p_assist1, p1.X, p3.Y, p2.X, p3.Y);

break;

case "CAD.AssistalignmentShape":

Point p4 = ((AssistalignmentShape)currentShapes[i]).getP1();

Point p5 = ((AssistalignmentShape)currentShapes[i]).getP2();

Point p6 = ((AssistalignmentShape)currentShapes[i]).getP3();

Pen p_assist2 = new Pen(Color.Green, 0);

p_assist2.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //自定义样式

p_assist2.DashPattern = new float[] { 2, 1 };

g.DrawLine(p_assist2, p4.X, p4.Y, p6.X, p4.Y);

g.DrawLine(p_assist2, p5.X, p5.Y, p6.X, p5.Y);

g.DrawLine(p_assist2, p6.X, p4.Y, p6.X, p5.Y);

break;

}

((BaseShape)currentShapes[i]).superDraw(g);//变幻的时候

}

this.pictureBox1.Image.Clone();//这句话是关键    //释放此 System.Drawing.Image 使用的所有资源。

pictureBox1.Image.Save(saveFileDialog3.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);

MessageBox.Show(this, "图片保存成功!", "信息提示");

}

}

else

{

MessageBox.Show("当前界面没有图形!");

}

}

private void pictureBox1_Click(object sender, EventArgs e)

{

}

private void toolStripLabel1_Click(object sender, EventArgs e)

{

}

private void toolStripMenuItem1_Click(object sender, EventArgs e)

{

}

private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)

{

}

private void txt_currenttool_TextChanged(object sender, EventArgs e)

{

}

private void pictureBox3_Click(object sender, EventArgs e)

{

fontDialog1.ShowColor = true;//这行代码一定要出现在fontDialog1.ShowDialog()之前。

fontDialog1.ShowDialog();

foreach (BaseShape shape in currentShapes)

{

if (shape.GetType().ToString().Equals("CAD.AssistShape"))

{

((AssistShape)shape).getTxtAssist().Font = fontDialog1.Font;

((AssistShape)shape).getTxtAssist().ForeColor = fontDialog1.Color;//设置字体颜色

}

}

}

private void button2_Click(object sender, EventArgs e)

{

bool isSave = true;

SaveFileDialog saveImageDialog = new SaveFileDialog();

saveImageDialog.Title = "Capture screen image savedialog";

saveImageDialog.Filter = @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";

if (saveImageDialog.ShowDialog() == DialogResult.OK)

{

string fileName = saveImageDialog.FileName.ToString();

if (fileName != "" && fileName != null)

{

string fileExtName = fileName.Substring(fileName.LastIndexOf(".") 1).ToString();

System.Drawing.Imaging.ImageFormat imgformat = null;

if (fileExtName != "")

{

switch (fileExtName)

{

case "jpg":

imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;

break;

case "bmp":

imgformat = System.Drawing.Imaging.ImageFormat.Bmp;

break;

case "gif":

imgformat = System.Drawing.Imaging.ImageFormat.Gif;

break;

default:

MessageBox.Show("只能存取为: jpg,bmp,gif 格式");

isSave = false;

break;

}

}

//默认保存为JPG格式

if (imgformat == null)

{

imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;

}

if (isSave)

{

try

{

pictureBox1.Image.Save(fileName, imgformat);

//RealtimeVideoForm.image.Save(fileName, imgformat);

MessageBox.Show("图片成功保存!~~");

}

catch

{

MessageBox.Show("保存失败!");

}

}

}

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值