コード例 #1
0
        private PenAction GetAction(PathPartAdorner pathPartAdorner)
        {
            PenAction        penAction        = (PenAction)null;
            PathEditorTarget pathEditorTarget = pathPartAdorner.PathAdornerSet.PathEditorTarget;
            PathFigure       pathFigure       = pathEditorTarget.PathGeometry.Figures[pathPartAdorner.FigureIndex];

            for (int index1 = 0; index1 < pathFigure.Segments.Count; ++index1)
            {
                System.Windows.Media.PathSegment segment = pathFigure.Segments[index1];
                for (int index2 = 0; index2 < PathSegmentUtilities.GetPointCount(segment); ++index2)
                {
                    if (PathSegmentUtilities.GetPointKind(segment, index2) == PathPointKind.Arc)
                    {
                        return((PenAction)null);
                    }
                }
            }
            if (pathPartAdorner is PathPointAdorner)
            {
                penAction = (PenAction) new ConvertPointAction(pathEditorTarget, this.ActiveSceneViewModel);
            }
            else if (pathPartAdorner is PathTangentAdorner || pathPartAdorner is PenTangentAdorner)
            {
                penAction = (PenAction) new TangentDragAction(pathEditorTarget, this.ActiveSceneViewModel, pathPartAdorner is PenTangentAdorner);
            }
            else if (pathPartAdorner is PathSegmentAdorner)
            {
                penAction = (PenAction) new ConvertSegmentAction(pathEditorTarget, this.ActiveSceneViewModel);
            }
            return(penAction);
        }
コード例 #2
0
        public PathSegmentHandle(MoonlightController controller, IHandleGroup group, PathSegment seg, DependencyProperty point)
            : base(controller, group)
        {
            if (seg == null)
                throw new ArgumentNullException("seg");

            if (point == null)
                throw new ArgumentNullException("point");
            segment = seg;
            point_property = point;
        }
コード例 #3
0
ファイル: WindowsCanvas.cs プロジェクト: pfjgeng/Tida.CAD
        /// <summary>
        /// 得到圆弧的几何图形;
        /// </summary>
        /// <param name="center"></param>
        /// <param name="screenRadius"></param>
        /// <param name="beginAngle"></param>
        /// <param name="angle"></param>
        /// <param name="smallAngle"></param>
        /// <returns></returns>
        private static SystemMedia.PathGeometry GetArcGeometry(Point startScreenPoint, Point endScreenPoint, double screenRadius, bool smallAngle, SystemMedia.SweepDirection sweepDirection)
        {
            var arcSegment = new SystemMedia.ArcSegment(endScreenPoint, new System.Windows.Size(screenRadius, screenRadius), 0D, !smallAngle, sweepDirection, true);

            var segments   = new SystemMedia.PathSegment[] { arcSegment };
            var pathFigure = new SystemMedia.PathFigure(startScreenPoint, segments, false);

            var figures = new SystemMedia.PathFigure[] { pathFigure };

            arcSegment.Freeze();
            pathFigure.Freeze();

            return(new SystemMedia.PathGeometry(figures, SystemMedia.FillRule.EvenOdd, null));
        }
コード例 #4
0
ファイル: PathHandleGroup.cs プロジェクト: mono/lunareclipse
        private void AddBezierSegmentHandles(PathSegment segment)
        {
            IHandle handle;

            handle = new BezierSegmentPoint3Handle(Controller, this, segment as BezierSegment);
            AddHandle(handle);

            handle = new PathSegmentHandle(Controller, this, segment,
                                                   BezierSegment.Point1Property);
            AddHandle(handle);

            handle = new PathSegmentHandle(Controller, this, segment,
                                           BezierSegment.Point2Property);
            AddHandle(handle);
        }
コード例 #5
0
        public BezierSegmentFrame(UIElement child, PathFigure fig, BezierSegment bez)
            : base(child)
        {
            bezier = bez;
            figure = fig;

            previous = null;

            foreach (PathSegment segment in figure.Segments) {
                BezierSegment bs = segment as BezierSegment;
                if (segment == bezier)
                    break;
                previous = segment;
            }

            point1_line = CreateLine();
            point2_line = CreateLine();
        }
コード例 #6
0
        public static Rect GetMinimalMaxRect(m.PathGeometry pg, double rahmen)
        {
            pg = pg.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);
            m.PathSegment tmp        = pg.Figures[0].Segments[0];
            Point         firstPoint = ((m.PolyLineSegment)tmp).Points[0];

            Point max = firstPoint;
            Point min = firstPoint;

            foreach (m.PathFigure pathFigure in pg.Figures)
            {
                foreach (m.PathSegment segments in pathFigure.Segments)
                {
                    foreach (Point point in ((m.PolyLineSegment)segments).Points)
                    {
                        if (point.X > max.X)
                        {
                            max.X = point.X;
                        }
                        if (point.X < min.X)
                        {
                            min.X = point.X;
                        }
                        if (point.Y > max.Y)
                        {
                            max.Y = point.Y;
                        }
                        if (point.Y < min.Y)
                        {
                            min.Y = point.Y;
                        }
                    }
                }
            }

            min.X -= rahmen;
            min.Y -= rahmen;

            max.X += rahmen;
            max.Y += rahmen;

            return(new Rect(min, max));
        }
