Ejemplo n.º 1
0
        public TransitionEditingForm(PNTransition transition)
        {
            InitializeComponent();
            _transition = transition;
            textBox1.Text = _transition.Name;

            this.TextBox_ProgramTab.CodeEditor.Dock = DockStyle.None;
            this.TextBox_ProgramTab.CodeEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.TextBox_ProgramTab.CodeEditor.Location = new System.Drawing.Point(71, 274);
            this.TextBox_ProgramTab.CodeEditor.Name = "TextBox_Program";
            this.TextBox_ProgramTab.CodeEditor.Size = new System.Drawing.Size(365, 180);
            this.TextBox_ProgramTab.CodeEditor.TabIndex = 11;
            this.Controls.Add(TextBox_ProgramTab.CodeEditor);

            TextBox_ProgramTab.HideGoToDeclarition();

            StringBuilder sb = new StringBuilder();
            foreach (PNPlace place in _transition.InputPlaces)
            {
                sb.AppendLine(place.Name);
            }
            txtInputPlaces.Text = sb.ToString();

            sb = new StringBuilder();
            foreach (PNPlace place in _transition.OutputPlaces)
            {
                sb.AppendLine(place.Name);
            }
            txtOutputPlaces.Text = sb.ToString();
            txtGuard.Text = _transition.Guard;
            TextBox_ProgramTab.Text = _transition.Program;
        }
Ejemplo n.º 2
0
        private void Button_AddNewTransition_Click(object sender, EventArgs e)
        {
            PointF p = Point.Empty;
            //Add from menu bar
            if (Button_AddNewTransition.Checked)
            {
                p = this.Canvas.LastMouseClickPosition;
            }
            else
            {
                p = this.Canvas.lastRightClickPosition;
            }

            PNTransition classitem = new PNTransition(string.Format("T{0}", Canvas.TransitionCounter), "", 0);
            Canvas.TransitionCounter++;

            classitem.X = p.X;
            classitem.Y = p.Y;

            //classitem.Initialize();

            AddCanvasItem(classitem);
            Canvas.Refresh();
            SetDirty();
        }
Ejemplo n.º 3
0
        private string GetState(PNTransition transition)
        {
            StringBuilder sb = new StringBuilder();
            Dictionary<PNPlace, int> ins = new Dictionary<PNPlace, int>();
            Dictionary<PNPlace, int> outs = new Dictionary<PNPlace, int>();
            List<PNArc> arcs = GetArcList();

            foreach (var arc in arcs)
            {
                if (arc.To is PNTransition && (arc.To as PNTransition).Name.Equals(transition.Name))
                    ins.Add(arc.From as PNPlace, arc.Weight);

                if (arc.From is PNTransition && (arc.From as PNTransition).Name.Equals(transition.Name))
                    outs.Add(arc.To as PNPlace, arc.Weight);
            }

            List<string> guards = new List<string>();
            List<string> updates = new List<string>();
            foreach (KeyValuePair<PNPlace, int> kvp in ins)
            {
                guards.Add(string.Format("({0} >= {1})", kvp.Key.Name, kvp.Value));
                if (!string.IsNullOrEmpty(kvp.Key.Guard))
                    guards.Add(kvp.Key.Guard);

                updates.Add(string.Format("{0} = ({0} - {1}); ", kvp.Key.Name, kvp.Value));
            }

            foreach (KeyValuePair<PNPlace, int> kvp in outs)
            {
                if (kvp.Key.Capacity > 0)
                    guards.Add(string.Format("({0} + {1} <= {2})", kvp.Key.Name, kvp.Value, kvp.Key.Capacity));

                updates.Add(string.Format("{0} = ({0} + {1}); ", kvp.Key.Name, kvp.Value));
            }

            if (!string.IsNullOrEmpty(transition.Guard))
                guards.Add(transition.Guard);

            if (!string.IsNullOrEmpty(transition.Program))
                updates.Add(transition.Program);

            ins.Clear();
            outs.Clear();

            string guard = string.Empty;
            string update = string.Empty;
            for (int i = 0; i < guards.Count; i++)
            {
                if (i == (guards.Count - 1))
                {
                    guard += guards[i];
                    continue;
                }

                guard += guards[i] + " && ";
            }

            foreach (var str in updates)
                update += str;

            sb.AppendFormat("\"Start\"--[{0}] ##@@ {1} @@## {{{2}}}-->\"End\"", guard, transition.Name, update);

            return sb.ToString();
        }
