private void btnCut_Click(object sender, RoutedEventArgs e)
        {
            _numberOfPastes = 0;
            if (_selectedFigures.Count != 0)
            {
                nothingToPaste = false;
                cutOrCopy      = cutOrCopyMode.cut;

                cuttedOrCopiedArcs.Clear();
                cuttedOrCopiedFigures.Clear();

                cuttedOrCopiedFigures.AddRange(_selectedFigures);
                cuttedOrCopiedArcs.AddRange(_selectedArcs);

                List <PetriNetNode> cuttedF = new List <PetriNetNode>();
                List <VArc>         cuttedA = new List <VArc>();
                cuttedF.AddRange(cuttedOrCopiedFigures);
                cuttedA.AddRange(cuttedOrCopiedArcs);

                List <VArc> impl = new List <VArc>();
                AddThisArcsToListOfCuttedArcs(cuttedOrCopiedFigures, impl);

                List <PetriNetNode> cutF = new List <PetriNetNode>();
                List <VArc>         cutA = new List <VArc>();
                cutF.AddRange(cuttedOrCopiedFigures);
                cutA.AddRange(impl);

                UnselectFigures();//(selectedFigures, selectedArcs);

                List <PetriNetNode> old = new List <PetriNetNode>();
                foreach (PetriNetNode figure in cutF)
                {
                    PetriNetNode f = PetriNetNode.Create();
                    f.CoordX = figure.CoordX;
                    f.CoordY = figure.CoordY;
                    f.Id     = figure.Id;
                    old.Add(f);
                }

                CutFigures(cutF, cutA);

                CutCommand newCommand = new CutCommand(cuttedF, old, cuttedA, impl);
                Command.ExecutedCommands.Push(newCommand);
                Command.CanceledCommands.Clear();

                HideAllProperties();
            }
            else
            {
                nothingToPaste = true;
            }

            TurnOnSelectMode();
        }
示例#2
0
        public VArc(PetriNetNode first, PetriNetNode second)
        {
            //TODO Здесь очень большая опасность в случае сетей Петри!
            //TODO Можно засунуть неправильную сеть
            //TODO сейчас проверяю при создании сети вообще
            //Debug.Assert(((first is Place) && (second is Place)) || ((first is Transition) && (second is Transition)), "first and second must be of different types");

            From = first;
            To   = second;
            Counter++;//какой ужас! в конструкторе!!!
            Id     = "arc" + Counter;
            Weight = "1";
        }
示例#3
0
        public void ShowProperties(PetriNetNode selected)
        {
            lblID.Visibility      = Visibility.Visible;
            lblIDValue.Visibility = Visibility.Visible;

            lblName.Visibility   = Visibility.Visible;
            tbName.Visibility    = Visibility.Visible;
            btnOkName.Visibility = Visibility.Visible;

            lblIngoingArcs.Visibility    = Visibility.Visible;
            textBoxIngoinArcs.Visibility = Visibility.Visible;

            lblOutgoinArcs.Visibility      = Visibility.Visible;
            textBoxOutgoingArcs.Visibility = Visibility.Visible;

            lblIDValue.Content = selected.Id;
            tbName.Text        = selected.Label;
            VPlace place = selected as VPlace;

            if (place != null)
            {
                ShowOnlyPlaceProperties();
                tbTokenNumber.Text = place.NumberOfTokens.ToString();
            }
            else
            //HideOnlyPlaceProperties();
            {
                VTransition transition = selected as VTransition;
                ShowOnlyTransitionProperties();
                tbPriority.Text = transition.Priority.ToString();
            }

            textBoxIngoinArcs.Clear();
            textBoxOutgoingArcs.Clear();
            foreach (VArc a in selected.ThisArcs)
            {
                VArc arc = a;
                if (a.To != selected)
                {
                    textBoxOutgoingArcs.Text += arc.To.Id + "\n";
                }
                else
                {
                    textBoxIngoinArcs.Text += arc.From.Id + "\n";
                }
            }
        }
