コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = Graphics.FromImage(PB_Draw.Image);

            g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
            //g.RotateTransform(90);
            //g.DrawLine(new Pen(Color.Black, 50), ChosenLine.A, ChosenLine.B);
            PB_Draw.Refresh();
            //PB_Draw.Invalidate();
        }
コード例 #2
0
        public void DrawMorph()
        {
            Graphics g = Graphics.FromImage(PB_Draw.Image);

            g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
            g.ScaleTransform(1, -1);
            foreach (Line2D line2D in MorphingGroup)
            {
                g.DrawLine(new Pen(Color.Black, 1), line2D.Local_A.X, line2D.Local_A.Y, line2D.Local_B.X, line2D.Local_B.Y);
                g.FillEllipse(Brushes.Black, line2D.Local_A.X - 3, line2D.Local_A.Y - 3, 6, 6);
                g.FillEllipse(Brushes.Black, line2D.Local_B.X - 3, line2D.Local_B.Y - 3, 6, 6);
            }
            PB_Draw.Refresh();
        }
コード例 #3
0
        private void btn_CreateLine_Click(object sender, EventArgs e)
        {
            Line2D newLine = new Line2D();

            lines.Add(newLine);
            //Graphics g = Graphics.FromImage(PB_Draw.Image);
            Graphics g = Graphics.FromImage(PB_Draw.Image);

            g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
            g.ScaleTransform(1, -1);
            g.DrawLine(new Pen(Color.Black, 1), newLine.A, newLine.B);
            g.FillEllipse(Brushes.Black, newLine.A.X - 3, newLine.A.Y - 3, 6, 6);
            g.FillEllipse(Brushes.Black, newLine.B.X - 3, newLine.B.Y - 3, 6, 6);
            PB_Draw.Refresh();
            //PBDraw.Invalidate();
        }
コード例 #4
0
        public void DrawAllLines()
        {
            Graphics g = Graphics.FromImage(PB_Draw.Image);

            g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
            //Graphics g = Graphics.FromImage(PB_Draw.Image);
            g.Clear(Color.White);
            foreach (Line2D line2D in lines)
            {
                g.DrawLine(new Pen(Color.Black, 1), line2D.A, line2D.B);
                g.FillEllipse(Brushes.Black, line2D.A.X - 3, line2D.A.Y - 3, 6, 6);
                g.FillEllipse(Brushes.Black, line2D.B.X - 3, line2D.B.Y - 3, 6, 6);
            }
            PB_Draw.Refresh();
            //PBDraw.Invalidate();
        }
コード例 #5
0
 private void frm_Main_Load(object sender, EventArgs e)
 {
     lines = new List <Line2D>();
     maxX  = PB_Draw.Size.Width;
     maxY  = PB_Draw.Size.Height;
     bmp   = new Bitmap(PB_Draw.Width, PB_Draw.Height);
     for (int i = 0; i < PB_Draw.Width; i++)
     {
         for (int j = 0; j < PB_Draw.Height; j++)
         {
             bmp.SetPixel(i, j, Color.White);
         }
     }
     PB_Draw.Image = bmp;
     PB_Draw.Refresh();
 }
コード例 #6
0
        public void DrawAllLines()
        {
            Graphics g = Graphics.FromImage(PB_Draw.Image);

            g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
            g.ScaleTransform(1, -1);
            g.Clear(Color.White);
            if (CB_Axes.Checked)
            {
                ShowAxes();
            }
            foreach (Line2D line2D in lines)
            {
                g.DrawLine(new Pen(Color.Black, 1), line2D.Local_A.X, line2D.Local_A.Y, line2D.Local_B.X, line2D.Local_B.Y);
                g.FillEllipse(Brushes.Black, line2D.Local_A.X - 3, line2D.Local_A.Y - 3, 6, 6);
                g.FillEllipse(Brushes.Black, line2D.Local_B.X - 3, line2D.Local_B.Y - 3, 6, 6);
            }
            PB_Draw.Refresh();
        }
