コード例 #1
0
ファイル: TreeBuilder.cs プロジェクト: serg1236/images-search
        /// <summary>
        /// Creates the tree
        /// </summary>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        /// <param name="StartFromNodeID"></param>
        /// <param name="ImageType"></param>
        /// <returns></returns>
        public System.IO.Stream GenerateTree(int Width,
                                             int Height,
                                             string StartFromNodeID,
                                             ImageFormat ImageType)
        {
            MemoryStream Result = new MemoryStream();



            //reset image size
            imgHeight = 0;
            imgWidth  = 0;
            //reset percentage change
            PercentageChangeX = 1.0;
            PercentageChangeY = 1.0;
            //define the image
            nodeTree = null;
            nodeTree = new XmlDocument();
            string rootDescription = string.Empty;
            string rootNote        = string.Empty;

            if (dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID)).Length > 0)
            {
                rootDescription = ((TreeData.TreeDataTableRow)dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID))[0]).nodeDescription;
                rootNote        = ((TreeData.TreeDataTableRow)dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID))[0]).nodeNote;
            }

            XmlNode RootNode = GetXMLNode(StartFromNodeID, rootDescription, rootNote);

            nodeTree.AppendChild(RootNode);
            BuildTree(RootNode, 0);

            //check for intersection. line below should be remarked if not debugging
            //as it affects performance measurably.
            //OverlapExists();
            Bitmap bmp = new Bitmap(imgWidth, imgHeight + _VerticalSpace);

            gr = Graphics.FromImage(bmp);
            gr.Clear(_BGColor);
            DrawChart(RootNode, _LineColor);

            //if caller does not care about size, use original calculated size
            if (Width < 0)
            {
                Width = imgWidth;
            }
            if (Height < 0)
            {
                Height = imgHeight;
            }

            Bitmap ResizedBMP = new Bitmap(bmp, new Size(Width, Height));

            //after resize, determine the change percentage
            PercentageChangeX = Convert.ToDouble(Width) / imgWidth;
            PercentageChangeY = Convert.ToDouble(Height) / imgHeight;
            //after resize - change the coordinates of the list, in order return the proper coordinates
            //for each node
            if (PercentageChangeX != 1.0 || PercentageChangeY != 1.0)
            {
                //only resize coordinates if there was a resize
                CalculateImageMapData();
            }
            ResizedBMP.Save(Result, ImageType);
            ResizedBMP.Dispose();
            bmp.Dispose();
            gr.Dispose();
            return(Result);
        }
コード例 #2
0
ファイル: TreeBuilder.cs プロジェクト: BrentKnowles/flow2
        /// <summary>
        /// Creates the tree
        /// </summary>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        /// <param name="StartFromNodeID"></param>
        /// <param name="ImageType"></param>
        /// <returns></returns>
        public System.IO.Stream GenerateTree(int Width,
                                             int Height,
                                             string StartFromNodeID,
                                             ImageFormat ImageType, bool ShowCategory, bool ShowOverridePerson)
        {
            MemoryStream Result = new MemoryStream();

            _showCategory       = ShowCategory;
            _showOverridePerson = ShowOverridePerson;


            //reset image size
            imgHeight = 0;
            imgWidth  = 0;
            //reset percentage change
            PercentageChangeX = 1.0;
            PercentageChangeY = 1.0;
            //define the image
            nodeTree = null;
            nodeTree = new XmlDocument();
            string rootDescription = string.Empty;
            string rootNote        = string.Empty;
            string rootCategory    = string.Empty;
            string rootSOD         = string.Empty;

            if (dtTree == null)
            {
                return(null);
            }

            if (dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID)).Length > 0)
            {
                rootDescription = ((TreeData.TreeDataTableRow)dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID))[0]).nodeDescription;
                rootNote        = ((TreeData.TreeDataTableRow)dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID))[0]).nodeNote;
                rootCategory    = ((TreeData.TreeDataTableRow)dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID))[0]).nodeCategory;
                rootSOD         = ((TreeData.TreeDataTableRow)dtTree.Select(string.Format("nodeID='{0}'", StartFromNodeID))[0]).nodeSOD;
            }

            XmlNode RootNode = GetXMLNode(StartFromNodeID, rootDescription, rootNote, rootCategory, rootSOD, -1);

            nodeTree.AppendChild(RootNode);
            BuildTree(RootNode, 0);

            //check for intersection. line below should be remarked if not debugging
            //as it affects performance measurably.
            //OverlapExists();
            Bitmap bmp = new Bitmap(imgWidth, imgHeight);

            gr = Graphics.FromImage(bmp);
            gr.Clear(_BGColor);
            DrawChart(RootNode);

            foreach (lineToLine liner in listOfLinesToAdd)
            {
                Rectangle source = new Rectangle(0, 0, 0, 0);
                Rectangle dest   = new Rectangle(0, 0, 0, 0);
                foreach (Regions region in listOfBoxRegions)
                {
                    if (region.name.Trim() == liner.source)
                    {
                        source = region.Rect;
                    }
                    else
                    if (region.name.Trim() == liner.dest)
                    {
                        dest = region.Rect;
                    }
                }



                Pen extraPen = new Pen(Color.Pink, _LineWidth);
                // draw an extra line
                gr.DrawLine(extraPen, source.Right,
                            source.Bottom,
                            dest.Left,
                            dest.Top);


                gr.DrawLine(extraPen, 10,
                            100,
                            100,
                            100);
            }


            //if caller does not care about size, use original calculated size
            if (Width < 0)
            {
                Width = imgWidth;
            }
            if (Height < 0)
            {
                Height = imgHeight;
            }

            Bitmap ResizedBMP = new Bitmap(bmp, new Size(Width, Height));

            //after resize, determine the change percentage
            PercentageChangeX = Convert.ToDouble(Width) / imgWidth;
            PercentageChangeY = Convert.ToDouble(Height) / imgHeight;
            //after resize - change the coordinates of the list, in order return the proper coordinates
            //for each node
            if (PercentageChangeX != 1.0 || PercentageChangeY != 1.0)
            {
                //only resize coordinates if there was a resize
                CalculateImageMapData();
            }
            ResizedBMP.Save(Result, ImageType);
            ResizedBMP.Dispose();
            bmp.Dispose();
            gr.Dispose();
            return(Result);
        }