Exemplo n.º 1
0
        protected void readCommonObjectData(CadTemplate template)
        {
            while (this._reader.LastDxfCode != DxfCode.Subclass)
            {
                switch (this._reader.LastCode)
                {
                //object name
                case 0:
                    Debug.Assert(template.CadObject.ObjectName == this._reader.LastValueAsString);
                    break;

                //Handle
                case 5:
                    template.CadObject.Handle = this._reader.LastValueAsHandle;
                    break;

                //Start of application - defined group
                case 102:
                    this.readDefinedGroups(template);
                    continue;

                //Soft - pointer ID / handle to owner BLOCK_RECORD object
                case 330:
                    template.OwnerHandle = this._reader.LastValueAsHandle;
                    break;

                default:
                    this._notification?.Invoke(null, new NotificationEventArgs($"Unhandeled dxf code {this._reader.LastCode} at line {this._reader.Line}."));
                    break;
                }

                this._reader.ReadNext();
            }
        }
Exemplo n.º 2
0
        private void readDefinedGroups(CadTemplate template)
        {
            this.readDefinedGroups(out ulong?xdict, out List <ulong> reactorsHandles);

            template.XDictHandle     = xdict;
            template.ReactorsHandles = template.ReactorsHandles;
        }
Exemplo n.º 3
0
        private CadTemplate readObject()
        {
            CadTemplate template = null;

            switch (this._reader.LastValueAsString)
            {
            case DxfFileToken.ObjectDictionary:
                return(this.readDictionary());

            case DxfFileToken.ObjectLayout:
                template = new CadLayoutTemplate(new Layout());
                break;

            case DxfFileToken.TableXRecord:
                template = new CadXRecordTemplate(new XRecrod());
                break;

            default:
                this._notification?.Invoke(null, new NotificationEventArgs($"Object not implemented: {this._reader.LastValueAsString}"));
                do
                {
                    this._reader.ReadNext();
                }while (this._reader.LastDxfCode != DxfCode.Start);
                return(null);
            }

            //Jump the 0 marker
            this._reader.ReadNext();

            this.readCommonObjectData(template);

            while (this._reader.LastDxfCode == DxfCode.Subclass)
            {
                switch (this._reader.LastValueAsString)
                {
                case DxfSubclassMarker.Layout:
                    this.readMapped <Layout>(template.CadObject, template);
                    break;

                case DxfSubclassMarker.PlotSettings:
                    this.readMapped <PlotSettings>(template.CadObject, template);
                    break;

                case DxfSubclassMarker.XRecord:
                    this.readMapped <XRecrod>(template.CadObject, template);
                    break;

                default:
                    this._notification?.Invoke(null, new NotificationEventArgs($"Unhandeled dxf entity subclass {this._reader.LastValueAsString}"));
                    while (this._reader.LastDxfCode != DxfCode.Start)
                    {
                        this._reader.ReadNext();
                    }
                    break;
                }
            }

            return(template);
        }
Exemplo n.º 4
0
        public override void Read()
        {
            //Advance to the first value in the section
            this._reader.ReadNext();

            //Loop until the section ends
            while (this._reader.LastValueAsString != DxfFileToken.EndSection)
            {
                CadTemplate template = this.readObject();

                if (template == null)
                {
                    continue;
                }

                //Add the object and the template to the builder
                this._builder.AddTemplate(template);
            }
        }
