Exemplo n.º 1
0
 void OnItemSelected(object sender, CanvasItemEventArgs e)
 {
     if (e.CanvasItem is ClassCanvasItem)
     {
         classeditor.SetClass(((ClassCanvasItem)e.CanvasItem).RepresentedClassType);
     }
     else
     {
         classeditor.SetClass(null);
     }
 }
        private void Canvas_ItemDoubleClick(object sender, CanvasItemEventArgs e)
        {
            if (e.CanvasItem.Item is StateItem)
            {                                             //a state node is clicked
                StateItem editedState = e.CanvasItem.Item as StateItem;
                string    sName       = editedState.Name; //the name of the sensor clicked on the canvas

                MessageBox.Show("The state clicked is " + sName, "State information",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 3
0
        private void Canvas_CanvasItemSelected(object sender, CanvasItemEventArgs e)
        {
            if (this.Button_AddLink.Checked)
            {
                if (this.SelectedItems.Count > 0 && e.CanvasItem != null)
                {
                    CanvasItemData SelectedItem = this.SelectedItems[0];
                    if (SelectedItem.Item is StateItem && e.CanvasItem.Item is StateItem
                        && SelectedItem.Item.GetType() != e.CanvasItem.Item.GetType())
                    {
                        StateItem sourceState = SelectedItem.Item as StateItem;
                        StateItem targetState = e.CanvasItem.Item as StateItem;
                        PNArc r = new PNArc(SelectedItem.Item, targetState);
                        if (sourceState is PNTransition)
                        {
                            (sourceState as PNTransition).OutputPlaces.Add(targetState as PNPlace);
                        }
                        else
                        {
                            (targetState as PNTransition).InputPlaces.Add(sourceState as PNPlace);
                        }
                        this.AddLink(r);
                        SetDirty();

                    }

                    e.CanvasItem.Item.HandleMouseUp(new PointF());
                    Button_AddLink.Checked = false;
                }
                else if (this.SelectedItems.Count == 0 && e.CanvasItem != null)
                {
                    //Select the starting state of route
                    this.SelectedItems.Clear();
                    this.SelectedItems.Add(e.CanvasItem);
                    Canvas.temporaryNails.Add((e.CanvasItem.Item as StateItem).Center());
                }
                else if (this.SelectedItems.Count > 0 && e.CanvasItem == null)
                {
                    //Click on canvas to create a new nail
                    Canvas.temporaryNails.Add(this.Canvas.LastMouseClickPosition);
                }

            }
            else
            {
                this.SelectedItems.Clear();
                if (e.CanvasItem != null)
                {
                    this.SelectedItems.Add(e.CanvasItem);
                    e.CanvasItem.Item.HandleSelected(this.Canvas);
                }
                CanvasItemData SelectedItem = e.CanvasItem;
                if (SelectedItem == null)
                {
                    //Button_AddToken.Enabled = false;
                    //Button_DeleteToken.Enabled = false;
                    if (Button_AddNewState.Checked)
                    {
                        Button_AddNewState_Click(sender, e);
                        Button_AddNewState.Checked = false;
                    }

                    if (Button_AddNewTransition.Checked)
                    {
                        Button_AddNewTransition_Click(sender, e);
                        Button_AddNewTransition.Checked = false;
                    }
                }
                else
                {
                    //if (e.CanvasItem.Item is PNPlace && Button_AddToken.Checked)
                    //{
                    //    PNPlace place = e.CanvasItem.Item as PNPlace;
                    //    place.NumberOfTokens++;
                    //    Button_AddToken.Checked = false;
                    //    Canvas.Refresh();
                    //    SetDirty();
                    //}

                    //if (e.CanvasItem.Item is PNPlace && Button_DeleteToken.Checked)
                    //{
                    //    PNPlace place = e.CanvasItem.Item as PNPlace;
                    //    place.NumberOfTokens--;
                    //    Button_DeleteToken.Checked = false;
                    //    Canvas.Refresh();
                    //    SetDirty();
                    //}

                    //if (e.CanvasItem.Item is PNTransition)
                    //{
                    //    Button_AddToken.Enabled = false;
                    //    Button_DeleteToken.Enabled = false;
                    //}
                }
            }
            SelectedRoute = null;
            this.Button_Delete.Enabled = (this.SelectedItems.Count > 0);
            if (SelectedItems.Count == 1 && SelectedItems[0].Item is PNPlace)
            {
                //Button_AddToken.Enabled = true;
                //PNPlace place = SelectedItems[0].Item as PNPlace;
                //Button_DeleteToken.Enabled = (place.NumberOfTokens > 0);
            }
        }
Exemplo n.º 4
0
        private void Canvas_ItemDoubleClick(object sender, CanvasItemEventArgs e)
        {
            if (e.CanvasItem.Item is PNPlace)
            {
                PNPlace editedState = e.CanvasItem.Item as PNPlace;
                PlaceEditingForm form = new PlaceEditingForm(editedState);
                string lastName = editedState.Name;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    this.StoreCurrentCanvas();
                    SetDirty();
                    if (!this.Canvas.CheckStateNameDuplicate())
                    {
                        editedState.Name = lastName;
                    }
                }
                Canvas.Refresh();
            }

            if (e.CanvasItem.Item is PNTransition)
            {
                PNTransition editedState = e.CanvasItem.Item as PNTransition;
                TransitionEditingForm form = new TransitionEditingForm(editedState);
                string lastName = editedState.Name;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    this.StoreCurrentCanvas();
                    SetDirty();
                    if (!this.Canvas.CheckStateNameDuplicate())
                    {
                        editedState.Name = lastName;
                    }
                }
                Canvas.Refresh();
            }
        }
Exemplo n.º 5
0
        private void Canvas_ItemDoubleClick(object sender, CanvasItemEventArgs e)
        {
            if (e.CanvasItem.Item is StateItem)
            {
                StateItem editedState = e.CanvasItem.Item as StateItem;
                string lastName = editedState.Name;
                Form form = CreateItemEditForm(editedState);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    this.StoreCurrentCanvas();
                    SetDirty();
                    if (!this.Canvas.CheckStateNameDuplicate())
                        editedState.Name = lastName;
                }

                Canvas.Refresh();
            }
        }