コード例 #7
0
 public static void UpdateAllPoints(PathGeometry geometry, Transform transform)
 {
     for (int index1 = 0; index1 < geometry.Figures.Count; ++index1)
     {
         PathFigure       figure           = geometry.Figures[index1];
         PathFigureEditor pathFigureEditor = new PathFigureEditor(figure);
         int index2 = 1;
         if (!PathFigureUtilities.IsClosed(figure) || !PathFigureUtilities.IsCloseSegmentDegenerate(figure))
         {
             pathFigureEditor.SetPoint(0, transform.Transform(figure.StartPoint));
         }
         for (int index3 = 0; index3 < figure.Segments.Count; ++index3)
         {
             System.Windows.Media.PathSegment segment = figure.Segments[index3];
             int pointCount = PathSegmentUtilities.GetPointCount(segment);
             for (int index4 = 0; index4 < pointCount; ++index4)
             {
                 Point point = PathSegmentUtilities.GetPoint(segment, index4);
                 pathFigureEditor.SetPoint(index2, transform.Transform(point));
                 ++index2;
             }
         }
     }
 }
コード例 #8
0
ファイル: PathHandleGroup.cs プロジェクト: mono/lunareclipse
 private void AddLineSegmentHandle(PathSegment segment)
 {
     IHandle handle = new LineSegmentHandle(Controller, this, segment);
     AddHandle(handle);
 }
コード例 #9
0
		private DesignItem SegmentToDesignItem(PathSegment s)
		{
			var sDes = designItem.Services.Component.RegisterComponentForDesigner(s.Clone());
			
			if (!((PathSegment)s).IsStroked)
				sDes.Properties[PathSegment.IsStrokedProperty].SetValue(((PathSegment)s).IsStroked);
			if (((PathSegment)s).IsSmoothJoin)
				sDes.Properties[PathSegment.IsSmoothJoinProperty].SetValue(((PathSegment)s).IsSmoothJoin);
				
			if (s is LineSegment) {
				sDes.Properties[LineSegment.PointProperty].SetValue(((LineSegment)s).Point);
			} else if (s is QuadraticBezierSegment) {
				sDes.Properties[QuadraticBezierSegment.Point1Property].SetValue(((QuadraticBezierSegment)s).Point1);
				sDes.Properties[QuadraticBezierSegment.Point2Property].SetValue(((QuadraticBezierSegment)s).Point2);
			} else if (s is BezierSegment) {
				sDes.Properties[BezierSegment.Point1Property].SetValue(((BezierSegment)s).Point1);
				sDes.Properties[BezierSegment.Point2Property].SetValue(((BezierSegment)s).Point2);
				sDes.Properties[BezierSegment.Point3Property].SetValue(((BezierSegment)s).Point3);
			} else if (s is ArcSegment) {
				sDes.Properties[ArcSegment.PointProperty].SetValue(((ArcSegment)s).Point);
				sDes.Properties[ArcSegment.IsLargeArcProperty].SetValue(((ArcSegment)s).IsLargeArc);
				sDes.Properties[ArcSegment.RotationAngleProperty].SetValue(((ArcSegment)s).RotationAngle);
				sDes.Properties[ArcSegment.SizeProperty].SetValue(((ArcSegment)s).Size);
				sDes.Properties[ArcSegment.SweepDirectionProperty].SetValue(((ArcSegment)s).SweepDirection);
			} else if (s is PolyLineSegment) {
				sDes.Properties[PolyLineSegment.PointsProperty].SetValue(((PolyLineSegment)s).Points);
			} else if (s is PolyQuadraticBezierSegment) {
				sDes.Properties[PolyQuadraticBezierSegment.PointsProperty].SetValue(((PolyQuadraticBezierSegment)s).Points);
			} else if (s is PolyBezierSegment) {
				sDes.Properties[PolyBezierSegment.PointsProperty].SetValue(((PolyBezierSegment)s).Points);
			}
			return sDes;
		}
コード例 #10
0
ファイル: Adornment.cs プロジェクト: jerryshi2007/AK47Source
    private static PathSegment Copy(PathSegment s) {
      if (s == null) return null;

      LineSegment ls = s as LineSegment;
      if (ls != null) {
        return new LineSegment() { Point = ls.Point };
      }
      BezierSegment bs = s as BezierSegment;
      if (bs != null) {
        return new BezierSegment() { Point1 = bs.Point1, Point2 = bs.Point2, Point3 = bs.Point3 };
      }
      QuadraticBezierSegment qbs = s as QuadraticBezierSegment;
      if (qbs != null) {
        return new QuadraticBezierSegment() { Point1 = qbs.Point1, Point2 = qbs.Point2 };
      }
      ArcSegment arc = s as ArcSegment;
      if (arc != null) {
        return new ArcSegment() { Point = arc.Point, Size = arc.Size, SweepDirection = arc.SweepDirection, IsLargeArc = arc.IsLargeArc, RotationAngle = arc.RotationAngle };
      }
      PolyLineSegment pls = s as PolyLineSegment;
      if (pls != null) {
        return new PolyLineSegment() { Points = Copy(pls.Points) };
      }
      PolyBezierSegment pbs = s as PolyBezierSegment;
      if (pbs != null) {
        return new PolyBezierSegment() { Points = Copy(pbs.Points) };
      }
      PolyQuadraticBezierSegment pqbs = s as PolyQuadraticBezierSegment;
      if (pqbs != null) {
        return new PolyQuadraticBezierSegment() { Points = Copy(pqbs.Points) };
      }
      Diagram.Error("Copying an unknown kind of PathSegment: " + s.ToString());
      return null;
    }
コード例 #11
0
 public PathSegmentData(Point startPoint, System.Windows.Media.PathSegment pathSegment)
 {
     PathSegment = pathSegment;
     StartPoint  = startPoint;
 }
コード例 #12
0
 public LineSegmentHandle(MoonlightController controller, IHandleGroup group, PathSegment seg)
     : base(controller, group, seg, LineSegment.PointProperty)
 {
 }
