Exemple #1
0
        /// <summary>
        /// Сохранить представление в поток
        /// </summary>
        public void SaveToStream(Stream stream)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDoc.AppendChild(xmlDecl);

            // запись заголовка представления
            XmlElement rootElem = xmlDoc.CreateElement("SchemeView");

            rootElem.SetAttribute("title", SchemeParams.Title);
            xmlDoc.AppendChild(rootElem);

            // запись параметров схемы
            XmlElement schemeElem = xmlDoc.CreateElement("Scheme");

            rootElem.AppendChild(schemeElem);

            WriteProp(schemeElem, "Size", SchemeParams.Size);
            WriteProp(schemeElem, "BackColor", SchemeParams.BackColor);
            if (SchemeParams.BackImage != null)
            {
                WriteProp(schemeElem, "BackImageName", SchemeParams.BackImage.Name);
            }
            WriteProp(schemeElem, "ForeColor", SchemeParams.ForeColor);
            WriteProp(schemeElem, "Font", SchemeParams.Font);

            // запись элементов схемы
            XmlElement elemsElem = xmlDoc.CreateElement("Elements");

            rootElem.AppendChild(elemsElem);

            foreach (Element elem in ElementList)
            {
                XmlElement elemElem = xmlDoc.CreateElement(elem.GetType().Name);
                elemsElem.AppendChild(elemElem);

                WriteProp(elemElem, "ID", elem.ID);
                WriteProp(elemElem, "Name", elem.Name);
                WriteProp(elemElem, "Location", elem.Location);
                WriteProp(elemElem, "Size", elem.Size);
                WriteProp(elemElem, "ZIndex", elem.ZIndex);

                if (elem is StaticText)
                {
                    StaticText staticText = (StaticText)elem;
                    WriteProp(elemElem, "AutoSize", staticText.AutoSize);
                    WriteProp(elemElem, "BackColor", staticText.BackColor);
                    WriteProp(elemElem, "BorderColor", staticText.BorderColor);
                    WriteProp(elemElem, "ForeColor", staticText.ForeColor);
                    WriteProp(elemElem, "Font", staticText.Font);
                    WriteProp(elemElem, "Text", staticText.Text);
                    WriteProp(elemElem, "WordWrap", staticText.WordWrap);
                    WriteProp(elemElem, "HAlign", staticText.HAlign);
                    WriteProp(elemElem, "VAlign", staticText.VAlign);

                    if (elem is DynamicText)
                    {
                        DynamicText dynamicText = (DynamicText)elem;
                        WriteProp(elemElem, "ToolTip", dynamicText.ToolTip);
                        WriteProp(elemElem, "UnderlineOnHover", dynamicText.UnderlineOnHover);
                        WriteProp(elemElem, "BackColorOnHover", dynamicText.BackColorOnHover);
                        WriteProp(elemElem, "BorderColorOnHover", dynamicText.BorderColorOnHover);
                        WriteProp(elemElem, "ForeColorOnHover", dynamicText.ForeColorOnHover);
                        WriteProp(elemElem, "InCnlNum", dynamicText.InCnlNum);
                        WriteProp(elemElem, "CtrlCnlNum", dynamicText.CtrlCnlNum);
                        WriteProp(elemElem, "Action", dynamicText.Action);
                        WriteProp(elemElem, "ShowValue", dynamicText.ShowValue);
                    }

                    elemsElem.AppendChild(elemElem);
                }
                else if (elem is StaticPicture)
                {
                    StaticPicture staticPicture = (StaticPicture)elem;
                    WriteProp(elemElem, "BorderColor", staticPicture.BorderColor);
                    if (staticPicture.Image != null)
                    {
                        WriteProp(elemElem, "ImageName", staticPicture.Image.Name);
                    }
                    WriteProp(elemElem, "ImageStretch", staticPicture.ImageStretch);

                    if (elem is DynamicPicture)
                    {
                        DynamicPicture dynamicPicture = (DynamicPicture)elem;
                        WriteProp(elemElem, "ToolTip", dynamicPicture.ToolTip);
                        if (dynamicPicture.ImageOnHover != null)
                        {
                            WriteProp(elemElem, "ImageOnHoverName", dynamicPicture.ImageOnHover.Name);
                        }
                        WriteProp(elemElem, "BorderColorOnHover", dynamicPicture.BorderColorOnHover);
                        WriteProp(elemElem, "InCnlNum", dynamicPicture.InCnlNum);
                        WriteProp(elemElem, "CtrlCnlNum", dynamicPicture.CtrlCnlNum);
                        WriteProp(elemElem, "Action", dynamicPicture.Action);

                        if (dynamicPicture.Conditions != null && dynamicPicture.Conditions.Count > 0)
                        {
                            XmlElement condsElem = xmlDoc.CreateElement("Conditions");
                            elemElem.AppendChild(condsElem);

                            foreach (Condition cond in dynamicPicture.Conditions)
                            {
                                WriteProp(condsElem, "Condition", cond);
                            }
                        }
                    }
                }
            }

            // запись словаря изображений схемы
            XmlElement imagesElem = xmlDoc.CreateElement("Images");

            rootElem.AppendChild(imagesElem);

            foreach (Image image in ImageDict.Values)
            {
                WriteProp(imagesElem, "Image", image);
            }

            // запись фильтра по входным каналам
            XmlElement cnlsFilterElem = xmlDoc.CreateElement("CnlsFilter");

            cnlsFilterElem.InnerText = string.Join <int>(" ", CnlsFilter);
            rootElem.AppendChild(cnlsFilterElem);

            xmlDoc.Save(stream);
        }
