Skip to content

Commit

Permalink
added mechanism for applying changes
Browse files Browse the repository at this point in the history
  • Loading branch information
braunms committed Jul 16, 2024
1 parent e0ae629 commit 072afa6
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 171 deletions.
243 changes: 196 additions & 47 deletions Core/Abstracts/AbstractFilter.cs

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@
<Compile Include="Data\GenericDataStructure.cs" />
<Compile Include="Data\GenericMetaData.cs" />
<None Include="Filtering\Filter.cs.template" />
<Compile Include="Filtering\ValueSelectionFilter.cs" />
<Compile Include="Filtering\ColumnSelectionFilter.cs" />
<Compile Include="Filtering\TransposeFilter.cs" />
<Compile Include="Filtering\FilterManager.cs" />
<Compile Include="GUI\LoadingProgressBar.cs">
<SubType>Component</SubType>
Expand Down
16 changes: 6 additions & 10 deletions Core/Data/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class DataManager : AbstractService
public delegate void SetDataCallback_Delegate(GenericDataStructure ouput_data);

public delegate GenericDataStructure GetGenericDataCallback_Delegate(int data_uid);
public delegate void UpdateSelectedDataCallback_Delegate(GenericDataStructure input_data, List<int> data_uids);
public delegate void UpdateSelectedDataCallback_Delegate(int data_uid, GenericDataStructure input_data);

public delegate int RegisterDataCallback_Delegate(Type data_type, UpdateVisualizationCallback_Delegate update_callback);
public delegate void UnregisterUpdateCallback_Delegate(int data_uid);
Expand Down Expand Up @@ -121,7 +121,7 @@ public void UpdateAllDataCallback(GenericDataStructure input_data)
/// Callback to propagate new input data to selected data types in the data manager.
/// </summary>
/// <param name="input_data">The new input data.</param>
public void UpdateSelectedDataCallback(GenericDataStructure input_data, List<int> data_uids)
public void UpdateSelectedDataCallback(int data_uid, GenericDataStructure input_data)
{
if (!_initialized)
{
Expand All @@ -134,16 +134,12 @@ public void UpdateSelectedDataCallback(GenericDataStructure input_data, List<int
return;
}

foreach (int data_uid in data_uids)
if (!_data_library.ContainsKey(data_uid))
{
if (!_data_library.ContainsKey(data_uid))
{
Log.Default.Msg(Log.Level.Error, "Received unknown data UID");
continue;
}
_data_library[data_uid]._Data.UpdateData(input_data);
_data_library[data_uid]._UpdateVisualization(true);
Log.Default.Msg(Log.Level.Error, "Received unknown data UID");
}
_data_library[data_uid]._Data.UpdateData(input_data);
_data_library[data_uid]._UpdateVisualization(true);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Core/Data/DataTypeGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void UpdateData(GenericDataStructure data)


_Dimension = data.GetDimension();
_data_generic = data.DeepCopy(_update_metadata_handler);
_data_generic = data.DeepCopy();
_data_specific = _data_generic;
init_metadata(_data_specific);

Expand Down
22 changes: 15 additions & 7 deletions Core/Data/GenericDataStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public class GenericDataStructure
/* ------------------------------------------------------------------*/
#region public functions

/// DEBUG
public GenericDataStructure()
{
Log.Default.Msg(Log.Level.Debug, " ----> Created new instance of GenericDataStructure");
}
~GenericDataStructure()
{
Log.Default.Msg(Log.Level.Debug, " ----< Deleted instance of GenericDataStructure");
}
/// DEBUG

public void AddBranch(GenericDataStructure branch) { _Branches.Add(branch); }

public void AddEntry(GenericDataEntry entry) { _Entries.Add(entry); }
Expand Down Expand Up @@ -140,13 +151,13 @@ public bool Transpose()
return true;
}

public GenericDataStructure DeepCopy(PropertyChangedEventHandler update_metadata_handler)
public GenericDataStructure DeepCopy()
{
var branch_clone = new GenericDataStructure();

foreach (var branch in _Branches)
{
branch_clone.AddBranch(branch.DeepCopy(update_metadata_handler));
branch_clone.AddBranch(branch.DeepCopy());
}
foreach (var entry in _Entries)
{
Expand All @@ -160,11 +171,8 @@ public GenericDataStructure DeepCopy(PropertyChangedEventHandler update_metadata
{
entry_clone._Types.Add(type);
}
entry_clone._Metadata._Index = entry._Metadata._Index;
entry_clone._Metadata._Label = entry._Metadata._Label;
entry_clone._Metadata._Dimension = entry._Metadata._Dimension;
entry_clone._Metadata._Selected = entry._Metadata._Selected;
entry_clone._Metadata.PropertyChanged += update_metadata_handler;
// Do not clone metadata since this should be shared even with deep copies
entry_clone._Metadata = entry._Metadata;
branch_clone.AddEntry(entry_clone);
}
branch_clone._Label = _Label;
Expand Down
25 changes: 19 additions & 6 deletions Core/Filtering/Filter.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Core.Abstracts;

INSTRUCTIONS for creating own custom data filter:

see https://github.com/IntCDC/VisuAlFroG/blob/main/docs/developer-uide.md
see https://github.com/IntCDC/VisuAlFroG/blob/main/docs/developer-guide.md

*/

Expand All @@ -31,33 +31,46 @@ namespace Core
/// <summary>
/// Class defining the configuration required for restoring content.
/// </summary>
/*
public class Configuration : AbstractFilter.Configuration
{
//TODO Add additional information required to restore the filter
/// XXX TODO Add additional information required to restore the filter
}
* */

#endregion

/* ------------------------------------------------------------------*/
#region public functions



#endregion

/* ------------------------------------------------------------------*/
#region protected functions

protected override UIElement create_ui()
{
var ui = new Grid();
_Name = "Transpose";

var ui = new TextBlock();
ui.Text = "Filter description ...";


// Call when value has changed and filter should be applied with changes
// set_apply_dirty();

// Place the UI stuff of your filter here...

return ui;
}

protected override void apply_filter(GenericDataStructure in_out_data)
{
// Change in_out_data accodingly...

}

#endregion
}
}
}
}
69 changes: 49 additions & 20 deletions Core/Filtering/FilterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class FilterListMetadata
public delegate bool CreateFilterCallback_Delegate(Type filter_type);
public delegate bool DeleteFilterCallback_Delegate(int filter_uid);
public delegate void ModifyUIFilterList_Delegate(UIElement element, AbstractFilter.ListModification mod);
public delegate void FilterChanged_Delegate(int filter_uid, List<int> data_uids);