示例#4
0
        public void RemoveNode(PetriNetNode node)
        {
            node.IsSelect = false;
            VPlace place = node as VPlace;

            if (place != null)
            {
                //Net.places.Remove(place);
                VPlace selPlace = place;
                MainModelCanvas.Children.Remove(selPlace.NumberOfTokensLabel);
                while (selPlace.TokensList.Count != 0)
                {
                    MainModelCanvas.Children.Remove(selPlace.TokensList[0]);
                    selPlace.TokensList.RemoveAt(0);
                }
            }
            // else
            //   Net.transitions.Remove(selected as Transition);

            DeleteArcs(node.ThisArcs);
            //selected.ThisArcs.Clear();

            var objectToRemove = GetKeyByValueForFigures(node);

            _allFiguresObjectReferences.Remove(objectToRemove);

            Shape shapeToRemove = objectToRemove as Shape;

            if (shapeToRemove != null)
            {
                shapeToRemove.Stroke = Brushes.Black;
                MainModelCanvas.Children.Remove(shapeToRemove);
            }

            Label labelForRemove;

            NodesToLabelsInCanvas.TryGetValue(node, out labelForRemove);
            MainModelCanvas.Children.Remove(labelForRemove);

            Net.RemoveNode(node);
        }
示例#5
0
 public ChangeNameCommand(PetriNetNode figure, string oldN, string newN)
 {
     namedFigure = figure;
     oldName     = oldN;
     newName     = newN;
 }
示例#6
0
 public AddFigureCommand(PetriNetNode thisFigure, Shape thisShape)
 {
     newFigure = thisFigure;
     shape     = thisShape;
 }
示例#7
0
        public static List <VArc> OpenGraphMl(XmlDocument graphmlDoc, out bool exc)
        {
            var returnArcs = new List <VArc>();

            keys.Clear();
            exc = false;
            XmlNode graph = null;

            if (graphmlDoc.DocumentElement.LastChild.Name == "graph")
            {
                graph = graphmlDoc.DocumentElement.LastChild;
            }

            for (var i = 0; i < graphmlDoc.DocumentElement.ChildNodes.Count; i++)
            {
                if (graphmlDoc.DocumentElement.ChildNodes[i].Name != "key")
                {
                    continue;
                }
                string keyId = null, keyValue = null;
                for (var j = 0; j < graphmlDoc.DocumentElement.ChildNodes[i].Attributes.Count; j++)
                {
                    switch (graphmlDoc.DocumentElement.ChildNodes[i].Attributes[j].Name)
                    {
                    case "id":
                        keyId = graphmlDoc.DocumentElement.ChildNodes[i].Attributes[j].Value;
                        break;

                    case "attr.name":
                        keyValue = graphmlDoc.DocumentElement.ChildNodes[i].Attributes[j].Value;
                        break;
                    }
                }
                if (!keys.ContainsKey(keyId))
                {
                    keys.Add(keyId, keyValue);
                }
            }

            bool isArcsDirectedByDefault = false;

            if (graph == null)
            {
                MessageBox.Show("Node 'graph' is missed, check the file");
                exc = true;
                return(returnArcs);
            }
            else if (graph.LastChild.Name == "edgedefault")
            {
                if (graph.LastChild.Value == "directed")
                {
                    isArcsDirectedByDefault = true;
                }
            }
            XmlNodeList graphObjects = graph.ChildNodes;

            if (graphObjects.Count == 0)
            {
                MessageBox.Show("There are no nodes in the graph, check the file");
                exc = true;
                return(returnArcs);
            }

            foreach (XmlNode node in graphObjects)
            {
                var id = "";

                if (node.Name == "node")
                {
                    for (int i = 0; i < node.Attributes.Count; i++)
                    {
                        if (node.Attributes[i].Name == "id")
                        {
                            id = node.Attributes[i].Value;
                        }
                    }

                    VPlace place = VPlace.Create(0, 0);
                    place.Id = id;
                    PNEditorControl.Net.places.Add(place);
                    //SetOfFigures.Figures.Add(place);
                }
                else if (node.Name == "edge")
                {
                }
                else
                {
                    MessageBox.Show("The file contains element with foreign name, it will be ignored, check the file");
                }
            }

            if (PNEditorControl.Net.Nodes.Count == 0)
            {
                MessageBox.Show("There are no nodes in the graph, check the file");
                exc = true;
                return(returnArcs);
            }
            else
            {
                foreach (XmlNode node in graphObjects)
                {
                    if (node.Name != "edge")
                    {
                        continue;
                    }
                    PetriNetNode from = null, to = null;
                    string       fromId = null, toId = null, id = null, directed = null;

                    for (int i = 0; i < node.Attributes.Count; i++)
                    {
                        switch (node.Attributes[i].Name)
                        {
                        case "source":
                            fromId = node.Attributes[i].Value;
                            break;

                        case "target":
                            toId = node.Attributes[i].Value;
                            break;

                        case "id":
                            id = node.Attributes[i].Value;
                            break;

                        case "directed":
                            directed = node.Attributes[i].Value;
                            break;
                        }
                    }
                    double weight = 0;
                    if (node.FirstChild != null)
                    {
                        var data = node.FirstChild;
                        for (var i = 0; i < data.Attributes.Count; i++)
                        {
                            if (data.Attributes[i].Name != "key")
                            {
                                continue;
                            }
                            string weightValue;
                            keys.TryGetValue(data.Attributes[i].Value, out weightValue);
                            if (weightValue == "weight")
                            {
                                double.TryParse(data.InnerText.Replace('.', ','), out weight);
                            }
                        }
                    }

                    foreach (var figure in PNEditorControl.Net.Nodes)
                    {
                        if (figure.Id == fromId)
                        {
                            from = figure;
                        }
                        else if (figure.Id == toId)
                        {
                            to = figure;
                        }
                    }

                    var arc = new VArc(from, to)
                    {
                        Weight = weight > 1 ? weight.ToString(CultureInfo.InvariantCulture) : "1",
                        Id     = id
                    };
                    if (directed != null)
                    {
                        arc.IsDirected = directed == "true";
                    }
                    else
                    {
                        arc.IsDirected = isArcsDirectedByDefault;
                    }

                    returnArcs.Add(arc);
                }
            }
            return(returnArcs);
        }