コード例 #13
0
ファイル: EaseHelper.cs プロジェクト: heartszhang/WeiZhi3
        /// <summary>
        /// Returns new PathSegment by easing startValue to endValue using a time percentage 0 -> 1.
        /// </summary>
        public static PathSegment EaseValue(PathSegment startValue, PathSegment endValue, double percent)
        {
            var startType = startValue.GetType();
            var endType = endValue.GetType();
            if ( startType != endType ) return endValue; // can't ease different types... returning expected end type

            if ( endValue is LineSegment) return EaseValue((LineSegment)startValue, (LineSegment)endValue, percent);
            if ( endValue is BezierSegment) return EaseValue((BezierSegment)startValue, (BezierSegment)endValue, percent);
            if ( endValue is ArcSegment) return EaseValue((ArcSegment)startValue, (ArcSegment)endValue, percent);
            if ( endValue is PolyLineSegment) return EaseValue((PolyLineSegment)startValue, (PolyLineSegment)endValue, percent);
            if ( endValue is PolyBezierSegment) return EaseValue((PolyBezierSegment)startValue, (PolyBezierSegment)endValue, percent);
            if ( endValue is PolyQuadraticBezierSegment) return EaseValue((PolyQuadraticBezierSegment)startValue, (PolyQuadraticBezierSegment)endValue, percent);
            if ( endValue is QuadraticBezierSegment) return EaseValue((QuadraticBezierSegment)startValue, (QuadraticBezierSegment)endValue, percent);

            return endValue;
        }
コード例 #14
0
ファイル: PathGeometryHelper.cs プロジェクト: Altaxo/Altaxo
		public static void GetStartAndEndVector(Point startPoint, PathSegment seg, out Point endPoint, out Vector startVector, out Vector endVector)
		{
			ArcSegment arcSegment;
			BezierSegment bezierSegment;
			LineSegment lineSegment;
			PolyBezierSegment polyBezierSegment;
			PolyLineSegment polyLineSegment;
			PolyQuadraticBezierSegment polyQuadraticBezierSegment;
			QuadraticBezierSegment quadraticBezierSegment;

			if (null != (lineSegment = (seg as LineSegment)))
			{
				startVector = endVector = lineSegment.Point - startPoint;
				endPoint = lineSegment.Point;
			}
			else if (null != (polyLineSegment = (seg as PolyLineSegment)))
			{
				var pts = polyLineSegment.Points;
				var len = pts.Count;
				startVector = pts[0] - startPoint;
				if (len >= 2)
					startPoint = pts[len - 2];
				endVector = pts[len - 1] - startPoint;
				endPoint = pts[len - 1];
			}
			else if (null != (bezierSegment = (seg as BezierSegment)))
			{
				startVector = bezierSegment.Point1 - startPoint;
				endVector = bezierSegment.Point3 - bezierSegment.Point2;
				endPoint = bezierSegment.Point3;
			}
			else if (null != (polyBezierSegment = (seg as PolyBezierSegment)))
			{
				var pts = polyBezierSegment.Points;
				var len = pts.Count;
				startVector = pts[0] - startPoint;
				endVector = pts[len - 1] - pts[len - 2];
				endPoint = pts[len - 1];
			}
			else
			{
				throw new NotImplementedException();
			}
		}
コード例 #15
0
        public static IEnumerable<Telerik.Windows.Documents.Fixed.Model.Graphics.PathSegment> ConvertPathSegments(PathSegment pathSegment)
        {
            Type segmentType = pathSegment.GetType();
            Func<PathSegment, IEnumerable<Telerik.Windows.Documents.Fixed.Model.Graphics.PathSegment>> converter;

            if (!segmentConverters.TryGetValue(segmentType, out converter))
            {
                throw new NotSupportedException(String.Format("Not supported PathSegment type: {0}", segmentType));
            }

            return converter(pathSegment);
        }
コード例 #16
0
ファイル: PieChart.cs プロジェクト: tdhieu/openvss
        /// <summary>
        /// Create PathSegment animation
        /// </summary>
        /// <param name="storyboard">Storyboard</param>
        /// <param name="target">Animation target</param>
        /// <param name="center">Center point</param>
        /// <param name="radius">Radius</param>
        /// <param name="startAngle">Start angle</param>
        /// <param name="stopAngle">Stop angle</param>
        /// <returns>Storyboard</returns>
        private static Storyboard CreatePathSegmentAnimation(DataSeries currentDataSeries, DataPoint currentDataPoint, Storyboard storyboard, PathSegment target, Point center, Double radius, Double startAngle, Double stopAngle)
        {
            List<Point> points = GenerateAnimationPoints(center, radius, startAngle, stopAngle);
            List<Double> frames = GenerateAnimationFrames(points.Count, 1);
            List<KeySpline> splines = AnimationHelper.GenerateKeySplineList(points.Count);

            PointAnimationUsingKeyFrames pieSliceAnimation = null;

            if (typeof(ArcSegment).IsInstanceOfType(target))
            {
                pieSliceAnimation = CreatePointAnimation(currentDataSeries, currentDataPoint, target, "(ArcSegment.Point)", 0.5, frames, points, splines);
            }
            else
            {
                pieSliceAnimation = CreatePointAnimation(currentDataSeries, currentDataPoint, target, "(LineSegment.Point)", 0.5, frames, points, splines);
            }

            storyboard.Children.Add(pieSliceAnimation);

            return storyboard;
        }
