예제 #1
0
        internal void ActivateCanvas(GraphCanvas canvas)
        {
            if (canvas == CurrentGraphCanvas)
            {
                return;
            }

            //canvas
            //this.canvasGrid.Children.Remove(canvas);
            //this.canvasGrid.Children.Add(canvas);
            canvas.graphCanvas.Focus();

            //scale
            GraphVisualHost.sliderScrollHandled = true;// set the slider value and scrollview,
            //no need HandleScrollViewerScrollChanged
            double sliderValue;
            double horizontalOffset;
            double verticalOffset;

            canvas.GetZoomAndPanInfo(out sliderValue, out horizontalOffset, out verticalOffset);
            slider.Value = sliderValue;
            this.scaleTransform.ScaleX = sliderValue;
            this.scaleTransform.ScaleY = sliderValue;
            canvasScrollViewer.ScrollToHorizontalOffset(horizontalOffset);
            canvasScrollViewer.ScrollToVerticalOffset(verticalOffset);

            //record the canvasId
            currentGraphCanvas = graphCanvases.IndexOf(canvas);
        }
예제 #2
0
        private void AddGraphCanvas(GraphCanvas graphCanvas, string canvasName)
        {
            if (graphCanvases.Count == 0)
            {
                this.libraryView.Visibility       = Visibility.Visible;
                this.zoomAndPanControl.Visibility = Visibility.Visible;
            }
            //add canvas
            graphCanvases.Add(graphCanvas);
            canvasGrid.Children.Add(graphCanvas);
            currentGraphCanvas = graphCanvases.Count - 1;

            //add tab
            string tabName = string.Empty;

            if (string.IsNullOrEmpty(canvasName))
            {
                newCanvasCount++;
                tabName = DesignScriptStudio.Graph.Core.Configurations.DefaultName + newCanvasCount.ToString();
            }
            else
            {
                tabName = canvasName;
            }
            tabControl.AddTab(tabName, graphCanvas);

            //reset canvas
            ResetZoomAndPan();

            if (null != this.hostApplication)
            {
                this.hostApplication.GraphActivated((uint)currentGraphCanvas);
            }
        }
예제 #3
0
        public IGraphController GetController(uint identifier)
        {
            if (uint.MaxValue == identifier) // Get the current controller.
            {
                if (null == graphCanvases || (graphCanvases.Count <= 0))
                {
                    return(null);
                }

                GraphCanvas graphCanvas = graphCanvases[currentGraphCanvas];
                if (null == graphCanvas.VisualHost) // When file first loaded.
                {
                    return(null);
                }

                return(graphCanvases[currentGraphCanvas].Controller);
            }

            foreach (GraphCanvas canvas in graphCanvases)
            {
                IGraphController controller = canvas.Controller;
                if (controller.Identifier == identifier)
                {
                    return(controller);
                }
            }

            return(null);
        }
예제 #4
0
 private void NewExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (this.graphCanvases.Count() == 0 || tabControl.CloseTab(tabControl.TabControl.SelectedContent))
     {
         GraphCanvas graphCanvas = new GraphCanvas(this);
         AddGraphCanvas(graphCanvas, null);
     }
 }
예제 #5
0
        internal void UpdateCurrentCanvas(uint identifier)
        {
            GraphCanvas canvas = GetCanvas(identifier);

            if (canvas != null)
            {
                currentGraphCanvas = graphCanvases.IndexOf(canvas);
            }
        }
예제 #6
0
        private void DeleteExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            GraphCanvas graphCanvas = this.CurrentGraphCanvas;

            if (null != graphCanvas)
            {
                graphCanvas.VisualHost.HandleShortcutDelete();
            }
        }
        internal void AddTab(string tabName, GraphCanvas canvas)
        {
            GraphTabItem newTab = new GraphTabItem(this, this.graphControl);

            newTab.Header       = tabName;
            newTab.Canvas       = canvas;
            newTab.IsInEditMode = false;
            tabs.Add(newTab);
            TabControl.SelectedIndex = tabs.Count() - 1;
        }
예제 #8
0
        internal void SnapShotCanvas(uint identifier)
        {
            GraphCanvas canvas = GetCanvas(identifier);

            if (canvas != null)
            {
                canvas.SetZoomAndPanInfo(slider.Value, canvasScrollViewer.HorizontalOffset, canvasScrollViewer.VerticalOffset);
            }

            ResetZoomAndPan();
        }
