Exemplo n.º 1
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            if (LayerHandle.Code != DwgHandleReferenceCode.SoftOwner && LayerHandle.Code != DwgHandleReferenceCode.HardOwner)
            {
                throw new DwgReadException("Incorrect layer handle code.");
            }

            if (!_isLineTypeByLayer && (LineTypeHandle.IsEmpty || !LineTypeHandle.IsValidNavigationHandle))
            {
                throw new DwgReadException("Incorrect line type handle code.");
            }

            if (!_noLinks && !PreviousEntityHandle.IsNullNavigationHandle && !PreviousEntityHandle.IsValidNavigationHandle)
            {
                throw new DwgReadException("Invalid previous entity handle code.");
            }

            if (!_noLinks && !NextEntityHandle.IsNullNavigationHandle && !NextEntityHandle.IsValidNavigationHandle)
            {
                throw new DwgReadException("Invalid next entity handle code.");
            }

            if (_entityMode == 0 && !_subentityRef.IsValidNavigationHandle)
            {
                throw new DwgReadException("Incorrect sub entity handle code.");
            }

            Layer = objectCache.GetObject <DwgLayer>(reader, GetNavigationHandle(LayerHandle).HandleOrOffset);
            if (!_isLineTypeByLayer)
            {
                LineType = objectCache.GetObject <DwgLineType>(reader, GetNavigationHandle(LineTypeHandle).HandleOrOffset);
            }

            OnAfterEntityRead(reader, objectCache);
        }
Exemplo n.º 2
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            if (BlockControlHandle.Code != DwgHandleReferenceCode.HardPointer)
            {
                throw new DwgReadException("Incorrect block header control object parent handle code.");
            }

            if (BlockEntityHandle.Code != DwgHandleReferenceCode.SoftPointer)
            {
                throw new DwgReadException("Incorrect block entity handle code.");
            }

            if (!IsXRef && !IsOverlaidXref)
            {
                if (_firstEntityHandle.Code != DwgHandleReferenceCode.HardPointer)
                {
                    throw new DwgReadException("Incorrect first entity handle code.");
                }

                if (_lastEntityHandle.Code != DwgHandleReferenceCode.HardPointer)
                {
                    throw new DwgReadException("Incorrect last entity handle code.");
                }
            }

            if (EndBlockEntityHandle.Code != DwgHandleReferenceCode.SoftPointer)
            {
                throw new DwgReadException("Incorrect end block entity handle code.");
            }

            Block    = objectCache.GetObject <DwgBlock>(reader, BlockEntityHandle.HandleOrOffset);
            EndBlock = objectCache.GetObject <DwgEndBlock>(reader, EndBlockEntityHandle.HandleOrOffset);
            LoadEntities(reader, objectCache);
        }
Exemplo n.º 3
0
        private void LoadEntities(BitReader reader, DwgObjectCache objectCache)
        {
            var isModelSpaceBlock = IsModelSpaceBlock;
            var isPaperSpaceBlock = IsPaperSpaceBlock;

            Entities.Clear();
            var currentEntityHandle = _firstEntityHandle;

            while (currentEntityHandle.HandleOrOffset != 0)
            {
                var obj = objectCache.GetObject(reader, currentEntityHandle.HandleOrOffset, allowNull: true);
                if (obj is DwgEntity entity)
                {
                    Entities.Add(entity);
                    currentEntityHandle = currentEntityHandle.GetNextHandle(entity.NextEntityHandle);
                    if (isModelSpaceBlock && entity._entityMode != 0b10)
                    {
                        throw new DwgReadException("Expected entity mode 2 for children of model space block.");
                    }
                    if (isPaperSpaceBlock && entity._entityMode != 0b01)
                    {
                        throw new DwgReadException("Expected entity mode 1 for children of paper space block.");
                    }
                    if (!isModelSpaceBlock && !isPaperSpaceBlock && entity._entityMode != 0b00)
                    {
                        throw new DwgReadException("Expected entity mode 0 for children of regular blocks.");
                    }
                }
                else
                {
                    currentEntityHandle = default(DwgHandleReference);
                }
            }
        }
Exemplo n.º 4
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _blockHeaders.Clear();
            foreach (var blockHeaderHandle in _entityHandles)
            {
                if (blockHeaderHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child block header handle code.");
                }

                var blockHeader = objectCache.GetObject<DwgBlockHeader>(reader, blockHeaderHandle.HandleOrOffset);
                if (!blockHeader.BlockControlHandle.IsEmpty && blockHeader.BlockControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect block header control object parent handle reference.");
                }

                _blockHeaders.Add(blockHeader.Name, blockHeader);
            }

            if (_modelSpaceBlockHeaderHandle.Code != DwgHandleReferenceCode.SoftPointer)
            {
                throw new DwgReadException("Incorrect model space block header handle code.");
            }

            if (_paperSpaceBlockHeaderHandle.Code != DwgHandleReferenceCode.SoftPointer)
            {
                throw new DwgReadException("Incorrect paper space block header handle code.");
            }
        }
