public static void AddPoint(List <float> Input) { if (Input.Count == 0) { PointF p1 = ShapeSystem.gridSystem.cursorPosition; cadPoint newPoint = new cadPoint(p1); Console.WriteLine("Point " + newPoint.IdShape.ToString() + " created as {0}", newPoint.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } else if (Input.Count == 2) { float x1 = (Input[0]); float y1 = (Input[1]); PointF p1 = new PointF(x1, y1); cadPoint newPoint = new cadPoint(p1); Console.WriteLine("Point " + newPoint.IdShape.ToString() + " created as {0}", newPoint.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } else { Console.WriteLine("Invalid input."); return; } }
public static void AddEllipse(List <float> Input) { if (Input.Count() == 1) { PointF P1 = ShapeSystem.gridSystem.cursorPosition; float R = Input[0]; Ellipse retCircle = new Ellipse(P1, R); Console.WriteLine("Ellipse " + retCircle.IdShape.ToString() + " created as {0}", retCircle.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } else if (Input.Count() == 3) { PointF P1 = new PointF(Input[0], Input[1]); float R = Input[2]; Ellipse retCircle = new Ellipse(P1, R); Console.WriteLine("Ellipse " + retCircle.IdShape.ToString() + " created as {0}", retCircle.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } else { Console.WriteLine("Invalid input for Ellipse."); } }
public List <PointF> GetSnapPoints() { List <PointF> snaps = new List <PointF>(); snaps.Add(new PointF(P1.X, P1.Y - R)); snaps.Add(new PointF(P1.X, P1.Y + R)); snaps.Add(new PointF(P1.X - R, P1.Y)); snaps.Add(new PointF(P1.X + R, P1.Y)); snaps.Add(P1); foreach (Shape S in ShapeSystem.ShapeList.Where(s => s is Line)) { Line L = (Line)S; PointF potential1 = new PointF(); PointF potential2 = new PointF(); int result = ShapeSystem.FindLineCircleIntersections(P1, R, L.P1, L.P2, out potential1, out potential2); if (result == 2) { snaps.Add(potential1); snaps.Add(potential2); } else if (result == 1) { snaps.Add(potential1); } } return(snaps); }
public void Load() { foreach (Line L in list_Line) { ShapeSystem.ShapeList.Add(L); ShapeSystem.AddShapeToDataSet(L); } foreach (LinearDimension L in list_Dim) { ShapeSystem.ShapeList.Add(L); ShapeSystem.AddShapeToDataSet(L); } foreach (cadPoint L in list_cadPoint) { ShapeSystem.ShapeList.Add(L); ShapeSystem.AddShapeToDataSet(L); } foreach (Rect L in list_Rect) { ShapeSystem.ShapeList.Add(L); ShapeSystem.AddShapeToDataSet(L); } foreach (Ellipse L in list_Ellipse) { ShapeSystem.ShapeList.Add(L); ShapeSystem.AddShapeToDataSet(L); } }
public void DrawSnaps(Graphics g) { if (!(showSnaps)) { return; } g.Clip = new Region(gridBounds); //Cursor if (showActiveSnaps) { foreach (Shape S in ShapeSystem.ShapeList.Where(s => s.isActiveShape == true && s is iSnappable)) { foreach (PointF sp in ((iSnappable)S).GetSnapPoints()) { PointF P = realizePoint(sp); g.DrawLine(new Pen(Color.Orange), new PointF(P.X - 10, P.Y), new PointF(P.X + 10, P.Y)); g.DrawLine(new Pen(Color.Orange), new PointF(P.X, P.Y - 10), new PointF(P.X, P.Y + 10)); } } } else { foreach (PointF S in ShapeSystem.GetSnapPoints()) { PointF P = realizePoint(S); g.DrawLine(new Pen(Color.Orange), new PointF(P.X - 10, P.Y), new PointF(P.X + 10, P.Y)); g.DrawLine(new Pen(Color.Orange), new PointF(P.X, P.Y - 10), new PointF(P.X, P.Y + 10)); } } }
public static void AddLine(List <float> Input) { if (ShapeSystem.gridSystem.relativePositioning && Input.Count == 2) { PointF p1 = new PointF(ShapeSystem.gridSystem.cursorPosition.X, ShapeSystem.gridSystem.cursorPosition.Y); float x2 = (Input[0] + p1.X); float y2 = (Input[1] + p1.Y); PointF p2 = new PointF(x2, y2); Line RetLine = new Line(p1, p2); ShapeSystem.gridSystem.cursorPosition = p2; Console.WriteLine("Line " + RetLine.IdShape.ToString() + " created as {0}", RetLine.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } if (Input.Count != 4) { Console.WriteLine("Invalid input."); return; } else { float x1 = (Input[0]); float y1 = (Input[1]); float x2 = (Input[2]); float y2 = (Input[3]); PointF p1 = new PointF(x1, y1); PointF p2 = new PointF(x2, y2); Line RetLine = new Line(p1, p2); Console.WriteLine("Line " + RetLine.IdShape.ToString() + " created as {0}", RetLine.MetaDesc); ShapeSystem.gridSystem.cursorPosition = p2; ShapeSystem.UpdateSnapPoints(); return; } }
public Ellipse(PointF P1, float R) { this.P1 = P1; this.R = R; this.MetaName = "Ellipse"; this.MetaDesc = P1.X.ToString() + "," + P1.Y.ToString() + "; R: " + R.ToString(); ShapeSystem.AddShapeToDataSet(this); }
public cadPoint(PointF p1) { this.P1 = p1; this.ParentId = -1; this.MetaName = "Point"; object[] MetaDescArray = { this.P1.X, this.P1.Y }; this.MetaDesc = string.Format("({0},{1})", MetaDescArray); ShapeSystem.AddShapeToDataSet(this); }
//Line with Parent public Line(PointF p1, PointF p2, Shape parent) { this.Points.Add(p1); this.Points.Add(p2); this.ParentId = parent.IdShape; this.MetaName = "Line"; object[] MetaDescArray = { this.Points[0].X, this.Points[0].Y, this.Points[1].X, this.Points[1].Y }; this.MetaDesc = string.Format("({0},{1}):({2},{3})", MetaDescArray); ShapeSystem.AddShapeToDataSet(this); this.slope = (Points[1].Y - Points[0].Y) / (Points[1].X - Points[0].X); }
public Rect(PointF p1, PointF p2, PointF p3, PointF p4) { this.AB = new Line(p1, p2, (Shape)this); this.BC = new Line(p2, p3, (Shape)this); this.CD = new Line(p3, p4, (Shape)this); this.DA = new Line(p4, p1, (Shape)this); this.ParentId = -1; this.MetaName = "Rect"; object[] MetaDescArray = { AB.IdShape, BC.IdShape, CD.IdShape, DA.IdShape }; this.MetaDesc = string.Format("L{0}, L{1}, L{2}, L{3}", MetaDescArray); ShapeSystem.AddShapeToDataSet(this); }
public static bool RemoveActiveShape() { Shape S = ShapeSystem.ShapeList.Where(s => s.isActiveShape == true).FirstOrDefault(); if (S != null) { ShapeSystem.ShapeList.Remove(S); DT_ShapeList.Rows.Remove(DT_ShapeList.Rows.Find(S.IdShape)); ShapeSystem.UpdateSnapPoints(); return(true); } return(false); }
public static void ClearData() { List <int> ShapeIds = new List <int>(); foreach (Shape S in ShapeSystem.ShapeList) { ShapeIds.Add(S.IdShape); } foreach (int I in ShapeIds) { RemoveShapeById(I); } ShapeSystem.UpdateSnapPoints(); }
public bool DeSerializeAndLoadShapes(string fileName) { try { Snapshot snapshot = DeserializeFromFile <Snapshot>(fileName); ShapeSystem.ClearData(); snapshot.Load(); ShapeSystem.UpdateSnapPoints(); Console.WriteLine("Shape system \"{0}\" loaded.", fileName); } catch (Exception e) { Console.WriteLine("An error occoured: {0}", e.Message); } return(false); }
public LinearDimension(PointF P1, PointF P2) { this.P1 = P1; this.P2 = P2; this.ParentId = -1; float x1 = this.P1.X; float y1 = this.P1.Y; float x2 = this.P2.X; float y2 = this.P2.Y; this.TxFont = new System.Drawing.Font("Consolas", 8F, System.Drawing.FontStyle.Regular); this.dimLength = (float)Math.Sqrt((Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2))); this.MetaName = "Dim"; object[] MetaDescArray = { P1.X, P1.Y, P2.X, P2.Y }; this.MetaDesc = string.Format("({0},{1}):({2},{3})", MetaDescArray); this.distanceFromLine = .0625F; this.leadingLineLength = .5F; this.dimInsetFromLeadingLine = .125F; ShapeSystem.AddShapeToDataSet(this); }
public LinearDimension(Line L, float dist) { this.P1 = L.P1; this.P2 = L.P2; this.ParentId = L.IdShape; float x1 = this.P1.X; float y1 = this.P1.Y; float x2 = this.P2.X; float y2 = this.P2.Y; this.TxFont = new System.Drawing.Font("Consolas", 8F, System.Drawing.FontStyle.Regular); this.dimLength = (float)Math.Sqrt((Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2))); this.MetaName = "Dim"; object[] MetaDescArray = { L.MetaName, L.IdShape }; this.MetaDesc = string.Format("{0} {1}", MetaDescArray); this.distanceFromLine = .0625F; this.leadingLineLength = dist; this.dimInsetFromLeadingLine = .125F; ShapeSystem.AddShapeToDataSet(this); }
public CadSystem(PointF origin, SizeF containerSize, float scale, int dpi) { this.gridSystem = new GridSystem(origin, containerSize, scale, dpi); ShapeSystem.InitSystem(); ShapeSystem.SetGrid(gridSystem); //SET FUNCTIONS this.drawingFunctions.Add("L", Line.AddLine); this.drawingFunctions.Add("RT", Rect.AddRect); this.drawingFunctions.Add("E", Ellipse.AddEllipse); this.drawingFunctions.Add("C", gridSystem.SetCursor); this.drawingFunctions.Add("P", cadPoint.AddPoint); this.drawingFunctions.Add("AJD", LinearDimension.AdjDim); this.drawingFunctions.Add("DIM", LinearDimension.AddNewDim); this.drawingFunctions.Add("FILL", ShapeSystem.SetShapeFillColor); Action PosToggle = () => gridSystem.TogglePositioning(); Action DimActiveLine = () => ShapeSystem.DimensionActiveLine(); this.gridFunctions.Add("R", PosToggle); this.gridFunctions.Add("D", DimActiveLine); }
public static void AddRect(List <float> Input) { //Width and height from cursor if (ShapeSystem.gridSystem.relativePositioning && Input.Count == 2) { PointF cursor = new PointF(ShapeSystem.gridSystem.cursorPosition.X, ShapeSystem.gridSystem.cursorPosition.Y); PointF p1 = new PointF(Math.Min(cursor.X, cursor.X + Input[0]), Math.Min(cursor.Y, cursor.Y + Input[1])); PointF p2 = new PointF(Math.Max(cursor.X, cursor.X + Input[0]), Math.Min(cursor.Y, cursor.Y + Input[1])); PointF p3 = new PointF(Math.Max(cursor.X, cursor.X + Input[0]), Math.Max(cursor.Y, cursor.Y + Input[1])); PointF p4 = new PointF(Math.Min(cursor.X, cursor.X + Input[0]), Math.Max(cursor.Y, cursor.Y + Input[1])); Rect RetRect = new Rect(p1, p2, p3, p4); ShapeSystem.gridSystem.cursorPosition = cursor; Console.WriteLine("Rectangle " + RetRect.IdShape.ToString() + " created as {0}", RetRect.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } if (Input.Count != 4) { Console.WriteLine("Invalid input."); return; } else { PointF pRef = new PointF(Input[0], Input[1]); PointF p1 = new PointF(Math.Min(pRef.X, pRef.X + Input[2]), Math.Min(pRef.Y, pRef.Y + Input[3])); PointF p2 = new PointF(Math.Max(pRef.X, pRef.X + Input[2]), Math.Min(pRef.Y, pRef.Y + Input[3])); PointF p3 = new PointF(Math.Max(pRef.X, pRef.X + Input[2]), Math.Max(pRef.Y, pRef.Y + Input[3])); PointF p4 = new PointF(Math.Min(pRef.X, pRef.X + Input[2]), Math.Max(pRef.Y, pRef.Y + Input[3])); Rect RetRect = new Rect(p1, p2, p3, p4); ShapeSystem.gridSystem.cursorPosition = pRef; Console.WriteLine("Rectangle " + RetRect.IdShape.ToString() + " created as {0}", RetRect.MetaDesc); ShapeSystem.UpdateSnapPoints(); return; } }
public Shape() { ShapeSystem.ShapeList.Add(this); IdShape = ShapeSystem.ShapeList.Max(m => m.IdShape) + 1; ShapeSystem.MakeActiveShape(this); }