Skip to content

Commit

Permalink
added data viewer (tabular raw data) and data validator (+ extract la…
Browse files Browse the repository at this point in the history
…bels)
  • Loading branch information
braunms committed May 6, 2024
1 parent c07109b commit 40825db
Show file tree
Hide file tree
Showing 24 changed files with 507 additions and 377 deletions.
2 changes: 1 addition & 1 deletion Core/Abstracts/AbstractDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AbstractDataType(PropertyChangedEventHandler meta_data_update_handler)
/// </summary>
/// <param name="value_types"></param>
/// <returns></returns>
protected bool CompatibleValueTypes(List<Type> value_types)
protected bool CompatibleTypes(List<Type> value_types)
{
bool incompatible = false;
foreach (Type t in value_types)
Expand Down
3 changes: 2 additions & 1 deletion Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
<Compile Include="Abstracts\IMetaData.cs" />
<Compile Include="Data\DataManager.cs" />
<Compile Include="Data\DataTypeGeneric.cs" />
<Compile Include="Data\DataValidation.cs" />
<Compile Include="Data\DataValidator.cs" />
<Compile Include="Data\TestData.cs" />
<Compile Include="Data\GenericDataEntry.cs" />
<Compile Include="Data\GenericDataStructure.cs" />
<Compile Include="Data\MetaDataGeneric.cs" />
Expand Down
83 changes: 33 additions & 50 deletions Core/Data/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DataManager : AbstractService
/// <summary>
/// Function provided by the interface (= Grasshopper) which allows pass output data to the interface
/// </summary>
public delegate void OutputData_Delegate(ref GenericDataStructure ouput_data);
public delegate void OutputData_Delegate(GenericDataStructure ouput_data);

/// <summary>
///
Expand Down Expand Up @@ -96,7 +96,7 @@ public override bool Terminate()
/// Callback to propagate new input data to the data manager.
/// </summary>
/// <param name="input_data">Reference to the new input data.</param>
public void UpdateInputData(ref GenericDataStructure input_data)
public void UpdateInputData(GenericDataStructure input_data)
{
if (!_initialized)
{
Expand All @@ -110,38 +110,19 @@ public void UpdateInputData(ref GenericDataStructure input_data)
}
_timer.Start();


// Only process valid input data
if (!DataValidation.Analyze(ref input_data)) {
return;
}

Log.Default.Msg(Log.Level.Info, "Updating data ...");
// Update generic data type...
_data_library[typeof(DataTypeGeneric)].UpdateData(input_data);
var data = get_generic_data();

// ...then update all other data types
foreach (var pair in _data_library)
Log.Default.Msg(Log.Level.Info, "Processing new input data...");
if (_data_validator.Convert(input_data, out GenericDataStructure validated_data))
{
if (pair.Key != typeof(DataTypeGeneric))
foreach (var pair in _data_library)
{
pair.Value.UpdateData(input_data);
pair.Value.UpdateData(validated_data);
}
foreach (var update_callback in _update_callbacks)
{
update_callback(true);
}
}

// Notify visualizations about (meta) data changes via registered update callbacks
if (_update_callbacks == null)
{
Log.Default.Msg(Log.Level.Error, "No callback list for registered update callbacks");
return;
}
foreach (var update_callback in _update_callbacks)
{
update_callback(true);
}

Log.Default.Msg(Log.Level.Info, "DONE");
Log.Default.Msg(Log.Level.Info, "...done.");

_timer.Stop();
}
Expand All @@ -156,27 +137,26 @@ public void SetOutputDataCallback(OutputData_Delegate outputdata_callback)
}