コード例 #7
0
 private void frm_Main_Load(object sender, EventArgs e)
 {
     btn_Change.Enabled = false;
     lines = new List <Line2D>();
     maxX  = PB_Draw.Size.Width;
     maxY  = PB_Draw.Size.Height;
     bmp   = new Bitmap(PB_Draw.Width, PB_Draw.Height);
     for (int i = 0; i < PB_Draw.Width; i++)
     {
         for (int j = 0; j < PB_Draw.Height; j++)
         {
             bmp.SetPixel(i, j, Color.White);
         }
     }
     ChosenGroupOfLines = new List <Line2D>();
     PB_Draw.Image      = bmp;
     //PB_Draw.Refresh();
     ShowAxes();
     PB_Draw.Refresh();
     dgv_Massive.Rows.Add(4);
     dgv_Massive.AutoSizeColumnsMode    = DataGridViewAutoSizeColumnsMode.Fill;
     dgv_Massive.Rows[0].Cells[0].Value = "0";
     dgv_Massive.Rows[0].Cells[1].Value = "0";
     dgv_Massive.Rows[0].Cells[2].Value = "0";
     dgv_Massive.Rows[0].Cells[3].Value = "0";
     dgv_Massive.Rows[1].Cells[0].Value = "0";
     dgv_Massive.Rows[1].Cells[1].Value = "0";
     dgv_Massive.Rows[1].Cells[2].Value = "0";
     dgv_Massive.Rows[1].Cells[3].Value = "0";
     dgv_Massive.Rows[2].Cells[0].Value = "0";
     dgv_Massive.Rows[2].Cells[1].Value = "0";
     dgv_Massive.Rows[2].Cells[2].Value = "0";
     dgv_Massive.Rows[2].Cells[3].Value = "0";
     dgv_Massive.Rows[3].Cells[0].Value = "0";
     dgv_Massive.Rows[3].Cells[1].Value = "0";
     dgv_Massive.Rows[3].Cells[2].Value = "0";
     dgv_Massive.Rows[3].Cells[3].Value = "0";
     MakeDreamHouse();
 }
コード例 #8
0
        private void PB_Draw_MouseMove(object sender, MouseEventArgs e)
        {
            if (movement == action.NoAction)
            {
                if (ChosenLine == null)
                {
                    CurrentX = e.X - maxX / 2;
                    CurrentY = maxY / 2 - e.Y;
                    Line2D cur = null;
                    for (int i = 0; i < lines.Count; i++)
                    {
                        if (CheckForLine(CurrentX, CurrentY, lines[i]))
                        {
                            cur = lines[i];
                            break;
                        }
                    }
                    if (CurrentLine != null)
                    {
                        Graphics g = Graphics.FromImage(PB_Draw.Image);
                        g.DrawLine(new Pen(Color.Black, 1), CurrentLine.A, CurrentLine.B);
                        PB_Draw.Refresh();
                        CurrentLine = null;
                    }
                    if (cur != null)
                    {
                        Graphics g = Graphics.FromImage(PB_Draw.Image);
                        g.DrawLine(new Pen(Color.Red, 1), cur.A, cur.B);
                        PB_Draw.Refresh();
                        CurrentLine = cur;
                    }
                    else
                    {
                    }
                }
            }
            else
            {
                switch (movement)
                {
                case action.MoveLine:
                    ChosenLine.Move(e.X - startPosition.X, e.Y - startPosition.Y);
                    startPosition.X = e.X;
                    startPosition.Y = e.Y;
                    DrawAllLines();
                    break;

                case action.MovePointA:
                    ChosenLine.MoveA(e.X - startPosition.X, e.Y - startPosition.Y);
                    startPosition.X = e.X;
                    startPosition.Y = e.Y;
                    DrawAllLines();
                    break;

                case action.MovePointB:
                    ChosenLine.MoveB(e.X - startPosition.X, e.Y - startPosition.Y);
                    startPosition.X = e.X;
                    startPosition.Y = e.Y;
                    DrawAllLines();
                    break;
                }
            }
        }
