Пример #1
0
        public PetriNetworkForm(PetriNetwork petriNetwork)
        {
            this.DoubleBuffered = true;
            InitializeComponent();

            this.petriNetwork = petriNetwork;
            this.petriNetwork.dimensionChanged += new DimensionHandler(petriNetwork_dimensionChanged);
            this.petriNetwork.eventHandler += new PetriNetworkEventHandler(sendEventMessageToConsole);
            this.petriNetwork.eventNotifier += new PetriNetworkNotifier(petriNetwork_eventNotifier);

            this.petriNetwork_dimensionChanged(petriNetwork.Width, petriNetwork.Height);
            this.pbPetriNetwork.SizeMode = PictureBoxSizeMode.StretchImage;

            this.zoomValue = 100;

            this.MouseWheel += new MouseEventHandler(pbPetriNetwork_MouseWheel);

            this.ClearPetriNetwork();
            this.calculateStrech();

            this.modifyWindowText();

            this.isStartEdgeAvailable = false;
            this.isStartSelectRectangle = false;
            this.isStartMove = false;
            this.startEdge = null;
            this.endEdge = null;
            this.moveItem = null;

            this.Text = this.petriNetwork.Title;
            this.rtbDescription.Text = this.petriNetwork.Description;

            this.gridPen = new Pen(Color.FromArgb(220, 220, 220));
            this.tsslInfo.Text = "";
        }
Пример #2
0
 public override void draw(PetriNetwork network)
 {
     if (this.menuItem.Checked)
     {
         if (network != null)
         {
             if (!network.Equals(this.network))
             {
                 this.network = network;
                 this.init(this.pbStateHierarchy, this.network.StateHierarchy.Width, this.network.StateHierarchy.Height);
             }
             this.toolStripStateHierarchy.Enabled = true;
             Graphics g = Graphics.FromImage(this.pbStateHierarchy.Image);
             g.SmoothingMode = SmoothingMode.AntiAlias;
             g.Clear(Color.White);
             network.StateHierarchy.draw(g, this.network.VisualSettings, this.network.ActualStateVector);
         }
         else
         {
             this.toolStripStateHierarchy.Enabled = false;
             this.clear(this.pbStateHierarchy);
         }
         this.pbStateHierarchy.Refresh();
     }
 }
