Exemplo n.º 1
0
        private void txtInput_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                FeedbackConnectionFindView form = new FeedbackConnectionFindView(this.SelectedInput);
                form.ShowDialog(this);

                if (form.DialogResult == DialogResult.OK)
                {
                    this.SelectedInput   = form.SelectedConnection;
                    this.SelectedDecoder = form.SelectedDecoder;

                    this.SelectedInput.ElementPinIndex = this.ConnectionIndex;
                    this.SelectedInput.Element         = this.Element;
                    FeedbackDecoderConnection.Save(this.SelectedInput);
                }
            }
            else if (e.Button.Index == 1)
            {
                if (this.SelectedInput == null)
                {
                    MessageBox.Show("This connection is not connected to any decoder input.",
                                    Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                AccessoryDecoderConnection.Delete(this.SelectedInput.ID);

                this.SelectedInput   = null;
                this.SelectedDecoder = null;
            }

            ShowSelectedOutput();
        }
Exemplo n.º 2
0
        private void ListFeedbackConnections()
        {
            InputEditorControl        control;
            FeedbackDecoderConnection connection;

            if (!this.Element.Properties.IsFeedback || this.Element.Properties.NumberOfFeedbackConnections <= 0)
            {
                tabFeedbackConnections.PageVisible = false;
                return;
            }

            // Create connection controls
            for (int i = 1; i <= this.Element.Properties.NumberOfFeedbackConnections; i++)
            {
                connection = FeedbackDecoderConnection.GetByIndex(this.Element, i);

                if (connection != null)
                {
                    control = new InputEditorControl(connection);
                }
                else
                {
                    control = new InputEditorControl(this.Element);
                }

                control.ConnectionIndex = i;
                control.Text            = string.Format("Sensor connection {0}", i);
                control.Dock            = DockStyle.Top;

                tabFeedbackConnections.Controls.Add(control);

                control.BringToFront();
            }
        }
Exemplo n.º 3
0
        public FeedbackConnectionFindView(FeedbackDecoderConnection connection)
        {
            InitializeComponent();
            ShowInputs(connection);

            chkShowUnused.Checked = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a new instance of <see cref="OutputEditorControl"/>.
        /// </summary>
        /// <remarks>Constructor for design purposes. Don't use in runtime.</remarks>
        public InputEditorControl(FeedbackDecoderConnection output)
        {
            InitializeComponent();
            Initialize();

            this.FixedHeight     = this.Height;
            this.SelectedInput   = output;
            this.SelectedDecoder = output.Device;
            this.Element         = output.Element;

            ShowSelectedOutput();
        }
Exemplo n.º 5
0
 private void FilterUsedConnections(TreeListNode root, bool unusedOnly)
 {
     foreach (TreeListNode node in root.Nodes)
     {
         if (node.HasChildren)
         {
             this.FilterUsedConnections(node, unusedOnly);
         }
         else
         {
             FeedbackDecoderConnection output = node.Tag as FeedbackDecoderConnection;
             node.Visible = !unusedOnly || (output?.Element == null);
         }
     }
 }
Exemplo n.º 6
0
        void ShowInputs(FeedbackDecoderConnection connection)
        {
            TreeListNode   root;
            TreeListNode   mod;
            TreeListNode   output;
            TreeListColumn col;
            Dictionary <int, FeedbackDecoderConnection> connections;

            tvwConnections.BeginUpdate();

            tvwConnections.Nodes.Clear();
            tvwConnections.Columns.Clear();

            col              = tvwConnections.Columns.Add();
            col.Caption      = "Decoder input";
            col.VisibleIndex = 0;
            col              = tvwConnections.Columns.Add();
            col.Caption      = "Address";
            col.VisibleIndex = 1;
            col              = tvwConnections.Columns.Add();
            col.Caption      = "Element";
            col.VisibleIndex = 2;
            tvwConnections.EndUpdate();

            tvwConnections.BeginUnboundLoad();

            root = tvwConnections.AppendNode(new object[] { "Modules", string.Empty, string.Empty }, null);
            root.StateImageIndex = 4;
            root.Expanded        = true;

            foreach (FeedbackEncoder decoder in OTCContext.Project.FeedbackEncoders)
            {
                mod = tvwConnections.AppendNode(new object[] { decoder.Name, string.Empty, string.Empty }, root);
                mod.StateImageIndex = 1;
                mod.Tag             = decoder;

                connections = new Dictionary <int, FeedbackDecoderConnection>();

                // Create the non existing connections
                foreach (FeedbackDecoderConnection inputConn in decoder.Connections)
                {
                    connections.Add(inputConn.DecoderInput, inputConn);
                }

                for (int inputidx = 1; inputidx <= decoder.Inputs; inputidx++)
                {
                    if (!connections.ContainsKey(inputidx))
                    {
                        connections.Add(inputidx, new FeedbackDecoderConnection()
                        {
                            DecoderInput = inputidx,
                            Address      = decoder.StartAddress + inputidx - 1,
                            Device       = decoder,
                            Element      = null
                        });
                    }
                }

                foreach (FeedbackDecoderConnection con in connections.Values)
                {
                    if (con.IsNew || this.ShowUsedConnections)
                    {
                        output = tvwConnections.AppendNode(new object[] { con.DecoderInput,
                                                                          con.Address.ToString("D4"),
                                                                          con.Element == null ? "<empty>" : con.Element.Name }, mod);
                        output.StateImageIndex = (con.Element == null ? 2 : 3);
                        output.Tag             = con;

                        if (connection?.ID == con.ID)
                        {
                            tvwConnections.FocusedNode = output;
                        }
                    }
                }
            }

            if (tvwConnections.FocusedNode != null && tvwConnections.FocusedNode != root)
            {
                tvwConnections.MakeNodeVisible(tvwConnections.FocusedNode);
            }
            else
            {
                root.Expanded = true;
            }

            tvwConnections.EndUnboundLoad();
        }