Пример #1
0
        private void LoadPart(string partname)
        {
            var     flstud = new DatLoader(RootPath, partname, HiQuality);
            var     poly   = flstud.LoadFromFile();
            DatPart dt     = new DatPart();

            dt.Name      = partname;
            dt.Polygones = poly;
            DatObj.Add(dt);
        }
Пример #2
0
        public new List <Polygone> LoadFromFile()
        {
            try
            {
                StreamReader file       = new StreamReader(Path + FileName);
                string       firstldr   = "";
                string       strline    = "";
                bool         IsOutOfLdr = false;
                while (!file.EndOfStream)
                {
                    if (!IsOutOfLdr)
                    {
                        strline = file.ReadLine();
                    }
                    else
                    {
                        IsOutOfLdr = false;
                    }
                    strline = Text.CleanSpace(strline);
                    var IsLdrEmbedded = IsBeginningLdrEmbedded(strline);
                    //check if it is an embedded file
                    if (IsLdrEmbedded != "")
                    {
                        if (firstldr == "")
                        {
                            firstldr = IsLdrEmbedded;
                        }
                        Console.WriteLine($"Reading file {IsLdrEmbedded}");
                        //get the lines related to this one
                        strline = Text.CleanSpace(file.ReadLine());
                        StreamWriter ldrwrite = new StreamWriter(RootPath + IsLdrEmbedded, false);
                        while ((IsBeginningLdrEmbedded(strline) == "") && (!file.EndOfStream))
                        {
                            strline = Text.CleanSpace(file.ReadLine());
                            ldrwrite.WriteLine(strline);
                            IsOutOfLdr = true;
                        }
                        ldrwrite.Close();
                        ldrwrite.Dispose();
                    }
                }
                file.Close();
                file.Dispose();

                DatLoader mydat = new DatLoader(RootPath, firstldr, HiQuality);
                Polygones = mydat.LoadFromFile();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exceptoin: {ex.Message}");
                //do nothing
            }
            return(Polygones);
        }
Пример #3
0
        public Loader(string rootpath, string path, string filename, bool hiqual)
        {
            HiQuality = hiqual;
            RootPath  = rootpath;
            Path      = path;
            FileName  = filename;

            if (DatObj == null)
            {
                DatObj = new List <DatPart>();
                //load the stud as used a lot
                LoadPart(@"stud.dat");
                // do same with 1-4cyli.dat
                LoadPart(@"1-4cyli.dat");
            }

            try
            {
                Files.AddRange(Directory.GetFiles(RootPath, "*.*", SearchOption.AllDirectories));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (FileName.ToLower().Contains(".mpd"))
            {
                var fileMpd = new MpdLoader(RootPath, Path, FileName, hiqual);
                Polygones = fileMpd.LoadFromFile();
            }
            else if (FileName.ToLower().Contains(".ldr"))
            {
                var fileLdr = new LdrLoader(RootPath, Path, FileName, hiqual);
                Polygones = fileLdr.LoadFromFile();
            }
            else if (FileName.ToLower().Contains(".dat"))
            {
                var filetoload = new DatLoader(RootPath, FileName, hiqual);
                Polygones = filetoload.LoadFromFile();
            }
        }
Пример #4
0
        public List <Polygone> DecryptLine(string strline)
        {
            var elems = strline.Split(' ');
            //What is the action?
            int action = GetFirstDigit(strline);

            switch (action)
            {
            case 1:
                //there must be a file name at the end as it just can't be 1 point alone
                if (elems.Length != 15)
                {
                    break;
                }
                var poly = new List <Polygone>();
                //check if element is existing
                var ret = Loader.DatObj.Where(x => x.Name.ToLower() == elems.Last().ToLower());
                if (!ret.Any())
                {
                    Console.WriteLine($"Cloning {elems.Last()}");
                    DatLoader ld = new DatLoader(RootPath, elems.Last(), HiQuality);
                    poly = ld.LoadFromFile();
                }
                else
                {
                    //Clone the existing part
                    poly = ret.First().Polygones.DeepClone <List <Polygone> >();
                }


                Point t = new Point(float.Parse(elems[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                    float.Parse(elems[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                    float.Parse(elems[4], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                Point m1 = new Point(float.Parse(elems[5], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                     float.Parse(elems[6], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                     float.Parse(elems[7], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                Point m2 = new Point(float.Parse(elems[8], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                     float.Parse(elems[9], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                     float.Parse(elems[10], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                Point m3 = new Point(float.Parse(elems[11], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                     float.Parse(elems[12], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                     float.Parse(elems[13], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                var col = int.Parse(elems[1]);
                for (int i = 0; i < poly.Count; i++)
                {
                    poly[i].Matrix(m1, m2, m3, t);
                    if (poly[i].Color == 16)
                    {
                        poly[i].Color = col;
                    }
                }
                return(poly);

            //break;
            case 2:
                //We don't need the specific lines
                break;

            case 3:
                //it's the standard triangle
                if (elems.Length != 11)
                {
                    break;
                }
                Point ptc1 = new Point(float.Parse(elems[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                       float.Parse(elems[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                       float.Parse(elems[4], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                Point ptc2 = new Point(float.Parse(elems[5], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                       float.Parse(elems[6], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                       float.Parse(elems[7], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                Point ptc3 = new Point(float.Parse(elems[8], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                       float.Parse(elems[9], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture),
                                       float.Parse(elems[10], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture));
                Polygone plc = new Polygone(ptc1, ptc2, ptc3);
                plc.Color = int.Parse(elems[1]);
                return(new List <Polygone> {
                    plc
                });

            //break;
            case 4:
                //it's a rectangle, will need to transform into 2 triuangles
                if (elems.Length != 14)
                {
                    break;
                }
                float    a1 = float.Parse(elems[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    a2 = float.Parse(elems[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    a3 = float.Parse(elems[4], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    b1 = float.Parse(elems[5], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    b2 = float.Parse(elems[6], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    b3 = float.Parse(elems[7], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    c1 = float.Parse(elems[8], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    c2 = float.Parse(elems[9], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    c3 = float.Parse(elems[10], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    d1 = float.Parse(elems[11], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    d2 = float.Parse(elems[12], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                float    d3 = float.Parse(elems[13], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                Polygone qq1;
                Polygone qq2;
                qq1 = new Polygone(new Point(a1, a2, a3),
                                   new Point(b1, b2, b3), new Point(c1, c2, c3));
                qq2 = new Polygone(new Point(c1, c2, c3),
                                   new Point(d1, d2, d3), new Point(a1, a2, a3));

                qq1.Color = int.Parse(elems[1]);
                qq2.Color = int.Parse(elems[1]);
                return(new List <Polygone> {
                    qq1, qq2
                });

            //break;
            case 5:
                //As for case 2, there is no need of converting hidden lines
                break;

            case 0:
                //check if it is a part as we'll save it at the end
                if (elems.Length > 3)
                {
                    if (elems[1] == @"!LDRAW_ORG")
                    {
                        if (elems[2].ToLower() == @"part")
                        {
                            IsPart = true;
                        }
                    }
                }
                break;

            default:
                break;
            }
            return(new List <Polygone>());
        }