Beispiel #1
0
        private void SetPadName(System.Drawing.Rectangle Rect)
        {
            List <Tuple <CadFile, int> > suggets = mModel.GetSuggestCadItemName(Rect);
            int id = -1;

            if (suggets.Count > 0)
            {
                SuggestLinkPadWindow avaiWD = new SuggestLinkPadWindow(suggets);
                avaiWD.ShowDialog();
                id = avaiWD.ItemSelected;
            }
            if (id > -1)
            {
                List <PadItem> pads = mModel.GetPadsInRect(Rect, Linked: false);
                foreach (var item in pads)
                {
                    CadFile cadFile   = suggets[id].Item1;
                    int     idCadItem = suggets[id].Item2;
                    CadItem cadItem   = cadFile.CadItems[idCadItem];
                    PadItem pad       = item;
                    int     idPadItem = mModel.Gerber.PadItems.IndexOf(pad);
                    pad.CadFileID    = cadFile.CadFileID;
                    pad.CadItemIndex = idCadItem;
                    cadItem.PadsIndex.Add(idPadItem);
                }
                ShowAllLayerImb(ActionMode.Update_Color_Gerber);
            }
        }
Beispiel #2
0
        private void cmbState_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbState.SelectedItem != null)
            {
                PadItem item = (PadItem)cmbState.SelectedItem;

                switch (item.Name)
                {
                case "ArtBoardLeft":
                    State = ArtBoardState.ArtboardLeft;
                    break;

                case "ArtBoardRight":
                    State = ArtBoardState.ArtBoardRight;
                    break;

                case "PaintSplitLeft":
                    State = ArtBoardState.PaintSplitLeft;
                    break;

                case "PaintSplitRight":
                    State = ArtBoardState.PaintSplitRight;
                    break;

                case "Preview":
                    State = ArtBoardState.Preview;
                    break;
                }
            }
        }