예제 #9
0
        private void CreateBlankOrRecoveredCanvas(bool recovery)
        {
            GraphCanvas graphCanvas = null;

            if (false != recovery) // We're in recovery mode.
            {
                if (null == filesToRecover || (filesToRecover.Count <= 0))
                {
                    throw new InvalidOperationException("Nothing to recover (A0FFDCB8BBE9)");
                }

                try
                {
                    // We did find some files to recover from...
                    uint   graphId       = filesToRecover.Keys.ElementAt(0);
                    string fileToRecover = filesToRecover[graphId];
                    graphCanvas = new GraphCanvas(this, fileToRecover);
                }
                catch (Exception)
                {
                    // Some problem due to recovery, we can't do much about those
                    // backup files now, so proceed to create the default blank
                    // canvas as per normal. We don't want some backup files to
                    // cause DSS to be not-launchable.
                }
            }

            if (null == graphCanvas) // Just in case recovery failed.
            {
                // Not in recovery mode, create empty.
                graphCanvas = new GraphCanvas(this);
            }

            //create the first canvas
            graphCanvases.Add(graphCanvas);
            currentGraphCanvas = graphCanvases.Count - 1;
            canvasGrid.Children.Add(graphCanvas);
            newCanvasCount++;
            string header = "Graph" + newCanvasCount.ToString();

            tabControl.AddTab(header, graphCanvas);

            canvasScrollViewer.Focusable = false;
            graphCanvas.Focusable        = true;
            graphCanvas.Focus();

            ResetZoomAndPan();
        }
        public CustomTextBox(GraphCanvas newGraphCanvas, bool acceptReturn, SolidColorBrush backgroundColor, String font,
                             FontWeight weight, double fontSize, double maxWidth, double minWidth)
        {
            InitializeComponent();
            this.InternalTextBox.Text = "";
            emptyWidth = this.InternalTextBox.ActualWidth;

            this.Focusable             = true;
            this.IsEnabled             = true;
            TextBoxGrid.Focusable      = true;
            TextBoxGrid.IsEnabled      = true;
            InternalTextBox.Focusable  = true;
            InternalTextBox.IsEnabled  = true;
            InternalTextBox.AcceptsTab = true;

            InternalTextBox.Background    = backgroundColor;
            InternalTextBox.FontFamily    = new FontFamily(font);
            InternalTextBox.FontWeight    = weight;
            InternalTextBox.FontSize      = fontSize;
            InternalTextBox.TextAlignment = TextAlignment.Left;
            if (acceptReturn != true)
            {
                this.InternalTextBox.MaxWidth = 175; //textbox size for 25chars
                InternalTextBox.AcceptsTab    = false;
            }
            else
            {
                this.InternalTextBox.MaxWidth     = 510;
                this.InternalTextBox.TextWrapping = TextWrapping.Wrap;
                this.SelectAll = false;
            }
            if (minWidth > 172)
            {
                minWidth = 172;
            }

            InternalTextBox.AcceptsReturn = acceptReturn;
            InternalTextBox.MinWidth      = minWidth;
            InternalTextBox.Loaded       += new RoutedEventHandler(OnInternalTextBoxLoaded);
            InternalTextBox.TextChanged  += new TextChangedEventHandler(OnInternalTextBoxTextChanged);
            this.graphCanvas    = newGraphCanvas;
            isInNormalTextStage = false;
        }
예제 #11
0
        public CustomTextBox(GraphCanvas newGraphCanvas, bool acceptReturn, SolidColorBrush backgroundColor, String font,
            FontWeight weight, double fontSize, double maxWidth, double minWidth)
        {
            InitializeComponent();
            this.InternalTextBox.Text = "";
            emptyWidth = this.InternalTextBox.ActualWidth;

            this.Focusable = true;
            this.IsEnabled = true;
            TextBoxGrid.Focusable = true;
            TextBoxGrid.IsEnabled = true;
            InternalTextBox.Focusable = true;
            InternalTextBox.IsEnabled = true;
            InternalTextBox.AcceptsTab = true;

            InternalTextBox.Background = backgroundColor;
            InternalTextBox.FontFamily = new FontFamily(font);
            InternalTextBox.FontWeight = weight;
            InternalTextBox.FontSize = fontSize;
            InternalTextBox.TextAlignment = TextAlignment.Left;
            if (acceptReturn != true)
            {
                this.InternalTextBox.MaxWidth = 175; //textbox size for 25chars
                InternalTextBox.AcceptsTab = false;
            }
            else
            {
                this.InternalTextBox.MaxWidth = 510;
                this.InternalTextBox.TextWrapping = TextWrapping.Wrap;
                this.SelectAll = false;
            }
            if (minWidth > 172)
                minWidth = 172;

            InternalTextBox.AcceptsReturn = acceptReturn;
            InternalTextBox.MinWidth = minWidth;
            InternalTextBox.Loaded += new RoutedEventHandler(OnInternalTextBoxLoaded);
            InternalTextBox.TextChanged += new TextChangedEventHandler(OnInternalTextBoxTextChanged);
            this.graphCanvas = newGraphCanvas;
            isInNormalTextStage = false;
        }
