示例#1
0
        private void PlaceOutput_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            // Draws Place object
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle           r   = this.ClientRectangle;
            LinearGradientBrush lgb = new LinearGradientBrush(r, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);

            // Draw on background a letter which describes PlaceType
            StringFormat sfo = new StringFormat();

            sfo.LineAlignment = StringAlignment.Center;
            sfo.Alignment     = StringAlignment.Center;

            Font fo = new Font(this.Parent.Font.FontFamily, pne.Zoom * 10f, FontStyle.Bold);

            Pen pSign = new Pen(Color.Black, 3 * pne.Zoom);

            Point[] pa = new Point[4]
            {
                new Point((int)(64 * pne.Zoom), (int)(30 * pne.Zoom)),
                new Point((int)(54 * pne.Zoom), (int)(30 * pne.Zoom)),
                new Point((int)(54 * pne.Zoom), (int)(44 * pne.Zoom)),
                new Point((int)(64 * pne.Zoom), (int)(44 * pne.Zoom)),
            };
            g.DrawLines(pSign, pa);

            pSign.CustomEndCap = new AdjustableArrowCap(4 * pne.Zoom, 3 * pne.Zoom, true);
            pSign.Width        = (int)(2 * pne.Zoom);
            g.DrawLine(pSign, new Point((int)(57 * pne.Zoom), (int)(37 * pne.Zoom)), new Point((int)(67 * pne.Zoom), (int)(37 * pne.Zoom)));

            g.FillRectangle(lgb, r);

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 7);

            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("P" + sIndex, f, bBlack, new RectangleF(new PointF(0f, this.Height - pne.Zoom * 23f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(this.sName, f, bBlack, new RectangleF(new PointF(0f, pne.Zoom * 6f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            RectangleF rTokens = new RectangleF(new PointF(0f, 0f), new SizeF(this.Width, this.Height));

            this.DrawTokens(g, bBlack, rTokens, sf);
        }
示例#2
0
        private void Output_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle           r   = this.ClientRectangle;
            LinearGradientBrush lgb = new LinearGradientBrush(r, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);

            g.FillRectangle(lgb, r);

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 7);

            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("Out" + sIndex, f, bBlack, r, sf);
        }
示例#3
0
        public Point GetTopLeftPointOfOutputPort(int iPortNumber)
        {
            if (this.Parent is PetriNetEditor)
            {
                PetriNetEditor pne = (PetriNetEditor)this.Parent;

                Port pFound = null;
                foreach (Port p in this.alOutputPorts)
                {
                    if (p.PortNumber == iPortNumber)
                    {
                        pFound = p;
                        break;
                    }
                }

                // Scale to Port Bounds
                if (pFound != null)
                {
                    RectangleF rf = pFound.PortRegion.GetBounds(this.CreateGraphics());
                    return(new Point((int)(rf.X * 1 / pne.Zoom), (int)(rf.Y * 1 / pne.Zoom)));
                }
            }
            return(Point.Empty);
        }
示例#4
0
文件: Place.cs 项目: wbadry/Petri.Net
        public void DrawTokens(Graphics g, Brush b, RectangleF r, StringFormat sf)
        {
            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            // Draw tokens
            if (this.iTokens == 1)
            {
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 4, r.Y + this.Height / 2 - pne.Zoom * 4, pne.Zoom * 8, pne.Zoom * 8);
            }
            else if (this.iTokens == 2)
            {
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 4, r.Y + this.Height / 2 - pne.Zoom * 10, pne.Zoom * 8, pne.Zoom * 8);
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 4, r.Y + this.Height / 2 + pne.Zoom * 2, pne.Zoom * 8, pne.Zoom * 8);
            }
            else if (this.iTokens == 3)
            {
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 4, r.Y + this.Height / 2 - pne.Zoom * 10, pne.Zoom * 8, pne.Zoom * 8);
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 10, r.Y + this.Height / 2 + pne.Zoom * 2, pne.Zoom * 8, pne.Zoom * 8);
                g.FillEllipse(b, r.X + this.Width / 2 + pne.Zoom * 2, r.Y + this.Height / 2 + pne.Zoom * 2, pne.Zoom * 8, pne.Zoom * 8);
            }
            else if (this.iTokens == 4)
            {
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 10, r.Y + this.Height / 2 - pne.Zoom * 10, pne.Zoom * 8, pne.Zoom * 8);
                g.FillEllipse(b, r.X + this.Width / 2 + pne.Zoom * 2, r.Y + this.Height / 2 - pne.Zoom * 10, pne.Zoom * 8, pne.Zoom * 8);
                g.FillEllipse(b, r.X + this.Width / 2 - pne.Zoom * 10, r.Y + this.Height / 2 + pne.Zoom * 2, pne.Zoom * 8, pne.Zoom * 8);
                g.FillEllipse(b, r.X + this.Width / 2 + pne.Zoom * 2, r.Y + this.Height / 2 + pne.Zoom * 2, pne.Zoom * 8, pne.Zoom * 8);
            }
            else if (this.iTokens < 0 || this.iTokens > 4)
            {
                Font fTokens = new Font(this.Parent.Font.FontFamily, pne.Zoom * 12f, FontStyle.Bold);
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                g.DrawString(this.iTokens.ToString(), fTokens, b, r, sf);
            }
        }
示例#5
0
        private void Subsystem_Paint(object sender, PaintEventArgs e)
        {
            // Draws Subsystem object
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle rect = this.ClientRectangle;

            LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);

            g.FillRectangle(lgb, rect);

            Pen pBlack = new Pen(this.cBorderColor, pne.Zoom * 5);

            g.DrawRectangle(pBlack, 0, 0, this.Width - 1, this.Height - 1);

            g.FillRegion(Brushes.Red, this.ConnectableInputRegion);
            g.FillRegion(Brushes.Red, this.ConnectableOutputRegion);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            string sText = (this.sName != "") ? this.sName + "\n\n" + "S" + this.sIndex : "S" + this.sIndex.ToString();

            g.DrawString(sText, f, bBlack, new Rectangle(new Point(0, 0), new Size(this.Width - (int)(pne.Zoom * 2), this.Height)), sf);

            foreach (object o in this.htInputGraphicsPaths.Keys)
            {
                GraphicsPath gp = (GraphicsPath)this.htInputGraphicsPaths[o];
                g.DrawPath(Pens.Black, gp);

                string sIndex = ((Input)o).Index.ToString();
                Point  p      = (Point)this.htInputInputPoints[o];

                g.DrawString(sIndex, f, bBlack, p, sf);
            }

            foreach (object o in this.htOutputGraphicsPaths.Keys)
            {
                GraphicsPath gp = (GraphicsPath)this.htOutputGraphicsPaths[o];
                g.DrawPath(Pens.Black, gp);

                string sIndex = ((Output)o).Index.ToString();
                Point  p      = (Point)this.htOutputOutputPoints[o];

                g.DrawString(sIndex, f, bBlack, p, sf);
            }
        }
        private void SelectableAndMovableControl_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            // This function is used to reset PetriNetEditor PressedKey property to None
            // on KeyUp event. This is used for selection of objects with Shift key

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            pne.PressedKey = Keys.None;
        }
