GetBounds() private method

private GetBounds ( ) : RectangleF
return RectangleF
Exemplo n.º 1
0
        public override void DrawShapeOnGraphics(GraphicsPath shapeAsGraphicsPath, Graphics g)
        {
            styleToDecorate.DrawShapeOnGraphics(shapeAsGraphicsPath, g);

              Region shapeAsRegion = new Region(shapeAsGraphicsPath);
              RectangleF rr = shapeAsRegion.GetBounds(g);
              CreateGradient(rr);
              g.FillRegion(styleToDecorate.fillBrush_, shapeAsRegion);
        }
Exemplo n.º 2
0
        public void AddObject(Region path, string layer, ToolTipInfo toolTipInfo, System.Drawing.Graphics g)
        {
            lock (m_QuadTree)
            {
                RectangleF rf = path.GetBounds(g);
                Envelope env = new Envelope(rf.Left, rf.Right, rf.Bottom, rf.Top);

                m_QuadTree.Insert(env, new QuickInfoObject(path, layer, toolTipInfo, env));
            }
        }
Exemplo n.º 3
0
		// a region with an "empty ctor" graphic path is "empty" (i.e. not infinite)
		private void CheckEmpty (string prefix, Region region)
		{
			Assert.IsTrue (region.IsEmpty (graphic), prefix + "IsEmpty");
			Assert.IsFalse (region.IsInfinite (graphic), prefix + "graphic");

			RectangleF rect = region.GetBounds (graphic);
			Assert.AreEqual (0f, rect.X, prefix + "GetBounds.X");
			Assert.AreEqual (0f, rect.Y, prefix + "GetBounds.Y");
			Assert.AreEqual (0f, rect.Width, prefix + "GetBounds.Width");
			Assert.AreEqual (0f, rect.Height, prefix + "GetBounds.Height");
		}
Exemplo n.º 4
0
        private Vector2D method_3(string text, IList <Vector2D> characterAdvances)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(Vector2D.Zero);
            }
            Vector2D vector2D        = Vector2D.Zero;
            Graphics measureGraphics = Class940.MeasureGraphics;

            if (characterAdvances != null)
            {
                CharacterRange[] ranges = new CharacterRange[text.Length];
                for (int First = 0; First < text.Length; ++First)
                {
                    ranges[First] = new CharacterRange(First, 1);
                }
                StringFormat stringFormat = new StringFormat(StringFormat.GenericTypographic);
                stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap;
                stringFormat.SetMeasurableCharacterRanges(ranges);
                System.Drawing.Region[] regionArray = measureGraphics.MeasureCharacterRanges(text, this.class1060_0.Font, (RectangleF)Rectangle.Empty, stringFormat);
                if (regionArray.Length > 0)
                {
                    for (int index = 0; index < regionArray.Length; ++index)
                    {
                        System.Drawing.Region region = regionArray[index];
                        RectangleF            bounds = region.GetBounds(measureGraphics);
                        region.Dispose();
                        vector2D = new Vector2D((double)bounds.Right, 0.0);
                        characterAdvances.Add(vector2D);
                    }
                }
                stringFormat.Dispose();
            }
            else
            {
                CharacterRange[] ranges = new CharacterRange[1] {
                    new CharacterRange(0, text.Length)
                };
                StringFormat stringFormat = new StringFormat(StringFormat.GenericTypographic);
                stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap;
                stringFormat.SetMeasurableCharacterRanges(ranges);
                System.Drawing.Region[] regionArray = measureGraphics.MeasureCharacterRanges(text, this.class1060_0.Font, (RectangleF)Rectangle.Empty, stringFormat);
                if (regionArray.Length > 0)
                {
                    System.Drawing.Region region = regionArray[regionArray.Length - 1];
                    RectangleF            bounds = region.GetBounds(measureGraphics);
                    region.Dispose();
                    vector2D = new Vector2D((double)bounds.Right, 0.0);
                }
                stringFormat.Dispose();
            }
            return(vector2D);
        }
Exemplo n.º 5
0
		public void TestBounds()
		{
			Bitmap bmp = new Bitmap (600, 800);
			Graphics dc = Graphics.FromImage (bmp);
			Rectangle rect1, rect2;
			Region rgn1, rgn2;
			RectangleF bounds;

			rect1 = new Rectangle (500, 30, 60, 80);
			rect2 = new Rectangle (520, 40, 60, 80);
			rgn1 = new Region(rect1);
			rgn2 = new Region(rect2);
			rgn1.Union(rgn2);

			bounds = rgn1.GetBounds (dc);

			Assert.AreEqual (500, bounds.X);
			Assert.AreEqual (30, bounds.Y);
			Assert.AreEqual (80, bounds.Width);
			Assert.AreEqual (90, bounds.Height);
		}
 /// <summary>
 /// OnPaint will go through the enabled elements (vertical ReminderMessage, GridLines, LineNumbers, BorderLines,
 /// MarginLines) and will draw them if enabled. At the same time, it will build GraphicsPaths for each of those
 /// elements (that are enabled), which will be used in SeeThroughMode (if it's active): the figures in the
 /// GraphicsPaths will form a customized outline for the control by setting them as the Region of the LineNumber
 /// control. Note: the vertical ReminderMessages are only drawn during designtime. 
 /// </summary>
 /// <param name="e"></param>
 protected override void OnPaint(PaintEventArgs e)
 {
     // Build the list of visible LineNumberItems (= pLineNumberItems) first. (doesn't take long, so it can stay in OnPaint)
     UpdateVisibleLineNumberItems();
     base.OnPaint(e);
     // Quality settings
     e.Graphics.TextRenderingHint = pLineNumbersAntiAlias ? TextRenderingHint.AntiAlias : TextRenderingHint.SystemDefault;
     // NOTE: The GraphicsPaths are only used for SeeThroughMode
     // FillMode.Winding: combined outline ( Alternate: XOR'ed outline )
     GraphicsPath gpGridLines = new GraphicsPath(FillMode.Winding);
     GraphicsPath gpBorderLines = new GraphicsPath(FillMode.Winding);
     GraphicsPath gpMarginLines = new GraphicsPath(FillMode.Winding);
     GraphicsPath gpLineNumbers = new GraphicsPath(FillMode.Winding);
     if (DesignMode)
     {
         string reminderToShow = string.Empty;
         if (RTParent == null)
         {
             reminderToShow = "-!- Set ParentRichTextBox -!-";
         }
         else if (pLineNumberItems.Count == 0)
         {
             reminderToShow = "LineNumbers (  " + RTParent.Name + "  )";
         }
         if (reminderToShow.Length > 0)
         {
             e.Graphics.TranslateTransform(Width / 2f, Height / 2f);
             e.Graphics.RotateTransform(-90f);
             StringFormat format = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
             SizeF textSize = e.Graphics.MeasureString(reminderToShow, Font, new Point(0, 0), format);
             e.Graphics.DrawString(reminderToShow, Font, Brushes.WhiteSmoke, 1f, 1f, format);
             e.Graphics.DrawString(reminderToShow, Font, Brushes.Firebrick, 0f, 0f, format);
             e.Graphics.ResetTransform();
             Rectangle reminderRectangle = new Rectangle((int)Math.Round((Width / 2.0) - (textSize.Height / 2.0)),
                                                          (int)Math.Round((Height / 2.0) - (textSize.Width / 2.0)),
                                                          (int)Math.Round(textSize.Height), (int)Math.Round(textSize.Width));
             gpLineNumbers.AddRectangle(reminderRectangle);
             gpLineNumbers.CloseFigure();
             if (pAutoSizing)
             {
                 reminderRectangle.Inflate((int)Math.Round(textSize.Height * 0.2), (int)Math.Round(textSize.Width * 0.1));
                 pAutoSizingSize = new Size(reminderRectangle.Width, reminderRectangle.Height);
             }
         }
     }
     if (pLineNumberItems.Count > 0)
     {
         // The visible LineNumberItems with their BackgroundGradient and GridLines
         // Loop through every visible LineNumberItem
         using (Pen pen = new Pen(pGridLinesColor, pGridLinesThickness) { DashStyle = pGridLinesStyle })
         {
             StringFormat format = new StringFormat
             {
                 Alignment = StringAlignment.Near,
                 LineAlignment = StringAlignment.Near,
                 FormatFlags =
                     StringFormatFlags.NoClip | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox
             };
             for (int i = 0; i <= pLineNumberItems.Count - 1; i++)
             {
                 // Background gradient
                 if (pGradientShow)
                 {
                     using (LinearGradientBrush brush = new LinearGradientBrush(pLineNumberItems[i].Rectangle,
                         pGradientStartColor, pGradientEndColor, pGradientDirection))
                     {
                         e.Graphics.FillRectangle(brush, pLineNumberItems[i].Rectangle);
                     }
                 }
                 // Grid lines
                 if (pGridLinesShow)
                 {
                     e.Graphics.DrawLine(pen, new Point(0, pLineNumberItems[i].Rectangle.Y),
                         new Point(Width, pLineNumberItems[i].Rectangle.Y));
                     Rectangle rect = new Rectangle((int)Math.Round(-pGridLinesThickness), pLineNumberItems[i].Rectangle.Y,
                         (int)Math.Round(Width + (pGridLinesThickness * 2.0)),
                         (int)Math.Round((Height - pLineNumberItems[0].Rectangle.Y) + pGridLinesThickness));
                     gpGridLines.AddRectangle(rect);
                     gpGridLines.CloseFigure();
                 }
                 // Line numbers
                 if (pLineNumbersShow)
                 {
                     string textToShow;
                     if (pLineNumbersShowLeadingZeroes)
                     {
                         textToShow = pLineNumbersShowAsHexadecimal
                                         ? pLineNumberItems[i].LineNumber.ToString("X4")
                                         : pLineNumberItems[i].LineNumber.ToString("D4");
                     }
                     else
                     {
                         textToShow = pLineNumbersShowAsHexadecimal
                                         ? pLineNumberItems[i].LineNumber.ToString("X4")
                                         : pLineNumberItems[i].LineNumber.ToString("D4");
                     }
                     Point point = new Point(0, 0);
                     SizeF textSize = e.Graphics.MeasureString(textToShow, Font, point, format);
                     // Text alignment
                     point = GetAlignmentPoint(textSize, pLineNumberItems[i]);
                     // Text clipping
                     Rectangle itemClipRectangle = new Rectangle(point, textSize.ToSize());
                     if (pLineNumbersClipByItemRectangle)
                     {
                         // If selected, the text will be clipped so that it doesn't spill out of its own
                         // LineNumberItem-area. Only the part of the text inside the LineNumberItem.
                         // Rectangle should be visible, so intersect with the ItemRectangle.
                         // The SetClip method temporary restricts the drawing area of the control for whatever
                         // is drawn next.
                         itemClipRectangle.Intersect(pLineNumberItems[i].Rectangle);
                         e.Graphics.SetClip(itemClipRectangle);
                     }
                     // Text drawing
                     using (SolidBrush brush = new SolidBrush(ForeColor))
                     {
                         e.Graphics.DrawString(textToShow, Font, brush, point, format);
                         e.Graphics.ResetClip();
                     }
                     // The GraphicsPath for the LineNumber is just a rectangle behind the text, to keep the paintingspeed high and avoid ugly artifacts.
                     gpLineNumbers.AddRectangle(itemClipRectangle);
                     gpLineNumbers.CloseFigure();
                 }
             }
             // Grid lines thickness and linestyle in SeeThroughMode. All GraphicsPath lines are drawn as solid to keep the paintingspeed high.
             if (pGridLinesShow)
             {
                 pen.DashStyle = DashStyle.Solid;
                 gpGridLines.Widen(pen);
             }
         }
     }
     Point left = new Point((int)Math.Round(Math.Floor(pBorderLinesThickness / 2.0)),
                              (int)Math.Round(Math.Floor(pBorderLinesThickness / 2.0)));
     Point right = new Point((int)Math.Round(Width - Math.Ceiling(pBorderLinesThickness / 2.0)),
                               (int)Math.Round(Height - Math.Ceiling(pBorderLinesThickness / 2.0)));
     // Border lines
     Point[] borderLinesPoints = new Point[5];
     borderLinesPoints[0] = new Point(left.X, left.Y);
     borderLinesPoints[1] = new Point(right.X, left.Y);
     borderLinesPoints[2] = new Point(right.X, right.Y);
     borderLinesPoints[3] = new Point(left.X, right.Y);
     borderLinesPoints[4] = new Point(left.X, left.Y);
     if (pBorderLinesShow)
     {
         using (Pen pen = new Pen(pBorderLinesColor, pBorderLinesThickness) { DashStyle = pBorderLinesStyle })
         {
             e.Graphics.DrawLines(pen, borderLinesPoints);
             gpBorderLines.AddLines(borderLinesPoints);
             gpBorderLines.CloseFigure();
             pen.DashStyle = DashStyle.Solid;
             gpBorderLines.Widen(pen);
         }
     }
     // Margin lines
     if (pMarginLinesShow && (pMarginLinesSide > LineNumberDockSide.None))
     {
         left = new Point((int)Math.Round(-pMarginLinesThickness), (int)Math.Round(-pMarginLinesThickness));
         right = new Point((int)Math.Round(Width + pMarginLinesThickness),
                             (int)Math.Round(Height + pMarginLinesThickness));
         using (Pen pen = new Pen(pMarginLinesColor, pMarginLinesThickness) { DashStyle = pMarginLinesStyle })
         {
             if ((pMarginLinesSide == LineNumberDockSide.Left) | (pMarginLinesSide == LineNumberDockSide.Height))
             {
                 e.Graphics.DrawLine(pen, new Point((int)Math.Round(Math.Floor(pMarginLinesThickness / 2.0)), 0),
                                     new Point((int)Math.Round(Math.Floor(pMarginLinesThickness / 2.0)), Height - 1));
                 left = new Point((int)Math.Round(Math.Ceiling(pMarginLinesThickness / 2.0)),
                                    (int)Math.Round(-pMarginLinesThickness));
             }
             if ((pMarginLinesSide == LineNumberDockSide.Right) | (pMarginLinesSide == LineNumberDockSide.Height))
             {
                 e.Graphics.DrawLine(pen, new Point((int)Math.Round(Width - Math.Ceiling(pMarginLinesThickness / 2.0)), 0),
                                     new Point((int)Math.Round(Width - Math.Ceiling(pMarginLinesThickness / 2.0)), Height - 1));
                 right = new Point((int)Math.Round(Width - Math.Ceiling(pMarginLinesThickness / 2.0)),
                                     (int)Math.Round(Height + pMarginLinesThickness));
             }
             // GraphicsPath for the MarginLines(s): MarginLines(s) are drawn as a rectangle connecting the left
             // and right points, which are either inside or outside of sight, depending on whether the MarginLines
             // at that side is visible. "left": TopLeft and "right": BottomRight
             gpMarginLines.AddRectangle(new Rectangle(left, new Size(right.X - left.X, right.Y - left.Y)));
             pen.DashStyle = DashStyle.Solid;
             gpMarginLines.Widen(pen);
         }
     }
     Region region = new Region(ClientRectangle);
     // SeeThroughMode: combine all the GraphicsPaths and set them as the region for the control.
     if (pSeeThroughMode)
     {
         region.MakeEmpty();
         region.Union(gpBorderLines);
         region.Union(gpMarginLines);
         region.Union(gpGridLines);
         region.Union(gpLineNumbers);
     }
     if (region.GetBounds(e.Graphics).IsEmpty)
     {
         // Note: If the control is in a condition that would show it as empty, then a border-region is still
         // drawn regardless of it's borders on/off state. This is added to make sure that the bounds of the
         // control are never lost (it would remain empty if this was not done).
         gpBorderLines.AddLines(borderLinesPoints);
         gpBorderLines.CloseFigure();
         using (Pen pen = new Pen(pBorderLinesColor, 1f) { DashStyle = DashStyle.Solid })
         {
             gpBorderLines.Widen(pen);
             region = new Region(gpBorderLines);
         }
     }
     Region = region;
 }
        /// <summary>
        /// Draws a regular buttton in selected state
        /// </summary>
        public void DrawButtonSelected(Graphics g, Rectangle bounds, Corners corners)
        {
            var outerR = Rectangle.FromLTRB(
                bounds.Left,
                bounds.Top,
                bounds.Right - 1,
                bounds.Bottom - 1);

            var innerR = Rectangle.FromLTRB(
                bounds.Left + 1,
                bounds.Top + 1,
                bounds.Right - 2,
                bounds.Bottom - 2);

            var glossyR = Rectangle.FromLTRB(
                bounds.Left + 1,
                bounds.Top + 1,
                bounds.Right - 2,
                bounds.Top + Convert.ToInt32((double)bounds.Height * .36));

            using (var boundsPath = RoundRectangle(outerR, 3, corners))
            {
                using (var brus = new SolidBrush(ColorTable.ButtonSelectedBgOut))
                {
                    g.FillPath(brus, boundsPath);
                }

                #region Main Bg
                using (var path = new GraphicsPath())
                {
                    path.AddEllipse(new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height * 2));
                    path.CloseFigure();
                    using (var gradient = new PathGradientBrush(path))
                    {
                        gradient.WrapMode = WrapMode.Clamp;
                        gradient.CenterPoint = new PointF(
                            Convert.ToSingle(bounds.Left + bounds.Width / 2),
                            Convert.ToSingle(bounds.Bottom));
                        gradient.CenterColor = ColorTable.ButtonSelectedBgCenter;
                        gradient.SurroundColors = new [] { ColorTable.ButtonSelectedBgOut };

                        var lastClip = g.Clip;
                        var newClip = new Region(boundsPath);
                        newClip.Intersect(lastClip);
                        g.SetClip(newClip.GetBounds(g));
                        g.FillPath(gradient, path);
                        g.Clip = lastClip;
                    }
                }
                #endregion

                //Border
                using (var p = new Pen(ColorTable.ButtonSelectedBorderOut))
                {
                    g.DrawPath(p, boundsPath);
                }

                //Inner border
                using (var path = RoundRectangle(innerR, 3, corners))
                {
                    using (var p = new Pen(ColorTable.ButtonSelectedBorderIn))
                    {
                        g.DrawPath(p, path);
                    }
                }

                //Glossy effect
                using (var path = RoundRectangle(glossyR, 3, (corners & Corners.NorthWest) | (corners & Corners.NorthEast)))
                {
                    using (var b = new LinearGradientBrush(
                        glossyR, ColorTable.ButtonSelectedGlossyNorth, ColorTable.ButtonSelectedGlossySouth, 90))
                    {
                        b.WrapMode = WrapMode.TileFlipXY;
                        g.FillPath(b, path);
                    }
                }
            }
        }
        private void RenderItemBackgroundPressed(System.Windows.Forms.ToolStripItemRenderEventArgs e)
        {
           if (Theme.Standard.Style == RibbonOrbStyle.Office_2013)
            {
                Rectangle rectBorder = new Rectangle(1, 1, e.Item.Width - 1, e.Item.Height - 1);
                Rectangle rect = new Rectangle(2, 2, e.Item.Width - 2, e.Item.Height - 2);

                using (SolidBrush b = new SolidBrush(Theme.Standard.RendererColorTable.ButtonPressed_2013))
                {
                   using (SolidBrush sb = new SolidBrush(Theme.Standard.RendererColorTable.ButtonBorderOut))
                    {
                        e.Graphics.FillRectangle(sb, rectBorder);
                    }

                    e.Graphics.FillRectangle(b, rect);
                }
            }
            else
            {
                Rectangle rectBorder = new Rectangle(1, 1, e.Item.Width - 1, e.Item.Height - 1);
                Rectangle rect = new Rectangle(2, 2, e.Item.Width - 2, e.Item.Height - 2);

                Rectangle innerR = Rectangle.FromLTRB(1, 1, e.Item.Width - 2, e.Item.Height - 2);
                Rectangle glossyR = Rectangle.FromLTRB(1, 1, e.Item.Width - 2, 1 + Convert.ToInt32((double)e.Item.Bounds.Height * .36));

                using (SolidBrush brus = new SolidBrush(Theme.Standard.RendererColorTable.ButtonPressedBgOut))
                {
                    e.Graphics.FillRectangle(brus, rectBorder);
                }

                //Border
                using (Pen p = new Pen(Theme.Standard.RendererColorTable.ButtonPressedBorderOut))
                {
                    e.Graphics.DrawRectangle(p, rectBorder);
                }

                //Inner border
                Rectangle RoundedRect = Rectangle.Round(innerR);
                using (Pen p = new Pen(Theme.Standard.RendererColorTable.ButtonPressedBorderIn))
                {
                    e.Graphics.DrawRectangle(p, RoundedRect);
                }

                #region Main Bg
                using (GraphicsPath path = new GraphicsPath())
                {
                    path.AddEllipse(new Rectangle(1, 1, e.Item.Width, e.Item.Height * 2));
                    path.CloseFigure();
                    using (PathGradientBrush gradient = new PathGradientBrush(path))
                    {
                        gradient.WrapMode = WrapMode.Clamp;
                        gradient.CenterPoint = new PointF(Convert.ToSingle(1 + e.Item.Width / 2), Convert.ToSingle(e.Item.Bounds.Height));
                        gradient.CenterColor = Theme.Standard.RendererColorTable.ButtonPressedBgCenter;
                        gradient.SurroundColors = new Color[] { Theme.Standard.RendererColorTable.ButtonPressedBgOut };

                        Blend blend = new Blend(3);
                        blend.Factors = new float[] { 0f, 0.8f, 0f };
                        blend.Positions = new float[] { 0f, 0.30f, 1f };


                        Region lastClip = e.Graphics.Clip;
                        Region newClip = new Region(rectBorder);
                        newClip.Intersect(lastClip);
                        e.Graphics.SetClip(newClip.GetBounds(e.Graphics));
                        e.Graphics.FillPath(gradient, path);
                        e.Graphics.Clip = lastClip;
                    }
                }
                #endregion

                //Glossy effect
                using (GraphicsPath path = new GraphicsPath())
                {
                    path.AddRectangle(Rectangle.Round(glossyR));
                    using (LinearGradientBrush b = new LinearGradientBrush(glossyR, Theme.Standard.RendererColorTable.ButtonPressedGlossyNorth, Theme.Standard.RendererColorTable.ButtonPressedGlossySouth, 90))
                    {
                        b.WrapMode = WrapMode.TileFlipXY;
                        e.Graphics.FillPath(b, path);
                    }
                }
            }
        }
