-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using OSPSuite.Core.Domain.Builder; | ||
using OSPSuite.Utility.Visitor; | ||
|
||
namespace OSPSuite.Core.Domain | ||
{ | ||
public class ModuleConfiguration : IVisitable<IVisitor> | ||
{ | ||
public Module Module { get; } | ||
|
||
/// <summary> | ||
/// Reference to selected molecule start value in the Module (can be null if none is used) | ||
/// </summary> | ||
public MoleculeStartValuesBuildingBlock SelectedMoleculeStartValues { get; } | ||
|
||
/// <summary> | ||
/// Reference to selected parameter start value in the Module (can be null if none is used) | ||
/// </summary> | ||
public ParameterStartValuesBuildingBlock SelectedParameterStartValues { get; } | ||
|
||
public ModuleConfiguration(Module module, MoleculeStartValuesBuildingBlock selectedMoleculeStartValueBuilding = null, ParameterStartValuesBuildingBlock selectedParameterStartValues = null) | ||
{ | ||
Module = module; | ||
SelectedMoleculeStartValues = selectedMoleculeStartValueBuilding ?? module.MoleculeStartValuesCollection.FirstOrDefault(); | ||
SelectedParameterStartValues = selectedParameterStartValues ?? module.ParameterStartValuesCollection.FirstOrDefault(); | ||
} | ||
|
||
public void AcceptVisitor(IVisitor visitor) | ||
{ | ||
Module.AcceptVisitor(visitor); | ||
} | ||
|
||
public virtual IEnumerable<IMoleculeBuilder> AllPresentMolecules() | ||
{ | ||
if (Module.Molecule == null || SelectedMoleculeStartValues == null) | ||
return Enumerable.Empty<IMoleculeBuilder>(); | ||
|
||
return Module.Molecule.AllPresentFor(SelectedMoleculeStartValues); | ||
} | ||
|
||
public virtual IEnumerable<MoleculeStartValue> AllPresentMoleculeValues() | ||
{ | ||
if (Module.Molecule == null) | ||
return Enumerable.Empty<MoleculeStartValue>(); | ||
|
||
return AllPresentMoleculeValuesFor(Module.Molecule.Select(x => x.Name)); | ||
} | ||
|
||
public virtual IEnumerable<MoleculeStartValue> AllPresentMoleculeValuesFor(IEnumerable<string> moleculeNames) | ||
{ | ||
if (SelectedMoleculeStartValues == null) | ||
return Enumerable.Empty<MoleculeStartValue>(); | ||
|
||
return SelectedMoleculeStartValues | ||
.Where(msv => moleculeNames.Contains(msv.MoleculeName)) | ||
.Where(msv => msv.IsPresent); | ||
} | ||
} | ||
} |