コード例 #1
0
        /// <summary>
        /// 保存矩形
        /// </summary>
        public void SaveRects()
        {
            float x = DrawPanel.CurZoom;

            DrawPanel.CurZoom = 1;
            Dictionary <string, XmlElement> _tempSnips = TmpltDoc.GetAllSnipElementClone();
            XmlElement docEle = (XmlElement)TmpltDoc.DocumentElement.SelectSingleNode("rects");

            docEle.RemoveAll();

            RectLayer boundaryRect = new RectLayer(0, 0, DrawPanel.Width, DrawPanel.Height, TmpltDoc.TmpltCss);

            LineToRect(boundaryRect);


            AddRectToXml(docEle, new RectTreeNode(boundaryRect, null));

            XmlNodeList snipNodes = docEle.SelectNodes(@"//snip");

            foreach (XmlNode snipNode in snipNodes)
            {
                if (snipNode.NodeType == XmlNodeType.Element)
                {
                    SnipXmlElement snipEle = (SnipXmlElement)snipNode;
                    string         id      = snipEle.Id;
                    if (_tempSnips.ContainsKey(id))
                    {
                        CssSection tempCss = CssSection.Parse(snipEle.GetAttribute("css"));
                        XmlUtilService.CopyXmlElement(_tempSnips[id], snipEle);
                        snipEle.Width  = tempCss.Properties["width"];
                        snipEle.Height = tempCss.Properties["height"];
                        snipEle.Css    = tempCss.ToString();
                    }
                }
            }
            DrawPanel.CurZoom = x;

            TmpltDoc.Reseted = true;
        }
コード例 #2
0
 public FindLindByRectAndRow(RectLayer rect, bool isRow)
 {
     this.Rect  = rect;
     this.IsRow = isRow;
 }
コード例 #3
0
 public RectTreeNode(RectLayer rect, XmlElement xmlEle)
 {
     this.Element   = xmlEle;
     this.RectLayer = rect;
 }
