Example #1
0
 private void pbPetriNetwork_MouseUp(object sender, MouseEventArgs e)
 {
     PointF noAlignEndCoordinates = this.convertPixelToCoord(e.X, e.Y);
     this.endCoordinatesF = this.alignToGrid(noAlignEndCoordinates);
     bool find = false;
     switch ((this.MdiParent as MDIParent).SelectedToolboxItem)
     {
         case NetworkToolboxItem.EDGE:
             if (isStartEdgeAvailable) {
                 AbstractItem edgeItem = this.petriNetwork.getVisualItemByCoordinates(this.endCoordinatesF);
                 if ((edgeItem != null) && ( edgeItem is AbstractNetworkItem ))
                 {
                     AbstractNetworkItem networkItem = (AbstractNetworkItem)edgeItem;
                     this.endEdge = networkItem;
                     if (!(this.startEdge is AbstractNote))
                     {
                         this.petriNetwork.addEdge(this.startEdge, this.endEdge, new PointF(0,0));
                     }
                     else
                     {
                         AbstractNote note = (AbstractNote)this.startEdge;
                         note.AttachedItem = this.endEdge;
                     }
                     find = true;
                 }
                 else if ((edgeItem != null) && (edgeItem is AbstractEdge))
                 {
                     if (this.startEdge is AbstractNote) {
                         AbstractNote note = (AbstractNote)this.startEdge;
                         note.AttachedItem = edgeItem;
                         find = true;
                     }
                 }
                 else if (edgeItem == null)
                 {
                     // auto add position/transition
                     if (this.startEdge is AbstractPosition)
                     {
                         if (!this.selectVisualItem(endCoordinatesF))
                         {
                             this.endEdge = this.petriNetwork.addTransition(null, new Random().Next(0, 90), endCoordinatesF, new SizeF(5, 20));
                             this.petriNetwork.addEdge(this.startEdge, this.endEdge, new PointF(0, 0));
                             find = true;
                         }
                     }
                     else if (this.startEdge is AbstractTransition)
                     {
                         if (!this.selectVisualItem(endCoordinatesF))
                         {
                             this.endEdge = this.petriNetwork.addPosition(null, endCoordinatesF, (float)20);
                             this.petriNetwork.addEdge(this.startEdge, this.endEdge, new PointF(0, 0));
                             find = true;
                         }
                     }
                 }
             }
             break;
         case NetworkToolboxItem.SELECT:
             if ( (isStartSelectRectangle) && ( this.theRectangle.Width != 0 ) && ( this.theRectangle.Height != 0 ) )
             {
                 (this.MdiParent as MDIParent).removeStatusStripSelectRectangles();
                 ControlPaint.DrawReversibleFrame(this.theRectangle,this.BackColor, FrameStyle.Dashed);
                 this.petriNetwork.unselectAllItem();
                 find = this.selectVisualItem(this.convertSelectRectangle(this.theRectangle));
                 ControlPaint.DrawReversibleFrame(this.theRectangle, this.BackColor, FrameStyle.Dashed);
                 this.theRectangle = new Rectangle(0, 0, 0, 0);
             }
             break;
         case NetworkToolboxItem.MOVE:
             if (this.isStartMove)
             {
                 if (this.moveItem is AbstractNetworkItem)
                 {
                     if (MoveCorner.NONE.Equals(this.moveCorner))
                     {
                         if (this.petriNetwork.isSelected(this.moveItem))
                         {
                             PointF offset = this.alignToGrid(new PointF(this.endCoordinatesF.X - this.startCoordinatesF.X, this.endCoordinatesF.Y - this.startCoordinatesF.Y));
                             this.petriNetwork.modifySelectedItems(NetworkProperty.ORIGO, offset);
                         }
                         else
                         {
                             AbstractNetworkItem networkItem = (AbstractNetworkItem)this.moveItem;
                             networkItem.Origo = this.endCoordinatesF;
                         }
                     }
                     else
                     {
                         // resize
                         PointF offset = new PointF(noAlignEndCoordinates.X - this.startCoordinatesF.X, noAlignEndCoordinates.Y - this.startCoordinatesF.Y);
                         if (this.moveCorner.Equals(MoveCorner.LABEL) && this.moveItem is AbstractNetworkItem)
                         {
                             AbstractNetworkItem ani = (AbstractNetworkItem)this.moveItem;
                             ani.LabelOffset = new PointF(ani.LabelOffset.X + offset.X, ani.LabelOffset.Y + offset.Y);
                         }
                         else
                         {
                             if (this.moveItem is AbstractNote)
                             {
                                 ((AbstractNote)this.moveItem).setNoteParametersForResize(this.moveCorner, offset);
                             }
                             else if (this.moveItem is AbstractPosition)
                             {
                                 ((AbstractPosition)this.moveItem).setPositionParametersForResize(this.moveCorner, offset);
                             }
                             else if (this.moveItem is AbstractTransition)
                             {
                                 ((AbstractTransition)this.moveItem).setTransitionParametersForResize(this.moveCorner, offset);
                             }
                         }
                     }
                 }
                 else if (this.moveItem is AbstractEdge)
                 {
                     AbstractEdge networkEdge = (AbstractEdge)this.moveItem;
                     networkEdge.setCurveMiddlePointOffset(this.endCoordinatesF);
                     // networkEdge.CurveMiddlePointOffset = offset;
                 }
                 find = true;
             }
             break;
     }
     this.isStartEdgeAvailable = false;
     this.isStartSelectRectangle = false;
     this.isStartMove = false;
     this.startEdge = null;
     this.endEdge = null;
     this.moveItem = null;
     if (find)
     {
         this.drawPetriNetwork(null,null);
     }
 }
