Пример #1
0
        /// <summary>
        /// Imports a PNML document and converts it to a PetriNet instance.
        /// </summary>
        /// <param name="document">An instance of PnmlDocument to import.</param>
        /// <returns>An instance of PetriNet that represents the Petri Net extracted from the document.</returns>
        public PetriNet Import(PersistentDocument document)
        {
            var petriNet = new PetriNet();

            // Loading PNML document content.
            var xDocument = GetXmlDocumentFromPnmlDocument(document);

            // Loading Places and Transitions.
            var nonArcElements = xDocument.Element("pnml").Element("net").Elements().Where(element => element.Name != "arc");
            foreach (var xPNElement in nonArcElements)
            {
                switch (xPNElement.Name.ToString())
                {
                    case "place":
                        var place = GetPlaceObjectFromPnmlElement(xPNElement);
                        if (place != null)
                        {
                            petriNet.Elements.Add(place);
                        }
                        break;

                    case "transition":
                        var transition = GetTransitionObjectFromPnmlElement(xPNElement);
                        if (transition != null)
                        {
                            petriNet.Elements.Add(transition);
                        }
                        break;
                }
            }

            // Loading Arcs.
            var arcElements = xDocument.Element("pnml").Element("net").Elements().Where(element => element.Name == "arc");
            foreach (var xArcElement in arcElements)
            {
                var arc = GetArcObjectFromPnmlElement(petriNet, xArcElement);
                if (arc != null)
                {
                    petriNet.Elements.Add(arc);
                }
            }

            petriNet.UpdateElementRelationships();
            return petriNet;
        }
Пример #2
0
        public void LoadPetriNet(PetriNet petriNet)
        {
            SelectedWidgets.Clear();
            Widgets.Clear();

            petriNet.UpdateElementRelationships();
            foreach (var element in petriNet.Elements)
            {
                var widget = CreateWidgetForElement(element);
                widget.Location = new Point
                (
                    (int)element.GetGraphicsMetadataItem("graphics.position.@x", 30),
                    (int)element.GetGraphicsMetadataItem("graphics.position.@y", 30)
                );
                Widgets.Add(widget);
            }

            HandleWidgetsChanged();
            HandleSelectedWidgetsChanged();
            UpdateControlAvailability();
            RedrawCanvas();
        }
Пример #3
0
 public PetriNet ExportToPetriNet()
 {
     var result = new PetriNet();
     foreach (var widget in Widgets)
     {
         if (!(widget is ArcWidget))
         {
             widget.Element.SetGraphicsMetadataItem("graphics.position.@x", widget.Location.X);
             widget.Element.SetGraphicsMetadataItem("graphics.position.@y", widget.Location.Y);
             widget.Element.SetGraphicsMetadataItem("graphics.dimension.@x", widget.Size);
             widget.Element.SetGraphicsMetadataItem("graphics.dimension.@y", widget.Size);
         }
         result.Elements.Add(widget.Element);
     }
     result.UpdateElementRelationships();
     return result;
 }