/// <summary> /// Draw the given problem to the drawing. /// </summary> /// <param name="problem">The problem to draw.</param> public void draw(UIProblemDrawer.ProblemDescription problem) { // Reset to create the dictionaries. reset(); //Draw the hard-coded problem. try { drawPoints(problem); drawSegments(problem); drawCircles(problem); shadeProblem(problem); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine(e.Message + " " + e.StackTrace); } }
/// <summary> /// Async invocation of draw on the UI thread. /// </summary> /// <param name="desc">The problem to draw.</param> public void invokeDraw(UIProblemDrawer.ProblemDescription desc) { SmartDispatcher.BeginInvoke(() => draw(desc)); }
/// <summary> /// If the problem is a shaded area problem, shade the goal regions. /// </summary> /// <param name="problem">The problem being drawn.</param> private void shadeProblem(UIProblemDrawer.ProblemDescription problem) { if (problem.Regions != null) { //Shade each region foreach (var region in problem.Regions) { ShadedRegion sr = new ShadedRegion(region); sr.Draw(drawingHost.CurrentDrawing, ShadedRegion.BRUSHES[1]); } } }
/// <summary> /// Draw each segment in the problem and save it to the lookup dictionary. /// </summary> /// <param name="problem">The problem being drawn.</param> private void drawSegments(UIProblemDrawer.ProblemDescription problem) { //Add each segment to the drawing foreach (var seg in problem.Segments) { if (seg != null) { //Look already drawn points var pt1 = points[seg.Point1]; var pt2 = points[seg.Point2]; //Create and add the segment var segment = Factory.CreateSegment(drawingHost.CurrentDrawing, pt1, pt2); Actions.Add(drawingHost.CurrentDrawing, segment); //Save to lookup dictionary segments.Add(seg, segment); } } }
/// <summary> /// Draw each point in the problem and save it to the lookup dictionary. /// </summary> /// <param name="problem">The problem being drawn.</param> private void drawPoints(UIProblemDrawer.ProblemDescription problem) { //Add each point to the drawing foreach (var pt in problem.Points) { //Create and add the point var point = Factory.CreateFreePoint(drawingHost.CurrentDrawing, new System.Windows.Point(pt.X, pt.Y)); point.Name = pt.name; Actions.Add(drawingHost.CurrentDrawing, point); //Save to lookup dictionary points.Add(pt, point); } }
/// <summary> /// Draw each circle in the problem and save it to the lookup dictionary. /// Circles in LiveGeometry need two points. We have the center, but may need a point on the circle itself. /// If a point exists on the circle we will use that, if not a point will be created on the circle to the direct /// right of the center. /// </summary> /// <param name="problem">The problem being drawn.</param> private void drawCircles(UIProblemDrawer.ProblemDescription problem) { //Add circles to the drawing foreach (var circ in problem.Circles) { //Lookup center point var center = points[circ.center]; IPoint pointOnCircle; if (circ.pointsOnCircle.Count > 0) //Point on circle exists { pointOnCircle = points[circ.pointsOnCircle[0]]; } else //Does not exist, we need to make one { pointOnCircle = Factory.CreateFreePoint( drawingHost.CurrentDrawing, new System.Windows.Point(circ.center.X + circ.radius, circ.center.Y)); } //Create circle and add to drawing IPoint[] dependencies = { center, pointOnCircle }; Circle circle = Factory.CreateCircle(drawingHost.CurrentDrawing, new List<IFigure>(dependencies)); Actions.Add(drawingHost.CurrentDrawing, circle); //Save to lookup dictionary circles.Add(circ, circle); } }
/// <summary> /// Create the UIProblemDrawer. /// This method should only be called once, and should be called before any call to getInstance(). /// </summary> /// <param name="draw">The Action that handles a UI draw.</param> /// <param name="clear">The Action that handles a UI clear.</param> /// <param name="reset">The Action that handles a ProblemDrawer reset.</param> public static void create(Action<ProblemDescription> draw, Action clear, Action reset) { Debug.Assert(instance == null, "create() should only be called once."); instance = new UIProblemDrawer(draw, clear, reset); }
/// <summary> /// Create the UIProblemDrawer. /// This method should only be called once, and should be called before any call to getInstance(). /// </summary> /// <param name="draw">The Action that handles a UI draw.</param> /// <param name="clear">The Action that handles a UI clear.</param> /// <param name="reset">The Action that handles a ProblemDrawer reset.</param> public static void create(Action <ProblemDescription> draw, Action clear, Action reset) { Debug.Assert(instance == null, "create() should only be called once."); instance = new UIProblemDrawer(draw, clear, reset); }