Esempio n. 1
0
        public object GetFileSettingsFromDrawing(Drawing drawing)
        {
            var settings = new DxfFileSettings();
            var dxfFile  = drawing.Tag as DxfFile;

            if (dxfFile != null)
            {
                settings.FileVersion = dxfFile.Header.Version.ToFileVersion();
            }

            return(settings);
        }
Esempio n. 2
0
        public INotifyPropertyChanged GetFileSettingsFromDrawing(Drawing drawing)
        {
            var settings = new DxfFileSettings();
            var dxfFile  = drawing.Tag as DxfFile;

            if (dxfFile != null)
            {
                settings.FileVersion = dxfFile.Header.Version.ToFileVersion();
            }

            return(settings);
        }
Esempio n. 3
0
        public static DxfFile ToDxfFile(Drawing drawing, ViewPort viewPort, DxfFileSettings settings)
        {
            var file = new DxfFile();

            file.Layers.Clear();
            if (drawing.Tag is DxfFile oldFile)
            {
                // preserve settings from the original file
                file.Header.CreationDate          = oldFile.Header.CreationDate;
                file.Header.CreationDateUniversal = oldFile.Header.CreationDateUniversal;
                file.Header.Version = oldFile.Header.Version;
            }

            if (settings is object)
            {
                file.Header.Version = settings.FileVersion.ToDxfFileVersion();
            }

            // save layers and entities
            file.Header.CurrentLayer       = drawing.CurrentLayer.Name;
            file.Header.UnitFormat         = drawing.Settings.UnitFormat.ToDxfUnitFormat();
            file.Header.UnitPrecision      = (short)drawing.Settings.UnitPrecision;
            file.Header.AngleUnitPrecision = (short)drawing.Settings.AnglePrecision;
            foreach (var layer in drawing.GetLayers().OrderBy(x => x.Name))
            {
                if (!file.Layers.Any(l => l.Name == layer.Name))
                {
                    file.Layers.Add(new DxfLayer(layer.Name, layer.Color.ToDxfColor())
                    {
                        IsLayerOn = layer.IsVisible
                    });
                }

                foreach (var item in layer.GetEntities().OrderBy(e => e.Id))
                {
                    if (item.Kind == EntityKind.Aggregate)
                    {
                        // dxf files treat aggregate entities as separate items
                        var agg   = (AggregateEntity)item;
                        var block = new DxfBlock();
                        block.Layer = layer.Name;
                        foreach (var child in agg.Children.Select(c => c.ToDxfEntity(layer)))
                        {
                            block.Entities.Add(child);
                        }

                        file.Blocks.Add(block);
                    }
                    else
                    {
                        var entity = item.ToDxfEntity(layer);
                        if (entity != null)
                        {
                            file.Entities.Add(entity);
                        }
                    }
                }
            }

            // save viewport
            // TODO: use `DxfFile.ActiveViewPort` when available
            file.ViewPorts.Clear();
            file.ViewPorts.Add(new DxfViewPort(DxfViewPort.ActiveViewPortName)
            {
                LowerLeft     = viewPort.BottomLeft.ToDxfPoint(),
                ViewDirection = viewPort.Sight.ToDxfVector(),
                ViewHeight    = viewPort.ViewHeight
            });

            return(file);
        }