Esempio n. 1
0
        private void AlgorithmSetEvent(object sender, Tuple <int, SortedItem> e)
        {
            e.Item2.SetColor(Color.Red);
            VisualizationPanel.Refresh();
            Thread.Sleep(20);

            e.Item2.SetPosition(e.Item1);
            VisualizationPanel.Refresh();
            Thread.Sleep(20);

            e.Item2.SetColor(Color.Blue);
            VisualizationPanel.Refresh();
            Thread.Sleep(20);
        }
Esempio n. 2
0
        private void AlgorithmCompareEvent(object sender, Tuple <SortedItem, SortedItem> e)
        {
            e.Item1.SetColor(Color.Red);
            e.Item2.SetColor(Color.Green);
            VisualizationPanel.Refresh();

            Thread.Sleep(20);

            e.Item1.SetColor(Color.Blue);
            e.Item2.SetColor(Color.Blue);
            VisualizationPanel.Refresh();

            Thread.Sleep(20);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a new panel to the container.
        /// </summary>
        /// <param name="panel">The panel to be added to the container.</param>
        /// <param name="isRootChild">Flag indicating whether panel is root child.</param>
        public void AddPanel(VisualizationPanel panel, bool isRootChild = true)
        {
            panel.SetParentContainer(this);
            if (isRootChild)
            {
                if (this.CurrentPanel != null)
                {
                    this.Panels.Insert(this.Panels.IndexOf(this.CurrentPanel) + 1, panel);
                }
                else
                {
                    this.Panels.Add(panel);
                }
            }

            this.CurrentPanel = panel;
        }
Esempio n. 4
0
        private void UpdateContextMenu(StackPanel panel)
        {
            VisualizationPanel            currentPanel         = VisualizationContext.Instance.VisualizationContainer.CurrentPanel;
            List <VisualizationPanelType> compatiblePanelTypes = VisualizationContext.Instance.VisualizerMap.GetCompatiblePanelTypes(currentPanel);

            foreach (object item in panel.ContextMenu.Items)
            {
                if (item is MenuItem menuItem)
                {
                    // Enable/disable all "visualize in current panel" menuitems based on the current visualization panel in the container
                    if (menuItem.Tag is VisualizerMetadata visualizerMetadata && visualizerMetadata.IsInNewPanel == false)
                    {
                        menuItem.Visibility = compatiblePanelTypes.Contains(visualizerMetadata.VisualizationPanelType) ? Visibility.Visible : Visibility.Collapsed;
                    }
                }
            }
        }
        private HitTestResultBehavior ContextMenuHitTestResult(HitTestResult result)
        {
            // Find the visualization panel view that the mouse is over
            DependencyObject dependencyObject = result.VisualHit;

            while (dependencyObject != null)
            {
                if (dependencyObject is IContextMenuItemsSource contextMenuItemsSource && contextMenuItemsSource.ContextMenuItemsSourceType == ContextMenuItemsSourceType.VisualizationPanel)
                {
                    // Get the visualization panel related to the visualization panel view
                    this.mouseOverVisualizationPanel = (contextMenuItemsSource as VisualizationPanelView).DataContext as VisualizationPanel;
                    return(HitTestResultBehavior.Stop);
                }

                dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
            }

            return(HitTestResultBehavior.Continue);
        }
Esempio n. 6
0
        private int FindPanelMoveIndices(VisualizationPanel droppedPanel, int position, out int currentPanelIndex)
        {
            // Find the index of the panel whose vertical center is closest the panel being dragged's vertical center
            var visualizationContainer = droppedPanel.Container;

            currentPanelIndex = visualizationContainer.Panels.IndexOf(droppedPanel);

            // Look through the shown panels and figure out when we are below the previous vertical center by above
            // the next vertical center
            double previousVerticalCenter = double.NaN;
            double currentLocation        = double.NaN;

            for (int i = 0; i < visualizationContainer.Panels.Count; i++)
            {
                if (visualizationContainer.Panels[i].IsShown)
                {
                    if (double.IsNaN(previousVerticalCenter))
                    {
                        currentLocation = visualizationContainer.Panels[i].Height / 2;
                    }
                    else
                    {
                        currentLocation += visualizationContainer.Panels[i].Height / 2;

                        // Now, if we are after the previous location but before the current one
                        if (position > previousVerticalCenter && position <= currentLocation)
                        {
                            // Then we've found the drop position
                            return(currentPanelIndex < i ? i - 1 : i);
                        }
                    }

                    // Save the previous vertical center
                    previousVerticalCenter = currentLocation;

                    // Increment the position
                    currentLocation += visualizationContainer.Panels[i].Height / 2;
                }
            }

            return(visualizationContainer.Panels.Count - 1);
        }
Esempio n. 7
0
        private void BttnSort_Click(AlgorithmBase <SortedItem> algorithm)
        {
            RefreshItems();

            for (int i = 0; i < algorithm.Items.Count; i++)
            {
                algorithm.Items[i].SetPosition(i);
            }

            VisualizationPanel.Refresh();

            algorithm.CompareEvent += AlgorithmCompareEvent;
            algorithm.SwopEvent    += AlgorithmSwopEvent;
            algorithm.SetEvent     += AlgorithmSetEvent;
            var time = algorithm.Sort();

            TimeLabel.Text        = "Time: " + time.Seconds;
            ComparsionsLabel.Text = "Compare: " + algorithm.ComparsionCount;
            SwopsLabel.Text       = "Swops: " + algorithm.ComparsionCount;
        }
Esempio n. 8
0
        /// <summary>
        /// Called internally by the VisualizationPanel to connect the parent chain.
        /// </summary>
        /// <param name="panel">Panel to connect this visualization object to.</param>
        internal void SetParentPanel(VisualizationPanel panel)
        {
            if (this.panel != null)
            {
                this.OnDisconnect();
                this.navigator.CursorChanged -= this.OnCursorChanged;
                this.panel     = null;
                this.container = null;
                this.navigator = null;
            }

            if (panel != null)
            {
                this.panel     = panel;
                this.container = this.panel.Container;
                this.navigator = this.container.Navigator;
                this.navigator.CursorChanged += this.OnCursorChanged;
                this.OnConnect();
            }
        }
        private void DropStream(DragEventArgs e)
        {
            if (e.Data.GetData(DragDropDataName.StreamTreeNode) is StreamTreeNode streamTreeNode)
            {
                // Get the mouse position
                Point mousePosition = e.GetPosition(this.Items);

                // Get the visualization panel (if any) that the mouse is above
                VisualizationPanel visualizationPanel = this.GetVisualizationPanelUnderMouse(mousePosition);

                // Get the list of commands that are compatible with the user dropping the stream here
                var visualizers = streamTreeNode.GetCompatibleVisualizers(visualizationPanel, isUniversal: false, isInNewPanel: false);

                // If there are compatible visualization commands, select the first one
                if (visualizers.Any())
                {
                    VisualizationContext.Instance.VisualizeStream(streamTreeNode, visualizers.First(), visualizationPanel);
                }
            }
        }
        private void DropStream(DragEventArgs e)
        {
            StreamTreeNode streamTreeNode = e.Data.GetData(DragDropDataName.StreamTreeNode) as StreamTreeNode;

            if (streamTreeNode != null)
            {
                // Get the mouse position
                Point mousePosition = e.GetPosition(this.Items);

                // Get the visualization panel (if any) that the mouse is above
                VisualizationPanel visualizationPanel = this.GetVisualizationPanelUnderMouse(mousePosition);

                // Get the list of commands that are compatible with the user dropping the stream here
                List <VisualizerMetadata> metadatas = this.GetStreamDropCommands(streamTreeNode, visualizationPanel);

                // If there's any compatible visualization commands, execute the first one
                if (metadatas.Count > 0)
                {
                    VisualizationContext.Instance.VisualizeStream(streamTreeNode, metadatas[0], visualizationPanel);
                }
            }
        }
Esempio n. 11
0
        private void AlgorithmSwopEvent(object sender, Tuple <SortedItem, SortedItem> e)
        {
            e.Item1.SetColor(Color.Aqua);
            e.Item2.SetColor(Color.Brown);
            VisualizationPanel.Refresh();

            Thread.Sleep(20);

            var temp = e.Item1.Number;

            e.Item1.SetPosition(e.Item2.Number);
            e.Item2.SetPosition(temp);
            VisualizationPanel.Refresh();

            Thread.Sleep(20);

            e.Item1.SetColor(Color.Blue);
            e.Item2.SetColor(Color.Blue);
            VisualizationPanel.Refresh();

            Thread.Sleep(20);
        }
Esempio n. 12
0
        /// <inheritdoc/>
        public void AppendContextMenuItems(List <MenuItem> menuItems)
        {
            if (this.DataContext is InstantVisualizationContainer instantVisualizationContainer)
            {
                // Find the child panel that the mouse is over
                // Run a hit test at the mouse cursor
                this.mouseOverVisualizationPanel = null;
                VisualTreeHelper.HitTest(
                    this,
                    null,
                    new HitTestResultCallback(this.ContextMenuHitTestResult),
                    new PointHitTestParameters(Mouse.GetPosition(this)));

                if (this.mouseOverVisualizationPanel != null)
                {
                    menuItems.Add(MenuItemHelper.CreateMenuItem(IconSourcePath.InstantContainerAddCellLeft, $"Insert Cell to the Left", instantVisualizationContainer.CreateIncreaseCellCountCommand(this.mouseOverVisualizationPanel, true)));
                    menuItems.Add(MenuItemHelper.CreateMenuItem(IconSourcePath.InstantContainerAddCellRight, $"Insert Cell to the Right", instantVisualizationContainer.CreateIncreaseCellCountCommand(this.mouseOverVisualizationPanel, false)));
                    menuItems.Add(MenuItemHelper.CreateMenuItem(null, $"Remove Cell", instantVisualizationContainer.CreateRemoveCellCommand(this.mouseOverVisualizationPanel)));
                    menuItems.Add(MenuItemHelper.CreateMenuItem(IconSourcePath.InstantContainerRemoveCell, $"Remove {instantVisualizationContainer.Name}", instantVisualizationContainer.RemovePanelCommand));
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Removes the indicated panel.
        /// </summary>
        /// <param name="panel">The panel to be removed from the container.</param>
        public void RemovePanel(VisualizationPanel panel)
        {
            // change the current panel
            if (this.CurrentPanel == panel)
            {
                this.CurrentPanel = null;
            }

            // If the panel being deleted contains the stream currently being snapped to, then reset the snap to stream object
            if ((this.snapToVisualizationObject != null) && panel.VisualizationObjects.Contains(this.snapToVisualizationObject))
            {
                this.SnapToVisualizationObject = null;
            }

            panel.Clear();
            this.Panels.Remove(panel);

            if ((this.CurrentPanel == null) && (this.Panels.Count > 0))
            {
                this.CurrentPanel = this.Panels.Last();
            }
        }
Esempio n. 14
0
        private void Items_Drop(object sender, DragEventArgs e)
        {
            if (e.Handled == false)
            {
                string dragOperation = e.Data.GetData("DragOperation") as string;
                if (dragOperation == "ReorderPanels")
                {
                    // Get the VisualizationPanel that's being dropped
                    VisualizationPanel droppedPanel = e.Data.GetData("VisualizationPanel") as VisualizationPanel;
                    if (droppedPanel != null)
                    {
                        // Find the index of the panel being moved, and the index we should move it to
                        int moveToIndex = this.FindPanelMoveIndices(droppedPanel, this.dragDropAdorner.VerticalCenter, out int moveFromIndex);

                        // Check that we're not just trying to put the panel back where it started
                        if (moveFromIndex != moveToIndex)
                        {
                            droppedPanel.Container.Panels.Move(moveFromIndex, moveToIndex);
                        }

                        // Timeline Visualization Panels have multiple drag & drop operation types, only one of which
                        // can be in effect at any time.  If the panel being dropped is one of those then we need to
                        // signal to it that this drag operation is done.
                        TimelineVisualizationPanelView visualizationPanelView = e.Data.GetData("VisualizationPanelView") as TimelineVisualizationPanelView;
                        if (visualizationPanelView != null)
                        {
                            visualizationPanelView.FinishDragDrop();
                        }
                    }

                    this.dragDropAdorner.Hide();
                    this.Cursor = Cursors.Arrow;
                }

                e.Handled = true;
            }
        }
        private int FindPanelMoveIndices(VisualizationPanel droppedPanel, int panelVerticalCenter, out int currentPanelIndex)
        {
            // Find the index of the panel whose vertical center is closest the panel being dragged's vertical center
            VisualizationContainer visualizationContainer = droppedPanel.Container;

            currentPanelIndex = -1;

            // Work out which Visualization Panel's vertical center is closest to the vertical center of the panel being dropped
            double currentVerticalCenter = 0;
            double minDelta    = double.MaxValue;
            int    targetIndex = -1;

            for (int index = 0; index < visualizationContainer.Panels.Count; index++)
            {
                VisualizationPanel visualizationPanel = visualizationContainer.Panels[index];

                // If this is the panel we're dropping, we need that info too
                if (visualizationPanel == droppedPanel)
                {
                    currentPanelIndex = index;
                }

                // Is this panel's vertical center closer to our panel's vertical center
                currentVerticalCenter += visualizationPanel.Height / 2;
                double deltaY = Math.Abs(panelVerticalCenter - currentVerticalCenter);
                if (deltaY < minDelta)
                {
                    targetIndex = index;
                    minDelta    = deltaY;
                }

                currentVerticalCenter += visualizationPanel.Height / 2;
            }

            return(targetIndex);
        }
Esempio n. 16
0
 private List <VisualizerMetadata> GetStreamDropCommands(Type messageType, VisualizationPanel visualizationPanel)
 {
     // Get all the commands that are applicable to this stream tree node and the panel it was dropped over
     return(VisualizationContext.Instance.VisualizerMap.GetByDataTypeAndPanelAboveSeparator(messageType, visualizationPanel));
 }
        private List <VisualizerMetadata> GetStreamDropCommands(StreamTreeNode streamTreeNode, VisualizationPanel visualizationPanel)
        {
            List <VisualizerMetadata> metadatas = new List <VisualizerMetadata>();

            // Get all the commands that are applicable to this stream tree node and the panel it was dropped over
            Type streamType = VisualizationContext.Instance.GetStreamType(streamTreeNode);

            metadatas = VisualizationContext.Instance.VisualizerMap.GetByDataTypeAndPanelAboveSeparator(streamType, visualizationPanel);

            return(metadatas);
        }
Esempio n. 18
0
        /// <summary>
        /// Gets all the above the separator entries for a given datatype and visualization panel.
        /// </summary>
        /// <param name="dataType">The datatype to search for.</param>
        /// <param name="visualizationPanel">The type of visualization panel to search for.</param>
        /// <returns>A list of visualizer metadata objects.</returns>
        public List <VisualizerMetadata> GetByDataTypeAndPanelAboveSeparator(Type dataType, VisualizationPanel visualizationPanel)
        {
            this.EnsureInitialized();
            List <VisualizerMetadata> results;

            if (visualizationPanel == null)
            {
                // Dropping stream into empty space.  Find the "in new panel" commands that are above the separator and have a compatible data type
                results = this.visualizers.FindAll(e => (dataType == e.DataType || dataType.IsSubclassOf(e.DataType)) && e.IsInNewPanel && e.IsAboveSeparator);
            }
            else
            {
                // Dropping onto a specific panel.  Find the non "in new panel" commands that are above the separator, have a compatible panel type, and compatible data type
                List <VisualizationPanelType> compatiblePanels = this.GetCompatiblePanelTypes(visualizationPanel);
                results = this.visualizers.FindAll(e => (dataType == e.DataType || dataType.IsSubclassOf(e.DataType)) && compatiblePanels.Contains(e.VisualizationPanelType) && !e.IsInNewPanel && e.IsAboveSeparator);
            }

            return(results);
        }