Beispiel #1
0
        public static MpCadData_v1002 CreateMpCadData_v1002(CadData cd)
        {
            MpCadData_v1002 data = MpCadData_v1002.Create(cd.DB);

            data.ViewInfo.WorldScale = cd.WorldScale;

            data.ViewInfo.PaperSettings.Set(cd.PageSize);

            return(data);
        }
Beispiel #2
0
        private static void SaveToMsgPackJsonFile(string fname, PlotterViewModel vm)
        {
            PlotterController pc = vm.Controller;

            CadData cd = new CadData(
                pc.DB,
                pc.DC.WorldScale,
                pc.PageSize);


            MpCadFile.SaveAsJson(fname, cd);
        }
Beispiel #3
0
        private static void LoadFromMsgPackJsonFile(string fname, PlotterViewModel vm)
        {
            CadData?cd = MpCadFile.LoadJson(fname);

            if (cd == null)
            {
                return;
            }

            CadData rcd = cd.Value;

            vm.SetWorldScale(rcd.WorldScale);

            PlotterController pc = vm.Controller;

            pc.PageSize = rcd.PageSize;

            pc.SetDB(rcd.DB);
        }
Beispiel #4
0
        public static CadData CreateCadData_v1002(MpCadData_v1002 mpcd)
        {
            CadData cd = new CadData();

            MpViewInfo_v1002 viewInfo = mpcd.ViewInfo;

            double worldScale = 0;

            PaperPageSize pps = null;

            if (viewInfo != null)
            {
                worldScale = viewInfo.WorldScale;

                if (viewInfo.PaperSettings != null)
                {
                    pps = viewInfo.PaperSettings.GetPaperPageSize();
                }
            }


            if (worldScale == 0)
            {
                worldScale = 1.0;
            }

            cd.WorldScale = worldScale;


            if (pps == null)
            {
                pps = new PaperPageSize();
            }

            cd.PageSize = pps;

            cd.DB = mpcd.GetDB();

            return(cd);
        }