Exemple #2
0
 /// <summary>
 /// Клонировать объект
 /// </summary>
 public override object Clone()
 {
     DynamicPicture dynamicPicture = new DynamicPicture();
     dynamicPicture.CopyFrom(this);
     return dynamicPicture;
 }
Exemple #3
0
        /// <summary>
        /// Загрузить представление из потока
        /// </summary>
        public override void LoadFromStream(Stream stream)
        {
            // очистка представления
            Clear();

            // загрузка XML-документа
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(stream);

            // проверка типа представления
            XmlElement rootElem = xmlDoc.DocumentElement;

            if (!rootElem.Name.Equals("SchemeView", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // получение заголовка представления
            Title = rootElem.GetAttribute("title");
            SchemeParams.Title = Title;

            // загрузка параметров схемы
            XmlNode schemeNode = rootElem.SelectSingleNode("Scheme");

            if (schemeNode != null)
            {
                SchemeParams.Size      = ReadSizeProp(schemeNode, Scheme.DefaultSize);
                SchemeParams.BackColor = ReadStringProp(schemeNode, "BackColor");
                SchemeParams.BackImage = ReadImageNameProp(schemeNode, "BackImageName");
                SchemeParams.ForeColor = ReadStringProp(schemeNode, "ForeColor");
                SchemeParams.Font      = ReadFontProp(schemeNode, true);
            }

            // загрузка элементов схемы
            XmlNode elemsNode = rootElem.SelectSingleNode("Elements");

            if (elemsNode != null)
            {
                foreach (XmlNode elemNode in elemsNode.ChildNodes)
                {
                    string  tagName    = elemNode.Name.ToLowerInvariant();
                    Element element    = null;
                    int     inCnlNum   = 0;
                    int     ctrlCnlNum = 0;

                    if (tagName == "statictext" || tagName == "dynamictext")
                    {
                        DynamicText dynamicText = tagName == "dynamictext" ? new DynamicText() : null;
                        StaticText  staticText  = dynamicText == null ? new StaticText() : dynamicText;
                        element = staticText;

                        staticText.AutoSize    = ReadBoolProp(elemNode, "AutoSize");
                        staticText.BackColor   = ReadStringProp(elemNode, "BackColor");
                        staticText.BorderColor = ReadStringProp(elemNode, "BorderColor");
                        staticText.ForeColor   = ReadStringProp(elemNode, "ForeColor");
                        staticText.Font        = ReadFontProp(elemNode);
                        staticText.Text        = ReadStringProp(elemNode, "Text");
                        staticText.WordWrap    = ReadBoolProp(elemNode, "WordWrap");
                        staticText.HAlign      = ReadHAlignProp(elemNode);
                        staticText.VAlign      = ReadVAlignProp(elemNode);

                        if (dynamicText != null)
                        {
                            dynamicText.ToolTip            = ReadStringProp(elemNode, "ToolTip");
                            dynamicText.UnderlineOnHover   = ReadBoolProp(elemNode, "UnderlineOnHover");
                            dynamicText.BackColorOnHover   = ReadStringProp(elemNode, "BackColorOnHover");
                            dynamicText.BorderColorOnHover = ReadStringProp(elemNode, "BorderColorOnHover");
                            dynamicText.ForeColorOnHover   = ReadStringProp(elemNode, "ForeColorOnHover");
                            inCnlNum               = ReadIntProp(elemNode, "InCnlNum");
                            ctrlCnlNum             = ReadIntProp(elemNode, "CtrlCnlNum");
                            dynamicText.InCnlNum   = inCnlNum;
                            dynamicText.CtrlCnlNum = ctrlCnlNum;
                            dynamicText.Action     = ReadActionProp(elemNode);
                            dynamicText.ShowValue  = ReadShowValueProp(elemNode);
                        }
                    }
                    else if (tagName == "staticpicture" || tagName == "dynamicpicture")
                    {
                        DynamicPicture dynamicPicture = tagName == "dynamicpicture" ? new DynamicPicture() : null;
                        StaticPicture  staticPicture  = dynamicPicture == null ? new StaticPicture() : dynamicPicture;
                        element = staticPicture;

                        staticPicture.BorderColor  = ReadStringProp(elemNode, "BorderColor");
                        staticPicture.Image        = ReadImageNameProp(elemNode, "ImageName");
                        staticPicture.ImageStretch = ReadImageStretchProp(elemNode);

                        if (dynamicPicture != null)
                        {
                            dynamicPicture.ToolTip            = ReadStringProp(elemNode, "ToolTip");
                            dynamicPicture.ImageOnHover       = ReadImageNameProp(elemNode, "ImageOnHoverName");
                            dynamicPicture.BorderColorOnHover = ReadStringProp(elemNode, "BorderColorOnHover");
                            inCnlNum   = ReadIntProp(elemNode, "InCnlNum");
                            ctrlCnlNum = ReadIntProp(elemNode, "CtrlCnlNum");
                            dynamicPicture.InCnlNum   = inCnlNum;
                            dynamicPicture.CtrlCnlNum = ctrlCnlNum;
                            dynamicPicture.Action     = ReadActionProp(elemNode);

                            XmlNode condsNode = elemNode.SelectSingleNode("Conditions");
                            if (condsNode != null)
                            {
                                dynamicPicture.Conditions = new List <Condition>();
                                XmlNodeList condNodes = condsNode.SelectNodes("Condition");
                                foreach (XmlNode condNode in condNodes)
                                {
                                    Condition condition = new Condition();
                                    condition.CompareOperator1 = ReadCompareOperatorProp(condNode, "CompareOperator1");
                                    condition.CompareArgument1 = ReadDoubleProp(condNode, "CompareArgument1");
                                    condition.CompareOperator2 = ReadCompareOperatorProp(condNode, "CompareOperator2");
                                    condition.CompareArgument2 = ReadDoubleProp(condNode, "CompareArgument2");
                                    condition.LogicalOperator  = ReadLogicalOperatorProp(condNode, "LogicalOperator");
                                    condition.Image            = ReadImageNameProp(condNode, "ImageName");
                                    dynamicPicture.Conditions.Add(condition);
                                }
                            }
                        }
                    }

                    if (element != null)
                    {
                        element.ID = ReadIntProp(elemNode, "ID");

                        if (element.ID > 0)
                        {
                            element.Name     = ReadStringProp(elemNode, "Name");
                            element.Location = ReadLocationProp(elemNode, Element.DefaultLocation);
                            element.Size     = ReadSizeProp(elemNode, Element.DefaultSize);
                            element.ZIndex   = ReadIntProp(elemNode, "ZIndex");
                            ElementList.Add(element);
                            ElementDict[element.ID] = element;

                            if (inCnlNum > 0)
                            {
                                AddCnlNum(inCnlNum);
                            }
                            if (ctrlCnlNum > 0)
                            {
                                AddCtrlCnlNum(ctrlCnlNum);
                            }
                            if (maxID < element.ID)
                            {
                                maxID = element.ID;
                            }
                        }
                    }
                }
            }

            // загрузка словаря изображений схемы
            XmlNode imagesNode = rootElem.SelectSingleNode("Images");

            if (imagesNode != null)
            {
                XmlNodeList imageNodes = imagesNode.SelectNodes("Image");
                foreach (XmlNode imageNode in imageNodes)
                {
                    Image  image = new Image();
                    string name  = ReadStringProp(imageNode, "Name");
                    image.Name = name;
                    image.Data = Convert.FromBase64String(ReadStringProp(imageNode, "Data"));
                    if (name != "")
                    {
                        ImageDict[name] = image;
                    }
                }
            }

            // загрузка фильтра по входным каналам
            XmlNode cnlsFilterNode = rootElem.SelectSingleNode("CnlsFilter");

            if (cnlsFilterNode != null)
            {
                string[] cnlNums = cnlsFilterNode.InnerText.Split(Separator, StringSplitOptions.RemoveEmptyEntries);

                foreach (string cnlNumStr in cnlNums)
                {
                    int cnlNum;
                    if (int.TryParse(cnlNumStr, out cnlNum))
                    {
                        int ind = CnlsFilter.BinarySearch(cnlNum);
                        if (ind < 0)
                        {
                            CnlsFilter.Insert(~ind, cnlNum);
                            AddCnlNum(cnlNum);
                        }
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Загрузить представление из потока
        /// </summary>
        public override void LoadFromStream(Stream stream)
        {
            // очистка представления
            Clear();

            // загрузка XML-документа
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(stream);

            // проверка формата файла (потока)
            XmlElement rootElem = xmlDoc.DocumentElement;

            if (!rootElem.Name.Equals("SchemeView", StringComparison.OrdinalIgnoreCase))
            {
                throw new ScadaException(SchemePhrases.IncorrectFileFormat);
            }

            // загрузка документа схемы
            XmlNode documentNode = rootElem.SelectSingleNode("Document") ?? rootElem.SelectSingleNode("Scheme");

            if (documentNode != null)
            {
                SchemeDoc.LoadFromXml(documentNode);

                // загрузка заголовка схемы для старого формата
                if (SchemeDoc.Title == "")
                {
                    SchemeDoc.Title = rootElem.GetAttribute("title");
                }

                // установка заголовка представления
                Title = SchemeDoc.Title;

                // загрузка фильтра по входным каналам для старого формата
                XmlNode cnlsFilterNode = rootElem.SelectSingleNode("CnlsFilter");
                if (cnlsFilterNode != null)
                {
                    SchemeDoc.CnlFilter.ParseCnlFilter(cnlsFilterNode.InnerText);
                }

                // добавление входных каналов представления
                foreach (int cnlNum in SchemeDoc.CnlFilter)
                {
                    AddCnlNum(cnlNum);
                }
            }

            // загрузка компонентов схемы
            XmlNode componentsNode = rootElem.SelectSingleNode("Components") ?? rootElem.SelectSingleNode("Elements");

            if (componentsNode != null)
            {
                foreach (XmlNode componentNode in componentsNode.ChildNodes)
                {
                    // создание компонента
                    string        nodeName  = componentNode.Name.ToLowerInvariant();
                    BaseComponent component = null;

                    if (nodeName == "statictext")
                    {
                        component = new StaticText();
                    }
                    else if (nodeName == "dynamictext")
                    {
                        component = new DynamicText();
                    }
                    else if (nodeName == "staticpicture")
                    {
                        component = new StaticPicture();
                    }
                    else if (nodeName == "dynamicpicture")
                    {
                        component = new DynamicPicture();
                    }

                    if (component != null)
                    {
                        // загрузка компонента и добавление его в представление
                        component.SchemeDoc = SchemeDoc;
                        component.LoadFromXml(componentNode);
                        Components[component.ID] = component;

                        // добавление входных каналов представления
                        if (component is IDynamicComponent)
                        {
                            IDynamicComponent dynamicComponent = (IDynamicComponent)component;
                            AddCnlNum(dynamicComponent.InCnlNum);
                            AddCtrlCnlNum(dynamicComponent.CtrlCnlNum);
                        }

                        // определение макс. идентификатора компонентов
                        if (component.ID > maxComponentID)
                        {
                            maxComponentID = component.ID;
                        }
                    }
                }
            }

            // загрузка изображений схемы
            XmlNode imagesNode = rootElem.SelectSingleNode("Images");

            if (imagesNode != null)
            {
                Dictionary <string, Image> images = SchemeDoc.Images;
                XmlNodeList imageNodes            = imagesNode.SelectNodes("Image");
                foreach (XmlNode imageNode in imageNodes)
                {
                    Image image = new Image();
                    image.LoadFromXml(imageNode);
                    if (!string.IsNullOrEmpty(image.Name))
                    {
                        images[image.Name] = image;
                    }
                }
            }
        }