示例#1
0
 public static void Compare(ICapStyle styleA, ICapStyle styleB, int version)
 {
     CompareBaseStyle(styleA, styleB, version);
     Compare(styleA.ColorStyle, styleB.ColorStyle, version);
     Assert.AreEqual <CapShape>(styleA.CapShape, styleB.CapShape);
     Assert.AreEqual <short>(styleA.CapSize, styleB.CapSize);
 }
示例#2
0
        /// <summary>
        /// Finds and returns the <see cref="T:System.Drawing.Drawing2D.GraphicsPath" /> used for creating the line cap for the given cap style.
        /// Can be used for drawing the line cap's interior.
        /// </summary>
        public static GraphicsPath GetCapPath(ICapStyle capStyle, ILineStyle lineStyle)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }

            // Build CapKey
            CapKey capKey;

            capKey.CapStyle  = capStyle;
            capKey.LineStyle = lineStyle;
            // Find/create CapPath
            GraphicsPath capPath;

            if (!_capPathCache.TryGetValue(capKey, out capPath))
            {
                // Scale GraphicsPath down for correcting the automatic scaling that is applied to
                // LineCaps by GDI+ when altering the LineWidth of the pen
                CalcCapShape(ref capPath, capStyle.CapShape, capStyle.CapSize * (1f / lineStyle.LineWidth));
                _capPathCache.Add(capKey, capPath);
            }
            return(capPath);
        }