/// <summary>
/// Notify registered callers on update input data. Called by visualizations.
/// Register update callback of calling visualization.
/// </summary>
public void RegisterUpdateTypeCallback(UpdateCallback_Delegate update_callback, Type data_type)
{
// Register update callback of calling visualization
if (_update_callbacks == null)
if (!_initialized)
{
Log.Default.Msg(Log.Level.Error, "No callback list for registered update callbacks");
Log.Default.Msg(Log.Level.Error, "Initialization required prior to execution");
return;
}

if (_update_callbacks.Contains(update_callback))
{
Log.Default.Msg(Log.Level.Debug, "Callback for update data already registered");
return;
}
_update_callbacks.Add(update_callback);

// Register data type of calling visualization

if (!_data_library.ContainsKey(data_type))
{
// Create new data variety
var variety = (IDataType)Activator.CreateInstance(data_type, (PropertyChangedEventHandler)event_metadata_changed);
if (variety == null)
{
Expand All @@ -196,24 +176,25 @@ public void RegisterUpdateTypeCallback(UpdateCallback_Delegate update_callback,
}

/// <summary>
/// Notify registered callers on update input data. Called by visualizations.
/// Unregister data update callback of calling visualization.
/// XXX TODO Track used data types for being able to delete them is unused.
/// </summary>
public void UnregisterUpdateCallback(UpdateCallback_Delegate update_callback)
{
// Unregister data update callback of calling visualization
if (_update_callbacks == null)
if (!_initialized)
{
Log.Default.Msg(Log.Level.Error, "No callback list for registered update callbacks");
Log.Default.Msg(Log.Level.Error, "Initialization required prior to execution");
return;
}

if (_update_callbacks.Contains(update_callback))
{
_update_callbacks.Remove(update_callback);
return;
}
Log.Default.Msg(Log.Level.Debug, "Callback for update data already removed");

/// XXX TODO Track used data types for being able to delete them is unused.
else
{
Log.Default.Msg(Log.Level.Debug, "Callback for update data already removed");
}
}

/// <summary>
Expand All @@ -238,10 +219,6 @@ public object RequestDataCallback(Type data_type)
return _data_library[data_type]._Get;
}


/* ------------------------------------------------------------------*/
// private functions

/// <summary>
/// Send changed output data to interface
/// </summary>
Expand All @@ -264,7 +241,7 @@ public void SendOutputData()
out_data.AddEntry(metadata_entry);
}
}
_outputdata_callback(ref out_data);
_outputdata_callback(out_data);
}
}
else
Expand All @@ -273,6 +250,10 @@ public void SendOutputData()
}
}


/* ------------------------------------------------------------------*/
// private functions

/// <summary>
/// Callback provided for getting notified on changed meta data
/// !!! This function is currently called for every single change !!!
Expand All @@ -282,7 +263,7 @@ public void SendOutputData()
private void event_metadata_changed(object sender, PropertyChangedEventArgs e)
{
var sender_selection = sender as IMetaData;
if ((sender_selection == null) || (e.PropertyName != "IsSelected"))
if ((sender_selection == null) || (e.PropertyName != "_Selected"))
{
Log.Default.Msg(Log.Level.Error, "Unknown sender");
return;
Expand Down Expand Up @@ -343,6 +324,8 @@ private GenericDataStructure get_generic_data(bool silent = false)
private Dictionary<Type, IDataType> _data_library = null;
private OutputData_Delegate _outputdata_callback = null;
private List<UpdateCallback_Delegate> _update_callbacks = null;

private DataValidator _data_validator = new DataValidator();
}
}
}
16 changes: 5 additions & 11 deletions Core/Data/DataTypeGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ public override void UpdateData(GenericDataStructure data)
return;
}

if (!CompatibleDimensionality(data.DataDimension()) || !CompatibleValueTypes(data.ValueTypes()))
if (!CompatibleDimensionality(data.Dimension()) || !CompatibleTypes(data.Types()))
{
return;
}
_data = data;

uint index = 0;
init_metadata(_data, ref index);
_data = data;
init_metadata(_data);

_loaded = true;
}
Expand Down Expand Up @@ -80,20 +79,15 @@ public override void UpdateMetaDataEntry(IMetaData updated_meta_data)
/// Recursively initialize meta data.
/// </summary>
/// <param name="data">The data branch.</param>
/// <param name="index">The entry index</param>
private void init_metadata(GenericDataStructure data, ref uint index)
private void init_metadata(GenericDataStructure data)
{
foreach (var entry in data._Entries)
{
entry._Metadata._Selected = false;
entry._Metadata._Index = index;
entry._Metadata.PropertyChanged += _meta_data_update_handler;

index++;
}
foreach (var branch in data._Branches)
{
init_metadata(branch, ref index);
init_metadata(branch);
}
}
}
Expand Down
36 changes: 0 additions & 36 deletions Core/Data/DataValidation.cs

This file was deleted.

Loading

0 comments on commit 40825db

Please sign in to comment.