Example #1
0
        private void piPropertiesInspector_SelectedObjectChanged(object sender, EventArgs e)
        {
            object o = this.piPropertiesInspector.SelectedObject;

            if (o is Place)
            {
                if (!(o is PlaceInput))
                {
                    if (this.pnd.PetriNetType == PetriNetType.TimeInvariant)
                    {
                        this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new TimeInvariantAttribute() });
                    }
                    else
                    {
                        this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new CommonPropertiesAttribute() });
                    }
                }
                else
                {
                    PlaceInput pi = (PlaceInput)o;

                    if (pi.InputType == InputType.Fixed)
                    {
                        this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new TimeInvariantAttribute(), new PeriodicInputTypeAttribute(), new StohasticInputTypeAttribute() });
                    }
                    else if (pi.InputType == InputType.Periodic)
                    {
                        this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new TimeInvariantAttribute(), new PeriodicInputTypeAttribute() });
                    }
                    else if (pi.InputType == InputType.Stohastic)
                    {
                        this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new TimeInvariantAttribute(), new StohasticInputTypeAttribute() });
                    }
                }
            }
            else
            {
                this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new CommonPropertiesAttribute() });
            }

            if (o is SelectableAndMovableControl)
            {
                SelectableAndMovableControl s = (SelectableAndMovableControl)o;
                s.PerformActivation();
            }
            else if (o is Connection)
            {
                Connection cn = (Connection)o;
                if (cn.IsVirtual == true)
                {
                    this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new CommonPropertiesAttribute() });
                }
                else
                {
                    this.piPropertiesInspector.BrowsableAttributes = new AttributeCollection(new Attribute[] { new ConnectionPropertiesAttribute() });
                }

                cn.PerformActivation();
            }
        }
        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();
        }
Example #3
0
 public PetriNetEditorMergeModule(SelectableAndMovableControl smac)
 {
     this.alObjects.Add(smac);
 }
Example #4
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();
            }
        }