/// <summary> /// Centralized method to handle the instantiation of all Shapes and Tessellations. /// </summary> /// <param name="shape">Used to determine which shape to instantiate.</param> /// <param name="ratio">Optional parameter that defaults to 0. (Only used for rectangle)</param> /// <returns> /// Returns a Control array of length 2, the first element being the instance of the Shape /// and the second being the instance of the Tessellation. /// </returns> private void instantiateShapes(out Shape instShape, out Tessellation instTess, int shape, double ratio = 0d) { // Checks for the default tabPage that is added as a placeholder, and removes it if a shape is being created. if (tabControl1.TabPages.Contains(tabPage1)) { tabControl1.TabPages.Remove(tabPage1); } Shape tempShape = null; Tessellation tempTess = null; // Each switch case sets the lastTab field, adds the Shape instance to the shapes List, adds the Tessellation instance to the tessellations List, // adds the Shape to the tabControl and sets the ContextMenu of that tab to the context menu field in the Shape base class. switch (shape) { case 0: tempShape = new Equilateral(); EventSource.output("Equilateral Triangle tab created."); tempTess = new EquilateralTess(); tempTess.Name = "Equilateral" + (tempShape.getShapeCount() - 1); break; case 1: tempShape = new IsosTri90(); EventSource.output("90 Isosceles Triangle tab created."); tempTess = new IsosTri90Tess(); tempTess.Name = "IsosTri90" + (tempShape.getShapeCount() - 1); break; case 2: tempShape = new IsosTri120(); EventSource.output("120 Isosceles Triangle tab created."); tempTess = new IsosTri120Tess(); tempTess.Name = "IsosTri120" + (tempShape.getShapeCount() - 1); break; case 3: tempShape = new Tri3060(); EventSource.output("30-60-90 Triangle tab created."); tempTess = new Tri3060Tess(); tempTess.Name = "Tri3060" + (tempShape.getShapeCount() - 1); break; case 4: tempShape = new Hexagon(); EventSource.output("120 Hexagon tab created."); tempTess = new HexagonTess(); tempTess.Name = "Hexagon" + (tempShape.getShapeCount() - 1); break; case 5: tempShape = new Rhombus(); EventSource.output("60-120 Rhombus tab created."); tempTess = new RhombusTess(); tempTess.Name = "Rhombus" + (tempShape.getShapeCount() - 1); break; case 6: tempShape = new Kite(); EventSource.output("60-90-120 Kite tab created."); tempTess = new KiteTess(); tempTess.Name = "Kite" + (tempShape.getShapeCount() - 1); break; case 7: tempShape = new Rect(ratio); EventSource.output("Rectangle tab created."); tempTess = new RectTess(ratio); tempTess.Name = "Rectangle" + (tempShape.getShapeCount() - 1); break; default: break; } // The order for this must remain the same, the Shape and Tessellation instances must be added to the Lists before they are added to the Controls // because it triggers an event for the tabControl when a new Control is added, and the lastTab must be configured correctly for it. if (shapes.Count() != 0) lastTab = (Shape)tabControl1.SelectedTab; shapes.Add(tempShape); tessellations.Add(tempTess); tabControl1.TabPages.Add(tempShape); instShape = tempShape; instTess = tempTess; }