示例#3
0
 public static void Compare(IStyleSet designA, IStyleSet designB, int version)
 {
     foreach (ICapStyle styleA in designA.CapStyles)
     {
         ICapStyle styleB = designB.CapStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (ICharacterStyle styleA in designA.CharacterStyles)
     {
         ICharacterStyle styleB = designB.CharacterStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (IColorStyle styleA in designA.ColorStyles)
     {
         IColorStyle styleB = designB.ColorStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (IFillStyle styleA in designA.FillStyles)
     {
         IFillStyle styleB = designB.FillStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (ILineStyle styleA in designA.LineStyles)
     {
         ILineStyle styleB = designB.LineStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
     foreach (IParagraphStyle styleA in designA.ParagraphStyles)
     {
         IParagraphStyle styleB = designB.ParagraphStyles[styleA.Name];
         Compare(styleA, styleB, version);
     }
 }
示例#4
0
        /// <summary>
        /// Returns the untransformed axis aligned bounding rectangle of the line cap defined by the given styles.
        /// </summary>
        public static Rectangle GetCapBounds(ICapStyle capStyle, ILineStyle lineStyle, float angleDeg)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }
            Rectangle result = Geometry.InvalidRectangle;

            PointF[] buffer = null;
            GetCapPoints(capStyle, lineStyle, ref buffer);

            // Transform cap points
            _matrix.Reset();
            _matrix.RotateAt(angleDeg + 90, Point.Empty);
            // Scale GraphicsPath up for correcting the automatic scaling that is applied to
            // LineCaps by GDI+ when altering the LineWidth of the pen
            _matrix.Scale(lineStyle.LineWidth, lineStyle.LineWidth);
            _matrix.TransformPoints(buffer);

            Geometry.CalcBoundingRectangle(buffer, out result);
            ShapeUtils.InflateBoundingRectangle(ref result, lineStyle);

            return(result);
        }
示例#5
0
        public static CircularArc ConnectShapesArc(Shape Start, Shape End, ICapStyle StartCapStyle, ICapStyle EndCapStyle, Object Tag,
                                                   Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project, ILineStyle LineStyle, Layer Layer)
        {
            CircularArc arc = (CircularArc)Project.ShapeTypes["CircularArc"].CreateInstance();

            arc.LineStyle          = LineStyle;
            arc.Tag                = Tag;
            arc.SecurityDomainName = 'B';


            Display.Diagram.Shapes.Add(arc);
            arc.StartCapStyle = StartCapStyle;
            arc.EndCapStyle   = EndCapStyle;
            arc.Connect(ControlPointId.FirstVertex, Start, ControlPointId.Reference);
            arc.Connect(ControlPointId.LastVertex, End, ControlPointId.Reference);

            Point firstPt = arc.GetControlPointPosition(ControlPointId.FirstVertex);
            Point lastPt  = arc.GetControlPointPosition(ControlPointId.LastVertex);
            Point dstPos  = Point.Empty;

            dstPos.X = ((firstPt.X + lastPt.X) / 2) + 1;
            dstPos.Y = ((firstPt.Y + lastPt.Y) / 2) + 1;

            arc.InsertVertex(ControlPointId.LastVertex, dstPos.X, dstPos.Y);

            Display.Diagram.AddShapeToLayers(arc, Layer.Id);

            Project.Repository.Insert((Shape)arc, Display.Diagram);

            return(arc);
        }
示例#6
0
        private static GraphicsPath GetCapPath(ICapStyle capStyle, ILineStyle lineStyle)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }

            // build CapKey
            CapKey capKey;

            capKey.CapStyle  = capStyle;
            capKey.LineStyle = lineStyle;
            // find/create CapPath
            GraphicsPath capPath;

            capPathCache.TryGetValue(capKey, out capPath);
            if (capPath == null)
            {
                CalcCapShape(ref capPath, capStyle.CapShape, capStyle.CapSize);
                // Scale GraphicsPath down for correcting the automatic scaling that is applied to
                // LineCaps by GDI+ when altering the LineWidth of the pen
                matrix.Reset();
                matrix.Scale(1f / lineStyle.LineWidth, 1f / lineStyle.LineWidth);
                capPath.Transform(matrix);
                capPathCache.Add(capKey, capPath);
            }
            return(capPath);
        }
示例#7
0
        /// <summary>
        /// Deletes all tools based on the given CapStyle.
        /// </summary>
        private static void NotifyCapStyleChanged(ICapStyle capStyle)
        {
            Debug.Assert(capStyle != null);

            // Collect affected PenKeys
            List <PenKey> penKeys = new List <PenKey>();

            foreach (KeyValuePair <PenKey, Pen> item in _penCache)
            {
                if (item.Key.StartCapStyle != null && item.Key.StartCapStyle == capStyle)
                {
                    penKeys.Add(item.Key);
                }
                else if (item.Key.EndCapStyle != null && item.Key.EndCapStyle == capStyle)
                {
                    penKeys.Add(item.Key);
                }
            }
            // Delete affected Pens
            foreach (PenKey penKey in penKeys)
            {
                Pen pen = _penCache[penKey];
                _penCache.Remove(penKey);
                pen.Dispose();
                pen = null;
            }
            penKeys.Clear();

            // Collect affected CustomLineCaps
            List <CapKey> capKeys = new List <CapKey>();

            foreach (KeyValuePair <CapKey, CustomLineCap> item in _capCache)
            {
                if (item.Key.CapStyle == capStyle)
                {
                    capKeys.Add(item.Key);
                }
            }

            // Delete affected CustomLineCaps
            foreach (CapKey capKey in capKeys)
            {
                CustomLineCap cap = _capCache[capKey];
                _capCache.Remove(capKey);
                cap.Dispose();
                cap = null;
            }
            // Delete affected GraphicsPaths
            foreach (CapKey capKey in capKeys)
            {
                if (_capPathCache.ContainsKey(capKey))
                {
                    GraphicsPath path = _capPathCache[capKey];
                    _capPathCache.Remove(capKey);
                    path.Dispose();
                    path = null;
                }
            }
            capKeys.Clear();
        }
示例#8
0
 public static void Compare(IStyleSet savedDesign, IStyleSet loadedDesign, int version)
 {
     foreach (ICapStyle savedStyle in savedDesign.CapStyles)
     {
         ICapStyle loadedStyle = loadedDesign.CapStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (ICharacterStyle savedStyle in savedDesign.CharacterStyles)
     {
         ICharacterStyle loadedStyle = loadedDesign.CharacterStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (IColorStyle savedStyle in savedDesign.ColorStyles)
     {
         IColorStyle loadedStyle = loadedDesign.ColorStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (IFillStyle savedStyle in savedDesign.FillStyles)
     {
         IFillStyle loadedStyle = loadedDesign.FillStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (ILineStyle savedStyle in savedDesign.LineStyles)
     {
         ILineStyle loadedStyle = loadedDesign.LineStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
     foreach (IParagraphStyle savedStyle in savedDesign.ParagraphStyles)
     {
         IParagraphStyle loadedStyle = loadedDesign.ParagraphStyles[savedStyle.Name];
         Compare(savedStyle, loadedStyle, version);
     }
 }
示例#9
0
		public bool HasCustomLineCap(ICapStyle capStyle) {
			if (capStyle == null) return false;
			return (capStyle.CapShape != CapShape.None 
				&& capStyle.CapShape != CapShape.Round 
				&& capStyle.CapShape != CapShape.Flat 
				&& capStyle.CapShape != CapShape.Peak);
		}
示例#10
0
        private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICapStyle capStyle)
        {
            Pen   capPen = ToolCache.GetPen(design.LineStyles.Normal, null, capStyle);
            float scale  = 1;

            if (capStyle.CapSize + 2 >= previewBounds.Height)
            {
                scale = Geometry.CalcScaleFactor(capStyle.CapSize + 2, capStyle.CapSize + 2, previewBounds.Width - 2, previewBounds.Height - 2);
                gfx.ScaleTransform(scale, scale);
            }
            int startX, endX, y;

            startX = previewBounds.Left;
            if (capPen.StartCap == LineCap.Custom)
            {
                startX += (int)Math.Round(capStyle.CapSize - capPen.CustomStartCap.BaseInset);
            }
            startX = (int)Math.Round(startX / scale);
            endX   = previewBounds.Right;
            if (capPen.EndCap == LineCap.Custom)
            {
                endX -= (int)Math.Round(capStyle.CapSize - capPen.CustomEndCap.BaseInset);
            }
            endX = (int)Math.Round(endX / scale);
            y    = (int)Math.Round((previewBounds.Y + ((float)previewBounds.Height / 2)) / scale);
            gfx.DrawLine(capPen, startX, y, endX, y);
        }
示例#11
0
 public static void Compare(ICapStyle savedStyle, ICapStyle loadedStyle, int version)
 {
     CompareBaseStyle(savedStyle, loadedStyle, version);
     Compare(savedStyle.ColorStyle, loadedStyle.ColorStyle, version);
     Assert.AreEqual <CapShape>(savedStyle.CapShape, loadedStyle.CapShape);
     Assert.AreEqual <short>(savedStyle.CapSize, loadedStyle.CapSize);
 }
示例#12
0
 public bool HasCustomLineCap(ICapStyle capStyle)
 {
     if (capStyle == null)
     {
         return(false);
     }
     return(capStyle.CapShape != CapShape.None);
 }
示例#13
0
 public ShapeTag(string Id, object Object,
                 ILineStyle LineStyle, IFillStyle FillStyle, ICapStyle CapStyle)
 {
     this.Id        = Id;
     this.Object    = Object;
     this.LineStyle = LineStyle;
     this.FillStyle = FillStyle;
     this.CapStyle  = CapStyle;
 }
示例#14
0
        private static void SetLineCap(Pen pen, ILineStyle lineStyle, ICapStyle capStyle, bool isStartCap)
        {
            if (pen == null)
            {
                throw new ArgumentNullException("pen");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }
            LineCap cap = LineCap.Round;

            if (capStyle != null)
            {
                switch (capStyle.CapShape)
                {
                case CapShape.None:
                case CapShape.Round:
                    cap = LineCap.Round;
                    break;

                case CapShape.Flat:
                    cap = LineCap.Square;
                    break;

                case CapShape.Peak:
                    cap = LineCap.Triangle;
                    break;

                default:
                    cap = LineCap.Custom;
                    break;
                }
            }
            if (isStartCap)
            {
                pen.StartCap = cap;
                if (cap == LineCap.Custom)
                {
                    pen.CustomStartCap = GetCustomLineCap(capStyle, lineStyle);
                }
            }
            else
            {
                pen.EndCap = cap;
                if (cap == LineCap.Custom)
                {
                    pen.CustomEndCap = GetCustomLineCap(capStyle, lineStyle);
                }
            }
        }
示例#15
0
        private void DrawCapStyleItem(ICapStyle capStyle, DrawItemEventArgs e)
        {
            ILineStyle lineStyle = styleSet.LineStyles.Normal;
            Pen        capPen    = ToolCache.GetPen(lineStyle, capStyle, capStyle);
            Brush      capBrush  = null;

            PointF[] capPoints = null;

            int left  = previewRect.Left;
            int right = previewRect.Right;

            if (capPen.StartCap == LineCap.Custom)
            {
                if (capPen.CustomStartCap.BaseInset > 0)
                {
                    left  += (int)Math.Round(capStyle.CapSize - capPen.CustomStartCap.BaseInset);
                    right -= (int)Math.Round(capStyle.CapSize - capPen.CustomEndCap.BaseInset);
                }
            }
            int y = previewRect.Y + (previewRect.Height / 2);

            // Start Cap
            if (HasCustomLineCap(capStyle))
            {
                capBrush = ToolCache.GetBrush(capStyle.ColorStyle, lineStyle);
                ToolCache.GetCapPoints(capStyle, styleSet.LineStyles.Normal, ref capPoints);
                float angle = Geometry.RadiansToDegrees(Geometry.Angle(left, y, right, y));
                matrix.Reset();
                matrix.Translate(left, y);
                matrix.Rotate(angle + 90);
                matrix.TransformPoints(capPoints);
                e.Graphics.FillPolygon(capBrush, capPoints, System.Drawing.Drawing2D.FillMode.Alternate);
            }
            // End Cap
            if (HasCustomLineCap(capStyle))
            {
                capBrush = ToolCache.GetBrush(capStyle.ColorStyle, lineStyle);
                ToolCache.GetCapPoints(capStyle, styleSet.LineStyles.Normal, ref capPoints);
                float angle = Geometry.RadiansToDegrees(Geometry.Angle(right, y, left, y));
                matrix.Reset();
                matrix.Translate(right, y);
                matrix.Rotate(angle + 90);
                matrix.TransformPoints(capPoints);
                e.Graphics.FillPolygon(capBrush, capPoints, System.Drawing.Drawing2D.FillMode.Alternate);
            }
            // Draw
            e.Graphics.DrawLine(capPen, left, y, right, y);
            e.Graphics.DrawString(capStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
        }
示例#16
0
        /// <summary>
        /// Finds and returns the <see cref="T:System.Drawing.Drawing2D.CustomLineCap" /> for the given <see cref="T:Dataweb.NShape.ICapStyle" /> and <see cref="T:Dataweb.NShape.ILineStyle" />.
        /// </summary>
        private static CustomLineCap GetCustomLineCap(ICapStyle capStyle, ILineStyle lineStyle)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }

            // Build CapKey
            CapKey capKey;

            capKey.CapStyle  = capStyle;
            capKey.LineStyle = lineStyle;
            // Find/create CustomLineCap
            CustomLineCap customCap = null;

            if (!_capCache.TryGetValue(capKey, out customCap))
            {
                // Get GraphicsPath for the CustomLineCap
                GraphicsPath capPath = GetCapPath(capStyle, lineStyle);

                // Create custom cap using the cap path
                customCap            = new CustomLineCap(null, capPath);
                customCap.StrokeJoin = lineStyle.LineJoin;
                // ToDo: Use WidthScale property and remove the manual scaling
                customCap.WidthScale = 1;
                //customCap.WidthScale = 1f / lineStyle.LineWidth;
                _rectFBuffer = capPath.GetBounds();
                // ToDo: Write a GetBaseInset() method for this purpose
                if (capStyle.CapShape == CapShape.OpenArrow)
                {
                    customCap.BaseInset = _rectFBuffer.Height / 4f;
                }
                else
                {
                    customCap.BaseInset = (float)(_rectFBuffer.Height - (_rectFBuffer.Height + _rectFBuffer.Y));
                }

                // Add cap to the cache
                _capCache.Add(capKey, customCap);
            }
            return(customCap);
        }
示例#17
0
        private static Polyline ConnectShapesWithCapStyle(Shape Start, Shape End, ICapStyle StartCapStyle, ICapStyle EndCapStyle, Object Tag, Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project)
        {
            Polyline arrow = (Polyline)Project.ShapeTypes["Polyline"].CreateInstance();

            arrow.Tag = Tag;
            arrow.SecurityDomainName = 'B';
            Display.Diagram.Shapes.Add(arrow);
            arrow.StartCapStyle = StartCapStyle;
            arrow.EndCapStyle   = EndCapStyle;
            arrow.Connect(ControlPointId.FirstVertex, Start, ControlPointId.Reference);
            arrow.Connect(ControlPointId.LastVertex, End, ControlPointId.Reference);

            Project.Repository.Insert((Shape)arrow, Display.Diagram);


            return(arrow);
        }
示例#18
0
        /// <ToBeCompleted></ToBeCompleted>
        public static Pen GetPen(ILineStyle lineStyle, ICapStyle startCapStyle, ICapStyle endCapStyle)
        {
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }

            PenKey penKey;

            penKey.LineStyle     = lineStyle;
            penKey.StartCapStyle = startCapStyle;
            penKey.EndCapStyle   = endCapStyle;

            Pen pen = null;

            penCache.TryGetValue(penKey, out pen);
            if (pen == null)
            {
                // If the corresponding pen was not found, create a new pen based on the given LineStyle
                pen = new Pen(GetColor(lineStyle.ColorStyle, lineStyle.ColorStyle.ConvertToGray), lineStyle.LineWidth);
                // "PenAlignment.Inset" does not draw exactly along the outline of the shape and
                // causes GraphicsPath.Widen(Pen pen) to produce strance results
                //pen.Alignment = PenAlignment.Inset;
                pen.LineJoin = lineStyle.LineJoin;
                pen.DashCap  = lineStyle.DashCap;
                if (lineStyle.DashType == DashType.Solid)
                {
                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                }
                else
                {
                    pen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
                    pen.DashPattern = lineStyle.DashPattern;
                }
                // Create LineCaps
                SetLineCap(pen, lineStyle, startCapStyle, true);
                SetLineCap(pen, lineStyle, endCapStyle, false);

                // Add created pen to the PenCache
                penCache.Add(penKey, pen);
            }
            return(pen);
        }
示例#19
0
        /// <summary>
        /// Finds and returns the <see cref="T:System.Drawing.Drawing2D.CustomLineCap" /> for the given <see cref="T:Dataweb.NShape.ICapStyle" /> and <see cref="T:Dataweb.NShape.ILineStyle" />.
        /// </summary>
        public static CustomLineCap GetCustomLineCap(ICapStyle capStyle, ILineStyle lineStyle)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }

            // build CapKey
            CapKey capKey;

            capKey.CapStyle  = capStyle;
            capKey.LineStyle = lineStyle;
            // get GraphicsPath for the CustomLineCap
            GraphicsPath capPath = GetCapPath(capStyle, lineStyle);
            // find/create CustomLineCap
            CustomLineCap customCap = null;

            capCache.TryGetValue(capKey, out customCap);
            if (customCap == null)
            {
                customCap            = new CustomLineCap(null, capPath);
                customCap.StrokeJoin = lineStyle.LineJoin;
                customCap.WidthScale = 1;
                rectFBuffer          = capPath.GetBounds();
                if (capStyle.CapShape == CapShape.ArrowOpen)
                {
                    customCap.BaseInset = 0;
                }
                else
                {
                    customCap.BaseInset = (float)(rectFBuffer.Height - (rectFBuffer.Height + rectFBuffer.Y));
                }
                capCache.Add(capKey, customCap);
            }
            return(customCap);
        }
        public static Shape RenderRelationshipVector(Neo4j.Driver.V1.IRelationship Rel, Dataweb.NShape.WinFormsUI.Display Display)
        {
            //Globals
            Project project = Display.Project;
            Diagram diagram = Display.Diagram;
            Design  design  = project.Design;

            Layer layer = diagram.Layers["OVERLAY"];
            //

            //Defaults
            ILineStyle stroke   = design.LineStyles.Green;
            ICapStyle  startCap = design.CapStyles.None;
            ICapStyle  endCap   = design.CapStyles.OpenArrow;
            //


            //Reference Shape
            Shape shapeReference = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(Rel.Id.As <string>(), Display.Project.Design.CapStyles.None), "Polyline", Display);

            return(NShapeHelper.DrawParallelArrow((Polyline)shapeReference, Rel, Display, project, stroke, layer));
        }
