Пример #1
0
        public override void SaveItem(XmlDocument doc, XmlElement element)
        {
            XmlElement el = doc.CreateElement("Page");
            base.SaveItem(doc, el);

            UnitsManager unitMng = new UnitsManager();

            XmlAttribute attr = doc.CreateAttribute("Version");
            attr.Value = "1.0";
            el.SetAttributeNode(attr);

            // save info
            XmlElement el2 = doc.CreateElement("Info");
            attr = doc.CreateAttribute("Description");
            attr.Value = this.Description;
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            // save size
            el2 = doc.CreateElement("Size");
            attr = doc.CreateAttribute("Width");
            attr.Value = this.WidthInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el2.SetAttributeNode(attr);

            attr = doc.CreateAttribute("Height");
            attr.Value = this.HeightInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            // FillColor
            el2 = doc.CreateElement("FillColor");
            attr = doc.CreateAttribute("R"); attr.Value = this.FillColor.R.ToString(); el2.SetAttributeNode(attr);
            attr = doc.CreateAttribute("G"); attr.Value = this.FillColor.G.ToString(); el2.SetAttributeNode(attr);
            attr = doc.CreateAttribute("B"); attr.Value = this.FillColor.B.ToString(); el2.SetAttributeNode(attr);
            attr = doc.CreateAttribute("A"); attr.Value = this.FillColor.A.ToString(); el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            el2 = doc.CreateElement("BackgroundImage");
            attr = doc.CreateAttribute("Name");
            attr.Value = this.ImageName;
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            // embedd image data here if embeddImageToTemplate is used
            el2 = doc.CreateElement("EmbeddedImage");
            attr = doc.CreateAttribute("Name");
            attr.Value = this.ImageName;
            el2.SetAttributeNode(attr);

            if (imageData != null && imageData.Length > 0)
            {
                attr = doc.CreateAttribute("EmbeddedDecodedImageLength"); attr.Value = imageData.Length.ToString(); el2.SetAttributeNode(attr);
                XmlText textValue = doc.CreateTextNode("EmdeddedImageData");
                textValue.Value = Convert.ToBase64String(imageData);
                attr = doc.CreateAttribute("EmbeddedImageLength"); attr.Value = textValue.Value.Length.ToString(); el2.SetAttributeNode(attr);
                el2.AppendChild(textValue);
            }
            el.AppendChild(el2);

            // save children without balloons
            el2 = doc.CreateElement("Items");
            foreach(EditorItem child in this.Children)
            {
                if(child is Balloon) { }
                else
                {
                    child.Save(doc, el2);
                }
            }
            el.AppendChild(el2);

            // save children with balloons
            el2 = doc.CreateElement("Balloons");
            foreach(EditorItem child in this.Children)
            {
                if(child is Balloon)
                {
                    child.Save(doc, el2);
                }
            }
            el.AppendChild(el2);

            element.AppendChild(el);
        }
Пример #2
0
        /// <summary>
        /// Main load method
        /// </summary>
        /// <param name="element"></param>
        public override void Load(System.Xml.XmlNode element)
        {
            base.Load(element);

            UnitsManager unitMng = new UnitsManager();
            EditorFont editorFont = null;
            float fontSize = 12.0f;

            // Load font for older versions is kept here.
            // should be removed on first public release
            XmlNode node = element.SelectSingleNode("Font");
            if (node != null)
            {
                int fontId = Convert.ToInt32(node.Attributes["SaveID"].Value);
                fontSize = (float)Convert.ToDouble(node.Attributes["FontSize"].Value);
                // Load font from font manager
                editorFont = FontManager.Instance.FindFont(fontId);
            }

            // Load font color
            int r = 0, g = 0, b = 0;
            if (node != null)
            {
                XmlAttribute attr = (XmlAttribute) node.Attributes.GetNamedItem("FontColorR");
                if (attr != null)
                {
                    r = Convert.ToInt32(attr.Value);
                }
                attr = (XmlAttribute) node.Attributes.GetNamedItem("FontColorG");
                if (attr != null)
                {
                    g = Convert.ToInt32(attr.Value);
                }
                attr = (XmlAttribute) node.Attributes.GetNamedItem("FontColorB");
                if (attr != null)
                {
                    b = Convert.ToInt32(attr.Value);
                }
            }

            this.ForeColor = Color.FromArgb(r, g, b);

            if (editorFont == null)
            {
                MessageBox.Show("Font cannot be found in saved document. It will be replaced with the default one");
                font = new Font("Arial", fontSize);
            }
            else
            {
                // make new font based on loaded editor font
               this.Font = new Font(editorFont.Font.Name, fontSize,
                               editorFont.Font.Style, editorFont.Font.Unit,
                               editorFont.Font.GdiCharSet, editorFont.Font.GdiVerticalFont);
            }
        }
