From 69668a88292707c9dd199f80c692ab0d76743aad Mon Sep 17 00:00:00 2001 From: Jeff Uchitjil Date: Wed, 26 Jun 2013 17:15:55 -0500 Subject: [PATCH 1/3] Clean up and consolidate children logic to simplify the editors. Fix a bug where null targets can disrupt the editors. --- .../ColorGradientTypeEditorControl.cs | 31 +++-------------- .../ColorTypeEditor/ColorTypeEditorControl.cs | 31 +++-------------- Modules/Property/Color/ColorProperty.cs | 34 +++++++++++-------- 3 files changed, 29 insertions(+), 67 deletions(-) diff --git a/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs b/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs index a12ebfd3d..adf218a06 100644 --- a/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs +++ b/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs @@ -34,43 +34,22 @@ public IEffect TargetEffect { _targetEffect = value; _discreteColors = false; + if (_targetEffect == null) return; + + HashSet validColors = new HashSet(); // look for the color property of the target effect element, and restrict the gradient. // If it's a group, iterate through all children (and their children, etc.), finding as many color // properties as possible; then we can decide what to do based on that. - validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => GetValidColorsForElementNode(x))); - + validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x))); + _discreteColors = validColors.Any(); _validDiscreteColors = validColors; UpdateGradientImage(); } } - private HashSet GetValidColorsForElementNode(ElementNode elementNode) - { - HashSet validColors = new HashSet(); - switch (ColorModule.getColorTypeForElementNode(elementNode)) - { - case ElementColorType.FullColor: - break; - - case ElementColorType.MultipleDiscreteColors: - case ElementColorType.SingleColor: - _discreteColors = true; - validColors.AddRange(ColorModule.getValidColorsForElementNode(elementNode)); - break; - } - - //recurse the children - if (elementNode.Children.Any()) - { - validColors.AddRange(elementNode.Children.SelectMany(x => GetValidColorsForElementNode(x))); - } - - return validColors; - } - public object[] EffectParameterValues { get { return new object[] { ColorGradientValue }; } diff --git a/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs b/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs index 1436fb359..47eca9252 100644 --- a/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs +++ b/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs @@ -34,42 +34,19 @@ public IEffect TargetEffect { _targetEffect = value; _discreteColors = false; + if (_targetEffect == null) return; + HashSet validColors = new HashSet(); // look for the color property of the target effect element, and restrict the gradient. // If it's a group, iterate through all children (and their children, etc.), finding as many color // properties as possible; then we can decide what to do based on that. - validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => GetValidColorsForElementNode(x))); - + validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x))); + _discreteColors = validColors.Any(); _validDiscreteColors = validColors; } } - private HashSet GetValidColorsForElementNode(ElementNode elementNode) - { - HashSet validColors = new HashSet(); - switch (ColorModule.getColorTypeForElementNode(elementNode)) - { - case ElementColorType.FullColor: - break; - - case ElementColorType.MultipleDiscreteColors: - case ElementColorType.SingleColor: - _discreteColors = true; - validColors.AddRange(ColorModule.getValidColorsForElementNode(elementNode)); - break; - } - - //recurse the children - if (elementNode.Children.Any()) - { - validColors.AddRange(elementNode.Children.SelectMany(x => GetValidColorsForElementNode(x))); - } - - return validColors; - } - - public object[] EffectParameterValues { get { return new object[] { ColorValue }; } diff --git a/Modules/Property/Color/ColorProperty.cs b/Modules/Property/Color/ColorProperty.cs index 8acd7df99..b80531ccc 100644 --- a/Modules/Property/Color/ColorProperty.cs +++ b/Modules/Property/Color/ColorProperty.cs @@ -119,7 +119,6 @@ public ColorSet Colors } } - // static 'helper' methods in the color property // gets the color type for a given element node. If no color properties are defined, it's assumed to be "full color". public static ElementColorType getColorTypeForElementNode(ElementNode element) @@ -133,24 +132,31 @@ public static ElementColorType getColorTypeForElementNode(ElementNode element) // gets a enumerable of valid colors for the given element node. If the element is full color, an empty enumeration // will be returned; otherwise one of more colors will be returned (for single or multiple discrete colors). + // wIt will recurse the children to collect from all parts of the element public static IEnumerable getValidColorsForElementNode(ElementNode element) { HashSet result = new HashSet(); ColorModule colorModule = element.Properties.Get(ColorDescriptor.ModuleId) as ColorModule; - if (colorModule == null) { - return result; + if (colorModule != null) { + switch (colorModule.ColorType) + { + case ElementColorType.FullColor: + break; + + case ElementColorType.MultipleDiscreteColors: + colorModule.Colors.ForEach(x => result.Add(x)); + break; + + case ElementColorType.SingleColor: + result.Add(colorModule.SingleColor); + break; + } } - switch (colorModule.ColorType) { - case ElementColorType.FullColor: - break; - - case ElementColorType.MultipleDiscreteColors: - colorModule.Colors.ForEach(x => result.Add(x)); - break; - - case ElementColorType.SingleColor: - result.Add(colorModule.SingleColor); - break; + + //recurse the children + if (element.Children.Any()) + { + result.AddRange(element.Children.SelectMany(x => getValidColorsForElementNode(x))); } return result; From 37f0ae5eff73e88cd5fb6cf7eedec86631d599ec Mon Sep 17 00:00:00 2001 From: Jeff Uchitjil Date: Wed, 26 Jun 2013 17:18:30 -0500 Subject: [PATCH 2/3] Logic to set the default color when a new effect is added to one in our set if we have discrete colors. Uses the first color in the set. Otherwise leave it white as before. --- Modules/Effect/Chase/Chase.cs | 13 +++++++++++++ Modules/Effect/Chase/Chase.csproj | 5 +++++ Modules/Effect/Chase/ChaseData.cs | 2 +- Modules/Effect/Pulse/Pulse.cs | 11 ++++++++++- Modules/Effect/Pulse/PulseData.cs | 2 +- Modules/Effect/SetLevel/SetLevel.cs | 12 ++++++++++++ Modules/Effect/SetLevel/SetLevelData.cs | 2 +- .../ChaseEffectEditor/ChaseEffectEditorControl.cs | 7 ++++++- .../ColorGradientTypeEditorControl.cs | 2 +- .../ColorTypeEditor/ColorTypeEditorControl.cs | 2 +- Modules/Property/Color/ColorProperty.cs | 10 +++++++--- 11 files changed, 58 insertions(+), 10 deletions(-) diff --git a/Modules/Effect/Chase/Chase.cs b/Modules/Effect/Chase/Chase.cs index 937948842..8199a4280 100644 --- a/Modules/Effect/Chase/Chase.cs +++ b/Modules/Effect/Chase/Chase.cs @@ -9,6 +9,7 @@ using VixenModules.App.Curves; using System.Drawing; using ZedGraph; +using VixenModules.Property.Color; namespace VixenModules.Effect.Chase { @@ -25,6 +26,18 @@ public Chase() protected override void _PreRender() { _elementData = new EffectIntents(); + if (StaticColor.IsEmpty) //We have a new effect + { + //Try to set a default color gradient from our available colors if we have discrete colors + HashSet validColors = new HashSet(); + validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); + ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First()); + + //Set a default color + StaticColor = validColors.DefaultIfEmpty(Color.White).First(); + + } + DoRendering(); } diff --git a/Modules/Effect/Chase/Chase.csproj b/Modules/Effect/Chase/Chase.csproj index 73f51ff83..343c19be6 100644 --- a/Modules/Effect/Chase/Chase.csproj +++ b/Modules/Effect/Chase/Chase.csproj @@ -66,6 +66,11 @@ Curves False + + {73068A83-B3B7-4A2C-923D-71C7886CD5E3} + Color + False + {A815A79E-305D-4167-A0BC-FFA590BB4644} Pulse diff --git a/Modules/Effect/Chase/ChaseData.cs b/Modules/Effect/Chase/ChaseData.cs index 558185b0b..70c36a0a7 100644 --- a/Modules/Effect/Chase/ChaseData.cs +++ b/Modules/Effect/Chase/ChaseData.cs @@ -49,7 +49,7 @@ public ChaseData() ColorHandling = ChaseColorHandling.StaticColor; PulseOverlap = 0; DefaultLevel = 0; - StaticColor = Color.White; + StaticColor = Color.Empty; ColorGradient = new ColorGradient(); PulseCurve = new Curve(); ChaseMovement = new Curve(); diff --git a/Modules/Effect/Pulse/Pulse.cs b/Modules/Effect/Pulse/Pulse.cs index a9ffeb825..466d2ba63 100644 --- a/Modules/Effect/Pulse/Pulse.cs +++ b/Modules/Effect/Pulse/Pulse.cs @@ -29,6 +29,15 @@ public Pulse() protected override void _PreRender() { _elementData = new EffectIntents(); + + if (ColorGradient == null) //We have a new effect + { + //Try to set a default color gradient from our available colors if we have discrete colors + HashSet validColors = new HashSet(); + validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); + ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First()); + } + foreach (ElementNode node in TargetNodes) { if (node != null) RenderNode(node); @@ -76,7 +85,7 @@ private void RenderNode(ElementNode node) if (colorType == ElementColorType.FullColor) { addIntentsToElement(elementNode.Element); } else { - IEnumerable colors = ColorModule.getValidColorsForElementNode(elementNode); + IEnumerable colors = ColorModule.getValidColorsForElementNode(elementNode, false); foreach (Color color in colors) { addIntentsToElement(elementNode.Element, color); } diff --git a/Modules/Effect/Pulse/PulseData.cs b/Modules/Effect/Pulse/PulseData.cs index 56343724f..0f98f56c3 100644 --- a/Modules/Effect/Pulse/PulseData.cs +++ b/Modules/Effect/Pulse/PulseData.cs @@ -21,7 +21,7 @@ public class PulseData : ModuleDataModelBase public PulseData() { LevelCurve = new Curve(); - ColorGradient = new ColorGradient(); + //ColorGradient = new ColorGradient(); } public override IModuleDataModel Clone() diff --git a/Modules/Effect/SetLevel/SetLevel.cs b/Modules/Effect/SetLevel/SetLevel.cs index ee5ca8228..3bd0bd138 100644 --- a/Modules/Effect/SetLevel/SetLevel.cs +++ b/Modules/Effect/SetLevel/SetLevel.cs @@ -9,6 +9,7 @@ using Vixen.Module.Effect; using Vixen.Sys.Attribute; using System.Drawing; +using VixenModules.Property.Color; namespace VixenModules.Effect.SetLevel { @@ -26,6 +27,15 @@ protected override void _PreRender() { _elementData = new EffectIntents(); + if (Color.ToArgb() == Color.Black.ToArgb()) //We have a new effect as empty is black in RGB. + { + //Set a default color if we have discrete colors + HashSet validColors = new HashSet(); + validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); + Color = validColors.DefaultIfEmpty(Color.White).First(); + + } + foreach (ElementNode node in TargetNodes) { if (node != null) RenderNode(node); @@ -67,5 +77,7 @@ private void RenderNode(ElementNode node) _elementData.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero); } } + + } } diff --git a/Modules/Effect/SetLevel/SetLevelData.cs b/Modules/Effect/SetLevel/SetLevelData.cs index c7095cb8f..9959ffbf4 100644 --- a/Modules/Effect/SetLevel/SetLevelData.cs +++ b/Modules/Effect/SetLevel/SetLevelData.cs @@ -21,7 +21,7 @@ class SetLevelData : ModuleDataModelBase public SetLevelData() { level = 1; - color = Color.White; + color = Color.Empty; //This ends up being black in RGB. } public override IModuleDataModel Clone() diff --git a/Modules/EffectEditor/ChaseEffectEditor/ChaseEffectEditorControl.cs b/Modules/EffectEditor/ChaseEffectEditor/ChaseEffectEditorControl.cs index 158275d99..a670cad96 100644 --- a/Modules/EffectEditor/ChaseEffectEditor/ChaseEffectEditorControl.cs +++ b/Modules/EffectEditor/ChaseEffectEditor/ChaseEffectEditorControl.cs @@ -30,7 +30,12 @@ public ChaseEffectEditorControl() public IEffect TargetEffect { get { return _targetEffect; } - set { _targetEffect = value; } + set { + _targetEffect = value; + //Ensure target effect is passed through as these editors need it. + colorTypeEditorControlStaticColor.TargetEffect = _targetEffect; + colorGradientTypeEditorControlGradient.TargetEffect = _targetEffect; + } } public object[] EffectParameterValues diff --git a/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs b/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs index adf218a06..1cf960a65 100644 --- a/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs +++ b/Modules/EffectEditor/ColorGradientTypeEditor/ColorGradientTypeEditorControl.cs @@ -42,7 +42,7 @@ public IEffect TargetEffect // look for the color property of the target effect element, and restrict the gradient. // If it's a group, iterate through all children (and their children, etc.), finding as many color // properties as possible; then we can decide what to do based on that. - validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x))); + validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); _discreteColors = validColors.Any(); _validDiscreteColors = validColors; diff --git a/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs b/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs index 47eca9252..df2326cfc 100644 --- a/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs +++ b/Modules/EffectEditor/ColorTypeEditor/ColorTypeEditorControl.cs @@ -41,7 +41,7 @@ public IEffect TargetEffect // look for the color property of the target effect element, and restrict the gradient. // If it's a group, iterate through all children (and their children, etc.), finding as many color // properties as possible; then we can decide what to do based on that. - validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x))); + validColors.AddRange(_targetEffect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); _discreteColors = validColors.Any(); _validDiscreteColors = validColors; } diff --git a/Modules/Property/Color/ColorProperty.cs b/Modules/Property/Color/ColorProperty.cs index b80531ccc..7c6a0506b 100644 --- a/Modules/Property/Color/ColorProperty.cs +++ b/Modules/Property/Color/ColorProperty.cs @@ -133,7 +133,7 @@ public static ElementColorType getColorTypeForElementNode(ElementNode element) // gets a enumerable of valid colors for the given element node. If the element is full color, an empty enumeration // will be returned; otherwise one of more colors will be returned (for single or multiple discrete colors). // wIt will recurse the children to collect from all parts of the element - public static IEnumerable getValidColorsForElementNode(ElementNode element) + public static IEnumerable getValidColorsForElementNode(ElementNode element, bool includeChildren) { HashSet result = new HashSet(); ColorModule colorModule = element.Properties.Get(ColorDescriptor.ModuleId) as ColorModule; @@ -154,10 +154,14 @@ public static ElementColorType getColorTypeForElementNode(ElementNode element) } //recurse the children - if (element.Children.Any()) + if (includeChildren) { - result.AddRange(element.Children.SelectMany(x => getValidColorsForElementNode(x))); + if (element.Children.Any()) + { + result.AddRange(element.Children.SelectMany(x => getValidColorsForElementNode(x, true))); + } } + return result; } From cbcd9692381ed8418ea4c16f782bdb7b1522bfbf Mon Sep 17 00:00:00 2001 From: Jeff Uchitjil Date: Wed, 26 Jun 2013 19:58:57 -0500 Subject: [PATCH 3/3] Discrete color enable the spin effect. --- Modules/Effect/Spin/Spin.cs | 12 ++++++++++++ Modules/Effect/Spin/Spin.csproj | 19 ++++++++++++------- Modules/Effect/Spin/SpinData.cs | 2 +- .../SpinEffectEditorControl.cs | 7 ++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Modules/Effect/Spin/Spin.cs b/Modules/Effect/Spin/Spin.cs index 8cf0f99b3..23270bd85 100644 --- a/Modules/Effect/Spin/Spin.cs +++ b/Modules/Effect/Spin/Spin.cs @@ -9,6 +9,7 @@ using VixenModules.App.Curves; using System.Drawing; using ZedGraph; +using VixenModules.Property.Color; namespace VixenModules.Effect.Spin { @@ -25,6 +26,17 @@ public Spin() protected override void _PreRender() { _elementData = new EffectIntents(); + if (StaticColor.IsEmpty) //We have a new effect + { + //Try to set a default color gradient from our available colors if we have discrete colors + HashSet validColors = new HashSet(); + validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); + ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First()); + + //Set a default color + StaticColor = validColors.DefaultIfEmpty(Color.White).First(); + + } DoRendering(); } diff --git a/Modules/Effect/Spin/Spin.csproj b/Modules/Effect/Spin/Spin.csproj index 006af2dfc..7c7afb896 100644 --- a/Modules/Effect/Spin/Spin.csproj +++ b/Modules/Effect/Spin/Spin.csproj @@ -1,4 +1,4 @@ - + Debug @@ -31,11 +31,11 @@ 4 - - {50B78623-FCF4-48AF-93FF-FA87C937028F} - Vixen - False - + + {50B78623-FCF4-48AF-93FF-FA87C937028F} + Vixen + False + @@ -65,6 +65,11 @@ Curves False + + {73068A83-B3B7-4A2C-923D-71C7886CD5E3} + Color + False + {A815A79E-305D-4167-A0BC-FFA590BB4644} Pulse @@ -79,4 +84,4 @@ --> - + \ No newline at end of file diff --git a/Modules/Effect/Spin/SpinData.cs b/Modules/Effect/Spin/SpinData.cs index b786dc268..9cfed51d3 100644 --- a/Modules/Effect/Spin/SpinData.cs +++ b/Modules/Effect/Spin/SpinData.cs @@ -63,7 +63,7 @@ public SpinData() PulseTime = 100; PulsePercentage = 10; DefaultLevel = 0; - StaticColor = Color.White; + StaticColor = Color.Empty; ColorGradient = new ColorGradient(); PulseCurve = new Curve(); ReverseSpin = false; diff --git a/Modules/EffectEditor/SpinEffectEditor/SpinEffectEditorControl.cs b/Modules/EffectEditor/SpinEffectEditor/SpinEffectEditorControl.cs index 7295871d4..e0e1b82db 100644 --- a/Modules/EffectEditor/SpinEffectEditor/SpinEffectEditorControl.cs +++ b/Modules/EffectEditor/SpinEffectEditor/SpinEffectEditorControl.cs @@ -26,7 +26,12 @@ public SpinEffectEditorControl() public IEffect TargetEffect { get { return _targetEffect; } - set { _targetEffect = value; } + set { + _targetEffect = value; + //Ensure target effect is passed through as these editors need it. + colorTypeEditorControlStaticColor.TargetEffect = _targetEffect; + colorGradientTypeEditorControlGradient.TargetEffect = _targetEffect; + } } public object[] EffectParameterValues