mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 18:40:05 +00:00 
			
		
		
		
	Timeline step back
This commit is contained in:
		
							parent
							
								
									6f1fb84397
								
							
						
					
					
						commit
						0ddd9d91ea
					
				
					 2 changed files with 90 additions and 12 deletions
				
			
		|  | @ -33,6 +33,7 @@ public: | ||||||
|    TimelineManager* self_; |    TimelineManager* self_; | ||||||
| 
 | 
 | ||||||
|    void SelectTime(std::chrono::system_clock::time_point selectedTime = {}); |    void SelectTime(std::chrono::system_clock::time_point selectedTime = {}); | ||||||
|  |    void StepBack(); | ||||||
| 
 | 
 | ||||||
|    std::string                           radarSite_ {"?"}; |    std::string                           radarSite_ {"?"}; | ||||||
|    std::string                           previousRadarSite_ {"?"}; |    std::string                           previousRadarSite_ {"?"}; | ||||||
|  | @ -51,6 +52,12 @@ TimelineManager::~TimelineManager() = default; | ||||||
| 
 | 
 | ||||||
| void TimelineManager::SetRadarSite(const std::string& radarSite) | void TimelineManager::SetRadarSite(const std::string& radarSite) | ||||||
| { | { | ||||||
|  |    if (p->radarSite_ == radarSite) | ||||||
|  |    { | ||||||
|  |       // No action needed
 | ||||||
|  |       return; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    logger_->debug("SetRadarSite: {}", radarSite); |    logger_->debug("SetRadarSite: {}", radarSite); | ||||||
| 
 | 
 | ||||||
|    p->radarSite_ = radarSite; |    p->radarSite_ = radarSite; | ||||||
|  | @ -123,6 +130,8 @@ void TimelineManager::AnimationStepBegin() | ||||||
| void TimelineManager::AnimationStepBack() | void TimelineManager::AnimationStepBack() | ||||||
| { | { | ||||||
|    logger_->debug("AnimationStepBack"); |    logger_->debug("AnimationStepBack"); | ||||||
|  | 
 | ||||||
|  |    p->StepBack(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void TimelineManager::AnimationPlay() | void TimelineManager::AnimationPlay() | ||||||
|  | @ -217,6 +226,60 @@ void TimelineManager::Impl::SelectTime( | ||||||
|       }); |       }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void TimelineManager::Impl::StepBack() | ||||||
|  | { | ||||||
|  |    scwx::util::async( | ||||||
|  |       [this]() | ||||||
|  |       { | ||||||
|  |          // Take a lock for time selection
 | ||||||
|  |          std::unique_lock lock {selectTimeMutex_}; | ||||||
|  | 
 | ||||||
|  |          // Determine time to get active volume times
 | ||||||
|  |          std::chrono::system_clock::time_point queryTime = adjustedTime_; | ||||||
|  |          if (queryTime == std::chrono::system_clock::time_point {}) | ||||||
|  |          { | ||||||
|  |             queryTime = std::chrono::system_clock::now(); | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          // Request active volume times
 | ||||||
|  |          auto radarProductManager = | ||||||
|  |             manager::RadarProductManager::Instance(radarSite_); | ||||||
|  |          auto volumeTimes = | ||||||
|  |             radarProductManager->GetActiveVolumeTimes(queryTime); | ||||||
|  | 
 | ||||||
|  |          std::set<std::chrono::system_clock::time_point>::const_iterator it; | ||||||
|  | 
 | ||||||
|  |          if (adjustedTime_ == std::chrono::system_clock::time_point {}) | ||||||
|  |          { | ||||||
|  |             // If the adjusted time is live, get the last element in the set
 | ||||||
|  |             it = volumeTimes.cend(); | ||||||
|  |             if (!volumeTimes.empty()) | ||||||
|  |             { | ||||||
|  |                --it; | ||||||
|  |             } | ||||||
|  |          } | ||||||
|  |          else | ||||||
|  |          { | ||||||
|  |             // Get the current element in the set
 | ||||||
|  |             it = scwx::util::GetBoundedElementIterator(volumeTimes, | ||||||
|  |                                                        adjustedTime_); | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          // Only if we aren't at the beginning of the volume times set
 | ||||||
|  |          if (it != volumeTimes.cbegin()) | ||||||
|  |          { | ||||||
|  |             // Select the previous time
 | ||||||
|  |             adjustedTime_ = *(--it); | ||||||
|  |             selectedTime_ = adjustedTime_; | ||||||
|  | 
 | ||||||
|  |             logger_->debug("Volume time updated: {}", | ||||||
|  |                            scwx::util::TimeString(adjustedTime_)); | ||||||
|  | 
 | ||||||
|  |             emit self_->VolumeTimeUpdated(adjustedTime_); | ||||||
|  |          } | ||||||
|  |       }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| std::shared_ptr<TimelineManager> TimelineManager::Instance() | std::shared_ptr<TimelineManager> TimelineManager::Instance() | ||||||
| { | { | ||||||
|    static std::weak_ptr<TimelineManager> timelineManagerReference_ {}; |    static std::weak_ptr<TimelineManager> timelineManagerReference_ {}; | ||||||
|  |  | ||||||
|  | @ -8,14 +8,13 @@ namespace scwx | ||||||
| namespace util | namespace util | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| template<class Container, class ReturnType = Container::const_pointer> | template<class Container> | ||||||
| ReturnType GetBoundedElementPointer(Container& container, | Container::const_iterator | ||||||
|  | GetBoundedElementIterator(Container&                          container, | ||||||
|                           const typename Container::key_type& key) |                           const typename Container::key_type& key) | ||||||
| { | { | ||||||
|    ReturnType elementPtr {nullptr}; |  | ||||||
| 
 |  | ||||||
|    // Find the first element greater than the key requested
 |    // Find the first element greater than the key requested
 | ||||||
|    auto it = container.upper_bound(key); |    typename Container::const_iterator it = container.upper_bound(key); | ||||||
| 
 | 
 | ||||||
|    // An element with a key greater was found
 |    // An element with a key greater was found
 | ||||||
|    if (it != container.cend()) |    if (it != container.cend()) | ||||||
|  | @ -25,19 +24,34 @@ ReturnType GetBoundedElementPointer(Container& container, | ||||||
|       { |       { | ||||||
|          // Get the element immediately preceding, this the element we are
 |          // Get the element immediately preceding, this the element we are
 | ||||||
|          // looking for
 |          // looking for
 | ||||||
|          elementPtr = &(*(--it)); |          --it; | ||||||
|       } |       } | ||||||
|       else |       else | ||||||
|       { |       { | ||||||
|          // The current element is a good substitute
 |          // The current element is a good substitute
 | ||||||
|          elementPtr = &(*it); |  | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|    else if (container.size() > 0) |    else if (container.size() > 0) | ||||||
|    { |    { | ||||||
|       // An element with a key greater was not found. If it exists, it must be
 |       // An element with a key greater was not found. If it exists, it must be
 | ||||||
|       // the last element.
 |       // the last element. Decrement the end iterator.
 | ||||||
|       elementPtr = &(*container.rbegin()); |       --it; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return it; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | template<class Container, class ReturnType = Container::const_pointer> | ||||||
|  | ReturnType GetBoundedElementPointer(Container& container, | ||||||
|  |                                     const typename Container::key_type& key) | ||||||
|  | { | ||||||
|  |    ReturnType elementPtr {nullptr}; | ||||||
|  | 
 | ||||||
|  |    auto it = GetBoundedElementIterator(container, key); | ||||||
|  | 
 | ||||||
|  |    if (it != container.cend()) | ||||||
|  |    { | ||||||
|  |       elementPtr = &(*(it)); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    return elementPtr; |    return elementPtr; | ||||||
|  | @ -48,9 +62,10 @@ ReturnType GetBoundedElement(std::map<Key, T>& map, const Key& key) | ||||||
| { | { | ||||||
|    ReturnType element; |    ReturnType element; | ||||||
| 
 | 
 | ||||||
|    typename std::map<Key, T>::pointer elementPtr = |    typename std::map<Key, T>::const_pointer elementPtr = | ||||||
|       GetBoundedElementPointer<std::map<Key, T>, |       GetBoundedElementPointer<std::map<Key, T>, | ||||||
|                                typename std::map<Key, T>::pointer>(map, key); |                                typename std::map<Key, T>::const_pointer>(map, | ||||||
|  |                                                                          key); | ||||||
|    if (elementPtr != nullptr) |    if (elementPtr != nullptr) | ||||||
|    { |    { | ||||||
|       element = elementPtr->second; |       element = elementPtr->second; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat