예제 #1
0
        /// <summary>
        /// ViewNode 转 KNXView
        /// </summary>
        /// <param name="knx"></param>
        public void ToKnx(KNXView knx, BackgroundWorker worker)
        {
            if (null != worker)
            {
                worker.ReportProgress(0, string.Format(UIResMang.GetString("TextIsExporting"), this.Title));
            }

            knx.Id              = this.Id;
            knx.Text            = this.Text;
            knx.Title           = this.Title;
            knx.Left            = this.Location.X;
            knx.Top             = this.Location.Y;
            knx.Width           = this.Size.Width;
            knx.Height          = this.Size.Height;
            knx.Padding         = new KNXPadding(this.Padding);
            knx.DisplayBorder   = (int)this.DisplayBorder;
            knx.BorderColor     = ColorHelper.ColorToHexStr(this.BorderColor);
            knx.Alpha           = this.Alpha;
            knx.Radius          = this.Radius;
            knx.FlatStyle       = (int)this.FlatStyle;
            knx.BackgroundColor = ColorHelper.ColorToHexStr(this.BackgroundColor);
            knx.BackgroundImage = this.BackgroundImage;
            knx.TitleFont       = this.TitleFont.ToKnx();

            MyCache.ValidResImgNames.Add(knx.BackgroundImage);
        }
예제 #2
0
        public static ViewNode ImportKNXView(BackgroundWorker worker, KNXView knx, string ResImgDir)
        {
            ViewNode node = null;


            if (MyConst.View.KnxAppType == knx.GetType().Name)
            {
                node = ImportAppNode(worker, knx as KNXApp, ResImgDir);
            }
            else if (MyConst.View.KnxAreaType == knx.GetType().Name)
            {
                node = ImportAreaNode(worker, null, knx as KNXArea, ResImgDir);
            }
            else if (MyConst.View.KnxRoomType == knx.GetType().Name)
            {
                node = ImportRoomNode(worker, null, knx as KNXRoom, ResImgDir);
            }
            else if (MyConst.View.KnxPageType == knx.GetType().Name)
            {
                node = ImportPageNode(worker, null, knx as KNXPage, ResImgDir);
            }
            else if (IsControlNode(knx.GetType().Name))
            {
                node = ImportControlNode(worker, null, knx as KNXControlBase, ResImgDir);
            }

            return(node);
        }
예제 #3
0
        public static KNXView ExportViewNode(BackgroundWorker worker, ViewNode node, string ImgResDir, Point RelPoint)
        {
            KNXView knx = null;


            if (MyConst.View.KnxAppType == node.Name)
            {
                knx = ExportApp(worker, node as AppNode, ImgResDir);
            }
            else if (MyConst.View.KnxAreaType == node.Name)
            {
                knx = ExportArea(worker, null, node as AreaNode, ImgResDir);
            }
            else if (MyConst.View.KnxRoomType == node.Name)
            {
                knx = ExportRoom(worker, null, node as RoomNode, ImgResDir);
            }
            else if (MyConst.View.KnxPageType == node.Name)
            {
                knx = ExportPage(worker, null, node as PageNode, ImgResDir);
            }
            else if (IsControlNode(node.Name))
            {
                knx = ExportControl(worker, null, node, ImgResDir, RelPoint);
            }

            return(knx);
        }
