/// <summary> /// エッジの矢印描画物作成。 /// </summary> private Polygon NewArrowPoly(WWVectorD2 pos1, WWVectorD2 pos2, Brush stroke) { var dir2to1N = WWVectorD2.Sub(pos1, pos2).Normalize(); var dir2to1S = dir2to1N.Scale(mDP.mArrowSz); // 2→1の方向と垂直のベクトル2つ。 var dirA = new WWVectorD2(-dir2to1N.Y, dir2to1N.X).Scale(mDP.mArrowSz * 0.5); var dirB = new WWVectorD2(dir2to1N.Y, -dir2to1N.X).Scale(mDP.mArrowSz * 0.5); var vecA = WWVectorD2.Add(dir2to1S, dirA); var vecB = WWVectorD2.Add(dir2to1S, dirB); var pos2a = WWVectorD2.Add(pos2, dir2to1N.Scale(mDP.mPointSz / 2)); var posA = WWVectorD2.Add(pos2a, vecA); var posB = WWVectorD2.Add(pos2a, vecB); var pc = new PointCollection(); pc.Add(new Point(posB.X, posB.Y)); pc.Add(new Point(pos2a.X, pos2a.Y)); pc.Add(new Point(posA.X, posA.Y)); var poly = new Polygon(); poly.Points = pc; poly.Fill = stroke; poly.StrokeThickness = 0; return(poly); }
/// <summary> /// エッジの描画物を作り、キャンバスに登録。 /// 描画物が無い状態で呼んで下さい。 /// </summary> public void EdgeDrawablesCreate(Edge edge, Brush brush) { System.Diagnostics.Debug.Assert(edge.line == null); System.Diagnostics.Debug.Assert(edge.arrow == null); var p1 = mPP.FindPointByIdx(edge.fromPointIdx, PointProc.FindPointMode.FindAll); var p2 = mPP.FindPointByIdx(edge.toPointIdx, PointProc.FindPointMode.FindAll); edge.line = DrawUtil.NewLine(p1.xy, p2.xy, brush); edge.arrow = NewArrowPoly(p1.xy, p2.xy, brush); Canvas.SetZIndex(edge.line, mDP.Z_Edge); Canvas.SetZIndex(edge.arrow, mDP.Z_Edge); mDP.mCanvas.Children.Add(edge.line); mDP.mCanvas.Children.Add(edge.arrow); // 文字を出す。 var xy = WWVectorD2.Add(p1.xy, p2.xy).Scale(0.5); edge.tbIdx = new TextBlock(); edge.tbIdx.Padding = new Thickness(2); edge.tbIdx.Text = EdgeDescriptionText(edge.EdgeIdx, edge.C, edge.B); edge.tbIdx.Foreground = mDP.mEdgeTextFgBrush; edge.tbIdx.Background = mDP.mEdgeTextBgBrush; edge.tbIdx.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var tbWH = edge.tbIdx.DesiredSize; Canvas.SetLeft(edge.tbIdx, xy.X - tbWH.Width / 2); Canvas.SetTop(edge.tbIdx, xy.Y - tbWH.Height / 2); Canvas.SetZIndex(edge.tbIdx, mDP.Z_Edge + 1); mDP.mCanvas.Children.Add(edge.tbIdx); }
/// <summary> /// エッジの係数が変更された。 /// </summary> public void EdgeParamChanged(Edge edge, double newC, double newB) { edge.tbIdx.Text = EdgeDescriptionText(edge.EdgeIdx, newC, newB); // 表示位置を調整する。 var p1 = mPP.FindPointByIdx(edge.fromPointIdx, PointProc.FindPointMode.FindAll); var p2 = mPP.FindPointByIdx(edge.toPointIdx, PointProc.FindPointMode.FindAll); var xy = WWVectorD2.Add(p1.xy, p2.xy).Scale(0.5); edge.tbIdx.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var tbWH = edge.tbIdx.DesiredSize; Canvas.SetLeft(edge.tbIdx, xy.X - tbWH.Width / 2); Canvas.SetTop(edge.tbIdx, xy.Y - tbWH.Height / 2); }