Exemple #1
0
    IEnumerator Start()
    {
        // get render target;
        plane     = GameObject.Find("Plane");
        cameraMat = plane.GetComponent <MeshRenderer>().material;

        // get a reference to web cam decoder component;
        decoder = GetComponent <WebCamDecoder>();

        // get encoders;
        qrEncoder = Barcode.GetEncoder(BarcodeType.QrCode, new QrCodeEncodeOptions()
        {
            ECLevel = QrCodeErrorCorrectionLevel.H
        });

        pdf417Encoder = Barcode.GetEncoder(BarcodeType.Pdf417);

        qrEncoder.Options.Margin     = 1;
        pdf417Encoder.Options.Margin = 2;

        // init web cam;
        if (Application.platform == RuntimePlatform.OSXWebPlayer ||
            Application.platform == RuntimePlatform.WindowsWebPlayer)
        {
            yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam));
        }

        var devices    = WebCamTexture.devices;
        var deviceName = devices[0].name;

        cameraTexture = new WebCamTexture(deviceName, 1920, 1080);
        cameraTexture.Play();

        // start decoding;
        yield return(StartCoroutine(decoder.StartDecoding(cameraTexture)));

        cameraMat.mainTexture = cameraTexture;

        // adjust texture orientation;
        plane.transform.rotation = plane.transform.rotation *
                                   Quaternion.AngleAxis(cameraTexture.videoRotationAngle, Vector3.up);
    }
Exemple #2
0
        private bool CalculateSize(ref Size currentSize)
        {
            IBarcodeEncoder enc = GetEncoder(this.BarcodeType);

            if (enc == null)
            {
                throw new Exception("That encoder is not implemented yet.");
            }

            IBarcodeSizer        sizer  = enc.Sizer;
            IBarcodeModularSizer mSizer = sizer as IBarcodeModularSizer;

            try
            {
                enc.Text = this.Data;

                sizer  = enc.Sizer;
                mSizer = sizer as IBarcodeModularSizer;

                sizer.DPI = (float)this.Dpi.Value;
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }

            BarcodeRenderMode mode = BarcodeRenderMode.None;

            if (this.Guarded)
            {
                mode |= BarcodeRenderMode.Guarded;
            }
            if (this.Notched)
            {
                mode |= BarcodeRenderMode.Notched;
            }
            if (this.Numbered)
            {
                mode |= BarcodeRenderMode.Numbered;
            }
            if (this.Braced)
            {
                mode |= BarcodeRenderMode.Braced;
            }
            if (this.Boxed)
            {
                mode |= BarcodeRenderMode.Boxed;
            }

            sizer.Mode = mode;

            if (this.Height.Value < sizer.Height)
            {
                this.Height = new Unit(sizer.Height);
            }

            Size actualSize;

            if (sizer.DPI == 0 || mSizer == null)
            {
                //Logical mode, or simple fixed size.
                actualSize = sizer.GetValidSize(new Size((int)sizer.Width, (int)Height.Value));
                SetSizeDisplay(actualSize, ref currentSize);
            }
            else
            {
                actualSize = sizer.GetValidSize(new Size((int)sizer.Width, (int)Height.Value));
                SetSizeDisplay(actualSize, ref currentSize);
            }

            return(true);
        }
Exemple #3
0
        private Bitmap GenerateBarcodeStandard()
        {
            Bitmap result      = null;
            Size   currentSize = new Size(0, 0);

            IBarcodeEncoder enc = GetEncoder(this.BarcodeType);

            if (enc == null)
            {
                throw new Exception("That encoder is not implemented yet.");
            }

            try
            {
                enc.Text = this.Data;
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }

            BarcodeRenderMode mode = BarcodeRenderMode.None;

            if (this.Guarded)
            {
                mode |= BarcodeRenderMode.Guarded;
            }
            if (this.Notched)
            {
                mode |= BarcodeRenderMode.Notched;
            }
            if (this.Numbered)
            {
                mode |= BarcodeRenderMode.Numbered;
            }
            if (this.Braced)
            {
                mode |= BarcodeRenderMode.Braced;
            }
            if (this.Boxed)
            {
                mode |= BarcodeRenderMode.Boxed;
            }

            enc.Sizer.Mode = mode;
            enc.Sizer.DPI  = (float)this.Dpi.Value;

            bool calculResult = CalculateSize(ref currentSize);

            if (calculResult == false)
            {
                throw new Exception("Error calculating the size.");
            }

            if (!enc.Sizer.IsValidSize(currentSize))
            {
                throw new Exception("Invalid size.");
            }

            IBarcodeGenerator gen = enc.Generator;

            result = gen.GenerateBarcode(currentSize);

            return(result);
        }
