예제 #1
0
파일: Note.cs 프로젝트: davidbedok/UBPNS
        public override void draw(Graphics g, bool selected, bool mark, NetworkVisualSettings visualSettings, NetworkVisibleSettings visibleSettings, bool markAsReadyToFire, bool showHelpEllipse)
        {
            // base.draw(g, selected, mark, visualSettings, visibleSettings, markAsReadyToFire);
            if (visibleSettings.VisibleNotes)
            {
                if (this.attachedItem != null)
                {
                    if (this.attachedItem is AbstractNetworkItem)
                    {
                        AbstractNetworkItem networkItem = (AbstractNetworkItem)this.attachedItem;
                        if (this.attachedItem is Transition)
                        {
                            g.DrawLine(visualSettings.NoteLinePen, this.Origo, networkItem.Origo);
                        }
                        else if (this.attachedItem is Position)
                        {
                            Position position = (Position)networkItem;
                            g.DrawLine(visualSettings.NoteLinePen, this.Origo, this.getPositionPoint(this.Origo, position.Origo, position.Radius));
                        }
                    }
                    else if (this.attachedItem is AbstractEdge)
                    {
                        AbstractEdge edgeItem = (AbstractEdge)this.attachedItem;
                        g.DrawLine(visualSettings.NoteLinePen, this.Origo, edgeItem.getCurveMiddlePoint());
                    }
                }

                this.drawNote(g, null, visualSettings.ShadowBrush, this.ShadowRectangle);
                this.drawNote(g, (selected ? visualSettings.SelectedItemPen : visualSettings.NoteBorderPen), visualSettings.NoteBrush, this.Rectangle);
                g.DrawString(this.text, visualSettings.NoteFont, visualSettings.NoteTextBrush, this.Rectangle);
            }
        }
예제 #2
0
        public override void draw(Graphics g, bool selected, bool mark, NetworkVisualSettings visualSettings, NetworkVisibleSettings visibleSettings, bool markAsReadyToFire, bool showHelpEllipse)
        {
            base.draw(g, selected, mark, visualSettings, visibleSettings, markAsReadyToFire, showHelpEllipse);
            Brush brush = ((mark && !TransitionType.SOURCE.Equals(this.TransitionType)) ? visualSettings.MarkBrush : (selected ? visualSettings.SelectedItemBrush : (markAsReadyToFire ? visualSettings.MarkAsReadyToFireBrush : visualSettings.DefaultBrush)));

            AbstractItem.MATRIX.RotateAt((float)this.Angle, this.Origo, MatrixOrder.Append);
            g.Transform = AbstractItem.MATRIX;
            if ( TransitionType.NORMAL.Equals(this.TransitionType) ) {
                g.FillRectangle(brush, this.Rectangle);
            }
            else
            {
                Pen pen = ((mark && !TransitionType.SOURCE.Equals(this.TransitionType)) ? visualSettings.MarkPen : (selected ? visualSettings.SelectedItemPen : (markAsReadyToFire ? visualSettings.MarkAsReadyToFirePen : visualSettings.DefaultPen)));
                RectangleF rect = this.Rectangle;
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                if (TransitionType.SOURCE.Equals(this.TransitionType)) {
                    float radius = 3;
                    if (this.Size.Width > this.Size.Height)
                    {
                        radius = Math.Abs(this.Size.Height / 2 - 1);
                    }
                    else
                    {
                        radius = Math.Abs(this.Size.Width / 2 - 1);
                    }
                    g.FillEllipse(brush, this.Origo.X - radius, this.Origo.Y - radius, 2 * radius, 2 * radius);
                }
                else if (TransitionType.SINK.Equals(this.TransitionType))
                {
                    //
                }
            }

            AbstractItem.MATRIX.Reset();
            g.Transform = AbstractItem.MATRIX;
            if (this.showAnnotation)
            {
                string labelName = (visibleSettings.VisibleTransitionLabel ? this.name : "");
                string label = labelName + (this.Priority > 0 && visibleSettings.VisiblePriority ? ("".Equals(labelName) ? "" : " (") + this.Priority.ToString() + ("".Equals(labelName) ? "" : ")") : "");
                if (!"".Equals(label))
                {
                    SizeF textSize = g.MeasureString(label, visualSettings.DefaultFont);
                    float offset = (this.Size.Width - textSize.Width) / 2;
                    g.DrawString(label, visualSettings.DefaultFont, visualSettings.DefaultBrush, this.Point.X + offset + this.LabelOffset.X, this.Point.Y - textSize.Height + this.LabelOffset.Y);
                }
            }
            if ((visibleSettings.VisibleClock) && ( this.Delay > 0 ))
            {
                this.drawClock(g, new PointF(this.Origo.X + this.clockOffset.X, this.Origo.Y + this.clockOffset.Y), visualSettings);
            }
        }
