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 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; } } } }