示例#1
0
 public void CaptureArcFormattingCommandOnExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (arcShape == null)
     {
         if (SelectedAddItem.Contains("Arc"))
         {
             arcShape = (string)Application.Current.Resources[SelectedAddItem];
         }
         else if (windowsMgr.activeGraphCanvas.Selection.SelectedArc != null)
         {
             arcShape = ((DisplayShape)windowsMgr.activeGraphCanvas.Selection.SelectedArc.
                         DisplayShape).String;
         }
         if (arcShape != null)
         {
             var s = (Path)MyXamlHelpers.Parse(arcShape);
             s.RenderTransform      = new MatrixTransform();
             ApplyArcFormatVB.Child = (Shape)MyXamlHelpers.Parse(arcShape);
         }
         txtblkCaptureArcFormat.Text       = "Release Arc Format";
         txtblkCaptureArcFormat.Foreground = Brushes.Red;
         SetSelectedAddItem(0);
     }
     else
     {
         arcShape = null;
         ApplyArcFormatVB.Child            = null;
         txtblkCaptureArcFormat.Text       = "Capture Arc Format";
         txtblkCaptureArcFormat.Foreground = Brushes.Black;
     }
 }
示例#2
0
 internal string XamlWrite()
 {
     return(MyXamlHelpers.XamlOfShape(
                new Path
     {
         Fill = Fill,
         Height = Height,
         HorizontalAlignment = HorizontalAlignment,
         Language = Language,
         LayoutTransform = LayoutTransform,
         Margin = Margin,
         Tag = icon.UpdateTag() + Controller.ToString(),
         Opacity = Opacity,
         RenderSize = RenderSize,
         RenderTransform = RenderTransform,
         RenderTransformOrigin = RenderTransformOrigin,
         SnapsToDevicePixels = SnapsToDevicePixels,
         Stretch = Stretch,
         Stroke = Stroke,
         StrokeDashArray = StrokeDashArray,
         StrokeDashCap = StrokeDashCap,
         StrokeDashOffset = StrokeDashOffset,
         StrokeEndLineCap = StrokeEndLineCap,
         StrokeLineJoin = StrokeLineJoin,
         StrokeMiterLimit = StrokeMiterLimit,
         StrokeStartLineCap = StrokeStartLineCap,
         StrokeThickness = StrokeThickness,
         Visibility = Visibility,
         VerticalAlignment = VerticalAlignment,
         Width = Width,
         Data = DefiningGeometry
     },
                icon.UpdateTag() + Controller.ToString()));
 }
示例#3
0
        public static void UpdateNodeShape(node n)
        {
            string        strShape;
            List <string> shapeData;

            if (n.DisplayShape == null)
            {
                shapeData = new List <string>();
            }
            else
            {
                shapeData
                    = new List <string>(n.DisplayShape.ToString().Split(new[] { ',', '.' }));
            }
            if (shapeData.Count == 0)
            {
                strShape = updateNodeShapeKeyString("");
            }
            else
            {
                strShape = updateNodeShapeKeyString(shapeData[0]);
            }
            if (shapeData.Count > 1)
            {
                MyXamlHelpers.SetValue(ref strShape, "Fill",
                                       BrushSelector.GetColorFromString(shapeData[1]).ToString());
                MyXamlHelpers.SetValue(ref strShape, "Width", shapeData[2]);
                MyXamlHelpers.SetValue(ref strShape, "Height", shapeData[3]);
            }
            MyXamlHelpers.SetValue(ref strShape, "Tag", n.name);
            n.DisplayShape = new DisplayShape(strShape, ShapeRepresents.Node, n);
        }