示例#21
0
        /// <summary>
        /// Constructs a polygon from the given cap style used for drawing the line cap's interior.
        /// </summary>
        public static void GetCapPoints(ICapStyle capStyle, ILineStyle lineStyle, ref PointF[] capPoints)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }
            // Copy path points to point buffer
            GraphicsPath capPath = GetCapPath(capStyle, lineStyle);

            if (capPoints == null)
            {
                capPoints = new PointF[capPath.PointCount];
            }
            else if (capPoints.Length != capPath.PointCount)
            {
                Array.Resize(ref capPoints, capPath.PointCount);
            }
            Array.Copy(capPath.PathPoints, capPoints, capPoints.Length);
        }
示例#22
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICapStyle capStyle) {
			Pen capPen = ToolCache.GetPen(design.LineStyles.Normal, null, capStyle);
			float scale = 1;
			if (capStyle.CapSize + 2 >= previewBounds.Height) {
				scale = Geometry.CalcScaleFactor(capStyle.CapSize + 2, capStyle.CapSize + 2, previewBounds.Width - 2, previewBounds.Height - 2);
				gfx.ScaleTransform(scale, scale);
			}
			int startX, endX, y;
			startX = previewBounds.Left;
			if (capPen.StartCap == LineCap.Custom)
				startX += (int)Math.Round(capStyle.CapSize - capPen.CustomStartCap.BaseInset);
			startX = (int)Math.Round(startX / scale);
			endX = previewBounds.Right;
			if (capPen.EndCap == LineCap.Custom)
				endX -= (int)Math.Round(capStyle.CapSize - capPen.CustomEndCap.BaseInset);
			endX = (int)Math.Round(endX / scale);
			y = (int)Math.Round((previewBounds.Y + ((float)previewBounds.Height / 2)) / scale);
			gfx.DrawLine(capPen, startX, y, endX, y);
		}
