/// <summary> /// reads file from constant path /// </summary> public void ReadFile() { string[] lines = File.ReadAllLines(Constants.path); Shape.Shape lastShape = null; int lastTabs = 0; foreach (var line in lines) { if (line.StartsWith("Rectangle") || line.StartsWith("Ellipse")) { lastTabs = 0; newShape = null; lastShape = CreateShape(line); } if (line.StartsWith("Ornament")) { lastTabs = 0; CreateOrnament(line, lastShape); } if (line.StartsWith("\t")) { int tabCount = line.Count(t => t == '\t'); if (tabCount > lastTabs) { if (newShape == null) { if (IsShape(line)) { lastShape.AddChild(IsShape(line) ? CreateShape(line) : null); newShape = lastShape.GetChildren().Last(); } } else { newShape.AddChild(IsShape(line) ? CreateShape(line) : null); lastShape = newShape; newShape = lastShape.GetChildren().Last(); } } if (tabCount == lastTabs) { if (IsShape(line)) { lastShape.AddChild(IsShape(line) ? CreateShape(line) : null); newShape = lastShape.GetChildren().Last(); } else if (IsOrnament(line)) { CreateOrnament(line, newShape ?? lastShape); } } lastTabs = tabCount; } } }
public override void Execute() { oldFocusedShape = DrawingInstance.Instance.FocusedShape; oldFocusedShapes = new List <Shape.Shape>(); foreach (var shap in DrawingInstance.Instance.FocusedShapes) { parent.AddChild(shap); oldFocusedShapes.Add(shap); } DrawingInstance.Instance.FocusedShape = null; DrawingInstance.Instance.FocusedShapes.Clear(); }