예제 #4
0
        /// <summary>
        /// KNXView 转 ViewNode
        /// </summary>
        /// <param name="knx"></param>
        public ViewNode(KNXView knx, BackgroundWorker worker)
        {
            this.Id   = knx.Id;
            this.Text = knx.Text;

            if (ImportedHelper.IsLessThan2_0_3())
            {
                this.Title = knx.Text;
            }
            else
            {
                this.Title = knx.Title;
            }

            if (null != worker)
            {
                worker.ReportProgress(0, string.Format(UIResMang.GetString("TextIsImporting"), this.Title));
            }

            this.Location = new Point(knx.Left, knx.Top);
            this.Size     = new Size(knx.Width, knx.Height);
            if (null != knx.Padding)
            {
                this.Padding = knx.Padding.ToPadding();
            }
            else
            {
                this.Padding = new Padding(0);
            }
            this.DisplayBorder   = (EBool)Enum.ToObject(typeof(EBool), knx.DisplayBorder);
            this.BorderColor     = ColorHelper.HexStrToColor(knx.BorderColor);
            this.Alpha           = knx.Alpha;
            this.Radius          = knx.Radius;
            this.FlatStyle       = (EFlatStyle)Enum.ToObject(typeof(EFlatStyle), knx.FlatStyle);
            this.BackgroundColor = ColorHelper.HexStrToColor(knx.BackgroundColor ?? "#FFFFFF");
            this.BackgroundImage = knx.BackgroundImage;
            if (ImportedHelper.IsLessThan2_5_2())
            {
                this.TitleFont = new STFont(knx.FontColor, knx.FontSize);
            }
            else
            {
                this.TitleFont = new STFont(knx.TitleFont);
            }

            this.State = ControlState.Normal;
        }
예제 #5
0
 /// <summary>
 /// ViewNode 转 KNXView
 /// </summary>
 /// <param name="knx"></param>
 protected void ToKnx(KNXView knx)
 {
     knx.Id     = this.Id;
     knx.Text   = this.Text;
     knx.Left   = this.X;
     knx.Top    = this.Y;
     knx.Width  = this.Width;
     knx.Height = this.Height;
     //knx.Left = this.Location.X;
     //knx.Top = this.Location.Y;
     //knx.Width = this.Size.Width;
     //knx.Height = this.Size.Height;
     knx.DisplayBorder   = (int)this.DisplayBorder;
     knx.BorderColor     = FrmMainHelp.ColorToHexStr(this.BorderColor);
     knx.Alpha           = this.Alpha;
     knx.Radius          = this.Radius;
     knx.FlatStyle       = (int)this.FlatStyle;
     knx.BackgroundColor = FrmMainHelp.ColorToHexStr(this.BackgroundColor);
     knx.BackgroundImage = this.BackgroundImage;
     knx.FontColor       = FrmMainHelp.ColorToHexStr(this.FontColor);
     knx.FontSize        = this.FontSize;
 }
