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

Pluging in new Simulation OutputMapings and Charts #777

Merged
merged 20 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 3 additions & 1 deletion src/MoBi.Assets/AppConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
Expand Down Expand Up @@ -1423,6 +1423,8 @@ public static class Captions
public static readonly string ModelDiagram = "Diagram";
public static readonly string SimulationParameters = "Parameters";
public static readonly string Results = "Results";
public static readonly string TimeProfile = "Time Profile";
public static readonly string SimulationData = "Data";
public static readonly string IsStationary = "Stationary";
public static readonly string DefaultStartAmount = "Amount";
public static readonly string MoleculeType = "Molecule Type";
Expand Down
6 changes: 3 additions & 3 deletions src/MoBi.Assets/MoBi.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="11.1.26" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.26" />
<PackageReference Include="OSPSuite.Core" Version="11.1.26" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.30" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.30" />
<PackageReference Include="OSPSuite.Core" Version="11.1.30" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/MoBi.BatchTool/MoBi.BatchTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="11.1.26" />
<PackageReference Include="OSPSuite.Core" Version="11.1.30" />
<PackageReference Include="OSPSuite.DevExpress" Version="21.2.3" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.52" GeneratePathProperty="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public ClearResultsCommand(IMoBiSimulation simulation)

protected override void ExecuteWith(IMoBiContext context)
{
var result = _simulation.Results;
_simulation.Results = null;
var result = _simulation.ResultsDataRepository;
_simulation.ResultsDataRepository = null;
Description = AppConstants.Commands.RemoveFromDescription(ObjectType, result.Name, _simulation.Name);
context.PublishEvent(new RemovedDataEvent(result));
}
Expand Down
4 changes: 2 additions & 2 deletions src/MoBi.Core/Commands/RemoveSimulationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ protected override void ExecuteWith(IMoBiContext context)
context.UnregisterSimulation(_simulation);
context.PublishEvent(new SimulationRemovedEvent(_simulation));

//Do not serialize Results
_simulation.Results = null;
//Do not serialize ResultsDataRepository
_simulation.ResultsDataRepository = null;
_serializationStream = context.Serialize(_simulation);
}

Expand Down
2 changes: 1 addition & 1 deletion src/MoBi.Core/Commands/RenameSimulationResultsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void ExecuteWith(IMoBiContext context)
public override void RestoreExecutionData(IMoBiContext context)
{
_simulation = context.Get<IMoBiSimulation>(SimulationId);
_dataRepository = _simulation.HistoricResults[DataRepositoryId] ?? _simulation.Results;
_dataRepository = _simulation.HistoricResults[DataRepositoryId] ?? _simulation.ResultsDataRepository;
}
}
}
10 changes: 5 additions & 5 deletions src/MoBi.Core/Domain/Model/MoBiSimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Visitor;