Пример #3
0
 /// <summary>
 /// Refresh Petri net of the MiniMap, StateMatrix, etc.
 /// </summary>
 public void refreshMiniMap(PetriNetwork network)
 {
     PetriNetwork actNetwork = this.getActivePetriNetwork();
     if ( ( ( actNetwork != null ) && ( actNetwork.Equals(network) ) ) || ( network == null ) )
     {
         MiniMap miniMap = (MiniMap)this.getToolWindow(typeof(MiniMap));
         if ((miniMap != null) && (miniMap.Visible))
         {
             miniMap.draw(network);
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Refresh Petri net of the MiniMap, StateMatrix, etc.
 /// </summary>
 public void refreshToolWindowsPetriNetwork(PetriNetwork network)
 {
     PetriNetwork actNetwork = this.getActivePetriNetwork();
     if ( ( ( actNetwork != null ) && ( actNetwork.Equals(network) ) ) || ( network == null ) ) {
         foreach (GeneralToolWindow toolWindow in this.toolWindowList)
         {
             if (toolWindow.Visible)
             {
                 toolWindow.draw(network);
             }
         }
     }
 }
Пример #5
0
 public override void draw(PetriNetwork network)
 {
     if (this.menuItem.Checked)
     {
         if (network != null)
         {
             this.lbEvents.Items.Clear();
             this.network = network;
             this.lbEvents.Items.AddRange(this.network.StringEvents.ToArray());
         }
         else
         {
             this.clear();
         }
     }
 }
Пример #6
0
 protected override void dialogOK()
 {
     try
     {
         int width = Convert.ToInt32(this.nudWidth.Value);
         int height = Convert.ToInt32(this.nudHeight.Value);
         int sh_width = Convert.ToInt32(this.nudStateHierarchyWidth.Value);
         int sh_height = Convert.ToInt32(this.nudStateHierarchyHeight.Value);
         int defaultEdgeWeight = Convert.ToInt32(this.nudDefaultEdgeWeight.Value);
         int simulationTimeout = Convert.ToInt32(this.nudTimeout.Value);
         IdentityProvider identityProvider = new IdentityProvider(tbPositionPrefix.Text, tbTransitionPrefix.Text, tbTokenPrefix.Text, tbNotePrefix.Text, 0, 0, 0, 0);
         string certificateSubject = CryptoHelper.getInstance().Subject;
         this.petriNetwork = new PetriNetwork(this.rand, tbName.Text, "", width, height, sh_width, sh_height, identityProvider, tbStatePrefix.Text, defaultEdgeWeight, 0, null, FireRule.getDefault(), simulationTimeout, certificateSubject, DateTime.Now);
     }
     catch (OverflowException e)
     {
         throw new SimApplicationException("Conversion error.",e);
     }
 }
Пример #7
0
 public override void draw(PetriNetwork network)
 {
     if (this.menuItem.Checked)
     {
         if (network != null)
         {
             this.initMiniMap(network);
             Graphics g = Graphics.FromImage(this.pbMiniMap.Image);
             g.SmoothingMode = SmoothingMode.AntiAlias;
             g.Clear(Color.White);
             network.draw(g, null, false);
         }
         else
         {
             Graphics g = Graphics.FromImage(this.pbMiniMap.Image);
             g.Clear(Color.White);
         }
         this.pbMiniMap.Refresh();
     }
 }
Пример #8
0
        public override void draw(PetriNetwork network)
        {
            if (this.menuItem.Checked)
            {
                if (network != null)
                {
                    this.network = network;
                    List<Position> positions = this.network.Positions;
                    List<Transition> transitions = this.network.Transitions;
                    List<StateVector> states = this.network.StateHierarchy.States;

                    this.lbItems.Items.Clear();
                    this.lbItems.Items.AddRange(positions.ToArray());
                    this.lbItems.Items.AddRange(transitions.ToArray());
                    this.lbItems.Items.AddRange(states.ToArray());
                }
                else
                {
                    this.lbItems.Items.Clear();
                }
            }
        }
Пример #9
0
        public override void draw(PetriNetwork network)
        {
            if (this.menuItem.Checked)
            {
                if (network != null)
                {
                    this.lbTransitionHistory.Items.Clear();
                    this.network = network;
                    this.lbTransitionHistory.Items.AddRange(this.network.TransitionHistory.ToArray());
                    if (this.lbTransitionHistory.Items.Count > 0)
                    {
                        this.lbTransitionHistory.SelectedIndexChanged -= new EventHandler(lbTransitionHistory_SelectedIndexChanged);
                        this.lbTransitionHistory.SetSelected(this.lbTransitionHistory.Items.Count - 1, true);
                        this.lbTransitionHistory.SetSelected(this.lbTransitionHistory.Items.Count - 1, false);
                        this.lbTransitionHistory.SelectedIndexChanged += new EventHandler(lbTransitionHistory_SelectedIndexChanged);
                    }

                }
                else
                {
                    this.clear();
                }
            }
        }
Пример #10
0
 public void fire(PetriNetwork network)
 {
     this.network = network;
     this.tsbFire.PerformClick();
 }
Пример #11
0
 public void stopSimulation(PetriNetwork network)
 {
     this.network = network;
     this.tsbStop.PerformClick();
 }
Пример #12
0
        public override void draw(PetriNetwork network)
        {
            if (this.menuItem.Checked)
            {
                if (network != null)
                {
                    this.toolStripStateMatrix.Enabled = true;
                    this.network = network;

                    this.tsbFire.Enabled = !this.network.ActiveSimulation;
                    this.tsbAutoFire.Enabled = !this.network.ActiveSimulation;
                    this.tsbStop.Enabled = this.network.ActiveSimulation;

                    List<Position> positions = network.Positions;
                    List<StateVector> stateMatrix = network.StateMatrix;

                    Graphics g = Graphics.FromImage(this.pbStateMatrix.Image);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    Font font = new Font("Arial", 10);

                    Font fontBold = new Font("Arial", 10, FontStyle.Bold);

                    float headerPosWidth = 100;
                    float rowHeight = 15;
                    float maxWidth = 0;
                    float maxHeight = 0;
                    foreach (Position position in positions)
                    {
                        SizeF textSize = g.MeasureString(position.Name, font);
                        if (textSize.Width > maxWidth)
                        {
                            maxWidth = textSize.Width;
                        }
                        if (textSize.Height > maxHeight)
                        {
                            maxHeight = textSize.Height;
                        }
                    }
                    if (maxWidth > 0)
                    {
                        headerPosWidth = maxWidth + StateMatrix.MARGIN * 2;
                        rowHeight = maxHeight;
                    }
                    float stateWidth = 40;
                    float headerHeight = 25;
                    maxWidth = 0;
                    maxHeight = 0;
                    foreach (StateVector stateVector in network.StateMatrix)
                    {
                        SizeF textSize = g.MeasureString(stateVector.Name, (stateVector.Equals(network.ActualStateVector) ? fontBold : font));
                        if (textSize.Width > maxWidth)
                        {
                            maxWidth = textSize.Width;
                        }
                        if (textSize.Height > maxHeight)
                        {
                            maxHeight = textSize.Height;
                        }
                    }
                    if (maxWidth > 0)
                    {
                        stateWidth = maxWidth + StateMatrix.MARGIN * 2;
                        headerHeight = maxHeight + StateMatrix.MARGIN * 2;
                    }

                    this.init(this.pbStateMatrix, (int)(headerPosWidth + network.StateMatrix.Count * stateWidth), (int)(positions.Count * rowHeight + headerHeight));
                    g = Graphics.FromImage(this.pbStateMatrix.Image);
                    g.Clear(Color.White);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    Pen pen = new Pen(Color.FromArgb(0, 0, 0));
                    Brush brush = new SolidBrush(Color.FromArgb(0, 0, 0));
                    Brush brushSelected = new SolidBrush(Color.FromArgb(0, 0, 200));
                    g.DrawRectangle(pen, 0, 0, this.width, this.height);

                    g.DrawLine(pen, headerPosWidth, 0, headerPosWidth, this.height);
                    g.DrawLine(pen, 0, headerHeight, this.width, headerHeight);

                    g.DrawString("M", font, brush, new RectangleF(StateMatrix.MARGIN, StateMatrix.MARGIN, headerPosWidth - 2 * StateMatrix.MARGIN, headerHeight - 2 * StateMatrix.MARGIN));
                    int i = 0;
                    foreach (Position position in positions)
                    {
                        g.DrawString(position.Name, font, brush, new RectangleF(StateMatrix.MARGIN, headerHeight + i * rowHeight, headerPosWidth - 2 * StateMatrix.MARGIN, rowHeight));
                        i++;
                    }

                    int j = 0;
                    foreach (StateVector stateVector in network.StateMatrix)
                    {
                        RectangleF rect = new RectangleF(headerPosWidth + StateMatrix.MARGIN + j * stateWidth, StateMatrix.MARGIN, stateWidth - 2 * StateMatrix.MARGIN, headerHeight - 2 * StateMatrix.MARGIN);
                        stateVector.Map = rect;
                        if (stateVector.Equals(network.ActualStateVector))
                        {
                            g.DrawString(stateVector.Name, fontBold, brushSelected, rect);
                        }
                        else
                        {
                            g.DrawString(stateVector.Name, font, brush, rect);
                        }

                        i = 0;
                        foreach (Position position in positions)
                        {
                            int tokenCount = stateVector.getTokenCountByPositionUnid(position.Unid);
                            g.DrawString(tokenCount.ToString(), font, brush, new RectangleF(headerPosWidth + StateMatrix.MARGIN + (j * stateWidth), headerHeight + i * rowHeight, stateWidth - 2 * StateMatrix.MARGIN, rowHeight));
                            i++;
                        }
                        j++;
                    }
                    i++;

                }
                else
                {
                    this.toolStripStateMatrix.Enabled = false;
                    Graphics g = Graphics.FromImage(this.pbStateMatrix.Image);
                    g.Clear(Color.White);

                    this.tsbFire.Enabled = true;
                    this.tsbAutoFire.Enabled = true;
                    this.tsbStop.Enabled = false;
                }
                this.pbStateMatrix.Refresh();
            }
        }
Пример #13
0
 private void stateAction_callAction(StateMatrixAction action, PetriNetwork network)
 {
     if (network != null)
     {
         bool reDraw = true;
         switch (action)
         {
             case StateMatrixAction.CLEAR:
                 network.clearStateMatrix(false);
                 break;
             case StateMatrixAction.FIRE:
                 network.fire(false);
                 this.reDrawActivePetriNetwork(false);
                 break;
             case StateMatrixAction.CLEARALLSTATE:
                 network.deleteAllStates();
                 break;
             case StateMatrixAction.AUTOFIRE:
                 if (this.ActiveMdiChild is PetriNetworkForm)
                 {
                     (this.ActiveMdiChild as PetriNetworkForm).autoFire();
                     reDraw = false;
                 }
                 break;
             case StateMatrixAction.STOPAUTOFIRE:
                 if (this.ActiveMdiChild is PetriNetworkForm)
                 {
                     (this.ActiveMdiChild as PetriNetworkForm).stopAutoFire();
                 }
                 break;
         }
         if (reDraw)
         {
             this.refreshToolWindowsPetriNetwork(network);
         }
         else
         {
             this.refreshMiniMap(network);
         }
     }
 }
Пример #14
0
 private void childSimulationNotifier(PetriNetwork network, FireEvent fireEvent)
 {
     switch (fireEvent)
     {
         case FireEvent.DEADLOCK:
             StateMatrix stateMatrix = (StateMatrix)this.getToolWindow(typeof(StateMatrix));
             if (stateMatrix != null)
             {
                 stateMatrix.stopSimulation(network);
             }
             break;
     }
 }
Пример #15
0
 public virtual void draw(PetriNetwork network)
 {
     //
 }
Пример #16
0
 private void initMiniMap(PetriNetwork network)
 {
     this.pbMiniMap.Image = new Bitmap(network.Width, network.Height);
 }
Пример #17
0
 public void startSimulation(PetriNetwork network)
 {
     this.network = network;
     this.tsbAutoFire.PerformClick();
 }
Пример #18
0
 public override void draw(PetriNetwork network)
 {
     //
 }
Пример #19
0
        public override void draw(PetriNetwork network)
        {
            if (this.menuItem.Checked)
            {
                if (network != null)
                {
                    this.toolStripNeighborhoodMatrix.Enabled = true;
                    this.network = network;

                    List<Position> positions = network.Positions;
                    List<Transition> transitions = network.Transitions;

                    if ((positions.Count > 0) && (transitions.Count > 0))
                    {

                        Graphics gmw = Graphics.FromImage(this.pbMinusWeight.Image);
                        Font font = new Font("Arial", 10);
                        Font fontBold = new Font("Arial", 10, FontStyle.Bold);

                        float posWidth = 0;
                        float rowHeight = 15;
                        float maxWidth = 0;
                        float maxHeight = 0;
                        foreach (Position position in positions)
                        {
                            SizeF textSize = gmw.MeasureString(position.Name, font);
                            if (textSize.Width > maxWidth)
                            {
                                maxWidth = textSize.Width;
                            }
                            if (textSize.Height > maxHeight)
                            {
                                maxHeight = textSize.Height;
                            }
                        }
                        if (maxWidth > 0)
                        {
                            posWidth = maxWidth + NeighborhoodMatrix.MARGIN * 2;
                            rowHeight = maxHeight + NeighborhoodMatrix.MARGIN * 2;
                        }

                        float traWidth = 0;
                        maxWidth = 0;
                        maxHeight = 0;
                        foreach (Transition transition in transitions)
                        {
                            SizeF textSize = gmw.MeasureString(transition.Name, font);
                            if (textSize.Width > maxWidth)
                            {
                                maxWidth = textSize.Width;
                            }
                            if (textSize.Height > maxHeight)
                            {
                                maxHeight = textSize.Height;
                            }
                        }
                        if (maxWidth > 0)
                        {
                            traWidth = maxWidth + NeighborhoodMatrix.MARGIN * 2;
                        }

                        this.initNeighborhoodMatrix((int)(posWidth * positions.Count + traWidth), (int)((transitions.Count + 1) * rowHeight));
                        gmw = Graphics.FromImage(this.pbMinusWeight.Image);
                        Graphics gpw = Graphics.FromImage(this.pbPlusWeight.Image);
                        Graphics gnm = Graphics.FromImage(this.pbNeighborhoodMatrix.Image);
                        Pen pen = new Pen(Color.FromArgb(0, 0, 0));
                        Brush brush = new SolidBrush(Color.FromArgb(0, 0, 0));
                        Brush brushSelected = new SolidBrush(Color.FromArgb(0, 0, 200));
                        StringFormat drawFormat = new StringFormat();
                        drawFormat.Alignment = StringAlignment.Center;
                        drawFormat.LineAlignment = StringAlignment.Center;
                        this.sideDraw(gmw, pen, traWidth, rowHeight, "W-", font, brush, drawFormat, transitions);
                        this.sideDraw(gpw, pen, traWidth, rowHeight, "W+", font, brush, drawFormat, transitions);
                        this.sideDraw(gnm, pen, traWidth, rowHeight, "W", font, brush, drawFormat, transitions);

                        int i = 0;
                        foreach (Position position in positions)
                        {
                            RectangleF prect = new RectangleF(traWidth + i * posWidth, 0, posWidth, rowHeight);
                            gmw.DrawString(position.Name, font, brush, prect, drawFormat);
                            gpw.DrawString(position.Name, font, brush, prect, drawFormat);
                            gnm.DrawString(position.Name, font, brush, prect, drawFormat);

                            int j = 0;
                            foreach (Transition transition in transitions)
                            {
                                int minusWeight = this.network.getMinusWeight(position, transition);
                                int plusWeight = this.network.getPlusWeight(position, transition);
                                RectangleF rect = new RectangleF(traWidth + (i * posWidth), rowHeight + j * rowHeight, posWidth, rowHeight);
                                gmw.DrawString(minusWeight.ToString(), font, brush, rect, drawFormat);
                                gpw.DrawString(plusWeight.ToString(), font, brush, rect, drawFormat);
                                gnm.DrawString((plusWeight - minusWeight).ToString(), font, brush, rect, drawFormat);
                                j++;
                            }

                            i++;
                        }

                    }
                    else
                    {
                        this.clear();
                    }
                }
                else
                {
                    this.toolStripNeighborhoodMatrix.Enabled = false;
                    this.clear();
                }
                this.pbMinusWeight.Refresh();
            }
        }
Пример #20
0
 private void saveAs(PetriNetwork network)
 {
     if (CryptoHelper.getInstance().HasKey)
     {
         if (network != null)
         {
             SaveFileDialog dialog = new SaveFileDialog();
             dialog.Filter = "Petri Network XML file (*.pn.xml)|*.pn.xml";
             if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 Cursor actCursor = this.Cursor;
                 this.Cursor = Cursors.WaitCursor;
                 network.saveToXml(dialog.FileName);
                 this.ActiveMdiChild.Text = network.Title;
                 this.recentFilesHelper.addRecentFile(network.PetriRecentFile);
                 // this.child_networkItemSelected(network.SelectedItems, true);
                 this.writeConsole(network.Name + " network was saved as " + network.FileName + " .");
                 this.Cursor = actCursor;
             }
         }
     }
 }