Skip to content

Commit

Permalink
Fixes #820 individual serialization (#849)
Browse files Browse the repository at this point in the history
* work in progress

* update core
  • Loading branch information
rwmcintosh authored Dec 21, 2022
1 parent c7ccd33 commit d7d51ce
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/MoBi.Assets/AppConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,7 @@ public static class Captions
public static readonly string AddMetabolizingEnzyme = "Add Metagbolizing Enzyme";
public static readonly string AddTransportProtein = "Add Transport Protein";
public static readonly string AddSpecificBindingPartner = "Add Binding Partner";
public static readonly string Individuals = "Individuals";

public static string SumFormulaDescription(string iterationPattern) => $"Sum formula is defined as R1*…*Rm*∑{iterationPattern}*Q1_#i*…Qn_#i where R1…Rm (m>=0) are the quantities of an independent object (as absolute path or relative path); {iterationPattern} is a control variable (parameter, molecule amount, … defined by certain conditions); and Q1_#i…Qn_#i (n>=0) are the quantities that are obtained from a path relative to {iterationPattern}";

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="12.0.77" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.77" />
<PackageReference Include="OSPSuite.Core" Version="12.0.77" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.84" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.84" />
<PackageReference Include="OSPSuite.Core" Version="12.0.84" />
</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="12.0.77" />
<PackageReference Include="OSPSuite.Core" Version="12.0.84" />
<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
3 changes: 3 additions & 0 deletions src/MoBi.Core/Domain/Model/MoBiProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface IMoBiProject : IProject
IReadOnlyList<IMoleculeStartValuesBuildingBlock> MoleculeStartValueBlockCollection { get; }
IReadOnlyList<IParameterStartValuesBuildingBlock> ParametersStartValueBlockCollection { get; }
IReadOnlyList<ExpressionProfileBuildingBlock> ExpressionProfileCollection { get; }
IReadOnlyList<IndividualBuildingBlock> IndividualsCollection { get; }
IReadOnlyList<ISimulationSettings> SimulationSettingsCollection { get; }

ReactionDimensionMode ReactionDimensionMode { get; set; }
Expand Down Expand Up @@ -124,6 +125,8 @@ private IReadOnlyList<T> get<T>()

public IReadOnlyList<ExpressionProfileBuildingBlock> ExpressionProfileCollection => get<ExpressionProfileBuildingBlock>();

public IReadOnlyList<IndividualBuildingBlock> IndividualsCollection => get<IndividualBuildingBlock>();

public IReadOnlyList<ISimulationSettings> SimulationSettingsCollection => get<ISimulationSettings>();

public IReadOnlyList<IPassiveTransportBuildingBlock> PassiveTransportCollection => get<IPassiveTransportBuildingBlock>();
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="12.0.77" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.77" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.77" />
<PackageReference Include="OSPSuite.Infrastructure.Export" Version="12.0.77" />
<PackageReference Include="OSPSuite.Infrastructure.Reporting" Version="12.0.77" />
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="12.0.77" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.77" />
<PackageReference Include="OSPSuite.Core" Version="12.0.84" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.84" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.84" />
<PackageReference Include="OSPSuite.Infrastructure.Export" Version="12.0.84" />
<PackageReference Include="OSPSuite.Infrastructure.Reporting" Version="12.0.84" />
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="12.0.84" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.84" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

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="12.0.77" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.77" />
<PackageReference Include="OSPSuite.Core" Version="12.0.84" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.84" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public bool IsSatisfiedBy(IViewItem viewItem, IPresenterWithContextMenu<IViewIte
}
}

public class RootContextMenuFactoryForIndividualBuildingBlock : RootNodeContextMenuFactoryFor<IndividualBuildingBlock>
{
public RootContextMenuFactoryForIndividualBuildingBlock() : base(MoBiRootNodeTypes.IndividualsFolder)
{
}
}

