Beispiel #1
0
        public STPanel(ViewNode node)
        {
            this.node = node;
            //this.State = ControlState.Normal;

            this.SetStyle(
                ControlStyles.UserPaint |  //控件自行绘制,而不使用操作系统的绘制
                //ControlStyles.ContainerControl |
                ControlStyles.AllPaintingInWmPaint | //忽略擦出的消息,减少闪烁。
                ControlStyles.OptimizedDoubleBuffer |//在缓冲区上绘制,不直接绘制到屏幕上,减少闪烁。
                ControlStyles.ResizeRedraw | //控件大小发生变化时,重绘。
                ControlStyles.SupportsTransparentBackColor |
                ControlStyles.DoubleBuffer,
                true);//支持透明背景颜色
        }
        private static ViewNode ImportControlNode(BackgroundWorker worker, ContainerNode parentNode, KNXControlBase knx, string ResImgDir)
        {
            ViewNode node = null;

            switch (knx.GetType().Name)
            {
            case MyConst.Controls.KnxBlindsType:
                node = new BlindsNode(knx as KNXBlinds, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxLabelType:
                node = new LabelNode(knx as KNXLabel, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxSceneButtonType:
                node = new SceneButtonNode(knx as KNXSceneButton, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxSliderSwitchType:
                node = new SliderSwitchNode(knx as KNXSliderSwitch, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxSwitchType:
                node = new SwitchNode(knx as KNXSwitch, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxValueDisplayType:
                node = new ValueDisplayNode(knx as KNXValueDisplay, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxTimerButtonType:
                node = new TimerButtonNode(knx as KNXTimerButton, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxDigitalAdjustmentType:
                node = new DigitalAdjustmentNode(knx as KNXDigitalAdjustment, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxImageButtonType:
                node = new ImageButtonNode(knx as KNXImageButton, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxShutterType:
                node = new ShutterNode(knx as KNXShutter, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxDimmerType:
                node = new DimmerNode(knx as KNXDimmer, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxWebCamViewerType:
                node = new WebCamerNode(knx as KNXWebCamer, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxMediaButtonType:
                node = new MediaButtonNode(knx as KNXMediaButton, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxAirConditionType:
                node = new AirConditionNode(knx as KNXAirCondition, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxHVACType:
                node = new HVACNode(knx as KNXHVAC, worker, ResImgDir);
                break;

            case MyConst.Controls.KnxGroupBoxType:
                node = new GroupBoxNode(knx as KNXGroupBox, worker, ResImgDir);

                KNXGroupBox knxGroupBox = knx as KNXGroupBox;
                if (knxGroupBox.Controls != null && knxGroupBox.Controls.Count > 0)
                {
                    foreach (var item in knxGroupBox.Controls)
                    {
                        ImportControlNode(worker, node as ContainerNode, item, ResImgDir);
                    }
                }

                break;

            default:
                MessageBox.Show(UIResMang.GetString("Message39") + knx.GetType().Name, UIResMang.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            if (null != parentNode)
            {
                parentNode.Nodes.Add(node);
            }

            return(node);
        }
        /// <summary>
        /// 将ViewNode对象转为KNXControlBase对象
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private static KNXControlBase ExportControl(BackgroundWorker worker, KNXContainer parent, ViewNode node, string ImgResDir, Point RelPoint)
        {
            KNXControlBase knx = null;

            // 节点的类型
            switch (node.Name)
            {
            case MyConst.Controls.KnxBlindsType:
                knx = (node as BlindsNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxLabelType:
                knx = (node as LabelNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxSceneButtonType:
                knx = (node as SceneButtonNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxSliderSwitchType:
                knx = (node as SliderSwitchNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxSwitchType:
                knx = (node as SwitchNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxValueDisplayType:
                knx = (node as ValueDisplayNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxTimerButtonType:
                knx = (node as TimerButtonNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxDigitalAdjustmentType:
                knx = (node as DigitalAdjustmentNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxImageButtonType:
                knx = (node as ImageButtonNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxShutterType:
                knx = (node as ShutterNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxDimmerType:
                knx = (node as DimmerNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxWebCamViewerType:
                knx = (node as WebCamerNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxMediaButtonType:
                knx = (node as MediaButtonNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxAirConditionType:
                knx = (node as AirConditionNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxHVACType:
                knx = (node as HVACNode).ExportTo(worker, ImgResDir, RelPoint);
                break;

            case MyConst.Controls.KnxGroupBoxType:
                knx = (node as GroupBoxNode).ExportTo(worker, ImgResDir, RelPoint);

                if (node.Nodes.Count > 0)
                {
                    // 添加控件
                    foreach (ViewNode childNode in node.Nodes)
                    {
                        ExportControl(worker, knx as KNXContainer, childNode, ImgResDir, node.LocationInPageFact);
                    }
                }
                break;

            default:
                MessageBox.Show(UIResMang.GetString("Message38") + node.Name, UIResMang.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            if ((null != knx) && (null != parent))
            {
                parent.Controls.Add(knx);
            }

            return(knx);
        }
Beispiel #4
0
        /// <summary>
        /// parentNode的子孙控件中是否有childNode
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="childNode"></param>
        /// <returns></returns>
        private bool ContainsChildNode(ViewNode parentNode, ViewNode childNode)
        {
            bool contains = false;
            TreeNode ppNode = parentNode.Parent;
            TreeNode pcNode = childNode.Parent;
            while (true) // 遍历ChildNode的父控件、祖控件...
            {
                if (null != pcNode)
                {
                    if (pcNode == parentNode) // 子控件的父控件与parenNode一致,则包含
                    {
                        contains = true;
                        break;
                    }
                    else if (pcNode == ppNode) // 子控件的父控件与parentNode的父控件一致,则不包含
                    {
                        contains = false;
                        break;
                    }
                }
                else
                {
                    break;
                }

                pcNode = pcNode.Parent;

            }

            return contains;
        }
Beispiel #5
0
        private bool ControlsAlignment(ViewNode node, ViewNode sNode, List<Line> Lines)
        {
            Rectangle sNodeRect = sNode.RectInPage;
            bool alreadyAlign = false;

            foreach (ViewNode vNode in node.Nodes) // 遍历node下的子控件
            {
                Rectangle vNodeRect = vNode.RectInPage;

                /* 不与自身、父控件进行边沿比对。与父控件边沿比对请看 ↑CheckMargin() */
                if (/*vNode == sNode*/vNode.IsSelected || vNode == sNode.Parent)
                {
                    continue;
                }

                int sideLeft = sNodeRect.Left - vNodeRect.Left; // 左边沿比对
                int compensateLeft = sideLeft + sNode.AliCompX;
                int sideRight = sNodeRect.Right - vNodeRect.Right; // 右边沿比对
                int compensateRight = sideRight + sNode.AliCompX;
                if ((compensateLeft >= 0) && (compensateLeft <= 5)) // 比对控件与被比对控件的左侧距离差
                {
                    if (UIEditor.Entity.ViewNode.ControlState.Move == sNode.State) // 仅控件处于移动状态时才产生吸附效应
                    {
                        sNode.X = sNode.GetLocationXFromLocationXInPage(vNodeRect.Left);
                        sNode.AliCompX += sideLeft;
                        sNode.AliNode = vNode;
                    }

                    if (sNodeRect.Top > vNodeRect.Top) // 比对控件在被比对控件的上侧时
                    {
                        Lines.Add(new Line(new Point(vNodeRect.Left - 1, vNodeRect.Top), new Point(sNode.RectInPage.Left - 1, sNodeRect.Bottom)));
                    }
                    else
                    {
                        Lines.Add(new Line(new Point(sNode.RectInPage.Left - 1, sNodeRect.Top), new Point(vNodeRect.Left - 1, vNodeRect.Bottom)));
                    }

                    alreadyAlign = true;
                    break;
                }
                else if ((compensateRight >= -5) && (compensateRight <= 0)) // 比对控件与被比对控件的右侧距离差
                {
                    if (UIEditor.Entity.ViewNode.ControlState.Move == sNode.State) // 仅控件处于移动状态时才产生吸附效应
                    {
                        sNode.X = sNode.GetLocationXFromLocationRightInPage(vNodeRect.Right);
                        sNode.AliCompX += sideRight;
                        sNode.AliNode = vNode;
                    }

                    if (sNodeRect.Top > vNodeRect.Top) // 比对控件在被比对控件的上侧时
                    {
                        Lines.Add(new Line(new Point(vNodeRect.Right, vNodeRect.Top), new Point(sNode.RectInPage.Right, sNodeRect.Bottom)));
                    }
                    else
                    {
                        Lines.Add(new Line(new Point(sNode.RectInPage.Right, sNodeRect.Top), new Point(vNodeRect.Right, vNodeRect.Bottom)));
                    }

                    alreadyAlign = true;
                    break;
                }
                else if ((0 != sNode.AliCompX) && (sNode.AliNode.Id == vNode.Id))
                {
                    sNode.X += sNode.AliCompX;
                    sNode.AliCompX = 0;

                    alreadyAlign = true;
                    break;
                }

                int sideTop = sNodeRect.Top - vNodeRect.Top; // 上边沿比对
                int compensateTop = sideTop + sNode.AliCompY;
                int sideBottom = sNodeRect.Bottom - vNodeRect.Bottom; // 下边沿比对
                int compensateBottom = sideBottom + sNode.AliCompY;
                if ((compensateTop >= 0) && (compensateTop <= 5))   // 比对控件与被比对控件的顶部距离差在[0,5)之间时
                {
                    if (UIEditor.Entity.ViewNode.ControlState.Move == sNode.State) // 仅控件处于移动状态时才产生吸附效应
                    {
                        sNode.Y = sNode.GetLocationYFromLocationYInPage(vNodeRect.Top);
                        sNode.AliCompY += sideTop;
                        sNode.AliNode = vNode;
                    }

                    if (sNodeRect.Left > vNodeRect.Left) // 比对控件在被比对控件的左侧
                    {
                        Lines.Add(new Line(new Point(vNodeRect.Left, vNodeRect.Top - 1), new Point(sNodeRect.Right, sNode.RectInPage.Top - 1)));
                    }
                    else // 比对控件在被比对控件的右侧或两者的起始点重合时
                    {
                        Lines.Add(new Line(new Point(sNodeRect.Left, sNode.RectInPage.Top - 1), new Point(vNodeRect.Right, vNodeRect.Top - 1)));
                    }

                    alreadyAlign = true;
                    break;
                }
                else if ((compensateBottom >= -5) && (compensateBottom <= 0)) // 比对控件与被比对控件的底部距离差在[0,5)之间时
                {
                    if (UIEditor.Entity.ViewNode.ControlState.Move == sNode.State)  // 仅控件处于移动状态时才产生吸附效应
                    {
                        sNode.Y = sNode.GetLocationYFromLocationBottomInPage(vNodeRect.Bottom);
                        sNode.AliCompY += sideBottom;
                        sNode.AliNode = vNode;
                    }

                    if (sNodeRect.Left > vNodeRect.Left) // 比对控件在被比对控件的左侧
                    {
                        Lines.Add(new Line(new Point(vNodeRect.Left, vNodeRect.Bottom), new Point(sNodeRect.Right, sNode.RectInPage.Bottom)));
                    }
                    else
                    {
                        Lines.Add(new Line(new Point(sNodeRect.Left, sNode.RectInPage.Bottom), new Point(vNodeRect.Right, vNodeRect.Bottom)));
                    }

                    alreadyAlign = true;
                    break;
                }
                else if ((0 != sNode.AliCompY) && (sNode.AliNode.Id == vNode.Id))
                {
                    sNode.Y += sNode.AliCompY;
                    sNode.AliCompY = 0;

                    alreadyAlign = true;
                    break;
                }

                /* 若被比对控件还包含子控件,则继续与其子控件进行边沿比对 */
                if (vNode.Nodes.Count > 0)
                {
                    alreadyAlign = ControlsAlignment(vNode, sNode, Lines);
                    if (alreadyAlign)
                    {
                        break;
                    }
                }
            }

            return alreadyAlign;
        }
Beispiel #6
0
 private void AddSelectedNode(ViewNode node)
 {
     node.IsSelected = true;
     node.ParCompX = 0;
     node.ParCompY = 0;
     node.ParNode = null;
     node.GapCompX = 0;
     node.GapCompY = 0;
     node.GapNode = null;
     node.AliCompX = 0;
     node.AliCompY = 0;
     node.AliNode = null;
     this.SelectedNodes.Add(node);
 }
Beispiel #7
0
 /// <summary>
 /// 用鼠标拖出的矩形框框选控件
 /// </summary>
 /// <param name="node"></param>
 private void BoxControl(ViewNode node)
 {
     foreach (ViewNode cNode in node.Nodes)
     {
         if (this.RectFrame.IntersectsWith(cNode.VisibleRectInPage))
         {
             AddSelectedNode(cNode);
         }
     }
 }
Beispiel #8
0
 public void RefreshControls(ViewNode node)
 {
     this.Invalidate(node.FrameBound, false);
 }
Beispiel #9
0
        public void SetSelectedControl(ViewNode node)
        {
            ClearSelectedNodes();
            //node.IsSelected = true;
            //this.SelectedNodes.Add(node);
            AddSelectedNode(node);

            this.Refresh();
        }
Beispiel #10
0
 public void ControlPropertyChanged(ViewNode node)
 {
     this.Refresh();
 }
Beispiel #11
0
 public void DeleteControl(ViewNode node)
 {
     this.Controls.Remove(node.panel);
     this.Controls.Remove(node.fc);
     this.Refresh();
 }
Beispiel #12
0
 public void AddControl(ViewNode node)
 {
     //this.Refresh();
     RefreshControls(node);
 }
Beispiel #13
0
        /// <summary>
        /// 从父控件移出、移到新的父控件
        /// </summary>
        /// <param name="cNode"></param>
        /// <param name="e"></param>
        private void MoveOutIn(ViewNode cNode, Point p)
        {
            GetContainsPointNodes(p);

            //Point locationInPage = cNode.LocationInPage;
            ViewNode pNode = cNode.Parent as ViewNode;
            if (pNode.VisibleRectInPage.Contains(p)) // 拖动子控件的鼠标位置还在子控件的父控件中
            {
                Console.WriteLine("MoveOutIn:" + pNode.VisibleRectInPage + " " + p);
                ViewNode topGroupBoxNode = null;
                if (MyConst.Controls.KnxGroupBoxType == cNode.Name) // 拖动的子控件为GroupBox类型
                {
                    topGroupBoxNode = GetTopGroupBoxNodeExceptNode(cNode);
                }
                else
                {
                    topGroupBoxNode = GetTopGroupBoxNode();
                }

                if (null != topGroupBoxNode && topGroupBoxNode != cNode && topGroupBoxNode != pNode)
                {
                    foreach (ViewNode node in this.SelectedNodes)
                    {
                        Point locationInPage = node.LocationInPage;
                        this.cqp.ExecuteCommand(new TreeNodeRemove(node.TreeView, node));

                        this.cqp.ExecuteCommand(new TreeNodeAdd(topGroupBoxNode.TreeView, topGroupBoxNode, node, -1));
                        Point loc = ViewNode.GetLocationInParent(topGroupBoxNode.LocationInPage, locationInPage);
                        node.X = loc.X;
                        node.Y = loc.Y;
                    }
                    topGroupBoxNode.Expand();
                }
            }
            else
            {
                ViewNode topGroupBoxNode = null;
                if (MyConst.Controls.KnxGroupBoxType == cNode.Name)
                {
                    topGroupBoxNode = GetTopGroupBoxNodeExceptNode(cNode);
                }
                else
                {
                    topGroupBoxNode = GetTopGroupBoxNode();
                }

                if (null != topGroupBoxNode)
                {
                    if (topGroupBoxNode != cNode)
                    {
                        foreach (ViewNode node in this.SelectedNodes)
                        {
                            Point locationInPage = node.LocationInPage;
                            this.cqp.ExecuteCommand(new TreeNodeRemove(node.TreeView, node));

                            this.cqp.ExecuteCommand(new TreeNodeAdd(topGroupBoxNode.TreeView, topGroupBoxNode, node, -1));
                            Point loc = ViewNode.GetLocationInParent(topGroupBoxNode.LocationInPage, locationInPage);
                            node.X = loc.X;
                            node.Y = loc.Y;
                        }
                        topGroupBoxNode.Expand();
                    }
                }
                else
                {
                    foreach (ViewNode node in this.SelectedNodes)
                    {
                        Point locationInPage = node.LocationInPage;
                        this.cqp.ExecuteCommand(new TreeNodeRemove(node.TreeView, node));

                        this.cqp.ExecuteCommand(new TreeNodeAdd(this.node.TreeView, this.node, node, -1));
                        Point loc = ViewNode.GetLocationInParent(new Point(this.node.X, this.node.Y), locationInPage);
                        node.X = loc.X;
                        node.Y = loc.Y;
                    }
                    this.node.Expand();
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// 获取当前鼠标位置除了gbNode以外的最顶层的GroupBox
        /// </summary>
        /// <param name="gbNode"></param>
        /// <returns></returns>
        private GroupBoxNode GetTopGroupBoxNodeExceptNode(ViewNode gbNode)
        {
            int count = this.ContainsPointNodes.Count;
            if (count > 0)
            {
                /* 在Z向上从上至下搜寻GroupBox */
                bool start = false;
                for (int i = count - 1; i >= 0; i--)
                {
                    GroupBoxNode node = this.ContainsPointNodes[i] as GroupBoxNode;
                    if (null != node) // 确认node为GroupBox
                    {
                        if (node.Id == gbNode.Id)
                        {
                            start = true;
                            continue;
                        }
                        else if (start) // 从gbNode之下开始找GroupNode
                        {
                            return node;
                        }
                        else // node在gbNode之上
                        {
                            if (!ContainsChildNode(gbNode, node))
                            {
                                return node;
                            }
                        }

                    }

                }

                return null;
            }
            else
            {
                return null;
            }
        }
Beispiel #15
0
 private void SetSelectedNode(ViewNode node)
 {
     this.curSelectedNode = node;
     this.ucdo.SetSelectedNode(node);
     this.ucProperty.DisplayNode(node);
 }
Beispiel #16
0
        private void ProjectChanged(ViewNode node)
        {
            this.Saved = false;

            switch (node.Name)
            {
                case MyConst.View.KnxAppType:
                case MyConst.View.KnxAreaType:
                case MyConst.View.KnxRoomType:
                    break;

                case MyConst.View.KnxPageType:
                    SetTabPageTitle(node.Id.ToString(), node.Text + " " + "*");
                    break;

                default:
                    PageNode pageNode = GetPageNodeFromParent(node);
                    if (null != pageNode)
                    {
                        SetTabPageTitle(pageNode.Id.ToString(), pageNode.Text + " " + "*");
                    }
                    break;
            }
        }