Ejemplo n.º 1
0
 public virtual double GetAutoOrientAngle(MarkerSvgNodeRenderer marker, bool reverse)
 {
     Object[] pathShapes = GetShapes().ToArray();
     if (pathShapes.Length > 1)
     {
         Vector v = new Vector(0, 0, 0);
         if (SvgConstants.Attributes.MARKER_END.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER)))
         {
             // Create vector from the last two shapes
             IPathShape lastShape         = (IPathShape)pathShapes[pathShapes.Length - 1];
             IPathShape secondToLastShape = (IPathShape)pathShapes[pathShapes.Length - 2];
             v = new Vector((float)(lastShape.GetEndingPoint().GetX() - secondToLastShape.GetEndingPoint().GetX()), (float
                                                                                                                     )(lastShape.GetEndingPoint().GetY() - secondToLastShape.GetEndingPoint().GetY()), 0f);
         }
         else
         {
             if (SvgConstants.Attributes.MARKER_START.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER)))
             {
                 // Create vector from the first two shapes
                 IPathShape firstShape  = (IPathShape)pathShapes[0];
                 IPathShape secondShape = (IPathShape)pathShapes[1];
                 v = new Vector((float)(secondShape.GetEndingPoint().GetX() - firstShape.GetEndingPoint().GetX()), (float)(
                                    secondShape.GetEndingPoint().GetY() - firstShape.GetEndingPoint().GetY()), 0f);
             }
         }
         // Get angle from this vector and the horizontal axis
         Vector xAxis    = new Vector(1, 0, 0);
         double rotAngle = SvgCoordinateUtils.CalculateAngleBetweenTwoVectors(xAxis, v);
         return(v.Get(1) >= 0 && !reverse ? rotAngle : rotAngle * -1f);
     }
     return(0);
 }
 public virtual double GetAutoOrientAngle(MarkerSvgNodeRenderer marker, bool reverse)
 {
     if (points.Count > 1)
     {
         Vector v = new Vector(0, 0, 0);
         if (SvgConstants.Attributes.MARKER_END.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER)))
         {
             Point lastPoint         = points[points.Count - 1];
             Point secondToLastPoint = points[points.Count - 2];
             v = new Vector((float)(lastPoint.GetX() - secondToLastPoint.GetX()), (float)(lastPoint.GetY() - secondToLastPoint
                                                                                          .GetY()), 0f);
         }
         else
         {
             if (SvgConstants.Attributes.MARKER_START.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER)))
             {
                 Point firstPoint  = points[0];
                 Point secondPoint = points[1];
                 v = new Vector((float)(secondPoint.GetX() - firstPoint.GetX()), (float)(secondPoint.GetY() - firstPoint.GetY
                                                                                             ()), 0f);
             }
         }
         Vector xAxis    = new Vector(1, 0, 0);
         double rotAngle = SvgCoordinateUtils.CalculateAngleBetweenTwoVectors(xAxis, v);
         return(v.Get(1) >= 0 && !reverse ? rotAngle : rotAngle * -1f);
     }
     return(0);
 }
Ejemplo n.º 3
0
        public override ISvgNodeRenderer CreateDeepCopy()
        {
            MarkerSvgNodeRenderer copy = new MarkerSvgNodeRenderer();

            DeepCopyAttributesAndStyles(copy);
            DeepCopyChildren(copy);
            return(copy);
        }
        public virtual double GetAutoOrientAngle(MarkerSvgNodeRenderer marker, bool reverse)
        {
            Vector v = new Vector(GetAttribute(this.attributesAndStyles, SvgConstants.Attributes.X2) - GetAttribute(this
                                                                                                                    .attributesAndStyles, SvgConstants.Attributes.X1), GetAttribute(this.attributesAndStyles, SvgConstants.Attributes
                                                                                                                                                                                    .Y2) - GetAttribute(this.attributesAndStyles, SvgConstants.Attributes.Y1), 0f);
            Vector xAxis    = new Vector(1, 0, 0);
            double rotAngle = SvgCoordinateUtils.CalculateAngleBetweenTwoVectors(xAxis, v);

            return(v.Get(1) >= 0 && !reverse ? rotAngle : rotAngle * -1f);
        }
