Exemplo n.º 1
0
        public void SetXYValueTest()
        {
            Viewport viewport = new Viewport();

            XY manual  = new XY(1, 1);
            XY dxfProp = new XY(2, 2);

            viewport.SnapBase = manual;

            DxfClassMap map = DxfClassMap.Create <Viewport>();

            map.DxfProperties[13].SetValue(viewport, dxfProp.X);
            map.DxfProperties[23].SetValue(viewport, dxfProp.Y);

            Assert.Equal(dxfProp, viewport.SnapBase);
        }
Exemplo n.º 2
0
        public void SetXYZValueTest()
        {
            Line line = new Line();

            XYZ manual  = new XYZ(1, 1, 1);
            XYZ dxfProp = new XYZ(2, 2, 2);

            line.StartPoint = manual;

            DxfClassMap map = DxfClassMap.Create <Line>();

            map.DxfProperties[10].SetValue(line, dxfProp.X);
            map.DxfProperties[20].SetValue(line, dxfProp.Y);
            map.DxfProperties[30].SetValue(line, dxfProp.Z);

            Assert.Equal(dxfProp, line.StartPoint);
        }
Exemplo n.º 3
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();
            }
        }