Ejemplo n.º 4
0
        public override void LoadFromXml(XmlElement elem)
        {
            Node.Text = elem.GetAttribute(NAME_PROCESS_NODE_NAME, "");
            Console.Write(Node.Text);
            Parameters = elem.GetAttribute(PARAMETER_NODE_NAME, "");
            Console.Write(Parameters);
            Zoom = float.Parse(elem.GetAttribute(ZOOM_PROCESS_NODE_NAME, ""));
            PlaceCounter = int.Parse(elem.GetAttribute(PLACE_COUNTER));
            TransitionCounter = int.Parse(elem.GetAttribute(TRANSITION_COUNTER));

            int color = 0;

            // --replace by lqvu--
            //XmlElement topologyElement = (XmlElement)elem.ChildNodes[0];
            //LoadTopologyElement(topologyElement);
            // --
            int id = 0;
            if (elem.ChildNodes.Count == 4)
            {
                XmlElement topologyElement = (XmlElement)elem.ChildNodes[id++];
                LoadTopologyElement(topologyElement);
            }
            // --

            XmlElement placesElement = (XmlElement)elem.ChildNodes[id++];
            foreach (XmlElement element in placesElement.ChildNodes)
            {
                string elementId = element.GetAttribute(XmlTag.TAG_REFERENCE_ID);
                if (this.mSensors.Exists(x => x.ID == elementId)) color = 1;
                if (this.mChannels.Exists(x => x.ID == elementId)) color = -1;
                PNPlace place = new PNPlace(string.Empty, 0, elementId, color);
                place.LoadFromXml(element);
                this.AddSingleCanvasItem(place);
                this.AddSingleCanvasItem(place.labelItems);
            }

            XmlElement transitionsElement = (XmlElement)elem.ChildNodes[id++];
            foreach (XmlElement element in transitionsElement.ChildNodes)
            {
                string elementId = element.GetAttribute(XmlTag.TAG_REFERENCE_ID);
                if (this.mSensors.Exists(x => x.ID == elementId)) color = 1;
                if (this.mChannels.Exists(x => x.ID == elementId)) color = -1;

                String nameProp = element.GetAttribute("Name");
                if (nameProp != null && nameProp.Length > 3 && nameProp.Substring(0, 4) == "Conn")
                    color = 2;

                PNTransition transition = new PNTransition(string.Empty, elementId, color);
                transition.LoadFromXml(element);
                this.AddSingleCanvasItem(transition);
                this.AddSingleCanvasItem(transition.labelItems);
            }

            XmlElement linksElement = (XmlElement)elem.ChildNodes[id++];
            foreach (XmlElement element in linksElement.ChildNodes)
            {
                PNArc arc = new PNArc(null, null);
                arc.LoadFromXML(element, this);

                this.AddSingleLink(arc);
                foreach (NailItem nailItem in arc.Nails)
                {
                    this.AddSingleCanvasItem(nailItem);
                }

                this.AddSingleCanvasItem(arc.Label);
            }
        }
