Exemplo n.º 1
0
 public override Line2DBase Cut(float x, bool cutRight)
 {
     if (this.IsVertical || !this.ContainsAbsciss(x))
     {
         return null;
     }
     Line2DBase cutLine = null;
     PointF cutPoint = new PointF(x, this.ValueAtX(x));
     if (cutPoint == this.Point1) { return null; } // Don't create an empty segment
     if (this.VX > 0) // HalfLine is infinite on the right
     {
         if (cutRight)
         {
             cutLine = new Segment2D(this.Point1, cutPoint, this.Pen);
         }
         else
         {
             cutLine = new HalfLine2D(cutPoint, this.VX, this.VY, this.Pen);
         }
     }
     else // HalfLine is infinite on the left
     {
         if (cutRight)
         {
             cutLine = new HalfLine2D(cutPoint, this.VX, this.VY, this.Pen);
         }
         else
         {
             cutLine = new Segment2D(this.Point1, cutPoint, this.Pen);
         }
     }
     cutLine.Pen = this.Pen;
     return cutLine;
 }
Exemplo n.º 2
0
 public override Line2DBase Cut(float x, bool cutRight)
 {
     if (this.IsVertical)
     {
         return null;
     }
     HalfLine2D cutLine = null;
     PointF cutPoint = new PointF(x, this.ValueAtX(x));
     if (this.VX > 0 && cutRight)
     {
         cutLine = new HalfLine2D(cutPoint, -this.VX, -this.VY, this.Pen);
     }
     else
     {
         cutLine = new HalfLine2D(cutPoint, this.VX, this.VY, this.Pen);
     }
     cutLine.Pen = this.Pen;
     return cutLine;
 }
Exemplo n.º 3
0
        public List<Line2DBase> GetLines(Pen pen)
        {
            List<Line2DBase> lines = new List<Line2DBase>();

             if (this.Point1 == PointF.Empty || this.Point2 == PointF.Empty || this.Point3 == PointF.Empty)
             {
            return null;
             }
             // Calculate projected line
             Segment2D segment2D = new Segment2D(this.Point2, this.Point3);

             PointF endPoint = new PointF(this.Point3.X + segment2D.VX, this.Point3.Y + segment2D.VY);

             Line2DBase medianLine = new HalfLine2D(this.Point1, this.Point3, pen);
             lines.Add(medianLine);

             // Calculate channel lines.
             lines.Add(new HalfLine2D(this.Point2, medianLine.VX, medianLine.VY, pen));
             lines.Add(new HalfLine2D(endPoint, medianLine.VX, medianLine.VY, pen));
             lines.Add(new Segment2D(this.Point2, endPoint, pen));

             return lines;
        }
Exemplo n.º 4
0
 protected void DrawTmpHalfLine(Graphics graph, Pen pen, PointF point1, PointF point2, bool useTransform, bool temporary)
 {
     // Calculate intersection with bounding rectangle
      Rectangle2D rect2D = new Rectangle2D(GraphRectangle);
      HalfLine2D newLine = new HalfLine2D(point1, point2);
      if (useTransform)
      {
     newLine.Draw(graph, pen, this.matrixValueToScreen, rect2D, this.IsLogScale);
      }
      else
      {
     newLine.Draw(graph, pen, GraphControl.matrixIdentity, rect2D, false);
      }
 }
Exemplo n.º 5
0
 public PointF Intersection(HalfLine2D line)
 {
     float k;
     k = line.VX * VY - line.VY * VX;
     if (k == 0) return PointF.Empty;
     k = (VY * (Point1.X - line.Point1.X) + VX * (line.Point1.Y - Point1.Y)) / k;
     PointF intersectionPoint = new PointF(line.Point1.X + k * line.VX, line.Point1.Y + k * line.VY);
     if (line.ContainsAbsciss(intersectionPoint.X) && new Rectangle2D(this.Point1, this.Point2).Contains(intersectionPoint))
     {
         return intersectionPoint;
     }
     else
     {
         return PointF.Empty;
     }
 }
Exemplo n.º 6
0
 private void MouseClickDrawing(System.Windows.Forms.MouseEventArgs e, ref PointF mousePoint, ref PointF mouseValuePoint)
 {
     switch (this.DrawingMode)
     {
         case GraphDrawMode.AddLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         Line2D newLine = new Line2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.AddSegment:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         Segment2D newSegment = new Segment2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newSegment);
                         AddToUndoBuffer(GraphActionType.AddItem, newSegment);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.AddHalfLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         HalfLine2D newhalfLine = new HalfLine2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newhalfLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newhalfLine);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.FanLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         Line2D newLine = (Line2D)new Line2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.AndrewPitchFork:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     if (andrewPitchFork == null)
                     {
                         andrewPitchFork = new AndrewPitchFork(mouseValuePoint, PointF.Empty, PointF.Empty);
                     }
                     else
                     {
                         // Selecting second point
                         andrewPitchFork.Point2 = mouseValuePoint;
                         this.DrawingStep = GraphDrawingStep.ItemSelected;
                     }
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting third point
                     andrewPitchFork.Point3 = mouseValuePoint;
                     try
                     {
                         foreach (Line2DBase newLine in andrewPitchFork.GetLines(this.DrawingPen))
                         {
                             drawingItems.Add(newLine);
                             AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         }
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         andrewPitchFork = null;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.CopyLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Select the line to copy
                     selectedLineIndex = FindClosestLine(mousePoint);
                     if (selectedLineIndex != -1)
                     {
                         this.DrawingStep = GraphDrawingStep.ItemSelected;
                     }
                     break;
                 case GraphDrawingStep.ItemSelected: // Create new // line
                     if (selectedLineIndex != -1)
                     {
                         Line2D newLine = ((Line2DBase)this.drawingItems[selectedLineIndex]).GetParallelLine(mouseValuePoint);
                         newLine.Pen = this.DrawingPen;
                         drawingItems.Add(newLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         selectedLineIndex = -1;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         HighlightClosestLine(e);
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.DeleteItem:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Delete element
                     selectedLineIndex = FindClosestLine(mousePoint);
                     if (selectedLineIndex != -1)
                     {
                         DrawingItem removeLine = this.drawingItems.ElementAt(selectedLineIndex);
                         this.drawingItems.RemoveAt(selectedLineIndex);
                         AddToUndoBuffer(GraphActionType.DeleteItem, removeLine);
                         this.BackgroundDirty = true; // New to redraw the background
                         HighlightClosestLine(e);
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.CutLine:
             if (this.DrawingStep == GraphDrawingStep.SelectItem)
             {
                 selectedLineIndex = FindClosestLine(mousePoint);
                 if (selectedLineIndex != -1) // #### Check if visible to avoid cutting out of scope items
                 {
                     Line2DBase itemToCut = (Line2DBase)this.drawingItems.ElementAt(selectedLineIndex);
                     Line2DBase cutItem = itemToCut.Cut(mouseValuePoint.X, (Control.ModifierKeys & Keys.Control) == 0);
                     if (cutItem != null)
                     {
                         this.drawingItems.RemoveAt(selectedLineIndex);
                         this.drawingItems.Add(cutItem);
                         AddToUndoBuffer(GraphActionType.CutItem, itemToCut, cutItem);
                         this.BackgroundDirty = true; // New to redraw the background
                         HighlightCutLine(e, mouseValuePoint, (Control.ModifierKeys & Keys.Control) == 0);
                     }
                 }
             }
             break;
         default:
             break;
     }
 }