public void Draw( EdgeLayout layoutState )
        {
            var styleState = myPresentation.GetPropertySetFor<EdgeStyle>().Get( Owner.Id );

            var stream = new StreamGeometry();
            var context = stream.Open();

            context.BeginFigure( layoutState.Points.First(), false, false );

            context.PolyBezierTo( layoutState.Points.Skip( 1 ).ToList(), true, false );

            // draw arrow head
            var start = layoutState.Points.Last();
            var v = start - layoutState.Points.ElementAt( layoutState.Points.Count() - 2 );
            v.Normalize();

            start = start - v * 0.15;
            context.BeginFigure( start + v * 0.28, true, true );
            double t = v.X; v.X = v.Y; v.Y = -t;  // Rotate 90°
            context.LineTo( start + v * 0.08, true, true );
            context.LineTo( start + v * -0.08, true, true );
            context.Close();

            var pen = new Pen( styleState.Color, 0.016 );

            // http://stackoverflow.com/questions/1755520/improve-drawingvisual-renders-speed
            Visual = new DrawingVisual();
            var dc = Visual.RenderOpen();
            dc.DrawGeometry( pen.Brush, pen, stream );
            dc.Close();

            Visual.SetValue( GraphItemProperty, Owner );
        }
        public void Draw( EdgeLayout layoutState )
        {
            var styleState = myPresentation.GetPropertySetFor<EdgeStyle>().Get( Owner.Id );
            var label = myPresentation.GetPropertySetFor<Caption>().Get( Owner.Id );

            var stream = new StreamGeometry();
            var context = stream.Open();

            context.BeginFigure( layoutState.Points.First(), false, false );

            context.PolyBezierTo( layoutState.Points.Skip( 1 ).ToList(), true, false );

            // draw arrow head
            var start = layoutState.Points.Last();
            var v = start - layoutState.Points.ElementAt( layoutState.Points.Count() - 2 );
            v.Normalize();

            start = start - v * 0.15;
            context.BeginFigure( start + v * 0.28, true, true );
            double t = v.X; v.X = v.Y; v.Y = -t;  // Rotate 90°
            context.LineTo( start + v * 0.08, true, true );
            context.LineTo( start + v * -0.08, true, true );
            context.Close();

            var pen = new Pen( styleState.Color, 0.016 );

            // http://stackoverflow.com/questions/1755520/improve-drawingvisual-renders-speed
            Visual = new DrawingVisual();
            var dc = Visual.RenderOpen();
            dc.DrawGeometry( pen.Brush, pen, stream );

            if( label.DisplayText != label.OwnerId )
            {
                var sourceLayoutState = myPresentation.GetModule<IGraphLayoutModule>().GetLayout( Owner.Source );
                
                var tx = new FormattedText( label.DisplayText,
                    CultureInfo.InvariantCulture,
                    FlowDirection.LeftToRight,
                    myFont,
                    sourceLayoutState.Height * 0.5, Brushes.Black );

                dc.DrawText( tx, new Point( layoutState.LabelPosition.X - tx.Width, layoutState.LabelPosition.Y - tx.Height ) );
            }

            dc.Close();

            Visual.SetValue( GraphItemProperty, Owner );
        }
        public EdgeLayout ReadEdgeLayout( string edgeId )
        {
            int pointCount = myReader.ReadInt();
            var points = new List<Point>();
            for( int i = 0; i < pointCount; ++i )
            {
                points.Add( ReadPoint() );
            }

            var layout = new EdgeLayout( edgeId );
            layout.Points = points;

            return layout;
        }
Exemple #4
0
        public void Add(EdgeLayout layout)
        {
            myEdgeLayouts.Add(layout.OwnerId, layout);

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, layout));
        }