Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataflow extension for FilterDesigner #275

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions src/Gemini.Demo/Gemini.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="C5, Version=2.3.5280.26713, Culture=neutral, PublicKeyToken=282361b99ded7e8e, processorArchitecture=MSIL">
<HintPath>..\packages\C5.2.3.0.1\lib\net40\C5.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro, Version=2.0.2.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.Core.2.0.2\lib\net45\Caliburn.Micro.dll</HintPath>
<Private>True</Private>
Expand All @@ -52,6 +55,15 @@
<HintPath>..\packages\Caliburn.Micro.2.0.2\lib\net45\Caliburn.Micro.Platform.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Common.Logging, Version=2.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.2.2.0\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Core.2.2.0\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="Gridsum.DataflowEx, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Gridsum.DataflowEx.1.1.3\lib\net45\Gridsum.DataflowEx.dll</HintPath>
</Reference>
<Reference Include="Gu.Localization, Version=6.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Gu.Localization.6.1.0.0\lib\net45\Gu.Localization.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -81,18 +93,46 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.1.37\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.3.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Core, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.Core.3.1.1\lib\net45\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.Interfaces.3.1.1\lib\net45\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Linq, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.Linq.3.1.1\lib\net45\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.PlatformServices, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.PlatformServices.3.1.1\lib\net45\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Windows.Threading, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
</Reference>
<Reference Include="System.Reflection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reflection.4.1.0\lib\net462\System.Reflection.dll</HintPath>
</Reference>
<Reference Include="System.Reflection.Metadata, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reflection.Metadata.1.1.0\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Dataflow, Version=4.6.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Dataflow.4.7.0\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -150,6 +190,8 @@
<Compile Include="Modules\FilterDesigner\Commands\OpenGraphCommandHandler.cs" />
<Compile Include="Modules\FilterDesigner\Design\DesignTimeGraphViewModel.cs" />
<Compile Include="Modules\FilterDesigner\Design\DesignTimeImages.cs" />
<Compile Include="Modules\FilterDesigner\Logger.cs" />
<Compile Include="Modules\FilterDesigner\LoggerFacory.cs" />
<Compile Include="Modules\FilterDesigner\MenuDefinitions.cs" />
<Compile Include="Modules\FilterDesigner\Sample.cs" />
<Compile Include="Modules\FilterDesigner\ShaderEffects\AddEffect.cs" />
Expand All @@ -158,22 +200,32 @@
<Compile Include="Modules\FilterDesigner\Util\BitmapUtility.cs" />
<Compile Include="Modules\FilterDesigner\Util\FastBitmap.cs" />
<Compile Include="Modules\FilterDesigner\Util\ShaderEffectUtility.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\ConnectionViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\ConnectorDirection.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\ConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connection\BitmapSourceConnection.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connection\ConnectionViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connection\GenericConnectionViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\ConnectorDirection.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\ConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\Input\BitmapSourceInputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\Input\GenericInputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\Output\BitmapSourceOutputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\Output\GenericOutputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\Add.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\ColorInput.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\DynamicElement.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\BitmapSourceElement.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\ImageSource.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\Multiply.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Elements\ShaderEffectElement.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\ElementViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\GraphViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\InputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\OutputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\Input\InputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\Connector\Output\OutputConnectorViewModel.cs" />
<Compile Include="Modules\FilterDesigner\ViewModels\JoinAnyBlock.cs" />
<Compile Include="Modules\FilterDesigner\Views\GraphView.xaml.cs">
<DependentUpon>GraphView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\FilterDesigner\Views\ImagePreview.xaml.cs">
<DependentUpon>ImagePreview.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\Home\Commands\ViewHelixCommandDefinition.cs" />
<Compile Include="Modules\Home\Commands\ViewHelixCommandHandler.cs" />
<Compile Include="Modules\Home\Module.cs" />
Expand Down Expand Up @@ -286,6 +338,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Modules\FilterDesigner\Views\ImagePreview.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\Home\Views\HelixView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -332,6 +388,7 @@
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EffectCompile" Condition="'@(Effect)' != '' ">
<PixelShaderCompile Sources="@(Effect)">
Expand Down
41 changes: 41 additions & 0 deletions src/Gemini.Demo/Modules/FilterDesigner/JoinAnyBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Gridsum.DataflowEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

