Skip to content

Commit 9ff4595

Browse files
committed
Fix for #883
In addition to resolving this, I've moved the code into Helios.Controls (leaving a stub in DH98Mosquito for backwards compatibility). The toolbox Locking Three Way Toggle Switch is now a Helios.Base.LockingThreeWayToggleSwitch instead of Helios.DH98Mosquito.LockingThreeWayToggleSwitch which was the case in 1.6.6150.2. The consequence of this is that if someone with a dev build of Helios pulls out a Locking Three Way Toggle Switch from the toolbox, then it will not be available to users running 1.6.6150.2 and will potentially case an exception during profile load. If you're editing an existing control in a profile from 1.6.6150.2, then you'll be ok If you need to create a new Locking Three Way Toggle Switch, add it from the toolbox using Helios 1.6.6150.2, save the profile, then edit the control in the Dev Build
1 parent ed9ecf2 commit 9ff4595

File tree

5 files changed

+197
-151
lines changed

5 files changed

+197
-151
lines changed

Aircraft Mosquito Plugin/Controls/LockingThreeWayToggleSwitch.cs

Lines changed: 5 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -18,169 +18,23 @@ namespace GadrocsWorkshop.Helios.Controls.DH98Mosquito
1818
{
1919
using GadrocsWorkshop.Helios.Controls;
2020
using GadrocsWorkshop.Helios.ComponentModel;
21-
using GadrocsWorkshop.Helios.Controls.Capabilities;
22-
using System;
23-
using System.Xml;
24-
using static GadrocsWorkshop.Helios.Interfaces.DCS.Common.NetworkTriggerValue;
2521

26-
[HeliosControl("Helios.DH98Mosquito.LockingThreeWayToggleSwitch", "Locking Three Way Toggle Switches", "Three Way Toggle Switches", typeof(ThreeWayToggleSwitchRenderer), HeliosControlFlags.None)]
27-
public class LockingThreeWayToggleSwitch : ThreeWayToggleSwitch
22+
[HeliosControl("Helios.DH98Mosquito.LockingThreeWayToggleSwitch", "Locking Three Way Toggle Switches", "Three Way Toggle Switches", typeof(ThreeWayToggleSwitchRenderer), HeliosControlFlags.NotShownInUI)]
23+
public class LockingThreeWayToggleSwitch : Controls.ThreeWayToggleSwitchLocking
2824
{
29-
private HeliosValue _positionOneLockValue;
30-
private HeliosValue _positionTwoLockValue;
31-
private HeliosValue _positionThreeLockValue;
32-
33-
private bool _positionOneLocked = false;
34-
private bool _positionTwoLocked = false;
35-
private bool _positionThreeLocked = false;
36-
public LockingThreeWayToggleSwitch() : this("Locking Three Way Toggle Switch", new System.Windows.Size(50, 100)) {}
37-
public LockingThreeWayToggleSwitch(string name, System.Windows.Size size)
38-
: base(name, size)
39-
{
40-
_positionOneLockValue = new HeliosValue(this, BindingValue.Empty, "", "position one lock", "Lock Position 1.", "True / False", BindingValueUnits.Boolean);
41-
_positionOneLockValue.Execute += PositionOneLock_Execute;
42-
Values.Add(_positionOneLockValue);
43-
Actions.Add(_positionOneLockValue);
44-
_positionTwoLockValue = new HeliosValue(this, BindingValue.Empty, "", "position two lock", "Lock Position 2.", "True / False", BindingValueUnits.Boolean);
45-
_positionTwoLockValue.Execute += PositionTwoLock_Execute;
46-
Values.Add(_positionTwoLockValue);
47-
Actions.Add(_positionTwoLockValue);
48-
_positionThreeLockValue = new HeliosValue(this, BindingValue.Empty, "", "position three lock", "Lock Position 3.", "True / False", BindingValueUnits.Boolean);
49-
_positionThreeLockValue.Execute += PositionThreeLock_Execute;
50-
Values.Add(_positionThreeLockValue);
51-
Actions.Add(_positionThreeLockValue);
52-
53-
}
25+
// Retained for Backwards Compatibility following move of this control to Helios.Controls
26+
public LockingThreeWayToggleSwitch() : base("Locking Three Way Toggle Switch", new System.Windows.Size(50, 100)) { }
27+
public LockingThreeWayToggleSwitch(string name, System.Windows.Size size) : base(name, size) { }
5428

5529
#region Properties
5630

5731
#endregion
5832

59-
void PositionOneLock_Execute(object action, HeliosActionEventArgs e)
60-
{
61-
_positionOneLocked = e.Value.BoolValue;
62-
}
63-
void PositionTwoLock_Execute(object action, HeliosActionEventArgs e)
64-
{
65-
_positionTwoLocked = e.Value.BoolValue;
66-
}
67-
void PositionThreeLock_Execute(object action, HeliosActionEventArgs e)
68-
{
69-
_positionThreeLocked = e.Value.BoolValue;
70-
}
7133
#region HeliosControl Implementation
7234

73-
public override void Reset()
74-
{
75-
base.Reset();
76-
77-
BeginTriggerBypass(true);
78-
SwitchPosition = DefaultPosition;
79-
EndTriggerBypass(true);
80-
}
81-
82-
protected override void ThrowSwitch(ToggleSwitchBase.SwitchAction action)
83-
{
84-
if (action == SwitchAction.Increment)
85-
{
86-
switch (SwitchPosition)
87-
{
88-
case ThreeWayToggleSwitchPosition.One:
89-
if (!_positionTwoLocked)
90-
{
91-
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
92-
}
93-
break;
94-
case ThreeWayToggleSwitchPosition.Two:
95-
if (!_positionThreeLocked)
96-
{
97-
SwitchPosition = ThreeWayToggleSwitchPosition.Three;
98-
}
99-
break;
100-
}
101-
}
102-
else if (action == SwitchAction.Decrement)
103-
{
104-
switch (SwitchPosition)
105-
{
106-
case ThreeWayToggleSwitchPosition.Two:
107-
if (!_positionOneLocked)
108-
{
109-
SwitchPosition = ThreeWayToggleSwitchPosition.One;
110-
}
111-
break;
112-
case ThreeWayToggleSwitchPosition.Three:
113-
if (!_positionTwoLocked)
114-
{
115-
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
116-
}
117-
break;
118-
}
119-
}
120-
}
121-
122-
public override void MouseUp(System.Windows.Point location)
123-
{
124-
base.MouseUp(location);
125-
126-
switch (SwitchPosition)
127-
{
128-
case ThreeWayToggleSwitchPosition.One:
129-
if (SwitchType == ThreeWayToggleSwitchType.MomOnMom || SwitchType == ThreeWayToggleSwitchType.MomOnOn)
130-
{
131-
if (!_positionTwoLocked)
132-
{
133-
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
134-
}
135-
}
136-
break;
137-
case ThreeWayToggleSwitchPosition.Three:
138-
if (SwitchType == ThreeWayToggleSwitchType.OnOnMom || SwitchType == ThreeWayToggleSwitchType.MomOnMom)
139-
{
140-
if (!_positionTwoLocked)
141-
{
142-
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
143-
}
144-
}
145-
break;
146-
}
147-
}
148-
149-
public override void WriteXml(XmlWriter writer)
150-
{
151-
base.WriteXml(writer);
152-
}
153-
154-
public override void ReadXml(XmlReader reader)
155-
{
156-
base.ReadXml(reader);
157-
}
158-
15935
#endregion
16036

16137
#region Actions
162-
163-
void SetPositionAction_Execute(object action, HeliosActionEventArgs e)
164-
{
165-
try
166-
{
167-
BeginTriggerBypass(e.BypassCascadingTriggers);
168-
int newPosition = 0;
169-
if (int.TryParse(e.Value.StringValue, out newPosition))
170-
{
171-
if (newPosition > 0 && newPosition <= 3)
172-
{
173-
SwitchPosition = (ThreeWayToggleSwitchPosition)newPosition;
174-
}
175-
}
176-
EndTriggerBypass(e.BypassCascadingTriggers);
177-
}
178-
catch
179-
{
180-
// No-op if the parse fails we won't set the position.
181-
}
182-
}
183-
18438
#endregion
18539
}
18640
}

