mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:00:04 +00:00 
			
		
		
		
	Modify how level 3 tilts are selected to keep them more consistent
This commit is contained in:
		
							parent
							
								
									b74229a3f4
								
							
						
					
					
						commit
						316da55000
					
				
					 1 changed files with 80 additions and 27 deletions
				
			
		|  | @ -98,7 +98,8 @@ public: | ||||||
|        prevLongitude_ {0.0}, |        prevLongitude_ {0.0}, | ||||||
|        prevZoom_ {0.0}, |        prevZoom_ {0.0}, | ||||||
|        prevBearing_ {0.0}, |        prevBearing_ {0.0}, | ||||||
|        prevPitch_ {0.0} |        prevPitch_ {0.0}, | ||||||
|  |        tiltsToIndices_ {} | ||||||
|    { |    { | ||||||
|       // Create views
 |       // Create views
 | ||||||
|       auto overlayProductView = std::make_shared<view::OverlayProductView>(); |       auto overlayProductView = std::make_shared<view::OverlayProductView>(); | ||||||
|  | @ -273,6 +274,9 @@ public: | ||||||
|    bool productAvailabilityUpdated_ {false}; |    bool productAvailabilityUpdated_ {false}; | ||||||
|    bool productAvailabilityProductSelected_ {false}; |    bool productAvailabilityProductSelected_ {false}; | ||||||
| 
 | 
 | ||||||
|  |    std::unordered_map<std::string, size_t> tiltsToIndices_; | ||||||
|  |    size_t currentTiltIndex_ {0}; | ||||||
|  | 
 | ||||||
| public slots: | public slots: | ||||||
|    void Update(); |    void Update(); | ||||||
| }; | }; | ||||||
|  | @ -829,6 +833,17 @@ void MapWidget::SelectRadarProduct(common::RadarProductGroup group, | ||||||
|       productCode = common::GetLevel3ProductCodeByAwipsId(productName); |       productCode = common::GetLevel3ProductCodeByAwipsId(productName); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    if (group == common::RadarProductGroup::Level3) | ||||||
|  |    { | ||||||
|  |       const auto& tiltIndex = p->tiltsToIndices_.find(productName); | ||||||
|  |       p->currentTiltIndex_ = | ||||||
|  |          tiltIndex != p->tiltsToIndices_.cend() ? tiltIndex->second : 0; | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       p->currentTiltIndex_ = 0; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    if (radarProductView == nullptr || |    if (radarProductView == nullptr || | ||||||
|        radarProductView->GetRadarProductGroup() != group || |        radarProductView->GetRadarProductGroup() != group || | ||||||
|        (radarProductView->GetRadarProductGroup() == |        (radarProductView->GetRadarProductGroup() == | ||||||
|  | @ -933,11 +948,6 @@ void MapWidget::SelectRadarSite(std::shared_ptr<config::RadarSite> radarSite, | ||||||
|       if (radarProductView != nullptr) |       if (radarProductView != nullptr) | ||||||
|       { |       { | ||||||
|          radarProductView->set_radar_product_manager(p->radarProductManager_); |          radarProductView->set_radar_product_manager(p->radarProductManager_); | ||||||
|          SelectRadarProduct(radarProductView->GetRadarProductGroup(), |  | ||||||
|                             radarProductView->GetRadarProductName(), |  | ||||||
|                             0, |  | ||||||
|                             radarProductView->selected_time(), |  | ||||||
|                             false); |  | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       p->AddLayers(); |       p->AddLayers(); | ||||||
|  | @ -1756,6 +1766,24 @@ void MapWidgetImpl::RadarProductManagerConnect() | ||||||
|               this, |               this, | ||||||
|               [this]() |               [this]() | ||||||
|               { |               { | ||||||
|  |                  const common::Level3ProductCategoryMap& categoryMap = | ||||||
|  |                     widget_->GetAvailableLevel3Categories(); | ||||||
|  | 
 | ||||||
|  |                  tiltsToIndices_.clear(); | ||||||
|  |                  for (const auto& category : categoryMap) | ||||||
|  |                  { | ||||||
|  |                     for (const auto& product : category.second) | ||||||
|  |                     { | ||||||
|  |                        for (size_t tiltIndex = 0; | ||||||
|  |                             tiltIndex < product.second.size(); | ||||||
|  |                             tiltIndex++) | ||||||
|  |                        { | ||||||
|  |                           tiltsToIndices_.emplace(product.second[tiltIndex], | ||||||
|  |                                                   tiltIndex); | ||||||
|  |                        } | ||||||
|  |                     } | ||||||
|  |                  } | ||||||
|  | 
 | ||||||
|                  productAvailabilityUpdated_ = true; |                  productAvailabilityUpdated_ = true; | ||||||
|                  CheckLevel3Availability(); |                  CheckLevel3Availability(); | ||||||
|                  Q_EMIT widget_->Level3ProductsChanged(); |                  Q_EMIT widget_->Level3ProductsChanged(); | ||||||
|  | @ -2058,7 +2086,7 @@ void MapWidgetImpl::CheckLevel3Availability() | ||||||
|     * has been updated |     * has been updated | ||||||
|     * |     * | ||||||
|     * productAvailabilityProductSelected_ Only update once the radar site is |     * productAvailabilityProductSelected_ Only update once the radar site is | ||||||
|     * fully selected, including the current product |     * fully selected | ||||||
|     */ |     */ | ||||||
|    if (!(productAvailabilityCheckNeeded_ && productAvailabilityUpdated_ && |    if (!(productAvailabilityCheckNeeded_ && productAvailabilityUpdated_ && | ||||||
|          productAvailabilityProductSelected_)) |          productAvailabilityProductSelected_)) | ||||||
|  | @ -2073,6 +2101,9 @@ void MapWidgetImpl::CheckLevel3Availability() | ||||||
|       return; |       return; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    // Get radar product view for fallback selection
 | ||||||
|  |    auto radarProductView = context_->radar_product_view(); | ||||||
|  | 
 | ||||||
|    const common::Level3ProductCategoryMap& categoryMap = |    const common::Level3ProductCategoryMap& categoryMap = | ||||||
|       widget_->GetAvailableLevel3Categories(); |       widget_->GetAvailableLevel3Categories(); | ||||||
| 
 | 
 | ||||||
|  | @ -2083,6 +2114,12 @@ void MapWidgetImpl::CheckLevel3Availability() | ||||||
|       common::GetLevel3CategoryByProduct(productName); |       common::GetLevel3CategoryByProduct(productName); | ||||||
|    if (productCategory == common::Level3ProductCategory::Unknown) |    if (productCategory == common::Level3ProductCategory::Unknown) | ||||||
|    { |    { | ||||||
|  |       // Default to the same as already selected
 | ||||||
|  |       widget_->SelectRadarProduct(radarProductView->GetRadarProductGroup(), | ||||||
|  |                                   radarProductView->GetRadarProductName(), | ||||||
|  |                                   0, | ||||||
|  |                                   radarProductView->selected_time(), | ||||||
|  |                                   false); | ||||||
|       return; |       return; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  | @ -2090,38 +2127,54 @@ void MapWidgetImpl::CheckLevel3Availability() | ||||||
|    // Has no products in this category, do not change categories
 |    // Has no products in this category, do not change categories
 | ||||||
|    if (availableProductsIt == categoryMap.cend()) |    if (availableProductsIt == categoryMap.cend()) | ||||||
|    { |    { | ||||||
|  |       // Default to the same as already selected
 | ||||||
|  |       widget_->SelectRadarProduct(radarProductView->GetRadarProductGroup(), | ||||||
|  |                                   radarProductView->GetRadarProductName(), | ||||||
|  |                                   0, | ||||||
|  |                                   radarProductView->selected_time(), | ||||||
|  |                                   false); | ||||||
|       return; |       return; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    const auto& availableProducts = availableProductsIt->second; |    const auto& availableProducts = availableProductsIt->second; | ||||||
|    const auto& availableTiltsIt  = availableProducts.find(productName); |    const auto& availableTiltsIt  = availableProducts.find(productName); | ||||||
|    // Does not have the same product, but has others in the same category.
 |  | ||||||
|    // Switch to the default product and tilt in this category.
 |  | ||||||
|    if (availableTiltsIt == availableProducts.cend()) |  | ||||||
|    { |  | ||||||
|       widget_->SelectRadarProduct( |  | ||||||
|          common::RadarProductGroup::Level3, |  | ||||||
|          common::GetLevel3CategoryDefaultProduct(productCategory, categoryMap), |  | ||||||
|          0, |  | ||||||
|          widget_->GetSelectedTime()); |  | ||||||
|       return; |  | ||||||
|    } |  | ||||||
| 
 | 
 | ||||||
|    const auto& availableTilts = availableTiltsIt->second; |    const auto& availableTilts = | ||||||
|    const auto& tilt           = std::ranges::find_if( |       availableTiltsIt == availableProducts.cend() ? | ||||||
|       availableTilts, |          // Does not have the same product, but has others in the same category.
 | ||||||
|       [productTilt](const std::string& tilt) { return productTilt == tilt; }); |          // Switch to the default product and tilt in this category.
 | ||||||
|    // Tilt is not available, set it to first tilt
 |          availableProducts.at(common::GetLevel3ProductByAwipsId( | ||||||
|    if (tilt == availableTilts.cend() && availableTilts.size() > 0) |             common::GetLevel3CategoryDefaultProduct(productCategory, | ||||||
|  |                                                     categoryMap))) : | ||||||
|  |          // Has the same product
 | ||||||
|  |          availableTiltsIt->second; | ||||||
|  | 
 | ||||||
|  |    // Try to match the tilt to the last tilt.
 | ||||||
|  |    if (currentTiltIndex_ < availableTilts.size()) | ||||||
|    { |    { | ||||||
|       widget_->SelectRadarProduct(common::RadarProductGroup::Level3, |       widget_->SelectRadarProduct(common::RadarProductGroup::Level3, | ||||||
|                                   availableTilts[0], |                                   availableTilts[currentTiltIndex_], | ||||||
|                                   0, |                                   0, | ||||||
|                                   widget_->GetSelectedTime()); |                                   widget_->GetSelectedTime()); | ||||||
|       return; |  | ||||||
|    } |    } | ||||||
|  |    else if (availableTilts.size() > 0) | ||||||
|  |    { | ||||||
|  |       widget_->SelectRadarProduct(common::RadarProductGroup::Level3, | ||||||
|  |                                   availableTilts[availableTilts.size() - 1], | ||||||
|  |                                   0, | ||||||
|  |                                   widget_->GetSelectedTime()); | ||||||
| 
 | 
 | ||||||
|    // Tilt is available, no change needed
 |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       // No tilts available in this case, default to the same as already
 | ||||||
|  |       // selected
 | ||||||
|  |       widget_->SelectRadarProduct(radarProductView->GetRadarProductGroup(), | ||||||
|  |                                   radarProductView->GetRadarProductName(), | ||||||
|  |                                   0, | ||||||
|  |                                   radarProductView->selected_time(), | ||||||
|  |                                   false); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } // namespace map
 | } // namespace map
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak