Beispiel #1
0
 public override void FinalFixup(List <GraphicElement> elements, ElementPropertyBag epb)
 {
     base.FinalFixup(elements, epb);
     StartConnectedShape = elements.SingleOrDefault(e => e.Id == epb.StartConnectedShapeId);
     EndConnectedShape   = elements.SingleOrDefault(e => e.Id == epb.EndConnectedShapeId);
     base.FinalFixup(elements, epb);
 }
Beispiel #2
0
        public virtual void Deserialize(ElementPropertyBag epb)
        {
            Id = epb.Id;

            if (!String.IsNullOrEmpty(epb.Json))
            {
                Json = JsonConvert.DeserializeObject <Dictionary <string, string> >(epb.Json);
            }

            DisplayRectangle = epb.DisplayRectangle;
            BorderPen.Dispose();
            BorderPen = new Pen(epb.BorderPenColor, epb.BorderPenWidth);
            FillBrush.Dispose();
            FillBrush = new SolidBrush(epb.FillBrushColor);
            Text      = epb.Text;
            TextColor = epb.TextColor;
            // If missing (backwards compatibility) middle-center align.
            TextAlign = epb.TextAlign == 0 ? ContentAlignment.MiddleCenter : epb.TextAlign;
            TextFont.Dispose();
            FontStyle fontStyle = (epb.TextFontUnderline ? FontStyle.Underline : FontStyle.Regular) | (epb.TextFontItalic ? FontStyle.Italic : FontStyle.Regular) | (epb.TextFontStrikeout ? FontStyle.Strikeout : FontStyle.Regular);

            TextFont = new Font(epb.TextFontFamily, epb.TextFontSize, fontStyle);

            HasCornerAnchors    = epb.HasCornerAnchors;
            HasCenterAnchors    = epb.HasCenterAnchors;
            HasLeftRightAnchors = epb.HasLeftRightAnchors;
            HasTopBottomAnchors = epb.HasTopBottomAnchors;

            HasCornerConnections    = epb.HasCornerConnections;
            HasCenterConnections    = epb.HasCenterConnections;
            HasLeftRightConnections = epb.HasLeftRightConnections;
            HasTopBottomConnections = epb.HasTopBottomConnections;
        }
Beispiel #3
0
        public virtual void Serialize(ElementPropertyBag epb)
        {
            epb.ElementName       = GetType().AssemblyQualifiedName;
            epb.Id                = Id;
            epb.DisplayRectangle  = DisplayRectangle;
            epb.BorderPenColor    = BorderPen.Color;
            epb.BorderPenWidth    = (int)BorderPen.Width;
            epb.FillBrushColor    = FillBrush.Color;
            epb.Text              = Text;
            epb.TextColor         = TextColor;
            epb.TextFontFamily    = TextFont.FontFamily.Name;
            epb.TextFontSize      = TextFont.Size;
            epb.TextFontUnderline = TextFont.Underline;
            epb.TextFontStrikeout = TextFont.Strikeout;
            epb.TextFontItalic    = TextFont.Italic;

            epb.HasCornerAnchors    = HasCornerAnchors;
            epb.HasCenterAnchors    = HasCenterAnchors;
            epb.HasLeftRightAnchors = HasLeftRightAnchors;
            epb.HasTopBottomAnchors = HasTopBottomAnchors;

            epb.HasCornerConnections    = HasCornerConnections;
            epb.HasCenterConnections    = HasCenterConnections;
            epb.HasLeftRightConnections = HasLeftRightConnections;
            epb.HasTopBottomConnections = HasTopBottomConnections;

            Connections.ForEach(c => c.Serialize(epb));
        }
Beispiel #4
0
        public virtual void Deserialize(ElementPropertyBag epb)
        {
            Id = epb.Id;
            DisplayRectangle = epb.DisplayRectangle;
            BorderPen.Dispose();
            BorderPen = new Pen(epb.BorderPenColor, epb.BorderPenWidth);
            FillBrush.Dispose();
            FillBrush = new SolidBrush(epb.FillBrushColor);
            Text      = epb.Text;
            TextColor = epb.TextColor;
            TextFont.Dispose();
            FontStyle fontStyle = (epb.TextFontUnderline ? FontStyle.Underline : FontStyle.Regular) | (epb.TextFontItalic ? FontStyle.Italic : FontStyle.Regular) | (epb.TextFontStrikeout ? FontStyle.Strikeout : FontStyle.Regular);

            TextFont = new Font(epb.TextFontFamily, epb.TextFontSize, fontStyle);

            HasCornerAnchors    = epb.HasCornerAnchors;
            HasCenterAnchors    = epb.HasCenterAnchors;
            HasLeftRightAnchors = epb.HasLeftRightAnchors;
            HasTopBottomAnchors = epb.HasTopBottomAnchors;

            HasCornerConnections    = epb.HasCornerConnections;
            HasCenterConnections    = epb.HasCenterConnections;
            HasLeftRightConnections = epb.HasLeftRightConnections;
            HasTopBottomConnections = epb.HasTopBottomConnections;
        }
