Beispiel #1
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);
            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);
            }
        }
Beispiel #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);
            }
        }
 public static NetworkVisibleSettings openFromXml(XmlNodeList root)
 {
     NetworkVisibleSettings ret = new NetworkVisibleSettings();
     foreach (XmlNode node in root)
     {
         string namespaceUri = node.NamespaceURI;
         string localName = node.LocalName;
         switch (namespaceUri)
         {
             case PetriXmlHelper.XML_SETTINGS_NAMESPACE:
                 switch (localName)
                 {
                     case "EdgeLabel":
                         ret.visibleEdgeLabel = PetriNetwork.openBoolData(node);
                         break;
                     case "EdgeWeight":
                         ret.visibleEdgeWeight = PetriNetwork.openBoolData(node);
                         break;
                     case "Notes":
                         ret.visibleNotes = PetriNetwork.openBoolData(node);
                         break;
                     case "PositionLabel":
                         ret.visiblePositionLabel = PetriNetwork.openBoolData(node);
                         break;
                     case "Priority":
                         ret.visiblePriority = PetriNetwork.openBoolData(node);
                         break;
                     case "TransitionLabel":
                         ret.visibleTransitionLabel = PetriNetwork.openBoolData(node);
                         break;
                     case "EdgeHelpLine":
                         ret.visibleEdgeHelpLine = PetriNetwork.openBoolData(node);
                         break;
                     case "ReadyToFireTransitions":
                         ret.visibleReadyToFireTransitions = PetriNetwork.openBoolData(node);
                         break;
                     case "Capacity":
                         ret.visibleCapacity = PetriNetwork.openBoolData(node);
                         break;
                     case "Clock":
                         ret.visibleClock = PetriNetwork.openBoolData(node);
                         break;
                 }
                 break;
         }
     }
     return ret;
 }
Beispiel #4
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>();
        }
Beispiel #5
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);
                }
            }
        }
Beispiel #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));
                }
            }
        }
        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));
                }
            }
        }