コード例 #9
0
        private void PB_Draw_MouseUp(object sender, MouseEventArgs e)
        {
            if (movement == action.Median)
            {
                Point3D M = new Point3D((ChosenLine.A.X + ChosenLine.B.X) / 2, (ChosenLine.A.Y + ChosenLine.B.Y) / 2, (ChosenLine.A.Y + ChosenLine.B.Y) / 2);
                lines.Add(new Line2D(CurrentX, CurrentY, 0, M.X, M.Y, M.Z));
                DrawAllLines();
                movement = action.NoAction;
            }
            else if (movement == action.Height)
            {
                //Вычислить Z
                var A    = ChosenLine.equation[0];
                var B    = ChosenLine.equation[1];
                var C    = ChosenLine.equation[2];
                int Xval = (int)((-A * C - B * A * CurrentY + B * B * CurrentX) / (B * B + A * A));
                int Yval = (int)((A * A * CurrentY - A * B * CurrentX - C * B) / (B * B + A * A));
                int Zval;
                if (Math.Abs(ChosenLine.vector[0]) > 0.00001)
                {
                    Zval = (int)(ChosenLine.A.Z + ChosenLine.vector[2] * ((Xval - ChosenLine.A.X) / ChosenLine.vector[0]));
                }
                else
                {
                    Zval = (int)(ChosenLine.A.Z + ChosenLine.vector[2] * ((Yval - ChosenLine.A.Y) / ChosenLine.vector[1]));
                }
                Point3D H = new Point3D(Xval, Yval, Zval);
                lines.Add(new Line2D(CurrentX, CurrentY, 0, H.X, H.Y, H.Z));
                DrawAllLines();
                movement = action.NoAction;
            }
            if (ModifierKeys != Keys.Control && ChosenGroupOfLines.Count > 0 && CurrentLine != null)
            {
                ChosenGroupOfLines.Clear();
                DrawAllLines();
                btn_Change.Enabled = false;
            }
            if (CurrentLine != null && (ChosenLine == null || ModifierKeys == Keys.Control))
            {
                var f = new Font(Font.FontFamily, 8);
                ChosenLine = CurrentLine;

                Graphics g = Graphics.FromImage(PB_Draw.Image);
                // -- //
                g.DrawString(ChosenLine.Local_A.X + "; " + ChosenLine.Local_A.Y + "; " + ChosenLine.Local_A.Z, f, Brushes.Black, new PointF(ChosenLine.Local_A.X - 3 + maxX / 2, maxY / 2 - ChosenLine.Local_A.Y + 5));
                g.DrawString(ChosenLine.Local_B.X + "; " + ChosenLine.Local_B.Y + "; " + ChosenLine.Local_B.Z, f, Brushes.Black, new PointF(ChosenLine.Local_B.X - 3 + maxX / 2, maxY / 2 - ChosenLine.Local_B.Y + 5));
                g.DrawString(ChosenLine.UserEq, f, Brushes.Black, new PointF((ChosenLine.Local_B.X + maxX / 2 + ChosenLine.Local_A.X + maxX / 2) / 2, (maxY / 2 - ChosenLine.Local_B.Y + maxY / 2 - ChosenLine.Local_A.Y) / 2));
                PB_Draw.Refresh();
                tb1_X.Text = ChosenLine.A.X.ToString();
                tb1_Y.Text = ChosenLine.A.Y.ToString();
                tb1_Z.Text = ChosenLine.A.Z.ToString();

                tb2_X.Text         = ChosenLine.B.X.ToString();
                tb2_Y.Text         = ChosenLine.B.Y.ToString();
                tb2_Z.Text         = ChosenLine.B.Z.ToString();
                btn_Change.Enabled = true;
            }
            else if (ChosenLine != null)//&&movement==action.NoAction
            {
                movement   = action.NoAction;
                ChosenLine = null;
            }
            if (ChosenLine != null && ModifierKeys == Keys.Control)
            {
                //ChosenGroupOfLines.Add(ChosenLine);
                Line2D cur = null;
                for (int i = 0; i < lines.Count; i++)
                {
                    if (CheckForLine(CurrentX, CurrentY, lines[i]))
                    {
                        cur = lines[i];
                        break;
                    }
                }
                // if (cur!=null && !ChosenGroupOfLines.Contains(cur))
                if (cur != null)
                {
                    ChosenGroupOfLines.Add(cur);
                    Graphics g = Graphics.FromImage(PB_Draw.Image);
                    g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
                    g.ScaleTransform(1, -1);
                    g.DrawLine(new Pen(Color.Red, 1), cur.Local_A.X, cur.Local_A.Y, cur.Local_B.X, cur.Local_B.Y);// -- //
                    PB_Draw.Refresh();
                }
                ChosenLine = cur;
            }
            chosenGroup();
            if (ChosenLine != null && ChosenGroup != null)
            {
                Graphics g = Graphics.FromImage(PB_Draw.Image);
                g.TranslateTransform((float)maxX / 2, (float)maxY / 2);
                g.ScaleTransform(1, -1);
                foreach (Line2D ln2d in ChosenGroup.lines)
                {
                    g.DrawLine(new Pen(Color.Red, 1), ln2d.Local_A.X, ln2d.Local_A.Y, ln2d.Local_B.X, ln2d.Local_B.Y);// -- //
                }
                Refresh();
            }
            if (ChosenLine == null)
            {
                btn_Change.Enabled = false;
                DrawAllLines();
            }
        }