Exemplo n.º 9
0
        // 原理:由大到小生成图像中心区域,然后用总区域减去该中心区域,并用材质画刷填充
        private void Animator03()
        {
            const float stepCount = 4; // 每次收缩的步长像素
            try
            {
                OnDrawStarted(this, EventArgs.Empty);
                ClearBackground();

                // 建立空区域,如使用Region的无参构造函数则建立一个无限大小的区域,而非空区域
                Region region = new Region(new GraphicsPath());
                // 建立位图材质画刷
                TextureBrush textureBrush = new TextureBrush(bmp);
                for (float x = 0; x <= bmp.Width / 2f; x += stepCount)
                {
                    // 添加整个位图区域
                    region.Union(new Rectangle(0, 0, bmp.Width, bmp.Height));
                    // 从中心开始,由大到小填充背景色或填充缩小尺寸的原图
                    // 计算高度变化量,如果宽度大,则高度变化量小于宽度,否则大于宽度
                    float y = x * bmp.Height / bmp.Width;
                    RectangleF rect = new RectangleF(x, y, bmp.Width - 2f * x, bmp.Height - 2f * y);
                    // 计算整个位图区域与背景色区域的差集
                    region.Exclude(rect);
                    dc.FillRegion(textureBrush, region); // 使用材质画刷填充区域

                    ShowBmp(region.GetBounds(dc));
                    Thread.Sleep(10 * delay);
                }
                // 由于stepCount可能无法被宽度整除,则最终生成的背景色区域并不为空,故在循环结束后绘制整个位图
                dc.DrawImage(bmp, 0, 0);

                ShowBmp();
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
            finally
            {
                OnDrawCompleted(this, EventArgs.Empty);
            }
        }
Exemplo n.º 10
0
		public void InfinityIntersectTranslate ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Intersect (new Rectangle (-10, -10, 20, 20));
				r.Translate (10, 10);
				RectangleF bounds = r.GetBounds (graphic);
				Assert.AreEqual (0, bounds.X, "X");
				Assert.AreEqual (0, bounds.Y, "Y");
				Assert.AreEqual (20, bounds.Width, "Width");
				Assert.AreEqual (20, bounds.Height, "Height");
			}
		}
Exemplo n.º 11
0
        private void PaintForm(Graphics g, Region clip)
        {
            if (!clip.GetBounds(g).Equals(UpdateRegion.GetBounds(g)))
                UpdateRegion.Union(clip);

            DrawBackground(g);

            Opacity = Layout.Settings.Opacity;

            if (Layout.Settings.AntiAliasing)
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
            else
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.CompositingQuality = CompositingQuality.GammaCorrected;
            g.InterpolationMode = InterpolationMode.Bilinear;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            ComponentRenderer.CalculateOverallSize(Layout.Mode);

            var scaleFactor = Layout.Mode == LayoutMode.Vertical
                ? Height / Math.Max(ComponentRenderer.OverallSize, 1f)
                : Width / Math.Max(ComponentRenderer.OverallSize, 1f);

            g.ResetTransform();
            g.ScaleTransform(scaleFactor, scaleFactor);
            float transformedWidth = Width;
            float transformedHeight = Height;

            if (Layout.Mode == LayoutMode.Vertical)
                transformedWidth /= scaleFactor;
            else
                transformedHeight /= scaleFactor;

            BackColor = Color.Black;

            ComponentRenderer.Render(g, CurrentState, transformedWidth, transformedHeight, Layout.Mode, UpdateRegion);

            var currentSize = ComponentRenderer.OverallSize;

            if (OldSize >= 0)
            {
                if (OldSize != currentSize)
                {
                    MinimumSize = new Size(0, 0);
                    if (Layout.Mode == LayoutMode.Vertical)
                        Height = (int)((currentSize / (double)OldSize) * Height + 0.5);
                    else
                        Width = (int)((currentSize / (double)OldSize) * Width + 0.5);
                }
                FixSize();
                if (Layout.Mode == LayoutMode.Vertical)
                    MinimumSize = new Size(100, (int)((ComponentRenderer.OverallSize / 3) + 0.5f));
                else
                    MinimumSize = new Size((int)((ComponentRenderer.OverallSize / 3) + 0.5f), 25);
            }
            else
            {
                if (Layout.Mode == LayoutMode.Vertical)
                    Size = new Size(Layout.VerticalWidth, Layout.VerticalHeight);
                else
                    Size = new Size(Layout.HorizontalWidth, Layout.HorizontalHeight);
                OldSize++;
            }

            if (OldSize >= 0)
                OldSize = currentSize;
        }
Exemplo n.º 12
0
        private void PaintForm(Graphics g, Region clip)
        {
            if (CurrentState.LayoutSettings.BackgroundColor != Color.Transparent
                || CurrentState.LayoutSettings.BackgroundGradient != GradientType.Plain
                && CurrentState.LayoutSettings.BackgroundColor2 != Color.Transparent)
            {
                var gradientBrush = new LinearGradientBrush(
                            new PointF(0, 0),
                            CurrentState.LayoutSettings.BackgroundGradient == GradientType.Horizontal
                            ? new PointF(this.Size.Width, 0)
                            : new PointF(0, this.Size.Height),
                            CurrentState.LayoutSettings.BackgroundColor,
                            CurrentState.LayoutSettings.BackgroundGradient == GradientType.Plain
                            ? CurrentState.LayoutSettings.BackgroundColor
                            : CurrentState.LayoutSettings.BackgroundColor2);
                g.FillRectangle(gradientBrush, 0, 0, this.Size.Width, this.Size.Height);
            }

            this.Opacity = Layout.Settings.Opacity;

            if (Layout.Settings.AntiAliasing)
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
            else
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.CompositingQuality = CompositingQuality.GammaCorrected;
            g.InterpolationMode = InterpolationMode.Bilinear;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            var scaleFactor = Layout.Mode == LayoutMode.Vertical
                ? (float)this.Height / Math.Max(ComponentRenderer.OverallHeight, 1f)
                : (float)this.Width / Math.Max(ComponentRenderer.OverallWidth, 1f);

            g.ResetTransform();
            g.ScaleTransform(scaleFactor, scaleFactor);
            float transformedWidth = this.Width;
            float transformedHeight = this.Height;

            if (Layout.Mode == LayoutMode.Vertical)
                transformedWidth /= scaleFactor;
            else
                transformedHeight /= scaleFactor;

            this.BackColor = Color.Black;

            if (!clip.GetBounds(g).Equals(UpdateRegion.GetBounds(g)))
                UpdateRegion.Union(clip);

            /*if (!CurrentState.DrawLock.TryEnterReadLock(500))
                return;*/

            ComponentRenderer.Render(g, CurrentState, transformedWidth, transformedHeight, Layout.Mode, UpdateRegion);
                
            //CurrentState.DrawLock.ExitReadLock();

            var currentSize = Layout.Mode == LayoutMode.Vertical ? ComponentRenderer.OverallHeight : ComponentRenderer.OverallWidth;

            if (OldSize >= 0)
            {
                if (OldSize != currentSize)
                {
                    this.MinimumSize = new Size(0, 0);
                    if (Layout.Mode == LayoutMode.Vertical)
                        this.Height = (int)((currentSize / (double)OldSize) * this.Height + 0.5);
                    else
                        this.Width = (int)((currentSize / (double)OldSize) * this.Width + 0.5);
                }
                FixSize();
                if (Layout.Mode == LayoutMode.Vertical)
                    this.MinimumSize = new Size(100, (int)((ComponentRenderer.OverallHeight / 2) * (100 / Math.Max(100, ComponentRenderer.MinimumWidth)) + 0.5f));
                else
                    this.MinimumSize = new Size((int)((ComponentRenderer.OverallWidth / 2) * (25 / Math.Max(25, ComponentRenderer.MinimumHeight)) + 0.5f), 25);
            }
            else
            {
                if (Layout.Mode == LayoutMode.Vertical)
                    this.Size = new Size(Layout.VerticalWidth, Layout.VerticalHeight);
                else
                    this.Size = new Size(Layout.HorizontalWidth, Layout.HorizontalHeight);
                OldSize++;
            }

            if (OldSize == 0)
                RefreshesRemaining = 10;

            if (OldSize >= 0)
                OldSize = currentSize;
        }
