Commit 659eab71 LN

元器件可增加图片,导出程序时带图片导出。

1 个父辈 e4c3b1e4
......@@ -97,7 +97,9 @@ namespace TSA_V.Common
[MyConfigComment("是否启用元器件计数功能")]
public static MyConfig<bool> Device_UsePNCount = true;
[MyConfigComment("位号是否可以修改")]
public static MyConfig<bool> Device_CanModifyTagNo = false ;
public static MyConfig<bool> Device_CanModifyTagNo = false;
[MyConfigComment("元器件图片路径")]
public static MyConfig<string> Device_ComImagePath = @"\config\componentImage\";
[MyConfigComment("手势服务器端口")]
public static MyConfig<int> Hand_ServerPort = 8765;
[MyConfigComment("手势范围设置:x,y,w,h")]
......@@ -171,6 +173,8 @@ namespace TSA_V.Common
[MyConfigComment("最后一次校准信息,保存后作为新板子的基准")]
public static MyConfig<string> Data_LastCalibrateInfo ="";
[MyConfigComment("最后一次选择图片的目录")]
public static MyConfig<string> Data_LastOpenImagePath = "";
[MyConfigComment("RGB灯带端口号")]
......
......@@ -35,6 +35,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="AOI">
<HintPath>..\dll\AOI.dll</HintPath>
</Reference>
<Reference Include="Asa.IOModule.AIOBOX">
<HintPath>..\dll\Asa.IOModule.AIOBOX.dll</HintPath>
</Reference>
......
......@@ -97,6 +97,8 @@ namespace TSA_V.DeviceLibrary
public Image myImage = null;
public List<ComponetInfo> componetList { get; set; } = null;
public string GetImgPath(bool isCheck = false)
{
string path = ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_PATH);
......@@ -109,7 +111,7 @@ namespace TSA_V.DeviceLibrary
}
else
{
imagePath = Application.StartupPath + @"\" + path + ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_DEFAULT);
imagePath = Application.StartupPath + @"/" + path + ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_PATH);
}
}
return imagePath;
......@@ -176,6 +178,8 @@ namespace TSA_V.DeviceLibrary
/// </summary>
public byte[] imageByte { get; set; }
public string imageBase64Data { get; set; }
public bool IsValid()
{
if (String.IsNullOrEmpty(boardName))
......
......@@ -401,7 +401,7 @@ namespace TSA_V.LoadCSVLibrary
}
public static bool UpdateComponet(string bomName, ComponetInfo com)
public static bool UpdateComponet(string bomName, ComponetInfo com,bool updateImage=false )
{
if (!allComMap.ContainsKey(bomName))
{
......@@ -413,9 +413,17 @@ namespace TSA_V.LoadCSVLibrary
if (oldList[index].IsSameCom(com))
{
oldList[index] = com;
break;
if (!updateImage)
{
break;
}
}else if (updateImage && oldList[index].PN.Equals(com.PN))
{
oldList[index].imgInfo = null;
}
}
if (SaveBomToFile(bomName, oldList))
{
......@@ -537,17 +545,31 @@ namespace TSA_V.LoadCSVLibrary
return false;
}
}
public static void RemoveBom(string bomName)
{
string fileName = getFilePath(bomName);
if (allComMap.ContainsKey(bomName))
{
try
{
allComMap.Remove(bomName);
string fileName = getFilePath(bomName);
if (allComMap.ContainsKey(bomName))
{
allComMap.Remove(bomName);
}
if (File.Exists(fileName))
{
File.Delete(fileName);
}
//删除图片文件夹
string filePath = Path.Combine(Setting_NInit.Device_ComImagePath, @"/" + bomName);
if (Directory.Exists(filePath))
{
Directory.Delete(filePath);
}
}
if (File.Exists(fileName))
{
File.Delete(fileName);
catch (Exception ex)
{
LogUtil.error("RemoveBom " + bomName + "出错:" + ex.ToString());
}
}
......@@ -809,6 +831,7 @@ namespace TSA_V.LoadCSVLibrary
for (int i = 0; i < list.Count; i++)
{
list[i].Id = i + 1;
list[i].SaveImage(bomName, null, list[i].ImgBase64Data);
}
CSVBomManager.AddBom(bomName, list);
......
using System;
using AOI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;
......@@ -72,7 +75,80 @@ namespace TSA_V.LoadCSVLibrary
///投影文字
/// </summary>
[CSVAttribute("Text", "投影文字", false)]
public string Text { get; set; }
public string Text { get; set; }
///// <summary>
/////图片文件名
///// </summary>
//[CSVAttribute("ImageName", "图片文件名", false)]
//public string ImageName { get; set; } = "";
public string ImgBase64Data { get; set; } = "";
public Image imgInfo { get; set; } = null;
public Image GetImage(string bomName )
{
if (imgInfo == null)
{
string path =ImagePath(bomName);
if (File.Exists(path))
{
imgInfo = Eyemlib.DeepClone( Image.FromFile(path));
}
}
return imgInfo;
}
public bool SaveImage(string bomName, Image newImage, string base64Data = "")
{
try
{
string imagePath = ImagePath(bomName);
//ImageName = @"\" + bomName + @"\" + PN + ".bmp";
string path = Path.GetDirectoryName(imagePath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (File.Exists(imagePath))
{
File.Delete(imagePath);
}
if (newImage == null && base64Data != "")
{
ImageUtilM.Base64StringToFile(base64Data, imagePath);
imgInfo = null;
base64Data = "";
return true;
}
if (newImage == null)
{
//ImageName = "";
return false;
}
else
{
newImage.Save(imagePath);
imgInfo = null;
base64Data = "";
return true;
}
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
return false;
}
public string ImagePath(string bomName )
{
string path = Application.StartupPath + Setting_NInit.Device_ComImagePath + @"\" + bomName + @"\" + PN + ".bmp"; ;
return path;
}
public int GetSortPosition()
{
......
......@@ -231,41 +231,49 @@ namespace TSA_V.DeviceLibrary
if (!CSVBomManager.BomNameIsExists(board.bomName))
{
List<ComponetInfo> componetInfos = new List<ComponetInfo>();
int i = 0;
foreach (SMTPointInfo p in board.smtList)
{
ComponetInfo c = new ComponetInfo();
if (p.componet != null)
if (board.componetList!=null&& board.componetList.Count > 0)
{
componetInfos = board.componetList;
}
else
{
int i = 0;
foreach (SMTPointInfo p in board.smtList)
{
c = p.componet;
if (p.PositionNum != c.PositionNum)
ComponetInfo c = new ComponetInfo();
if (p.componet != null)
{
LogUtil.error($"改导入程序【{board.boardName}】组装点【{p.TagNo + " " + p.PN}】的位置从【{p.PositionNum}】改为元器件库对应位置【{c.PositionNum}】 ");
p.PositionNum = c.PositionNum;
c = p.componet;
if (p.PositionNum != c.PositionNum)
{
LogUtil.error($"改导入程序【{board.boardName}】组装点【{p.TagNo + " " + p.PN}】的位置从【{p.PositionNum}】改为元器件库对应位置【{c.PositionNum}】 ");
p.PositionNum = c.PositionNum;
}
}
}
else
{
c.Id = i + 1;
c.PN = p.PN;
c.PositionNum =p.PositionNum;
c.PositionX = p.PositionX;
c.PositionY = p.PositionY;
c.TagNo = p.TagNo;
c.Notes = "";
c.Text =p.ShowText;
c.ComponentDes = "";
else
{
c.Id = i + 1;
c.PN = p.PN;
c.PositionNum = p.PositionNum;
c.PositionX = p.PositionX;
c.PositionY = p.PositionY;
c.TagNo = p.TagNo;
c.Notes = "";
c.Text = p.ShowText;
c.ComponentDes = "";
}
i++;
componetInfos.Add(c);
}
i++;
componetInfos.Add(c);
}
board.bomName = CSVBomManager.AutoAddBomList(board.bomName, componetInfos);
LogUtil.info("导入程序:程序名【" + board.boardName + "】,自动创建bom【"+board.bomName+"】");
}
board.componetList = null;
board.boardId = BoardManager.GetNextId();
BoardManager.Add(board);
......
......@@ -10,10 +10,10 @@ using TSA_V.Common;
namespace TSA_V.DeviceLibrary
{
public class ImageUtilM
public class ImageUtilM
{
private static string defPath = @"D:\image\";
private static string defPath = @"D:\image\";
public static bool canSavePic(string path = "", int checkZhao = 50)
{
......@@ -68,7 +68,7 @@ namespace TSA_V.DeviceLibrary
{
if (!canSavePic(path))
{
DeleteOldFiles(path, day);
DeleteOldFiles(path, day);
}
else
{
......@@ -115,7 +115,7 @@ namespace TSA_V.DeviceLibrary
string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp";
try
{
{
if (AutoDelFiles(dire))
{
bitmap.Save(dire + iamgeName, ImageFormat.Bmp);
......@@ -129,5 +129,138 @@ namespace TSA_V.DeviceLibrary
}
return dire + iamgeName;
}
public static string BitMapToBase64(Image bitmap, int width = 0, int height = 0, int quality = 100)
{
try
{
if (bitmap == null) return "";
if (width == 0 || height == 0)
{
width = bitmap.Width;
height = bitmap.Height;
}
using (MemoryStream ms = new MemoryStream())
{
var tarbmp = ZoomImage(bitmap, height, width, quality);
tarbmp.Save(ms, ImageFormat.Jpeg);
byte[] bytes = ms.GetBuffer();
string base64 = Convert.ToBase64String(bytes);
// tarbmp.Save($".\\test_BitMapToBase64.bmp",ImageFormat.Jpeg);
//File.WriteAllText("E:\\Neotel\\Codes\\DLL\\IPCamera\\WindowsFormsApp1\\bin\\Debug\\test_BitMapToBase64.txt", base64);
//Base64ToBitmap(base64);
return base64;
}
}
catch (Exception e)
{
LogUtil.error("BitMapToStream: "+ e.ToString());
}
return "";
}
private static Image ZoomImage(Image bitmap, int destHeight, int destWidth, int quality = 100)
{
try
{
System.Drawing.Image sourImage = bitmap;
int width = 0, height = 0;
//按比例缩放
int sourWidth = sourImage.Width;
int sourHeight = sourImage.Height;
if (sourHeight > destHeight || sourWidth > destWidth)
{
if ((sourWidth * destHeight) > (sourHeight * destWidth))
{
width = destWidth;
height = (destWidth * sourHeight) / sourWidth;
}
else
{
height = destHeight;
width = (sourWidth * destHeight) / sourHeight;
}
}
else
{
width = sourWidth;
height = sourHeight;
}
Bitmap destBitmap = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage(destBitmap);
g.Clear(Color.Transparent);
//设置画布的描绘质量
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(sourImage, new Rectangle((destWidth - width) / 2, (destHeight - height) / 2, width, height), 0, 0, sourImage.Width, sourImage.Height, GraphicsUnit.Pixel);
//g.DrawImage(sourImage, new Rectangle(0, 0, destWidth, destHeight), new Rectangle(0, 0, sourImage.Width, sourImage.Height), GraphicsUnit.Pixel);
g.Dispose();
//设置压缩质量
System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
long[] qualitys = new long[1];
qualitys[0] = quality;
System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualitys);
encoderParams.Param[0] = encoderParam;
sourImage.Dispose();
return destBitmap;
}
catch (Exception ex)
{
return bitmap;
}
}
public static Bitmap Base64StringToImage(string inputStr)
{
try
{
if (inputStr == "")
{
return null;
}
byte[] arr = Convert.FromBase64String(inputStr);
//using (MemoryStream ms = new MemoryStream(arr))
{
MemoryStream ms = new MemoryStream(arr);
Bitmap bmp = new Bitmap(ms);
ms.Close();
return bmp;
}
}
catch (Exception ex)
{
LogUtil.error("Base64StringToImage 转换失败/nException:" + ex.ToString());
return null;
}
}
public static bool Base64StringToFile(string inputStr,string filePath)
{
try
{
if (inputStr == "")
{
return false ;
}
byte[] arr = Convert.FromBase64String(inputStr);
using (MemoryStream ms = new MemoryStream(arr))
{
using (Image image = Image.FromStream(ms))
{
image.Save(filePath, ImageFormat.Bmp); // 可根据实际需要保存为不同格式的图片
return true;
}
}
}
catch (Exception ex)
{
LogUtil.error("Base64StringToImage 转换失败/nException:" + ex.ToString());
return false ;
}
}
}
}
此文件的差异太大,无法显示。
......@@ -51,14 +51,10 @@ namespace TSA_V
lblMsg.Text = "";
Setting_NInit.ChangeConfig();
AGerberController.ErrorLogEvent += AGerberController_ErrorLogEvent;
//if (FormManager.UserInfo.Limit.Equals(UserLimit.Admin))
//{
// btnMaintenance.Visible = true;
//}
//else
//{
// btnMaintenance.Visible = false ;
//}
if (String.IsNullOrEmpty(Setting_NInit.Data_LastOpenImagePath))
{
Setting_NInit.Data_LastOpenImagePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
}
private void AGerberController_ErrorLogEvent(Exception ex)
......
......@@ -931,6 +931,14 @@ namespace TSA_V
/// 元器件【{0}】已配置位置【{1}】,请重新输入位置
/// </summary>
public static string PnHasPos = "PnHasPos";
/// <summary>
/// 图片名称
/// </summary>
public static string Column_imgName = "Column_imgName";
/// <summary>
/// 图片
/// </summary>
public static string Column_img = "Column_img";
}
}
......@@ -431,14 +431,10 @@ namespace TSA_V
}
private void btnOpenFile_Click(object sender, LinkLabelLinkClickedEventArgs e)
{
openFileDialogImg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
//openFileDialogImg.DefaultExt = "jpg|gif|bmp|png|jpeg";
//openFileDialogImg.Filter = "jpg|*.jpg|gif|*.gif|bmp|*.bmp|png|*.png|jpeg|*.jpeg";
{
openFileDialogImg.Filter = "Image Files|*.bmp;*.jpg;*.gif;*.png;*jpeg|gerber Files|*.*";
openFileDialogImg.Multiselect = true;
string directory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//桌面路径
openFileDialogImg.InitialDirectory = directory;
openFileDialogImg.Multiselect = true;
openFileDialogImg.InitialDirectory = Setting_NInit.Data_LastOpenImagePath;
if (openFileDialogImg.ShowDialog() == DialogResult.OK)
{
......@@ -476,6 +472,7 @@ namespace TSA_V
{
txtBoardW.Text = w.ToString();
}
Setting_NInit.Data_LastOpenImagePath =Path.GetDirectoryName( files[0]);
}
}
else
......@@ -493,6 +490,7 @@ namespace TSA_V
this.txtImagePath.Text = openFileDialogImg.FileName;
return;
}
Setting_NInit.Data_LastOpenImagePath = Path.GetDirectoryName(file);
}
}
MessageBox.Show(ResourceCulture.GetString("FileError", "文件格式错误 "));
......
......@@ -15,6 +15,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.LoadCSVLibrary;
using System.Drawing.Imaging;
using AOI;
namespace TSA_V
{
......@@ -353,20 +354,59 @@ namespace TSA_V
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
board.imageByte = BoardManager.ImgToByte(board.GetImgPath());
for (int i= 0;i < board.smtList.Count; i++){
SMTPointInfo p = board.smtList[i];
board.smtList[i].componet = CSVBomManager.GetCom(board.boardName, p);
//for (int i= 0;i < board.smtList.Count; i++){
// SMTPointInfo p = board.smtList[i];
// board.smtList[i].componet = CSVBomManager.GetCom(board.bomName, p);
// //优先使用bom的位置
// if(board.smtList[i].componet!=null)
// {
// string bomPos = board.smtList[i].componet.PositionNum;
// if (p.PositionNum!=bomPos )
// {
// p.PositionNum = bomPos;
// }
// //图片设置为base64格式
// string path = board.smtList[i].componet.ImagePath(board.bomName);
// if (File.Exists(path))
// {
// Image image = Image.FromFile(path);
// board.smtList[i].componet.ImgBase64Data = ImageUtilM.BitMapToBase64(Eyemlib.DeepClone(image));
// }
// }
//}
for (int i = 0; i < board.smtList.Count; i++)
{
ComponetInfo obj = CSVBomManager.GetCom(board.bomName, board.smtList[i]);
//优先使用bom的位置
if(board.smtList[i].componet!=null)
if (obj != null)
{
if (board.smtList[i].PositionNum != obj.PositionNum)
{
board.smtList[i].PositionNum = obj.PositionNum;
}
}
board.smtList[i].componet = null;
}
List<ComponetInfo> componetInfos = CSVBomManager.GetComList(board.bomName);
if (componetInfos != null && componetInfos.Count > 0)
{
board.componetList = new List<ComponetInfo>();
foreach (ComponetInfo obj in componetInfos)
{
string bomPos = board.smtList[i].componet.PositionNum;
if (p.PositionNum!=bomPos )
//图片设置为base64格式
string path = obj.ImagePath(board.bomName);
if (File.Exists(path))
{
p.PositionNum = bomPos;
}
Image image = Image.FromFile(path);
obj.ImgBase64Data = ImageUtilM.BitMapToBase64(Eyemlib.DeepClone(image));
}
board.componetList.Add(obj);
}
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "";
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
......@@ -387,6 +427,7 @@ namespace TSA_V
MessageBox.Show(ResourceCulture.GetString("成功导出程序到文件:")+"\r\n" + filePath, ResourceCulture.GetString("提示"));
}
}
board.componetList = null;
}
}
......
......@@ -18,10 +18,17 @@ namespace TSA_V
{
private string fileName = "";
private bool update = false;
public FrmNImageViewer(string fileName)
public Image lastImage = null;
/// <summary>
/// 选择图片的方式0=新增电路板。1=元器件图片
/// </summary>
public int SelType=0;
public FrmNImageViewer(string fileName,int type=0)
{
InitializeComponent();
this.fileName = fileName;
this.SelType = type;
}
private void FrmImageViewer_Load(object sender, EventArgs e)
......@@ -30,6 +37,8 @@ namespace TSA_V
{
System.Drawing.Image img = System.Drawing.Image.FromFile(fileName);
Bitmap myImage = new System.Drawing.Bitmap(img);
lastImage = myImage;
this.picViewer.Image = myImage;
img.Dispose();
......@@ -64,11 +73,22 @@ namespace TSA_V
{
if (update)
{
//备份原图
BackFile();
Image newImage = (Image)picViewer.Image.Clone();
newImage.Save(fileName);
LogUtil.info("保存修改后的图片:" + fileName);
if (SelType == 0)
{
//备份原图
BackFile();
Image newImage = (Image)picViewer.Image.Clone();
lastImage = newImage;
newImage.Save(fileName);
LogUtil.info("保存修改后的图片:" + fileName);
}
else
{
Image newImage = (Image)picViewer.Image.Clone();
lastImage = newImage;
LogUtil.info($"SelType={SelType}不需要保存图片");
}
}
this.DialogResult = DialogResult.OK;
......
......@@ -680,6 +680,21 @@ namespace TSA_V
Setting_NInit.Work_ProcedureName = "";
Setting_NInit.Work_TagNumber = 0;
}
if (com.GetImage(BoardManager.CurrBoard.bomName) != null)
{
picPNImg.SizeMode = PictureBoxSizeMode.Zoom;
picPNImg.Image = com.imgInfo;
panPNImg.Visible = true;
groupPNImg.Visible = true;
}
else
{
picPNImg.Image = null;
panPNImg.Visible = false;
groupPNImg.Visible = false;
}
#endregion
}
else
......@@ -1156,20 +1171,20 @@ namespace TSA_V
private void WriteStateStr()
{
return;
//全局图(粉色表示已完成;橘色表示未开始;红色表示实时位置) 12, 327
//Graphics g = e.Graphics;
Graphics g= groupBoard.CreateGraphics();
Font f = new Font("微软雅黑", 10.5F);
string end = ResourceCulture.GetString(ResourceCulture.State_End, "已完成");
string notStart = ResourceCulture.GetString(ResourceCulture.State_NotStart, "未开始");
string postion = ResourceCulture.GetString(ResourceCulture.State_Postiion, "实时位置");
int width = groupBoard.Size.Width;
g.DrawString(end, f, Brushes.HotPink, width-260, 0);
g.DrawString(notStart, f, Brushes.Orange, width-160, 0);
g.DrawString(postion, f, Brushes.Red, width-80, 0);
////全局图(粉色表示已完成;橘色表示未开始;红色表示实时位置) 12, 327
////Graphics g = e.Graphics;
//Graphics g= groupBoard.CreateGraphics();
//Font f = new Font("微软雅黑", 10.5F);
//string end = ResourceCulture.GetString(ResourceCulture.State_End, "已完成");
//string notStart = ResourceCulture.GetString(ResourceCulture.State_NotStart, "未开始");
//string postion = ResourceCulture.GetString(ResourceCulture.State_Postiion, "实时位置");
//int width = groupBoard.Size.Width;
//g.DrawString(end, f, Brushes.HotPink, width-260, 0);
//g.DrawString(notStart, f, Brushes.Orange, width-160, 0);
//g.DrawString(postion, f, Brushes.Red, width-80, 0);
////g.Dispose();
//g.Flush();
//g.Dispose();
g.Flush();
g.Dispose();
}
private void btnIo_Click(object sender, EventArgs e)
......@@ -1198,6 +1213,9 @@ namespace TSA_V
groupBoard.Size = new Size(picBoard.Width + 6, picBoard.Height + 6);
groupBoard.Location = new Point(groupBox2.Location.X + groupBox2.Width - groupBoard.Width, groupBox2.Location.Y + groupBox2.Height - groupBoard.Height);
}
groupPNImg.Size = new Size(groupBox2.Width / 5, groupBox2.Height / 5);
groupPNImg.Location = new Point(groupBox2.Location.X, groupBox2.Location.Y + groupBox2.Height - groupPNImg.Height);
}
private void StartVideo()
......
......@@ -98,8 +98,10 @@ namespace TSA_V
int index = 0;
foreach (SMTPointInfo weld in pointList)
{
float x = (float)Math.Abs(weld.PositionX) * imageXiShu;
float y = (float)Math.Abs(weld.PositionY) * imageXiShu;
//float x = (float)Math.Abs(weld.PositionX) * imageXiShu;
//float y = (float)Math.Abs(weld.PositionY) * imageXiShu;
float x = (float) weld.PositionX * imageXiShu;
float y = (float) weld.PositionY * imageXiShu;
int lineLength = 8;
Color color = Color.HotPink;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!