Helios/Controls/ThreeWayToggleSwitchAppearanceEditor.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace GadrocsWorkshop.Helios.Controls
2222
/// Interaction logic for ToggleSwitchAppearanceEditor.xaml
2323
/// </summary>
2424
[HeliosPropertyEditor("Helios.Base.ThreeWayToggleSwitch", "Appearance")]
25+
[HeliosPropertyEditor("Helios.Base.LockingThreeWayToggleSwitch", "Appearance")]
26+
[HeliosPropertyEditor("Helios.DH98Mosquito.LockingThreeWayToggleSwitch", "Appearance")]
27+
2528
public partial class ThreeWayToggleSwitchAppearanceEditor : HeliosPropertyEditor
2629
{
2730
public ThreeWayToggleSwitchAppearanceEditor()

Helios/Controls/ThreeWayToggleSwitchBehaviorEditor.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace GadrocsWorkshop.Helios.Controls
2323
/// </summary>
2424
[HeliosPropertyEditor("Helios.Base.ThreeWayToggleSwitch", "Behavior")]
2525
[HeliosPropertyEditor("Helios.Base.RockerSwitch", "Behavior")]
26+
[HeliosPropertyEditor("Helios.Base.LockingThreeWayToggleSwitch", "Behavior")]
27+
[HeliosPropertyEditor("Helios.DH98Mosquito.LockingThreeWayToggleSwitch", "Behavior")]
28+
2629
public partial class ThreeWayToggleSwitchBehaviorEditor : HeliosPropertyEditor
2730
{
2831
public ThreeWayToggleSwitchBehaviorEditor()
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Copyright 2014 Craig Courtney
2+
// Copyright 2025 Helios Contributors
3+
//
4+
// Helios is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Helios is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace GadrocsWorkshop.Helios.Controls
18+
{
19+
using GadrocsWorkshop.Helios.Controls;
20+
using GadrocsWorkshop.Helios.ComponentModel;
21+
using GadrocsWorkshop.Helios.Controls.Capabilities;
22+
using System;
23+
using System.Xml;
24+
25+
[HeliosControl("Helios.Base.LockingThreeWayToggleSwitch", "Locking Three Way Toggle Switches", "Three Way Toggle Switches", typeof(ThreeWayToggleSwitchRenderer), HeliosControlFlags.None)]
26+
public class ThreeWayToggleSwitchLocking : ThreeWayToggleSwitch
27+
{
28+
private HeliosValue _positionOneLockValue;
29+
private HeliosValue _positionTwoLockValue;
30+
private HeliosValue _positionThreeLockValue;
31+
32+
private bool _positionOneLocked = false;
33+
private bool _positionTwoLocked = false;
34+
private bool _positionThreeLocked = false;
35+
public ThreeWayToggleSwitchLocking() : this("Locking Three Way Toggle Switch", new System.Windows.Size(50, 100)) {}
36+
public ThreeWayToggleSwitchLocking(string name, System.Windows.Size size)
37+
: base(name, size)
38+
{
39+
_positionOneLockValue = new HeliosValue(this, BindingValue.Empty, "", "position one lock", "Lock Position 1.", "True / False", BindingValueUnits.Boolean);
40+
_positionOneLockValue.Execute += PositionOneLock_Execute;
41+
Values.Add(_positionOneLockValue);
42+
Actions.Add(_positionOneLockValue);
43+
_positionTwoLockValue = new HeliosValue(this, BindingValue.Empty, "", "position two lock", "Lock Position 2.", "True / False", BindingValueUnits.Boolean);
44+
_positionTwoLockValue.Execute += PositionTwoLock_Execute;
45+
Values.Add(_positionTwoLockValue);
46+
Actions.Add(_positionTwoLockValue);
47+
_positionThreeLockValue = new HeliosValue(this, BindingValue.Empty, "", "position three lock", "Lock Position 3.", "True / False", BindingValueUnits.Boolean);
48+
_positionThreeLockValue.Execute += PositionThreeLock_Execute;
49+
Values.Add(_positionThreeLockValue);
50+
Actions.Add(_positionThreeLockValue);
51+
52+
}
53+
54+
#region Properties
55+
56+
#endregion
57+
58+
void PositionOneLock_Execute(object action, HeliosActionEventArgs e)
59+
{
60+
_positionOneLocked = e.Value.BoolValue;
61+
}
62+
void PositionTwoLock_Execute(object action, HeliosActionEventArgs e)
63+
{
64+
_positionTwoLocked = e.Value.BoolValue;
65+
}
66+
void PositionThreeLock_Execute(object action, HeliosActionEventArgs e)
67+
{
68+
_positionThreeLocked = e.Value.BoolValue;
69+
}
70+
#region HeliosControl Implementation
71+
72+
public override void Reset()
73+
{
74+
base.Reset();
75+
76+
BeginTriggerBypass(true);
77+
SwitchPosition = DefaultPosition;
78+
EndTriggerBypass(true);
79+
}
80+
81+
protected override void ThrowSwitch(ToggleSwitchBase.SwitchAction action)
82+
{
83+
if (action == SwitchAction.Increment)
84+
{
85+
switch (SwitchPosition)
86+
{
87+
case ThreeWayToggleSwitchPosition.One:
88+
if (!_positionTwoLocked)
89+
{
90+
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
91+
}
92+
break;
93+
case ThreeWayToggleSwitchPosition.Two:
94+
if (!_positionThreeLocked)
95+
{
96+
SwitchPosition = ThreeWayToggleSwitchPosition.Three;
97+
}
98+
break;
99+
}
100+
}
101+
else if (action == SwitchAction.Decrement)
102+
{
103+
switch (SwitchPosition)
104+
{
105+
case ThreeWayToggleSwitchPosition.Two:
106+
if (!_positionOneLocked)
107+
{
108+
SwitchPosition = ThreeWayToggleSwitchPosition.One;
109+
}
110+
break;
111+
case ThreeWayToggleSwitchPosition.Three:
112+
if (!_positionTwoLocked)
113+
{
114+
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
115+
}
116+
break;
117+
}
118+
}
119+
}
120+
121+
public override void MouseUp(System.Windows.Point location)
122+
{
123+
base.MouseUp(location);
124+
125+
switch (SwitchPosition)
126+
{
127+
case ThreeWayToggleSwitchPosition.One:
128+
if (SwitchType == ThreeWayToggleSwitchType.MomOnMom || SwitchType == ThreeWayToggleSwitchType.MomOnOn)
129+
{
130+
if (!_positionTwoLocked)
131+
{
132+
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
133+
}
134+
}
135+
break;
136+
case ThreeWayToggleSwitchPosition.Three:
137+
if (SwitchType == ThreeWayToggleSwitchType.OnOnMom || SwitchType == ThreeWayToggleSwitchType.MomOnMom)
138+
{
139+
if (!_positionTwoLocked)
140+
{
141+
SwitchPosition = ThreeWayToggleSwitchPosition.Two;
142+
}
143+
}
144+
break;
145+
}
146+
}
147+
148+
public override void WriteXml(XmlWriter writer)
149+
{
150+
base.WriteXml(writer);
151+
}
152+
153+
public override void ReadXml(XmlReader reader)
154+
{
155+
base.ReadXml(reader);
156+
}
157+
158+
#endregion
159+
160+
#region Actions
161+
162+
void SetPositionAction_Execute(object action, HeliosActionEventArgs e)
163+
{
164+
try
165+
{
166+
BeginTriggerBypass(e.BypassCascadingTriggers);
167+
int newPosition = 0;
168+
if (int.TryParse(e.Value.StringValue, out newPosition))
169+
{
170+
if (newPosition > 0 && newPosition <= 3)
171+
{
172+
SwitchPosition = (ThreeWayToggleSwitchPosition)newPosition;
173+
}
174+
}
175+
EndTriggerBypass(e.BypassCascadingTriggers);
176+
}
177+
catch
178+
{
179+
// No-op if the parse fails we won't set the position.
180+
}
181+
}
182+
183+
#endregion
184+
}
185+
}

Helios/Helios.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<DependentUpon>AlternateImageAppearanceEditor.xaml</DependentUpon>
104104
</Compile>
105105
<Compile Include="Controls\Capabilities\IRefreshableImage.cs" />
106+
<Compile Include="Controls\ThreeWayToggleSwitchLocking.cs" />
106107
<Compile Include="Controls\RotaryEncoderIndcatorClickable.cs" />
107108
<Compile Include="Controls\PotentiometerIndcatorClickable.cs" />
108109
<Compile Include="Controls\RotaryEncoderClickableAppearanceEditor.xaml.cs">

0 commit comments

Comments
 (0)