Esempio n. 1
0
        /// <summary>
        /// Recreate non-serializable elements after deserialization
        /// </summary>
        public void Deserialized(BoardGrid boardGrid)
        {
            BoardGrid = boardGrid;

            ComponentImage = new Image
            {
                Source = new BitmapImage(ImageSource) // Image to display
            };

            GraphicalComponent = new Border
            {
                Width           = 2 * BoardGrid.GridSpacing + 2 * BoardGrid.GridThickness, // The component covers 2 grid cells
                Height          = 2 * BoardGrid.GridSpacing + 2 * BoardGrid.GridThickness,
                Child           = ComponentImage,
                BorderBrush     = new SolidColorBrush(Colors.Black),
                BorderThickness = new Thickness(0),
                ToolTip         = Name
            };

            Position = Position; // Set the position of the graphical element and connect it to nodes

            // Add the component to the BoardGrid
            BoardGrid.Children.Add(GraphicalComponent);

            // Rotation
            Rotation = new RotateTransform();
            GraphicalComponent.RenderTransform = Rotation;
            RotationAngle = RotationAngle; // To compute the rotation center and apply the rotation to anchors
        }
Esempio n. 2
0
        public Dictionary <int, GraphLink> IdLinks = new Dictionary <int, GraphLink>(); //Allow to get a link with its ID
        #endregion


        #region Constructor
        public Graph(BoardGrid boardGrid)
        {
            BoardGrid = boardGrid;
            GenerateGraph();
            NumberNodesLinks();
            BoardGrid.DisplayGraphIds(this);
        }
Esempio n. 3
0
 public SavedCircuit(BoardGrid boardGrid)
 {
     // Save what has to be saved
     Components = boardGrid.ComponentsOnBoard;
     Wires      = boardGrid.WiresOnBoard;
     Nodes      = boardGrid.Nodes;
 }
Esempio n. 4
0
        /// <summary>
        /// Handler called when the new circuit button is clicked
        /// </summary>
        private void NewCircuitButton_Click(object sender, RoutedEventArgs e)
        {
            BoardGrid = new BoardGrid();
            CanvasController.Content = BoardGrid;

            // Reinitialize the buttons
            RotateLeftButton.IsEnabled            = false;
            RotateRightButton.IsEnabled           = false;
            DeleteButton.IsEnabled                = false;
            WireModeButton.IsChecked              = false;
            MultipleWiresModeCheckBox.IsEnabled   = false;
            MultipleWiresModeTextBlock.Visibility = Visibility.Collapsed;
        }
Esempio n. 5
0
        /// <summary>
        /// Add to the new BoardGrid and recreate the rectangles after deserialization
        /// </summary>
        public void Deserialized(BoardGrid boardGrid)
        {
            BoardGrid = boardGrid;

            Rectangles = new List <Rectangle>();
            for (int i = 0; i < 3; i++)
            {
                Rectangle newRect = new Rectangle()
                {
                    Fill = Brushes.Black
                };
                newRect.MouseLeftButtonUp += SwitchIsSelected;
                Rectangles.Add(newRect);
                BoardGrid.Children.Add(Rectangles[i]);
            }
            Redraw();
        }
Esempio n. 6
0
        private Vector MouseOffset; // The position of the node to drag relative to the mouse
        #endregion


        #region Constructor

        public WireDragger(BoardGrid boardGrid, Wire wire, Node draggingNode, Vector mouseOffset)
        {
            BoardGrid    = boardGrid;
            Wire         = wire;
            DraggingNode = draggingNode;
            MouseOffset  = mouseOffset;

            // Search for the static node
            if (DraggingNode == Wire.Nodes[0])
            {
                StaticNode = Wire.Nodes[1];
            }
            else
            {
                StaticNode = Wire.Nodes[0];
            }

            BoardGrid.DraggingWire = true;
        }
Esempio n. 7
0
        [NonSerialized()] private List <Rectangle> Rectangles; // The 3 rectangles composing the wire
        #endregion


        #region Constructor

        public Wire(BoardGrid boardGrid, Node originNode)
        {
            BoardGrid  = boardGrid;
            Thickness  = Properties.Settings.Default.WireThickness; // Default thickness
            Rectangles = new List <Rectangle>();
            for (int i = 0; i < 3; i++)
            {
                Rectangle newRect = new Rectangle()
                {
                    Fill = Brushes.Black
                };
                newRect.MouseLeftButtonUp += SwitchIsSelected;
                Rectangles.Add(newRect);
                BoardGrid.Children.Add(Rectangles[i]);
            }
            Nodes = new List <Node>()
            {
                originNode, originNode
            };
        }
Esempio n. 8
0
 /// <summary>
 /// Create the board once the windows is loaded to avoid some issues
 /// </summary>
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     BoardGrid = new BoardGrid();
     CanvasController.Content = BoardGrid;
     LoadComponents();
 }
