44using MoBi . Assets ;
55using MoBi . Core . Domain . Extensions ;
66using MoBi . Core . Domain . Model ;
7- using MoBi . Core . Domain . Repository ;
7+ using MoBi . Core . Services ;
88using MoBi . Presentation . DTO ;
99using MoBi . Presentation . Mappers ;
1010using MoBi . Presentation . Views ;
11- using OSPSuite . Assets ;
1211using OSPSuite . Core . Domain ;
1312using OSPSuite . Core . Domain . Builder ;
1413using OSPSuite . Core . Domain . Services ;
@@ -39,6 +38,8 @@ public class SelectEventAssignmentTargetPresenter : AbstractDisposablePresenter<
3938 private readonly ISelectEntityInTreePresenter _selectEntityInTreePresenter ;
4039 private readonly ISpatialStructureToSpatialStructureDTOMapper _spatialStructureDTOMapper ;
4140 private readonly IBuildingBlockRepository _buildingBlockRepository ;
41+ private readonly IPathAndValueContainerizingTask _containerizingTask ;
42+ private readonly Cache < IBuildingBlock , IContainer > _pathAndValueContainers = new Cache < IBuildingBlock , IContainer > ( ) ;
4243 private IReadOnlyList < MoleculeBuilder > _molecules ;
4344 private IReadOnlyList < ReactionBuilder > _reactions ;
4445 private ICache < IObjectBase , string > _forbiddenAssignees ;
@@ -54,7 +55,8 @@ public SelectEventAssignmentTargetPresenter(
5455 IReactionDimensionRetriever dimensionRetriever ,
5556 ISelectEntityInTreePresenter selectEntityInTreePresenter ,
5657 ISpatialStructureToSpatialStructureDTOMapper spatialStructureDTOMapper ,
57- IBuildingBlockRepository buildingBlockRepository
58+ IBuildingBlockRepository buildingBlockRepository ,
59+ IPathAndValueContainerizingTask containerizingTask
5860 )
5961 : base ( view )
6062 {
@@ -63,6 +65,7 @@ IBuildingBlockRepository buildingBlockRepository
6365 _selectEntityInTreePresenter = selectEntityInTreePresenter ;
6466 _spatialStructureDTOMapper = spatialStructureDTOMapper ;
6567 _buildingBlockRepository = buildingBlockRepository ;
68+ _containerizingTask = containerizingTask ;
6669 _objectPathFactory = objectPathFactory ;
6770 _dummyMoleculeDTOMapper = dummyMoleculeDTOMapper ;
6871 _dummyReactionDTOMapper = dummyReactionDTOMapper ;
@@ -94,14 +97,18 @@ public IReadOnlyList<ObjectBaseDTO> GetChildren(ObjectBaseDTO parentDTO)
9497 if ( parent . IsAnImplementationOf < IDistributedParameter > ( ) )
9598 return Array . Empty < ObjectBaseDTO > ( ) ;
9699
97- var spatialStructureDTO = parentDTO as SpatialStructureDTO ;
98- if ( spatialStructureDTO != null )
100+ if ( parentDTO is SpatialStructureDTO spatialStructureDTO )
99101 return mapSpatialStructureChildren ( spatialStructureDTO ) ;
100102
101- var container = parent as IContainer ;
102- if ( container == null )
103+ if ( parent is IndividualBuildingBlock individualBuildingBlock )
104+ return map ( _containerizingTask . ChildrenFor < IndividualBuildingBlock , IndividualParameter > ( individualBuildingBlock , _pathAndValueContainers ) ) ;
105+
106+ if ( ! ( parent is IContainer container ) )
103107 return Array . Empty < ObjectBaseDTO > ( ) ;
104108
109+ if ( _containerizingTask . IsInCachedTree ( container , _pathAndValueContainers ) )
110+ return map ( _containerizingTask . ChildrenFor ( container , _pathAndValueContainers ) ) ;
111+
105112 if ( parent . IsAnImplementationOf < MoleculeBuilder > ( ) || parent . IsAnImplementationOf < ReactionBuilder > ( ) )
106113 {
107114 //Molecule builder and reaction builder are dummy entities at that stage=>add dummy parameters
@@ -112,7 +119,7 @@ public IReadOnlyList<ObjectBaseDTO> GetChildren(ObjectBaseDTO parentDTO)
112119 return map ( globalParameterUnder ( container ) ) ;
113120 }
114121
115- //Real structural container.
122+ //Real structural container.
116123 var list = new List < ObjectBaseDTO > ( ) ;
117124
118125 //Add sub containers
@@ -136,10 +143,10 @@ private IReadOnlyList<ObjectBaseDTO> mapSpatialStructureChildren(SpatialStructur
136143 if ( spatialStructureDTO . MoleculeProperties != null )
137144 objectBaseDTOs . Add ( spatialStructureDTO . MoleculeProperties ) ;
138145
139- if ( spatialStructureDTO . TopContainers != null && spatialStructureDTO . TopContainers . Any ( ) )
146+ if ( spatialStructureDTO . TopContainers != null && spatialStructureDTO . TopContainers . Any ( ) )
140147 objectBaseDTOs . AddRange ( spatialStructureDTO . TopContainers ) ;
141148
142- if ( spatialStructureDTO . Neighborhoods != null )
149+ if ( spatialStructureDTO . Neighborhoods != null )
143150 objectBaseDTOs . Add ( spatialStructureDTO . Neighborhoods ) ;
144151
145152 return objectBaseDTOs ;
@@ -199,9 +206,11 @@ public void Init(IContainer container, ICache<IObjectBase, string> forbiddenAssi
199206 _molecules = _buildingBlockRepository . MoleculeBlockCollection . SelectMany ( bb => bb . All ( ) ) . Distinct ( new NameComparer < MoleculeBuilder > ( ) ) . OrderBy ( x => x . Name ) . ToList ( ) ;
200207 _reactions = _buildingBlockRepository . ReactionBlockCollection . SelectMany ( bb => bb . All ( ) ) . Distinct ( new NameComparer < ReactionBuilder > ( ) ) . OrderBy ( x => x . Name ) . ToList ( ) ;
201208 _forbiddenAssignees = forbiddenAssignees ;
209+ _pathAndValueContainers . Clear ( ) ;
202210 var list = new List < ObjectBaseDTO > ( ) ;
203211 list . AddRange ( _buildingBlockRepository . SpatialStructureCollection . MapAllUsing ( _spatialStructureDTOMapper ) ) ;
204212 list . Add ( _objectBaseDTOMapper . MapFrom ( container ) ) ;
213+ list . AddRange ( _buildingBlockRepository . IndividualsCollection . MapAllUsing ( _objectBaseDTOMapper ) ) ;
205214 list . AddRange ( globalReactionParameters ( ) ) ;
206215
207216 _selectEntityInTreePresenter . InitTreeStructure ( list ) ;
@@ -229,6 +238,12 @@ private FormulaUsablePath generatePathFromDTO(ObjectBaseDTO dto)
229238 return formulaUsablePathFrom ( path , getDimensionFor ( dto ) ) ;
230239 }
231240
241+ if ( dto . ObjectBase is IndividualParameter individualParameter )
242+ {
243+ var path = new ObjectPath ( individualParameter . Path ) ;
244+ return formulaUsablePathFrom ( path , individualParameter . Dimension ) ;
245+ }
246+
232247 var selectedEntity = _context . Get < IEntity > ( dto . Id ) ;
233248 if ( selectedEntity . IsAnImplementationOf < IUsingFormula > ( ) )
234249 {
@@ -259,8 +274,6 @@ private IEntity getExistingParentContainerFromDTO(ObjectBaseDTO dto)
259274 return dtoParent . ObjectBase as IEntity ;
260275 }
261276
262-
263-
264277 private IEnumerable < ObjectBaseDTO > getLocalInformationForReaction ( IContainer container )
265278 {
266279 return _reactions . Select ( x => _dummyReactionDTOMapper . MapFrom ( x , container ) ) ;
0 commit comments