コード例 #1
0
        private void createNewDiagram(Canvas canvas, string tabName)
        {
            if (canvas == null)
            {
                canvas = new ScrollableCanvas();
            }

            ClosableTabItem theTabItem   = new ClosableTabItem();
            ScrollViewer    scrollViewer = new ScrollViewer();

            canvas.Background            = Brushes.Transparent;
            canvas.MouseDown            += OnMouseDown;
            canvas.MouseLeftButtonDown  += Canvas_MouseLeftButtonDown;
            canvas.MouseRightButtonDown += Canvas_MouseRightButtonDown;

            scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Visible;
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
            scrollViewer.Content = canvas;

            theTabItem.IsSelected = true;
            theTabItem.Content    = scrollViewer;
            theTabItem.Title      = tabName;
            tabs.Items.Add(theTabItem);
            tabs.SelectionChanged += TabControl_SelectionChanged;

            attachContextMenu(canvas);

            currentCanvas = canvas;
        }
コード例 #2
0
        public void Shape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Mouse.Capture(null);
            captured = false;
            //Сюда необходимо вставить персчет размер канваса для увелечения скрола или наоборот
            //ModelChanged();
            //currentCanvas.UpdateLayout();

            ScrollableCanvas scCanvas = currentCanvas as ScrollableCanvas;

            double bottomMost = 0d;
            double rightMost  = 0d;

            foreach (object obj in scCanvas.Children)
            {
                FrameworkElement child = obj as FrameworkElement;

                if (child != null)
                {
                    child.Measure(new Size(10, 10));
                    bottomMost = Math.Max(bottomMost, VisualTreeHelper.GetOffset(child).Y + child.DesiredSize.Height);
                    rightMost  = Math.Max(rightMost, VisualTreeHelper.GetOffset(child).X + child.DesiredSize.Width);
                }
            }

            //currentCanvas.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            currentCanvas.RenderSize = new Size(rightMost, bottomMost);
            scCanvas.RenderSize      = new Size(rightMost, bottomMost);
            ModelChanged();
            currentCanvas.UpdateLayout();
        }
コード例 #3
0
 private void OnMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (currentEntity != null && e.LeftButton == MouseButtonState.Pressed)
     {
         if (currentEntity is ConnectionLine && selected != null && selected is Port)
         {
             connect();
         }
         else if (currentEntity is SubDiagram)
         {
             SubDiagram       sd = currentEntity as SubDiagram;
             ScrollableCanvas sc = currentCanvas as ScrollableCanvas;
             if (sc.Equals(sc, sd.ProjectItem.Canvas as ScrollableCanvas))
             {
                 currentEntity = null;
                 MessageBox.Show("Нельзя добавить процесс к самому себе");
             }
             else
             {
                 UndoRedoManager.putInUndoStack((ScrollableCanvas)currentCanvas);
                 UndoRedoManager.clearRedoStack((ScrollableCanvas)currentCanvas);
                 sd.canvas = currentCanvas;
                 drawOnCanvas(e.GetPosition(this));
             }
         }
         else if (!(currentEntity is ConnectionLine))
         {
             UndoRedoManager.putInUndoStack((ScrollableCanvas)currentCanvas);
             UndoRedoManager.clearRedoStack((ScrollableCanvas)currentCanvas);
             drawOnCanvas(e.GetPosition(this));
         }
     }
 }
コード例 #4
0
        private void RedoComand(object sender, ExecutedRoutedEventArgs e)
        {
            ScrollableCanvas canvas      = (ScrollableCanvas)currentCanvas;
            Project          instance    = Project.Instance;
            ProjectItem      projectItem = instance.byCanvas((ScrollableCanvas)canvas);

            ScrollableCanvas storedCanvas = UndoRedoManager.redoProceed(canvas.id);

            if (storedCanvas != null)
            {
                UndoRedoManager.putInUndoStack((ScrollableCanvas)currentCanvas);

                // Simple changing canvas dosen't work
                // Elements can't be children in two canvas, so we have to store it and clear stored canvas
                // Also we need to change canvas in elements
                List <UIElement> elements = new List <UIElement>();

                foreach (UIElement elem in storedCanvas.Children)
                {
                    elements.Add(elem);
                }

                storedCanvas.Children.Clear();
                currentCanvas.Children.Clear();

                foreach (UIElement elem in elements)
                {
                    ((UIEntity)elem).canvas = currentCanvas;
                    currentCanvas.Children.Add(elem);
                }
            }
        }
