Ejemplo n.º 1
0
        /// <summary>
        /// 设置当前页面所有控件的选中状态
        /// </summary>
        /// <param Name="enabled">true表示所有控件选中,false表示所有控件反选</param>
        public void selectAll(Boolean enabled)
        {
            List <SVPanel> vList = new List <SVPanel>();

            foreach (Control item in this.Controls)
            {
                SVPanel panel = item as SVPanel;
                if (panel == null)
                {
                    continue;
                }

                if (enabled)
                {
                    if (panel.IsMoved)
                    {
                        vList.Add(panel);
                    }
                }
                else
                {
                    vList.Add(panel);
                }
            }

            RedoUndo.setEnabled(false);
            foreach (var item in vList)
            {
                item.Selected = enabled;
            }

            RedoUndo.setEnabled(true);
            this.Refresh();
        }
Ejemplo n.º 2
0
            public override void Remove(Control value)
            {
                base.Remove(value);

                if (value is SVPanelNode)
                {
                    return;
                }

                //记录重做操作
                SVRedoUndoItem recordItem = new SVRedoUndoItem();

                recordItem.ReDo = () =>
                {
                    SVPanel panel = value as SVPanel;
                    RedoUndo.setEnabled(false);
                    panel.Selected = false;
                    base.Remove(value);
                    RedoUndo.setEnabled(true);
                };
                recordItem.UnDo = () =>
                {
                    SVPanel panel = value as SVPanel;
                    RedoUndo.setEnabled(false);
                    panel.Selected = false;
                    base.Add(value);
                    RedoUndo.setEnabled(true);
                };
                RedoUndo.recordOper(recordItem);
            }
