All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BuildingFootprintServiceQuery.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "BuildingFootprints.h"
6 #include "BuildingFootprintService.h"
7 #include "MortonKey.h"
8 #include "ICallback.h"
9 #include "LatLongAltitude.h"
10 #include "BuildingFootprintResourceService.h"
11 
12 #include <vector>
13 #include <functional>
14 
15 
16 namespace Eegeo
17 {
18  namespace BuildingFootprints
19  {
20 
21  struct IFootprintDistanceFunctor;
22  struct IFootprintAltitudeOverlapFunctor;
23 
24  struct QueryParams
25  {
26  enum DistanceSelectionType
27  {
28  Centroid,
29  Outline
30  };
31 
32  Space::LatLong CentreLatLong;
33  double CentreAltitude;
34  float SearchRadius;
35  int MaxResults;
36  bool AllFootprintsForGroup;
37  bool OnlyOverlappingAltitude;
38  DistanceSelectionType DistanceType;
39  const BuildingFootprintService::IQueryCallback& UserCallback;
40 
41  QueryParams(const Space::LatLong& centreLatLong, float searchRadius, int maxResults, bool allFootprintsForGroup, DistanceSelectionType distanceType, const BuildingFootprintService::IQueryCallback& userCallback)
42  : CentreLatLong(centreLatLong)
43  , CentreAltitude(0.0)
44  , SearchRadius(searchRadius)
45  , MaxResults(maxResults)
46  , AllFootprintsForGroup(allFootprintsForGroup)
47  , OnlyOverlappingAltitude(false)
48  , DistanceType(distanceType)
49  , UserCallback(userCallback)
50  {}
51 
52  QueryParams(const Space::LatLongAltitude& centreLatLongAlt, float searchRadius, int maxResults, bool allFootprintsForGroup, DistanceSelectionType distanceType, const BuildingFootprintService::IQueryCallback& userCallback)
53  : CentreLatLong(centreLatLongAlt.GetLatLong())
54  , CentreAltitude(centreLatLongAlt.GetAltitude())
55  , SearchRadius(searchRadius)
56  , MaxResults(maxResults)
57  , AllFootprintsForGroup(allFootprintsForGroup)
58  , OnlyOverlappingAltitude(true)
59  , DistanceType(distanceType)
60  , UserCallback(userCallback)
61  {}
62  };
63 
65  {
66  typedef std::vector<Streaming::MortonKey> MortonKeyVector;
68 
69  BuildingFootprintServiceQuery(const BuildingFootprintServiceRequestId requestId,
70  const QueryParams& queryParams,
71  const TServiceCallback& serviceCallback,
72  BuildingFootprintResourceService& footprintResourceService,
73  BuildingFootprintRepository& footprintRepository);
74 
76 
77 
78  virtual void Execute();
79 
80  void Cancel();
81 
82  bool IsCancelled() const { return m_isCancelled; }
83 
84  BuildingFootprintServiceRequestId GetRequestId() const { return m_requestId; }
85 
86  virtual QueryParams GetQueryParams() const { return m_queryParams; }
87 
88  const MortonKeyVector& GetKeysToGather() const { return m_keysToGather; }
89 
90  virtual void Finalise();
91 
92  private:
93  bool AllSucceeded() const { return m_keysRemaining == 0 && !m_anyFail; }
94  bool AnySucceeded() const { return m_keysRemaining == 0 && m_anySuccess; }
95 
96  void HandleLoadForKey(const BuildingFootprintResourceService::LoadForKeyResult& result);
97 
98  BuildingFootprintServiceRequestId m_requestId;
99 
100  const QueryParams m_queryParams;
101 
102 
104  TLoadForKeyCallback m_loadForKeyCallback;
105 
106  const TServiceCallback& m_serviceCallback;
107 
108  BuildingFootprintResourceService& m_footprintResourceService;
109  BuildingFootprintRepository& m_footprintRepository;
110 
111  const IFootprintDistanceFunctor* m_pDistanceFunctor;
112  const IFootprintAltitudeOverlapFunctor* m_pAltitudeOverlapFunctor;
113  int m_keysRemaining;
114  MortonKeyVector m_keysToGather;
115  bool m_anyFail;
116  bool m_anySuccess;
117  bool m_isCancelled;
118  bool m_preventQueryDeletion;
119  std::vector<const BuildingFootprint*> m_footprints;
120  float m_overrideSearchRadius;
121  std::vector<BuildingFootprintResourceService::CancelHandle> m_cancellableFootprintQueries;
122  };
123  }
124 }