示例#1
0
        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);
        }
示例#2
0
        public DwgDrawing()
        {
            FileHeader = new DwgFileHeader(DwgVersionId.Default, 0, 0, 0);
            Variables  = new DwgHeaderVariables();
            Classes    = new List <DwgClassDefinition>();

            var continuous = new DwgLineType("CONTINUOUS")
            {
                Description = "Solid line"
            };
            var defaultLayer = new DwgLayer("0")
            {
                LineType = continuous
            };
            var standardStyle      = new DwgStyle("STANDARD");
            var standardMLineStyle = DwgMLineStyle.GetDefaultMLineStyle();

            BlockHeaders = new DwgBlockControlObject()
            {
                DwgBlockHeader.GetPaperSpaceBlockRecord(defaultLayer),
                DwgBlockHeader.GetModelSpaceBlockRecord(defaultLayer)
            };
            Layers = new DwgLayerControlObject
            {
                defaultLayer
            };
            Styles = new DwgStyleControlObject()
            {
                standardStyle
            };
            LineTypes = new DwgLineTypeControlObject()
            {
                new DwgLineType("BYLAYER"),
                new DwgLineType("BYBLOCK"),
                continuous
            };
            Views     = new DwgViewControlObject();
            UCSs      = new DwgUCSControlObject();
            ViewPorts = new DwgViewPortControlObject()
            {
                DwgViewPort.GetActiveViewPort()
            };
            AppIds = new DwgAppIdControlObject()
            {
                DwgAppId.GetAcadAppId(),
                    DwgAppId.GetAcadMLeaderVersionAppId()
            };
            DimStyles = new DwgDimStyleControlObject()
            {
                DwgDimStyle.GetStandardDimStyle(standardStyle)
            };
            ViewPortEntityHeaders = new DwgViewPortEntityHeaderControlObject();
            GroupDictionary       = new DwgDictionary();
            MLineStyleDictionary  = new DwgDictionary()
            {
                { standardMLineStyle.Name, standardMLineStyle }
            };
            NamedObjectDictionary = new DwgDictionary();

            PaperSpaceBlockRecord = BlockHeaders["*PAPER_SPACE"];
            ModelSpaceBlockRecord = BlockHeaders["*MODEL_SPACE"];
            ByLayerLineType       = LineTypes["BYLAYER"];
            ByBlockLineType       = LineTypes["BYBLOCK"];
            ContinuousLineType    = LineTypes["CONTINUOUS"];
            CurrentLayer          = Layers["0"];
            TextStyle             = Styles["STANDARD"];
            CurrentEntityLineType = LineTypes["BYBLOCK"];
            DimensionStyle        = DimStyles["STANDARD"];
            CurrentMultiLineStyle = (DwgMLineStyle)MLineStyleDictionary["Standard"];
            DimensionTextStyle    = Styles["STANDARD"];
        }
示例#3
0
        internal static DwgFileHeader Parse(BitReader reader)
        {
            reader.StartCrcCheck();
            var versionString = reader.ReadStringAscii(6);
            var version       = DwgVersionIdExtensions.VersionIdFromString(versionString);
            var unknown1      = reader.ReadBytes(6);
            var maintVer      = 0;

            if (version == DwgVersionId.R14)
            {
                maintVer = unknown1[5];
            }

            var marker = reader.ReadByte();

            if (marker != 1)
            {
                throw new DwgReadException("Expected value of 1 at offset 13.");
            }

            var imagePointer = reader.ReadInt();
            var unknown2     = reader.ReadBytes(2);
            var codePage     = reader.ReadShort();

            var header = new DwgFileHeader(version, maintVer, imagePointer, codePage);

            var recordLocatorCount = reader.ReadInt();

            for (int i = 0; i < recordLocatorCount; i++)
            {
                var locator = DwgSectionLocator.Parse(reader);
                switch (i)
                {
                case 0:
                    header.HeaderVariablesLocator = locator;
                    break;

                case 1:
                    header.ClassSectionLocator = locator;
                    break;

                case 2:
                    header.ObjectMapLocator = locator;
                    break;

                case 3:
                    header.UnknownSection_R13C3AndLaterLocator = locator;
                    break;

                case 4:
                    header.UnknownSection_PaddingLocator = locator;
                    break;
                }
            }

            ushort crcXorValue;

            switch (recordLocatorCount)
            {
            case 0:
            case 1:
            case 2:
                crcXorValue = 0;
                break;

            case 3:
                crcXorValue = 0xAD98;
                break;

            case 4:
                crcXorValue = 0x8101;
                break;

            case 5:
                crcXorValue = 0x3CC4;
                break;

            case 6:
                crcXorValue = 0x8461;
                break;

            default:
                throw new DwgReadException("Unsupported record locator count.");
            }

            reader.ValidateCrc(xorValue: crcXorValue);
            reader.ValidateSentinel(HeaderSentinel);

            return(header);
        }