Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Container CreateGridTemplate(Project project, string name)
        {
            var container = GetTemplate(project, name);

            CreateGrid(project, container);

            return container;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Container GetTemplate(Project project, string name)
        {
            var container = Container.Create(name);

            container.IsTemplate = true;
            container.Background = ArgbColor.Create(0xFF, 0xFF, 0xFF, 0xFF);

            foreach (var layer in container.Layers)
            {
                layer.Name = string.Concat("Template", layer.Name);
            }

            return container;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="project"></param>
 /// <param name="container"></param>
 private void CreateGrid(Project project, Container container)
 {
     var style = project
         .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
         .Styles.FirstOrDefault(s => s.Name == "Grid");
     var layer = container.Layers.FirstOrDefault();
     var builder = layer.Shapes.ToBuilder();
     var grid = XRectangle.Create(
         0, 0,
         container.Width, container.Height,
         style,
         project.Options.PointShape);
     grid.IsStroked = false;
     grid.IsFilled = false;
     grid.IsGrid = true;
     grid.OffsetX = 30.0;
     grid.OffsetY = 30.0;
     grid.CellWidth = 30.0;
     grid.CellHeight = 30.0;
     grid.State.Flags &= ~ShapeStateFlags.Printable;
     builder.Add(grid);
     layer.Shapes = builder.ToImmutable();
 }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Container GetContainer(Project project, string name)
        {
            var container = Container.Create(name);

            if (project.CurrentTemplate == null)
            {
                var template = GetTemplate(project, "Empty");
                var templateBuilder = project.Templates.ToBuilder();
                templateBuilder.Add(template);
                project.Templates = templateBuilder.ToImmutable();
                project.CurrentTemplate = template;
            }

            container.Template = project.CurrentTemplate;
            container.Width = container.Template.Width;
            container.Height = container.Template.Height;
            return container;
        }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="project"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public Document GetDocument(Project project, string name)
 {
     var document = Document.Create(name);
     return document;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="project"></param>
 /// <param name="serializer"></param>
 /// <returns></returns>
 public static void Save(string path, Project project, ISerializer serializer)
 {
     using (var stream = new FileStream(path, FileMode.Create))
     {
         Save(stream, project, serializer);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="project"></param>
        /// <param name="serializer"></param>
        public static void Save(Stream stream, Project project, ISerializer serializer)
        {
            using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                // First step is to write project entry.
                var jsonEntry = archive.CreateEntry(ProjectEntryName);
                using (var jsonStream = jsonEntry.Open())
                {
                    var json = serializer.Serialize(project);
                    WriteUtf8Text(jsonStream, json);
                }

                // Second step is to write (if any) project images.
                var keys = Editor.GetAllShapes<XImage>(project).Select(i => i.Path).Distinct();
                foreach (var key in keys)
                {
                    var bytes = project.GetImage(key);
                    if (bytes != null)
                    {
                        var imageEntry = archive.CreateEntry(key);
                        using (var imageStream = imageEntry.Open())
                        {
                            WriteBinary(imageStream, bytes);
                        }
                    }
                }

                // NOTE: Purge deleted images from memory is not called here to enable Undo/Redo.
                //project.PurgeUnusedImages(new HashSet<string>(keys));
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static Project Create(string name = "Project")
 {
     var p = new Project()
     {
         Name = name,
         Options = Options.Create(),
         Databases = ImmutableArray.Create<Database>(),
         StyleLibraries = ImmutableArray.Create<StyleLibrary>(),
         GroupLibraries = ImmutableArray.Create<GroupLibrary>(),
         Templates = ImmutableArray.Create<Container>(),
         Documents = ImmutableArray.Create<Document>(),
     };
     return p;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Container CreateBoundingTemplate(Project project, string name)
        {
            var container = GetTemplate(project, name);

            CreateBoundingBox(project, container);

            return container;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="container"></param>
        private void CreateBoundingBox(Project project, Container container)
        {
            var layer = container.Layers.FirstOrDefault();
            var builder = layer.Shapes.ToBuilder();
            var style = project
                .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
                .Styles.FirstOrDefault(s => s.Name == "Grid");
            var grid = XRectangle.Create(
                0, 0,
                container.Width, container.Height,
                style,
                project.Options.PointShape);
            grid.IsStroked = false;
            grid.IsFilled = false;
            grid.IsGrid = true;
            grid.OffsetX = 30.0;
            grid.OffsetY = 30.0;
            grid.CellWidth = 30.0;
            grid.CellHeight = 30.0;
            grid.State.Flags &= ~ShapeStateFlags.Printable;
            //builder.Add(grid);

            var defaultext = XText.Create(
                container.Width / 2, 10,
                container.Width / 2, 20,
                style,
                project.Options.PointShape,
                "3D Template 4.5 Single Scale");
            defaultext.Style.TextStyle.FontSize = 14;
            defaultext.Style.TextStyle.FontStyle.Flags = FontStyleFlags.Italic;
            defaultext.State.Flags &= ~ShapeStateFlags.Printable;
            //defaultext.Style.Stroke = ArgbColor.Create(0xFF, 0x33, 0x99, 0xff);
            defaultext.Style.TextStyle.FontName = "Swis721 BT";
            builder.Add(defaultext);

            style = project
                .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
                .Styles.FirstOrDefault(s => s.Name == "Text");
            var tr = XLine.Create(
                container.Width / 2 + 340.1568F - 45F, container.Height / 2 - 207.8688F,
                container.Width / 2 + 340.1568F + 45F, container.Height / 2 - 207.8688F,
                style,
                project.Options.PointShape);
            builder.Add(tr);
            var tr2 = XLine.Create(
                container.Width / 2 + 340.1568F, container.Height / 2 - 207.8688F - 45F,
                container.Width / 2 + 340.1568F, container.Height / 2 - 207.8688F + 45F,
                style,
                project.Options.PointShape);
            builder.Add(tr2);
            var tr3 = XEllipse.Create(
                container.Width / 2 + 340.1568F - 25F, container.Height / 2 - 207.8688F - 25F,
                container.Width / 2 + 340.1568F + 25F, container.Height / 2 - 207.8688F + 25F,
                style,
                project.Options.PointShape);
            builder.Add(tr3);

            var br = XLine.Create(
                container.Width / 2 - 340.1568F - 45F, container.Height / 2 + 207.8688F,
                container.Width / 2 - 340.1568F + 45F, container.Height / 2 + 207.8688F,
                style,
                project.Options.PointShape);
            builder.Add(br);
            var br2 = XLine.Create(
                container.Width / 2 - 340.1568F, container.Height / 2 + 207.8688F - 45F,
                container.Width / 2 - 340.1568F, container.Height / 2 + 207.8688F + 45F,
                style,
                project.Options.PointShape);
            builder.Add(br2);
            var br3 = XEllipse.Create(
                container.Width / 2 - 340.1568F - 25F, container.Height / 2 + 207.8688F - 25F,
                container.Width / 2 - 340.1568F + 25F, container.Height / 2 + 207.8688F + 25F,
                style,
                project.Options.PointShape);
            builder.Add(br3);

            style = project
                .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
                .Styles.FirstOrDefault(s => s.Name == "Grid");
            var cr = XLine.Create(
                container.Width / 2 - 6.8736F, container.Height / 2,
                container.Width / 2 + 6.8736F, container.Height / 2,
                style,
                project.Options.PointShape);
            cr.State.Flags &= ~ShapeStateFlags.Printable;
            builder.Add(cr);
            var cr2 = XLine.Create(
                container.Width / 2, container.Height / 2 - 6.8736F,
                container.Width / 2, container.Height / 2 + 6.8736F,
                style,
                project.Options.PointShape);
            cr2.State.Flags &= ~ShapeStateFlags.Printable;
            builder.Add(cr2);
            var cr3 = XEllipse.Create(
                container.Width / 2 - 204.096F - 9.4464F, container.Height / 2 - 204.096F - 9.4464F,
                container.Width / 2 + 204.096F + 9.4464F, container.Height / 2 + 204.096F + 9.4464F,
                style,
                project.Options.PointShape);
            cr3.State.Flags &= ~ShapeStateFlags.Printable;
            builder.Add(cr3);

            var cr4 = XEllipse.Create(
            container.Width / 2 - 9.4464F, container.Height / 2 - 9.4464F,
            container.Width / 2 + 9.4464F, container.Height / 2 + 9.4464F,
            style,
            project.Options.PointShape);
            cr4.State.Flags &= ~ShapeStateFlags.Printable;
            builder.Add(cr4);

            style = project
                .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
                .Styles.FirstOrDefault(s => s.Name == "BoundingBox");
            var boundingbox = XRectangle.Create(
                0, 0,
                container.Width, container.Height,
                style,
                project.Options.PointShape);
            boundingbox.IsStroked = true;
            boundingbox.IsFilled = false;
            boundingbox.IsGrid = true;
            boundingbox.OffsetX = 0;
            boundingbox.OffsetY = 0;
            boundingbox.CellWidth = container.Width;
            boundingbox.CellHeight = container.Height;
            boundingbox.State.Flags &= ~ShapeStateFlags.Printable;
            builder.Add(boundingbox);

            layer.Shapes = builder.ToImmutable();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Container GetTemplate(Project project, string name)
        {
            // A5	420 x 595	559 x 794	874 x 1240	1748 x 2480
            var container = Container.Create(name, 794, 559);

            container.IsTemplate = true;
            container.Background = ArgbColor.Create(0xFF, 0xFF, 0xFF, 0xFF);

            foreach (var layer in container.Layers)
            {
                layer.Name = string.Concat("Template", layer.Name);
            }

            return container;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        public void Remove(Project project)
        {
            if (project == null)
                return;

            project.PropertyChanged -= ProjectObserver;

            Verbose("Remove Project: " + project.Name);

            Remove(project.Options);

            if (project.Databases != null)
            {
                foreach (var database in project.Databases)
                {
                    Remove(database);
                }
            }

            if (project.Documents != null)
            {
                foreach (var document in project.Documents)
                {
                    Remove(document);
                }
            }

            if (project.Templates != null)
            {
                foreach (var template in project.Templates)
                {
                    Remove(template);
                }
            }

            if (project.StyleLibraries != null)
            {
                foreach (var sg in project.StyleLibraries)
                {
                    Remove(sg);
                }
            }
        }