Ejemplo n.º 5
0
        public override void LoadFromXml(XmlElement elem)
        {
            Node.Text = elem.GetAttribute(NAME_PROCESS_NODE_NAME, "");
            Console.Write(Node.Text);
            Parameters = elem.GetAttribute(PARAMETER_NODE_NAME, "");
            Console.Write(Parameters);
            Zoom              = float.Parse(elem.GetAttribute(ZOOM_PROCESS_NODE_NAME, ""));
            PlaceCounter      = int.Parse(elem.GetAttribute(PLACE_COUNTER));
            TransitionCounter = int.Parse(elem.GetAttribute(TRANSITION_COUNTER));

            int color = 0;

            // --replace by lqvu--
            //XmlElement topologyElement = (XmlElement)elem.ChildNodes[0];
            //LoadTopologyElement(topologyElement);
            // --
            int id = 0;

            if (elem.ChildNodes.Count == 4)
            {
                XmlElement topologyElement = (XmlElement)elem.ChildNodes[id++];
                LoadTopologyElement(topologyElement);
            }
            // --

            XmlElement placesElement = (XmlElement)elem.ChildNodes[id++];

            foreach (XmlElement element in placesElement.ChildNodes)
            {
                string elementId = element.GetAttribute(XmlTag.TAG_REFERENCE_ID);
                if (this.mSensors.Exists(x => x.ID == elementId))
                {
                    color = 1;
                }
                if (this.mChannels.Exists(x => x.ID == elementId))
                {
                    color = -1;
                }
                PNPlace place = new PNPlace(string.Empty, 0, elementId, color);
                place.LoadFromXml(element);
                this.AddSingleCanvasItem(place);
                this.AddSingleCanvasItem(place.labelItems);
            }

            XmlElement transitionsElement = (XmlElement)elem.ChildNodes[id++];

            foreach (XmlElement element in transitionsElement.ChildNodes)
            {
                string elementId = element.GetAttribute(XmlTag.TAG_REFERENCE_ID);
                if (this.mSensors.Exists(x => x.ID == elementId))
                {
                    color = 1;
                }
                if (this.mChannels.Exists(x => x.ID == elementId))
                {
                    color = -1;
                }

                String nameProp = element.GetAttribute("Name");
                if (nameProp != null && nameProp.Length > 3 && nameProp.Substring(0, 4) == "Conn")
                {
                    color = 2;
                }

                PNTransition transition = new PNTransition(string.Empty, elementId, color);
                transition.LoadFromXml(element);
                this.AddSingleCanvasItem(transition);
                this.AddSingleCanvasItem(transition.labelItems);
            }

            XmlElement linksElement = (XmlElement)elem.ChildNodes[id++];

            foreach (XmlElement element in linksElement.ChildNodes)
            {
                PNArc arc = new PNArc(null, null);
                arc.LoadFromXML(element, this);

                this.AddSingleLink(arc);
                foreach (NailItem nailItem in arc.Nails)
                {
                    this.AddSingleCanvasItem(nailItem);
                }

                this.AddSingleCanvasItem(arc.Label);
            }
        }
Ejemplo n.º 6
0
        private string GetState(PNTransition transition)
        {
            StringBuilder             sb   = new StringBuilder();
            Dictionary <PNPlace, int> ins  = new Dictionary <PNPlace, int>();
            Dictionary <PNPlace, int> outs = new Dictionary <PNPlace, int>();
            List <PNArc> arcs = GetArcList();

            foreach (var arc in arcs)
            {
                if (arc.To is PNTransition && (arc.To as PNTransition).Name.Equals(transition.Name))
                {
                    ins.Add(arc.From as PNPlace, arc.Weight);
                }

                if (arc.From is PNTransition && (arc.From as PNTransition).Name.Equals(transition.Name))
                {
                    outs.Add(arc.To as PNPlace, arc.Weight);
                }
            }

            List <string> guards  = new List <string>();
            List <string> updates = new List <string>();

            foreach (KeyValuePair <PNPlace, int> kvp in ins)
            {
                guards.Add(string.Format("({0} >= {1})", kvp.Key.Name, kvp.Value));
                if (!string.IsNullOrEmpty(kvp.Key.Guard))
                {
                    guards.Add(kvp.Key.Guard);
                }

                updates.Add(string.Format("{0} = ({0} - {1}); ", kvp.Key.Name, kvp.Value));
            }

            foreach (KeyValuePair <PNPlace, int> kvp in outs)
            {
                if (kvp.Key.Capacity > 0)
                {
                    guards.Add(string.Format("({0} + {1} <= {2})", kvp.Key.Name, kvp.Value, kvp.Key.Capacity));
                }

                updates.Add(string.Format("{0} = ({0} + {1}); ", kvp.Key.Name, kvp.Value));
            }

            if (!string.IsNullOrEmpty(transition.Guard))
            {
                guards.Add(transition.Guard);
            }

            if (!string.IsNullOrEmpty(transition.Program))
            {
                updates.Add(transition.Program);
            }

            ins.Clear();
            outs.Clear();

            string guard  = string.Empty;
            string update = string.Empty;

            for (int i = 0; i < guards.Count; i++)
            {
                if (i == (guards.Count - 1))
                {
                    guard += guards[i];
                    continue;
                }

                guard += guards[i] + " && ";
            }

            foreach (var str in updates)
            {
                update += str;
            }

            sb.AppendFormat("\"Start\"--[{0}] ##@@ {1} @@## {{{2}}}-->\"End\"", guard, transition.Name, update);

            return(sb.ToString());
        }