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 Publish(Database database, Teigha.GraphicsSystem.LayoutHelperDevice helperDevice) { using (mDwfExportParams param = new mDwfExportParams()) { param.Database = database; param.BackgroundColor = helperDevice.BackgroundColor; param.InkedArea = false; param.ColorMapOptimize = false; PublishDrawingSheets pds = new PublishDrawingSheets(param); if (DialogResult.OK == pds.ShowDialog()) { Export_Import.ExportDwf(param); } } }
private void DisposeCadComponent() { try { ClearSelection(); CadSelectionManager.Instance.Dispose(); if (selRect != null) { helperDevice.ActiveView.Erase(selRect); } selRect = null; if (gripManager != null) { gripManager.uninit(); gripManager = null; } if (graphics != null) { graphics.Dispose(); } if (helperDevice != null) { if (!helperDevice.IsDisposed) { helperDevice.Dispose(); helperDevice = null; } } if (database != null) { if (!database.IsDisposed) { database.Dispose(); database = null; } } if (dd != null) { dd.Dispose(); dd = null; } } catch (System.Exception ex) { Debug.WriteLine(ex.Message); } }
public static void Publish3d(Database database, Teigha.GraphicsSystem.LayoutHelperDevice helperDevice) { SaveFileDialog sfd = new SaveFileDialog(); sfd.AddExtension = true; sfd.DefaultExt = "dwf"; sfd.Title = "3D DWF Publish"; sfd.Filter = String.Format("3D DWF (Desgin Web Format) v6.01 (*.dwf)|*.dwf"); if (sfd.ShowDialog() == DialogResult.OK) { using (mDwf3dExportParams param = new mDwf3dExportParams()) { param.Database = database; param.FileName = sfd.FileName; param.BackgroundColor = helperDevice.BackgroundColor; Export_Import.Publish3d(param); } } }
public static void DWF_export(Database database, Teigha.GraphicsSystem.LayoutHelperDevice helperDevice) { SaveFileDialog sfd = new SaveFileDialog(); sfd.AddExtension = true; sfd.DefaultExt = "dwf"; sfd.Title = "Export To Dwf"; sfd.Filter = String.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}", "Binary DWF (Desgin Web Format) v6.0 (*.dwf)|*.dwf", "Zipped Ascii Encoded 2D Stream DWF (Design Web Format) v6.0 (*.dwf)|*.dwf", "Compressed DWF (Design Web Format) v5.5 (*.dwf)|*.dwf", "Binary DWF (Design Web Format) v5.5 (*.dwf)|*.dwf", "Ascii DWF (Design Web Format) v5.5 (*.dwf)|*.dwf", "Compressed DWF (Design Web Format) v4.2 (*.dwf)|*.dwf", "Binary DWF (Design Web Format) v4.2 (*.dwf)|*.dwf", "Ascii DWF (Design Web Format) v4.2 (*.dwf)|*.dwf"); if (sfd.ShowDialog() == DialogResult.OK) { String strFileName = sfd.FileName; using (mDwfExportParams param = new mDwfExportParams()) { param.Database = database; param.FileName = strFileName; param.BackgroundColor = helperDevice.BackgroundColor; param.InkedArea = false; param.ColorMapOptimize = false; param.ExportInvisibleText = true; DwfPageDataCollection pageDataColl = new DwfPageDataCollection(); DWFPageData pageData; switch (sfd.FilterIndex) { case 1: param.Format = DwfFormat.UNCOMPRESSED_BINARY; param.Version = DwfVersion.Dwf_v60; pageData = new DWFPageData(); pageData.Layout = LayoutManager.Current.CurrentLayout; pageDataColl.Add(pageData); param.PageData = pageDataColl; break; case 2: param.Format = DwfFormat.ASCII; param.Version = DwfVersion.Dwf_v60; pageData = new DWFPageData(); pageData.Layout = LayoutManager.Current.CurrentLayout; pageDataColl.Add(pageData); param.PageData = pageDataColl; break; case 3: param.Format = DwfFormat.COMPRESSED_BINARY; param.Version = DwfVersion.Dwf_v55; break; case 4: param.Format = DwfFormat.UNCOMPRESSED_BINARY; param.Version = DwfVersion.Dwf_v55; break; case 5: param.Format = DwfFormat.ASCII; param.Version = DwfVersion.Dwf_v55; break; case 6: param.Format = DwfFormat.COMPRESSED_BINARY; param.Version = DwfVersion.Dwf_v42; break; case 7: param.Format = DwfFormat.UNCOMPRESSED_BINARY; param.Version = DwfVersion.Dwf_v42; break; case 8: param.Format = DwfFormat.ASCII; param.Version = DwfVersion.Dwf_v42; break; default: return; } Export_Import.ExportDwf(param); } } }
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; } } } }
private bool ChangePaper(string path) { if (lm != null) { lm.LayoutSwitched -= new Teigha.DatabaseServices.LayoutEventHandler(reinitGraphDevice); HostApplicationServices.WorkingDatabase = null; lm = null; } if (path == null) { splitContainer1.Panel2.Enabled = false; if (database != null) { database.Dispose(); database = null; } helperDevice = null; Invalidate(); return(true); } bool bLoaded = true; database = new Database(false, false); if (path.ToLower().LastIndexOf(".dwg") > 0) { try { database.ReadDwgFile(path, FileOpenMode.OpenForReadAndAllShare, false, ""); } catch (System.Exception ex) { MessageBox.Show(ex.Message); bLoaded = false; } } else if (path.ToLower().LastIndexOf(".dxf") > 0) { try { database.DxfIn(path, ""); } catch (System.Exception ex) { MessageBox.Show(ex.Message); bLoaded = false; } } if (bLoaded) { HostApplicationServices.WorkingDatabase = database; lm = LayoutManager.Current; lm.LayoutSwitched += new Teigha.DatabaseServices.LayoutEventHandler(reinitGraphDevice); String str = HostApplicationServices.Current.FontMapFileName; //menuStrip. splitContainer1.Panel2.Enabled = true; //this.Text = String.Format("OdViewExMgd - [{0}]", openFileDialog.SafeFileName); paperNow = Path.GetFileName(path); initializeGraphics(); Invalidate(); } return(bLoaded); }