コード例 #17
0
        private void WriteElement(PathSegment segment)
        {
            string typeName = WriteStartElement(segment);

            ArcSegment arc = segment as ArcSegment;
            if (arc != null) {
                WriteAttribute("IsLargeArc", arc.IsLargeArc, false);
                WriteAttribute("Point", arc.Point, DefaultPoint);
                WriteAttribute("RotationAngle", arc.RotationAngle, 0);
                WriteAttribute("Size", arc.Size, DefaultSize);
                WriteAttribute("SweepDirection", arc.SweepDirection, SweepDirection.Counterclockwise);
                goto End;
            }
            BezierSegment bezier = segment as BezierSegment;
            if (bezier != null) {
                WriteAttribute("Point1", bezier.Point1, DefaultPoint);
                WriteAttribute("Point2", bezier.Point2, DefaultPoint);
                WriteAttribute("Point3", bezier.Point3, DefaultPoint);
                goto End;
            }
            LineSegment line = segment as LineSegment;
            if (line != null) {
                WriteAttribute("Point", line.Point, DefaultPoint);
                goto End;
            }
            PolyBezierSegment polyBezier = segment as PolyBezierSegment;
            if (polyBezier != null) {
                WriteAttribute("Points", polyBezier.Points);
                goto End;
            }
            PolyLineSegment polyLine = segment as PolyLineSegment;
            if (polyLine != null) {
                WriteAttribute("Points", polyLine.Points);
                goto End;
            }
            PolyQuadraticBezierSegment polyQuadraticBezier = segment as PolyQuadraticBezierSegment;
            if (polyQuadraticBezier != null) {
                WriteAttribute("Points", polyQuadraticBezier.Points);
                goto End;
            }
            QuadraticBezierSegment quadraticBezier = segment as QuadraticBezierSegment;
            if (quadraticBezier != null) {
                WriteAttribute("Point1", quadraticBezier.Point1, DefaultPoint);
                WriteAttribute("Point2", quadraticBezier.Point2, DefaultPoint);
                goto End;
            }
        End:
            WriteEndElement();
        }
