private void LoadFromFile(string path, params object[] otherParams) { this.FilePath = path; this.DocumentName = Path.GetFileNameWithoutExtension(path); this.ExtensionName = Path.GetExtension(path); if (loadFileThread != null) { if (loadFileThread.IsAlive) { return; } } if (!string.IsNullOrEmpty(this.FilePath)) { if (cadImage != null) //处理现有打开的文档 { cadImage.DrawMatrixChanged -= new CADImport.EventHandler(cadImage_DrawMatrixChanged); cadImage.AfterRotate -= new CADImport.EventHandler(cadImage_AfterRotate); cadImage.Dispose(); cadImage = null; if (this.HostControl != null && this.HostControl.LayerControl != null) { this.HostControl.LayerControl.Clear(); } } this.HostControl.SetBusyCursor(); EventBus.Trigger(new MultiThreadStatusStartEventData("正在打开文件" + this.DocumentName + "...", this, this.HostControl)); cadImage = CADImage.CreateImageByExtension(FilePath); cadImage.NavigateDrawMatrix = navigateDrawMatrix; cadImage.visibleArea = ((Control)this.HostControl).ClientSize; cadImage.Painter.viewportRect = new DRect(0, 0, cadImage.visibleArea.Width, cadImage.visibleArea.Height); ImageRectangleF = new RectangleF(0, 0, (float)cadImage.AbsWidth, (float)cadImage.AbsHeight); cadImage.DrawMatrixChanged += new CADImport.EventHandler(cadImage_DrawMatrixChanged); cadImage.AfterRotate += new CADImport.EventHandler(cadImage_AfterRotate); CADImport.CADConst.DefaultSHXParameters.UseSHXFonts = cadImportConfiguration.UseSHXFonts; if (cadImportConfiguration.UseSHXFonts) { DoSHXFonts(); } else { DoTTFFonts(); } cadImage.GraphicsOutMode = cadImportConfiguration.DrawGraphicsMode; cadImage.ChangeDrawMode(cadImportConfiguration.DrawGraphicsMode, (Control)this.HostControl); cadImage.ChangeGraphicsMode(cadImportConfiguration.DrawGraphicsMode, renderMode); if (cadImage is CADRasterImage) { (cadImage as CADRasterImage).Control = (Control)this.HostControl; } } if (this.cadImage != null) { CADImage.CodePage = System.Text.Encoding.Default.CodePage;//note - charset was set here CADImage.LastLoadedFilePath = Path.GetDirectoryName(path); CreateNewLoadThread(path); } }
public void Close() { cadImage.Dispose(); cadImage = null; }