Exemple #1
0
		public void Draw (Graphics graphics, Route route, bool atEnd)
		{
			if (graphics == null) return;
			if (route == null) return;
			GraphicsState state = graphics.Save();
			float direction = 0;
			PointF pos = default(PointF);
			if (atEnd)
			{
				pos = route.GetEndPoint();
				direction = ConvertDirection(route.GetEndDirection());
			}
			else
			{
				pos = route.GetStartPoint();
				direction = ConvertDirection(route.GetStartDirection());
			}
			
			// In matrix math, the correct way is to put rotation BEFORE
			// translation. However, the simple transformation maethods of
			// GDI+ works in "Prepend" mode, which reverses the order of
			// operations.
			graphics.TranslateTransform(pos.X, pos.Y);
			graphics.RotateTransform(direction);
			
			Paint(graphics);
			graphics.Restore(state);
		}
Exemple #2
0
        public ChannelEditForm(Route route, LTSCanvas canvas, NetMode mode)
        {
            do
            {
                InitializeComponent();

                mChannel = (WSNChannel)route;
                mMode = mode;
                mCanvas = canvas;

                List<LTSCanvas.CanvasItemData> canvasItems = canvas.itemsList;
                foreach (LTSCanvas.CanvasItemData itemData in canvasItems)
                {
                    if (itemData.Item is StateItem)
                    {
                        this.cmbSource.Items.Add(itemData.Item);
                        this.cmbDest.Items.Add(itemData.Item);

                        if (itemData.Item.Equals(route.From))
                            this.cmbSource.SelectedItem = itemData.Item;

                        if (itemData.Item.Equals(route.To))
                            this.cmbDest.SelectedItem = itemData.Item;
                    }
                }

                if (!mMode.Equals(NetMode.MULTICAST))
                {
                    txtSensorsConn.Visible = false;
                    lblSensorsConn.Visible = false;
                    break;
                }

                StringBuilder subConn = new StringBuilder();
                subConn.Append(((WSNSensor)mChannel.To).ID.ToString());

                foreach (int item in mChannel.SubIdList)
                    subConn.Append("," + item);

                txtSensorsConn.Text = subConn.ToString();
            } while (false);
        }
Exemple #3
0
        void Canvas_CanvasRouteSelected(object sender, CanvasRouteEventArgs e)
        {
            this.SelectedItems.Clear();
            if (this.Button_AddNewNail.Checked)
            {
                Button_AddNewNail_Click(sender, e);
                Button_AddNewNail.Checked = false;

            }
            else
            {
                SelectedRoute = e.CanvasItem;
                this.Button_Delete.Enabled = true;
            }
            //Button_AddToken.Enabled = false;
            //Button_DeleteToken.Enabled = false;
        }
Exemple #4
0
 public void RemoveCanvasRoute(Route route)
 {
     this.Canvas.RemoveCanvasRoute(route);
     StoreCurrentCanvas();
 }
Exemple #5
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);
            }
        }
Exemple #6
0
 protected override Form CreateTransitionEditForm(Route route)
 {
     return new ChannelEditForm(route, Canvas, Build.mMode);
 }
Exemple #7
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);
        }
Exemple #8
0
 private void AddLink(Route route)
 {
     this.Canvas.AddLink(route);
     StoreCurrentCanvas();
 }
Exemple #9
0
 /// <summary>
 /// Create form for edit transition
 /// </summary>
 /// <param name="route"></param>
 /// <param name="items"></param>
 /// <returns></returns>
 protected virtual Form CreateTransitionEditForm(Route route)
 {
     return null;
 }
Exemple #10
0
        private void EditingLink(Route route)
        {
            Form form = CreateTransitionEditForm(route);
            if (form.ShowDialog() == DialogResult.OK)
            {
                this.StoreCurrentCanvas();
                SetDirty();
            }

            Canvas.Refresh();
        }