Ejemplo n.º 1
0
        private void CircuitDraw_MouseMove(object sender, MouseEventArgs e)
        {
            if (moving == true && selected != null)
            {
                switch (selected.Type)
                {
                case Type.Resistor:
                    selected.Coordinates = CenterElement(e.Location, Type.Resistor);
                    break;

                case Type.Capacitor:
                    selected.Coordinates = CenterElement(e.Location, Type.Capacitor);
                    break;

                case Type.VoltGenerator:
                    selected.Coordinates = CenterElement(e.Location, Type.AmpGenerator);
                    break;

                case Type.AmpGenerator:
                    selected.Coordinates = CenterElement(e.Location, Type.VoltGenerator);
                    break;
                }
            }

            if (Math.Abs(MouseLastLocation.X - e.Location.X) > 20 || Math.Abs(MouseLastLocation.Y - e.Location.Y) > 10)
            {
                MouseLastLocation = e.Location;
                DrawShadow(CircuitDraw.PointToClient(Cursor.Position), false);
                DrawnOnce = false;
            }
            else if (!DrawnOnce)
            {
                DrawShadow(CircuitDraw.PointToClient(Cursor.Position), true);
            }
        }
Ejemplo n.º 2
0
 private void BtnCursor_Click(object sender, EventArgs e)
 {
     selected = IsSomethingThere(CircuitDraw.PointToClient(Cursor.Position));
     if (selected != null)
     {
         MouseEventArgs m = e as MouseEventArgs;
         if (m.Button == MouseButtons.Left)
         {
             lblName.Text         = selected.Name;
             lblValue.Text        = selected.Value.ToString();
             lblElementValue.Text = selected.Value.ToString();
             moving = false;
         }
         else if (m.Button == MouseButtons.Right)
         {
             if (moving == false)
             {
                 moving = true;
             }
             else
             {
                 moving = false;
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void Reset()
 {
     using (Graphics g = CircuitDraw.CreateGraphics())
     {
         g.Clear(Color.White);
         Elements.Clear();
     }
 }
Ejemplo n.º 4
0
 private void DrawElements(List <Element> list)
 {
     using (Graphics g = CircuitDraw.CreateGraphics())
         foreach (Element element in list)
         {
             element.Draw(g);
         }
     ChangesMade = false;
 }
Ejemplo n.º 5
0
        private void ClearGrid()
        {
            if (!ChangesMade)
            {
                return;
            }

            using (Graphics g = CircuitDraw.CreateGraphics())
            {
                g.Clear(Color.White);
            }
        }
Ejemplo n.º 6
0
 private void BtnRotate_Click(object sender, EventArgs e)
 {
     selected = IsSomethingThere(CircuitDraw.PointToClient(Cursor.Position));
     if (selected != null)
     {
         if (selected.Type == Type.Resistor || selected.Type == Type.Capacitor)
         {
             selected.SwitchOrientation();
         }
         else
         {
             selected.SwitchDirection();
         }
     }
 }
Ejemplo n.º 7
0
        private void CircuitDraw_MouseClick(object sender, MouseEventArgs e)
        {
            using (Graphics g = CircuitDraw.CreateGraphics())
            {
                if (IsSomethingThere(new Point(e.X, e.Y)) != null && !btnCursor.Focused && !btnRotate.Focused && !btnConnect.Focused)
                {
                    MessageBox.Show("There's already something there.");
                }
                else
                {
                    if (btnResistor.Focused == true)
                    {
                        Element R = new Element(Type.Resistor, $"R{ResistorCounter++}", 50, Orientation.Horizontal, Direction.None, CenterElement(e.Location, Type.Resistor));
                        Elements.Add(R);  //Adds the component to global list
                    }
                    else if (btnCapacitor.Focused == true)
                    {
                        Element C = new Element(Type.Capacitor, $"C{CapacitorCounter++}", 50, Orientation.Horizontal, Direction.None, CenterElement(e.Location, Type.Capacitor));
                        Elements.Add(C);
                    }
                    else if (btnAmpGenerator.Focused == true)
                    {
                        Element A = new Element(Type.AmpGenerator, $"J{AmpGeneratorCounter++}", 50, Orientation.Horizontal, Direction.Right, CenterElement(e.Location, Type.AmpGenerator));
                        Elements.Add(A);
                    }
                    else if (btnVoltGenerator.Focused == true)
                    {
                        Point   Center = new Point(e.Location.X - (52 / 2), e.Location.Y - (52 / 2));
                        Element V      = new Element(Type.VoltGenerator, $"E{VoltGeneratorCounter++}", 50, Orientation.Horizontal, Direction.Right, CenterElement(e.Location, Type.VoltGenerator));
                        Elements.Add(V);
                    }
                    else if (btnCursor.Focused)
                    {
                        BtnCursor_Click(sender, e);
                    }
                    else if (btnRotate.Focused)
                    {
                        BtnRotate_Click(sender, e);
                    }
                    else if (btnConnect.Focused)
                    {
                        BtnConnect_Click(sender, e);
                    }
                }

                ChangesMade = true;
            }
        }
Ejemplo n.º 8
0
        private void DrawShadow(Point point, bool UndoChangesMade)
        {
            using (Graphics g = CircuitDraw.CreateGraphics())
            {
                if (((btnAmpGenerator.Focused || btnAmpGenerator.Focused || btnCapacitor.Focused || btnResistor.Focused) && !UndoChangesMade) == true)
                {
                    ChangesMade = true;
                }

                if (UndoChangesMade)
                {
                    ClearGrid();
                    DrawGrid();
                    DrawElements(Elements);
                    DrawnOnce = true;
                }

                Element element = new Element();
                if (btnResistor.Focused == true)
                {
                    element.Coordinates = CenterElement(point, Type.Resistor);
                    element.DummyDraw(g);
                }
                else if (btnCapacitor.Focused == true)
                {
                    element.Type        = Type.Capacitor;
                    element.Coordinates = CenterElement(point, Type.Capacitor);

                    element.DummyDraw(g);
                }
                else if (btnAmpGenerator.Focused == true)
                {
                    element.Type        = Type.AmpGenerator;
                    element.Coordinates = CenterElement(point, Type.AmpGenerator);

                    element.DummyDraw(g);
                }
                else if (btnVoltGenerator.Focused == true)
                {
                    element.Type        = Type.VoltGenerator;
                    element.Coordinates = CenterElement(point, Type.VoltGenerator);

                    element.DummyDraw(g);
                }
            }
        }
Ejemplo n.º 9
0
 private void BtnConnect_Click(object sender, EventArgs e)
 {
     //if the selected element is null and we click at a good element
     if (selected == null && IsSomethingThere(CircuitDraw.PointToClient(Cursor.Position)) != null)
     {
         selected = IsSomethingThere(CircuitDraw.PointToClient(Cursor.Position));
     }
     else if (selected != null)
     {
         if (IsSomethingThere(CircuitDraw.PointToClient(Cursor.Position)) != null)
         {
             Element second = IsSomethingThere(CircuitDraw.PointToClient(Cursor.Position));
             //TODO See the position of the element and connec it accordingly
             MessageBox.Show($"{selected.Name} connected to {second.Name}");
             selected = null;
         }
     }
 }
Ejemplo n.º 10
0
        public void DrawGrid()
        {
            if (!ChangesMade)
            {
                return;
            }

            Bitmap bm = new Bitmap(CircuitDraw.Width, CircuitDraw.Height);

            using (Graphics g = Graphics.FromImage(bm))
            {
                for (int i = 0; i < this.Width; i += 20)
                {
                    g.DrawLine(new Pen(Color.Gray, 1), i, 0, i, this.Height);
                    g.DrawLine(new Pen(Color.Gray, 1), 0, i, this.Width, i);
                }
            }
            CircuitDraw.Image = bm;
            CircuitDraw.Refresh();
        }