Exemplo n.º 13
0
        /// <summary>
        /// OnPaint will go through the enabled elements (vertical ReminderMessage, GridLines, LineNumbers, BorderLines, MarginLines) and will
        /// draw them if enabled. At the same time, it will build GraphicsPaths for each of those elements (that are enabled), which will be used 
        /// in SeeThroughMode (if it's active): the figures in the GraphicsPaths will form a customized outline for the control by setting them as the 
        /// Region of the LineNumber control. Note: the vertical ReminderMessages are only drawn during designtime. 
        /// </summary>
        /// <param name="e"></param>
        /// <remarks></remarks>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            //   Build the list of visible LineNumberItems (= zLNIs) first. (doesn't take long, so it can stay in OnPaint)
            this.Update_VisibleLineNumberItems();
            base.OnPaint(e);

            // --- QualitySettings
            if (zLineNumbers_AntiAlias == true) {
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            } else {
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            }

            // --- Local Declarations
            string zTextToShow = "";
            string zReminderToShow = "";
            StringFormat zSF = new StringFormat();
            SizeF zTextSize = default(SizeF);
            Pen zPen = new Pen(this.ForeColor);
            SolidBrush zBrush = new SolidBrush(this.ForeColor);
            Point zPoint = new Point(0, 0);
            Rectangle zItemClipRectangle = new Rectangle(0, 0, 0, 0);

            //   NOTE: The GraphicsPaths are only used for SeeThroughMode
            //   FillMode.Winding: combined outline ( Alternate: XOR'ed outline )
            System.Drawing.Drawing2D.GraphicsPath zGP_GridLines = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
            System.Drawing.Drawing2D.GraphicsPath zGP_BorderLines = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
            System.Drawing.Drawing2D.GraphicsPath zGP_MarginLines = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
            System.Drawing.Drawing2D.GraphicsPath zGP_LineNumbers = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
            Region zRegion = new Region(base.ClientRectangle);

            // ----------------------------------------------
            // --- DESIGNTIME / NO VISIBLE ITEMS
            if (this.DesignMode == true) {
                //   Show a vertical reminder message
                if (zParent == null) {
                    zReminderToShow = "-!- Set ParentRichTextBox -!-";
                } else {
                    if (zLNIs.Count == 0)
                        zReminderToShow = "LineNrs (  " + zParent.Name + "  )";
                }
                if (zReminderToShow.Length > 0) {
                    // --- Centering and Rotation for the reminder message
                    e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2);
                    e.Graphics.RotateTransform(-90);
                    zSF.Alignment = StringAlignment.Center;
                    zSF.LineAlignment = StringAlignment.Center;
                    // --- Show the reminder message (with small shadow)
                    zTextSize = e.Graphics.MeasureString(zReminderToShow, this.Font, zPoint, zSF);
                    e.Graphics.DrawString(zReminderToShow, this.Font, Brushes.WhiteSmoke, 1, 1, zSF);
                    e.Graphics.DrawString(zReminderToShow, this.Font, Brushes.Firebrick, 0, 0, zSF);
                    e.Graphics.ResetTransform();

                    //Rectangle zReminderRectangle = new Rectangle(this.Width / 2 - zTextSize.Height / 2, this.Height / 2 - zTextSize.Width / 2, zTextSize.Height, zTextSize.Width);
                    Rectangle zReminderRectangle = new Rectangle((int)(this.Width / 2 - zTextSize.Height / 2), (int)(this.Height / 2 - zTextSize.Width / 2), (int)(zTextSize.Height), (int)(zTextSize.Width));
                    zGP_LineNumbers.AddRectangle(zReminderRectangle);
                    zGP_LineNumbers.CloseFigure();

                    if (zAutoSizing == true) {
                        zReminderRectangle.Inflate((int)(zTextSize.Height * 0.2), (int)(zTextSize.Width * 0.1));
                        //zReminderRectangle.Inflate(zTextSize.Height * 0.2, zTextSize.Width * 0.1);
                        zAutoSizing_Size = new Size(zReminderRectangle.Width, zReminderRectangle.Height);
                    }
                }
            }

            // ----------------------------------------------
            // --- DESIGN OR RUNTIME / WITH VISIBLE ITEMS (which means zParent exists)
            if (zLNIs.Count > 0) {
                //   The visible LineNumberItems with their BackgroundGradient and GridLines
                //   Loop through every visible LineNumberItem
                System.Drawing.Drawing2D.LinearGradientBrush zLGB = null;
                zPen = new Pen(zGridLines_Color, zGridLines_Thickness);
                zPen.DashStyle = zGridLines_Style;
                zSF.Alignment = StringAlignment.Near;
                zSF.LineAlignment = StringAlignment.Near;
                //zSF.FormatFlags = StringFormatFlags.FitBlackBox + StringFormatFlags.NoClip + StringFormatFlags.NoWrap;
                zSF.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoClip | StringFormatFlags.NoWrap;

                for (int zA = 0; zA <= zLNIs.Count - 1; zA++) {
                    // --- BackgroundGradient
                    if (zGradient_Show == true) {
                        //zLGB = new Drawing2D.LinearGradientBrush(zLNIs(zA).Rectangle, zGradient_StartColor, zGradient_EndColor, zGradient_Direction);
                        zLGB = new System.Drawing.Drawing2D.LinearGradientBrush(zLNIs[zA].Rectangle, zGradient_StartColor, zGradient_EndColor, zGradient_Direction);
                        e.Graphics.FillRectangle(zLGB, zLNIs[zA].Rectangle);
                        //e.Graphics.FillRectangle(zLGB, zLNIs(zA).Rectangle);
                    }

                    // --- GridLines
                    if (zGridLines_Show == true) {
                        e.Graphics.DrawLine(zPen, new Point(0, zLNIs[zA].Rectangle.Y), new Point(this.Width, zLNIs[zA].Rectangle.Y));
                        //e.Graphics.DrawLine(zPen, new Point(0, zLNIs(zA).Rectangle.Y), new Point(this.Width, zLNIs(zA).Rectangle.Y));

                        //   NOTE: Every item in a GraphicsPath is a closed figure, so instead of adding gridlines as lines, we'll add them
                        //   as rectangles that loop out of sight. Their height uses the zContentRectangle which is the maxsize of
                        //   the ParentRichTextBox's contents.
                        //   NOTE: Slight adjustment needed when the first item has a negative Y coordinate.
                        //   This explains the " - zLNIs(0).Rectangle.Y" (which adds the negative size to the height
                        //   to make sure the rectangle's bottompart stays out of sight)
                        //zGP_GridLines.AddRectangle(new Rectangle(-zGridLines_Thickness, zLNIs(zA).Rectangle.Y, this.Width + zGridLines_Thickness * 2, this.Height - zLNIs(0).Rectangle.Y + zGridLines_Thickness));
                        zGP_GridLines.AddRectangle(new Rectangle(	(int)(-zGridLines_Thickness),
                                                                                                            (int)(zLNIs[zA].Rectangle.Y),
                                                                                                            (int)(this.Width + zGridLines_Thickness * 2),
                                                                                                            (int)(this.Height - zLNIs[zA].Rectangle.Y + zGridLines_Thickness)
                                                                                                            ));
                        zGP_GridLines.CloseFigure();
                    }

                    // --- LineNumbers
                    if (zLineNumbers_Show == true) {
                        //   TextFormatting
                        if (zLineNumbers_ShowLeadingZeroes == true) {
                            zTextToShow = (zLineNumbers_ShowAsHexadecimal ? zLNIs[zA].LineNumber.ToString("X") : zLNIs[zA].LineNumber.ToString(zLineNumbers_Format));
                            //zTextToShow = (zLineNumbers_ShowAsHexadecimal ? zLNIs(zA).LineNumber.ToString("X") : zLNIs(zA).LineNumber.ToString(zLineNumbers_Format));
                        } else {
                            zTextToShow = (zLineNumbers_ShowAsHexadecimal ? zLNIs[zA].LineNumber.ToString("X") : zLNIs[zA].LineNumber.ToString());
                            //zTextToShow = (zLineNumbers_ShowAsHexadecimal ? zLNIs(zA).LineNumber.ToString("X") : zLNIs(zA).LineNumber.ToString);
                        }

                        //   TextSizing
                        zTextSize = e.Graphics.MeasureString(zTextToShow, this.Font, zPoint, zSF);
                        //   TextAlignment and positioning   (zPoint = TopLeftCornerPoint of the text)
                        //   TextAlignment, padding, manual offset (via LineNrs_Offset) and zTextSize are all included in the calculation of zPoint.
                        switch (zLineNumbers_Alignment) {
                            case ContentAlignment.TopLeft:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Left + this.Padding.Left + zLineNumbers_Offset.Width), (int)(zLNIs[zA].Rectangle.Top + this.Padding.Top + zLineNumbers_Offset.Height));
                                break;
                            case ContentAlignment.MiddleLeft:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Left + this.Padding.Left + zLineNumbers_Offset.Width), (int)(zLNIs[zA].Rectangle.Top + (zLNIs[zA].Rectangle.Height / 2) + zLineNumbers_Offset.Height - zTextSize.Height / 2));
                                break;
                            case ContentAlignment.BottomLeft:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Left + this.Padding.Left + zLineNumbers_Offset.Width), (int)(zLNIs[zA].Rectangle.Bottom - this.Padding.Bottom + 1 + zLineNumbers_Offset.Height - zTextSize.Height));
                                break;
                            case ContentAlignment.TopCenter:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Width / 2 + zLineNumbers_Offset.Width - zTextSize.Width / 2), (int)(zLNIs[zA].Rectangle.Top + this.Padding.Top + zLineNumbers_Offset.Height));
                                break;
                            case ContentAlignment.MiddleCenter:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Width / 2 + zLineNumbers_Offset.Width - zTextSize.Width / 2), (int)(zLNIs[zA].Rectangle.Top + (zLNIs[zA].Rectangle.Height / 2) + zLineNumbers_Offset.Height - zTextSize.Height / 2));
                                break;
                            case ContentAlignment.BottomCenter:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Width / 2 + zLineNumbers_Offset.Width - zTextSize.Width / 2), (int)(zLNIs[zA].Rectangle.Bottom - this.Padding.Bottom + 1 + zLineNumbers_Offset.Height - zTextSize.Height));
                                break;
                            case ContentAlignment.TopRight:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Right - this.Padding.Right + zLineNumbers_Offset.Width - zTextSize.Width), (int)(zLNIs[zA].Rectangle.Top + this.Padding.Top + zLineNumbers_Offset.Height));
                                break;
                            case ContentAlignment.MiddleRight:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Right - this.Padding.Right + zLineNumbers_Offset.Width - zTextSize.Width), (int)(zLNIs[zA].Rectangle.Top + (zLNIs[zA].Rectangle.Height / 2) + zLineNumbers_Offset.Height - zTextSize.Height / 2));
                                break;
                            case ContentAlignment.BottomRight:
                                zPoint = new Point((int)(zLNIs[zA].Rectangle.Right - this.Padding.Right + zLineNumbers_Offset.Width - zTextSize.Width), (int)(zLNIs[zA].Rectangle.Bottom - this.Padding.Bottom + 1 + zLineNumbers_Offset.Height - zTextSize.Height));
                                break;
                        }
                        //   TextClipping
                        zItemClipRectangle = new Rectangle(zPoint, zTextSize.ToSize());
                        if (zLineNumbers_ClipByItemRectangle == true) {
                            //   If selected, the text will be clipped so that it doesn't spill out of its own LineNumberItem-area.
                            //   Only the part of the text inside the LineNumberItem.Rectangle should be visible, so intersect with the ItemRectangle
                            //   The SetClip method temporary restricts the drawing area of the control for whatever is drawn next.
                            zItemClipRectangle.Intersect(zLNIs[zA].Rectangle);
                            e.Graphics.SetClip(zItemClipRectangle);
                        }
                        //   TextDrawing
                        e.Graphics.DrawString(zTextToShow, this.Font, zBrush, zPoint, zSF);
                        e.Graphics.ResetClip();
                        //   The GraphicsPath for the LineNumber is just a rectangle behind the text, to keep the paintingspeed high and avoid ugly artifacts.
                        zGP_LineNumbers.AddRectangle(zItemClipRectangle);
                        zGP_LineNumbers.CloseFigure();
                    }
                }

                // --- GridLinesThickness and Linestyle in SeeThroughMode. All GraphicsPath lines are drawn as solid to keep the paintingspeed high.
                if (zGridLines_Show == true) {
                    zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                    zGP_GridLines.Widen(zPen);
                }

                // --- Memory CleanUp
                if (zLGB != null)
                    zLGB.Dispose();
            }

            // ----------------------------------------------
            // --- DESIGN OR RUNTIME / ALWAYS
            //Point zP_Left = new Point(Math.Floor(zBorderLines_Thickness / 2), Math.Floor(zBorderLines_Thickness / 2));
            //Point zP_Right = new Point(this.Width - Math.Ceiling(zBorderLines_Thickness / 2), this.Height - Math.Ceiling(zBorderLines_Thickness / 2));

            Point zP_Left = new Point(
                                                                    (int)(Math.Floor(zBorderLines_Thickness / 2)),
                                                                    (int)(Math.Floor(zBorderLines_Thickness / 2))
                                                             );
            Point zP_Right = new Point(
                                                                    (int)(this.Width - Math.Ceiling(zBorderLines_Thickness / 2)),
                                                                    (int)(this.Height - Math.Ceiling(zBorderLines_Thickness / 2))
                                                                );

            // --- BorderLines
            Point[] zBorderLines_Points = {
                new Point(zP_Left.X, zP_Left.Y),
                new Point(zP_Right.X, zP_Left.Y),
                new Point(zP_Right.X, zP_Right.Y),
                new Point(zP_Left.X, zP_Right.Y),
                new Point(zP_Left.X, zP_Left.Y)
            };
            if (zBorderLines_Show == true) {
                zPen = new Pen(zBorderLines_Color, zBorderLines_Thickness);
                zPen.DashStyle = zBorderLines_Style;
                e.Graphics.DrawLines(zPen, zBorderLines_Points);
                zGP_BorderLines.AddLines(zBorderLines_Points);
                zGP_BorderLines.CloseFigure();
                //   BorderThickness and Style for SeeThroughMode
                zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                zGP_BorderLines.Widen(zPen);
            }

            // --- MarginLines
            if (zMarginLines_Show == true && zMarginLines_Side > LineNumberDockSide.None) {
                zP_Left = new Point((int)(-zMarginLines_Thickness), (int)(-zMarginLines_Thickness));
                zP_Right = new Point((int)(this.Width + zMarginLines_Thickness), (int)(this.Height + zMarginLines_Thickness));
                zPen = new Pen(zMarginLines_Color, zMarginLines_Thickness);
                zPen.DashStyle = zMarginLines_Style;
                if (zMarginLines_Side == LineNumberDockSide.Left | zMarginLines_Side == LineNumberDockSide.Height) {
                    e.Graphics.DrawLine(zPen, new Point(
                                                                                            (int)(Math.Floor(zMarginLines_Thickness / 2)), 0),
                                                                                            new Point(
                                                                                                                (int)(Math.Floor(zMarginLines_Thickness / 2)),
                                                                                                                this.Height - 1)
                                                                                                                );
                    zP_Left = new Point(
                                                            (int)(Math.Ceiling(zMarginLines_Thickness / 2)),
                                                            (int)(-zMarginLines_Thickness));
                }
                if (zMarginLines_Side == LineNumberDockSide.Right | zMarginLines_Side == LineNumberDockSide.Height) {
                    e.Graphics.DrawLine(zPen, new Point(
                                                                                            (int)(this.Width - Math.Ceiling(zMarginLines_Thickness / 2)), 0),
                                                                                            new Point(
                                                                                                                (int)(this.Width - Math.Ceiling(zMarginLines_Thickness / 2)),
                                                                                                                (int)(this.Height - 1))
                                                                                        );

                    zP_Right = new Point(
                                                                (int)(this.Width - Math.Ceiling(zMarginLines_Thickness / 2)),
                                                                (int)(this.Height + zMarginLines_Thickness)
                                                            );
                }
                //   GraphicsPath for the MarginLines(s):
                //   MarginLines(s) are drawn as a rectangle connecting the zP_Left and zP_Right points, which are either inside or
                //   outside of sight, depending on whether the MarginLines at that side is visible. zP_Left: TopLeft and ZP_Right: BottomRight
                zGP_MarginLines.AddRectangle(new Rectangle(zP_Left, new Size(zP_Right.X - zP_Left.X, zP_Right.Y - zP_Left.Y)));
                zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                zGP_MarginLines.Widen(zPen);
            }

            // ----------------------------------------------
            // --- SeeThroughMode
            //   combine all the GraphicsPaths (= zGP_... ) and set them as the region for the control.
            if (zSeeThroughMode == true) {
                zRegion.MakeEmpty();
                zRegion.Union(zGP_BorderLines);
                zRegion.Union(zGP_MarginLines);
                zRegion.Union(zGP_GridLines);
                zRegion.Union(zGP_LineNumbers);
            }

            // --- Region
            if (zRegion.GetBounds(e.Graphics).IsEmpty == true) {
                //   Note: If the control is in a condition that would show it as empty, then a border-region is still drawn regardless of it's borders on/off state.
                //   This is added to make sure that the bounds of the control are never lost (it would remain empty if this was not done).
                zGP_BorderLines.AddLines(zBorderLines_Points);
                zGP_BorderLines.CloseFigure();
                zPen = new Pen(zBorderLines_Color, 1);
                zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                zGP_BorderLines.Widen(zPen);

                zRegion = new Region(zGP_BorderLines);
            }
            this.Region = zRegion;

            // ----------------------------------------------
            // --- Memory CleanUp
            if (zPen != null)
                zPen.Dispose();
            if (zBrush != null)
                zPen.Dispose();
            if (zRegion != null)
                zRegion.Dispose();
            if (zGP_GridLines != null)
                zGP_GridLines.Dispose();
            if (zGP_BorderLines != null)
                zGP_BorderLines.Dispose();
            if (zGP_MarginLines != null)
                zGP_MarginLines.Dispose();
            if (zGP_LineNumbers != null)
                zGP_LineNumbers.Dispose();
        }
