Ejemplo n.º 1
0
        private void PaintBezierHandles(object sender, PaintEventArgs e, Transition transition)
        {
            AutomataUI fw    = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs
            double     angle = 0.0;

            foreach (Transition subtransition in fw.transitionList) // check if there is a return transition to draw double connections correctly
            {
                if (subtransition.startState.ID == transition.endState.ID && subtransition.endState.ID == transition.startState.ID)
                {
                    angle = 0.4;
                    break;
                }
                else
                {
                    angle = 0.0;
                }
            }


            Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(transition.startState.Bounds), State.Center(transition.endState.Bounds), 40, 40, angle); //draw line from state to state

            bezierEdit.bezierStart = new Rectangle(new Point(myEdgePoints.A.X - 5 + transition.startBezierPoint.X, myEdgePoints.A.Y - 5 + transition.startBezierPoint.Y), new Size(10, 10));
            bezierEdit.bezierEnd   = new Rectangle(new Point(myEdgePoints.B.X - 5 + transition.endBezierPoint.X, myEdgePoints.B.Y - 5 + transition.endBezierPoint.Y), new Size(10, 10));


            e.Graphics.DrawLine(GrayPen, myEdgePoints.A, AddTwoPoints(bezierEdit.bezierStart.Location, new Point(5, 5)));
            e.Graphics.DrawLine(GrayPen, myEdgePoints.B, AddTwoPoints(bezierEdit.bezierEnd.Location, new Point(5, 5)));

            e.Graphics.FillEllipse(OrangeBrush, bezierEdit.bezierStart);
            e.Graphics.FillEllipse(OrangeBrush, bezierEdit.bezierEnd);
        }
Ejemplo n.º 2
0
        private void PaintEditTransition(object sender, PaintEventArgs e)
        {
            var fw = sender as AutomataUITimeBased; // connect to encapsulating class GUIAutomataUINode aka main.cs

            if (fw.startConnectionState != null)
            {
                var myEdgePoints = new Lines.EdgePoints();

                if (fw.targetConnectionState != null)                                                                                                             // is transition between state and state
                {
                    myEdgePoints = Lines.GetEdgePoints(State.Center(fw.startConnectionState.Bounds), State.Center(fw.targetConnectionState.Bounds), 40, 40, 0.0); //draw line from state to state
                }
                else // is transition between state and mouse
                {
                    myEdgePoints = Lines.GetEdgePoints(State.Center(fw.startConnectionState.Bounds), new Point(fw.x, fw.y), 40, 10, 0.0); // get edge points for mouse
                }
                e.Graphics.DrawLine(RedPen, myEdgePoints.A, myEdgePoints.B);                                                              //drawline
            }
        }
Ejemplo n.º 3
0
        // Methoden //
        private void PaintTransitions(object sender, PaintEventArgs e)
        {
            AutomataUI fw = sender as AutomataUI; // connect to encapsulating class GUIAutomataUINode aka main.cs

            double winkel = 0.0;

            greenPen.Alignment = PenAlignment.Center;

            transitionPaths.Clear();

            int i = 0;

            #region lines

            foreach (Transition transition in fw.transitionList) // draw lines
            {
                if (transition.IsPingPong)
                {
                    AzurePen.CustomStartCap  = bigArrow;
                    OrangePen.CustomStartCap = bigArrow;
                    AzurePen.DashStyle       = DashStyle.Dot;
                }
                else
                {
                    AzurePen.CustomStartCap  = noArrow;
                    OrangePen.CustomStartCap = noArrow;
                    AzurePen.DashStyle       = DashStyle.Solid;
                }

                foreach (Transition subtransition in fw.transitionList) // check if there is a return transition to draw double connections correctly
                {
                    if (subtransition.startState.ID == transition.endState.ID && subtransition.endState.ID == transition.startState.ID)
                    {
                        winkel = 0.4;
                        break;
                    }
                    else
                    {
                        winkel = 0.0;
                    }
                }

                // getting start and endpoint for transition lines
                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(transition.startState.Bounds), State.Center(transition.endState.Bounds), 40, 40, winkel);

                #region bezierstuff
                //empty path object
                bezierEdit.path = new GraphicsPath();

                //create path with edge positions
                bezierEdit.path.AddBezier(myEdgePoints.A, AddTwoPoints(myEdgePoints.A, transition.startBezierPoint), AddTwoPoints(myEdgePoints.B, transition.endBezierPoint), myEdgePoints.B);

                if (transition == bezierEdit.highlightTransition)
                {
                    e.Graphics.DrawPath(RedPen, bezierEdit.path);                                               // draw red editable bezier
                }
                else if (i == fw.TransitionIndex[fw.ShowSlice[0]] && fw.TransitionFramesOut[fw.ShowSlice[0]] > 0)
                {
                    e.Graphics.DrawPath(OrangePen, bezierEdit.path);                                                                                               // active transition
                }
                else
                {
                    e.Graphics.DrawPath(AzurePen, bezierEdit.path); //draw standard bezier
                }
                transitionPaths.Add(bezierEdit.path);               // create list of bezier paths for hitdetection
                i++;
                #endregion
            }
            #endregion

            #region text
            foreach (Transition transition in fw.transitionList)        // draw text
            {
                foreach (Transition subtransition in fw.transitionList) // check if there is a return transition to draw double connections correctly
                {
                    if (subtransition.startState.ID == transition.endState.ID && subtransition.endState.ID == transition.startState.ID)
                    {
                        winkel = 0.4;
                        break;
                    }
                    else
                    {
                        winkel = 0.0;
                    }
                }

                string text       = transition.Name + " [" + Convert.ToString(transition.Frames) + "]"; // create text
                SizeF  stringSize = new SizeF();
                stringSize = e.Graphics.MeasureString(text, myfont, 100);

                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(transition.startState.Bounds), State.Center(transition.endState.Bounds), 40, 40, winkel);

                //could be optimized and only done once
                Point center = CalculateBezierCenter(0.5, myEdgePoints.A, AddTwoPoints(myEdgePoints.A, transition.startBezierPoint), AddTwoPoints(myEdgePoints.B, transition.endBezierPoint), myEdgePoints.B);


                Rectangle Bounds = new Rectangle(
                    center,
                    new Size(Convert.ToInt32(stringSize.Width + 1),
                             Convert.ToInt32(stringSize.Height + 1)));
                Bounds.X = Bounds.X - (Bounds.Size.Width / 2);
                Bounds.Y = Bounds.Y - (Bounds.Size.Height / 2);

                e.Graphics.FillRectangle(transBackColor, Bounds);
                e.Graphics.DrawString(text, myfont, whiteBrush, Bounds, format); //text

                transition.Bounds = Bounds;                                      //set textbounds to transition
            }
            #endregion
        }