#endregion

Expand All @@ -65,13 +66,13 @@ public bool Initialize(DataManager.GetGenericDataCallback_Delegate get_selected_
_timer.Start();


_content_metadata = new List<AbstractFilter.ContentMetadata>();
_contents_metadata = new List<AbstractFilter.ContentMetadata>();
_ordered_filter_list = new List<int>();

_get_selected_data_callback = get_selected_data_callback;
_update_selected_data_callback = update_selected_data_callback;

register_content(typeof(ColumnSelectionFilter));
register_content(typeof(ValueSelectionFilter));
register_content(typeof(TransposeFilter));


_timer.Stop();
Expand All @@ -83,7 +84,9 @@ public override bool Terminate()
{
if (_initialized)
{
_content_metadata = null;
_contents_metadata = null;
_ordered_filter_list.Clear();
_ordered_filter_list = null;
_update_selected_data_callback = null;
_get_selected_data_callback = null;
_modify_ui_filter_list_callback = null;
Expand All @@ -100,7 +103,7 @@ public List<FilterListMetadata> GetFilterTypeList()
foreach (var filter_data in _contents)
{
var filter_metadata = new FilterListMetadata();
///filter_metadata.ID = id; // for enumeration in combobox
///filter_metadata.ID = id; /// required for enumeration in combobox?
filter_metadata.Name = filter_data.Key.Name;
filter_metadata.Type = filter_data.Key;
list.Add(filter_metadata);
Expand All @@ -112,13 +115,6 @@ public List<FilterListMetadata> GetFilterTypeList()
public void SetModifyUIFilterList(ModifyUIFilterList_Delegate modify_ui_filter_list_callback)
{
_modify_ui_filter_list_callback = modify_ui_filter_list_callback;
foreach (var filter_data in _contents)
{
foreach (var filter in filter_data.Value)
{
_modify_ui_filter_list_callback(filter.Value.GetUI(), AbstractFilter.ListModification.ADD);
}
}
}

public bool CreateFilterCallback(Type filter_type)
Expand All @@ -137,12 +133,15 @@ public bool CreateFilterCallback(Type filter_type)
if (_contents.ContainsKey(filter_type))
{
var filter = (AbstractFilter)Activator.CreateInstance(filter_type);
if (filter.Initialize(_get_selected_data_callback, _update_selected_data_callback, _modify_ui_filter_list_callback, DeleteFilterCallback))
if (filter.Initialize(_get_selected_data_callback, _update_selected_data_callback, this.filter_changed, DeleteFilterCallback))
{
if (filter.CreateUI())
{
filter.ContentMetadataListCallback(_content_metadata);
filter.ContentMetadataListCallback(_contents_metadata);
_contents[filter_type].Add(filter._UID, filter);
_ordered_filter_list.Add(filter._UID);
// Add filter to UI list
_modify_ui_filter_list_callback(filter.GetUI(), ListModification.ADD);
return true;
}
else
Expand All @@ -169,7 +168,11 @@ public bool DeleteFilterCallback(int filter_uid)
{
if (filter_types.Value.ContainsKey(filter_uid))
{
// Remove filter from UI list
_modify_ui_filter_list_callback(filter_types.Value[filter_uid].GetUI(), ListModification.DELETE);
filter_types.Value[filter_uid].Terminate();
// Call after terminate
_ordered_filter_list.Remove(filter_types.Value[filter_uid]._UID);
return filter_types.Value.Remove(filter_uid);
}
}
Expand Down Expand Up @@ -211,32 +214,32 @@ public bool ApplyConfigurations(string configurations)

public void AddContentMetadataCallback(AbstractFilter.ContentMetadata content_metadata)
{
_content_metadata.Add(content_metadata);
_contents_metadata.Add(content_metadata);

foreach (var filter_type in _contents)
{
foreach (var filter in filter_type.Value)
{
filter.Value.ContentMetadataListCallback(_content_metadata);
filter.Value.ContentMetadataListCallback(_contents_metadata);
}
}
}

public void DeleteContentMetadataCallback(int data_uid)
{
foreach (var cm in _content_metadata)
foreach (var cm in _contents_metadata)
{
if (cm.DataUID == data_uid)
{
_content_metadata.Remove(cm);
_contents_metadata.Remove(cm);
break;
}
}
foreach (var filter_type in _contents)
{
foreach (var filter in filter_type.Value)
{
filter.Value.ContentMetadataListCallback(_content_metadata);
filter.Value.ContentMetadataListCallback(_contents_metadata);
}
}
}
Expand All @@ -261,14 +264,40 @@ protected override bool reset_content(AbstractFilter filter_value)
/* ------------------------------------------------------------------*/
#region private functions

void filter_changed(int filter_uid, List<int> data_uids)
{
// Notify all subsequent filters that previous filter has changed and that their original data has changed
if (!_ordered_filter_list.Contains(filter_uid))
{
Log.Default.Msg(Log.Level.Error, "Missing filter UID");

}

var index = _ordered_filter_list.FindIndex(f => (f == filter_uid));
for (int i = index+1; i < _ordered_filter_list.Count; i++)
{
foreach (var filter_type in _contents)
{
foreach (var filter in filter_type.Value)
{
if (filter.Value._UID == _ordered_filter_list[i])
{
filter.Value.SetDirty(data_uids);
}
}
}
}
}

#endregion

/* ------------------------------------------------------------------*/
#region private variables

// Required to provide new filters with content metadata
private List<AbstractFilter.ContentMetadata> _content_metadata = null;
private List<AbstractFilter.ContentMetadata> _contents_metadata = null;

private List<int> _ordered_filter_list = null;

private DataManager.UpdateSelectedDataCallback_Delegate _update_selected_data_callback = null;
private DataManager.GetGenericDataCallback_Delegate _get_selected_data_callback = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,52 @@ namespace Core
{
namespace Filter
{
public class ColumnSelectionFilter : AbstractFilter
public class TransposeFilter : AbstractFilter
{
/* ------------------------------------------------------------------*/
#region public classes

/// <summary>
/// Class defining the configuration required for restoring content.
/// </summary>
/*
public class Configuration : AbstractFilter.Configuration
{
/// XXX TODO Add additional information required to restore the filter
}
* */

#endregion

/* ------------------------------------------------------------------*/
#region public functions



#endregion

/* ------------------------------------------------------------------*/
#region protected functions

protected override UIElement create_ui()
{
var ui = new Grid();
_Name = "Column Selection";
_Name = "Transpose";

var ui = new TextBlock();
ui.Text = "Transpose tabular 2D data";


ui.Height = 150;
// Call when filter option has changed and filter should be applied again
// SetDirty();


return ui;
}

protected override void apply_filter(GenericDataStructure in_out_data)
{
in_out_data.Transpose();
}

#endregion
}
}
Expand Down
Loading

0 comments on commit 072afa6

Please sign in to comment.