Exemple #4
0
        private bool CalculateSize()
        {
            IBarcodeEncoder enc = GetEncoder();

            if (enc == null)
            {
                return(false);
            }

            IBarcodeSizer        sizer  = enc.Sizer;
            IBarcodeModularSizer mSizer = sizer as IBarcodeModularSizer;

            try {
                //if ((enc.Flags&BarcodeEncoderFlags.Composite)!=0 ||
                //    (enc.Generator!=null && (enc.Generator.Flags & BarcodeGeneratorFlags.VariableLength)!=0))
                enc.Text = _tbData.Text;

                //if ((enc.Flags & BarcodeEncoderFlags.Composite) != 0) {
                sizer  = enc.Sizer;
                mSizer = sizer as IBarcodeModularSizer;
                //}

                sizer.DPI = (int)_nupDpi.Value;
            } catch (ArgumentException ex) {
                MessageBox.Show(ex.Message);
                return(false);
            }

            BarcodeRenderMode mode = BarcodeRenderMode.None;

            if (_cbGuarded.Checked)
            {
                mode |= BarcodeRenderMode.Guarded;
            }
            if (_cbNotched.Checked)
            {
                mode |= BarcodeRenderMode.Notched;
            }
            if (_cbNumbered.Checked)
            {
                mode |= BarcodeRenderMode.Numbered;
            }
            if (_cbBraced.Checked)
            {
                mode |= BarcodeRenderMode.Braced;
            }
            if (_cbBoxed.Checked)
            {
                mode |= BarcodeRenderMode.Boxed;
            }

            sizer.Mode = mode;
            //Ok, now what we do depends on the options that are set.

            if (_nudHeight.Value < sizer.Height)
            {
                _nudHeight.Value = sizer.Height;
            }

            Size actualSize;

            if (sizer.DPI == 0 || mSizer == null)
            {
                //Logical mode, or simple fixed size.
                actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value));
                SetSizeDisplay(actualSize);
            }
            else if (_rbDesiredWidth.Checked)
            {
                //They have given a desired width.
                if (_nudDesiredWidth.Value == 0)
                {
                    actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value));
                    SetSizeDisplay(actualSize);
                }
                else
                {
                    float mils = BarcodeUtilities.CalculateModuleWidth(mSizer, (int)(mSizer.DPI * (float)_nudDesiredWidth.Value));
                    _nudModuleWidth.Value = (decimal)mils;
                    mSizer.Module         = mils;
                    if (_nudHeight.Value < sizer.Height)
                    {
                        _nudHeight.Value = sizer.Height;
                    }
                    actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value));
                    SetSizeDisplay(actualSize);
                }
            }
            else
            {
                //rbModule checked.
                mSizer.Module = (float)_nudModuleWidth.Value;
                if (_nudHeight.Value < sizer.Height)
                {
                    _nudHeight.Value = sizer.Height;
                }
                actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value));
                SetSizeDisplay(actualSize);
            }

            return(true);
        }
