Ejemplo n.º 1
0
        /// <summary>
        /// Returns a Windows Media Path Geometry from a Rhinocommon Arc
        /// </summary>
        /// <param name="input">Rhinocommon Arc</param>
        /// <returns>System Windows Media Path Geometry</returns>
        public static Sm.PathGeometry ToGeometry(this Rg.Arc input)
        {
            Sm.ArcSegment            arc               = new Sm.ArcSegment();
            Sm.PathFigure            figure            = new Sm.PathFigure();
            Sm.PathGeometry          geometry          = new Sm.PathGeometry();
            Sm.PathFigureCollection  figureCollection  = new Sm.PathFigureCollection();
            Sm.PathSegmentCollection segmentCollection = new Sm.PathSegmentCollection();

            figure.StartPoint = input.StartPoint.ToWindowsPoint();

            arc.Point = input.EndPoint.ToWindowsPoint();
            arc.Size  = new Sw.Size(input.Radius, input.Radius);
            if (Rg.Vector3d.VectorAngle(input.Plane.Normal, Rg.Vector3d.ZAxis) > 0)
            {
                arc.SweepDirection = Sm.SweepDirection.Counterclockwise;
            }
            else
            {
                arc.SweepDirection = Sm.SweepDirection.Clockwise;
            }
            arc.IsLargeArc = (input.Angle > Math.PI);

            segmentCollection.Add(arc);
            figure.Segments = segmentCollection;
            figureCollection.Add(figure);
            geometry.Figures = figureCollection;

            return(geometry);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a string representation of this object based on the format string
        /// and IFormatProvider passed in.
        /// If the provider is null, the CurrentCulture is used.
        /// See the documentation for IFormattable for more information.
        /// </summary>
        /// <returns>
        /// A string representation of this object.
        /// </returns>
        internal string ConvertToString(string format, IFormatProvider provider)
        {
            PathSegmentCollection segments = Segments;

            return("M" +
                   ((IFormattable)StartPoint).ToString(format, provider) +
                   (segments != null ? segments.ConvertToString(format, provider) : "") +
                   (IsClosed ? "z" : ""));
        }
Ejemplo n.º 3
0
            internal Enumerator(PathSegmentCollection list)
            {
                Debug.Assert(list != null, "list may not be null.");

                _list    = list;
                _version = list._version;
                _index   = -1;
                _current = default(PathSegment);
            }
Ejemplo n.º 4
0
        internal override void SetSegmentCount(int segmentCount)
        {
            Debug.Assert(_figures != null, "It is illegal to call SetSegmentCount before BeginFigure.");
            Debug.Assert(_currentFigure != null, "It is illegal to call SetSegmentCount before BeginFigure.");
            Debug.Assert(_segments == null, "It is illegal to call SetSegmentCount multiple times per BeginFigure or after a *To method.");
            Debug.Assert(segmentCount > 0);

            _segments = new PathSegmentCollection(segmentCount);
            _currentFigure.Segments = _segments;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// ArcTo - append an ArcTo to the current figure.
        /// </summary>
        public override void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked, bool isSmoothJoin)
        {
            Debug.Assert(_figures != null);
            Debug.Assert(_currentFigure != null);

            FinishSegment();

            // Is this the first segment?
            if (_segments == null)
            {
                // While we could always just retrieve _currentFigure.Segments (which would auto-promote)
                // it's more efficient to create the collection ourselves and set it explicitly.

                _segments = new PathSegmentCollection();
                _currentFigure.Segments = _segments;
            }

            ArcSegment segment = new ArcSegment();

            segment.Point = point;
            segment.Size  = size;

            if (isLargeArc != s_defaultValueForArcSegmentIsLargeArc)
            {
                segment.IsLargeArc = isLargeArc;
            }

            if (sweepDirection != s_defaultValueForArcSegmentSweepDirection)
            {
                segment.SweepDirection = sweepDirection;
            }

            if (rotationAngle != s_defaultValueForArcSegmentRotationAngle)
            {
                segment.RotationAngle = rotationAngle;
            }

            // Handle common PathSegment properties.
            if (isStroked != s_defaultValueForPathSegmentIsStroked)
            {
                segment.IsStroked = isStroked;
            }

            if (isSmoothJoin != s_defaultValueForPathSegmentIsSmoothJoin)
            {
                segment.IsSmoothJoin = isSmoothJoin;
            }

            _segments.Add(segment);

            _currentSegmentType = MIL_SEGMENT_TYPE.MilSegmentArc;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// SerializeData - Serialize the contents of this Figure to the provided context.
        /// </summary>
        internal void SerializeData(StreamGeometryContext ctx)
        {
            ctx.BeginFigure(StartPoint, IsFilled, IsClosed);

            PathSegmentCollection segments = Segments;

            int pathSegmentCount = segments == null ? 0 : segments.Count;

            for (int i = 0; i < pathSegmentCount; i++)
            {
                segments.Internal_GetItem(i).SerializeData(ctx);
            }
        }
Ejemplo n.º 7
0
        public static PathFigure GetPathFigureFromPoint(IEnumerable <Point> linePoints)
        {
            var pf = new PathFigure();

            System.Windows.Media.PathSegmentCollection ls = new System.Windows.Media.PathSegmentCollection();
            var start = linePoints.First();

            foreach (var p in linePoints.Skip(1))
            {
                ls.Add(new System.Windows.Media.LineSegment(p, true));
            }
            pf.StartPoint = start;
            pf.Segments   = ls;
            return(pf);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Implementation of Freezable.GetCurrentValueAsFrozenCore()
        /// </summary>
        protected override void GetCurrentValueAsFrozenCore(Freezable source)
        {
            PathSegmentCollection sourcePathSegmentCollection = (PathSegmentCollection)source;

            base.GetCurrentValueAsFrozenCore(source);

            int count = sourcePathSegmentCollection._collection.Count;

            _collection = new FrugalStructList <PathSegment>(count);

            for (int i = 0; i < count; i++)
            {
                PathSegment newValue = (PathSegment)sourcePathSegmentCollection._collection[i].GetCurrentValueAsFrozen();
                OnFreezablePropertyChanged(/* oldValue = */ null, newValue);
                _collection.Add(newValue);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="start">The path's startpoint</param>
        /// <param name="segments">A collection of segments</param>
        /// <param name="closed">Indicates whether the figure is closed</param>
        public PathFigure(Point start, IEnumerable <PathSegment> segments, bool closed)
        {
            StartPoint = start;
            PathSegmentCollection mySegments = Segments;

            if (segments != null)
            {
                foreach (PathSegment item in segments)
                {
                    mySegments.Add(item);
                }
            }
            else
            {
                throw new ArgumentNullException("segments");
            }

            IsClosed = closed;
        }
Ejemplo n.º 10
0
        public static PathFigure GetPathFigureFromPoints(IEnumerable <Point> linePoints)
        {
            var pf = new PathFigure();

            System.Windows.Media.PathSegmentCollection ls = new System.Windows.Media.PathSegmentCollection();
            var start = linePoints.First();

            {
                foreach (var p in linePoints.Skip(1))
                {
                    var lineSegement = new System.Windows.Media.LineSegment(p, true);
                    ls.Add(lineSegement);
                }
            }
            pf.StartPoint = start;
            pf.Segments   = ls;
            pf.IsClosed   = false;
            pf.IsFilled   = false;
            return(pf);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns a Windows Media Path Geometry from a Rhinocommon Polyline
        /// </summary>
        /// <param name="input">Rhinocommon Polyline</param>
        /// <returns>System Windows Media Path Geometry</returns>
        public static Sm.PathGeometry ToGeometry(this Rg.Polyline input)
        {
            Sm.PathFigure            figure            = new Sm.PathFigure();
            Sm.PathGeometry          geometry          = new Sm.PathGeometry();
            Sm.PathFigureCollection  figureCollection  = new Sm.PathFigureCollection();
            Sm.PathSegmentCollection segmentCollection = new Sm.PathSegmentCollection();

            figure.StartPoint = input[0].ToWindowsPoint();
            for (int i = 1; i < input.Count; i++)
            {
                Sm.LineSegment line = new Sm.LineSegment(input[i].ToWindowsPoint(), true);
                segmentCollection.Add(line);
            }

            figure.Segments = segmentCollection;
            figureCollection.Add(figure);
            geometry.Figures = figureCollection;

            return(geometry);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns true if this geometry may have curved segments
        /// </summary>
        public bool MayHaveCurves()
        {
            PathSegmentCollection segments = Segments;

            if (segments == null)
            {
                return(false);
            }

            int count = segments.Count;

            for (int i = 0; i < count; i++)
            {
                if (segments.Internal_GetItem(i).IsCurved())
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 13
0
        void ComputeConnectorLine()
        {
            _myPath.Clear();
            if (_model.StartPointDocking == ConnectorDocking.Undefined)
            {
                _start = _model.From.GetPreferredConnectorStart(_start, out double relPos1, out ConnectorDocking docking1, out ulong _1);
                _model.StartPointDocking          = docking1;
                _model.StartPointRelativePosition = relPos1;
            }
            else
            {
                _start = _model.From.GetConnectorPoint(_model.StartPointDocking, _model.StartPointRelativePosition, 0);
            }

            if (_model.EndPointDocking == ConnectorDocking.Undefined)
            {
                _end = _model.To.GetPreferredConnectorEnd(_end, out double relPos2, out ConnectorDocking docking2, out ulong _1);
                _model.EndPointDocking          = docking2;
                _model.EndPointRelativePosition = relPos2;
            }
            else
            {
                _end = _model.To.GetConnectorPoint(_model.EndPointDocking, _model.EndPointRelativePosition, 0);
            }

            System.Windows.Media.PathSegmentCollection ls = new System.Windows.Media.PathSegmentCollection()
            {
                new System.Windows.Media.LineSegment(_end, true)
            };

            var pf = new System.Windows.Media.PathFigure()
            {
                StartPoint = _start,
                Segments   = ls
            };

            _myPath.Add(pf);
        }
Ejemplo n.º 14
0
        internal PathFigure GetTransformedCopy(Matrix matrix)
        {
            PathSegmentCollection segments = Segments;

            PathFigure result  = new PathFigure();
            Point      current = StartPoint;

            result.StartPoint = current * matrix;

            if (segments != null)
            {
                int count = segments.Count;
                for (int i = 0; i < count; i++)
                {
                    segments.Internal_GetItem(i).AddToFigure(matrix, result, ref current);
                }
            }

            result.IsClosed = IsClosed;
            result.IsFilled = IsFilled;

            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns a Windows Media Bezier Spline Path Geometry from a Rhinocommon Curve
        /// </summary>
        /// <param name="input">Rhinocommon Curve</param>
        /// <returns>System Windows Media Bezier Curve Path Geometry </returns>
        public static Sm.PathGeometry ToGeometry(this Rg.Curve input)
        {
            Rg.NurbsCurve nurbsCurve = input.ToNurbsCurve();
            nurbsCurve.MakePiecewiseBezier(true);
            Rg.BezierCurve[] bezier = Rg.BezierCurve.CreateCubicBeziers(nurbsCurve, 0, 0);

            Sm.PathFigure            figure            = new Sm.PathFigure();
            Sm.PathGeometry          geometry          = new Sm.PathGeometry();
            Sm.PathFigureCollection  figureCollection  = new Sm.PathFigureCollection();
            Sm.PathSegmentCollection segmentCollection = new Sm.PathSegmentCollection();

            figure.StartPoint = bezier[0].GetControlVertex3d(0).ToWindowsPoint();
            for (int i = 0; i < bezier.Count(); i++)
            {
                Sm.BezierSegment segment = new Sm.BezierSegment(bezier[i].GetControlVertex3d(1).ToWindowsPoint(), bezier[i].GetControlVertex3d(2).ToWindowsPoint(), bezier[i].GetControlVertex3d(3).ToWindowsPoint(), true);
                segmentCollection.Add(segment);
            }

            figure.Segments = segmentCollection;
            figureCollection.Add(figure);
            geometry.Figures = figureCollection;

            return(geometry);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Equilateral triangle of side 'sideLength', centered on the same point as if a circle of diameter 'sideLength' was there
        /// </summary>
        private static XamlMedia.PathGeometry CreateTriangle(double sideLength)
        {
            var altitude     = Math.Sqrt(3) / 2.0 * sideLength;
            var inradius     = altitude / 3.0;
            var circumradius = 2.0 * inradius;

            var top   = new XamlPoint(0, -circumradius);
            var left  = new XamlPoint(sideLength * -0.5, inradius);
            var right = new XamlPoint(sideLength * 0.5, inradius);

            var segments = new XamlMedia.PathSegmentCollection();

            segments.Add(new XamlMedia.LineSegment(left, true));
            segments.Add(new XamlMedia.LineSegment(right, true));
            var figure  = new XamlMedia.PathFigure(top, segments, true);
            var figures = new XamlMedia.PathFigureCollection();

            figures.Add(figure);

            return(new XamlMedia.PathGeometry
            {
                Figures = figures
            });
        }
Ejemplo n.º 17
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.router1 = ((System.Windows.Controls.Image)(target));
     return;
     case 2:
     this.router2 = ((System.Windows.Controls.Image)(target));
     return;
     case 3:
     this.router7 = ((System.Windows.Controls.Image)(target));
     return;
     case 4:
     this.router5 = ((System.Windows.Controls.Image)(target));
     return;
     case 5:
     this.router3 = ((System.Windows.Controls.Image)(target));
     return;
     case 6:
     this.router6 = ((System.Windows.Controls.Image)(target));
     return;
     case 7:
     this.router4 = ((System.Windows.Controls.Image)(target));
     return;
     case 8:
     this.router8 = ((System.Windows.Controls.Image)(target));
     return;
     case 9:
     this.sourceComputer = ((System.Windows.Controls.Image)(target));
     return;
     case 10:
     this.sourceComputer_Copy = ((System.Windows.Controls.Image)(target));
     return;
     case 11:
     this.weightR1R7Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 12:
     this.weightR1R2Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 13:
     this.weightR2R3Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 14:
     this.weightR5R6Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 15:
     this.weightR2R5Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 16:
     this.weightR5R7Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 17:
     this.weightR7R8Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 18:
     this.weightR3R6Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 19:
     this.weightR6R8Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 20:
     this.weightR3R4Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 21:
     this.weightR4R8Red = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 22:
     this.btnStart = ((System.Windows.Controls.Button)(target));
     
     #line 2239 "..\..\MainWindow.xaml"
     this.btnStart.Click += new System.Windows.RoutedEventHandler(this.Button_Click_1);
     
     #line default
     #line hidden
     return;
     case 23:
     this.txtShortestPathRed = ((System.Windows.Controls.TextBox)(target));
     return;
     case 24:
     this.txtDistanceRed = ((System.Windows.Controls.TextBox)(target));
     return;
     case 25:
     this.RedEllipse = ((System.Windows.Shapes.Ellipse)(target));
     return;
     case 26:
     this.BlueEllipse = ((System.Windows.Shapes.Ellipse)(target));
     return;
     case 27:
     this.txtShortestPathBlue = ((System.Windows.Controls.TextBox)(target));
     return;
     case 28:
     this.txtDistanceBlue = ((System.Windows.Controls.TextBox)(target));
     return;
     case 29:
     this.txtWinner = ((System.Windows.Controls.TextBox)(target));
     return;
     case 30:
     this.txtInput1 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 31:
     this.txtInput2 = ((System.Windows.Controls.TextBox)(target));
     return;
     case 32:
     this.weightR1R2Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 33:
     this.weightR1R7Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 34:
     this.weightR5R7Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 35:
     this.weightR2R5Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 36:
     this.weightR2R3Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 37:
     this.weightR5R6Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 38:
     this.weightR7R8Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 39:
     this.weightR3R6Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 40:
     this.weightR6R8Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 41:
     this.weightR4R8Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 42:
     this.weightR3R4Blue = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 43:
     this.sineCanvasScrollViewerRed = ((System.Windows.Controls.ScrollViewer)(target));
     return;
     case 44:
     this.sineCanvasRed = ((System.Windows.Controls.Canvas)(target));
     return;
     case 45:
     this.sineWaveRed = ((System.Windows.Shapes.Path)(target));
     return;
     case 46:
     this.pathCollectionRed = ((System.Windows.Media.PathSegmentCollection)(target));
     return;
     case 47:
     this.sineCanvasScrollViewerBlue = ((System.Windows.Controls.ScrollViewer)(target));
     return;
     case 48:
     this.sineCanvasBlue = ((System.Windows.Controls.Canvas)(target));
     return;
     case 49:
     this.sineWaveBlue = ((System.Windows.Shapes.Path)(target));
     return;
     case 50:
     this.pathCollectionBlue = ((System.Windows.Media.PathSegmentCollection)(target));
     return;
     case 51:
     this.frameTextBlockRed = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 52:
     this.frameTextBlockBlue = ((System.Windows.Controls.TextBlock)(target));
     return;
     }
     this._contentLoaded = true;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// FinishSegment - called to completed any outstanding Segment which may be present.
        /// </summary>
        private void FinishSegment()
        {
            if (_currentSegmentPoints != null)
            {
                Debug.Assert(_currentFigure != null);

                int count = _currentSegmentPoints.Count;

                Debug.Assert(count > 0);

                // Is this the first segment?
                if (_segments == null)
                {
                    // While we could always just retrieve _currentFigure.Segments (which would auto-promote)
                    // it's more efficient to create the collection ourselves and set it explicitly.

                    _segments = new PathSegmentCollection();
                    _currentFigure.Segments = _segments;
                }

                PathSegment segment;

                switch (_currentSegmentType)
                {
                case MIL_SEGMENT_TYPE.MilSegmentPolyLine:
                    if (count == 1)
                    {
                        LineSegment lSegment = new LineSegment();
                        lSegment.Point = _currentSegmentPoints[0];
                        segment        = lSegment;
                    }
                    else
                    {
                        PolyLineSegment pSegment = new PolyLineSegment();
                        pSegment.Points = _currentSegmentPoints;
                        segment         = pSegment;
                    }
                    break;

                case MIL_SEGMENT_TYPE.MilSegmentPolyBezier:
                    if (count == 3)
                    {
                        BezierSegment bSegment = new BezierSegment();
                        bSegment.Point1 = _currentSegmentPoints[0];
                        bSegment.Point2 = _currentSegmentPoints[1];
                        bSegment.Point3 = _currentSegmentPoints[2];
                        segment         = bSegment;
                    }
                    else
                    {
                        Debug.Assert(count % 3 == 0);

                        PolyBezierSegment pSegment = new PolyBezierSegment();
                        pSegment.Points = _currentSegmentPoints;
                        segment         = pSegment;
                    }
                    break;

                case MIL_SEGMENT_TYPE.MilSegmentPolyQuadraticBezier:
                    if (count == 2)
                    {
                        QuadraticBezierSegment qSegment = new QuadraticBezierSegment();
                        qSegment.Point1 = _currentSegmentPoints[0];
                        qSegment.Point2 = _currentSegmentPoints[1];
                        segment         = qSegment;
                    }
                    else
                    {
                        Debug.Assert(count % 2 == 0);

                        PolyQuadraticBezierSegment pSegment = new PolyQuadraticBezierSegment();
                        pSegment.Points = _currentSegmentPoints;
                        segment         = pSegment;
                    }
                    break;

                default:
                    segment = null;
                    Debug.Assert(false);
                    break;
                }

                // Handle common PathSegment properties.
                if (_currentSegmentIsStroked != s_defaultValueForPathSegmentIsStroked)
                {
                    segment.IsStroked = _currentSegmentIsStroked;
                }

                if (_currentSegmentIsSmoothJoin != s_defaultValueForPathSegmentIsSmoothJoin)
                {
                    segment.IsSmoothJoin = _currentSegmentIsSmoothJoin;
                }

                _segments.Add(segment);

                _currentSegmentPoints = null;
                _currentSegmentType   = MIL_SEGMENT_TYPE.MilSegmentNone;
            }
        }
Ejemplo n.º 19
0
 public PathFigure(Point startPoint, IEnumerable <PathSegment> segments, Boolean isClosed)
 {
     StartPoint = startPoint;
     Segments   = new PathSegmentCollection(segments);
     IsClosed   = isClosed;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Can serialze "this" to a string.
        /// This returns true iff IsFilled == c_isFilled and the segment
        /// collection can be stroked.
        /// </summary>
        internal bool CanSerializeToString()
        {
            PathSegmentCollection segments = Segments;

            return((IsFilled == c_IsFilled) && ((segments == null) || segments.CanSerializeToString()));
        }