예제 #12
0
        private void LoadExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.graphCanvases.Count() == 0 || tabControl.CloseTab(tabControl.TabControl.SelectedContent))
            {
                string fileFilter = "DesignScript Graph Files " +
                                    "(*.bin)|*.bin|All Files (*.*)|*.*";

                // Displays an OpenFileDialog for user to select a file.
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter      = fileFilter;
                openFileDialog.Title       = "Select a DesignScript Graph file";
                openFileDialog.Multiselect = false;

                bool?result = openFileDialog.ShowDialog();
                if (result.HasValue && (result.Value == true))
                {
                    int index = tabControl.FindTab(openFileDialog.FileName);
                    if (index < 0)
                    {
                        GraphCanvas graphCanvas = new GraphCanvas(this, openFileDialog.FileName);
                        AddGraphCanvas(graphCanvas, (new FileInfo(openFileDialog.FileName)).Name);
                    }
                    else
                    {
                        tabControl.TabControl.SelectedIndex = index;
                    }
                }
            }

            if (this.CurrentGraphCanvas != null)
            {
                this.CurrentGraphCanvas.Focus();
            }
            else
            {
                this.MasterGrid.Focus();
            }

            e.Handled = true;
        }
예제 #13
0
        internal void RemoveCanvas(uint identifier)
        {
            // there is another ResetZoomAndPan() in the AddGraphCanvas()
            // to ensure the scroll viewer and slider to be reset properly.
            //
            ResetZoomAndPan();
            GraphCanvas canvas = GetCanvas(identifier);

            canvasGrid.Children.Remove(canvas);
            graphCanvases.Remove(canvas);

            // need to keep the keyboard focus on the Master Grid
            // to enable the command short cut keys
            //
            Keyboard.Focus(this.MasterGrid);

            if (graphCanvases.Count() == 0)
            {
                this.libraryView.Visibility       = Visibility.Collapsed;
                this.zoomAndPanControl.Visibility = Visibility.Collapsed;
                this.FeedbackMsssagePanel.Children.Clear();
                return;
            }
        }
 private void NewExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (this.graphCanvases.Count() == 0 || tabControl.CloseTab(tabControl.TabControl.SelectedContent))
     {
         GraphCanvas graphCanvas = new GraphCanvas(this);
         AddGraphCanvas(graphCanvas, null);
     }
 }
        private void LoadExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.graphCanvases.Count() == 0 || tabControl.CloseTab(tabControl.TabControl.SelectedContent))
            {
                string fileFilter = "DesignScript Graph Files " +
                    "(*.bin)|*.bin|All Files (*.*)|*.*";

                // Displays an OpenFileDialog for user to select a file.
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = fileFilter;
                openFileDialog.Title = "Select a DesignScript Graph file";
                openFileDialog.Multiselect = false;

                bool? result = openFileDialog.ShowDialog();
                if (result.HasValue && (result.Value == true))
                {
                    int index = tabControl.FindTab(openFileDialog.FileName);
                    if (index < 0)
                    {
                        GraphCanvas graphCanvas = new GraphCanvas(this, openFileDialog.FileName);
                        AddGraphCanvas(graphCanvas, (new FileInfo(openFileDialog.FileName)).Name);
                    }
                    else
                        tabControl.TabControl.SelectedIndex = index;
                }
            }

            if (this.CurrentGraphCanvas != null)
                this.CurrentGraphCanvas.Focus();
            else
                this.MasterGrid.Focus();

            e.Handled = true;
        }
예제 #16
0
        private void CreateBlankOrRecoveredCanvas(bool recovery)
        {
            GraphCanvas graphCanvas = null;

            if (false != recovery) // We're in recovery mode.
            {
                if (null == filesToRecover || (filesToRecover.Count <= 0))
                    throw new InvalidOperationException("Nothing to recover (A0FFDCB8BBE9)");

                try
                {
                    // We did find some files to recover from...
                    uint graphId = filesToRecover.Keys.ElementAt(0);
                    string fileToRecover = filesToRecover[graphId];
                    graphCanvas = new GraphCanvas(this, fileToRecover);
                }
                catch (Exception)
                {
                    // Some problem due to recovery, we can't do much about those
                    // backup files now, so proceed to create the default blank
                    // canvas as per normal. We don't want some backup files to
                    // cause DSS to be not-launchable.
                }
            }

            if (null == graphCanvas) // Just in case recovery failed.
            {
                // Not in recovery mode, create empty.
                graphCanvas = new GraphCanvas(this);
            }

            //create the first canvas
            graphCanvases.Add(graphCanvas);
            currentGraphCanvas = graphCanvases.Count - 1;
            canvasGrid.Children.Add(graphCanvas);
            newCanvasCount++;
            string header = "Graph" + newCanvasCount.ToString();
            tabControl.AddTab(header, graphCanvas);

            canvasScrollViewer.Focusable = false;
            graphCanvas.Focusable = true;
            graphCanvas.Focus();

            ResetZoomAndPan();
        }