Exemplo n.º 6
0
        private void Canvas_CanvasItemSelected(object sender, CanvasItemEventArgs e)
        {
            SelectedRoute = null;
            if (this.Button_AddLink.Checked)
            {
                if (this.SelectedItems.Count > 0 && e.CanvasItem != null)
                {
                    CanvasItemData SelectedItem = this.SelectedItems[0];
                    if (SelectedItem.Item is StateItem && e.CanvasItem.Item is StateItem)
                    {
                        StateItem sourceState = SelectedItem.Item as StateItem;
                        StateItem targetState = e.CanvasItem.Item as StateItem;
                        Route r = CreateRoute(sourceState, targetState);
                        this.AddLink(r);
                        SetDirty();

                        // update config
                        UpdateConfig();
                    }

                    e.CanvasItem.Item.HandleMouseUp(new PointF());
                    Button_AddLink.Checked = false;
                }
                else if (this.SelectedItems.Count == 0 && e.CanvasItem != null && e.CanvasItem.Item is StateItem)
                {
                    //Select the starting state of route
                    this.SelectedItems.Clear();
                    this.SelectedItems.Add(e.CanvasItem);
                    Canvas.temporaryNails.Add((e.CanvasItem.Item as StateItem).Center());
                }
                else if (this.SelectedItems.Count > 0 && e.CanvasItem == null)
                {
                    //Click on canvas to create a new nail
                    Canvas.temporaryNails.Add(this.Canvas.LastMouseClickPosition);
                }
            }
            else
            {
                this.SelectedItems.Clear();
                if (e.CanvasItem != null)
                {
                    this.SelectedItems.Add(e.CanvasItem);
                    e.CanvasItem.Item.HandleSelected(this.Canvas);
                    if (e.CanvasItem.Item is Transition)
                    {
                        Route route = (e.CanvasItem.Item as Transition).FindSelectedRouteBasedOnTransition(this.Canvas);
                        this.SelectedRoute = route;
                    }
                }

                CanvasItemData SelectedItem = e.CanvasItem;
                if (SelectedItem == null && this.Button_AddNewState.Checked)
                {
                    Button_AddNewState_Click(sender, e);
                    Button_AddNewState.Checked = false;
                }
            }

            this.Button_Delete.Enabled = (this.SelectedItems.Count > 0);
        }