Skip to content
Snippets Groups Projects
Commit db92c34f authored by Tim Übelhör's avatar Tim Übelhör
Browse files

Fixed saving and loading the workspace.

parent cdb66f79
Branches
Tags
No related merge requests found
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ModeliChart.Basics
namespace ModeliChart.Basics
{
/// <summary>
/// The different types of channels the fmu standard allows.
......
......
......@@ -14,22 +14,20 @@ namespace ModeliChart.Files
public interface IUiConfig
{
/// <summary>
/// Load the instruments from a repository.
/// The update frequency of the UI.
/// </summary>
/// <param name="dataSources">The dataSources are needed to extract the channels.s</param>
/// <returns></returns>
IEnumerable<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)> LoadInstrumentAreas(
IEnumerable<IModelInstance> modelInstances, IDataRepository dataRepository, ISimulation simulation);
double RefreshRate_Hz { get; set; }
IEnumerable<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)> InstrumentAreas { get; set; }
/// <summary>
/// Save the instruments to the repository
/// Saves the properties that have been set.
/// </summary>
/// <param name=""></param>
void SaveInstrumentAreas(IEnumerable<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)> areas);
void SaveConfig();
/// <summary>
/// The update frequency of the UI.
/// Loads the properties.
/// </summary>
double RefreshRate_Hz { get; set; }
void LoadConfig(ISimulation simulation, IDataRepository dataRepository);
}
}
......@@ -24,18 +24,34 @@ namespace ModeliChart.Files {
static ChannelReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Cg1DaGFubmVsLnByb3RvEhFNb2RlbGlDaGFydC5GaWxlcyJbCgxQcm90b0No",
"YW5uZWwSDAoEbmFtZRgBIAEoCRIZChFmbXVfaW5zdGFuY2VfbmFtZRgCIAEo",
"CRIRCgl2YWx1ZV9yZWYYAyABKA0SDwoHZW5hYmxlZBgEIAEoCGIGcHJvdG8z"));
"Cg1DaGFubmVsLnByb3RvEhFNb2RlbGlDaGFydC5GaWxlcyLQAQoMUHJvdG9D",
"aGFubmVsEgwKBG5hbWUYASABKAkSGQoRZm11X2luc3RhbmNlX25hbWUYAiAB",
"KAkSEQoJdmFsdWVfcmVmGAMgASgNEg8KB2VuYWJsZWQYBCABKAgSEAoIc2V0",
"dGFibGUYBSABKAgSFgoOZGlzcGxheWVkX3VuaXQYBiABKAkSEwoLZGVzY3Jp",
"cHRpb24YByABKAkSNAoMY2hhbm5lbF90eXBlGAggASgOMh4uTW9kZWxpQ2hh",
"cnQuRmlsZXMuQ2hhbm5lbFR5cGUqRQoLQ2hhbm5lbFR5cGUSCwoHSU5URUdF",
"UhAAEggKBFJFQUwQARIICgRFTlVNEAISCwoHQk9PTEVBThADEggKBE5PTkUQ",
"BGIGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::ModeliChart.Files.ProtoChannel), global::ModeliChart.Files.ProtoChannel.Parser, new[]{ "Name", "FmuInstanceName", "ValueRef", "Enabled" }, null, null, null)
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ModeliChart.Files.ChannelType), }, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::ModeliChart.Files.ProtoChannel), global::ModeliChart.Files.ProtoChannel.Parser, new[]{ "Name", "FmuInstanceName", "ValueRef", "Enabled", "Settable", "DisplayedUnit", "Description", "ChannelType" }, null, null, null)
}));
}
#endregion
}
#region Enums
public enum ChannelType {
[pbr::OriginalName("INTEGER")] Integer = 0,
[pbr::OriginalName("REAL")] Real = 1,
[pbr::OriginalName("ENUM")] Enum = 2,
[pbr::OriginalName("BOOLEAN")] Boolean = 3,
[pbr::OriginalName("NONE")] None = 4,
}
#endregion
#region Messages
/// <summary>
/// Settings of a ModeliChart channel.
......@@ -69,6 +85,10 @@ namespace ModeliChart.Files {
fmuInstanceName_ = other.fmuInstanceName_;
valueRef_ = other.valueRef_;
enabled_ = other.enabled_;
settable_ = other.settable_;
displayedUnit_ = other.displayedUnit_;
description_ = other.description_;
channelType_ = other.channelType_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
......@@ -121,6 +141,50 @@ namespace ModeliChart.Files {
}
}
/// <summary>Field number for the "settable" field.</summary>
public const int SettableFieldNumber = 5;
private bool settable_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Settable {
get { return settable_; }
set {
settable_ = value;
}
}
/// <summary>Field number for the "displayed_unit" field.</summary>
public const int DisplayedUnitFieldNumber = 6;
private string displayedUnit_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string DisplayedUnit {
get { return displayedUnit_; }
set {
displayedUnit_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "description" field.</summary>
public const int DescriptionFieldNumber = 7;
private string description_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Description {
get { return description_; }
set {
description_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "channel_type" field.</summary>
public const int ChannelTypeFieldNumber = 8;
private global::ModeliChart.Files.ChannelType channelType_ = 0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::ModeliChart.Files.ChannelType ChannelType {
get { return channelType_; }
set {
channelType_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as ProtoChannel);
......@@ -138,6 +202,10 @@ namespace ModeliChart.Files {
if (FmuInstanceName != other.FmuInstanceName) return false;
if (ValueRef != other.ValueRef) return false;
if (Enabled != other.Enabled) return false;
if (Settable != other.Settable) return false;
if (DisplayedUnit != other.DisplayedUnit) return false;
if (Description != other.Description) return false;
if (ChannelType != other.ChannelType) return false;
return Equals(_unknownFields, other._unknownFields);
}
......@@ -148,6 +216,10 @@ namespace ModeliChart.Files {
if (FmuInstanceName.Length != 0) hash ^= FmuInstanceName.GetHashCode();
if (ValueRef != 0) hash ^= ValueRef.GetHashCode();
if (Enabled != false) hash ^= Enabled.GetHashCode();
if (Settable != false) hash ^= Settable.GetHashCode();
if (DisplayedUnit.Length != 0) hash ^= DisplayedUnit.GetHashCode();
if (Description.Length != 0) hash ^= Description.GetHashCode();
if (ChannelType != 0) hash ^= ChannelType.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
......@@ -177,6 +249,22 @@ namespace ModeliChart.Files {
output.WriteRawTag(32);
output.WriteBool(Enabled);
}
if (Settable != false) {
output.WriteRawTag(40);
output.WriteBool(Settable);
}
if (DisplayedUnit.Length != 0) {
output.WriteRawTag(50);
output.WriteString(DisplayedUnit);
}
if (Description.Length != 0) {
output.WriteRawTag(58);
output.WriteString(Description);
}
if (ChannelType != 0) {
output.WriteRawTag(64);
output.WriteEnum((int) ChannelType);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
......@@ -197,6 +285,18 @@ namespace ModeliChart.Files {
if (Enabled != false) {
size += 1 + 1;
}
if (Settable != false) {
size += 1 + 1;
}
if (DisplayedUnit.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(DisplayedUnit);
}
if (Description.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Description);
}
if (ChannelType != 0) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) ChannelType);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
......@@ -220,6 +320,18 @@ namespace ModeliChart.Files {
if (other.Enabled != false) {
Enabled = other.Enabled;
}
if (other.Settable != false) {
Settable = other.Settable;
}
if (other.DisplayedUnit.Length != 0) {
DisplayedUnit = other.DisplayedUnit;
}
if (other.Description.Length != 0) {
Description = other.Description;
}
if (other.ChannelType != 0) {
ChannelType = other.ChannelType;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
......@@ -247,6 +359,22 @@ namespace ModeliChart.Files {
Enabled = input.ReadBool();
break;
}
case 40: {
Settable = input.ReadBool();
break;
}
case 50: {
DisplayedUnit = input.ReadString();
break;
}
case 58: {
Description = input.ReadString();
break;
}
case 64: {
channelType_ = (global::ModeliChart.Files.ChannelType) input.ReadEnum();
break;
}
}
}
}
......
......
using System;
using ModeliChart.Basics;
using ModeliChart.RemoteMode;
using ModeliChart.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModeliChart.UserControls;
using ModeliChart.Basics;
using ModeliChart.RemoteMode;
namespace ModeliChart.Files
{
......@@ -14,17 +14,82 @@ namespace ModeliChart.Files
/// </summary>
static class ProtoConverter
{
public static ModeliChart.UserControls.InstrumentType ToModeliInstrumentType(ProtoInstrument.Types.ProtoInstrumentType type)
{
switch (type)
{
case ProtoInstrument.Types.ProtoInstrumentType.OneChannel:
return InstrumentType.OneChannelInstrument;
case ProtoInstrument.Types.ProtoInstrumentType.TwoChannel:
return InstrumentType.TwoChannelInstrument;
case ProtoInstrument.Types.ProtoInstrumentType.MultiChannel:
return InstrumentType.MultiChannelInstrument;
default:
return InstrumentType.MultiChannelInstrument;
}
}
public static Basics.ChannelType ToModeliChannelType(ChannelType type)
{
switch (type)
{
case ChannelType.Boolean:
return Basics.ChannelType.Boolean;
case ChannelType.Enum:
return Basics.ChannelType.Enum;
case ChannelType.Integer:
return Basics.ChannelType.Integer;
case ChannelType.None:
return Basics.ChannelType.None;
case ChannelType.Real:
return Basics.ChannelType.Real;
default:
return Basics.ChannelType.None;
}
}
public static ChannelType ToProtoChannelType(Basics.ChannelType type)
{
switch (type)
{
case Basics.ChannelType.Boolean:
return ChannelType.Boolean;
case Basics.ChannelType.Enum:
return ChannelType.Enum;
case Basics.ChannelType.Integer:
return ChannelType.Integer;
case Basics.ChannelType.None:
return ChannelType.None;
case Basics.ChannelType.Real:
return ChannelType.Real;
default:
return ChannelType.None;
}
}
/// <summary>
/// Conversion from domain channel to proto channel.
/// </summary>
/// <param name="channel"></param>
/// <returns></returns>
public static ProtoChannel ToProtoChannel(IChannel channel) => new ProtoChannel()
public static ProtoChannel ToProtoChannel(IChannel channel) => new ProtoChannel
{
Name = channel.Name,
FmuInstanceName = channel.ModelInstanceName,
ValueRef = channel.ValueRef,
Enabled = channel.Enabled
Enabled = channel.Enabled,
ChannelType = ToProtoChannelType(channel.ChannelType),
Description = channel.Description ?? "",
DisplayedUnit = channel.DisplayedUnit ?? "",
Settable = channel.Settable
};
public static Channel ToModeliChannel(ProtoChannel channel) => new Basics.Channel(channel.Name, channel.ValueRef, channel.Description, channel.Settable)
{
ChannelType = ToModeliChannelType(channel.ChannelType),
DisplayedUnit = channel.DisplayedUnit,
Enabled = channel.Enabled,
ModelInstanceName = channel.FmuInstanceName
};
/// <summary>
......@@ -65,6 +130,32 @@ namespace ModeliChart.Files
}
}
public static (string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments) ToModeliInstrumentArea(
ProtoInstrumentArea area, ISimulation simulation, IDataRepository dataRepository)
{
var instruments = new List<UniversalOxyInstrument>();
foreach (var protoInstrument in area.Instruments)
{
// Create instrument
var instrument = new UniversalOxyInstrument(simulation, dataRepository)
{
DisplayedInterval = protoInstrument.IntervalSec,
InstrumentType = ProtoConverter.ToModeliInstrumentType(protoInstrument.InstrumentType),
SweepMode = protoInstrument.SweepMode
};
// Add channels
var channels = protoInstrument.Channels
.Select(ProtoConverter.ToModeliChannel);
foreach (var channel in channels)
{
instrument.AddChannel(channel);
}
// Add instrument
instruments.Add(instrument);
}
return (area.Name, instruments);
}
/// <summary>
/// Converts the instrument area setup to a proto instrument area.
/// </summary>
......
......
......@@ -8,6 +8,7 @@ using ModeliChart.LocalMode;
using ModeliChart.RemoteMode;
using System.IO;
using Google.Protobuf;
using ModeliChart.Log;
namespace ModeliChart.Files
{
......@@ -39,19 +40,20 @@ namespace ModeliChart.Files
public Task SaveSimulationAsync(ISimulation simulation)
{
// Load the proto and then update it
var simulationSettings = LoadSimulationSettings();
// Update the proto
simulationSettings.ChannelLinks.Clear();
simulationSettings.ChannelLinks.AddRange(simulation.ChannelLinks.Select(ProtoConverter.ToProtoChannelLink));
simulationSettings.FmuInstances.Clear();
simulationSettings.FmuInstances.AddRange(simulation.ModelInstances.Select(ProtoConverter.ToProtoFmuInstance));
simulationSettings.RemoteSettings = ProtoConverter.ToProtoRemoteSettings(simulation);
simulationSettings.StepSize = simulation.GetStepSize();
// Convert
var settings = new ProtoSimulationSettings
{
StepSize = simulation.GetStepSize(),
RemoteSettings = ProtoConverter.ToProtoRemoteSettings(simulation)
};
settings.ChannelLinks.AddRange(simulation.ChannelLinks
.Select(ProtoConverter.ToProtoChannelLink));
settings.FmuInstances.AddRange(simulation.ModelInstances
.Select(ProtoConverter.ToProtoFmuInstance));
// Save changes
using (var fs = File.OpenWrite(path))
using (var fs = File.Create(path))
{
simulationSettings.WriteTo(fs);
settings.WriteTo(fs);
}
return Task.CompletedTask;
}
......@@ -65,17 +67,22 @@ namespace ModeliChart.Files
private ProtoSimulationSettings LoadSimulationSettings()
{
// The file might not exist yet
if (File.Exists(path))
try
{
using (var fs = File.OpenRead(path))
{
return ProtoSimulationSettings.Parser.ParseFrom(fs);
}
}
else
catch (FileNotFoundException)
{
ConsoleLogger.WriteLine("Simulation Config", "Could not load the configuration, the file has not been found.");
return new ProtoSimulationSettings();
}
catch (InvalidProtocolBufferException)
{
ConsoleLogger.WriteLine("Simulation Config", "Could not load the configuration, invalid proto file.");
return new ProtoSimulationSettings();
}
}
......@@ -97,6 +104,7 @@ namespace ModeliChart.Files
}
return result;
}
private static async Task BuildModelInstances(ISimulation simulation, ProtoSimulationSettings simulationSettings, IModelRepository modelRepo)
{
// Match instances with thei model
......
......
......@@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModeliChart.Log;
namespace ModeliChart.Files
{
......@@ -15,7 +16,9 @@ namespace ModeliChart.Files
/// </summary>
class ProtoUiConfig : IUiConfig
{
private string path;
private readonly string path;
public double RefreshRate_Hz { get; set; }
public IEnumerable<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)> InstrumentAreas { get; set; }
/// <summary>
/// The repository uses a proto file to store the data.
......@@ -23,122 +26,45 @@ namespace ModeliChart.Files
/// <param name="path">The path to the protofile that will be used.</param>
public ProtoUiConfig(string path)
{
// Dependencies
this.path = path;
// Default values
RefreshRate_Hz = 50;
InstrumentAreas = Enumerable.Empty<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)>();
}
public double RefreshRate_Hz
public void LoadConfig(ISimulation simulation, IDataRepository dataRepository)
{
get
try
{
var value = LoadUiSettings().RefreshRateHz;
if (value == 0)
{
// Provide default non null value
value = 50;
RefreshRate_Hz = value;
}
return value;
}
set
{
// Load the proto and update the insruments
var proto = LoadUiSettings();
proto.RefreshRateHz = value;
// Save the changes
using (var fs = File.OpenWrite(path))
using (var fs = File.OpenRead(path))
{
proto.WriteTo(fs);
var settings = ProtoUiSettings.Parser.ParseFrom(fs);
InstrumentAreas = settings.InstrumentAreas.Select(area =>
ProtoConverter.ToModeliInstrumentArea(area,simulation, dataRepository));
RefreshRate_Hz = settings.RefreshRateHz;
}
}
}
public IEnumerable<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)> LoadInstrumentAreas(
IEnumerable<IModelInstance> modelInstances, IDataRepository dataRepository, ISimulation simulation)
catch (FileNotFoundException)
{
// Load from proto file
var protoInstrumentAreas = LoadUiSettings().InstrumentAreas;
// Create the actual setups
var result = new List<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)>();
foreach (var protoArea in protoInstrumentAreas)
{
var instruments = new List<UniversalOxyInstrument>();
foreach (var protoInstrument in protoArea.Instruments)
{
// Create instrument
var instrument = new UniversalOxyInstrument(simulation, dataRepository)
{
DisplayedInterval = protoInstrument.IntervalSec,
InstrumentType = ConvertInstrumentType(protoInstrument.InstrumentType),
SweepMode = protoInstrument.SweepMode
};
// Add channels
foreach (var pc in protoInstrument.Channels)
{
var channel = FindChannel(pc.Name, pc.FmuInstanceName);
if (channel != null)
{
instrument.AddChannel(channel);
}
}
// Add instrument
instruments.Add(instrument);
ConsoleLogger.WriteLine("Ui Configuration", "Could not load the configuration, the file has not been found.");
}
result.Add((protoArea.Name, instruments));
}
return result;
// Local helper functions
ModeliChart.UserControls.InstrumentType ConvertInstrumentType(ProtoInstrument.Types.ProtoInstrumentType type)
{
switch (type)
catch (InvalidProtocolBufferException)
{
case ProtoInstrument.Types.ProtoInstrumentType.OneChannel:
return InstrumentType.OneChannelInstrument;
case ProtoInstrument.Types.ProtoInstrumentType.TwoChannel:
return InstrumentType.TwoChannelInstrument;
case ProtoInstrument.Types.ProtoInstrumentType.MultiChannel:
return InstrumentType.MultiChannelInstrument;
default:
return InstrumentType.MultiChannelInstrument;
ConsoleLogger.WriteLine("Ui Configuration", "Could not load the configuration, the protocol buffer is invalid.");
}
}
IChannel FindChannel(string channelName, string dataSourceName) =>
modelInstances.FirstOrDefault(m => m.Name == dataSourceName)
?.Channels.FirstOrDefault(c => c.Name == channelName);
}
public void SaveInstrumentAreas(IEnumerable<(string AreaTitle, IEnumerable<UniversalOxyInstrument> Instruments)> areas)
public void SaveConfig()
{
// Load the proto and update the insruments
var proto = LoadUiSettings();
proto.InstrumentAreas.Clear();
proto.InstrumentAreas.AddRange(areas.Select(ProtoConverter.ToProtoInstrumentArea));
var settings = new ProtoUiSettings { RefreshRateHz = RefreshRate_Hz };
settings.InstrumentAreas.AddRange(InstrumentAreas.Select(ProtoConverter.ToProtoInstrumentArea));
// Save the changes
using (var fs = File.OpenWrite(path))
using (var fs = File.Create(path))
{
proto.WriteTo(fs);
settings.WriteTo(fs);
}
}
/// <summary>
/// Loads the proto from the file.
/// If it does not exist yet, a new ModeliProto instance is created.
/// </summary>
/// <returns></returns>
private ProtoUiSettings LoadUiSettings()
{
// The file might not exist yet
if (File.Exists(path))
{
using (var fs = File.OpenRead(path))
{
return ProtoUiSettings.Parser.ParseFrom(fs);
}
}
else
{
return new ProtoUiSettings();
}
}
}
}
......@@ -48,17 +48,17 @@ namespace ModeliChart.Files
/// <summary>
/// This config can be used to save and load a simulation.
/// </summary>
public ISimulationConfig SimulationConfig { get; private set; }
public ISimulationConfig SimulationConfig { get; }
/// <summary>
/// This repository can be used to manage fmu models.
/// </summary>
public IModelRepository ModelRepository { get; private set; }
public IModelRepository ModelRepository { get; }
/// <summary>
/// This config can be used to save and load the settings of the instruments.
/// </summary>
public IUiConfig UiConfig { get; private set; }
public IUiConfig UiConfig { get; }
/// <summary>
/// Use this repository to store the parameter settings of channels in this workspace.
......
......
......@@ -176,7 +176,8 @@ namespace ModeliChart.LocalMode
public async Task RemoveModelInstance(IModelInstance modelInstance)
{
// Remove from simulation
await taskQueue.Add(() => fmuInstances.Remove(modelInstance.Name)).ConfigureAwait(false);
await taskQueue.Add(() => fmuInstances = fmuInstances.Remove(modelInstance.Name))
.ConfigureAwait(false);
modelInstance.Dispose();
}
......
......
......@@ -26,7 +26,7 @@ namespace ModeliChart.UI
private IDataRepository dataRepository;
private SimulationDataStorer dataStorer;
// Display areas
private List<ModelInstanceArea> _dataSourceAreas = new List<ModelInstanceArea>();
private List<ModelInstanceArea> modelInstanceAreas = new List<ModelInstanceArea>();
private List<InstrumentArea> instrumentAreas = new List<InstrumentArea>();
// UI worker task
private const int REFRESH_RATE = 30; // milliseconds
......@@ -368,16 +368,16 @@ namespace ModeliChart.UI
{
if (ribChkBoxShowAvailableChannels.Checked == true)
{
for (int i = 0; i < _dataSourceAreas.Count; i++)
for (int i = 0; i < modelInstanceAreas.Count; i++)
{
_dataSourceAreas[i].Show();
modelInstanceAreas[i].Show();
}
}
else
{
for (int i = 0; i < _dataSourceAreas.Count; i++)
for (int i = 0; i < modelInstanceAreas.Count; i++)
{
_dataSourceAreas[i].Hide();
modelInstanceAreas[i].Hide();
}
}
}
......@@ -407,7 +407,7 @@ namespace ModeliChart.UI
private void RibbonOrbMenuItemQuit_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void RibbonButtonLink_Click(object sender, EventArgs e)
......@@ -421,7 +421,7 @@ namespace ModeliChart.UI
{
// Show the dialog
PresetsArea.ShowDialog(simulation.ModelInstances);
foreach (ModelInstanceArea area in _dataSourceAreas)
foreach (ModelInstanceArea area in modelInstanceAreas)
{
area.RefreshChannels();
}
......@@ -489,8 +489,8 @@ namespace ModeliChart.UI
{
Size = new Size(175, 175)
};
dataSrcArea.Show(dockPanel, WeifenLuo.WinFormsUI.Docking.DockState.DockLeft);
_dataSourceAreas.Add(dataSrcArea);
dataSrcArea.Show(dockPanel, DockState.DockLeft);
modelInstanceAreas.Add(dataSrcArea);
// Subscribe closed event of area
dataSrcArea.FormClosing += DataSrcArea_FormClosing;
......@@ -536,12 +536,12 @@ namespace ModeliChart.UI
{
BeginInvoke(new Action(() => CloseModelInstanceArea(instance)));
}
var dataSourceArea = _dataSourceAreas
var instanceArea = modelInstanceAreas
.FirstOrDefault(area => area.ModelInstance.Name.Equals(instance.Name));
_dataSourceAreas.Remove(dataSourceArea);
modelInstanceAreas.Remove(instanceArea);
// The handler will remove the datasource from the simulation. This is not the intention of this method.
dataSourceArea.FormClosing -= DataSrcArea_FormClosing;
dataSourceArea.Close();
instanceArea.FormClosing -= DataSrcArea_FormClosing;
instanceArea.Close();
}
#endregion
......@@ -591,8 +591,10 @@ namespace ModeliChart.UI
/// <returns></returns>
private async Task SaveWorkspaceAsync()
{
workspace.UiConfig.SaveInstrumentAreas(instrumentAreas
.Select(area => (area.Title, area.Instruments)));
workspace.UiConfig.InstrumentAreas = instrumentAreas
.Select(a => (a.Title, a.Instruments));
workspace.UiConfig.RefreshRate_Hz = REFRESH_RATE;
workspace.UiConfig.SaveConfig();
await workspace.SimulationConfig.SaveSimulationAsync(simulation);
}
......@@ -630,13 +632,14 @@ namespace ModeliChart.UI
simulation.ModelInstances.SelectMany(instance => instance.Channels));
StatusLogger.Progress = 70;
// Create instruments
foreach (var (AreaTitle, Instruments) in workspace.UiConfig.LoadInstrumentAreas(
simulation.ModelInstances, dataRepository, simulation))
workspace.UiConfig.LoadConfig(simulation, dataRepository);
foreach (var (AreaTitle, Instruments) in workspace.UiConfig.InstrumentAreas)
{
AddInstrumentArea(new InstrumentArea(AreaTitle, Instruments));
}
StatusLogger.Progress = 90;
// Load time values
// TODO use properties
ribTxtSimInterval.TextBoxText = (1.0 / simulation.GetStepSize()).ToString();
ribTxtUIInterval.TextBoxText = workspace.UiConfig.RefreshRate_Hz.ToString();
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment