-
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.
Fixes #1920 create neighborhood builder with path instead of containe…
…r: (#1922) * Fixes #1920 create neighborhood builder with path instead of container: * Fixes #1920 create neighborhood builder with path instead of container * add icons * add icons
- Loading branch information
Showing
44 changed files
with
503 additions
and
448 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
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
60 changes: 45 additions & 15 deletions
60
src/OSPSuite.Core/Comparison/NeighborhoodBaseDiffBuilder.cs
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 |
---|---|---|
@@ -1,45 +1,75 @@ | ||
using OSPSuite.Assets; | ||
using OSPSuite.Core.Domain; | ||
using OSPSuite.Core.Domain.Builder; | ||
using OSPSuite.Core.Domain.Services; | ||
|
||
namespace OSPSuite.Core.Comparison | ||
{ | ||
public class NeighborhoodBaseDiffBuilder : DiffBuilder<INeighborhoodBase> | ||
public abstract class NeighborhoodBaseDiffBuilder<TNeighborhood> : DiffBuilder<TNeighborhood> where TNeighborhood : class, IContainer | ||
{ | ||
private readonly ContainerDiffBuilder _containerDiffBuilder; | ||
private readonly IEntityPathResolver _entityPathResolver; | ||
|
||
public NeighborhoodBaseDiffBuilder(ContainerDiffBuilder containerDiffBuilder, IEntityPathResolver entityPathResolver) | ||
protected NeighborhoodBaseDiffBuilder(ContainerDiffBuilder containerDiffBuilder) | ||
{ | ||
_containerDiffBuilder = containerDiffBuilder; | ||
_entityPathResolver = entityPathResolver; | ||
} | ||
|
||
public override void Compare(IComparison<INeighborhoodBase> comparison) | ||
public override void Compare(IComparison<TNeighborhood> comparison) | ||
{ | ||
_containerDiffBuilder.Compare(comparison); | ||
compareNeighbors(comparison); | ||
} | ||
|
||
private void compareNeighbors(IComparison<INeighborhoodBase> comparison) | ||
private void compareNeighbors(IComparison<TNeighborhood> comparison) | ||
{ | ||
var firstNeigbor1Path = _entityPathResolver.PathFor(comparison.Object1.FirstNeighbor); | ||
var secondNeigbor1Path = _entityPathResolver.PathFor(comparison.Object1.SecondNeighbor); | ||
var firstNeigbor2Path = _entityPathResolver.PathFor(comparison.Object2.FirstNeighbor); | ||
var secondNeigbor2Path = _entityPathResolver.PathFor(comparison.Object2.SecondNeighbor); | ||
var (firstNeighbor1Path, secondNeighbor1Path, firstNeighbor2Path, secondNeighbor2Path) = GetNeighborsComparisonPath(comparison); | ||
|
||
if (firstNeigbor1Path.Equals(firstNeigbor2Path) && secondNeigbor1Path.Equals(secondNeigbor2Path) || | ||
firstNeigbor1Path.Equals(secondNeigbor2Path) && secondNeigbor1Path.Equals(firstNeigbor2Path)) | ||
if (firstNeighbor1Path.Equals(firstNeighbor2Path) && secondNeighbor1Path.Equals(secondNeighbor2Path) || | ||
firstNeighbor1Path.Equals(secondNeighbor2Path) && secondNeighbor1Path.Equals(firstNeighbor2Path)) | ||
return; | ||
|
||
comparison.Add(new PropertyValueDiffItem | ||
{ | ||
CommonAncestor = comparison.Object1, | ||
FormattedValue1 = Captions.Diff.ConnectionBetween(firstNeigbor1Path, secondNeigbor1Path), | ||
FormattedValue2 = Captions.Diff.ConnectionBetween(firstNeigbor2Path, secondNeigbor2Path), | ||
FormattedValue1 = Captions.Diff.ConnectionBetween(firstNeighbor1Path, secondNeighbor1Path), | ||
FormattedValue2 = Captions.Diff.ConnectionBetween(firstNeighbor2Path, secondNeighbor2Path), | ||
PropertyName = Captions.Diff.Connection, | ||
Description = Captions.Diff.PropertyDiffers(Captions.Diff.Connection, Captions.Diff.ConnectionBetween(firstNeigbor1Path, secondNeigbor1Path), Captions.Diff.ConnectionBetween(firstNeigbor2Path, secondNeigbor2Path)) | ||
Description = Captions.Diff.PropertyDiffers(Captions.Diff.Connection, Captions.Diff.ConnectionBetween(firstNeighbor1Path, secondNeighbor1Path), Captions.Diff.ConnectionBetween(firstNeighbor2Path, secondNeighbor2Path)) | ||
}); | ||
} | ||
|
||
protected abstract (ObjectPath firstNeighbor1Path, ObjectPath secondNeighbor1Path, ObjectPath firstNeighbor2Path, ObjectPath secondNeighbor2Path) GetNeighborsComparisonPath(IComparison<TNeighborhood> comparison); | ||
} | ||
|
||
public class NeighborhoodBuilderDiffBuilder : NeighborhoodBaseDiffBuilder<NeighborhoodBuilder> | ||
{ | ||
public NeighborhoodBuilderDiffBuilder(ContainerDiffBuilder containerDiffBuilder) : base(containerDiffBuilder) | ||
{ | ||
} | ||
|
||
protected override (ObjectPath firstNeighbor1Path, ObjectPath secondNeighbor1Path, ObjectPath firstNeighbor2Path, ObjectPath secondNeighbor2Path) GetNeighborsComparisonPath(IComparison<NeighborhoodBuilder> comparison) | ||
{ | ||
return (comparison.Object1.FirstNeighborPath, comparison.Object1.SecondNeighborPath, comparison.Object2.FirstNeighborPath, comparison.Object2.SecondNeighborPath); | ||
} | ||
} | ||
|
||
public class NeighborhoodDiffBuilder : NeighborhoodBaseDiffBuilder<Neighborhood> | ||
{ | ||
private readonly IEntityPathResolver _entityPathResolver; | ||
|
||
public NeighborhoodDiffBuilder(ContainerDiffBuilder containerDiffBuilder, IEntityPathResolver entityPathResolver) : base(containerDiffBuilder) | ||
{ | ||
_entityPathResolver = entityPathResolver; | ||
} | ||
|
||
protected override (ObjectPath firstNeighbor1Path, ObjectPath secondNeighbor1Path, ObjectPath firstNeighbor2Path, ObjectPath secondNeighbor2Path) GetNeighborsComparisonPath(IComparison<Neighborhood> comparison) | ||
{ | ||
var firstNeighbor1Path = _entityPathResolver.ObjectPathFor(comparison.Object1.FirstNeighbor); | ||
var secondNeighbor1Path = _entityPathResolver.ObjectPathFor(comparison.Object1.SecondNeighbor); | ||
var firstNeighbor2Path = _entityPathResolver.ObjectPathFor(comparison.Object2.FirstNeighbor); | ||
var secondNeighbor2Path = _entityPathResolver.ObjectPathFor(comparison.Object2.SecondNeighbor); | ||
|
||
return (firstNeighbor1Path, secondNeighbor1Path, firstNeighbor2Path, secondNeighbor2Path); | ||
} | ||
} | ||
} |
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,68 @@ | ||
using System.Xml.Linq; | ||
using OSPSuite.Core.Domain; | ||
using OSPSuite.Core.Domain.Builder; | ||
using OSPSuite.Core.Serialization; | ||
using OSPSuite.Core.Serialization.Exchange; | ||
using OSPSuite.Utility.Extensions; | ||
using OSPSuite.Utility.Visitor; | ||
|
||
namespace OSPSuite.Core.Converters.v12 | ||
{ | ||
public class Converter110To120 : IObjectConverter, | ||
IVisitor<ISpatialStructure>, | ||
IVisitor<SimulationTransfer>, | ||
IVisitor<IModelCoreSimulation>, | ||
IVisitor<IBuildConfiguration> | ||
{ | ||
private readonly IObjectPathFactory _objectPathFactory; | ||
private bool _converted; | ||
|
||
public Converter110To120(IObjectPathFactory objectPathFactory) | ||
{ | ||
_objectPathFactory = objectPathFactory; | ||
} | ||
|
||
public bool IsSatisfiedBy(int version) => version == PKMLVersion.V11_0; | ||
|
||
public (int convertedToVersion, bool conversionHappened) Convert(object objectToUpdate) | ||
{ | ||
_converted = false; | ||
performConversion(objectToUpdate); | ||
return (PKMLVersion.V12_0, _converted); | ||
} | ||
|
||
public (int convertedToVersion, bool conversionHappened) ConvertXml(XElement element) | ||
{ | ||
return (PKMLVersion.V12_0, false); | ||
} | ||
|
||
private void performConversion(object objectToUpdate) => this.Visit(objectToUpdate); | ||
|
||
public void Visit(ISpatialStructure spatialStructure) | ||
{ | ||
spatialStructure.Neighborhoods.Each(updateNeighborsPathIn); | ||
} | ||
|
||
private void updateNeighborsPathIn(NeighborhoodBuilder neighborhoodBuilder) | ||
{ | ||
neighborhoodBuilder.FirstNeighborPath = _objectPathFactory.CreateAbsoluteObjectPath(neighborhoodBuilder.FirstNeighbor); | ||
neighborhoodBuilder.SecondNeighborPath = _objectPathFactory.CreateAbsoluteObjectPath(neighborhoodBuilder.SecondNeighbor); | ||
_converted = true; | ||
} | ||
|
||
public void Visit(SimulationTransfer simulationTransfer) | ||
{ | ||
Visit(simulationTransfer.Simulation); | ||
} | ||
|
||
public void Visit(IModelCoreSimulation modelCoreSimulation) | ||
{ | ||
Visit(modelCoreSimulation.BuildConfiguration); | ||
} | ||
|
||
public void Visit(IBuildConfiguration buildConfiguration) | ||
{ | ||
Visit(buildConfiguration.SpatialStructure); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,49 +1,65 @@ | ||
using System.Collections.Generic; | ||
using OSPSuite.Core.Domain.Services; | ||
|
||
namespace OSPSuite.Core.Domain.Builder | ||
{ | ||
public interface INeighborhoodBuilder : INeighborhoodBase | ||
public interface INeighborhoodBase : IContainer | ||
{ | ||
IContainer MoleculeProperties { get; } | ||
IEnumerable<IParameter> Parameters { get; } | ||
void AddParameter(IParameter newParameter); | ||
void RemoveParameter(IParameter parameterToRemove); | ||
bool IsConnectedTo(IContainer container); | ||
/// <summary> | ||
/// First neighbor in the neighborhood. | ||
/// </summary> | ||
IContainer FirstNeighbor { get; } | ||
|
||
/// <summary> | ||
/// Second neighbor in the neighborhood. | ||
/// </summary> | ||
IContainer SecondNeighbor { get; } | ||
} | ||
|
||
public class NeighborhoodBuilder : Container, INeighborhoodBuilder | ||
public class NeighborhoodBuilder : Container, INeighborhoodBase | ||
{ | ||
//We define a property set for the first neighbor only to be compatible with serialization prior to v12 | ||
public IContainer FirstNeighbor { get; set; } | ||
|
||
//We define a property set for the second neighbor only to be compatible with serialization prior to v12 | ||
public IContainer SecondNeighbor { get; set; } | ||
|
||
public ObjectPath FirstNeighborPath { get; set; } | ||
public ObjectPath SecondNeighborPath { get; set; } | ||
|
||
public NeighborhoodBuilder() | ||
{ | ||
ContainerType = ContainerType.Neighborhood; | ||
} | ||
|
||
public IContainer MoleculeProperties | ||
{ | ||
get { return this.GetSingleChildByName<IContainer>(Constants.MOLECULE_PROPERTIES); } | ||
} | ||
public IContainer MoleculeProperties => this.Container(Constants.MOLECULE_PROPERTIES); | ||
|
||
public IEnumerable<IParameter> Parameters | ||
{ | ||
get { return GetChildren<IParameter>(); } | ||
} | ||
public IEnumerable<IParameter> Parameters => GetChildren<IParameter>(); | ||
|
||
public void AddParameter(IParameter newParameter) => Add(newParameter); | ||
|
||
public void AddParameter(IParameter newParameter) | ||
public void RemoveParameter(IParameter parameterToRemove) => RemoveChild(parameterToRemove); | ||
|
||
public bool IsConnectedTo(ObjectPath containerPath) | ||
{ | ||
Add(newParameter); | ||
return Equals(FirstNeighborPath, containerPath) || Equals(SecondNeighborPath, containerPath); | ||
} | ||
|
||
public void RemoveParameter(IParameter parameterToRemove) | ||
public void ResolveReference(IContainer container) | ||
{ | ||
RemoveChild(parameterToRemove); | ||
FirstNeighbor = FirstNeighborPath.Resolve<IContainer>(container); | ||
SecondNeighbor = SecondNeighborPath.Resolve<IContainer>(container); | ||
} | ||
|
||
public bool IsConnectedTo(IContainer container) | ||
public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager) | ||
{ | ||
return Equals(FirstNeighbor, container) || Equals(SecondNeighbor, container); | ||
base.UpdatePropertiesFrom(source, cloneManager); | ||
var sourceNeighborhood = source as NeighborhoodBuilder; | ||
if (sourceNeighborhood == null) | ||
return; | ||
|
||
FirstNeighborPath = sourceNeighborhood.FirstNeighborPath; | ||
SecondNeighborPath = sourceNeighborhood.SecondNeighborPath; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.