Пример #1
0
        // type 4, 4 point poly processor
        private void type4(String[] data, StreamWriter writefile, bool inverted)
        {
            // Create and initalize values.
            int color;
//            Point3D p1 = null, p2 = null, p3 = null, p4 = null;
            Vector3     p1, p2, p3, p4;
            LdrawMatrix top = (LdrawMatrix)matrices.Peek();

            p1 = new Vector3();
            p2 = new Vector3();
            p3 = new Vector3();
            p4 = new Vector3();

            // Get color to proper format
            color = Int32.Parse(data[1]);
            // Then doubles for 4 3d points... (columins for transform)
            p1.X = Double.Parse(data[2]);
            p1.Y = Double.Parse(data[3]);
            p1.Z = Double.Parse(data[4]);

            p2.X = Double.Parse(data[5]);
            p2.Y = Double.Parse(data[6]);
            p2.Z = Double.Parse(data[7]);

            p3.X = Double.Parse(data[8]);
            p3.Y = Double.Parse(data[9]);
            p3.Z = Double.Parse(data[10]);

            p4.X = Double.Parse(data[11]);
            p4.Y = Double.Parse(data[12]);
            p4.Z = Double.Parse(data[13]);

            // Done! Now transform it into current coorditate system
            //top.transformPoint(p1);
            //top.transformPoint(p2);
            //top.transformPoint(p3);
            //top.transformPoint(p4);

            // Is color "previous color"? If so, use it.
            if (color == 16 || color == 24)
            {
                color = top.color;
            }
            // Write it out.
            if (!inverted)
            {
                writetype4obj(color, p1, p2, p3, p4, writefile);
            }
            else
            {
                writetype4obj(color, p1, p4, p3, p2, writefile);
            }
        }
Пример #2
0
        private void addStack(int color, double x, double y, double z, double a, double b,
                              double c, double d, double e, double f, double g, double h,
                              double i)
        {
            // Create a new stack with those paramaters.
            LdrawMatrix newone = new LdrawMatrix(color, x, y, z, a, b, c, d, e, f, g, h, i);

            if (matrices.Count != 0)
            {
                double aa, bb, cc, dd, ee, ff, gg, hh, ii;
//                Point3D p = new Point3D(x, y, z);
                Vector3 p = new Vector3(x, y, z);

                LdrawMatrix top = (LdrawMatrix)matrices.Peek();

                // Trandform matrix to last coordate system
                // Creating new matrix that does both transformations in one step.
                aa = (top.a * newone.a) + (top.b * newone.d) + (top.c * newone.g);
                dd = (top.d * newone.a) + (top.e * newone.d) + (top.f * newone.g);
                gg = (top.g * newone.a) + (top.h * newone.d) + (top.i * newone.g);

                bb = (top.a * newone.b) + (top.b * newone.e) + (top.c * newone.h);
                ee = (top.d * newone.b) + (top.e * newone.e) + (top.f * newone.h);
                hh = (top.g * newone.b) + (top.h * newone.e) + (top.i * newone.h);

                cc = (top.a * newone.c) + (top.b * newone.f) + (top.c * newone.i);
                ff = (top.d * newone.c) + (top.e * newone.f) + (top.f * newone.i);
                ii = (top.g * newone.c) + (top.h * newone.f) + (top.i * newone.i);

                //Now transform point into stack current coord...
                //top.transformPoint(p);

                // All finished. Now fill in results into matrix then push it in.
                newone.x = p.X;
                newone.y = p.Y;
                newone.z = p.Z;
                newone.a = aa;
                newone.b = bb;
                newone.c = cc;
                newone.d = dd;
                newone.e = ee;
                newone.f = ff;
                newone.g = gg;
                newone.h = hh;
                newone.i = ii;
                matrices.Push(newone);
            }
        }
