public Arrow(GraphicState s1, GraphicState s2) { fromState = s1; toState = s2; transitionToken = ""; updateArrowPosition(s1, s2); }
private void updateDraggedState() { int x = selectedState.location.X; int y = selectedState.location.Y; bool shouldProcess = enlargeBackBufferAsRequired(ref x, ref y); selectedState.location.X = x; selectedState.location.Y = y; if (shouldProcess) { Graphics g = Graphics.FromImage(backBuffer); g.SmoothingMode = SmoothingMode.AntiAlias; GraphicState.drawState(selectedState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat); foreach (GraphicState state in stateArrayList) { foreach (Arrow arrow in state.exitArrowList) { arrow.updateArrowPosition(state, null); } foreach (Arrow arrow in state.entryArrowList) { arrow.updateArrowPosition(null, state); } } reDrawBackBuffer(); panel2.Invalidate(); } }
private void Panel2_MouseDown(object sender, MouseEventArgs e) { if (attributeEditorRadioButton.Checked && e.Button == MouseButtons.Left) { selectedState = GraphicState.getStateSelected(stateArrayList, new Point(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y), ref deviation); } }
private void updateEdgeStates() { if (topMostState == null) { topMostState = leftMostState = rightMostState = botMostState = (GraphicState)stateArrayList[0]; } foreach (GraphicState state in stateArrayList) { if (state.location.X < leftMostState.location.X) { leftMostState = state; } if (state.location.Y < topMostState.location.Y) { topMostState = state; } if (state.location.X > rightMostState.location.X) { rightMostState = state; } if (state.location.Y > botMostState.location.Y) { botMostState = state; } } }
private bool getCurrentTransitionArrow(int x, int y) { bool reDraw = false; currentTransitionArrow = null; foreach (Arrow arrow in allArrowList) { if (arrow.textRect.Contains(x, y) && GraphicState.getStateSelected(stateArrayList, new Point(x, y)) == null) { currentTransitionArrow = arrow; if (arrow.isHoverOver) { break; } arrow.isHoverOver = true; reDraw = true; break; } } foreach (Arrow arrow in allArrowList) { if (arrow.isHoverOver && arrow != currentTransitionArrow) { reDraw = true; arrow.isHoverOver = false; } } return(reDraw); }
private void Panel2_MouseMove(object sender, MouseEventArgs e) { if (selectedState != null) { dragPoint.X = e.X - panel2.AutoScrollPosition.X; dragPoint.Y = e.Y - panel2.AutoScrollPosition.Y; if (!dragDropTimer.Enabled) { dragDropTimer.Start(); } } else if (attributeEditorRadioButton.Checked && !transitionTokenTextField.Visible) { getSelectedTransition(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y); } else if (deleterRadioButton.Checked) { GraphicState prevHoverState = hoverState; Arrow prevTransitionArrow = currentTransitionArrow; hoverState = GraphicState.getStateSelected(stateArrayList, new Point(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y)); getCurrentTransitionArrow(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y); if (hoverState != prevHoverState || currentTransitionArrow != prevTransitionArrow) { reDrawBackBuffer(); panel2.Invalidate(); } } }
public static GraphicState getStateSelected(List <GraphicState> stateArrayList, Point point, ref Point deviation) { GraphicState selectedState = getStateSelected(stateArrayList, point); if (selectedState != null) { deviation.X = point.X - selectedState.location.X; deviation.Y = point.Y - selectedState.location.Y; } return(selectedState); }
public void updateArrowPosition(GraphicState s1, GraphicState s2) { bezierPoint1 = new Point(-1, -1); bezierPoint2 = new Point(-1, -1); if (s1 == null) { s1 = fromState; } if (s2 == null) { s2 = toState; } if (s1 != s2) { double t1 = Math.Atan2(s2.location.Y - s1.location.Y, s2.location.X - s1.location.X); double t2 = Math.Atan2(s1.location.Y - s2.location.Y, s1.location.X - s2.location.X); start = new Point((int)(Math.Cos(t1) * GraphicState.STATE_RADII + s1.location.X), (int)(Math.Sin(t1) * GraphicState.STATE_RADII + s1.location.Y)); end = new Point((int)(Math.Cos(t2) * GraphicState.STATE_RADII + s2.location.X), (int)(Math.Sin(t2) * GraphicState.STATE_RADII + s2.location.Y)); double theta1 = Math.Atan2(start.Y - s1.location.Y, start.X - s1.location.X); theta1 = (((theta1 * 180) / Math.PI - 10) * Math.PI) / 180; double theta2 = Math.Atan2(end.Y - s2.location.Y, end.X - s2.location.X); theta2 = (((theta2 * 180) / Math.PI + 10) * Math.PI) / 180; start.X = (int)(Math.Cos(theta1) * GraphicState.STATE_RADII + s1.location.X); start.Y = (int)(Math.Sin(theta1) * GraphicState.STATE_RADII + s1.location.Y); end.X = (int)(Math.Cos(theta2) * GraphicState.STATE_RADII + s2.location.X); end.Y = (int)(Math.Sin(theta2) * GraphicState.STATE_RADII + s2.location.Y); //pathEquation = new LineEquation(start.X, start.Y, end.X, end.Y); double theta = Math.Atan2(start.Y - end.Y, start.X - end.X); theta = (((theta * 180) / Math.PI) * Math.PI) / 180; double theta3 = (((theta * 180) / Math.PI - 10) * Math.PI) / 180; double theta4 = (((theta * 180) / Math.PI + 10) * Math.PI) / 180; arrowTipPoint1 = new Point((int)(Math.Cos(theta3) * 30 + end.X), (int)(Math.Sin(theta3) * 30 + end.Y)); arrowTipPoint2 = new Point((int)(Math.Cos(theta4) * 30 + end.X), (int)(Math.Sin(theta4) * 30 + end.Y)); textRect = new Rectangle((3 * start.X + end.X) / 4 - GraphicState.STATE_RADII, (3 * start.Y + end.Y) / 4 - GraphicState.STATE_RADII, 2 * GraphicState.STATE_RADII, 2 * GraphicState.STATE_RADII); } else { start = new Point((int)(s1.location.X - GraphicState.STATE_RADII / Math.Sqrt(2)), (int)(s1.location.Y - GraphicState.STATE_RADII / Math.Sqrt(2)) + 5); end = new Point((int)(s1.location.X + GraphicState.STATE_RADII / Math.Sqrt(2)), (int)(s1.location.Y - GraphicState.STATE_RADII / Math.Sqrt(2))); bezierPoint1.X = start.X + GraphicState.STATE_RADII / 10; bezierPoint1.Y = start.Y - 2 * GraphicState.STATE_RADII; bezierPoint2.X = end.X - GraphicState.STATE_RADII / 10; bezierPoint2.Y = start.Y - 2 * GraphicState.STATE_RADII; arrowTipPoint1 = new Point(end.X - 7, end.Y - 20); arrowTipPoint2 = new Point(end.X + 5, end.Y - 20); textRect = new Rectangle((bezierPoint1.X + bezierPoint2.X) / 2 - GraphicState.STATE_RADII, (bezierPoint1.Y + bezierPoint2.Y) / 2 - GraphicState.STATE_RADII, 2 * GraphicState.STATE_RADII, 2 * GraphicState.STATE_RADII); } }
private bool shouldCreateNewTransition(GraphicState toState) { foreach (Arrow exitArrow in fromState.exitArrowList) { foreach (Arrow entryArrow in toState.entryArrowList) { if (exitArrow == entryArrow) { return(false); } } } return(true); }
public static void setZOrderOfStateOnTop(GraphicState state, List <GraphicState> stateArrayList) { int maxZOrder = -1; state.zOrder = -1; foreach (GraphicState s in stateArrayList) { if (s != state && Math.Sqrt(Math.Pow(s.location.X - state.location.X, 2) + Math.Pow(s.location.Y - state.location.Y, 2)) <= 2 * STATE_RADII && s.zOrder > maxZOrder) { maxZOrder = s.zOrder; } } state.zOrder = maxZOrder + 1; }
private void Panel2_MouseUp(object sender, MouseEventArgs e) { if (attributeEditorRadioButton.Checked && e.Button == MouseButtons.Left) { if (selectedState != null) { updateDraggedState(); GraphicState.setZOrderOfStateOnTop(selectedState, stateArrayList); updateEdgeStates(); shirnkCanvasAsRequired(); } selectedState = null; } }
private void deleteItem() { if (hoverState != null) { foreach (GraphicState state in stateArrayList) { if (state != hoverState) { foreach (Arrow arrow in state.exitArrowList) { if (arrow.toState == hoverState) { state.exitArrowList.Remove(arrow); allArrowList.Remove(arrow); break; } } } } foreach (Arrow arrow in hoverState.exitArrowList) { allArrowList.Remove(arrow); } stateArrayList.Remove(hoverState); if (hoverState == botMostState) { botMostState = new GraphicState(new Point(0, 0), "no name"); } if (hoverState == rightMostState) { rightMostState = new GraphicState(new Point(0, 0), "no name"); } updateEdgeStates(); shirnkCanvasAsRequired(); hoverState = null; reDrawBackBuffer(); panel2.Invalidate(); } else if (currentTransitionArrow != null) { currentTransitionArrow.fromState.exitArrowList.Remove(currentTransitionArrow); currentTransitionArrow.toState.entryArrowList.Remove(currentTransitionArrow); allArrowList.Remove(currentTransitionArrow); currentTransitionArrow = null; reDrawBackBuffer(); panel2.Invalidate(); } }
private void panel2_Click(object sebder, MouseEventArgs e) { if (transitionTokenTextField.Visible) { getTextFieldData(); } if (stateCreatorRadioButton.Checked && e.Button == MouseButtons.Left) { createNewState(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y); } else if (transitionCreatorRadioButton.Checked && e.Button == MouseButtons.Left) { selectTransitionState(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y); } else if (attributeEditorRadioButton.Checked && e.Button == MouseButtons.Left && currentTransitionArrow != null) { initializeTokenTextField(); } else if (deleterRadioButton.Checked && e.Button == MouseButtons.Left) { deleteItem(); } else if (e.Button == MouseButtons.Right && attributeEditorRadioButton.Checked) { if ((propertyChangingState = GraphicState.getStateSelected(stateArrayList, new Point(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y))) != null) { if (propertyChangingState.final) { finalStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; } else { finalStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Unchecked; } if (propertyChangingState.initial) { initialStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; } else { initialStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Unchecked; } StateContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y); } } }
public static void drawState(GraphicState state, Graphics g, SolidBrush stateBrush, Pen stateBorderPen, Font stateNameFont, SolidBrush stateNameBrush, StringFormat stateNameStringFormat, Rectangle rect) { g.FillEllipse(stateBrush, rect); g.DrawEllipse(stateBorderPen, rect.X + 3, rect.Y + 3, rect.Width - 6, rect.Height - 6); if (state.final) { g.DrawEllipse(stateBorderPen, rect.X + 12, rect.Y + 12, rect.Width - 24, rect.Height - 24); } g.DrawString(state.stateName, stateNameFont, stateNameBrush, rect, stateNameStringFormat); if (state.initial) { stateBorderPen.Width = GraphicState.STATE_RADII; stateBorderPen.EndCap = System.Drawing.Drawing2D.LineCap.Triangle; g.DrawLine(stateBorderPen, state.location.X - GraphicState.STATE_RADII - 25, state.location.Y, state.location.X - GraphicState.STATE_RADII - 23, state.location.Y); stateBorderPen.Width = 3; } }
private void createNewState(int x, int y) { enlargeBackBufferAsRequired(ref x, ref y); Graphics g = Graphics.FromImage(backBuffer); g.SmoothingMode = SmoothingMode.AntiAlias; GraphicState s = new GraphicState(new Point(x, y), "q" + num); stateArrayList.Add(s); GraphicState.setZOrderOfStateOnTop(s, stateArrayList); GraphicState.drawState(s, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat); num++; updateEdgeStates(); panel2.Invalidate(); }
public AutomataDisplayPage(GraphicState initialState, Bitmap backBuffer, String validationString) { InitializeComponent(); this.currentState = initialState; this.backBuffer = backBuffer; this.validationString = validationString; backBuffer = new Bitmap(backBuffer.Width, backBuffer.Height); greenPen = new Pen(Color.FromArgb(0, 255, 0), 3); stateNameBrush = new SolidBrush(Color.White); backGroundBrush = new SolidBrush(drawPanel1.BackColor); stateNameFont = new Font("New Times Roman", 15, FontStyle.Bold); stateNameStringFormat = new StringFormat(); stateNameStringFormat.Alignment = StringAlignment.Center; stateNameStringFormat.LineAlignment = StringAlignment.Center; displayStringRect = new Rectangle(0, 0, 0, 0); drawPanel1.AutoScrollMinSize = backBuffer.Size; speech = new SpeechSynthesizer(); speech.Rate = -2; speech.SetOutputToDefaultAudioDevice(); }
private void openFiniteAutomataDisplayTab(GraphicState initialState, Bitmap backBuffer) { if (initialState != null) { Input inputForm = new Input(); inputForm.StartPosition = FormStartPosition.CenterScreen; DialogResult res = inputForm.ShowDialog(); if (res == DialogResult.OK) { AutomataDisplayPage display = (AutomataDisplayPage)createNewTab(new AutomataDisplayPage(initialState, backBuffer, inputForm.getText()), "Display", ref automataDisplayTabNumber); display.onUserCloseClick += new AutomataDisplayPage.clickEventHandler(closeTab); materialTabSelector1.Enabled = false; } } else { AutomataMessageBox error = new AutomataMessageBox("No initial state selected"); error.StartPosition = FormStartPosition.CenterScreen; error.ShowDialog(); } }
private void reDrawBackBuffer() { Graphics g = Graphics.FromImage(backBuffer); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRectangle(backGroundBrush, 0, 0, backBuffer.Width, backBuffer.Height); stateArrayList.Sort((x, y) => x.zOrder.CompareTo(y.zOrder)); foreach (GraphicState state in stateArrayList) { foreach (Arrow arrow in state.exitArrowList) { Pen arrowPen = (arrow.isHoverOver) ? stateBorderPen2 : stateBorderPen; if (arrow.bezierPoint1.X == -1) { g.DrawLine(arrowPen, arrow.start, arrow.end); } else { g.DrawBezier(arrowPen, arrow.start, arrow.bezierPoint1, arrow.bezierPoint2, arrow.end); } g.DrawLine(arrowPen, arrow.arrowTipPoint1, arrow.end); g.DrawLine(arrowPen, arrow.arrowTipPoint2, arrow.end); g.FillRectangle(backGroundBrush, arrow.textRect.X + GraphicState.STATE_RADII - arrow.transitionToken.Length * 15 / 2, arrow.textRect.Y + GraphicState.STATE_RADII - stateNameFont.Height / 2, arrow.transitionToken.Length * 15, stateNameFont.Height); g.DrawString(arrow.transitionToken, stateNameFont, stateNameBrush, arrow.textRect, stateNameStringFormat); } } foreach (GraphicState state in stateArrayList) { if (state != selectedState) { GraphicState.drawState(state, g, stateBrush, (state == hoverState)?stateBorderPen2: stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat); } } if (selectedState != null) { GraphicState.drawState(selectedState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat); } }
private void selectTransitionState(int x, int y) { GraphicState s = GraphicState.getStateSelected(stateArrayList, new Point(x, y)); Graphics g = Graphics.FromImage(backBuffer); g.SmoothingMode = SmoothingMode.AntiAlias; if (s != null) { if (fromState == null) { fromState = s; GraphicState.drawState(s, g, stateBrush, stateBorderPen2, stateNameFont, stateNameBrush, stateNameStringFormat); } else { GraphicState.drawState(fromState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat); if (shouldCreateNewTransition(s)) { Arrow arrow = new Arrow(fromState, s); allArrowList.Add(arrow); currentTransitionArrow = arrow; initializeTokenTextField(); fromState.exitArrowList.Add(arrow); s.entryArrowList.Add(arrow); reDrawBackBuffer(); } fromState = null; } panel2.Invalidate(); } else if (fromState != null) { GraphicState.drawState(fromState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat); fromState = null; panel2.Invalidate(); } }
public static GraphicState getStateSelected(List <GraphicState> stateArrayList, Point point) { List <GraphicState> candidateStates = new List <GraphicState>(); foreach (GraphicState state in stateArrayList) { if (Math.Sqrt(Math.Pow(point.X - state.location.X, 2) + Math.Pow(point.Y - state.location.Y, 2)) <= STATE_RADII) { candidateStates.Add(state); } } int maxZOrder = -1; GraphicState selectedState = null; foreach (GraphicState state in candidateStates) { if (state.zOrder > maxZOrder) { selectedState = state; maxZOrder = selectedState.zOrder; } } return(selectedState); }
private void materialRaisedButton1_Click(object sender, EventArgs e) { //if(validationString.ElementAt(currStringIndex)) if (validationString.Length > 0) { targetArrow = null; if (currentState != null) { foreach (Arrow arrow in currentState.exitArrowList) { foreach (String str in arrow.getDelta()) { if (str.CompareTo("" + validationString[currStringIndex]) == 0) { targetArrow = arrow; break; } } if (targetArrow != null) { break; } } } if (targetArrow != null) { currentState = targetArrow.toState; } else { currentState = null; } if (currentState == null) { materialRaisedButton1.Enabled = false; displayMessageBox("String not accepted"); } else { if (materialCheckBox1.Checked) { speech.Speak(targetArrow.fromState.stateName + " on " + Char.ToUpper(validationString[currStringIndex]) + " goes to " + targetArrow.toState.stateName); } processedString = processedString + validationString[currStringIndex]; if (currStringIndex + 1 != validationString.Length) { currStringIndex++; } else if (currentState.final) { materialRaisedButton1.Enabled = false; displayMessageBox("String accepted"); } else { materialRaisedButton1.Enabled = false; displayMessageBox("String not accepted"); } } drawPanel1.Invalidate(); } }
public static void drawState(GraphicState state, Graphics g, SolidBrush stateBrush, Pen stateBorderPen, Font stateNameFont, SolidBrush stateNameBrush, StringFormat stateNameStringFormat) { Rectangle rect = new Rectangle(state.location.X - STATE_RADII, state.location.Y - STATE_RADII, 2 * STATE_RADII, 2 * STATE_RADII); drawState(state, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat, rect); }