<commit_before>// Copyright eeGeo Ltd (2012-2014), All Rights Reserved

#include "WorldPinsService.h"
#include "IWorldPinSelectionHandler.h"
#include "IWorldPinsRepository.h"
#include "IWorldPinsFactory.h"
#include "PinRepository.h"
#include "PinController.h"
#include "LatLongAltitude.h"
#include "Pin.h"
#include "Bounds.h"
#include "EarthConstants.h"
#include "Logger.h"

namespace ExampleApp
{
    namespace WorldPins
    {
        WorldPinsService::WorldPinsService(IWorldPinsRepository& worldPinsRepository,
                                           IWorldPinsFactory& worldPinsFactory,
                                           Eegeo::Pins::PinRepository& pinRepository,
                                           Eegeo::Pins::PinController& pinController,
                                           const Eegeo::Rendering::EnvironmentFlatteningService& flatteningService)
        : m_worldPinsRepository(worldPinsRepository)
        , m_worldPinsFactory(worldPinsFactory)
        , m_pinRepository(pinRepository)
        , m_pinController(pinController)
        , m_environmentFlatteningService(flatteningService)
        {
        }
        
        WorldPinsService::~WorldPinsService()
        {
            while(m_worldPinsRepository.GetItemCount() != 0)
            {
                WorldPinItemModel* item = m_worldPinsRepository.GetItemAtIndex(0);
                RemovePin(item);
            }
        }
        
        WorldPinItemModel* WorldPinsService::AddPin(IWorldPinSelectionHandler* pSelectionHandler,
                                                    const WorldPinFocusData& worldPinFocusData,
                                                    const Eegeo::Space::LatLong& location,
                                                    int iconIndex)
        {
            
            Eegeo::Pins::Pin* pPin = m_worldPinsFactory.CreatePin(location, iconIndex);
            
            m_pinRepository.AddPin(*pPin);
            
            Eegeo::Pins::TPinId pinId = pPin->GetId();
            
            mapIt pinIt = m_pinsToSelectionHandlers.find(pinId);
            Eegeo_ASSERT(pinIt == m_pinsToSelectionHandlers.end(), "Attempting to add same pin ID %d twice.\n", pinId);
            
            m_pinsToSelectionHandlers[pinId] = pSelectionHandler;
            
            WorldPinItemModel* model = Eegeo_NEW(WorldPinItemModel)(pinId, pSelectionHandler, worldPinFocusData);
            m_worldPinsRepository.AddItem(model);

            UpdatePinScale(*model, model->TransitionStateValue());
            
            return model;
        }
        
        void WorldPinsService::RemovePin(WorldPinItemModel* pinItemModel)
        {
            Eegeo::Pins::Pin* pPin = m_pinRepository.GetPinById(pinItemModel->Id());
            
            Eegeo_TTY("Pin removed\n");
            m_pinRepository.RemovePin(*pPin);
            ErasePin(pinItemModel->Id());
            
            m_worldPinsRepository.RemoveItem(pinItemModel);
            Eegeo_DELETE pinItemModel;
        }
        
        void WorldPinsService::UpdatePinScale(const WorldPinItemModel& pinItemModel, float scale)
        {
            Eegeo::Pins::Pin* pPin = m_pinRepository.GetPinById(pinItemModel.Id());
            Eegeo_ASSERT(pPin != NULL);
            m_pinController.SetScaleForPin(*pPin, scale);
        }
        
        bool WorldPinsService::HandleTouchTap(const Eegeo::v2& screenTapPoint)
        {
            std::vector<Eegeo::Pins::Pin*> intersectingPinsClosestToCameraFirst;
            
            if(m_pinController.TryGetPinsIntersectingScreenPoint(screenTapPoint, intersectingPinsClosestToCameraFirst))
            {
                Eegeo_ASSERT(intersectingPinsClosestToCameraFirst.size() > 0);
                Eegeo::Pins::Pin* pSelectedPin = intersectingPinsClosestToCameraFirst[0];
                Eegeo_ASSERT(pSelectedPin != NULL);
                mapIt pinIt = m_pinsToSelectionHandlers.find(pSelectedPin->GetId());
                Eegeo_ASSERT(pinIt != m_pinsToSelectionHandlers.end(), "Selected pin with unknown ID %d.\n", pSelectedPin->GetId());
                IWorldPinSelectionHandler& selectionHandler = *pinIt->second;
                selectionHandler.SelectPin();
                return true;
            }
            
            return false;
        }
        