Exemplo n.º 14
0
        public static BitmapPosData CreateFromDesktopImageInClippedRegion(Region rg, Point[] ptPath)
        {
            Console.WriteLine("CopyDesktopImageToClippedRegion");

            BitmapPosData data = null;
            int screenX;
            int screenY;
            IntPtr hBmp;
            IntPtr hdcScreen = GetDC(GetDesktopWindow());
            IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);

            screenX = GetSystemMetrics(0);
            screenY = GetSystemMetrics(1);
            hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);

            if (hBmp != IntPtr.Zero)
            {
                IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
                BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);

                SelectObject(hdcCompatible, hOldBmp);
                DeleteDC(hdcCompatible);
                ReleaseDC(GetDesktopWindow(), hdcScreen);

                Bitmap bmpDt = System.Drawing.Image.FromHbitmap(hBmp);
                Graphics gd = Graphics.FromImage(bmpDt);
                RectangleF rc = rg.GetBounds(gd);
                Bitmap bmpClip = new Bitmap((int)rc.Width, (int)rc.Height);
                Graphics gt = Graphics.FromImage(bmpClip);
                Region rgnTempPict = rg.Clone();
                rgnTempPict.Translate(-rc.X, -rc.Y);
                gt.SetClip(rgnTempPict, System.Drawing.Drawing2D.CombineMode.Replace);
                RectangleF rc2 = rg.GetBounds(gt);
                gt.DrawImage(bmpDt, new Rectangle(0, 0, bmpClip.Width, bmpClip.Height), new Rectangle((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), GraphicsUnit.Pixel);
                for (int i = 0; i < ptPath.Length; i++)
                {
                    ptPath[i].Offset((int)-rc.X, (int)-rc.Y);
                }
                data = new BitmapPosData(bmpClip, rgnTempPict.Clone(), new Point(0, 0), ptPath);
                rgnTempPict.Dispose();

                gd.Dispose();
                gt.Dispose();

                DeleteObject(hBmp);
                GC.Collect();
            }
            return data;
        }
Exemplo n.º 15
0
	public void Invalidate(Region region, bool invalidateChildren)
			{
				if (!Visible)
				{
					return; // nothing to do 
				}

				if (toolkitWindow == null)
				{
					if ((parent == null) || (!parent.IsHandleCreated))
					{
						return;
					}

					CreateControl ();
				}

				using (Region region1 = region.Clone())
				{
					InvalidateInternal(region1, invalidateChildren);
					using (Graphics g = CreateGraphics())
					{
						Rectangle bounds = Rectangle.Truncate(region.GetBounds(g));
						OnInvalidated(new InvalidateEventArgs(bounds));
					}
				}
			}