コード例 #18
0
        protected virtual void CreatePathAdorners(List <Adorner> oldAdornerList, List <Adorner> newAdornerList)
        {
            this.adornerCounts.Clear();
            this.adornerOffsets.Clear();
            PathPartSelectionSet      partSelectionSet = this.PathPartSelectionSet;
            List <PathPointAdorner>   list1            = new List <PathPointAdorner>();
            List <PathSegmentAdorner> list2            = new List <PathSegmentAdorner>();
            List <PathTangentAdorner> list3            = new List <PathTangentAdorner>();
            int index1 = 0;
            int index2 = 0;
            int index3 = 0;

            foreach (Adorner adorner in oldAdornerList)
            {
                PathPointAdorner pathPointAdorner;
                if ((pathPointAdorner = adorner as PathPointAdorner) != null)
                {
                    list1.Add(pathPointAdorner);
                }
                else
                {
                    PathSegmentAdorner pathSegmentAdorner;
                    if ((pathSegmentAdorner = adorner as PathSegmentAdorner) != null)
                    {
                        list2.Add(pathSegmentAdorner);
                    }
                    else
                    {
                        PathTangentAdorner pathTangentAdorner;
                        if ((pathTangentAdorner = adorner as PathTangentAdorner) != null)
                        {
                            list3.Add(pathTangentAdorner);
                        }
                    }
                }
            }
            for (int figureIndex = 0; figureIndex < this.PathGeometry.Figures.Count; ++figureIndex)
            {
                PathFigure       figure           = this.PathGeometry.Figures[figureIndex];
                PathFigureEditor pathFigureEditor = new PathFigureEditor(figure);
                this.adornerOffsets.Add((object)this.AdornerList.Count);
                int length1 = PathFigureUtilities.PointCount(figure);
                int length2 = length1 + (PathFigureUtilities.IsClosed(figure) ? true : false);
                PathSegmentAdorner[] pathSegmentAdornerArray = new PathSegmentAdorner[length2];
                PathPointKind[]      pathPointKindArray      = new PathPointKind[length2];
                pathPointKindArray[0] = pathFigureEditor.GetPointKind(0);
                int num1 = 1;
                for (int index4 = 0; index4 < figure.Segments.Count; ++index4)
                {
                    System.Windows.Media.PathSegment segment = figure.Segments[index4];
                    int pointCount = PathSegmentUtilities.GetPointCount(segment);
                    for (int index5 = 0; index5 < pointCount; ++index5)
                    {
                        pathPointKindArray[num1++] = PathSegmentUtilities.GetPointKind(segment, index5);
                    }
                }
                int index6 = 1;
                for (int segmentIndex = 0; segmentIndex < figure.Segments.Count; ++segmentIndex)
                {
                    int pointCount = PathSegmentUtilities.GetPointCount(figure.Segments[segmentIndex]);
                    for (int segmentPointIndex = 0; segmentPointIndex < pointCount; ++segmentPointIndex)
                    {
                        if (pathPointKindArray[index6] != PathPointKind.BezierHandle)
                        {
                            PathSegmentAdorner pathSegmentAdorner;
                            if (index2 < list2.Count)
                            {
                                pathSegmentAdorner = list2[index2];
                                pathSegmentAdorner.Initialize(figureIndex, index6 % length1, segmentIndex, segmentPointIndex);
                                oldAdornerList.Remove((Adorner)pathSegmentAdorner);
                                ++index2;
                            }
                            else
                            {
                                pathSegmentAdorner = new PathSegmentAdorner(this, figureIndex, index6 % length1, segmentIndex, segmentPointIndex);
                            }
                            if (partSelectionSet != null)
                            {
                                pathSegmentAdorner.IsActive = partSelectionSet.IsSelected((PathPart)(PathSegment)pathSegmentAdorner);
                            }
                            newAdornerList.Add((Adorner)pathSegmentAdorner);
                            pathSegmentAdornerArray[index6] = pathSegmentAdorner;
                        }
                        else
                        {
                            pathSegmentAdornerArray[index6] = (PathSegmentAdorner)null;
                        }
                        ++index6;
                    }
                }
                if (figure.IsClosed && figure.Segments.Count > 0)
                {
                    Point lastPoint = PathSegmentUtilities.GetLastPoint(figure.Segments[figure.Segments.Count - 1]);
                    if (!VectorUtilities.ArePathPointsVeryClose(figure.StartPoint, lastPoint))
                    {
                        PathSegmentAdorner pathSegmentAdorner;
                        if (index2 < list2.Count)
                        {
                            pathSegmentAdorner = list2[index2];
                            pathSegmentAdorner.Initialize(figureIndex, index6 % length1, -1, 0);
                            oldAdornerList.Remove((Adorner)pathSegmentAdorner);
                            ++index2;
                        }
                        else
                        {
                            pathSegmentAdorner = new PathSegmentAdorner(this, figureIndex, index6 % length1, -1, 0);
                        }
                        if (partSelectionSet != null)
                        {
                            pathSegmentAdorner.IsActive = partSelectionSet.IsSelected((PathPart)(PathSegment)pathSegmentAdorner);
                        }
                        newAdornerList.Add((Adorner)pathSegmentAdorner);
                        pathSegmentAdornerArray[index6] = pathSegmentAdorner;
                    }
                }
                this.adornerCounts.Add((object)(this.AdornerList.Count - (int)this.adornerOffsets[this.adornerOffsets.Count - 1]));
                this.adornerTypes.Add((object)PathPart.PartType.PathSegment);
                PathPointAdorner[] pathPointAdornerArray = new PathPointAdorner[length1];
                int index7 = 0;
                for (int segmentIndex = -1; segmentIndex < figure.Segments.Count; ++segmentIndex)
                {
                    int num2 = 1;
                    if (segmentIndex != -1)
                    {
                        num2 = PathSegmentUtilities.GetPointCount(figure.Segments[segmentIndex]);
                    }
                    for (int segmentPointIndex = 0; segmentPointIndex < num2 && index7 < length1; ++segmentPointIndex)
                    {
                        if (pathPointKindArray[index7] == PathPointKind.BezierHandle)
                        {
                            pathPointAdornerArray[index7] = (PathPointAdorner)null;
                        }
                        else
                        {
                            PathPointAdorner pathPointAdorner;
                            if (index1 < list1.Count)
                            {
                                pathPointAdorner = list1[index1];
                                pathPointAdorner.Initialize(figureIndex, index7, segmentIndex, segmentPointIndex);
                                oldAdornerList.Remove((Adorner)pathPointAdorner);
                                ++index1;
                            }
                            else
                            {
                                pathPointAdorner = new PathPointAdorner(this, figureIndex, index7, segmentIndex, segmentPointIndex);
                            }
                            pathPointAdornerArray[index7] = pathPointAdorner;
                            if (partSelectionSet != null)
                            {
                                pathPointAdornerArray[index7].IsActive = partSelectionSet.IsSelected((PathPart)(PathPoint)pathPointAdornerArray[index7]);
                            }
                        }
                        ++index7;
                    }
                }
                int endPointIndex = 0;
                for (int segmentIndex = -1; segmentIndex < figure.Segments.Count; ++segmentIndex)
                {
                    int num2 = 1;
                    if (segmentIndex != -1)
                    {
                        num2 = PathSegmentUtilities.GetPointCount(figure.Segments[segmentIndex]);
                    }
                    for (int segmentPointIndex = 0; segmentPointIndex < num2 && endPointIndex < length1; ++segmentPointIndex)
                    {
                        if (pathPointKindArray[endPointIndex] == PathPointKind.BezierHandle)
                        {
                            PathPointAdorner   pathPointAdorner   = (PathPointAdorner)null;
                            PathSegmentAdorner pathSegmentAdorner = (PathSegmentAdorner)null;
                            if (pathPointKindArray[endPointIndex] == PathPointKind.BezierHandle && endPointIndex + 2 < pathPointKindArray.Length && pathPointKindArray[endPointIndex + 2] == PathPointKind.Cubic)
                            {
                                pathPointAdorner   = pathPointAdornerArray[endPointIndex - 1];
                                pathSegmentAdorner = pathSegmentAdornerArray[endPointIndex + 2];
                            }
                            else if (pathPointKindArray[endPointIndex] == PathPointKind.BezierHandle && endPointIndex + 1 < pathPointKindArray.Length && pathPointKindArray[endPointIndex + 1] == PathPointKind.Cubic)
                            {
                                pathPointAdorner   = pathPointAdornerArray[(endPointIndex + 1) % length1];
                                pathSegmentAdorner = pathSegmentAdornerArray[endPointIndex + 1];
                            }
                            if (pathPointAdorner != null)
                            {
                                PathTangentAdorner pathTangentAdorner;
                                if (index3 < list3.Count)
                                {
                                    pathTangentAdorner = list3[index3];
                                    pathTangentAdorner.Initialize(figureIndex, endPointIndex, segmentIndex, segmentPointIndex, pathPointAdorner, pathSegmentAdorner);
                                    oldAdornerList.Remove((Adorner)pathTangentAdorner);
                                    ++index3;
                                }
                                else
                                {
                                    pathTangentAdorner = new PathTangentAdorner(this, figureIndex, endPointIndex, segmentIndex, segmentPointIndex, pathPointAdorner, pathSegmentAdorner);
                                }
                                newAdornerList.Add((Adorner)pathTangentAdorner);
                            }
                        }
                        ++endPointIndex;
                    }
                }
                foreach (PathPointAdorner pathPointAdorner in pathPointAdornerArray)
                {
                    if (pathPointAdorner != null)
                    {
                        newAdornerList.Add((Adorner)pathPointAdorner);
                    }
                }
                this.adornerOffsets.Add((object)this.AdornerList.Count);
                this.adornerCounts.Add((object)(this.AdornerList.Count - (int)this.adornerOffsets[this.adornerOffsets.Count - 1]));
                this.adornerTypes.Add((object)PathPart.PartType.PathPoint);
            }
        }