示例#8
0
 private object GetKeyByValueForFigures(PetriNetNode el)
 {
     return((from ex in _allFiguresObjectReferences where ex.Value.Equals(el) select ex.Key).FirstOrDefault());
 }
示例#9
0
        /// <summary>
        /// Read model from PNML
        /// </summary>
        /// <param name="pnmlDoc">pnml document</param>
        /// <param name="exc">shows whether any mistakes has been detected</param>
        public static List <VArc> OpenPnml(XmlDocument pnmlDoc, out bool exc)
        {
            var returnArcs = new List <VArc>();

            exc = false;
            XmlNode net = null;

            if (pnmlDoc.DocumentElement.FirstChild.Name == "net")
            {
                net = pnmlDoc.DocumentElement.FirstChild;
            }

            if (net == null)
            {
                MessageBox.Show("Node 'net' is missed, check the file");
                exc = true;
                return(returnArcs);
            }

            XmlNode page = null;

            for (var i = 0; i < net.ChildNodes.Count; i++)
            {
                if (net.ChildNodes[i].Name == "page")
                {
                    page = net.ChildNodes[i];
                }
            }

            if (page == null)
            {
                MessageBox.Show("Node 'page' is missed, check the file");
                exc = true;
                return(returnArcs);
            }

            var petriNetObjects = page.ChildNodes;

            if (petriNetObjects.Count == 0)
            {
                MessageBox.Show("There are no nodes in the net, check the file");
                exc = true;
                return(returnArcs);
            }

            foreach (XmlNode figure in petriNetObjects)
            {
                string id = "", name = "";
                int    numberOfTokens = 0;
                double x = -1, y = -1;

                if (figure.Name == "place" || figure.Name == "transition")
                {
                    for (var i = 0; i < figure.Attributes.Count; i++)
                    {
                        if (figure.Attributes[i].Name == "id")
                        {
                            id = figure.Attributes[i].Value;
                        }
                    }

                    var figureNodes = figure.ChildNodes;

                    //todo Какой-то очень стремный кусок кода. Нужно рефакторить

                    for (int i = 0; i < figureNodes.Count; i++)
                    {
                        if (figureNodes[i].Name == "name")
                        {
                            name = figureNodes[i].FirstChild.InnerText;
                        }
                        else if (figureNodes[i].Name == "graphics")
                        {
                            for (int j = 0; j < figureNodes[i].ChildNodes.Count; j++)
                            {
                                if (figureNodes[i].ChildNodes[j].Name == "position")
                                {
                                    for (int k = 0; k < figureNodes[i].ChildNodes[j].Attributes.Count; k++)
                                    {
                                        if (figureNodes[i].ChildNodes[j].Attributes[k].Name == "x")
                                        {
                                            if (double.TryParse(figureNodes[i].ChildNodes[j].Attributes[k].Value.Replace('.', ','), out x) == false || x < 0)
                                            {
                                                x = 0;
                                                MessageBox.Show("Node " + id + " has incorrect x-coordinate(it will be assumed as 0)");
                                            }
                                        }
                                        else if (figureNodes[i].ChildNodes[j].Attributes[k].Name == "y")
                                        {
                                            if (double.TryParse(figureNodes[i].ChildNodes[j].Attributes[k].Value.Replace('.', ','), out y) == false || y < 0)
                                            {
                                                y = 0;
                                                MessageBox.Show("Node " + id + " has incorrect y-coordinate(it will be assumed as 0)");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (figureNodes[i].Name == "initialMarking")
                        {
                            if (int.TryParse(figureNodes[i].FirstChild.InnerText, out numberOfTokens) == false)
                            {
                                numberOfTokens = 0;
                                MessageBox.Show("Place " + id + " has incorrect number of tokens(it will be assumed as 0)");
                            }
                        }
                    }

                    if (figure.Name == "place")
                    {
                        var place = VPlace.Create(x, y);
                        place.Id             = id;
                        place.Label          = name;
                        place.NumberOfTokens = numberOfTokens;
                        PNEditorControl.Net.places.Add(place);
                        //SetOfFigures.Figures.Add(place);
                    }
                    else
                    {
                        var transition = VTransition.Create(x, y);
                        transition.Id    = id;
                        transition.Label = name;
                        PNEditorControl.Net.transitions.Add(transition);
                        //SetOfFigures.Figures.Add(transition);
                    }
                }
                else if (figure.Name == "arc")
                {
                }
                else
                {
                    MessageBox.Show("The file contains element with foreign name, it will be ignored, check the file");
                }
            }
            if (PNEditorControl.Net.Nodes.Count == 0)
            {
                MessageBox.Show("There are no nodes in the net, check the file");
                exc = true;
                return(returnArcs);
            }
            else
            {
                foreach (XmlNode figure in petriNetObjects)
                {
                    if (figure.Name != "arc")
                    {
                        continue;
                    }

                    PetriNetNode from = null, to = null;
                    string       fromId = null, toId = null, id = null;

                    for (var i = 0; i < figure.Attributes.Count; i++)
                    {
                        switch (figure.Attributes[i].Name)
                        {
                        case "source":
                            fromId = figure.Attributes[i].Value;
                            break;

                        case "target":
                            toId = figure.Attributes[i].Value;
                            break;

                        case "id":
                            id = figure.Attributes[i].Value;
                            break;
                        }
                    }

                    var arcWeight = 1;
                    if (figure.FirstChild != null)
                    {
                        if (figure.FirstChild.Name == "name")
                        {
                            int.TryParse(figure.FirstChild.FirstChild.FirstChild.InnerText, out arcWeight);
                        }
                    }

                    foreach (var f in PNEditorControl.Net.Nodes)
                    {
                        if (f.Id == fromId)
                        {
                            from = f;
                        }
                        else if (f.Id == toId)
                        {
                            to = f;
                        }
                    }

                    var arc = new VArc(from, to)
                    {
                        Weight     = arcWeight.ToString(),
                        Id         = id,
                        IsDirected = true
                    };
                    returnArcs.Add(arc);
                }
            }
            return(returnArcs);
        }
示例#10
0
 public List <VArc> GetIngoingArcs(PetriNetNode figure)
 {
     return(figure.ThisArcs.Where(t => t.To == figure).ToList());
 }