コード例 #1
0
ファイル: PetriNetworkForm.cs プロジェクト: davidbedok/UBPNS
 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);
     }
 }
コード例 #2
0
ファイル: PetriNetworkForm.cs プロジェクト: davidbedok/UBPNS
 public void singleSelectItem(AbstractItem item)
 {
     if (item != null)
     {
         bool tmp = this.petriNetwork.isSelected(item);
         this.petriNetwork.unselectAllItem();
         if (!tmp)
         {
             this.petriNetwork.reverseSelection(item);
         }
         if (this.networkItemSelected != null)
         {
             this.networkItemSelected(this.petriNetwork.SelectedItems, false);
         }
     }
 }
コード例 #3
0
ファイル: PetriNetworkForm.cs プロジェクト: davidbedok/UBPNS
 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;
     }
 }
コード例 #4
0
 private void addCustomTokenRow(AbstractItem parent, AbstractToken token, bool disabled)
 {
     this.tlpToken.RowStyles.Add(new RowStyle(SizeType.Absolute, MDIParent.PROPERTY_ROW_HEIGHT));
     this.tlpToken.Controls.Add(ControlHelper.getPropertyLabel(token.Unid.ToString()), 0, this.tmpTokenPanelRowCount);
     this.tlpToken.Controls.Add(ControlHelper.getPropertyTextBox(token.Name, new EventHandler(tokenAndEventValueChanged), new PropertyTag(null, token, NetworkProperty.NAME), disabled), 1, this.tmpTokenPanelRowCount);
     this.tlpToken.Controls.Add(ControlHelper.getPropertyColorPanel(token.TokenColor, new EventHandler(tokenAndEventValueChanged), new PropertyTag(null, token, NetworkProperty.COLOR), disabled), 2, this.tmpTokenPanelRowCount);
     this.tlpToken.Controls.Add(ControlHelper.getPropertyButton("DEL", new EventHandler(tokenAndEventValueChanged), new PropertyTag(parent, token, NetworkProperty.DELETE), disabled), 3, this.tmpTokenPanelRowCount);
     this.tmpTokenPanelRowCount++;
 }
コード例 #5
0
 private void refreshPropertyData(AbstractItem item)
 {
     foreach (Control control in this.tlpProperty.Controls)
     {
         if ((control != null) && (control is NumericUpDown) && (control.Tag != null) && (control.Tag is NetworkProperty))
         {
             NumericUpDown nud = (NumericUpDown)control;
             nud.ValueChanged -= new EventHandler(dynamicProperty_ValueChanged);
             NetworkProperty propertyTag = (NetworkProperty)control.Tag;
             if (item is AbstractNetworkItem)
             {
                 AbstractNetworkItem networkItem = (AbstractNetworkItem)item;
                 try
                 {
                     switch (propertyTag)
                     {
                         case NetworkProperty.ORIGO_X:
                             nud.Value = (decimal)networkItem.Origo.X;
                             break;
                         case NetworkProperty.ORIGO_Y:
                             nud.Value = (decimal)networkItem.Origo.Y;
                             break;
                         case NetworkProperty.POINT_X:
                             nud.Value = (decimal)networkItem.Point.X;
                             break;
                         case NetworkProperty.POINT_Y:
                             nud.Value = (decimal)networkItem.Point.Y;
                             break;
                         case NetworkProperty.RADIUS:
                             nud.Value = (decimal)networkItem.Radius;
                             break;
                         case NetworkProperty.SIZE_WIDTH:
                             nud.Value = (decimal)networkItem.Size.Width;
                             break;
                         case NetworkProperty.SIZE_HEIGHT:
                             nud.Value = (decimal)networkItem.Size.Height;
                             break;
                         case NetworkProperty.LABELOFFSET_X:
                             nud.Value = (decimal)networkItem.LabelOffset.X;
                             break;
                         case NetworkProperty.LABELOFFSET_Y:
                             nud.Value = (decimal)networkItem.LabelOffset.Y;
                             break;
                     }
                 }
                 catch (ArgumentOutOfRangeException e)
                 {
                     this.writeConsole("An error happened, while refresh properties. "+ e.Message);
                 }
             }
             else if (item is AbstractEdge)
             {
                 AbstractEdge edge = (AbstractEdge)item;
                 try
                 {
                     switch (propertyTag)
                     {
                         case NetworkProperty.CURVE_OFFSET_X:
                             nud.Value = (decimal)edge.CurveMiddlePointOffset.X;
                             break;
                         case NetworkProperty.CURVE_OFFSET_Y:
                             nud.Value = (decimal)edge.CurveMiddlePointOffset.Y;
                             break;
                         case NetworkProperty.WEIGHT:
                             nud.Value = (decimal)edge.Weight;
                             break;
                     }
                 }
                 catch (ArgumentOutOfRangeException e)
                 {
                     this.writeConsole("An error happened, while refresh properties. " + e.Message);
                 }
             }
             nud.ValueChanged += new EventHandler(dynamicProperty_ValueChanged);
         }
     }
 }