Beispiel #5
0
        public virtual void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
        {
            epb.ElementName       = GetType().AssemblyQualifiedName;
            epb.Id                = Id;
            epb.Json              = JsonConvert.SerializeObject(Json);
            epb.DisplayRectangle  = DisplayRectangle;
            epb.BorderPenColor    = BorderPen.Color;
            epb.BorderPenWidth    = (int)BorderPen.Width;
            epb.FillBrushColor    = FillBrush.Color;
            epb.Text              = Text;
            epb.TextColor         = TextColor;
            epb.TextAlign         = TextAlign;
            epb.TextFontFamily    = TextFont.FontFamily.Name;
            epb.TextFontSize      = TextFont.Size;
            epb.TextFontUnderline = TextFont.Underline;
            epb.TextFontStrikeout = TextFont.Strikeout;
            epb.TextFontItalic    = TextFont.Italic;

            epb.HasCornerAnchors    = HasCornerAnchors;
            epb.HasCenterAnchors    = HasCenterAnchors;
            epb.HasLeftRightAnchors = HasLeftRightAnchors;
            epb.HasTopBottomAnchors = HasTopBottomAnchors;

            epb.HasCornerConnections    = HasCornerConnections;
            epb.HasCenterConnections    = HasCenterConnections;
            epb.HasLeftRightConnections = HasLeftRightConnections;
            epb.HasTopBottomConnections = HasTopBottomConnections;

            Connections.ForEach(c => c.Serialize(epb, elementsBeingSerialized));
            GroupChildren.ForEach(c => epb.Children.Add(new ChildPropertyBag()
            {
                ChildId = c.Id
            }));
        }
Beispiel #6
0
 public override void Serialize(ElementPropertyBag epb)
 {
     base.Serialize(epb);
     epb.StartCap = StartCap;
     epb.EndCap   = EndCap;
     epb.StartConnectedShapeId = StartConnectedShape?.Id ?? Guid.Empty;
     epb.EndConnectedShapeId   = EndConnectedShape?.Id ?? Guid.Empty;
 }
Beispiel #7
0
 public override void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
 {
     base.Serialize(epb, elementsBeingSerialized);
     epb.StartPoint = StartPoint;
     epb.EndPoint   = EndPoint;
     epb.HyAdjust   = hyAdjust;
     epb.VxAdjust   = vxAdjust;
 }
Beispiel #8
0
 public override void Deserialize(ElementPropertyBag epb)
 {
     base.Deserialize(epb);
     StartPoint = epb.StartPoint;
     EndPoint   = epb.EndPoint;
     hyAdjust   = epb.HyAdjust;
     vxAdjust   = epb.VxAdjust;
 }
Beispiel #9
0
        public void Serialize(ElementPropertyBag epb)
        {
            ConnectionPropertyBag cpb = new ConnectionPropertyBag();

            cpb.ToElementId            = ToElement.Id;
            cpb.ToConnectionPoint      = ToConnectionPoint;
            cpb.ElementConnectionPoint = ElementConnectionPoint;
            epb.Connections.Add(cpb);
        }
Beispiel #10
0
        public override void Deserialize(ElementPropertyBag epb)
        {
            base.Deserialize(epb);

            string truePath;

            if (Json.TryGetValue("TruePath", out truePath))
            {
                TruePath = (TruePath)Enum.Parse(typeof(TruePath), truePath);
            }
        }
Beispiel #11
0
 public void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
 {
     // If partial serialization (like copying a subset of shapes, don't include unselected connectors.)
     if (elementsBeingSerialized.Contains(ToElement))
     {
         ConnectionPropertyBag cpb = new ConnectionPropertyBag();
         cpb.ToElementId            = ToElement.Id;
         cpb.ToConnectionPoint      = ToConnectionPoint;
         cpb.ElementConnectionPoint = ElementConnectionPoint;
         epb.Connections.Add(cpb);
     }
 }
Beispiel #12
0
        public static string Serialize(GraphicElement el)
        {
            ElementPropertyBag epb = new ElementPropertyBag();

            el.Serialize(epb);
            XmlSerializer xs = new XmlSerializer(typeof(ElementPropertyBag));
            StringBuilder sb = new StringBuilder();
            TextWriter    tw = new StringWriter(sb);

            xs.Serialize(tw, epb);

            return(sb.ToString());
        }