示例#4
0
        public static void UpdateArcShape(arc a)
        {
            string strShape;
            var    shapeData = new List <string>();

            if (a.DisplayShape != null)
            {
                shapeData = new List <string>(a.DisplayShape.ToString().Split(new[] { ',', '.' }));
            }
            if (shapeData.Count == 0)
            {
                strShape = updateArcShapeKeyString("");
            }
            else
            {
                strShape = updateArcShapeKeyString(shapeData[0]);
            }
            if (shapeData.Count > 1)
            {
                MyXamlHelpers.SetValue(ref strShape, "Stroke",
                                       BrushSelector.GetColorFromString(shapeData[1]).ToString());
                MyXamlHelpers.SetValue(ref strShape, "StrokeThickness", shapeData[2]);
            }
            MyXamlHelpers.SetValue(ref strShape, "Tag", a.name);
            a.DisplayShape = new DisplayShape(strShape, ShapeRepresents.Arc, a);
        }
        public static CanvasProperty DeSerializeFromXML(string xmlString)
        {
            try
            {
                /* to make it load old versions of the CanvasProperties from
                * 1/2009 to 9/2009, we replace Canvas with CanvasProperty */
                xmlString = xmlString.Replace("<Canvas ", "<CanvasProperty ");
                xmlString = xmlString.Replace("</Canvas>", "</CanvasProperty>");
                var context = new ParserContext();
                context.XmlnsDictionary.Add("GraphSynth", "clr-namespace:GraphSynth.UI;assembly=GraphSynth");
                var canvas = (CanvasProperty)MyXamlHelpers.Parse(xmlString, context);

                /***** Notice!: If you have crashed GS2.0 here, then
                 * the try-catch failed. This happens due to a setting
                 * in your Visual Studio environment. To fix this:
                 * 1) Go to Debug->Exceptions.
                 * 2) expand Common Language Runtime Exceptions
                 * 3) Scroll Down to System.Windows.Markup.XamlParseException
                 * 4) uncheck the box in the "Thrown" Column. */

                /* any negative values in CanvasWidth are reset to zero s.t. there are not problems in
                 * re-opening the canvas. */
                canvas.CanvasWidth = new Thickness(Math.Max(0.0, canvas.CanvasWidth.Left),
                                                   Math.Max(0.0, canvas.CanvasWidth.Top),
                                                   Math.Max(0.0, canvas.CanvasWidth.Right),
                                                   Math.Max(0.0, canvas.CanvasWidth.Bottom));
                return(canvas);
            }
            catch
            {
                SearchIO.output("Failed to open Canvas data from file. "
                                + "It is likely non-existent, or in an old format.");
                return(new CanvasProperty());
            }
        }
        private void OpenTemplateFromFile()
        {
            var filename    = "";
            var fileChooser = new OpenFileDialog
            {
                Title            = "Open a canvas template stored in another file.",
                InitialDirectory = GSApp.settings.WorkingDirAbsolute,
                Filter           = "GraphSynth files|*.gxml;*.grxml;*.rsxml|All xml files|*.xml;*.xaml"
            };

            if ((Boolean)fileChooser.ShowDialog())
            {
                filename = fileChooser.FileName;
            }
            if (filename.Length > 0)
            {
                try
                {
                    var    cp  = ((WPFFiler)GSApp.settings.filer).LoadCanvasProperty(XElement.Load(filename));
                    string key = null;
                    if (cp != null)
                    {
                        Value = cp;
                        key   = "from=>" + Path.GetFileNameWithoutExtension(filename);
                        if (!Application.Current.Resources.MergedDictionaries[1].Contains(key))
                        {
                            var xamlString = "<DataTemplate>"
                                             + CanvasProperty.SerializeCanvasToXml(cp) + "</DataTemplate>";

                            var dt = (DataTemplate)MyXamlHelpers.Parse(xamlString);
                            Application.Current.Resources.MergedDictionaries[1].Add(key, dt);
                        }
                    }
                    //}
                    ReadInTemplates(key);
                }
                catch (Exception exc)
                {
                    ErrorLogger.Catch(exc);
                }
            }
        }