Пример #3
0
        // Actual processing file section
        // reads file and open sub-part files or performs transitions as nesscary.
        // parameter root is used to tell processFile that its an orginial file and not a subpart.
        private int processFile(String file, StreamWriter WF, bool inverted, bool root = false)
        {
            StreamReader RF   = null;
            LdrawMatrix  work = null;
            String       line = null;

            String[] s               = null;
            String[] space           = { " " }; // Used for split line
            bool     thisOneInverted = false;   // Remember where it was flagged inverted.

            work = (LdrawMatrix)matrices.Peek();

            // If processing a MPD file, priority is always subparts in MPD first.
            if (mpdenable)
            {
                String a = Path.GetFileName(file);
                //Debug.WriteLine("checking mpd subpart. part being found out is " + a);
                RF = mpd.getMPDSubpart(a);
                if (RF != null)
                {
                    //Debug.WriteLine("Got a subpart... with " + a);

                    //a = RF.ReadLine();
                    //Debug.WriteLine("#### debug print this main file");
                    // debug
                    //while (a != null)
                    //{
                    //  Debug.WriteLine(a);
                    //   a = RF.ReadLine();
                    //}
                    //RF.BaseStream.Seek(0L,0);
                }
            }

            // If RF is still null (or theres no MPD to use) load file
            if (RF == null)
            {
                //Check if file exists. The handle according.
                bool err = File.Exists(file);
                if (!err && !skiperror)
                {
                    return(1); // ignore errors not enabled, return with error
                }
                else if (!err && skiperror)
                {
                    return(0); // Return "its fine" even if file was not processed. (ignorerrors enabled)
                }
                RF = new StreamReader(file);
                // Was open a failure? if so return error.
                if (RF == null)
                {
                    return(1); // Hard error, cannot be skipped
                }
            }

            // Was stop requested?
            if (stopConvert == ProcessStatus.FORCESTOP)
            {
                stopConvert = ProcessStatus.NOTSTARTED;
                RF.Close();
                return(100);
            }

            // Check only when mpd isnt enabled.
            if (root && !mpdenable)
            {
                // Get root folder if it was root file...
                // Used for findfile default if not found in source directories.
                fileDir = Path.GetDirectoryName(file);
                //Debug.WriteLine(fileDir);
                //Debug.WriteLine(Path.GetExtension(file));
                // Check if its MPD type
                if (Path.GetExtension(file).ToLower().CompareTo(".mpd") == 0)
                {
                    RF.Close();
                    mpd       = new MPDFileList(file);
                    RF        = mpd.getMPDSubpart(null);
                    mpdenable = true; // enable mpd mode
                    // String a = RF.ReadLine();
                    //Debug.WriteLine("#### debug print this main file");
                    // debug
                    //while (a != null)
                    //{
                    //  Debug.WriteLine(a);
                    //    a = RF.ReadLine();
                    //}
                    //RF.BaseStream.Seek(0L,0);
                }
            }

            // Read first line
            line = RF.ReadLine();
            //if (root)
            //    Debug.WriteLine(line + " // read");
            while (line != null)
            {
                if (root)
                {
                    overall = (int)(((double)RF.BaseStream.Position / (double)RF.BaseStream.Length) * 100.0);
                    OnPercentUpdate(overall);
                }

                // Split line into "words"
                s = line.Split(space, StringSplitOptions.RemoveEmptyEntries);
                if (s.Length >= 1)
                {
                    switch (s[0])
                    {
                    case "0":    // Comment, invertnext or step.
                        if (s.Length > 1 && s[1].CompareTo("STEP") == 0)
                        {
                            // step found!
                            writeobjgroup(false, true, WF);
                            //debug.WriteLine("step found.");
                        }
                        // Is it invert next? it should be in format 0 BFC INVERTNEXT.
                        else if (s.Length > 2 && s[1].CompareTo("BFC") == 0 && s[2].CompareTo("INVERTNEXT") == 0)
                        {
                            // 0 BFC INVERTNEXT found!
                            inverted        = !inverted;
                            thisOneInverted = true;
                            //debug.WriteLine("invert next found. Status now " + inverted);
                        }
                        break;

                    case "1":    // new subpart file...
                        //Debug.Write("subpart found... legit: ");
                        if (s.Length < 14)
                        {
                            //Debug.WriteLine("no!");
                            // error!
                            RF.Close();
                            return(1);
                        }
                        else
                        {
                            //Debug.WriteLine("yes");
                            // If this is in root file, start a new line group
                            if (root)
                            {
                                writeobjgroup(true, false, WF);
                            }

                            //debug.WriteLine("////////////////////////////////////////////////////////////////////////////////");
                            //debug.WriteLine("New subpart: " + s[14] + " depth: " + ++depth + " matrices size: " + matrices.ToArray().Length);
                            int x = type1(s, WF, inverted);
                            if (root)
                            {
                                Debug.WriteLine("type1 exit... X:" + x + " line:" + line);
                            }

                            //debug.WriteLine("Leaving subpart. Depth: " + --depth + " matrices size: " + matrices.ToArray().Length);
                            //debug.WriteLine("////////////////////////////////////////////////////////////////////////////////");
                            if (x != 0)
                            {
                                return(x);
                            }
                        }
                        if (thisOneInverted)    // Was here where invert was enabled? if so it should be flipped.
                        {
                            inverted        = !inverted;
                            thisOneInverted = false;
                            //debug.WriteLine(" was inverted, undoing now. status: " + inverted);
                        }
                        break;

                    case "3":    // Triangle
                        //debug.Write("type 3... legal: ");
                        if (s.Length < 11)
                        {
                            //debug.WriteLine("no!");
                            // error!
                            RF.Close();
                            return(1);
                        }
                        else
                        {
                            //debug.WriteLine("yes");
                            type3(s, WF, inverted);
                        }
                        if (thisOneInverted)    // Was here where invert was enabled? if so it should be flipped.
                        {
                            inverted        = !inverted;
                            thisOneInverted = false;
                            //debug.WriteLine(" was inverted, undoing now. status: " + inverted);
                        }
                        break;

                    case "4":    // Quad
                        //debug.Write("type 4... legal: ");
                        if (s.Length < 14)
                        {
                            // debug.WriteLine("no!");
                            // error!
                            RF.Close();
                            return(1);
                        }
                        else
                        {
                            // debug.WriteLine("yes");
                            type4(s, WF, inverted);
                        }
                        if (thisOneInverted)    // Was here where invert was enabled? if so it should be flipped.
                        {
                            inverted        = !inverted;
                            thisOneInverted = false;
                            //debug.WriteLine(" was inverted, undoing now. status: " + inverted);
                        }
                        break;
                    }
                    //if(root)
                    //  Debug.WriteLine("Exit select case");
                }
                // Read next line
                //if(root)
                //  Debug.WriteLine(line + " after processed.");
                line = RF.ReadLine();
                //if (root)
                //  Debug.WriteLine(line + " // read");
            }


            // Clean up
            RF.Close();

            return(0);
        }