コード例 #19
0
ファイル: PieChart.cs プロジェクト: tdhieu/openvss
        /// <summary>
        /// Create interactivity animation for LabelLine
        /// </summary>
        /// <param name="storyboard">Storyboard</param>
        /// <param name="target">Target object</param>
        /// <param name="points">Array of Points</param>
        /// <returns>Storyboard</returns>
        private static Storyboard CreateLabelLineInteractivityAnimation(DataSeries currentDataSeries, DataPoint currentDataPoint, Storyboard storyboard, PathSegment target, params Point[] points)
        {
            List<Point> pointsList = points.ToList();
            List<Double> frames = GenerateAnimationFrames(pointsList.Count, 0.4);
            List<KeySpline> splines = AnimationHelper.GenerateKeySplineList(pointsList.Count);

            PointAnimationUsingKeyFrames labelLineAnimation = CreatePointAnimation(currentDataSeries, currentDataPoint, target, "(LineSegment.Point)", 0, frames, pointsList, splines);
            storyboard.Children.Add(labelLineAnimation);

            return storyboard;
        }
コード例 #20
0
ファイル: TickBar.cs プロジェクト: sjyanxin/WPFSource
        /// <summary>
        /// Draw ticks. 
        /// Ticks can be draw in 8 diffrent ways depends on Placment property and IsDirectionReversed property.
        /// 
        /// This function also draw selection-tick(s) if IsSelectionRangeEnabled is 'true' and 
        /// SelectionStart and SelectionEnd are valid.
        /// 
        /// The primary ticks (for Mininum and Maximum value) height will be 100% of TickBar's render size (use Width or Height
        /// depends on Placement property).
        ///
        /// The secondary ticks (all other ticks, including selection-tics) height will be 75% of TickBar's render size. 
        ///
        /// Brush that use to fill ticks is specified by Shape.Fill property. 
        /// 
        /// Pen that use to draw ticks is specified by Shape.Pen property.
        /// </summary> 
        protected override void OnRender(DrawingContext dc)
        {
            Size size = new Size(ActualWidth,ActualHeight);
            double range = Maximum - Minimum; 
            double tickLen = 0.0d;  // Height for Primary Tick (for Mininum and Maximum value)
            double tickLen2;        // Height for Secondary Tick 
            double logicalToPhysical = 1.0; 
            double progression = 1.0d;
            Point startPoint = new Point(0d,0d); 
            Point endPoint = new Point(0d, 0d);

            // Take Thumb size in to account
            double halfReservedSpace = ReservedSpace * 0.5; 

            switch(Placement) 
            { 
                case TickBarPlacement.Top:
                    if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Width)) 
                    {
                        return;
                    }
                    size.Width -= ReservedSpace; 
                    tickLen = - size.Height;
                    startPoint = new Point(halfReservedSpace, size.Height); 
                    endPoint = new Point(halfReservedSpace + size.Width, size.Height); 
                    logicalToPhysical = size.Width / range;
                    progression = 1; 
                    break;

                case TickBarPlacement.Bottom:
                    if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Width)) 
                    {
                        return; 
                    } 
                    size.Width -= ReservedSpace;
                    tickLen = size.Height; 
                    startPoint = new Point(halfReservedSpace, 0d);
                    endPoint = new Point(halfReservedSpace + size.Width, 0d);
                    logicalToPhysical = size.Width / range;
                    progression = 1; 
                    break;
 
                case TickBarPlacement.Left: 
                    if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Height))
                    { 
                        return;
                    }
                    size.Height -= ReservedSpace;
                    tickLen = -size.Width; 
                    startPoint = new Point(size.Width, size.Height + halfReservedSpace);
                    endPoint = new Point(size.Width, halfReservedSpace); 
                    logicalToPhysical = size.Height / range * -1; 
                    progression = -1;
                    break; 

                case TickBarPlacement.Right:
                    if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Height))
                    { 
                        return;
                    } 
                    size.Height -= ReservedSpace; 
                    tickLen = size.Width;
                    startPoint = new Point(0d, size.Height + halfReservedSpace); 
                    endPoint = new Point(0d, halfReservedSpace);
                    logicalToPhysical = size.Height / range * -1;
                    progression = -1;
                    break; 
            };
 
            tickLen2 = tickLen * 0.75; 

            // Invert direciton of the ticks 
            if (IsDirectionReversed)
            {
                progression = -progression;
                logicalToPhysical *= -1; 

                // swap startPoint & endPoint 
                Point pt = startPoint; 
                startPoint = endPoint;
                endPoint = pt; 
            }

            Pen pen = new Pen(Fill, 1.0d);
 
            bool snapsToDevicePixels = SnapsToDevicePixels;
            DoubleCollection xLines = snapsToDevicePixels ? new DoubleCollection() : null; 
            DoubleCollection yLines = snapsToDevicePixels ? new DoubleCollection() : null; 

            // Is it Vertical? 
            if ((Placement == TickBarPlacement.Left) || (Placement == TickBarPlacement.Right))
            {
                // Reduce tick interval if it is more than would be visible on the screen
                double interval = TickFrequency; 
                if (interval > 0.0)
                { 
                    double minInterval = (Maximum - Minimum) / size.Height; 
                    if (interval < minInterval)
                    { 
                        interval = minInterval;
                    }
                }
 
                // Draw Min & Max tick
                dc.DrawLine(pen, startPoint, new Point(startPoint.X + tickLen, startPoint.Y)); 
                dc.DrawLine(pen, new Point(startPoint.X, endPoint.Y), 
                                 new Point(startPoint.X + tickLen, endPoint.Y));
 
                if (snapsToDevicePixels)
                {
                    xLines.Add(startPoint.X);
                    yLines.Add(startPoint.Y - 0.5); 
                    xLines.Add(startPoint.X + tickLen);
                    yLines.Add(endPoint.Y - 0.5); 
                    xLines.Add(startPoint.X + tickLen2); 
                }
 
                // This property is rarely set so let's try to avoid the GetValue
                // caching of the mutable default value
                DoubleCollection ticks = null;
                bool hasModifiers; 
                if (GetValueSource(TicksProperty, null, out hasModifiers)
                    != BaseValueSourceInternal.Default || hasModifiers) 
                { 
                    ticks = Ticks;
                } 

                // Draw ticks using specified Ticks collection
                if ((ticks != null) && (ticks.Count > 0))
                { 
                    for (int i = 0; i < ticks.Count; i++)
                    { 
                        if (DoubleUtil.LessThanOrClose(ticks[i],Minimum) || DoubleUtil.GreaterThanOrClose(ticks[i],Maximum)) 
                        {
                            continue; 
                        }

                        double adjustedTick = ticks[i] - Minimum;
 
                        double y = adjustedTick * logicalToPhysical + startPoint.Y;
                        dc.DrawLine(pen, 
                            new Point(startPoint.X, y), 
                            new Point(startPoint.X + tickLen2, y));
 
                        if (snapsToDevicePixels)
                        {
                            yLines.Add(y - 0.5);
                        } 
                    }
                } 
                // Draw ticks using specified TickFrequency 
                else if (interval > 0.0)
                { 
                    for (double i = interval; i < range; i += interval)
                    {
                        double y = i * logicalToPhysical + startPoint.Y;
 
                        dc.DrawLine(pen,
                            new Point(startPoint.X, y), 
                            new Point(startPoint.X + tickLen2, y)); 

                        if (snapsToDevicePixels) 
                        {
                            yLines.Add(y - 0.5);
                        }
                    } 
                }
 
                // Draw Selection Ticks 
                if (IsSelectionRangeEnabled)
                { 
                    double y0 = (SelectionStart - Minimum) * logicalToPhysical + startPoint.Y;
                    Point pt0 = new Point(startPoint.X, y0);
                    Point pt1 = new Point(startPoint.X + tickLen2, y0);
                    Point pt2 = new Point(startPoint.X + tickLen2, y0 + Math.Abs(tickLen2) * progression); 

                    PathSegment[] segments = new PathSegment[] { 
                        new LineSegment(pt2, true), 
                        new LineSegment(pt0, true),
                    }; 
                    PathGeometry geo = new PathGeometry(new PathFigure[] { new PathFigure(pt1, segments, true) });

                    dc.DrawGeometry(Fill, pen, geo);
 
                    y0 = (SelectionEnd - Minimum) * logicalToPhysical + startPoint.Y;
                    pt0 = new Point(startPoint.X, y0); 
                    pt1 = new Point(startPoint.X + tickLen2, y0); 
                    pt2 = new Point(startPoint.X + tickLen2, y0 - Math.Abs(tickLen2) * progression);
 
                    segments = new PathSegment[] {
                        new LineSegment(pt2, true),
                        new LineSegment(pt0, true),
                    }; 
                    geo = new PathGeometry(new PathFigure[] { new PathFigure(pt1, segments, true) });
                    dc.DrawGeometry(Fill, pen, geo); 
                } 
            }
            else  // Placement == Top || Placement == Bottom 
            {
                // Reduce tick interval if it is more than would be visible on the screen
                double interval = TickFrequency;
                if (interval > 0.0) 
                {
                    double minInterval = (Maximum - Minimum) / size.Width; 
                    if (interval < minInterval) 
                    {
                        interval = minInterval; 
                    }
                }

                // Draw Min & Max tick 
                dc.DrawLine(pen, startPoint, new Point(startPoint.X, startPoint.Y + tickLen));
                dc.DrawLine(pen, new Point(endPoint.X, startPoint.Y), 
                                 new Point(endPoint.X, startPoint.Y + tickLen)); 

                if (snapsToDevicePixels) 
                {
                    xLines.Add(startPoint.X - 0.5);
                    yLines.Add(startPoint.Y);
                    xLines.Add(startPoint.X - 0.5); 
                    yLines.Add(endPoint.Y + tickLen);
                    yLines.Add(endPoint.Y + tickLen2); 
                } 

                // This property is rarely set so let's try to avoid the GetValue 
                // caching of the mutable default value
                DoubleCollection ticks = null;
                bool hasModifiers;
                if (GetValueSource(TicksProperty, null, out hasModifiers) 
                    != BaseValueSourceInternal.Default || hasModifiers)
                { 
                    ticks = Ticks; 
                }
 
                // Draw ticks using specified Ticks collection
                if ((ticks != null) && (ticks.Count > 0))
                {
                    for (int i = 0; i < ticks.Count; i++) 
                    {
                        if (DoubleUtil.LessThanOrClose(ticks[i],Minimum) || DoubleUtil.GreaterThanOrClose(ticks[i],Maximum)) 
                        { 
                            continue;
                        } 
                        double adjustedTick = ticks[i] - Minimum;

                        double x = adjustedTick * logicalToPhysical + startPoint.X;
                        dc.DrawLine(pen, 
                            new Point(x, startPoint.Y),
                            new Point(x, startPoint.Y + tickLen2)); 
 
                        if (snapsToDevicePixels)
                        { 
                            xLines.Add(x - 0.5);
                        }
                    }
                } 
                // Draw ticks using specified TickFrequency
                else if (interval > 0.0) 
                { 
                    for (double i = interval; i < range; i += interval)
                    { 
                        double x = i * logicalToPhysical + startPoint.X;
                        dc.DrawLine(pen,
                            new Point(x, startPoint.Y),
                            new Point(x, startPoint.Y + tickLen2)); 

                        if (snapsToDevicePixels) 
                        { 
                            xLines.Add(x - 0.5);
                        } 
                    }
                }

                // Draw Selection Ticks 
                if (IsSelectionRangeEnabled)
                { 
                    double x0 = (SelectionStart - Minimum) * logicalToPhysical + startPoint.X; 
                    Point pt0 = new Point(x0, startPoint.Y);
                    Point pt1 = new Point(x0, startPoint.Y + tickLen2); 
                    Point pt2 = new Point(x0 + Math.Abs(tickLen2) * progression, startPoint.Y + tickLen2);

                    PathSegment[] segments = new PathSegment[] {
                        new LineSegment(pt2, true), 
                        new LineSegment(pt0, true),
                    }; 
                    PathGeometry geo = new PathGeometry(new PathFigure[] { new PathFigure(pt1, segments, true) }); 

                    dc.DrawGeometry(Fill, pen, geo); 

                    x0 = (SelectionEnd - Minimum) * logicalToPhysical + startPoint.X;
                    pt0 = new Point(x0, startPoint.Y);
                    pt1 = new Point(x0, startPoint.Y + tickLen2); 
                    pt2 = new Point(x0 - Math.Abs(tickLen2) * progression, startPoint.Y + tickLen2);
 
                    segments = new PathSegment[] { 
                        new LineSegment(pt2, true),
                        new LineSegment(pt0, true), 
                    };
                    geo = new PathGeometry(new PathFigure[] { new PathFigure(pt1, segments, true) });
                    dc.DrawGeometry(Fill, pen, geo);
                } 
            }
 
            if (snapsToDevicePixels) 
            {
                xLines.Add(ActualWidth); 
                yLines.Add(ActualHeight);
                VisualXSnappingGuidelines = xLines;
                VisualYSnappingGuidelines = yLines;
            } 
            return;
        } 
