public static DwgObjectCache Parse(BitReader reader, DwgVersionId version) { var objectCache = new DwgObjectCache(version); var lastHandle = 0; var lastLocation = 0; reader.StartCrcCheck(); var sectionSize = reader.ReadShortBigEndian(); while (sectionSize != 2) { var sectionStart = reader.Offset; var sectionEnd = sectionStart + sectionSize - 2; while (reader.Offset < sectionEnd) { // read data var handleOffset = reader.Read_MC(allowNegation: false); var locationOffset = reader.Read_MC(); var handle = lastHandle + handleOffset; var location = lastLocation + locationOffset; objectCache._handleToOffset.Add(handle, location); lastHandle = handle; lastLocation = location; } reader.ValidateCrc(initialValue: DwgHeaderVariables.InitialCrcValue, readCrcAsMsb: true); reader.StartCrcCheck(); sectionSize = reader.ReadShortBigEndian(); } reader.ValidateCrc(initialValue: DwgHeaderVariables.InitialCrcValue, readCrcAsMsb: true); return(objectCache); }
private void LoadObjects(BitReader reader, DwgObjectCache objectCache) { AssertHandleType(Variables.BlockControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.BlockControlObjectHandle)); AssertHandleType(Variables.LayerControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.LayerControlObjectHandle)); AssertHandleType(Variables.StyleObjectControlHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.StyleObjectControlHandle)); AssertHandleType(Variables.LineTypeObjectControlHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.LineTypeObjectControlHandle)); AssertHandleType(Variables.ViewControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.ViewControlObjectHandle)); AssertHandleType(Variables.UcsControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.UcsControlObjectHandle)); AssertHandleType(Variables.ViewPortControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.ViewPortControlObjectHandle)); AssertHandleType(Variables.AppIdControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.AppIdControlObjectHandle)); AssertHandleType(Variables.DimStyleControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.DimStyleControlObjectHandle)); AssertHandleType(Variables.ViewPortEntityHeaderControlObjectHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.ViewPortEntityHeaderControlObjectHandle)); AssertHandleType(Variables.GroupDictionaryHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.GroupDictionaryHandle)); AssertHandleType(Variables.MLineStyleDictionaryHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.MLineStyleDictionaryHandle)); AssertHandleType(Variables.NamedObjectsDictionaryHandle, DwgHandleReferenceCode.SoftPointer, nameof(Variables.NamedObjectsDictionaryHandle)); AssertHandleType(Variables.PaperSpaceBlockRecordHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.PaperSpaceBlockRecordHandle)); AssertHandleType(Variables.ModelSpaceBlockRecordHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.ModelSpaceBlockRecordHandle)); AssertHandleType(Variables.ByLayerLineTypeHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.ByLayerLineTypeHandle)); AssertHandleType(Variables.ByBlockLineTypeHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.ByBlockLineTypeHandle)); AssertHandleType(Variables.ContinuousLineTypeHandle, DwgHandleReferenceCode.SoftOwner, nameof(Variables.ContinuousLineTypeHandle)); BlockHeaders = objectCache.GetObject <DwgBlockControlObject>(reader, Variables.BlockControlObjectHandle.HandleOrOffset); Layers = objectCache.GetObject <DwgLayerControlObject>(reader, Variables.LayerControlObjectHandle.HandleOrOffset); Styles = objectCache.GetObject <DwgStyleControlObject>(reader, Variables.StyleObjectControlHandle.HandleOrOffset); LineTypes = objectCache.GetObject <DwgLineTypeControlObject>(reader, Variables.LineTypeObjectControlHandle.HandleOrOffset); Views = objectCache.GetObject <DwgViewControlObject>(reader, Variables.ViewControlObjectHandle.HandleOrOffset); UCSs = objectCache.GetObject <DwgUCSControlObject>(reader, Variables.UcsControlObjectHandle.HandleOrOffset); ViewPorts = objectCache.GetObject <DwgViewPortControlObject>(reader, Variables.ViewPortControlObjectHandle.HandleOrOffset); AppIds = objectCache.GetObject <DwgAppIdControlObject>(reader, Variables.AppIdControlObjectHandle.HandleOrOffset); DimStyles = objectCache.GetObject <DwgDimStyleControlObject>(reader, Variables.DimStyleControlObjectHandle.HandleOrOffset); ViewPortEntityHeaders = objectCache.GetObject <DwgViewPortEntityHeaderControlObject>(reader, Variables.ViewPortEntityHeaderControlObjectHandle.HandleOrOffset); GroupDictionary = objectCache.GetObject <DwgDictionary>(reader, Variables.GroupDictionaryHandle.HandleOrOffset); MLineStyleDictionary = objectCache.GetObject <DwgDictionary>(reader, Variables.MLineStyleDictionaryHandle.HandleOrOffset); NamedObjectDictionary = objectCache.GetObject <DwgDictionary>(reader, Variables.NamedObjectsDictionaryHandle.HandleOrOffset); PaperSpaceBlockRecord = objectCache.GetObject <DwgBlockHeader>(reader, Variables.PaperSpaceBlockRecordHandle.HandleOrOffset); ModelSpaceBlockRecord = objectCache.GetObject <DwgBlockHeader>(reader, Variables.ModelSpaceBlockRecordHandle.HandleOrOffset); ByLayerLineType = objectCache.GetObject <DwgLineType>(reader, Variables.ByLayerLineTypeHandle.HandleOrOffset); ByBlockLineType = objectCache.GetObject <DwgLineType>(reader, Variables.ByBlockLineTypeHandle.HandleOrOffset); ContinuousLineType = objectCache.GetObject <DwgLineType>(reader, Variables.ContinuousLineTypeHandle.HandleOrOffset); CurrentViewPort = objectCache.GetObjectOrDefault <DwgViewPort>(reader, Variables.CurrentViewPortEntityHandle.HandleOrOffset); CurrentLayer = objectCache.GetObject <DwgLayer>(reader, Variables.CurrentLayerHandle.HandleOrOffset); TextStyle = objectCache.GetObject <DwgStyle>(reader, Variables.TextStyleHandle.HandleOrOffset); CurrentEntityLineType = objectCache.GetObject <DwgLineType>(reader, Variables.CurrentEntityLineTypeHandle.HandleOrOffset); DimensionStyle = objectCache.GetObject <DwgDimStyle>(reader, Variables.DimensionStyleHandle.HandleOrOffset); CurrentMultiLineStyle = objectCache.GetObject <DwgMLineStyle>(reader, Variables.CurrentMultiLineStyleHandle.HandleOrOffset); PaperSpaceCurrentUCS = objectCache.GetObjectOrDefault <DwgUCS>(reader, Variables.PaperSpaceCurrentUCSHandle.HandleOrOffset); CurrentUCS = objectCache.GetObjectOrDefault <DwgUCS>(reader, Variables.CurrentUCSHandle.HandleOrOffset); DimensionTextStyle = objectCache.GetObject <DwgStyle>(reader, Variables.DimensionTextStyleHandle.HandleOrOffset); }
public static DwgDrawing Load(byte[] data) { var reader = new BitReader(data); var drawing = new DwgDrawing(); drawing.FileHeader = DwgFileHeader.Parse(reader); drawing.Variables = DwgHeaderVariables.Parse(reader.FromOffset(drawing.FileHeader.HeaderVariablesLocator.Pointer), drawing.FileHeader.Version); drawing.Classes = DwgClasses.Parse(reader.FromOffset(drawing.FileHeader.ClassSectionLocator.Pointer), drawing.FileHeader.Version); // don't read the R13C3 and later unknown section drawing.FileHeader.ValidateSecondHeader(reader, drawing.Variables); drawing.ImageData = DwgImageData.Parse(reader.FromOffset(drawing.FileHeader.ImagePointer)); var objectCache = DwgObjectCache.Parse(reader.FromOffset(drawing.FileHeader.ObjectMapLocator.Pointer), drawing.FileHeader.Version); drawing.LoadObjects(reader, objectCache); return(drawing); }