DICtrl.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Aitex.Core.RT.Simulator;
  10. namespace Aitex.Core.Backend
  11. {
  12. public partial class DICtrl : UserControl
  13. {
  14. //public Action<string, bool> SetSimulatorValue;
  15. //private string _ioName;
  16. //private bool _rawValue;
  17. //private string _group;
  18. public string IOName { get; set; }
  19. public bool RawValue { get; private set; }
  20. public string LabelName
  21. {
  22. get => this.labelRaw.Text;
  23. set => this.labelRaw.Text = value;
  24. }
  25. public DICtrl()
  26. {
  27. InitializeComponent();
  28. }
  29. //public void SetIoName(string group, string ioName)
  30. //{
  31. // _ioName = ioName;
  32. // _group = group;
  33. //}
  34. //public void SetName(string name)
  35. //{
  36. // this.labelRaw.Text = name;
  37. //}
  38. public void SetValue(bool latchedValue, bool rawValue)
  39. {
  40. RawValue = rawValue;
  41. //this.labelValue.BackColor = latchedValue ? Color.Lime : Color.LightGray;
  42. this.labelRaw.BackColor = rawValue ? Color.Lime : Color.LightGray;
  43. }
  44. /*
  45. public void SetValue(bool latchedValue, bool rawValue, bool force)
  46. {
  47. //if ((this.labelName.BackColor == Color.Lime) == value)
  48. // return;
  49. this.labelName.BackColor = latchedValue ? Color.Lime : Color.LightGray;
  50. this.labelName.ForeColor = (latchedValue != rawValue) ? Color.Red : Color.Black;
  51. if (!force)
  52. {
  53. this.rbtAuto.BackColor = Color.LightGray;
  54. this.rbt0.BackColor = Color.LightGray;
  55. this.rbt1.BackColor = Color.LightGray;
  56. }
  57. else
  58. {
  59. if (latchedValue)
  60. {
  61. this.rbtAuto.BackColor = Color.LightGray;
  62. this.rbt0.BackColor = Color.LightGray;
  63. this.rbt1.BackColor = Color.Red;
  64. }
  65. else
  66. {
  67. this.rbtAuto.BackColor = Color.LightGray;
  68. this.rbt0.BackColor = Color.Red;
  69. this.rbt1.BackColor = Color.LightGray;
  70. }
  71. }
  72. }
  73. public bool? GetValue()
  74. {
  75. if (rbtAuto.Checked)
  76. return null;
  77. else if (rbt0.Checked)
  78. return false;
  79. else if (rbt1.Checked)
  80. return true;
  81. return null;
  82. }*/
  83. private void rbtAuto_CheckedChanged(object sender, EventArgs e)
  84. {
  85. //if (((RadioButton)sender).Checked)
  86. //{
  87. // if (Reactor.IsSimulation)
  88. // Simulation.Sim_TcAdsClient.Instance.DI_Forced[(int)Tag] = false;
  89. //}
  90. }
  91. private void rbt1_CheckedChanged(object sender, EventArgs e)
  92. {
  93. //if (((RadioButton)sender).Checked)
  94. //{
  95. // if (Reactor.IsSimulation)
  96. // {
  97. // Simulation.Sim_TcAdsClient.Instance.DI_Forced[(int)Tag] = true;
  98. // Simulation.Sim_TcAdsClient.Instance.INPUT.DI[(int)Tag] = 1;
  99. // }
  100. //}
  101. }
  102. private void rbt0_CheckedChanged(object sender, EventArgs e)
  103. {
  104. //if (((RadioButton)sender).Checked)
  105. //{
  106. // if (Reactor.IsSimulation)
  107. // {
  108. // Simulation.Sim_TcAdsClient.Instance.DI_Forced[(int)Tag] = true;
  109. // Simulation.Sim_TcAdsClient.Instance.INPUT.DI[(int)Tag] = 0;
  110. // }
  111. //}
  112. }
  113. private void labelName_Click(object sender, EventArgs e)
  114. {
  115. }
  116. //private void ButtonSet_Click(object sender, EventArgs e)
  117. //{
  118. // if (SetSimulatorValue != null)
  119. // SetSimulatorValue(_ioName, !_rawValue);
  120. //}
  121. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  122. {
  123. if (checkBox1.Checked)
  124. {
  125. checkBox2.Checked = RawValue;
  126. DiForce.Instance.Set(IOName, checkBox2.Checked);
  127. checkBox2.Enabled = true;
  128. this.BackColor = Color.DodgerBlue;
  129. }
  130. else
  131. {
  132. DiForce.Instance.Unset(IOName);
  133. checkBox2.Enabled = false;
  134. this.BackColor = Color.White;
  135. }
  136. }
  137. private void checkBox2_CheckedChanged(object sender, EventArgs e)
  138. {
  139. DiForce.Instance.Set(IOName, checkBox2.Checked);
  140. }
  141. }
  142. }