Exemplo n.º 1
0
        // Get the data for a contact and encode it

        private static string GetContactData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            // Name is mandatory

            object defName = GetDefault("Name", defs);
            string name    =
                GetMandatoryString(ed, "Name", defName);

            // All other fields are optional

            object defPhone = GetDefault("Phone", defs);
            string phone    =
                GetOptionalString(ed, "Phone number", defPhone);

            object defEmail = GetDefault("Email", defs);
            string email    =
                GetOptionalString(ed, "Email address", defEmail);

            object defAddress = GetDefault("Address", defs);
            string address    =
                GetOptionalString(ed, "Address", defAddress);

            object defAddress2 = GetDefault("Address2", defs);
            string address2    =
                GetOptionalString(ed, "Address 2", defAddress2);

            object defWebsite = GetDefault("Website", defs);
            string website    =
                GetOptionalString(ed, "Website", defWebsite);

            object defMemo = GetDefault("Memo", defs);
            string memo    =
                GetOptionalString(ed, "Memo", defMemo);

            // Create XData to store these input values

            rb = RbEncoder.CreateContactRb(
                name, phone, email, address, address2,
                website, memo
                );

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodeContact(
                       name, phone, email, address,
                       address2, website, memo
                       ));
        }
Exemplo n.º 2
0
        // Get the data for a URL and encode it

        private static string GetUrlData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            object defUrl = GetDefault("UValue", defs);
            string url    = GetMandatoryString(ed, "Url", defUrl);

            // Create XData to store the input value

            rb = RbEncoder.CreateUrlRb(url);

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodeUrl(url));
        }
Exemplo n.º 3
0
        // Get the data for some text and encode it

        private static string GetTextData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            object defText = GetDefault("TValue", defs);
            string text    = GetMandatoryString(ed, "Text", defText);

            // Create XData to store the input value

            rb = RbEncoder.CreateTextRb(text);

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodeText(text));
        }
Exemplo n.º 4
0
        // Get the data for a phone number and encode it

        private static string GetPhoneData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            object defPhone = GetDefault("PValue", defs);
            string phone    =
                GetMandatoryString(ed, "Phone number", defPhone);

            // Create XData to store the input value

            rb = RbEncoder.CreatePhoneRb(phone);

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodePhone(phone));
        }
Exemplo n.º 5
0
        // Get the data for an email address and encode it

        private static string GetEmailData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            object defEmail = GetDefault("EValue", defs);
            string email    =
                GetMandatoryString(ed, "Email address", defEmail);

            // Create XData to store the input value

            rb = RbEncoder.CreateEmailRb(email);

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodeEmail(email));
        }
Exemplo n.º 6
0
        // Get the data for a calendar event and encode it

        private static string GetCalendarData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            // Title is mandatory

            object defTitle = GetDefault("Title", defs);
            string title    =
                GetMandatoryString(ed, "Event title", defTitle);

            // All other fields are optional

            object   defStart = GetDefault("Start", defs);
            DateTime start    =
                GetMandatoryDateTime(ed, "Start date & time", defStart);

            object   defEnd = GetDefault("End", defs);
            DateTime end    =
                GetOptionalDateTime(ed, "End date & time", defEnd);

            object defLocation = GetDefault("Location", defs);
            string location    =
                GetOptionalString(ed, "Location", defLocation);

            object defDesc = GetDefault("Description", defs);
            string desc    =
                GetOptionalString(ed, "Description", defDesc);

            // Create XData to store these input values

            rb = RbEncoder.CreateCalendarRb(
                title, start, end, location, desc
                );

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodeCalendar(
                       title, start, end, location, desc
                       ));
        }
Exemplo n.º 7
0
        // Get the data for a geo-location and encode it

        private static string GetGeolocationData(
            Editor ed, ResultBuffer defs, out ResultBuffer rb
            )
        {
            object defLat = GetDefault("Lat", defs);
            double lat    =
                GetMandatoryDouble(ed, "Latitude", defLat);

            object defLng = GetDefault("Lat", defs);
            double lng    =
                GetMandatoryDouble(ed, "Longitude", defLng);

            object defQuery = GetDefault("Query", defs);
            string query    =
                GetOptionalString(ed, "Query", defQuery);

            // Create XData to store these input values

            rb = RbEncoder.CreateGeolocationRb(lat, lng, query);

            // Encode the data into a URL to generate a QR Code

            return(FormatDataHelper.EncodeGeolocation(lat, lng, query));
        }
Exemplo n.º 8
0
        public static void GenerateQRByCommandLine()
        {
            Editor ed =
                Application.DocumentManager.MdiActiveDocument.Editor;

            //Obtain type of QR Code

            PromptKeywordOptions pko =
                new PromptKeywordOptions(
                    "\nType of entity ");

            pko.Keywords.Add("Native");
            pko.Keywords.Add("Online");

            PromptResult pkr =
                ed.GetKeywords(pko);

            if (pkr.Status != PromptStatus.OK)
            {
                return;
            }

            //Obtain data from user

            ResultBuffer def = null; //this is used for editing
                                     //ignore for this command
            ResultBuffer rb;         //stores the information for late edit
            string       qrData = CommandLineHelper.GetTextForQrCode(
                ed, def, out rb);

            //Obtain the insert point and size

            Point3d insertPoint = Point3d.Origin;
            double  size        = 180;

            if (
                PromptInsertPointAndSize(
                    true, ref insertPoint, ref size) !=
                PromptStatus.OK
                )
            {
                return;
            }

            //generate the qr code entity

            Entity ent = null;

            switch (pkr.StringResult)
            {
            case "Native":
                ent = GenerateQRHatch(qrData,
                                      QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC,
                                      7, QRCodeEncoder.ERROR_CORRECTION.M, size);
                if (ent == null)
                {
                    return;
                }
                break;

            case "Online":
                string uri =
                    FormatDataHelper.EncodeQrCodeUrl(qrData);
                ent = CreateRasterImage(uri, size);
                break;
            }

            // Append to the current space

            AppendEntityToCurrentSpace(ent);

            // Add the xdata and move the ent to the correct location

            SetXDataAndMoveToLocation(
                ent, rb, insertPoint);
        }
