Skip to content

Commit

Permalink
Fixes #801 no refresh of gof plots
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre committed Nov 17, 2022
1 parent 78e3325 commit da81649
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 60 deletions.
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.59" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.59" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.60" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.60" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
</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.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
<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.53" GeneratePathProperty="true" />
Expand Down
8 changes: 7 additions & 1 deletion src/MoBi.Core/Domain/Model/MoBiSimulation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core.Chart;
using OSPSuite.Core.Chart.Simulations;
using OSPSuite.Core.Diagram;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
Expand All @@ -16,6 +17,9 @@ public interface IMoBiSimulation : IWithDiagramFor<IMoBiSimulation>, ISimulation
{
ICache<string, DataRepository> HistoricResults { get; }
CurveChart Chart { get; set; }
SimulationPredictedVsObservedChart PredictedVsObservedChart { get; set; }
SimulationResidualVsTimeChart ResidualVsTimeChart { get; set; }

IMoBiBuildConfiguration MoBiBuildConfiguration { get; }
string ParameterIdentificationWorkingDirectory { get; set; }
void Update(IMoBiBuildConfiguration buildConfiguration, IModel model);
Expand All @@ -39,6 +43,8 @@ public class MoBiSimulation : ModelCoreSimulation, IMoBiSimulation
private DataRepository _results;
public IDiagramModel DiagramModel { get; set; }
public CurveChart Chart { get; set; }
public SimulationPredictedVsObservedChart PredictedVsObservedChart { get; set; }
public SimulationResidualVsTimeChart ResidualVsTimeChart { get; set; }
public string ParameterIdentificationWorkingDirectory { get; set; }
public IDiagramManager<IMoBiSimulation> DiagramManager { get; set; }
public OutputMappings OutputMappings { get; set; } = new OutputMappings();
Expand Down Expand Up @@ -78,7 +84,7 @@ public bool UsesObservedData(DataRepository dataRepository)
return OutputMappings.Any(x => x.UsesObservedData(dataRepository)) || Charts.Any(x => chartUsesObservedData(dataRepository, x));
}

private static bool chartUsesObservedData(DataRepository dataRepository, CurveChart curveChart)
private bool chartUsesObservedData(DataRepository dataRepository, CurveChart curveChart)
{
return curveChart != null && curveChart.Curves.Any(c => Equals(c.yData.Repository, dataRepository));
}
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.59" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.59" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure.Export" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure.Reporting" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.60" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure.Export" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure.Reporting" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="11.1.60" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MoBi.Core.Domain.Model;
using MoBi.Core.Domain.Model.Diagram;
using OSPSuite.Core.Chart;
using OSPSuite.Core.Chart.Simulations;
using OSPSuite.Core.Serialization.Diagram;
using OSPSuite.Core.Serialization.Xml;
using OSPSuite.Serializer;
Expand Down Expand Up @@ -29,39 +30,57 @@ public override MoBiSimulation CreateObject(XElement element, SerializationConte
return new MoBiSimulation {DiagramManager = serializationContext.Resolve<ISimulationDiagramManager>()};
}

protected override void TypedDeserialize(MoBiSimulation simulation, XElement outputToDeserialize, SerializationContext serializationContext)
protected override void TypedDeserialize(MoBiSimulation simulation, XElement simulationElement, SerializationContext serializationContext)
{
base.TypedDeserialize(simulation, outputToDeserialize, serializationContext);
base.TypedDeserialize(simulation, simulationElement, serializationContext);

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

var chartSerializer = SerializerRepository.SerializerFor<CurveChart>();
var chartElement = outputToDeserialize.Element(chartSerializer.ElementName);
if (chartElement != null)
simulation.Chart = chartSerializer.Deserialize<CurveChart>(outputToDeserialize.Element(chartSerializer.ElementName), serializationContext);
simulation.Chart = deserializeChart<CurveChart>(simulationElement, serializationContext);
simulation.PredictedVsObservedChart = deserializeChart<SimulationPredictedVsObservedChart>(simulationElement, serializationContext);
simulation.ResidualVsTimeChart = deserializeChart<SimulationResidualVsTimeChart>(simulationElement, serializationContext);

var diagramSerializer = serializationContext.Resolve<IDiagramModelToXmlMapper>();

var diagramElement = outputToDeserialize.Element(diagramSerializer.ElementName);
var diagramElement = simulationElement.Element(diagramSerializer.ElementName);
if (diagramElement != null)
simulation.DiagramModel = diagramSerializer.XmlDocumentToDiagramModel(diagramElement.ToXmlDocument());
}

