Exemplo n.º 1
0
        public void Draw(Instance Ins, double ScaleF)
        {
            //Obtain Data
            List <List <double> > OriginDraw = ModelDraw(Ins.Nodes);
            List <List <Node> >   tmpCPs     = new List <List <Node> >();

            foreach (List <Node> item in Ins.Nodes)
            {
                List <Node> tmpItem = new List <Node>();
                item.ForEach(i => tmpItem.Add((Node)i.Clone()));
                tmpCPs.Add(tmpItem);
            }
            for (int i = 0; i != tmpCPs.Count; ++i)
            {
                for (int j = 0; j != tmpCPs[0].Count; ++j)
                {
                    tmpCPs[i][j].x += ScaleF * Ins.Disp[tmpCPs[i][j].n * 2];
                    tmpCPs[i][j].y += ScaleF * Ins.Disp[tmpCPs[i][j].n * 2 + 1];
                }
            }
            List <List <double> >         DeformedDraw = ModelDraw(tmpCPs);
            List <List <List <double> > > StressDraw   = new List <List <List <double> > >();

            foreach (IGAElement Ele in Ins.Eles)
            {
                StressDraw.Add(Ele.StressSample(Ins.Disp));
            }
            double Sxmin  = StressDraw[0][0][2];
            double Sxmax  = StressDraw[0][0][2];
            double Symin  = StressDraw[0][0][3];
            double Symax  = StressDraw[0][0][3];
            double Txymin = StressDraw[0][0][4];
            double Txymax = StressDraw[0][0][4];

            foreach (List <List <double> > EleStress in StressDraw)
            {
                foreach (List <double> Pxys in EleStress)
                {
                    Sxmin  = Sxmin > Pxys[2] ? Pxys[2] : Sxmin;
                    Sxmax  = Sxmax < Pxys[2] ? Pxys[2] : Sxmax;
                    Symin  = Symin > Pxys[3] ? Pxys[3] : Symin;
                    Symax  = Symax < Pxys[3] ? Pxys[3] : Symax;
                    Txymin = Txymin > Pxys[4] ? Pxys[4] : Txymin;
                    Txymax = Txymax < Pxys[4] ? Pxys[4] : Txymax;
                }
            }
            double ScaleSx  = 255 / (Sxmax - Sxmin);
            double ScaleSy  = 255 / (Symax - Symin);
            double ScaleTxy = 255 / (Txymax - Txymin);

            foreach (List <List <double> > EleStress in StressDraw)
            {
                for (int h = 0; h != EleStress.Count; ++h)
                {
                    List <double> tmpxy = xy(EleStress[h][0], EleStress[h][1], tmpCPs);
                    EleStress[h][0] = tmpxy[0];
                    EleStress[h][1] = tmpxy[1];
                }
            }
            //Initial
            int      Size    = 500;
            int      Margin  = 50;
            Bitmap   DispPic = new Bitmap(Size, Size);
            Bitmap   SxPic   = new Bitmap(Size, Size);
            Bitmap   SyPic   = new Bitmap(Size, Size);
            Bitmap   TxyPic  = new Bitmap(Size, Size);
            Graphics GDisp   = Graphics.FromImage(DispPic);
            Graphics GSx     = Graphics.FromImage(SxPic);
            Graphics GSy     = Graphics.FromImage(SyPic);
            Graphics GTxy    = Graphics.FromImage(TxyPic);

            GDisp.SmoothingMode = SmoothingMode.AntiAlias;
            GSx.SmoothingMode   = SmoothingMode.AntiAlias;
            GSy.SmoothingMode   = SmoothingMode.AntiAlias;
            GTxy.SmoothingMode  = SmoothingMode.AntiAlias;
            LinearGradientBrush linGrBrush = new LinearGradientBrush(new Point(124, 0), new Point(376, 0), Color.FromArgb(0, 0, 255), Color.FromArgb(255, 0, 0));

            GSx.FillRectangle(linGrBrush, 125, 470, 250, 20);
            GSy.FillRectangle(linGrBrush, 125, 470, 250, 20);
            GTxy.FillRectangle(linGrBrush, 125, 470, 250, 20);
            Rectangle    StringBoxLeft    = new Rectangle(0, 470, 125, 21);
            Rectangle    StringBoxRight   = new Rectangle(377, 470, 125, 21);
            StringFormat StringFormatLeft = new StringFormat();

            StringFormatLeft.Alignment     = StringAlignment.Far;
            StringFormatLeft.LineAlignment = StringAlignment.Center;
            StringFormat StringFormatRight = new StringFormat();

            StringFormatRight.Alignment     = StringAlignment.Near;
            StringFormatRight.LineAlignment = StringAlignment.Center;
            GSx.DrawString(Sxmin.ToString("E"), new Font("宋体", 9), new SolidBrush(Color.Black), StringBoxLeft, StringFormatLeft);
            GSx.DrawString(Sxmax.ToString("E"), new Font("宋体", 9), new SolidBrush(Color.Black), StringBoxRight, StringFormatRight);
            GSy.DrawString(Symin.ToString("E"), new Font("宋体", 9), new SolidBrush(Color.Black), StringBoxLeft, StringFormatLeft);
            GSy.DrawString(Symax.ToString("E"), new Font("宋体", 9), new SolidBrush(Color.Black), StringBoxRight, StringFormatRight);
            GTxy.DrawString(Txymin.ToString("E"), new Font("宋体", 9), new SolidBrush(Color.Black), StringBoxLeft, StringFormatLeft);
            GTxy.DrawString(Txymax.ToString("E"), new Font("宋体", 9), new SolidBrush(Color.Black), StringBoxRight, StringFormatRight);
            //Origin Offset
            GDisp.Transform = new Matrix(1, 0, 0, -1, 0, 0);
            GSx.Transform   = new Matrix(1, 0, 0, -1, 0, 0);
            GSy.Transform   = new Matrix(1, 0, 0, -1, 0, 0);
            GTxy.Transform  = new Matrix(1, 0, 0, -1, 0, 0);
            double minX = OriginDraw[0][0], maxX = OriginDraw[0][0], minY = OriginDraw[0][1], maxY = OriginDraw[0][1];

            foreach (List <double> Line in OriginDraw)
            {
                for (int h = 0; h != Line.Count; h += 2)
                {
                    minX = minX > Line[h] ? Line[h] : minX;
                    maxX = maxX < Line[h] ? Line[h] : maxX;
                    minY = minY > Line[h + 1] ? Line[h + 1] : minY;
                    maxY = maxY < Line[h + 1] ? Line[h + 1] : maxY;
                }
            }
            foreach (List <double> Line in DeformedDraw)
            {
                for (int h = 0; h != Line.Count; h += 2)
                {
                    minX = minX > Line[h] ? Line[h] : minX;
                    maxX = maxX < Line[h] ? Line[h] : maxX;
                    minY = minY > Line[h + 1] ? Line[h + 1] : minY;
                    maxY = maxY < Line[h + 1] ? Line[h + 1] : maxY;
                }
            }
            double Scale   = (Size - 2 * Margin) / ((maxX - minX) > (maxY - minY) ? (maxX - minX) : (maxY - minY));
            float  OffsetX = (float)(Size / 2) + System.Math.Abs((float)(Scale * minX)) - (float)(Scale * (maxX - minX) / 2);
            float  OffsetY = (float)(Size / 2) + System.Math.Abs((float)(Scale * maxY)) - (float)(Scale * (maxY - minY) / 2);

            GDisp.TranslateTransform(OffsetX, -OffsetY);
            GSx.TranslateTransform(OffsetX, -OffsetY);
            GSy.TranslateTransform(OffsetX, -OffsetY);
            GTxy.TranslateTransform(OffsetX, -OffsetY);
            //Draw Picture
            foreach (List <double> Line in OriginDraw)
            {
                for (int h = 0; h != Line.Count - 2; h += 2)
                {
                    GDisp.DrawLine(new Pen(Color.Blue), (float)(Line[h] * Scale), (float)(Line[h + 1] * Scale), (float)(Line[h + 2] * Scale), (float)(Line[h + 3] * Scale));
                }
            }
            int L = 10;

            foreach (List <List <double> > EleStress in StressDraw)
            {
                foreach (List <double> Pxys in EleStress)
                {
                    GSx.FillEllipse(new SolidBrush(Color.FromArgb((int)(ScaleSx * (Sxmax - Pxys[2])), 0, (int)(ScaleSx * (Pxys[2] - Sxmin)))), (float)(Pxys[0] * Scale - L / 2), (float)(Pxys[1] * Scale - L / 2), L, L);
                    GSy.FillEllipse(new SolidBrush(Color.FromArgb((int)(ScaleSy * (Symax - Pxys[3])), 0, (int)(ScaleSy * (Pxys[3] - Symin)))), (float)(Pxys[0] * Scale - L / 2), (float)(Pxys[1] * Scale - L / 2), L, L);
                    GTxy.FillEllipse(new SolidBrush(Color.FromArgb((int)(ScaleTxy * (Txymax - Pxys[4])), 0, (int)(ScaleTxy * (Pxys[4] - Txymin)))), (float)(Pxys[0] * Scale - L / 2), (float)(Pxys[1] * Scale - L / 2), L, L);
                }
            }
            foreach (List <double> Line in DeformedDraw)
            {
                for (int h = 0; h != Line.Count - 2; h += 2)
                {
                    GDisp.DrawLine(new Pen(Color.Red), (float)(Line[h] * Scale), (float)(Line[h + 1] * Scale), (float)(Line[h + 2] * Scale), (float)(Line[h + 3] * Scale));
                    GSx.DrawLine(new Pen(Color.Black), (float)(Line[h] * Scale), (float)(Line[h + 1] * Scale), (float)(Line[h + 2] * Scale), (float)(Line[h + 3] * Scale));
                    GSy.DrawLine(new Pen(Color.Black), (float)(Line[h] * Scale), (float)(Line[h + 1] * Scale), (float)(Line[h + 2] * Scale), (float)(Line[h + 3] * Scale));
                    GTxy.DrawLine(new Pen(Color.Black), (float)(Line[h] * Scale), (float)(Line[h + 1] * Scale), (float)(Line[h + 2] * Scale), (float)(Line[h + 3] * Scale));
                }
            }
            //Save
            DispPicture = DispPic;
            SxPicture   = SxPic;
            SyPicture   = SyPic;
            TxyPicture  = TxyPic;
        }