Exemplo n.º 5
0
        private void assignOwners(CadTemplate template)
        {
            if (template.CadObject.Owner != null || template.CadObject is CadDictionary)
            {
                return;
            }

            if (this.TryGetCadObject(template.OwnerHandle, out CadObject owner))
            {
                switch (owner)
                {
                case CadDictionary:
                    //Entries of the dictionary are assigned in the template
                    break;

                case BlockRecord record when template.CadObject is Entity entity:
                    record.Entities.Add(entity);
                    break;

                case Polyline pline when template.CadObject is Vertex v:
                    pline.Vertices.Add(v);
                    break;

                case Insert insert when template.CadObject is AttributeEntity att:
                    insert.Attributes.Add(att);
                    break;

                default:
                    this.NotificationHandler?.Invoke(null, new NotificationEventArgs($"Owner {owner.GetType().Name} with handle {owner.Handle} assignation not implemented for {template.CadObject.GetType().Name} with handle {template.CadObject.Handle}"));
                    break;
                }
            }
            else
            {
                this.NotificationHandler?.Invoke(null, new NotificationEventArgs($"Owner {template.OwnerHandle} not found for {template.GetType().FullName} with handle {template.CadObject.Handle}"));
            }
        }
Exemplo n.º 6
0
 public void AddTemplate(CadTemplate template)
 {
     this.templates[template.CadObject.Handle]  = template;
     this.cadObjects[template.CadObject.Handle] = template.CadObject;
 }
