コード例 #1
0
ファイル: clSliFileReader.cs プロジェクト: yovun/EOS-Formats
        //------------------------------------------//
        public clSliceData getSliceData(int ObjectIndex, int LayerIndex, float jobLayerThickness)
        {
            clSliceData sd = new clSliceData();
            int         n  = 0;

            if (ObjectIndex != 0)
            {
                return(sd);
            }


            float scaleFactor = m_FileHead.scaleFactor;

            //m_error.addInfo(System.IO.Path.GetFileName( m_filename)  +" : factor: " + scaleFactor + "; ");


            int convertedLayerindex = LayerIndex - (int)(m_IndexTable[0].layerPos / jobLayerThickness);     // Min z



            if ((convertedLayerindex >= 0) && (convertedLayerindex < m_IndexTable_count))
            {
                setOffset(m_IndexTable[convertedLayerindex].FileOffset);

                int OType = 0;
                while (OType != 2)
                {
                    //- Befehl/Operator Byte
                    OType = readIntBE(1);

                    switch (OType)
                    {
                    case 1:
                        //- ersten 2 Byte sind ca. die Höhe??!!!
                        readByte(11);     //- Header überspringen
                        //- Header... lesen???!!!
                        break;

                    case 2:
                        //- Ende
                        break;

                    case 3:
                        //Command : start polyline
                        //Syntax : $$POLYLINE/id,dir,n,p1x,p1y,...pnx,pny
                        //Parameters:
                        //
                        //	id		: INTEGER
                        //	dir,n		: INTEGER
                        //	p1x..pny	: REAL
                        //
                        //
                        //id : identifier to allow more than one model information in one file.
                        //id refers to the parameter id of command $$LABEL (HEADER-section).
                        //dir : Orientation of the line when viewing in the negative z-direction
                        //0 : clockwise (internal)
                        //1 : counter-clockwise (external)
                        //2 : open line (no solid)
                        //n : number of points
                        //p1x..pny : coordinates of the points 1..n

                        if (readIntBE(1) != 0)     //- vielleicht "dir"?
                        {
                            m_error.addWarning("unbekanntes Byte [dir?] @ " + m_offset);
                        }

                        n = readIntBE(2);


                        if (n > 0)
                        {
                            //int n2 = n*2; //- x+y
                            float[,] points = new float[n, 2];

                            //- Punkte lesen
                            for (int i = 0; i < n; i++)
                            {
                                //- Punkt lesen und mit internem Faktor skalieren
                                points[i, 0] = scaleFactor * readIntBE(2);
                                points[i, 1] = scaleFactor * readIntBE(2);
                            }

                            sd.addPolygon(points, n);
                        }

                        break;

                    case 4:
                        //- support
                        //m_error.addWarning("Support is not supported!");

                        //Command : start hatches
                        //Syntax : $$HATCHES/id,n,p1sx,p1sy,p1ex,p1ey,...pnex,pney
                        //Parameters:
                        //
                        //	id		: INTEGER
                        //	n		: INTEGER
                        //	p1sx..pney	: REAL
                        //
                        //id : identifier to allow more than one model information in one file.
                        //id refers to the parameter id of command $$LABEL (HEADER-section).
                        //n : number of hatches (n*4 =number of coordinates)
                        //p1sx..pney : coordinates of the hatches 1..n
                        //4 parameters for every hatch (startx,starty,endx,endy)


                        //- Keine Ahnung
                        if (readIntBE(1) != 0)
                        {
                            m_error.addWarning("unbekanntes Byte @ " + m_offset);
                        }

                        n = readIntBE(2);

                        if (n > 0)
                        {
                            //- hier gibt es 2 Punkt pro Linie
                            int m = n * 2;

                            float[,] points = new float[m, 2];

                            //- Punkte lesen: es werden 2*n Punkte eingelesen da jede Linie einen Start und ein Ende-Punkt hat
                            for (int i = 0; i < m; i++)
                            {
                                points[i, 0] = scaleFactor * readIntBE(2);    //- start/ende-x
                                points[i, 1] = scaleFactor * readIntBE(2);    //- start/ende-y
                            }

                            sd.addHatch(points, m);
                        }

                        break;

                    default:
                        m_error.addWarning("Data-Stream-Error??? Unknow Data Type: " + OType + " @ " + m_offset);
                        break;
                    }
                }
            }

            return(sd);
        }
コード例 #2
0
ファイル: clCliFileReader.cs プロジェクト: yovun/EOS-Formats
        //------------------------------------------//
        public clSliceData getSliceData(int ObjectIndex, int LayerIndex, float jobLayerThickness)
        {
            clSliceData retSlice = new clSliceData();

            if (ObjectIndex != 0)
            {
                return(retSlice);
            }

            if ((LayerIndex < 0) || (LayerIndex >= m_IndexTable_count))
            {
                return(retSlice);
            }

            setOffset(m_IndexTable[LayerIndex].FileOffset);

            float scale = m_FileHead.unit; //- Faktor in [mm]


            for (int i = 0; i < m_IndexTable[LayerIndex].polyCount; i++)
            {
                int cmd        = readIntBE(2);
                int pointCount = 0;
                float [,] pointBuffer;

                switch (cmd)
                {
                case 129:                      //- Start PolyLine short
                    readIntBE(2);              //- id
                    readIntBE(2);              //- dir

                    pointCount = readIntBE(2); //- number of points

                    pointBuffer = new float[pointCount, 2];

                    for (int p = 0; p < pointCount; p++)
                    {
                        pointBuffer[p, 0] = scale * readIntBE(2);
                        pointBuffer[p, 1] = scale * readIntBE(2);
                    }

                    retSlice.addPolygon(pointBuffer, pointCount);

                    break;


                case 130:                      //- Start PolyLine long

                    readIntBE(4);              //- id
                    readIntBE(4);              //- dir
                    pointCount = readIntBE(4); //- number of points

                    pointBuffer = new float[pointCount, 2];

                    for (int p = 0; p < pointCount; p++)
                    {
                        pointBuffer[p, 0] = readRealBE(4) * scale;
                        pointBuffer[p, 1] = readRealBE(4) * scale;
                    }

                    retSlice.addPolygon(pointBuffer, pointCount);
                    break;


                default:
                    m_error.addError("indexFileBinary() : data out of sync. Unknown command: " + cmd + " at pos: " + m_offset);
                    break;
                }
            }

            return(retSlice);
        }