Beispiel #5
0
        public static CadData Import(string path)
        {
            DxfDocument doc;

            try
            {
                PreProcessDxfFile(path);

                var debug_version = DxfDocument.CheckDxfFileVersion(path, out var debug_isBinary);

                // Handle failure to load (with no exception)
                doc = null;
                var innerException = null as Exception;
                ActionExtensions.InvokeWithTimeout(() =>
                {
                    try
                    {
                        doc = DxfDocument.Load(path);
                    }
                    catch (Exception ex)
                    {
                        innerException = ex;
                    }
                }, 1000);

                if (doc == null)
                {
                    throw new LibraryException($@"doc did not load: {innerException?.Message}", innerException);
                }
            }
            catch (Exception ex)
            {
                throw new LibraryException($@"DxfNet could not load the Dxf File: {ex.Message}
{nameof(path)}={path}", ex);
            }

            var inserts       = doc.Inserts.ToList();
            var insertsBlocks = inserts.Select(x => x.Block).ToList();

            var docUnits = doc.DrawingVariables.InsUnits;

            var insertsData        = inserts.Select(x => GetInsertItems(x, docUnits)).ToList();
            var debug_insertsData  = InsertData.Debug_Stats_Header + "\r\n" + insertsData.Select(x => x.Debug_Stats).ConcatString("\r\n");
            var debug_insertsTexts = insertsData.Select(x => x.Debug_Texts).ConcatString("\r\n");
            var debug_textsData    = doc.Texts.Select(x => x.Value).ConcatString("\r\n");
            var debug_mtextsData   = doc.MTexts.Select(x => x.Value).ConcatString("\r\n");
            var debug_docData      = $"{doc.Texts.Count()} {doc.MTexts.Count()} {doc.AttributeDefinitions.Where(x => x.Flags == AttributeFlags.Constant).Count()} {doc.Lines.Count()} {doc.Circles.Count()}";

            var flatData = FlattenInsertsData(insertsData);

            //// TEST: No Inserts
            //var flatData = new FlatData()
            //{
            //    AttributeDefinitions = new List<InsertTransform<AttributeDefinition>>(),
            //    Attributes = new List<InsertTransform<netDxf.Entities.Attribute>>(),
            //    Circles = new List<InsertTransform<Circle>>(),
            //    Debug_Name = "",
            //    Lines = new List<InsertTransform<Line>>(),
            //    MTexts = new List<InsertTransform<MText>>(),
            //    Texts = new List<InsertTransform<Text>>(),
            //};

            flatData.Texts.AddRange(doc.Texts.Select(GetInsertOffset_Root));
            flatData.MTexts.AddRange(doc.MTexts.Select(GetInsertOffset_Root));
            flatData.AttributeDefinitions.AddRange(doc.AttributeDefinitions.Where(x => x.Flags == AttributeFlags.Constant).Select(GetInsertOffset_Root));
            flatData.Lines.AddRange(doc.Lines.Select(GetInsertOffset_Root));
            flatData.Circles.AddRange(doc.Circles.Select(GetInsertOffset_Root));

            var d = new CadData
            {
                Texts = flatData.Texts.Select(x => new CadText
                {
                    Debug_Raw  = x,
                    Bounds     = GetBounds(x),
                    FontHeight = GetFontHeight(x, (float)x.Value.Height),
                    Context    = GetContextPath(x),
                    Text       = x.Value.Value,
                }).Concat(
                    flatData.MTexts.Select(x => new CadText
                {
                    Debug_Raw  = x,
                    Bounds     = GetBounds(x),
                    FontHeight = GetFontHeight(x, (float)x.Value.Height),
                    Context    = GetContextPath(x),
                    Text       = x.Value.PlainText(),
                })
                    ).Concat(
                    flatData.AttributeDefinitions.Select(x => new CadText
                {
                    Debug_Raw  = x,
                    Bounds     = GetBounds(x),
                    FontHeight = GetFontHeight(x, (float)x.Value.Height),
                    Context    = GetContextPath(x),
                    Text       = x.Value.Value + "",
                })
                    ).Concat(
                    flatData.Attributes.Select(x => new CadText
                {
                    Debug_Raw  = x,
                    Bounds     = GetBounds(x.Value),
                    FontHeight = (float)x.Value.Height,
                    Context    = GetContextPath(x),
                    Text       = x.Value.Value + "",
                })
                    ).ToList()
            };

            d.Texts = SplitSpacedOutTexts(d.Texts);
            // Remove Duplicate Texts
            d.Texts = d.Texts.GroupBy(x => new { x.Text, xPos = Math.Round(x.Bounds.Min.X, 2), yPos = Math.Round(x.Bounds.Min.Y, 2) }).Select(g => g.First()).ToList();
            d.Texts.ForEach(x => x.Text = CleanText(x.Text));

            d.Lines = flatData.Lines.Select(x => new CadLine
            {
                Debug_Raw = x,
                Start     = x.Transform(x.Value.StartPoint.ToGeometryVector()),
                End       = x.Transform(x.Value.EndPoint.ToGeometryVector()),
                Context   = GetContextPath(x),
            }).ToList();

            d.Circles = flatData.Circles.Select(x => new CadCircle
            {
                Debug_Raw = x,
                Circle    = new Geometry.Circle(x.Transform(x.Value.Center.ToGeometryVector()).X,
                                                x.Transform(x.Value.Center.ToGeometryVector()).Y,
                                                Math.Abs(x.Transform(new System.Numerics.Vector2((float)x.Value.Radius, (float)x.Value.Radius)).X - x.Transform(new System.Numerics.Vector2(0, 0)).X)),
                Context = GetContextPath(x),
            }).ToList();

            //var debug_item = d.Texts.Where(x => x.Text == "21-21571-00").ToList();
            //var debug_lines = !debug_item.Any() ? null : d.Lines.Where(x => Common.Geometry.MathExt.Intersects(debug_item.First().Bounds, Geometry.Bounds.FromPoints(x.Start, x.End))).ToList();


            return(d);
        }