示例#23
0
		private void DrawCapStyleItem(ICapStyle capStyle, DrawItemEventArgs e)
		{
			ILineStyle lineStyle = styleSet.LineStyles.Normal;
			Pen capPen = ToolCache.GetPen(lineStyle, capStyle, capStyle);
			Brush capBrush = null;
			PointF[] capPoints = null;

			int left = previewRect.Left;
			int right = previewRect.Right;
			if (capPen.StartCap == LineCap.Custom) {
				if (capPen.CustomStartCap.BaseInset > 0) {
					left += (int) Math.Round(capStyle.CapSize - capPen.CustomStartCap.BaseInset);
					right -= (int) Math.Round(capStyle.CapSize - capPen.CustomEndCap.BaseInset);
				}
			}
			int y = previewRect.Y + (previewRect.Height/2);
			// Start Cap
			if (HasCustomLineCap(capStyle)) {
				capBrush = ToolCache.GetBrush(capStyle.ColorStyle, lineStyle);
				ToolCache.GetCapPoints(capStyle, styleSet.LineStyles.Normal, ref capPoints);
				float angle = Geometry.RadiansToDegrees(Geometry.Angle(left, y, right, y));
				matrix.Reset();
				matrix.Translate(left, y);
				matrix.Rotate(angle + 90);
				matrix.TransformPoints(capPoints);
				e.Graphics.FillPolygon(capBrush, capPoints, System.Drawing.Drawing2D.FillMode.Alternate);
			}
			// End Cap
			if (HasCustomLineCap(capStyle)) {
				capBrush = ToolCache.GetBrush(capStyle.ColorStyle, lineStyle);
				ToolCache.GetCapPoints(capStyle, styleSet.LineStyles.Normal, ref capPoints);
				float angle = Geometry.RadiansToDegrees(Geometry.Angle(right, y, left, y));
				matrix.Reset();
				matrix.Translate(right, y);
				matrix.Rotate(angle + 90);
				matrix.TransformPoints(capPoints);
				e.Graphics.FillPolygon(capBrush, capPoints, System.Drawing.Drawing2D.FillMode.Alternate);
			}
			// Draw
			e.Graphics.DrawLine(capPen, left, y, right, y);
			e.Graphics.DrawString(capStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
		}
        public static Shape RenderRelationship(yggdrasil2.Topology.IGP.Link.Link link, Dataweb.NShape.WinFormsUI.Display Display)
        {
            //Globals
            Project project = Display.Project;
            Diagram diagram = Display.Diagram;
            Design  design  = project.Design;

            Layer layer = diagram.Layers["NETWORK"];
            //

            //Defaults
            ILineStyle stroke   = design.LineStyles.Normal;
            ICapStyle  startCap = design.CapStyles.None;
            ICapStyle  endCap   = design.CapStyles.None;

            //

            if (link.OperationalStatus)
            {
                stroke = design.LineStyles.Green;
            }
            else
            {
                stroke = design.LineStyles.Red;
            }

            //Start and End Shapes
            Shape shapeStart = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(link.SourceNode, null), "Circle", Display);
            Shape shapeEnd   = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(link.TargetNode, null), "Circle", Display);

            while (shapeStart == null || shapeEnd == null)
            {
                System.Threading.Thread.Sleep(1);

                shapeStart = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(link.SourceNode, null), "Circle", Display);
                shapeEnd   = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(link.TargetNode, null), "Circle", Display);
            }

            Shape exists = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(link.Id, null), "Polyline", Display);

            Shape reverseExists = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(link.ReverseId, null), "Polyline", Display);

            if (exists != null)
            {
                exists.LineStyle = stroke;
                ((UI.ShapeTag)exists.Tag).LineStyle = stroke;

                if (reverseExists != null)
                {
                    reverseExists.LineStyle = stroke;
                    ((UI.ShapeTag)reverseExists.Tag).LineStyle = stroke;
                }

                return(exists);
            }
            else
            {
                return(NShapeHelper.ConnectShapes(shapeStart, shapeEnd,
                                                  new display.UI.ShapeTag(link.Id, link, stroke, null, Display.Project.Design.CapStyles.None),
                                                  Display, project, stroke, layer));
            }
        }