namespace Gemini.Demo.Modules.FilterDesigner
{
public class JoinAny<T1, T2>
{
public Task Completion => throw new NotImplementedException();
public Dataflow<T1, T1> Target1;
public Dataflow<T2, T2> Target2;
public Dataflow<(T1, T2), (T1, T2)> source;
public bool first;
T1 I1;
T2 I2;
public JoinAny()
{
Target1 = new BufferBlock<T1>(new DataflowBlockOptions()).ToDataflow();
Target2 = new BufferBlock<T2>(new DataflowBlockOptions()).ToDataflow();
Target1.OutputBlock.AsObservable().Subscribe(x => _in1(x));
Target2.OutputBlock.AsObservable().Subscribe(x => _in2(x));

source = new BufferBlock<(T1, T2)>().ToDataflow();

}
private void _in2(T2 x)
{
I2 = x;
if (I1 != null) source.SendAsync((I1, I2));
}
private void _in1(T1 x)
{
I1 = x;
if (I2 != null) source.SendAsync((I1, I2));
}
}
}
45 changes: 45 additions & 0 deletions src/Gemini.Demo/Modules/FilterDesigner/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Common.Logging.Simple;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Logging;
using Common.Logging.Factory;
using System.ComponentModel.Composition;
using Gemini.Modules.ErrorList;

namespace Gemini.Demo.Modules.FilterDesigner
{
public class Logger : AbstractLogger
{
public override bool IsTraceEnabled => true;

public override bool IsDebugEnabled => true;

public override bool IsInfoEnabled => true;

public override bool IsWarnEnabled => true;

public override bool IsErrorEnabled => true;

public override bool IsFatalEnabled => true;

IErrorList _display;


public Logger(IErrorList display)
{
_display = display;
}


protected override void WriteInternal(LogLevel level, object message, Exception exception)
{

if(message !=null) _display.AddItem(ErrorListItemType.Message, message.ToString());
if(exception != null) _display.AddItem(ErrorListItemType.Error, exception.ToString());

}
}
}
31 changes: 31 additions & 0 deletions src/Gemini.Demo/Modules/FilterDesigner/LoggerFacory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Common.Logging.Factory;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Logging;
using Gemini.Modules.ErrorList;

namespace Gemini.Demo.Modules.FilterDesigner
{
[Export(typeof(LoggerFacory))]
public class LoggerFacory : AbstractCachingLoggerFactoryAdapter
{
Logger l;
IErrorList _display;

[ImportingConstructor]
public LoggerFacory(IErrorList display)
{
_display = display;
}


protected override ILog CreateLogger(string name)
{
return l = l ?? new Logger(_display);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Gemini.Demo.Modules.FilterDesigner.ViewModels.Connector.Input;
using Gemini.Demo.Modules.FilterDesigner.ViewModels.Connector.Output;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Gemini.Demo.Modules.FilterDesigner.ViewModels.Connection
{
class BitmapSourceConnection : GenericConnectionViewModel<BitmapSource>
{
public BitmapSourceConnection(GenericOutputConnectorViewModel<BitmapSource> from, GenericInputConnectorViewModel<BitmapSource> to) :base(from,to)
{
}

public BitmapSourceConnection(GenericOutputConnectorViewModel<BitmapSource> from) : base(from)
{
}

Brush __color = new SolidColorBrush(System.Windows.Media.Color.FromRgb(36, 97, 121));
internal override Brush _color { get { return __color; } set { __color = value; } }
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using System;
using System.Windows;
using Caliburn.Micro;
using System.Windows.Media;
using System.ComponentModel;

namespace Gemini.Demo.Modules.FilterDesigner.ViewModels
{
public class ConnectionViewModel : PropertyChangedBase
public abstract class ConnectionViewModel : PropertyChangedBase, IsSelectable
{
private OutputConnectorViewModel _from;
public abstract Type ConnectionType { get; set; }

internal abstract OutputConnectorViewModel _from { get; set; }
public OutputConnectorViewModel From
{
get { return _from; }
private set
{
if (value.Type != ConnectionType) throw new Exception();
if (_from != null)
{
_from.PositionChanged -= OnFromPositionChanged;
Expand All @@ -31,24 +36,39 @@ private set
}
}

private InputConnectorViewModel _to;
[Browsable(false)]
private bool _isSelected;

public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
NotifyOfPropertyChange(() => IsSelected);
}
}


internal abstract InputConnectorViewModel _to { get; set; }
public InputConnectorViewModel To
{
get { return _to; }
set
{
if (value.Type != ConnectionType) throw new Exception();
if (_to != null)
{
_to.PositionChanged -= OnToPositionChanged;
_to.Connection = null;
_to.Connections.Remove(this);
}

_to = value;

if (_to != null)
{
_to.PositionChanged += OnToPositionChanged;
_to.Connection = this;
_to.Connections.Add(this);
ToPosition = _to.Position;
}

Expand All @@ -67,6 +87,18 @@ public Point FromPosition
}
}

internal abstract Brush _color { get; set; }
public Brush Color
{
get { return _color; }
set
{
_color = value;
NotifyOfPropertyChange(() => Color);
}
}


private Point _toPosition;
public Point ToPosition
{
Expand Down
Loading