Exemplo n.º 7
0
        private void readTable()
        {
            Debug.Assert(this._reader.LastValueAsString == DxfFileToken.TableEntry);

            //Read the table name
            this._reader.ReadNext();

            int nentries = 0;

            this.readCommonObjectData(out string name, out ulong handle, out ulong?ownerHandle, out ulong?xdictHandle, out List <ulong> reactors);

            Debug.Assert(this._reader.LastValueAsString == DxfSubclassMarker.Table);

            this._reader.ReadNext();

            while (this._reader.LastDxfCode != DxfCode.Start)
            {
                switch (this._reader.LastCode)
                {
                //Maximum number of entries in table
                case 70:
                    nentries = this._reader.LastValueAsInt;
                    break;

                case 100 when this._reader.LastValueAsString == DxfSubclassMarker.DimensionStyleTable:
                    while (this._reader.LastDxfCode != DxfCode.Start)
                    {
                        //Dimstyle has the code 71 for the count of entries
                        //Also has 340 codes for each entry with the handles
                        this._reader.ReadNext();
                    }
                    break;

                default:
                    this._notification?.Invoke(null, new NotificationEventArgs($"Unhandeled dxf code {this._reader.LastCode} at line {this._reader.Line}."));
                    break;
                }

                if (this._reader.LastDxfCode == DxfCode.Start)
                {
                    break;
                }

                this._reader.ReadNext();
            }

            CadTemplate template = null;

            switch (name)
            {
            case DxfFileToken.TableAppId:
                template = new DwgTableTemplate <AppId>(new AppIdsTable());
                this.readEntries((DwgTableTemplate <AppId>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((AppIdsTable)template.CadObject);
                break;

            case DxfFileToken.TableBlockRecord:
                template = new DwgBlockCtrlObjectTemplate(new BlockRecordsTable());
                this.readEntries((DwgBlockCtrlObjectTemplate)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((BlockRecordsTable)template.CadObject);
                break;

            case DxfFileToken.TableVport:
                template = new DwgTableTemplate <VPort>(new VPortsTable());
                this.readEntries((DwgTableTemplate <VPort>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((VPortsTable)template.CadObject);
                break;

            case DxfFileToken.TableLinetype:
                template = new DwgTableTemplate <LineType>(new LineTypesTable());
                this.readEntries((DwgTableTemplate <LineType>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((LineTypesTable)template.CadObject);
                break;

            case DxfFileToken.TableLayer:
                template = new DwgTableTemplate <Layer>(new LayersTable());
                this.readEntries((DwgTableTemplate <Layer>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((LayersTable)template.CadObject);
                break;

            case DxfFileToken.TableStyle:
                template = new DwgTableTemplate <TextStyle>(new TextStylesTable());
                this.readEntries((DwgTableTemplate <TextStyle>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((TextStylesTable)template.CadObject);
                break;

            case DxfFileToken.TableView:
                template = new DwgTableTemplate <View>(new ViewsTable());
                this.readEntries((DwgTableTemplate <View>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((ViewsTable)template.CadObject);
                break;

            case DxfFileToken.TableUcs:
                template = new DwgTableTemplate <UCS>(new UCSTable());
                this.readEntries((DwgTableTemplate <UCS>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((UCSTable)template.CadObject);
                break;

            case DxfFileToken.TableDimstyle:
                template = new DwgTableTemplate <DimensionStyle>(new DimensionStylesTable());
                this.readEntries((DwgTableTemplate <DimensionStyle>)template);
                template.CadObject.Handle = handle;
                this._builder.DocumentToBuild.RegisterCollection((DimensionStylesTable)template.CadObject);
                break;

            default:
                throw new DxfException($"Unknown table name {name}");
            }

            Debug.Assert(ownerHandle == null || ownerHandle.Value == 0);

            template.OwnerHandle     = ownerHandle;
            template.XDictHandle     = xdictHandle;
            template.ReactorsHandles = reactors;

            //Add the object and the template to the builder
            this._builder.AddTableTemplate((ICadTableTemplate)template);
        }
Exemplo n.º 8
0
        private void readEntries <T>(DwgTableTemplate <T> tableTemplate)
            where T : TableEntry
        {
            //Read all the entries until the end of the table
            while (this._reader.LastValueAsString != DxfFileToken.EndTable)
            {
                this.readCommonObjectData(out string name, out ulong handle, out ulong?ownerHandle, out ulong?xdictHandle, out List <ulong> reactors);

                Debug.Assert(this._reader.LastValueAsString == DxfSubclassMarker.TableRecord);
                Debug.Assert(this._reader.LastValueAsString == DxfSubclassMarker.TableRecord);

                this._reader.ReadNext();

                CadTemplate template = null;

                //Get the entry
                switch (name)
                {
                case DxfFileToken.TableAppId:
                    AppId appid = new AppId();
                    template = new CadTableEntryTemplate <AppId>(appid);
                    this.readMapped <AppId>(appid, template);
                    break;

                case DxfFileToken.TableBlockRecord:
                    BlockRecord record = new BlockRecord();
                    template = new CadBlockRecordTemplate(record);
                    this.readMapped <BlockRecord>(record, template);
                    break;

                case DxfFileToken.TableDimstyle:
                    DimensionStyle dimStyle = new DimensionStyle();
                    template = new DwgDimensionStyleTemplate(dimStyle);
                    this.readMapped <DimensionStyle>(dimStyle, template);
                    break;

                case DxfFileToken.TableLayer:
                    Layer layer = new Layer();
                    template = new CadLayerTemplate(layer);
                    this.readMapped <Layer>(layer, template);
                    break;

                case DxfFileToken.TableLinetype:
                    LineType ltype = new LineType();
                    template = new CadLineTypeTemplate(ltype);
                    this.readMapped <LineType>(ltype, template);
                    break;

                case DxfFileToken.TableStyle:
                    TextStyle style = new TextStyle();
                    template = new CadTableEntryTemplate <TextStyle>(style);
                    this.readMapped <TextStyle>(style, template);
                    break;

                case DxfFileToken.TableUcs:
                    UCS ucs = new UCS();
                    template = new CadUcsTemplate(ucs);
                    this.readMapped <UCS>(ucs, template);
                    break;

                case DxfFileToken.TableView:
                    View view = new View();
                    template = new CadViewTemplate(view);
                    this.readMapped <View>(view, template);
                    break;

                case DxfFileToken.TableVport:
                    VPort vport = new VPort();
                    template = new CadVPortTemplate(vport);
                    this.readMapped <VPort>(vport, template);
                    break;

                default:
                    Debug.Fail($"Unhandeled table {name}.");
                    break;
                }

                //Setup the common fields
                template.CadObject.Handle = handle;
                template.OwnerHandle      = ownerHandle;
                template.XDictHandle      = xdictHandle;
                template.ReactorsHandles  = reactors;

                tableTemplate.EntryHandles.Add(template.CadObject.Handle);

                //Add the object and the template to the builder
                this._builder.AddTemplate(template);
            }
        }
Exemplo n.º 9
0
        protected void readMapped <T>(CadObject cadObject, CadTemplate template)
            where T : CadObject
        {
            DxfClassMap map = DxfClassMap.Create <T>();

            Debug.Assert(map.Name == this._reader.LastValueAsString);
            this._reader.ReadNext();

            while (this._reader.LastDxfCode != DxfCode.Start &&
                   this._reader.LastDxfCode != DxfCode.Subclass)
            {
                //Check for an extended data code
                if (this._reader.LastDxfCode >= DxfCode.ExtendedDataAsciiString)
                {
                    this.readExtendedData(cadObject);
                    this._reader.ReadNext();
                    continue;
                }
                else if (this._reader.LastDxfCode == DxfCode.ControlString)
                {
                    if (!template.CheckDxfCode(this._reader.LastCode, this._reader.LastValue))
                    {
                        this.readDefinedGroups(template);
                    }
                    else
                    {
                        this._reader.ReadNext();
                    }

                    continue;
                }

                if (!map.DxfProperties.TryGetValue(this._reader.LastCode, out DxfProperty dxfProperty))
                {
                    if (!template.CheckDxfCode(this._reader.LastCode, this._reader.LastValue))
                    {
                        this._notification?.Invoke(null, new NotificationEventArgs($"Dxf code {this._reader.LastCode} not found in map for {typeof(T)} | value : {this._reader.LastValueAsString}"));
                    }

                    this._reader.ReadNext();
                    continue;
                }

                if (dxfProperty.ReferenceType == DxfReferenceType.Handle)
                {
                    if (!template.AddHandle(this._reader.LastCode, this._reader.LastValueAsHandle))
                    {
                        this._notification?.Invoke(null, new NotificationEventArgs($"Dxf referenced code {this._reader.LastCode} not implemented in the {template.GetType().Name} for {typeof(T)} | value : {this._reader.LastValueAsHandle}"));
                    }
                }
                else if (dxfProperty.ReferenceType == DxfReferenceType.Name)
                {
                    if (!template.AddName(this._reader.LastCode, this._reader.LastValueAsString))
                    {
                        this._notification?.Invoke(null, new NotificationEventArgs($"Dxf named referenced code {this._reader.LastCode} not implemented in the {template.GetType().Name} for {typeof(T)} | value : {this._reader.LastValueAsHandle}"));
                    }
                }
                else if (dxfProperty.ReferenceType == DxfReferenceType.Count)
                {
                    //Do nothing just marks the amount
                }
                else
                {
                    switch (this._reader.LastGroupCodeValue)
                    {
                    case GroupCodeValueType.String:
                    case GroupCodeValueType.Point3D:
                    case GroupCodeValueType.Double:
                    case GroupCodeValueType.Int16:
                    case GroupCodeValueType.Int32:
                    case GroupCodeValueType.Int64:
                    case GroupCodeValueType.Chunk:
                    case GroupCodeValueType.Bool:
                        dxfProperty.SetValue(cadObject, this._reader.LastValue);
                        break;

                    case GroupCodeValueType.Comment:
                        this._notification?.Invoke(null, new NotificationEventArgs($"Comment in the file :  {this._reader.LastValueAsString}"));
                        break;

                    case GroupCodeValueType.Handle:
                    case GroupCodeValueType.ObjectId:
                    case GroupCodeValueType.None:
                    default:
                        this._notification?.Invoke(null, new NotificationEventArgs($"Group Code not handled {this._reader.LastGroupCodeValue} for {typeof(T)}, code : {this._reader.LastCode} | value : {this._reader.LastValueAsString}"));
                        break;
                    }
                }

                this._reader.ReadNext();
            }
        }