示例#1
0
 /// <summary>
 /// When a new Control (Shape) is added to the form, and it is the only Shape currently instantiated, set up the selectTab to add the Tessellation
 /// to the split container correctly when more than one tab is created (when this adding behavior is handled by tabControl1_Selected_1),
 /// and do the first time insert into the split container. As well, set the splitter distance as it needs to be configured the first time.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="ControlEventArgs"/> instance containing the event data.</param>
 private void tabControl1_ControlAdded(object sender, ControlEventArgs e)
 {
     if(!tabControl1.Controls.Contains(tabPage1) && this.shapes.Count == 1){
         Shape temp = (Shape)e.Control;
         Tessellation tessTemp = findTessellation(temp.Name);
         splitContainer1.Panel2.Controls.Add(tessTemp);
         splitContainer1.Panel2Collapsed = false;
         splitContainer1.SplitterDistance = this.Width / 2;
         lastTab = (Shape)tabControl1.SelectedTab;
     }
 }
示例#2
0
        /// <summary>
        /// This handles when a new tab is selected. It grabs all the data pertinent to the currently selected tab from the corresponding instances
        /// of Shape and Tessellations from their respective Lists, updates the textboxes/track bars and reruns the simulation (invalidates them).
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="TabControlEventArgs"/> instance containing the event data.</param>
        private void tabControl1_Selected_1(object sender, TabControlEventArgs e)
        {
            // If the default tab is not there and there is more than one Shape current initialized, perform a selected tab change.
            if (!tabControl1.Controls.Contains(tabPage1) && this.shapes.Count > 1)
            {
                Shape tab = (Shape)e.TabPage;
                EventSource.output(tab.Name + " tab was selected");
                angleBox.Text = "" + tab.getStartAngle();
                bouncesBox.Text = "" + tab.getBounces();
                pointBox.Text = "" + tab.getStartPoint();
                if (tab.getStartAngle() > 0 && tab.getStartAngle() < 180)
                    trackBar4.Value = (int)tab.getStartAngle();
                if (tab.getStartPoint() > 0 && tab.getStartPoint() < 1)
                    trackBar2.Value = (int)(tab.getStartPoint() * 100d);

                splitContainer1.Panel2.Controls.RemoveByKey(lastTab.Name);
                Tessellation tessTemp = findTessellation(tab.Name);
                splitContainer1.Panel2.Controls.Add(tessTemp);
                lastTab = (Shape)tabControl1.SelectedTab;
            }
        }
示例#3
0
        /// <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;
        }