Beispiel #13
0
        public static GraphicElement DeserializeElement(Canvas canvas, string data)
        {
            XmlSerializer      xs  = new XmlSerializer(typeof(ElementPropertyBag));
            TextReader         tr  = new StringReader(data);
            ElementPropertyBag epb = (ElementPropertyBag)xs.Deserialize(tr);
            Type           t       = Type.GetType(epb.ElementName);
            GraphicElement el      = (GraphicElement)Activator.CreateInstance(t, new object[] { canvas });

            el.Deserialize(epb);        // A specific deserialization does not preserve connections.
            el.Id = Guid.NewGuid();     // We get a new GUID when deserializing a specific element.

            return(el);
        }
Beispiel #14
0
        public override void FinalFixup(List <GraphicElement> elements, ElementPropertyBag epb, Dictionary <Guid, Guid> oldNewGuidMap)
        {
            base.FinalFixup(elements, epb, oldNewGuidMap);

            if (epb.StartConnectedShapeId != Guid.Empty)
            {
                StartConnectedShape = elements.SingleOrDefault(e => e.Id == oldNewGuidMap[epb.StartConnectedShapeId]);
            }

            if (epb.EndConnectedShapeId != Guid.Empty)
            {
                EndConnectedShape = elements.SingleOrDefault(e => e.Id == oldNewGuidMap[epb.EndConnectedShapeId]);
            }
        }
Beispiel #15
0
        public override void Deserialize(ElementPropertyBag epb)
        {
            base.Deserialize(epb);
            string state;

            if (Json.TryGetValue("State", out state))
            {
                State = (CollapseState)Enum.Parse(typeof(CollapseState), state);
            }

            string size;

            if (Json.TryGetValue("ExpandedSize", out size))
            {
                TypeConverter tc = TypeDescriptor.GetConverter(typeof(Size));
                ExpandedSize = (Size)tc.ConvertFromString(size);
            }
        }
Beispiel #16
0
        public override void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
        {
            base.Serialize(epb, elementsBeingSerialized);
            epb.StartCap = StartCap;
            epb.EndCap   = EndCap;

            // Don't assign connected shape ID to partial copy and paste selection where target is not in elements being serialized.

            if (elementsBeingSerialized.Contains(StartConnectedShape))
            {
                epb.StartConnectedShapeId = StartConnectedShape?.Id ?? Guid.Empty;
            }

            if (elementsBeingSerialized.Contains(EndConnectedShape))
            {
                epb.EndConnectedShapeId = EndConnectedShape?.Id ?? Guid.Empty;
            }
        }
Beispiel #17
0
        public static string Serialize(List <GraphicElement> elements)
        {
            List <ElementPropertyBag> sps = new List <ElementPropertyBag>();

            elements.ForEach(el =>
            {
                ElementPropertyBag epb = new ElementPropertyBag();
                el.Serialize(epb);
                sps.Add(epb);
            });

            XmlSerializer xs = new XmlSerializer(sps.GetType());
            StringBuilder sb = new StringBuilder();
            TextWriter    tw = new StringWriter(sb);

            xs.Serialize(tw, sps);

            return(sb.ToString());
        }
Beispiel #18
0
 public override void Serialize(ElementPropertyBag epb)
 {
     base.Serialize(epb);
     epb.StartPoint = startPoint;
     epb.EndPoint   = endPoint;
 }
Beispiel #19
0
 public virtual void FinalFixup(List <GraphicElement> elements, ElementPropertyBag epb, Dictionary <Guid, Guid> oldNewGuidMap)
 {
     elements.ForEach(el => el.UpdateProperties());
 }
Beispiel #20
0
 public override void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
 {
     Json["State"]        = State.ToString();
     Json["ExpandedSize"] = ExpandedSize.Width + "," + ExpandedSize.Height;
     base.Serialize(epb, elementsBeingSerialized);
 }
Beispiel #21
0
 public override void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
 {
     Json["TruePath"] = TruePath.ToString();
     base.Serialize(epb, elementsBeingSerialized);
 }
Beispiel #22
0
 public override void Serialize(ElementPropertyBag epb, IEnumerable <GraphicElement> elementsBeingSerialized)
 {
     base.Serialize(epb, elementsBeingSerialized);
     epb.StartPoint = startPoint;
     epb.EndPoint   = endPoint;
 }
Beispiel #23
0
 public override void Deserialize(ElementPropertyBag epb)
 {
     base.Deserialize(epb);
     StartCap = epb.StartCap;
     EndCap   = epb.EndCap;
 }
Beispiel #24
0
 public override void Deserialize(ElementPropertyBag epb)
 {
     base.Deserialize(epb);
     startPoint = epb.StartPoint;
     endPoint   = epb.EndPoint;
 }
Beispiel #25
0
 public virtual void FinalFixup(List <GraphicElement> elements, ElementPropertyBag epb)
 {
     elements.ForEach(el => el.UpdateProperties());
 }