示例#25
0
		private static GraphicsPath GetCapPath(ICapStyle capStyle, ILineStyle lineStyle) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");

			// build CapKey
			CapKey capKey;
			capKey.CapStyle = capStyle;
			capKey.LineStyle = lineStyle;
			// find/create CapPath
			GraphicsPath capPath;
			capPathCache.TryGetValue(capKey, out capPath);
			if (capPath == null) {
				CalcCapShape(ref capPath, capStyle.CapShape, capStyle.CapSize);
				// Scale GraphicsPath down for correcting the automatic scaling that is applied to
				// LineCaps by GDI+ when altering the LineWidth of the pen
				matrix.Reset();
				matrix.Scale(1f / lineStyle.LineWidth, 1f / lineStyle.LineWidth);
				capPath.Transform(matrix);
				capPathCache.Add(capKey, capPath);
			}
			return capPath;
		}
示例#26
0
		/// <summary>
		/// Deletes all tools based on the given CapStyle.
		/// </summary>
		private static void NotifyCapStyleChanged(ICapStyle capStyle) {
			Debug.Assert(capStyle != null);
			
			// collect affected PenKeys
			List<PenKey> penKeys = new List<PenKey>();
			foreach (KeyValuePair<PenKey, Pen> item in penCache)
				if (item.Key.StartCapStyle != null && item.Key.StartCapStyle == capStyle)
					penKeys.Add(item.Key);
				else if (item.Key.EndCapStyle != null && item.Key.EndCapStyle == capStyle)
					penKeys.Add(item.Key);
			// delete affected Pens
			foreach (PenKey penKey in penKeys) {
				Pen pen = penCache[penKey];
				penCache.Remove(penKey);
				pen.Dispose();
				pen = null;
			}
			penKeys.Clear();

			// collect affected CustomLineCaps
			List<CapKey> capKeys = new List<CapKey>();
			foreach (KeyValuePair<CapKey, CustomLineCap> item in capCache)
				if (item.Key.CapStyle == capStyle)
					capKeys.Add(item.Key);
			// delete affected CustomLineCaps
			foreach (CapKey capKey in capKeys) {
				CustomLineCap cap = capCache[capKey];
				capCache.Remove(capKey);
				cap.Dispose();
				cap = null;
			}

			// delete all GraphicsPaths
			foreach (CapKey capKey in capKeys) {
				if (capPathCache.ContainsKey(capKey)) {
					GraphicsPath path = capPathCache[capKey];
					capPathCache.Remove(capKey);
					path.Dispose();
					path = null;
				}
			}
			capKeys.Clear();
		}