예제 #3
0
        public AbstractNetwork(Random rand, int stateGenNumber, string statePrefix, int sh_width, int sh_height)
        {
            this.rand = rand;
            this.items = new List<AbstractNetworkItem>();
            this.selectedItems = new List<AbstractItem>();
            this.edges = new List<AbstractEdge>();
            this.visualSettings = new NetworkVisualSettings();
            this.visibleSettings = new NetworkVisibleSettings();
            this.stateMatrix = new List<StateVector>();
            this.stateHierarchy = new StateHierarchy(this.rand, sh_width, sh_height);

            this.unidGenNumber = 0;
            this.stateGenNumber = stateGenNumber;
            this.statePrefix = statePrefix;
            this.events = new EventTrunk();
            this.transitionHistory = new List<TransitionHistoryItem>();
        }
예제 #4
0
        public override void draw(Graphics g, bool selected, bool mark, NetworkVisualSettings visualSettings, NetworkVisibleSettings visibleSettings, bool markAsReadyToFire, bool showHelpEllipse)
        {
            base.draw(g, selected, mark, visualSettings, visibleSettings, markAsReadyToFire, showHelpEllipse);
            g.FillEllipse(visualSettings.ShadowBrush, this.ShadowRectangle);
            g.FillEllipse(visualSettings.BackgroundBrush, this.Rectangle);

            Pen pen = (mark ? visualSettings.MarkPen : (selected ? visualSettings.SelectedItemPen : visualSettings.DefaultPen));
            g.DrawEllipse(pen, this.Rectangle);

            int tokenCount = this.tokens.Count;
            PointF tp = this.Origo;
            switch (tokenCount)
            {
                case 0:

                    break;
                case 1:
                    this.tokens[0].draw(g, this.Origo, visualSettings);
                    break;
                case 2:
                    tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y - AbstractPosition.TOKEN_MOVE_SMALL);
                    this.tokens[0].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X + AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y + AbstractPosition.TOKEN_MOVE_SMALL);
                    this.tokens[1].draw(g, tp, visualSettings);
                    break;
                case 3:
                    tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y - AbstractPosition.TOKEN_MOVE_MINI2);
                    this.tokens[0].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X + AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y - AbstractPosition.TOKEN_MOVE_MINI2);
                    this.tokens[1].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X, this.Origo.Y + AbstractPosition.TOKEN_MOVE_MINI2);
                    this.tokens[2].draw(g, tp, visualSettings);
                    break;
                case 4:
                    tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y - AbstractPosition.TOKEN_MOVE_SMALL);
                    this.tokens[0].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X + AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y + AbstractPosition.TOKEN_MOVE_SMALL);
                    this.tokens[1].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X + AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y - AbstractPosition.TOKEN_MOVE_SMALL);
                    this.tokens[2].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE_SMALL, this.Origo.Y + AbstractPosition.TOKEN_MOVE_SMALL);
                    this.tokens[3].draw(g, tp, visualSettings);
                    break;
                case 5:
                    tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE, this.Origo.Y - AbstractPosition.TOKEN_MOVE);
                    this.tokens[0].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X + AbstractPosition.TOKEN_MOVE, this.Origo.Y + AbstractPosition.TOKEN_MOVE);
                    this.tokens[1].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X + AbstractPosition.TOKEN_MOVE, this.Origo.Y - AbstractPosition.TOKEN_MOVE);
                    this.tokens[2].draw(g, tp, visualSettings);
                    tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE, this.Origo.Y + AbstractPosition.TOKEN_MOVE);
                    this.tokens[3].draw(g, tp, visualSettings);
                    this.tokens[4].draw(g, this.Origo, visualSettings);
                    break;
            }
            if (tokenCount > 5)
            {
                tp = new PointF(this.Origo.X - AbstractPosition.TOKEN_MOVE_MINI, this.Origo.Y - AbstractPosition.TOKEN_MOVE_MINI2);
                this.tokens[0].draw(g, tp, visualSettings);
                g.DrawString(tokenCount.ToString(), visualSettings.DefaultFont, visualSettings.DefaultBrush, this.Origo.X - AbstractPosition.TOKEN_MOVE_MINI, this.Origo.Y);
            }
            if (this.showAnnotation)
            {
                string labelName = (visibleSettings.VisiblePositionLabel ? this.name : "");
                string label = labelName + (this.CapacityLimit > 0 && visibleSettings.VisibleCapacity ? ("".Equals(labelName) ? "" : " (") + this.CapacityLimit.ToString() + ("".Equals(labelName) ? "" : ")") : "");
                if (!"".Equals(label))
                {
                    SizeF textSize = g.MeasureString(label, visualSettings.DefaultFont);
                    float offset = (this.Size.Width - textSize.Width) / 2;
                    g.DrawString(label, visualSettings.DefaultFont, visualSettings.DefaultBrush, this.Point.X + offset + this.LabelOffset.X, this.Point.Y - textSize.Height + this.LabelOffset.Y);
                }
            }
        }
