Exemplo n.º 1
0
 /// <summary>
 /// 预览图类型
 /// </summary>
 /// <param name="database"></param>
 /// <param name="ctx"></param>
 public static void preparePlotstyles(Database database, ContextForDbDatabase ctx)
 {
     using (BlockTableRecord paperBTR = (BlockTableRecord)database.CurrentSpaceId.GetObject(OpenMode.ForRead))
     {
         //通过块表记录得到布局
         using (Layout pLayout = (Layout)paperBTR.LayoutId.GetObject(OpenMode.ForRead))
         {
             if (ctx.IsPlotGeneration ? pLayout.PlotPlotStyles : pLayout.ShowPlotStyles)
             {
                 string pssFile = pLayout.CurrentStyleSheet;
                 if (pssFile.Length > 0)
                 {
                     string testpath = ((HostAppServ)HostApplicationServices.Current).FindFile(pssFile, database, FindFileHint.Default);
                     if (testpath.Length > 0)
                     {
                         using (FileStreamBuf pFileBuf = new FileStreamBuf(testpath))
                         {
                             ctx.LoadPlotStyleTable(pFileBuf);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void SVG_export(Database database)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.AddExtension = true;
            sfd.DefaultExt   = "svg";
            sfd.Filter       = "SVG files (*.svg)|*.svg";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                // SVG export is a rendering device too
                using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule("TD_SvgExport.tx", false, true))
                {
                    if (gsModule == null) // if SVG export module is not found
                    {
                        return;
                    }
                    // create graphics device
                    using (Teigha.GraphicsSystem.Device dev = gsModule.CreateDevice())
                    {
                        using (FileStreamBuf outStr = new FileStreamBuf(sfd.FileName, false, FileShareMode.DenyWrite, FileCreationDisposition.CreateAlways))
                        {
                            // setup device properties
                            using (Dictionary props = dev.Properties)
                            {
                                // SVG export uses stream output
                                props.AtPut("Output", outStr);
                                // lines may look thin - may be scaled
                                props.AtPut("LineWeightScale", new RxVariant(1.0));
                                // number of digits after decimal point in the output file
                                props.AtPut("Precision", new RxVariant(6));
                                // place to put images (may be relative path)
                                props.AtPut("ImageBase", new RxVariant(System.IO.Path.GetDirectoryName(sfd.FileName)));
                                // missing font
                                props.AtPut("GenericFontFamily", new RxVariant("sans-serif"));
                                // software HLR engine enabled
                                props.AtPut("UseHLR", new RxVariant(true));
                                // whether to use blended gradients for complex gradient fill (may increase size)
                                props.AtPut("EnableGouraudShading", new RxVariant(true));
                            }
                            dev.SetLogicalPalette(Device.LightPalette); // light palette with white background
                            ContextForDbDatabase ctx = new ContextForDbDatabase(database);
                            ctx.SetPlotGeneration(true);
                            LayoutHelperDevice hd = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx);
                            // size is SVG viewbox
                            hd.OnSize(new System.Drawing.Rectangle(0, 0, 1024, 768));
                            hd.Update();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void ExportPDF()
        {
            try
            {
                mPDFExportParams param = new mPDFExportParams();
                param.Author           = "FSSG";
                param.BackgroundColor  = Color.White;
                param.Creator          = "FSSG";
                param.Database         = database;
                param.Flags            = PDFExportFlags.Default;
                param.FlateCompression = true;
                param.imageDPI         = 72;
                param.Keywords         = "";
                param.Layouts.Add("Layout1");

                StreamBuf stream = new FileStreamBuf(@"C:\Users\Tdme\Desktop\2555.00-718.00.pdf", false, FileShareMode.DenyReadWrite, FileCreationDisposition.CreateAlways);
                param.OutputStream = stream;

                PageParams page = new PageParams();
                page.setParams(200, 200);
                param.PageParams.Add(page);

                param.Palette  = new Color[] { Color.Red, Color.Green, Color.Blue };
                param.Producer = "FSSG";
                param.Subject  = "FSSG";
                param.Title    = "FSSG";
                param.UseHLR   = true;
                param.Versions = PDFExportVersions.Last;

                Export_Import.ExportPDF(param);

                ulong i = stream.Length;
                stream.Dispose();
            }
            catch (System.Exception ex) {
                Logger.log("", ex);
            }
        }
Exemplo n.º 4
0
        private void Export_Click(object sender, EventArgs e)
        {
            if (outputFile.Text.Length > 0)
            {
                using (mPDFExportParams param = new mPDFExportParams())
                {
                    param.Database = database;
                    using (FileStreamBuf fileStrem = new FileStreamBuf(outputFile.Text, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
                    {
                        param.OutputStream = fileStrem;

                        param.Flags = (embedded_fonts.Checked ? PDFExportFlags.EmbededTTF : 0) |
                                      (SHXTextAsGeometry.Checked ? PDFExportFlags.SHXTextAsGeometry : 0) |
                                      (TTGeometry.Checked ? PDFExportFlags.TTFTextAsGeometry : 0) |
                                      (ESimpGeometryOpt.Checked ? PDFExportFlags.SimpleGeomOptimization : 0) |
                                      (ZoomExtents.Checked ? PDFExportFlags.ZoomToExtentsMode : 0) |
                                      (EnableLayerSup_pdfv1_5.Checked ? PDFExportFlags.EnableLayers : 0) |
                                      (ExportOffLay.Checked ? PDFExportFlags.IncludeOffLayers : 0);

                        param.Title        = textBox_title.Text;
                        param.Author       = textBox_author.Text;
                        param.Subject      = textBox_subject.Text;
                        param.Keywords     = textBox_keywords.Text;
                        param.Creator      = textBox_creator.Text;
                        param.Producer     = textBox_producer.Text;
                        param.UseHLR       = UseHidLRAlgorithm.Checked;
                        param.EncodeStream = EncodedSZ.Checked;

                        bool bV15 = EnableLayerSup_pdfv1_5.Checked || ExportOffLay.Checked;
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;

                        StringCollection strColl = new StringCollection();
                        if (radioButton_All.Checked)
                        {
                            using (DBDictionary layouts = (DBDictionary)database.LayoutDictionaryId.GetObject(OpenMode.ForRead))
                            {
                                foreach (DBDictionaryEntry entry in layouts)
                                {
                                    strColl.Add(entry.Key);
                                }
                            }
                        }
                        param.Layouts = strColl;

                        int nPages = Math.Max(1, strColl.Count);
                        PageParamsCollection pParCol = new PageParamsCollection();
                        Double width  = Double.Parse(PapWidth.Text);
                        Double height = Double.Parse(PapHeight.Text);
                        for (int i = 0; i < nPages; ++i)
                        {
                            PageParams pp = new PageParams();
                            pp.setParams(width, height);
                            pParCol.Add(pp);
                        }
                        param.PageParams = pParCol;
                        Export_Import.ExportPDF(param);
                    }
                }
                Close();
            }
        }
Exemplo n.º 5
0
        static int Main(string[] args)
        {
            int nRes = 0; // Return value for main

            /**********************************************************************/
            /* Set command line defaults                                          */
            /**********************************************************************/
            SaveType   fileType    = SaveType.Save12;
            DwgVersion outVer      = DwgVersion.AC1021;
            bool       disableWait = false;

            /**********************************************************************/
            /* Initialize Teigha                                                  */
            /**********************************************************************/
            using (Services svcs = new Services())
            {
                /**********************************************************************/
                /* Display the Product and Version that created the executable        */
                /**********************************************************************/
                Console.WriteLine("\nOdWriteEx developed using %ls ver %ls");

                /**********************************************************************/
                /* Parse Command Line inputs                                          */
                /**********************************************************************/
                bool bInvalidArgs = (args.Length < 2);
                if (bInvalidArgs)
                {
                    bInvalidArgs = true;
                    nRes         = 1;
                }

                /**********************************************************************/
                /* Set file version                                                   */
                /**********************************************************************/
                if (args.Length >= 2)
                {
                    string argv2 = args[1];
                    switch (argv2)
                    {
                    case "ACAD12":
                        outVer = DwgVersion.vAC12;
                        break;

                    case "ACAD13":
                        outVer = DwgVersion.vAC13;
                        break;

                    case "ACAD14":
                        outVer = DwgVersion.vAC14;
                        break;

                    case "ACAD2000":
                        outVer = DwgVersion.vAC15;
                        break;

                    case "ACAD2004":
                        outVer = DwgVersion.vAC18;
                        break;

                    case "ACAD2007":
                        outVer = DwgVersion.vAC21;
                        break;

                    case "ACAD2010":
                        outVer = DwgVersion.vAC24;
                        break;

                    default:
                        bInvalidArgs = true;
                        nRes         = 1;
                        break;
                    }
                }

                /**********************************************************************/
                /* Set file type                                                      */
                /**********************************************************************/
                if (args.Length >= 3)
                {
                    string argv3 = args[2];
                    switch (argv3)
                    {
                    case "DWG":
                        fileType = SaveType.Save12;
                        break;

                    case "DXF":
                        fileType = SaveType.Save13;
                        break;

                    default:
                        bInvalidArgs = true;
                        nRes         = 1;
                        break;
                    }
                }

                /**********************************************************************/
                /* Disable prompt of pressing ENTER                                   */
                /**********************************************************************/
                if (args.Length >= 4)
                {
                    string argv4 = args[3];
                    if (argv4 == "-NoWait")
                    {
                        disableWait = true;
                    }
                }

                if (bInvalidArgs)
                {
                    Console.WriteLine("\n\n\tusage: OdWriteEx <filename> [OutVer] [OutType] [-NoWait]");
                    Console.WriteLine("\n\tOutVer can be any of ACAD12, ACAD13, ACAD14, ACAD2000, ACAD2004, ACAD2007, ACAD2010\n");
                    Console.WriteLine("\n\tOutType can be any of DWG, DXF\n");
                    Console.WriteLine("\n\t-NoWait disables prompt of pressing ENTER at the end of execution.\n");
                    return(nRes);
                }

                /**********************************************************************/
                /* Load and Release RecomputeDimBlock                                 */
                /**********************************************************************/
                //::odrxDynamicLinker()->loadApp(TD_T("RecomputeDimBlock")).release();
                //::odrxDynamicLinker()->loadApp(TD_T("ExFieldEvaluator")).release();

                /**********************************************************************/
                /* Find the folder of the output file                                 */
                /**********************************************************************/
                string outputFolder = args[0];
                outputFolder = Path.GetDirectoryName(outputFolder);
                FileStreamBuf fileBuf = new FileStreamBuf(args[0], false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways);

                try
                {
                    /********************************************************************/
                    /* Create a default OdDbDatabase object                             */
                    /********************************************************************/
                    using (Database pDb = new Database())
                    {
                        DatabaseSummaryInfo        pSumInfo = pDb.SummaryInfo;
                        DatabaseSummaryInfoBuilder builder  = new DatabaseSummaryInfoBuilder(pSumInfo);
                        builder.Title    = "Title";
                        builder.Author   = "Author";
                        builder.Comments = "Comments";
                        builder.Comments = "File was created by OdWriteEx";
                        pDb.SummaryInfo  = builder.ToDatabaseSummaryInfo();

                        /********************************************************************/
                        /* Fill the database                                                */
                        /********************************************************************/
                        HostApplicationServices.WorkingDatabase = pDb;
                        DbFiller filler = new DbFiller();
                        filler.fillDatabase(pDb);

                        /********************************************************************/
                        /* Audit the database                                               */
                        /********************************************************************/
                        using (AuditInfo aiAppAudit = new CustomAuditInfo(outputFolder + "AuditReport.txt"))
                        {
                            aiAppAudit.FixErrors = true;
                            Console.WriteLine("\n\n");
                            pDb.Audit(aiAppAudit);
                        }
                        #region TODO block
                        //{
                        //  OdSecurityParams securityParams;
                        //  securityParams.password = "******";
                        //  securityParams.nFlags = 1;
                        //  securityParams.nProvType = 0xd;

                        //  // L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
                        //  static wchar_t pn[] =
                        //  {
                        //    0x4D, 0x69, 0x63, 0x72, 0x6F,
                        //    0x73, 0x6F, 0x66, 0x74, 0x20,
                        //    0x42, 0x61, 0x73, 0x65, 0x20,
                        //    0x44, 0x53, 0x53, 0x20, 0x61,
                        //    0x6E, 0x64, 0x20, 0x44, 0x69,
                        //    0x66, 0x66, 0x69, 0x65, 0x2D,
                        //    0x48, 0x65, 0x6C, 0x6C, 0x6D,
                        //    0x61, 0x6E, 0x20, 0x43, 0x72,
                        //    0x79, 0x70, 0x74, 0x6F, 0x67,
                        //    0x72, 0x61, 0x70, 0x68, 0x69,
                        //    0x63, 0x20, 0x50, 0x72, 0x6F,
                        //    0x76, 0x69, 0x64, 0x65, 0x72,
                        //    0x00
                        //  };
                        //  securityParams.provName = pn;

                        //  /************************************************************************/
                        //  /* Uncomment the following line to add the password TD_T("Teigha") to the  */
                        //  /* R18+ file to be created                                              */
                        //  /************************************************************************/
                        //  //pDb->setSecurityParams(securityParams);
                        //}
                        #endregion
                        /********************************************************************/
                        /* Write the database                                               */
                        /********************************************************************/
                        pDb.SaveAs(fileBuf, fileType, outVer, true, 16);

                        /*if (SaveType.Save12 == fileType)
                         * {
                         * pDb.SaveAs(args[0], outVer);
                         * }
                         * else
                         * pDb.DxfOut(args[0], 16, outVer);//16 - default*/
                        Console.WriteLine("\nDatabase has been saved as {0}", pDb.Filename);
                    }
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("\n\nError: {0}", e.Message);
                    nRes = -1;
                }
            }

            if (nRes != 0)
            {
                Console.WriteLine("\n\nPress ENTER to continue...");
                if (!disableWait)
                {
                    Console.ReadLine();
                }
            }
            Console.WriteLine("\n\n");
            return(nRes);
        }