示例#27
0
		/// <ToBeCompleted></ToBeCompleted>
		public static Pen GetPen(ILineStyle lineStyle, ICapStyle startCapStyle, ICapStyle endCapStyle) {
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			
			PenKey penKey;
			penKey.LineStyle = lineStyle;
			penKey.StartCapStyle = startCapStyle;
			penKey.EndCapStyle = endCapStyle;

			Pen pen = null;
			penCache.TryGetValue(penKey, out pen);
			if (pen == null) {
				// If the corresponding pen was not found, create a new pen based on the given LineStyle
				pen = new Pen(GetColor(lineStyle.ColorStyle, lineStyle.ColorStyle.ConvertToGray), lineStyle.LineWidth);
				// "PenAlignment.Inset" does not draw exactly along the outline of the shape and
				// causes GraphicsPath.Widen(Pen pen) to produce strance results
				//pen.Alignment = PenAlignment.Inset;
				pen.LineJoin = lineStyle.LineJoin;
				pen.DashCap = lineStyle.DashCap;
				if (lineStyle.DashType == DashType.Solid)
					pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
				else {
					pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
					pen.DashPattern = lineStyle.DashPattern;
				}
				// Create LineCaps
				SetLineCap(pen, lineStyle, startCapStyle, true);
				SetLineCap(pen, lineStyle, endCapStyle, false);

				// Add created pen to the PenCache
				penCache.Add(penKey, pen);
			}
			return pen;
		}