Exemplo n.º 9
0
        public static void EditQR()
        {
            Document doc =
                Application.DocumentManager.MdiActiveDocument;
            Editor   ed = doc.Editor;
            Database db = doc.Database;

            // Ask user to select an QR code, hatch or raster image

            PromptEntityOptions peo =
                new PromptEntityOptions("Select a QR code: ");

            peo.SetRejectMessage(
                "\nMust be a hatch or a raster image"
                );
            peo.AddAllowedClass(typeof(Hatch), true);

            // AutoCAD crash if we try AddAllowedClass for RasterImage
            // when no raster image is defined or just hatch QRs were
            // defined, probably because in C++ we need to call
            // acedArxLoad("acismui.arx"), which is not exposed in .NET,
            // so let's check before if the drawing contains any
            // RasterImages, if not we don't need this filter.

            if (!RasterImageDef.GetImageDictionary(db).IsNull)
            {
                peo.AddAllowedClass(typeof(RasterImage), true);
            }
            PromptEntityResult entityResult = ed.GetEntity(peo);

            if (entityResult.Status != PromptStatus.OK)
            {
                return;
            }

            Transaction tr = db.TransactionManager.StartTransaction();

            using (tr)
            {
                Entity ent =
                    tr.GetObject(entityResult.ObjectId, OpenMode.ForRead)
                    as Entity;
                ResultBuffer rb =
                    ent.GetXDataForApplication(APPLICATION_PREFIX);

                if (rb != null && rb.AsArray().Length == 0)
                {
                    ed.WriteMessage("\nThis is not a valid QR code");
                    tr.Commit(); //faster
                    return;
                }

                // Show the form with current information

                QRCodeForm form = new QRCodeForm();
                form.IsEditing = true;
                form.QREncodeDataAsResultBuffer = rb;
                rb.Dispose();
                System.Windows.Forms.DialogResult res =
                    Application.ShowModalDialog(form);
                if (res != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                //Get insert point and size

                double size =
                    ent.GeometricExtents.MaxPoint.X -
                    ent.GeometricExtents.MinPoint.X;
                Point3d inspt = ent.GeometricExtents.MinPoint;


                if (ent is RasterImage)
                {
                    // Just update the raster image definition

                    RasterImage    image    = ent as RasterImage;
                    RasterImageDef imageDef =
                        tr.GetObject(image.ImageDefId, OpenMode.ForWrite)
                        as RasterImageDef;
                    imageDef.SourceFileName =
                        FormatDataHelper.EncodeQrCodeUrl(form.QREncodeData);
                    imageDef.Load();
                }
                else
                {
                    // Erase current entity

                    ent.UpgradeOpen();
                    ent.Erase();

                    // Create a new one

                    Entity newEnt =
                        GenerateQRHatch(
                            form.QREncodeData, form.QREncode,
                            form.QRVersion, form.QRErrorCorrect, (int)size
                            );
                    if (newEnt == null)
                    {
                        return;
                    }
                    ResultBuffer newRb = form.QREncodeDataAsResultBuffer;
                    newEnt.XData = newRb;
                    newRb.Dispose();
                    newEnt.TransformBy(
                        Matrix3d.Displacement(inspt.GetAsVector())
                        );
                    AppendEntityToCurrentSpace(newEnt);
                }

                tr.Commit();
            }
        }
Exemplo n.º 10
0
        public static void GenerateQRByForm()
        {
            // Show the form
            QRCodeForm form = new QRCodeForm();

            System.Windows.Forms.DialogResult res =
                Application.ShowModalDialog(form);
            if (res != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            // Obtain insert point and size

            Point3d insertPoint = Point3d.Origin;
            double  size        = form.QRSize;

            if (
                PromptInsertPointAndSize(
                    form.QRSacelOnScreen,
                    ref insertPoint, ref size) != PromptStatus.OK
                )
            {
                return;
            }

            // Generate the QR entity

            Entity ent = null;

            switch (form.QREntityType)
            {
            case QRCodeForm.QRType.Hatch:

                // Generate the QR as a Hatch entity

                ent = GenerateQRHatch(
                    form.QREncodeData, form.QREncode,
                    form.QRVersion, form.QRErrorCorrect, size
                    );
                if (ent == null)
                {
                    return;
                }

                // Append to the current space

                AppendEntityToCurrentSpace(ent);
                break;

            case QRCodeForm.QRType.Online:

                // Generate the QR as an ONline Raster Image entity

                string uri =
                    FormatDataHelper.EncodeQrCodeUrl(form.QREncodeData);
                ent = CreateRasterImage(uri, size);
                break;
            }

            if (ent == null)
            {
                return;
            }

            // Add the xdata and move the ent to the correct location

            SetXDataAndMoveToLocation(
                ent, form.QREncodeDataAsResultBuffer, insertPoint
                );
        }