コード例 #21
0
        public object Convert( object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            Debug.Assert( values != null && values.Length == 9, "EdgeRouteToPathConverter should have 9 parameters: pos (1,2), size (3,4) of source; pos (5,6), size (7,8) of target; routeInformation (9)." );

            #region Get the inputs
            //get the position of the source
            Point sourcePos = new Point()
                              	{
                              		X = ( values[0] != DependencyProperty.UnsetValue ? (double)values[0] : 0.0 ),
                              		Y = ( values[1] != DependencyProperty.UnsetValue ? (double)values[1] : 0.0 )
                              	};
            //get the size of the source
            Size sourceSize = new Size()
                              	{
                              		Width = ( values[2] != DependencyProperty.UnsetValue ? (double)values[2] : 0.0 ),
                              		Height = ( values[3] != DependencyProperty.UnsetValue ? (double)values[3] : 0.0 )
                              	};
            //get the position of the target
            Point targetPos = new Point()
                              	{
                              		X = ( values[4] != DependencyProperty.UnsetValue ? (double)values[4] : 0.0 ),
                              		Y = ( values[5] != DependencyProperty.UnsetValue ? (double)values[5] : 0.0 )
                              	};
            //get the size of the target
            Size targetSize = new Size()
                              	{
                              		Width = ( values[6] != DependencyProperty.UnsetValue ? (double)values[6] : 0.0 ),
                              		Height = ( values[7] != DependencyProperty.UnsetValue ? (double)values[7] : 0.0 )
                              	};

            //get the route informations
            Point[] routeInformation = ( values[8] != DependencyProperty.UnsetValue ? (Point[])values[8] : null );
            #endregion
            bool hasRouteInfo = routeInformation != null && routeInformation.Length > 0;

            //
            // Create the path
            //
            Point p1 = GraphConverterHelper.CalculateAttachPoint( sourcePos, sourceSize, ( hasRouteInfo ? routeInformation[0] : targetPos ) );
            Point p2 = GraphConverterHelper.CalculateAttachPoint( targetPos, targetSize, ( hasRouteInfo ? routeInformation[routeInformation.Length - 1] : sourcePos ) );

            PathSegment[] segments = new PathSegment[1 + ( hasRouteInfo ? routeInformation.Length : 0 )];
            if ( hasRouteInfo )
                //append route points
                for ( int i = 0; i < routeInformation.Length; i++ )
                    segments[i] = new LineSegment( routeInformation[i], true );

            Point pLast = ( hasRouteInfo ? routeInformation[routeInformation.Length - 1] : p1 );
            Vector v = pLast - p2;
            v = v / v.Length * 5;
            Vector n = new Vector( -v.Y, v.X ) * 0.3;

            segments[segments.Length - 1] = new LineSegment( p2 + v, true );

            PathFigureCollection pfc = new PathFigureCollection( 2 );
            pfc.Add( new PathFigure( p1, segments, false ) );
            pfc.Add( new PathFigure( p2,
                                     new PathSegment[] {
                                                       	new LineSegment(p2 + v - n, true),
                                                       	new LineSegment(p2 + v + n, true)}, true ) );

            return pfc;
        }
コード例 #22
0
		void TestLineSegment (PathSegment segment, double x, double y, string message)
		{
			LineSegment ls = (LineSegment)segment;
			Assert.AreEqual (ls.Point, new Point (x, y), message + " 1");
			Assert.IsTrue (ls.IsStroked, message + " 2");
		}