/// <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();
 }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <param name="p"></param>
        /// <param name="treshold"></param>
        /// <returns></returns>
        public static BaseShape HitTest(Container container, Vector2 p, double treshold)
        {
            var result = HitTest(container.CurrentLayer.Shapes.Reverse(), p, treshold, 0, 0);
            if (result != null)
            {
                return result;
            }

            return null;
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <param name="rect"></param>
        /// <param name="treshold"></param>
        /// <returns></returns>
        public static ImmutableHashSet<BaseShape> HitTest(Container container, Rect2 rect, double treshold)
        {
            var builder = ImmutableHashSet.CreateBuilder<BaseShape>();

            var selection = new Vector2[]
            {
                new Vector2(rect.X, rect.Y),
                new Vector2(rect.X + rect.Width, rect.Y),
                new Vector2(rect.X + rect.Width, rect.Y + rect.Height),
                new Vector2(rect.X, rect.Y + rect.Height)
            };

            HitTest(container.CurrentLayer.Shapes.Reverse(), rect, selection, builder, treshold, 0, 0);

            return builder.ToImmutableHashSet();
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        public void Add(Container container)
        {
            if (container == null)
                return;

            container.PropertyChanged += ContainerObserver;

            if (container.Background != null)
            {
                container.Background.PropertyChanged += ContainerBackgroudObserver;
            }

            Verbose("Add Container: " + container.Name);

            if (container.Layers != null)
            {
                Add(container.Layers);
            }

            if (container.Properties != null)
            {
                Add(container.Properties);
            }

            //Add(container.WorkingLayer);
        }
Example #5
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();
        }
Example #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="container"></param>
 /// <param name="db"></param>
 /// <param name="r"></param>
 public void Draw(object gfx, Container container, ImmutableArray<ShapeProperty> db, Record r)
 {
     foreach (var layer in container.Layers)
     {
         if (layer.IsVisible)
         {
             Draw(gfx, layer, db, r);
         }
     }
 }
Example #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="container"></param>
 private void DrawBackgroundInternal(Graphics gfx, Container container)
 {
     Brush brush = ToSolidBrush(container.Background);
     var rect = Rect2.Create(0, 0, container.Width, container.Height);
     gfx.FillRectangle(
         brush,
         _scaleToPage(rect.X),
         _scaleToPage(rect.Y),
         _scaleToPage(rect.Width),
         _scaleToPage(rect.Height));
     brush.Dispose();
 }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="container"></param>
 /// <param name="ic"></param>
 public void Save(string path, Container container, IImageCache ic)
 {
     using (var bitmap = new Bitmap((int)container.Width, (int)container.Height))
     {
         using (var ms = MakeMetafileStream(bitmap, container, ic))
         {
             using (var fs = File.Create(path))
             {
                 ms.WriteTo(fs);
             }
         }
     }
 }
Example #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="container"></param>
 /// <param name="ic"></param>
 public void SetClipboard(Container container, IImageCache ic)
 {
     try
     {
         using (var bitmap = new Bitmap((int)container.Width, (int)container.Height))
         {
             using (var ms = MakeMetafileStream(bitmap, container, ic))
             {
                 var data = new WPF.DataObject();
                 data.SetData(WPF.DataFormats.EnhancedMetafile, ms);
                 WPF.Clipboard.SetDataObject(data, true);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.Print(ex.Message);
         Debug.Print(ex.StackTrace);
     }
 }
Example #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="container"></param>
        /// <param name="ic"></param>
        /// <returns></returns>
        public MemoryStream MakeMetafileStream(
            Bitmap bitmap,
            Container container,
            IImageCache ic)
        {
            var g = default(Graphics);
            var mf = default(Metafile);
            var ms = new MemoryStream();

            try
            {
                using (g = Graphics.FromImage(bitmap))
                {
                    var hdc = g.GetHdc();
                    mf = new Metafile(ms, hdc);
                    g.ReleaseHdc(hdc);
                }

                using (g = Graphics.FromImage(mf))
                {
                    var r = new EmfRenderer(72.0 / 96.0);
                    r.State.ImageCache = ic;

                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    g.PageUnit = GraphicsUnit.Display;

                    if (container.Template != null)
                    {
                        r.Draw(g, container.Template, container.Properties, null);
                    }

                    r.Draw(g, container, container.Properties, null);
                    r.ClearCache(isZooming: false);
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (mf != null)
                {
                    mf.Dispose();
                }
            }
            return ms;
        }
Example #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="item"></param>
 public void OnCopy(object item)
 {
     if (item is Container)
     {
         var container = item as Container;
         _containerToCopy = container;
         _documentToCopy = default(Document);
     }
     else if (item is Document)
     {
         var document = item as Document;
         _containerToCopy = default(Container);
         _documentToCopy = document;
     }
     else if (item is EditorContext || item == null)
     {
         OnCopy();
     }
 }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public Container Clone(Container container)
        {
            try
            {
                var template = container.Template;
                var json = _serializer.Serialize(container);
                if (!string.IsNullOrEmpty(json))
                {
                    var clone = _serializer.Deserialize<Container>(json);
                    if (clone != null)
                    {
                        var shapes = clone.Layers.SelectMany(l => l.Shapes);
                        TryToRestoreStyles(shapes);
                        TryToRestoreRecords(shapes);
                        clone.Template = template;
                        return clone;
                    }
                }
            }
            catch (Exception ex)
            {
                if (_editor.Log != null)
                {
                    _editor.Log.LogError("{0}{1}{2}",
                        ex.Message,
                        Environment.NewLine,
                        ex.StackTrace);
                }
            }

            return null;
        }
Example #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Container Create(string name = "Container", double width = 794, double height = 559)
        {
            var c = new Container()
            {
                Name = name,
                Width = width,
                Height = height,
                Background = ArgbColor.Create(0x00, 0xFF, 0xFF, 0xFF),
                Properties = ImmutableArray.Create<ShapeProperty>(),
                Layers = ImmutableArray.Create<Layer>()
            };

            var builder = c.Layers.ToBuilder();
            builder.Add(Layer.Create("Layer1", c));
            builder.Add(Layer.Create("Layer2", c));
            builder.Add(Layer.Create("Layer3", c));
            builder.Add(Layer.Create("Layer4", c));
            c.Layers = builder.ToImmutable();

            c.CurrentLayer = c.Layers.FirstOrDefault();
            c.WorkingLayer = Layer.Create("Working", c);
            c.HelperLayer = Layer.Create("Helper", c);

            return c;
        }
Example #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="owner"></param>
 /// <param name="isVisible"></param>
 /// <returns></returns>
 public static Layer Create(string name, Container owner, bool isVisible = true)
 {
     return new Layer()
     {
         Name = name,
         Owner = owner,
         IsVisible = isVisible,
         Shapes = ImmutableArray.Create<BaseShape>()
     };
 }