Esempio n. 9
0
 /// <summary>
 /// Update the BoardGrid attribute after deserialization
 /// </summary>
 public void Deserialized(BoardGrid boardGrid)
 {
     BoardGrid = boardGrid;
 }
Esempio n. 10
0
        public Dictionary <object, Directions> ConnectedElements = new Dictionary <object, Directions>(); // The elements connected (Up, Right, Down, Left)
        #endregion


        #region Constructor

        public Node(Point position, BoardGrid boardGrid)
        {
            // Save attributes
            BoardGrid = boardGrid as BoardGrid;
            Position  = position;
        }
Esempio n. 11
0
        /// <summary>
        /// Add one component to the board
        /// </summary>
        /// <param name="position">The component position</param>
        /// <param name="boardGrid">The canvas on which to display the component</param>
        /// <param name="xmlElement">The XML Element with the component data</param>
        public Component(Point position, BoardGrid boardGrid, XElement xmlElement)
        {
            // Save parameters
            BoardGrid = boardGrid as BoardGrid;
            _Name     = xmlElement.Element("name").Value;

            // Display the image
            ImageSource    = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, Properties.Settings.Default.ResourcesFolder, xmlElement.Element("image").Value));
            ComponentImage = new Image
            {
                Source = new BitmapImage(ImageSource) // Image to display
            };

            GraphicalComponent = new Border
            {
                Width           = 2 * BoardGrid.GridSpacing + 2 * BoardGrid.GridThickness, // The component covers 2 grid cells
                Height          = 2 * BoardGrid.GridSpacing + 2 * BoardGrid.GridThickness,
                Child           = ComponentImage,
                BorderBrush     = new SolidColorBrush(Colors.Black),
                BorderThickness = new Thickness(0),
                ToolTip         = Name
            };
            ImageSize = new Vector(GraphicalComponent.Width, GraphicalComponent.Height);
            Scale     = GraphicalComponent.Width / (double)xmlElement.Element("width");

            Position = position;
            // Add the component to the BoardGrid
            BoardGrid.ComponentsOnBoard.Add(this);
            BoardGrid.Children.Add(GraphicalComponent);

            // Rotation
            Rotation = new RotateTransform(0);
            GraphicalComponent.RenderTransform = Rotation;

            // Anchors
            IEnumerable <XElement> xmlAnchors = xmlElement.Element("anchors").Elements("anchor"); // Get all the anchors present in the XML

            foreach (XElement xmlAnchor in xmlAnchors)
            {
                // Parse each anchor's position
                Vector anchor = new Vector
                {
                    X = (double)xmlAnchor.Element("posX") * Scale + GraphicalComponent.BorderThickness.Left,
                    Y = (double)xmlAnchor.Element("posY") * Scale + GraphicalComponent.BorderThickness.Top
                };
                anchor.X = Math.Round(anchor.X, 0); // Round the anchor composants
                anchor.Y = Math.Round(anchor.Y, 0);
                Anchors.Add(anchor);
            }

            // Attributes
            Attributes      = new Dictionary <string, double?>();
            AttributesUnits = new Dictionary <string, Dictionary <string, double> >();
            if (xmlElement.Element("attributes") != null)                                                      // Check if there are attributes
            {
                IEnumerable <XElement> xmlAttributes = xmlElement.Element("attributes").Elements("attribute"); // Get all the attributes present in the XML
                foreach (XElement xmlAttribute in xmlAttributes)                                               // Parse each attribute's name and available units
                {
                    Attributes.Add((string)xmlAttribute.Element("name"), null);                                // The value is undefined for now
                    AttributesUnits.Add((string)xmlAttribute.Element("name"), new Dictionary <string, double>());

                    foreach (XElement xmlUnit in xmlAttribute.Element("units").Elements("unit"))
                    {
                        AttributesUnits[(string)xmlAttribute.Element("name")].Add((string)xmlUnit.Element("symbol"), (double)xmlUnit.Element("value"));
                    }
                }
            }

            // Event handlers
            GraphicalComponent.MouseLeftButtonDown += Component_MouseLeftButtonDown; // Event handler to trigger selection or properties editing
            GraphicalComponent.MouseLeftButtonUp   += Component_MouseLeftButtonUp;   // Event handler to trigger selection or properties editing
            GraphicalComponent.MouseMove           += Component_MouseMove;           // Event handler to trigger drag&drop
        }
Esempio n. 12
0
        }                                    // The Graph representing the simulated circuit
        #endregion


        #region Constructor
        public Simulation(BoardGrid boardGrid)
        {
            BoardGrid      = boardGrid;
            SimulatedGraph = new Graph(boardGrid); // Generate the graph representing the circuit
        }