Skip to content

Commit

Permalink
Added dictionary that stores created representations
Browse files Browse the repository at this point in the history
  • Loading branch information
srudenkoamc committed Nov 8, 2023
1 parent b2955d3 commit 43a9602
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
70 changes: 70 additions & 0 deletions Elements/src/DoorProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Elements
{
internal class DoorProperties
{
private readonly double _width;
private readonly double _height;
private readonly Material _material;
private readonly DoorOpeningSide _openingSide;
private readonly DoorOpeningType _openingType;

public DoorProperties(Door door)
{
_width = door.ClearWidth;
_height = door.ClearHeight;
_material = door.Material;
_openingSide = door.OpeningSide;
_openingType = door.OpeningType;
}

public override bool Equals(object obj)
{
if (!(obj is DoorProperties doorProps))
{
return false;
}

if (!_width.ApproximatelyEquals(doorProps._width))
{
return false;
}

if (!_height.ApproximatelyEquals(doorProps._height))
{
return false;
}

if (!_material.Id.Equals(doorProps._material.Id))
{
return false;
}

if (!_openingSide.Equals(doorProps._openingSide))
{
return false;
}

if (!_openingType.Equals(doorProps._openingType))
{
return false;
}

return true;
}

public override int GetHashCode()
{
int hash = 17;
hash = hash * 31 + _width.GetHashCode();
hash = hash * 31 + _height.GetHashCode();
hash = hash * 31 + _material.Id.GetHashCode();
hash = hash * 31 + _openingSide.GetHashCode();
hash = hash * 31 + _openingType.GetHashCode();
return hash;
}
}
}
21 changes: 18 additions & 3 deletions Elements/src/DoorRepresentationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ namespace Elements
{
internal class DoorRepresentationProvider : RepresentationProvider<Door>
{
public override List<RepresentationInstance> GetInstances(Door element)
private readonly Dictionary<DoorProperties, List<RepresentationInstance>> _doorTypeToRepresentations;

public DoorRepresentationProvider()
{
_doorTypeToRepresentations = new Dictionary<DoorProperties, List<RepresentationInstance>>();
}

public override List<RepresentationInstance> GetInstances(Door door)
{
var doorProps = new DoorProperties(door);

if (_doorTypeToRepresentations.TryGetValue(doorProps, out var representations))
{
return representations;
}

var representationInstances = new List<RepresentationInstance>()
{
CreateSolidDoorRepresentation(element),
CreateCurveDoorRepresentation(element)
CreateSolidDoorRepresentation(door),
CreateCurveDoorRepresentation(door)
};

_doorTypeToRepresentations[doorProps] = representationInstances;
return representationInstances;
}

Expand Down

0 comments on commit 43a9602

Please sign in to comment.