Beispiel #3
0
        private void ShowDetail()
        {
            int id = -1;

            this.Dispatcher.Invoke(() =>
            {
                id = cbFOV.SelectedIndex;
            });
            System.Drawing.Rectangle ROI = mModel.Gerber.FOVs[id].ROI;
            this.Dispatcher.Invoke(() =>
            {
                txtROIX.Text      = ROI.X.ToString();
                txtROIY.Text      = ROI.Y.ToString();
                txtROIWidth.Text  = ROI.Width.ToString();
                txtROIHeight.Text = ROI.Height.ToString();
            });

            if (mImage != null)
            {
                var modelFov = mModel.FOV;
                System.Drawing.Rectangle ROIGerber = new System.Drawing.Rectangle(
                    mAnchorROIGerber[id].X - modelFov.Width / 2, mAnchorROIGerber[id].Y - modelFov.Height / 2,
                    modelFov.Width, modelFov.Height);
                mImage.ROI = ROI;
                using (Image <Bgr, byte> imgGerberBgr = new Image <Bgr, byte>(ROIGerber.Size))
                    using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
                    {
                        for (int i = 0; i < mModel.Gerber.PadItems.Count; i++)
                        {
                            PadItem item = mModel.Gerber.PadItems[i];
                            if (item.FOVs.Count > 0)
                            {
                                if (item.FOVs[0] == id)
                                {
                                    System.Drawing.Point[] cntPointSub = new System.Drawing.Point[item.ContourAdjust.Length];
                                    for (int j = 0; j < cntPointSub.Length; j++)
                                    {
                                        cntPointSub[j] = new System.Drawing.Point(item.ContourAdjust[j].X - ROIGerber.X, item.ContourAdjust[j].Y - ROIGerber.Y);
                                    }
                                    contours.Push(new VectorOfPoint(cntPointSub));
                                }
                            }
                        }
                        CvInvoke.DrawContours(imgGerberBgr, contours, -1, new MCvScalar(255), -1);
                        CvInvoke.AddWeighted(imgGerberBgr, 0.5, mImage, 0.5, 1, imgGerberBgr);
                        this.Dispatcher.Invoke(() =>
                        {
                            BitmapSource bms = Utils.Convertor.Bitmap2BitmapSource(imgGerberBgr.Bitmap);
                            imb.Source       = bms;
                        });
                    }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            else
            {
                mLog.Info(string.Format("Cant Capture image in FOV : {0}", id + 1));
            }
        }
Beispiel #4
0
        private void btAdjustPad_Click(object sender, RoutedEventArgs e)
        {
            int id = -1;

            mAdjustPad = true;
            this.Dispatcher.Invoke(() =>
            {
                id = cbFOV.SelectedIndex;
            });
            if (id > -1)
            {
                System.Drawing.Rectangle ROI = mModel.Gerber.FOVs[id].ROI;
                mImage.ROI = ROI;
                var modelFov = mModel.FOV;
                System.Drawing.Rectangle ROIGerber = new System.Drawing.Rectangle(
                    mAnchorROIGerber[id].X - modelFov.Width / 2, mAnchorROIGerber[id].Y - modelFov.Height / 2,
                    modelFov.Width, modelFov.Height);
                if (mAdjustPad)
                {
                    List <System.Drawing.Rectangle> padBoundInFOV = new List <System.Drawing.Rectangle>();
                    List <PadItem> padInFOV = new List <PadItem>();
                    for (int i = 0; i < mModel.Gerber.PadItems.Count; i++)
                    {
                        PadItem item = mModel.Gerber.PadItems[i];
                        if (item.FOVs.Count > 0)
                        {
                            if (item.FOVs[0] == id)
                            {
                                System.Drawing.Rectangle padBound = item.Bouding;

                                padBound.X -= ROIGerber.X;
                                padBound.Y -= ROIGerber.Y;
                                padBoundInFOV.Add(padBound);
                                padInFOV.Add(mModel.Gerber.PadItems[i]);
                            }
                        }
                    }
                    var adjustPadResult = VI.AutoAdjustROIFOV.AdjustPad(mImage, padBoundInFOV, new Hsv(145, 110, 130), new Hsv(255, 255, 255), mModel.Gerber.FOVs[id].ROI);
                    for (int i = 0; i < padInFOV.Count; i++)
                    {
                        System.Drawing.Rectangle bounding = new System.Drawing.Rectangle(padInFOV[i].Bouding.X, padInFOV[i].Bouding.Y, padInFOV[i].Bouding.Width, padInFOV[i].Bouding.Height);
                        System.Drawing.Point[]   cntPoint = new System.Drawing.Point[padInFOV[i].Contour.Length];
                        bounding.X += adjustPadResult[i].X;
                        bounding.Y += adjustPadResult[i].Y;
                        for (int j = 0; j < cntPoint.Length; j++)
                        {
                            cntPoint[j] = new System.Drawing.Point(padInFOV[i].Contour[j].X + adjustPadResult[i].X, padInFOV[i].Contour[j].Y + adjustPadResult[i].Y);
                        }
                        padInFOV[i].BoudingAdjust = bounding;
                        padInFOV[i].ContourAdjust = cntPoint;
                    }
                    mAdjustPad = false;
                }
                ShowDetail();
            }
        }
        public void LoadVariables()
        {
            // Check MeasurePoints

            foreach (System.Drawing.Point subP in mModel.MeasurePoints.Points)
            {
                if (subP == null)
                {
                    mModel.MeasurePoints.Points = new List <System.Drawing.Point>();
                    break;
                }
            }

            if (mModel.Gerber.MarkPoint.PadMark[0] > 0)
            {
                mPadMark = mModel.Gerber.PadItems[mModel.Gerber.MarkPoint.PadMark[0]];
            }
            var readCode = mModel.HardwareSettings.ReadCodePosition;

            for (int i = 0; i < readCode.Count; i++)
            {
                mReadCodePosition.Add(readCode[i].Copy());
            }
            mExposureTime = mModel.HardwareSettings.ExposureTime;
            mGain         = mModel.HardwareSettings.Gain;
            for (int i = 0; i < 4; i++)
            {
                mLightIntensity[i] = mModel.HardwareSettings.LightIntensity[i];
            }
            mMatchingScore = mModel.Gerber.MarkPoint.Score;
            mGrayLevel     = mModel.Gerber.MarkPoint.ThresholdValue;
            mSearchX       = mModel.Gerber.MarkPoint.SearchX;
            mSearchY       = mModel.Gerber.MarkPoint.SearchY;
            System.Drawing.Point p = mModel.HardwareSettings.MarkPosition;
            mMarkPoint = new System.Drawing.Point(p.X, p.Y);
            mConveyor  = mModel.HardwareSettings.Conveyor;
            mDPI       = mModel.DPI;
        }
Beispiel #6
0
        private void btAdjust_Click(object sender, RoutedEventArgs e)
        {
            int id = -1;

            this.Dispatcher.Invoke(() =>
            {
                id = cbFOV.SelectedIndex;
            });
            if (id > -1)
            {
                System.Drawing.Rectangle ROI = new System.Drawing.Rectangle();
                this.Dispatcher.Invoke(() => {
                    ROI = new System.Drawing.Rectangle(
                        Convert.ToInt32(txtROIX.Text),
                        Convert.ToInt32(txtROIY.Text),
                        Convert.ToInt32(txtROIWidth.Text),
                        Convert.ToInt32(txtROIHeight.Text)
                        );
                });
                mImage.ROI = ROI;
                var modelFov = mModel.FOV;
                System.Drawing.Rectangle ROIGerber = new System.Drawing.Rectangle(
                    mAnchorROIGerber[id].X - modelFov.Width / 2, mAnchorROIGerber[id].Y - modelFov.Height / 2,
                    modelFov.Width, modelFov.Height);
                mModel.Gerber.ProcessingGerberImage.ROI = ROIGerber;
                using (Image <Gray, byte> imgGerber = mModel.Gerber.ProcessingGerberImage.Copy())
                {
                    ROI = VI.AutoAdjustROIFOV.Adjust(mImage, imgGerber, new Hsv(145, 110, 130), new Hsv(255, 255, 255), mModel.FOV, ROI);
                    mModel.Gerber.FOVs[id].ROI = ROI;
                }
                if (mAdjustPad)
                {
                    List <System.Drawing.Rectangle> padBoundInFOV = new List <System.Drawing.Rectangle>();
                    List <PadItem> padInFOV = new List <PadItem>();
                    for (int i = 0; i < mModel.Gerber.PadItems.Count; i++)
                    {
                        PadItem item = mModel.Gerber.PadItems[i];
                        if (item.FOVs.Count > 0)
                        {
                            if (item.FOVs[0] == id)
                            {
                                System.Drawing.Rectangle padBound = item.Bouding;
                                padBound.X -= ROIGerber.X;
                                padBound.Y -= ROIGerber.Y;
                                padBoundInFOV.Add(padBound);
                                padInFOV.Add(mModel.Gerber.PadItems[i]);
                            }
                        }
                    }
                    var adjustPadResult = VI.AutoAdjustROIFOV.AdjustPad(mImage, padBoundInFOV, new Hsv(145, 110, 130), new Hsv(255, 255, 255), mModel.Gerber.FOVs[id].ROI);
                    for (int i = 0; i < padInFOV.Count; i++)
                    {
                        System.Drawing.Rectangle bounding = padInFOV[i].Bouding;
                        System.Drawing.Point[]   cntPoint = padInFOV[i].Contour;
                        bounding.X += adjustPadResult[i].X;
                        bounding.Y += adjustPadResult[i].Y;
                        for (int j = 0; j < cntPoint.Length; j++)
                        {
                            cntPoint[j].X += adjustPadResult[i].X;
                            cntPoint[j].Y += adjustPadResult[i].Y;
                        }
                        padInFOV[i].BoudingAdjust = bounding;
                        padInFOV[i].ContourAdjust = cntPoint;
                    }

                    mAdjustPad = false;
                }
                mModel.Gerber.ProcessingGerberImage.ROI = new System.Drawing.Rectangle();
                ShowDetail();
            }
        }
Beispiel #7
0
        private void CaptureMark()
        {
            //mPlcComm.Logout();
            bool lightStrobe = !Convert.ToBoolean(mParam.LIGHT_MODE);

            System.Drawing.Point[] markPointXYPLC = mModel.GetPLCMarkPosition();
            PadItem[] PadMark = new PadItem[2];
            for (int i = 0; i < 2; i++)
            {
                PadMark[i] = mModel.Gerber.PadItems[mModel.Gerber.MarkPoint.PadMark[i]];
            }
            mMark = new System.Drawing.Point[2];
            double matchingScore = mModel.Gerber.MarkPoint.Score;

            for (int i = 0; i < markPointXYPLC.Length; i++)
            {
                System.Drawing.Point mark = markPointXYPLC[i];
                int x = mark.X;
                int y = mark.Y;
                mLog.Info(string.Format("{0}, Position Name : {1},  X = {2}, Y = {3}", "Moving TOP Axis", "Mark " + (i + 1).ToString(), x, y));
                using (Image <Bgr, byte> image = VI.CaptureImage.CaptureFOV(mPlcComm, mCamera, mark))
                {
                    if (image != null)
                    {
                        System.Drawing.Rectangle ROI = mModel.GetRectROIMark();
                        image.ROI = ROI;
                        using (Image <Gray, byte> imgGray = new Image <Gray, byte>(image.Size))
                        {
                            CvInvoke.CvtColor(image, imgGray, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);
                            CvInvoke.Threshold(imgGray, imgGray, mModel.Gerber.MarkPoint.ThresholdValue, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
                            VectorOfPoint cnt      = new VectorOfPoint(PadMark[i].Contour);
                            var           markInfo = Mark.MarkDetection(imgGray, cnt);
                            cnt.Dispose();
                            cnt = null;
                            double realScore = markInfo.Item2;
                            realScore = Math.Round((1 - realScore) * 100.0, 2);
                            if (realScore > matchingScore)
                            {
                                using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
                                {
                                    if (markInfo.Item1 != null)
                                    {
                                        contours.Push(markInfo.Item1);
                                        Moments mm = CvInvoke.Moments(markInfo.Item1);
                                        if (mm.M00 != 0)
                                        {
                                            mMark[i] = new System.Drawing.Point(Convert.ToInt32(mm.M10 / mm.M00), Convert.ToInt32(mm.M01 / mm.M00));
                                        }
                                    }
                                }
                                if (i == 1)
                                {
                                    mMarkAdjust.Status = Utils.ActionStatus.Successfully;
                                    System.Drawing.Point ct = new System.Drawing.Point(image.Width / 2, image.Height / 2);
                                    mMarkAdjust.X = ct.X - mMark[0].X;
                                    mMarkAdjust.Y = ct.Y - mMark[0].Y;
                                }
                            }
                            else
                            {
                                mLog.Info(string.Format("Score matching is lower score standard... {0} < {1}", realScore, matchingScore));
                                mMarkAdjust.Status = Utils.ActionStatus.Fail;
                                break;
                            }
                        }
                    }
                    else
                    {
                        mLog.Info(string.Format("Cant Capture image in Mark : {0}", i + 1));
                        mMarkAdjust.Status = Utils.ActionStatus.Fail;
                        break;
                    }
                }
            }
        }