Ejemplo n.º 5
0
        private static bool MarkerWidthHeightAreCorrect(MarkerSvgNodeRenderer namedObject)
        {
            ILog   log          = LogManager.GetLogger(typeof(MarkerSvgNodeRenderer));
            String markerWidth  = namedObject.GetAttribute(SvgConstants.Attributes.MARKER_WIDTH);
            String markerHeight = namedObject.GetAttribute(SvgConstants.Attributes.MARKER_HEIGHT);
            bool   isCorrect    = true;

            if (markerWidth != null)
            {
                float absoluteMarkerWidthValue = CssUtils.ParseAbsoluteLength(markerWidth);
                if (absoluteMarkerWidthValue == 0)
                {
                    log.Warn(SvgLogMessageConstant.MARKER_WIDTH_IS_ZERO_VALUE);
                    isCorrect = false;
                }
                else
                {
                    if (absoluteMarkerWidthValue < 0)
                    {
                        log.Warn(SvgLogMessageConstant.MARKER_WIDTH_IS_NEGATIVE_VALUE);
                        isCorrect = false;
                    }
                }
            }
            if (markerHeight != null)
            {
                float absoluteMarkerHeightValue = CssUtils.ParseAbsoluteLength(markerHeight);
                if (absoluteMarkerHeightValue == 0)
                {
                    log.Warn(SvgLogMessageConstant.MARKER_HEIGHT_IS_ZERO_VALUE);
                    isCorrect = false;
                }
                else
                {
                    if (absoluteMarkerHeightValue < 0)
                    {
                        log.Warn(SvgLogMessageConstant.MARKER_HEIGHT_IS_NEGATIVE_VALUE);
                        isCorrect = false;
                    }
                }
            }
            return(isCorrect);
        }
        public virtual void DrawMarker(SvgDrawContext context, MarkerVertexType markerVertexType)
        {
            Point point = null;

            if (MarkerVertexType.MARKER_START.Equals(markerVertexType))
            {
                point = points[0];
            }
            else
            {
                if (MarkerVertexType.MARKER_END.Equals(markerVertexType))
                {
                    point = points[points.Count - 1];
                }
            }
            if (point != null)
            {
                String moveX = SvgCssUtils.ConvertDoubleToString(CssUtils.ConvertPtsToPx(point.x));
                String moveY = SvgCssUtils.ConvertDoubleToString(CssUtils.ConvertPtsToPx(point.y));
                MarkerSvgNodeRenderer.DrawMarker(context, moveX, moveY, markerVertexType, this);
            }
        }
        public virtual void DrawMarker(SvgDrawContext context, MarkerVertexType markerVertexType)
        {
            String moveX = null;
            String moveY = null;

            if (MarkerVertexType.MARKER_START.Equals(markerVertexType))
            {
                moveX = this.attributesAndStyles.Get(SvgConstants.Attributes.X1);
                moveY = this.attributesAndStyles.Get(SvgConstants.Attributes.Y1);
            }
            else
            {
                if (MarkerVertexType.MARKER_END.Equals(markerVertexType))
                {
                    moveX = this.attributesAndStyles.Get(SvgConstants.Attributes.X2);
                    moveY = this.attributesAndStyles.Get(SvgConstants.Attributes.Y2);
                }
            }
            if (moveX != null && moveY != null)
            {
                MarkerSvgNodeRenderer.DrawMarker(context, moveX, moveY, markerVertexType, this);
            }
        }
Ejemplo n.º 8
0
        public virtual void DrawMarker(SvgDrawContext context, MarkerVertexType markerVertexType)
        {
            Object[] allShapesOrdered = GetShapes().ToArray();
            Point    point            = null;

            if (MarkerVertexType.MARKER_START.Equals(markerVertexType))
            {
                point = ((AbstractPathShape)allShapesOrdered[0]).GetEndingPoint();
            }
            else
            {
                if (MarkerVertexType.MARKER_END.Equals(markerVertexType))
                {
                    point = ((AbstractPathShape)allShapesOrdered[allShapesOrdered.Length - 1]).GetEndingPoint();
                }
            }
            if (point != null)
            {
                String moveX = SvgCssUtils.ConvertDoubleToString(point.x);
                String moveY = SvgCssUtils.ConvertDoubleToString(point.y);
                MarkerSvgNodeRenderer.DrawMarker(context, moveX, moveY, markerVertexType, this);
            }
        }