public class RootContextMenuFactoryForExpressionProfileBuildingBlock : RootNodeContextMenuFactoryFor<ExpressionProfileBuildingBlock>
{
public RootContextMenuFactoryForExpressionProfileBuildingBlock() : base(MoBiRootNodeTypes.ExpressionProfilesFolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

namespace MoBi.Presentation.MenusAndBars.ContextMenus
{
public class RootContextMenuForIndividualBuildingBlock : RootContextMenuFor<IMoBiProject, IndividualBuildingBlock>
{
public RootContextMenuForIndividualBuildingBlock(IObjectTypeResolver objectTypeResolver, IMoBiContext context) : base(objectTypeResolver, context)
{
}

protected override void CreateAddItems(IMoBiProject parent)
{
_allMenuItems.Add(CreateAddExistingItemFor(parent));
}
}

public class RootContextMenuForExpressionProfileBuildingBlock : RootContextMenuFor<IMoBiProject, ExpressionProfileBuildingBlock>
{
public RootContextMenuForExpressionProfileBuildingBlock(IObjectTypeResolver objectTypeResolver, IMoBiContext context) : base(objectTypeResolver, context)
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="12.0.77" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="12.0.77" />
<PackageReference Include="OSPSuite.Core" Version="12.0.77" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.84" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="12.0.84" />
<PackageReference Include="OSPSuite.Core" Version="12.0.84" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
Expand Down
4 changes: 2 additions & 2 deletions src/MoBi.Presentation/Nodes/MoleculeTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel;
using MoBi.Presentation.DTO;
using OSPSuite.Presentation.Nodes;
using MoBi.Presentation.DTO;
using System.ComponentModel;

namespace MoBi.Presentation.Nodes
{
Expand Down
1 change: 1 addition & 0 deletions src/MoBi.Presentation/Nodes/RootNodeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MoBiRootNodeTypes
public static readonly RootNodeType MoleculeStartValuesFolder = new RootNodeType(AppConstants.Captions.MoleculeStartValues, ApplicationIcons.MoleculeStartValuesFolder);
public static readonly RootNodeType ParameterStartValuesFolder = new RootNodeType(AppConstants.Captions.ParameterStartValues, ApplicationIcons.ParameterStartValuesFolder);
public static readonly RootNodeType ExpressionProfilesFolder = new RootNodeType(AppConstants.Captions.ExpressionProfiles, ApplicationIcons.ExpressionProfileFolder);
public static readonly RootNodeType IndividualsFolder = new RootNodeType(AppConstants.Captions.Individuals, ApplicationIcons.IndividualFolder);
public static readonly RootNodeType SimulationSettingsFolder = new RootNodeType(AppConstants.Captions.SimulationSettings, ApplicationIcons.SimulationSettingsFolder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected override void AddProjectToTree(IMoBiProject project)
_view.AddNode(_treeNodeFactory.CreateFor(MoBiRootNodeTypes.MoleculeStartValuesFolder));
_view.AddNode(_treeNodeFactory.CreateFor(MoBiRootNodeTypes.ParameterStartValuesFolder));
_view.AddNode(_treeNodeFactory.CreateFor(MoBiRootNodeTypes.ExpressionProfilesFolder));
_view.AddNode(_treeNodeFactory.CreateFor(MoBiRootNodeTypes.IndividualsFolder));
_view.AddNode(_treeNodeFactory.CreateFor(RootNodeTypes.ObservedDataFolder));

project.MoleculeBlockCollection.Each(bb => addBuildingBlockToTree(bb, MoBiRootNodeTypes.MoleculeFolder));
Expand All @@ -74,6 +75,7 @@ protected override void AddProjectToTree(IMoBiProject project)
project.MoleculeStartValueBlockCollection.Each(bb => addBuildingBlockToTree(bb, MoBiRootNodeTypes.MoleculeStartValuesFolder));
project.ParametersStartValueBlockCollection.Each(bb => addBuildingBlockToTree(bb, MoBiRootNodeTypes.ParameterStartValuesFolder));
project.ExpressionProfileCollection.Each(bb => addBuildingBlockToTree(bb, MoBiRootNodeTypes.ExpressionProfilesFolder));
project.IndividualsCollection.Each(bb => addBuildingBlockToTree(bb, MoBiRootNodeTypes.IndividualsFolder));

project.SimulationSettingsCollection.Each(bb => addBuildingBlockToTree(bb, MoBiRootNodeTypes.SimulationSettingsFolder));

Expand Down Expand Up @@ -184,6 +186,9 @@ private ITreeNode addBuildingBlock(IBuildingBlock buildingBlock)

if (buildingBlock.IsAnImplementationOf<ExpressionProfileBuildingBlock>())
return addBuildingBlockToTree(buildingBlock, MoBiRootNodeTypes.ExpressionProfilesFolder);

if (buildingBlock.IsAnImplementationOf<IndividualBuildingBlock>())
return addBuildingBlockToTree(buildingBlock, MoBiRootNodeTypes.IndividualsFolder);

throw new ArgumentOutOfRangeException();
}
Expand Down
17 changes: 0 additions & 17 deletions src/MoBi.Presentation/Tasks/Interaction/AbstractStartValuesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ protected bool HasEquivalentFormula(IStartValue startValue, IFormula targetFormu
return _startValuePathTask.HasEquivalentFormula(startValue, targetFormula);
}

public override IMoBiCommand ChangeValueFormulaCommand(TBuildingBlock startValues, TStartValue startValue, IFormula formula)
{
return new ChangeValueFormulaCommand<TStartValue>(startValues, startValue, formula, startValue.Formula).Run(Context);
}

protected static bool HasEquivalentStartValue(IStartValue startValue, IParameter parameter)
{
var (value, _) = parameter.TryGetValue();
Expand Down Expand Up @@ -279,13 +274,6 @@ public ICommand SetValueOrigin(TBuildingBlock buildingBlock, ValueOrigin valueOr
return new UpdateValueOriginInStartValueCommand<TStartValue>(startValue, valueOrigin, buildingBlock).Run(Context);
}

public override IMoBiCommand SetFormula(TBuildingBlock buildingBlock, TStartValue startValue, IFormula formula)
{
var shouldClearValue = startValue.Value.HasValue;

return SetFormula(buildingBlock, startValue, formula, shouldClearValue);
}

public abstract bool CanResolve(TBuildingBlock buildingBlock, TStartValue startValue);

protected static bool ShouldFormulaBeOverridden(ImportedQuantityDTO quantityDTO, TStartValue startValue)
Expand Down Expand Up @@ -327,10 +315,5 @@ public IMoBiCommand EditStartValueContainerPath(TBuildingBlock buildingBlock, TS
{
return _startValuePathTask.UpdateStartValueContainerPath(buildingBlock, startValue, indexToUpdate, newValue);
}

protected override IMoBiCommand SetValueWithUnit(TStartValue startValue, double? newBaseValue, Unit unit, TBuildingBlock startValues)
{
return new PathAndValueEntityValueOrUnitChangedCommand<TStartValue, TBuildingBlock>(startValue, newBaseValue, unit, startValues).Run(Context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface IInteractionTaskForPathAndValueEntity<in TBuildingBlock, in TBu

public abstract class InteractionTaskForPathAndValueEntity<TBuildingBlock, TBuilder> : InteractionTasksForEnumerableBuildingBlock<TBuildingBlock, TBuilder>, IInteractionTaskForPathAndValueEntity<TBuildingBlock, TBuilder>
where TBuildingBlock : class, IBuildingBlock, IBuildingBlock<TBuilder>
where TBuilder : class, IUsingFormula, IWithDisplayUnit
where TBuilder : PathAndValueEntity, IUsingFormula, IWithDisplayUnit
{
protected readonly IMoBiFormulaTask _moBiFormulaTask;

Expand Down Expand Up @@ -82,9 +82,10 @@ protected IMoBiCommand AddFormulaToFormulaCacheAndSetOnBuilder<TFormula>(TBuildi
return macroCommand;
}

protected abstract double? ValueFromBuilder(TBuilder builder);

public abstract IMoBiCommand ChangeValueFormulaCommand(TBuildingBlock buildingBlock, TBuilder builder, IFormula formula);
public IMoBiCommand SetFormula(TBuildingBlock buildingBlock, TBuilder builder, IFormula formula)
{
return SetFormula(buildingBlock, builder, formula, shouldClearValue: builder.Value.HasValue);
}

protected IMoBiCommand setFormula(TBuildingBlock buildingBlock, TBuilder builder, IFormula formula)
{
Expand Down Expand Up @@ -113,14 +114,12 @@ public IMoBiCommand SetDisplayValueWithUnit(TBuilder builder, double? newDisplay
return SetValueWithUnit(builder, unit.UnitValueToBaseUnitValue(newDisplayValue.GetValueOrDefault(double.NaN)), unit, buildingBlock);
}

protected abstract IMoBiCommand SetValueWithUnit(TBuilder builder, double? unitValueToBaseUnitValue, Unit unit, TBuildingBlock buildingBlock);

protected IMoBiCommand setValue(TBuilder builder, double? newDisplayValue, Unit unit, TBuildingBlock buildingBlock)
{
return SetDisplayValueWithUnit(builder, newDisplayValue, unit, buildingBlock);
}

public abstract IMoBiCommand SetFormula(TBuildingBlock buildingBlock, TBuilder builder, IFormula formula);


public IMoBiCommand SetValue(TBuildingBlock buildingBlock, double? valueInDisplayUnit, TBuilder builder)
{
Expand Down Expand Up @@ -155,5 +154,32 @@ public virtual ICommand<IMoBiContext> AddNewFormulaAtBuildingBlock(TBuildingBloc

return macroCommand;
}

protected virtual double? ValueFromBuilder(TBuilder builder)
{
return builder.Value;
}

public IMoBiCommand ChangeValueFormulaCommand(TBuildingBlock buildingBlock, TBuilder builder, IFormula formula)
{
return new ChangeValueFormulaCommand<TBuilder>(buildingBlock, builder, formula, builder.Formula).Run(Context);
}

protected IMoBiCommand SetValueWithUnit(TBuilder builder, double? unitValueToBaseUnitValue, Unit unit, TBuildingBlock buildingBlock)
{
return new PathAndValueEntityValueOrUnitChangedCommand<TBuilder, TBuildingBlock>(builder, unitValueToBaseUnitValue, unit, buildingBlock).Run(Context);
}

public override IMoBiCommand Merge(TBuildingBlock buildingBlockToMerge, TBuildingBlock targetBuildingBlock)
{
// TODO
return new MoBiEmptyCommand();
}

protected override IMoBiMacroCommand GenerateAddCommandAndUpdateFormulaReferences(TBuilder builder, TBuildingBlock targetBuildingBlock, string originalBuilderName = null)
{
// You cannot add Individual Parameters to the buildingBlock
return new MoBiMacroCommand();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
using MoBi.Core.Commands;
using MoBi.Core.Domain.Services;
using MoBi.Core.Domain.Services;
using MoBi.Presentation.Tasks.Edit;
using OSPSuite.Core.Commands.Core;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.UnitSystem;

namespace MoBi.Presentation.Tasks.Interaction
{
public interface IInteractionTasksForExpressionProfileBuildingBlock : IInteractionTasksForBuildingBlock<ExpressionProfileBuildingBlock>, IInteractionTaskForPathAndValueEntity<ExpressionProfileBuildingBlock, ExpressionParameter>
public interface IInteractionTaskForIndividualBuildingBlock: IInteractionTasksForBuildingBlock<IndividualBuildingBlock>, IInteractionTaskForPathAndValueEntity<IndividualBuildingBlock, IndividualParameter>
{

}

public class InteractionTasksForExpressionProfileBuildingBlock : InteractionTaskForPathAndValueEntity<ExpressionProfileBuildingBlock, ExpressionParameter>, IInteractionTasksForExpressionProfileBuildingBlock
public class InteractionTaskForIndividualBuildingBlock : InteractionTaskForPathAndValueEntity<IndividualBuildingBlock, IndividualParameter>
{
public InteractionTasksForExpressionProfileBuildingBlock(IInteractionTaskContext interactionTaskContext, IEditTasksForBuildingBlock<ExpressionProfileBuildingBlock> editTask, IMoBiFormulaTask formulaTask) :
base(interactionTaskContext, editTask, formulaTask)
public InteractionTaskForIndividualBuildingBlock(IInteractionTaskContext interactionTaskContext, IEditTasksForBuildingBlock<IndividualBuildingBlock> editTask, IMoBiFormulaTask moBiFormulaTask) : base(interactionTaskContext, editTask, moBiFormulaTask)
{
}

public override IMoBiCommand Merge(ExpressionProfileBuildingBlock buildingBlockToMerge, ExpressionProfileBuildingBlock targetBuildingBlock)
{
// TODO
return new MoBiEmptyCommand();
}

public override IMoBiCommand SetFormula(ExpressionProfileBuildingBlock buildingBlock, ExpressionParameter builder, IFormula formula)
{
return SetFormula(buildingBlock, builder, formula, shouldClearValue:builder.Value.HasValue);
}
}

protected override IMoBiMacroCommand GenerateAddCommandAndUpdateFormulaReferences(ExpressionParameter builder, ExpressionProfileBuildingBlock targetBuildingBlock, string originalBuilderName = null)
{
// You cannot add ExpressionParameters to the buildingBlock
return new MoBiMacroCommand();
}
public interface IInteractionTasksForExpressionProfileBuildingBlock : IInteractionTasksForBuildingBlock<ExpressionProfileBuildingBlock>, IInteractionTaskForPathAndValueEntity<ExpressionProfileBuildingBlock, ExpressionParameter>
{

}

protected override double? ValueFromBuilder(ExpressionParameter builder)
public class InteractionTasksForExpressionProfileBuildingBlock : InteractionTaskForPathAndValueEntity<ExpressionProfileBuildingBlock, ExpressionParameter>, IInteractionTasksForExpressionProfileBuildingBlock
{
public InteractionTasksForExpressionProfileBuildingBlock(IInteractionTaskContext interactionTaskContext, IEditTasksForBuildingBlock<ExpressionProfileBuildingBlock> editTask, IMoBiFormulaTask formulaTask) :
base(interactionTaskContext, editTask, formulaTask)
{
return builder.Value;
}

public override IMoBiCommand ChangeValueFormulaCommand(ExpressionProfileBuildingBlock buildingBlock, ExpressionParameter builder, IFormula formula)
{
return new ChangeValueFormulaCommand<ExpressionParameter>(buildingBlock, builder, formula, builder.Formula).Run(Context);
}

protected override IMoBiCommand SetValueWithUnit(ExpressionParameter builder, double? unitValueToBaseUnitValue, Unit unit, ExpressionProfileBuildingBlock startValues)
{
return new PathAndValueEntityValueOrUnitChangedCommand<ExpressionParameter, ExpressionProfileBuildingBlock>(builder, unitValueToBaseUnitValue, unit, startValues).Run(Context);
}
}
}
Loading

0 comments on commit d7d51ce

Please sign in to comment.