public void Visit(mEllipse ellipse) { ellipse.Width = width; ellipse.Height = height; ellipse.X = x; ellipse.Y = y; ellipse.Load(); }
/*private funcs*/ public void GenerateTransformRect() { selectionRect = new SelectionRectangle(); selectionRect.Padding = 9; int padding = selectionRect.Padding; int width = Width + (padding * 2); int height = Height + (padding * 2); mRectangle rect = new mRectangle(width, height, Color.Transparent); rect.X = X - padding; rect.Y = Y - padding; rect.BorderSize = 2; rect.DrawBorder = true; rect.Load(); int handleSize = 10; int correction = handleSize / 2;//\(handleSize + (handleSize/2)); mEllipse topleft = new mEllipse(handleSize, handleSize, Color.Black); topleft.X = rect.X - correction; topleft.Y = rect.Y - correction; topleft.Load(); selectionRect.TopLeft = topleft; mEllipse topright = new mEllipse(handleSize, handleSize, Color.Black); topright.X = rect.X + rect.Width - correction; topright.Y = rect.Y - correction; topright.Load(); selectionRect.TopRight = topright; mEllipse bottomleft = new mEllipse(handleSize, handleSize, Color.Black); bottomleft.X = rect.X - correction; bottomleft.Y = rect.Y + rect.Height - correction; bottomleft.Load(); selectionRect.BottomLeft = bottomleft; mEllipse bottomright = new mEllipse(handleSize, handleSize, Color.Black); bottomright.X = rect.X + rect.Width - correction; bottomright.Y = rect.Y + rect.Height - correction; bottomright.Load(); selectionRect.BottomRight = bottomright; selectionRect.SelectRect = rect; }
public void Visit(aShape shape) { if (shape.GetType() == typeof(ShapeTextDecorator)) { ShapeTextDecorator s = (ShapeTextDecorator)shape; Visit(s); } else if (shape.GetType() == typeof(ShapeComposite)) { ShapeComposite s = (ShapeComposite)shape; Visit(s); } else if (shape.GetType() == typeof(mRectangle)) { mRectangle s = (mRectangle)shape; Visit(s); } else if (shape.GetType() == typeof(mEllipse)) { mEllipse s = (mEllipse)shape; Visit(s); } }
public void Visit(mEllipse ellipse) { output += ellipse.ShapeName + " " + ellipse.X + " " + ellipse.Y + " " + ellipse.Width + " " + ellipse.Height + "\n"; }
public void Visit(mEllipse ellipse) { ellipse.X += deltaX; ellipse.Y += deltaY; }
public static List <aShape> Deserialize(string path) { List <aShape> shapes = new List <aShape>(); Regex rxGroup = new Regex(@"(\t*)(group)\s(?<groupNumber>\d+)(\n\r|\n|\r)(?<shapes>(((\t+)(?<type>ornament)\s(Top|Botton|Left|Right)\s(\')(?<text>.*)(\')|(\t+)(?<isTextShape>t\s)*(?<type>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+))(\n\r|\n|\r))*)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rxTextShape = new Regex(@"(ornament)\s(?<textpos>Top|Botton|Left|Right)\s(\')(?<text>.*)(\')(\n\r|\n|\r)(t\s)(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rxShape = new Regex(@"(?<isGrouped>(\t*))(?<isTextShape>t\s)*(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (!File.Exists(path)) { throw new System.ArgumentException("Filepath does not exist!"); } string shapeStrings = File.ReadAllText(path); MatchCollection matchesGroups = rxGroup.Matches(shapeStrings); ShapeComposite group = new ShapeComposite(); ShapeComposite prevGroup = null; ShapeComposite underGroup = null; foreach (Match m in matchesGroups) { GroupCollection groups = m.Groups; string gr = groups["shapes"].Value; int.TryParse(groups["groupNumber"].Value, out int groupNumber); if (groupNumber > 0) { ShapeComposite newGroup = new ShapeComposite(); List <aShape> temp = deserializeGroupShapes(gr); foreach (aShape s in temp) { newGroup.Add(s); } if (underGroup != null) { underGroup.Add(newGroup); underGroup = newGroup; } else { prevGroup.Add(newGroup); underGroup = newGroup; } } else { if (prevGroup != null) { shapes.Add(prevGroup); prevGroup = null; } if (group == null) { group = new ShapeComposite(); } List <aShape> temp = deserializeGroupShapes(gr); foreach (aShape s in temp) { group.Add(s); } prevGroup = group; group = null; } } if (prevGroup != null) { shapes.Add(prevGroup); prevGroup = null; } if (group != null) { shapes.Add(group); } MatchCollection matchesTextShapes = rxTextShape.Matches(shapeStrings); foreach (Match m in matchesTextShapes) { GroupCollection groups = m.Groups; aShape temp = null; TextPos textPos = StringToTextpos(groups["textpos"].Value); string text = groups["text"].Value; //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; ShapeTextDecorator decTemp = new ShapeTextDecorator(temp); decTemp.AddText(text, textPos); if (temp != null) { temp.Load(); shapes.Add(decTemp); } else { return(shapes); } } MatchCollection matchesShapes = rxShape.Matches(shapeStrings); foreach (Match m in matchesShapes) { GroupCollection groups = m.Groups; //Check on group and text if (groups["isTextShape"].Value != string.Empty || groups["isGrouped"].Value != string.Empty) { continue; } aShape temp = null; //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; if (temp != null) { temp.Load(); shapes.Add(temp); } else { return(shapes); } } return(shapes); }
static List <aShape> deserializeGroupShapes(string shapes) { Regex rxTextShape = new Regex(@"(\t*)(ornament)\s(?<textpos>Top|Botton|Left|Right)\s(\')(?<text>.*)(\')(\n\r|\n|\r)(\t*)t\s(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rxShape = new Regex(@"(\t*)(?<isTextShape>t\s)*(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matchesTextShapes = rxTextShape.Matches(shapes); List <aShape> returnShapes = new List <aShape>(); foreach (Match m in matchesTextShapes) { GroupCollection groups = m.Groups; aShape temp = null; TextPos textPos = StringToTextpos(groups["textpos"].Value); string text = groups["text"].Value; //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; ShapeTextDecorator decTemp = new ShapeTextDecorator(temp); decTemp.AddText(text, textPos); if (temp != null) { temp.Load(); returnShapes.Add(decTemp); } } MatchCollection matchesShapes = rxShape.Matches(shapes); foreach (Match m in matchesShapes) { GroupCollection groups = m.Groups; aShape temp = null; if (groups["isTextShape"].Value != string.Empty) { continue; } //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; if (temp != null) { temp.Load(); returnShapes.Add(temp); } } return(returnShapes); }