4 #include "ShapeEventTypes.h"
6 #include "Positioning.h"
7 #include "IPositioningViewComponent.h"
8 #include "IShapeView.h"
9 #include "ShapeHelpers.h"
10 #include "InteriorInteractionModel.h"
12 #include <unordered_set>
21 template <
typename TArgs>
28 typename TArgs::ShapeViewRepositoryType& viewRepository,
30 typename TArgs::ShapeModelAddedEventType& shapeModelAddedEvent,
31 typename TArgs::ShapeModelRemovedEventType& shapeModelRemovedEvent,
32 typename TArgs::ShapeModelChangedEventType& shapeModelChangedEvent,
34 : m_viewFactory(viewFactory)
35 , m_viewRepository(viewRepository)
36 , m_positioningViewComponent(positioningViewComponent)
37 , m_shapeModelAddedEvent(shapeModelAddedEvent)
38 , m_shapeModelRemovedEvent(shapeModelRemovedEvent)
39 , m_shapeModelChangedEvent(shapeModelChangedEvent)
40 , m_shapeModelAddedHandler(
this, &ThisType::OnShapeModelAdded)
41 , m_shapeModelRemovedHandler(
this, &ThisType::OnShapeModelRemoved)
42 , m_shapeModelChangedHandler(
this, &ThisType::OnShapeModelChanged)
43 , m_positioningViewComponentChangedHandler(
this, &ThisType::OnPositioningViewComponentChanged)
44 , m_positioningViewComponentChanged(
true)
45 , m_interiorInteractionModel(interiorInteractionModel)
47 m_shapeModelAddedEvent.Register(m_shapeModelAddedHandler);
48 m_shapeModelRemovedEvent.Register(m_shapeModelRemovedHandler);
49 m_shapeModelChangedEvent.Register(m_shapeModelChangedHandler);
50 m_positioningViewComponent.GetPositioningViewComponentChangedEvent().Register(m_positioningViewComponentChangedHandler);
55 m_shapeModelAddedEvent.Unregister(m_shapeModelAddedHandler);
56 m_shapeModelRemovedEvent.Unregister(m_shapeModelRemovedHandler);
57 m_shapeModelChangedEvent.Unregister(m_shapeModelChangedHandler);
58 m_positioningViewComponent.GetPositioningViewComponentChangedEvent().Unregister(m_positioningViewComponentChangedHandler);
63 for (
auto pShapeModel : m_modelsNeedingViewRebind)
65 UnbindView(*pShapeModel);
66 BindView(*pShapeModel);
68 m_modelsNeedingViewRebind.clear();
70 if (m_positioningViewComponentChanged)
72 std::vector<typename TArgs::ShapeViewType*> views;
73 m_viewRepository.AllItems(views);
75 for (
auto view : views)
79 m_positioningViewComponentChanged =
false;
84 void BindView(
const typename TArgs::ShapeModelType& shapeModel)
86 auto pView = m_viewFactory.CreateView(shapeModel);
87 m_viewRepository.Add(shapeModel.GetId(), pView);
92 void UnbindView(
const typename TArgs::ShapeModelType& shapeModel)
94 auto pView = m_viewRepository.Get(shapeModel.GetId());
95 m_viewRepository.Remove(shapeModel.GetId());
99 void OnShapeModelAdded(
const typename TArgs::ShapeModelType& shapeModel)
101 BindView(shapeModel);
104 void OnShapeModelRemoved(
const typename TArgs::ShapeModelType& shapeModel)
106 m_modelsNeedingViewRebind.erase(&shapeModel);
107 UnbindView(shapeModel);
110 void OnShapeModelChanged(
const typename TArgs::ShapeModelChangedMessageType& message)
112 if (message.GeometryChanged)
114 m_modelsNeedingViewRebind.insert(&message.ShapeModel);
118 auto& view = *m_viewRepository.Get(message.ShapeModel.GetId());
123 void OnPositioningViewComponentChanged()
125 m_positioningViewComponentChanged =
true;
131 const bool show = ShouldShowView(view);
132 view.SetHidden(!show);
136 bool ShouldShowView(
const IShapeView& view)
const
138 const auto& model = view.GetShapeModel();
139 bool isExpanded = m_interiorInteractionModel.IsFullyExpanded() || m_interiorInteractionModel.IsEnteringExpanded();
140 return ShapeHelpers::ShouldDisplayShape(model, m_positioningViewComponent, isExpanded);
143 typename TArgs::ShapeViewFactoryType& m_viewFactory;
144 typename TArgs::ShapeViewRepositoryType& m_viewRepository;
146 typename TArgs::ShapeModelAddedEventType& m_shapeModelAddedEvent;
147 typename TArgs::ShapeModelRemovedEventType& m_shapeModelRemovedEvent;
148 typename TArgs::ShapeModelChangedEventType& m_shapeModelChangedEvent;
155 std::unordered_set<const typename TArgs::ShapeModelType*> m_modelsNeedingViewRebind;
156 bool m_positioningViewComponentChanged;