예제 #6
0
        /// <summary>
        /// KNXView 转 ViewNode
        /// </summary>
        /// <param name="knx"></param>
        public ViewNode(KNXView knx)
        {
            this.Id     = knx.Id;
            this.Text   = knx.Text;
            this.X      = knx.Left;
            this.Y      = knx.Top;
            this.Width  = knx.Width;
            this.Height = knx.Height;
            //this.Location = new Point(knx.Left, knx.Top);
            //this.Size = new Size(knx.Width, knx.Height);
            this.DisplayBorder   = (EBool)Enum.ToObject(typeof(EBool), knx.DisplayBorder);
            this.BorderColor     = FrmMainHelp.HexStrToColor(knx.BorderColor);
            this.Alpha           = knx.Alpha;
            this.Radius          = knx.Radius;
            this.FlatStyle       = (EFlatStyle)Enum.ToObject(typeof(EFlatStyle), knx.FlatStyle);
            this.BackgroundColor = FrmMainHelp.HexStrToColor(knx.BackgroundColor ?? "#FFFFFF");
            this.BackgroundImage = knx.BackgroundImage;
            this.FontColor       = FrmMainHelp.HexStrToColor(knx.FontColor ?? "#000000");
            this.FontSize        = knx.FontSize;

            this.State = ControlState.Normal;
        }
        public static void ExportToCollections(List <ViewNode> nodes, string path)
        {
            string name    = Path.GetFileNameWithoutExtension(path);         // 目标文件的名称,不含扩展名
            string tempDir = Path.Combine(MyCache.ProjTempCollFolder, name); // 收藏文件临时目录

            /* 清空临时目录 */
            FileHelper.DeleteFolder(tempDir);
            Directory.CreateDirectory(tempDir);

            PageNode pageNode = ViewNode.GetPageNodeFromParent(nodes[0]);
            int      width    = pageNode.Size.Width;
            int      height   = pageNode.Size.Height;

            /* 在控件的原始位置绘制 */
            Bitmap   bm = new Bitmap(width, height);
            Graphics g  = Graphics.FromImage(bm);

            foreach (ViewNode node in nodes)
            {
                node.DrawAt(g, 1.0f, true); // 绘制控件
            }

            Rectangle rect      = ViewNode.GetMinimumCommonRectangleInPage(nodes);
            int       newWidth  = rect.Width;
            int       newHeight = rect.Height;
            int       Side      = newWidth > newHeight ? newWidth : newHeight;

            Side += 10;
            Bitmap   img      = new Bitmap(Side, Side);
            Graphics graphics = Graphics.FromImage(img);

            graphics.DrawImage(bm, (Side - newWidth) / 2, (Side - newHeight) / 2, rect, GraphicsUnit.Pixel);

            /* 保存预览图片 */
            string preview = Path.Combine(tempDir, MyConst.TemplatePreviewFile);  // 模板预览图片

            ImageHelper.SaveImageAsPNG(img, preview);

            /* 创建图片资源临时存放目录 */
            string tempImgDir = Path.Combine(tempDir, MyConst.ImgFolder);

            Directory.CreateDirectory(tempImgDir);

            /* 创建模板的界面元文件,并导出图片资源 */
            TemplateMeta template = new TemplateMeta();

            foreach (ViewNode node in nodes)
            {
                /* 添加控件到界面元文件 */
                KNXView knx = EntityHelper.ExportViewNode(null, node, tempImgDir, rect.Location);
                template.Views.Add(knx);
            }

            /* 保存界面元文件 */
            string metaFile = Path.Combine(tempDir, MyConst.TemplateMetaFile);                      // 界面元文件

            AppStorage.SaveAsFile(template, metaFile);                                              // 保存模板文件

            VersionStorage.SaveTemplateVersionFile(Path.Combine(tempDir, MyConst.TemplateVersion)); // 保存模板文件的版本信息。

            ZipHelper.ZipDir(tempDir, path);                                                        // 压缩为最终的收藏文件
        }