コード例 #5
0
ファイル: UndoRedoManager.cs プロジェクト: Sonic58/SAPR-SIM
        public static void clearRedoStack(ScrollableCanvas scrollableCanvas)
        {
            long id = scrollableCanvas.id;

            if (redoStack.ContainsKey(id))
            {
                redoStack[id].Clear();
            }
        }
コード例 #6
0
ファイル: ToolBarEvents.cs プロジェクト: Sonic58/SAPR-SIM
 private ClosableTabItem findTabItem(ProjectItem item)
 {
     foreach (ClosableTabItem ti in tabs.Items)
     {
         ScrollableCanvas sc = (ti.Content as ScrollViewer).Content as ScrollableCanvas;
         ProjectItem      pi = Project.Instance.byCanvas(sc);
         if (pi.Equals(item))
         {
             return(ti);
         }
     }
     return(null);
 }
コード例 #7
0
ファイル: ProjectItem.cs プロジェクト: Sonic58/SAPR-SIM
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (obj.GetType() != typeof(ProjectItem))
            {
                return(false);
            }

            ProjectItem another = obj as ProjectItem;

            // C#...
            ScrollableCanvas thisCanvas    = canvas as ScrollableCanvas;
            ScrollableCanvas anotherCanvas = another.Canvas as ScrollableCanvas;

            return(thisCanvas.Equals(thisCanvas, anotherCanvas));
        }
コード例 #8
0
ファイル: UndoRedoManager.cs プロジェクト: Sonic58/SAPR-SIM
        private static void putInStack(ScrollableCanvas scrollableCanvas, Dictionary <long, FixedSizedStack <byte[]> > stack)
        {
            long id = scrollableCanvas.id;

            Stream stream = new MemoryStream();

            new BinaryFormatter().Serialize(stream, scrollableCanvas);

            if (stack.ContainsKey(id))
            {
                FixedSizedStack <byte[]> fsq = stack[id];
                fsq.Push(StreamUtils.ReadFromStream(stream));
            }
            else
            {
                FixedSizedStack <byte[]> fsq = new FixedSizedStack <byte[]>();
                fsq.Push(StreamUtils.ReadFromStream(stream));
                stack.Add(id, fsq);
            }
        }
コード例 #9
0
ファイル: UndoRedoManager.cs プロジェクト: Sonic58/SAPR-SIM
        public static void clearRedoStack(UIEntity selected)
        {
            ScrollableCanvas canvas = (ScrollableCanvas)selected.canvas;

            clearRedoStack(canvas);
        }
コード例 #10
0
ファイル: UndoRedoManager.cs プロジェクト: Sonic58/SAPR-SIM
 public static void putInRedoStack(ScrollableCanvas scrollableCanvas)
 {
     putInStack(scrollableCanvas, redoStack);
 }
コード例 #11
0
ファイル: UndoRedoManager.cs プロジェクト: Sonic58/SAPR-SIM
        public static void putInUndoStack(UIEntity selected)
        {
            ScrollableCanvas canvas = (ScrollableCanvas)selected.canvas;

            putInUndoStack(canvas);
        }
コード例 #12
0
ファイル: Project.cs プロジェクト: Sonic58/SAPR-SIM
 public ProjectItem byCanvas(ScrollableCanvas canvas)
 {
     return(items.Where(i => canvas.Equals(i.Canvas as ScrollableCanvas, canvas)).First());
 }