protected override XElement TypedSerialize(MoBiSimulation simulation, SerializationContext serializationContext)
{
var xElement = base.TypedSerialize(simulation, serializationContext);
var chartSerializer = SerializerRepository.SerializerFor<CurveChart>();
var simulationElement = base.TypedSerialize(simulation, serializationContext);

var diagramSerializer = serializationContext.Resolve<IDiagramModelToXmlMapper>();

if (simulation.DiagramModel != null)
xElement.Add(diagramSerializer.DiagramModelToXmlDocument(simulation.DiagramModel).ToXElement());
simulationElement.Add(diagramSerializer.DiagramModelToXmlDocument(simulation.DiagramModel).ToXElement());

if (simulation.Chart != null)
xElement.Add(chartSerializer.Serialize(simulation.Chart, serializationContext));
addSerializedChart(simulationElement, simulation.Chart, serializationContext);
addSerializedChart(simulationElement, simulation.PredictedVsObservedChart, serializationContext);
addSerializedChart(simulationElement, simulation.ResidualVsTimeChart, serializationContext);

return xElement;
return simulationElement;
}

private T deserializeChart<T>(XElement simulationElement, SerializationContext serializationContext) where T : class
{
var chartSerializer = SerializerRepository.SerializerFor<T>();
var chartElement = simulationElement.Element(chartSerializer.ElementName);
if (chartElement == null)
return null;

return chartSerializer.Deserialize<T>(simulationElement.Element(chartSerializer.ElementName), serializationContext);
}

private void addSerializedChart<T>(XElement simulationElement, T chart, SerializationContext serializationContext) where T : class
{
if (chart == null)
return;

var chartSerializer = SerializerRepository.SerializerFor<T>();
simulationElement.Add(chartSerializer.Serialize(chart, serializationContext));
}
}
}
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.59" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.60" />
</ItemGroup>

<ItemGroup>
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.59" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.59" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.60" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="11.1.60" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
Expand Down
38 changes: 21 additions & 17 deletions src/MoBi.Presentation/Presenter/EditSimulationPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ public void Edit(IMoBiSimulation simulation)
UpdateCaption();
_view.Display();
loadChart();
_simulationPredictedVsObservedChartPresenter.UpdateAnalysisBasedOn(_simulation);
_simulationResidualVsTimeChartPresenter.UpdateAnalysisBasedOn(_simulation);
}
}

