void initializeGraphics() { try { graphics = Graphics.FromHwnd(panel1.Handle); // load some predefined rendering module (may be also "WinDirectX" or "WinOpenGL") using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule("WinGDI.txv", false, true)) { // create graphics device using (Teigha.GraphicsSystem.Device graphichsDevice = gsModule.CreateDevice()) { // setup device properties using (Dictionary props = graphichsDevice.Properties) { if (props.Contains("WindowHWND")) // Check if property is supported { props.AtPut("WindowHWND", new RxVariant((Int32)panel1.Handle)); // hWnd necessary for DirectX device } if (props.Contains("WindowHDC")) // Check if property is supported { props.AtPut("WindowHDC", new RxVariant(graphics.GetHdc())); // hWindowDC necessary for Bitmap device } if (props.Contains("DoubleBufferEnabled")) // Check if property is supported { props.AtPut("DoubleBufferEnabled", new RxVariant(true)); } if (props.Contains("EnableSoftwareHLR")) // Check if property is supported { props.AtPut("EnableSoftwareHLR", new RxVariant(true)); } if (props.Contains("DiscardBackFaces")) // Check if property is supported { props.AtPut("DiscardBackFaces", new RxVariant(true)); } } // setup paperspace viewports or tiles ContextForDbDatabase ctx = new ContextForDbDatabase(database); ctx.UseGsModel = true; helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(graphichsDevice, ctx); Aux.preparePlotstyles(database, ctx); gripManager.init(helperDevice, helperDevice.Model, database); //helperDevice.ActiveView.Mode = Teigha.GraphicsSystem.RenderMode.HiddenLine; } } // set palette helperDevice.SetLogicalPalette(Device.DarkPalette); // set output extents resize(); helperDevice.Model.Invalidate(InvalidationHint.kInvalidateAll); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
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(); } } } } }
private void button1_Click(object sender, EventArgs e) { if (DialogResult.OK == openFileDialog.ShowDialog()) { using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule("WinDirectX.txv", false, true)) { // create graphics device using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice()) { // setup device properties using (Dictionary props = dev.Properties) { props.AtPut("BitPerPixel", new RxVariant(int.Parse(comboBox1.Text))); } ContextForDbDatabase ctx = new ContextForDbDatabase(database); ctx.PaletteBackground = colorDialog.Color; LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx); helperDevice.SetLogicalPalette(Device.LightPalette); // light palette Rectangle rect = new Rectangle(0, 0, (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value); helperDevice.OnSize(rect); ctx.SetPlotGeneration(checkBoxPlotGeneration.Checked); if (ctx.IsPlotGeneration) { helperDevice.BackgroundColor = colorDialog.Color; } else { helperDevice.BackgroundColor = Color.FromArgb(0, 173, 174, 173); } helperDevice.Update(); if (DialogResult.OK == saveFileDialog.ShowDialog()) { Export_Import.ExportBitmap(helperDevice, saveFileDialog.FileName); Close(); } } } } }
public void Print(Database db, Teigha.GraphicsSystem.View pView, bool bPreview) { database = db; pViewDr = pView; ObjectId idLayout = database.CurrentSpaceId; using (BlockTableRecord btr = (BlockTableRecord)database.CurrentSpaceId.GetObject(OpenMode.ForRead)) { using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead)) { PrintDocument prDoc = new PrintDocument(); prDoc.PrintPage += new PrintPageEventHandler(this.PrintPage); prDoc.PrinterSettings.PrinterName = pLayout.PlotConfigurationName; PageSettings pageSetting = prDoc.DefaultPageSettings; PlotRotation rotation = pLayout.PlotRotation; if (rotation == PlotRotation.Degrees090 || rotation == PlotRotation.Degrees270) { pageSetting.Landscape = true; } else { pageSetting.Landscape = false; } Double kMmPerInch = 10 / 2.54; Point2d ptPaperSize = pLayout.PlotPaperSize; PaperSize ps = new PaperSize(pLayout.CanonicalMediaName, (int)(ptPaperSize.X * kMmPerInch), (int)(ptPaperSize.Y * kMmPerInch)); pageSetting.PaperSize = ps; //default as OdaMfc pageSetting.Margins.Left = 0; pageSetting.Margins.Right = 0; pageSetting.Margins.Top = 0; pageSetting.Margins.Bottom = 0; prDoc.DefaultPageSettings = pageSetting; if (prDoc.PrinterSettings.IsValid) { try { //WinGDI, WinOpenGL using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule("WinGDI.txv", false, true)) { using (Teigha.GraphicsSystem.Device graphichsDevice = gsModule.CreateDevice()) { using (ContextForDbDatabase ctx = new ContextForDbDatabase(database)) { ctx.SetPlotGeneration(true); ctx.UseGsModel = true; m_pPrinterDevice = LayoutHelperDevice.SetupActiveLayoutViews(graphichsDevice, ctx); m_pPrinterDevice.BackgroundColor = Color.FromArgb(0, 255, 255, 255); m_pPrinterDevice.SetLogicalPalette(Device.LightPalette); Aux.preparePlotstyles(database, ctx); } } } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } if (bPreview) { PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog(); printPreviewDialog.Document = prDoc; printPreviewDialog.ShowDialog(); } else { prDoc.Print(); } m_pPrinterDevice = null; database = null; pViewDr = null; } } } }