public Point GetCenterSelected() { List <Point> centerSelected = new List <Point>(); for (int i = 0; i < CadItems.Count; i++) { Point ct = Point.Round(CadItems[i].Center); ct.X += this.X; ct.Y += this.Y; Point newCtRotate = ImageProcessingUtils.PointRotation(ct, new Point((int)this.CenterRotation.X + this.X, (int)this.CenterRotation.Y + this.Y), this.Angle * Math.PI / 180.0); Rectangle bound = new Rectangle(newCtRotate.X, newCtRotate.Y, 1, 1); if (this.SelectCenter.Contains(bound)) { centerSelected.Add(newCtRotate); } } if (centerSelected.Count > 0) { long x = 0; long y = 0; for (int i = 0; i < centerSelected.Count; i++) { x += centerSelected[i].X; y += centerSelected[i].Y; } x = x / centerSelected.Count; y = y / centerSelected.Count; return(new Point(Convert.ToInt32(x), Convert.ToInt32(y))); } else { return(new Point()); } }
public List <object> GetListLayerInRect(System.Drawing.Rectangle Rect) { List <object> listObj = new List <object>(); if (Rect != Rectangle.Empty) { //gerber layer var a = GetPadsInRect(Rect, true); var b = GetPadsInRect(Rect, false); if (a.Count + b.Count > 0) { listObj.Add(this.Gerber); } // cad layer foreach (var item in this.Cad) { for (int i = 0; i < item.CadItems.Count; i++) { Point ct = Point.Round(item.CadItems[i].Center); ct.X += item.X; ct.Y += item.Y; Point newCtRotate = ImageProcessingUtils.PointRotation(ct, new Point((int)item.CenterRotation.X + item.X, (int)item.CenterRotation.Y + item.Y), item.Angle * Math.PI / 180.0); Rectangle bound = new Rectangle(newCtRotate.X, newCtRotate.Y, 1, 1); if (Rect.Contains(bound)) { listObj.Add(item); break; } } } } return(listObj); }
public static Point GetCenterRotated(Point Center, Point CenterRotate, int X, int Y, double Angle) { Center.X += X; Center.Y += Y; CenterRotate.X += X; CenterRotate.Y += Y; Point cadCenterRotated = ImageProcessingUtils.PointRotation(Center, CenterRotate, Angle * Math.PI / 180.0); return(cadCenterRotated); }
public List <Tuple <CadFile, int> > GetSuggestCadItemName(Rectangle Rect, bool GetAllComponent = false) { List <Tuple <CadFile, int> > suggest = new List <Tuple <CadFile, int> >(); if (Rect != Rectangle.Empty) { Thread t1 = new Thread(() => { // find pads in rect for (int i = 0; i < this.Gerber.PadItems.Count; i++) { var item = this.Gerber.PadItems[i]; if (item.CadItemIndex >= 0) { Rectangle bound = new Rectangle(item.Center.X, item.Center.Y, 1, 1); if (Rect.Contains(bound)) { for (int j = 0; j < this.Cad.Count; j++) { if (this.Cad[j].CadFileID == item.CadFileID) { Tuple <CadFile, int> tlCad = new Tuple <CadFile, int>(this.Cad[j], item.CadItemIndex); lock (suggest) { if (!suggest.Contains(tlCad)) { suggest.Add(tlCad); } } } } } } } }); // cad layer Thread t2 = new Thread(() => { foreach (var item in this.Cad) { for (int i = 0; i < item.CadItems.Count; i++) { Point ct = Point.Round(item.CadItems[i].Center); ct.X += item.X; ct.Y += item.Y; Point newCtRotate = ImageProcessingUtils.PointRotation(ct, new Point((int)item.CenterRotation.X + item.X, (int)item.CenterRotation.Y + item.Y), item.Angle * Math.PI / 180.0); Rectangle bound = new Rectangle(newCtRotate.X, newCtRotate.Y, 1, 1); if (Rect.Contains(bound)) { Tuple <CadFile, int> tlCad = new Tuple <CadFile, int>(item, i); lock (suggest) { if (!suggest.Contains(tlCad) || i == item.CadItems.Count - 1) { suggest.Add(tlCad); } } } } } foreach (var item in this.Cad) { for (int i = item.CadItems.Count - 1; i >= 0; i--) { Tuple <CadFile, int> tlCad = new Tuple <CadFile, int>(item, i); if (!suggest.Contains(tlCad)) { suggest.Add(tlCad); if (!GetAllComponent) { break; } } } } }); t1.Start(); t2.Start(); t1.Join(); t2.Join(); } return(suggest); }
public static Image <Bgr, byte> GetLayoutImage(Model model, ActionMode mode) { //Stopwatch sw = new Stopwatch(); //sw.Start(); Image <Bgr, byte> img = null; if (model.Gerber is GerberFile) { if (model.Gerber.Visible) { switch (mode) { case ActionMode.Render: DrawColor(model); break; case ActionMode.Rotation: DrawColor(model); break; case ActionMode.Update_Color_Gerber: DrawColor(model); break; case ActionMode.Draw_Cad: break; case ActionMode.Select_Pad: break; default: break; } } //Console.WriteLine(sw.ElapsedMilliseconds); if (model.Gerber.Visible) { img = model.ImgGerberProcessedBgr.Copy(); if (model.Gerber.SelectPad != Rectangle.Empty) { HightLightSelectPad(img, model); } } else { img = new Image <Bgr, byte>(model.ImgGerberProcessedBgr.Size); } foreach (CadFile item in model.Cad) { if (item.Visible) { int x = item.X; int y = item.Y; double angle = item.Angle * Math.PI / 180.0; Color cl = item.Color; foreach (CadItem caditem in item.CadItems) { Point ct = Point.Round(caditem.Center); string txt = caditem.Name; ct.X += x; ct.Y += y; Point newCtRotate = ImageProcessingUtils.PointRotation(ct, new Point(item.CenterRotation.X + item.X, item.CenterRotation.Y + item.Y), angle); MCvScalar color = new MCvScalar(cl.B, cl.G, cl.R); if (item.SelectCenter != Rectangle.Empty) { Rectangle bound = new Rectangle(newCtRotate.X, newCtRotate.Y, 1, 1); if (item.SelectCenter.Contains(bound)) { color = new MCvScalar(255, 255, 255); } } if (model.ShowComponentCenter) { CvInvoke.Circle(img, newCtRotate, 3, color, -1); } if (model.ShowLinkLine) { if (caditem.Name != "UNDEFINE") { for (int i = 0; i < caditem.PadsIndex.Count; i++) { CvInvoke.Line(img, newCtRotate, model.Gerber.PadItems[caditem.PadsIndex[i]].Center, new MCvScalar(0, 255, 0), 1); } } } if (model.ShowComponentName) { newCtRotate.X += 5; CvInvoke.PutText(img, txt, newCtRotate, Emgu.CV.CvEnum.FontFace.HersheyDuplex, 0.5, color, 1, Emgu.CV.CvEnum.LineType.Filled); } } } } if (model.Gerber.Visible) { HightLightMarkPoint(img, model); } } return(img); }