예제 #8
0
        private void UpdateListViewItems(List <Template> templates)
        {
            if (GroupBy.Type == this.SelectedGroupBy)
            {
                this.listView.ShowGroups = true;

                ListViewGroup lvgGroupBox = new ListViewGroup();
                lvgGroupBox.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgGroupBox);

                ListViewGroup lvgBlinds = new ListViewGroup();
                lvgBlinds.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgBlinds);

                ListViewGroup lvgDigitalAdjustment = new ListViewGroup();
                lvgDigitalAdjustment.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgDigitalAdjustment);

                ListViewGroup lvgImageButton = new ListViewGroup();
                lvgImageButton.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgImageButton);

                ListViewGroup lvgLabel = new ListViewGroup();
                lvgLabel.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgLabel);

                ListViewGroup lvgSceneButton = new ListViewGroup();
                lvgSceneButton.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgSceneButton);

                ListViewGroup lvgSliderSwitch = new ListViewGroup();
                lvgSliderSwitch.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgSliderSwitch);

                ListViewGroup lvgSwitch = new ListViewGroup();
                lvgSwitch.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgSwitch);

                ListViewGroup lvgTimer = new ListViewGroup();
                lvgTimer.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgTimer);

                ListViewGroup lvgValueDisplay = new ListViewGroup();
                lvgValueDisplay.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgValueDisplay);

                ListViewGroup lvgUngroup = new ListViewGroup();
                lvgUngroup.HeaderAlignment = HorizontalAlignment.Center;
                this.listView.Groups.Add(lvgUngroup);

                foreach (Template tpl in templates)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = tpl.Name;

                    this.imageListSmall.Images.Add(tpl.Name, tpl.Preview);
                    this.imageListLarge.Images.Add(tpl.Name, tpl.Preview);
                    lvi.ImageKey = tpl.Name;

                    lvi.SubItems.Add(tpl.Version.LastModified);

                    if (1 == tpl.Views.Count)
                    {
                        KNXView view = tpl.Views[0];
                        switch (view.GetType().Name)
                        {
                        case MyConst.View.KnxAppType:
                            break;

                        case MyConst.View.KnxAreaType:
                            break;

                        case MyConst.View.KnxRoomType:
                            break;

                        case MyConst.View.KnxPageType:
                            break;

                        case MyConst.Controls.KnxGroupBoxType:
                            lvgGroupBox.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxBlindsType:
                            lvgBlinds.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxDigitalAdjustmentType:
                            lvgDigitalAdjustment.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxLabelType:
                            lvgLabel.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxSceneButtonType:
                            lvgSceneButton.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxSliderSwitchType:
                            lvgSliderSwitch.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxSwitchType:
                            lvgSwitch.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxTimerButtonType:
                            lvgTimer.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxValueDisplayType:
                            lvgValueDisplay.Items.Add(lvi);
                            break;

                        case MyConst.Controls.KnxImageButtonType:
                            lvgImageButton.Items.Add(lvi);
                            break;

                        default:
                            lvgUngroup.Items.Add(lvi);
                            break;
                        }
                    }
                    else if (tpl.Views.Count > 1)
                    {
                        lvgUngroup.Items.Add(lvi);
                    }

                    this.listView.Items.Add(lvi);
                }

                lvgGroupBox.Header          = UIResMang.GetString("TextGroupBox") + "(" + lvgGroupBox.Items.Count + ")";
                lvgBlinds.Header            = UIResMang.GetString("TextBlinds") + "(" + lvgBlinds.Items.Count + ")";
                lvgDigitalAdjustment.Header = UIResMang.GetString("TextDigitalAdjustment") + "(" + lvgDigitalAdjustment.Items.Count + ")";
                lvgImageButton.Header       = UIResMang.GetString("TextImageButton") + "(" + lvgImageButton.Items.Count + ")";
                lvgLabel.Header             = UIResMang.GetString("TextLabel") + "(" + lvgLabel.Items.Count + ")";
                lvgSceneButton.Header       = UIResMang.GetString("TextSceneButton") + "(" + lvgSceneButton.Items.Count + ")";
                lvgSliderSwitch.Header      = UIResMang.GetString("TextSliderSwitch") + "(" + lvgSliderSwitch.Items.Count + ")";
                lvgSwitch.Header            = UIResMang.GetString("TextSwitch") + "(" + lvgSwitch.Items.Count + ")";
                lvgTimer.Header             = UIResMang.GetString("TextTimer") + "(" + lvgTimer.Items.Count + ")";
                lvgValueDisplay.Header      = UIResMang.GetString("TextValueDisplay") + "(" + lvgValueDisplay.Items.Count + ")";
                lvgUngroup.Header           = UIResMang.GetString("Combination") + "(" + lvgUngroup.Items.Count + ")";
            }
            else
            {
                this.listView.ShowGroups = false;

                foreach (Template tpl in templates)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = tpl.Name;

                    this.imageListSmall.Images.Add(tpl.Name, tpl.Preview);
                    this.imageListLarge.Images.Add(tpl.Name, tpl.Preview);
                    lvi.ImageKey = tpl.Name;

                    lvi.SubItems.Add(tpl.Version.LastModified);

                    this.listView.Items.Add(lvi);
                }
            }

            this.Text = UIResMang.GetString("Collections") + "(" + this.listView.Items.Count + ")";
        }