Example #2
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 = "";
        }
Example #3
0
 private void drawPetriNetwork(AbstractNetworkItem edgeStartItem, AbstractNetworkItem edgeSelectionItem, bool toolWindowsRefresh = true)
 {
     Graphics g = Graphics.FromImage(this.pbPetriNetwork.Image);
     g.SmoothingMode = SmoothingMode.AntiAlias;
     g.Clear(Color.White);
     this.drawGrid(g, this.gridPen, Properties.Settings.Default.GridSize);
     if (this.petriNetwork.isConnectedItem(edgeSelectionItem))
     {
         this.petriNetwork.selectEdge(edgeSelectionItem);
         if (this.networkItemSelected != null)
         {
             this.networkItemSelected(this.petriNetwork.SelectedItems, false);
         }
     }
     else
     {
         this.petriNetwork.setStartNetworkItemForEdgeSelection(edgeSelectionItem);
     }
     this.petriNetwork.draw(g, edgeStartItem, NetworkToolboxItem.MOVE.Equals((this.MdiParent as MDIParent).SelectedToolboxItem));
     this.pbPetriNetwork.Refresh();
     if (toolWindowsRefresh)
     {
         (this.MdiParent as MDIParent).refreshToolWindowsPetriNetwork(this.petriNetwork);
     }
     else
     {
         (this.MdiParent as MDIParent).refreshMiniMap(this.petriNetwork);
     }
 }
Example #4
0
 private void pbPetriNetwork_MouseDown(object sender, MouseEventArgs e)
 {
     AbstractItem item = null;
     this.startCoordinatesF = this.convertPixelToCoord(e.X, e.Y);
     this.startCoordinates = this.pbPetriNetwork.PointToScreen(new Point(e.X, e.Y));
     switch ((this.MdiParent as MDIParent).SelectedToolboxItem)
     {
         case NetworkToolboxItem.EDGE:
             item = this.petriNetwork.getVisualItemByCoordinates(this.startCoordinatesF);
             if ((item != null) && ( item is AbstractNetworkItem ))
             {
                 bool valid = true;
                 if (item is AbstractTransition)
                 {
                     if (TransitionType.SINK.Equals(((AbstractTransition)item).TransitionType))
                     {
                         valid = false;
                     }
                 }
                 if (valid)
                 {
                     AbstractNetworkItem networkItem = (AbstractNetworkItem)item;
                     this.startEdge = networkItem;
                     this.endCoordinates = this.startCoordinates;
                     this.isStartEdgeAvailable = true;
                     this.isStartSelectRectangle = false;
                     this.isStartMove = false;
                     if (!(networkItem is AbstractNote))
                     {
                         this.drawPetriNetwork(networkItem, null);
                     }
                 }
             }
             break;
         case NetworkToolboxItem.SELECT:
             this.isStartEdgeAvailable = false;
             this.isStartSelectRectangle = true;
             this.isStartMove = false;
             break;
         case NetworkToolboxItem.MOVE:
             // search sizeable corner
             SearchItemResultTransfer searchItemResultTransfer = this.petriNetwork.getVisualItemEdgesByCoordinates(this.startCoordinatesF);
             if (searchItemResultTransfer != null)
             {
                 item = searchItemResultTransfer.Item;
                 this.moveCorner = searchItemResultTransfer.MoveEdge;
             }
             else
             {
                 item = this.petriNetwork.getVisualItemByCoordinates(this.startCoordinatesF);
                 this.moveCorner = MoveCorner.NONE;
             }
             if ((item != null) && (item is AbstractItem))
             {
                 AbstractItem networkItem = (AbstractItem)item;
                 this.moveItem = networkItem;
                 this.endCoordinates = this.startCoordinates;
                 this.isStartEdgeAvailable = false;
                 this.isStartSelectRectangle = false;
                 this.isStartMove = true;
             }
             break;
     }
 }
