Esempio n. 1
0
 public Tuple<netDxf.Tables.Layer, List<netDxf.Entities.EntityObject>> ToDxfEntitiesAndLayer()
 {
     List<netDxf.Entities.EntityObject> entities = this.ToDXFEntities();
     netDxf.Tables.Layer dxfLayer = new netDxf.Tables.Layer(this.Name) { Color = new netDxf.AciColor(this.Color) };
     if (this._color.A == 255
         && this._color.R == 255
         && this._color.G == 255
         && this._color.B == 255)
     {
         dxfLayer.Color = new netDxf.AciColor(7);
     }
     foreach (var item in entities)
     {
         item.Layer = dxfLayer;
     }
     return new Tuple<netDxf.Tables.Layer, List<netDxf.Entities.EntityObject>>(dxfLayer, entities);
 }
Esempio n. 2
0
        public Tuple <netDxf.Tables.Layer, List <netDxf.Entities.EntityObject> > ToDxfEntitiesAndLayer()
        {
            List <netDxf.Entities.EntityObject> entities = this.ToDXFEntities();

            netDxf.Tables.Layer dxfLayer = new netDxf.Tables.Layer(this.Name)
            {
                Color = new netDxf.AciColor(this.Color)
            };
            if (this._color.A == 255 &&
                this._color.R == 255 &&
                this._color.G == 255 &&
                this._color.B == 255)
            {
                dxfLayer.Color = new netDxf.AciColor(7);
            }
            foreach (var item in entities)
            {
                item.Layer = dxfLayer;
            }
            return(new Tuple <netDxf.Tables.Layer, List <netDxf.Entities.EntityObject> >(dxfLayer, entities));
        }