Exemplo n.º 5
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _entries.Clear();
            if (_entityHandles.Count != _names.Count)
            {
                throw new DwgReadException("Mismatch between reported entry count and entry handles/names read.");
            }

            for (int i = 0; i < _entityHandles.Count; i++)
            {
                var entryHandle = _entityHandles[i];
                var name        = _names[i];
                if (entryHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child entry handle code.");
                }

                if (entryHandle.HandleOrOffset != 0)
                {
                    var entry = objectCache.GetObject(reader, entryHandle.HandleOrOffset, allowNull: true);
                    // TODO: check parent handle
                    if (entry != null)
                    {
                        _entries.Add(name, entry);
                    }
                }
            }
        }
Exemplo n.º 6
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            if (LayerControlHandle.Code != DwgHandleReferenceCode.HardPointer)
            {
                throw new DwgReadException("Incorrect layer control object parent handle code.");
            }

            if (_lineTypeHandle.Code != DwgHandleReferenceCode.SoftOwner)
            {
                throw new DwgReadException("Incorrect layer line type handle code.");
            }

            LineType = objectCache.GetObject <DwgLineType>(reader, _lineTypeHandle.HandleOrOffset);
        }
Exemplo n.º 7
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            if (DimStyleControlHandle.Code != DwgHandleReferenceCode.HardPointer)
            {
                throw new DwgReadException("Incorrect style control object parent handle code.");
            }

            if (_styleHandle.Code != DwgHandleReferenceCode.SoftOwner)
            {
                throw new DwgReadException("Incorrect style handle code.");
            }

            Style = objectCache.GetObject <DwgStyle>(reader, _styleHandle.HandleOrOffset);
        }
Exemplo n.º 8
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _ucs.Clear();
            foreach (var ucsHandle in _entityHandles)
            {
                if (ucsHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child UCS handle code.");
                }

                var ucs = objectCache.GetObject <DwgUCS>(reader, ucsHandle.HandleOrOffset);
                if (ucs.UCSControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect UCS control object parent handle reference.");
                }

                _ucs.Add(ucs.Name, ucs);
            }
        }
Exemplo n.º 9
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _styles.Clear();
            foreach (var styleHandle in _entityHandles)
            {
                if (styleHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child style handle code.");
                }

                var style = objectCache.GetObject <DwgDimStyle>(reader, styleHandle.HandleOrOffset);
                if (style.DimStyleControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect style control object parent handle reference.");
                }

                _styles.Add(style.Name, style);
            }
        }
Exemplo n.º 10
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _lineTypes.Clear();
            foreach (var lineTypeHandle in _entityHandles)
            {
                if (lineTypeHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child line type handle code.");
                }

                var lineType = objectCache.GetObject <DwgLineType>(reader, lineTypeHandle.HandleOrOffset);
                if (!lineType.LineTypeControlHandle.IsEmpty && lineType.LineTypeControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect line type control object parent handle reference.");
                }

                _lineTypes.Add(lineType.Name, lineType);
            }
        }
Exemplo n.º 11
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _viewPortEntityHeaders.Clear();
            foreach (var viewPortEntityHeaderHandle in _entityHandles)
            {
                if (viewPortEntityHeaderHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child view port entity header handle code.");
                }

                var viewPortEntityHeader = objectCache.GetObject <DwgViewPortEntityHeader>(reader, viewPortEntityHeaderHandle.HandleOrOffset);
                if (viewPortEntityHeader.ViewPortEntityHeaderControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect view port entity header control object parent handle reference.");
                }

                _viewPortEntityHeaders.Add(viewPortEntityHeader.Name, viewPortEntityHeader);
            }
        }
Exemplo n.º 12
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _appIds.Clear();
            foreach (var appIdHandle in _entityHandles)
            {
                if (appIdHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child app id handle code.");
                }

                var appId = objectCache.GetObject <DwgAppId>(reader, appIdHandle.HandleOrOffset);
                if (appId.AppIdControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect app id control object parent handle reference.");
                }

                _appIds.Add(appId.Name, appId);
            }
        }
Exemplo n.º 13
0
        internal override void OnAfterObjectRead(BitReader reader, DwgObjectCache objectCache)
        {
            _layers.Clear();
            _layersFromHandle.Clear();
            foreach (var layerHandle in _entityHandles)
            {
                if (layerHandle.Code != DwgHandleReferenceCode.None)
                {
                    throw new DwgReadException("Incorrect child layer handle code.");
                }

                var layer = objectCache.GetObject <DwgLayer>(reader, layerHandle.HandleOrOffset);
                if (layer.LayerControlHandle.HandleOrOffset != Handle.HandleOrOffset)
                {
                    throw new DwgReadException("Incorrect layer control object parent handle reference.");
                }

                _layers.Add(layer.Name, layer);
                _layersFromHandle.Add(layer.Handle.HandleOrOffset, layer);
            }
        }