Example #5
0
 public void addEdge(int weight, AbstractNetworkItem start, AbstractNetworkItem end, PointF curveMiddlePoint)
 {
     if ((start != null) && (end != null))
     {
         if ((start is Position) && (end is Transition))
         {
             Transition endTransition = (Transition)end;
             if (!TransitionType.SOURCE.Equals(endTransition.TransitionType))
             {
                 this.addEdgePositionTransition(weight, (Position)start, endTransition, curveMiddlePoint);
             }
         }
         else if ((start is Transition) && (end is Position))
         {
             Transition startTransition = (Transition)start;
             if (!TransitionType.SINK.Equals(startTransition.TransitionType))
             {
                 this.addEdgeTransitionPosition(weight, startTransition, (Position)end, curveMiddlePoint);
             }
         }
     }
 }
Example #6
0
 public void draw(Graphics g, AbstractNetworkItem edgeStartItem, bool showHelpEllipse)
 {
     bool markPosition = false;
     bool markTransition = false;
     bool mark = false;
     bool markAsReadyToFire = false;
     if (edgeStartItem != null)
     {
         if (edgeStartItem is Position)
         {
             markTransition = true;
         }
         else
         {
             markPosition = true;
         }
     }
     List<Transition> readyToFireTransitions = null;
     if (this.visibleSettings.VisibleReadyToFireTransitions)
     {
         readyToFireTransitions = this.getReadyToFireTransition();
     }
     foreach (AbstractNetworkItem item in this.items)
     {
         mark = false;
         markAsReadyToFire = false;
         if ((item is Position) && (markPosition))
         {
             mark = true;
         }
         else if ((item is Transition) && (markTransition))
         {
             mark = true;
         }
         else if ((this.connectedItems != null) && (this.connectedItems.Contains(item)))
         {
             mark = true;
         }
         if ((item is Transition) && (readyToFireTransitions != null) && (readyToFireTransitions.Contains(item)))
         {
             markAsReadyToFire = true;
         }
         item.draw(g, this.isSelected(item), mark, this.visualSettings, this.visibleSettings, markAsReadyToFire, showHelpEllipse);
     }
     foreach (AbstractEdge item in this.edges)
     {
         item.draw(g, this.isSelected(item), this.VisualSettings, this.visibleSettings);
     }
 }
Example #7
0
 private List<AbstractNetworkItem> getConnectedItems(AbstractNetworkItem item)
 {
     List<AbstractNetworkItem> ret = new List<AbstractNetworkItem>();
     if (item != null)
     {
         foreach (AbstractEdge edge in this.edges)
         {
             if (item.Equals(edge.Start))
             {
                 ret.Add(edge.End);
             }
         }
     }
     return ret;
 }
Example #8
0
 public void addEdge(AbstractNetworkItem start, AbstractNetworkItem end, PointF curveMiddlePoint)
 {
     this.addEdge(this.defaultEdgeWeight, start, end, curveMiddlePoint);
 }
Example #9
0
 /// <summary>
 /// Delete item (position, transition or note) and any connected notes.
 /// </summary>
 private void deleteItem(AbstractNetworkItem item)
 {
     if (this.items.Contains(item))
     {
         this.removeNoteAttachmentBeforeDelete(item);
         this.unselectItem(item);
         this.items.Remove(item);
         if (!(item is AbstractNote))
         {
             this.deleteAllStates();
         }
     }
 }
Example #10
0
 protected void addItem(AbstractNetworkItem item)
 {
     if (!this.items.Contains(item))
     {
         this.items.Add(item);
         if (!(item is AbstractNote))
         {
             this.deleteAllStates();
         }
     }
 }
Example #11
0
 /// <summary>
 /// To select an edge via special tool, you have to select the start point first.
 /// </summary>
 public void setStartNetworkItemForEdgeSelection(AbstractNetworkItem item)
 {
     this.startNetworkItemForEdgeSelection = item;
     this.connectedItems = this.getConnectedItems(item);
 }
Example #12
0
 /// <summary>
 /// Select an edge between two NetworkItems (position and transitions). You have to set startNetworkItemForEdgeSelection before use this method.
 /// </summary>
 public void selectEdge(AbstractNetworkItem item)
 {
     AbstractEdge ret = null;
     if ((item != null) && (this.startNetworkItemForEdgeSelection != null) && (!item.Equals(this.startNetworkItemForEdgeSelection)))
     {
         foreach (AbstractEdge edge in this.edges)
         {
             if ((item.Equals(edge.End)) && (this.startNetworkItemForEdgeSelection.Equals(edge.Start)))
             {
                 ret = edge;
                 break;
             }
         }
     }
     this.reverseSelection(ret);
     this.startNetworkItemForEdgeSelection = null;
     this.connectedItems = null;
 }
Example #13
0
 /// <summary>
 /// Return true, if network item is connected to the start point (for edge selection).
 /// </summary>
 public bool isConnectedItem(AbstractNetworkItem item)
 {
     bool ret = false;
     if ((this.connectedItems != null) && (this.connectedItems.Count > 0))
     {
         ret = this.connectedItems.Contains(item);
     }
     return ret;
 }