Exemple #5
0
        private bool GenerateBarecode()
        {
            // --- STANDARD ---
            if (_rbStandard.Checked)
            {
                IBarcodeEncoder enc = GetEncoder();

                if (enc == null)
                {
                    MessageBox.Show("That encoder is not implemented yet.");
                    return(false);
                }

                try
                {
                    enc.Text = _tbData.Text;
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message);
                    return(false);
                }

                BarcodeRenderMode mode = BarcodeRenderMode.None;
                if (_cbGuarded.Checked)
                {
                    mode |= BarcodeRenderMode.Guarded;
                }
                if (_cbNotched.Checked)
                {
                    mode |= BarcodeRenderMode.Notched;
                }
                if (_cbNumbered.Checked)
                {
                    mode |= BarcodeRenderMode.Numbered;
                }
                if (_cbBraced.Checked)
                {
                    mode |= BarcodeRenderMode.Braced;
                }
                if (_cbBoxed.Checked)
                {
                    mode |= BarcodeRenderMode.Boxed;
                }

                enc.Sizer.Mode = mode;
                enc.Sizer.DPI  = (int)_nupDpi.Value;

                IBarcodeModularSizer mSizer = enc.Sizer as IBarcodeModularSizer;
                if (mSizer != null)
                {
                    if (_nudModuleWidth.Value != 0)
                    {
                        mSizer.Module = (float)_nudModuleWidth.Value;
                    }
                }

                bool calculResult = CalculateSize();
                if (calculResult == false)
                {
                    return(false);
                }

                if (!enc.Sizer.IsValidSize(_currentSize))
                {
                    MessageBox.Show("Invalid size.");
                    return(false);
                }

                IBarcodeGenerator gen = enc.Generator;
                _bmpPrimary      = gen.GenerateBarcode(_currentSize);
                _pbBarcode.Image = _bmpPrimary;
            }

            // --- HIBC ---
            else
            {
                ActiveUp.WebControls.SecondaryDataHibc secondData = new ActiveUp.WebControls.SecondaryDataHibc();
                if (_tbDate.Text != "")
                {
                    try
                    {
                        secondData.Date = DateTime.Parse(_tbDate.Text);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Invalid date format in the Date box.");
                        return(false);
                    }
                }

                if (_tbQuantity.Text != "")
                {
                    try
                    {
                        secondData.Quantity = int.Parse(_tbQuantity.Text);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("The value in the quantity box must be a number between 0 and 99999.");
                        return(false);
                    }
                }

                if (_tbSerial.Text != "")
                {
                    secondData.Lot = _tbSerial.Text;
                }

                if (_comboDateFormat.SelectedItem != null)
                {
                    try
                    {
                        secondData.DateFormat = (ActiveUp.WebControls.HibcDateFormat)Enum.Parse(typeof(ActiveUp.WebControls.HibcDateFormat), (string)_comboDateFormat.SelectedItem);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("An error occured in parsing the date format.");
                        return(false);
                    }
                }

                Regex licCheck = new Regex("[A-Z][A-Z0-9]{3}", RegexOptions.IgnoreCase);
                Regex pcnCheck = new Regex("[A-Z0-9]{1,13}", RegexOptions.IgnoreCase);
                Regex gs1Check = new Regex("[0-9]{12}");

                if (_rbHIBCLIC.Checked)
                {
                    //Check the LIC and PCN.
                    if (_tbLICorGS1.Text == "" || !licCheck.IsMatch(_tbLICorGS1.Text))
                    {
                        MessageBox.Show("The LIC is not formatted correctly.");
                        return(false);
                    }

                    if (_tbPCN.Text != "" && !pcnCheck.IsMatch(_tbPCN.Text))
                    {
                        MessageBox.Show("The PCN is not formatted correctly.");
                        return(false);
                    }
                }
                else
                {
                    //GS1
                    if (_tbLICorGS1.Text == "" || !gs1Check.IsMatch(_tbLICorGS1.Text))
                    {
                        MessageBox.Show("The GS1 is not formatted correctly.");
                        return(false);
                    }

                    if (_tbPCN.Text != "" && !pcnCheck.IsMatch(_tbPCN.Text))
                    {
                        MessageBox.Show("The PCN is not formatted correctly.");
                        return(false);
                    }
                }

                byte uom;
                try
                {
                    uom = byte.Parse((string)_comboUnitOfMeasurement.SelectedItem);
                }
                catch (Exception)
                {
                    MessageBox.Show("The Unit of Measurement is not set.");
                    return(false);
                }

                IBarcodeEncoder[] encoders;
                ActiveUp.WebControls.PrimaryEncodingMode   pMode;
                ActiveUp.WebControls.SecondaryEncodingMode sMode;


                try
                {
                    pMode = (ActiveUp.WebControls.PrimaryEncodingMode)Enum.Parse(typeof(ActiveUp.WebControls.PrimaryEncodingMode), (string)_comboPrimaryMode.SelectedItem);
                }
                catch (Exception)
                {
                    MessageBox.Show("An error occured in parsing the primary encoding mode.");
                    return(false);
                }

                try
                {
                    sMode = (ActiveUp.WebControls.SecondaryEncodingMode)Enum.Parse(typeof(ActiveUp.WebControls.SecondaryEncodingMode), (string)_comboSecondaryMode.SelectedItem);
                }
                catch (Exception)
                {
                    MessageBox.Show("An error occured in parsing the secondary encoding mode.");
                    return(false);
                }

                try
                {
                    if (_rbHIBCLIC.Checked)
                    {
                        encoders = ActiveUp.WebControls.HIBCEncoder.EncodeHIBC(_tbLICorGS1.Text, _tbPCN.Text, uom, secondData, pMode, sMode);
                    }
                    else
                    {
                        encoders = ActiveUp.WebControls.HIBCEncoder.EncodeGS1(uom.ToString() + _tbLICorGS1.Text, (_tbPCN.Text == "") ? null : _tbPCN.Text, secondData, pMode, sMode);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An exception occured:\n" + ex.Message);
                    return(false);
                }

                encoders[0].Sizer.DPI = (float)_nupDpi.Value;
                if (encoders.Length == 2)
                {
                    encoders[1].Sizer.DPI = (float)_nupDpi.Value;
                }

                encoders[0].Sizer.Mode = BarcodeRenderMode.Guarded | BarcodeRenderMode.Numbered;
                if (encoders.Length == 2)
                {
                    encoders[1].Sizer.Mode = BarcodeRenderMode.Guarded | BarcodeRenderMode.Numbered;
                }

                _bmpPrimary = encoders[0].Generator.GenerateBarcode(encoders[0].Sizer.Size);
                if (encoders.Length == 2)
                {
                    _bmpSecondary = encoders[1].Generator.GenerateBarcode(encoders[1].Sizer.Size);
                }

                if (_rbPrimary.Checked)
                {
                    _pbBarcode.Image = _bmpPrimary;
                }
                else
                {
                    _pbBarcode.Image = _bmpSecondary;
                }
            }

            return(true);
        }