Пример #4
0
        // type 1, subpart file processor.
        private int type1(String[] data, StreamWriter writefile, bool inverted)
        {
            int         color;
            double      x, y, z, a, b, c, d, e, f, g, h, i;
            LdrawMatrix top = (LdrawMatrix)matrices.Peek();
            String      fullpathfile;
            int         res;

            // Debug
            // debug.WriteLine("peeking matrices - data: " + top.color + " " + top.x + " " +
            //    top.y + " " + top.z + " " + top.a + " " + top.b + " " + top.c + " " + top.d + " " +
            //  top.e + " " + top.f + " " + top.g + " " + top.h + " " + top.i);

            // First, was this file excluded?
            // if so, just return to caller.
            if (isExcluded(data[14]))
            {
                return(0);
            }

            // Process data into proper formats
            color = Int32.Parse(data[1]);

            x = Double.Parse(data[2]);
            y = Double.Parse(data[3]);
            z = Double.Parse(data[4]);

            a = Double.Parse(data[5]);
            b = Double.Parse(data[6]);
            c = Double.Parse(data[7]);

            d = Double.Parse(data[8]);
            e = Double.Parse(data[9]);
            f = Double.Parse(data[10]);

            g = Double.Parse(data[11]);
            h = Double.Parse(data[12]);
            i = Double.Parse(data[13]);

            // Is color "previous color" or "invert color"? If so, use last color.
            if (color == 16 || color == 24)
            {
                color = top.color;
            }

            // Now add the new transformation matrix to stack.
            addStack(color, x, y, z, a, b, c, d, e, f, g, h, i);

            // Okay the setup is ready...
            // Try to find full path for file.
            fullpathfile = findfile(data[14]);

            // Update per subMax subfiles. prevents any GUI from lagging
            updatecounter++;
            if (updatecounter == subMax)
            {
                OnPercentUpdate(overall);
                updatecounter = 0;
            }

            // Now call processfile...
            res = processFile(fullpathfile, writefile, inverted);
            // Done with the matrix, remove it.
            matrices.Pop();
            return(res);
        }