private void addObservedDataRepositories(IList<DataRepository> data, IEnumerable<Curve> curves)
{
Expand All @@ -158,38 +156,44 @@ public override void Edit(object subject)

private void loadChart()
{
if (_simulationPredictedVsObservedChartPresenter.Chart == null)
{
var chart = _chartFactory.Create<SimulationPredictedVsObservedChart>();
_simulationPredictedVsObservedChartPresenter.InitializeAnalysis(chart, _simulation);
}

if (_simulationResidualVsTimeChartPresenter.Chart == null)
{
var chart = _chartFactory.Create<SimulationResidualVsTimeChart>();
_simulationResidualVsTimeChartPresenter.InitializeAnalysis(chart, _simulation);
}

CurveChartTemplate defaultTemplate = null;

var data = new List<DataRepository>();
if (_simulation.ResultsDataRepository != null)
data.Add(_simulation.ResultsDataRepository);


//This whole initialization of Chart in presenter is really ugly.
//It's done like this now so that we can release 11.1 but should be done like in PK-Sim (multiple chart per simulation, added dynamically)
if (_simulation.Chart == null)
{
_simulation.Chart = _chartFactory.Create<CurveChart>().WithAxes();
_chartTask.SetOriginText(_simulation.Name, _simulation.Chart);
}

if (_simulation.PredictedVsObservedChart == null)
_simulation.PredictedVsObservedChart = _chartFactory.Create<SimulationPredictedVsObservedChart>();

if(_simulationPredictedVsObservedChartPresenter.Chart == null)
_simulationPredictedVsObservedChartPresenter.InitializeAnalysis(_simulation.PredictedVsObservedChart, _simulation);
else
_simulationPredictedVsObservedChartPresenter.UpdateAnalysisBasedOn(_simulation);

if (_simulation.ResidualVsTimeChart == null)
_simulation.ResidualVsTimeChart = _chartFactory.Create<SimulationResidualVsTimeChart>();

if (_simulationResidualVsTimeChartPresenter.Chart == null)
_simulationResidualVsTimeChartPresenter.InitializeAnalysis(_simulation.ResidualVsTimeChart, _simulation);
else
_simulationResidualVsTimeChartPresenter.UpdateAnalysisBasedOn(_simulation);


// Whether or not the chart is new, if it has no curves
// we apply the simulation default template
if (_simulation.Chart.Curves.Count == 0)
defaultTemplate = _simulation.DefaultChartTemplate;

addObservedDataRepositories(data, _simulation.Chart.Curves);
_simulationPredictedVsObservedChartPresenter.UpdateAnalysisBasedOn(_simulation);
_simulationResidualVsTimeChartPresenter.UpdateAnalysisBasedOn(_simulation);
_chartPresenter.Show(_simulation.Chart, data, defaultTemplate);
}

Expand Down
10 changes: 5 additions & 5 deletions src/MoBi.UI/MoBi.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
<PackageReference Include="OSPSuite.DataBinding.DevExpress" Version="6.0.0.2" />
<PackageReference Include="OSPSuite.DevExpress" Version="21.2.3" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Infrastructure" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure.Castle" Version="11.1.59" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.59" />
<PackageReference Include="OSPSuite.UI" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure.Castle" Version="11.1.60" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.60" />
<PackageReference Include="OSPSuite.UI" Version="11.1.60" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
Expand Down
4 changes: 2 additions & 2 deletions src/MoBi/MoBi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
<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.53" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.8" GeneratePathProperty="true" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.112" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.59" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.60" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.TeXReporting" Version="3.0.0.4" GeneratePathProperty="true" />

</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions tests/MoBi.Tests/MoBi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="OSPSuite.BDDHelper" Version="4.0.0.1" />
<PackageReference Include="OSPSuite.Core" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure" Version="11.1.59" />
<PackageReference Include="OSPSuite.Infrastructure.Castle" Version="11.1.59" />
<PackageReference Include="OSPSuite.UI" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure" Version="11.1.60" />
<PackageReference Include="OSPSuite.Infrastructure.Castle" Version="11.1.60" />
<PackageReference Include="OSPSuite.UI" Version="11.1.60" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.8" GeneratePathProperty="true" />
Expand Down
4 changes: 2 additions & 2 deletions tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="OSPSuite.BDDHelper" Version="4.0.0.1" />
<PackageReference Include="OSPSuite.Core" Version="11.1.59" />
<PackageReference Include="OSPSuite.UI" Version="11.1.59" />
<PackageReference Include="OSPSuite.Core" Version="11.1.60" />
<PackageReference Include="OSPSuite.UI" Version="11.1.60" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MoBi.Core\MoBi.Core.csproj" />
Expand Down

0 comments on commit da81649

Please sign in to comment.