示例#7
0
        private void PlaceResource_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            // Draws Place object
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle           r   = this.ClientRectangle;
            LinearGradientBrush lgb = new LinearGradientBrush(r, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);
            Brush bFill             = new LinearGradientBrush(r, Color.White, Color.Red, LinearGradientMode.ForwardDiagonal);

            // Draw on background a letter which describes PlaceType
            StringFormat sfo = new StringFormat();

            sfo.LineAlignment = StringAlignment.Center;
            sfo.Alignment     = StringAlignment.Center;

            Font fo = new Font(this.Parent.Font.FontFamily, pne.Zoom * 10f, FontStyle.Bold);

            g.DrawString("R", fo, Brushes.Black, new Rectangle(new Point((int)(42 * pne.Zoom), 0), new Size((int)(this.Width - 42 * pne.Zoom), this.Height)), sfo);

            g.FillRectangle(lgb, r);

            if (bShowCircularWaitings == true && pne.Document.CircularWaitingPlaces.Contains(this))
            {
                Pen pRoyalBlue = new Pen(Color.RoyalBlue, pne.Zoom * 7);
                g.DrawEllipse(pRoyalBlue, new Rectangle(r.X + (int)(4 * pne.Zoom), r.Y + (int)(4 * pne.Zoom), r.Width - (int)(8 * pne.Zoom), r.Height - (int)(8 * pne.Zoom)));
            }

            // For showing processing time of each place
            g.FillPie(bFill, r, -90f, 360f * ((float)this.iFillAngle / (float)this.iMaxFillAngle));

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 7);

            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("P" + sIndex, f, bBlack, new RectangleF(new PointF(0f, this.Height - pne.Zoom * 23f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(this.sName, f, bBlack, new RectangleF(new PointF(0f, pne.Zoom * 6f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            RectangleF rTokens = new RectangleF(new PointF(0f, 0f), new SizeF(this.Width, this.Height));

            this.DrawTokens(g, bBlack, rTokens, sf);
        }
示例#8
0
        public void DrawModel(Graphics g)
        {
            Point pt = this.Location;

            PetriNetEditor pne   = (PetriNetEditor)this.Parent;
            Rectangle      r     = new Rectangle(pt, this.Size);
            Brush          bFill = new LinearGradientBrush(r, Color.White, Color.Red, LinearGradientMode.ForwardDiagonal);

            g.FillEllipse(Brushes.White, r);

            // Draw on background a letter which describes PlaceType
            StringFormat sfo = new StringFormat();

            sfo.LineAlignment = StringAlignment.Center;
            sfo.Alignment     = StringAlignment.Center;

            Font fo = new Font(this.Parent.Font.FontFamily, pne.Zoom * 10f, FontStyle.Bold);

            Pen pSign = new Pen(Color.LightGray, 2 * pne.Zoom);

            Point[] pa = new Point[4]
            {
                new Point(pt.X + (int)(54 * pne.Zoom), pt.Y + (int)(30 * pne.Zoom)),
                new Point(pt.X + (int)(64 * pne.Zoom), pt.Y + (int)(30 * pne.Zoom)),
                new Point(pt.X + (int)(64 * pne.Zoom), pt.Y + (int)(44 * pne.Zoom)),
                new Point(pt.X + (int)(54 * pne.Zoom), pt.Y + (int)(44 * pne.Zoom)),
            };

            g.DrawLines(pSign, pa);

            pSign.CustomEndCap = new AdjustableArrowCap(4 * pne.Zoom, 3 * pne.Zoom, true);
            pSign.Width        = (int)(2 * pne.Zoom);
            g.DrawLine(pSign, new Point(pt.X + (int)(52 * pne.Zoom), pt.Y + (int)(37 * pne.Zoom)), new Point(pt.X + (int)(62 * pne.Zoom), pt.Y + (int)(37 * pne.Zoom)));

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 4);

            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("P" + iIndex.ToString(), f, bBlack, new RectangleF(new PointF(pt.X, pt.Y + this.Height - pne.Zoom * 23f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(this.sName, f, bBlack, new RectangleF(new PointF(pt.X, pt.Y + pne.Zoom * 6f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            RectangleF rTokens = new RectangleF(new PointF(pt.X, pt.Y), new SizeF(this.Width, this.Height));

            this.DrawTokens(g, bBlack, rTokens, sf);
        }
示例#9
0
        public void DrawModel(Graphics g)
        {
            Point pt = this.Location;

            PetriNetEditor pne   = (PetriNetEditor)this.Parent;
            Rectangle      r     = new Rectangle(pt, this.Size);
            Brush          bFill = new LinearGradientBrush(r, Color.White, Color.Red, LinearGradientMode.ForwardDiagonal);

            g.FillEllipse(Brushes.White, r);

            // Draw on background a letter which describes PlaceType
            StringFormat sfo = new StringFormat();

            sfo.LineAlignment = StringAlignment.Center;
            sfo.Alignment     = StringAlignment.Center;

            Font fo = new Font(this.Parent.Font.FontFamily, pne.Zoom * 10f, FontStyle.Bold);

            g.DrawString("R", fo, Brushes.LightGray, new Rectangle(new Point(pt.X + (int)(42 * pne.Zoom), pt.Y), new Size((int)(this.Width - 42 * pne.Zoom), this.Height)), sfo);

            if (bShowCircularWaitings == true && pne.Document.CircularWaitingPlaces.Contains(this))
            {
                Pen pRoyalBlue = new Pen(Color.RoyalBlue, pne.Zoom * 4);
                g.DrawEllipse(pRoyalBlue, new Rectangle(pt.X + (int)(4 * pne.Zoom), pt.Y + (int)(4 * pne.Zoom), r.Width - (int)(8 * pne.Zoom), r.Height - (int)(8 * pne.Zoom)));
            }

            // For showing processing time of each place
            g.FillPie(bFill, r, -90f, 360f * ((float)this.iFillAngle / (float)this.iMaxFillAngle));

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 4);

            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("P" + iIndex.ToString(), f, bBlack, new RectangleF(new PointF(pt.X, pt.Y + this.Height - pne.Zoom * 23f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(this.sName, f, bBlack, new RectangleF(new PointF(pt.X, pt.Y + pne.Zoom * 6f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            RectangleF rTokens = new RectangleF(new PointF(pt.X, pt.Y), new SizeF(this.Width, this.Height));

            this.DrawTokens(g, bBlack, rTokens, sf);
        }
示例#10
0
        private void PlaceControl_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            // Draws Place object
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle           r   = this.ClientRectangle;
            LinearGradientBrush lgb = new LinearGradientBrush(r, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);

            // Draw on background a letter which describes PlaceType
            StringFormat sfo = new StringFormat();

            sfo.LineAlignment = StringAlignment.Center;
            sfo.Alignment     = StringAlignment.Center;

            Font fo = new Font(this.Parent.Font.FontFamily, pne.Zoom * 10f, FontStyle.Bold);

            g.FillRectangle(lgb, r);

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 7);

            g.DrawEllipse(pBlack, r);

            // Draw ellipse for Control Place
            g.DrawEllipse(new Pen(Color.Black, pne.Zoom * 2f), new Rectangle(new Point((int)(pne.Zoom * 6), (int)(pne.Zoom * 6)), new Size((int)(this.DefaultSize.Width * pne.Zoom - 2 * (int)(pne.Zoom * 6)), (int)(this.DefaultSize.Height * pne.Zoom - 2 * (int)(pne.Zoom * 6)))));

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("P" + sIndex, f, bBlack, new RectangleF(new PointF(0f, this.Height - pne.Zoom * 23f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(this.sName, f, bBlack, new RectangleF(new PointF(0f, pne.Zoom * 6f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            RectangleF rTokens = new RectangleF(new PointF(0f, 0f), new SizeF(this.Width, this.Height));

            this.DrawTokens(g, bBlack, rTokens, sf);
        }
示例#11
0
        private void Transition_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            // Draws Transition object
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle rect = this.ClientRectangle;

            // Get background color based on properties
            cBackgroundColor = this.GetBackgroundColor();

            LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);

            g.FillRectangle(lgb, rect);

            if (bShowConflicts == true && this.IsConflicting())
            {
                Pen pRed = new Pen(Color.Red, pne.Zoom * 7);
                g.DrawRectangle(pRed, new Rectangle(rect.X + (int)(3 * pne.Zoom), rect.Y + (int)(3 * pne.Zoom), rect.Width - (int)(6 * pne.Zoom), rect.Height - (int)(6 * pne.Zoom)));
            }

            Pen pBlack = new Pen(this.cBorderColor, pne.Zoom * 5);

            g.DrawRectangle(pBlack, 0, 0, this.Width - 1, this.Height - 1);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            if (this.Orientation == ControlOrientation.Vertical)
            {
                sf.FormatFlags = StringFormatFlags.DirectionVertical;
            }

            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("T" + this.sIndex, f, bBlack, new Rectangle(new Point(0, 0), new Size(this.Width - (int)(pne.Zoom * 2), this.Height)), sf);
        }
示例#12
0
        private void DescriptionLabel_Paint(object sender, PaintEventArgs e)
        {
            // Draws DescriptionLabel object
            Graphics g = e.Graphics;

            if (PetriNetDocument.AntiAlias == true)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Rectangle rect = this.ClientRectangle;

            LinearGradientBrush lgb = null;

            if (this.cBackgroundColor == this.cActiveColor)
            {
                lgb = new LinearGradientBrush(rect, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);
            }
            else
            {
                lgb = new LinearGradientBrush(rect, this.cBackgroundColor, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);
            }

            g.FillRectangle(lgb, rect);

            Pen pBlack = new Pen(this.cBorderColor, pne.Zoom * 2);

            g.DrawRectangle(pBlack, 0, 0, this.Width - 1, this.Height - 1);

            Brush        bBlack = new SolidBrush(this.cTextColor);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            Font f = new Font(this.fntTextFont.FontFamily, pne.Zoom * this.fntTextFont.Size, this.fntTextFont.Style);

            g.DrawString(this.Text, f, bBlack, new Rectangle(new Point(0, 0), new Size(this.Width - (int)(pne.Zoom * 2), this.Height)), sf);
        }
示例#13
0
        public void DrawModel(Graphics g)
        {
            Point pt = this.Location;

            PetriNetEditor pne   = (PetriNetEditor)this.Parent;
            Rectangle      r     = new Rectangle(pt, this.Size);
            Brush          bFill = new LinearGradientBrush(r, Color.White, Color.Red, LinearGradientMode.ForwardDiagonal);

            g.FillEllipse(Brushes.White, r);

            // Draw on background a letter which describes PlaceType
            StringFormat sfo = new StringFormat();

            sfo.LineAlignment = StringAlignment.Center;
            sfo.Alignment     = StringAlignment.Center;

            Font fo = new Font(this.Parent.Font.FontFamily, pne.Zoom * 10f, FontStyle.Bold);

            // Draw ellipse for Control Place
            g.DrawEllipse(new Pen(Color.Black, pne.Zoom * 2f), new Rectangle(new Point(pt.X + (int)(pne.Zoom * 6), pt.Y + (int)(pne.Zoom * 6)), new Size((int)(this.DefaultSize.Width * pne.Zoom - 2 * (int)(pne.Zoom * 6)), (int)(this.DefaultSize.Height * pne.Zoom - 2 * (int)(pne.Zoom * 6)))));

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 4);

            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("P" + iIndex.ToString(), f, bBlack, new RectangleF(new PointF(pt.X, pt.Y + this.Height - pne.Zoom * 23f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(this.sName, f, bBlack, new RectangleF(new PointF(pt.X, pt.Y + pne.Zoom * 6f), new SizeF(this.Width, pne.Zoom * 20f)), sf);

            sf.LineAlignment = StringAlignment.Center;
            RectangleF rTokens = new RectangleF(new PointF(pt.X, pt.Y), new SizeF(this.Width, this.Height));

            this.DrawTokens(g, bBlack, rTokens, sf);
        }
示例#14
0
        public void DrawModel(Graphics g)
        {
            Point     pt = this.Location;
            Rectangle r  = new Rectangle(pt, this.Size);

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            Pen pBlack = new Pen(Color.Black, pne.Zoom * 4);

            g.FillEllipse(Brushes.White, r);
            g.DrawEllipse(pBlack, r);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("Out" + sIndex, f, bBlack, r, sf);
        }
示例#15
0
        public void DrawModel(Graphics g)
        {
            Point pt = this.Location;

            PetriNetEditor pne = (PetriNetEditor)this.Parent;
            Rectangle      r   = new Rectangle(pt, this.Size);

//			g.FillRectangle(new SolidBrush(SystemColors.Info), r);
//
//			Pen pBlack = new Pen(this.cBorderColor, pne.Zoom * 2);
//			g.DrawRectangle(pBlack, r);

            Brush        bBlack = new SolidBrush(this.cTextColor);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            Font f = new Font(this.fntTextFont.FontFamily, pne.Zoom * this.fntTextFont.Size, this.fntTextFont.Style);

            g.DrawString(this.Text, f, bBlack, new Rectangle(new Point(pt.X, pt.Y), new Size(this.Width - (int)(pne.Zoom * 2), this.Height)), sf);
        }
示例#16
0
        public static Metafile SaveMetafile(Stream stream, PetriNetEditor pne)
        {
            float fZoom = pne.Zoom;

            Graphics g  = pne.CreateGraphics();
            IntPtr   ip = g.GetHdc();
            Metafile mf = new Metafile(stream, ip);

            g.ReleaseHdc(ip);
            g.Dispose();

            Graphics gg = Graphics.FromImage(mf);

            if (PetriNetDocument.AntiAlias == true)
            {
                gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            }

            //Draw all Connections
            foreach (Connection cn in pne.Connections)
            {
                cn.DrawConnection(gg, pne, Color.Black, Color.Red);
            }

            // Draw all Objects
            foreach (object o in pne.Objects)
            {
                if (o is IMetafileModel)
                {
                    IMetafileModel imm = (IMetafileModel)o;
                    imm.DrawModel(gg);
                }
            }


            gg.Dispose();

            return(mf);
        }
        protected void SelectableAndMovableControl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Remembers point where mouse was clicked in Place control
            ptMouseDragOffset = new Point(e.X, e.Y);

            // Remembers initial Location
            this.ptInitialLocation = this.Location;

            // Enables mouse capture
            this.Capture = true;

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            // if this condition is true allow selecting object, else moving objects is available
            if (!pne.SelectedObjects.Contains(this) || pne.PressedKey == Keys.ShiftKey)
            {
                if (this.SelectionChanged != null)
                {
                    this.SelectionChanged(this, new SelectionEventArgs(pne.PressedKey));
                }
            }

            // Remember all objects in selection initial positions for Undo/Redo
            this.alObjects.Clear();
            this.alOldValues.Clear();
            foreach (object o in pne.SelectedObjects)
            {
                if (o is SelectableAndMovableControl)
                {
                    this.alObjects.Add(o);

                    SelectableAndMovableControl smac = (SelectableAndMovableControl)o;
                    this.alOldValues.Add(smac.Location);
                }
            }

            // Brings control to top of z-order
            this.BringToFront();
        }
示例#18
0
        public void DrawModel(Graphics g)
        {
            Point pt = this.Location;

            PetriNetEditor pne = (PetriNetEditor)this.Parent;
            Rectangle      r   = new Rectangle(pt, this.Size);

            LinearGradientBrush lgb = new LinearGradientBrush(r, Color.White, this.cBackgroundColor, LinearGradientMode.ForwardDiagonal);

            Brush bBack = (bShowFireableTransitions == true && this.CanFire()) ? lgb : Brushes.White;

            g.FillRectangle(bBack, r);

            if (bShowConflicts == true && this.IsConflicting())
            {
                Pen pRed = new Pen(Color.Red, pne.Zoom * 4);
                g.DrawRectangle(pRed, new Rectangle(r.X + (int)(3 * pne.Zoom), r.Y + (int)(3 * pne.Zoom), r.Width - (int)(6 * pne.Zoom), r.Height - (int)(6 * pne.Zoom)));
            }

            Pen pBlack = new Pen(this.cBorderColor, pne.Zoom * 3);

            g.DrawRectangle(pBlack, pt.X, pt.Y, this.Width, this.Height);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            if (this.Orientation == ControlOrientation.Vertical)
            {
                sf.FormatFlags = StringFormatFlags.DirectionVertical;
            }

            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            g.DrawString("T" + this.sIndex, f, bBlack, new Rectangle(new Point(pt.X, pt.Y), new Size(this.Width - (int)(pne.Zoom * 2), this.Height)), sf);
        }
示例#19
0
        private void ConnectableControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.Capture == true && e.Button == MouseButtons.Right)
            {
                PetriNetEditor pne = (PetriNetEditor)this.Parent;
                Panel          pnl = (Panel)pne.Parent;

                Point ptBegin = this.PointToScreen(ptMouseDragOffset);
                ptBegin         = pne.PointToClient(ptBegin);
                pne.ptDragBegin = ptBegin;

                Point ptEnd = this.PointToScreen(new Point(e.X, e.Y));
                ptEnd         = pne.PointToClient(ptEnd);
                pne.ptDragEnd = ptEnd;

                Control cBegin = this.GetChildAtPoint(ptBegin);
                Control cEnd   = this.GetChildAtPoint(ptEnd);

                Point ptNewScrollPosition = new Point(0, 0);
                if (ptEnd.X < -pnl.AutoScrollPosition.X || ptEnd.Y < -pnl.AutoScrollPosition.Y)
                {
                    ptNewScrollPosition    = new Point(Math.Min(ptEnd.X, -pnl.AutoScrollPosition.X), Math.Min(ptEnd.Y, -pnl.AutoScrollPosition.Y));
                    pnl.AutoScrollPosition = ptNewScrollPosition;
                }
                else if (ptEnd.X > (pnl.Width - 25 - pnl.AutoScrollPosition.X) || ptEnd.Y > (pnl.Height + 15 - pnl.AutoScrollPosition.Y))
                {
                    ptNewScrollPosition    = new Point(Math.Max(ptEnd.X - pnl.Width + 25, -pnl.AutoScrollPosition.X), Math.Min(ptEnd.Y - pnl.Height + 15, -pnl.AutoScrollPosition.Y));
                    pnl.AutoScrollPosition = ptNewScrollPosition;
                }
                else if (ptEnd.X > (pnl.Width - 25 - pnl.AutoScrollPosition.X) || ptEnd.Y > (pnl.Height - 15 - pnl.AutoScrollPosition.Y))
                {
                    ptNewScrollPosition    = new Point(Math.Max(ptEnd.X - pnl.Width + 25, -pnl.AutoScrollPosition.X), Math.Max(ptEnd.Y - pnl.Height + 15, -pnl.AutoScrollPosition.Y));
                    pnl.AutoScrollPosition = ptNewScrollPosition;
                }

                pne.Refresh();
            }
        }
示例#20
0
        public void DrawModel(Graphics g)
        {
            Point pt = this.Location;

            PetriNetEditor pne = (PetriNetEditor)this.Parent;
            Rectangle      r   = new Rectangle(pt, this.Size);

            g.FillRectangle(Brushes.White, r);

            Pen pBlack = new Pen(this.cBorderColor, pne.Zoom * 3);

            g.DrawRectangle(pBlack, pt.X, pt.Y, this.Width - 1, this.Height - 1);

            Region ri = this.ConnectableInputRegion.Clone();
            Region ro = this.ConnectableOutputRegion.Clone();

            ri.Translate(pt.X, pt.Y);
            ro.Translate(pt.X, pt.Y);

            g.FillRegion(Brushes.Red, ri);
            g.FillRegion(Brushes.Red, ro);

            Brush        bBlack = new SolidBrush(Color.Black);
            StringFormat sf     = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            Font f = new Font(this.Parent.Font.FontFamily, pne.Zoom * 7f, FontStyle.Bold);

            string sText = (this.sName != "") ? this.sName + "\n\n" + "S" + this.sIndex : "S" + this.sIndex.ToString();

            g.DrawString(sText, f, bBlack, new Rectangle(new Point(pt.X, pt.Y), new Size(this.Width - (int)(pne.Zoom * 2), this.Height)), sf);

            foreach (object o in this.htInputGraphicsPaths.Keys)
            {
                GraphicsPath gp = (GraphicsPath)((GraphicsPath)this.htInputGraphicsPaths[o]).Clone();
                System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                m.Translate(pt.X, pt.Y);
                gp.Transform(m);
                g.DrawPath(Pens.Black, gp);

                string sIndex = ((Input)o).Index.ToString();
                Point  p      = (Point)this.htInputInputPoints[o];

                p.X += pt.X - (int)(pne.Zoom * 5f);
                p.Y += pt.Y - (int)(pne.Zoom * 7f);

                g.DrawString(sIndex, f, bBlack, p);
            }

            foreach (object o in this.htOutputGraphicsPaths.Keys)
            {
                GraphicsPath gp = (GraphicsPath)((GraphicsPath)this.htOutputGraphicsPaths[o]).Clone();
                System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                m.Translate(pt.X, pt.Y);
                gp.Transform(m);
                g.DrawPath(Pens.Black, gp);

                string sIndex = ((Output)o).Index.ToString();
                Point  p      = (Point)this.htOutputOutputPoints[o];

                p.X += pt.X - (int)(pne.Zoom * 5f);
                p.Y += pt.Y - (int)(pne.Zoom * 7f);

                g.DrawString(sIndex, f, bBlack, p);
            }
        }
示例#21
0
        public void AdjustConnectableRegions()
        {
            if (this.Parent is PetriNetEditor)
            {
                PetriNetEditor pne = (PetriNetEditor)this.Parent;

                this.alInputPorts.Clear();
                this.alOutputPorts.Clear();

                ArrayList alInputPoints  = new ArrayList();
                ArrayList alOutputPoints = new ArrayList();
                ArrayList alInputs       = new ArrayList();
                ArrayList alOutputs      = new ArrayList();

                int iX      = int.MaxValue;
                int iY      = int.MaxValue;
                int iWidth  = 0;
                int iHeight = 0;

                int iHalfArrowWidth = (int)(7 * pne.Zoom);

                foreach (object o in this.Objects)
                {
                    SelectableAndMovableControl smac = (SelectableAndMovableControl)o;

                    if (o is Input)
                    {
                        alInputs.Add(o);
                        alInputPoints.Add(smac.Location);
                    }
                    if (o is Output)
                    {
                        alOutputs.Add(o);
                        alOutputPoints.Add(smac.Location);
                    }

                    if (smac.Location.X < iX)
                    {
                        iX = smac.Location.X;
                    }
                    if (smac.Location.Y < iY)
                    {
                        iY = smac.Location.Y;
                    }
                    if (smac.Location.X + smac.Width > iWidth)
                    {
                        iWidth = smac.Location.X + smac.Width;
                    }
                    if (smac.Location.Y + smac.Height > iHeight)
                    {
                        iHeight = smac.Location.Y + smac.Height;
                    }
                }

                Rectangle rect = new Rectangle(iX, iY, iWidth - iX, iHeight - iY);

                // Transform rect coordinates in client coordinates
                float iXScaler = (float)(this.Size.Width) / (float)rect.Width;
                float iYScaler = (float)(this.Size.Height) / (float)rect.Height;

                // Smaller rect
                float iXScaler2 = (float)(this.Width - 20 * pne.Zoom) / (float)this.Width;
                float iYScaler2 = (float)(this.Height - 20 * pne.Zoom) / (float)this.Height;

                GraphicsPath gpInputs  = new GraphicsPath();
                GraphicsPath gpOutputs = new GraphicsPath();

                this.htInputGraphicsPaths.Clear();
                this.htInputInputPoints.Clear();
                this.htOutputGraphicsPaths.Clear();
                this.htOutputOutputPoints.Clear();

                for (int i = 0; i < alInputPoints.Count; i++)
                {
                    object o = alInputPoints[i];

                    Point p = (Point)o;
                    p.X -= iX;
                    p.Y -= iY;

                    Point         pFixed = this.GetFixedPoint(p, rect);
                    LineDirection ldEnd  = this.GetDirection(p, this.GetCenterPoint(p, rect), rect);

                    p = pFixed;

                    p.X = (int)(p.X * iXScaler);
                    p.Y = (int)(p.Y * iYScaler);

                    //Scale to smaller rect
                    p.X = (int)((p.X) * iXScaler2) + (int)(10 * pne.Zoom);
                    p.Y = (int)((p.Y) * iYScaler2) + (int)(10 * pne.Zoom);


                    GraphicsPath gp = new GraphicsPath();
                    if (ldEnd == LineDirection.Left)
                    {
                        gp.AddPolygon(new Point[] { new Point(0, p.Y - iHalfArrowWidth), new Point(iHalfArrowWidth, p.Y), new Point(0, p.Y + iHalfArrowWidth) });
                        p.X += 3;
                    }
                    if (ldEnd == LineDirection.Up)
                    {
                        gp.AddPolygon(new Point[] { new Point(p.X - iHalfArrowWidth, 0), new Point(p.X, iHalfArrowWidth), new Point(p.X + iHalfArrowWidth, 0) });
                        p.Y += 3;
                    }
                    if (ldEnd == LineDirection.Down)
                    {
                        gp.AddPolygon(new Point[] { new Point(p.X - iHalfArrowWidth, this.Height - 1), new Point(p.X, this.Height - 1 - iHalfArrowWidth), new Point(p.X + iHalfArrowWidth, this.Height - 1) });
                        p.Y -= 3;
                    }
                    if (ldEnd == LineDirection.Right)
                    {
                        gp.AddPolygon(new Point[] { new Point(this.Width - 1, p.Y - iHalfArrowWidth), new Point(this.Width - 1 - iHalfArrowWidth, p.Y), new Point(this.Width - 1, p.Y + iHalfArrowWidth) });
                        p.X -= 3;
                    }

                    this.htInputInputPoints.Add(alInputs[alInputPoints.IndexOf(o)], p);

                    gpInputs.AddPath(gp, false);
                    this.htInputGraphicsPaths.Add(alInputs[alInputPoints.IndexOf(o)], gp);

                    Port port = new Port(((Input)alInputs[i]).Index, new Region(gp));
                    this.alInputPorts.Add(port);
                }

                for (int i = 0; i < alOutputPoints.Count; i++)
                {
                    object o = alOutputPoints[i];

                    Point p = (Point)o;
                    p.X -= iX;
                    p.Y -= iY;

                    Point         pFixed = this.GetFixedPoint(p, rect);
                    LineDirection ldEnd  = this.GetDirection(p, this.GetCenterPoint(p, rect), rect);

                    p = pFixed;

                    p.X = (int)(p.X * iXScaler);
                    p.Y = (int)(p.Y * iYScaler);

                    //Scale to smaller rect
                    p.X = (int)((p.X) * iXScaler2) + (int)(10 * pne.Zoom);
                    p.Y = (int)((p.Y) * iYScaler2) + (int)(10 * pne.Zoom);


                    GraphicsPath gp = new GraphicsPath();
                    if (ldEnd == LineDirection.Left)
                    {
                        gp.AddPolygon(new Point[] { new Point(iHalfArrowWidth, p.Y - iHalfArrowWidth), new Point(0, p.Y), new Point(iHalfArrowWidth, p.Y + iHalfArrowWidth) });
                        p.X += 3;
                    }
                    if (ldEnd == LineDirection.Up)
                    {
                        gp.AddPolygon(new Point[] { new Point(p.X - iHalfArrowWidth, iHalfArrowWidth), new Point(p.X, 0), new Point(p.X + iHalfArrowWidth, iHalfArrowWidth) });
                        p.Y += 3;
                    }
                    if (ldEnd == LineDirection.Down)
                    {
                        gp.AddPolygon(new Point[] { new Point(p.X - iHalfArrowWidth, this.Height - 1 - iHalfArrowWidth), new Point(p.X, this.Height - 1), new Point(p.X + iHalfArrowWidth, this.Height - 1 - iHalfArrowWidth) });
                        p.Y -= 3;
                    }
                    if (ldEnd == LineDirection.Right)
                    {
                        gp.AddPolygon(new Point[] { new Point(this.Width - 1 - iHalfArrowWidth, p.Y - iHalfArrowWidth), new Point(this.Width - 1, p.Y), new Point(this.Width - 1 - iHalfArrowWidth, p.Y + iHalfArrowWidth) });
                        p.X -= 3;
                    }

                    this.htOutputOutputPoints.Add(alOutputs[alOutputPoints.IndexOf(o)], p);

                    gpOutputs.AddPath(gp, false);
                    this.htOutputGraphicsPaths.Add(alOutputs[alOutputPoints.IndexOf(o)], gp);

                    Port port = new Port(((Output)alOutputs[i]).Index, new Region(gp));
                    this.alOutputPorts.Add(port);
                }

                this.Refresh();
            }
        }
示例#22
0
        public void OnEditingFinished()
        {
            this.OnResize(EventArgs.Empty);

            if (this.Parent is PetriNetEditor)
            {
                PetriNetEditor pne = (PetriNetEditor)this.Parent;

                //Check for valid connections
                for (int i = this.Parents.Count - 1; i >= 0; i--)
                {
                    ConnectableControl cc = (ConnectableControl)this.Parents[i];
                    Connection         cn = Connection.GetConnectionBetweenControls(cc, this);

                    //Find input port with same number as connection output port
                    if (!this.InputPortNumberExists(cn.ToPort))
                    {
                        ConnectableControl ccFrom = cn.From;
                        ConnectableControl ccTo   = cn.To;

                        // Dispose connection
                        ccFrom.Childs.Remove(ccTo);
                        ccTo.Parents.Remove(ccFrom);

                        pne.Connections.Remove(cn);
                        cn.Dispose();
                    }
                }

                for (int i = this.Childs.Count - 1; i >= 0; i--)
                {
                    ConnectableControl cc = (ConnectableControl)this.Childs[i];
                    Connection         cn = Connection.GetConnectionBetweenControls(this, cc);

                    //Find input port with same number as connection output port
                    if (!this.OutputPortNumberExists(cn.FromPort))
                    {
                        ConnectableControl ccFrom = cn.From;
                        ConnectableControl ccTo   = cn.To;

                        // Dispose connection
                        ccFrom.Childs.Remove(ccTo);
                        ccTo.Parents.Remove(ccFrom);

                        pne.Connections.Remove(cn);
                        cn.Dispose();
                    }
                }

                // Adjust Virtual connections weights
                foreach (Connection cn in pne.Connections)
                {
                    if (cn.From == this)
                    {
                        cn.Weight = cn.GetOutputWeightsSum(this);
                    }
                    else if (cn.To == this)
                    {
                        cn.Weight = cn.GetInputWeightsSum(this);
                    }
                }

                pne.OnContentsChanged();
            }
        }
示例#23
0
        private void SubsystemEditor_CreateGUI(PetriNetDocument pnd, Subsystem ssOwner)
        {
            this.pnd     = pnd;
            this.ssOwner = ssOwner;

            Panel pnlEditorContainer = new Panel();

            pnlEditorContainer.AutoScroll = true;
            pnlEditorContainer.Dock       = DockStyle.Fill;

            this.pneEditor                         = new PetriNetEditor(pnd, pnd.InstanceCounter);
            this.pneEditor.AutoScroll              = true;
            this.pneEditor.AutoScrollMinSize       = new Size(3000, 3000);
            this.pneEditor.Size                    = new Size(3000, 3000);
            this.pneEditor.Location                = new Point(0, 0);
            this.pneEditor.ContentsChanged        += new EventHandler(pneEditor_ContentsChanged);
            this.pneEditor.SelectedObjectsChanged += new EventHandler(pneEditor_SelectedObjectsChanged);
            this.pneEditor.PropertiesChanged      += new EventHandler(pneEditor_PropertiesChanged);

            if (this.oDeserializedZoomLevel != null)
            {
                this.pneEditor.Zoom = (float)this.oDeserializedZoomLevel;
            }

            pnlEditorContainer.Controls.Add(pneEditor);
            this.Controls.Add(pnlEditorContainer);

            // Create the object that manages the docking state
            this.dmDockingManager = new Crownwood.Magic.Docking.DockingManager(this, Crownwood.Magic.Common.VisualStyle.IDE);
            this.dmDockingManager.InnerControl = pnlEditorContainer;
            this.dmDockingManager.OuterControl = tbToolBar;

            Crownwood.Magic.Docking.Content toolbox = dmDockingManager.Contents.Add(this.tbToolBox, "Toolbox", this.ilContent, 1);
            toolbox.AutoHideSize = new Size(200, 300);
            toolbox.DisplaySize  = new Size(200, 300);
            toolbox.FloatingSize = new Size(200, 300);
            Crownwood.Magic.Docking.Content properties = dmDockingManager.Contents.Add(this.piPropertiesInspector, "Properties", this.ilContent, 0);
            properties.AutoHideSize = new Size(200, 300);
            properties.DisplaySize  = new Size(200, 300);
            properties.FloatingSize = new Size(200, 300);
            Crownwood.Magic.Docking.WindowContent wc = dmDockingManager.AddContentWithState(toolbox, Crownwood.Magic.Docking.State.DockLeft);

            //dmDockingManager.AddContentToWindowContent(notePad2, wc);
            // Add a new WindowContent to the existing Zone already created
            this.dmDockingManager.AddContentToZone(properties, wc.ParentZone, 1);

            this.tbToolBox.EnabledToolbox = true;

            // Load layout
            if (File.Exists(Application.StartupPath + "\\layoutSubsystem.config.xml"))
            {
                this.dmDockingManager.LoadConfigFromFile(Application.StartupPath + "\\layoutSubsystem.config.xml");
            }

            // Initialize piPropertiesInspector
            this.piPropertiesInspector.SelectedObjectChanged += new EventHandler(piPropertiesInspector_SelectedObjectChanged);

            #region Initialize ToolBar control
            this.tbToolBar.Dock         = DockStyle.Top;
            this.tbToolBar.ButtonSize   = new Size(24, 24);
            this.tbToolBar.ImageList    = ilToolBar;
            this.tbToolBar.ButtonClick += new ToolBarButtonClickEventHandler(tbToolBar_ButtonClick);
            this.tbToolBar.Appearance   = ToolBarAppearance.Flat;

            this.tbbReset.Enabled    = false;
            this.tbbReset.ImageIndex = 3;
            this.tbToolBar.Buttons.Add(tbbReset);

            this.tbbStart.Enabled    = false;
            this.tbbStart.ImageIndex = 4;
            this.tbToolBar.Buttons.Add(tbbStart);

            this.tbbPause.Enabled    = false;
            this.tbbPause.ImageIndex = 5;
            this.tbToolBar.Buttons.Add(tbbPause);

            this.tbbStop.Enabled    = false;
            this.tbbStop.ImageIndex = 6;
            this.tbToolBar.Buttons.Add(tbbStop);

            this.tbbStep.Enabled    = false;
            this.tbbStep.ImageIndex = 7;
            this.tbToolBar.Buttons.Add(tbbStep);

            this.tbbSeparator4.Style = ToolBarButtonStyle.Separator;
            this.tbToolBar.Buttons.Add(tbbSeparator4);

            this.tbbUndo.ImageIndex   = 13;
            this.tbbUndo.ToolTipText  = "Undo";
            this.tbbUndo.Style        = ToolBarButtonStyle.DropDownButton;
            this.tbbUndo.DropDownMenu = this.cmUndo;
            this.tbToolBar.Buttons.Add(tbbUndo);

            this.tbbRedo.ImageIndex   = 14;
            this.tbbRedo.ToolTipText  = "Redo";
            this.tbbRedo.Style        = ToolBarButtonStyle.DropDownButton;
            this.tbbRedo.DropDownMenu = this.cmRedo;
            this.tbToolBar.Buttons.Add(tbbRedo);

            this.tbbSeparator2.Style = ToolBarButtonStyle.Separator;
            this.tbToolBar.Buttons.Add(tbbSeparator2);

//			this.tbbConflicts.ImageIndex = 8;
//			this.tbbConflicts.Style = ToolBarButtonStyle.ToggleButton;
//			this.tbToolBar.Buttons.Add(tbbConflicts);
//
//			this.tbbCircularWaits.ImageIndex = 9;
//			this.tbbCircularWaits.Style = ToolBarButtonStyle.ToggleButton;
//			this.tbToolBar.Buttons.Add(tbbCircularWaits);
//
//			this.tbbFireable.ImageIndex = 10;
//			this.tbbFireable.Style = ToolBarButtonStyle.ToggleButton;
//			this.tbbFireable.Pushed = true;
//			this.tbToolBar.Buttons.Add(tbbFireable);
//
//			this.tbbFired.ImageIndex = 11;
//			this.tbbFired.Style = ToolBarButtonStyle.ToggleButton;
//			this.tbbFired.Pushed = true;
//			this.tbToolBar.Buttons.Add(tbbFired);
//
//			this.tbbSeparator3.Style = ToolBarButtonStyle.Separator;
//			this.tbToolBar.Buttons.Add(tbbSeparator3);

            this.tbbZoom.ImageIndex   = 12;
            this.tbbZoom.Style        = ToolBarButtonStyle.DropDownButton;
            this.tbbZoom.DropDownMenu = this.cmZoom;
            this.tbToolBar.Buttons.Add(tbbZoom);
            this.Controls.Add(this.tbToolBar);
            #endregion

            // Initialize MenuControl
            this.mcMenuControl      = new Crownwood.Magic.Menus.MenuControl();
            this.mcMenuControl.Dock = DockStyle.Top;
            this.Controls.Add(mcMenuControl);

            #region Initialize this.mcFile

            mcFile = new Crownwood.Magic.Menus.MenuCommand("&File");

            mcFileExport          = new Crownwood.Magic.Menus.MenuCommand("&Export...");
            mcFileExport.Shortcut = Shortcut.CtrlE;
            mcFileExport.Click   += new EventHandler(mcFileExport_Click);
            mcFile.MenuCommands.Add(mcFileExport);

            mcFileSeparator1 = new Crownwood.Magic.Menus.MenuCommand("-");
            mcFile.MenuCommands.Add(mcFileSeparator1);

            mcFileClose        = new Crownwood.Magic.Menus.MenuCommand("&Close");
            mcFileClose.Click += new EventHandler(mcFileClose_Click);
            mcFile.MenuCommands.Add(mcFileClose);

            this.mcMenuControl.MenuCommands.Add(mcFile);

            #endregion

            #region Initialize this.mcEdit

            mcEdit = new Crownwood.Magic.Menus.MenuCommand("&Edit");

            mcEditUndo            = new Crownwood.Magic.Menus.MenuCommand("&Undo");
            mcEditUndo.Click     += new EventHandler(mcEditUndo_Click);
            mcEditUndo.ImageList  = ilMenu;
            mcEditUndo.ImageIndex = 4;
            mcEditUndo.Shortcut   = Shortcut.CtrlZ;
            mcEditUndo.Enabled    = false;
            mcEdit.MenuCommands.Add(mcEditUndo);

            mcEditRedo            = new Crownwood.Magic.Menus.MenuCommand("&Redo");
            mcEditRedo.Click     += new EventHandler(mcEditRedo_Click);
            mcEditRedo.ImageList  = ilMenu;
            mcEditRedo.ImageIndex = 5;
            mcEditRedo.Shortcut   = Shortcut.CtrlY;
            mcEditRedo.Enabled    = false;
            mcEdit.MenuCommands.Add(mcEditRedo);

            mcEditSeparator1 = new Crownwood.Magic.Menus.MenuCommand("-");
            mcEdit.MenuCommands.Add(mcEditSeparator1);

            mcEditCut            = new Crownwood.Magic.Menus.MenuCommand("Cu&t");
            mcEditCut.Click     += new EventHandler(mcEditCut_Click);
            mcEditCut.ImageList  = ilMenu;
            mcEditCut.ImageIndex = 6;
            mcEditCut.Shortcut   = Shortcut.CtrlX;
            mcEdit.MenuCommands.Add(mcEditCut);

            mcEditCopy            = new Crownwood.Magic.Menus.MenuCommand("&Copy");
            mcEditCopy.Click     += new EventHandler(mcEditCopy_Click);
            mcEditCopy.ImageList  = ilMenu;
            mcEditCopy.ImageIndex = 7;
            mcEditCopy.Shortcut   = Shortcut.CtrlC;
            mcEdit.MenuCommands.Add(mcEditCopy);

            mcEditPaste            = new Crownwood.Magic.Menus.MenuCommand("&Paste");
            mcEditPaste.Click     += new EventHandler(mcEditPaste_Click);
            mcEditPaste.ImageList  = ilMenu;
            mcEditPaste.ImageIndex = 8;
            mcEditPaste.Shortcut   = Shortcut.CtrlV;
            mcEdit.MenuCommands.Add(mcEditPaste);

            mcEditDelete            = new Crownwood.Magic.Menus.MenuCommand("&Delete");
            mcEditDelete.Click     += new EventHandler(mcEditDelete_Click);
            mcEditDelete.ImageList  = ilMenu;
            mcEditDelete.ImageIndex = 9;
            mcEditDelete.Shortcut   = Shortcut.Del;
            mcEdit.MenuCommands.Add(mcEditDelete);

            mcEditSeparator2 = new Crownwood.Magic.Menus.MenuCommand("-");
            mcEdit.MenuCommands.Add(mcEditSeparator2);

            mcEditCopyModel           = new Crownwood.Magic.Menus.MenuCommand("Copy &model");
            mcEditCopyModel.Click    += new EventHandler(mcEditCopyModel_Click);
            mcEditCopyModel.ImageList = ilMenu;
            //mcEditCopyModel.ImageIndex = 9;
            //mcEditCopyModel.Shortcut = Shortcut.Del;
            mcEdit.MenuCommands.Add(mcEditCopyModel);

            mcEditSeparator3 = new Crownwood.Magic.Menus.MenuCommand("-");
            mcEdit.MenuCommands.Add(mcEditSeparator3);

            mcEditGroup           = new Crownwood.Magic.Menus.MenuCommand("&Group");
            mcEditGroup.Click    += new EventHandler(mcEditGroup_Click);
            mcEditGroup.ImageList = ilMenu;
            //mcEditGroup.ImageIndex = 8;
            mcEditGroup.Shortcut = Shortcut.CtrlG;
            mcEdit.MenuCommands.Add(mcEditGroup);

            mcEditSeparator4 = new Crownwood.Magic.Menus.MenuCommand("-");
            mcEdit.MenuCommands.Add(mcEditSeparator4);

            mcEditSelectAll           = new Crownwood.Magic.Menus.MenuCommand("Select &All");
            mcEditSelectAll.Click    += new EventHandler(mcEditSelectAll_Click);
            mcEditSelectAll.ImageList = ilMenu;
            mcEditSelectAll.Shortcut  = Shortcut.CtrlA;
            mcEdit.MenuCommands.Add(mcEditSelectAll);

            this.mcMenuControl.MenuCommands.Add(mcEdit);

            #endregion

            #region Initialize this.mcView

            mcView = new Crownwood.Magic.Menus.MenuCommand("&View");

            foreach (Crownwood.Magic.Docking.Content c in this.dmDockingManager.Contents)
            {
                Crownwood.Magic.Menus.MenuCommand mc = new Crownwood.Magic.Menus.MenuCommand(c.Title);
                mc.Image  = c.ImageList.Images[c.ImageIndex];
                mc.Click += new EventHandler(mcViewContents_Click);
                mcView.MenuCommands.Add(mc);
            }

            this.mcMenuControl.MenuCommands.Add(mcView);

            #endregion


            #region Initialize ActionList
            // Initialize ActionList
            this.alMenuActionList.ImageList = this.ilMenu;

            this.aEditUndo.Checked    = false;
            this.aEditUndo.Enabled    = false;
            this.aEditUndo.Hint       = null;
            this.aEditUndo.Shortcut   = System.Windows.Forms.Shortcut.CtrlZ;
            this.aEditUndo.Tag        = null;
            this.aEditUndo.ImageIndex = 4;
            this.aEditUndo.Text       = mcEditUndo.Text;
            this.aEditUndo.Visible    = true;
            this.aEditUndo.Update    += new System.EventHandler(this.aEditUndo_Update);
            this.alMenuActionList.Actions.Add(this.aEditUndo);
            this.alMenuActionList.SetAction(this.mcEditUndo, this.aEditUndo);

            this.aEditRedo.Checked    = false;
            this.aEditRedo.Enabled    = false;
            this.aEditRedo.Hint       = null;
            this.aEditRedo.Shortcut   = System.Windows.Forms.Shortcut.CtrlY;
            this.aEditRedo.Tag        = null;
            this.aEditRedo.ImageIndex = 5;
            this.aEditRedo.Text       = mcEditRedo.Text;
            this.aEditRedo.Visible    = true;
            this.aEditRedo.Update    += new System.EventHandler(this.aEditRedo_Update);
            this.alMenuActionList.Actions.Add(this.aEditRedo);
            this.alMenuActionList.SetAction(this.mcEditRedo, this.aEditRedo);

            this.aEditDelete.Checked    = false;
            this.aEditDelete.Enabled    = false;
            this.aEditDelete.Hint       = null;
            this.aEditDelete.Shortcut   = System.Windows.Forms.Shortcut.Del;
            this.aEditDelete.Tag        = null;
            this.aEditDelete.ImageIndex = 9;
            this.aEditDelete.Text       = mcEditDelete.Text;
            this.aEditDelete.Visible    = true;
            this.aEditDelete.Update    += new System.EventHandler(this.aEditDelete_Update);
            this.alMenuActionList.Actions.Add(this.aEditDelete);
            this.alMenuActionList.SetAction(this.mcEditDelete, this.aEditDelete);

            this.aEditCut.Checked    = false;
            this.aEditCut.Enabled    = false;
            this.aEditCut.Hint       = null;
            this.aEditCut.Shortcut   = System.Windows.Forms.Shortcut.CtrlX;
            this.aEditCut.ImageIndex = 6;
            this.aEditCut.Tag        = null;
            this.aEditCut.Text       = mcEditCut.Text;
            this.aEditCut.Visible    = true;
            this.aEditCut.Update    += new System.EventHandler(this.aEditCut_Update);
            this.alMenuActionList.Actions.Add(this.aEditCut);
            this.alMenuActionList.SetAction(this.mcEditCut, this.aEditCut);

            this.aEditCopy.Checked    = false;
            this.aEditCopy.Enabled    = false;
            this.aEditCopy.Hint       = null;
            this.aEditCopy.Shortcut   = System.Windows.Forms.Shortcut.CtrlC;
            this.aEditCopy.ImageIndex = 7;
            this.aEditCopy.Tag        = null;
            this.aEditCopy.Text       = mcEditCopy.Text;
            this.aEditCopy.Visible    = true;
            this.aEditCopy.Update    += new System.EventHandler(this.aEditCopy_Update);
            this.alMenuActionList.Actions.Add(this.aEditCopy);
            this.alMenuActionList.SetAction(this.mcEditCopy, this.aEditCopy);

            this.aEditPaste.Checked    = false;
            this.aEditPaste.Enabled    = false;
            this.aEditPaste.Hint       = null;
            this.aEditPaste.Shortcut   = System.Windows.Forms.Shortcut.CtrlV;
            this.aEditPaste.ImageIndex = 8;
            this.aEditPaste.Tag        = null;
            this.aEditPaste.Text       = mcEditPaste.Text;
            this.aEditPaste.Visible    = true;
            this.aEditPaste.Update    += new System.EventHandler(this.aEditPaste_Update);
            this.alMenuActionList.Actions.Add(this.aEditPaste);
            this.alMenuActionList.SetAction(this.mcEditPaste, this.aEditPaste);

            this.aEditGroup.Checked    = false;
            this.aEditGroup.Enabled    = false;
            this.aEditGroup.Hint       = null;
            this.aEditGroup.Shortcut   = System.Windows.Forms.Shortcut.CtrlG;
            this.aEditGroup.ImageIndex = 12;
            this.aEditGroup.Tag        = null;
            this.aEditGroup.Text       = mcEditGroup.Text;
            this.aEditGroup.Visible    = true;
            this.aEditGroup.Update    += new System.EventHandler(this.aEditGroup_Update);
            this.alMenuActionList.Actions.Add(this.aEditGroup);
            this.alMenuActionList.SetAction(this.mcEditGroup, this.aEditGroup);

            #endregion

            // Initialize Undo/Redo context menus
            this.cmUndo.Popup += new EventHandler(cmUndo_Popup);
            this.cmRedo.Popup += new EventHandler(cmRedo_Popup);
        }
示例#24
0
        private void ConnectableControl_MouseUp(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.SizeAll;

            PetriNetEditor pne = (PetriNetEditor)this.Parent;

            pne.Invalidate();

            if (pne.bConnecting == true)
            {
                pne.bConnecting = false;

                Point ptEnd = this.PointToScreen(new Point(e.X, e.Y));
                ptEnd = pne.PointToClient(ptEnd);

                Control cEnd = pne.GetChildAtPoint(ptEnd);

                if (cEnd is ConnectableControl && cEnd != this)
                {
                    ConnectableControl cc = (ConnectableControl)cEnd;

                    if (this.CanConnectTo(cc))
                    {
                        if (this.alChilds.Contains(cc) != true)
                        {
                            // Set ptEnd to client coordinates of cc
                            ptEnd = pne.PointToScreen(ptEnd);
                            ptEnd = cc.PointToClient(ptEnd);

                            if (cc.CanConnectToThisPoint(ptEnd))
                            {
                                if (this is IConnector && cc is IConnector)
                                {
                                    this.alChilds.Add(cc);
                                    cc.alParents.Add(this);

                                    #region Determine Output port
                                    // Determine Output port
                                    Port pOutput = null;
                                    foreach (Port p in this.alOutputPorts)
                                    {
                                        GraphicsPath gp = new GraphicsPath();
                                        gp.AddEllipse(ptMouseDragOffset.X - 1, ptMouseDragOffset.Y - 1, 2, 2);

                                        Region r = new Region(gp);
                                        r.Intersect(p.PortRegion);

                                        RectangleF rf = r.GetBounds(this.CreateGraphics());

                                        if (rf.Height != 0 || rf.Width != 0)
                                        {
                                            pOutput = p;
                                            break;
                                        }
                                    }
                                    #endregion

                                    #region Determine Input port
                                    // Determine Input port
                                    Port pInput = null;
                                    foreach (Port p in cc.alInputPorts)
                                    {
                                        GraphicsPath gp = new GraphicsPath();
                                        gp.AddEllipse(ptEnd.X - 1, ptEnd.Y - 1, 2, 2);

                                        Region r = new Region(gp);
                                        r.Intersect(p.PortRegion);

                                        RectangleF rf = r.GetBounds(this.CreateGraphics());

                                        if (rf.Height != 0 || rf.Width != 0)
                                        {
                                            pInput = p;
                                            break;
                                        }
                                    }
                                    #endregion

                                    // Scale to Port Bounds
                                    RectangleF rfBegin       = pOutput.PortRegion.GetBounds(this.CreateGraphics());
                                    Point      ptScaledBegin = new Point(ptMouseDragOffset.X - (int)rfBegin.X, ptMouseDragOffset.Y - (int)rfBegin.Y);

                                    RectangleF rfEnd       = pInput.PortRegion.GetBounds(this.CreateGraphics());
                                    Point      ptScaledEnd = new Point(ptEnd.X - (int)rfEnd.X, ptEnd.Y - (int)rfEnd.Y);

                                    // Create new Connection Instance and add it
                                    Connection cn = pne.CreateNewConnection(this, cc, pOutput.PortNumber, pInput.PortNumber, ptScaledBegin, ptScaledEnd, 1);

                                    pne.Connections.Add(cn);

                                    // To notify parent PetriNetEditor that new connection has been created
                                    if (this.ConnectionCreated != null)
                                    {
                                        this.ConnectionCreated(cn, EventArgs.Empty);
                                    }

                                    // Raises PropertiesChanged event to notify Parent
                                    // that Childs property is changed
                                    if (this.PropertiesChanged != null)
                                    {
                                        this.PropertiesChanged(this, new EventArgs());
                                    }
                                }
                                else
                                {
                                    throw new InterfaceNotImplementedException("Not all conecting controls implement IConnector interface");
                                }
                            }
                        }
                        else
                        {
                            if (DialogResult.Yes == MessageBox.Show("Are you sure you want to delete this connection?", "Petri .NET Simulator 1.0 - Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                            {
                                // Remove this ConnectableControl from Parents collection of child cc
                                int iParentIndex = cc.Parents.IndexOf(this);
                                cc.Parents.Remove(this);

                                // Remove cc from this places Childs collection
                                this.alChilds.Remove(cc);

                                // Remove connection between these two controls
                                Connection cn = Connection.GetConnectionBetweenControls(this, cc);
                                pne.Connections.Remove(cn);

                                pne.Refresh();

                                if (this.PropertiesChanged != null)
                                {
                                    this.PropertiesChanged(this, new EventArgs());
                                }
                            }
                        }
                    }
                }
            }
        }