Exemplo n.º 16
0
        /*public void ResetPoly()
        {
            SvgElementCollection col= tlVectorControl1.SVGDocument.SelectCollection;
            if(col.Count<1){
                return;
            }
            SvgElementCollection.ISvgElementEnumerator enumerator1 = tlVectorControl1.DrawArea.ElementList.GetEnumerator();
            foreach(SvgElement ele in col){
                if (ele.GetType().ToString() == "ItopVector.Core.Figure.Polygon")
                {
                    glebeProperty p=new glebeProperty();
                    p.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                    p.EleID = ((IGraph)ele).ID;
                    p = Services.BaseService.GetObject("SelectglebePropertyByEleID", p);
                    if(p!=null){
                        PointF[] tfArray1 = TLMath.getPolygonPoints(ele);
                        GraphicsPath selectAreaPath = new GraphicsPath();
                        selectAreaPath.AddLines(tfArray1);
                        selectAreaPath.CloseFigure();
                        Region region1 = new Region(selectAreaPath);
                        while (enumerator1.MoveNext())
                        {
                            IGraph graph1 = (IGraph)enumerator1.Current;
                            GraphicsPath path1 = (GraphicsPath)graph1.GPath.Clone();
                            path1.Transform(graph1.GraphTransform.Matrix);
                            Region region2 = new Region(path1);
                            region2.Intersect(region1);
                            if (!region2.GetBounds(Graphics.FromHwnd(IntPtr.Zero)).IsEmpty)
                            {
                                glebeProperty p1 = new glebeProperty();
                                p1.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                p1.EleID = graph1.ID;
                                p1 = Services.BaseService.GetObject("SelectglebePropertyByEleID", p1);
                                if(p1!=null){
                                    p1.ParentEleID = p.UID;
                                    Services.BaseService.Update("UpdateglebePropertyAreaAll", p1);
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("更新完成。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }*/
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            try
            {
                if (e.ClickedItem.Text == "属性")
                {
                    XmlElement xml1 = (XmlElement)tlVectorControl1.SVGDocument.CurrentElement;
                    //PointF[] pf = TLMath.getPolygonPoints(xml1);
                    DeviceHelper.xml1 = xml1;
                    //((Polygon)xml1).Transform.Matrix.TransformPoints(pf);
                    // 规划
                    if (getlayer(SvgDocument.currentLayer, "电网规划层", tlVectorControl1.SVGDocument.getLayerList()))
                    {

                        if (xml1 == null || tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
                        {
                            MessageBox.Show("请先选择规划区域。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.RectangleElement")
                        {
                            //frmImgManager frm = new frmImgManager();
                            //frm.Show();
                        }
                        if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Polygon")
                        {
                            XmlNodeList n1 = tlVectorControl1.SVGDocument.GetElementsByTagName("use");
                            PointF[] tfArray1 = TLMath.getPolygonPoints(xml1);
                            string str220 = "";
                            string str110 = "";
                            string str66 = "";

                            string str_id = "";
                            GraphicsPath selectAreaPath = new GraphicsPath();
                            selectAreaPath.AddLines(tfArray1);
                            selectAreaPath.CloseFigure();
                            //Matrix x=new Matrix(
                            //Region region1 = new Region(selectAreaPath);
                            for (int i = 0; i < n1.Count; i++)
                            {
                                float OffX = 0f;
                                float OffY = 0f;
                                bool ck = false;
                                Use use = (Use)n1[i];
                                if (use.GetAttribute("xlink:href").Contains("byq") || use.GetAttribute("xlink:href").Contains("pds"))
                                {
                                    if (selectAreaPath.IsVisible(use.CenterPoint))
                                    {
                                        if (use.GetAttribute("Deviceid") != "")
                                        {
                                            str_id = str_id + "'" + use.GetAttribute("Deviceid") + "',";
                                        }
                                    }
                                }
                                if (use.GetAttribute("xlink:href").Contains("Substation"))
                                {
                                    //string strMatrix = use.GetAttribute("transform");
                                    //if (strMatrix != "")
                                    //{
                                    //    strMatrix = strMatrix.Replace("matrix(", "");
                                    //    strMatrix = strMatrix.Replace(")", "");
                                    //    string[] mat = strMatrix.Split(',');
                                    //    if (mat.Length > 5)
                                    //    {
                                    //        OffX = Convert.ToSingle(mat[4]);
                                    //        OffY = Convert.ToSingle(mat[5]);
                                    //    }
                                    //}
                                    if (frmlar.getSelectedLayer().Contains(use.GetAttribute("layer")))
                                    {
                                        ck = true;
                                    }
                                    PointF TempPoint = TLMath.getUseOffset(use.GetAttribute("xlink:href"));
                                    //if (selectAreaPath.IsVisible(use.X + TempPoint.X + OffX, use.Y + TempPoint.Y + OffY) && ck)
                                    if (selectAreaPath.IsVisible(use.CenterPoint) && ck)
                                    {
                                        if (use.GetAttribute("xlink:href").Contains("220"))
                                        {
                                            str220 = str220 + "'" + use.GetAttribute("Deviceid") + "',";
                                        }
                                        if (use.GetAttribute("xlink:href").Contains("110"))
                                        {
                                            str110 = str110 + "'" + use.GetAttribute("Deviceid") + "',";
                                        }
                                        if (use.GetAttribute("xlink:href").Contains("66"))
                                        {
                                            str66 = str66 + "'" + use.GetAttribute("Deviceid") + "',";
                                        }
                                    }
                                }
                            }
                            if (str220.Length > 1)
                            {
                                str220 = str220.Substring(0, str220.Length - 1);
                            }
                            if (str110.Length > 1)
                            {
                                str110 = str110.Substring(0, str110.Length - 1);
                            }
                            if (str66.Length > 1)
                            {
                                str66 = str66.Substring(0, str66.Length - 1);
                            }
                            if (str_id.Length > 1)
                            {
                                str_id = str_id.Substring(0, str_id.Length - 1);
                            }
                            glebeProperty _gle = new glebeProperty();
                            _gle.EleID = tlVectorControl1.SVGDocument.CurrentElement.ID;
                            _gle.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;

                            IList<glebeProperty> UseProList = Services.BaseService.GetList<glebeProperty>("SelectglebePropertyByEleID", _gle);
                            if (UseProList.Count > 0)
                            {
                                _gle = UseProList[0];
                                _gle.LayerID = SvgDocument.currentLayer;
                                frmMainProperty f = new frmMainProperty();
                                f.strID = str_id;
                                f.InitData(_gle, str220, str110, str66);
                                PointF[] pn = (PointF[])((Polygon)xml1).Points.Clone();
                                ((Polygon)xml1).Transform.Matrix.TransformPoints(pn);
                                string s1 = "";
                                for (int p = 0; p < pn.Length; p++)
                                {
                                    s1 = s1 + pn[p].X.ToString() + " " + pn[p].Y.ToString() + ",";
                                }
                                f.Str = s1;
                                f.ShowDialog();
                                if (f.checkBox1.Checked == false)
                                {
                                    tlVectorControl1.SVGDocument.RootElement.RemoveChild(tlVectorControl1.SVGDocument.CurrentElement);
                                }

                                 if (this.Owner!=null)
                                 {
                                    MethodInfo method = this.Owner.GetType().GetMethod("UpdateSpatataldata");
                                    if (method != null)
                                    {
                                        string[] paramValues = new string[] { f.glebeProp.ObligateField16 };
                                        ParameterInfo[] paramInfos = method.GetParameters();
                                        if (paramInfos.Length == paramValues.Length)
                                        {
                                            // 参数个数相同才会执行
                                            object[] methodParams = new object[paramValues.Length];
                                            for (int i = 0; i < paramValues.Length; i++)
                                                methodParams[i] = Convert.ChangeType(paramValues[i], paramInfos[i].ParameterType, CultureInfo.InvariantCulture);

                                            //object instance = (method.IsStatic) ? null : Activator.CreateInstance(this.Owner.GetType());
                                            object result = method.Invoke(this.Owner, methodParams);
                                        }

                                    }
                                    this.Close();
                                 }
                                //tlVectorControl1.Refresh();
                            }
                            else
                            {
                                _gle = new glebeProperty();
                                _gle.LayerID = SvgDocument.currentLayer;
                                frmMainProperty f = new frmMainProperty();
                                f.strID = str_id;
                                f.InitData(_gle, str220, str110, str66);
                                PointF[] pn = (PointF[])((Polygon)xml1).Points.Clone();
                                ((Polygon)xml1).Transform.Matrix.TransformPoints(pn);
                                string s1 = "";
                                for (int p = 0; p < pn.Length; p++)
                                {
                                    s1 = s1 + pn[p].X.ToString() + " " + pn[p].Y.ToString() + ",";
                                }
                                f.Str = s1;
                                f.ShowDialog();
                                if (this.Owner != null)
                                {
                                    MethodInfo method = this.Owner.GetType().GetMethod("UpdateSpatataldata");
                                    if (method != null)
                                    {
                                        string[] paramValues = new string[] { f.glebeProp.ObligateField16 };
                                        ParameterInfo[] paramInfos = method.GetParameters();
                                        if (paramInfos.Length == paramValues.Length)
                                        {
                                            // 参数个数相同才会执行
                                            object[] methodParams = new object[paramValues.Length];
                                            for (int i = 0; i < paramValues.Length; i++)
                                                methodParams[i] = Convert.ChangeType(paramValues[i], paramInfos[i].ParameterType, CultureInfo.InvariantCulture);

                                           // object instance = (method.IsStatic) ? null : Activator.CreateInstance(this.Owner.GetType());
                                            object result = method.Invoke(this.Owner, methodParams);
                                        }

                                    }
                                    this.Close();
                                }
                            }

                            //}
                        }

                    }
                    if (getlayer(SvgDocument.currentLayer, "城市规划层", tlVectorControl1.SVGDocument.getLayerList()))
                    {

                        if (tlVectorControl1.SVGDocument.getRZBRatio() != "")
                        {
                            rzb = tlVectorControl1.SVGDocument.getRZBRatio();
                        }

                        if (xml1 == null || tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
                        {
                            MessageBox.Show("请先选择地块。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Polygon")
                        {
                            string IsArea = ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).GetAttribute("IsArea");
                            if (IsArea != "")
                            {

                                frmProperty f = new frmProperty();//地块属性
                                if (SelUseArea == "") { SelUseArea = "0"; }
                                f.InitData(xml1.GetAttribute("id"), tlVectorControl1.SVGDocument.SvgdataUid, SelUseArea, rzb, SvgDocument.currentLayer);
                                //f.ShowDialog();
            #if(!CITY)
                                //将其中心点保存在XML中
                                PointF p = TLMath.polyCentriod((XmlElement)tlVectorControl1.SVGDocument.CurrentElement);
                                string title = p.X.ToString() + "," + p.Y.ToString();
                                ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).SetAttribute("centrpoint", title);
                                if (progtype != "城市规划层")
                                {
                                    f.IsReadonly = true;
                                }
            #endif
                                if (f.ShowDialog() == DialogResult.OK)
                                {
                                    SVG_ENTITY ent = new SVG_ENTITY();
                                    if (f.IsCreate)
                                    {
                                        ent.SUID = Guid.NewGuid().ToString();
                                        ent.EleID = f.gPro.EleID;
                                        ent.layerID = f.gPro.LayerID;
                                        ent.MDATE = System.DateTime.Now;
                                        ent.NAME = f.gPro.UseID;
                                        ent.svgID = f.gPro.SvgUID;
                                        ent.TYPE = "polygon-dk";
                                        //ent.voltage = f.gPro.Voltage;
                                        Services.BaseService.Create<SVG_ENTITY>(ent);
                                    }
                                    else
                                    {
                                        ent.NAME = f.gPro.UseID;
                                        ent.layerID = f.gPro.LayerID;
                                        ent.MDATE = System.DateTime.Now;
                                        //ent.voltage = fl.Line.Voltage;
                                        Services.BaseService.Update<SVG_ENTITY>(ent);
                                    }
                                    if (f.gPro.ObligateField1 != "")
                                    {
                                        string color1 = ColorTranslator.ToHtml(Color.FromArgb(Convert.ToInt32(f.gPro.ObligateField1)));
                                        color1 = "fill:" + color1 + ";";
                                        ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).SetAttribute("style", color1);
                                        tlVectorControl1.UpdateProperty();
                                    }

                                }
                            }
                        }
                    }
                    if (!Wjghboolflag)
                    {
                        if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Line" || tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Polyline")
                        {
                            string lineWidth = "2";
                            string IsLead = ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).GetAttribute("IsLead");
                            //if (IsLead != "")       //原先导线的属性添加情况

                            if (IsLead != "")       //修改后的导线的属性添加情况
                            {
                                XmlNodeList n11 = tlVectorControl1.SVGDocument.SelectNodes("svg/polygon [@IsArea='1']");
                                using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
                                {
                                    List<glebeProperty> glist = new List<glebeProperty>();
                                    for (int i = 0; i < n11.Count; i++)
                                    {
                                        IGraph graph1 = (IGraph)n11[i];
                                        GraphicsPath path1 = (GraphicsPath)graph1.GPath.Clone();
                                        //path1.Transform(graph1.GraphTransform.Matrix);
                                        Region ef1 = new Region(path1);

                                        Polyline line = tlVectorControl1.SVGDocument.CurrentElement as Polyline;
                                        GraphicsPath gr2 = new GraphicsPath();
                                        //gr2.AddLines(pfs);
                                        gr2.AddPath(line.GPath, true);
                                        gr2.CloseFigure();
                                        Region region = new Region(gr2);
                                        ef1.Intersect(region);
                                        if (!ef1.GetBounds(g).IsEmpty)
                                        {
                                            glebeProperty gy = new glebeProperty();
                                            gy.EleID = graph1.ID;
                                            gy.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                            gy = (glebeProperty)Services.BaseService.GetObject("SelectglebePropertyByEleID", gy);
                                            if (gy != null)
                                            {
                                                glebeType gt = new glebeType();
                                                gt.UID = gy.TypeUID;
                                                gt = (glebeType)Services.BaseService.GetObject("SelectglebeTypeByKey", gt);
                                                gy.TypeUID = gt.TypeName;
                                                glist.Add(gy);
                                            }
                                        }
                                    }
                                    DeviceHelper.glist = glist;
                                }
                                string dhx = xml1.GetAttribute("dhx_key");
                                if (dhx == "1" && checkEdit2.Checked == false)
                                {
                                    frmDHXdlg d = new frmDHXdlg();
                                    d.uid = xml1.GetAttribute("id");
                                    d.Show();
                                    return;
                                }

                                PSPDEV obj = new PSPDEV();
                                string deviceid = xml1.GetAttribute("Deviceid");
                                DeviceHelper.pspflag = false;
                                DeviceHelper.Wjghflag = false;
                                if (string.IsNullOrEmpty(deviceid))
                                {
                                    string[] deviceType = new string[] { "05", "74", "75" };
                                    string xlwhere = " where SUID not in (";
                                    XmlNodeList lslist = tlVectorControl1.SVGDocument.SelectNodes("svg/polyline [@IsLead='1'] [@Deviceid!=''] [@layer='" + SvgDocument.currentLayer + "']");
                                    for (int x1 = 0; x1 < lslist.Count; x1++)
                                    {
                                        XmlElement _node = lslist[x1] as XmlElement;
                                        xlwhere = xlwhere + "'" + _node.GetAttribute("Deviceid") + "',";
                                    }
                                    if (xlwhere.Length > 20)
                                    {
                                        xlwhere = xlwhere.Substring(0, xlwhere.Length - 1);
                                        xlwhere = xlwhere + ") and ";
                                    }
                                    else
                                    {
                                        xlwhere = "";
                                    }
                                    DeviceHelper.xlwhere = xlwhere;
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(Itop.Client.MIS.ProgUID, deviceType);
                                    DeviceHelper.xlwhere = "";
                                    if (obj is PSPDEV)
                                    {
                                        deviceid = ((PSPDEV)obj).SUID;
                                        xml1.SetAttribute("Deviceid", deviceid);
                                        obj.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        obj.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        obj.EleID = ((SvgElement)xml1).ID;
                                        Services.BaseService.Update<PSPDEV>(obj);
                                    }
                                }
                                if (!string.IsNullOrEmpty(deviceid))
                                {
                                    DeviceHelper.uid = tlVectorControl1.SVGDocument.SvgdataUid;
                                    DeviceHelper.layerid = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    DeviceHelper.eleid = tlVectorControl1.SVGDocument.CurrentElement.ID;

                                    obj = (PSPDEV)DeviceHelper.GetDevice<PSPDEV>(deviceid);
                                    if (obj != null)//------------wwwMX
                                    {
                                        xml1.SetAttribute("info-name", ((PSPDEV)obj).Name);
                                        if (obj.Type == "05")
                                        {
                                            DeviceHelper.ShowDeviceDlg(DeviceType.XL, deviceid, false);
                                        }
                                        if (obj.Type == "01")
                                        {
                                            DeviceHelper.ShowDeviceDlg(DeviceType.MX, deviceid, false);
                                        }

                                    }

                                    //***** ********添加FistNode和LastNode
                                    XmlNodeList useList = tlVectorControl1.SVGDocument.SelectNodes("svg/use");

                                    foreach (XmlNode element in useList)
                                    {
                                        if (!string.IsNullOrEmpty((element as XmlElement).GetAttribute("Deviceid")))
                                        {
                                            string con = "WHERE SvgUID='" + (element as XmlElement).GetAttribute("Deviceid") + "'AND ProjectID = '" + Itop.Client.MIS.ProgUID + "'" + "AND Type='01'";
                                            IList pspMX = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                            if (pspMX != null)
                                            {
                                                foreach (PSPDEV pspmx in pspMX)
                                                {
                                                    if (obj.IName == pspmx.Name)
                                                    {
                                                        (xml1 as XmlElement).SetAttribute("FirstNode", (element as XmlElement).GetAttribute("id"));

                                                    }
                                                    else if (obj.JName == pspmx.Name)
                                                    {
                                                        (xml1 as XmlElement).SetAttribute("LastNode", (element as XmlElement).GetAttribute("id"));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                //**

                            }
                        }

                        if (xml1.GetAttribute("xlink:href").Contains("Substation") || xml1.GetAttribute("xlink:href").Contains("Power"))
                        {//变电站属性
                            string lab = xml1.GetAttribute("xlink:href");

                            float x = 0f;
                            float y = 0f;

                            x = ((Use)xml1).X;

                            y = ((Use)xml1).Y;

                            PointF p1 = new PointF(x, y);
                            PointF[] pnt = new PointF[1];
                            pnt[0] = p1;
                            Use temp = xml1.Clone() as Use;
                            temp.Transform.Matrix.TransformPoints(pnt);

                            LongLat templat = mapview.OffSetZero(-(int)(pnt[0].X * tlVectorControl1.ScaleRatio), -(int)(pnt[0].Y * tlVectorControl1.ScaleRatio));

                            string[] jd = templat.Longitude.ToString("####.####").Split('.');
                            int d1 = Convert.ToInt32(jd[0]);
                            string[] df1 = Convert.ToString(Convert.ToDecimal("0." + jd[1]) * 60).Split('.');
                            int f1 = Convert.ToInt32(df1[0]);
                            decimal m1 = Convert.ToDecimal("0." + df1[1]) * 60;

                            string[] wd = templat.Latitude.ToString("####.####").Split('.');
                            int d2 = Convert.ToInt32(wd[0]);
                            string[] df2 = Convert.ToString(Convert.ToDecimal("0." + wd[1]) * 60).Split('.');
                            int f2 = Convert.ToInt32(df2[0]);
                            decimal m2 = Convert.ToDecimal("0." + df2[1]) * 60;

                            string strjwd = "经纬度: " + d1.ToString() + "°" + f1.ToString() + "′" + m1.ToString("##.#") + "″," + d2.ToString() + "°" + f2.ToString() + "′" + m2.ToString("##.#") + "″";
                            object obj = null;
                            string deviceid = xml1.GetAttribute("Deviceid");
                            DeviceHelper.pspflag = false;
                            DeviceHelper.Wjghflag = false;
                        Lab1://变电站、电源属性
                            if (string.IsNullOrEmpty(deviceid))
                            {
                                //XmlElement n1 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                                if (xml1.GetAttribute("xlink:href").Contains("Power"))
                                {
                                    obj = DeviceHelper.SelectDevice(DeviceType.DY, Itop.Client.MIS.ProgUID);
                                    //if (obj == null)
                                    //{
                                    //    tlVectorControl1.SVGDocument.CurrentElement = xml1 as SvgElement;
                                    //    tlVectorControl1.Delete();
                                    //}
                                    if (obj is PSP_PowerSubstation_Info)
                                    {
                                        deviceid = ((PSP_PowerSubstation_Info)obj).UID;
                                        ((PSP_PowerSubstation_Info)obj).LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        //((PSP_PowerSubstation_Info)obj). = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        Services.BaseService.Update<PSP_PowerSubstation_Info>(((PSP_PowerSubstation_Info)obj));
                                        xml1.SetAttribute("Deviceid", deviceid);
                                        xml1.SetAttribute("info-name", ((PSP_PowerSubstation_Info)obj).Title);
                                    }

                                    substation sb = new substation();
                                    sb.UID = ((PSP_PowerSubstation_Info)obj).UID;
                                    sb = (substation)Services.BaseService.GetObject("SelectsubstationByKey", sb);
                                    if (sb != null)
                                    {
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_PowerSubstation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_PowerSubstation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Update<substation>(sb);
                                    }
                                    else
                                    {
                                        sb = new substation();
                                        sb.UID = ((PSP_PowerSubstation_Info)obj).UID;
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.EleID = xml1.GetAttribute("id");
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        if (((PSP_PowerSubstation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_PowerSubstation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Create<substation>(sb);
                                    }
                                }
                                else
                                {
                                    DeviceHelper.uid = tlVectorControl1.SVGDocument.SvgdataUid;
                                    DeviceHelper.eleid = tlVectorControl1.SVGDocument.CurrentElement.ID;
                                    DeviceHelper.layerid = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    //wwww
                                    string bdzwhere = " UID not in (";

                                    XmlNodeList useList = tlVectorControl1.SVGDocument.SelectNodes("svg/use [@Deviceid!=''] [@layer='" + SvgDocument.currentLayer + "']");

                                    for (int x2 = 0; x2 < useList.Count; x2++)
                                    {
                                        XmlElement _node = useList[x2] as XmlElement;
                                        bdzwhere = bdzwhere + "'" + _node.GetAttribute("Deviceid") + "',";
                                    }
                                    if (bdzwhere.Length > 13)
                                    {
                                        bdzwhere = bdzwhere.Substring(0, bdzwhere.Length - 1);
                                        bdzwhere = bdzwhere + ") and ";
                                    }
                                    else
                                    {
                                        bdzwhere = "";
                                    }

                                    DeviceHelper.bdzwhere = bdzwhere;
                                    obj = DeviceHelper.SelectDevice(DeviceType.BDZ, Itop.Client.MIS.ProgUID);
                                    DeviceHelper.bdzwhere = "";
                                    //if (obj == null)
                                    //{
                                    //    tlVectorControl1.SVGDocument.CurrentElement = xml1 as SvgElement;
                                    //    tlVectorControl1.Delete();
                                    //}
                                    if (obj is PSP_Substation_Info)
                                    {
                                        deviceid = ((PSP_Substation_Info)obj).UID;
                                        ((PSP_Substation_Info)obj).LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        ((PSP_Substation_Info)obj).EleID = tlVectorControl1.SVGDocument.CurrentElement.ID;
                                        Services.BaseService.Update<PSP_Substation_Info>(((PSP_Substation_Info)obj));
                                        xml1.SetAttribute("Deviceid", deviceid);
                                        xml1.SetAttribute("info-name", ((PSP_Substation_Info)obj).Title);
                                        //return;

                                    }
                                    /*
                                    substation sb = new substation();
                                    sb.UID = ((PSP_Substation_Info)obj).UID;
                                    sb = (substation)Services.BaseService.GetObject("SelectsubstationByKey", sb);
                                    if (sb != null)
                                    {

                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_Substation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_Substation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Update<substation>(sb);
                                    }
                                    else
                                    {
                                        sb = new substation();
                                        sb.UID = ((PSP_Substation_Info)obj).UID;
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.EleID = xml1.GetAttribute("id");
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        if (((PSP_Substation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_Substation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Create<substation>(sb);
                                    }*/
                                }
                            }
                            if (!string.IsNullOrEmpty(deviceid))
                            {
                                if (xml1.GetAttribute("xlink:href").Contains("Power"))
                                {
                                    DeviceHelper.uid = tlVectorControl1.SVGDocument.SvgdataUid;
                                    DeviceHelper.eleid = tlVectorControl1.SVGDocument.CurrentElement.ID;
                                    DeviceHelper.layerid = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    obj = DeviceHelper.GetDevice<PSP_PowerSubstation_Info>(deviceid);
                                    if (obj != null)
                                    {

                                        //XmlElement n1 = tlVectorControl1.SVGDocument.SelectSingleNode("/text[@ParentUID='" + xml1.GetAttribute("id") + "']");
                                        if (DeviceHelper.ShowDeviceDlg(DeviceType.DY, deviceid, false))
                                        {
                                            obj = DeviceHelper.GetDevice<PSP_PowerSubstation_Info>(deviceid);
                                            xml1.SetAttribute("info-name", ((PSP_PowerSubstation_Info)obj).Title);
                                        }
                                    }
                                    else
                                    {
                                        deviceid = ""; goto Lab1;
                                    }

                                    // re
                                    substation sb = new substation();
                                    sb.UID = ((PSP_PowerSubstation_Info)obj).UID;
                                    sb = (substation)Services.BaseService.GetObject("SelectsubstationByKey", sb);
                                    if (sb != null)
                                    {
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_PowerSubstation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_PowerSubstation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Update<substation>(sb);
                                    }
                                    else
                                    {
                                        sb = new substation();
                                        sb.UID = ((PSP_PowerSubstation_Info)obj).UID;
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_PowerSubstation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_PowerSubstation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Create<substation>(sb);
                                    }
                                }
                                else
                                {
                                    obj = DeviceHelper.GetDevice<PSP_Substation_Info>(deviceid);
                                    if (obj != null)
                                    {
                                        //XmlElement n1 = tlVectorControl1.SVGDocument.SelectSingleNode("/text[@ParentUID='" + xml1.GetAttribute("id") + "']");
                                        if (DeviceHelper.ShowDeviceDlg(DeviceType.BDZ, deviceid, false))
                                        {
                                            obj = DeviceHelper.GetDevice<PSP_Substation_Info>(deviceid);
                                            xml1.SetAttribute("info-name", ((PSP_Substation_Info)obj).Title);
                                        }
                                    }
                                    else
                                    {
                                        deviceid = ""; goto Lab1;
                                    }
                                    substation sb = new substation();
                                    sb.UID = ((PSP_Substation_Info)obj).UID;
                                    sb = (substation)Services.BaseService.GetObject("SelectsubstationByKey", sb);
                                    if (sb != null)
                                    {
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_Substation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_Substation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Update<substation>(sb);
                                    }
                                    else
                                    {
                                        sb = new substation();
                                        sb.UID = ((PSP_Substation_Info)obj).UID;
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.EleID = xml1.GetAttribute("id");
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        if (((PSP_Substation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_Substation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Create<substation>(sb);
                                    }
                                }

                            }

                        }
                        if (xml1.GetAttribute("xlink:href").Contains("XL_GT_3") || xml1.GetAttribute("xlink:href").Contains("XL_GT_4"))
                        {
                            frmInputNum num = new frmInputNum();
                            num.InputStr = xml1.GetAttribute("order");
                            num.ShowDialog();
                            xml1.SetAttribute("order", num.InputStrSEL);
                        }
                        if (xml1.GetAttribute("xlink:href").Contains("hwg") || xml1.GetAttribute("xlink:href").Contains("pds") ||
                            xml1.GetAttribute("xlink:href").Contains("fjx") || xml1.GetAttribute("xlink:href").Contains("kbs") ||
                            xml1.GetAttribute("xlink:href").Contains("byq") || xml1.GetAttribute("xlink:href").Contains("kg") ||
                             xml1.GetAttribute("xlink:href").Contains("gt"))
                        {
                            //frmInputDialog n1 = new frmInputDialog();
                            //n1.InputStr = xml1.GetAttribute("info-name").ToString();
                            //if (n1.ShowDialog() == DialogResult.OK)
                            //{
                            //    xml1.SetAttribute("info-name", n1.InputStr);
                            //}
                            PSPDEV obj = new PSPDEV();
                            string deviceid = xml1.GetAttribute("Deviceid");
                            DeviceHelper.pspflag = false;
                            DeviceHelper.Wjghflag = false;
                            if (string.IsNullOrEmpty(deviceid))
                            {
                                if (xml1.GetAttribute("xlink:href").Contains("kbs"))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.KBS, Itop.Client.MIS.ProgUID);
                                }
                                if (xml1.GetAttribute("xlink:href").Contains("fjx"))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.FZX, Itop.Client.MIS.ProgUID);
                                }
                                if (xml1.GetAttribute("xlink:href").Contains("hwg"))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.HWG, Itop.Client.MIS.ProgUID);
                                }
                                if (xml1.GetAttribute("xlink:href").Contains("kg"))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.ZSKG, Itop.Client.MIS.ProgUID);
                                }
                                if (xml1.GetAttribute("xlink:href").Contains("pds"))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.PDS, Itop.Client.MIS.ProgUID);
                                }
                                if (xml1.GetAttribute("xlink:href").Contains("byq"))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(Itop.Client.MIS.ProgUID, "51", "52");
                                }
                                //if (xml1.GetAttribute("xlink:href").Contains("gt"))
                                //{
                                //    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.GT, Itop.Client.MIS.ProgUID);
                                //}
                                if (obj is PSPDEV)
                                {
                                    deviceid = ((PSPDEV)obj).SUID;
                                    xml1.SetAttribute("Deviceid", deviceid);
                                    obj.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                    obj.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                    // obj.EleID = ((SvgElement)xml1).ID;
                                    Services.BaseService.Update<PSPDEV>(obj);
                                }
                            }
                            if (!string.IsNullOrEmpty(deviceid))
                            {
                                DeviceHelper.uid = tlVectorControl1.SVGDocument.SvgdataUid;
                                DeviceHelper.layerid = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                DeviceHelper.eleid = tlVectorControl1.SVGDocument.CurrentElement.ID;

                                obj = (PSPDEV)DeviceHelper.GetDevice<PSPDEV>(deviceid);
                                if (obj != null)//------------wwwMX
                                {
                                    xml1.SetAttribute("info-name", ((PSPDEV)obj).Name);
                                    DeviceHelper.ShowDeviceDlg((DeviceType)int.Parse(obj.Type), deviceid, false);
                                    //if (obj.Type == "54")
                                    //{
                                    //    DeviceHelper.ShowDeviceDlg(DeviceType.KBS, deviceid, false);
                                    //}
                                    //if (obj.Type == "56")
                                    //{
                                    //    DeviceHelper.ShowDeviceDlg(DeviceType.HWG, deviceid, false);
                                    //}
                                    //if (obj.Type == "58")
                                    //{
                                    //    DeviceHelper.ShowDeviceDlg(DeviceType.FZX, deviceid, false);
                                    //}
                                    //if (obj.Type == "51" )
                                    //{
                                    //    DeviceHelper.ShowDeviceDlg(DeviceType.FZX, deviceid, false);
                                    //}
                                    //if (obj.Type == "52")
                                    //{
                                    //    DeviceHelper.ShowDeviceDlg(DeviceType.FZX, deviceid, false);
                                    //}
                                }
                            }

                        }
                        /* if (xml1.GetAttribute("xlink:href").Contains("kbs") || xml1.GetAttribute("xlink:href").Contains("hwg"))
                         {
                             //frmkbsProperty num = new frmkbsProperty();
                             //num.InitData(((SvgElement)xml1).ID, tlVectorControl1.SVGDocument.SvgdataUid, tlVectorControl1.SVGDocument.CurrentLayer.ID);
                             //num.ShowDialog();

                         }
                         if (xml1.GetAttribute("xlink:href").Contains("fjx"))
                         {
                             frmfjxProperty num = new frmfjxProperty();
                             num.InitData(((SvgElement)xml1).ID, tlVectorControl1.SVGDocument.SvgdataUid, tlVectorControl1.SVGDocument.CurrentLayer.ID);
                             num.ShowDialog();
                         }
                         if (xml1.GetAttribute("xlink:href").Contains("byq"))
                         {
                             frmbyqProperty num = new frmbyqProperty();
                             num.InitData(((SvgElement)xml1).ID, tlVectorControl1.SVGDocument.SvgdataUid, tlVectorControl1.SVGDocument.CurrentLayer.ID);
                             num.ShowDialog();
                         } */
                        if (xml1.GetAttribute("xlink:href").Contains("SB_GT"))
                        {
                            string lineWidth = "2";

                            string Code = xltProcessor.GetCurrentLineCode();
                            string _len = xltProcessor.GetWholeLineLength(Code).ToString("#####.####");

                            frmLineProperty fl = new frmLineProperty();
                            fl.LineNode = tlVectorControl1.SVGDocument.CurrentElement;
                            fl.InitData(Code, tlVectorControl1.SVGDocument.SvgdataUid, _len, SvgDocument.currentLayer);
                            if (fl.ShowDialog() == DialogResult.OK)
                            {
                                //Value="stroke-dasharray:8 8;stroke-width:2;stroke:#00C000;"
                                lineWidth = fl.LineWidth;
                                string styleValue = "";
                                if (fl.Line.ObligateField1 == "规划")
                                {
                                    styleValue = "stroke-dasharray:4 4;stroke-width:" + lineWidth + ";";
                                }
                                else
                                {
                                    styleValue = "stroke-width:" + lineWidth + ";";
                                }

                                styleValue = styleValue + "stroke:" + ColorTranslator.ToHtml(Color.FromArgb(Convert.ToInt32(fl.Line.ObligateField2)));
                                ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).RemoveAttribute("style");
                                ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).SetAttribute("style", styleValue);

                                xltProcessor.SetWholeLineAttribute(Code, "style", styleValue);
                            }
                        }
                    }
                    #region 网架优化的属性输入

                    if (Wjghboolflag)
                    {
                        checkwjghelement();
                        if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Line" || tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Polyline")
                        {
                            string lineWidth = "2";
                            string IsLead = ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).GetAttribute("IsLead");
                            if (IsLead != "")       //修改后的导线的属性添加情况
                            {
                                PSPDEV obj = new PSPDEV();
                                string deviceid = xml1.GetAttribute("Deviceid");
                                DeviceHelper.pspflag = false;
                                DeviceHelper.Wjghflag = true;
                                DeviceHelper.wjghuid = ff.Key;
                                if (string.IsNullOrEmpty(deviceid))
                                {
                                    obj = (PSPDEV)DeviceHelper.SelectDevice(DeviceType.XL, Itop.Client.MIS.ProgUID);
                                    if (obj == null)
                                    {
                                        tlVectorControl1.SVGDocument.CurrentElement = xml1 as SvgElement;
                                        tlVectorControl1.Delete();
                                    }
                                    if (obj is PSPDEV)
                                    {
                                        deviceid = ((PSPDEV)obj).SUID;
                                        xml1.SetAttribute("Deviceid", deviceid);
                                        obj.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        obj.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        obj.EleID = ((SvgElement)xml1).ID;
                                        Services.BaseService.Update<PSPDEV>((PSPDEV)obj);
                                    }
                                }
                                if (!string.IsNullOrEmpty(deviceid))
                                {
                                    obj = (PSPDEV)DeviceHelper.GetDevice<PSPDEV>(deviceid);
                                    if (obj != null)
                                    {
                                        xml1.SetAttribute("info-name", ((PSPDEV)obj).Name);
                                        DeviceHelper.ShowDeviceDlg(DeviceType.XL, deviceid, false);
                                    }

                                    LineInfo li = new LineInfo();
                                    li.UID = obj.SUID;
                                    li = (LineInfo)Services.BaseService.GetObject("SelectLineInfoByKey", li);
                                    if (li != null)
                                    {
                                        li.LayerID = SvgDocument.currentLayer;
                                        li.EleID = xml1.GetAttribute("id");
                                        li.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        LineType lt = new LineType();
                                        lt.TypeName = li.Voltage.ToString() + "kV";
                                        lt = (LineType)Services.BaseService.GetObject("SelectLineTypeByTypeName", lt);
                                        li.ObligateField3 = obj.OperationYear;
                                        li.ObligateField2 = lt.Color;
                                        lineWidth = lt.ObligateField1;
                                        if (!string.IsNullOrEmpty(li.ObligateField3))
                                        {
                                            if (Convert.ToInt32(obj.OperationYear) > DateTime.Now.Year)
                                            {
                                                li.ObligateField1 = "规划";
                                            }
                                            else
                                                li.ObligateField1 = "运行";
                                        }
                                        Services.BaseService.Update<LineInfo>(li);
                                    }
                                    else
                                    {
                                        li = new LineInfo();
                                        li.UID = obj.SUID;
                                        li.LineName = obj.Name;
                                        li.Length = obj.LineLength.ToString();
                                        li.LineType = obj.LineType;
                                        li.Voltage = obj.ReferenceVolt.ToString();
                                        li.EleID = xml1.GetAttribute("id");
                                        li.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        LineType lt = new LineType();
                                        lt.TypeName = obj.ReferenceVolt.ToString() + "kV";
                                        lt = (LineType)Services.BaseService.GetObject("SelectLineTypeByTypeName", lt);
                                        li.ObligateField3 = obj.OperationYear;
                                        li.ObligateField2 = lt.Color;
                                        lineWidth = lt.ObligateField1;
                                        if (!string.IsNullOrEmpty(li.ObligateField3))
                                        {
                                            if (Convert.ToInt32(obj.OperationYear) > DateTime.Now.Year)
                                            {
                                                li.ObligateField1 = "规划";
                                            }
                                            else
                                                li.ObligateField1 = "运行";
                                        }

                                        Services.BaseService.Create<LineInfo>(li);
                                    }

                                    string styleValue = "";
                                    if (li.ObligateField1 == "规划")
                                    {
                                        styleValue = "stroke-dasharray:" + ghType + ";stroke-width:" + lineWidth + ";";
                                    }
                                    else
                                    {
                                        styleValue = "stroke-width:" + lineWidth + ";";
                                    }
                                    //string aa= ColorTranslator.ToHtml(Color.Black);
                                    styleValue = styleValue + "stroke:" + ColorTranslator.ToHtml(Color.FromArgb(Convert.ToInt32(li.ObligateField2)));
                                    SvgElement se = tlVectorControl1.SVGDocument.CurrentElement;
                                    se.RemoveAttribute("style");
                                    se.SetAttribute("style", styleValue);
                                    se.SetAttribute("info-name", li.LineName);
                                    //***** ********添加FistNode和LastNode
                                    XmlNodeList useList = tlVectorControl1.SVGDocument.SelectNodes("svg/use");

                                    foreach (XmlNode element in useList)
                                    {
                                        if (!string.IsNullOrEmpty((element as XmlElement).GetAttribute("Deviceid")))
                                        {
                                            string con = "WHERE SvgUID='" + (element as XmlElement).GetAttribute("Deviceid") + "'AND ProjectID = '" + Itop.Client.MIS.ProgUID + "'" + "AND Type='01'";
                                            IList pspMX = Services.BaseService.GetList("SelectPSPDEVByCondition", con);
                                            if (pspMX != null)
                                            {
                                                foreach (PSPDEV pspmx in pspMX)
                                                {
                                                    if (obj.IName == pspmx.Name)
                                                    {
                                                        (xml1 as XmlElement).SetAttribute("FirstNode", (element as XmlElement).GetAttribute("id"));

                                                    }
                                                    else if (obj.JName == pspmx.Name)
                                                    {
                                                        (xml1 as XmlElement).SetAttribute("LastNode", (element as XmlElement).GetAttribute("id"));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                //**

                            }
                        }

                        if (xml1.GetAttribute("xlink:href").Contains("Substation") || xml1.GetAttribute("xlink:href").Contains("Power"))
                        {
                            string lab = xml1.GetAttribute("xlink:href");

                            float x = 0f;
                            float y = 0f;

                            x = ((Use)xml1).X;

                            y = ((Use)xml1).Y;

                            PointF p1 = new PointF(x, y);
                            PointF[] pnt = new PointF[1];
                            pnt[0] = p1;
                            Use temp = xml1.Clone() as Use;
                            temp.Transform.Matrix.TransformPoints(pnt);

                            LongLat templat = mapview.OffSetZero(-(int)(pnt[0].X * tlVectorControl1.ScaleRatio), -(int)(pnt[0].Y * tlVectorControl1.ScaleRatio));

                            string[] jd = templat.Longitude.ToString("####.####").Split('.');
                            int d1 = Convert.ToInt32(jd[0]);
                            string[] df1 = Convert.ToString(Convert.ToDecimal("0." + jd[1]) * 60).Split('.');
                            int f1 = Convert.ToInt32(df1[0]);
                            decimal m1 = Convert.ToDecimal("0." + df1[1]) * 60;

                            string[] wd = templat.Latitude.ToString("####.####").Split('.');
                            int d2 = Convert.ToInt32(wd[0]);
                            string[] df2 = Convert.ToString(Convert.ToDecimal("0." + wd[1]) * 60).Split('.');
                            int f2 = Convert.ToInt32(df2[0]);
                            decimal m2 = Convert.ToDecimal("0." + df2[1]) * 60;

                            string strjwd = "经纬度: " + d1.ToString() + "°" + f1.ToString() + "′" + m1.ToString("##.#") + "″," + d2.ToString() + "°" + f2.ToString() + "′" + m2.ToString("##.#") + "″";
                            object obj = null;
                            string deviceid = xml1.GetAttribute("Deviceid");
                            DeviceHelper.pspflag = false;
                            DeviceHelper.Wjghflag = true;
                            if (string.IsNullOrEmpty(deviceid))
                            {
                                //XmlElement n1 = tlVectorControl1.SVGDocument.CreateElement("text") as Text;
                                if (xml1.GetAttribute("xlink:href").Contains("Power"))
                                {
                                    obj = DeviceHelper.SelectDevice(DeviceType.DY, Itop.Client.MIS.ProgUID);
                                    if (obj == null)
                                    {
                                        tlVectorControl1.SVGDocument.CurrentElement = xml1 as SvgElement;
                                        tlVectorControl1.Delete();
                                    }
                                    if (obj is PSP_PowerSubstation_Info)
                                    {
                                        deviceid = ((PSP_PowerSubstation_Info)obj).UID;
                                        ((PSP_PowerSubstation_Info)obj).LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;

                                        Services.BaseService.Update<PSP_PowerSubstation_Info>(((PSP_PowerSubstation_Info)obj));
                                        xml1.SetAttribute("Deviceid", deviceid);
                                    }
                                    substation sb = new substation();
                                    sb.UID = ((PSP_PowerSubstation_Info)obj).UID;
                                    sb = (substation)Services.BaseService.GetObject("SelectsubstationByKey", sb);
                                    if (sb != null)
                                    {
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_PowerSubstation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_PowerSubstation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Update<substation>(sb);
                                    }
                                    else
                                    {
                                        sb = new substation();
                                        sb.UID = ((PSP_PowerSubstation_Info)obj).UID;
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.EleID = xml1.GetAttribute("id");
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        if (((PSP_PowerSubstation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_PowerSubstation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Create<substation>(sb);
                                    }
                                }
                                else
                                {
                                    obj = DeviceHelper.SelectDevice(DeviceType.BDZ, Itop.Client.MIS.ProgUID);
                                    if (obj == null)
                                    {
                                        tlVectorControl1.SVGDocument.CurrentElement = xml1 as SvgElement;
                                        tlVectorControl1.Delete();
                                    }
                                    if (obj is PSP_Substation_Info)
                                    {
                                        deviceid = ((PSP_Substation_Info)obj).UID;
                                        ((PSP_Substation_Info)obj).LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        ((PSP_Substation_Info)obj).EleID = tlVectorControl1.SVGDocument.CurrentElement.ID;
                                        Services.BaseService.Update<PSP_Substation_Info>(((PSP_Substation_Info)obj));
                                        xml1.SetAttribute("Deviceid", deviceid);

                                    }
                                    substation sb = new substation();
                                    sb.UID = ((PSP_Substation_Info)obj).UID;
                                    sb = (substation)Services.BaseService.GetObject("SelectsubstationByKey", sb);
                                    if (sb != null)
                                    {

                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        sb.EleID = xml1.GetAttribute("id");
                                        if (((PSP_Substation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_Substation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Update<substation>(sb);
                                    }
                                    else
                                    {
                                        sb = new substation();
                                        sb.UID = ((PSP_Substation_Info)obj).UID;
                                        sb.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                                        sb.EleID = xml1.GetAttribute("id");
                                        sb.LayerID = tlVectorControl1.SVGDocument.CurrentLayer.ID;
                                        if (((PSP_Substation_Info)obj).Flag == "2")
                                        {
                                            sb.ObligateField3 = "规划";
                                        }
                                        else if (((PSP_Substation_Info)obj).Flag == "1")
                                        {
                                            sb.ObligateField3 = "现行";
                                        }
                                        Services.BaseService.Create<substation>(sb);
                                    }
                                }
                            }
                            if (!string.IsNullOrEmpty(deviceid))
                            {
                                if (xml1.GetAttribute("xlink:href").Contains("Power"))
                                {
                                    obj = DeviceHelper.GetDevice<PSP_PowerSubstation_Info>(deviceid);
                                    if (obj != null)
                                    {
                                        xml1.SetAttribute("info-name", ((PSP_PowerSubstation_Info)obj).Title);
                                        //XmlElement n1 = tlVectorControl1.SVGDocument.SelectSingleNode("/text[@ParentUID='" + xml1.GetAttribute("id") + "']");
                                        DeviceHelper.ShowDeviceDlg(DeviceType.DY, deviceid, false);
                                    }

                                }
                                else
                                {
                                    obj = DeviceHelper.GetDevice<PSP_Substation_Info>(deviceid);
                                    if (obj != null)
                                    {
                                        xml1.SetAttribute("info-name", ((PSP_Substation_Info)obj).Title);
                                        //XmlElement n1 = tlVectorControl1.SVGDocument.SelectSingleNode("/text[@ParentUID='" + xml1.GetAttribute("id") + "']");
                                        DeviceHelper.ShowDeviceDlg(DeviceType.BDZ, deviceid, false);
                                    }

                                }

                            }

                        }
                        if (xml1.GetAttribute("xlink:href").Contains("XL_GT_3") || xml1.GetAttribute("xlink:href").Contains("XL_GT_4"))
                        {
                            frmInputNum num = new frmInputNum();
                            num.InputStr = xml1.GetAttribute("order");
                            num.ShowDialog();
                            xml1.SetAttribute("order", num.InputStrSEL);
                        }

                        //if (xml1.GetAttribute("xlink:href").Contains("kbs") || xml1.GetAttribute("xlink:href").Contains("hwg"))
                        //{
                        //    frmkbsProperty num = new frmkbsProperty();
                        //    num.InitData(((SvgElement)xml1).ID, tlVectorControl1.SVGDocument.SvgdataUid, tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        //    num.ShowDialog();
                        //}
                        //if (xml1.GetAttribute("xlink:href").Contains("fjx"))
                        //{
                        //    frmfjxProperty num = new frmfjxProperty();
                        //    num.InitData(((SvgElement)xml1).ID, tlVectorControl1.SVGDocument.SvgdataUid, tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        //    num.ShowDialog();
                        //}
                        //if (xml1.GetAttribute("xlink:href").Contains("byq"))
                        //{
                        //    frmbyqProperty num = new frmbyqProperty();
                        //    num.InitData(((SvgElement)xml1).ID, tlVectorControl1.SVGDocument.SvgdataUid, tlVectorControl1.SVGDocument.CurrentLayer.ID);
                        //    num.ShowDialog();
                        //}
                        if (xml1.GetAttribute("xlink:href").Contains("SB_GT"))
                        {
                            string lineWidth = "2";

                            string Code = xltProcessor.GetCurrentLineCode();
                            string _len = xltProcessor.GetWholeLineLength(Code).ToString("#####.####");

                            frmLineProperty fl = new frmLineProperty();
                            fl.LineNode = tlVectorControl1.SVGDocument.CurrentElement;
                            fl.InitData(Code, tlVectorControl1.SVGDocument.SvgdataUid, _len, SvgDocument.currentLayer);
                            if (fl.ShowDialog() == DialogResult.OK)
                            {
                                //Value="stroke-dasharray:8 8;stroke-width:2;stroke:#00C000;"
                                lineWidth = fl.LineWidth;
                                string styleValue = "";
                                if (fl.Line.ObligateField1 == "规划")
                                {
                                    styleValue = "stroke-dasharray:4 4;stroke-width:" + lineWidth + ";";
                                }
                                else
                                {
                                    styleValue = "stroke-width:" + lineWidth + ";";
                                }

                                styleValue = styleValue + "stroke:" + ColorTranslator.ToHtml(Color.FromArgb(Convert.ToInt32(fl.Line.ObligateField2)));
                                ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).RemoveAttribute("style");
                                ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).SetAttribute("style", styleValue);

                                xltProcessor.SetWholeLineAttribute(Code, "style", styleValue);
                            }
                        }
                    }
                    #endregion
                }
                if (e.ClickedItem.Text == "移动")
                {
                    if (tlVectorControl1.SVGDocument.CurrentElement == null || tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
                    {
                        return;
                    }
                    XmlElement xmln = (XmlElement)tlVectorControl1.SVGDocument.CurrentElement;
                    frmMove fm = new frmMove();
                    PointF pf11 = ((Use)xmln).CenterPoint;
                    LongLat temp = mapview.ParseToLongLat((int)pf11.X, (int)pf11.Y);
                    string[] jd = temp.Longitude.ToString("####.####").Split('.');
                    int d1 = Convert.ToInt32(jd[0]);
                    string[] df1 = Convert.ToString(Convert.ToDecimal("0." + jd[1]) * 60).Split('.');
                    int f1 = Convert.ToInt32(df1[0]);
                    decimal m1 = Convert.ToDecimal("0." + df1[1]) * 60;

                    string[] wd = temp.Latitude.ToString("####.####").Split('.');
                    int d2 = Convert.ToInt32(wd[0]);
                    string[] df2 = Convert.ToString(Convert.ToDecimal("0." + wd[1]) * 60).Split('.');
                    int f2 = Convert.ToInt32(df2[0]);
                    decimal m2 = Convert.ToDecimal("0." + df2[1]) * 60;
                    strj1 = d1.ToString();
                    strw1 = f1.ToString();
                    strd1 = m1.ToString();
                    strj2 = d2.ToString();
                    strw2 = f2.ToString();
                    strd2 = m2.ToString();
                    fm.Init(strj1, strw1, strd1, strj2, strw2, strd2);
                    if (fm.ShowDialog() == DialogResult.OK)
                    {
                        string strValue = fm.StrValue;
                        string[] str = strValue.Split(',');
                        string[] JWD1 = str[0].Split(' ');
                        decimal J1 = Convert.ToDecimal(JWD1[0]);
                        decimal W1 = Convert.ToDecimal(JWD1[1]);
                        decimal D1 = Convert.ToDecimal(JWD1[2]);
                        string[] JWD2 = str[1].Split(' ');
                        decimal J2 = Convert.ToDecimal(JWD2[0]);
                        decimal W2 = Convert.ToDecimal(JWD2[1]);
                        decimal D2 = Convert.ToDecimal(JWD2[2]);

                        decimal JD = J1 + W1 / 60 + D1 / 3600;
                        decimal WD = J2 + W2 / 60 + D2 / 3600;

                        PointF pf1 = mapview.ParseToPoint(JD, WD);

                        PointF p1 = ((Use)xmln).CenterPoint;

                        SvgElement e1 = xmln as SvgElement;
                        Matrix matrix2 = ((IGraph)e1).GraphTransform.Matrix.Clone();
                        Matrix matrix3 = tlVectorControl1.DrawArea.CoordTransform.Clone();
                        matrix3.Invert();
                        matrix2.Multiply(matrix3, MatrixOrder.Append);
                        matrix2.Invert();
                        PointF[] pfArray1 = new PointF[] { new PointF(pf1.X / tlVectorControl1.ScaleRatio, pf1.Y / tlVectorControl1.ScaleRatio), p1 };
                        matrix2.TransformPoints(pfArray1);

                        float single1 = pfArray1[0].X - pfArray1[1].X;
                        float single2 = pfArray1[0].Y - pfArray1[1].Y;

                        Matrix matrix6 = ((IGraph)e1).Transform.Matrix.Clone();
                        if (e1.SvgAttributes.ContainsKey("transform"))
                        {
                            Matrix matrix7 = ((Matrix)e1.SvgAttributes["transform"]).Clone();
                            matrix7.Invert();
                            matrix6.Multiply(matrix7, MatrixOrder.Append);
                        }
                        Matrix matrix5 = new Matrix();
                        matrix5.Translate(single1, single2);
                        Matrix matrix8 = ((IGraph)e1).Transform.Matrix.Clone();
                        matrix8.Multiply(matrix5);
                        matrix6.Invert();
                        matrix6.Multiply(matrix8, MatrixOrder.Append);
                        Transf tf = new Transf();
                        tf.setMatrix(matrix6);
                        (xmln as Use).Transform = tf;

                    }
                }
                if (e.ClickedItem.Text == "接线图")
                {
                    if (tlVectorControl1.SVGDocument.CurrentElement == null || tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
                    {
                        return;
                    }
                    ParentUID = tlVectorControl1.SVGDocument.SvgdataUid;
                    Save();
                    ParentUID = tlVectorControl1.SVGDocument.SvgdataUid;
                    SVGFILE svg_temp = new SVGFILE();
                    //XmlElement xml1 = ((XmlElement)(e.Elements[0]));xml1.GetAttribute("id");
                    svg_temp.SUID = ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).GetAttribute("id");
                    svg_temp.FILENAME = getBdzName(svg_temp.SUID);// ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).GetAttribute("info-name");
                    string strWhere = string.Format("suid='{0}' or filename='{1}' ", svg_temp.SUID, svg_temp.FILENAME);
                    IList svglist = Services.BaseService.GetList("SelectSVGFILEByWhere", strWhere);
                    OpenJXT(svglist, svg_temp);
                    //frmlar.SymbolDoc = tlVectorControl1.SVGDocument;
                    //frmlar.Progtype = MapType;
                    //frmlar.InitData();
                    //JxtBar();
                }
                if (e.ClickedItem.Text == "打开")
                {
                    if (tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
                    {
                        MessageBox.Show("请选择地块。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    UseRelating UseRel = new UseRelating();
                    UseRel.UseID = tlVectorControl1.SVGDocument.CurrentElement.ID;
                    IList<UseRelating> UseRelList = Services.BaseService.GetList<UseRelating>("SelectUseRelatingByUseID", UseRel);
                    if (UseRelList.Count < 1)
                    {
                        MessageBox.Show("选择的地块还没有关联到其他地图,请先设置关联地图", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    UseRel = UseRelList[0];
                    SVGFILE svgFile = new SVGFILE();
                    svgFile.SUID = UseRel.LinkUID;
                    IList svgList = Services.BaseService.GetList("SelectSVGFILEByKey", svgFile);
                    if (svgList.Count < 1)
                    {
                        MessageBox.Show("被关联的地图已经被删除,请重新设置关联地图", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    svgFile = (SVGFILE)svgList[0];
                    //SvgDocument doc = new SvgDocument();

                    if (!string.IsNullOrEmpty(svgFile.SVGDATA))
                    {
                        //doc.LoadXml(svgFile.SVGDATA);
                        ctlfile_OnOpenSvgDocument(sender, svgFile.SUID);
                    }

                }
                if (e.ClickedItem.Text == "区域打印")
                {
                    PrintHelper ph = new PrintHelper(tlVectorControl1, mapview);
                    frmPrinter dlg = new frmPrinter();
                    dlg.printHelper = ph;
                    dlg.ShowDialog();
                    return;
                    ArrayList idlist = new ArrayList();
                    ArrayList symlist = new ArrayList();

                    SvgDocument _doc = new SvgDocument();

                    Graph poly1 = tlVectorControl1.SVGDocument.CurrentElement as Graph;
                    if (poly1 == null || poly1.GetAttribute("id") == "svg")
                    {
                        return;
                    }

                    GraphicsPath gr1 = new GraphicsPath();
                    //gr1.AddRectangle(TLMath.getRectangle(poly1));
                    gr1.AddPolygon(TLMath.getPolygonPoints(poly1));
                    //gr1.CloseFigure();
                    gr1 = (GraphicsPath)poly1.GPath.Clone();
                    gr1.Transform((poly1 as IGraph).Transform.Matrix);

                    RectangleF ef1 = gr1.GetBounds();
                    ef1 = PathFunc.GetBounds(gr1);
                    StringBuilder svgtxt = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><svg id=\"svg\" width=\"" + ef1.Width + "\" height=\"" + ef1.Height + "\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:itop=\"http://www.Itop.com/itop\">");

                    XmlNodeList nlist = tlVectorControl1.SVGDocument.GetElementsByTagName("defs");
                    if (nlist.Count > 0)
                    {
                        XmlNode node = nlist[0];
                        svgtxt.AppendLine(node.OuterXml);
                    }
                    SvgElementCollection.ISvgElementEnumerator enumerator1 = tlVectorControl1.DrawArea.ElementList.GetEnumerator();// mouseAreaControl.PicturePanel.ElementList.GetEnumerator();
                    while (enumerator1.MoveNext())
                    {
                        IGraph graph1 = (IGraph)enumerator1.Current;

                        GraphicsPath path1 = (GraphicsPath)graph1.GPath.Clone();
                        //path1.Transform(graph1.GraphTransform.Matrix);
                        //path1.Transform(graph1.Transform.Matrix);
                        // RectangleF ef2 = path1.GetBounds();// PathFunc.GetBounds(path1);

                        //for (int n = 0; n < selCol.Count - 1; n++)
                        //{
                        //    //_doc.AppendChild((XmlNode)selCol[n]);
                        //    svgtxt = svgtxt + ((XmlElement)selCol[n]).OuterXml + "\r\n";
                        //}
                        if (!graph1.Visible || !graph1.DrawVisible || !graph1.Layer.Visible) continue;

                        GraphicsPath path2 = (GraphicsPath)graph1.GPath.Clone();
                        path2.Transform(graph1.Transform.Matrix);
                        RectangleF ef2 = PathFunc.GetBounds(path2);

                        if (ef1.Contains(ef2) || RectangleF.Intersect(ef1, ef2) != RectangleF.Empty)
                        {

                            SvgElement ele = (SvgElement)graph1;
                            svgtxt.AppendLine(ele.OuterXml);
                            //tlVectorControl1.SVGDocument.AddSelectElement(graph1);
                            if (graph1 is Use)
                            {
                                //PointF offset = TLMath.getUseOffset(((XmlElement)graph1).GetAttribute("xlink:href"));
                                //if (ef1.Contains(new PointF(((Use)graph1).X + offset.X, ((Use)graph1).Y + offset.Y))) {
                                //SvgElement ele = (SvgElement)graph1;
                                //svgtxt.AppendLine(ele.OuterXml);

                                string symid = ((XmlElement)graph1).GetAttribute("xlink:href");
                                if (!symlist.Contains(symid))
                                {
                                    symlist.Add(symid);
                                }
                                //}
                            }
                            if (graph1.GetType().FullName == "ItopVector.Core.Figure.Polyline")
                            {
                                string IsLead = ((XmlElement)graph1).GetAttribute("IsLead");
                                if (IsLead != "")
                                {
                                    if (ef1.Contains(ef2))
                                    {
                                        idlist.Add(graph1.ID);
                                    }
                                }
                            }
                        }
                    }
                    symlist = ResetList(symlist);
                    svgtxt.AppendLine("</svg>");
                    _doc.LoadXml(svgtxt.ToString());
                    _doc.SvgdataUid = tlVectorControl1.SVGDocument.SvgdataUid;
                    frmPrintF pri = new frmPrintF();
                    pri.Init(tlVectorControl1.SVGDocument.CurrentElement.ID, tlVectorControl1.SVGDocument.SvgdataUid);
                    if (pri.ShowDialog() == DialogResult.OK)
                    {
                        frmSubPrint s = new frmSubPrint();
                        s.Vector = tlVectorControl1;
                        s.InitImg(pri.strzt, pri.strgs, pri.pri, idlist, symlist);
                        s.Open(_doc, ef1);
                        s.Show();
                    }
                }
                if (e.ClickedItem.Text == "分类统计报表")
                {
                    if (tlVectorControl1.SVGDocument.CurrentElement == null || tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
                    {
                        return;
                    }
                    IGraph poly1 = (IGraph)tlVectorControl1.SVGDocument.CurrentElement;
                    frmPloyPrint p = new frmPloyPrint();

                    p.InitDate(poly1.ID, tlVectorControl1.SVGDocument.SvgdataUid);
                    p.ShowDialog();
                }
                if (e.ClickedItem.Text == "保存图片")
                {
                    if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.RectangleElement")
                    {

                        PrintHelper ph = new PrintHelper(tlVectorControl1, mapview);
                        frmImgManager frm = new frmImgManager();
                        frm.Pic = ph.getImage();
                        frm.ShowDialog();
                    }
                }

            }
            catch (Exception e1)
            {
                //MessageBox.Show(e1.Message);
            }
            if (e.ClickedItem.Text == "三维变电站")
            {
                try
                {
                    string strid = tlVectorControl1.SVGDocument.CurrentElement.ID;
                    substation s = new substation();
                    s.EleID = strid;
                    s.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
                    s = (substation)Services.BaseService.GetObject("SelectsubstationByEleID", s);
                    ProcessStartInfo p = new ProcessStartInfo();
                    p.FileName = Application.StartupPath + "\\" + s.EleName + "\\bdz.exe";
                    p.WorkingDirectory = Application.StartupPath + "\\" + s.EleName;
                    Process.Start(p);
                }
                catch (Exception e1) { }
            }
            if (e.ClickedItem.Text == "清除关联")
            {
                ((XmlElement)tlVectorControl1.SVGDocument.CurrentElement).RemoveAttribute("Deviceid");
            }
            if (e.ClickedItem.Text == "更新关联变电站")
            {
                UpdateLine();
            }
            if (e.ClickedItem.Text == "删除")
            {
                Delete();
            }
        }
Exemplo n.º 17
0
		public void InfinityIntersectTransform ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Intersect (new Rectangle (-10, -10, 20, 20));
				using (Matrix m = new Matrix (2, 0, 0, 0.5f, 10, 10)) {
					r.Transform (m);
				}
				RectangleF bounds = r.GetBounds (graphic);
				Assert.AreEqual (-10, bounds.X, "X");
				Assert.AreEqual (5, bounds.Y, "Y");
				Assert.AreEqual (40, bounds.Width, "Width");
				Assert.AreEqual (10, bounds.Height, "Height");
			}
		}
Exemplo n.º 18
0
		/// <summary>
		/// Overridden.  PiccoloDirect3D only supports rectangular clip regions.  So, if a
		/// non-rectangular region is pushed, the bounds of that region will be used instead.
		/// </summary>
		/// <param name="aClip">The clip to push.</param>
		public override void PushClip(Region aClip) {
			PushClip(aClip.GetBounds(graphics));
		}
Exemplo n.º 19
0
        // 原理:将图像分为正方形块,然后计算所有分块按照奇偶从左到右显示或从右到左显示所需的区域,并用材质画刷填充
        private void Animator06()
        {
            const float blockSize = 70; // 正方块的边长
            const int showWidth = 1; // 每次显示的像素列数
            try
            {
                OnDrawStarted(this, EventArgs.Empty);
                ClearBackground();

                // 建立空区域,如使用Region的无参构造函数则建立一个无限大小的区域,而非空区域
                Region region = new Region(new GraphicsPath());
                // 建立位图材质画刷
                TextureBrush textureBrush = new TextureBrush(bmp);
                // 分块的行坐标+列坐标为偶数则从左到右逐列显示本块,否则从右到左逐列显示本块
                for (int i = 0; i <= Math.Ceiling(blockSize / showWidth); i++)
                {
                    for (int x = 0; x < Math.Ceiling(bmp.Width / blockSize); x++)
                    {
                        for (int y = 0; y < Math.Ceiling(bmp.Height / blockSize); y++)
                        {
                            RectangleF rect;
                            // 判断块的行列坐标和为奇数或偶数
                            if ((x + y) % 2 == 0)
                            {
                                rect = new RectangleF(x * blockSize + i * showWidth, y * blockSize, showWidth, blockSize);
                            }
                            else
                            {
                                rect = new RectangleF((x + 1) * blockSize - i * showWidth, y * blockSize, showWidth, blockSize);
                            }
                            region.Union(rect); // 将要显示的区域合并到region中
                        }
                    }
                    dc.FillRegion(textureBrush, region); // 使用材质画刷填充区域

                    ShowBmp(region.GetBounds(dc));
                    Thread.Sleep(10 * delay);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
            finally
            {
                OnDrawCompleted(this, EventArgs.Empty);
            }
        }
Exemplo n.º 20
0
		public void ClipBoundsTest() {
			Region r = new Region();
			Assert.IsTrue(t.Graphics.ClipBounds.Equals(r.GetBounds(t.Graphics)));

			RectangleF rf = new RectangleF(10, 10, 60, 60);
			r = new Region(rf);
			t.Graphics.Clip = r;
			Assert.IsTrue(rf.Equals(t.Graphics.ClipBounds));
		}
Exemplo n.º 21
0
 private RectangleF GetTransformCellRect(int index)
 {
     RectangleF rect = GetCellRect(index);
     Region region = new Region(rect);
     region.Translate(AutoScrollPosition.X, AutoScrollPosition.Y);
     rect = region.GetBounds(CreateGraphics());
     return rect;
 }
        /// <summary>
        /// Draws a regular button in the Checked and Selected state
        /// </summary>
        /// <param name="e"></param>
        /// <param name="button"></param>
		public void DrawButtonCheckedSelected(Graphics g, Rectangle bounds, Corners corners, Ribbon ribbon)
		{
			if(ribbon.OrbStyle==RibbonOrbStyle.Office_2013) corners=Corners.None;

			Rectangle outerR=Rectangle.FromLTRB(bounds.Left, bounds.Top, bounds.Right-1, bounds.Bottom-1);

			using(GraphicsPath boundsPath=RoundRectangle(outerR, 3, corners))
			{
				Rectangle innerR=Rectangle.FromLTRB(bounds.Left+1, bounds.Top+1, bounds.Right-2, bounds.Bottom-2);
				Rectangle glossyR=Rectangle.FromLTRB(bounds.Left+1, bounds.Top+1, bounds.Right-2, bounds.Top+Convert.ToInt32((double)bounds.Height*.36));

				using(SolidBrush brus=new SolidBrush(ColorTable.ButtonCheckedSelectedBgOut))
				{
					g.FillPath(brus, boundsPath);
				}

				#region Main Bg
				using(GraphicsPath path=new GraphicsPath())
				{
					path.AddEllipse(new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height*2));
					path.CloseFigure();
					using(PathGradientBrush gradient=new PathGradientBrush(path))
					{
						gradient.WrapMode=WrapMode.Clamp;
						gradient.CenterPoint=new PointF(
								Convert.ToSingle(bounds.Left+bounds.Width/2),
								Convert.ToSingle(bounds.Bottom));
						gradient.CenterColor=ColorTable.ButtonCheckedSelectedBgCenter;
						gradient.SurroundColors=new Color[] { ColorTable.ButtonCheckedSelectedBgOut };

						Blend blend=new Blend(3);
						blend.Factors=new float[] { 0f, 0.8f, 0f };
						blend.Positions=new float[] { 0f, 0.30f, 1f };


						Region lastClip=g.Clip;
						Region newClip=new Region(boundsPath);
						newClip.Intersect(lastClip);
						g.SetClip(newClip.GetBounds(g));
						g.FillPath(gradient, path);
						g.Clip=lastClip;
					}
				}
				#endregion

				//Glossy effect
				using(GraphicsPath path=RoundRectangle(glossyR, 3, (corners&Corners.NorthWest)|(corners&Corners.NorthEast)))
				{
					using(LinearGradientBrush b=new LinearGradientBrush(glossyR, ColorTable.ButtonCheckedSelectedGlossyNorth, ColorTable.ButtonCheckedSelectedGlossySouth, 90))
					{
						b.WrapMode=WrapMode.TileFlipXY;
						g.FillPath(b, path);
					}
				}

				//Border
				using(Pen p=new Pen(ColorTable.ButtonCheckedSelectedBorderOut))
				{
					g.DrawPath(p, boundsPath);
				}

				//Inner border
				using(GraphicsPath path=RoundRectangle(innerR, 3, corners))
				{
					using(Pen p=new Pen(ColorTable.ButtonCheckedSelectedBorderIn))
					{
						g.DrawPath(p, path);
					}
				}
			}
		}
Exemplo n.º 23
0
		public void SetSaveReset ()
		{
			Bitmap bmp = new Bitmap (200, 200);
			Graphics g = Graphics.FromImage (bmp);
			GraphicsState state_default, state_modified;

			state_default = g.Save (); // Default

			g.CompositingMode = CompositingMode.SourceCopy;
			g.CompositingQuality = CompositingQuality.GammaCorrected;
			g.InterpolationMode = InterpolationMode.HighQualityBilinear;
			g.PageScale = 2;
			g.PageUnit = GraphicsUnit.Inch;
			g.PixelOffsetMode = PixelOffsetMode.Half;
			g.Clip = new Region (new Rectangle (0, 0, 100, 100));
			g.RenderingOrigin = new Point (10, 20);
			g.SmoothingMode = SmoothingMode.AntiAlias;
			g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;


			state_modified = g.Save (); // Modified

			g.CompositingMode = CompositingMode.SourceOver;
			g.CompositingQuality = CompositingQuality.Default;
			g.InterpolationMode = InterpolationMode.Bilinear;
			g.PageScale = 5;
			g.PageUnit = GraphicsUnit.Display;
			g.PixelOffsetMode = PixelOffsetMode.Default;
			g.Clip = new Region (new Rectangle (1, 2, 20, 25));
			g.RenderingOrigin = new Point (5, 6);
			g.SmoothingMode = SmoothingMode.None;
			g.TextRenderingHint = TextRenderingHint.SystemDefault;

			g.Restore (state_modified);

			Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetSaveReset1");
			Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetSaveReset2");
			Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetSaveReset3");
			Assert.AreEqual (2, g.PageScale, "SetSaveReset4");
			Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetSaveReset5");
			Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetSaveReset6");
			Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetSaveReset7");
			Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetSaveReset8");
			Assert.AreEqual (TextRenderingHint.ClearTypeGridFit, g.TextRenderingHint, "SetSaveReset9");
			Assert.AreEqual (0, (int) g.ClipBounds.X, "SetSaveReset10");
			Assert.AreEqual (0, (int) g.ClipBounds.Y, "SetSaveReset10");

			g.Restore (state_default);

			Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "SetSaveReset11");
			Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "SetSaveReset12");
			Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "SetSaveReset13");
			Assert.AreEqual (1, g.PageScale, "SetSaveReset14");
			Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "SetSaveReset15");
			Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "SetSaveReset16");
			Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "SetSaveReset17");
			Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "SetSaveReset18");
			Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetSaveReset19");

			Region r = new Region ();
			Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "SetSaveReset20");

			g.Dispose ();
		}
Exemplo n.º 24
0
		/// <summary>
		/// Pushes the current clip onto the clip stack and sets clip of the graphics context to
		/// the intersection of the current clip and the given clip.
		/// </summary>
		/// <remarks>
		/// The intersection of the current local clip and the new local clip is also pushed onto
		/// the local clip stack.
		/// </remarks>
		/// <param name="aClip">The clip to push.</param>
		public virtual void PushClip(Region aClip) {
			RectangleF newLocalClip = RectangleF.Intersect(LocalClip, aClip.GetBounds(graphics));
			localClipStack.Push(newLocalClip);

			Region currentClip = Graphics.Clip;
			clipStack.Push(currentClip);
			aClip = aClip.Clone();
			aClip.Intersect(currentClip);
			Graphics.Clip = aClip;
		}
Exemplo n.º 25
0
		public void InfinityExclude ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Exclude (new Rectangle (5, 5, 10, 10));
				Assert.IsFalse (r.IsInfinite (graphic), "after");
				RectangleF bounds = r.GetBounds (graphic);
				Assert.AreEqual (-4194304, bounds.X, "X");
				Assert.AreEqual (-4194304, bounds.Y, "Y");
				Assert.AreEqual (8388608, bounds.Width, "Width");
				Assert.AreEqual (8388608, bounds.Height, "Height");
			}
		}
Exemplo n.º 26
0
        IEnumerable<object> IPickingAdapter.Pick(Region region)
        {
            if (m_annotatedDiagram == null)
                return EmptyEnumerable<object>.Instance;

            List<object> hit = new List<object>();
            RectangleF bounds;
            using (Graphics g = AdaptedControl.CreateGraphics())
                bounds = region.GetBounds(g);

            if (m_transformAdapter != null)
                bounds = GdiUtil.InverseTransform(m_transformAdapter.Transform, bounds);

            foreach (IAnnotation annotation in m_annotatedDiagram.Annotations)
            {
                Rectangle annotationBounds = GetBounds(annotation);
                if (bounds.IntersectsWith(annotationBounds))
                    hit.Add(annotation);
            }

            return hit;
        }
Exemplo n.º 27
0
        protected virtual void DrawBackground(TabStrip tabStrip, Rectangle tabStripRect, Graphics g, TabColorScheme colors, Region tabsRegion, eTabStripAlignment tabAlignment, Rectangle selectedTabRect)
		{
			if(colors.TabBackground2.IsEmpty)
			{
                if (!colors.TabBackground.IsEmpty)
                {
                    using (SolidBrush brush = new SolidBrush(colors.TabBackground))
                        g.FillRegion(brush, tabsRegion);
                }
			}
			else
			{
				using(LinearGradientBrush brush=BarFunctions.CreateLinearGradientBrush(tabsRegion.GetBounds(g),colors.TabBackground,colors.TabBackground2,colors.TabBackgroundGradientAngle))
					g.FillRegion(brush, tabsRegion);
			}

		}
Exemplo n.º 28
0
		public void DefaultProperties ()
		{
			Bitmap bmp = new Bitmap (200, 200);
			Graphics g = Graphics.FromImage (bmp);
			Region r = new Region ();

			Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "DefaultProperties1");
			Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "DefaultProperties2");
			Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "DefaultProperties3");
			Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "DefaultProperties4");
			Assert.AreEqual (1, g.PageScale, "DefaultProperties5");
			Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "DefaultProperties6");
			Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "DefaultProperties7");
			Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "DefaultProperties8");
			Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "DefaultProperties9");
			Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "DefaultProperties10");

			r.Dispose ();
		}