コード例 #4
0
        ///// <summary>
        ///// 生成div层次关系
        ///// </summary>
        //private void MakeDivLayer()
        //{
        //    RectLayer boundaryRect = new RectLayer(0, 0, DrawPanel.Width, DrawPanel.Height,TmpltDoc.TmpltCss);
        //    LineToRect(boundaryRect);
        //    WriteRectLayer(boundaryRect);
        //}

        ///// <summary>
        ///// 将层次化的矩形写入XML,使用树的宽度遍历算法
        ///// </summary>
        ///// <param name="rect"></param>
        //private void WriteRectLayer(RectLayer rect)
        //{
        //    XmlDocument xmlDoc = new XmlDocument();
        //    string str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<body></body>";

        //    xmlDoc.LoadXml(str);
        //    //xmlDoc.Load(@"D:\shiyitang\div.xml");

        //    XmlElement xmlElement = xmlDoc.DocumentElement;
        //    XmlElement xmlEleTmp = null;

        //    Queue<RectTreeNode> que = new Queue<RectTreeNode>();
        //    que.Enqueue(new RectTreeNode(rect, xmlElement));

        //    RectTreeNode curNode = null;
        //    Rect resultRect = null;

        //    while (que.Count > 0)
        //    {
        //        //访问本结点
        //        curNode = que.Dequeue();
        //        resultRect = DrawPanel.ListRect.SnipRectList.Find(
        //            new FindRectByLayerRect(curNode.RectLayer).PredicateEqualRect);
        //        if (resultRect != null)
        //        {
        //            curNode.Element.SetAttribute("snippage_id", ((SnipRect)resultRect).SnipID);
        //        }

        //        //如果有孩子,则孩子结点入队
        //        if (curNode.RectLayer.ChildRects != null)
        //        {
        //            foreach (RectLayer childRect in curNode.RectLayer.ChildRects)
        //            {
        //                xmlEleTmp = xmlDoc.CreateElement("div");
        //                curNode.Element.AppendChild(xmlEleTmp);//置其为孩子

        //                que.Enqueue(new RectTreeNode(childRect, xmlEleTmp));
        //            }
        //        }
        //    }
        //    xmlDoc.Save(@"d:\" + TmpltID + @".xml");
        //}

        /// <summary>
        /// 递归实现将分割线转化为矩形
        /// </summary>
        /// <param name="snipRect"></param>
        private void LineToRect(RectLayer snipRect)
        {
            if (snipRect == null)
            {
                return;
            }

            FindLindByRectAndRow findRectPartion;   ///寻找能以给定方向(isRow)切割给定矩形之分割线
            FindLineByLine       findLinePartion;   ///寻找能与给定直线正交之分割线
            FindLineByLine       findLineTo;        /// 寻找终点位于给定直线之分割线
            List <PartitionLine> resultRectPartion; ///找到与给定方向(isRow)切割给定矩形之分割线的结果集
            List <PartitionLine> resultLinePartion; ///找到与给定直线正交之分割线的结果集
            RectLayer            Rect;

            ///行优先寻找能横向切割矩形的分割线
            findRectPartion   = new FindLindByRectAndRow(snipRect, true);
            resultRectPartion = DrawPanel.HPartionLines.FindAll(new Predicate <PartitionLine>(findRectPartion.Predicate));
            if (resultRectPartion.Count > 2)//找到横向切割线,2为两个边界线
            {
                snipRect.IsRow = true;
                resultRectPartion.Sort(new CompareLinePosition());
                if (snipRect.ChildRects == null)//如果还没有new出childRects,则创建
                {
                    snipRect.ChildRects = new List <RectLayer>();
                }

                ///循环生成页面矩形
                int i;
                for (i = 1; i < resultRectPartion.Count; i++)
                {
                    Rect = new RectLayer(snipRect.X,
                                         resultRectPartion[i - 1].Position,
                                         snipRect.Width,
                                         resultRectPartion[i].Position - resultRectPartion[i - 1].Position,
                                         "");
                    snipRect.ChildRects.Add(Rect);
                    LineToRect(Rect);
                }
            }
            else///没有横向切割线,则纵向寻找
            {
                snipRect.IsRow    = false;
                findRectPartion   = new FindLindByRectAndRow(snipRect, false);
                resultRectPartion = DrawPanel.VPartionLines.FindAll(new Predicate <PartitionLine>(findRectPartion.Predicate));

                if (resultRectPartion.Count > 2)///找到纵向切割线
                {
                    resultRectPartion.Sort(new CompareLinePosition());

                    if (snipRect.ChildRects == null)///如果还没有new出childRects,则创建
                    {
                        snipRect.ChildRects = new List <RectLayer>();
                    }
                    int i = 0, j = 0;
                    while (i < resultRectPartion.Count - 1)
                    {
                        PartitionLine conditionLine = new PartitionLine(
                            snipRect.Y, snipRect.Y + snipRect.Height, resultRectPartion[i].Position, false
                            );///此分割线实质上是此矩的左边界的向右偏移
                        findLinePartion   = new FindLineByLine(conditionLine);
                        resultLinePartion = DrawPanel.HPartionLines.FindAll(new Predicate <PartitionLine>(findLinePartion.PredicatePartedLineRight));
                        if (resultLinePartion.Count > 0)///找到所有与给定线相交的分割线
                        {
                            resultLinePartion.Sort(new CompareLineLen(resultRectPartion[i]));
                            findLineTo = new FindLineByLine(resultLinePartion[0]);
                            j          = i;
                            i          = resultRectPartion.FindLastIndex(
                                new Predicate <PartitionLine>(findLineTo.PredicateLineTo)
                                );
                            if (i == -1)///如果没有找到,说明此正交分割线没有终止于结果集的任何一条分割线
                            ///此时,结果应该是最后一条
                            {
                                i = resultRectPartion.Count - 1;
                            }
                            Rect = new RectLayer(
                                resultRectPartion[j].Position,
                                snipRect.Y,
                                resultRectPartion[i].Position - resultRectPartion[j].Position,
                                snipRect.Height, "");
                            snipRect.ChildRects.Add(Rect);
                            LineToRect(Rect);
                        }
                        else//没有与之下次之直线,则形成一个新矩形
                        {
                            j = i;
                            ++i;
                            Rect = new RectLayer(
                                resultRectPartion[j].Position,
                                snipRect.Y,
                                resultRectPartion[i].Position - resultRectPartion[j].Position,
                                snipRect.Height, "");
                            snipRect.ChildRects.Add(Rect);
                            LineToRect(Rect);
                        }
                    }
                }
            }
        }
コード例 #5
0
 public FindRectByLayerRect(RectLayer rect)
 {
     Rect = rect;
 }