예제 #17
0
        private void ConvertNodesToCodeExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            GraphCanvas graphCanvas = this.CurrentGraphCanvas;

            graphCanvas.VisualHost.HandleConvertNodesToCode();
        }
예제 #18
0
        internal void ActivateCanvas(GraphCanvas canvas)
        {
            if (canvas == CurrentGraphCanvas)
                return;

            //canvas
            //this.canvasGrid.Children.Remove(canvas);
            //this.canvasGrid.Children.Add(canvas);
            canvas.graphCanvas.Focus();

            //scale
            GraphVisualHost.sliderScrollHandled = true;// set the slider value and scrollview,
            //no need HandleScrollViewerScrollChanged
            double sliderValue;
            double horizontalOffset;
            double verticalOffset;
            canvas.GetZoomAndPanInfo(out sliderValue, out horizontalOffset, out verticalOffset);
            slider.Value = sliderValue;
            this.scaleTransform.ScaleX = sliderValue;
            this.scaleTransform.ScaleY = sliderValue;
            canvasScrollViewer.ScrollToHorizontalOffset(horizontalOffset);
            canvasScrollViewer.ScrollToVerticalOffset(verticalOffset);

            //record the canvasId
            currentGraphCanvas = graphCanvases.IndexOf(canvas);
        }
예제 #19
0
        public GraphVisualHost(GraphCanvas graphCanvas, GraphControl graphControl, string startupFile)
        {
            this.graphCanvas = graphCanvas;
            this.graphControl = graphControl;

            if (children == null)
                children = new VisualCollection(this);

            if (string.IsNullOrEmpty(startupFile))
                this.graphController = ClassFactory.CreateGraphController(this);
            else
            {
                try
                {
                    this.graphController = ClassFactory.CreateGraphController(this, startupFile);
                }
                catch (FileNotFoundException e)
                {
                    MessageBox.Show(string.Format("FileNotFoundException: {0}", e.FileName));
                }
                catch (IOException e)
                {
                    MessageBox.Show(string.Format("IOException: {0}", e.Message));
                }
                catch (InvalidDataException e)
                {
                    MessageBox.Show(string.Format("InvalidDataException: {0}", e.Message));
                }
                catch (FileVersionException e)
                {
                    string message = string.Format(UiStrings.FutureFileVersionFmt, e.RequiredAppVersion);

                    MessageBoxResult result = MessageBoxResult.None;
                    string caption = UiStrings.IncompatibleVersion;
                    result = MessageBox.Show(message, caption, MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                    {
                        System.Diagnostics.Process.Start(CoreStrings.DesignScriptSiteUrl);
                    }
                }
                catch (Exception e)
                {
                    this.graphController = ClassFactory.CreateGraphController(this);
                    this.graphControl.DisplayException(e);
                }
                finally
                {
                    if (null == graphController)
                        this.graphController = ClassFactory.CreateGraphController(this);
                }
            }

            DrawingVisual foregroundVisual = new DrawingVisual();
            edgeVisuals.Add(foregroundVisual, 0);
            this.children.Add(foregroundVisual);

            if (!string.IsNullOrEmpty(startupFile))
                this.ZoomToFit();
        }
예제 #20
0
        private void AddGraphCanvas(GraphCanvas graphCanvas, string canvasName)
        {
            if (graphCanvases.Count == 0)
            {
                this.libraryView.Visibility = Visibility.Visible;
                this.zoomAndPanControl.Visibility = Visibility.Visible;
            }
            //add canvas
            graphCanvases.Add(graphCanvas);
            canvasGrid.Children.Add(graphCanvas);
            currentGraphCanvas = graphCanvases.Count - 1;

            //add tab
            string tabName = string.Empty;
            if (string.IsNullOrEmpty(canvasName))
            {
                newCanvasCount++;
                tabName = DesignScriptStudio.Graph.Core.Configurations.DefaultName + newCanvasCount.ToString();
            }
            else
                tabName = canvasName;
            tabControl.AddTab(tabName, graphCanvas);

            //reset canvas
            ResetZoomAndPan();

            if (null != this.hostApplication)
                this.hostApplication.GraphActivated((uint)currentGraphCanvas);
        }