Esempio n. 3
0
        public void Contour(DxfDocument dxf, double[,] d, double[] x, double[] y, double[] z)
        {
            double x1 = 0.0;
            double x2 = 0.0;
            double y1 = 0.0;
            double y2 = 0.0;

            var h  = new double[5];
            var sh = new int[5];
            var xh = new double[5];
            var yh = new double[5];

            int ilb = d.GetLowerBound(0);
            int iub = d.GetUpperBound(0);
            int jlb = d.GetLowerBound(1);
            int jub = d.GetUpperBound(1);
            int nc  = z.Length;

            // The indexing of im and jm should be noted as it has to start from zero
            // unlike the fortran counter part
            int[] im = { 0, 1, 1, 0 };
            int[] jm = { 0, 0, 1, 1 };

            // Note that castab is arranged differently from the FORTRAN code because
            // Fortran and C/C++ arrays are transposed of each other, in this case
            // it is more tricky as castab is in 3 dimension
            int[,,] castab =
            {
                { { 0, 0, 8 }, { 0, 2, 5 }, { 7, 6, 9 } }, { { 0, 3, 4 }, { 1, 3, 1 }, { 4, 3, 0 } },
                { { 9, 6, 7 }, { 5, 2, 0 }, { 8, 0, 0 } }
            };

            Func <int, int, double> xsect = (p1, p2) => (h[p2] * xh[p1] - h[p1] * xh[p2]) / (h[p2] - h[p1]);
            Func <int, int, double> ysect = (p1, p2) => (h[p2] * yh[p1] - h[p1] * yh[p2]) / (h[p2] - h[p1]);

            for (int j = jub - 1; j >= jlb; j--)
            {
                int i;
                for (i = ilb; i <= iub - 1; i++)
                {
                    double temp1 = Math.Min(d[i, j], d[i, j + 1]);
                    double temp2 = Math.Min(d[i + 1, j], d[i + 1, j + 1]);
                    double dmin  = Math.Min(temp1, temp2);
                    temp1 = Math.Max(d[i, j], d[i, j + 1]);
                    temp2 = Math.Max(d[i + 1, j], d[i + 1, j + 1]);
                    double dmax = Math.Max(temp1, temp2);

                    if (dmax >= z[0] && dmin <= z[nc - 1])
                    {
                        short k;
                        for (k = 0; k < nc; k++)
                        {
                            if (z[k] >= dmin && z[k] <= dmax)
                            {
                                int m;
                                for (m = 4; m >= 0; m--)
                                {
                                    if (m > 0)
                                    {
                                        // The indexing of im and jm should be noted as it has to
                                        // start from zero
                                        h[m]  = d[i + im[m - 1], j + jm[m - 1]] - z[k];
                                        xh[m] = x[i + im[m - 1]];
                                        yh[m] = y[j + jm[m - 1]];
                                    }
                                    else
                                    {
                                        h[0]  = 0.25 * (h[1] + h[2] + h[3] + h[4]);
                                        xh[0] = 0.5 * (x[i] + x[i + 1]);
                                        yh[0] = 0.5 * (y[j] + y[j + 1]);
                                    }

                                    if (h[m] > 0.0)
                                    {
                                        sh[m] = 1;
                                    }
                                    else if (h[m] < 0.0)
                                    {
                                        sh[m] = -1;
                                    }
                                    else
                                    {
                                        sh[m] = 0;
                                    }
                                }

                                // Note: at this stage the relative heights of the corners and the
                                // centre are in the h array, and the corresponding coordinates are
                                // in the xh and yh arrays. The centre of the box is indexed by 0
                                // and the 4 corners by 1 to 4 as shown below.
                                // Each triangle is then indexed by the parameter m, and the 3
                                // vertices of each triangle are indexed by parameters m1,m2,and
                                // m3.
                                // It is assumed that the centre of the box is always vertex 2
                                // though this isimportant only when all 3 vertices lie exactly on
                                // the same contour level, in which case only the side of the box
                                // is drawn.
                                // vertex 4 +-------------------+ vertex 3
                                // | \               / |
                                // |   \    m-3    /   |
                                // |     \       /     |
                                // |       \   /       |
                                // |  m=2    X   m=2   |       the centre is vertex 0
                                // |       /   \       |
                                // |     /       \     |
                                // |   /    m=1    \   |
                                // | /               \ |
                                // vertex 1 +-------------------+ vertex 2
                                // Scan each triangle in the box
                                for (m = 1; m <= 4; m++)
                                {
                                    int m1 = m;
                                    int m2 = 0;
                                    int m3;
                                    if (m != 4)
                                    {
                                        m3 = m + 1;
                                    }
                                    else
                                    {
                                        m3 = 1;
                                    }

                                    int caseValue = castab[sh[m1] + 1, sh[m2] + 1, sh[m3] + 1];
                                    if (caseValue != 0)
                                    {
                                        switch (caseValue)
                                        {
                                        case 1:     // Line between vertices 1 and 2
                                            x1 = xh[m1];
                                            y1 = yh[m1];
                                            x2 = xh[m2];
                                            y2 = yh[m2];
                                            break;

                                        case 2:     // Line between vertices 2 and 3
                                            x1 = xh[m2];
                                            y1 = yh[m2];
                                            x2 = xh[m3];
                                            y2 = yh[m3];
                                            break;

                                        case 3:     // Line between vertices 3 and 1
                                            x1 = xh[m3];
                                            y1 = yh[m3];
                                            x2 = xh[m1];
                                            y2 = yh[m1];
                                            break;

                                        case 4:     // Line between vertex 1 and side 2-3
                                            x1 = xh[m1];
                                            y1 = yh[m1];
                                            x2 = xsect(m2, m3);
                                            y2 = ysect(m2, m3);
                                            break;

                                        case 5:     // Line between vertex 2 and side 3-1
                                            x1 = xh[m2];
                                            y1 = yh[m2];
                                            x2 = xsect(m3, m1);
                                            y2 = ysect(m3, m1);
                                            break;

                                        case 6:     // Line between vertex 3 and side 1-2
                                            x1 = xh[m3];
                                            y1 = yh[m3];
                                            x2 = xsect(m1, m2);
                                            y2 = ysect(m1, m2);
                                            break;

                                        case 7:     // Line between sides 1-2 and 2-3
                                            x1 = xsect(m1, m2);
                                            y1 = ysect(m1, m2);
                                            x2 = xsect(m2, m3);
                                            y2 = ysect(m2, m3);
                                            break;

                                        case 8:     // Line between sides 2-3 and 3-1
                                            x1 = xsect(m2, m3);
                                            y1 = ysect(m2, m3);
                                            x2 = xsect(m3, m1);
                                            y2 = ysect(m3, m1);
                                            break;

                                        case 9:     // Line between sides 3-1 and 1-2
                                            x1 = xsect(m3, m1);
                                            y1 = ysect(m3, m1);
                                            x2 = xsect(m1, m2);
                                            y2 = ysect(m1, m2);
                                            break;

                                        default:
                                            break;
                                        }
                                        Vector3 pk_1 = new Vector3(x1, y1, 0);
                                        Vector3 pk_2 = new Vector3(x2, y2, 0);
                                        netDxf.Entities.Line ln_1 = new netDxf.Entities.Line(pk_1, pk_2);
                                        string nazwa_warsty       = z[k].ToString();
                                        int    index0;
                                        if (nazwa_warsty.IndexOf(",") != -1)
                                        {
                                            index0       = nazwa_warsty.IndexOf(",");
                                            nazwa_warsty = nazwa_warsty.Substring(0, index0) + "_" + nazwa_warsty.Substring(index0 + 1, nazwa_warsty.Length - index0 - 1);
                                        }

                                        netDxf.Tables.Layer warstwa = new netDxf.Tables.Layer("h-" + nazwa_warsty + "m");
                                        dxf.Layers.Add(warstwa);
                                        ln_1.Layer = warstwa;
                                        dxf.AddEntity(ln_1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public netDxf.DxfDocument ToDXFDocument()
        {
            PointD[] boundary   = this.Boundary;
            PointD   sizeP      = boundary[1] - boundary[0];
            double   longLength = sizeP.ToArray().Max();

            netDxf.DxfDocument doc = new netDxf.DxfDocument(netDxf.Header.DxfVersion.AutoCad2007);

            //標註設定
            netDxf.Tables.DimensionStyle StandardDimStyle = doc.DimensionStyles["Standard"];
            StandardDimStyle.DIMDEC   = (short)3;
            StandardDimStyle.DIMATFIT = 3;
            StandardDimStyle.DIMASZ   = longLength / 80;
            StandardDimStyle.DIMTXT   = longLength / 120;

            //依圖層
            List <Layer> allLayers = (from entity in this.Entities.Values
                                      where entity is Layer
                                      select(Layer) entity).ToList();

            foreach (var layer in allLayers)
            {
                Tuple <netDxf.Tables.Layer, List <netDxf.Entities.EntityObject> > LayerAndEntities = layer.ToDxfEntitiesAndLayer();
                netDxf.Tables.Layer dxfLayer = LayerAndEntities.Item1;
                List <netDxf.Entities.EntityObject> entities = LayerAndEntities.Item2;
                //doc.Layers.Add(dxfLayer);
                foreach (var item in entities)
                {
                    if (item is netDxf.Entities.Dimension)
                    {
                        (item as netDxf.Entities.Dimension).Style = StandardDimStyle;
                    }
                    doc.AddEntity(item);
                }
            }


            //依元素
            netDxf.Tables.Layer defualtLayer = new netDxf.Tables.Layer("defualt");
            List <IToDXFEntity> Entities     = (from entity in this.Entities.Values
                                                where entity is IToDXFEntity
                                                select(IToDXFEntity) entity).ToList();

            foreach (var entity in Entities)
            {
                netDxf.Entities.EntityObject dxfEntity = entity.ToDXFEntity();
                if (dxfEntity != null)
                {
                    dxfEntity.Layer = defualtLayer;
                    doc.AddEntity(dxfEntity);
                }
            }
            List <IToDXFEntities> MultEntities = (from entity in this.Entities.Values
                                                  where entity is IToDXFEntities
                                                  select(IToDXFEntities) entity).ToList();

            foreach (var entity in MultEntities)
            {
                foreach (netDxf.Entities.EntityObject item in entity.ToDXFEntities())
                {
                    item.Layer = defualtLayer;
                    doc.AddEntity(item);
                }
            }

            return(doc);
        }
Esempio n. 5
0
        public netDxf.DxfDocument ToDXFDocument()
        {
            PointD[] boundary = this.Boundary;
            PointD sizeP = boundary[1] - boundary[0];
            double longLength = sizeP.ToArray().Max();
            netDxf.DxfDocument doc = new netDxf.DxfDocument(netDxf.Header.DxfVersion.AutoCad2007);

            //標註設定
            netDxf.Tables.DimensionStyle StandardDimStyle = doc.DimensionStyles["Standard"];
            StandardDimStyle.DIMDEC = (short)3;
            StandardDimStyle.DIMATFIT = 3;
            StandardDimStyle.DIMASZ = longLength / 80;
            StandardDimStyle.DIMTXT = longLength / 120;

            //依圖層
            List<Layer> allLayers = (from entity in this.Entities.Values
                                     where entity is Layer
                                     select (Layer)entity).ToList();
            foreach (var layer in allLayers)
            {
                Tuple<netDxf.Tables.Layer, List<netDxf.Entities.EntityObject>> LayerAndEntities = layer.ToDxfEntitiesAndLayer();
                netDxf.Tables.Layer dxfLayer = LayerAndEntities.Item1;
                List<netDxf.Entities.EntityObject> entities = LayerAndEntities.Item2;
                //doc.Layers.Add(dxfLayer);
                foreach (var item in entities)
                {
                    if (item is netDxf.Entities.Dimension)
                        (item as netDxf.Entities.Dimension).Style = StandardDimStyle;
                    doc.AddEntity(item);
                }
            }
            

            //依元素
            netDxf.Tables.Layer defualtLayer = new netDxf.Tables.Layer("defualt");
            List<IToDXFEntity> Entities = (from entity in this.Entities.Values
                                                  where entity is IToDXFEntity
                                                  select (IToDXFEntity)entity).ToList();
            foreach (var entity in Entities)
            {
                netDxf.Entities.EntityObject dxfEntity = entity.ToDXFEntity();
                if (dxfEntity != null)
                {
                    dxfEntity.Layer = defualtLayer;
                    doc.AddEntity(dxfEntity); 
                }
            }
            List<IToDXFEntities> MultEntities = (from entity in this.Entities.Values
                                             where entity is IToDXFEntities
                                             select (IToDXFEntities)entity).ToList();
            foreach (var entity in MultEntities)
            {
                foreach (netDxf.Entities.EntityObject item in entity.ToDXFEntities())
                {
                    item.Layer = defualtLayer;
                    doc.AddEntity(item);
                }
            }

            return doc;
        }