示例#28
0
		/// <ToBeCompleted></ToBeCompleted>
		public static void GetCapPoints(ICapStyle capStyle, ILineStyle lineStyle, ref PointF[] capPoints) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			
			GraphicsPath capPath = GetCapPath(capStyle, lineStyle);
			if (capPoints == null)
				capPoints = new PointF[capPath.PointCount];
			else if (capPoints.Length != capPath.PointCount)
				Array.Resize(ref capPoints, capPath.PointCount);
			Array.Copy(capPath.PathPoints, capPoints, capPoints.Length);
		}
示例#29
0
		public bool HasCustomLineCap(ICapStyle capStyle) {
			if (capStyle == null) return false;
			return (capStyle.CapShape != CapShape.None);
		}
示例#30
0
		private static void SetLineCap(Pen pen, ILineStyle lineStyle, ICapStyle capStyle, bool isStartCap) {
			if (pen == null) throw new ArgumentNullException("pen");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			LineCap cap = LineCap.Round;
			if (capStyle != null) {
				switch (capStyle.CapShape) {
					case CapShape.None:
						cap = LineCap.Round;
						break;
					default:
						cap = LineCap.Custom;
						break;
				}
			}
			if (isStartCap) {
				pen.StartCap = cap;
				if (cap == LineCap.Custom)
					pen.CustomStartCap = GetCustomLineCap(capStyle, lineStyle);
			} else {
				pen.EndCap = cap;
				if (cap == LineCap.Custom)
					pen.CustomEndCap = GetCustomLineCap(capStyle, lineStyle);
			}
		}
示例#31
0
        /// <ToBeCompleted></ToBeCompleted>
        protected virtual void DrawGluePointLine(Graphics graphics, ILineStyle lineStyle, ICapStyle capStyle)
        {
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }
            Pen pen = ToolCache.GetPen(LineStyle, null, capStyle);

            DrawGluePointLine(graphics, pen);
        }
