Example #1
0
        private void LoadScheme(string path)
        {
            filename    = path;
            modified    = false;
            dragElement = null;
            connectLine = null;
            menuElement = null;
            move        = false;
            scheme?.Dispose();
            scheme = null;

            if (string.IsNullOrEmpty(path))
            {
                scheme   = new DrawableScheme(pictureBox.Width, pictureBox.Height);
                filename = null;
            }
            else
            {
                try
                {
                    using (var file = File.Open(path, FileMode.Open))
                        scheme = DrawableSchemeStorage.Load(file);
                }
                catch (Exception exception)
                {
                    ShowError(String.Format(Resource.Localization.Error_PathOpen, path), exception);

                    filename = null;
                    scheme   = new DrawableScheme(pictureBox.Width, pictureBox.Height);
                }
            }

            DrawScheme();
        }
Example #2
0
        private void moveElementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modified = true;

            toolStripButton_Click(moveButton, null);
            dragElement = menuElement;
            menuElement = null;
        }
Example #3
0
        private void deleteElementMenuStripItem_Click(object sender, EventArgs e)
        {
            modified = true;

            scheme.RemoveElement(menuElement);
            DrawScheme();
            menuElement = null;
        }
Example #4
0
 private void createConnectionToolStripMenuItem_Click(object sender, EventArgs e)
 {
     toolStripButton_Click(connectionButton, null);
     if (!(menuElement is Output))
     {
         modified    = true;
         connectLine = new Line(menuElement, null);
     }
     menuElement = null;
 }
Example #5
0
        private void LoadScheme(Scheme source)
        {
            filename    = null;
            modified    = false;
            dragElement = null;
            connectLine = null;
            menuElement = null;
            move        = false;
            scheme?.Dispose();

            scheme = DrawableScheme.FromScheme(source, pictureBox.Width, pictureBox.Height);

            DrawScheme();
        }
Example #6
0
        private void renameElementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new NameDialog())
                if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(dialog.NewName))
                {
                    modified = true;

                    foreach (Output output in scheme.Elements.Where(x => x is Output && (x as Output).Input == menuElement.Name))
                    {
                        output.Input = dialog.NewName;
                    }
                    foreach (Component component in scheme.Elements.Where(x => x is Component && (x as Component).Input.Contains(menuElement.Name)))
                    {
                        component.RemoveInput(menuElement.Name);
                        component.AddInput(dialog.NewName);
                    }
                    menuElement.Name = dialog.NewName;

                    DrawScheme();
                    menuElement = null;
                }
        }
Example #7
0
 public ElementMovedEventArgs(IMoveableElement movedElement, double horizontalChange, double verticalChange)
 {
     MovedElement     = movedElement;
     HorizontalChange = horizontalChange;
     VerticalChange   = verticalChange;
 }
Example #8
0
 public Line(IMoveableElement element1, IMoveableElement element2)
 {
     connection = new Tuple <IMoveableElement, IMoveableElement>(element1, element2);
 }
Example #9
0
        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            modified = true;

            string item = listBox.SelectedItem as string;

            switch (item)
            {
            case "Input":
            {
                var max_input_number = (scheme.Inputs.Count > 0 ? scheme.Inputs
                                        .Select(x =>
                    {
                        int number;
                        if (int.TryParse(x.Name.Substring(1), out number))
                        {
                            return(number);
                        }
                        else
                        {
                            return(0);
                        }
                    })
                                        .Max() : 0);

                dragElement = new DrawableInput(
                    $"x{max_input_number + 1}",
                    0, 0,
                    DrawableScheme.ElementWidth,
                    DrawableScheme.ElementHeight
                    );
            }
            break;

            case "Output":
            {
                var max_output_number = (scheme.Outputs.Count > 0 ? scheme.Outputs
                                         .Select(x =>
                    {
                        int number;
                        if (int.TryParse(x.Name.Substring(1), out number))
                        {
                            return(number);
                        }
                        else
                        {
                            return(0);
                        }
                    })
                                         .Max() : 0);

                dragElement = new DrawableOutput(
                    $"y{max_output_number + 1}",
                    null,
                    0, 0,
                    DrawableScheme.ElementWidth,
                    DrawableScheme.ElementHeight
                    );
            }
            break;

            default:
            {
                ComponentType componentType;
                if (Enum.TryParse(item, out componentType))
                {
                    var max_component_number = (scheme.Components.Count > 0 ? scheme.Components
                                                .Select(x =>
                        {
                            int number;
                            if (int.TryParse(x.Name.Substring(1), out number))
                            {
                                return(number);
                            }
                            else
                            {
                                return(0);
                            }
                        })
                                                .Max() : 0);

                    dragElement = new DrawableComponent(
                        $"c{max_component_number + 1}",
                        componentType,
                        new string[] { },
                        0, 0,
                        DrawableScheme.ElementWidth,
                        DrawableScheme.ElementHeight
                        );
                }
            }
            break;
            }
        }
Example #10
0
        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Control)
            {
                move              = true;
                moveLastLocation  = e.Location;
                pictureBox.Cursor = Cursors.NoMove2D;
            }
            else if (e.Button == MouseButtons.Left)
            {
                if (dragElement != null)
                {
                    var overflowElements = scheme.GetElementsAtRectangle(
                        dragElement.X,
                        dragElement.Y,
                        dragElement.Width,
                        dragElement.Height
                        );
                    if (overflowElements.Count() == 0 || (overflowElements.Count() == 1 && overflowElements.Contains(dragElement)))
                    {
                        dragElement = null;
                    }
                }
                else if (moveButton.Checked)
                {
                    modified    = true;
                    dragElement = scheme.GetElementAtLocation(e.Location) as IMoveableElement;
                }

                if (connectLine != null)
                {
                    var underMouseElement = scheme.GetElementAtLocation(e.Location) as IMoveableElement;
                    if (underMouseElement != null && underMouseElement != connectLine.connection.Item1)
                    {
                        connectLine.connection = new Tuple <IMoveableElement, IMoveableElement>(
                            connectLine.connection.Item1,
                            underMouseElement
                            );

                        var add = !scheme.Elements.Contains(connectLine);

                        if (connectLine.connection.Item2 is Component)
                        {
                            ((Component)connectLine.connection.Item2).AddInput(connectLine.connection.Item1.Name);
                        }
                        else if (connectLine.connection.Item2 is Output && string.IsNullOrEmpty(((Output)connectLine.connection.Item2).Input))
                        {
                            ((Output)connectLine.connection.Item2).Input = connectLine.connection.Item1.Name;
                        }
                        else
                        {
                            add = false;
                        }

                        if (add)
                        {
                            scheme.AddElement(connectLine);
                            DrawScheme();
                            connectLine = null;
                        }
                    }
                }
                else if (connectionButton.Checked)
                {
                    var underMouseElement = scheme.GetElementAtLocation(e.Location) as IMoveableElement;
                    if (underMouseElement != null && !(underMouseElement is Output))
                    {
                        modified    = true;
                        connectLine = new Line(underMouseElement, null);
                    }
                }

                if (deleteButton.Checked)
                {
                    var toDelete = scheme.GetElementAtLocation(e.Location);
                    if (toDelete != null)
                    {
                        modified = true;
                        scheme.RemoveElement(toDelete);
                        DrawScheme();
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (connectLine != null)
                {
                    DrawScheme();
                }

                dragElement = null;
                connectLine = null;

                menuElement = scheme.GetElementAtLocation(e.Location) as IMoveableElement;
                pictureBox.ContextMenuStrip = (menuElement == null ? schemeMenuStrip : elementMenuStrip);
            }
        }