예제 #5
0
 public static NetworkVisualSettings openFromXml(XmlNodeList root)
 {
     NetworkVisualSettings ret = new NetworkVisualSettings();
     foreach (XmlNode node in root)
     {
         string namespaceUri = node.NamespaceURI;
         string localName = node.LocalName;
         switch (namespaceUri)
         {
             case NetworkVisualSettings.XML_COLOR_NAMESPACE:
                 Color color = NetworkVisualSettings.openColor(node);
                 switch (localName)
                 {
                     case "DefaultColor":
                         ret.DefaultColor = color;
                         break;
                     case "MarkColor":
                         ret.MarkColor = color;
                         break;
                     case "SelectedColor":
                         ret.SelectedColor = color;
                         break;
                     case "HelpColor":
                         ret.HelpColor = color;
                         break;
                     case "StateColor":
                         ret.StateColor = color;
                         break;
                     case "MarkAsReadyToFireColor":
                         ret.MarkAsReadyToFireColor = color;
                         break;
                     case "ClockColor":
                         ret.ClockColor = color;
                         break;
                 }
                 break;
             case NetworkVisualSettings.XML_FONT_NAMESPACE:
                 Font font = NetworkVisualSettings.openFont(node);
                 switch (localName)
                 {
                     case "DefaultFont":
                         ret.defaultFont = font;
                         break;
                 }
                 break;
             case NetworkVisualSettings.XML_PEN_NAMESPACE:
                 switch (localName)
                 {
                     case "DefaultEdgePen":
                         NetworkVisualSettings.openPen(node, ret.defaultEdgePen);
                         break;
                     case "DefaultPen":
                         NetworkVisualSettings.openPen(node, ret.defaultPen);
                         break;
                     case "MarkPen":
                         NetworkVisualSettings.openPen(node, ret.markPen);
                         break;
                     case "SelectedEdgePen":
                         NetworkVisualSettings.openPen(node, ret.selectedEdgePen);
                         break;
                     case "SelectedItemPen":
                         NetworkVisualSettings.openPen(node, ret.selectedItemPen);
                         break;
                     case "HelpPen":
                         NetworkVisualSettings.openPen(node, ret.helpPen);
                         break;
                     case "StatePen":
                         NetworkVisualSettings.openPen(node, ret.statePen);
                         break;
                     case "StateEdgePen":
                         NetworkVisualSettings.openPen(node, ret.stateEdgePen);
                         break;
                     case "MarkAsReadyToFirePen":
                         NetworkVisualSettings.openPen(node, ret.markAsReadyToFirePen);
                         break;
                     case "ClockPen":
                         NetworkVisualSettings.openPen(node, ret.clockPen);
                         break;
                 }
                 break;
         }
     }
     return ret;
 }
