Esempio n. 1
0
 public void RemoveDrawing(XProjectDrawing pDrawing)
 {
     if (Drawings.Contains(pDrawing))
     {
         pDrawing.CloseDrawing();
         Drawings.Remove(pDrawing);
     }
 }
Esempio n. 2
0
        private void OpenDrawing(XProjectDrawing pDrawing)
        {
            TabItem ti = null;

            foreach (TabItem ti_ in tab.Items)
            {
                if (ti_.DataContext == pDrawing)
                {
                    ti = ti_;
                    break;
                }
            }

            if (ti == null)
            {
                ti             = new TabItem();
                ti.DataContext = pDrawing;

                var sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                var tb = new TextBlock();
                tb.VerticalAlignment = VerticalAlignment.Center;
                BindingOperations.SetBinding(tb, TextBlock.TextProperty, new Binding("DrawingName"));
                sp.Children.Add(tb);
                var cb  = new Button();
                var img = new Image();
                img.Source = FindResource("CloseImage") as ImageSource;
                cb.Content = img;
                cb.Click  += CloseTab_Click;
                cb.Width   = 16;
                cb.Height  = 16;
                cb.Margin  = new Thickness(5, 0, 0, 0);
                cb.Style   = FindResource(ToolBar.ButtonStyleKey) as Style;
                sp.Children.Add(cb);
                ti.Header = sp;

                var scrollViewer = new ScrollViewer();
                scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
                scrollViewer.Background = new SolidColorBrush(Colors.Gray);

                var canvas = new Canvas();

                scrollViewer.Content = canvas;
                ti.Content           = scrollViewer;

                var drawing = pDrawing.GetDrawing(canvas);
                DependencyPropertyDescriptor.FromProperty(XDrawing.ModeProperty, typeof(XDrawing)).AddValueChanged(drawing, DrawingModeChanged);
                tab.Items.Add(ti);
            }
            tab.SelectedItem = ti;
            CheckModeButton();
        }
Esempio n. 3
0
 private void CopyDrawing_Click(object sender, RoutedEventArgs e)
 {
     if (m_Project != null)
     {
         var pDrawing = projectTree.SelectedItem as XProjectDrawing;
         if (pDrawing != null)
         {
             var newDrawing = new XProjectDrawing();
             newDrawing.DrawingName  = String.Format("copy of {0}", pDrawing.DrawingName);
             newDrawing.ExportFormat = pDrawing.ExportFormat;
             newDrawing.DrawingSize  = pDrawing.DrawingSize;
             pDrawing.StoreXmlCode();
             newDrawing.XmlCode = new XElement(pDrawing.XmlCode);
             m_Project.Drawings.Add(newDrawing);
             projectTree.SelectObject(newDrawing);
             OpenDrawing(newDrawing);
         }
     }
 }
Esempio n. 4
0
        private void AddDrawing_Click(object sender, RoutedEventArgs e)
        {
            if (m_Project != null)
            {
                var pDrawing = new XProjectDrawing();

                int n    = 0;
                var name = "newDrawing";
                while (GetDrawing(name) != null)
                {
                    name = String.Format("newDrawing_{0}", ++n);
                }
                pDrawing.DrawingName  = name;
                pDrawing.ExportFormat = m_Project.DefaultExportFormat;
                m_Project.Drawings.Add(pDrawing);
                projectTree.ExpandObject(m_Project);
                projectTree.SelectObject(pDrawing);
                OpenDrawing(pDrawing);
            }
        }
Esempio n. 5
0
        public void Load(string path)
        {
            ProjectFilePath = path;

            var doc  = XDocument.Load(ProjectFilePath);
            var xPrj = new
            {
                Version             = (string)doc.Root.Elements("FileVersion").FirstOrDefault(),
                ProjectName         = (string)doc.Root.Elements("ProjectName").FirstOrDefault(),
                DefaultExportFormat = (string)doc.Root.Elements("DefaultExportFormat").FirstOrDefault(),
                XAMLFilePath        = (string)doc.Root.Elements("XAMLFilePath").FirstOrDefault(),
                Drawings            = from d in doc.Root.Descendants("Drawing")
                                      select new
                {
                    DrawingName     = (string)d.Attributes("Name").FirstOrDefault(),
                    ExportFormat    = (string)d.Elements("ExportFormat").FirstOrDefault(),
                    DrawingSize     = (string)d.Elements("DrawingSize").FirstOrDefault(),
                    SaveDrawingSize = (string)d.Elements("SaveDrawingSize").FirstOrDefault()
                }
            };

            ProjectName = xPrj.ProjectName ?? String.Empty;
            if (xPrj.DefaultExportFormat != null)
            {
                DefaultExportFormat = (XDrawingExportFormat)Enum.Parse(typeof(XDrawingExportFormat), xPrj.DefaultExportFormat);
            }
            XAMLFilePath = xPrj.XAMLFilePath ?? String.Empty;

            foreach (var d in xPrj.Drawings)
            {
                var drawing = new XProjectDrawing();
                drawing.DrawingName = d.DrawingName ?? String.Empty;
                if (d.ExportFormat != null)
                {
                    drawing.ExportFormat = (XDrawingExportFormat)Enum.Parse(typeof(XDrawingExportFormat), d.ExportFormat);
                }
                else
                {
                    drawing.ExportFormat = DefaultExportFormat;
                }
                if (d.DrawingSize != null)
                {
                    drawing.DrawingSize = Size.Parse(d.DrawingSize);
                }
                if (d.SaveDrawingSize != null)
                {
                    drawing.SaveDrawingSize = Boolean.Parse(d.SaveDrawingSize);
                }
                Drawings.Add(drawing);
            }

            var xamlPath = XAMLFilePath;

            if (!Path.IsPathRooted(xamlPath))
            {
                xamlPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProjectFilePath), xamlPath));
            }
            if (File.Exists(xamlPath))
            {
                var xamlDoc = XDocument.Load(xamlPath);

                XNamespace nsx = "http://schemas.microsoft.com/winfx/2006/xaml";

                var xDrawings = from d in xamlDoc.Root.Elements()
                                where d.Name.LocalName == "Canvas" || d.Name.LocalName == "DrawingImage"
                                select new
                {
                    XmlCode = d,
                    Key     = d.Attribute(nsx + "Key").Value
                };

                foreach (var d in xDrawings)
                {
                    var drawing = GetDrawing(d.Key);
                    if (drawing == null)
                    {
                        drawing              = new XProjectDrawing();
                        drawing.DrawingName  = d.Key;
                        drawing.ExportFormat = d.XmlCode.Name.LocalName == "Canvas" ? XDrawingExportFormat.Canvas : XDrawingExportFormat.DrawingImage;
                        Drawings.Add(drawing);
                    }
                    drawing.XmlCode = new XElement(d.XmlCode);
                    foreach (var xe in drawing.XmlCode.DescendantsAndSelf())
                    {
                        xe.Name = xe.Name.LocalName;
                    }
                    drawing.XmlCode.RemoveAttributes();
                }
            }
        }