示例#7
0
        private Boolean ValidateXAMLBrush(ref string input, out Brush temp)
        {
            try
            {
                temp = (Brush)MyXamlHelpers.Parse(input);

                /***** Notice!: If you have crashed GS2.0 here, then
                 * the try-catch failed. This happens due to a setting
                 * in your Visual Studio environment. To fix this:
                 * 1) Go to Debug->Exceptions.
                 * 2) expand Common Language Runtime Exceptions
                 * 3) Scroll Down to System.Windows.Markup.XamlParseException
                 * 4) uncheck the box in the "Thrown" Column. */
                return(true);
            }
            catch
            {
                temp = Value;
                return(false);
            }
        }
        protected GraphLayoutController()
        {
            PlayIcon =
                (Path)MyXamlHelpers.Parse("<Path Name=\"PlayIcon\" Stroke=\"Black\" Fill=\"Green\" Data=\"M 0 0 V 20 L 20 10 Z\" />");
            PauseIcon =
                (Path)MyXamlHelpers.Parse("<Path Name=\"PauseIcon\" Stroke=\"Black\" Fill=\"DarkRed\" Data=\"M3,0L17,0 20,3 20,17 17,20 3,20 0,17 0,3z\"/>");

            PlayStopButton = new ToggleButton();
            progressBar1   = new ProgressBar();
            stackContent   = new StackPanel
            {
                VerticalAlignment = VerticalAlignment.Center,
                Orientation       = Orientation.Vertical
            };
            txtStatus = new TextBlock
            {
                Margin              = new Thickness(3),
                TextWrapping        = TextWrapping.Wrap,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch,
                Text = "Graph Layout operation in progress."
            };
            keepButton = new Button
            {
                Content = new TextBlock
                {
                    TextWrapping        = TextWrapping.Wrap,
                    TextAlignment       = TextAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Text = "Keep & Close"
                }
            };
            revertButton = new Button
            {
                Content = new TextBlock
                {
                    TextWrapping        = TextWrapping.Wrap,
                    TextAlignment       = TextAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Text = "Revert & Close"
                }
            };

            var midGrid = new Grid();

            midGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto
            });
            midGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(50.0, GridUnitType.Star)
            });
            midGrid.Children.Add(PlayStopButton);
            midGrid.Children.Add(progressBar1);
            Grid.SetColumn(PlayStopButton, 0);
            Grid.SetColumn(progressBar1, 1);

            var btmGrid = new Grid();

            btmGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(500.0, GridUnitType.Star)
            });
            btmGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(50)
            });
            btmGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(50)
            });
            btmGrid.Children.Add(txtStatus);
            btmGrid.Children.Add(keepButton);
            btmGrid.Children.Add(revertButton);
            Grid.SetColumn(txtStatus, 0);
            Grid.SetColumn(keepButton, 1);
            Grid.SetColumn(revertButton, 2);

            WindowStartupLocation = WindowStartupLocation.Manual;
            SizeToContent         = SizeToContent.Height;
            Width   = 400;
            Content = new StackPanel {
                Orientation = Orientation.Vertical
            };
            ((StackPanel)Content).Children.Add(stackContent);
            ((StackPanel)Content).Children.Add(midGrid);
            ((StackPanel)Content).Children.Add(btmGrid);
            PlayStopButton.Checked   += PlayStopButton_Checked;
            PlayStopButton.Unchecked += PlayStopButton_Unchecked;
            revertButton.Click       += revertButton_Click;
            keepButton.Click         += keepButton_Click;
        }