예제 #6
0
        public void draw(Graphics g, bool selected, NetworkVisualSettings visualSettings, NetworkVisibleSettings visibleSettings)
        {
            Pen pen = visualSettings.DefaultEdgePen;
            if (EdgeType.NORMAL.Equals(this.edgeType))
            {
                pen = (selected ? visualSettings.SelectedEdgePen : visualSettings.DefaultEdgePen);
                pen.Width = (this.Weight); // + 1
            }
            else if (EdgeType.INHIBITOR.Equals(this.edgeType))
            {
                pen = (selected ? visualSettings.SelectedInhibitorArcPen : visualSettings.InhibitorArcPen);
                pen.Width = (this.Weight); // + 1
            }
            else if (EdgeType.RESET.Equals(this.edgeType))
            {
                pen = (selected ? visualSettings.SelectedResetArcPen : visualSettings.ResetArcPen);
            }
            PointF startPoint = this.getStartPoint();
            PointF endPoint = this.getEndPoint();
            if (this.showAnnotation)
            {
                if ((this.Weight > 1) || (!"".Equals(this.name)))
                {
                    string label = "";
                    if ((this.Weight > 1) && ("".Equals(this.name)))
                    {
                        label = (visibleSettings.VisibleEdgeWeight ? this.Weight.ToString() : "");
                    }
                    else if ((this.Weight <= 1) && (!"".Equals(this.name)))
                    {
                        label = (visibleSettings.VisibleEdgeLabel ? this.name : "");
                    }
                    else
                    {
                        label = (visibleSettings.VisibleEdgeLabel ? this.name : "") + (visibleSettings.VisibleEdgeWeight ? " (" + this.Weight.ToString() + ")" : "");
                    }

                    float la = Math.Abs(endPoint.X - startPoint.X) / 2;
                    float lb = Math.Abs(endPoint.Y - startPoint.Y) / 2;
                    float a = startPoint.X + la * (startPoint.X < endPoint.X ? 1 : -1);
                    float b = startPoint.Y + lb * (startPoint.Y < endPoint.Y ? 1 : -1);

                    float offsetX = AbstractEdge.STRING_ROT_OFFSET_VALUE;
                    float offsetY = -AbstractEdge.STRING_ROT_OFFSET_VALUE;
                    SizeF textSize = g.MeasureString(label, visualSettings.DefaultFont);
                    double angle = Math.Atan(la / lb);
                    double angleDeg = angle * 180 / Math.PI;
                    if ((this.Start.Origo.X <= this.End.Origo.X) && (this.Start.Origo.Y <= this.End.Origo.Y))
                    {
                        angleDeg = 90 - angleDeg;
                    }
                    if ((this.Start.Origo.X < this.End.Origo.X) && (this.Start.Origo.Y > this.End.Origo.Y))
                    {
                        angleDeg = -90 + angleDeg;
                        offsetX *= -1;
                    }
                    if ((this.Start.Origo.X >= this.End.Origo.X) && (this.Start.Origo.Y >= this.End.Origo.Y))
                    {
                        angleDeg = 180 - 90 - angleDeg;
                    }
                    if ((this.Start.Origo.X > this.End.Origo.X) && (this.Start.Origo.Y < this.End.Origo.Y))
                    {
                        angleDeg = 180 + 90 + angleDeg;
                        offsetX *= -1;
                    }

                    AbstractItem.MATRIX.RotateAt((float)angleDeg, new PointF(a, b), MatrixOrder.Append);
                    g.Transform = AbstractItem.MATRIX;
                    /* if (!this.isZeroCurveMiddlePointOffset())
                    {
                        PointF middlePoint = this.getCurveMiddlePoint();
                        a = middlePoint.X;
                        b = middlePoint.Y;
                    }*/
                    PointF strPoint = new PointF(a - textSize.Width / 2 + offsetX, b - textSize.Height / 2 + offsetY);
                    if (!this.isZeroCurveMiddlePointOffset())
                    {
                        PointF middlePoint = this.getCurveMiddlePoint();
                        strPoint = new PointF(middlePoint.X - textSize.Width / 2, middlePoint.Y - textSize.Height / 2);
                    }
                    g.DrawString(label, visualSettings.DefaultFont, visualSettings.DefaultBrush, strPoint);
                    AbstractItem.MATRIX.Reset();
                    g.Transform = AbstractItem.MATRIX;
                }
            }
            if (this.isZeroCurveMiddlePointOffset())
            {
                g.DrawLine(pen, startPoint, endPoint);
            }
            else
            {
                PointF middlePoint = this.getMiddlePoint();
                PointF[] points = new PointF[3];
                points[0] = startPoint;
                points[1] = new PointF(middlePoint.X + this.curveMiddlePointOffset.X, middlePoint.Y + this.curveMiddlePointOffset.Y);
                points[2] = endPoint;
                g.DrawCurve(pen, points);
                if (visibleSettings.VisibleEdgeHelpLine)
                {
                    // g.DrawLine(visualSettings.HelpPen, this.getStartPoint(), this.getEndPoint());
                    // g.DrawEllipse(visualSettings.HelpPen, new RectangleF(middlePoint.X - 5, middlePoint.Y - 5, 10, 10));
                    g.DrawEllipse(visualSettings.HelpPen, new RectangleF(points[1].X - 5, points[1].Y - 5, 10, 10));
                }
            }
        }