namespace MoBi.Core.Domain.Model
{
public interface IMoBiSimulation : IWithDiagramFor<IMoBiSimulation>, ISimulation, IWithChartTemplates
{
DataRepository Results { get; set; }
{
ICache<string, DataRepository> HistoricResults { get; }
CurveChart Chart { get; set; }
IMoBiBuildConfiguration MoBiBuildConfiguration { get; }
Expand Down Expand Up @@ -43,7 +43,7 @@ public class MoBiSimulation : ModelCoreSimulation, IMoBiSimulation
public CurveChart Chart { get; set; }
public string ParameterIdentificationWorkingDirectory { get; set; }
public IDiagramManager<IMoBiSimulation> DiagramManager { get; set; }

public OutputMappings OutputMappings { get; set; } = new OutputMappings();
public MoBiSimulation()
{
HistoricResults = new Cache<string, DataRepository>(x => x.Id, x => null);
Expand Down Expand Up @@ -168,9 +168,9 @@ public void MarkResultsOutOfDate()
HasUpToDateResults = false;
}

public bool HasResults => Results != null;
public bool HasResults => ResultsDataRepository != null;

public DataRepository Results
public DataRepository ResultsDataRepository
{
get => _results;
set
Expand Down
14 changes: 7 additions & 7 deletions src/MoBi.Core/MoBi.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
<PackageReference Include="FluentNHibernate" Version="2.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="11.1.26" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.26" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.26" />
<PackageReference Include="OSPSuite.Infrastructure.Export" Version="11.1.26" />
<PackageReference Include="OSPSuite.Infrastructure.Reporting" Version="11.1.26" />
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="11.1.26" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="11.1.26" />
<PackageReference Include="OSPSuite.Core" Version="11.1.30" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.30" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.30" />
<PackageReference Include="OSPSuite.Infrastructure.Export" Version="11.1.30" />
<PackageReference Include="OSPSuite.Infrastructure.Reporting" Version="11.1.30" />
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="11.1.30" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="11.1.30" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void addSimulationToProject(SimulationMetaData simulationMetaData, Seria
_project.AddSimulation(simulation);
deserializeResults(simulation, simulationMetaData, serializationContext);
//Ensure that all references to simulations (Simulation itself, results etc) are available in the serialization context
serializationContext.AddRepository(simulation.Results);
serializationContext.AddRepository(simulation.ResultsDataRepository);
simulation.HistoricResults.Each(serializationContext.AddRepository);
serializationContext.Register(simulation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public SerializationContext Create(Type type = null, SerializationContext parent
if (project != null && shouldRegisterSimulations)
{
var allSimulations = project.Simulations;
var allSimulationResults = allSimulations.Where(s => s.HasResults).Select(s => s.Results);
var allSimulationResults = allSimulations.Where(s => s.HasResults).Select(s => s.ResultsDataRepository);
allRepositories.AddRange(allSimulationResults.Union(project.AllObservedData));

//Also register simulations to ensure that they are available as well for deserialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public MoBiSimulationXmlSerializer() : base(SerializationConstants.MoBiSimulatio
public override void PerformMapping()
{
base.PerformMapping();
Map(x => x.Results);
Map(x => x.ResultsDataRepository);
georgeDaskalakis marked this conversation as resolved.
Show resolved Hide resolved
Map(x => x.ParameterIdentificationWorkingDirectory);
Map(x => x.HasUpToDateResults);
}
Expand All @@ -30,8 +30,8 @@ protected override void TypedDeserialize(MoBiSimulation simulation, XElement out
{
base.TypedDeserialize(simulation, outputToDeserialize, serializationContext);

if (simulation.Results != null)
serializationContext.AddRepository(simulation.Results);
if (simulation.ResultsDataRepository != null)
serializationContext.AddRepository(simulation.ResultsDataRepository);

var chartSerializer = SerializerRepository.SerializerFor<CurveChart>();
var chartElement = outputToDeserialize.Element(chartSerializer.ElementName);
Expand Down
2 changes: 1 addition & 1 deletion src/MoBi.Core/Services/SimulationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void addSimulationToProject(IMoBiSimulation simulation, MoBiMacroCommand

addBuildConfigurationToProject(project, moBiSimulation.MoBiBuildConfiguration, loadCommand);

moBiSimulation.Results = simulation.Results;
moBiSimulation.ResultsDataRepository = simulation.ResultsDataRepository;
if (!_nameCorrector.CorrectName(project.Simulations, moBiSimulation))
return;

Expand Down
4 changes: 2 additions & 2 deletions src/MoBi.Engine/MoBi.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="11.1.26" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.26" />
<PackageReference Include="OSPSuite.Core" Version="11.1.30" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.30" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public IContextMenu InitializeWith(DataRepository dataRepository, IMoBiSimulatio
.WithIcon(ApplicationIcons.SimulationComparison)
.WithCommandFor<ShowDataRepositoryUICommand, DataRepository>(dataRepository));

if (!Equals(simulation.Results, dataRepository))
if (!Equals(simulation.ResultsDataRepository, dataRepository))
{
var persitableCommand = CreateMenuButton.WithCaption(dataRepository.IsPersistable() ? AppConstants.MenuNames.DiscardResults : AppConstants.MenuNames.KeepResults)
.WithCommandFor<SwitchHistoricalResultPersistanceUICommand, DataRepository>(dataRepository);
Expand Down
6 changes: 3 additions & 3 deletions src/MoBi.Presentation/MoBi.Presentation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<PackageReference Include="Northwoods.GoWin" Version="5.2.0" />
<PackageReference Include="OSPSuite.TeXReporting" Version="3.0.0.4" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.26" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="11.1.26" />
<PackageReference Include="OSPSuite.Core" Version="11.1.26" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.30" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="11.1.30" />
<PackageReference Include="OSPSuite.Core" Version="11.1.30" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
Expand Down
4 changes: 2 additions & 2 deletions src/MoBi.Presentation/Nodes/TreeNodeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public ITreeNode CreateFor(ClassifiableSimulation classifiableSimulation)
var buildConfigNode = CreateFor(simulation.MoBiBuildConfiguration);

simNode.AddChild(buildConfigNode);
if (simulation.Results != null)
simNode.AddChild(CreateFor(simulation.Results));
if (simulation.ResultsDataRepository != null)
simNode.AddChild(CreateFor(simulation.ResultsDataRepository));

//uses reverse so that the first result is the last node
simulation.HistoricResults.Reverse().Each(res => simNode.AddChild(CreateFor(res)));
Expand Down
32 changes: 25 additions & 7 deletions src/MoBi.Presentation/Presenter/ChartPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using MoBi.Assets;
using MoBi.Core.Domain.Extensions;
Expand All @@ -11,6 +12,7 @@
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Events;
using OSPSuite.Core.Services;
using OSPSuite.Presentation.Binders;
using OSPSuite.Presentation.Core;
using OSPSuite.Presentation.MenuAndBars;
Expand All @@ -25,6 +27,11 @@

namespace MoBi.Presentation.Presenter
{
public class ObservedDataAddedToChartEventArgs : EventArgs
{
public IReadOnlyList<DataRepository> AddedDataRepositories { get; set; }
}

/// <summary>
/// Aggregates the presenters needed to show a chart
/// </summary>
Expand All @@ -49,24 +56,28 @@ public interface IChartPresenter : IPresenter<IChartView>,
void Show(CurveChart chart, IReadOnlyList<DataRepository> dataRepositories, CurveChartTemplate defaultTemplate = null);

void UpdateTemplatesFor(IWithChartTemplates withChartTemplates);
event EventHandler<ObservedDataAddedToChartEventArgs> OnObservedDataAddedToChart;
}

public abstract class ChartPresenter : ChartPresenter<CurveChart, IChartView, IChartPresenter>, IChartPresenter
{
public event EventHandler<ObservedDataAddedToChartEventArgs> OnObservedDataAddedToChart = delegate { };

protected readonly IMoBiContext _context;
private readonly IUserSettings _userSettings;
private readonly IChartUpdater _chartUpdater;
protected readonly IChartTemplatingTask _chartTemplatingTask;
protected readonly ICache<DataRepository, IMoBiSimulation> _dataRepositoryCache;

private readonly IOutputMappingMatchingTask _OutputMappingMatchingTask;
private readonly ObservedDataDragDropBinder _observedDataDragDropBinder;
private bool _initialized;

private IChartDisplayPresenter displayPresenter => _chartPresenterContext.DisplayPresenter;
private IChartEditorPresenter editorPresenter => _chartPresenterContext.EditorPresenter;

protected ChartPresenter(IChartView chartView, ChartPresenterContext chartPresenterContext, IMoBiContext context, IUserSettings userSettings,
IChartTemplatingTask chartTemplatingTask, IChartUpdater chartUpdater) :
IChartTemplatingTask chartTemplatingTask, IChartUpdater chartUpdater, IOutputMappingMatchingTask OutputMappingMatchingTask) :
base(chartView, chartPresenterContext)
{
_chartUpdater = chartUpdater;
Expand All @@ -75,6 +86,7 @@ protected ChartPresenter(IChartView chartView, ChartPresenterContext chartPresen

_chartTemplatingTask = chartTemplatingTask;
_dataRepositoryCache = new Cache<DataRepository, IMoBiSimulation>(onMissingKey: x => null);
_OutputMappingMatchingTask = OutputMappingMatchingTask;
georgeDaskalakis marked this conversation as resolved.
Show resolved Hide resolved

_userSettings = userSettings;
_context = context;
Expand Down Expand Up @@ -157,7 +169,8 @@ private void initLayout()

protected void LoadFromTemplate(CurveChartTemplate chartTemplate, bool triggeredManually, bool propagateChartChangeEvent = true)
{
_chartTemplatingTask.InitFromTemplate(_dataRepositoryCache, Chart, editorPresenter, chartTemplate, CurveNameDefinition, triggeredManually, propagateChartChangeEvent);
_chartTemplatingTask.InitFromTemplate(_dataRepositoryCache, Chart, editorPresenter, chartTemplate, CurveNameDefinition, triggeredManually,
propagateChartChangeEvent);
}

protected virtual void OnDragOver(object sender, IDragEvent e)
Expand Down Expand Up @@ -229,6 +242,7 @@ private void addObservedData(IReadOnlyList<DataRepository> repositories)
{
editorPresenter.AddDataRepositories(repositories);
repositories.SelectMany(x => x.ObservationColumns()).Each(observationColumn => editorPresenter.AddCurveForColumn(observationColumn));
OnObservedDataAddedToChart(this, new ObservedDataAddedToChartEventArgs() { AddedDataRepositories = repositories });
_chartPresenterContext.Refresh();
}

Expand Down Expand Up @@ -283,15 +297,19 @@ private void addDataRepositoriesToDataRepositoryCache(IReadOnlyCollection<DataRe
.Each(dataRepository =>
{
var simulation = findSimulation(dataRepository) ?? findHistoricSimulation(dataRepository);
if (simulation != null)
_dataRepositoryCache.Add(dataRepository, simulation);
if (simulation == null) return;

_dataRepositoryCache.Add(dataRepository, simulation);
_OutputMappingMatchingTask.AddMatchingOutputMapping(dataRepository, simulation);

_context.PublishEvent(new ObservedDataAddedToAnalysableEvent(simulation, dataRepository, false));
});
}

private IMoBiSimulation findSimulation(DataRepository dataRepository)
{
return _context.CurrentProject.Simulations
.FirstOrDefault(simulation => Equals(simulation.Results, dataRepository));
.FirstOrDefault(simulation => Equals(simulation.ResultsDataRepository, dataRepository));
}

private IMoBiSimulation findHistoricSimulation(DataRepository dataRepository)
Expand All @@ -316,7 +334,7 @@ private void replaceSimulationRepositories(IReadOnlyCollection<DataRepository> d
public void Handle(ObservedDataRemovedEvent eventToHandle)
{
var dataRepository = eventToHandle.DataRepository;
editorPresenter.RemoveDataRepositories(new[] {dataRepository});
editorPresenter.RemoveDataRepositories(new[] { dataRepository });
displayPresenter.Refresh();
}

Expand Down
7 changes: 5 additions & 2 deletions src/MoBi.Presentation/Presenter/ComparisonChartPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OSPSuite.Core.Chart;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Mappers;
using OSPSuite.Core.Services;
using OSPSuite.Presentation.Services.Charts;
using IChartTemplatingTask = MoBi.Presentation.Tasks.IChartTemplatingTask;

Expand All @@ -17,8 +18,10 @@ public class ComparisonChartPresenter : ChartPresenter, IComparisonChartPresente
{
private readonly IQuantityPathToQuantityDisplayPathMapper _quantityDisplayPathMapper;

public ComparisonChartPresenter(IChartView chartView, IMoBiContext context, IUserSettings userSettings, IChartTemplatingTask chartTemplatingTask, IQuantityPathToQuantityDisplayPathMapper quantityDisplayPathMapper, IChartUpdater chartUpdater, ChartPresenterContext chartPresenterContext) :
base(chartView, chartPresenterContext, context, userSettings, chartTemplatingTask, chartUpdater)
public ComparisonChartPresenter(IChartView chartView, IMoBiContext context, IUserSettings userSettings,
IChartTemplatingTask chartTemplatingTask, IQuantityPathToQuantityDisplayPathMapper quantityDisplayPathMapper, IChartUpdater chartUpdater,
ChartPresenterContext chartPresenterContext, IOutputMappingMatchingTask OutputMappingMatchingTask) :
base(chartView, chartPresenterContext, context, userSettings, chartTemplatingTask, chartUpdater, OutputMappingMatchingTask)
{
_quantityDisplayPathMapper = quantityDisplayPathMapper;
}
Expand Down
Loading