示例#9
0
        public void setUpGraphElementAddButtons()
        {
            var dic = new ResourceDictionary();

            try
            {
                dic.Source = new Uri(GSApp.settings.WorkingDirAbsolute + GSApp.settings.CustomShapesFile,
                                     UriKind.Absolute);
            }
            catch
            {
                SearchIO.output("Custom Shapes File was not found or is invalid.");
            }
            foreach (string k in dic.Keys)
            {
                if (!Application.Current.Resources.Contains(k))
                {
                    Application.Current.Resources.Add(k, XamlWriter.Save(dic[k]));
                }
            }

            var dtNIS    = (DataTemplate)Application.Current.Resources["NodeIconShape"];
            var dtNHS    = (DataTemplate)Application.Current.Resources["HyperArcIconShape"];
            var dtAddBtn = (DataTemplate)Application.Current.Resources["AddButtonTemplate"];

            NodeAddToolbar.Items.Clear();
            ArcAddToolbar.Items.Clear();
            HyperAddToolbar.Items.Clear();
            SelectedAddItems = new List <string>();
            SelectedAddItems.Add("");
            var shortCutKeysList = new List <Key>();

            shortCutKeysList.Add(Key.Escape);
            var temp        = (Button)dtAddBtn.LoadContent();
            var imageLength = temp.Width - 8;

            foreach (object key in Application.Current.Resources.Keys)
            {
                var keyString = key as string;
                try
                {
                    var b     = (Button)dtAddBtn.LoadContent();
                    var s     = (Shape)MyXamlHelpers.Parse((string)Application.Current.Resources[key]);
                    var scStr = "";
                    if (s.Tag != null)
                    {
                        scStr = s.Tag.ToString().Split(new[] { ':' })[0];
                    }
                    var scKey = findShortCut(ref scStr);
                    shortCutKeysList.Add(scKey);
                    SelectedAddItems.Add(keyString);
                    b.Name              = keyString;
                    b.Click            += AddNodeArcButton_Click;
                    b.MouseDoubleClick += AddNodeArcButton_DoubleClick;
                    if (keyString.ToLowerInvariant().Contains("node"))
                    {
                        var NIS     = (Shape)dtNIS.LoadContent();
                        var NISsize = new Size(NIS.Width, NIS.Height);
                        var scale   = imageLength / Math.Max(s.Height, NISsize.Height);
                        s.Height           *= scale;
                        s.Width            *= scale;
                        NIS.Height         *= scale;
                        NIS.Width          *= scale;
                        s.VerticalAlignment = NIS.VerticalAlignment = VerticalAlignment.Top;
                        NIS.Margin          = new Thickness(0, (s.Height - NIS.Height) / 2, 0, 0);
                        b.Tag = scKey;
                        for (var i = 0; i <= NodeAddToolbar.Items.Count; i++)
                        {
                            if (i == NodeAddToolbar.Items.Count)
                            {
                                NodeAddToolbar.Items.Add(b);
                                break;
                            }
                            else if ((int)scKey < (int)((Key)((Button)NodeAddToolbar.Items[i]).Tag))
                            {
                                NodeAddToolbar.Items.Insert(i, b);
                                break;
                            }
                        }
                        ((TextBlock)((Grid)b.Content).Children[0]).Text = scStr;
                        ((TextBlock)((Grid)b.Content).Children[1]).Text = keyString;
                        ((Grid)b.Content).Children.Insert(0, s);
                        ((Grid)b.Content).Children.Insert(1, NIS);
                    }
                    else if (keyString.ToLowerInvariant().Contains("arc"))
                    {
                        ((TextBlock)((Grid)b.Content).Children[0]).Text = scStr;
                        ((TextBlock)((Grid)b.Content).Children[1]).Text = keyString;
                        s.VerticalAlignment = VerticalAlignment.Top;
                        Grid.SetRow(s, 0);
                        ((Grid)b.Content).Children.Add(s);
                        if (s as Path != null)
                        {
                            var pathGeo = ((Path)s).Data;
                            if (pathGeo.IsFrozen)
                            {
                                pathGeo = pathGeo.Clone();
                            }
                            var scale = imageLength /
                                        Math.Max(pathGeo.Bounds.Height, pathGeo.Bounds.Width);
                            pathGeo.Transform = new ScaleTransform(scale, scale);
                        }
                        else
                        {
                            s.Height = s.Width = imageLength;
                        }
                        b.Tag = scKey;
                        for (var i = 0; i <= ArcAddToolbar.Items.Count; i++)
                        {
                            if (i == ArcAddToolbar.Items.Count)
                            {
                                ArcAddToolbar.Items.Add(b);
                                break;
                            }
                            else if ((int)scKey < (int)((Key)((Button)ArcAddToolbar.Items[i]).Tag))
                            {
                                ArcAddToolbar.Items.Insert(i, b);
                                break;
                            }
                        }
                    }
                    else if (keyString.ToLowerInvariant().Contains("hyper"))
                    {
                        ((TextBlock)((Grid)b.Content).Children[0]).Text = scStr;
                        ((TextBlock)((Grid)b.Content).Children[1]).Text = keyString;
                        s.VerticalAlignment = VerticalAlignment.Top;
                        Grid.SetRow(s, 0);
                        ((Grid)b.Content).Children.Add(s);
                        if (s as Path != null)
                        {
                            var pathGeo = ((Path)s).Data;
                            if (pathGeo.IsFrozen)
                            {
                                pathGeo = pathGeo.Clone();
                            }
                            var scale = imageLength /
                                        Math.Max(pathGeo.Bounds.Height, pathGeo.Bounds.Width);
                            pathGeo.Transform = new ScaleTransform(scale, scale);
                        }
                        else
                        {
                            s.Height = s.Width = imageLength;
                        }
                        b.Tag = scKey;
                        for (var i = 0; i <= HyperAddToolbar.Items.Count; i++)
                        {
                            if (i == HyperAddToolbar.Items.Count)
                            {
                                HyperAddToolbar.Items.Add(b);
                                break;
                            }
                            else if ((int)scKey < (int)((Key)((Button)HyperAddToolbar.Items[i]).Tag))
                            {
                                HyperAddToolbar.Items.Insert(i, b);
                                break;
                            }
                        }
                    }
                }
                catch
                {
                    SearchIO.output(keyString + " did not load correctly");
                }
            }
            shortCutKeys = shortCutKeysList.Select(k => k.ToString()).ToArray();
        }