Пример #3
0
        public override void Load(System.Xml.XmlNode element)
        {
            base.Load(element);

            UnitsManager unitMng = new UnitsManager();

            // Load info
            XmlNode node = element.SelectSingleNode("Info");
            if (node != null)
            {
                this.Description = node.Attributes["Description"].Value;
            }

            // Load page size
            node = element.SelectSingleNode("Size");
            if (node != null)
            {
                MeasureUnit = unitMng.StringToUnit(node.Attributes["Width"].Value);
                WidthInUnits = (float)(System.Convert.ToDouble(node.Attributes["Width"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
                HeightInUnits = (float)(System.Convert.ToDouble(node.Attributes["Height"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
            }
            else
            {
                // set default sizes
                MeasureUnit = MeasureUnits.cm;
                WidthInUnits = (float)unitMng.ConvertUnit(19, MeasureUnits.cm, MeasureUnits.point);
                HeightInPixels = (float)unitMng.ConvertUnit(21, MeasureUnits.cm, MeasureUnits.point);
            }

            // Load fill color
            node = element.SelectSingleNode("FillColor");
            if (node != null)
            {
                try
                {
                    int r = Convert.ToInt32(node.Attributes["R"].Value);
                    int g = Convert.ToInt32(node.Attributes["G"].Value);
                    int b = Convert.ToInt32(node.Attributes["B"].Value);
                    int a = Convert.ToInt32(node.Attributes["A"].Value);
                    this.FillColor = Color.FromArgb(a, r, g, b);
                }
                catch { }
            }

            // Load BackgroundImageName
            node = element.SelectSingleNode("BackgroundImage");
            if (node != null)
            {
                this.imageName = node.Attributes["Name"].Value;
            }

            // load embedded image if available
            node = element.SelectSingleNode("EmbeddedImage");
            if (node != null)
            {
                if (node.InnerText != null && node.InnerText.Length > 0)
                {
                    this.imageData = Convert.FromBase64String(node.InnerText);
                    pictureForDisplay = Bitmap.FromStream(new MemoryStream(this.imageData));
                }
            }

            // Load none balloons items
            node = element.SelectSingleNode("Items");
            if(node != null)
            {
                foreach(XmlNode childNode in node.ChildNodes)
                {
                    if(childNode.Name == "Item")
                    {
                        // this is not valid for generator but this can be loaded into editor
                        string itemType = childNode.Attributes["Type"].Value;
                        EditorItem newItem = ReportPage.CreateItemFromType(itemType);
                        newItem.Load(childNode);
                        newItem.Parent = this;
                        //Children.Add(newItem);
                    }
                }
            }

            // Load balloons
            node = element.SelectSingleNode("Balloons");
            if (node != null)
            {
                foreach(XmlNode balloonNode in node.ChildNodes)
                {
                    if (balloonNode.Name == "Balloon")
                    {
                        string tmpType;
                        tmpType = balloonNode.Attributes["Type"].Value;
                        if (tmpType == "Static")
                        {
                            StaticBalloon child = new StaticBalloon();
                            //child.Parent = this;
                            child.Load(balloonNode);
                            child.Parent = this;
                            //Children.Add(child);
                        }
                        else if (tmpType == "Dynamic")
                        {
                            DynamicBalloon child = new DynamicBalloon();
                            //child.Parent = this;
                            child.Load(balloonNode);
                            child.Parent = this;
                            //Children.Add(child);
                        }
                    }
                    else if (balloonNode.Name == "Item")
                    {
                        // this is not valid for generator but this can be loaded into editor
                        string itemType = balloonNode.Attributes["Type"].Value;
                        EditorItem newItem = ReportPage.CreateItemFromType(itemType);
                        newItem.Load(balloonNode);
                        newItem.Parent = this;
                        //Children.Add(newItem);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Here is actual save method. Element should be already created one
        /// </summary>
        /// <param name="node"></param>
        public virtual void SaveItem(XmlDocument doc, System.Xml.XmlElement element)
        {
            UnitsManager unitMng = new UnitsManager();

            // save name attribute
            XmlAttribute attr = doc.CreateAttribute("Name");
            attr.Value = Name;
            element.SetAttributeNode(attr);

            // save location
            XmlElement el = doc.CreateElement("Location");
            attr = doc.CreateAttribute("PositionX");
            attr.Value = LocationInUnitsX.ToString() + unitMng.UnitToString(MeasureUnit);
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("PositionY");
            attr.Value = LocationInUnitsY.ToString() + unitMng.UnitToString(MeasureUnit);
            el.SetAttributeNode(attr);

            element.AppendChild(el);

            // save Width and Height. This is same as shape but generator wants those information as well
            el = doc.CreateElement("Width");
            attr = doc.CreateAttribute("Value");
            attr.Value = this.WidthInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el.SetAttributeNode(attr);
            element.AppendChild(el);

            el = doc.CreateElement("Height");
            attr = doc.CreateAttribute("Value");
            attr.Value = this.HeightInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el.SetAttributeNode(attr);
            element.AppendChild(el);

            el = doc.CreateElement("WidthInPixels");
            attr = doc.CreateAttribute("Value");
            attr.Value = this.WidthInPixels.ToString();
            el.SetAttributeNode(attr);
            element.AppendChild(el);

            el = doc.CreateElement("HeightInPixels");
            attr = doc.CreateAttribute("Value");
            attr.Value = this.HeightInPixels.ToString();
            el.SetAttributeNode(attr);
            element.AppendChild(el);

            // save Shape
            el = doc.CreateElement("Shape");
            attr = doc.CreateAttribute("Type");
            attr.Value = "Rectangle";
            el.SetAttributeNode(attr);

            XmlElement el2 = doc.CreateElement("Dimensions");
            attr = doc.CreateAttribute("Width");
            attr.Value = this.WidthInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            attr = doc.CreateAttribute("Height");
            attr.Value = this.HeightInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            element.AppendChild(el);

            // Save Scale
            el = doc.CreateElement("Scale");
            attr = doc.CreateAttribute("x");
            attr.Value = this.ScaleXFactor.ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("y");
            attr.Value = this.ScaleXFactor.ToString();
            el.SetAttributeNode(attr);

            element.AppendChild(el);

            // save transformations
            el = doc.CreateElement("Transformation");
            attr = doc.CreateAttribute("a");
            attr.Value = this.TransformationMatrix.Elements[0].ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("b");
            attr.Value = this.TransformationMatrix.Elements[1].ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("c");
            attr.Value = this.TransformationMatrix.Elements[2].ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("d");
            attr.Value = this.TransformationMatrix.Elements[3].ToString();
            el.SetAttributeNode(attr);

            element.AppendChild(el);

            // save rotation
            el = doc.CreateElement("Rotation");
            attr = doc.CreateAttribute("Value");
            attr.Value = this.RotationAngle.ToString();
            el.SetAttributeNode(attr);

            element.AppendChild(el);

            // save dock position
            el = doc.CreateElement("DockPosition");
            attr = doc.CreateAttribute("Dock");
            attr.Value = this.DockPositionString;
            el.SetAttributeNode(attr);

            element.AppendChild(el);

            // save anchor properties
            if(anchor != null)
            {
                el = doc.CreateElement("Anchor");
                attr = doc.CreateAttribute("Top");
                attr.Value = this.anchor.TopAnchor.ToString();
                el.SetAttributeNode(attr);
                attr = doc.CreateAttribute("Bottom");
                attr.Value = this.anchor.Bottomanchor.ToString();
                el.SetAttributeNode(attr);
                attr = doc.CreateAttribute("Left");
                attr.Value = this.anchor.LeftAnchor.ToString();
                el.SetAttributeNode(attr);
                attr = doc.CreateAttribute("Right");
                attr.Value = this.anchor.RightAnchor.ToString();
                el.SetAttributeNode(attr);

                element.AppendChild(el);
            }
        }
Пример #5
0
        /// <summary>
        /// How this item is loaded
        /// </summary>
        /// <param name="node"></param>
        public virtual void Load(System.Xml.XmlNode element)
        {
            UnitsManager unitMng = new UnitsManager();

            // load name
            XmlAttribute attr = (XmlAttribute)element.Attributes.GetNamedItem("Name");
            if (attr != null)
            {
                this.Name = attr.Value;
            }

            // Load location if available
            XmlNode locationNode = element.SelectSingleNode("Location");
            if (locationNode != null)
            {
                this.MeasureUnit = unitMng.StringToUnit(locationNode.Attributes["PositionX"].Value);
                this.LocationInUnitsX = (float)(System.Convert.ToDouble(locationNode.Attributes["PositionX"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
                this.LocationInUnitsY = (float)(System.Convert.ToDouble(locationNode.Attributes["PositionY"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
            }

            // Load dimensions and shape definition
            XmlNode shapeNode = element.SelectSingleNode("Shape");
            if (shapeNode != null)
            {
                string shapeType = shapeNode.Attributes["Type"].Value;
                if (shapeType == "Rectangle")
                {
                    // load width and height
                    XmlNode dimensionNode = shapeNode.SelectSingleNode("Dimensions");
                    if (dimensionNode != null)
                    {
                        this.WidthInUnits = (float)(System.Convert.ToDouble(dimensionNode.Attributes["Width"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
                        this.HeightInUnits = (float)(System.Convert.ToDouble(dimensionNode.Attributes["Height"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
                    }
                }
            }

            // Load scale
            XmlNode scaleNode = element.SelectSingleNode("Scale");
            if (scaleNode != null)
            {
                MeasureUnits mUnit = unitMng.StringToUnit(scaleNode.Attributes["x"].Value);
                this.ScaleXFactor = (float)(System.Convert.ToDouble(scaleNode.Attributes["x"].Value.TrimEnd(unitMng.UnitToString(mUnit).ToCharArray())));
                this.ScaleYFactor = (float)(System.Convert.ToDouble(scaleNode.Attributes["y"].Value.TrimEnd(unitMng.UnitToString(mUnit).ToCharArray())));
            }

            // Load Transformation
            XmlNode transNode = element.SelectSingleNode("Transformation");
            if (transNode != null)
            {
                TransformationMatrix.Elements[0] = (float)System.Convert.ToDouble(transNode.Attributes["a"].Value);
                TransformationMatrix.Elements[1] = (float)System.Convert.ToDouble(transNode.Attributes["b"].Value);
                TransformationMatrix.Elements[2] = (float)System.Convert.ToDouble(transNode.Attributes["c"].Value);
                TransformationMatrix.Elements[3] = (float)System.Convert.ToDouble(transNode.Attributes["d"].Value);
            }

            // Load Rotation
            XmlNode rotationNode = element.SelectSingleNode("Rotation");
            if(rotationNode != null)
            {
                this.RotationAngle = Convert.ToInt16(rotationNode.Attributes[0].Value);
            }

            // load width in pixels and height in pixels as editor works with those
            XmlNode widthInPixelsNode = element.SelectSingleNode("WidthInPixels");
            if (widthInPixelsNode != null)
            {
                this.WidthInPixels = (float) Convert.ToDouble(widthInPixelsNode.Attributes[0].Value);
            }

            XmlNode heightInPixelsNode = element.SelectSingleNode("HeightInPixels");
            if (heightInPixelsNode != null)
            {
                this.HeightInPixels = (float) Convert.ToDouble(heightInPixelsNode.Attributes[0].Value);
            }

            // Load dock position
            XmlNode dockPos = element.SelectSingleNode("DockPosition");
            if (dockPos != null)
            {
                this.DockPositionString = dockPos.Attributes["Dock"].Value;
            }

            // load anchor property
            XmlNode anchorNode = element.SelectSingleNode("Anchor");
            if(anchorNode != null)
            {
                if(this.anchor == null) this.anchor = new Anchor(this);
                this.ItemAnchor.TopAnchor = Convert.ToBoolean(anchorNode.Attributes["Top"].Value);
                this.ItemAnchor.Bottomanchor = Convert.ToBoolean(anchorNode.Attributes["Bottom"].Value);
                this.ItemAnchor.LeftAnchor = Convert.ToBoolean(anchorNode.Attributes["Left"].Value);
                this.ItemAnchor.RightAnchor = Convert.ToBoolean(anchorNode.Attributes["Right"].Value);
            }

            this.commands.Clear();
            if(this is EditorProject || this is ReportPage)
            {
            }
            else
            {
                EditorItemFactory.Instance.CreateItem(this);
            }
        }
Пример #6
0
        /// <summary>
        /// Load font object
        /// </summary>
        /// <param name="node"></param>
        public void Load(System.Xml.XmlNode node)
        {
            UnitsManager unitMng = new UnitsManager();

            this.saveID = Convert.ToInt32(node.Attributes["SaveID"].Value);

            int italic = System.Convert.ToInt32(node.Attributes["Italic"].Value);
            int bold = System.Convert.ToInt32(node.Attributes["Bold"].Value);

            FontStyle style = FontStyle.Regular;
            if (italic == 1)
            {
                style = FontStyle.Italic;
            }
            if (bold == 1)
            {
                style |= FontStyle.Bold;
            }

            this.Font = new Font(node.Attributes["Name"].Value, 12.0f, style);
        }
Пример #7
0
        public void Save(XmlDocument doc, XmlElement element)
        {
            UnitsManager unitMng = new UnitsManager();

            XmlElement el = doc.CreateElement("Shading");
            XmlAttribute attr = doc.CreateAttribute("Type");
            attr.Value = ((int)gradientType).ToString();
            el.SetAttributeNode(attr);
            element.AppendChild(el);

            el = doc.CreateElement("AxialCoords");
            attr = doc.CreateAttribute("FromX");
            attr.Value = this.Point1.X.ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("FromY");
            attr.Value = this.Point1.Y.ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("ToX");
            attr.Value = this.Point2.X.ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("ToY");
            attr.Value = this.Point2.Y.ToString();
            el.SetAttributeNode(attr);

            element.AppendChild(el);

            // function type
            el = doc.CreateElement("FunctionType");
            attr = doc.CreateAttribute("Type");
            attr.Value = this.functionType.ToString();
            el.SetAttributeNode(attr);
            element.AppendChild(el);

            el = doc.CreateElement("Color");
            attr = doc.CreateAttribute("FromR"); attr.Value = this.Color1.R.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("FromG"); attr.Value = this.Color1.G.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("FromB"); attr.Value = this.Color1.B.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("ToR"); attr.Value = this.Color2.R.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("ToG"); attr.Value = this.Color2.G.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("ToB"); attr.Value = this.Color2.B.ToString(); el.SetAttributeNode(attr);
            element.AppendChild(el);

            el = doc.CreateElement("GradientDefinition");
            attr = doc.CreateAttribute("Angle"); attr.Value = this.Angle.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("BlendPosition1"); attr.Value = this.BlendPosition1.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("BlendPosition2"); attr.Value = this.BlendPosition2.ToString(); el.SetAttributeNode(attr);
            element.AppendChild(el);
        }
Пример #8
0
        public void Load(RectangleShape shape, XmlNode element)
        {
            UnitsManager unitMng = new UnitsManager();
            XmlNode node;

            // Load shading definition
            node = element.SelectSingleNode("Shading");
            if (node != null)
            {
                this.gradientType = (GradientType)Convert.ToInt32(node.Attributes["Type"].Value);
            }

            // Load axial cords
            node = element.SelectSingleNode("AxialCoords");
            if (node != null)
            {
                float x = (float)Convert.ToDouble(node.Attributes["FromX"].Value);
                float y = (float)Convert.ToDouble(node.Attributes["FromY"].Value);
                this.Point1 = new PointF(x, y);

                x = (float)Convert.ToDouble(node.Attributes["ToX"].Value);
                y = (float)Convert.ToDouble(node.Attributes["ToY"].Value);
                this.Point2 = new PointF(x, y);
            }

            // Load function
            node = element.SelectSingleNode("Function");
            if (node != null)
            {
                this.functionType = Convert.ToInt32(node.Attributes["Type"]);
            }

            // Load color
            node = element.SelectSingleNode("Color");
            if (node != null)
            {
                int r = Convert.ToInt32(node.Attributes["FromR"].Value);
                int g = Convert.ToInt32(node.Attributes["FromG"].Value);
                int b = Convert.ToInt32(node.Attributes["FromB"].Value);
                this.Color1 = Color.FromArgb(r, g, b);

                r = Convert.ToInt32(node.Attributes["ToR"].Value);
                g = Convert.ToInt32(node.Attributes["ToG"].Value);
                b = Convert.ToInt32(node.Attributes["ToB"].Value);
                this.Color2 = Color.FromArgb(r, g, b);
            }

            //Load gradient definition
            node = element.SelectSingleNode("GradientDefinition");
            if(node != null)
            {
                this.Angle = (float)Convert.ToDouble(node.Attributes["Angle"].Value);
                this.BlendPosition1 = (float)Convert.ToDouble(node.Attributes["BlendPosition1"].Value);
                this.BlendPosition2 = (float)Convert.ToDouble(node.Attributes["BlendPosition2"].Value);
            }
        }