Ejemplo n.º 3
0
        public void saveXML(SVXml xml)
        {
            //保存后修改状态。
            IsModify = false;

            xml.setAttr("ID", _attrib.id.ToString());

            XmlElement width = xml.createNode("Width");

            width.InnerText = _attrib.Width.ToString();

            XmlElement height = xml.createNode("Height");

            height.InnerText = _attrib.Height.ToString();

            XmlElement back = xml.createNode("Backcolor");

            back.InnerText = _attrib.BackColor.ToArgb().ToString();

            XmlElement mainPage = xml.createNode("MainPage");

            mainPage.InnerText = _attrib.IsMainPage.ToString();

            XmlElement backGroundType = xml.createNode("BackGroundType");

            backGroundType.InnerText = _attrib.BackGroundType.ToString();

            XmlElement picShowName = xml.createNode("PicShowName");

            picShowName.InnerText = _attrib.PicIconData.ShowName;

            XmlElement picFile = xml.createNode("PicFile");

            picFile.InnerText = _attrib.PicIconData.ImageFileName;

            XmlElement alignMent = xml.createNode("alignment");

            alignMent.InnerText = _attrib.IsAlignment.ToString();

            //保存当前页面的所有子控件
            foreach (Control ctrl in this.Controls)
            {
                SVPanel svPanel = ctrl as SVPanel;
                if (svPanel == null)
                {
                    continue;
                }

                svPanel.saveXML(xml);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 通过控件ID号来查找对应的页面,并记录相关跳转信息
        /// </summary>
        /// <param oldName="id">控件ID</param>
        private void findID(int id)
        {
            _findView.Clear();
            _findView.AppendText("---------------查找结果如下:-----------------\n");
            _findView.AppendText("\n");

            foreach (SVPageNode pageNode in _treeView.Nodes)
            {
                foreach (TreeNode classItem in pageNode.Nodes)
                {
                    foreach (SVPageNode item in classItem.Nodes)
                    {
                        SVPageWidget widget = item.Addtionobj as SVPageWidget;
                        if (widget == null)
                        {
                            continue;
                        }

                        if (widget.Attrib.id == id)
                        {
                            String text = String.Format("找到名为【{0}】的页面, id:{1}", widget.PageName, id);
                            _findView.AppendText(text);
                            _findView.setMark(widget);
                            _findView.AppendText("\n");
                        }

                        foreach (var panel in widget.Controls)
                        {
                            SVPanel p = panel as SVPanel;
                            if (p == null)
                            {
                                continue;
                            }

                            if (p.Id == id)
                            {
                                String text = String.Format("名为【{0}】的页面中, 找到控件====>类型【{1}】.", widget.PageName, p.GetType().Name);
                                _findView.AppendText(text);
                                _findView.setMark(p);
                                _findView.AppendText("\n");
                            }
                        }
                    }
                }
            }

            if (!_findView.isMatches())
            {
                _findView.AppendText("没有查找到相关内容!");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 输出查找结果
        /// </summary>
        /// <param oldName="panel">当前控件</param>
        /// <param oldName="vStr">当前判断的字符串</param>
        void outputFindResult(SVPanel panel, String vStr)
        {
            SVPageWidget widget = panel.Parent as SVPageWidget;

            if (widget == null)
            {
                return;
            }

            ///查找的字符串是否为空
            String findString = textBox.Text;

            if (String.IsNullOrWhiteSpace(findString))
            {
                return;
            }

            ///字符串
            String findStr = findString;
            String oldStr  = vStr;

            ///是否大小写匹配
            if (caseCheckBox.Checked)
            {
                findStr = findStr.ToLower();
                oldStr  = oldStr.ToLower();
            }

            ///全字匹配
            if (wholeCheckBox.Checked)
            {
                if (findStr == oldStr)
                {
                    String text = String.Format("页面【{0}】中, 找到控件====>类型【{1}】.", widget.PageName, panel.GetType().Name);
                    _findView.AppendText(text);
                    _findView.setMark(panel);
                    _findView.AppendText("\n");
                }
            }
            else
            {
                if (oldStr.Contains(findStr))
                {
                    String text = String.Format("页面【{0}】中, 找到控件====>类型【{1}】.", widget.PageName, panel.GetType().Name);
                    _findView.AppendText(text);
                    _findView.setMark(panel);
                    _findView.AppendText("\n");
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 检查当前页面中的元素超出了页面的显示范围
        /// </summary>
        /// <param Name="panel">页面对象</param>
        void checkOutOfRange(SVPageWidget widget)
        {
            foreach (Control ctrl in widget.Controls)
            {
                SVPanel svCtrl = ctrl as SVPanel;
                if (svCtrl == null)
                {
                    continue;
                }

                if (!widget.ClientRectangle.Contains(svCtrl.Bounds))
                {
                    String msg = String.Format("ID为{0}的控件超出当前页面{1}的显示范围", svCtrl.Id, widget.PageName);
                    throw new SVCheckValidException(msg);
                }
            }
        }
Ejemplo n.º 7
0
        /*
         * 检查当前页面中,多个控件之间是否有重叠的情况
         * 如果控件之间有重叠,将抛出异常 SVCheckValidException
         **/
        void checkOverlapping(SVPageWidget widget)
        {
            foreach (Control ctrl in widget.Controls)
            {
                foreach (Control child in widget.Controls)
                {
                    ///如果是同一个控件,就排除
                    if (ctrl == child)
                    {
                        continue;
                    }

                    //排除直线控件的相交情况
                    if (ctrl is SVLine || child is SVLine)
                    {
                        continue;
                    }

                    SVPanel svCtrl  = ctrl as SVPanel;
                    SVPanel svChild = child as SVPanel;

                    ///过滤控件类型
                    if (svCtrl == null || svChild == null)
                    {
                        continue;
                    }

                    int left1   = ctrl.Location.X;
                    int right1  = ctrl.Location.X + ctrl.Width;
                    int top1    = ctrl.Location.Y;
                    int bottom1 = ctrl.Location.Y + ctrl.Height;

                    int left2   = child.Location.X;
                    int right2  = child.Location.X + child.Width;
                    int top2    = child.Location.Y;
                    int bottom2 = child.Location.Y + child.Height;

                    if (!(right1 < left2 || left1 > right2 || bottom1 < top2 || top1 > bottom2))
                    {
                        String msg = String.Format("{0}页面中的,控件{1} 和 控件{2} 产生重叠", widget.PageName, svCtrl.Id, svChild.Id);
                        throw new SVCheckValidException(msg);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        //检查ID是否重复
        void checkIDRepeat()
        {
            ///用来保存当前工程中已经遍历的页面和控件的ID及名称
            Dictionary <Int32, String> dict    = new Dictionary <Int32, String>();
            HashSet <UInt16>           hashSet = new HashSet <UInt16>();

            foreach (var item in SVGlobalData.PageContainer)
            {
                SVPageWidget widget   = item.Value;
                String       pageText = widget.PageName;

                ///检查页面ID是否发生重复
                if (dict.ContainsKey(widget.Attrib.id))
                {
                    String msg = String.Format(dict[widget.Attrib.id] + "和页面{0}的ID重复", pageText);
                    throw new SVCheckValidException(msg);
                }

                ///保存页面ID
                dict.Add(widget.Attrib.id, String.Format("页面{0}", pageText));

                hashSet.Clear();
                ///遍历页面中的所有子控件
                foreach (var contrl in widget.Controls)
                {
                    ///过滤不是定义的控件
                    SVPanel panel = contrl as SVPanel;
                    if (panel == null)
                    {
                        continue;
                    }

                    ///当前控件ID是否存在
                    if (hashSet.Contains(panel.Id))
                    {
                        String msg = String.Format("页面[{0}]存在重复的ID号, 值为:{1}", pageText, panel.Id);
                        throw new SVCheckValidException(msg);
                    }

                    hashSet.Add(panel.Id);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 选中树节点后发生的事件
        /// 将当前选中节点中的控件对象设置为选中状态
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        void SVObjTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            ObjTreeNode node = e.Node as ObjTreeNode;

            if (node == null)
            {
                return;
            }

            SVPanel panel = node.objControl as SVPanel;

            if (panel == null)
            {
                return;
            }

            panel.Selected = true;
            panel.Refresh();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 单击树节点事件
        /// 清空当前选中节点对象的选中状态
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        void SVObjTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            ObjTreeNode node = this.SelectedNode as ObjTreeNode;

            if (node == null)
            {
                return;
            }

            SVPanel panel = node.objControl as SVPanel;

            if (panel == null)
            {
                return;
            }

            panel.Selected = false;
            panel.Refresh();
        }
Ejemplo n.º 11
0
        /*
         * 通过XML文件来加载页面控件对象
         *
         * xml - 一个页面对应的xml对象
         * isCreate - true: 创建新的ID号
         *            false: 直接使用文件中的ID号
         * */
        public void loadXML(SVXml xml, Boolean isCreate = false)
        {
            _redoUndo.setEnabled(false);

            XmlElement page = xml.CurrentElement;

            if (isCreate)
            {
                var instance = SVUniqueID.instance();
                _attrib.id = instance.newUniqueID();
                instance.saveFile();
            }
            else
            {
                _attrib.id = UInt16.Parse(page.GetAttribute("ID"));
            }

            try
            {
                XmlElement width = xml.select("Width");
                _attrib.Width = int.Parse(width.InnerText);

                XmlElement height = xml.select("Height");
                _attrib.Height = int.Parse(height.InnerText);

                XmlElement back = xml.select("Backcolor");
                _attrib.BackColor = Color.FromArgb(int.Parse(back.InnerText));

                XmlElement mainPage = xml.select("MainPage");
                _attrib.IsMainPage = Boolean.Parse(mainPage.InnerText);
                if (_attrib.IsMainPage)
                {
                    setToMainPageWidget();
                }

                XmlElement backGroundType = xml.select("BackGroundType");
                _attrib.BackGroundType = Byte.Parse(backGroundType.InnerText);

                XmlElement picShowName = xml.select("PicShowName");
                _attrib.PicIconData.ShowName = picShowName.InnerText;

                XmlElement picFile = xml.select("PicFile");
                _attrib.PicIconData.ImageFileName = picFile.InnerText;


                XmlElement alignMent = xml.select("alignment");
                _attrib.IsAlignment = Byte.Parse(alignMent.InnerText);
            }
            catch (Exception)
            {
            }

            //读取当前页面的所有子控件
            List <XmlElement> listNodes = xml.selectChilds();

            foreach (XmlElement node in listNodes)
            {
                SVPanel svPanel = SVNameToObject.getInstance(node.Name) as SVPanel;
                if (svPanel == null)
                {
                    continue;
                }

                svPanel.setRedoUndoObject(_redoUndo);
                svPanel.setParentID(_attrib.id);

                svPanel.MouseDown += new MouseEventHandler((sder, ev) =>
                {
                    MouseSelectEvent(sder, ev);
                });

                svPanel.MouseUp += new MouseEventHandler((sder, ev) =>
                {
                    MouseSelectEvent(sder, ev);
                });

                this.Controls.Add(svPanel);
                xml.CurrentElement = node;
                svPanel.loadXML(xml, isCreate);
                svPanel.refreshPropertyToPanel();
            }

            _redoUndo.setEnabled(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 初始化页面的框选操作
        /// </summary>
        void initRectSelect()
        {
            ///记录鼠标按下位置
            Point recordStartPos = new Point();

            this.MouseDown += new MouseEventHandler((sender, e) =>
            {
                ///如果不是按下鼠标左键,就不记录
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                SVSelectPanelObjs._VK_Ctrl = false;
                ///鼠标按下,清空所有控件的选中状态
                selectAll(false);
                ///记录鼠标按下时候的坐标点
                recordStartPos = new Point(e.X, e.Y);
            });


            this.MouseMove += new MouseEventHandler((sender, e) =>
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                _rect.Size = new Size(Math.Abs(e.X - recordStartPos.X), Math.Abs(e.Y - recordStartPos.Y));

                int tmpWidth  = e.X - recordStartPos.X;
                int tmpHeight = e.Y - recordStartPos.Y;

                if (tmpWidth > 0)
                {
                    if (tmpHeight < 0)
                    {
                        _rect.Location = new Point(recordStartPos.X, recordStartPos.Y + tmpHeight);
                    }
                    else
                    {
                        _rect.Location = recordStartPos;
                    }
                }
                else
                {
                    if (tmpHeight < 0)
                    {
                        _rect.Location = new Point(recordStartPos.X + tmpWidth, recordStartPos.Y + tmpHeight);
                    }
                    else
                    {
                        _rect.Location = new Point(recordStartPos.X + tmpWidth, recordStartPos.Y);
                    }
                }

                _isShowRect = true;
                this.Refresh();
            });

            ///是否显示边框
            this.Paint += new PaintEventHandler((sender, e) =>
            {
                int value = this.BackColor.ToArgb();
                Color c   = Color.FromArgb(value ^ 0xFFFFFF);

                if (_isShowRect)
                {
                    e.Graphics.DrawRectangle(new Pen(c, 1), _rect);
                }
            });

            ///鼠标弹起执行检查,设置选中控件的状态
            this.MouseUp += new MouseEventHandler((sender, e) =>
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                ///将在边框范围内的控件选中
                List <Control> vList = new List <Control>();
                foreach (Control item in this.Controls)
                {
                    SVPanel vPanel = item as SVPanel;
                    if (vPanel == null)
                    {
                        continue;
                    }

                    if (_rect.Contains(vPanel.Bounds))
                    {
                        vList.Add(vPanel);
                    }
                }

                foreach (var item in vList)
                {
                    ((SVPanel)item).Selected = true;
                }

                _isShowRect = false;
                this.Refresh();
            });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 控件拖入页面窗口中的事件操作
        /// </summary>
        /// <param Name="e"></param>
        protected override void OnDragDrop(DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(SVSelectItem)))
            {
                return;
            }

            ///禁用记录
            _redoUndo.setEnabled(false);

            SVSelectItem item = (SVSelectItem)e.Data.GetData(typeof(SVSelectItem));
            SVPanel      btn  = (SVPanel)(item._obj);

            btn.setRedoUndoObject(_redoUndo);
            btn.setParentID(Attrib.id);
            btn.refreshPropertyToPanel();

            btn.Location = this.PointToClient(new Point(e.X, e.Y));
            btn.Location = new Point(btn.Location.X - btn.Width / 2, btn.Location.Y - btn.Height / 2);
            btn.setStartPos(btn.Location);

            this.Controls.Add(btn);
            btn.newID();
            ChildAddEvent(btn, null);

            btn.MouseDown += new MouseEventHandler((sder, ev) =>
            {
                MouseSelectEvent(sder, ev);
            });

            btn.MouseUp += new MouseEventHandler((sder, ev) =>
            {
                MouseSelectEvent(sder, ev);
            });


            ///启用记录
            _redoUndo.setEnabled(true);

            ///记录重做操作
            ///这里只记录控件的添加和删除操作,其他属性的改变并不会被记录下来。
            SVRedoUndoItem recordItem = new SVRedoUndoItem();

            recordItem.ReDo = () =>
            {
                _redoUndo.setEnabled(false);
                btn.Selected = false;
                this.Controls.Add(btn);
                _redoUndo.setEnabled(true);
            };
            recordItem.UnDo = () =>
            {
                _redoUndo.setEnabled(false);
                btn.Selected = false;
                this.Controls.Remove(btn);
                _redoUndo.setEnabled(true);
            };

            ///执行记录
            _redoUndo.recordOper(recordItem);
        }
Ejemplo n.º 14
0
        //检查控件数量是否正确,并且包含检查每个控件本身
        void checkControlCount()
        {
            ///判断当前页面数是否超出最大范围
            if (SVGlobalData.PageContainer.Count > SVLimit.MAX_PAGE_NUMBER)
            {
                String msg = String.Format("最大页面数为{0},当前总页面数为{1}", SVLimit.MAX_PAGE_NUMBER, SVGlobalData.PageContainer.Count);
                throw new SVCheckValidException(msg);
            }

            ///循环判断每一页面
            foreach (var item in SVGlobalData.PageContainer)
            {
                SVPageWidget widget = item.Value;
                checkOverlapping(widget);
                checkOutOfRange(widget);

                ///所有计数都为0
                Int32 btnCount    = 0;
                Int32 labelCount  = 0;
                Int32 iconCount   = 0;
                Int32 gifCount    = 0;
                Int32 lineCount   = 0;
                Int32 analogCount = 0;
                Int32 binaryCount = 0;
                Int32 trendCount  = 0;
                Int32 heartCount  = 0;

                //检查每个控件本身属性
                foreach (var contrl in widget.Controls)
                {
                    SVPanel panel = contrl as SVPanel;
                    if (panel == null)
                    {
                        continue;
                    }

                    ///对每一种控件进行计数
                    if (panel is SVButton)
                    {
                        btnCount++;
                    }
                    else if (panel is SVLabel)
                    {
                        labelCount++;
                    }
                    else if (panel is SVLine)
                    {
                        lineCount++;
                    }
                    else if (panel is SVIcon)
                    {
                        iconCount++;
                    }
                    else if (panel is SVGif)
                    {
                        gifCount++;
                    }
                    else if (panel is SVAnalog)
                    {
                        analogCount++;
                    }
                    else if (panel is SVBinary)
                    {
                        binaryCount++;
                    }
                    else if (panel is SVHeartbeat)
                    {
                        heartCount++;
                    }
                    else if (panel is SVCurve)
                    {
                        trendCount++;
                    }

                    ///判断当前控件个数是否合法
                    if (btnCount > SVLimit.PAGE_BTN_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的按钮个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (labelCount > SVLimit.PAGE_AREA_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的文本个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (lineCount > SVLimit.PAGE_LINE_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的线条个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (iconCount > SVLimit.PAGE_ICON_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的静态图个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (gifCount > SVLimit.PAGE_GIF_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的静态图个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (analogCount > SVLimit.PAGE_ANA_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的模拟量个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (binaryCount > SVLimit.PAGE_BOOL_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的开关量个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (trendCount > SVLimit.PAGE_TCHART_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的趋势图个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (heartCount > SVLimit.PAGE_TICKGIF_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的心跳控件个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    ///单个控件判断
                    panel.checkValid();
                }
            }
        }