예제 #7
0
파일: Token.cs 프로젝트: davidbedok/UBPNS
 public override void draw(Graphics g, PointF point, NetworkVisualSettings visualSettings)
 {
     g.FillEllipse(this.TokenBrush, point.X - AbstractToken.TOKEN_RADIUS, point.Y - AbstractToken.TOKEN_RADIUS, 2 * AbstractToken.TOKEN_RADIUS, 2 * AbstractToken.TOKEN_RADIUS);
 }
예제 #8
0
 public void draw(Graphics g, NetworkVisualSettings visualSettings, StateVector actualState)
 {
     RectangleF rect = this.Rectangle;
     Pen pen = ( this.Equals(actualState) ? visualSettings.SelectedItemPen : visualSettings.StatePen);
     g.DrawEllipse(pen, rect);
     SizeF textSize = g.MeasureString(this.name, visualSettings.DefaultFont);
     g.DrawString(this.name, visualSettings.DefaultFont, visualSettings.StateBrush, this.origo.X - textSize.Width / 2, this.origo.Y - textSize.Height / 2);
 }
예제 #9
0
 public void draw(Graphics g, NetworkVisualSettings visualSettings, StateVector actualState)
 {
     foreach (StateVector state in this.states)
     {
         state.draw(g, visualSettings, actualState);
     }
     foreach (EdgeStateState edge in this.edges)
     {
         edge.draw(g, visualSettings);
     }
 }
예제 #10
0
 public void drawClock(Graphics g, PointF clockOrigo, NetworkVisualSettings visualSettings)
 {
     float bigRadius = this.ClockRadius;
     float smallRadius = bigRadius * 2 / 3;
     g.DrawEllipse(visualSettings.ClockPen, clockOrigo.X - bigRadius, clockOrigo.Y - bigRadius, 2 * bigRadius, 2 * bigRadius);
     PointF p1 = new PointF((float)(clockOrigo.X - (bigRadius - 1) * Math.Cos(Math.PI / 3)), (float)(clockOrigo.Y - (bigRadius - 1) * Math.Sin(Math.PI / 3)));
     g.DrawLine(visualSettings.ClockPen, clockOrigo, p1);
     PointF p2 = new PointF((float)(clockOrigo.X + smallRadius * Math.Cos(Math.PI / 6)), (float)(clockOrigo.Y - smallRadius * Math.Sin(Math.PI / 6)));
     g.DrawLine(visualSettings.ClockPen, clockOrigo, p2);
     g.DrawString(this.Delay.ToString() + " ms", visualSettings.DefaultFont, visualSettings.ClockBrush, new PointF(clockOrigo.X + smallRadius, clockOrigo.Y + smallRadius));
 }
예제 #11
0
 public void draw(Graphics g, NetworkVisualSettings visualSettings)
 {
     g.DrawLine(visualSettings.StateEdgePen, this.getStartPoint(), this.getEndPoint());
 }
예제 #12
0
        public virtual void draw(Graphics g, bool selected, bool mark, NetworkVisualSettings visualSettings, NetworkVisibleSettings visibleSettings, bool markAsReadyToFire, bool showHelpEllipse)
        {
            if (visibleSettings.VisibleEdgeHelpLine && showHelpEllipse)
            {
                float r = AbstractNetworkItem.HELP_ELLIPSE_RADIUS_DRAW;
                g.DrawEllipse(visualSettings.HelpPen, new RectangleF(this.point.X - r, this.point.Y - r, 2 * r, 2 * r));
                g.DrawEllipse(visualSettings.HelpPen, new RectangleF(this.point.X + this.size.Width - r, this.point.Y - r, 2 * r, 2 * r));
                g.DrawEllipse(visualSettings.HelpPen, new RectangleF(this.point.X - r, this.point.Y + this.size.Height - r, 2 * r, 2 * r));
                g.DrawEllipse(visualSettings.HelpPen, new RectangleF(this.point.X + this.size.Width - r, this.point.Y + this.size.Height - r, 2 * r, 2 * r));

                if (this.showAnnotation && this.name != null && this.name != "")
                {
                    g.DrawEllipse(visualSettings.HelpPen, new RectangleF(this.point.X + (this.size.Width / 2) + this.labelOffset.X - r, this.point.Y - AbstractNetworkItem.LABEL_HELP_ELLIPSE_OFFSET + this.labelOffset.Y - r, 2 * r, 2 * r));
                }
            }
        }
예제 #13
0
 public abstract void draw(Graphics g, PointF point, NetworkVisualSettings visualSettings);