From da8164927b6724819919e1f249920c7f872332c1 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Wed, 16 Nov 2022 19:47:08 -0500 Subject: [PATCH] Fixes #801 no refresh of gof plots --- src/MoBi.Assets/MoBi.Assets.csproj | 6 +-- src/MoBi.BatchTool/MoBi.BatchTool.csproj | 2 +- src/MoBi.Core/Domain/Model/MoBiSimulation.cs | 8 +++- src/MoBi.Core/MoBi.Core.csproj | 14 +++--- .../Serializer/MoBiSimulationXmlSerializer.cs | 45 +++++++++++++------ src/MoBi.Engine/MoBi.Engine.csproj | 4 +- .../MoBi.Presentation.csproj | 6 +-- .../Presenter/EditSimulationPresenter.cs | 38 +++++++++------- src/MoBi.UI/MoBi.UI.csproj | 10 ++--- src/MoBi/MoBi.csproj | 4 +- tests/MoBi.Tests/MoBi.Tests.csproj | 8 ++-- tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj | 4 +- 12 files changed, 89 insertions(+), 60 deletions(-) diff --git a/src/MoBi.Assets/MoBi.Assets.csproj b/src/MoBi.Assets/MoBi.Assets.csproj index 8779cf4a2..fdf7c2180 100644 --- a/src/MoBi.Assets/MoBi.Assets.csproj +++ b/src/MoBi.Assets/MoBi.Assets.csproj @@ -26,9 +26,9 @@ - - - + + + diff --git a/src/MoBi.BatchTool/MoBi.BatchTool.csproj b/src/MoBi.BatchTool/MoBi.BatchTool.csproj index 36362bec1..d713071f5 100644 --- a/src/MoBi.BatchTool/MoBi.BatchTool.csproj +++ b/src/MoBi.BatchTool/MoBi.BatchTool.csproj @@ -60,7 +60,7 @@ - + diff --git a/src/MoBi.Core/Domain/Model/MoBiSimulation.cs b/src/MoBi.Core/Domain/Model/MoBiSimulation.cs index e9ce06bdd..2fb0b2868 100644 --- a/src/MoBi.Core/Domain/Model/MoBiSimulation.cs +++ b/src/MoBi.Core/Domain/Model/MoBiSimulation.cs @@ -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; @@ -16,6 +17,9 @@ public interface IMoBiSimulation : IWithDiagramFor, ISimulation { ICache 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); @@ -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 DiagramManager { get; set; } public OutputMappings OutputMappings { get; set; } = new OutputMappings(); @@ -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)); } diff --git a/src/MoBi.Core/MoBi.Core.csproj b/src/MoBi.Core/MoBi.Core.csproj index 52ca060c0..78a0ca665 100644 --- a/src/MoBi.Core/MoBi.Core.csproj +++ b/src/MoBi.Core/MoBi.Core.csproj @@ -32,13 +32,13 @@ - - - - - - - + + + + + + + diff --git a/src/MoBi.Core/Serialization/Xml/Serializer/MoBiSimulationXmlSerializer.cs b/src/MoBi.Core/Serialization/Xml/Serializer/MoBiSimulationXmlSerializer.cs index 030418b01..8f8fd4487 100644 --- a/src/MoBi.Core/Serialization/Xml/Serializer/MoBiSimulationXmlSerializer.cs +++ b/src/MoBi.Core/Serialization/Xml/Serializer/MoBiSimulationXmlSerializer.cs @@ -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; @@ -29,39 +30,57 @@ public override MoBiSimulation CreateObject(XElement element, SerializationConte return new MoBiSimulation {DiagramManager = serializationContext.Resolve()}; } - 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(); - var chartElement = outputToDeserialize.Element(chartSerializer.ElementName); - if (chartElement != null) - simulation.Chart = chartSerializer.Deserialize(outputToDeserialize.Element(chartSerializer.ElementName), serializationContext); + simulation.Chart = deserializeChart(simulationElement, serializationContext); + simulation.PredictedVsObservedChart = deserializeChart(simulationElement, serializationContext); + simulation.ResidualVsTimeChart = deserializeChart(simulationElement, serializationContext); var diagramSerializer = serializationContext.Resolve(); - 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(); + var simulationElement = base.TypedSerialize(simulation, serializationContext); var diagramSerializer = serializationContext.Resolve(); 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(XElement simulationElement, SerializationContext serializationContext) where T : class + { + var chartSerializer = SerializerRepository.SerializerFor(); + var chartElement = simulationElement.Element(chartSerializer.ElementName); + if (chartElement == null) + return null; + + return chartSerializer.Deserialize(simulationElement.Element(chartSerializer.ElementName), serializationContext); + } + + private void addSerializedChart(XElement simulationElement, T chart, SerializationContext serializationContext) where T : class + { + if (chart == null) + return; + + var chartSerializer = SerializerRepository.SerializerFor(); + simulationElement.Add(chartSerializer.Serialize(chart, serializationContext)); } } } \ No newline at end of file diff --git a/src/MoBi.Engine/MoBi.Engine.csproj b/src/MoBi.Engine/MoBi.Engine.csproj index 31492ecf0..9c60e888c 100644 --- a/src/MoBi.Engine/MoBi.Engine.csproj +++ b/src/MoBi.Engine/MoBi.Engine.csproj @@ -32,8 +32,8 @@ - - + + diff --git a/src/MoBi.Presentation/MoBi.Presentation.csproj b/src/MoBi.Presentation/MoBi.Presentation.csproj index 6da3427fd..3721623b4 100644 --- a/src/MoBi.Presentation/MoBi.Presentation.csproj +++ b/src/MoBi.Presentation/MoBi.Presentation.csproj @@ -28,9 +28,9 @@ - - - + + + diff --git a/src/MoBi.Presentation/Presenter/EditSimulationPresenter.cs b/src/MoBi.Presentation/Presenter/EditSimulationPresenter.cs index 66fd4b485..5e2711a08 100644 --- a/src/MoBi.Presentation/Presenter/EditSimulationPresenter.cs +++ b/src/MoBi.Presentation/Presenter/EditSimulationPresenter.cs @@ -136,9 +136,7 @@ public void Edit(IMoBiSimulation simulation) UpdateCaption(); _view.Display(); loadChart(); - _simulationPredictedVsObservedChartPresenter.UpdateAnalysisBasedOn(_simulation); - _simulationResidualVsTimeChartPresenter.UpdateAnalysisBasedOn(_simulation); - } + } private void addObservedDataRepositories(IList data, IEnumerable curves) { @@ -158,38 +156,44 @@ public override void Edit(object subject) private void loadChart() { - if (_simulationPredictedVsObservedChartPresenter.Chart == null) - { - var chart = _chartFactory.Create(); - _simulationPredictedVsObservedChartPresenter.InitializeAnalysis(chart, _simulation); - } - - if (_simulationResidualVsTimeChartPresenter.Chart == null) - { - var chart = _chartFactory.Create(); - _simulationResidualVsTimeChartPresenter.InitializeAnalysis(chart, _simulation); - } - CurveChartTemplate defaultTemplate = null; var data = new List(); 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().WithAxes(); _chartTask.SetOriginText(_simulation.Name, _simulation.Chart); } + if (_simulation.PredictedVsObservedChart == null) + _simulation.PredictedVsObservedChart = _chartFactory.Create(); + + if(_simulationPredictedVsObservedChartPresenter.Chart == null) + _simulationPredictedVsObservedChartPresenter.InitializeAnalysis(_simulation.PredictedVsObservedChart, _simulation); + else + _simulationPredictedVsObservedChartPresenter.UpdateAnalysisBasedOn(_simulation); + + if (_simulation.ResidualVsTimeChart == null) + _simulation.ResidualVsTimeChart = _chartFactory.Create(); + + 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); } diff --git a/src/MoBi.UI/MoBi.UI.csproj b/src/MoBi.UI/MoBi.UI.csproj index 75cd5760f..4f6b4481c 100644 --- a/src/MoBi.UI/MoBi.UI.csproj +++ b/src/MoBi.UI/MoBi.UI.csproj @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/src/MoBi/MoBi.csproj b/src/MoBi/MoBi.csproj index 52d1ee2fc..8a7fd1657 100644 --- a/src/MoBi/MoBi.csproj +++ b/src/MoBi/MoBi.csproj @@ -71,13 +71,13 @@ - + - + diff --git a/tests/MoBi.Tests/MoBi.Tests.csproj b/tests/MoBi.Tests/MoBi.Tests.csproj index 5ae6520b1..838913be0 100644 --- a/tests/MoBi.Tests/MoBi.Tests.csproj +++ b/tests/MoBi.Tests/MoBi.Tests.csproj @@ -45,10 +45,10 @@ - - - - + + + + diff --git a/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj b/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj index 6387fd6f3..14cf0094a 100644 --- a/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj +++ b/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj @@ -17,8 +17,8 @@ - - + +