Exemplo n.º 29
0
		public void Invalidate (Region region, bool invalidateChildren)
		{
			using (Graphics g = CreateGraphics ()){
				RectangleF bounds = region.GetBounds (g);
				Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height), invalidateChildren);
			}
		}
      public override void OnPaint(object sender, RibbonElementPaintEventArgs e)
      {
         Owner.Renderer.OnRenderRibbonItem(new RibbonItemRenderEventArgs(Owner, e.Graphics, e.Clip, this));

         if (e.Mode != RibbonElementSizeMode.Compact)
         {
            Region lastClip = e.Graphics.Clip;
            Region newClip = new Region(lastClip.GetBounds(e.Graphics));
            newClip.Intersect(ContentBounds);
            e.Graphics.SetClip(newClip.GetBounds(e.Graphics));

            foreach (RibbonButton button in Buttons)
            {
               if (!button.Bounds.IsEmpty)
                  button.OnPaint(this, new RibbonElementPaintEventArgs(button.Bounds, e.Graphics, ButtonsSizeMode));
            }
            e.Graphics.SetClip(lastClip.GetBounds(e.Graphics));
         }
      }
Exemplo n.º 31
0
        private void PaintForm(Graphics g, Region clip)
        {
            if (!clip.GetBounds(g).Equals(UpdateRegion.GetBounds(g)))
                UpdateRegion.Union(clip);

            DrawBackground(g);

            Opacity = Layout.Settings.Opacity;

            if (Layout.Settings.AntiAliasing)
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
            else
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.CompositingQuality = CompositingQuality.GammaCorrected;
            g.InterpolationMode = InterpolationMode.Bilinear;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            ComponentRenderer.CalculateOverallSize(Layout.Mode);

            var scaleFactor = Layout.Mode == LayoutMode.Vertical
                ? Height / Math.Max(ComponentRenderer.OverallSize, 1f)
                : Width / Math.Max(ComponentRenderer.OverallSize, 1f);

            g.ResetTransform();
            g.ScaleTransform(scaleFactor, scaleFactor);
            float transformedWidth = Width;
            float transformedHeight = Height;

            if (Layout.Mode == LayoutMode.Vertical)
                transformedWidth /= scaleFactor;
            else
                transformedHeight /= scaleFactor;

            BackColor = Color.Black;

            ComponentRenderer.Render(g, CurrentState, transformedWidth, transformedHeight, Layout.Mode, UpdateRegion);

            KeepLayoutSize();  
        }