        void WorldPinsService::GetPinEcefAndScreenLocations(const WorldPinItemModel& pinItemModel,<commit_msg>Change to WorldPinService. Prohibiting pins without heights from rendering by setting scale to zero. Since we're spreading height retrieval over a number of frames, it was common to see pins render, then receive heights, then jump. We now defer the rendering for a number of frames until we have a height. Buddy: Malc<commit_after>// Copyright eeGeo Ltd (2012-2014), All Rights Reserved

#include "WorldPinsService.h"
#include "IWorldPinSelectionHandler.h"
#include "IWorldPinsRepository.h"
#include "IWorldPinsFactory.h"
#include "PinRepository.h"
#include "PinController.h"
#include "LatLongAltitude.h"
#include "Pin.h"
#include "Bounds.h"
#include "EarthConstants.h"
#include "Logger.h"

namespace ExampleApp
{
    namespace WorldPins
    {
        WorldPinsService::WorldPinsService(IWorldPinsRepository& worldPinsRepository,
                                           IWorldPinsFactory& worldPinsFactory,
                                           Eegeo::Pins::PinRepository& pinRepository,
                                           Eegeo::Pins::PinController& pinController,
                                           const Eegeo::Rendering::EnvironmentFlatteningService& flatteningService)
        : m_worldPinsRepository(worldPinsRepository)
        , m_worldPinsFactory(worldPinsFactory)
        , m_pinRepository(pinRepository)
        , m_pinController(pinController)
        , m_environmentFlatteningService(flatteningService)
        {
        }
        
        WorldPinsService::~WorldPinsService()
        {
            while(m_worldPinsRepository.GetItemCount() != 0)
            {
                WorldPinItemModel* item = m_worldPinsRepository.GetItemAtIndex(0);
                RemovePin(item);
            }
        }
        
        WorldPinItemModel* WorldPinsService::AddPin(IWorldPinSelectionHandler* pSelectionHandler,
                                                    const WorldPinFocusData& worldPinFocusData,
                                                    const Eegeo::Space::LatLong& location,
                                                    int iconIndex)
        {
            
            Eegeo::Pins::Pin* pPin = m_worldPinsFactory.CreatePin(location, iconIndex);
            
            m_pinRepository.AddPin(*pPin);
            
            Eegeo::Pins::TPinId pinId = pPin->GetId();
            
            mapIt pinIt = m_pinsToSelectionHandlers.find(pinId);
            Eegeo_ASSERT(pinIt == m_pinsToSelectionHandlers.end(), "Attempting to add same pin ID %d twice.\n", pinId);
            
            m_pinsToSelectionHandlers[pinId] = pSelectionHandler;
            
            WorldPinItemModel* model = Eegeo_NEW(WorldPinItemModel)(pinId, pSelectionHandler, worldPinFocusData);
            m_worldPinsRepository.AddItem(model);

            UpdatePinScale(*model, model->TransitionStateValue());
            
            return model;
        }
        
        void WorldPinsService::RemovePin(WorldPinItemModel* pinItemModel)
        {
            Eegeo::Pins::Pin* pPin = m_pinRepository.GetPinById(pinItemModel->Id());
            
            Eegeo_TTY("Pin removed\n");
            m_pinRepository.RemovePin(*pPin);
            ErasePin(pinItemModel->Id());
            
            m_worldPinsRepository.RemoveItem(pinItemModel);
            Eegeo_DELETE pinItemModel;
        }
        
        void WorldPinsService::UpdatePinScale(const WorldPinItemModel& pinItemModel, float scale)
        {
            Eegeo::Pins::Pin* pPin = m_pinRepository.GetPinById(pinItemModel.Id());
            Eegeo_ASSERT(pPin != NULL);
            
            float scaleWithTerrainHeight = pPin->HasTerrainHeight() ? scale : 0.f;
            m_pinController.SetScaleForPin(*pPin, scaleWithTerrainHeight);
        }
        
        bool WorldPinsService::HandleTouchTap(const Eegeo::v2& screenTapPoint)
        {
            std::vector<Eegeo::Pins::Pin*> intersectingPinsClosestToCameraFirst;
            
            if(m_pinController.TryGetPinsIntersectingScreenPoint(screenTapPoint, intersectingPinsClosestToCameraFirst))
            {
                Eegeo_ASSERT(intersectingPinsClosestToCameraFirst.size() > 0);
                Eegeo::Pins::Pin* pSelectedPin = intersectingPinsClosestToCameraFirst[0];
                Eegeo_ASSERT(pSelectedPin != NULL);
                mapIt pinIt = m_pinsToSelectionHandlers.find(pSelectedPin->GetId());
                Eegeo_ASSERT(pinIt != m_pinsToSelectionHandlers.end(), "Selected pin with unknown ID %d.\n", pSelectedPin->GetId());
                IWorldPinSelectionHandler& selectionHandler = *pinIt->second;
                selectionHandler.SelectPin();
                return true;
            }
            
            return false;
        }
        
        void WorldPinsService::GetPinEcefAndScreenLocations(const WorldPinItemModel& pinItemModel,
{'fraction_non_alphanumeric': 0.0838799870953866, 'fraction_numerical': 0.0029035380148403054, 'mean_word_length': 2.083554376657825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2996055', 'n_tokens_mistral': 2525, 'n_tokens_neox': 2455, 'n_words': 390}