コード例 #6
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 /// <summary>
 /// Return true, if item (edge, position, transition or note) is selected.
 /// </summary>
 public bool isSelected(AbstractItem item)
 {
     return this.selectedItems.Contains(item);
 }
コード例 #7
0
ファイル: PetriNetwork.cs プロジェクト: davidbedok/UBPNS
 public void addNote(string name, PointF origo, SizeF size, AbstractItem attachedItem)
 {
     this.addItem(new Note(this.identityProvider.noteIdentity(name), this.unidGenNumber++, true, origo, size, attachedItem, "new note"));
 }
コード例 #8
0
 public SearchItemResultTransfer(AbstractItem item, MoveCorner moveEdge)
 {
     this.item = item;
     this.moveEdge = moveEdge;
 }
コード例 #9
0
ファイル: AbstractNote.cs プロジェクト: davidbedok/UBPNS
 public AbstractNote(string name, long unid, bool showAnnotation, PointF origo, SizeF size, AbstractItem attachedItem, string text)
     : base(name, unid, showAnnotation, origo, size)
 {
     this.attachedItem = attachedItem;
        this.text = text;
 }
コード例 #10
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 private void selectItem(AbstractItem item)
 {
     if (!this.selectedItems.Contains(item))
     {
         this.selectedItems.Add(item);
     }
 }
コード例 #11
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 private void unselectItem(AbstractItem item)
 {
     if (this.selectedItems.Contains(item))
     {
         this.selectedItems.Remove(item);
     }
 }
コード例 #12
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 private void removeNoteAttachmentBeforeDelete(AbstractItem item)
 {
     AbstractNote note = this.hasNotes(item);
     if (note != null)
     {
         note.AttachedItem = null;
     }
 }
コード例 #13
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 private AbstractNote hasNotes(AbstractItem aitem)
 {
     AbstractNote ret = null;
     foreach (AbstractNetworkItem item in this.items)
     {
         if (item is AbstractNote)
         {
             AbstractNote note = (AbstractNote)item;
             if (aitem.Equals(note.AttachedItem))
             {
                 ret = note;
                 break;
             }
         }
     }
     return ret;
 }
コード例 #14
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 public void reverseSelection(AbstractItem item)
 {
     if (this.isSelected(item))
     {
         this.unselectItem(item);
     }
     else
     {
         this.selectItem(item);
     }
 }
コード例 #15
0
ファイル: PetriNetworkForm.cs プロジェクト: davidbedok/UBPNS
        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 = "";
        }
コード例 #16
0
ファイル: Note.cs プロジェクト: davidbedok/UBPNS
 public Note(string name, long unid, bool showAnnotation, PointF origo, SizeF size, AbstractItem attachedItem, string text)
     : base(name, unid, showAnnotation, origo, size, attachedItem, text)
 {
 }
コード例 #17
0
ファイル: PropertyTag.cs プロジェクト: davidbedok/UBPNS
 public PropertyTag(AbstractItem parent, AbstractItem item, NetworkProperty property)
 {
     this.parent = parent;
     this.item = item;
     this.property = property;
 }
コード例 #18
0
ファイル: AbstractNetwork.cs プロジェクト: davidbedok/UBPNS
 /// <summary>
 /// Delete item (position, transition or note) and any connected edges.
 /// </summary>
 public void deleteItemAndConnectedEdges(AbstractItem item)
 {
     if (item != null)
     {
         if (item is AbstractNetworkItem)
         {
             AbstractNetworkItem networkItem = (AbstractNetworkItem)item;
             List<AbstractEdge> markToDelete = new List<AbstractEdge>();
             foreach (AbstractEdge edge in this.edges)
             {
                 if (networkItem.Equals(edge.Start) || networkItem.Equals(edge.End))
                 {
                     markToDelete.Add(edge);
                 }
             }
             foreach (AbstractEdge edge in markToDelete)
             {
                 this.deleteEdge(edge);
             }
             this.deleteItem(networkItem);
         }
         else if (item is AbstractEdge)
         {
             AbstractEdge edge = (AbstractEdge)item;
             this.deleteEdge(edge);
         }
     }
 }