Example #1
0
 private static void UpdateMainLinePos(EdgeDisplay display)
 {
     if (display.NegGradient)
     {
         display.edgeLine.X1 = display.XDiff;
         display.edgeLine.X2 = 0.0;
         display.edgeLine.Y1 = 0.0;
         display.edgeLine.Y2 = display.YDiff;
     }
     else
     {
         display.edgeLine.X1 = 0.0;
         display.edgeLine.X2 = display.XDiff;
         display.edgeLine.Y1 = 0.0;
         display.edgeLine.Y2 = display.YDiff;
     }
 }
 private void OnMeshChanged(Mesh newMesh)
 {
     markedEdges.Clear();
     undoTree = new UndoTree();
     if (double.IsNaN(this.ActualHeight) || double.IsNaN(this.ActualWidth))
         return;
     UpdateScaleFactor(newMesh, new Size(this.ActualWidth, this.ActualHeight));
       //          RectangleGeometry rectGeo = new RectangleGeometry();
     //        rectGeo.Rect = new Rect(0.0, 0.0, this.ActualWidth, this.ActualHeight);
       //      this.Clip = rectGeo;
     this.Children.Clear();
     if (newMesh == null)
         return;
     for (int i = 0; i < newMesh.Edges.Count; i++)
     {
         Edge edge = newMesh.Edges[i];
         float x1,x2,y1,y2;
         newMesh.GetEdgeExtent(edge, out x1, out y1, out x2, out y2);
         EdgeDisplay edgeDisplay = new EdgeDisplay();
         edgeDisplay.XDiff = Math.Abs(x2 - x1)*scaleFactor;
         edgeDisplay.Width = edgeDisplay.XDiff + 1;
         edgeDisplay.YDiff = Math.Abs(y2 - y1) * scaleFactor;
         edgeDisplay.Height = edgeDisplay.YDiff + 1;
         edgeDisplay.EdgeState = edge.State;
         edgeDisplay.EdgeColor = edge.Color;
         edgeDisplay.Marked = markedEdges.Contains(i);
         edgeDisplay.NegGradient = x1 == x2 ? false : (y2 - y1) / (x2 - x1) < 0;
         edgeDisplay.SetValue(Canvas.TopProperty, Math.Min(y2, y1) * scaleFactor + yOffset);
         edgeDisplay.SetValue(Canvas.LeftProperty, Math.Min(x2, x1) * scaleFactor + xOffset);
         this.Children.Add(edgeDisplay);
     }
     for (int i = 0; i < newMesh.Intersections.Count; i++)
     {
         Intersection inters = newMesh.Intersections[i];
         Ellipse ellipse = new Ellipse();
         ellipse.Width = 4;
         ellipse.Height = 4;
         ellipse.SetValue(Canvas.TopProperty, inters.Y * scaleFactor + yOffset - ellipse.Height / 2.0);
         ellipse.SetValue(Canvas.LeftProperty, inters.X * scaleFactor + xOffset - ellipse.Width / 2.0);
         ellipse.Stroke = new SolidColorBrush(Colors.Black);
         ellipse.Fill = new SolidColorBrush(Colors.Black);
         ellipse.StrokeThickness = 1.0;
         this.Children.Add(ellipse);
     }
     for (int i = 0; i < newMesh.Cells.Count; i++)
     {
         Cell cell = newMesh.Cells[i];
         CellDisplay cellDisplay = new CellDisplay();
         PointCollection points = new PointCollection();
         for (int j = 0; j < cell.Intersections.Count; j++)
         {
             Intersection inters = newMesh.Intersections[cell.Intersections[j]];
             points.Add(new Point(inters.X * scaleFactor + xOffset, inters.Y * scaleFactor + yOffset));
         }
         cellDisplay.Points = points;
         cellDisplay.FontFamily = new FontFamily("Tahoma");
         cellDisplay.FontSize = 18;
         cellDisplay.CellColor = cell.Color;
         cellDisplay.TargetCount = cell.TargetCount;
         cellDisplay.Width = scaleFactor;
         cellDisplay.Height = scaleFactor;
         this.Children.Add(cellDisplay);
     }
 }