示例#32
0
		public bool HasCustomLineCap(ICapStyle capStyle)
		{
			if (capStyle == null) return false;
			return (capStyle.CapShape != CapShape.None
			        && capStyle.CapShape != CapShape.Round
			        && capStyle.CapShape != CapShape.Flat
			        && capStyle.CapShape != CapShape.Peak);
		}
        public static Shape RenderRelationship(Neo4j.Driver.V1.IRelationship Rel, Dataweb.NShape.WinFormsUI.Display Display)
        {
            //Globals
            Project project = Display.Project;
            Diagram diagram = Display.Diagram;
            Design  design  = project.Design;

            Layer layer = diagram.Layers["NETWORK"];
            //

            //Defaults
            ILineStyle stroke   = design.LineStyles.Normal;
            ICapStyle  startCap = design.CapStyles.None;
            ICapStyle  endCap   = design.CapStyles.None;

            //

            if (Rel.Properties.ContainsKey("Operational_Status"))
            {
                if (Rel.Properties["Operational_Status"].As <bool>())
                {
                    stroke = design.LineStyles.Green;
                }
                else
                {
                    stroke = design.LineStyles.Red;
                }
            }


            //Start and End Shapes
            Shape shapeStart = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(Rel.StartNodeId.As <string>(), null), "Circle", Display);
            Shape shapeEnd   = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(Rel.EndNodeId.As <string>(), null), "Circle", Display);


            Shape exists = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(Rel.Id.As <string>(), null), "Polyline", Display);

            if (exists != null)
            {
                exists.LineStyle = stroke;

                return(exists);
            }
            else
            {
                //Rel Type
                switch (Rel.Type)
                {
                case "Link":
                    return(NShapeHelper.ConnectShapes(shapeStart, shapeEnd,
                                                      new display.UI.ShapeTag(Rel.Id.As <string>(), Rel, stroke, null, Display.Project.Design.CapStyles.None),
                                                      Display, project, stroke, layer));

                default:
                    return(NShapeHelper.ConnectShapes(shapeStart, shapeEnd,
                                                      new display.UI.ShapeTag(Rel.Id.As <string>(), Rel, stroke, null, Display.Project.Design.CapStyles.None),
                                                      Display, project, stroke, layer));
                }
                //
            }
        }
示例#34
0
		/// <summary>
		/// Finds and returns the <see cref="T:System.Drawing.Drawing2D.CustomLineCap" /> for the given <see cref="T:Dataweb.NShape.ICapStyle" /> and <see cref="T:Dataweb.NShape.ILineStyle" />.
		/// </summary>
		public static CustomLineCap GetCustomLineCap(ICapStyle capStyle, ILineStyle lineStyle) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");

			// build CapKey
			CapKey capKey;
			capKey.CapStyle = capStyle;
			capKey.LineStyle = lineStyle;
			// get GraphicsPath for the CustomLineCap
			GraphicsPath capPath = GetCapPath(capStyle, lineStyle);
			// find/create CustomLineCap
			CustomLineCap customCap = null;
			capCache.TryGetValue(capKey, out customCap);
			if (customCap == null) {
				customCap = new CustomLineCap(null, capPath);
				customCap.StrokeJoin = lineStyle.LineJoin;
				customCap.WidthScale = 1;
				rectFBuffer = capPath.GetBounds();
				if (capStyle.CapShape == CapShape.ArrowOpen)
					customCap.BaseInset = 0;
				else 
					customCap.BaseInset = (float)(rectFBuffer.Height - (rectFBuffer.Height + rectFBuffer.Y));
				capCache.Add(capKey, customCap);
			}
			return customCap;
		}
示例#35
0
		/// <summary>
		/// Returns the untransformed axis aligned bounding rectangle of the line cap defined by the given styles.
		/// </summary>
		public static Rectangle GetCapBounds(ICapStyle capStyle, ILineStyle lineStyle, float angleDeg) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			Rectangle result = Rectangle.Empty;
			GetCapPoints(capStyle, lineStyle, ref pointFBuffer);

			// Transform cap points
			matrix.Reset();
			matrix.RotateAt(angleDeg + 90, Point.Empty);
			// Scale GraphicsPath up for correcting the automatic scaling that is applied to
			// LineCaps by GDI+ when altering the LineWidth of the pen
			matrix.Scale(lineStyle.LineWidth, lineStyle.LineWidth);
			matrix.TransformPoints(pointFBuffer);

			Geometry.CalcBoundingRectangle(pointFBuffer, out result);
			return result;
		}
示例#36
0
		/// <ToBeCompleted></ToBeCompleted>
		protected virtual void DrawGluePointLine(Graphics graphics, ILineStyle lineStyle, ICapStyle capStyle) {
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			Pen pen = ToolCache.GetPen(LineStyle, null, capStyle);
			DrawGluePointLine(graphics, pen);
		}